cmdtree

A trie command launcher for X11
git clone git://jb55.com/cmdtree
Log | Files | Refs | README | LICENSE

commit 8a59f41102b4189e66d9176cccb579857431be48
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 26 Jun 2018 15:41:06 -0700

cmdtree

Diffstat:
A.dir-locals.el | 7+++++++
A.gitignore | 1+
AMakefile | 5+++++
Acmdtree.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el @@ -0,0 +1,7 @@ +((c-mode . ((c-file-style . "linux") + (indent-tabs-mode . t) + (show-trailing-whitespace . t) + (c-basic-offset . 8) + (tab-width . 8) + )) + ) diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +/cmdtree diff --git a/Makefile b/Makefile @@ -0,0 +1,5 @@ + +all: cmdtree + +cmdtree: cmdtree.c + $(CC) -O -g -lX11 $< -o $@ diff --git a/cmdtree.c b/cmdtree.c @@ -0,0 +1,53 @@ +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Xresource.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +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; +}