From bbddf16690634fa90d643f8068dae06b7e480d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Uveri=C4=87?= Date: Mon, 3 May 2021 00:55:33 +0200 Subject: [PATCH 1/3] slow down event spamming in main loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dušan Uverić --- instantwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instantwm.c b/instantwm.c index 1f42e438..0c6ae7a6 100644 --- a/instantwm.c +++ b/instantwm.c @@ -3931,7 +3931,7 @@ run(void) /* main event loop */ XSync(dpy, False); while (running && !XNextEvent(dpy, &ev)) - if (handler[ev.type]) + if (handler[ev.type] && XEventsQueued(dpy, QueuedAlready) < 250) handler[ev.type](&ev); /* call handler */ } From e8b7177f863ad0992dd2197567543c0b97564871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Uveri=C4=87?= Date: Mon, 3 May 2021 09:19:57 +0200 Subject: [PATCH 2/3] lower queue event value for main loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dušan Uverić --- instantwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instantwm.c b/instantwm.c index 0c6ae7a6..cd9cdb13 100644 --- a/instantwm.c +++ b/instantwm.c @@ -3931,7 +3931,7 @@ run(void) /* main event loop */ XSync(dpy, False); while (running && !XNextEvent(dpy, &ev)) - if (handler[ev.type] && XEventsQueued(dpy, QueuedAlready) < 250) + if (handler[ev.type] && XEventsQueued(dpy, QueuedAlready) < 125) handler[ev.type](&ev); /* call handler */ } From e5de102facad1189ed9393c1c55fef9d4a0b1c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Uveri=C4=87?= Date: Thu, 6 May 2021 13:10:28 +0200 Subject: [PATCH 3/3] add ratelimit to main event loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dušan Uverić --- instantwm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/instantwm.c b/instantwm.c index cd9cdb13..918fb5cd 100644 --- a/instantwm.c +++ b/instantwm.c @@ -3928,11 +3928,19 @@ void run(void) { XEvent ev; + int ratelimit = 200; + int currentrate = 0; /* main event loop */ XSync(dpy, False); while (running && !XNextEvent(dpy, &ev)) - if (handler[ev.type] && XEventsQueued(dpy, QueuedAlready) < 125) + { + currentrate = XEventsQueued(dpy, QueuedAlready); + if (handler[ev.type] && currentrate < ratelimit) + { handler[ev.type](&ev); /* call handler */ + ratelimit = currentrate > 150 ? 10 : 200; + } + } } void