From b3fa4a6cd8dccee17d49b2ec8934d9488071c10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sat, 4 Dec 2021 00:26:01 +0100 Subject: [PATCH] color-manager: Add API to set brightness It uses the org.gnome.SettingsDaemon.Power.Screen D-Bus API. Currently brightness set if the proxy is not ready are ignored; whether the brightness value should be cached and set once it appears or whether color profiles should be reapplied is yet to be decided. Part-of: --- .../org.gnome.SettingsDaemon.Power.Screen.xml | 5 ++ src/backends/meta-color-manager.c | 59 +++++++++++++++++++ src/backends/meta-color-manager.h | 3 + src/meson.build | 7 +++ 4 files changed, 74 insertions(+) create mode 100644 data/dbus-interfaces/org.gnome.SettingsDaemon.Power.Screen.xml diff --git a/data/dbus-interfaces/org.gnome.SettingsDaemon.Power.Screen.xml b/data/dbus-interfaces/org.gnome.SettingsDaemon.Power.Screen.xml new file mode 100644 index 000000000..05e4b8dc0 --- /dev/null +++ b/data/dbus-interfaces/org.gnome.SettingsDaemon.Power.Screen.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/backends/meta-color-manager.c b/src/backends/meta-color-manager.c index 0004af63c..face6abe2 100644 --- a/src/backends/meta-color-manager.c +++ b/src/backends/meta-color-manager.c @@ -53,6 +53,7 @@ #include "backends/meta-monitor.h" #include "meta-dbus-gsd-color.h" +#include "meta-dbus-gsd-power-screen.h" enum { @@ -79,6 +80,7 @@ typedef struct _MetaColorManagerPrivate GHashTable *devices; MetaDbusSettingsDaemonColor *gsd_color; + MetaDbusSettingsDaemonPowerScreen *gsd_power_screen; gboolean is_ready; } MetaColorManagerPrivate; @@ -243,6 +245,34 @@ on_gsd_color_ready (GObject *source_object, priv->gsd_color = gsd_color; } +static void +on_gsd_power_screen_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); + MetaDbusSettingsDaemonPowerScreen *gsd_power_screen; + g_autoptr (GError) error = NULL; + + gsd_power_screen = + meta_dbus_settings_daemon_power_screen_proxy_new_for_bus_finish (res, + &error); + if (!gsd_power_screen) + { + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + return; + + g_warning ("Failed to create gsd-power-screen D-Bus proxy: %s", error->message); + return; + } + + meta_topic (META_DEBUG_COLOR, + "Connection to org.gnome.SettingsDaemon.PowerScreen established"); + priv->gsd_power_screen = gsd_power_screen; +} + static void meta_color_manager_constructed (GObject *object) { @@ -266,6 +296,15 @@ meta_color_manager_constructed (GObject *object) priv->cancellable, on_gsd_color_ready, color_manager); + + meta_dbus_settings_daemon_power_screen_proxy_new_for_bus ( + G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + "org.gnome.SettingsDaemon.Power.Screen", + "/org/gnome/SettingsDaemon/Power", + priv->cancellable, + on_gsd_power_screen_ready, + color_manager); } static void @@ -278,6 +317,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_power_screen); g_clear_object (&priv->gsd_color); g_clear_object (&priv->color_store); g_clear_pointer (&priv->lcms_context, cmsDeleteContext); @@ -418,3 +458,22 @@ meta_color_manager_get_lcms_context (MetaColorManager *color_manager) return priv->lcms_context; } + +void +meta_color_manager_set_brightness (MetaColorManager *color_manager, + int brightness) +{ + MetaColorManagerPrivate *priv = + meta_color_manager_get_instance_private (color_manager); + + if (!priv->gsd_power_screen) + { + meta_topic (META_DEBUG_COLOR, + "No org.gnome.SettingsDaemon.Power.Screen service available, " + "not setting brightness"); + return; + } + + meta_dbus_settings_daemon_power_screen_set_brightness (priv->gsd_power_screen, + brightness); +} diff --git a/src/backends/meta-color-manager.h b/src/backends/meta-color-manager.h index ca263ac61..90369b8f7 100644 --- a/src/backends/meta-color-manager.h +++ b/src/backends/meta-color-manager.h @@ -35,4 +35,7 @@ META_EXPORT_TEST MetaColorDevice * meta_color_manager_get_color_device (MetaColorManager *color_manager, MetaMonitor *monitor); +void meta_color_manager_set_brightness (MetaColorManager *color_manager, + int brightness); + #endif /* META_COLOR_MANAGER_H */ diff --git a/src/meson.build b/src/meson.build index af492ed69..4bc295057 100644 --- a/src/meson.build +++ b/src/meson.build @@ -930,6 +930,13 @@ dbus_gsd_color_built_sources = gnome.gdbus_codegen('meta-dbus-gsd-color', ) mutter_built_sources += dbus_gsd_color_built_sources +dbus_gsd_power_screen_built_sources = gnome.gdbus_codegen('meta-dbus-gsd-power-screen', + join_paths(dbus_interfaces_dir, 'org.gnome.SettingsDaemon.Power.Screen.xml'), + interface_prefix: 'org.gnome.', + namespace: 'MetaDbus', +) +mutter_built_sources += dbus_gsd_power_screen_built_sources + wayland_protocol_server_headers = [] wayland_protocol_client_headers = [] wayland_protocol_sources = []