From 8a59f41102b4189e66d9176cccb579857431be48 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 26 Jun 2018 15:41:06 -0700 Subject: cmdtree --- cmdtree.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 cmdtree.c (limited to 'cmdtree.c') diff --git a/cmdtree.c b/cmdtree.c new file mode 100644 index 0000000..5802d64 --- /dev/null +++ b/cmdtree.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#include +#include +#include + +int main(void) { + Display *d; + XIC xic; + Window w; + XEvent e; + char *msg = "cmdtree is a tree of commands"; + int s; + char buf[32]; + int len, done = 0; + KeySym ksym = NoSymbol; + Status status; + XIM xim; + + d = XOpenDisplay(NULL); + if (d == NULL) { + fprintf(stderr, "Cannot open display\n"); + exit(1); + } + + s = DefaultScreen(d); + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1, + BlackPixel(d, s), WhitePixel(d, s)); + xim = XOpenIM(d, NULL, NULL, NULL); + xic = XCreateIC(xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, + XNClientWindow, w, XNFocusWindow, w, NULL); + XSelectInput(d, w, ExposureMask | KeyPressMask); + XMapWindow(d, w); + + while (!done) { + XNextEvent(d, &e); + if (e.type == Expose) { + XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10); + XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg)); + } + + if (e.type == KeyPress) { + len = XmbLookupString(xic, (XKeyEvent*)&e, buf, sizeof buf, &ksym, &status); + if (ksym == XK_q) break; + } + + } + + XCloseDisplay(d); + return 0; +} -- cgit v1.2.3