Commit 2b64efc1 authored by Jehan's avatar Jehan

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.
parent b1fc539f
......@@ -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 */
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment