aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-16 01:41:57 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-16 01:41:57 +0100
commit4c46bd7916ba692d75c5ee94099151b81695c48e (patch)
tree5b01b6c6d8c546f37f31202b4549d26ca044373b /src
parentb6ceb4af109f26885c91f01d0a63593158e567fa (diff)
Window: add function to check if the window has focus
Diffstat (limited to 'src')
-rw-r--r--src/window/window.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/window/window.c b/src/window/window.c
index f743ef0..440eecb 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -197,6 +197,7 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h
self->window = 0;
self->context = NULL;
self->open = false;
+ self->focused = false;
self->frame_time_limit = 0.0;
mgl_clock_init(&self->frame_timer);
@@ -313,6 +314,7 @@ static int mgl_window_init(mgl_window *self, const char *title, int width, int h
XSetICFocus(x11_context->xic);
self->open = true;
+ self->focused = false; /* TODO: Check if we need to call XGetInputFocus for this, or just wait for focus event */
return 0;
}
@@ -481,6 +483,16 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event
event->mouse_button.y = xev->xbutton.y;
return;
}
+ case FocusIn: {
+ event->type = MGL_EVENT_GAINED_FOCUS;
+ self->focused = true;
+ break;
+ }
+ case FocusOut: {
+ event->type = MGL_EVENT_LOST_FOCUS;
+ self->focused = false;
+ break;
+ }
case ConfigureNotify: {
while(XCheckTypedWindowEvent(context->connection, self->window, ConfigureNotify, xev)) {}
if(xev->xconfigure.width != self->size.x || xev->xconfigure.height != self->size.x) {
@@ -577,6 +589,10 @@ bool mgl_window_is_open(const mgl_window *self) {
return self->open;
}
+bool mgl_window_has_focus(const mgl_window *self) {
+ return self->focused;
+}
+
bool mgl_window_is_key_pressed(const mgl_window *self, mgl_key key) {
if(key < 0 || key >= __MGL_NUM_KEYS__)
return false;
@@ -585,7 +601,9 @@ bool mgl_window_is_key_pressed(const mgl_window *self, mgl_key key) {
void mgl_window_close(mgl_window *self) {
mgl_context *context = mgl_get_context();
+ XUnmapWindow(context->connection, self->window);
XDestroyWindow(context->connection, self->window);
+ XSync(context->connection, False);
self->open = false;
}