You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
window.get_wm_name() is empty but not in window.get_property() equivalent #212
I am trying to interact with chrome browser windows using X11 APIs but python-xlib wrapper always returns empty window names. Here is what xprop shows about chrome windows:
From looking at XGetWindowProperty's documentation:
If the specified property exists but its type does not match the specified
type, XGetWindowProperty returns the actual property type to actual_type_return,
the actual property format (never zero) to actual_format_return, and the property
length in bytes (even if the actual_format_return is 16 or 32) to bytes_after_return.
It also ignores the delete argument. The nitems_return argument is empty.
…it looks like our implementation of Window.get_full_property is wrong and should
call get_property again with the correct type if the previous attempt returned
a different type than asked for and bytes_after is not zero:
Xlib/xobject/drawable.py | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git i/Xlib/xobject/drawable.py w/Xlib/xobject/drawable.py
index c36a973..f79a7dc 100644
--- i/Xlib/xobject/drawable.py+++ w/Xlib/xobject/drawable.py@@ -470,17 +470,21 @@ def get_property(self, property, property_type, offset, length, delete = 0):
def get_full_property(self, property, property_type, sizehint = 10):
prop = self.get_property(property, property_type, 0, sizehint)
- if prop:- val = prop.value- if prop.bytes_after:- prop = self.get_property(property, property_type, sizehint,- prop.bytes_after // 4 + 1)- val = val + prop.value-- prop.value = val+ if not prop:+ return None+ if not prop.bytes_after:
return prop
+ val = prop.value+ if prop.property_type == property_type:+ offset = sizehint+ sizehint = prop.bytes_after // 4 + 1
else:
- return None+ assert not val+ property_type = prop.property_type+ offset = 0+ prop = self.get_property(property, property_type, offset, sizehint)+ prop.value = val + prop.value+ return prop
def get_full_text_property(self, property, property_type=X.AnyPropertyType, sizehint = 10):
prop = self.get_full_property(property, property_type,
If the property_type parameter in Python is meant as a sort of "filter" to specify what the returned property should be, then I believe repeating the request with a different type would be the wrong approach to the problem.
A better fix, IMHO, is to drop the Xatom.STRING argument when calling get_full_property in Window.get_wm_name() (and similar methods such as get_wm_icon_name). I wonder why it is using it instead of the default X.AnyPropertyType.
get_full_property() should not change a caller's argument: in case of an inconsistency between the requested and the obtained type it should either raise an exception or just return the obtained property as-is (bytes_left included) and let the caller handle the inconsistency. Otherwise, what's the point of the property_type parameter?
In other words: the meaning (and usefulness) of property_type in both Window.get_property() and Window.get_full_property() is debatable (IMHO both should be hard-coded to X.AnyPropertyType (= 0)), but in this case the bug is in Windows.get_wm_name() and friends for specifying the wrong type (or for specifying a type at all).
Activity
benoit-pierre commentedon Dec 2, 2021
I can reproduce with Chromium.
From looking at
XGetWindowProperty's documentation:…it looks like our implementation of
Window.get_full_propertyis wrong and shouldcall
get_propertyagain with the correct type if the previous attempt returneda different type than asked for and
bytes_afteris not zero:MestreLion commentedon Jan 23, 2023
If the
property_typeparameter in Python is meant as a sort of "filter" to specify what the returned property should be, then I believe repeating the request with a different type would be the wrong approach to the problem.A better fix, IMHO, is to drop the
Xatom.STRINGargument when callingget_full_propertyinWindow.get_wm_name()(and similar methods such asget_wm_icon_name). I wonder why it is using it instead of the defaultX.AnyPropertyType.MestreLion commentedon Jan 23, 2023
get_full_property()should not change a caller's argument: in case of an inconsistency between the requested and the obtained type it should either raise an exception or just return the obtained property as-is (bytes_leftincluded) and let the caller handle the inconsistency. Otherwise, what's the point of theproperty_typeparameter?MestreLion commentedon Jan 23, 2023
In other words: the meaning (and usefulness) of
property_typein bothWindow.get_property()andWindow.get_full_property()is debatable (IMHO both should be hard-coded toX.AnyPropertyType(=0)), but in this case the bug is inWindows.get_wm_name()and friends for specifying the wrong type (or for specifying a type at all).