tests/shell: Allow configuring the background color

This will be used to create background colors that will match fullscreen
window colors, so they can share the same ref test reference image.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3859>
This commit is contained in:
Jonas Ådahl 2024-11-14 15:43:58 +01:00 committed by Sebastian Wick
parent ea9e8bff2d
commit 1f3dd65594
7 changed files with 110 additions and 17 deletions

View File

@ -45,6 +45,7 @@ void meta_compositor_window_actor_stage_views_changed (MetaCompositor *composito
void meta_switch_workspace_completed (MetaCompositor *compositor); void meta_switch_workspace_completed (MetaCompositor *compositor);
META_EXPORT_TEST
MetaPluginManager * meta_compositor_get_plugin_manager (MetaCompositor *compositor); MetaPluginManager * meta_compositor_get_plugin_manager (MetaCompositor *compositor);
int64_t meta_compositor_monotonic_to_high_res_xserver_time (MetaCompositor *compositor, int64_t meta_compositor_monotonic_to_high_res_xserver_time (MetaCompositor *compositor,

View File

@ -457,3 +457,9 @@ meta_plugin_manager_locate_pointer (MetaPluginManager *plugin_mgr)
if (klass->locate_pointer) if (klass->locate_pointer)
klass->locate_pointer (plugin); klass->locate_pointer (plugin);
} }
MetaPlugin *
meta_plugin_manager_get_plugin (MetaPluginManager *plugin_mgr)
{
return plugin_mgr->plugin;
}

View File

@ -100,3 +100,6 @@ MetaInhibitShortcutsDialog *
MetaWindow *window); MetaWindow *window);
void meta_plugin_manager_locate_pointer (MetaPluginManager *mgr); void meta_plugin_manager_locate_pointer (MetaPluginManager *mgr);
META_EXPORT_TEST
MetaPlugin * meta_plugin_manager_get_plugin (MetaPluginManager *plugin_mgr);

View File

@ -26,6 +26,9 @@
#include <gio/gsettingsbackend.h> #include <gio/gsettingsbackend.h>
#include <fcntl.h> #include <fcntl.h>
#include "compositor/compositor-private.h"
#include "compositor/meta-plugin-manager.h"
#include "core/display-private.h"
#include "core/meta-context-private.h" #include "core/meta-context-private.h"
#include "meta/meta-x11-display.h" #include "meta/meta-x11-display.h"
#include "tests/meta-backend-test.h" #include "tests/meta-backend-test.h"
@ -53,6 +56,7 @@ typedef struct _MetaContextTestPrivate
MetaContextTestType type; MetaContextTestType type;
MetaContextTestFlag flags; MetaContextTestFlag flags;
MetaSessionManager *session_manager; MetaSessionManager *session_manager;
CoglColor *background_color;
} MetaContextTestPrivate; } MetaContextTestPrivate;
struct _MetaContextTestClass struct _MetaContextTestClass
@ -85,6 +89,7 @@ meta_context_test_finalize (GObject *object)
MetaContextTestPrivate *priv = MetaContextTestPrivate *priv =
meta_context_test_get_instance_private (context_test); meta_context_test_get_instance_private (context_test);
g_clear_pointer (&priv->background_color, cogl_color_free);
g_clear_object (&priv->session_manager); g_clear_object (&priv->session_manager);
G_OBJECT_CLASS (meta_context_test_parent_class)->finalize (object); G_OBJECT_CLASS (meta_context_test_parent_class)->finalize (object);
@ -307,6 +312,8 @@ meta_context_test_run_tests (MetaContextTest *context_test,
MetaTestRunFlags flags) MetaTestRunFlags flags)
{ {
MetaContext *context = META_CONTEXT (context_test); MetaContext *context = META_CONTEXT (context_test);
MetaContextTestPrivate *priv =
meta_context_test_get_instance_private (context_test);
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
if (!meta_context_setup (context, &error)) if (!meta_context_setup (context, &error))
@ -335,6 +342,18 @@ meta_context_test_run_tests (MetaContextTest *context_test,
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (priv->background_color)
{
MetaDisplay *display = meta_context_get_display (context);
MetaCompositor *compositor = display->compositor;
MetaPluginManager *plugin_manager =
meta_compositor_get_plugin_manager (compositor);
MetaPlugin *plugin = meta_plugin_manager_get_plugin (plugin_manager);
meta_test_shell_set_background_color (META_TEST_SHELL (plugin),
*priv->background_color);
}
g_idle_add (run_tests_idle, context_test); g_idle_add (run_tests_idle, context_test);
meta_context_notify_ready (context); meta_context_notify_ready (context);
@ -459,3 +478,14 @@ meta_context_test_init (MetaContextTest *context_test)
if (ret == NULL) if (ret == NULL)
g_warning ("Failed to clear mocked color devices: %s", error->message); g_warning ("Failed to clear mocked color devices: %s", error->message);
} }
void
meta_context_test_set_background_color (MetaContextTest *context_test,
CoglColor color)
{
MetaContextTestPrivate *priv =
meta_context_test_get_instance_private (context_test);
g_clear_pointer (&priv->background_color, cogl_color_free);
priv->background_color = cogl_color_copy (&color);
}

View File

@ -73,6 +73,8 @@ struct _MetaTestShell
ClutterActor *background_group; ClutterActor *background_group;
CoglColor *background_color;
struct { struct {
ClutterGrab *grab; ClutterGrab *grab;
ClutterActor *prev_focus; ClutterActor *prev_focus;
@ -257,11 +259,9 @@ on_switch_workspace_effect_stopped (ClutterTimeline *timeline,
} }
static void static void
on_monitors_changed (MetaMonitorManager *monitor_manager, reload_backgrounds (MetaTestShell *test_shell)
MetaPlugin *plugin)
{ {
MetaTestShell *test_shell = META_TEST_SHELL (plugin); MetaDisplay *display = meta_plugin_get_display (META_PLUGIN (test_shell));
MetaDisplay *display = meta_plugin_get_display (plugin);
GRand *rand; GRand *rand;
int i, n; int i, n;
@ -275,10 +275,6 @@ on_monitors_changed (MetaMonitorManager *monitor_manager,
ClutterContent *content; ClutterContent *content;
MtkRectangle rect; MtkRectangle rect;
ClutterActor *background_actor; ClutterActor *background_actor;
MetaBackground *background;
uint8_t red;
uint8_t green;
uint8_t blue;
meta_display_get_monitor_geometry (display, i, &rect); meta_display_get_monitor_geometry (display, i, &rect);
@ -289,17 +285,33 @@ on_monitors_changed (MetaMonitorManager *monitor_manager,
clutter_actor_set_position (background_actor, rect.x, rect.y); clutter_actor_set_position (background_actor, rect.x, rect.y);
clutter_actor_set_size (background_actor, rect.width, rect.height); clutter_actor_set_size (background_actor, rect.width, rect.height);
blue = g_rand_int_range (rand, 0, 255); if (test_shell->background_color)
green = g_rand_int_range (rand, 0, 255); {
red = g_rand_int_range (rand, 0, 255); g_autoptr (MetaBackground) background = NULL;
background = meta_background_new (display); background = meta_background_new (display);
meta_background_set_color (background, meta_background_set_color (background, test_shell->background_color);
&COGL_COLOR_INIT (red, green, blue, 255)); meta_background_content_set_background (background_content, background);
meta_background_content_set_background (background_content, background); }
g_object_unref (background); else
{
g_autoptr (MetaBackground) background = NULL;
uint8_t red;
uint8_t green;
uint8_t blue;
meta_background_content_set_vignette (background_content, TRUE, 0.5, 0.5); blue = g_rand_int_range (rand, 0, 255);
green = g_rand_int_range (rand, 0, 255);
red = g_rand_int_range (rand, 0, 255);
background = meta_background_new (display);
meta_background_set_color (background,
&COGL_COLOR_INIT (red, green, blue, 255));
meta_background_content_set_background (background_content, background);
meta_background_content_set_vignette (background_content,
TRUE, 0.5, 0.5);
}
clutter_actor_add_child (test_shell->background_group, background_actor); clutter_actor_add_child (test_shell->background_group, background_actor);
} }
@ -307,6 +319,15 @@ on_monitors_changed (MetaMonitorManager *monitor_manager,
g_rand_free (rand); g_rand_free (rand);
} }
static void
on_monitors_changed (MetaMonitorManager *monitor_manager,
MetaPlugin *plugin)
{
MetaTestShell *test_shell = META_TEST_SHELL (plugin);
reload_backgrounds (test_shell);
}
static void static void
on_overlay_key (MetaDisplay *display, on_overlay_key (MetaDisplay *display,
MetaTestShell *test_shell) MetaTestShell *test_shell)
@ -825,6 +846,16 @@ meta_test_shell_set_property (GObject *object,
} }
} }
static void
meta_test_shell_finalize (GObject *object)
{
MetaTestShell *test_shell = META_TEST_SHELL (object);
g_clear_pointer (&test_shell->background_color, cogl_color_free);
G_OBJECT_CLASS (meta_test_shell_parent_class)->finalize (object);
}
static void static void
meta_test_shell_class_init (MetaTestShellClass *klass) meta_test_shell_class_init (MetaTestShellClass *klass)
{ {
@ -832,6 +863,7 @@ meta_test_shell_class_init (MetaTestShellClass *klass)
MetaPluginClass *plugin_class = META_PLUGIN_CLASS (klass); MetaPluginClass *plugin_class = META_PLUGIN_CLASS (klass);
object_class->set_property = meta_test_shell_set_property; object_class->set_property = meta_test_shell_set_property;
object_class->finalize = meta_test_shell_finalize;
plugin_class->start = meta_test_shell_start; plugin_class->start = meta_test_shell_start;
plugin_class->map = meta_test_shell_map; plugin_class->map = meta_test_shell_map;
@ -858,3 +890,16 @@ meta_test_shell_init (MetaTestShell *test_shell)
{ {
test_shell->show_stage = TRUE; test_shell->show_stage = TRUE;
} }
void
meta_test_shell_set_background_color (MetaTestShell *test_shell,
CoglColor color)
{
if (test_shell->background_color &&
cogl_color_equal (test_shell->background_color, &color))
return;
g_clear_pointer (&test_shell->background_color, cogl_color_free);
test_shell->background_color = cogl_color_copy (&color);
reload_backgrounds (test_shell);
}

View File

@ -24,3 +24,7 @@ META_EXPORT
G_DECLARE_FINAL_TYPE (MetaTestShell, meta_test_shell, G_DECLARE_FINAL_TYPE (MetaTestShell, meta_test_shell,
META, TEST_SHELL, META, TEST_SHELL,
MetaPlugin) MetaPlugin)
META_EXPORT
void meta_test_shell_set_background_color (MetaTestShell *test_shell,
CoglColor color);

View File

@ -57,3 +57,7 @@ int meta_context_test_run_tests (MetaContextTest *context_test,
META_EXPORT META_EXPORT
void meta_context_test_wait_for_x11_display (MetaContextTest *context_test); void meta_context_test_wait_for_x11_display (MetaContextTest *context_test);
META_EXPORT
void meta_context_test_set_background_color (MetaContextTest *context_test,
CoglColor color);