Skip to content

Instantly share code, notes, and snippets.

@buma
Created May 24, 2015 09:51
Show Gist options
  • Select an option

  • Save buma/ff8e04b7a53e97a659d2 to your computer and use it in GitHub Desktop.

Select an option

Save buma/ff8e04b7a53e97a659d2 to your computer and use it in GitHub Desktop.
Changes needed in python xlib to support UTF8 WM_NAME
Index: Xlib/Xatom.py
===================================================================
--- Xlib/Xatom.py (revision 171)
+++ Xlib/Xatom.py (working copy)
@@ -85,3 +85,6 @@
WM_CLASS = 67
WM_TRANSIENT_FOR = 68
LAST_PREDEFINED = 68
+#Added
+UTF8_STRING = 291
+COMPOUND_TEXT = 446
Index: Xlib/xobject/drawable.py
===================================================================
--- Xlib/xobject/drawable.py (revision 171)
+++ Xlib/xobject/drawable.py (working copy)
@@ -640,10 +640,15 @@
onerror = onerror)
def get_wm_name(self):
- d = self.get_full_property(Xatom.WM_NAME, Xatom.STRING)
+ d = self.get_full_property(Xatom.WM_NAME, 0)
if d is None or d.format != 8:
return None
else:
+ if d.property_type == Xatom.UTF8_STRING:
+ #print "UTF:", type(d.value), repr(d.value)
+ return d.value.decode("utf-8")
+ elif d.property_type == Xatom.COMPOUND_TEXT:
+ return d.value.decode("utf-8", errors='ignore')
return d.value
def set_wm_icon_name(self, name, onerror = None):
@buma
Copy link
Author

buma commented May 24, 2015

To apply this patch install python xlib: pip install svn+https://python-xlib.svn.sourceforge.net/svnroot/python-xlib/tags/xlib_0_15rc1/ and go into installed folder lib/python2.7/site-packages and patch it
patch -b -p0 -i python-xlib_utf_name_support.diff. (-b makes backup -i inputs patch file)

To use it in selfspy then you only need utf8 branch for selfspy.

@blueyed
Copy link

blueyed commented Jul 8, 2015

It can be achieved also by changing selfspy only: selfspy/selfspy#126

The approach above would fall short for text=COMPOUND_TEXT (used by rxvt-unicode).
Using _NET_WM_NAME instead appears to be the simpler approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment