Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyd-application-mapper: Apply bindings when title/app id changes on wlroots #545

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions scripts/keyd-application-mapper
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,49 @@ class Wlroots():

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
windows[struct.unpack('I', payload)[0]] = {'title': '', 'appid': ''}
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
window_is_active = False

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
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

if window_is_active:
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):
Expand Down