Returned Xlib Objects XGetWindowProperty Zero

I am having trouble reading some of the ICCCM XWindow properties.

The problem is I am trying to read the _NET_WM_STATUS property. The function I'm using:

int get_property_value(Display* display, Window window,char *propname, long max_length,
           unsigned long *nitems_return, unsigned char **prop_return){
    int result;
    Atom property;
    Atom actual_type_return;
    int actual_format_return;
    unsigned long bytes_after_return;
    unsigned char* prop_to_return;
    unsigned long n_items;
    printf("-----GET_PROPERTY_VALUE-------\n");
    printf("\tPropname: %s\n", propname);
    property = XInternAtom(display, propname, True);
    if(property==None){
      printf("\tWrong Atom\n");
      return;
    }

    result = XGetWindowProperty(display, window, property, 0,   /* long_offset */
            (~0L),  /* long_length */
            False,  /* delete */
            AnyPropertyType,    /* req_type */
            &actual_type_return,
            &actual_format_return,
            &n_items, &bytes_after_return, &prop_to_return);
    if (result != Success){
        printf("\tXGetWindowProperty failed\n");
        return (-1);
    }   else {
        printf("\tActual Type: %s\n", XGetAtomName(display,property));
        printf("\tProperty format: %d\n", actual_format_return);
        //printf("Actual property return: %s\n", XGetAtomName(display,actual_type_return));
        printf("\tByte after return: %ld\n", bytes_after_return);
        printf("\tnitems return: %d\n", n_items);
        printf("\tprop return: %s\n", prop_to_return);
    }
    printf("-----END OF GET_PROPERTY_VALUE-------\n");

    return (0);
}

      

The get_property_value function is called after the ClientMessage is received, and this is the piece of code that handles the event:

    case ClientMessage:
        printf("ClientMessage\n");
        printf("Message: %s\n", XGetAtomName(display,local_event.xclient.message_type));
        unsigned long nitems_return;
        unsigned char *prop_return;
        get_property_value(display, local_event.xclient.window, XGetAtomName(display,local_event.xclient.message_type), 256, &nitems_return, (unsigned char **)&prop_return);
    break;

      

But when I read properties, sometimes I get a property with no values, is it possible? The problem is mainly when I try to read the AtomProperties sent from firefox (I try to read the _NET_WM_STATE value) in the ClientMessage event.

As you can see from the output, the property name is correctly read, but then it appears that it does not contain any element.

ClientMessage
Message: _NET_WM_STATE
-----GET_PROPERTY_VALUE-------
    Propname: _NET_WM_STATE
    Actual Type: _NET_WM_STATE
    Property format: 0
    Byte after return: 0
    nitems return: 0
    prop return: (null)
-----END OF GET_PROPERTY_VALUE-------

      

+3


source to share


1 answer


I still don't have enough comments to comment on (I'm kind of new to this), but I've spent some time struggling with Xlib and I'll try to see if I can help. I wrote a small program that includes your code:

#include <X11/Xlib.h>
#include <stdlib.h>
#include <stdio.h>

int get_property_value(Display* display, Window window,char *propname, long max_length,
           unsigned long *nitems_return, unsigned char **prop_return){
    int result;
    Atom property;
    Atom actual_type_return;
    int actual_format_return;
    unsigned long bytes_after_return;
    unsigned char* prop_to_return;
    unsigned long n_items;
    printf("-----GET_PROPERTY_VALUE-------\n");
    printf("\tPropname: %s\n", propname);
    property = XInternAtom(display, propname, True);
    if(property==None){
      printf("\tWrong Atom\n");
      return;
    }

    result = XGetWindowProperty(display, window, property, 0,   /* long_offset */
            (~0L),  /* long_length */
            False,  /* delete */
            AnyPropertyType,    /* req_type */
            &actual_type_return,
            &actual_format_return,
            &n_items, &bytes_after_return, &prop_to_return);
    if (result != Success){
        printf("\tXGetWindowProperty failed\n");
        return (-1);
    }   else {
        printf("\tActual Type: %s\n", XGetAtomName(display,actual_type_return));
        printf("\tProperty format: %d\n", actual_format_return);
        //printf("Actual property return: %s\n", XGetAtomName(display,actual_type_return));
        printf("\tByte after return: %ld\n", bytes_after_return);
        printf("\tnitems return: %d\n", n_items);
        printf("\tprop return: %s %s\n", XGetAtomName(display,*(Atom*)prop_to_return), XGetAtomName(display,((Atom*)prop_to_return)[1]));
    }
    printf("-----END OF GET_PROPERTY_VALUE-------\n");

    return (0);
}

int main(int argc, char** argv) {
    Display* dsp = XOpenDisplay(NULL);
    unsigned long nitems_return;
    unsigned char* prop_return;
    get_property_value(dsp, (Window)atoi(argv[1]), "_NET_WM_STATE", 100000, &nitems_return, &prop_return);
    return 0;
}

      

I changed some of the output: I changed the "Actual Type" output to print the name actual_type_return

, not property

(since it looked like a typo), and I changed the "prop return" output to print atom names instead of binary data. Anyway, I pointed this version of code to a Firefox instance running on my computer and this is what I got:

$ ./xproptest 60817587
-----GET_PROPERTY_VALUE-------
    Propname: _NET_WM_STATE
    Actual Type: ATOM
    Property format: 32
    Byte after return: 0
    nitems return: 2
    prop return: _NET_WM_STATE_MAXIMIZED_VERT _NET_WM_STATE_MAXIMIZED_HORZ
-----END OF GET_PROPERTY_VALUE-------

      



So, the good news is that your code works really well on my machine. I'm not sure why this doesn't work for you. Of course, the above output comes from when Firefox is maximized; when not, the output is as follows:

$ ./xproptest 60817587
-----GET_PROPERTY_VALUE-------
    Propname: _NET_WM_STATE
    Actual Type: ATOM
    Property format: 32
    Byte after return: 0
    nitems return: 0
    prop return:

      

... and then a couple of errors about how I read invalid Atoms, because the code above assumes there are two. This is the correct conclusion when the property is empty and has no values; however, notice how my property format is 32 and yours is 0. From reading the manuals, it looks like the only way to get format 0 from a successful call XGetWindowProperty

is to call it on the property, t exists. I'm not sure why your Firefox won't have it _NET_WM_STATE

, though.

Overall, I assume that your code does work fine (besides a typo in one of the outputs), but for some reason the property you are trying to read does not exist in the window you are trying to read it. If I am correct, if you check the value actual_type_return

after reading the property, you can see that it is None

. Also, you should be able (if you haven't already) to print the ID of the window you are trying to read in your code ( window

) and use xwininfo

and xprop

with the flag -id

in to check if the window you are reading is the one you are reading consider, and whether it actually has the property you are trying to read. Hope this helps you figure out what the problem is.

+3


source







All Articles