Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/org.cinnamon.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@
</description>
</key>

<key name="shared-panels" type="s">
<default>'[]'</default>
<summary>JSON string of shared panel information</summary>
<description>
Stores the panel ids that are being shared.
</description>
</key>

<key name="panels-autohide" type="as">
<default>['1:false']</default>
<summary>Auto-hide panel</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def set_object_value(self, info, value):
def check_settings(self, *args):
old_settings = self.settings
self.settings = self.get_settings()

if self.settings is None: return
for key in self.bindings:
new_value = self.settings[key]["value"]
if new_value != old_settings[key]["value"]:
Expand All @@ -147,10 +147,20 @@ def check_settings(self, *args):
for callback in callback_list:
callback(key, new_value)

for key in self.settings:
if ("value" in self.settings[key]
and self.settings[key]["value"] != old_settings[key]["value"]
and self.notify_callback
):
self.notify_callback(self, key, new_value)

def get_settings(self):
file = open(self.filepath)
raw_data = file.read()
file.close()
try:
file = open(self.filepath)
raw_data = file.read()
file.close()
except FileNotFoundError:
return
try:
settings = json.loads(raw_data, object_pairs_hook=collections.OrderedDict)
except:
Expand Down
22 changes: 18 additions & 4 deletions files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from PIL import Image
import datetime
import time
import json
except Exception as error_message:
print(error_message)
sys.exit(1)
Expand Down Expand Up @@ -856,19 +857,32 @@ def enable_extension(self, uuid, panel=1, box='right', position=0):
if self.collection_type == 'applet':
entries = []
applet_id = self.settings.get_int('next-applet-id')
self.settings.set_int('next-applet-id', (applet_id+1))
shared_panels = json.loads(self.settings.get_string('shared-panels'))

for entry in self.settings.get_strv(self.enabled_key):
info = entry.split(':')
pos = int(info[2])
if info[0] == f'panel{panel}' and info[1] == box and position <= pos:
info[2] = str(pos+1)
panelId = int(info[0][-1])
if (
(info[0] == f'panel{panel}' or panelId in shared_panels)
and info[1] == box
and position <= pos
):
new_pos = pos+1
info[2] = str(new_pos)
entries.append(':'.join(info))
else:
entries.append(entry)

entries.append(f'panel{panel}:{box}:{position}:{uuid}:{applet_id}')
if panel in shared_panels:
for panel in shared_panels:
entries.append(f'panel{panel}:{box}:{position}:{uuid}:{applet_id}')
applet_id += 1
else:
entries.append(f'panel{panel}:{box}:{position}:{uuid}:{applet_id}')
applet_id += 1

self.settings.set_int('next-applet-id', (applet_id))
self.settings.set_strv(self.enabled_key, entries)
elif self.collection_type == 'desklet':
desklet_id = self.settings.get_int('next-desklet-id')
Expand Down
32 changes: 16 additions & 16 deletions files/usr/share/cinnamon/cinnamon-settings/modules/cs_applets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from Spices import Spice_Harvester
from gi.repository import GLib, Gtk, Gdk
import config
import json

class Module:
name = "applets"
Expand Down Expand Up @@ -90,30 +91,29 @@ def __init__(self, parent, spices, window):

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

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

if self.current_panel_index - 1 >= 0:
self.current_panel_index -= 1
else:
self.current_panel_index = len(self.panels) - 1
self.panel_id = int(self.panels[self.current_panel_index].split(":")[0])
for _ in self.panels:
self.current_panel_index = (self.current_panel_index + step) % len(self.panels)
checked_panel_id = int(self.panels[self.current_panel_index].split(":")[0])
if checked_panel_id not in shared_panels or self.panel_id not in shared_panels:
self.panel_id = checked_panel_id
break

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

def next_panel(self, widget):
self.spices.send_proxy_signal('highlightPanel', '(ib)', self.panel_id, False)

if self.current_panel_index + 1 < len(self.panels):
self.current_panel_index += 1
else:
self.current_panel_index = 0
self.panel_id = int(self.panels[self.current_panel_index].split(":")[0])
def previous_panel(self, *args):
self.getNextPanel(False)

self.spices.send_proxy_signal('highlightPanel', '(ib)', self.panel_id, True)
def next_panel(self, widget):
self.getNextPanel()

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

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

if len(self.panels) > 1:
if len(self.panels) > 1 and len(self.panels) != len(shared_panels):
self.previous_button.show()
self.next_button.show()
# just in case, we'll make sure the current panel is highlighted
Expand Down
146 changes: 66 additions & 80 deletions files/usr/share/cinnamon/cinnamon-settings/modules/cs_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,46 +250,37 @@ def on_add_panel(self, widget):
if self.proxy:
self.proxy.addPanelQuery()

def on_previous_panel(self, widget):
def getNextPanel(self, positive_direction = True):
if self.panel_id and self.proxy:
self.proxy.highlightPanel('(ib)', int(self.panel_id), False)

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

if current - 1 >= 0:
self.current_panel = self.panels[current - 1]
self.panel_id = self.current_panel.panel_id
else:
self.current_panel = self.panels[len(self.panels) - 1]
self.panel_id = self.current_panel.panel_id
step = 1 if positive_direction else -1

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

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

self.config_stack.set_visible_child(self.current_panel)

def on_next_panel(self, widget):
if self.panel_id and self.proxy:
self.proxy.highlightPanel('(ib)', int(self.panel_id), False)

current = self.panels.index(self.current_panel)

if current + 1 < len(self.panels):
self.current_panel = self.panels[current + 1]
self.panel_id = self.current_panel.panel_id
else:
self.current_panel = self.panels[0]
self.panel_id = self.current_panel.panel_id
if int(self.panels[index].panel_id) not in shared_panels or int(self.panel_id) not in shared_panels:
self.current_panel = self.panels[index]
self.panel_id = self.current_panel.panel_id
break

self.config_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT)
self.config_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT if positive_direction
else Gtk.StackTransitionType.SLIDE_RIGHT)

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

self.config_stack.set_visible_child(self.current_panel)

def on_previous_panel(self, widget):
self.getNextPanel(False)

def on_next_panel(self, widget):
self.getNextPanel()

def id_or_monitor_position_used(self, kept_panels, monitor_layout, panel_id, monitor_id, position):
for keeper in kept_panels:
if keeper.panel_id == panel_id:
Expand Down Expand Up @@ -384,8 +375,10 @@ def on_panel_list_changed(self, *args):
self.next_button.show()
self.previous_button.show()

# Disable the panel switch buttons if there's only one panel
if len(self.panels) == 1:
# Disable the panel switch buttons if there's only one panel or if there is only shared panels
if len(self.panels) == 1 or (
len(self.panels) - len(json.loads(self.settings.get_string("shared-panels"))) == 0
):
self.next_button.set_sensitive(False)
self.previous_button.set_sensitive(False)
else:
Expand Down Expand Up @@ -438,11 +431,16 @@ def connect_to_settings(self, schema, key):
self.connect_widget_handlers()

def set_value(self, value):
shared_panels = json.loads(self.settings['shared-panels'])
vals = self.settings[self.key]
newvals = []
for val in vals:
if val.split(":")[0] == self.panel_id:
newvals.append(self.panel_id + ":" + self.stringify(value))
val_panel_id = val.split(":")[0]
if val_panel_id == self.panel_id or (
int(self.panel_id) in shared_panels
and int(val_panel_id) in shared_panels
):
newvals.append(val_panel_id + ":" + self.stringify(value))
else:
newvals.append(val)
self.settings[self.key] = newvals
Expand Down Expand Up @@ -511,36 +509,24 @@ def on_setting_changed(self, *args):
if value is not None and value != int(self.content_widget.get_value()):
self.content_widget.set_value(value)

class PanelJSONSpinButton(SpinButton, PanelWidgetBackend):
def __init__(self, label, schema, key, panel_id, zone, *args, **kwargs):
self.panel_id = panel_id
self.zone = zone
super(PanelJSONSpinButton, self).__init__(label, *args, **kwargs)

self.connect_to_settings(schema, key)

def get_range(self):
return

# We use integer directly here because that is all the panel currently uses.
# If that changes in the future, we will need to fix this.
def stringify(self, value):
return str(int(value))

def unstringify(self, value):
return int(value)

def on_setting_changed(self, *args):
self.content_widget.set_value(self.get_value())
class PanelJSONHelper:
def __init__(self, isSpinBtn, *args, **kwargs):
self.isSpinBtn = isSpinBtn
super().__init__(*args, **kwargs)

def set_value(self, value):
shared_panels = json.loads(self.settings['shared-panels'])
vals = json.loads(self.settings[self.key])
panel_id = int(self.panel_id)
for obj in vals:
if obj['panelId'] != int(self.panel_id):
if obj['panelId'] != panel_id and (
panel_id not in shared_panels
or obj['panelId'] not in shared_panels
):
continue
for key, val in obj.items():
if key == self.zone:
obj[key] = int(value)
obj[key] = int(value) if self.isSpinBtn else self.valtype(value)
break

self.settings[self.key] = json.dumps(vals)
Expand All @@ -553,8 +539,30 @@ def get_value(self):
continue
for key, val in obj.items():
if key == self.zone:
return int(val)
return 0 # prevent warnings if key is reset
return int(val) if self.isSpinBtn else self.valtype(val)
if self.isSpinBtn: return 0 # prevent warnings if key is reset

class PanelJSONSpinButton(PanelJSONHelper, SpinButton, PanelWidgetBackend):
def __init__(self, label, schema, key, panel_id, zone, *args, **kwargs):
self.panel_id = panel_id
self.zone = zone
super(PanelJSONSpinButton, self).__init__(True, label, *args, **kwargs)

self.connect_to_settings(schema, key)

def get_range(self):
return

# We use integer directly here because that is all the panel currently uses.
# If that changes in the future, we will need to fix this.
def stringify(self, value):
return str(int(value))

def unstringify(self, value):
return int(value)

def on_setting_changed(self, *args):
self.content_widget.set_value(self.get_value())

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

class PanelJSONComboBox(ComboBox, PanelWidgetBackend):
class PanelJSONComboBox(PanelJSONHelper, ComboBox, PanelWidgetBackend):
def __init__(self, label, schema, key, panel_id, zone, *args, **kwargs):
self.panel_id = panel_id
self.zone = zone
super(PanelJSONComboBox, self).__init__(label, *args, **kwargs)
super(PanelJSONComboBox, self).__init__(False, label, *args, **kwargs)

self.connect_to_settings(schema, key)

Expand All @@ -583,28 +591,6 @@ def stringify(self, value):
def unstringify(self, value):
return value

def set_value(self, value):
vals = json.loads(self.settings[self.key])
for obj in vals:
if obj['panelId'] != int(self.panel_id):
continue
for key, val in obj.items():
if key == self.zone:
obj[key] = self.valtype(value)
break

self.settings[self.key] = json.dumps(vals)

def get_value(self):
vals = self.settings[self.key]
vals = json.loads(vals)
for obj in vals:
if obj['panelId'] != int(self.panel_id):
continue
for key, val in obj.items():
if key == self.zone:
return self.valtype(val)

class PanelRange(Range, PanelWidgetBackend):
def __init__(self, label, schema, key, panel_id, *args, **kwargs):
self.panel_id = panel_id
Expand Down
Loading