From 1333d92fa5afcc68f5f37740f02c4fa151766861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 16 Aug 2024 23:03:43 +0200 Subject: [PATCH] xwayland: Set primary monitor using connector name We know let Xwayland set the RANDR names from the connectors. To stop relying on layouts and coordinates to match the primary logical monitor, instead use the connector name of the first monitor. Also make the X11 client sanity checking check that the right X11 output is primary as part of the monitor tests. Part-of: --- src/tests/monitor-unit-tests.c | 41 ++++++++++++++++++++++++++++++++++ src/wayland/meta-xwayland.c | 32 +++++++++----------------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/tests/monitor-unit-tests.c b/src/tests/monitor-unit-tests.c index 80730a58f..2e0539fc1 100644 --- a/src/tests/monitor-unit-tests.c +++ b/src/tests/monitor-unit-tests.c @@ -226,11 +226,52 @@ check_test_client_state (MetaTestClient *test_client) } } +static void +check_test_client_x11_state (MetaTestClient *test_client) +{ + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (test_backend); + MetaLogicalMonitor *primary_logical_monitor; + MetaMonitor *primary_monitor = NULL; + GError *error = NULL; + + primary_logical_monitor = + meta_monitor_manager_get_primary_logical_monitor (monitor_manager); + + if (primary_logical_monitor) + { + GList *monitors; + + monitors = meta_logical_monitor_get_monitors (primary_logical_monitor); + primary_monitor = g_list_first (monitors)->data; + } + + if (!meta_test_client_do (test_client, &error, + "sync", + NULL)) + { + g_error ("Failed to sync test client '%s': %s", + meta_test_client_get_id (test_client), error->message); + } + + if (!meta_test_client_do (test_client, &error, + "assert_primary_monitor", + primary_monitor + ? meta_monitor_get_connector (primary_monitor) + : "(none)", + NULL)) + { + g_error ("Failed to assert primary monitor in X11 test client '%s': %s", + meta_test_client_get_id (test_client), error->message); + } +} + static void check_monitor_test_clients_state (void) { check_test_client_state (wayland_monitor_test_client); check_test_client_state (x11_monitor_test_client); + check_test_client_x11_state (x11_monitor_test_client); } static void diff --git a/src/wayland/meta-xwayland.c b/src/wayland/meta-xwayland.c index 9a664afcb..406f8d218 100644 --- a/src/wayland/meta-xwayland.c +++ b/src/wayland/meta-xwayland.c @@ -1216,15 +1216,19 @@ meta_xwayland_set_primary_output (MetaX11Display *x11_display) MetaMonitorManager *monitor_manager = monitor_manager_from_x11_display (x11_display); XRRScreenResources *resources; - MetaLogicalMonitor *primary_monitor; + MetaLogicalMonitor *primary_logical_monitor; + GList *monitors; + MetaMonitor *primary_monitor; int i; - primary_monitor = + primary_logical_monitor = meta_monitor_manager_get_primary_logical_monitor (monitor_manager); - - if (!primary_monitor) + if (!primary_logical_monitor) return; + monitors = meta_logical_monitor_get_monitors (primary_logical_monitor); + primary_monitor = g_list_first (monitors)->data; + resources = XRRGetScreenResourcesCurrent (xdisplay, DefaultRootWindow (xdisplay)); if (!resources) @@ -1235,29 +1239,13 @@ meta_xwayland_set_primary_output (MetaX11Display *x11_display) { RROutput output_id = resources->outputs[i]; XRROutputInfo *xrandr_output; - XRRCrtcInfo *crtc_info = NULL; - MtkRectangle crtc_geometry; xrandr_output = XRRGetOutputInfo (xdisplay, resources, output_id); if (!xrandr_output) continue; - if (xrandr_output->crtc) - crtc_info = XRRGetCrtcInfo (xdisplay, resources, xrandr_output->crtc); - - XRRFreeOutputInfo (xrandr_output); - - if (!crtc_info) - continue; - - crtc_geometry.x = crtc_info->x; - crtc_geometry.y = crtc_info->y; - crtc_geometry.width = crtc_info->width; - crtc_geometry.height = crtc_info->height; - - XRRFreeCrtcInfo (crtc_info); - - if (mtk_rectangle_equal (&crtc_geometry, &primary_monitor->rect)) + if (g_strcmp0 (xrandr_output->name, + meta_monitor_get_connector (primary_monitor)) == 0) { XRRSetOutputPrimary (xdisplay, DefaultRootWindow (xdisplay), output_id);