1
0
Fork 0

test-client: Add 'assert_primary_monitor'

This is a X11 only assert, as only X11 has the concept of a primary
monitor.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3567>
This commit is contained in:
Jonas Ådahl 2024-08-16 23:06:53 +02:00 committed by Marge Bot
parent e2db6c8276
commit 9af1926056
2 changed files with 61 additions and 0 deletions

View file

@ -166,6 +166,7 @@ test_client = executable('mutter-test-client',
gio_unix_dep,
x11_dep,
xext_dep,
xrandr_dep,
graphene_dep,
gsettings_desktop_schemas_dep,
],

View file

@ -26,6 +26,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/sync.h>
#include "core/events.h"
@ -875,6 +876,65 @@ process_line (const char *line)
goto out;
}
}
else if (strcmp (argv[0], "assert_primary_monitor") == 0)
{
Display *xdisplay = gdk_x11_display_get_xdisplay (display);
GdkWindow *root_window = gdk_screen_get_root_window ((gdk_screen_get_default ()));
Window root_xwindow = gdk_x11_window_get_xid (root_window);
XRRScreenResources *resources;
RROutput primary_output;
XRROutputInfo *output_info;
char *expected_name;
if (wayland)
{
g_print ("Can only assert primary monitor on X11\n");
goto out;
}
if (argc != 2)
{
g_print ("usage: %s <monitor-name>\n", argv[0]);
goto out;
}
expected_name = argv[1];
resources = XRRGetScreenResourcesCurrent (xdisplay, root_xwindow);
if (!resources)
{
g_print ("Failed to retrieve XRANDR resources\n");
goto out;
}
primary_output = XRRGetOutputPrimary (xdisplay, root_xwindow);
if (!primary_output)
{
if (g_strcmp0 (expected_name, "(none)") != 0)
{
g_print ("Failed to primary XRANDR output\n");
goto out;
}
}
else
{
output_info = XRRGetOutputInfo (xdisplay, resources, primary_output);
if (!output_info)
{
g_print ("Failed to primary XRANDR output info\n");
goto out;
}
if (g_strcmp0 (expected_name, output_info->name) != 0)
{
XRRFreeOutputInfo (output_info);
g_print ("XRANDR output %s primary, expected %s\n",
output_info->name, expected_name);
goto out;
}
XRRFreeOutputInfo (output_info);
}
}
else if (strcmp (argv[0], "stop_after_next") == 0)
{
if (sync_after_lines != -1)