diff current_window_title_linux.py @ 3:3d7fc94a404a

a few more inputs; daemonize
author drewp@bigasterisk.com
date Wed, 08 Mar 2023 10:57:11 -0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/current_window_title_linux.py	Wed Mar 08 10:57:11 2023 -0800
@@ -0,0 +1,13 @@
+import Xlib
+import Xlib.display
+
+_disp = None
+
+
+def get_current_window_title():
+    global _disp
+    if _disp is None:
+        _disp = Xlib.display.Display()
+    window = _disp.get_input_focus().focus
+    # get_wm_name returns '': https://github.com/python-xlib/python-xlib/issues/212
+    return window.get_property(_disp.get_atom("WM_NAME"), _disp.get_atom("UTF8_STRING"), 0, 1024).value.decode('utf8')
\ No newline at end of file