From 1126546cbde26b977978c7f39926c6eeb4c67532 Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 25 Mar 2021 17:28:26 +0100 Subject: [PATCH 01/12] optional window icon --- nwg_panel/main.py | 2 +- nwg_panel/modules/sway_workspaces.py | 66 ++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 10 deletions(-) diff --git a/nwg_panel/main.py b/nwg_panel/main.py index 5865b9e2..4edbe15d 100644 --- a/nwg_panel/main.py +++ b/nwg_panel/main.py @@ -127,7 +127,7 @@ 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) + workspaces = SwayWorkspaces(panel["sway-workspaces"], common.i3, icons_path=icons_path) container.pack_start(workspaces, False, False, panel["items-padding"]) common.workspaces_list.append(workspaces) else: diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index ef006a4d..bfa0ea0e 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -2,27 +2,32 @@ import threading -from gi.repository import Gtk +from gi.repository import Gtk, GdkPixbuf import nwg_panel.common -from nwg_panel.tools import check_key +from nwg_panel.tools import check_key, get_icon, update_image class SwayWorkspaces(Gtk.Box): - def __init__(self, settings, i3): + def __init__(self, settings, i3, icons_path): Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0) self.settings = settings self.i3 = i3 self.ws_num2box = {} self.name_label = Gtk.Label("") + self.win_id = "" + self.icon = Gtk.Image() + self.icons_path = icons_path self.build_box() def build_box(self): check_key(self.settings, "numbers", [1, 2, 3, 4, 5, 6, 7, 8]) + check_key(self.settings, "show-icon", True) + check_key(self.settings, "image-size", 16) check_key(self.settings, "show-name", True) check_key(self.settings, "name-length", 40) - ws_num, win_name = self.find_focused() + ws_num, win_name, win_id = self.find_focused() for num in self.settings["numbers"]: eb = Gtk.EventBox() @@ -44,10 +49,18 @@ def build_box(self): else: eb.set_property("name", "task-box") - if self.settings["show-name"]: - self.pack_start(self.name_label, False, False, 6) + self.pack_start(self.icon, False, False, 6) + + if self.settings["show-icon"]: + if not self.icon.get_visible(): + self.icon.show() + self.update_icon(win_id, win_name) + else: + if self.icon.get_visible(): + self.icon.hide() - self.show_all() + if self.settings["show-name"]: + self.pack_start(self.name_label, False, False, 0) def on_click(self, w, e, num): nwg_panel.common.i3.command("workspace number {}".format(num)) @@ -59,7 +72,7 @@ def on_leave_notify_event(self, widget, event): widget.get_style_context().set_state(Gtk.StateFlags.NORMAL) def highlight_active(self): - ws_num, win_name = self.find_focused() + ws_num, win_name, win_id = self.find_focused() if ws_num > 0: for num in self.settings["numbers"]: if num == str(ws_num): @@ -67,8 +80,32 @@ def highlight_active(self): else: self.ws_num2box[num].set_property("name", "task-box") + if self.settings["show-icon"]: + self.update_icon(win_id, win_name) + self.name_label.set_text(win_name) + def update_icon(self, win_id, win_name): + if win_id and win_name: + icon_from_desktop = get_icon(win_id) + if icon_from_desktop: + if "/" not in icon_from_desktop and not icon_from_desktop.endswith( + ".svg") and not icon_from_desktop.endswith(".png"): + update_image(self.icon, icon_from_desktop, self.settings["image-size"], self.icons_path) + else: + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_from_desktop, self.settings["image-size"], + self.settings["image-size"]) + self.icon.set_from_pixbuf(pixbuf) + else: + image = Gtk.Image() + update_image(image, win_id, self.settings["image-size"], self.icons_path) + + if not self.icon.get_visible(): + self.icon.show() + else: + if self.icon.get_visible(): + self.icon.hide() + def refresh(self): thread = threading.Thread(target=self.highlight_active) thread.daemon = True @@ -80,6 +117,7 @@ def find_focused(self): workspaces = self.i3.get_workspaces() ws_num = -1 win_name = "" + win_id = "" # app_id if available, else window_class for ws in workspaces: if ws.focused: @@ -89,6 +127,11 @@ def find_focused(self): f = self.i3.get_tree().find_focused() if f.type == "con" and f.name and str(f.parent.workspace().num) in self.settings["numbers"]: win_name = f.name[:self.settings["name-length"]] + + if f.app_id: + win_id = f.app_id + elif f.window_class: + win_id = f.window_class for item in tree.descendants(): if item.type == "workspace": @@ -96,4 +139,9 @@ def find_focused(self): if str(node.workspace().num) in self.settings["numbers"] and node.focused: win_name = node.name - return ws_num, win_name + if node.app_id: + win_id = node.app_id + elif node.window_class: + win_id = node.window_class + + return ws_num, win_name, win_id From 412cf63b6a5e8525d09a7e2beb63aa2a8af9a107 Mon Sep 17 00:00:00 2001 From: piotr Date: Thu, 25 Mar 2021 23:32:05 +0100 Subject: [PATCH 02/12] add icon related fields --- nwg_panel/glade/config_sway_workspaces.glade | 49 +++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/nwg_panel/glade/config_sway_workspaces.glade b/nwg_panel/glade/config_sway_workspaces.glade index 5eb2c633..e008b280 100644 --- a/nwg_panel/glade/config_sway_workspaces.glade +++ b/nwg_panel/glade/config_sway_workspaces.glade @@ -2,7 +2,7 @@ - + True False @@ -57,6 +57,32 @@ of workspaces to show 2 + + + Show window name + True + True + False + True + + + 1 + 2 + + + + + Show focused window icon + True + True + False + True + + + 0 + 2 + + True @@ -66,7 +92,7 @@ of workspaces to show 0 - 3 + 4 @@ -76,20 +102,29 @@ of workspaces to show 1 + 4 + + + + + True + False + start + Icon size + + + 0 3 - - Show focused window + True True - False - True 1 - 2 + 3 From ce90e720143142e14bf1c95a634f0a12c6a42ed0 Mon Sep 17 00:00:00 2001 From: piotr Date: Fri, 26 Mar 2021 00:35:54 +0100 Subject: [PATCH 03/12] fixes to the window icon --- nwg_panel/modules/sway_workspaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index bfa0ea0e..a86a0206 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -123,7 +123,7 @@ def find_focused(self): if ws.focused: ws_num = ws.num - if self.settings["show-name"]: + if self.settings["show-name"] or self.settings["show-icon"]: f = self.i3.get_tree().find_focused() if f.type == "con" and f.name and str(f.parent.workspace().num) in self.settings["numbers"]: win_name = f.name[:self.settings["name-length"]] From e5fbfa201ce89e70d091de589f773cee06cd476a Mon Sep 17 00:00:00 2001 From: piotr Date: Fri, 26 Mar 2021 00:57:28 +0100 Subject: [PATCH 04/12] Workspaces: add window icon #42 --- nwg_panel/config.py | 19 +++++++++++++++++++ nwg_panel/glade/config_sway_workspaces.glade | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/nwg_panel/config.py b/nwg_panel/config.py index af3fb5ef..9e636235 100644 --- a/nwg_panel/config.py +++ b/nwg_panel/config.py @@ -69,6 +69,8 @@ }, "sway-workspaces": { "numbers": ["1", "2", "3", "4", "5", "6", "7", "8"], + "show-icon": True, + "image-size": 16, "show-name": True, "name-length": 40 }, @@ -1029,6 +1031,8 @@ def edit_sway_workspaces(self, *args): settings = self.panel["sway-workspaces"] defaults = { "numbers": [1, 2, 3, 4, 5, 6, 7, 8], + "show-icon": True, + "image-size": 16, "show-name": True, "name-length": 40 } @@ -1046,9 +1050,18 @@ def edit_sway_workspaces(self, *args): self.eb_workspaces_menu.set_text(text.strip()) self.eb_workspaces_menu.connect("changed", validate_workspaces) + self.ws_show_icon = builder.get_object("show-icon") + self.ws_show_icon.set_active(settings["show-icon"]) + self.ws_show_name = builder.get_object("show-name") self.ws_show_name.set_active(settings["show-name"]) + 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) + self.ws_image_size.configure(adj, 1, 0) + self.ws_image_size.set_value(settings["image-size"]) + self.ws_name_length = builder.get_object("name-length") self.ws_name_length.set_numeric(True) adj = Gtk.Adjustment(value=0, lower=1, upper=256, step_increment=1, page_increment=10, page_size=1) @@ -1066,10 +1079,16 @@ def update_sway_workspaces(self): if val: settings["numbers"] = val.split() + val = self.ws_show_icon.get_active() + if val is not None: + settings["show-icon"] = val + val = self.ws_show_name.get_active() if val is not None: settings["show-name"] = val + settings["image-size"] = int(self.ws_image_size.get_value()) + settings["name-length"] = int(self.ws_name_length.get_value()) save_json(self.config, self.file) diff --git a/nwg_panel/glade/config_sway_workspaces.glade b/nwg_panel/glade/config_sway_workspaces.glade index e008b280..cc0224ff 100644 --- a/nwg_panel/glade/config_sway_workspaces.glade +++ b/nwg_panel/glade/config_sway_workspaces.glade @@ -118,7 +118,7 @@ of workspaces to show - + True True From f5a1f6878722b9baef39b409a8e7d78dabb58025 Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Fri, 26 Mar 2021 13:58:25 +0100 Subject: [PATCH 05/12] remove unnecessary threading --- nwg_panel/modules/sway_workspaces.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index a86a0206..56cf7ef4 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -import threading - from gi.repository import Gtk, GdkPixbuf import nwg_panel.common @@ -49,15 +47,8 @@ def build_box(self): else: eb.set_property("name", "task-box") - self.pack_start(self.icon, False, False, 6) - if self.settings["show-icon"]: - if not self.icon.get_visible(): - self.icon.show() - self.update_icon(win_id, win_name) - else: - if self.icon.get_visible(): - self.icon.hide() + self.pack_start(self.icon, False, False, 6) if self.settings["show-name"]: self.pack_start(self.name_label, False, False, 0) @@ -71,7 +62,7 @@ def on_enter_notify_event(self, widget, event): def on_leave_notify_event(self, widget, event): widget.get_style_context().set_state(Gtk.StateFlags.NORMAL) - def highlight_active(self): + def refresh(self): ws_num, win_name, win_id = self.find_focused() if ws_num > 0: for num in self.settings["numbers"]: @@ -105,12 +96,6 @@ def update_icon(self, win_id, win_name): else: if self.icon.get_visible(): self.icon.hide() - - def refresh(self): - thread = threading.Thread(target=self.highlight_active) - thread.daemon = True - thread.start() - return True def find_focused(self): tree = self.i3.get_tree() @@ -122,6 +107,7 @@ def find_focused(self): for ws in workspaces: if ws.focused: ws_num = ws.num + break if self.settings["show-name"] or self.settings["show-icon"]: f = self.i3.get_tree().find_focused() From 87f9c29ee3d6b25c198c4c8fd690676467500b98 Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Fri, 26 Mar 2021 14:27:07 +0100 Subject: [PATCH 06/12] avoid unnecessary refreshes --- nwg_panel/modules/sway_workspaces.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index 56cf7ef4..ae8d215b 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -71,10 +71,12 @@ def refresh(self): else: self.ws_num2box[num].set_property("name", "task-box") - if self.settings["show-icon"]: + if self.settings["show-icon"] and win_id != self.win_id: self.update_icon(win_id, win_name) + self.win_id = win_id - self.name_label.set_text(win_name) + if self.settings["show-name"]: + self.name_label.set_text(win_name) def update_icon(self, win_id, win_name): if win_id and win_name: From 5248d0d4b090a0d47e4de999e2da05fce25c3d36 Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Fri, 26 Mar 2021 14:34:01 +0100 Subject: [PATCH 07/12] reorder for better readability --- nwg_panel/modules/sway_workspaces.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index ae8d215b..f6f80d0f 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -52,15 +52,6 @@ def build_box(self): if self.settings["show-name"]: self.pack_start(self.name_label, False, False, 0) - - def on_click(self, w, e, num): - nwg_panel.common.i3.command("workspace number {}".format(num)) - - def on_enter_notify_event(self, widget, event): - widget.get_style_context().set_state(Gtk.StateFlags.SELECTED) - - def on_leave_notify_event(self, widget, event): - widget.get_style_context().set_state(Gtk.StateFlags.NORMAL) def refresh(self): ws_num, win_name, win_id = self.find_focused() @@ -133,3 +124,12 @@ def find_focused(self): win_id = node.window_class return ws_num, win_name, win_id + + def on_click(self, w, e, num): + nwg_panel.common.i3.command("workspace number {}".format(num)) + + def on_enter_notify_event(self, widget, event): + widget.get_style_context().set_state(Gtk.StateFlags.SELECTED) + + def on_leave_notify_event(self, widget, event): + widget.get_style_context().set_state(Gtk.StateFlags.NORMAL) \ No newline at end of file From 1b9f9be14326e427f89378e9707624daa74f9b35 Mon Sep 17 00:00:00 2001 From: Piotr Miller Date: Fri, 26 Mar 2021 15:29:50 +0100 Subject: [PATCH 08/12] Cancel window close if re-entered in less than 1 second --- nwg_panel/modules/controls.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/nwg_panel/modules/controls.py b/nwg_panel/modules/controls.py index 65cc1e78..ec3a598c 100644 --- a/nwg_panel/modules/controls.py +++ b/nwg_panel/modules/controls.py @@ -274,7 +274,9 @@ def __init__(self, parent, position, alignment, settings, width, monitor=None, i self.bri_scale = None self.vol_scale = None - self.connect("show", self.refresh) + self.src_tag = 0 + + self.connect("show", self.on_window_show) check_key(settings, "output-switcher", False) self.sinks = [] @@ -285,6 +287,8 @@ def __init__(self, parent, position, alignment, settings, width, monitor=None, i eb.set_above_child(False) if settings["leave-closes"]: self.connect("leave_notify_event", self.on_window_exit) + self.connect("enter_notify_event", self.on_window_enter) + outer_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) eb.add(outer_vbox) @@ -523,7 +527,16 @@ def __init__(self, parent, position, alignment, settings, width, monitor=None, i Gdk.threads_add_timeout(GLib.PRIORITY_LOW, 500, self.refresh) def on_window_exit(self, w, e): - self.hide() + self.src_tag = GLib.timeout_add_seconds(1, self.hide) + + def on_window_enter(self, *args): + if self.src_tag > 0: + GLib.Source.remove(self.src_tag) + self.src_tag = 0 + + def on_window_show(self, *args): + self.src_tag = 0 + self.refresh def switch_menu_box(self, widget, event): if self.menu_box.get_visible(): From 445e9643ea47048f677c32cf768aaf0ee1b22d6b Mon Sep 17 00:00:00 2001 From: piotr Date: Sat, 27 Mar 2021 02:32:20 +0100 Subject: [PATCH 09/12] mark autotiling, mark non-empty --- nwg_panel/modules/controls.py | 1 - nwg_panel/modules/sway_workspaces.py | 53 ++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/nwg_panel/modules/controls.py b/nwg_panel/modules/controls.py index ec3a598c..e190d52f 100644 --- a/nwg_panel/modules/controls.py +++ b/nwg_panel/modules/controls.py @@ -288,7 +288,6 @@ def __init__(self, parent, position, alignment, settings, width, monitor=None, i if settings["leave-closes"]: self.connect("leave_notify_event", self.on_window_exit) self.connect("enter_notify_event", self.on_window_enter) - outer_vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) eb.add(outer_vbox) diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index f6f80d0f..18b8fc98 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -3,7 +3,7 @@ from gi.repository import Gtk, GdkPixbuf import nwg_panel.common -from nwg_panel.tools import check_key, get_icon, update_image +from nwg_panel.tools import check_key, get_icon, update_image,load_autotiling class SwayWorkspaces(Gtk.Box): @@ -12,10 +12,12 @@ def __init__(self, settings, i3, icons_path): self.settings = settings self.i3 = i3 self.ws_num2box = {} + self.ws_num2lbl = {} self.name_label = Gtk.Label("") self.win_id = "" self.icon = Gtk.Image() self.icons_path = icons_path + self.autotiling = load_autotiling() self.build_box() def build_box(self): @@ -24,8 +26,10 @@ def build_box(self): check_key(self.settings, "image-size", 16) check_key(self.settings, "show-name", True) check_key(self.settings, "name-length", 40) + check_key(self.settings, "mark-autotiling", True) + check_key(self.settings, "mark-content", True) - ws_num, win_name, win_id = self.find_focused() + ws_num, win_name, win_id, non_empty = self.find_details() for num in self.settings["numbers"]: eb = Gtk.EventBox() @@ -37,8 +41,18 @@ def build_box(self): box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=0) eb.add(box) - lbl = Gtk.Label(str(num)) + if self.settings["mark-autotiling"]: + try: + at = int(num) in self.autotiling + except: + at = False + autotiling = "a" if at in self.autotiling else "" + lbl = Gtk.Label("{}{}".format(autotiling, str(num))) + else: + lbl = Gtk.Label("{}".format(str(num))) + self.ws_num2box[num] = eb + self.ws_num2lbl[num] = lbl box.pack_start(lbl, False, False, 6) @@ -54,9 +68,26 @@ def build_box(self): self.pack_start(self.name_label, False, False, 0) def refresh(self): - ws_num, win_name, win_id = self.find_focused() + ws_num, win_name, win_id, non_empty = self.find_details() if ws_num > 0: for num in self.settings["numbers"]: + # mark non-empty WS with a dot + if self.settings["mark-content"]: + try: + int_num = int(num) + except: + int_num = 0 + lbl = self.ws_num2lbl[num] + text = lbl.get_text() + if int_num in non_empty: + if not text.endswith("."): + text += "." + lbl.set_text(text) + else: + if text.endswith("."): + text = text[0:-1] + lbl.set_text(text) + if num == str(ws_num): self.ws_num2box[num].set_property("name", "task-box-focused") else: @@ -90,7 +121,7 @@ def update_icon(self, win_id, win_name): if self.icon.get_visible(): self.icon.hide() - def find_focused(self): + def find_details(self): tree = self.i3.get_tree() workspaces = self.i3.get_workspaces() ws_num = -1 @@ -103,6 +134,7 @@ def find_focused(self): break if self.settings["show-name"] or self.settings["show-icon"]: + non_empty = [] f = self.i3.get_tree().find_focused() if f.type == "con" and f.name and str(f.parent.workspace().num) in self.settings["numbers"]: win_name = f.name[:self.settings["name-length"]] @@ -114,6 +146,15 @@ def find_focused(self): for item in tree.descendants(): if item.type == "workspace": + # find non-empty workspaces + if self.settings["mark-content"]: + tasks_num = 0 + for d in item.descendants(): + if d.type == "con" and d.name: + tasks_num += 1 + if tasks_num > 0: + non_empty.append(item.num) + for node in item.floating_nodes: if str(node.workspace().num) in self.settings["numbers"] and node.focused: win_name = node.name @@ -123,7 +164,7 @@ def find_focused(self): elif node.window_class: win_id = node.window_class - return ws_num, win_name, win_id + return ws_num, win_name, win_id, non_empty def on_click(self, w, e, num): nwg_panel.common.i3.command("workspace number {}".format(num)) From 4a3ed4c370b03c38de97914cbeb213e6e6ddc3bb Mon Sep 17 00:00:00 2001 From: piotr Date: Sat, 27 Mar 2021 02:44:33 +0100 Subject: [PATCH 10/12] mark autotiling, mark non-empty --- nwg_panel/config.py | 22 ++++++++++++-- nwg_panel/glade/config_sway_workspaces.glade | 31 +++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/nwg_panel/config.py b/nwg_panel/config.py index 9e636235..7540bf5d 100644 --- a/nwg_panel/config.py +++ b/nwg_panel/config.py @@ -72,7 +72,9 @@ "show-icon": True, "image-size": 16, "show-name": True, - "name-length": 40 + "name-length": 40, + "mark-autotiling": True, + "mark-content": True }, "clock": { "format": "%a, %d. %b %H:%M:%S", @@ -1034,7 +1036,9 @@ def edit_sway_workspaces(self, *args): "show-icon": True, "image-size": 16, "show-name": True, - "name-length": 40 + "name-length": 40, + "mark-autotiling": True, + "mark-content": True } for key in defaults: check_key(settings, key, defaults[key]) @@ -1068,6 +1072,12 @@ def edit_sway_workspaces(self, *args): self.ws_name_length.configure(adj, 1, 0) self.ws_name_length.set_value(settings["name-length"]) + self.ws_mark_autotiling = builder.get_object("mark-autotiling") + self.ws_mark_autotiling.set_active(settings["mark-autotiling"]) + + self.ws_mark_content = builder.get_object("mark-content") + self.ws_mark_content.set_active(settings["mark-content"]) + for item in self.scrolled_window.get_children(): item.destroy() self.scrolled_window.add(grid) @@ -1091,6 +1101,14 @@ def update_sway_workspaces(self): settings["name-length"] = int(self.ws_name_length.get_value()) + val = self.ws_mark_autotiling.get_active() + if val is not None: + settings["mark-autotiling"] = val + + val = self.ws_mark_content.get_active() + if val is not None: + settings["mark-content"] = val + save_json(self.config, self.file) def edit_scratchpad(self, *args): diff --git a/nwg_panel/glade/config_sway_workspaces.glade b/nwg_panel/glade/config_sway_workspaces.glade index cc0224ff..26bd166d 100644 --- a/nwg_panel/glade/config_sway_workspaces.glade +++ b/nwg_panel/glade/config_sway_workspaces.glade @@ -2,7 +2,7 @@ - + True False @@ -127,6 +127,35 @@ of workspaces to show 3 + + + Mark non-empty WS + True + True + False + True + + + 0 + 5 + + + + + Mark-autotiling + True + True + False + True + + + 1 + 5 + + + + + From 9e92aa98d7fbae79d6b10228e12f1b48ce9ed2ef Mon Sep 17 00:00:00 2001 From: piotr Date: Sat, 27 Mar 2021 03:47:00 +0100 Subject: [PATCH 11/12] show layout --- nwg_panel/modules/sway_workspaces.py | 36 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index 18b8fc98..e00edd93 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -16,6 +16,7 @@ def __init__(self, settings, i3, icons_path): self.name_label = Gtk.Label("") self.win_id = "" self.icon = Gtk.Image() + self.layout_icon = Gtk.Image() self.icons_path = icons_path self.autotiling = load_autotiling() self.build_box() @@ -28,8 +29,9 @@ def build_box(self): check_key(self.settings, "name-length", 40) check_key(self.settings, "mark-autotiling", True) check_key(self.settings, "mark-content", True) + check_key(self.settings, "show-layout", True) - ws_num, win_name, win_id, non_empty = self.find_details() + ws_num, win_name, win_id, non_empty, win_layout = self.find_details() for num in self.settings["numbers"]: eb = Gtk.EventBox() @@ -66,9 +68,12 @@ def build_box(self): if self.settings["show-name"]: self.pack_start(self.name_label, False, False, 0) + + if self.settings["show-layout"]: + self.pack_start(self.layout_icon, False, False, 6) def refresh(self): - ws_num, win_name, win_id, non_empty = self.find_details() + ws_num, win_name, win_id, non_empty, win_layout = self.find_details() if ws_num > 0: for num in self.settings["numbers"]: # mark non-empty WS with a dot @@ -99,6 +104,25 @@ def refresh(self): if self.settings["show-name"]: self.name_label.set_text(win_name) + + if self.settings["show-layout"]: + if win_name: + if win_layout == "splith": + update_image(self.layout_icon, "go-next-symbolic", self.settings["image-size"], self.icons_path) + elif win_layout == "splitv": + update_image(self.layout_icon, "go-down-symbolic", self.settings["image-size"], self.icons_path) + elif win_layout == "tabbed": + update_image(self.layout_icon, "view-dual-symbolic", self.settings["image-size"], self.icons_path) + elif win_layout == "stacked": + update_image(self.layout_icon, "view-paged-symbolic", self.settings["image-size"], self.icons_path) + else: + update_image(self.layout_icon, "window-new-symbolic", self.settings["image-size"], self.icons_path) + + if not self.layout_icon.get_visible(): + self.layout_icon.show() + else: + if self.layout_icon.get_visible(): + self.layout_icon.hide() def update_icon(self, win_id, win_name): if win_id and win_name: @@ -127,14 +151,15 @@ def find_details(self): ws_num = -1 win_name = "" win_id = "" # app_id if available, else window_class + layout = None for ws in workspaces: if ws.focused: ws_num = ws.num break + non_empty = [] if self.settings["show-name"] or self.settings["show-icon"]: - non_empty = [] f = self.i3.get_tree().find_focused() if f.type == "con" and f.name and str(f.parent.workspace().num) in self.settings["numbers"]: win_name = f.name[:self.settings["name-length"]] @@ -163,8 +188,11 @@ def find_details(self): win_id = node.app_id elif node.window_class: win_id = node.window_class + layout = node.parent.layout - return ws_num, win_name, win_id, non_empty + if not layout: + layout = f.parent.layout + return ws_num, win_name, win_id, non_empty, layout def on_click(self, w, e, num): nwg_panel.common.i3.command("workspace number {}".format(num)) From efbb9660081c4e3a527cfe279abe99e4b0b25b6a Mon Sep 17 00:00:00 2001 From: piotr Date: Sat, 27 Mar 2021 04:11:40 +0100 Subject: [PATCH 12/12] show parent layout --- nwg_panel/config.py | 13 ++++++++++-- nwg_panel/glade/config_sway_workspaces.glade | 21 +++++++++++++++++++- nwg_panel/modules/sway_workspaces.py | 6 ++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/nwg_panel/config.py b/nwg_panel/config.py index 7540bf5d..217d8123 100644 --- a/nwg_panel/config.py +++ b/nwg_panel/config.py @@ -74,7 +74,8 @@ "show-name": True, "name-length": 40, "mark-autotiling": True, - "mark-content": True + "mark-content": True, + "show-layout": True }, "clock": { "format": "%a, %d. %b %H:%M:%S", @@ -1038,7 +1039,8 @@ def edit_sway_workspaces(self, *args): "show-name": True, "name-length": 40, "mark-autotiling": True, - "mark-content": True + "mark-content": True, + "show-layout": True } for key in defaults: check_key(settings, key, defaults[key]) @@ -1078,6 +1080,9 @@ def edit_sway_workspaces(self, *args): self.ws_mark_content = builder.get_object("mark-content") self.ws_mark_content.set_active(settings["mark-content"]) + self.ws_show_layout = builder.get_object("show-layout") + self.ws_show_layout.set_active(settings["show-layout"]) + for item in self.scrolled_window.get_children(): item.destroy() self.scrolled_window.add(grid) @@ -1109,6 +1114,10 @@ def update_sway_workspaces(self): if val is not None: settings["mark-content"] = val + val = self.ws_show_layout.get_active() + if val is not None: + settings["show-layout"] = val + save_json(self.config, self.file) def edit_scratchpad(self, *args): diff --git a/nwg_panel/glade/config_sway_workspaces.glade b/nwg_panel/glade/config_sway_workspaces.glade index 26bd166d..7f87498f 100644 --- a/nwg_panel/glade/config_sway_workspaces.glade +++ b/nwg_panel/glade/config_sway_workspaces.glade @@ -2,7 +2,7 @@ - + True False @@ -153,6 +153,25 @@ of workspaces to show 5 + + + Show layout + True + True + False + True + + + 0 + 6 + + + + + + + + diff --git a/nwg_panel/modules/sway_workspaces.py b/nwg_panel/modules/sway_workspaces.py index e00edd93..231fef30 100644 --- a/nwg_panel/modules/sway_workspaces.py +++ b/nwg_panel/modules/sway_workspaces.py @@ -15,6 +15,7 @@ def __init__(self, settings, i3, icons_path): self.ws_num2lbl = {} self.name_label = Gtk.Label("") self.win_id = "" + self.win_pid = None self.icon = Gtk.Image() self.layout_icon = Gtk.Image() self.icons_path = icons_path @@ -151,6 +152,7 @@ def find_details(self): ws_num = -1 win_name = "" win_id = "" # app_id if available, else window_class + win_pid = None layout = None for ws in workspaces: @@ -169,6 +171,8 @@ def find_details(self): elif f.window_class: win_id = f.window_class + win_pid = f.pid + for item in tree.descendants(): if item.type == "workspace": # find non-empty workspaces @@ -189,9 +193,11 @@ def find_details(self): elif node.window_class: win_id = node.window_class layout = node.parent.layout + win_pid = node.pid if not layout: layout = f.parent.layout + return ws_num, win_name, win_id, non_empty, layout def on_click(self, w, e, num):