MonitorManager: Use composition instead of inheriting from dbus skeleton

MonitorManager was inheriting from MetaDBusDisplayConfigSkeleton, this was
causing introspection to see this like a GDBus skeleton object exposing to
clients methods that were not required.

Also, this required us to export meta_dbus_* symbols to the library, while
these should be actually private.

So, make MetaMonitorManager to be just a simple GObject holding a skeleton
instance, and connect to its signals reusing most of the code with just few
minor changes.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/395
This commit is contained in:
Marco Trevisan (Treviño) 2019-01-23 02:49:26 +01:00
parent 7f551ba776
commit e352011830
4 changed files with 72 additions and 38 deletions

View File

@ -1759,7 +1759,6 @@ check_mappable_devices (MetaInputSettings *input_settings)
static void
power_save_mode_changed_cb (MetaMonitorManager *manager,
GParamSpec *pspec,
gpointer user_data)
{
MetaInputSettingsPrivate *priv;
@ -1869,7 +1868,7 @@ meta_input_settings_init (MetaInputSettings *settings)
priv->monitor_manager = g_object_ref (meta_monitor_manager_get ());
g_signal_connect (priv->monitor_manager, "monitors-changed-internal",
G_CALLBACK (monitors_changed_cb), settings);
g_signal_connect (priv->monitor_manager, "notify::power-save-mode",
g_signal_connect (priv->monitor_manager, "power-save-mode-changed",
G_CALLBACK (power_save_mode_changed_cb), settings);
#ifdef HAVE_LIBWACOM

View File

@ -102,7 +102,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (MetaMonitorManager, g_object_unref)
struct _MetaMonitorManager
{
MetaDBusDisplayConfigSkeleton parent_instance;
GObject parent_instance;
MetaDBusDisplayConfig *display_config;
MetaBackend *backend;

View File

@ -73,7 +73,9 @@ enum
static GParamSpec *obj_props[PROP_LAST];
enum {
MONITORS_CHANGED,
MONITORS_CHANGED_INTERNAL,
POWER_SAVE_MODE_CHANGED,
CONFIRM_DISPLAY_CHANGE,
SIGNALS_LAST
};
@ -92,12 +94,10 @@ static gfloat transform_matrices[][6] = {
static int signals[SIGNALS_LAST];
static void meta_monitor_manager_display_config_init (MetaDBusDisplayConfigIface *iface);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaMonitorManager, meta_monitor_manager, META_DBUS_TYPE_DISPLAY_CONFIG_SKELETON,
G_IMPLEMENT_INTERFACE (META_DBUS_TYPE_DISPLAY_CONFIG, meta_monitor_manager_display_config_init));
G_DEFINE_TYPE (MetaMonitorManager, meta_monitor_manager, G_TYPE_OBJECT)
static void initialize_dbus_interface (MetaMonitorManager *manager);
static void monitor_manager_setup_dbus_config_handlers (MetaMonitorManager *manager);
static gboolean
meta_monitor_manager_is_config_complete (MetaMonitorManager *manager,
@ -334,7 +334,7 @@ power_save_mode_changed (MetaMonitorManager *manager,
gpointer user_data)
{
MetaMonitorManagerClass *klass;
int mode = meta_dbus_display_config_get_power_save_mode (META_DBUS_DISPLAY_CONFIG (manager));
int mode = meta_dbus_display_config_get_power_save_mode (manager->display_config);
if (mode == META_POWER_SAVE_UNSUPPORTED)
return;
@ -342,7 +342,7 @@ power_save_mode_changed (MetaMonitorManager *manager,
/* If DPMS is unsupported, force the property back. */
if (manager->power_save_mode == META_POWER_SAVE_UNSUPPORTED)
{
meta_dbus_display_config_set_power_save_mode (META_DBUS_DISPLAY_CONFIG (manager), META_POWER_SAVE_UNSUPPORTED);
meta_dbus_display_config_set_power_save_mode (manager->display_config, META_POWER_SAVE_UNSUPPORTED);
return;
}
@ -351,6 +351,8 @@ power_save_mode_changed (MetaMonitorManager *manager,
klass->set_power_save_mode (manager, mode);
manager->power_save_mode = mode;
g_signal_emit (manager, signals[POWER_SAVE_MODE_CHANGED], 0);
}
void
@ -737,14 +739,19 @@ meta_monitor_manager_constructed (GObject *object)
MetaBackend *backend = manager->backend;
MetaSettings *settings = meta_backend_get_settings (backend);
manager->display_config = meta_dbus_display_config_skeleton_new ();
manager->experimental_features_changed_handler_id =
g_signal_connect (settings,
"experimental-features-changed",
G_CALLBACK (experimental_features_changed),
manager);
g_signal_connect_object (manager, "notify::power-save-mode",
G_CALLBACK (power_save_mode_changed), manager, 0);
monitor_manager_setup_dbus_config_handlers (manager);
g_signal_connect_object (manager->display_config, "notify::power-save-mode",
G_CALLBACK (power_save_mode_changed), manager,
G_CONNECT_SWAPPED);
g_signal_connect_object (meta_backend_get_orientation_manager (backend),
"orientation-changed",
@ -786,6 +793,7 @@ meta_monitor_manager_dispose (GObject *object)
manager->dbus_name_id = 0;
}
g_clear_object (&manager->display_config);
g_clear_object (&manager->config_manager);
G_OBJECT_CLASS (meta_monitor_manager_parent_class)->dispose (object);
@ -847,6 +855,14 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
klass->read_edid = meta_monitor_manager_real_read_edid;
signals[MONITORS_CHANGED] =
g_signal_new ("monitors-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[MONITORS_CHANGED_INTERNAL] =
g_signal_new ("monitors-changed-internal",
G_TYPE_FROM_CLASS (object_class),
@ -855,6 +871,14 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[POWER_SAVE_MODE_CHANGED] =
g_signal_new ("power-save-mode-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
signals[CONFIRM_DISPLAY_CHANGE] =
g_signal_new ("confirm-display-change",
G_TYPE_FROM_CLASS (object_class),
@ -991,10 +1015,10 @@ combine_gpu_lists (MetaMonitorManager *manager,
static gboolean
meta_monitor_manager_handle_get_resources (MetaDBusDisplayConfig *skeleton,
GDBusMethodInvocation *invocation)
GDBusMethodInvocation *invocation,
MetaMonitorManager *manager)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_GET_CLASS (skeleton);
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_GET_CLASS (manager);
GList *combined_modes;
GList *combined_outputs;
GList *combined_crtcs;
@ -1265,9 +1289,9 @@ request_persistent_confirmation (MetaMonitorManager *manager)
static gboolean
meta_monitor_manager_handle_get_current_state (MetaDBusDisplayConfig *skeleton,
GDBusMethodInvocation *invocation)
GDBusMethodInvocation *invocation,
MetaMonitorManager *manager)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
MetaSettings *settings = meta_backend_get_settings (manager->backend);
GVariantBuilder monitors_builder;
GVariantBuilder logical_monitors_builder;
@ -1911,9 +1935,9 @@ meta_monitor_manager_handle_apply_monitors_config (MetaDBusDisplayConfig *skelet
guint serial,
guint method,
GVariant *logical_monitor_configs_variant,
GVariant *properties_variant)
GVariant *properties_variant,
MetaMonitorManager *manager)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
MetaMonitorManagerCapability capabilities;
GVariant *layout_mode_variant = NULL;
MetaLogicalMonitorLayoutMode layout_mode;
@ -2079,9 +2103,9 @@ meta_monitor_manager_handle_change_backlight (MetaDBusDisplayConfig *skeleton,
GDBusMethodInvocation *invocation,
guint serial,
guint output_index,
gint value)
gint value,
MetaMonitorManager *manager)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
GList *combined_outputs;
MetaOutput *output;
@ -2133,9 +2157,9 @@ static gboolean
meta_monitor_manager_handle_get_crtc_gamma (MetaDBusDisplayConfig *skeleton,
GDBusMethodInvocation *invocation,
guint serial,
guint crtc_id)
guint crtc_id,
MetaMonitorManager *manager)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
MetaMonitorManagerClass *klass;
GList *combined_crtcs;
MetaCrtc *crtc;
@ -2201,9 +2225,9 @@ meta_monitor_manager_handle_set_crtc_gamma (MetaDBusDisplayConfig *skeleton,
guint crtc_id,
GVariant *red_v,
GVariant *green_v,
GVariant *blue_v)
GVariant *blue_v,
MetaMonitorManager *manager)
{
MetaMonitorManager *manager = META_MONITOR_MANAGER (skeleton);
MetaMonitorManagerClass *klass;
GList *combined_crtcs;
MetaCrtc *crtc;
@ -2257,14 +2281,26 @@ meta_monitor_manager_handle_set_crtc_gamma (MetaDBusDisplayConfig *skeleton,
}
static void
meta_monitor_manager_display_config_init (MetaDBusDisplayConfigIface *iface)
monitor_manager_setup_dbus_config_handlers (MetaMonitorManager *manager)
{
iface->handle_get_resources = meta_monitor_manager_handle_get_resources;
iface->handle_change_backlight = meta_monitor_manager_handle_change_backlight;
iface->handle_get_crtc_gamma = meta_monitor_manager_handle_get_crtc_gamma;
iface->handle_set_crtc_gamma = meta_monitor_manager_handle_set_crtc_gamma;
iface->handle_get_current_state = meta_monitor_manager_handle_get_current_state;
iface->handle_apply_monitors_config = meta_monitor_manager_handle_apply_monitors_config;
g_signal_connect_object (manager->display_config, "handle-get-resources",
G_CALLBACK (meta_monitor_manager_handle_get_resources),
manager, 0);
g_signal_connect_object (manager->display_config, "handle-change-backlight",
G_CALLBACK (meta_monitor_manager_handle_change_backlight),
manager, 0);
g_signal_connect_object (manager->display_config, "handle-get-crtc-gamma",
G_CALLBACK (meta_monitor_manager_handle_get_crtc_gamma),
manager, 0);
g_signal_connect_object (manager->display_config, "handle-set-crtc-gamma",
G_CALLBACK (meta_monitor_manager_handle_set_crtc_gamma),
manager, 0);
g_signal_connect_object (manager->display_config, "handle-get-current-state",
G_CALLBACK (meta_monitor_manager_handle_get_current_state),
manager, 0);
g_signal_connect_object (manager->display_config, "handle-apply-monitors-config",
G_CALLBACK (meta_monitor_manager_handle_apply_monitors_config),
manager, 0);
}
static void
@ -2274,7 +2310,7 @@ on_bus_acquired (GDBusConnection *connection,
{
MetaMonitorManager *manager = user_data;
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager),
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager->display_config),
connection,
"/org/gnome/Mutter/DisplayConfig",
NULL);
@ -2712,7 +2748,9 @@ meta_monitor_manager_notify_monitors_changed (MetaMonitorManager *manager)
meta_backend_monitors_changed (manager->backend);
g_signal_emit (manager, signals[MONITORS_CHANGED_INTERNAL], 0);
g_signal_emit_by_name (manager, "monitors-changed");
g_signal_emit (manager, signals[MONITORS_CHANGED], 0);
meta_dbus_display_config_emit_monitors_changed (manager->display_config);
}
static void

View File

@ -54,9 +54,4 @@ MetaMonitorSwitchConfigType meta_monitor_manager_get_switch_config (MetaMonitorM
gint meta_monitor_manager_get_display_configuration_timeout (void);
#ifdef __GI_SCANNER__
/* Re-declaration of parent type for introspection */
GType meta_dbus_display_config_skeleton_get_type (void) G_GNUC_CONST;
#endif
#endif /* META_MONITOR_MANAGER_H */