From 85885c65396249d31d4f74c91706ca97e98abfc0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 23 Oct 2023 15:41:48 +1000 Subject: [PATCH] input-capture: Check barriers don't extend into nonexisting monitors Create a fake monitor region right of the right-most monitor and if a horizontal barrier extends into that region, fail the barrier. Barriers are aligned on the top/left edge of the pixel so the most natural barrier of (e.g. 0-1024) is also wrong - it's one pixel into the next monitor. Check this for nonexisting screens on the right too to avoid clients suddenly failing when multiple monitors are present. Part-of: --- src/backends/meta-input-capture-session.c | 27 +++++++++++++++++++++++ src/tests/input-capture-test-client.c | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/backends/meta-input-capture-session.c b/src/backends/meta-input-capture-session.c index ddf4b6d7e..73cb6e61f 100644 --- a/src/backends/meta-input-capture-session.c +++ b/src/backends/meta-input-capture-session.c @@ -748,6 +748,33 @@ check_barrier (MetaInputCaptureSession *session, } } + if (has_adjacent_monitor && y1 == y2) + { + MetaLogicalMonitor *monitor; + MetaLogicalMonitor *next; + MtkRectangle layout, fake_layout; + + monitor = meta_monitor_manager_get_logical_monitor_at (monitor_manager, 0, 0); + while ((next = meta_monitor_manager_get_logical_monitor_neighbor (monitor_manager, monitor, META_DISPLAY_RIGHT))) + monitor = next; + + layout = meta_logical_monitor_get_layout (monitor); + fake_layout = (MtkRectangle) { + .x = layout.x + layout.width, + .y = layout.y, + .width = layout.width, + .height = layout.height, + }; + + LineAdjacency adjacency = get_barrier_adjacency (&fake_layout, x1, y1, x2, y2, error); + if (adjacency != LINE_ADJACENCY_NONE) + { + g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, + "Line extends into nonexisting monitor region"); + return FALSE; + } + } + return has_adjacent_monitor; } diff --git a/src/tests/input-capture-test-client.c b/src/tests/input-capture-test-client.c index 759883e11..217f9fb35 100644 --- a/src/tests/input-capture-test-client.c +++ b/src/tests/input-capture-test-client.c @@ -702,8 +702,8 @@ test_barriers (void) * +==============+ */ barrier1 = input_capture_session_add_barrier (session, 0, 0, 0, 600); - barrier2 = input_capture_session_add_barrier (session, 800, 768, 1824, 768); - barrier3 = input_capture_session_add_barrier (session, 800, 0, 1824, 0); + barrier2 = input_capture_session_add_barrier (session, 800, 768, 1823, 768); + barrier3 = input_capture_session_add_barrier (session, 800, 0, 1823, 0); g_assert_cmpuint (barrier1, !=, 0); g_assert_cmpuint (barrier2, !=, 0);