rework hypr_watcher #321

This commit is contained in:
piotr
2024-10-04 03:23:13 +02:00
parent d4598c8843
commit 4c8fe7dcb0

View File

@@ -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):