From 2a8c11d69bf6fb05a3836018c682c05e8fd7c021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 1 Apr 2022 19:14:48 +0200 Subject: [PATCH] input-capture: Add D-Bus method to clear barriers This will be needed by the portal backend. Part-of: --- .../org.gnome.Mutter.InputCapture.xml | 2 + src/backends/meta-input-capture-session.c | 22 ++++++++++ src/tests/input-capture-test-client.c | 43 +++++++++++++++++++ src/tests/input-capture-tests.c | 43 +++++++++++++++++++ 4 files changed, 110 insertions(+) diff --git a/data/dbus-interfaces/org.gnome.Mutter.InputCapture.xml b/data/dbus-interfaces/org.gnome.Mutter.InputCapture.xml index c361b9744..858c03c39 100644 --- a/data/dbus-interfaces/org.gnome.Mutter.InputCapture.xml +++ b/data/dbus-interfaces/org.gnome.Mutter.InputCapture.xml @@ -44,6 +44,8 @@ + + diff --git a/src/backends/meta-input-capture-session.c b/src/backends/meta-input-capture-session.c index 9a59ffda7..807925187 100644 --- a/src/backends/meta-input-capture-session.c +++ b/src/backends/meta-input-capture-session.c @@ -532,6 +532,27 @@ handle_add_barrier (MetaDBusInputCaptureSession *object, return G_DBUS_METHOD_INVOCATION_HANDLED; } +static gboolean +handle_clear_barriers (MetaDBusInputCaptureSession *object, + GDBusMethodInvocation *invocation) +{ + MetaInputCaptureSession *session = META_INPUT_CAPTURE_SESSION (object); + + if (!check_permission (session, invocation)) + { + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, + G_DBUS_ERROR_ACCESS_DENIED, + "Permission denied"); + return G_DBUS_METHOD_INVOCATION_HANDLED; + } + + g_hash_table_remove_all (session->barriers); + + meta_dbus_input_capture_session_complete_clear_barriers (object, invocation); + + return G_DBUS_METHOD_INVOCATION_HANDLED; +} + static gboolean handle_get_zones (MetaDBusInputCaptureSession *object, GDBusMethodInvocation *invocation) @@ -749,6 +770,7 @@ static void meta_input_capture_session_init_iface (MetaDBusInputCaptureSessionIface *iface) { iface->handle_add_barrier = handle_add_barrier; + iface->handle_clear_barriers = handle_clear_barriers; iface->handle_enable = handle_enable; iface->handle_disable = handle_disable; iface->handle_release = handle_release; diff --git a/src/tests/input-capture-test-client.c b/src/tests/input-capture-test-client.c index 8693fb829..a71e69a8e 100644 --- a/src/tests/input-capture-test-client.c +++ b/src/tests/input-capture-test-client.c @@ -250,6 +250,16 @@ input_capture_session_add_barrier (InputCaptureSession *session, return barrier_id; } +static void +input_capture_session_clear_barriers (InputCaptureSession *session) +{ + g_autoptr (GError) error = NULL; + + if (!meta_dbus_input_capture_session_call_clear_barriers_sync ( + session->proxy, NULL, &error)) + g_warning ("Failed to clear barriers: %s", error->message); +} + static void input_capture_session_enable (InputCaptureSession *session) { @@ -479,6 +489,38 @@ test_barriers (void) input_capture_session_close (session); } +static void +test_clear_barriers (void) +{ + InputCapture *input_capture; + InputCaptureSession *session; + g_autolist (Zone) zones = NULL; + BarriersTestData data = {}; + + input_capture = input_capture_new (); + session = input_capture_create_session (input_capture); + + zones = input_capture_session_get_zones (session); + + input_capture_session_add_barrier (session, 0, 0, 0, 600); + + g_signal_connect (session->proxy, "activated", + G_CALLBACK (on_activated), &data); + + input_capture_session_enable (session); + + write_state (session, "1"); + + while (data.activated_barrier_id == 0) + g_main_context_iteration (NULL, TRUE); + + input_capture_session_clear_barriers (session); + write_state (session, "2"); + wait_for_state (session, "1"); + + input_capture_session_close (session); +} + static const struct { const char *name; @@ -487,6 +529,7 @@ static const struct { "sanity", test_sanity, }, { "zones", test_zones, }, { "barriers", test_barriers, }, + { "clear-barriers", test_clear_barriers, }, }; static void diff --git a/src/tests/input-capture-tests.c b/src/tests/input-capture-tests.c index 9e1eceb71..867949565 100644 --- a/src/tests/input-capture-tests.c +++ b/src/tests/input-capture-tests.c @@ -285,6 +285,47 @@ meta_test_input_capture_barriers (void) input_capture_test_client_finish (test_client); } +static void +meta_test_input_capture_clear_barriers (void) +{ + MetaBackend *backend = meta_context_get_backend (test_context); + ClutterSeat *seat = meta_backend_get_default_seat (backend); + g_autoptr (MetaVirtualMonitor) virtual_monitor1 = NULL; + g_autoptr (MetaVirtualMonitor) virtual_monitor2 = NULL; + g_autoptr (ClutterVirtualInputDevice) virtual_pointer = NULL; + InputCaptureTestClient *test_client; + + virtual_monitor1 = meta_create_test_monitor (test_context, 800, 600, 20.0); + + virtual_pointer = clutter_seat_create_virtual_device (seat, + CLUTTER_POINTER_DEVICE); + clutter_virtual_input_device_notify_absolute_motion (virtual_pointer, + g_get_monotonic_time (), + 10.0, 10.0); + + test_client = input_capture_test_client_new ("clear-barriers"); + input_capture_test_client_wait_for_state (test_client, "1"); + + clutter_virtual_input_device_notify_relative_motion (virtual_pointer, + g_get_monotonic_time (), + -20.0, 0.0); + meta_flush_input (test_context); + meta_wait_for_paint (test_context); + assert_pointer_position (seat, 0.0, 10.0); + + input_capture_test_client_wait_for_state (test_client, "2"); + + clutter_virtual_input_device_notify_relative_motion (virtual_pointer, + g_get_monotonic_time (), + 10.0, 10.0); + meta_flush_input (test_context); + meta_wait_for_paint (test_context); + assert_pointer_position (seat, 10.0, 20.0); + + input_capture_test_client_write_state (test_client, "1"); + input_capture_test_client_finish (test_client); +} + static void init_tests (void) { @@ -294,6 +335,8 @@ init_tests (void) meta_test_input_capture_zones); g_test_add_func ("/backends/native/input-capture/barriers", meta_test_input_capture_barriers); + g_test_add_func ("/backends/native/input-capture/clear-barriers", + meta_test_input_capture_clear_barriers); } int