aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-04-07 23:14:13 -0400
committerJesse Luehrs <doy@tozt.net>2014-04-07 23:14:13 -0400
commit133d3a7c48dc780982622215a3dc0f58abb6cf55 (patch)
tree4ced3fa7ff4cc98c5c41a2eab754dba82be2e69b
parenta8c3d350a87d83c5c8e0b53a89fff85d72873166 (diff)
downloadrunes-133d3a7c48dc780982622215a3dc0f58abb6cf55.tar.gz
runes-133d3a7c48dc780982622215a3dc0f58abb6cf55.zip
handle closing the window
-rw-r--r--events.c6
-rw-r--r--events.h1
-rw-r--r--xlib.c26
-rw-r--r--xlib.h7
4 files changed, 34 insertions, 6 deletions
diff --git a/events.c b/events.c
index cff1a31..45fe493 100644
--- a/events.c
+++ b/events.c
@@ -13,3 +13,9 @@ void runes_handle_keyboard_event(RunesTerm *t, char *buf, size_t len)
{
runes_display_glyph(t, buf, len);
}
+
+void runes_handle_close_window(RunesTerm *t)
+{
+ uv_stop(t->loop);
+ t->loop = NULL;
+}
diff --git a/events.h b/events.h
index af15430..23462d3 100644
--- a/events.h
+++ b/events.h
@@ -8,5 +8,6 @@ struct loop_data {
uv_loop_t *runes_loop_create(RunesTerm *t);
void runes_handle_keyboard_event(RunesTerm *t, char *buf, size_t len);
+void runes_handle_close_window(RunesTerm *t);
#endif
diff --git a/xlib.c b/xlib.c
index 73b8d84..02fab41 100644
--- a/xlib.c
+++ b/xlib.c
@@ -5,6 +5,10 @@
#include "runes.h"
+static char *atom_names[RUNES_NUM_ATOMS] = {
+ "WM_DELETE_WINDOW"
+};
+
RunesWindow *runes_window_create()
{
RunesWindow *w;
@@ -73,13 +77,13 @@ static void runes_process_event(uv_work_t *req, int status)
{
struct xlib_loop_data *data;
XEvent *e;
- RunesWindow *w;
+ RunesTerm *t;
UNUSED(status);
data = ((struct xlib_loop_data *)req->data);
e = &data->e;
- w = data->data.t->w;
+ t = data->data.t;
if (!XFilterEvent(e, None)) {
switch (e->type) {
@@ -93,7 +97,7 @@ static void runes_process_event(uv_work_t *req, int status)
buf = malloc(len);
for (;;) {
- chars = Xutf8LookupString(w->ic, &e->xkey, buf, len - 1, &sym, &s);
+ chars = Xutf8LookupString(t->w->ic, &e->xkey, buf, len - 1, &sym, &s);
if (s == XBufferOverflow) {
len = chars + 1;
buf = realloc(buf, len);
@@ -102,16 +106,23 @@ static void runes_process_event(uv_work_t *req, int status)
break;
}
- runes_handle_keyboard_event(data->data.t, buf, chars);
+ runes_handle_keyboard_event(t, buf, chars);
free(buf);
break;
}
+ case ClientMessage:
+ if ((Atom)e->xclient.data.l[0] == t->w->atoms[RUNES_ATOM_WM_DELETE_WINDOW]) {
+ runes_handle_close_window(t);
+ }
+ break;
default:
break;
}
}
- uv_queue_work(req->loop, req, runes_get_next_event, runes_process_event);
+ if (t->loop) {
+ uv_queue_work(t->loop, req, runes_get_next_event, runes_process_event);
+ }
}
void runes_loop_init(RunesTerm *t, uv_loop_t *loop)
@@ -120,13 +131,16 @@ void runes_loop_init(RunesTerm *t, uv_loop_t *loop)
void *data;
XGetICValues(t->w->ic, XNFilterEvents, &mask, NULL);
- XSelectInput(t->w->dpy, t->w->w, mask|KeyPressMask);
+ XSelectInput(t->w->dpy, t->w->w, mask|KeyPressMask|StructureNotifyMask);
XSetICFocus(t->w->ic);
data = malloc(sizeof(struct xlib_loop_data));
((struct loop_data *)data)->req.data = data;
((struct loop_data *)data)->t = t;
+ XInternAtoms(t->w->dpy, atom_names, RUNES_NUM_ATOMS, False, t->w->atoms);
+ XSetWMProtocols(t->w->dpy, t->w->w, &t->w->atoms[RUNES_ATOM_WM_DELETE_WINDOW], 1);
+
uv_queue_work(loop, data, runes_get_next_event, runes_process_event);
}
diff --git a/xlib.h b/xlib.h
index a8b84b0..3c8ae24 100644
--- a/xlib.h
+++ b/xlib.h
@@ -3,11 +3,18 @@
#include <X11/Xlib.h>
+enum runes_atoms {
+ RUNES_ATOM_WM_DELETE_WINDOW,
+ RUNES_NUM_ATOMS
+};
+
struct runes_window {
Display *dpy;
Window w;
GC gc;
XIC ic;
+
+ Atom atoms[RUNES_NUM_ATOMS];
};
struct xlib_loop_data {