[PATCH] x11: handle WM_DELETE_WINDOW
François Revol <[email protected]> Tue, 07 Jan 2014 01:17:46 +0100
| Newsgroups | gmane.editors.qemacs.devel |
|---|---|
| Message-ID | <[email protected]> |
This patch tries to handle the window close event in X11. I did the same as in the Haiku code, although I'm not sure it's the best way. Actually I noticed a bug when testing it: - open a file - make a change - hit F1 - hit F1 - hit C-g - hit C-g here it segfaults... François. _______________________________________________ Qemacs-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/qemacs-devel
qemacs-x11-wm_delete_window.diff
(text/x-patch, 1.7 KB)
Index: x11.c
===================================================================
RCS file: /sources/qemacs/qemacs/x11.c,v
retrieving revision 1.29
diff -u -r1.29 x11.c
--- x11.c 17 Dec 2013 16:06:36 -0000 1.29
+++ x11.c 7 Jan 2014 00:14:31 -0000
@@ -55,6 +55,7 @@
static Display *display;
static int xscreen;
static Window window;
+static Atom wm_delete_window;
static GC gc, gc_pixmap;
static XWindowAttributes attr;
static int event_mask;
@@ -319,6 +320,9 @@
XNFocusWindow, window,
NULL);
+ wm_delete_window = XInternAtom (display, "WM_DELETE_WINDOW", False);
+ XSetWMProtocols (display, window, &wm_delete_window, 1);
+
gc = XCreateGC(display, window, 0, NULL);
#ifdef CONFIG_XFT
renderDraw = XftDrawCreate(display, window, attr.visual,
@@ -1247,6 +1251,22 @@
while (XPending(display)) {
XNextEvent(display, &xev);
switch (xev.type) {
+ case ClientMessage:
+ if ((Atom)xev.xclient.data.l[0] == wm_delete_window) {
+ // cancel pending operation
+ ev->key_event.type = QE_KEY_EVENT;
+ ev->key_event.key = KEY_CTRL('g');
+ qe_handle_event(ev);
+
+ // simulate C-x C-c
+ ev->key_event.type = QE_KEY_EVENT;
+ ev->key_event.key = KEY_CTRL('x');
+ qe_handle_event(ev);
+ ev->key_event.type = QE_KEY_EVENT;
+ ev->key_event.key = KEY_CTRL('c');
+ qe_handle_event(ev);
+ }
+ break;
case ConfigureNotify:
if (term_resize(s, xev.xconfigure.width, xev.xconfigure.height)) {
qe_expose_set(s, rgn, 0, 0, s->width, s->height);