From 6a992be61bdce9f4bca95822543257321f6815e3 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Wed, 17 May 2023 17:31:33 +0200 Subject: Add events to exit from application and to close the window --- src/application.c | 5 ++++- src/window.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/application.c b/src/application.c index 91b1719..24ac7ba 100644 --- a/src/application.c +++ b/src/application.c @@ -61,7 +61,10 @@ cherry_application_main_loop(CherryApplication *app) case ClientMessage: atom_name = XGetAtomName(app->display, (Atom) event.xclient.data.l[0]); - if (strcmp("WM_DELETE_WINDOW", atom_name) == 0) { + if (strcmp("CHERRY_DISPOSE_ON_EXIT", atom_name) == 0) { + /* Exit from loop */ + finish = 1; + } else if (strcmp("WM_DELETE_WINDOW", atom_name) == 0) { dispatch_event(app, event.xclient.window, DELETE_WINDOW); } diff --git a/src/window.c b/src/window.c index 7311819..4ca6027 100644 --- a/src/window.c +++ b/src/window.c @@ -54,6 +54,16 @@ cherry_window_new(void) None, NULL, 0, &hints); + /* allow receiving mouse events */ + XSelectInput(app->display, + w->window_handler, + ButtonPressMask | KeyPressMask | ExposureMask); + + Atom wmDelete = XInternAtom(app->display, "WM_DELETE_WINDOW", True); + XSetWMProtocols(app->display, w->window_handler, &wmDelete, 1); + + Atom wmDispose = XInternAtom(app->display, "CHERRY_DISPOSE_ON_EXIT", True); + XSetWMProtocols(app->display, w->window_handler, &wmDelete, 1); w->gc = XCreateGC(app->display, w->window_handler, 0, 0); XSetBackground(app->display, w->gc, WhitePixel(app->display, app->screen)); -- cgit v1.2.3