@@ -26,6 +26,7 @@ class WorkspaceButton(QPushButton):
26
26
27
27
def __init__ (self , workspace_index : int , parent_widget : 'WorkspaceWidget' , label : str = None , active_label : str = None , populated_label : str = None , animation : bool = False ):
28
28
super ().__init__ ()
29
+ self ._animation_initialized = False
29
30
self .komorebic = KomorebiClient ()
30
31
self .workspace_index = workspace_index
31
32
self .parent_widget = parent_widget
@@ -66,13 +67,13 @@ def activate_workspace(self):
66
67
try :
67
68
self .komorebic .activate_workspace (self .parent_widget ._komorebi_screen ['index' ], self .workspace_index )
68
69
if self ._animation :
69
- self .animate_buttons ()
70
+ pass
71
+ #self.animate_buttons()
70
72
except Exception :
71
73
logging .exception (f"Failed to focus workspace at index { self .workspace_index } " )
72
74
73
- def animate_buttons (self , duration = 200 , step = 120 ):
74
- #Store the initial width if not already stored
75
- #we need this to animate the width back to the initial width
75
+ def animate_buttons (self , duration = 200 , step = 30 ):
76
+ # Store the initial width if not already stored (to enable reverse animations)
76
77
if not hasattr (self , '_initial_width' ):
77
78
self ._initial_width = self .width ()
78
79
@@ -81,7 +82,6 @@ def animate_buttons(self, duration=200, step=120):
81
82
82
83
step_duration = int (duration / step )
83
84
width_increment = (target_width - self ._current_width ) / step
84
-
85
85
self ._current_step = 0
86
86
87
87
def update_width ():
@@ -90,14 +90,16 @@ def update_width():
90
90
self .setFixedWidth (int (self ._current_width ))
91
91
self ._current_step += 1
92
92
else :
93
+ # Animation done: stop timer and set to target exactly
93
94
self ._animation_timer .stop ()
94
95
self .setFixedWidth (target_width )
95
96
96
97
# Stop any existing timer before starting a new one to prevent conflicts
97
98
if hasattr (self , '_animation_timer' ) and self ._animation_timer .isActive ():
98
99
self ._animation_timer .stop ()
99
100
100
- self ._animation_timer = QTimer ()
101
+ # Parent the timer to the widget to avoid potential memory leaks
102
+ self ._animation_timer = QTimer (self )
101
103
self ._animation_timer .timeout .connect (update_width )
102
104
self ._animation_timer .start (step_duration )
103
105
@@ -117,6 +119,7 @@ def __init__(
117
119
label_workspace_populated_btn : str ,
118
120
label_default_name : str ,
119
121
label_float_override : str ,
122
+ toggle_workspace_layer : dict ,
120
123
hide_if_offline : bool ,
121
124
label_zero_index : bool ,
122
125
hide_empty_workspaces : bool ,
@@ -131,6 +134,7 @@ def __init__(
131
134
self ._label_workspace_populated_btn = label_workspace_populated_btn
132
135
self ._label_default_name = label_default_name
133
136
self ._label_float_override = label_float_override
137
+ self ._toggle_workspace_layer = toggle_workspace_layer
134
138
self ._label_zero_index = label_zero_index
135
139
self ._hide_if_offline = hide_if_offline
136
140
self ._padding = container_padding
@@ -146,7 +150,8 @@ def __init__(
146
150
KomorebiEvent .CycleFocusMonitor .value ,
147
151
KomorebiEvent .FocusMonitorWorkspaceNumber .value ,
148
152
KomorebiEvent .FocusMonitorNumber .value ,
149
- KomorebiEvent .FocusWorkspaceNumber .value
153
+ KomorebiEvent .FocusWorkspaceNumber .value ,
154
+ KomorebiEvent .ToggleWorkspaceLayer .value
150
155
]
151
156
self ._update_buttons_event_watchlist = [
152
157
KomorebiEvent .EnsureWorkspaces .value ,
@@ -159,8 +164,7 @@ def __init__(
159
164
KomorebiEvent .Unmanage .value ,
160
165
KomorebiEvent .WatchConfiguration .value ,
161
166
KomorebiEvent .WorkspaceName .value ,
162
- KomorebiEvent .Cloak .value ,
163
- #KomorebiEvent.CloseWorkspace.value
167
+ KomorebiEvent .Cloak .value
164
168
]
165
169
# Disable default mouse event handling inherited from BaseWidget
166
170
self .mousePressEvent = None
@@ -188,6 +192,11 @@ def __init__(
188
192
self .float_override_label .hide ()
189
193
self .widget_layout .addWidget (self .float_override_label )
190
194
195
+ if self ._toggle_workspace_layer ['enabled' ]:
196
+ self .workspace_layer_label = QLabel ()
197
+ self .workspace_layer_label .setProperty ("class" , "workspace-layer" )
198
+ self .widget_layout .addWidget (self .workspace_layer_label )
199
+
191
200
self ._register_signals_and_events ()
192
201
193
202
def _register_signals_and_events (self ):
@@ -255,7 +264,10 @@ def _on_komorebi_update_event(self, event: dict, state: dict) -> None:
255
264
for workspace_index in unknown_indexes :
256
265
self ._try_remove_workspace_button (workspace_index )
257
266
self ._add_or_update_buttons ()
258
-
267
+
268
+ if event ['type' ] == KomorebiEvent .FocusChange .value :
269
+ self ._get_workspace_layer (self ._curr_workspace_index )
270
+
259
271
# Show float override label if float override is active
260
272
if state .get ('float_override' ) and self ._label_float_override :
261
273
self .float_override_label .show ()
@@ -301,6 +313,31 @@ def _get_workspace_new_status(self, workspace) -> WorkspaceStatus:
301
313
else :
302
314
return WORKSPACE_STATUS_EMPTY
303
315
316
+ def _get_workspace_layer (self , workspace_index : int ) -> None :
317
+ """
318
+ This function is used to get the workspace layer by index. (toggle-workspace-layer)
319
+ Also updates the label's CSS class based on current layer.
320
+ """
321
+ if self ._toggle_workspace_layer ['enabled' ]:
322
+ workspace = self ._komorebic .get_workspace_by_index (self ._komorebi_screen , workspace_index )
323
+ if workspace and 'layer' in workspace :
324
+ # Set base class plus layer-specific class
325
+ layer_type = workspace ['layer' ].lower () # Either "tiling" or "floating"
326
+ self .workspace_layer_label .setProperty ("class" , f"workspace-layer { layer_type } " )
327
+
328
+ # Set appropriate label text
329
+ if workspace ['layer' ] == 'Tiling' :
330
+ self .workspace_layer_label .setText (self ._toggle_workspace_layer ['tiling_label' ])
331
+ elif workspace ['layer' ] == 'Floating' :
332
+ self .workspace_layer_label .setText (self ._toggle_workspace_layer ['floating_label' ])
333
+ self .workspace_layer_label .style ().unpolish (self .workspace_layer_label )
334
+ self .workspace_layer_label .style ().polish (self .workspace_layer_label )
335
+ else :
336
+ self .workspace_layer_label .setProperty ("class" , "workspace-layer" )
337
+ self .workspace_layer_label .setText ("" )
338
+ self .workspace_layer_label .style ().unpolish (self .workspace_layer_label )
339
+ self .workspace_layer_label .style ().polish (self .workspace_layer_label )
340
+
304
341
def _update_button (self , workspace_btn : WorkspaceButton ) -> None :
305
342
workspace_index = workspace_btn .workspace_index
306
343
workspace = self ._komorebic .get_workspace_by_index (self ._komorebi_screen , workspace_index )
@@ -311,13 +348,15 @@ def _update_button(self, workspace_btn: WorkspaceButton) -> None:
311
348
workspace_btn .show ()
312
349
if workspace_btn .status != workspace_status :
313
350
workspace_btn .update_and_redraw (workspace_status )
314
- if self ._animation :
351
+ if self ._animation and workspace_btn . _animation_initialized :
315
352
workspace_btn .animate_buttons ()
316
353
workspace_btn .update_visible_buttons ()
354
+ self ._get_workspace_layer (workspace_index )
355
+ workspace_btn ._animation_initialized = True
317
356
318
357
def _add_or_update_buttons (self ) -> None :
319
358
buttons_added = False
320
- for workspace_index , workspace in enumerate (self ._komorebi_workspaces ):
359
+ for workspace_index , _ in enumerate (self ._komorebi_workspaces ):
321
360
try :
322
361
button = self ._workspace_buttons [workspace_index ]
323
362
self ._update_button (button )
0 commit comments