[Spice-commits] Branch '0.10' - 2 commits - client/windows

Uri Lublin uril at kemper.freedesktop.org
Thu Nov 24 09:20:10 PST 2011


 client/windows/red_window.cpp |   59 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 48 insertions(+), 11 deletions(-)

New commits:
commit 1ddeafdf2d4e2f96e2218ee014cb66bf13c9d955
Author: Gal Hammer <ghammer at redhat.com>
Date:   Mon Nov 14 12:51:39 2011 +0200

    client: handle the redundant right ctrl windows' message send when a alt-gr is pressed bz#709074
    
    Hello,
    
    The second patch check to see if Windows is sending a fake VK_CONTROL
    message when the user pressed Alt-Gr when using a non-US keyboard layout
    (German, Czech, etc...).
    
    If the function is_fake_ctrl return true and key event is translated to
    a REDKEY_INVALID and the event is discarded.
    
         Gal.
    (cherry picked from commit 9ffa2e9990dc5d5ae61c227d10d5234753c08402)

diff --git a/client/windows/red_window.cpp b/client/windows/red_window.cpp
index a474010..c86c458 100644
--- a/client/windows/red_window.cpp
+++ b/client/windows/red_window.cpp
@@ -52,6 +52,33 @@ static inline int to_red_mouse_state(WPARAM wParam)
            ((wParam & MK_RBUTTON) ? SPICE_MOUSE_BUTTON_MASK_RIGHT : 0);
 }
 
+// Return true if VK_RCONTROL is followed by a VK_RMENU with the same timestamp.
+static bool is_fake_ctrl(UINT message, WPARAM wParam, LPARAM lParam)
+{
+    if ((wParam == VK_CONTROL) && ((HIWORD (lParam) & KF_EXTENDED) == 0)) {
+        UINT next_peek;
+        if (message == WM_KEYDOWN) {
+            next_peek = WM_KEYDOWN;
+        } else if (message == WM_SYSKEYUP) {
+            next_peek = WM_KEYUP;
+        } else {
+            next_peek = WM_NULL;
+        }
+        if (next_peek != WM_NULL) {
+            MSG next_msg;
+            LONG time = GetMessageTime();
+            BOOL msg_exist = PeekMessage(&next_msg, NULL,
+                next_peek, next_peek, PM_NOREMOVE);
+            if ((msg_exist == TRUE) && (next_msg.time == time) &&
+                (next_msg.wParam == VK_MENU) &&
+                (HIWORD (next_msg.lParam) & KF_EXTENDED)) {
+                    return true;
+            }
+        }
+    }
+    return false;
+}
+
 static inline RedKey translate_key(UINT message, WPARAM wParam, LPARAM lParam)
 {
     uint32_t scan = HIWORD(lParam) & 0xff;
@@ -76,6 +103,13 @@ static inline RedKey translate_key(UINT message, WPARAM wParam, LPARAM lParam)
             return REDKEY_KOREAN_HANGUL;
         }
         break;
+    case VK_CONTROL:
+        // Ignore the fake right ctrl message which is send when alt-gr is
+        // pressed when using a non-US keyboard layout.
+        if (is_fake_ctrl(message, wParam, lParam)) {
+            return REDKEY_INVALID;
+        }
+        break;
     default:
         break;
     }
commit 97004c802655d920e526b3858aa76747bdf01f27
Author: Gal Hammer <ghammer at redhat.com>
Date:   Mon Nov 14 12:51:33 2011 +0200

    client: handle the redundant right ctrl windows' message send when a alt-gr is pressed bz#709074
    
    Hello,
    
    I first updated the translate_key function. It now requires the windows
    message as parameter (will be used later). It also use the raw wparam
    and lparam parameters in order to remove the code duplication when
    calling the function.
    
         Gal.
    (cherry picked from commit 33be8633f5712062752efe75adc745130a72c4c2)

diff --git a/client/windows/red_window.cpp b/client/windows/red_window.cpp
index 39960dc..a474010 100644
--- a/client/windows/red_window.cpp
+++ b/client/windows/red_window.cpp
@@ -52,12 +52,13 @@ static inline int to_red_mouse_state(WPARAM wParam)
            ((wParam & MK_RBUTTON) ? SPICE_MOUSE_BUTTON_MASK_RIGHT : 0);
 }
 
-static inline RedKey translate_key(int virtual_key, uint32_t scan, bool escape)
+static inline RedKey translate_key(UINT message, WPARAM wParam, LPARAM lParam)
 {
+    uint32_t scan = HIWORD(lParam) & 0xff;
     if (scan == 0) {
         return REDKEY_INVALID;
     }
-    switch (virtual_key) {
+    switch (wParam) {
     case VK_PAUSE:
         return REDKEY_PAUSE;
     case VK_SNAPSHOT:
@@ -74,13 +75,16 @@ static inline RedKey translate_key(int virtual_key, uint32_t scan, bool escape)
         } else if (scan == 0xf2) {
             return REDKEY_KOREAN_HANGUL;
         }
+        break;
     default:
-        //todo: always use vitrtual key
-        if (escape) {
-            scan += REDKEY_ESCAPE_BASE;
-        }
-        return (RedKey)scan;
+        break;
+    }
+    // TODO: always use virtual key
+    bool extended = ((HIWORD (lParam) & KF_EXTENDED) != 0);
+    if (extended) {
+        scan += REDKEY_ESCAPE_BASE;
     }
+    return (RedKey)scan;
 }
 
 static inline void send_filtered_keys(RedWindow* window)
@@ -214,7 +218,7 @@ LRESULT CALLBACK RedWindow_p::WindowProc(HWND hWnd, UINT message, WPARAM wParam,
         break;
     case WM_SYSKEYDOWN:
     case WM_KEYDOWN: {
-        RedKey key = translate_key(wParam, HIWORD(lParam) & 0xff, (lParam & (1 << 24)) != 0);
+        RedKey key = translate_key(message, wParam, lParam);
         window->get_listener().on_key_press(key);
 
         BYTE key_state[256];
@@ -237,7 +241,7 @@ LRESULT CALLBACK RedWindow_p::WindowProc(HWND hWnd, UINT message, WPARAM wParam,
     }
     case WM_SYSKEYUP:
     case WM_KEYUP: {
-        RedKey key = translate_key(wParam, HIWORD(lParam) & 0xff, (lParam & (1 << 24)) != 0);
+        RedKey key = translate_key(message, wParam, lParam);
         window->get_listener().on_key_release(key);
         break;
     }
@@ -1049,8 +1053,7 @@ static LRESULT CALLBACK MessageFilterProc(int nCode, WPARAM wParam, LPARAM lPara
         switch (msg->message) {
         case WM_SYSKEYUP:
         case WM_KEYUP: {
-            RedKey key = translate_key(msg->wParam, HIWORD(msg->lParam) & 0xff,
-                                       (msg->lParam & (1 << 24)) != 0);
+            RedKey key = translate_key(msg->message, wParam, lParam);
             filtered_up_keys.push_back(key);
             break;
         }


More information about the Spice-commits mailing list