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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xresource.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static Window root, parentwin, win;
static int screen;
static Display *display;
static int mw, mh;
static unsigned int lines = 0;
static XIC xic;
// config
static int topbar = 1;
#define MAX(A, B) ((A) > (B) ? (A) : (B))
static void
die(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr);
perror(NULL);
} else {
fputc('\n', stderr);
}
exit(1);
}
static void
setup()
{
int x, y;
XSetWindowAttributes swa;
XWindowAttributes wa;
XIM xim;
XClassHint ch = {"cmdtree", "cmdtree"};
if (!XGetWindowAttributes(display, parentwin, &wa))
die("could not get embedding window attributes: 0x%lx",
parentwin);
x = 0;
y = topbar ? 0 : wa.height - mh;
mw = wa.width;
lines = MAX(lines, 0);
/* mh = (lines + 1) * bh; */
mh = 100;
swa.override_redirect = True;
/* swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; */
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(display, parentwin, x, y, mw, mh, 0,
CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
XSetClassHint(display, win, &ch);
// what do?
/* XMapRaised(display, win); */
xim = XOpenIM(display, NULL, NULL, NULL);
xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
XNClientWindow, win, XNFocusWindow, win, NULL);
XSelectInput(display, win, ExposureMask | KeyPressMask);
XMapWindow(display, win);
XSetInputFocus(display, win, RevertToParent, CurrentTime);
// XXX embed
/* if (embed) { */
/* XSelectInput(dpy, parentwin, FocusChangeMask); */
/* if (XQueryTree(dpy, parentwin, &dw, &w, &dws, &du) && dws) { */
/* for (i = 0; i < du && dws[i] != win; ++i) */
/* XSelectInput(dpy, dws[i], FocusChangeMask); */
/* XFree(dws); */
/* } */
/* grabfocus(); */
/* } */
/* drw_resize(drw, mw, mh); */
/* drawmenu(); */
}
static void
run() {
XEvent e;
int done = 0;
char buf[32];
KeySym ksym = NoSymbol;
Status status;
static const char *msg = "cmdtree is a tree of commands";
while (!done) {
XNextEvent(display, &e);
if (e.type == Expose) {
XFillRectangle(display, win, DefaultGC(display, screen),
20, 20, 10, 10);
XDrawString(display, win, DefaultGC(display, screen), 10,
50, msg, strlen(msg));
}
if (e.type == KeyPress) {
XmbLookupString(xic, (XKeyEvent*)&e, buf,
sizeof buf, &ksym, &status);
if (ksym == XK_q) done = 1;
if (ksym == XK_Escape) done = 1;
}
}
}
int main(void) {
display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
screen = DefaultScreen(display);
root = RootWindow(display, screen);
// XXX embed
/* if (!embed || !(parentwin = strtol(embed, NULL, 0))) */
/* parentwin = root; */
parentwin = root;
setup();
run();
XCloseDisplay(display);
return 0;
}
|