rework hypr_watcher #321
This commit is contained in:
@@ -87,8 +87,6 @@ his = os.getenv('HYPRLAND_INSTANCE_SIGNATURE')
|
|||||||
if his:
|
if his:
|
||||||
from nwg_panel.modules.hyprland_taskbar import HyprlandTaskbar
|
from nwg_panel.modules.hyprland_taskbar import HyprlandTaskbar
|
||||||
from nwg_panel.modules.hyprland_workspaces import HyprlandWorkspaces
|
from nwg_panel.modules.hyprland_workspaces import HyprlandWorkspaces
|
||||||
last_client_addr = ""
|
|
||||||
last_client_title = ""
|
|
||||||
|
|
||||||
common_settings = {}
|
common_settings = {}
|
||||||
restart_cmd = ""
|
restart_cmd = ""
|
||||||
@@ -165,74 +163,49 @@ def hypr_watcher():
|
|||||||
|
|
||||||
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
client.connect(f"{hypr_dir}/{his}/.socket2.sock")
|
client.connect(f"{hypr_dir}/{his}/.socket2.sock")
|
||||||
|
just_refreshed = False
|
||||||
global last_client_addr, last_client_title
|
|
||||||
client_addr, client_title = None, None
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
datagram = client.recv(2048)
|
datagram = client.recv(2048)
|
||||||
e_full_string = datagram.decode('utf-8').strip()
|
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
|
event_names = []
|
||||||
if e_full_string.startswith("activewindow"):
|
for line in lines:
|
||||||
lines = e_full_string.splitlines()
|
event_names.append(line.split(">>")[0])
|
||||||
for line in lines:
|
print(event_names)
|
||||||
if line.startswith("activewindowv2"):
|
|
||||||
client_addr = e_full_string.split(">>")[1].strip()
|
|
||||||
elif line.startswith("activewindow>>"):
|
|
||||||
client_title = line.split(">>")[1].strip()
|
|
||||||
|
|
||||||
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"]:
|
if "activewindow" in event_name and just_refreshed:
|
||||||
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
|
just_refreshed = False
|
||||||
for item in common.h_taskbars_list:
|
break
|
||||||
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
|
|
||||||
last_client_title = client_title
|
|
||||||
last_client_addr = client_addr
|
|
||||||
continue
|
|
||||||
|
|
||||||
if event_name in ["focusedmon", "createworkspace"]:
|
print(f">>> Refreshing on {event_name}")
|
||||||
monitors, workspaces, clients, activewindow, activeworkspace = 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_taskbars_list:
|
||||||
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
|
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
|
||||||
last_client_title = client_title
|
|
||||||
last_client_addr = client_addr
|
|
||||||
continue
|
|
||||||
|
|
||||||
if event_name == "activewindow" and client_title != last_client_title:
|
for item in common.h_workspaces_list:
|
||||||
monitors, workspaces, clients, activewindow, activeworkspace = h_modules_get_all()
|
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
|
||||||
for item in common.h_taskbars_list:
|
|
||||||
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow)
|
|
||||||
|
|
||||||
for item in common.h_workspaces_list:
|
if event_name in ["createworkspace", "destroyworkspace", "focusedmon", "workspace"]:
|
||||||
GLib.timeout_add(0, item.refresh, monitors, workspaces, clients, activewindow, activeworkspace)
|
just_refreshed = True
|
||||||
|
|
||||||
last_client_title = client_title
|
break
|
||||||
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 = ""
|
|
||||||
|
|
||||||
|
|
||||||
def on_i3ipc_event(i3conn, event):
|
def on_i3ipc_event(i3conn, event):
|
||||||
|
Reference in New Issue
Block a user