XChangeProperty/XGetWindowProperty problem
Antoine Martin
antoine at nagafix.co.uk
Fri May 9 09:13:35 UTC 2025
You're using using format=32, which means `CARD32` aka `unsigned long`,
not to be confused with 32-bit integers, despite its name.
Switch from `int32_t` to `unsigned long`.
Cheers,
Antoine
On 09/05/2025 13:56, 406643764 wrote:
> 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
>
> <https://wx.mail.qq.com/home/index?
> t=readmail_businesscard_midpage&nocheck=true&name=406643764&icon=http%3A%2F%2Fthirdqq.qlogo.cn%2Fg%3Fb%3Dsdk%26k%3DJbWZCVxhvqPvCEFNVWedQw%26s%3D100%26t%3D1556323638%3Frand%3D1646747733&mail=406643764%40qq.com&code=>
More information about the xorg
mailing list