From 4ec82c58d9f011d7f94ad025bb2fefe9c2508c20 Mon Sep 17 00:00:00 2001 From: Matthias Grandl Date: Thu, 24 Nov 2022 12:32:39 +0100 Subject: [PATCH] keyd-application-mapper: Add hyperland support --- scripts/keyd-application-mapper | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/keyd-application-mapper b/scripts/keyd-application-mapper index e022e17..995e5f3 100755 --- a/scripts/keyd-application-mapper +++ b/scripts/keyd-application-mapper @@ -157,6 +157,43 @@ class SwayMonitor(): self.on_window_change(cls, title) +class HyprMonitor(): + def __init__(self, on_window_change): + assert_env('HYPRLAND_INSTANCE_SIGNATURE') + + self.on_window_change = on_window_change + + def init(self): + pass + + def run(self): + import socket + + last_cls = '' + last_title = '' + + s = "/tmp/hypr/" + str(os.getenv('HYPRLAND_INSTANCE_SIGNATURE')) + "/.socket2.sock" + + client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + client.connect(s) + + while True: + data = client.recv(4096) + msg = data.decode('utf-8') + tmp = msg.split('>>') + if tmp[0] == 'activewindow' and len(tmp) > 1: + cls, title = tmp[1].split(',') + + if title == '' and cls == '': + continue + + if last_cls != cls or last_title != title: + last_cls = cls + last_title = title + + self.on_window_change(cls, title) + + client.close() class XMonitor(): def __init__(self, on_window_change): @@ -367,6 +404,7 @@ class GnomeMonitor(): def get_monitor(on_window_change): monitors = [ ('Sway', SwayMonitor), + ('Hyprland', HyprMonitor), ('Gnome', GnomeMonitor), ('X', XMonitor), ]