2

Question

I'm trying to find NET_WM_NAME property for each of the window/client that X11 reports. Problem is that there's nothing returned - number of items is 0 and returned data results in empty string. I've looked at multiple code examples through out github and examples written in C and C++ , specifically Why is XGetWindowProperty returning null? as well as Xlib XGetWindowProperty Zero items returned , however I cannot find where is the problem with my code. Seemingly everything is fine, order of parameters passed to XGetWindowProperty function is in accordance with documentation, and the function returns success status, but results are empty. Where is the problem with my code ?

Code

Below is the code I am working with. The issue is xgetwindowproperty function. The other parts below it work fine, and are provided only for completeness.

#! /usr/bin/env python3
import sys
from ctypes import *

def xgetwindowproperty(display,w):

    actual_type_return   = c_ulong()
    actual_format_return = c_int()
    nitems_return        = c_ulong()
    bytes_after_return   = c_ulong()
    prop_return          = POINTER(c_ubyte)()

    wm_name = Xlib.XInternAtom(display,'_NET_WM_NAME',False)
    utf8atom = Xlib.XInternAtom(display,'UTF8_STRING',False)
    print('_NET_WM_NAME',wm_name, 'UTF8_STRING',utf8atom)

    # AnyPropertyType = c_long(0)
    status = Xlib.XGetWindowProperty(
            display,
            w,
            wm_name,
            0,
            65536, 
            False,
            utf8atom,
            byref(actual_type_return),
            byref(actual_format_return),
            byref(nitems_return),
            byref(bytes_after_return),
            byref(prop_return)
    )
    print(nitems_return.value) # returns 0
    # empty string as result
    print( 'Prop', ''.join([ chr(c) for c in prop_return[:bytes_after_return.value]  ]) ) 

    Xlib.XFree(prop_return)
    print('@'*10)
# -------

Xlib = CDLL("libX11.so.6")
display = Xlib.XOpenDisplay(None)
if display == 0: 
    sys.exit(2)

w = Xlib.XRootWindow(display, c_int(0))

root = c_ulong()
children = POINTER(c_ulong)()
parent = c_ulong()
nchildren = c_uint()

Xlib.XQueryTree(display, w, byref(root), byref(parent), byref(children), byref(nchildren))

for i in range(nchildren.value):
    print("Child:",children[i])
    xgetwindowproperty(display,children[i])
Sergiy Kolodyazhnyy
  • 938
  • 1
  • 13
  • 41
  • One thing that is certainly wrong is *argtypes* and *restype* not being defined for any of the functions. Check https://stackoverflow.com/questions/53182796/python-ctypes-issue-on-different-oses/53185316#53185316. – CristiFati Mar 15 '19 at 09:57

0 Answers0