2022-03-04 09:04:59 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/meta-virtual-monitor.h"
|
|
|
|
#include "compositor/meta-window-actor-private.h"
|
2022-09-28 14:51:32 -04:00
|
|
|
#include "core/window-private.h"
|
2022-03-04 09:04:59 -05:00
|
|
|
#include "meta-test/meta-context-test.h"
|
|
|
|
#include "tests/meta-test-utils.h"
|
|
|
|
#include "tests/meta-wayland-test-driver.h"
|
|
|
|
#include "tests/meta-wayland-test-utils.h"
|
2022-03-14 08:17:09 -04:00
|
|
|
#include "backends/native/meta-renderer-native.h"
|
|
|
|
#include "tests/meta-ref-test.h"
|
2022-09-28 14:53:18 -04:00
|
|
|
#include "wayland/meta-window-wayland.h"
|
2023-10-23 17:59:19 -04:00
|
|
|
#include "wayland/meta-wayland-surface-private.h"
|
2022-03-04 09:04:59 -05:00
|
|
|
|
|
|
|
static MetaContext *test_context;
|
|
|
|
static MetaWaylandTestDriver *test_driver;
|
2022-03-14 08:17:09 -04:00
|
|
|
static MetaVirtualMonitor *virtual_monitor;
|
|
|
|
static MetaWaylandTestClient *wayland_test_client;
|
|
|
|
static MetaWindow *test_window = NULL;
|
|
|
|
|
2022-09-28 14:51:32 -04:00
|
|
|
#define assert_wayland_surface_size(window, width, height) \
|
|
|
|
{ \
|
2022-05-18 07:51:44 -04:00
|
|
|
g_assert_cmpint (meta_wayland_surface_get_width (meta_window_get_wayland_surface (window)), \
|
2022-09-28 14:51:32 -04:00
|
|
|
==, \
|
|
|
|
width); \
|
2022-05-18 07:51:44 -04:00
|
|
|
g_assert_cmpint (meta_wayland_surface_get_height (meta_window_get_wayland_surface (window)), \
|
2022-09-28 14:51:32 -04:00
|
|
|
==, \
|
|
|
|
height); \
|
|
|
|
}
|
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
static ClutterStageView *
|
|
|
|
get_view (void)
|
|
|
|
{
|
|
|
|
MetaBackend *backend = meta_context_get_backend (test_context);
|
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
|
|
|
|
return CLUTTER_STAGE_VIEW (meta_renderer_get_views (renderer)->data);
|
|
|
|
}
|
2022-03-04 09:04:59 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
on_first_frame (MetaWindowActor *window_actor,
|
|
|
|
gboolean *done)
|
|
|
|
{
|
|
|
|
*done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
wait_for_first_frame (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWindowActor *window_actor;
|
|
|
|
gboolean done = FALSE;
|
|
|
|
glong handler_id;
|
|
|
|
|
|
|
|
window_actor = meta_window_actor_from_window (window);
|
|
|
|
handler_id = g_signal_connect (window_actor, "first-frame",
|
|
|
|
G_CALLBACK (on_first_frame), &done);
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
|
|
|
|
|
|
|
g_signal_handler_disconnect (window_actor, handler_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-03-14 08:17:09 -04:00
|
|
|
on_effects_completed (MetaWindowActor *window_actor,
|
|
|
|
gboolean *done)
|
2022-03-04 09:04:59 -05:00
|
|
|
{
|
2022-03-14 08:17:09 -04:00
|
|
|
*done = TRUE;
|
|
|
|
}
|
2022-03-04 09:04:59 -05:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
static void
|
|
|
|
wait_for_window_added (MetaWindow *window)
|
|
|
|
{
|
|
|
|
MetaWindowActor *window_actor;
|
|
|
|
gboolean done = FALSE;
|
|
|
|
gulong handler_id;
|
2022-03-04 09:04:59 -05:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
window_actor = meta_window_actor_from_window (window);
|
|
|
|
handler_id = g_signal_connect (window_actor, "effects-completed",
|
|
|
|
G_CALLBACK (on_effects_completed), &done);
|
2022-03-04 09:04:59 -05:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
while (!done)
|
2022-03-04 09:04:59 -05:00
|
|
|
g_main_context_iteration (NULL, TRUE);
|
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
g_signal_handler_disconnect (window_actor, handler_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
toplevel_fullscreen (void)
|
|
|
|
{
|
2023-07-19 19:46:15 -04:00
|
|
|
MtkRectangle rect;
|
2022-03-14 08:17:09 -04:00
|
|
|
|
|
|
|
wait_for_first_frame (test_window);
|
2022-03-04 09:04:59 -05:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
meta_window_get_frame_rect (test_window, &rect);
|
2023-10-27 12:14:57 -04:00
|
|
|
g_assert_cmpint (rect.width, ==, 640);
|
|
|
|
g_assert_cmpint (rect.height, ==, 480);
|
2022-03-04 09:04:59 -05:00
|
|
|
g_assert_cmpint (rect.x, ==, 0);
|
|
|
|
g_assert_cmpint (rect.y, ==, 0);
|
2022-09-28 14:51:32 -04:00
|
|
|
assert_wayland_surface_size (test_window, 10, 10);
|
2022-03-14 08:17:09 -04:00
|
|
|
}
|
2022-03-04 09:04:59 -05:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
static void
|
|
|
|
toplevel_fullscreen_ref_test (void)
|
|
|
|
{
|
2022-09-28 14:53:18 -04:00
|
|
|
MetaWindowWayland *wl_window = META_WINDOW_WAYLAND (test_window);
|
2023-07-19 19:46:15 -04:00
|
|
|
MtkRectangle rect;
|
2022-09-28 14:53:18 -04:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
wait_for_window_added (test_window);
|
2022-09-28 14:53:18 -04:00
|
|
|
assert_wayland_surface_size (test_window, 10, 10);
|
|
|
|
g_assert_true (meta_window_wayland_is_acked_fullscreen (wl_window));
|
2022-03-04 09:04:59 -05:00
|
|
|
|
2022-03-14 08:17:09 -04:00
|
|
|
meta_ref_test_verify_view (get_view (),
|
|
|
|
g_test_get_path (), 1,
|
|
|
|
meta_ref_test_determine_ref_test_flag ());
|
2022-09-28 14:53:18 -04:00
|
|
|
|
|
|
|
meta_window_unmake_fullscreen (test_window);
|
|
|
|
|
|
|
|
while (meta_window_wayland_is_acked_fullscreen (wl_window))
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
|
|
|
|
|
|
|
meta_window_move_frame (test_window, FALSE, 12, 13);
|
|
|
|
|
|
|
|
meta_window_get_frame_rect (test_window, &rect);
|
|
|
|
g_assert_cmpint (rect.width, ==, 10);
|
|
|
|
g_assert_cmpint (rect.height, ==, 10);
|
|
|
|
g_assert_cmpint (rect.x, ==, 12);
|
|
|
|
g_assert_cmpint (rect.y, ==, 13);
|
|
|
|
assert_wayland_surface_size (test_window, 10, 10);
|
|
|
|
|
|
|
|
meta_ref_test_verify_view (get_view (),
|
|
|
|
g_test_get_path (), 2,
|
|
|
|
meta_ref_test_determine_ref_test_flag ());
|
|
|
|
|
|
|
|
meta_window_make_fullscreen (test_window);
|
|
|
|
while (!meta_window_wayland_is_acked_fullscreen (wl_window))
|
|
|
|
g_main_context_iteration (NULL, FALSE);
|
|
|
|
|
|
|
|
meta_window_get_frame_rect (test_window, &rect);
|
2023-10-27 12:14:57 -04:00
|
|
|
g_assert_cmpint (rect.width, ==, 640);
|
|
|
|
g_assert_cmpint (rect.height, ==, 480);
|
2022-09-28 14:53:18 -04:00
|
|
|
g_assert_cmpint (rect.x, ==, 0);
|
|
|
|
g_assert_cmpint (rect.y, ==, 0);
|
|
|
|
assert_wayland_surface_size (test_window, 10, 10);
|
|
|
|
|
|
|
|
meta_ref_test_verify_view (get_view (),
|
|
|
|
g_test_get_path (), 3,
|
|
|
|
meta_ref_test_determine_ref_test_flag ());
|
2022-03-04 09:04:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_before_tests (void)
|
|
|
|
{
|
|
|
|
MetaWaylandCompositor *compositor =
|
|
|
|
meta_context_get_wayland_compositor (test_context);
|
|
|
|
|
|
|
|
test_driver = meta_wayland_test_driver_new (compositor);
|
2022-03-14 08:17:09 -04:00
|
|
|
|
2023-10-27 12:14:57 -04:00
|
|
|
virtual_monitor = meta_create_test_monitor (test_context,
|
|
|
|
640, 480, 60.0);
|
2022-03-14 08:17:09 -04:00
|
|
|
|
2022-05-27 16:55:43 -04:00
|
|
|
wayland_test_client = meta_wayland_test_client_new (test_context,
|
|
|
|
"fullscreen");
|
2022-03-14 08:17:09 -04:00
|
|
|
|
|
|
|
while (!(test_window =
|
|
|
|
meta_find_window_from_title (test_context, "fullscreen")))
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2022-03-04 09:04:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_after_tests (void)
|
|
|
|
{
|
2022-03-14 08:17:09 -04:00
|
|
|
meta_wayland_test_driver_emit_sync_event (test_driver, 0);
|
|
|
|
|
|
|
|
meta_wayland_test_client_finish (wayland_test_client);
|
|
|
|
|
|
|
|
g_clear_object (&virtual_monitor);
|
|
|
|
|
2022-03-04 09:04:59 -05:00
|
|
|
g_clear_object (&test_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_tests (void)
|
|
|
|
{
|
|
|
|
g_test_add_func ("/wayland/toplevel/fullscreen",
|
|
|
|
toplevel_fullscreen);
|
2022-03-14 08:17:09 -04:00
|
|
|
g_test_add_func ("/wayland/toplevel/fullscreen-ref-test",
|
|
|
|
toplevel_fullscreen_ref_test);
|
2022-03-04 09:04:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
g_autoptr (MetaContext) context = NULL;
|
|
|
|
|
|
|
|
context = meta_create_test_context (META_CONTEXT_TEST_TYPE_HEADLESS,
|
|
|
|
META_CONTEXT_TEST_FLAG_NO_X11);
|
|
|
|
g_assert (meta_context_configure (context, &argc, &argv, NULL));
|
|
|
|
|
|
|
|
test_context = context;
|
|
|
|
|
|
|
|
init_tests ();
|
|
|
|
|
|
|
|
g_signal_connect (context, "before-tests",
|
|
|
|
G_CALLBACK (on_before_tests), NULL);
|
|
|
|
g_signal_connect (context, "after-tests",
|
|
|
|
G_CALLBACK (on_after_tests), NULL);
|
|
|
|
|
|
|
|
return meta_context_test_run_tests (META_CONTEXT_TEST (context),
|
|
|
|
META_TEST_RUN_FLAG_NONE);
|
|
|
|
}
|