From b7078ddab798cc1f121efe60dca3b7a610d19cc5 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 10 Oct 2023 14:37:27 +1000 Subject: [PATCH] input-capture: Fix off-by-one for barrier validation Assuming two 1920x1080 screens next to each other: a horizontal barrier starting at 1920 going east is always outside the left screen. Assuming two 1920x1080 screens on top of each other: a vertical barrier starting at 1080 going south is always outside the top screen. Part-of: --- src/backends/meta-input-capture-session.c | 4 ++-- src/tests/input-capture-test-client.c | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/backends/meta-input-capture-session.c b/src/backends/meta-input-capture-session.c index 88076f4d7..ddf4b6d7e 100644 --- a/src/backends/meta-input-capture-session.c +++ b/src/backends/meta-input-capture-session.c @@ -640,7 +640,7 @@ get_barrier_adjacency (MtkRectangle *rect, return LINE_ADJACENCY_NONE; if (y_max < rect->y || - y_min > rect->y + rect->height) + y_min >= rect->y + rect->height) return LINE_ADJACENCY_NONE; if (rect->x + rect->width == x || rect->x == x) @@ -664,7 +664,7 @@ get_barrier_adjacency (MtkRectangle *rect, return LINE_ADJACENCY_NONE; if (x_max < rect->x || - x_min > rect->x + rect->width) + x_min >= rect->x + rect->width) return LINE_ADJACENCY_NONE; if (rect->y + rect->height == y || rect->y == y) diff --git a/src/tests/input-capture-test-client.c b/src/tests/input-capture-test-client.c index f9c9cecb4..759883e11 100644 --- a/src/tests/input-capture-test-client.c +++ b/src/tests/input-capture-test-client.c @@ -683,7 +683,7 @@ test_barriers (void) InputCapture *input_capture; InputCaptureSession *session; g_autolist (Zone) zones = NULL; - unsigned int barrier1, barrier2; + unsigned int barrier1, barrier2, barrier3; BarriersTestData data = {}; unsigned int prev_activated_serial; @@ -693,20 +693,24 @@ test_barriers (void) zones = input_capture_session_get_zones (session); /* - * +-------------+--------------+ - * || | | - * ||<--B#1 | | - * || | B#2 | - * +-------------+ | | - * | V | + * +-------------+==============+ + * || | ^ | + * ||<--B#1 | | | + * || | B#2 B#3 | + * +-------------+ | | + * | V | * +==============+ */ 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); g_assert_cmpuint (barrier1, !=, 0); g_assert_cmpuint (barrier2, !=, 0); + g_assert_cmpuint (barrier3, !=, 0); g_assert_cmpuint (barrier1, !=, barrier2); + g_assert_cmpuint (barrier1, !=, barrier3); + g_assert_cmpuint (barrier2, !=, barrier3); g_signal_connect (session->proxy, "activated", G_CALLBACK (on_activated), &data);