diff --git a/src/tests/meson.build b/src/tests/meson.build index 7b1623d97..f3550fba6 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -12,6 +12,7 @@ mutter_test_sources = [ 'meta-ref-test.h', 'meta-sensors-proxy-mock.c', 'meta-sensors-proxy-mock.h', + 'meta-test-monitor.c', 'meta-test-utils.c', 'meta-test-utils.h', ] diff --git a/src/tests/meta-test-monitor.c b/src/tests/meta-test-monitor.c new file mode 100644 index 000000000..f2f42d900 --- /dev/null +++ b/src/tests/meta-test-monitor.c @@ -0,0 +1,102 @@ +/* + * Copyright 2023 Red Hat + * + * 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 . + */ + +#include "config.h" + +#include "meta-test/meta-test-monitor.h" + +#include "backends/meta-virtual-monitor.h" +#include "backends/meta-monitor-manager-private.h" +#include "meta/meta-backend.h" + +struct _MetaTestMonitor +{ + GObject parent; + + MetaVirtualMonitor *virtual_monitor; +}; + +G_DEFINE_TYPE (MetaTestMonitor, meta_test_monitor, G_TYPE_OBJECT) + +static void +meta_test_monitor_dispose (GObject *object) +{ + MetaTestMonitor *test_monitor = META_TEST_MONITOR (object); + + g_clear_object (&test_monitor->virtual_monitor); + + G_OBJECT_CLASS (meta_test_monitor_parent_class)->dispose (object); +} + +static void +meta_test_monitor_class_init (MetaTestMonitorClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = meta_test_monitor_dispose; +} + +static void +meta_test_monitor_init (MetaTestMonitor *test_monitor) +{ +} + +MetaTestMonitor * +meta_test_monitor_new (MetaContext *context, + int width, + int height, + float refresh_rate, + GError **error) +{ + MetaBackend *backend = meta_context_get_backend (context); + MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); + g_autoptr (MetaVirtualMonitorInfo) monitor_info = NULL; + static int serial_count = 0x10000; + g_autofree char *serial = NULL; + MetaVirtualMonitor *virtual_monitor; + MetaTestMonitor *test_monitor; + + serial = g_strdup_printf ("0x%x", serial_count++); + monitor_info = meta_virtual_monitor_info_new (width, height, refresh_rate, + "MetaTestVendor", + "MetaTestMonitor", + serial); + virtual_monitor = meta_monitor_manager_create_virtual_monitor (monitor_manager, + monitor_info, + error); + if (!virtual_monitor) + return NULL; + + g_idle_add_once ((GSourceOnceFunc) meta_monitor_manager_reload, + monitor_manager); + + test_monitor = g_object_new (META_TYPE_TEST_MONITOR, NULL); + test_monitor->virtual_monitor = virtual_monitor; + + return test_monitor; +} + +/** + * meta_test_monitor_destroy: + * @test_monitor: (transfer full): A #MetaTestMonitor + */ +void +meta_test_monitor_destroy (MetaTestMonitor *test_monitor) +{ + g_object_run_dispose (G_OBJECT (test_monitor)); + g_object_unref (test_monitor); +} diff --git a/src/tests/meta-test/meson.build b/src/tests/meta-test/meson.build index 97cfa6e1e..632fb054a 100644 --- a/src/tests/meta-test/meson.build +++ b/src/tests/meta-test/meson.build @@ -2,6 +2,7 @@ mutter_test_includesubdir = join_paths(pkgname, 'meta-test') mutter_test_public_headers = files([ 'meta-context-test.h', + 'meta-test-monitor.h', ]) install_headers(mutter_test_public_headers, diff --git a/src/tests/meta-test/meta-test-monitor.h b/src/tests/meta-test/meta-test-monitor.h new file mode 100644 index 000000000..4c130a4d0 --- /dev/null +++ b/src/tests/meta-test/meta-test-monitor.h @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Red Hat + * + * 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 . + */ + +#ifndef META_TEST_MONITOR_H +#define META_TEST_MONITOR_H + +#include +#include +#include +#include + +#define META_TYPE_TEST_MONITOR (meta_test_monitor_get_type ()) +META_EXPORT +G_DECLARE_FINAL_TYPE (MetaTestMonitor, meta_test_monitor, + META, TEST_MONITOR, GObject) + +META_EXPORT +MetaTestMonitor * meta_test_monitor_new (MetaContext *context, + int width, + int height, + float refresh_rate, + GError **error); + +META_EXPORT +void meta_test_monitor_destroy (MetaTestMonitor *test_monitor); + +#endif /* META_TEST_MONITOR_H */