From f6d96a61181a2c21b560182f429ab54cf7953e06 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 7 Dec 2022 21:28:45 +0100 Subject: [PATCH] tests/stacking: Add support for moving the cursor and clicking Also test that clicking on a window will focus and raise it. Part-of: --- src/tests/meson.build | 1 + .../click-to-focus-and-raise.metatest | 33 ++++++++++++++++++ src/tests/test-runner.c | 34 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/tests/stacking/click-to-focus-and-raise.metatest diff --git a/src/tests/meson.build b/src/tests/meson.build index 64a37b84f..0ff50c043 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -488,6 +488,7 @@ stacking_tests = [ 'always-on-top', 'focus-default-window-globally-active-input', 'workspace-unmanaging-window', + 'click-to-focus-and-raise', ] foreach stacking_test: stacking_tests diff --git a/src/tests/stacking/click-to-focus-and-raise.metatest b/src/tests/stacking/click-to-focus-and-raise.metatest new file mode 100644 index 000000000..c6faeb552 --- /dev/null +++ b/src/tests/stacking/click-to-focus-and-raise.metatest @@ -0,0 +1,33 @@ +resize_monitor primary 800 600 + +new_client w wayland + +create w/1 csd +resize w/1 100 100 +show w/1 + +create w/2 csd +resize w/2 100 100 +show w/2 + +wait_reconfigure + +move w/1 0 0 +move w/2 100 0 + +wait_reconfigure + +assert_stacking w/1 w/2 +assert_focused w/2 + +assert_position w/1 0 0 +assert_size w/1 100 100 +assert_position w/2 100 0 +assert_size w/2 100 100 + +move_cursor_to 50 50 +click +wait + +assert_stacking w/2 w/1 +assert_focused w/1 diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index 4ca0facac..94017fd1a 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -43,6 +43,7 @@ typedef struct { GMainLoop *loop; gulong x11_display_opened_handler_id; MetaVirtualMonitor *virtual_monitor; + ClutterVirtualInputDevice *pointer; } TestCase; static gboolean @@ -76,6 +77,8 @@ test_case_new (MetaContext *context) { TestCase *test = g_new0 (TestCase, 1); MetaDisplay *display = meta_context_get_display (context); + MetaBackend *backend = meta_context_get_backend (context); + ClutterSeat *seat = meta_backend_get_default_seat (backend); if (display->x11_display) { @@ -93,6 +96,8 @@ test_case_new (MetaContext *context) test->clients = g_hash_table_new (g_str_hash, g_str_equal); test->loop = g_main_loop_new (NULL, FALSE); test->virtual_monitor = meta_create_test_monitor (context, 800, 600, 60.0); + test->pointer = clutter_seat_create_virtual_device (seat, + CLUTTER_POINTER_DEVICE); return test; } @@ -1170,6 +1175,34 @@ test_case_do (TestCase *test, meta_display_focus_default_window (display, timestamp); } + else if (strcmp (argv[0], "move_cursor_to") == 0) + { + if (argc != 3) + BAD_COMMAND("usage: %s ", argv[0]); + + float x = atof (argv[1]); + float y = atof (argv[2]); + + clutter_virtual_input_device_notify_absolute_motion (test->pointer, + CLUTTER_CURRENT_TIME, + x, y); + meta_flush_input (test->context); + } + else if (strcmp (argv[0], "click") == 0) + { + if (argc != 1) + BAD_COMMAND("usage: %s", argv[0]); + + clutter_virtual_input_device_notify_button (test->pointer, + CLUTTER_CURRENT_TIME, + CLUTTER_BUTTON_PRIMARY, + CLUTTER_BUTTON_STATE_PRESSED); + clutter_virtual_input_device_notify_button (test->pointer, + CLUTTER_CURRENT_TIME, + CLUTTER_BUTTON_PRIMARY, + CLUTTER_BUTTON_STATE_RELEASED); + meta_flush_input (test->context); + } else { BAD_COMMAND("Unknown command %s", argv[0]); @@ -1220,6 +1253,7 @@ test_case_destroy (TestCase *test, g_hash_table_destroy (test->clients); g_object_unref (test->virtual_monitor); + g_object_unref (test->pointer); g_free (test); return TRUE;