From 4c8fe7dcb0d3dbe6b1c67ad47f91535b211b5d06 Mon Sep 17 00:00:00 2001 From: piotr Date: Fri, 4 Oct 2024 03:23:13 +0200 Subject: [PATCH 1/2] rework hypr_watcher #321 --- nwg_panel/main.py | 91 +++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 59 deletions(-) diff --git a/nwg_panel/main.py b/nwg_panel/main.py index 5e8579c..5097e0f 100644 --- a/nwg_panel/main.py +++ b/nwg_panel/main.py @@ -87,8 +87,6 @@ his = os.getenv('HYPRLAND_INSTANCE_SIGNATURE') if his: from nwg_panel.modules.hyprland_taskbar import HyprlandTaskbar from nwg_panel.modules.hyprland_workspaces import HyprlandWorkspaces -last_client_addr = "" -last_client_title = "" common_settings = {} restart_cmd = "" @@ -165,74 +163,49 @@ def hypr_watcher(): client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) client.connect(f"{hypr_dir}/{his}/.socket2.sock") - - global last_client_addr, last_client_title - client_addr, client_title = None, None + just_refreshed = False while True: datagram = client.recv(2048) e_full_string = datagram.decode('utf-8').strip() - # eprint("Event: {}".format(e_full_string)) + lines = e_full_string.splitlines() - # remember client address & title (string) for further event filtering - if e_full_string.startswith("activewindow"): - lines = e_full_string.splitlines() - for line in lines: - if line.startswith("activewindowv2"): - client_addr = e_full_string.split(">>")[1].strip() - elif line.startswith("activewindow>>"): - client_title = line.split(">>")[1].strip() + event_names = [] + for line in lines: + event_names.append(line.split(">>")[0]) + print(event_names) - event_name = e_full_string.split(">>")[0] + for event_name in event_names: + if event_name in ["activespecial", + "activewindow", + "activewindowv2", + "changefloatingmode", + "closewindow", + "createworkspace", + "destroyworkspace", + "focusedmon", + "monitoradded", + "movewindow", + "openwindow", + "windowtitle", + "workspace"]: - if event_name in ["monitoradded", "openwindow", "movewindow"]: - 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) - last_client_title = client_title - last_client_addr = client_addr - continue + if "activewindow" in event_name and just_refreshed: + just_refreshed = False + break - if event_name in ["focusedmon", "createworkspace"]: - 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, activeworkspace) - last_client_title = client_title - last_client_addr = client_addr - continue + print(f">>> Refreshing on {event_name}") + 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) - if event_name == "activewindow" and client_title != last_client_title: - 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) + for item in common.h_workspaces_list: + 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, activeworkspace) + if event_name in ["createworkspace", "destroyworkspace", "focusedmon", "workspace"]: + just_refreshed = True - last_client_title = client_title - continue - - if event_name == "activewindowv2" and client_addr != last_client_addr: - 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) - - for item in common.h_workspaces_list: - 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, activeworkspace = h_modules_get_all() - for item in common.h_taskbars_list: - GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow) - - for item in common.h_workspaces_list: - GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace) - - last_client_addr = "" - last_client_title = "" + break def on_i3ipc_event(i3conn, event): From 1345106637399d499e3227a6aae588da042fed7a Mon Sep 17 00:00:00 2001 From: piotr Date: Sat, 5 Oct 2024 01:00:07 +0200 Subject: [PATCH 2/2] comments, messages --- nwg_panel/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nwg_panel/main.py b/nwg_panel/main.py index 5097e0f..f419869 100644 --- a/nwg_panel/main.py +++ b/nwg_panel/main.py @@ -152,7 +152,6 @@ def restart(): subprocess.Popen(restart_cmd, shell=True) -# read from Hyprland socket2 on async thread def hypr_watcher(): import socket @@ -173,7 +172,7 @@ def hypr_watcher(): event_names = [] for line in lines: event_names.append(line.split(">>")[0]) - print(event_names) + # print(f"events: {event_names}") for event_name in event_names: if event_name in ["activespecial", @@ -194,7 +193,7 @@ def hypr_watcher(): just_refreshed = False break - print(f">>> Refreshing on {event_name}") + # print(f">>> refreshing on {event_name}") 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) @@ -204,7 +203,6 @@ def hypr_watcher(): if event_name in ["createworkspace", "destroyworkspace", "focusedmon", "workspace"]: just_refreshed = True - break @@ -854,6 +852,7 @@ def main(): if his: if len(common.h_taskbars_list) > 0 or len(common.h_workspaces_list) > 0: print("his: '{}', starting hypr_watcher".format(his)) + # read from Hyprland socket2 on another thread thread = threading.Thread(target=hypr_watcher) thread.daemon = True thread.start()