From 43cd70089e921731633db1b1258d653c60cfedd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 29 Oct 2021 11:23:18 +0200 Subject: [PATCH] color-manager: Set up a D-Bus proxy to org.gnome.SettingsDaemon.Color gsd-color provides this API, which exposes details about the night light state. Currently, gsd-color also turns this state into CRTC gamma changes, but this will eventually change, and this is a preparation for this. The proxy isn't yet used for anything. Part-of: --- .../org.gnome.SettingsDaemon.Color.xml | 7 ++++ src/backends/meta-color-manager.c | 41 +++++++++++++++++++ src/meson.build | 7 ++++ src/tests/dbusmock-templates/gsd-color.py | 31 ++++++++++++++ src/tests/meta-dbus-runner.py | 1 + 5 files changed, 87 insertions(+) create mode 100644 data/dbus-interfaces/org.gnome.SettingsDaemon.Color.xml create mode 100644 src/tests/dbusmock-templates/gsd-color.py diff --git a/data/dbus-interfaces/org.gnome.SettingsDaemon.Color.xml b/data/dbus-interfaces/org.gnome.SettingsDaemon.Color.xml new file mode 100644 index 000000000..ead0096b8 --- /dev/null +++ b/data/dbus-interfaces/org.gnome.SettingsDaemon.Color.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/backends/meta-color-manager.c b/src/backends/meta-color-manager.c index c7bdc77e4..fd1b47814 100644 --- a/src/backends/meta-color-manager.c +++ b/src/backends/meta-color-manager.c @@ -51,6 +51,8 @@ #include "backends/meta-color-device.h" #include "backends/meta-monitor.h" +#include "meta-dbus-gsd-color.h" + enum { PROP_0, @@ -70,6 +72,8 @@ typedef struct _MetaColorManagerPrivate GCancellable *cancellable; GHashTable *devices; + + MetaDbusSettingsDaemonColor *gsd_color; } MetaColorManagerPrivate; G_DEFINE_TYPE_WITH_PRIVATE (MetaColorManager, meta_color_manager, G_TYPE_OBJECT) @@ -201,6 +205,33 @@ cd_client_connect_cb (GObject *source_object, color_manager); } +static void +on_gsd_color_ready (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + MetaColorManager *color_manager = META_COLOR_MANAGER (user_data); + MetaColorManagerPrivate *priv = + meta_color_manager_get_instance_private (color_manager); + MetaDbusSettingsDaemonColor *gsd_color; + g_autoptr (GError) error = NULL; + + gsd_color = + meta_dbus_settings_daemon_color_proxy_new_for_bus_finish (res, &error); + if (!gsd_color) + { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + + g_warning ("Failed to create gsd-color D-Bus proxy: %s", error->message); + return; + } + + meta_topic (META_DEBUG_COLOR, + "Connection to org.gnome.SettingsDaemon.Color established"); + priv->gsd_color = gsd_color; +} + static void meta_color_manager_constructed (GObject *object) { @@ -213,6 +244,15 @@ meta_color_manager_constructed (GObject *object) priv->cd_client = cd_client_new (); cd_client_connect (priv->cd_client, priv->cancellable, cd_client_connect_cb, color_manager); + + meta_dbus_settings_daemon_color_proxy_new_for_bus ( + G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + "org.gnome.SettingsDaemon.Color", + "/org/gnome/SettingsDaemon/Color", + priv->cancellable, + on_gsd_color_ready, + color_manager); } static void @@ -225,6 +265,7 @@ meta_color_manager_finalize (GObject *object) g_cancellable_cancel (priv->cancellable); g_clear_object (&priv->cancellable); g_clear_pointer (&priv->devices, g_hash_table_unref); + g_clear_object (&priv->gsd_color); G_OBJECT_CLASS (meta_color_manager_parent_class)->finalize (object); } diff --git a/src/meson.build b/src/meson.build index 160606dc5..adcfbad95 100644 --- a/src/meson.build +++ b/src/meson.build @@ -918,6 +918,13 @@ dbus_rtkit_built_sources = gnome.gdbus_codegen('meta-dbus-rtkit1', ) mutter_built_sources += dbus_rtkit_built_sources +dbus_gsd_color_built_sources = gnome.gdbus_codegen('meta-dbus-gsd-color', + join_paths(dbus_interfaces_dir, 'org.gnome.SettingsDaemon.Color.xml'), + interface_prefix: 'org.gnome.', + namespace: 'MetaDbus', +) +mutter_built_sources += dbus_gsd_color_built_sources + wayland_protocol_server_headers = [] wayland_protocol_client_headers = [] wayland_protocol_sources = [] diff --git a/src/tests/dbusmock-templates/gsd-color.py b/src/tests/dbusmock-templates/gsd-color.py new file mode 100644 index 000000000..9db39dcf0 --- /dev/null +++ b/src/tests/dbusmock-templates/gsd-color.py @@ -0,0 +1,31 @@ +'''gsd-color proxy mock template +''' + +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) any +# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text +# of the license. + +__author__ = 'Jonas Ã…dahl' +__copyright__ = '(c) 2021 Red Hat Inc.' + +import dbus +import os +from dbusmock import MOCK_IFACE + + +BUS_NAME = 'org.gnome.SettingsDaemon.Color' +MAIN_OBJ = '/org/gnome/SettingsDaemon/Color' +MAIN_IFACE = BUS_NAME +SYSTEM_BUS = False + + +def load(mock, parameters=None): + mock.night_light_active = False + mock.temperature = 6500 + + mock.AddProperty(MAIN_IFACE, 'NightLightActive', dbus.Boolean()) + mock.AddProperty(MAIN_IFACE, 'Temperature', dbus.UInt32()) + mock.Set(MAIN_IFACE, 'NightLightActive', mock.night_light_active) + mock.Set(MAIN_IFACE, 'Temperature', dbus.UInt32(mock.temperature)) diff --git a/src/tests/meta-dbus-runner.py b/src/tests/meta-dbus-runner.py index 41dcdab2d..9c4ce00a6 100755 --- a/src/tests/meta-dbus-runner.py +++ b/src/tests/meta-dbus-runner.py @@ -43,6 +43,7 @@ class MutterDBusTestCase(DBusTestCase): klass.start_from_local_template('localed') klass.start_from_local_template('colord') + klass.start_from_local_template('gsd-color') klass.system_bus_con = klass.get_dbus(system_bus=True) klass.session_bus_con = klass.get_dbus(system_bus=False)