mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-23 22:43:32 +00:00
Exit correctly when the close button is pressed on X11/Skia port
This commit is contained in:
parent
1bbaf60fd7
commit
272f24ed3a
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user