Bug 551724 - [Win32] Most dead key combinations no longer work
On Windows 10 build 18362 and later, PeekMessage fails unexpectedly
when looking for WM_DEADCHAR. The fix is to remove filter flags
OS.PM_QS_INPUT and OS.PM_QS_POSTMESSAGE which are redundant anyway.
This patch also fixes Bug 550059 and supersedes the fix for Bug 219750.
Change-Id: I1b38c536d70720a973314baccbea10a247e1a6c0
Signed-off-by: Nikita Nemkin <nikita@nemkin.ru>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 73616cc..b1e275c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -657,9 +657,14 @@
if (!OS.GetKeyboardState (keyboard)) return 0;
/* Translate the key to ASCII or UNICODE using the virtual keyboard */
- char [] result = new char [1];
- if (OS.ToUnicode (key, key, keyboard, result, 1, 0) == 1) return result [0];
- return 0;
+ char [] buffer = new char [1];
+ int len = OS.ToUnicode (key, key, keyboard, buffer, 1, 0);
+
+ /* If the key is a dead key, flush dead key state. */
+ while (len == -1) {
+ len = OS.ToUnicode (key, key, keyboard, buffer, 1, 0);
+ }
+ return (len != 0) ? buffer [0] : 0;
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java
index ad1f538..8909095 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java
@@ -1558,7 +1558,6 @@
if ((lParam & 0x40000000) != 0) return null;
}
- boolean lastDead = display.lastDead;
/* Clear last key and last ascii because a new key has been typed */
display.lastAscii = display.lastKey = 0;
display.lastVirtual = display.lastNull = display.lastDead = false;
@@ -1598,7 +1597,7 @@
if ((mapKey & 0x80000000) != 0) return null;
MSG msg = new MSG ();
- int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
+ int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD;
if (OS.PeekMessage (msg, hwnd, OS.WM_DEADCHAR, OS.WM_DEADCHAR, flags)) {
display.lastDead = true;
display.lastVirtual = mapKey == 0;
@@ -1607,17 +1606,6 @@
}
/*
- * When hitting accent keys twice in a row, PeekMessage only returns
- * a WM_DEADCHAR for the first WM_KEYDOWN. Ignore the second
- * WM_KEYDOWN and issue the key down event from inside WM_CHAR.
- */
- if (lastDead) {
- display.lastVirtual = mapKey == 0;
- display.lastKey = display.lastVirtual ? (int)wParam : mapKey;
- return null;
- }
-
- /*
* Bug in Windows. Somehow, the widget is becoming disposed after
* calling PeekMessage(). In rare circumstances, it seems that
* PeekMessage() can allow SWT listeners to run that might contain