From cb679636f77fe2a03e8dab3a511e28e1ab898316 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 6 Nov 2021 15:55:42 +0100 Subject: Fix exit being called when closing window, respond to wm ping, add is_open function to window --- src/window/window.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/window') diff --git a/src/window/window.c b/src/window/window.c index 30abebb..b7f9fd8 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -5,6 +5,8 @@ #include #include +/* TODO: Use gl OML present for other platforms than nvidia? nvidia doesn't support present yet */ + /* TODO: check for glx swap control extension string (GLX_EXT_swap_control, etc) */ static void set_vertical_sync_enabled(Window window, int enabled) { int result = 0; @@ -95,6 +97,12 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h XMapWindow(context->connection, self->window); } + /* TODO: Call XGetWMProtocols and add wm_delete_window_atom on top, to not overwrite existing wm protocol atoms */ + Atom wm_protocol_atoms[2] = { + context->wm_delete_window_atom, + context->net_wm_ping_atom + }; + XSetWMProtocols(context->connection, self->window, wm_protocol_atoms, 2); XFlush(context->connection); /* TODO: Check for failure? */ @@ -118,6 +126,7 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h XQueryPointer(context->connection, self->window, &dummy_w, &dummy_w, &dummy_i, &dummy_i, &self->cursor_position.x, &self->cursor_position.y, &dummy_u); mgl_window_on_resize(self, gwa.width, gwa.height); + self->open = true; return 0; } @@ -246,7 +255,7 @@ static bool mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event event->size.height = self->size.y; return true; } - return false; + break; } case MotionNotify: { while(XCheckTypedWindowEvent(mgl_get_context()->connection, self->window, MotionNotify, xev)) {} @@ -258,6 +267,18 @@ static bool mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event event->mouse_move.y = self->cursor_position.y; return true; } + case ClientMessage: { + mgl_context *context = mgl_get_context(); + if(xev->xclient.format == 32 && (unsigned long)xev->xclient.data.l[0] == context->wm_delete_window_atom) { + event->type = MGL_EVENT_CLOSED; + self->open = false; + return true; + } else if(xev->xclient.format == 32 && (unsigned long)xev->xclient.data.l[0] == context->net_wm_ping_atom) { + xev->xclient.window = DefaultRootWindow(context->connection); + XSendEvent(context->connection, DefaultRootWindow(context->connection), False, SubstructureNotifyMask | SubstructureRedirectMask, xev); + } + break; + } } /*fprintf(stderr, "unhandled event type: %d\n", xev->type);*/ event->type = MGL_EVENT_UNKNOWN; @@ -300,3 +321,7 @@ void mgl_window_set_view(mgl_window *self, mgl_view *new_view) { void mgl_window_get_view(mgl_window *self, mgl_view *view) { *view = self->view; } + +bool mgl_window_is_open(const mgl_window *self) { + return self->open; +} -- cgit v1.2.3