add & use h_get_active_workspace() #310
This commit is contained in:
@@ -186,50 +186,50 @@ def hypr_watcher():
|
|||||||
event_name = e_full_string.split(">>")[0]
|
event_name = e_full_string.split(">>")[0]
|
||||||
|
|
||||||
if event_name in ["monitoradded", "openwindow", "movewindow"]:
|
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:
|
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_title = client_title
|
||||||
last_client_addr = client_addr
|
last_client_addr = client_addr
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if event_name == "focusedmon":
|
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:
|
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_title = client_title
|
||||||
last_client_addr = client_addr
|
last_client_addr = client_addr
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if event_name == "activewindow" and client_title != last_client_title:
|
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:
|
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:
|
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_title = client_title
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if event_name == "activewindowv2" and client_addr != last_client_addr:
|
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:
|
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:
|
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
|
last_client_addr = client_addr
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if event_name in ["changefloatingmode", "closewindow"]:
|
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:
|
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:
|
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_addr = ""
|
||||||
last_client_title = ""
|
last_client_title = ""
|
||||||
@@ -270,9 +270,9 @@ def instantiate_content(panel, container, content_list, icons_path=""):
|
|||||||
# list initial data for Hyprland modules
|
# list initial data for Hyprland modules
|
||||||
if his:
|
if his:
|
||||||
if "hyprland-workspaces" in content_list or "hyprland-taskbar" in content_list:
|
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:
|
else:
|
||||||
monitors, workspaces, clients, activewindow = {}, {}, {}, {}
|
monitors, workspaces, clients, activewindow, activeworkspace = {}, {}, {}, {}, {}
|
||||||
|
|
||||||
for item in content_list:
|
for item in content_list:
|
||||||
if item == "sway-taskbar":
|
if item == "sway-taskbar":
|
||||||
@@ -348,7 +348,7 @@ def instantiate_content(panel, container, content_list, icons_path=""):
|
|||||||
if his:
|
if his:
|
||||||
if "hyprland-workspaces" in panel:
|
if "hyprland-workspaces" in panel:
|
||||||
workspaces = HyprlandWorkspaces(panel["hyprland-workspaces"], monitors, workspaces, clients,
|
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"])
|
container.pack_start(workspaces, False, False, panel["items-padding"])
|
||||||
common.h_workspaces_list.append(workspaces)
|
common.h_workspaces_list.append(workspaces)
|
||||||
else:
|
else:
|
||||||
|
@@ -6,7 +6,7 @@ from nwg_panel.tools import check_key, update_image_fallback_desktop, hyprctl
|
|||||||
|
|
||||||
|
|
||||||
class HyprlandWorkspaces(Gtk.Box):
|
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)
|
Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=0)
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.num_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
|
self.num_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
|
||||||
@@ -22,7 +22,7 @@ class HyprlandWorkspaces(Gtk.Box):
|
|||||||
self.ws_nums = []
|
self.ws_nums = []
|
||||||
|
|
||||||
self.build_box()
|
self.build_box()
|
||||||
self.refresh(monitors, workspaces, clients, activewindow)
|
self.refresh(monitors, workspaces, clients, activewindow, activeworkspace)
|
||||||
|
|
||||||
def build_box(self):
|
def build_box(self):
|
||||||
check_key(self.settings, "num-ws", 10)
|
check_key(self.settings, "num-ws", 10)
|
||||||
@@ -90,7 +90,7 @@ class HyprlandWorkspaces(Gtk.Box):
|
|||||||
|
|
||||||
return eb, lbl
|
return eb, lbl
|
||||||
|
|
||||||
def refresh(self, monitors, workspaces, clients, activewindow):
|
def refresh(self, monitors, workspaces, clients, activewindow, activeworkspace):
|
||||||
occupied_workspaces = []
|
occupied_workspaces = []
|
||||||
self.ws_id2name = {}
|
self.ws_id2name = {}
|
||||||
|
|
||||||
@@ -113,16 +113,9 @@ class HyprlandWorkspaces(Gtk.Box):
|
|||||||
client_title = "X|{}".format(client_title)
|
client_title = "X|{}".format(client_title)
|
||||||
floating = activewindow["floating"]
|
floating = activewindow["floating"]
|
||||||
pinned = activewindow["pinned"]
|
pinned = activewindow["pinned"]
|
||||||
active_ws = activewindow["workspace"]["id"]
|
|
||||||
else:
|
# fix #310
|
||||||
client_class = ""
|
active_ws = activeworkspace["id"]
|
||||||
client_title = ""
|
|
||||||
floating = False
|
|
||||||
pinned = False
|
|
||||||
for m in monitors:
|
|
||||||
if m["focused"]:
|
|
||||||
active_ws = m["activeWorkspace"]["id"]
|
|
||||||
break
|
|
||||||
|
|
||||||
for num in self.ws_nums:
|
for num in self.ws_nums:
|
||||||
if num in occupied_workspaces or self.settings["show-empty"]:
|
if num in occupied_workspaces or self.settings["show-empty"]:
|
||||||
|
@@ -885,8 +885,17 @@ def h_get_activewindow():
|
|||||||
return {}
|
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():
|
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):
|
def cmd_through_compositor(cmd):
|
||||||
|
Reference in New Issue
Block a user