Skip to content

Commit

Permalink
Merge pull request #51 from nwg-piotr/fix_ws
Browse files Browse the repository at this point in the history
Fix SwayWorkspaces, SwayTaskbar
  • Loading branch information
nwg-piotr authored Apr 15, 2021
2 parents bae8a65 + 49900f2 commit e64dc7a
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 58 deletions.
60 changes: 60 additions & 0 deletions nwg_panel/icons_dark/window-pop-out-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions nwg_panel/icons_light/window-pop-out-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions nwg_panel/modules/sway_taskbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def build_box(self):
if all_workspaces or desc.find_focused() is not None:
for con in desc.descendants():
if con.name or con.app_id:
win_box = WindowBox(con, self.settings, self.position, self.icons_path)
win_box = WindowBox(con, self.settings, self.position, self.icons_path, floating=con in desc.floating_nodes)
self.ws_box.pack_start(win_box, False, False, self.settings["task-padding"])
self.pack_start(self.ws_box, False, False, 0)
self.show_all()
Expand Down Expand Up @@ -97,7 +97,7 @@ def on_click(self, button):


class WindowBox(Gtk.EventBox):
def __init__(self, con, settings, position, icons_path):
def __init__(self, con, settings, position, icons_path, floating=False):
self.position = position
self.settings = settings
Gtk.EventBox.__init__(self)
Expand Down Expand Up @@ -152,6 +152,7 @@ def __init__(self, con, settings, position, icons_path):
self.set_tooltip_text(name)

check_key(settings, "show-layout", True)

if settings["show-layout"] and con.parent.layout:
if con.parent.layout == "splith":
image = Gtk.Image()
Expand All @@ -165,9 +166,10 @@ def __init__(self, con, settings, position, icons_path):
elif con.parent.layout == "stacked":
image = Gtk.Image()
update_image(image, "view-paged-symbolic", 16, icons_path)
else:

if floating:
image = Gtk.Image()
update_image(image, "window-new-symbolic", 16, icons_path)
update_image(image, "window-pop-out-symbolic", 16, icons_path)

self.box.pack_start(image, False, False, 4)

Expand Down
107 changes: 54 additions & 53 deletions nwg_panel/modules/sway_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def build_box(self):
check_key(self.settings, "mark-content", True)
check_key(self.settings, "show-layout", True)

ws_num, win_name, win_id, non_empty, win_layout = self.find_details()
if self.i3.get_tree().find_focused():
ws_num, win_name, win_id, non_empty, win_layout = self.find_details()

for num in self.settings["numbers"]:
eb = Gtk.EventBox()
Expand Down Expand Up @@ -74,56 +75,58 @@ def build_box(self):
self.pack_start(self.layout_icon, False, False, 6)

def refresh(self):
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
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 self.i3.get_tree().find_focused():
ws_num, win_name, win_id, non_empty, win_layout = self.find_details()

if num == str(ws_num):
self.ws_num2box[num].set_property("name", "task-box-focused")
else:
self.ws_num2box[num].set_property("name", "task-box")
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:
self.ws_num2box[num].set_property("name", "task-box")

if self.settings["show-icon"] and win_id != self.win_id:
self.update_icon(win_id, win_name)
self.win_id = win_id
if self.settings["show-icon"] and win_id != self.win_id:
self.update_icon(win_id, win_name)
self.win_id = win_id

if self.settings["show-name"]:
self.name_label.set_text(win_name)
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)
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-pop-out-symbolic", self.settings["image-size"], self.icons_path)

if not self.layout_icon.get_visible():
self.layout_icon.show()
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()
if self.layout_icon.get_visible():
self.layout_icon.hide()

def update_icon(self, win_id, win_name):
if win_id and win_name:
Expand Down Expand Up @@ -152,7 +155,6 @@ 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:
Expand All @@ -165,14 +167,12 @@ def find_details(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

win_pid = f.pid

for item in tree.descendants():
if item.type == "workspace":
# find non-empty workspaces
Expand All @@ -183,7 +183,7 @@ def find_details(self):
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
Expand All @@ -192,8 +192,9 @@ def find_details(self):
win_id = node.app_id
elif node.window_class:
win_id = node.window_class
layout = node.parent.layout
win_pid = node.pid
layout = "floating"

non_empty.append(node.workspace().num)

if not layout:
layout = f.parent.layout
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read(f_name):

setup(
name='nwg-panel',
version='0.2.2',
version='0.2.3',
description='GTK3-based panel for sway window manager',
packages=find_packages(),
include_package_data=True,
Expand Down

0 comments on commit e64dc7a

Please sign in to comment.