1
0
Fork 0

input-capture: Add D-Bus method to clear barriers

This will be needed by the portal backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
This commit is contained in:
Jonas Ådahl 2022-04-01 19:14:48 +02:00 committed by Carlos Garnacho
parent 1d1983edb5
commit 2a8c11d69b
4 changed files with 110 additions and 0 deletions

View file

@ -44,6 +44,8 @@
<arg name="id" type="u" direction="out" />
</method>
<method name="ClearBarriers" />
<method name="Enable" />
<method name="Disable" />

View file

@ -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;

View file

@ -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

View file

@ -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