-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacaron.c
More file actions
119 lines (101 loc) · 2.42 KB
/
macaron.c
File metadata and controls
119 lines (101 loc) · 2.42 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <Imlib2.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int width = 250;
int height = 250;
int x = 25;
int y = 25;
Display *dpy;
Window win;
Visual *vis;
int depth;
Colormap cm;
void help(const char *msg) {
printf("usage: %s [options] [file]\nOPTIONS:\n-x\n\tset x position\n-y\n\tset y position\n-w\n\tset width of widget\n-h\n\tset height of widget\n", msg);
exit(1);
}
void parseargs(int argc, char **argv) {
int option;
if (argc < 2) {
help(argv[0]);
}
while ((option = getopt(argc, argv, "x:y:w:h:")) != -1) {
switch (option) {
case 'x':
x = atoi(optarg);
break;
case 'y':
y = atoi(optarg);
break;
case 'w':
width = atoi(optarg);
break;
case 'h':
height = atoi(optarg);
break;
case '?':
help(argv[0]);
break;
}
}
if (optind >= argc) {
help(argv[0]);
}
}
void init() {
dpy = XOpenDisplay(NULL);
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), x, y, width, height, 0, 0, 0);
vis = DefaultVisual(dpy, DefaultScreen(dpy));
depth = DefaultDepth(dpy, DefaultScreen(dpy));
cm = DefaultColormap(dpy, DefaultScreen(dpy));
XSelectInput(dpy, win, ExposureMask);
XSetWindowBackgroundPixmap(dpy, win, None);
XClassHint *classhint = XAllocClassHint();
classhint->res_class = "macaron";
classhint->res_name = "macaron";
XSetClassHint(dpy, win, classhint);
XSetWindowAttributes attrs;
attrs.override_redirect = True;
XChangeWindowAttributes(dpy, win, CWOverrideRedirect, &attrs);
XMapWindow(dpy, win);
XLowerWindow(dpy, win);
// setup Imlib2
imlib_context_set_display(dpy);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
}
void cleanup() {
imlib_free_image();
XFreeColormap(dpy, cm);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
}
int main(int argc, char **argv) {
parseargs(argc, argv);
init();
// load image
Imlib_Image image;
image = imlib_load_image(argv[optind]);
if (image == NULL) {
printf("failed to load image\n");
exit(1);
}
imlib_context_set_image(image);
// draw image
XEvent ev;
while (1) {
XNextEvent(dpy, &ev);
if (ev.type == Expose) {
imlib_render_image_on_drawable_at_size(0, 0, width, height);
XFlush(dpy);
}
}
cleanup();
return 0;
}