2024-11-16 03:57:59 +03:00
|
|
|
diff --git a/scripts/keyd-application-mapper b/scripts/keyd-application-mapper
|
2024-11-16 06:52:58 +03:00
|
|
|
index 55dd63b..ed74f4e 100755
|
2024-11-16 03:57:59 +03:00
|
|
|
--- a/scripts/keyd-application-mapper
|
|
|
|
+++ b/scripts/keyd-application-mapper
|
2024-11-16 06:52:58 +03:00
|
|
|
@@ -176,18 +176,49 @@ class Wlroots():
|
2024-11-16 03:57:59 +03:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
windows = {}
|
|
|
|
+ active_window = None
|
|
|
|
+
|
|
|
|
while True:
|
|
|
|
(obj, event, payload) = self.wl.recv_msg()
|
|
|
|
if obj == 4 and event == 0:
|
|
|
|
- windows[struct.unpack('I', payload)[0]] = {}
|
|
|
|
-
|
|
|
|
- if obj in windows:
|
|
|
|
- if event == 0:
|
|
|
|
- windows[obj]['title'] = self.wl.read_string(payload)
|
|
|
|
- if event == 1:
|
|
|
|
- windows[obj]['appid'] = self.wl.read_string(payload)
|
|
|
|
- if event == 4 and payload[0] > 0 and payload[4] == 2:
|
|
|
|
- self.on_window_change(windows[obj].get('appid', ''), windows[obj].get('title', ''))
|
|
|
|
+ # zwlr_foreign_toplevel_manager_v1::toplevel event
|
2024-11-16 06:52:58 +03:00
|
|
|
+ windows[struct.unpack('I', payload)[0]] = {'title': '', 'appid': ''}
|
2024-11-16 03:57:59 +03:00
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ if obj not in windows:
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ if event == 0:
|
|
|
|
+ # zwlr_foreign_toplevel_handle_v1::title event
|
|
|
|
+ windows[obj]['title'] = self.wl.read_string(payload)
|
|
|
|
+ elif event == 1:
|
|
|
|
+ # zwlr_foreign_toplevel_handle_v1::app_id event
|
|
|
|
+ windows[obj]['appid'] = self.wl.read_string(payload)
|
|
|
|
+ elif event == 4:
|
|
|
|
+ # zwlr_foreign_toplevel_handle_v1::state event
|
|
|
|
+ if active_window == windows[obj]:
|
|
|
|
+ active_window = None
|
2024-11-16 06:52:58 +03:00
|
|
|
+ window_is_active = False
|
2024-11-16 03:57:59 +03:00
|
|
|
+
|
|
|
|
+ array_size = struct.unpack('I', payload[0:4])[0]
|
|
|
|
+ for i in range(0, array_size, 4):
|
|
|
|
+ start_offset = i + 4
|
|
|
|
+ end_offset = start_offset + 4
|
2024-11-16 06:52:58 +03:00
|
|
|
+ state = struct.unpack('I', payload[start_offset:end_offset])[0]
|
|
|
|
+ # zwlr_foreign_toplevel_handle_v1::state enum -> activated
|
|
|
|
+ if state == 2:
|
|
|
|
+ window_is_active = True
|
2024-11-16 03:57:59 +03:00
|
|
|
+
|
2024-11-16 06:52:58 +03:00
|
|
|
+ if window_is_active:
|
2024-11-16 03:57:59 +03:00
|
|
|
+ active_window = windows[obj]
|
|
|
|
+ elif event == 5 and active_window == windows[obj]:
|
|
|
|
+ # zwlr_foreign_toplevel_handle_v1::done event
|
|
|
|
+ self.on_window_change(active_window['appid'], active_window['title'])
|
|
|
|
+ elif event == 6:
|
|
|
|
+ # zwlr_foreign_toplevel_handle_v1::closed event
|
|
|
|
+ closed_window = windows.pop(obj)
|
|
|
|
+ if closed_window == active_window:
|
|
|
|
+ active_window = None
|
|
|
|
|
|
|
|
class XMonitor():
|
|
|
|
def __init__(self, on_window_change):
|