summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Castel <gilles@castel.dev>2019-06-19 17:14:55 +0200
committerGilles Castel <gilles@castel.dev>2019-06-19 17:14:55 +0200
commit11b786c82bbc77b3b4139a9bb8019be5454a1ebd (patch)
tree308dac29921a5beafb1a04301133b456da20edea
parent5446a7c67322086c22dfe712d49a8690fd2a6787 (diff)
Listen for existing Inkscape windows
-rw-r--r--main.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/main.py b/main.py
index f738a88..540b99a 100644
--- a/main.py
+++ b/main.py
@@ -58,7 +58,9 @@ class Manager():
keysym = self.disp.keycode_to_keysym(keycode, 0)
char = XK.keysym_to_string(keysym)
self.disp.allow_events(X.ReplayKeyboard, X.CurrentTime)
+
self.mode(self, evt, char)
+
if evt.type == X.DestroyNotify:
if evt.window.id == self.id:
self.ungrab()
@@ -69,18 +71,31 @@ def create(inkscape_id):
m = Manager(inkscape_id)
m.listen()
+def is_inkscape(window):
+ return window.get_wm_class() and window.get_wm_class()[0] == 'inkscape'
+
def main():
disp = Display()
screen = disp.screen()
root = screen.root
+
+ # First listen for existing windows
+ for window in root.query_tree().children:
+ if is_inkscape(window):
+ print('Found existing window')
+ listen = threading.Thread(target=create, args=[window.id])
+ listen.start()
+
+
+ # New windows
root.change_attributes(event_mask=X.SubstructureNotifyMask)
while True:
evt = disp.next_event()
if evt.type == X.CreateNotify:
window = evt.window
try:
- if window.get_wm_class() and window.get_wm_class()[0] == 'inkscape':
- print('Listening!')
+ if is_inkscape(window):
+ print('New window!')
listen = threading.Thread(target=create, args=[window.id])
listen.start()