Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sway workspaces #191

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
38 changes: 35 additions & 3 deletions nwg_panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,9 @@ def edit_sway_workspaces(self, *args):
"mark-autotiling": True,
"mark-content": True,
"show-layout": True,
"angle": 0.0
"angle": 0.0,
"hide-empty": False,
"hide-other-outputs": False,
}
for key in defaults:
check_key(settings, key, defaults[key])
Expand Down Expand Up @@ -1796,6 +1798,14 @@ def edit_sway_workspaces(self, *args):
self.ws_show_name.set_label(voc["show-window-name"])
self.ws_show_name.set_active(settings["show-name"])

self.ws_hide_empty = builder.get_object("hide-empty")
self.ws_hide_empty.set_label(voc["hide-empty"])
self.ws_hide_empty.set_active(settings["hide-empty"])

self.ws_hide_other_outputs = builder.get_object("hide-other-outputs")
self.ws_hide_other_outputs.set_label(voc["hide-other-outputs"])
self.ws_hide_other_outputs.set_active(settings["hide-other-outputs"])

self.ws_image_size = builder.get_object("image-size")
self.ws_image_size.set_numeric(True)
adj = Gtk.Adjustment(value=0, lower=8, upper=129, step_increment=1, page_increment=10, page_size=1)
Expand Down Expand Up @@ -1832,8 +1842,11 @@ def update_sway_workspaces(self):
settings = self.panel["sway-workspaces"]

val = self.eb_workspaces_menu.get_text()
if val:
if val is not None:
print('numbers', repr(settings["numbers"]), repr(val.split()))
settings["numbers"] = val.split()
print('numbers', repr(settings["numbers"]), repr(val.split()))


val = self.ws_custom_labels.get_text()
settings["custom-labels"] = val.split()
Expand All @@ -1849,6 +1862,14 @@ def update_sway_workspaces(self):
if val is not None:
settings["show-name"] = val

val = self.ws_hide_other_outputs.get_active()
if val is not None:
settings["hide-other-outputs"] = val

val = self.ws_hide_empty.get_active()
if val is not None:
settings["hide-empty"] = val

settings["image-size"] = int(self.ws_image_size.get_value())

settings["name-length"] = int(self.ws_name_length.get_value())
Expand Down Expand Up @@ -2598,7 +2619,9 @@ def edit_executor(self, item, name, new=False):
"interval": 1,
"angle": 0.0,
"sigrt": signal.SIGRTMIN,
"use-sigrt": False
"use-sigrt": False,
"icon": "view-refresh-symbolic",
"continuous": False
}
for key in defaults:
check_key(settings, key, defaults[key])
Expand Down Expand Up @@ -2660,6 +2683,9 @@ def edit_executor(self, item, name, new=False):
self.executor_icon_placement = builder.get_object("icon-placement")
self.executor_icon_placement.set_active_id(settings["icon-placement"])

self.executor_icon = builder.get_object("icon")
self.executor_icon.set_text(settings["icon"])

self.executor_icon_size = builder.get_object("icon-size")
self.executor_icon_size.set_numeric(True)
adj = Gtk.Adjustment(value=0, lower=8, upper=128, step_increment=1, page_increment=10, page_size=1)
Expand Down Expand Up @@ -2689,6 +2715,10 @@ def edit_executor(self, item, name, new=False):
self.executor_use_sigrt.set_label(voc["use-signal"])
self.executor_use_sigrt.set_active(settings["use-sigrt"])

self.executor_continuous = builder.get_object("continuous")
self.executor_continuous.set_label(voc["continuous"])
self.executor_continuous.set_active(settings["continuous"])

self.executor_remove = builder.get_object("remove")
self.executor_remove.set_label(voc["remove-executor"])

Expand Down Expand Up @@ -2736,6 +2766,7 @@ def update_executor(self):
val = self.executor_icon_placement.get_active_id()
if val:
settings["icon-placement"] = val
settings["icon"] = self.executor_icon.get_text()
settings["icon-size"] = int(self.executor_icon_size.get_value())
settings["interval"] = int(self.executor_interval.get_value())

Expand All @@ -2746,6 +2777,7 @@ def update_executor(self):

settings["sigrt"] = int(self.executor_sigrt.get_value())
settings["use-sigrt"] = self.executor_use_sigrt.get_active()
settings["continuous"] = self.executor_continuous.get_active()

self.panel[config_key] = settings
else:
Expand Down
41 changes: 39 additions & 2 deletions nwg_panel/glade/config_executor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="continuous">
<property name="label" translatable="yes">continuous</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="draw-indicator">True</property>
<property name="tooltip-text" translatable="yes">Updates the executor each time the script puts two lines of text (icon or empty line and text)</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-script">
<property name="visible">True</property>
Expand Down Expand Up @@ -347,6 +361,29 @@ executor will create a new one.</property>
<property name="top-attach">11</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-icon">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Icon:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">16</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="icon">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="width-chars">22</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">16</property>
</packing>
</child>
<child>
<object class="GtkButton" id="save-to-database">
<property name="label" translatable="yes">Save to database</property>
Expand All @@ -356,7 +393,7 @@ executor will create a new one.</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">16</property>
<property name="top-attach">17</property>
</packing>
</child>
<child>
Expand All @@ -369,7 +406,7 @@ executor will create a new one.</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">16</property>
<property name="top-attach">17</property>
</packing>
</child>
<child>
Expand Down
27 changes: 26 additions & 1 deletion nwg_panel/glade/config_sway_workspaces.glade
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,32 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkCheckButton" id="hide-empty">
<property name="label" translatable="yes">Hide empty workspaces</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="halign">start</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="hide-other-outputs">
<property name="label" translatable="yes">Hide workspaces in other outputs</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="halign">start</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">10</property>
</packing>
</child>
<child>
<placeholder/>
Expand Down
3 changes: 3 additions & 0 deletions nwg_panel/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"command": "Command",
"common": "Common",
"common-panel-settings": "Common nwg-panel settings",
"continuous": "Continuous",
"controls": "Controls",
"controls-window-width-tooltip": "Controls window width in pixels; leave 0 for auto.",
"cover-size": "Cover size",
Expand Down Expand Up @@ -80,6 +81,8 @@
"gust": "gust",
"header-icon-size": "Header icon size",
"height": "Height",
"hide-empty": "Hide empty workspaces",
"hide-other-outputs": "Hide workspaces on other outputs",
"homogeneous": "Homogeneous",
"homogeneous-tooltip": "Sets equal columns width be default if 'Modules center' not empty.",
"horizontal-padding": "Horizontal padding",
Expand Down
16 changes: 12 additions & 4 deletions nwg_panel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,20 @@ def instantiate_content(panel, container, content_list, icons_path=""):

if item == "sway-workspaces":
if sway:
if "sway-workspaces" in panel:
workspaces = SwayWorkspaces(panel["sway-workspaces"], common.i3, icons_path=icons_path)
if "sway-workspaces" not in panel:
print("'sway-workspaces' not defined in this panel instance")
else:
output = None
if "output" in panel:
output = "{}".format(panel["output"])

workspaces = SwayWorkspaces(panel["sway-workspaces"], common.i3,
icons_path=icons_path,
output=output)

container.pack_start(workspaces, False, False, panel["items-padding"])
common.workspaces_list.append(workspaces)
else:
print("'sway-workspaces' not defined in this panel instance")

else:
print("'sway-workspaces' ignored")

Expand Down
43 changes: 39 additions & 4 deletions nwg_panel/modules/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import threading
import signal

from shlex import split

import gi
from gi.repository import GLib

Expand All @@ -26,9 +28,11 @@ def __init__(self, settings, icons_path, executor_name):
self.image = Gtk.Image()
self.label = Gtk.Label("")
self.icon_path = None
self.process = None

check_key(settings, "script", "")
check_key(settings, "interval", 0)
check_key(settings, "icon", "view-refresh-symbolic")
check_key(settings, "root-css-name", "root-executor")
check_key(settings, "css-name", "")
check_key(settings, "icon-placement", "left")
Expand All @@ -42,6 +46,7 @@ def __init__(self, settings, icons_path, executor_name):
check_key(settings, "angle", 0.0)
check_key(settings, "sigrt", signal.SIGRTMIN)
check_key(settings, "use-sigrt", False)
check_key(settings, "continuous", False)

self.label.set_angle(settings["angle"])

Expand All @@ -52,7 +57,10 @@ def __init__(self, settings, icons_path, executor_name):
if settings["angle"] != 0.0:
self.box.set_orientation(Gtk.Orientation.VERTICAL)

update_image(self.image, "view-refresh-symbolic", self.settings["icon-size"], self.icons_path)
if self.settings["icon"] is None or len(self.settings["icon"]) == 0:
self.image.hide()
else:
update_image(self.image, self.settings["icon"], self.settings["icon-size"], self.icons_path)

self.set_property("name", settings["root-css-name"])

Expand Down Expand Up @@ -83,6 +91,7 @@ def __init__(self, settings, icons_path, executor_name):
def update_widget(self, output):
if output:
if len(output) == 1:
print("output1 {}".format(output))
if output[0].endswith(".svg") or output[0].endswith(".png"):
new_path = output[0].strip()
if new_path != self.icon_path:
Expand Down Expand Up @@ -110,7 +119,10 @@ def update_widget(self, output):

elif len(output) == 2:
new_path = output[0].strip()
if "/" not in new_path and "." not in new_path: # name given instead of path
if new_path == "":
if self.image.get_visible():
self.image.hide()
elif "/" not in new_path and "." not in new_path: # name given instead of path
update_image(self.image, new_path, self.settings["icon-size"], self.icons_path)
self.icon_path = new_path
else:
Expand All @@ -137,9 +149,32 @@ def update_widget(self, output):

def get_output(self):
if "script" in self.settings and self.settings["script"]:
script = split(self.settings["script"])
continuous = self.settings["continuous"]
try:
output = subprocess.check_output(self.settings["script"].split()).decode("utf-8").splitlines()
GLib.idle_add(self.update_widget, output)
if not continuous:
subprocess.check_output(script)
output = subprocess.check_output(split(self.settings["script"])).decode("utf-8").splitlines()
GLib.idle_add(self.update_widget, output)
return

if self.process is not None and self.process.poll() is None:
# Last process has not yet finished
# Wait for it, possibly this is a continuous output
return

self.process = subprocess.Popen(script,
stdout = subprocess.PIPE)
first_line = None
while True:
line = self.process.stdout.readline().decode('utf-8')
if line is None or len(line) == 0: break

if first_line is None:
first_line = line
else:
GLib.idle_add(self.update_widget, [first_line, line])
first_line = None
except Exception as e:
print(e)

Expand Down
Loading