From ee0677a02121da4541a5897d0c5c26aef45a96f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 6 Jan 2017 13:27:21 +0800 Subject: [PATCH] monitor-manager: Let backend implementations handle inital config How the initial configuration is done depends on the backend, so let them do it themself. https://bugzilla.gnome.org/show_bug.cgi?id=777732 --- src/backends/meta-monitor-manager-dummy.c | 9 +++ src/backends/meta-monitor-manager-private.h | 6 ++ src/backends/meta-monitor-manager.c | 55 +++++++++++-------- .../native/meta-monitor-manager-kms.c | 9 +++ .../x11/meta-monitor-manager-xrandr.c | 16 ++++++ src/tests/meta-monitor-manager-test.c | 9 +++ 6 files changed, 81 insertions(+), 23 deletions(-) diff --git a/src/backends/meta-monitor-manager-dummy.c b/src/backends/meta-monitor-manager-dummy.c index bf17b479b..71fb46ce3 100644 --- a/src/backends/meta-monitor-manager-dummy.c +++ b/src/backends/meta-monitor-manager-dummy.c @@ -169,6 +169,14 @@ meta_monitor_manager_dummy_read_current (MetaMonitorManager *manager) } } +static void +meta_monitor_manager_dummy_ensure_initial_config (MetaMonitorManager *manager) +{ + meta_monitor_manager_ensure_configured (manager); + + meta_monitor_manager_update_logical_state_derived (manager); +} + static void meta_monitor_manager_dummy_apply_config (MetaMonitorManager *manager, MetaCrtcInfo **crtcs, @@ -289,6 +297,7 @@ meta_monitor_manager_dummy_class_init (MetaMonitorManagerDummyClass *klass) MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass); manager_class->read_current = meta_monitor_manager_dummy_read_current; + manager_class->ensure_initial_config = meta_monitor_manager_dummy_ensure_initial_config; manager_class->apply_configuration = meta_monitor_manager_dummy_apply_config; } diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h index f579b9705..74b1ba2e1 100644 --- a/src/backends/meta-monitor-manager-private.h +++ b/src/backends/meta-monitor-manager-private.h @@ -298,6 +298,8 @@ struct _MetaMonitorManagerClass GBytes* (*read_edid) (MetaMonitorManager *, MetaOutput *); + void (*ensure_initial_config) (MetaMonitorManager *); + void (*apply_configuration) (MetaMonitorManager *, MetaCrtcInfo **, unsigned int , @@ -411,6 +413,10 @@ void meta_monitor_manager_tiled_monitor_added (MetaMonitorManager void meta_monitor_manager_tiled_monitor_removed (MetaMonitorManager *manager, MetaMonitor *monitor); +void meta_monitor_manager_ensure_configured (MetaMonitorManager *manager); + +void meta_monitor_manager_update_logical_state_derived (MetaMonitorManager *manager); + void meta_monitor_manager_clear_output (MetaOutput *output); void meta_monitor_manager_clear_mode (MetaCrtcMode *mode); void meta_monitor_manager_clear_crtc (MetaCrtc *crtc); diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index 195990bc4..cb76fd13d 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -120,7 +120,7 @@ derive_monitor_position (MetaMonitor *monitor, } static void -make_logical_config (MetaMonitorManager *manager) +meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager *manager) { GList *logical_monitors = NULL; GList *l; @@ -200,6 +200,12 @@ power_save_mode_changed (MetaMonitorManager *manager, manager->power_save_mode = mode; } +static void +meta_monitor_manager_ensure_initial_config (MetaMonitorManager *manager) +{ + META_MONITOR_MANAGER_GET_CLASS (manager)->ensure_initial_config (manager); +} + gboolean meta_monitor_manager_has_hotplug_mode_update (MetaMonitorManager *manager) { @@ -223,6 +229,12 @@ legacy_ensure_configured (MetaMonitorManager *manager) meta_monitor_config_make_default (manager->legacy_config, manager); } +void +meta_monitor_manager_ensure_configured (MetaMonitorManager *manager) +{ + legacy_ensure_configured (manager); +} + static void meta_monitor_manager_constructed (GObject *object) { @@ -237,19 +249,8 @@ meta_monitor_manager_constructed (GObject *object) meta_monitor_manager_read_current_state (manager); - legacy_ensure_configured (manager); + meta_monitor_manager_ensure_initial_config (manager); - /* Under XRandR, we don't rebuild our data structures until we see - the RRScreenNotify event, but at least at startup we want to have - the right configuration immediately. - - The other backends keep the data structures always updated, - so this is not needed. - */ - if (META_IS_MONITOR_MANAGER_XRANDR (manager)) - meta_monitor_manager_read_current_state (manager); - - make_logical_config (manager); initialize_dbus_interface (manager); manager->in_init = FALSE; @@ -1533,6 +1534,15 @@ meta_monitor_manager_read_current_state (MetaMonitorManager *manager) meta_monitor_manager_free_crtc_array (old_crtcs, n_old_crtcs); } +static void +meta_monitor_manager_notify_monitors_changed (MetaMonitorManager *manager) +{ + MetaBackend *backend = meta_get_backend (); + + meta_backend_monitors_changed (backend); + g_signal_emit_by_name (manager, "monitors-changed"); +} + static void meta_monitor_manager_update_monitor_modes_derived (MetaMonitorManager *manager) { @@ -1546,10 +1556,16 @@ meta_monitor_manager_update_monitor_modes_derived (MetaMonitorManager *manager) } } +void +meta_monitor_manager_update_logical_state_derived (MetaMonitorManager *manager) +{ + meta_monitor_manager_rebuild_logical_monitors_derived (manager); + meta_monitor_manager_update_monitor_modes_derived (manager); +} + void meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager) { - MetaBackend *backend = meta_get_backend (); GList *old_logical_monitors; if (manager->in_init) @@ -1557,16 +1573,9 @@ meta_monitor_manager_rebuild_derived (MetaMonitorManager *manager) old_logical_monitors = manager->logical_monitors; - make_logical_config (manager); - meta_monitor_manager_update_monitor_modes_derived (manager); + meta_monitor_manager_update_logical_state_derived (manager); - /* Tell the backend about that the monitors changed before emitting the - * signal, so that the backend can prepare itself before all the signal - * consumers. - */ - meta_backend_monitors_changed (backend); - - g_signal_emit_by_name (manager, "monitors-changed"); + meta_monitor_manager_notify_monitors_changed (manager); g_list_free_full (old_logical_monitors, g_object_unref); } diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c index 7c491fbb2..9b985d017 100644 --- a/src/backends/native/meta-monitor-manager-kms.c +++ b/src/backends/native/meta-monitor-manager-kms.c @@ -1337,6 +1337,14 @@ set_underscan (MetaMonitorManagerKms *manager_kms, } } +static void +meta_monitor_manager_kms_ensure_initial_config (MetaMonitorManager *manager) +{ + meta_monitor_manager_ensure_configured (manager); + + meta_monitor_manager_update_logical_state_derived (manager); +} + static void meta_monitor_manager_kms_apply_configuration (MetaMonitorManager *manager, MetaCrtcInfo **crtcs, @@ -1922,6 +1930,7 @@ meta_monitor_manager_kms_class_init (MetaMonitorManagerKmsClass *klass) manager_class->read_current = meta_monitor_manager_kms_read_current; manager_class->read_edid = meta_monitor_manager_kms_read_edid; + manager_class->ensure_initial_config = meta_monitor_manager_kms_ensure_initial_config; manager_class->apply_configuration = meta_monitor_manager_kms_apply_configuration; manager_class->set_power_save_mode = meta_monitor_manager_kms_set_power_save_mode; manager_class->get_crtc_gamma = meta_monitor_manager_kms_get_crtc_gamma; diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c index b5a130dab..b3f0dd4de 100644 --- a/src/backends/x11/meta-monitor-manager-xrandr.c +++ b/src/backends/x11/meta-monitor-manager-xrandr.c @@ -1279,6 +1279,21 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager, XFlush (manager_xrandr->xdisplay); } +static void +meta_monitor_manager_xrandr_ensure_initial_config (MetaMonitorManager *manager) +{ + meta_monitor_manager_ensure_configured (manager); + + /* + * Normally we don't rebuild our data structures until we see the + * RRScreenNotify event, but at least at startup we want to have the right + * configuration immediately. + */ + meta_monitor_manager_read_current_state (manager); + + meta_monitor_manager_update_logical_state_derived (manager); +} + static void meta_monitor_manager_xrandr_change_backlight (MetaMonitorManager *manager, MetaOutput *output, @@ -1571,6 +1586,7 @@ meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass) manager_class->read_current = meta_monitor_manager_xrandr_read_current; manager_class->read_edid = meta_monitor_manager_xrandr_read_edid; + manager_class->ensure_initial_config = meta_monitor_manager_xrandr_ensure_initial_config; manager_class->apply_configuration = meta_monitor_manager_xrandr_apply_configuration; manager_class->set_power_save_mode = meta_monitor_manager_xrandr_set_power_save_mode; manager_class->change_backlight = meta_monitor_manager_xrandr_change_backlight; diff --git a/src/tests/meta-monitor-manager-test.c b/src/tests/meta-monitor-manager-test.c index a89b2cfea..22b907375 100644 --- a/src/tests/meta-monitor-manager-test.c +++ b/src/tests/meta-monitor-manager-test.c @@ -83,6 +83,14 @@ meta_monitor_manager_test_read_current (MetaMonitorManager *manager) manager->n_outputs = manager_test->test_setup->n_outputs; } +static void +meta_monitor_manager_test_ensure_initial_config (MetaMonitorManager *manager) +{ + meta_monitor_manager_ensure_configured (manager); + + meta_monitor_manager_update_logical_state_derived (manager); +} + static void meta_monitor_manager_test_apply_configuration (MetaMonitorManager *manager, MetaCrtcInfo **crtcs, @@ -240,6 +248,7 @@ meta_monitor_manager_test_class_init (MetaMonitorManagerTestClass *klass) object_class->dispose = meta_monitor_manager_test_dispose; manager_class->read_current = meta_monitor_manager_test_read_current; + manager_class->ensure_initial_config = meta_monitor_manager_test_ensure_initial_config; manager_class->apply_configuration = meta_monitor_manager_test_apply_configuration; manager_class->tiled_monitor_added = meta_monitor_manager_test_tiled_monitor_added; manager_class->tiled_monitor_removed = meta_monitor_manager_test_tiled_monitor_removed;