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
|
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#define BUTTON_4_COMMAND "\x1b]5379;fontsize=larger\x07"
#define BUTTON_5_COMMAND "\x1b]5379;fontsize=smaller\x07"
void event_loop(Display* display);
int
main(int argc, char* argv[])
{
Display* display;
Window window;
XSetWindowAttributes attrs;
char* display_name = NULL;
int screen_no;
int x, y, w, h, i;
x = 0;
y = 0;
i = 1;
while (i < argc) {
if (strcmp(argv[i], "--display") == 0) {
i++;
display_name = argv[i];
} else if (strcmp(argv[i], "--geometry") == 0) {
i++;
XParseGeometry(argv[i], &x, &y, &w, &h);
}
i++;
}
w = h = 32;
display = XOpenDisplay(display_name);
screen_no = DefaultScreen(display);
attrs.override_redirect = True;
attrs.event_mask = ButtonPressMask | KeyPressMask | LeaveWindowMask;
attrs.background_pixel = WhitePixel(display, screen_no);
attrs.border_pixel = BlackPixel(display, screen_no);
window = XCreateWindow(display, RootWindow(display, screen_no),
x - (w / 2), y - (h / 2), w, h,
2, DefaultDepth(display, screen_no),
InputOutput, DefaultVisual(display, screen_no),
CWOverrideRedirect | CWEventMask |
CWBackPixel | CWBorderPixel,
&attrs);
XMapWindow(display, window);
event_loop(display);
return 0;
}
void
event_loop(Display* display)
{
XEvent event;
while (1) {
XNextEvent(display, &event);
switch (event.type) {
case ButtonPress:
if (event.xbutton.button == 4) {
fprintf(stdout, BUTTON_4_COMMAND);
} else if (event.xbutton.button == 5) {
fprintf(stdout, BUTTON_5_COMMAND);
} else {
return;
}
fflush(stdout);
break;
case LeaveNotify:
return;
break;
default:
break;
}
}
return;
}
|