1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include <X11/Xlib.h>
6
7 #define BUTTON_4_COMMAND "\x1b]5379;fontsize=larger\x07"
8 #define BUTTON_5_COMMAND "\x1b]5379;fontsize=smaller\x07"
9
10 void event_loop(Display *display);
11
main(int argc,char * argv[])12 int main(int argc, char *argv[]) {
13 Display *display;
14 Window window;
15 XSetWindowAttributes attrs;
16 char *display_name = NULL;
17 int screen_no;
18 int x, y, w, h, i;
19
20 x = 0;
21 y = 0;
22 i = 1;
23 while (i < argc) {
24 if (strcmp(argv[i], "--display") == 0) {
25 i++;
26 display_name = argv[i];
27 } else if (strcmp(argv[i], "--geometry") == 0) {
28 i++;
29 XParseGeometry(argv[i], &x, &y, &w, &h);
30 }
31 i++;
32 }
33 w = h = 32;
34
35 display = XOpenDisplay(display_name);
36 screen_no = DefaultScreen(display);
37
38 attrs.override_redirect = True;
39 attrs.event_mask = ButtonPressMask | KeyPressMask | LeaveWindowMask;
40 attrs.background_pixel = WhitePixel(display, screen_no);
41 attrs.border_pixel = BlackPixel(display, screen_no);
42
43 window = XCreateWindow(display, RootWindow(display, screen_no), x - (w / 2), y - (h / 2), w, h, 2,
44 DefaultDepth(display, screen_no), InputOutput,
45 DefaultVisual(display, screen_no),
46 CWOverrideRedirect | CWEventMask | CWBackPixel | CWBorderPixel, &attrs);
47
48 XMapWindow(display, window);
49
50 event_loop(display);
51 return 0;
52 }
53
event_loop(Display * display)54 void event_loop(Display *display) {
55 XEvent event;
56
57 while (1) {
58 XNextEvent(display, &event);
59 switch (event.type) {
60 case ButtonPress:
61 if (event.xbutton.button == 4) {
62 fprintf(stdout, BUTTON_4_COMMAND);
63 } else if (event.xbutton.button == 5) {
64 fprintf(stdout, BUTTON_5_COMMAND);
65 } else {
66 return;
67 }
68 fflush(stdout);
69 break;
70 case LeaveNotify:
71 return;
72 break;
73 default:
74 break;
75 }
76 }
77 return;
78 }
79