Commit a3f52949 authored by Martin Nordholts's avatar Martin Nordholts

Bug 633291 - Handle Shift-keys in X11 gdk_test_simulate_key()

If a level 1 key maps to a key value passed to
gdk_test_simulate_key(), raise the GDK_SHIFT_MASK flag so the reqested
key value is generated. Also add a regression test for this fix.
parent 932ab55c
......@@ -94,12 +94,17 @@ _gdk_x11_window_simulate_key (GdkWindow *window,
{
gint i;
for (i = 0; i < n_keys; i++)
if (keys[i].group == 0 && keys[i].level == 0)
if (keys[i].group == 0 && (keys[i].level == 0 || keys[i].level == 1))
{
xev.keycode = keys[i].keycode;
if (keys[i].level == 1)
{
/* Assume shift takes us to level 1 */
xev.state |= GDK_SHIFT_MASK;
}
break;
}
if (i >= n_keys) /* no match for group==0 and level==0 */
if (i >= n_keys) /* no match for group==0 and level==0 or 1 */
xev.keycode = keys[0].keycode;
}
g_free (keys);
......
......@@ -22,6 +22,12 @@
#include <string.h>
#include <math.h>
/* Use a keyval that requires Shift to be active (in typical layouts)
* like GDK_KEY_ampersand, which is '<shift>6'
*/
#define KEYVAL_THAT_REQUIRES_SHIFT GDK_KEY_ampersand
/* --- test functions --- */
static void
test_button_clicks (void)
......@@ -71,6 +77,40 @@ test_button_keys (void)
g_assert (c == 0);
}
static gboolean
store_last_key_release (GtkWidget *widget,
GdkEventKey *event,
gpointer user_data)
{
*((gint *)user_data) = event->keyval;
return FALSE;
}
static void
test_send_shift_key (void)
{
GtkWidget *window = gtk_test_display_button_window ("Test Window",
"Test: test_send_shift_key()",
"IgnoreMe1", NULL,
"SendMeKeys", NULL,
"IgnoreMe2", NULL,
NULL);
GtkWidget *button = gtk_test_find_widget (window, "SendMeKeys", GTK_TYPE_BUTTON);
gint last_key_release = 0;
gboolean simsuccess;
g_assert (button != NULL);
g_signal_connect (button, "key-release-event",
G_CALLBACK (store_last_key_release),
&last_key_release);
gtk_widget_grab_focus (button);
g_assert (gtk_widget_has_focus (button));
simsuccess = gtk_test_widget_send_key (button, KEYVAL_THAT_REQUIRES_SHIFT, 0 /*modifiers*/);
g_assert (simsuccess == TRUE);
while (gtk_events_pending ())
gtk_main_iteration ();
g_assert_cmpint (KEYVAL_THAT_REQUIRES_SHIFT, ==, last_key_release);
}
static void
test_slider_ranges (void)
{
......@@ -261,6 +301,7 @@ main (int argc,
g_test_add_func ("/ui-tests/text-access", test_text_access);
g_test_add_func ("/ui-tests/button-clicks", test_button_clicks);
g_test_add_func ("/ui-tests/keys-events", test_button_keys);
g_test_add_func ("/ui-tests/send-shift-key", test_send_shift_key);
g_test_add_func ("/ui-tests/slider-ranges", test_slider_ranges);
g_test_add_func ("/ui-tests/xserver-sync", test_xserver_sync);
g_test_add_func ("/ui-tests/spin-button-arrows", test_spin_button_arrows);
......
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