Skip to content

Commit ce220d3

Browse files
committed
feat: enhance power button configuration with additional actions and update layout
1 parent d87eeeb commit ce220d3

File tree

6 files changed

+50
-20
lines changed

6 files changed

+50
-20
lines changed

config.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
},
7474
"layout": {
7575
"left_section": ["workspaces", "window_title"],
76-
"middle_section": ["date_time"],
76+
"middle_section": ["date_time", "power"],
7777
"right_section": ["recorder", "@group:1", "@group:0", "system_tray"]
7878
},
7979
"module_groups": [
@@ -152,7 +152,8 @@
152152
"power": {
153153
"icon": "󰐥",
154154
"icon_size": "18px",
155-
"tooltip": true
155+
"tooltip": true,
156+
"buttons": ["suspend", "hibernate", "shutdown", "reboot", "logout", "lock"]
156157
},
157158
"recorder": {
158159
"path": "Videos/Screencasting",

hydepanel.schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,20 @@
630630
},
631631
"tooltip": {
632632
"type": "boolean"
633+
},
634+
"buttons": {
635+
"type": "array",
636+
"items": {
637+
"type": "string",
638+
"enum": [
639+
"logout",
640+
"reboot",
641+
"shutdown",
642+
"suspend",
643+
"lock",
644+
"hibernate"
645+
]
646+
}
633647
}
634648
}
635649
},

styles/power.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
@use "theme.scss";
33
@use "common" as common;
44

5+
#power-button-menu {
6+
background-color: theme.$background;
7+
}
8+
59
#power-control-button {
610
padding: common.toEm(40) common.toEm(120);
711
border-radius: 0;
@@ -22,7 +26,7 @@
2226
&:focus,
2327
&:active,
2428
&:hover {
25-
background-color: #3700b3;
29+
background-color: theme.$accent-purple;
2630
outline-style: none;
2731
}
2832
}

utils/constants.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,19 @@
196196
"location": "top",
197197
"widget_style": "default",
198198
},
199-
"power": {"icon": "󰐥", "icon_size": "18px", "tooltip": True},
199+
"power": {
200+
"icon": "󰐥",
201+
"icon_size": "18px",
202+
"tooltip": True,
203+
"buttons": [
204+
"lock",
205+
"logout",
206+
"suspend",
207+
"hibernate",
208+
"shutdown",
209+
"reboot",
210+
],
211+
},
200212
"recorder": {
201213
"path": "Videos/Screencasting",
202214
"icon_size": 16,

utils/widget_settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
)
1313

1414
# Power button configuration
15-
PowerButton = TypedDict("PowerButton", {"icon": str, "icon_size": int, "tooltip": bool})
15+
PowerButton = TypedDict(
16+
"PowerButton", {"icon": str, "icon_size": int, "tooltip": bool, "items": List[str]}
17+
)
1618

1719
# HyprSunset configuration
1820
HyprSunset = TypedDict(

widgets/power_button.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88

99
from shared import PopupWindow
1010
from shared.widget_container import ButtonWidget
11+
from utils.config import widget_config
1112
from utils.functions import handle_power_action
1213
from utils.widget_settings import BarConfig
1314
from utils.widget_utils import text_icon
1415

15-
POWER_BUTTONS = [
16-
{"name": "lock", "label": "Lock"},
17-
{"name": "logout", "label": "Logout"},
18-
{"name": "suspend", "label": "Suspend"},
19-
{"name": "hibernate", "label": "Hibernate"},
20-
{"name": "shutdown", "label": "Shutdown"},
21-
{"name": "reboot", "label": "Reboot"},
22-
]
16+
POWER_BUTTONS = widget_config["power"]["buttons"]
2317

2418

2519
class PowerMenuPopup(PopupWindow):
@@ -48,8 +42,7 @@ def __init__(
4842
orientation="h",
4943
children=[
5044
PowerControlButtons(
51-
name=value["name"],
52-
label=value["label"],
45+
name=value,
5346
size=self.icon_size,
5447
)
5548
for value in POWER_BUTTONS[0:3]
@@ -59,8 +52,7 @@ def __init__(
5952
orientation="h",
6053
children=[
6154
PowerControlButtons(
62-
name=value["name"],
63-
label=value["label"],
55+
name=value,
6456
size=self.icon_size,
6557
)
6658
for value in POWER_BUTTONS[3:]
@@ -90,7 +82,7 @@ def toggle_popup(self):
9082
class PowerControlButtons(ButtonWidget):
9183
"""A widget to show power options."""
9284

93-
def __init__(self, name, label, size, **kwargs):
85+
def __init__(self, name: str, size: int, show_label=True, **kwargs):
9486
(
9587
super().__init__(
9688
orientation="v",
@@ -103,7 +95,11 @@ def __init__(self, name, label, size, **kwargs):
10395
image_file=get_relative_path(f"../assets/icons/{name}.png"),
10496
size=size,
10597
),
106-
Label(label=label, style_classes="panel-text"),
98+
Label(
99+
label=name.capitalize(),
100+
style_classes="panel-text",
101+
visible=show_label,
102+
),
107103
],
108104
),
109105
**kwargs,
@@ -143,5 +139,6 @@ def __init__(self, widget_config: BarConfig, bar, **kwargs):
143139
self.set_tooltip_text("Power")
144140

145141
self.connect(
146-
"clicked", lambda *_: PowerMenuPopup().get_default().toggle_popup()
142+
"clicked",
143+
lambda *_: PowerMenuPopup().get_default().toggle_popup(),
147144
)

0 commit comments

Comments
 (0)