diff --git a/src/compositor/compositor-private.h b/src/compositor/compositor-private.h index a2b540716..f4eab4521 100644 --- a/src/compositor/compositor-private.h +++ b/src/compositor/compositor-private.h @@ -45,6 +45,7 @@ void meta_compositor_window_actor_stage_views_changed (MetaCompositor *composito void meta_switch_workspace_completed (MetaCompositor *compositor); +META_EXPORT_TEST MetaPluginManager * meta_compositor_get_plugin_manager (MetaCompositor *compositor); int64_t meta_compositor_monotonic_to_high_res_xserver_time (MetaCompositor *compositor, diff --git a/src/compositor/meta-plugin-manager.c b/src/compositor/meta-plugin-manager.c index 65b7fa66c..22ce62abd 100644 --- a/src/compositor/meta-plugin-manager.c +++ b/src/compositor/meta-plugin-manager.c @@ -457,3 +457,9 @@ meta_plugin_manager_locate_pointer (MetaPluginManager *plugin_mgr) if (klass->locate_pointer) klass->locate_pointer (plugin); } + +MetaPlugin * +meta_plugin_manager_get_plugin (MetaPluginManager *plugin_mgr) +{ + return plugin_mgr->plugin; +} diff --git a/src/compositor/meta-plugin-manager.h b/src/compositor/meta-plugin-manager.h index 8e5251f3f..fc14270fb 100644 --- a/src/compositor/meta-plugin-manager.h +++ b/src/compositor/meta-plugin-manager.h @@ -100,3 +100,6 @@ MetaInhibitShortcutsDialog * MetaWindow *window); void meta_plugin_manager_locate_pointer (MetaPluginManager *mgr); + +META_EXPORT_TEST +MetaPlugin * meta_plugin_manager_get_plugin (MetaPluginManager *plugin_mgr); diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c index fb937e23b..f90d1078e 100644 --- a/src/tests/meta-context-test.c +++ b/src/tests/meta-context-test.c @@ -26,6 +26,9 @@ #include #include +#include "compositor/compositor-private.h" +#include "compositor/meta-plugin-manager.h" +#include "core/display-private.h" #include "core/meta-context-private.h" #include "meta/meta-x11-display.h" #include "tests/meta-backend-test.h" @@ -53,6 +56,7 @@ typedef struct _MetaContextTestPrivate MetaContextTestType type; MetaContextTestFlag flags; MetaSessionManager *session_manager; + CoglColor *background_color; } MetaContextTestPrivate; struct _MetaContextTestClass @@ -85,6 +89,7 @@ meta_context_test_finalize (GObject *object) MetaContextTestPrivate *priv = meta_context_test_get_instance_private (context_test); + g_clear_pointer (&priv->background_color, cogl_color_free); g_clear_object (&priv->session_manager); G_OBJECT_CLASS (meta_context_test_parent_class)->finalize (object); @@ -307,6 +312,8 @@ meta_context_test_run_tests (MetaContextTest *context_test, MetaTestRunFlags flags) { MetaContext *context = META_CONTEXT (context_test); + MetaContextTestPrivate *priv = + meta_context_test_get_instance_private (context_test); g_autoptr (GError) error = NULL; if (!meta_context_setup (context, &error)) @@ -335,6 +342,18 @@ meta_context_test_run_tests (MetaContextTest *context_test, 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); meta_context_notify_ready (context); @@ -459,3 +478,14 @@ meta_context_test_init (MetaContextTest *context_test) if (ret == NULL) 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); +} diff --git a/src/tests/meta-test-shell.c b/src/tests/meta-test-shell.c index e4037eb83..92b325952 100644 --- a/src/tests/meta-test-shell.c +++ b/src/tests/meta-test-shell.c @@ -73,6 +73,8 @@ struct _MetaTestShell ClutterActor *background_group; + CoglColor *background_color; + struct { ClutterGrab *grab; ClutterActor *prev_focus; @@ -257,11 +259,9 @@ on_switch_workspace_effect_stopped (ClutterTimeline *timeline, } static void -on_monitors_changed (MetaMonitorManager *monitor_manager, - MetaPlugin *plugin) +reload_backgrounds (MetaTestShell *test_shell) { - MetaTestShell *test_shell = META_TEST_SHELL (plugin); - MetaDisplay *display = meta_plugin_get_display (plugin); + MetaDisplay *display = meta_plugin_get_display (META_PLUGIN (test_shell)); GRand *rand; int i, n; @@ -275,10 +275,6 @@ on_monitors_changed (MetaMonitorManager *monitor_manager, ClutterContent *content; MtkRectangle rect; ClutterActor *background_actor; - MetaBackground *background; - uint8_t red; - uint8_t green; - uint8_t blue; 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_size (background_actor, rect.width, rect.height); - blue = g_rand_int_range (rand, 0, 255); - green = g_rand_int_range (rand, 0, 255); - red = g_rand_int_range (rand, 0, 255); + if (test_shell->background_color) + { + g_autoptr (MetaBackground) background = NULL; - 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); - g_object_unref (background); + background = meta_background_new (display); + meta_background_set_color (background, test_shell->background_color); + meta_background_content_set_background (background_content, 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); } @@ -307,6 +319,15 @@ on_monitors_changed (MetaMonitorManager *monitor_manager, 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 on_overlay_key (MetaDisplay *display, 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 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); 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->map = meta_test_shell_map; @@ -858,3 +890,16 @@ meta_test_shell_init (MetaTestShell *test_shell) { 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); +} diff --git a/src/tests/meta-test-shell.h b/src/tests/meta-test-shell.h index 01f4c8d0e..b969bbd31 100644 --- a/src/tests/meta-test-shell.h +++ b/src/tests/meta-test-shell.h @@ -24,3 +24,7 @@ META_EXPORT G_DECLARE_FINAL_TYPE (MetaTestShell, meta_test_shell, META, TEST_SHELL, MetaPlugin) + +META_EXPORT +void meta_test_shell_set_background_color (MetaTestShell *test_shell, + CoglColor color); diff --git a/src/tests/meta-test/meta-context-test.h b/src/tests/meta-test/meta-context-test.h index e3ef6fb69..292592b2e 100644 --- a/src/tests/meta-test/meta-context-test.h +++ b/src/tests/meta-test/meta-context-test.h @@ -57,3 +57,7 @@ int meta_context_test_run_tests (MetaContextTest *context_test, META_EXPORT 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);