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
|
/* MAJE_LDLIB=-lX11 */
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xlib.h>
int main(int argc, char *argv[])
{
int c = 0;
while ((c = getopt(argc, argv, "")) != -1) {
switch (c) {
default:
return 1;
}
}
Display *dpy = XOpenDisplay("");
if (dpy == NULL) {
fprintf(stderr, "xbar: can't open display\n");
return 1;
}
int screen = DefaultScreen(dpy);
Colormap cmap = XDefaultColormap(dpy, screen);
XColor bg;
if (XParseColor(dpy, cmap, "black", &bg) == 0) {
fprintf(stderr, "couldn't find black\n");
bg.pixel = BlackPixel(dpy, 0);
} else if (XAllocColor(dpy, cmap, &bg) == 0) {
fprintf(stderr, "couldn't allocate black\n");
bg.pixel = BlackPixel(dpy, 0);
}
XColor fg;
if (XParseColor(dpy, cmap, "white", &fg) == 0) {
fprintf(stderr, "couldn't find white\n");
fg.pixel = WhitePixel(dpy, 0);
} else if (XAllocColor(dpy, cmap, &fg) == 0) {
fprintf(stderr, "couldn't allocate white\n");
fg.pixel = WhitePixel(dpy, 0);
}
int width = DisplayWidth(dpy, screen);
int height = 20;
Window win = XCreateSimpleWindow(dpy, XDefaultRootWindow(dpy),
0, 0, width, height, 0, 0, bg.pixel);
XStoreName(dpy, win, "xbar");
XSelectInput(dpy, win, ExposureMask | KeyPressMask);
XMapWindow(dpy, win);
XMoveWindow(dpy, win, 0, 0);
XSetForeground(dpy, DefaultGC(dpy, screen), fg.pixel);
for (;;) {
XEvent e;
XNextEvent(dpy, &e);
switch (e.type) {
case Expose:
XDrawString(dpy, win, DefaultGC(dpy, screen), 10, 10,
"hello", strlen("hello"));
break;
case KeyPress:
printf("keypress\n");
break;
default:
break;
}
}
return 0;
}
|