From 7acea115d95f57427ff8e34411d25ef5d9f46f49 Mon Sep 17 00:00:00 2001
From: dec05eba <dec05eba@protonmail.com>
Date: Wed, 27 Nov 2024 19:33:20 +0100
Subject: Only do XCheckTypedWindowEvent if not injected event

---
 src/window/window.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

(limited to 'src')

diff --git a/src/window/window.c b/src/window/window.c
index 5fcd466..2efb161 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -1373,7 +1373,7 @@ static bool mgl_on_rr_notify(mgl_context *context, x11_context *x11_context, XEv
     return false;
 }
 
-static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event *event, mgl_context *context) {
+static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event *event, mgl_context *context, bool injected) {
     x11_context *x11_context = self->context;
     switch(xev->type - context->randr_event_base) {
         case RRScreenChangeNotify: {
@@ -1465,7 +1465,9 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event
             return;
         }
         case ConfigureNotify: {
-            while(XCheckTypedWindowEvent(context->connection, self->window, ConfigureNotify, xev)) {}
+            if(!injected)
+                while(XCheckTypedWindowEvent(context->connection, self->window, ConfigureNotify, xev)) {}
+
             if(xev->xconfigure.x != self->pos.x || xev->xconfigure.y != self->pos.y) {
                 mgl_window_on_move(self, xev->xconfigure.x, xev->xconfigure.y);
             }
@@ -1483,7 +1485,9 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event
             return;
         }
         case MotionNotify: {
-            while(XCheckTypedWindowEvent(context->connection, self->window, MotionNotify, xev)) {}
+            if(!injected)
+                while(XCheckTypedWindowEvent(context->connection, self->window, MotionNotify, xev)) {}
+
             self->cursor_position.x = xev->xmotion.x;
             self->cursor_position.y = xev->xmotion.y;
 
@@ -1593,7 +1597,7 @@ bool mgl_window_poll_event(mgl_window *self, mgl_event *event) {
         XEvent xev; /* TODO: Move to window struct */
         XNextEvent(display, &xev);
         if(xev.xany.window == self->window || xev.type == ClientMessage || xev.type - context->randr_event_base >= 0)
-            mgl_window_on_receive_event(self, &xev, event, context);
+            mgl_window_on_receive_event(self, &xev, event, context, false);
         else
             event->type = MGL_EVENT_UNKNOWN;
         return true;
@@ -1605,7 +1609,7 @@ bool mgl_window_poll_event(mgl_window *self, mgl_event *event) {
 bool mgl_window_inject_x11_event(mgl_window *self, XEvent *xev, mgl_event *event) {
     mgl_context *context = mgl_get_context();
     event->type = MGL_EVENT_UNKNOWN;
-    mgl_window_on_receive_event(self, xev, event, context);
+    mgl_window_on_receive_event(self, xev, event, context, true);
     return event->type != MGL_EVENT_UNKNOWN;
 }
 
-- 
cgit v1.2.3-70-g09d2