Skip to content

Commit

Permalink
sniff_x: fix getting utf8 window titles, via _NET_WM_NAME
Browse files Browse the repository at this point in the history
This queried `_NET_WM_NAME` first, before falling back to the
python-xlib method, which only queries for `WM_NAME` with type `STRING`
(ignoring `UTF8_STRING` and `COMPOUND_TEXT`) therein.

Ref: selfspy#56 (comment)
(although selfspy#56 itself does not appear to be about the X sniffer).
  • Loading branch information
blueyed committed Jul 8, 2015
1 parent 1a08019 commit aa76881
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions selfspy/sniff_x.py
Expand Up @@ -159,6 +159,29 @@ def lookup_keysym(self, keysym):
return self.keysymdict[keysym]
return "[%d]" % keysym

def get_wm_name(self, win):
"""
Custom method to query for _NET_WM_NAME first, before falling back to
python-xlib's method, which (currently) only queries WM_NAME with
type=STRING."""

# _NET_WM_NAME = self.the_display.intern_atom('_NET_WM_NAME')
_NET_WM_NAME = 370
# UTF8_STRING = self.the_display.intern_atom('UTF8_STRING')
UTF8_STRING = 355

This comment has been minimized.

Copy link
@olejorgenb

olejorgenb Jul 24, 2015

Hardcoding atom ids doesn't work - need to do an intern as commented-out above. (I assume it will work to cache the atom for the duration of the program)


# Alternatively, we could also try WM_NAME with "UTF8_STRING" and
# "COMPOUND_TEXT", but _NET_WM_NAME should be good.

d = win.get_full_property(_NET_WM_NAME, UTF8_STRING)
if d is None or d.format != 8:
# Fallback.
r = win.get_wm_name()
if r:
return r.decode('latin1') # WM_NAME with type=STRING.
else:
return d.value.decode('utf8')

def get_cur_window(self):
i = 0
cur_class = None
Expand All @@ -173,7 +196,7 @@ def get_cur_window(self):
if type(cur_window) is int:
return None, None, None

cur_name = cur_window.get_wm_name()
cur_name = self.get_wm_name(cur_window)
cur_class = cur_window.get_wm_class()

if cur_class:
Expand All @@ -186,7 +209,7 @@ def get_cur_window(self):
break
cur_class = cur_class or ''
cur_name = cur_name or ''
return cur_class.decode('latin1'), cur_window, cur_name.decode('latin1')
return cur_class.decode('latin1'), cur_window, cur_name

def get_geometry(self, cur_window):
i = 0
Expand Down

0 comments on commit aa76881

Please sign in to comment.