add & use h_get_active_workspace() #310

This commit is contained in:
piotr
2024-07-15 23:49:53 +02:00
parent 2c13954dda
commit 2cd25c0e14
3 changed files with 32 additions and 30 deletions

View File

@@ -186,50 +186,50 @@ def hypr_watcher():
event_name = e_full_string.split(">>")[0]
if event_name in ["monitoradded", "openwindow", "movewindow"]:
monitors, workspaces, clients, activewindow = h_modules_get_all()
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
for item in common.h_taskbars_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
last_client_title = client_title
last_client_addr = client_addr
continue
if event_name == "focusedmon":
monitors, workspaces, clients, activewindow = h_modules_get_all()
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
for item in common.h_workspaces_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
last_client_title = client_title
last_client_addr = client_addr
continue
if event_name == "activewindow" and client_title != last_client_title:
monitors, workspaces, clients, activewindow = h_modules_get_all()
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
for item in common.h_taskbars_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
for item in common.h_workspaces_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
last_client_title = client_title
continue
if event_name == "activewindowv2" and client_addr != last_client_addr:
monitors, workspaces, clients, activewindow = h_modules_get_all()
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
for item in common.h_taskbars_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
for item in common.h_workspaces_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
last_client_addr = client_addr
continue
if event_name in ["changefloatingmode", "closewindow"]:
monitors, workspaces, clients, activewindow = h_modules_get_all()
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
for item in common.h_taskbars_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
for item in common.h_workspaces_list:
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
last_client_addr = ""
last_client_title = ""
@@ -270,9 +270,9 @@ def instantiate_content(panel, container, content_list, icons_path=""):
# list initial data for Hyprland modules
if his:
if "hyprland-workspaces" in content_list or "hyprland-taskbar" in content_list:
monitors, workspaces, clients, activewindow = h_modules_get_all()
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
else:
monitors, workspaces, clients, activewindow = {}, {}, {}, {}
monitors, workspaces, clients, activewindow, activeworkspace = {}, {}, {}, {}, {}
for item in content_list:
if item == "sway-taskbar":
@@ -348,7 +348,7 @@ def instantiate_content(panel, container, content_list, icons_path=""):
if his:
if "hyprland-workspaces" in panel:
workspaces = HyprlandWorkspaces(panel["hyprland-workspaces"], monitors, workspaces, clients,
activewindow, icons_path=icons_path)
activewindow, activeworkspace, icons_path=icons_path)
container.pack_start(workspaces, False, False, panel["items-padding"])
common.h_workspaces_list.append(workspaces)
else:

View File

@@ -6,7 +6,7 @@ from nwg_panel.tools import check_key, update_image_fallback_desktop, hyprctl
class HyprlandWorkspaces(Gtk.Box):
def __init__(self, settings, monitors, workspaces, clients, activewindow, icons_path):
def __init__(self, settings, monitors, workspaces, clients, activewindow, activeworkspace, icons_path):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
self.settings = settings
self.num_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
@@ -22,7 +22,7 @@ class HyprlandWorkspaces(Gtk.Box):
self.ws_nums = []
self.build_box()
self.refresh(monitors, workspaces, clients, activewindow)
self.refresh(monitors, workspaces, clients, activewindow, activeworkspace)
def build_box(self):
check_key(self.settings, "num-ws", 10)
@@ -90,7 +90,7 @@ class HyprlandWorkspaces(Gtk.Box):
return eb, lbl
def refresh(self, monitors, workspaces, clients, activewindow):
def refresh(self, monitors, workspaces, clients, activewindow, activeworkspace):
occupied_workspaces = []
self.ws_id2name = {}
@@ -113,16 +113,9 @@ class HyprlandWorkspaces(Gtk.Box):
client_title = "X|{}".format(client_title)
floating = activewindow["floating"]
pinned = activewindow["pinned"]
active_ws = activewindow["workspace"]["id"]
else:
client_class = ""
client_title = ""
floating = False
pinned = False
for m in monitors:
if m["focused"]:
active_ws = m["activeWorkspace"]["id"]
break
# fix #310
active_ws = activeworkspace["id"]
for num in self.ws_nums:
if num in occupied_workspaces or self.settings["show-empty"]:

View File

@@ -885,8 +885,17 @@ def h_get_activewindow():
return {}
def h_get_active_workspace():
reply = hyprctl("j/activeworkspace")
try:
return json.loads(reply)
except Exception as e:
eprint(e)
return {}
def h_modules_get_all():
return h_list_monitors(), h_list_workspaces(), h_list_clients(), h_get_activewindow()
return h_list_monitors(), h_list_workspaces(), h_list_clients(), h_get_activewindow(), h_get_active_workspace()
def cmd_through_compositor(cmd):