annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
1 import Xlib
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
2 import Xlib.display
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
3
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
4 _disp = None
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
5
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
6
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
7 def get_current_window_title():
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
8 global _disp
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
9 if _disp is None:
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
10 _disp = Xlib.display.Display()
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
11 window = _disp.get_input_focus().focus
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
12 # get_wm_name returns '': https://github.com/python-xlib/python-xlib/issues/212
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
13 return window.get_property(_disp.get_atom("WM_NAME"), _disp.get_atom("UTF8_STRING"), 0, 1024).value.decode('utf8')