You are not logged in.
First, I'm sorry that I once necrobump.
I did some search and found no much help, it just make me hurry somehow.
I have been learning Xlib, and wrote this:
#include <X11/Xlib.h>
int main()
{
Display *dpy = XOpenDisplay(NULL);
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
XSetWindowBackground(dpy, root, 0);
XClearWindow(dpy, root);
return 0;
}
It will just not change background.
How do I fix it?
I'm using i3wm, and
feh --bg-scale some.jpeg
can work properly.
Thanks.
Last edited by NUIL (2021-04-24 07:03:39)
Offline
Your code is missing an "XCloseDisplay(dpy);" which should be right before the return statement. Failing that, at least an "XFlush(dpy);" would be needed to make this work.
You cued up commands to be sent to the X server, but the program as-written exits before anything is actually sent. With either the XCloseDisplay or the XFlush line, the code will "work" assuming feh isn't running in the background.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I have tried this
#include <X11/Xlib.h>
int main()
{
Display *dpy = XOpenDisplay(NULL);
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
XSetWindowBackground(dpy, root, 0);
XClearWindow(dpy, root);
XFlush(dpy);
XCloseDisplay(dpy);
return 0;
}
and did
killall -q feh
before.
But still not work.
Offline
Please explain "does not work".
What do you expect to happen, what happens instead?
Also: are you maybe running a compositor (picom/xcompmgr/…)?
Online
I want to change wallpaper to, for now, as a test, pixel value 0.
After I killed xcompmgr, it can work (make the root window pixle value 0).
But how can I do this without xcompmgr killed?
Offline
xprop -root | grep PMAP
Online
xprop -root | grep PMAP
ESETROOT_PMAP_ID(PIXMAP): pixmap id # 0x3e00001
_XROOTPMAP_ID(PIXMAP): pixmap id # 0x3e00001
Could you give some explain? I'm not quite familiar with X.
Offline
Online
I have come to this
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <stdbool.h>
int main()
{
Display *dpy = XOpenDisplay(NULL);
int screen = DefaultScreen(dpy);
Screen *scr = ScreenOfDisplay(dpy, screen);
Window root = RootWindow(dpy, screen);
Atom prop_root = XInternAtom(dpy, "_XROOTPMAP_ID", false);
Atom prop_esetroot = XInternAtom(dpy, "ESETROOT_PMAP_ID", false);
Pixmap pixmap = XCreatePixmap(dpy, root, scr->width, scr->height,
DefaultDepth(dpy, screen));
/* GC gc = XCreateGC(dpy, root, GCForeground, 0); */
/* XPutImage(dpy, pixmap, gc, image, 0, 0, 0, 0, scr->width, scr->height); */
XChangeProperty(dpy, root, prop_root, XA_PIXMAP, 32, PropModeReplace,
(unsigned char *) &pixmap, 1);
XChangeProperty(dpy, root, prop_esetroot, XA_PIXMAP, 32, PropModeReplace,
(unsigned char *) &pixmap, 1);
XSetWindowBackgroundPixmap(dpy, root, pixmap);
XClearWindow(dpy, root);
XFlush(dpy);
XSetCloseDownMode(dpy, RetainPermanent);
XCloseDisplay(dpy);
return 0;
}
Looks like things left is to load an image/gen some color.
Thank you!
Offline
So this is all starting to sound like an X-Y problem. What are you *really* trying to do? Why are you writing code explicitly to work around other tools that you are running? Just stop running those other tools!
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
He's not necessarily working around something, but compositors will more often then never render into the root window and thus get the root window pixmap from those properties instead.
@NUIL, the block above in the linke feh code prevents background pixmaps from leaking memory (because of XKillClient, check https://man.archlinux.org/man/extra/lib … nMode.3.en )
Online
I see, thank you! I think this can be closed.
Offline
Edit your inital post and prepend [SOLVED] to the subject line.
Online