diff options
author | Jian-Hong Pan <jian-hong@endlessm.com> | 2019-03-29 15:04:16 +0800 |
---|---|---|
committer | Jian-Hong Pan <jian-hong@endlessm.com> | 2019-03-29 15:04:16 +0800 |
commit | 61aa8b8c54148a1d8ae93cabe2c6a9923ce74d68 (patch) | |
tree | c4d3a0c3fe52de36b5ebbdf6f1143a624b04c71a | |
parent | dce8028ef85c487d2ae39831432104864aa95664 (diff) | |
download | gnome-settings-daemon-61aa8b8c54148a1d8ae93cabe2c6a9923ce74d68.tar.gz |
power: Implement screen brightness cycle up action
Implement the screen brightness cycle up action for the
SCREEN_BRIGHTNESS_CYCLE_KEY media-key.
GNOME/gnome-settings-daemon#117
-rw-r--r-- | plugins/power/gsd-backlight.c | 66 | ||||
-rw-r--r-- | plugins/power/gsd-backlight.h | 7 | ||||
-rw-r--r-- | plugins/power/gsd-power-manager.c | 8 |
3 files changed, 77 insertions, 4 deletions
diff --git a/plugins/power/gsd-backlight.c b/plugins/power/gsd-backlight.c index e60c649d..304c6d57 100644 --- a/plugins/power/gsd-backlight.c +++ b/plugins/power/gsd-backlight.c @@ -582,8 +582,8 @@ gsd_backlight_step_up_async (GsdBacklight *backlight, * * For simplicity it is also valid to call gsd_backlight_set_brightness_finish() * allowing sharing the callback routine for calls to - * gsd_backlight_set_brightness_async(), gsd_backlight_step_up_async() and - * gsd_backlight_step_down_async(). + * gsd_backlight_set_brightness_async(), gsd_backlight_step_up_async(), + * gsd_backlight_step_down_async() and gsd_backlight_cycle_up_async(). * * Returns: The brightness in percent that was set. **/ @@ -628,8 +628,8 @@ gsd_backlight_step_down_async (GsdBacklight *backlight, * * For simplicity it is also valid to call gsd_backlight_set_brightness_finish() * allowing sharing the callback routine for calls to - * gsd_backlight_set_brightness_async(), gsd_backlight_step_up_async() and - * gsd_backlight_step_down_async(). + * gsd_backlight_set_brightness_async(), gsd_backlight_step_up_async(), + * gsd_backlight_step_down_async() and gsd_backlight_cycle_up_async(). * * Returns: The brightness in percent that was set. **/ @@ -642,6 +642,64 @@ gsd_backlight_step_down_finish (GsdBacklight *backlight, } /** + * gsd_backlight_cycle_up_async + * @backlight: a #GsdBacklight + * @cancellable: an optional #GCancellable, NULL to ignore + * @callback: the #GAsyncReadyCallback invoked for cycle up to be finished + * @user_data: the #gpointer passed to the callback + * + * Start a brightness cycle up operation by gsd_backlight_cycle_up_async(). + * The brightness will be stepped up if it is not already at the maximum. + * If it is already at the maximum, it will be set to the minimum brightness. + **/ +void +gsd_backlight_cycle_up_async (GsdBacklight *backlight, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + if (backlight->brightness_target < backlight->brightness_max) + gsd_backlight_step_up_async (backlight, + cancellable, + callback, + user_data); + else + gsd_backlight_set_brightness_val_async (backlight, + backlight->brightness_min, + cancellable, + callback, + user_data); +} + +/** + * gsd_backlight_cycle_up_finish + * @backlight: a #GsdBacklight + * @res: the #GAsyncResult passed to the callback + * @error: #GError return address + * + * Finish an operation started by gsd_backlight_cycle_up_async(). Will return + * the value that was actually set (which may be different because of rounding + * or as multiple set actions were queued up). + * + * Please note that a call to gsd_backlight_get_brightness() may not in fact + * return the same value if further operations to set the value are pending. + * + * For simplicity it is also valid to call gsd_backlight_set_brightness_finish() + * allowing sharing the callback routine for calls to + * gsd_backlight_set_brightness_async(), gsd_backlight_step_up_async(), + * gsd_backlight_step_down_async() and gsd_backlight_cycle_up_async(). + * + * Returns: The brightness in percent that was set. + **/ +gint +gsd_backlight_cycle_up_finish (GsdBacklight *backlight, + GAsyncResult *res, + GError **error) +{ + return g_task_propagate_int (G_TASK (res), error); +} + +/** * gsd_backlight_get_output_id * @backlight: a #GsdBacklight * diff --git a/plugins/power/gsd-backlight.h b/plugins/power/gsd-backlight.h index 2d4f3339..71086a32 100644 --- a/plugins/power/gsd-backlight.h +++ b/plugins/power/gsd-backlight.h @@ -49,6 +49,10 @@ void gsd_backlight_step_down_async (GsdBacklight *backlight, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); +void gsd_backlight_cycle_up_async (GsdBacklight *backlight, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); gint gsd_backlight_set_brightness_finish (GsdBacklight *backlight, GAsyncResult *res, @@ -62,6 +66,9 @@ gint gsd_backlight_step_down_finish (GsdBacklight *backlight, GAsyncResult *res, GError **error); +gint gsd_backlight_cycle_up_finish (GsdBacklight *backlight, + GAsyncResult *res, + GError **error); gint gsd_backlight_get_output_id (GsdBacklight *backlight); GsdBacklight* gsd_backlight_new (GnomeRRScreen *screen, diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c index f82392b2..6af787f5 100644 --- a/plugins/power/gsd-power-manager.c +++ b/plugins/power/gsd-power-manager.c @@ -96,6 +96,10 @@ static const gchar introspection_xml[] = " <arg type='i' name='new_percentage' direction='out'/>" " <arg type='i' name='output_id' direction='out'/>" " </method>" +" <method name='Cycle'>" +" <arg type='i' name='new_percentage' direction='out'/>" +" <arg type='i' name='output_id' direction='out'/>" +" </method>" " </interface>" " <interface name='org.gnome.SettingsDaemon.Power.Keyboard'>" " <property name='Brightness' type='i' access='readwrite'/>" @@ -2843,6 +2847,10 @@ handle_method_call_screen (GsdPowerManager *manager, g_debug ("screen step down"); gsd_backlight_step_down_async (manager->backlight, NULL, backlight_brightness_step_cb, invocation); + } else if (g_strcmp0 (method_name, "Cycle") == 0) { + g_debug ("screen cycle up"); + gsd_backlight_cycle_up_async (manager->backlight, NULL, backlight_brightness_step_cb, invocation); + } else { g_assert_not_reached (); } |