@@ -17,6 +17,15 @@ def __init__(self):
17
17
self .right = - 1
18
18
self .left = - 1
19
19
20
+ def position_used (self , position ):
21
+ if position == "top" :
22
+ return self .top != - 1
23
+ elif position == "bottom" :
24
+ return self .bottom != - 1
25
+ elif position == "left" :
26
+ return self .left != - 1
27
+ elif position == "right" :
28
+ return self .right != - 1
20
29
21
30
class PanelSettingsPage (SettingsPage ):
22
31
def __init__ (self , panel_id , settings , position ):
@@ -166,6 +175,7 @@ def on_module_selected(self):
166
175
self .panel_id = ""
167
176
168
177
self .panels = []
178
+ self .updating = False
169
179
170
180
self .previous_button = Gtk .Button (_ ("Previous panel" ))
171
181
self .next_button = Gtk .Button (_ ("Next panel" ))
@@ -279,26 +289,50 @@ def on_next_panel(self, widget):
279
289
280
290
self .config_stack .set_visible_child (self .current_panel )
281
291
292
+ def id_or_monitor_position_used (self , kept_panels , monitor_layout , panel_id , monitor_id , position ):
293
+ for keeper in kept_panels :
294
+ if keeper .panel_id == panel_id :
295
+ print ("cs_panel: Ignoring panel definition with an already-used ID: (ID: %s, Monitor: %d, Position: %s)" % (panel_id , monitor_id , position ))
296
+ return True
297
+ if monitor_layout [monitor_id ].position_used (position ):
298
+ print ("cs_panel: Ignoring panel definition with an already-used monitor:position: (ID: %s, Monitor: %d, Position: %s)" % (panel_id , monitor_id , position ))
299
+ return True
300
+ return False
301
+
282
302
def on_panel_list_changed (self , * args ):
303
+ if self .updating :
304
+ return
305
+
306
+ self .updating = True
307
+
283
308
if len (self .panels ) > 0 :
284
309
for panel in self .panels :
285
310
panel .destroy ()
286
311
287
312
self .panels = []
288
313
monitor_layout = []
289
314
290
- panels = self .settings .get_strv ("panels-enabled" )
315
+ panel_defs = self .settings .get_strv ("panels-enabled" )
291
316
n_mons = Gdk .Screen .get_default ().get_n_monitors ()
292
317
293
318
for i in range (n_mons ):
294
319
monitor_layout .append (Monitor ())
295
320
296
321
current_found = False
297
- for panel in panels :
298
- panel_id , monitor_id , position = panel .split (":" )
322
+ already_defined_panels = []
323
+ removals = []
324
+
325
+ for def_ in panel_defs :
326
+ panel_id , monitor_id , position = def_ .split (":" )
299
327
monitor_id = int (monitor_id )
328
+
329
+ if self .id_or_monitor_position_used (already_defined_panels , monitor_layout , panel_id , monitor_id , position ):
330
+ removals .append (def_ )
331
+ continue
332
+
300
333
panel_page = PanelSettingsPage (panel_id , self .settings , position )
301
334
self .config_stack .add_named (panel_page , panel_id )
335
+ already_defined_panels .append (panel_page )
302
336
303
337
# we may already have a current panel id from the command line or if
304
338
# if the panels-enabled key changed since everything was loaded
@@ -320,6 +354,12 @@ def on_panel_list_changed(self, *args):
320
354
else :
321
355
monitor_layout [monitor_id ].right = panel_page
322
356
357
+ if removals :
358
+ print ("Cleaning up conflicting defs in panels-enabled" )
359
+ for def_ in removals :
360
+ panel_defs .remove (def_ )
361
+ self .settings .set_strv ("panels-enabled" , panel_defs )
362
+
323
363
# Index the panels for the next/previous buttons
324
364
for monitor in monitor_layout :
325
365
for panel_page in (monitor .top , monitor .bottom , monitor .left , monitor .right ):
@@ -334,6 +374,7 @@ def on_panel_list_changed(self, *args):
334
374
self .add_panel_button .set_sensitive (True )
335
375
self .current_panel = None
336
376
self .panel_id = None
377
+ self .updating = False
337
378
return
338
379
339
380
self .config_stack .show ()
@@ -369,6 +410,8 @@ def on_panel_list_changed(self, *args):
369
410
except :
370
411
current_idx = 0
371
412
413
+ self .updating = False
414
+
372
415
if self .proxy :
373
416
self .proxy .highlightPanel ('(ib)' , int (self .panel_id ), True )
374
417
0 commit comments