Index: gnome-power-manager-2.27.1/src/gpm-feedback-widget.c =================================================================== --- gnome-power-manager-2.27.1.orig/src/gpm-feedback-widget.c 2009-06-19 10:59:20.000000000 +0200 +++ gnome-power-manager-2.27.1/src/gpm-feedback-widget.c 2009-06-19 12:24:41.000000000 +0200 @@ -30,6 +30,8 @@ #include "gpm-stock-icons.h" #include "egg-debug.h" +#include + static void gpm_feedback_finalize (GObject *object); static void gpm_feedback_show (GtkWidget *widget); @@ -44,6 +46,7 @@ GtkWidget *progress; guint timer_id; gchar *icon_name; + NotifyNotification *n; }; G_DEFINE_TYPE (GpmFeedback, gpm_feedback, G_TYPE_OBJECT) @@ -127,16 +130,104 @@ return FALSE; } +static gboolean +gpm_feedback_check_notification_server () +{ + gboolean supports_sync = FALSE; + GList *caps = NULL; + + caps = notify_get_server_caps (); + if (caps != NULL) { + if (g_list_find_custom (caps, + "x-canonical-private-synchronous", + (GCompareFunc) g_strcmp0) != NULL) + supports_sync = TRUE; + + g_list_foreach(caps, (GFunc)g_free, NULL); + g_list_free(caps); + } + + return supports_sync; +} + /** * gpm_feedback_display_value: **/ gboolean gpm_feedback_display_value (GpmFeedback *feedback, gfloat value) { + static const char *display_icon_name[] = { + "notification-display-brightness-off", + "notification-display-brightness-low", + "notification-display-brightness-medium", + "notification-display-brightness-high", + "notification-display-brightness-full", + NULL + }; + static const char *keyboard_icon_name[] = { + "notification-keyboard-brightness-off", + "notification-keyboard-brightness-low", + "notification-keyboard-brightness-medium", + "notification-keyboard-brightness-high", + "notification-keyboard-brightness-full", + NULL + }; + + const gchar *i18n_title; + int i; + g_return_val_if_fail (feedback != NULL, FALSE); g_return_val_if_fail (GPM_IS_FEEDBACK (feedback), FALSE); egg_debug ("Displaying %f on feedback widget", value); + + i18n_title = gtk_window_get_title (GTK_WINDOW (feedback->priv->main_window)); + + i = 4 * value + 1; + + if (value < 0) + { + i = 0; + } else if (i < 1) + i = 1; + else if (i > 4) + i = 4; + + if (gpm_feedback_check_notification_server ()) + { + notify_notification_set_hint_int32(feedback->priv->n, + "value", + value * 100); + if (!g_strcmp0 (feedback->priv->icon_name, + GPM_STOCK_BRIGHTNESS_LCD)) + { + notify_notification_set_hint_string(feedback->priv->n, + "x-canonical-private-synchronous", + "brightness"); + notify_notification_update (feedback->priv->n, + i18n_title, + "", + display_icon_name[i]); + } + + if (!g_strcmp0 (feedback->priv->icon_name, + GPM_STOCK_BRIGHTNESS_KBD)) + { + notify_notification_set_hint_string(feedback->priv->n, + "x-canonical-private-synchronous", + "kbd-brightness"); + /* TODO: same as above */ + notify_notification_update (feedback->priv->n, + i18n_title, + "", + keyboard_icon_name[i]); + } + + notify_notification_show (feedback->priv->n, NULL); + + return TRUE; + } + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (feedback->priv->progress), value); gpm_feedback_show (feedback->priv->main_window); @@ -202,6 +293,14 @@ /* hide until we get a request */ gtk_widget_hide (feedback->priv->main_window); + + if (! notify_is_initted()) + notify_init ("gnome-power-manager"); + + feedback->priv->n = notify_notification_new (" ", + "", + NULL, + NULL); } /** Index: gnome-power-manager-2.27.1/src/gpm-backlight.c =================================================================== --- gnome-power-manager-2.27.1.orig/src/gpm-backlight.c 2009-06-19 11:03:57.000000000 +0200 +++ gnome-power-manager-2.27.1/src/gpm-backlight.c 2009-06-19 12:45:54.000000000 +0200 @@ -202,6 +202,8 @@ gboolean hw_changed; guint value; guint old_value; + gboolean brightness_at_0; + gboolean brightness_at_100; if (backlight->priv->can_dim == FALSE) { egg_warning ("no dimming hardware"); @@ -216,6 +218,8 @@ /* get the last set brightness */ brightness = backlight->priv->master_percentage / 100.0f; + brightness_at_0 = brightness == 0.0f ? TRUE : FALSE; + brightness_at_100 = brightness == 1.0f ? TRUE : FALSE; egg_debug ("1. main brightness %f", brightness); /* get AC status */ @@ -269,6 +273,18 @@ /* convert to percentage */ value = (guint) ((brightness * 100.0f) + 0.5); + + /* only show dialog if interactive */ + if (interactive) + { + if (brightness_at_0 && brightness == 0.0f) + gpm_feedback_display_value (backlight->priv->feedback, -0.01f); + else if (brightness_at_100 && brightness == 1.0f) + gpm_feedback_display_value (backlight->priv->feedback, 1.01f); + else + gpm_feedback_display_value (backlight->priv->feedback, (float) brightness); + } + /* do not adjust down to zero */ if (value == 0) { egg_debug ("attempting to adjust to zero, skip"); @@ -282,10 +298,6 @@ return FALSE; } - /* only show dialog if interactive */ - if (interactive) - gpm_feedback_display_value (backlight->priv->feedback, (float) brightness); - ret = gpm_brightness_set (backlight->priv->brightness, value, &hw_changed); /* we emit a signal for the brightness applet */ if (ret && hw_changed) { @@ -364,8 +376,15 @@ GError *error = NULL; guint percentage; gboolean hw_changed; + gboolean percentage_at_0; + gboolean percentage_at_100; + egg_debug ("Button press event type=%s", type); + gpm_brightness_get (backlight->priv->brightness, &percentage); + percentage_at_0 = percentage == 0 ? TRUE : FALSE; + percentage_at_100 = percentage == 100 ? TRUE : FALSE; + if (strcmp (type, GPM_BUTTON_BRIGHT_UP) == 0) { /* go up one step */ ret = gpm_brightness_up (backlight->priv->brightness, &hw_changed); @@ -373,7 +392,10 @@ /* show the new value */ if (ret) { gpm_brightness_get (backlight->priv->brightness, &percentage); - gpm_feedback_display_value (backlight->priv->feedback, (float) percentage/100.0f); + if (percentage_at_100) + gpm_feedback_display_value (backlight->priv->feedback, 1.01f); + else + gpm_feedback_display_value (backlight->priv->feedback, (float) percentage/100.0f); /* save the new percentage */ backlight->priv->master_percentage = percentage; } @@ -389,7 +411,10 @@ /* show the new value */ if (ret) { gpm_brightness_get (backlight->priv->brightness, &percentage); - gpm_feedback_display_value (backlight->priv->feedback, (float) percentage/100.0f); + if (percentage_at_0) + gpm_feedback_display_value (backlight->priv->feedback, -0.01f); + else + gpm_feedback_display_value (backlight->priv->feedback, (float) percentage/100.0f); /* save the new percentage */ backlight->priv->master_percentage = percentage; } @@ -553,9 +578,22 @@ static void brightness_changed_cb (GpmBrightness *brightness, guint percentage, GpmBacklight *backlight) { + gboolean old_percentage_at_0; + gboolean old_percentage_at_100; + guint old_percentage; + + gpm_brightness_get (brightness, &old_percentage); + old_percentage_at_0 = old_percentage == 0 ? TRUE : FALSE; + old_percentage_at_100 = old_percentage == 100 ? TRUE : FALSE; + /* display the widget when something else changed the backlight */ egg_debug ("Need to display backlight feedback value %i", percentage); - gpm_feedback_display_value (backlight->priv->feedback, (float) percentage / 100.0f); + if (old_percentage_at_0 && percentage == 0) + gpm_feedback_display_value (backlight->priv->feedback, -0.01); + else if (old_percentage_at_100 && percentage == 100) + gpm_feedback_display_value (backlight->priv->feedback, 1.01f); + else + gpm_feedback_display_value (backlight->priv->feedback, (float) percentage / 100.0f); /* save the new percentage */ backlight->priv->master_percentage = percentage; Index: gnome-power-manager-2.27.1/src/gpm-manager.c =================================================================== --- gnome-power-manager-2.27.1.orig/src/gpm-manager.c 2009-06-19 11:08:06.000000000 +0200 +++ gnome-power-manager-2.27.1/src/gpm-manager.c 2009-06-19 12:51:07.000000000 +0200 @@ -1389,8 +1389,22 @@ static void brightness_kbd_changed_cb (GpmBrightnessKbd *brightness, gint percentage, GpmManager *manager) { + gboolean old_percentage_at_0; + gboolean old_percentage_at_100; + guint old_percentage; + + gpm_brightness_kbd_get (brightness, &old_percentage); + old_percentage_at_0 = old_percentage == 0 ? TRUE : FALSE; + old_percentage_at_100 = old_percentage == 100 ? TRUE : FALSE; + egg_debug ("Need to display backlight feedback value %i", percentage); - gpm_feedback_display_value (manager->priv->feedback_kbd, (float) percentage / 100.0f); + + if (old_percentage_at_0 && percentage == 0) + gpm_feedback_display_value (manager->priv->feedback_kbd, -0.01f); + else if (old_percentage_at_100 && percentage == 100) + gpm_feedback_display_value (manager->priv->feedback_kbd, 1.01f); + else + gpm_feedback_display_value (manager->priv->feedback_kbd, (float) percentage / 100.0f); } /**