From 128576c54b2352702bbaf9eca49eb21ef2b6afc1 Mon Sep 17 00:00:00 2001 From: deuce <> Date: Thu, 19 Feb 2015 10:29:51 +0000 Subject: [PATCH] Support CIO_KEY_QUIT in X11 mode. --- src/conio/x_cio.c | 8 ++++++++ src/conio/x_events.c | 10 ++++++++++ src/conio/x_events.h | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/conio/x_cio.c b/src/conio/x_cio.c index 4d19e1e593..1a13dabef0 100644 --- a/src/conio/x_cio.c +++ b/src/conio/x_cio.c @@ -348,6 +348,14 @@ int x_init(void) xp_dlclose(dl); return(-1); } + if((x11.XSetWMProtocols=xp_dlsym(dl,XSetWMProtocols))==NULL) { + xp_dlclose(dl); + return(-1); + } + if((x11.XInternAtom=xp_dlsym(dl,XInternAtom))==NULL) { + xp_dlclose(dl); + return(-1); + } if(sem_init(&pastebuf_set, 0, 0)) { xp_dlclose(dl); diff --git a/src/conio/x_events.c b/src/conio/x_events.c index f55c5622d0..ff7850476f 100644 --- a/src/conio/x_events.c +++ b/src/conio/x_events.c @@ -54,6 +54,7 @@ int x11_initialized=0; /* Sets the atom to be used for copy/paste operations */ #define CONSOLE_CLIPBOARD XA_PRIMARY +static Atom WM_DELETE_WINDOW=0; static Display *dpy=NULL; static Window win; @@ -218,6 +219,8 @@ static int init_window() x11.XSetWMProperties(dpy, win, NULL, NULL, 0, 0, NULL, wmhints, NULL); } + WM_DELETE_WINDOW = x11.XInternAtom(dpy, "WM_DELETE_WINDOW", False); + gcv.function = GXcopy; gcv.foreground = white; gcv.background = black; @@ -242,6 +245,7 @@ static int init_window() x11.XStoreName(dpy, win, "SyncConsole"); depth = DefaultDepth(dpy, DefaultScreen(dpy)); + x11.XSetWMProtocols(dpy, win, &WM_DELETE_WINDOW, 1); return(0); } @@ -460,6 +464,12 @@ static void expose_rect(x,y,width,height) static int x11_event(XEvent *ev) { switch (ev->type) { + case ClientMessage: + if (ev->xclient.format == 32 && ev->xclient.data.l[0] == WM_DELETE_WINDOW) { + uint16_t key=CIO_KEY_QUIT; + write(key_pipe[1], &key, 2); + } + break; /* Graphics related events */ case ConfigureNotify: x11_window_xpos=ev->xconfigure.x; diff --git a/src/conio/x_events.h b/src/conio/x_events.h index c19e1310e0..366aa51a3f 100644 --- a/src/conio/x_events.h +++ b/src/conio/x_events.h @@ -80,6 +80,8 @@ struct x11 { Status (*XGetWindowAttributes) (Display*,Window,XWindowAttributes*); XWMHints* (*XAllocWMHints) (void); void (*XSetWMProperties) (Display*, Window, XTextProperty*, XTextProperty*, char**, int, XSizeHints*, XWMHints*, XClassHint*); + Status (*XSetWMProtocols) (Display*, Window, Atom *, int); + Atom (*XInternAtom) (Display *, char *, Bool); }; -- GitLab