Skip to content

Commit 2c8a844

Browse files
committed
Shared panels
1 parent 51c029e commit 2c8a844

File tree

9 files changed

+787
-171
lines changed

9 files changed

+787
-171
lines changed

data/org.cinnamon.gschema.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@
124124
</description>
125125
</key>
126126

127+
<key name="shared-panels" type="s">
128+
<default>'[]'</default>
129+
<summary>JSON string of shared panel information</summary>
130+
<description>
131+
Stores the panel ids that are being shared.
132+
</description>
133+
</key>
134+
127135
<key name="panels-autohide" type="as">
128136
<default>['1:false']</default>
129137
<summary>Auto-hide panel</summary>

files/usr/share/cinnamon/cinnamon-settings/bin/JsonSettingsWidgets.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ def check_settings(self, *args):
147147
for callback in callback_list:
148148
callback(key, new_value)
149149

150+
for key in self.settings:
151+
if ("value" in self.settings[key]
152+
and self.settings[key]["value"] != old_settings[key]["value"]
153+
and self.notify_callback
154+
):
155+
self.notify_callback(self, key, new_value)
156+
150157
def get_settings(self):
151158
try:
152159
file = open(self.filepath)

files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from PIL import Image
1515
import datetime
1616
import time
17+
import json
1718
except Exception as error_message:
1819
print(error_message)
1920
sys.exit(1)
@@ -856,19 +857,32 @@ def enable_extension(self, uuid, panel=1, box='right', position=0):
856857
if self.collection_type == 'applet':
857858
entries = []
858859
applet_id = self.settings.get_int('next-applet-id')
859-
self.settings.set_int('next-applet-id', (applet_id+1))
860+
shared_panels = json.loads(self.settings.get_string('shared-panels'))
860861

861862
for entry in self.settings.get_strv(self.enabled_key):
862863
info = entry.split(':')
863864
pos = int(info[2])
864-
if info[0] == f'panel{panel}' and info[1] == box and position <= pos:
865-
info[2] = str(pos+1)
865+
panelId = int(info[0][-1])
866+
if (
867+
(info[0] == f'panel{panel}' or panelId in shared_panels)
868+
and info[1] == box
869+
and position <= pos
870+
):
871+
new_pos = pos+1
872+
info[2] = str(new_pos)
866873
entries.append(':'.join(info))
867874
else:
868875
entries.append(entry)
869876

870-
entries.append(f'panel{panel}:{box}:{position}:{uuid}:{applet_id}')
877+
if panel in shared_panels:
878+
for panel in shared_panels:
879+
entries.append(f'panel{panel}:{box}:{position}:{uuid}:{applet_id}')
880+
applet_id += 1
881+
else:
882+
entries.append(f'panel{panel}:{box}:{position}:{uuid}:{applet_id}')
883+
applet_id += 1
871884

885+
self.settings.set_int('next-applet-id', (applet_id))
872886
self.settings.set_strv(self.enabled_key, entries)
873887
elif self.collection_type == 'desklet':
874888
desklet_id = self.settings.get_int('next-desklet-id')

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from Spices import Spice_Harvester
88
from gi.repository import GLib, Gtk, Gdk
99
import config
10+
import json
1011

1112
class Module:
1213
name = "applets"
@@ -90,30 +91,29 @@ def __init__(self, parent, spices, window):
9091

9192
self.top_box.pack_start(self.panel_select_buttons, False, False, 0)
9293

93-
def previous_panel(self, *args):
94+
def getNextPanel(self, positive_direction = True):
9495
self.spices.send_proxy_signal('highlightPanel', '(ib)', self.panel_id, False)
96+
shared_panels = json.loads(self.spices.settings.get_string("shared-panels"))
97+
step = 1 if positive_direction else -1
9598

96-
if self.current_panel_index - 1 >= 0:
97-
self.current_panel_index -= 1
98-
else:
99-
self.current_panel_index = len(self.panels) - 1
100-
self.panel_id = int(self.panels[self.current_panel_index].split(":")[0])
99+
for _ in self.panels:
100+
self.current_panel_index = (self.current_panel_index + step) % len(self.panels)
101+
checked_panel_id = int(self.panels[self.current_panel_index].split(":")[0])
102+
if checked_panel_id not in shared_panels or self.panel_id not in shared_panels:
103+
self.panel_id = checked_panel_id
104+
break
101105

102106
self.spices.send_proxy_signal('highlightPanel', '(ib)', self.panel_id, True)
103107

104-
def next_panel(self, widget):
105-
self.spices.send_proxy_signal('highlightPanel', '(ib)', self.panel_id, False)
106-
107-
if self.current_panel_index + 1 < len(self.panels):
108-
self.current_panel_index += 1
109-
else:
110-
self.current_panel_index = 0
111-
self.panel_id = int(self.panels[self.current_panel_index].split(":")[0])
108+
def previous_panel(self, *args):
109+
self.getNextPanel(False)
112110

113-
self.spices.send_proxy_signal('highlightPanel', '(ib)', self.panel_id, True)
111+
def next_panel(self, widget):
112+
self.getNextPanel()
114113

115114
def panels_changed(self, *args):
116115
self.panels = []
116+
shared_panels = json.loads(self.spices.settings.get_string("shared-panels"))
117117
n_mons = Gdk.Screen.get_default().get_n_monitors()
118118

119119
# we only want to select panels that are on a connected screen
@@ -131,7 +131,7 @@ def panels_changed(self, *args):
131131
self.current_panel_index = 0
132132
self.panel_id = int(self.panels[self.current_panel_index].split(":")[0])
133133

134-
if len(self.panels) > 1:
134+
if len(self.panels) > 1 and len(self.panels) != len(shared_panels):
135135
self.previous_button.show()
136136
self.next_button.show()
137137
# just in case, we'll make sure the current panel is highlighted

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

Lines changed: 66 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -250,46 +250,37 @@ def on_add_panel(self, widget):
250250
if self.proxy:
251251
self.proxy.addPanelQuery()
252252

253-
def on_previous_panel(self, widget):
253+
def getNextPanel(self, positive_direction = True):
254254
if self.panel_id and self.proxy:
255255
self.proxy.highlightPanel('(ib)', int(self.panel_id), False)
256256

257-
current = self.panels.index(self.current_panel)
257+
index = current = self.panels.index(self.current_panel)
258+
shared_panels = json.loads(self.settings.get_string("shared-panels"))
258259

259-
if current - 1 >= 0:
260-
self.current_panel = self.panels[current - 1]
261-
self.panel_id = self.current_panel.panel_id
262-
else:
263-
self.current_panel = self.panels[len(self.panels) - 1]
264-
self.panel_id = self.current_panel.panel_id
260+
step = 1 if positive_direction else -1
265261

266-
self.config_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_RIGHT)
262+
for _ in self.panels:
263+
index = (index + step) % len(self.panels)
267264

268-
if self.proxy:
269-
self.proxy.highlightPanel('(ib)', int(self.panel_id), True)
270-
271-
self.config_stack.set_visible_child(self.current_panel)
272-
273-
def on_next_panel(self, widget):
274-
if self.panel_id and self.proxy:
275-
self.proxy.highlightPanel('(ib)', int(self.panel_id), False)
276-
277-
current = self.panels.index(self.current_panel)
278-
279-
if current + 1 < len(self.panels):
280-
self.current_panel = self.panels[current + 1]
281-
self.panel_id = self.current_panel.panel_id
282-
else:
283-
self.current_panel = self.panels[0]
284-
self.panel_id = self.current_panel.panel_id
265+
if int(self.panels[index].panel_id) not in shared_panels or int(self.panel_id) not in shared_panels:
266+
self.current_panel = self.panels[index]
267+
self.panel_id = self.current_panel.panel_id
268+
break
285269

286-
self.config_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT)
270+
self.config_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT if positive_direction
271+
else Gtk.StackTransitionType.SLIDE_RIGHT)
287272

288273
if self.proxy:
289274
self.proxy.highlightPanel('(ib)', int(self.panel_id), True)
290275

291276
self.config_stack.set_visible_child(self.current_panel)
292277

278+
def on_previous_panel(self, widget):
279+
self.getNextPanel(False)
280+
281+
def on_next_panel(self, widget):
282+
self.getNextPanel()
283+
293284
def id_or_monitor_position_used(self, kept_panels, monitor_layout, panel_id, monitor_id, position):
294285
for keeper in kept_panels:
295286
if keeper.panel_id == panel_id:
@@ -384,8 +375,10 @@ def on_panel_list_changed(self, *args):
384375
self.next_button.show()
385376
self.previous_button.show()
386377

387-
# Disable the panel switch buttons if there's only one panel
388-
if len(self.panels) == 1:
378+
# Disable the panel switch buttons if there's only one panel or if there is only shared panels
379+
if len(self.panels) == 1 or (
380+
len(self.panels) - len(json.loads(self.settings.get_string("shared-panels"))) == 0
381+
):
389382
self.next_button.set_sensitive(False)
390383
self.previous_button.set_sensitive(False)
391384
else:
@@ -438,11 +431,16 @@ def connect_to_settings(self, schema, key):
438431
self.connect_widget_handlers()
439432

440433
def set_value(self, value):
434+
shared_panels = json.loads(self.settings['shared-panels'])
441435
vals = self.settings[self.key]
442436
newvals = []
443437
for val in vals:
444-
if val.split(":")[0] == self.panel_id:
445-
newvals.append(self.panel_id + ":" + self.stringify(value))
438+
val_panel_id = val.split(":")[0]
439+
if val_panel_id == self.panel_id or (
440+
int(self.panel_id) in shared_panels
441+
and int(val_panel_id) in shared_panels
442+
):
443+
newvals.append(val_panel_id + ":" + self.stringify(value))
446444
else:
447445
newvals.append(val)
448446
self.settings[self.key] = newvals
@@ -511,36 +509,24 @@ def on_setting_changed(self, *args):
511509
if value is not None and value != int(self.content_widget.get_value()):
512510
self.content_widget.set_value(value)
513511

514-
class PanelJSONSpinButton(SpinButton, PanelWidgetBackend):
515-
def __init__(self, label, schema, key, panel_id, zone, *args, **kwargs):
516-
self.panel_id = panel_id
517-
self.zone = zone
518-
super(PanelJSONSpinButton, self).__init__(label, *args, **kwargs)
519-
520-
self.connect_to_settings(schema, key)
521-
522-
def get_range(self):
523-
return
524-
525-
# We use integer directly here because that is all the panel currently uses.
526-
# If that changes in the future, we will need to fix this.
527-
def stringify(self, value):
528-
return str(int(value))
529-
530-
def unstringify(self, value):
531-
return int(value)
532-
533-
def on_setting_changed(self, *args):
534-
self.content_widget.set_value(self.get_value())
512+
class PanelJSONHelper:
513+
def __init__(self, isSpinBtn, *args, **kwargs):
514+
self.isSpinBtn = isSpinBtn
515+
super().__init__(*args, **kwargs)
535516

536517
def set_value(self, value):
518+
shared_panels = json.loads(self.settings['shared-panels'])
537519
vals = json.loads(self.settings[self.key])
520+
panel_id = int(self.panel_id)
538521
for obj in vals:
539-
if obj['panelId'] != int(self.panel_id):
522+
if obj['panelId'] != panel_id and (
523+
panel_id not in shared_panels
524+
or obj['panelId'] not in shared_panels
525+
):
540526
continue
541527
for key, val in obj.items():
542528
if key == self.zone:
543-
obj[key] = int(value)
529+
obj[key] = int(value) if self.isSpinBtn else self.valtype(value)
544530
break
545531

546532
self.settings[self.key] = json.dumps(vals)
@@ -553,8 +539,30 @@ def get_value(self):
553539
continue
554540
for key, val in obj.items():
555541
if key == self.zone:
556-
return int(val)
557-
return 0 # prevent warnings if key is reset
542+
return int(val) if self.isSpinBtn else self.valtype(val)
543+
if self.isSpinBtn: return 0 # prevent warnings if key is reset
544+
545+
class PanelJSONSpinButton(PanelJSONHelper, SpinButton, PanelWidgetBackend):
546+
def __init__(self, label, schema, key, panel_id, zone, *args, **kwargs):
547+
self.panel_id = panel_id
548+
self.zone = zone
549+
super(PanelJSONSpinButton, self).__init__(True, label, *args, **kwargs)
550+
551+
self.connect_to_settings(schema, key)
552+
553+
def get_range(self):
554+
return
555+
556+
# We use integer directly here because that is all the panel currently uses.
557+
# If that changes in the future, we will need to fix this.
558+
def stringify(self, value):
559+
return str(int(value))
560+
561+
def unstringify(self, value):
562+
return int(value)
563+
564+
def on_setting_changed(self, *args):
565+
self.content_widget.set_value(self.get_value())
558566

559567
class PanelComboBox(ComboBox, PanelWidgetBackend):
560568
def __init__(self, label, schema, key, panel_id, *args, **kwargs):
@@ -569,11 +577,11 @@ def stringify(self, value):
569577
def unstringify(self, value):
570578
return value
571579

572-
class PanelJSONComboBox(ComboBox, PanelWidgetBackend):
580+
class PanelJSONComboBox(PanelJSONHelper, ComboBox, PanelWidgetBackend):
573581
def __init__(self, label, schema, key, panel_id, zone, *args, **kwargs):
574582
self.panel_id = panel_id
575583
self.zone = zone
576-
super(PanelJSONComboBox, self).__init__(label, *args, **kwargs)
584+
super(PanelJSONComboBox, self).__init__(False, label, *args, **kwargs)
577585

578586
self.connect_to_settings(schema, key)
579587

@@ -583,28 +591,6 @@ def stringify(self, value):
583591
def unstringify(self, value):
584592
return value
585593

586-
def set_value(self, value):
587-
vals = json.loads(self.settings[self.key])
588-
for obj in vals:
589-
if obj['panelId'] != int(self.panel_id):
590-
continue
591-
for key, val in obj.items():
592-
if key == self.zone:
593-
obj[key] = self.valtype(value)
594-
break
595-
596-
self.settings[self.key] = json.dumps(vals)
597-
598-
def get_value(self):
599-
vals = self.settings[self.key]
600-
vals = json.loads(vals)
601-
for obj in vals:
602-
if obj['panelId'] != int(self.panel_id):
603-
continue
604-
for key, val in obj.items():
605-
if key == self.zone:
606-
return self.valtype(val)
607-
608594
class PanelRange(Range, PanelWidgetBackend):
609595
def __init__(self, label, schema, key, panel_id, *args, **kwargs):
610596
self.panel_id = panel_id

0 commit comments

Comments
 (0)