From 45052aeafdbd8b8782878f6a1555ee4bd1b6c1f8 Mon Sep 17 00:00:00 2001 From: Mattia Formichetti Date: Tue, 11 Feb 2025 01:56:21 +0100 Subject: [PATCH] core/place: Normalize comparator functions to work_area coordinates Both northwest_cmp and northeast_cmp didn't account for the work_area's relative x and y coordinates which would lead to improper sorting on multi-monitor setups. To fix this, we pass the work_area when necessary and use it to offset the absolute coordinates. Part-of: --- src/core/place.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/place.c b/src/core/place.c index 8456934fe..574ef84f4 100644 --- a/src/core/place.c +++ b/src/core/place.c @@ -55,10 +55,12 @@ typedef enum static gint northwest_cmp (gconstpointer a, - gconstpointer b) + gconstpointer b, + gpointer user_data) { MetaWindow *aw = (gpointer) a; MetaWindow *bw = (gpointer) b; + MtkRectangle *area = user_data; MtkRectangle a_frame; MtkRectangle b_frame; int from_origin_a; @@ -67,10 +69,10 @@ northwest_cmp (gconstpointer a, meta_window_get_frame_rect (aw, &a_frame); meta_window_get_frame_rect (bw, &b_frame); - ax = a_frame.x; - ay = a_frame.y; - bx = b_frame.x; - by = b_frame.y; + ax = a_frame.x - area->x; + ay = a_frame.y - area->y; + bx = b_frame.x - area->x; + by = b_frame.y - area->y; from_origin_a = ax * ax + ay * ay; from_origin_b = bx * bx + by * by; @@ -100,9 +102,9 @@ northeast_cmp (gconstpointer a, meta_window_get_frame_rect (aw, &a_frame); meta_window_get_frame_rect (bw, &b_frame); ax = (area->x + area->width) - (a_frame.x + a_frame.width); - ay = a_frame.y; + ay = a_frame.y - area->y; bx = (area->x + area->width) - (b_frame.x + b_frame.width); - by = b_frame.y; + by = b_frame.y - area->y; from_origin_a = ax * ax + ay * ay; from_origin_b = bx * bx + by * by; @@ -155,7 +157,7 @@ find_next_cascade (MetaWindow *window, sorted = g_list_copy (windows); if (ltr) - sorted = g_list_sort (sorted, northwest_cmp); + sorted = g_list_sort_with_data (sorted, northwest_cmp, &work_area); else sorted = g_list_sort_with_data (sorted, northeast_cmp, &work_area);