I’m learning to use xlib and I’m unable to get XChangeProperty() to work for me.
I have a simple program that displays a window successfully. But calls to XChangeProperty() always fail with error code error 1 (BadRequest).
Can someone tell me what I’m doing wrong?
Here is my code to change a property.
static void
change_prop(Display *display, Window window)
{
unsigned char some_text[40] = "hello world!";
int retval;
Atom my_atom;
my_atom = XInternAtom(display, "PERSONAL_PROPERTY", False);
if (my_atom == None)
{
printf("### failed to create atom with name PERSONAL_PROPERTY\n");
return;
}
retval = XChangeProperty(display, /* connection to x server */
window, /* window whose property we want to change */
my_atom, /* property name */
XA_STRING, /* type of property */
8, /* format of prop; can be 8, 16, 32 */
PropModeReplace,
some_text, /* actual data */
10 /* number of elements */
);
printf("###### XChangeProperty() reted %d\n", retval);
}
Most xlib functions always return 1 and you should use error handlers to check for errors. See XChangeProperty implementation – note
return 1at the end.Your code works just fine:
result:
xprop result: