-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtapet.c
72 lines (56 loc) · 1.46 KB
/
tapet.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <Imlib2.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
Display *dpy = XOpenDisplay(NULL);
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual *vis = DefaultVisual(dpy, screen);
int screenDepth = DefaultDepth(dpy, screen);
int screenWidth = DisplayWidth(dpy, screen);
int screenHeight = DisplayHeight(dpy, screen);
unsigned int offsetX = 0;
unsigned int offsetY = 0;
unsigned int i;
for(i = 1; i < argc; i++) {
int c = argv[i][1];
switch(c) {
case 'x':
if(++i < argc)
offsetX = -atoi(argv[i]);
break;
case 'y':
if(++i < argc)
offsetY = -atoi(argv[i]);
break;
}
}
Imlib_Image image = imlib_load_image(argv[argc - 1]);
if(image)
{
Pixmap bg = XCreatePixmap(dpy, root, screenWidth, screenHeight, screenDepth);
imlib_context_set_image(image);
imlib_context_set_display(dpy);
imlib_context_set_visual(vis);
imlib_context_set_drawable(bg);
imlib_render_image_on_drawable(offsetX, offsetY);
// Ripped out of xsetroot.
Atom atomRoot = XInternAtom(dpy, "_XROOTPMAP_ID", False);
XChangeProperty(
dpy, root, atomRoot,
XA_PIXMAP, 32, PropModeReplace,
(unsigned char *) &bg, 1
);
XKillClient(dpy, AllTemporary);
XSetCloseDownMode(dpy, RetainPermanent);
XSetWindowBackgroundPixmap(dpy, root, bg);
XClearWindow(dpy, root);
XFlush(dpy);
XSync(dpy, False);
imlib_free_image();
}
return 0;
}