From 272f24ed3acf54f7e1b17d8c79ed70c7c117bf79 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 21 Apr 2017 12:48:05 -0300 Subject: [PATCH] Exit correctly when the close button is pressed on X11/Skia port --- src/she/x11/window.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/she/x11/window.cpp b/src/she/x11/window.cpp index 5cc0f0611..6cab48733 100644 --- a/src/she/x11/window.cpp +++ b/src/she/x11/window.cpp @@ -19,6 +19,10 @@ namespace she { namespace { +// Event generated by the window manager when the close button on the +// window is pressed by the userh. +Atom wmDeleteMessage = 0; + // See https://bugs.freedesktop.org/show_bug.cgi?id=12871 for more // information, it looks like the official way to convert a X Window // into our own user data pointer (X11Window instance) is using a map. @@ -68,6 +72,11 @@ X11Window::X11Window(::Display* display, int width, int height, int scale) , m_scale(scale) , m_clientSize(1, 1) { + // Initialize special messages (just the first time a X11Window is + // created) + if (!wmDeleteMessage) + wmDeleteMessage = XInternAtom(m_display, "WM_DELETE_WINDOW", False); + ::Window root = XDefaultRootWindow(m_display); XSetWindowAttributes swa; @@ -86,6 +95,7 @@ X11Window::X11Window(::Display* display, int width, int height, int scale) &swa); XMapWindow(m_display, m_window); + XSetWMProtocols(m_display, m_window, &wmDeleteMessage, 1); m_gc = XCreateGC(m_display, m_window, 0, nullptr); @@ -235,6 +245,15 @@ void X11Window::processX11Event(XEvent& event) break; } + case ClientMessage: + // When the close button is pressed + if (Atom(event.xclient.data.l[0]) == wmDeleteMessage) { + Event ev; + ev.setType(Event::CloseDisplay); + queueEvent(ev); + } + break; + } }