aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-06 15:55:42 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-06 15:55:42 +0100
commitcb679636f77fe2a03e8dab3a511e28e1ab898316 (patch)
treeb03cada4a37a50eb50cef1e21c75c56d938868a8 /src/window
parente2e7c0bf0747d55967c4be6374f3611cd96babb6 (diff)
Fix exit being called when closing window, respond to wm ping, add is_open function to window
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c27
1 files changed, 26 insertions, 1 deletions
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 <errno.h>
#include <stdio.h>
+/* 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;
+}