From 131a2f0b5c51fc821224bf7637ba58df0a5ae15a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Mar 2022 02:26:19 +0100 Subject: Set ic focus on focus, remove urgency hint on focus --- src/window/window.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/window/window.c') diff --git a/src/window/window.c b/src/window/window.c index 1df12e0..3f902e3 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -360,8 +360,6 @@ static int mgl_window_init(mgl_window *self, const char *title, const mgl_window return -1; } - 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; @@ -572,11 +570,23 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event return; } case FocusIn: { + x11_context *x11_context = self->context; + XSetICFocus(x11_context->xic); + + XWMHints* hints = XGetWMHints(context->connection, self->window); + if(hints) { + hints->flags &= ~XUrgencyHint; + XSetWMHints(context->connection, self->window, hints); + XFree(hints); + } + event->type = MGL_EVENT_GAINED_FOCUS; self->focused = true; return; } case FocusOut: { + x11_context *x11_context = self->context; + XUnsetICFocus(x11_context->xic); event->type = MGL_EVENT_LOST_FOCUS; self->focused = false; return; @@ -690,7 +700,8 @@ bool mgl_window_poll_event(mgl_window *self, mgl_event *event) { if(XPending(display)) { XEvent xev; /* TODO: Move to window struct */ XNextEvent(display, &xev); - mgl_window_on_receive_event(self, &xev, event, context); + if(xev.xany.window == self->window || event->type == ClientMessage) + mgl_window_on_receive_event(self, &xev, event, context); return true; } else { return false; -- cgit v1.2.3