XChangeProperty/XGetWindowProperty problem

Carsten Haitzler raster at rasterman.com
Fri May 9 09:49:43 UTC 2025


On Fri, 9 May 2025 14:56:09 +0800 "406643764" <406643764 at qq.com> said:

please make your text in emails actual text, not html... it will make replies
not full of junk like this.

you need to use long, not uint32_t for a 32bit property. don't ask. history.

> Hi, all. 
> 
> I use XChangeProperty/XGetWindowProperty as following code:
>  
> #include <stdio.h>
> #include <X11/Xlib.h>
> #include <X11/Xatom.h>
> 
> int main(void)
> {
>     Display *display=XOpenDisplay(NULL);
>     int screen=DefaultScreen(display);
>     Window root_win=RootWindow(display, screen);
> 
>     Window win=XCreateSimpleWindow(display, root_win, -1, -1, 1, 1,
> 0, 0, 0);     Atom prop=XInternAtom(display, "test_prop", False);
>     Atom type=XInternAtom(display, "test_type", False);
>     int32_t a[]={0x11223344, 0x55667788};
>     XChangeProperty(display, win, prop, type, 32, PropModeReplace,
> (unsigned char *)a, 2);
> 
>     int fmt;
>     unsigned long nitems=0, n=0, rest;
>     unsigned char *p=NULL;
>     Atom atype;
>     if( XGetWindowProperty(display, win, prop, 0, 2, False,
>         type, &atype, &fmt, &n,
> &rest, &p) != Success         || !atype
> || !fmt || !n || !p)         XFree(p), p=NULL;
>     long *d=(long *)p;
>     printf("%lx, %lx, %lu\n", d[0], d[1], rest);
> 
>     XCloseDisplay(display);
> 
>     return 0;
> }
> 
> 
> 
> But the output is:
> 
> 
> 11223344, 1, 0
> 
> 
> It should be:
> 
> 
> 11223344, 55667788, 0
> 
> 
> 
> What's wrong ?
> 
> 
> 
> 406643764
> 406643764 at qq.com
> 
> 
> 
>  

-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
Carsten Haitzler - raster at rasterman.com



More information about the xorg mailing list