You are not logged in.
I've written a little dwm status tool in C. At first I was using a system call to xsetroot, then I figured I could just set this directly.
I hit an odd stumbling block though. After much googling and experimenting I have an odd observation. This code does not act as I expected
Display *dpy;
Window root;
int scr;
dpy=XOpenDisplay(NULL);
if ( dpy == NULL) {
fprintf(stderr, "ERROR: could not open display\n");
exit(1);
}
scr = DefaultScreen(dpy);
root = XRootWindow(dpy,scr);
// snip unrelated string processing constructing a string that will go
// in place of "test" below once this is working.
XStoreName(dpy,root,"test");
I get no errors including when I tested the return value of XStoreName, yet it doesn't actually set the root window name.
To check my own sanity, I added a "char *temp;" declaration at the beginning. and the following line right at the end of the previous excerpt
XFetchName(dpy,root,temp);
printf("FETCHED: %s\n",&temp);
This did output "FETCHED: test" just as I had hoped, but this also had a "side-effect" of actually setting the root window name.
This makes no sense to me. Is this the Heisenburg uncertainty principle of the root window name: it's not really set until you observe that it is set?!
After thinking a little more I wondered whether some sort of refresh was required for the XStoreName to take effect. Perhaps the Fetch triggered this refresh. I can find no such requirement documented anywhere though.
For the time being setting then fetching is a suitable work around, but it seems a bit clumsy. Particularly when it allocates memory for a char * that I have to keep Xfree'ing.
Any enlightenment would be appreciated.
Edit: I've also looked at the code for xsetroot. It just calls XStoreName.
SOLUTION ... I knew it'd be something foolish:
As my program runs in a loop (for a dwm status bar) it never calls XCloseDisplay. In the absence of that call, XFlush is required for the settings to be applied.
In case anyone else runs into the same issue, XStoreName followed by XFlush does the trick.
Last edited by Trilby (2012-04-29 13:42:37)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline