Skip to content

Commit da30af3

Browse files
committed
cs_panel.py: Fix behavior when there are overlapping definitions.
All panel definitions were being processed. If for some reason a panel id was used twice, the second would still be added to the stack navigation list (self.panels). The same would occur if a given monitor:position slot had already been filled. This would break navigation when switching between panels - the button handlers would try to select pages from the stack that weren't in it. If any bad definitions are found, they're removed from 'panels- enabled' ref: 11406
1 parent 46b39c8 commit da30af3

File tree

1 file changed

+46
-3
lines changed
  • files/usr/share/cinnamon/cinnamon-settings/modules

1 file changed

+46
-3
lines changed

files/usr/share/cinnamon/cinnamon-settings/modules/cs_panel.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ def __init__(self):
1717
self.right = -1
1818
self.left = -1
1919

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
2029

2130
class PanelSettingsPage(SettingsPage):
2231
def __init__(self, panel_id, settings, position):
@@ -166,6 +175,7 @@ def on_module_selected(self):
166175
self.panel_id = ""
167176

168177
self.panels = []
178+
self.updating = False
169179

170180
self.previous_button = Gtk.Button(_("Previous panel"))
171181
self.next_button = Gtk.Button(_("Next panel"))
@@ -279,26 +289,50 @@ def on_next_panel(self, widget):
279289

280290
self.config_stack.set_visible_child(self.current_panel)
281291

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+
282302
def on_panel_list_changed(self, *args):
303+
if self.updating:
304+
return
305+
306+
self.updating = True
307+
283308
if len(self.panels) > 0:
284309
for panel in self.panels:
285310
panel.destroy()
286311

287312
self.panels = []
288313
monitor_layout = []
289314

290-
panels = self.settings.get_strv("panels-enabled")
315+
panel_defs = self.settings.get_strv("panels-enabled")
291316
n_mons = Gdk.Screen.get_default().get_n_monitors()
292317

293318
for i in range(n_mons):
294319
monitor_layout.append(Monitor())
295320

296321
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(":")
299327
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+
300333
panel_page = PanelSettingsPage(panel_id, self.settings, position)
301334
self.config_stack.add_named(panel_page, panel_id)
335+
already_defined_panels.append(panel_page)
302336

303337
# we may already have a current panel id from the command line or if
304338
# if the panels-enabled key changed since everything was loaded
@@ -320,6 +354,12 @@ def on_panel_list_changed(self, *args):
320354
else:
321355
monitor_layout[monitor_id].right = panel_page
322356

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+
323363
# Index the panels for the next/previous buttons
324364
for monitor in monitor_layout:
325365
for panel_page in (monitor.top, monitor.bottom, monitor.left, monitor.right):
@@ -334,6 +374,7 @@ def on_panel_list_changed(self, *args):
334374
self.add_panel_button.set_sensitive(True)
335375
self.current_panel = None
336376
self.panel_id = None
377+
self.updating = False
337378
return
338379

339380
self.config_stack.show()
@@ -369,6 +410,8 @@ def on_panel_list_changed(self, *args):
369410
except:
370411
current_idx = 0
371412

413+
self.updating = False
414+
372415
if self.proxy:
373416
self.proxy.highlightPanel('(ib)', int(self.panel_id), True)
374417

0 commit comments

Comments
 (0)