Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gtk2: backport some event handling patches fixing high CPU usage. Fixes
- Loading branch information
Showing
3 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
mingw-w64-gtk2/0020-GDK-W32-Always-process-all-available-messages.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
From bfdac2f70e005b2504cc3f4ebbdab328974d005a Mon Sep 17 00:00:00 2001 | ||
From: Jeremy Tan <jtanx@outlook.com> | ||
Date: Sat, 17 Sep 2016 17:19:59 +0800 | ||
Subject: [PATCH 06/25] GDK W32: Always process all available messages | ||
|
||
The GLib main loop blocks on MsgWaitForMultipleObjectsEx to | ||
determine if there are any incoming messages while also allowing | ||
for background tasks to run. If all available messages are not | ||
processed after MsgWaitForMultipleObjectsEx has signaled that | ||
there are available, CPU usage will skyrocket. | ||
|
||
From my limited understanding (by inspection of profiling | ||
under Visual Studio): | ||
Key is pressed - MsgWaitForMultipleObjectsEx unblocks, and | ||
sends message to GDK's event handler. Some event is now queued. | ||
|
||
g_poll unblocks, calls the g_event_dispatch which finally | ||
resolves to gdk_event_dispatch. This then calls | ||
_gdk_win32_display_queue_events, but since a message is already | ||
queued, it fails to call PeekMessage and returns immediately. | ||
|
||
At the next iteration, g_poll again calls MsgWaitForMultipleObjectsEx | ||
which queues yet another event and returns almost immediately, since | ||
there are events available which haven't been processed by PeekMessage. | ||
|
||
The dispatch function is then called and the process repeats. | ||
|
||
https://bugzilla.gnome.org/show_bug.cgi?id=771568 | ||
--- | ||
gdk/win32/gdkevents-win32.c | 3 +-- | ||
1 file changed, 1 insertion(+), 2 deletions(-) | ||
|
||
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c | ||
index 9b09edd052..e52f21c52e 100644 | ||
--- a/gdk/win32/gdkevents-win32.c | ||
+++ b/gdk/win32/gdkevents-win32.c | ||
@@ -3622,8 +3622,7 @@ _gdk_events_queue (GdkDisplay *display) | ||
if (modal_win32_dialog != NULL) | ||
return; | ||
|
||
- while (!_gdk_event_queue_find_first (display) && | ||
- PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE)) | ||
+ while (PeekMessageW (&msg, NULL, 0, 0, PM_REMOVE)) | ||
{ | ||
TranslateMessage (&msg); | ||
DispatchMessageW (&msg); | ||
-- | ||
2.19.1 | ||
|
36 changes: 36 additions & 0 deletions
36
mingw-w64-gtk2/0021-GDK-W32-Ignore-autorepeated-key-presses-on-modifier-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
From 61162225f712df648f38fd12bc0817cfa9f79a64 Mon Sep 17 00:00:00 2001 | ||
From: Jeremy Tan <jtanx@outlook.com> | ||
Date: Sat, 17 Sep 2016 20:46:30 +0800 | ||
Subject: [PATCH 07/25] GDK W32: Ignore autorepeated key presses on modifier | ||
keys | ||
|
||
The X11 backend does not send autorepeated messages for modifier keys, | ||
and doing so prevents motion compression from working. | ||
|
||
https://bugzilla.gnome.org/show_bug.cgi?id=771568 | ||
--- | ||
gdk/win32/gdkevents-win32.c | 8 ++++++++ | ||
1 file changed, 8 insertions(+) | ||
|
||
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c | ||
index e52f21c52e..ac91fa64cb 100644 | ||
--- a/gdk/win32/gdkevents-win32.c | ||
+++ b/gdk/win32/gdkevents-win32.c | ||
@@ -2274,6 +2274,14 @@ gdk_event_translate (MSG *msg, | ||
in_ime_composition) | ||
break; | ||
|
||
+ /* Ignore autorepeats on modifiers */ | ||
+ if (msg->message == WM_KEYDOWN && | ||
+ (msg->wParam == VK_MENU || | ||
+ msg->wParam == VK_CONTROL || | ||
+ msg->wParam == VK_SHIFT) && | ||
+ ((HIWORD(msg->lParam) & KF_REPEAT) >= 1)) | ||
+ break; | ||
+ | ||
if (!propagate (&window, msg, | ||
_gdk_display->keyboard_grab.window, | ||
_gdk_display->keyboard_grab.owner_events, | ||
-- | ||
2.19.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters