[gimp] tests: gimp_test_utils_synthesize_key_event() not working for win32.



commit 2b64efc11d50e2d714827205cba13cdd9af32eea
Author: Jehan <jehan girinstud io>
Date:   Fri Aug 15 16:35:57 2014 +0000

    tests: gimp_test_utils_synthesize_key_event() not working for win32.
    
    gdk_test_simulate_key() has currently no win32 implementation.
    Add this implementation in our code until a patch to GTK+ for this is
    merged. This fixes 2 `make check` tests for win32.

 app/tests/gimp-app-test-utils.c |   76 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/app/tests/gimp-app-test-utils.c b/app/tests/gimp-app-test-utils.c
index 395d5a4..850764e 100644
--- a/app/tests/gimp-app-test-utils.c
+++ b/app/tests/gimp-app-test-utils.c
@@ -37,6 +37,16 @@
 
 #include "gimp-app-test-utils.h"
 
+#ifdef G_OS_WIN32
+/* SendInput() requirement is Windows 2000 pro or over.
+ * We may need to set WINVER to make sure the compiler does not try to
+ * compile for on older version of win32, thus breaking the build.
+ * See
+ * http://msdn.microsoft.com/en-us/library/aa383745%28v=vs.85%29.aspx#setting_winver_or__win32_winnt
+ */
+#define WINVER 0x0500
+#include <windows.h>
+#endif /* G_OS_WIN32 */
 
 void
 gimp_test_utils_set_env_to_subpath (const gchar *root_env_var,
@@ -153,6 +163,71 @@ void
 gimp_test_utils_synthesize_key_event (GtkWidget *widget,
                                       guint      keyval)
 {
+#ifdef G_OS_WIN32
+  /* gdk_test_simulate_key() has no implementation for win32 currently.
+   * Use this for now. */
+  GdkKeymapKey *keys   = NULL;
+  gint          n_keys = 0;
+  INPUT         ip;
+  gint          i;
+
+  ip.type = INPUT_KEYBOARD;
+  ip.ki.wScan = 0;
+  ip.ki.time = 0;
+  ip.ki.dwExtraInfo = 0;
+  if (gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), keyval, &keys, &n_keys))
+    {
+      for (i = 0; i < n_keys; i++)
+        {
+          ip.ki.dwFlags = 0;
+          /* AltGr press. */
+          if (keys[i].group)
+            {
+              /* According to some virtualbox code I found, AltGr is
+               * simulated on win32 with LCtrl+RAlt */
+              ip.ki.wVk = VK_CONTROL;
+              SendInput(1, &ip, sizeof(INPUT));
+              ip.ki.wVk = VK_MENU;
+              SendInput(1, &ip, sizeof(INPUT));
+            }
+          /* Shift press. */
+          if (keys[i].level)
+            {
+              ip.ki.wVk = VK_SHIFT;
+              SendInput(1, &ip, sizeof(INPUT));
+            }
+          /* Key pressed. */
+          ip.ki.wVk = keys[i].keycode;
+          SendInput(1, &ip, sizeof(INPUT));
+
+          ip.ki.dwFlags = KEYEVENTF_KEYUP;
+          /* Key released. */
+          SendInput(1, &ip, sizeof(INPUT));
+          /* Shift release. */
+          if (keys[i].level)
+            {
+              ip.ki.wVk = VK_SHIFT;
+              SendInput(1, &ip, sizeof(INPUT));
+            }
+          /* AltrGr release. */
+          if (keys[i].group)
+            {
+              ip.ki.wVk = VK_MENU;
+              SendInput(1, &ip, sizeof(INPUT));
+              ip.ki.wVk = VK_CONTROL;
+              SendInput(1, &ip, sizeof(INPUT));
+            }
+          /* No need to loop for alternative keycodes. We want only one
+           * key generated. */
+          break;
+        }
+      g_free (keys);
+    }
+  else
+    {
+      g_warning ("%s: no win32 key mapping found for keyval %d.", G_STRFUNC, keyval);
+    }
+#else /* G_OS_WIN32 */
   gdk_test_simulate_key (gtk_widget_get_window (widget),
                          -1, -1, /*x, y*/
                          keyval,
@@ -163,6 +238,7 @@ gimp_test_utils_synthesize_key_event (GtkWidget *widget,
                          keyval,
                          0 /*modifiers*/,
                          GDK_KEY_RELEASE);
+#endif /* G_OS_WIN32 */
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]