Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/plugins/mousepad/valent-mousepad-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ valent_mousepad_plugin_mousepad_request_keyboard (ValentMousepadPlugin *self,

g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self));

if G_UNLIKELY (keysym == 0 && mask == 0)
return;

valent_packet_init (&builder, "kdeconnect.mousepad.request");

if ((special_key = valent_mousepad_keysym_to_keycode (keysym)) != 0)
Expand Down
9 changes: 8 additions & 1 deletion tests/fixtures/data/plugin-mousepad.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,14 @@
"id": 0,
"type": "kdeconnect.mousepad.request",
"body": {
"key": "test"
"key": "The quick brown fox jumps over the lazy dog"
}
},
"keyboard-keysym-unicode": {
"id": 0,
"type": "kdeconnect.mousepad.request",
"body": {
"key": "A©∑𝜑🚀"
}
}
}
102 changes: 69 additions & 33 deletions tests/plugins/mousepad/test-mousepad-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ static GQueue events = G_QUEUE_INIT;
g_free (_event_str); \
} G_STMT_END

static void
_valent_test_event_cmpstrv (const char *str)
{
const char *next = str;
gunichar codepoint;

while ((codepoint = g_utf8_get_char (next)) != 0)
{
uint32_t keysym = valent_input_unicode_to_keysym (codepoint);
char *event_str = NULL;
char *expected_str = NULL;

event_str = g_queue_pop_head (&events);
expected_str = g_strdup_printf ("KEYSYM %u 1", keysym);
g_assert_cmpstr (event_str, ==, expected_str);
g_free (event_str);
g_free (expected_str);

event_str = g_queue_pop_head (&events);
expected_str = g_strdup_printf ("KEYSYM %u 0", keysym);
g_assert_cmpstr (event_str, ==, expected_str);
g_free (event_str);
g_free (expected_str);

next = g_utf8_next_char (next);
}
}

static void
on_event_state_changed (GActionGroup *group,
const char *name,
Expand Down Expand Up @@ -74,6 +102,7 @@ test_mousepad_plugin_handle_request (ValentTestFixture *fixture,
gconstpointer user_data)
{
JsonNode *packet;
const char *str;

VALENT_TEST_CHECK ("Plugin sends the keyboard state on connect");
valent_test_fixture_connect (fixture);
Expand Down Expand Up @@ -166,18 +195,20 @@ test_mousepad_plugin_handle_request (ValentTestFixture *fixture,
_valent_test_event_cmpstr ("KEYSYM 65361 1");
_valent_test_event_cmpstr ("KEYSYM 65361 0");

VALENT_TEST_CHECK ("Plugin handles a request to press-release a series of keysyms");
packet = valent_test_fixture_lookup_packet (fixture, "keyboard-keysym-string");
valent_test_fixture_handle_packet (fixture, packet);
static const char *keysym_tests[] = {
"keyboard-keysym-string",
"keyboard-keysym-unicode",
};

for (size_t i = 0; i < G_N_ELEMENTS (keysym_tests); i++)
{
VALENT_TEST_CHECK ("Plugin handles a request to press-release a series of keysyms");
packet = valent_test_fixture_lookup_packet (fixture, keysym_tests[i]);
valent_test_fixture_handle_packet (fixture, packet);

_valent_test_event_cmpstr ("KEYSYM 116 1");
_valent_test_event_cmpstr ("KEYSYM 116 0");
_valent_test_event_cmpstr ("KEYSYM 101 1");
_valent_test_event_cmpstr ("KEYSYM 101 0");
_valent_test_event_cmpstr ("KEYSYM 115 1");
_valent_test_event_cmpstr ("KEYSYM 115 0");
_valent_test_event_cmpstr ("KEYSYM 116 1");
_valent_test_event_cmpstr ("KEYSYM 116 0");
valent_packet_get_string (packet, "key", &str);
_valent_test_event_cmpstrv (str);
}
}

static void
Expand All @@ -186,6 +217,9 @@ test_mousepad_plugin_send_keyboard_request (ValentTestFixture *fixture,
{
GActionGroup *actions = G_ACTION_GROUP (fixture->device);
JsonNode *packet;
uint32_t keysym;
unsigned int mask;
gunichar *w;
GVariantDict dict;
gboolean watch = FALSE;

Expand Down Expand Up @@ -213,10 +247,6 @@ test_mousepad_plugin_send_keyboard_request (ValentTestFixture *fixture,
g_assert_true (g_action_group_get_action_enabled (actions, "mousepad.event"));

VALENT_TEST_CHECK ("Plugin action `mousepad.event` sends ASCII with modifiers");
uint32_t keysym;
unsigned int mask;
gunichar *w;

keysym = 'a';
mask = KEYMOD_KDE_MASK;

Expand Down Expand Up @@ -258,24 +288,30 @@ test_mousepad_plugin_send_keyboard_request (ValentTestFixture *fixture,

VALENT_TEST_CHECK ("Plugin action `mousepad.event` sends special keys "
"(aka non-printable ASCII");
// TODO iterate special keys
keysym = KEYSYM_F12;
mask = 0;

g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "keysym", "u", keysym);
g_variant_dict_insert (&dict, "mask", "u", mask);
g_action_group_activate_action (actions, "mousepad.event",
g_variant_dict_end (&dict));

packet = valent_test_fixture_expect_packet (fixture);
v_assert_packet_type (packet, "kdeconnect.mousepad.request");
v_assert_packet_cmpint (packet, "specialKey", ==, 32);
v_assert_packet_no_field (packet, "alt");
v_assert_packet_no_field (packet, "ctrl");
v_assert_packet_no_field (packet, "shift");
v_assert_packet_no_field (packet, "super");
json_node_unref (packet);
for (size_t i = 1; i < 33; i++)
{
keysym = valent_mousepad_keycode_to_keysym (i);
mask = 0;

g_variant_dict_init (&dict, NULL);
g_variant_dict_insert (&dict, "keysym", "u", keysym);
g_variant_dict_insert (&dict, "mask", "u", mask);
g_action_group_activate_action (actions, "mousepad.event",
g_variant_dict_end (&dict));

// Reserved keycodes should be skipped
if (keysym == 0)
continue;

packet = valent_test_fixture_expect_packet (fixture);
v_assert_packet_type (packet, "kdeconnect.mousepad.request");
v_assert_packet_cmpint (packet, "specialKey", ==, i);
v_assert_packet_no_field (packet, "alt");
v_assert_packet_no_field (packet, "ctrl");
v_assert_packet_no_field (packet, "shift");
v_assert_packet_no_field (packet, "super");
json_node_unref (packet);
}

valent_test_watch_clear (actions, &watch);
}
Expand Down
Loading