commit 62ffa31710ed4b9bb009d674da91201f6a4ca332
Author: Bastien Nocera <hadess@hadess.net>
Date:   Fri Nov 6 11:45:44 2009 +0000

    [media-keys] Make OSD display more generic
    
    By allowing arbitrary icon-names for the display, and allowing
    choice of whether the level bar would be shown.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=600951

Index: gnome-settings-daemon-2.28.2/plugins/media-keys/gsd-media-keys-manager.c
===================================================================
--- gnome-settings-daemon-2.28.2.orig/plugins/media-keys/gsd-media-keys-manager.c
+++ gnome-settings-daemon-2.28.2/plugins/media-keys/gsd-media-keys-manager.c
@@ -596,8 +596,9 @@ do_eject_action (GsdMediaKeysManager *ma
         char *command;
 
         dialog_init (manager);
-        gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
-                                          GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT);
+        gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (manager->priv->dialog),
+                                                 "media-eject",
+                                                 FALSE);
         dialog_show (manager);
 
         command = gconf_client_get_string (manager->priv->conf_client,
Index: gnome-settings-daemon-2.28.2/plugins/media-keys/gsd-media-keys-window.c
===================================================================
--- gnome-settings-daemon-2.28.2.orig/plugins/media-keys/gsd-media-keys-window.c
+++ gnome-settings-daemon-2.28.2/plugins/media-keys/gsd-media-keys-window.c
@@ -48,6 +48,8 @@ struct GsdMediaKeysWindowPrivate
         guint                    fade_timeout_id;
         double                   fade_out_alpha;
         GsdMediaKeysWindowAction action;
+        char                    *icon_name;
+        gboolean                 show_level;
 
         guint                    volume_muted : 1;
         int                      volume_level;
@@ -182,15 +184,12 @@ action_changed (GsdMediaKeysWindow *wind
                         }
 
                         break;
-                case GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT:
-                        volume_controls_set_visible (window, FALSE);
-                        window_set_icon_name (window, "media-eject");
-                        break;
-                case GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS:
-                        volume_controls_set_visible (window, TRUE);
-                        window_set_icon_name (window, "gpm-brightness-lcd");
+                case GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM:
+                        volume_controls_set_visible (window, window->priv->show_level);
+                        window_set_icon_name (window, window->priv->icon_name);
                         break;
                 default:
+                        g_assert_not_reached ();
                         break;
                 }
         }
@@ -232,10 +231,34 @@ gsd_media_keys_window_set_action (GsdMed
                                   GsdMediaKeysWindowAction action)
 {
         g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
+        g_return_if_fail (action == GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME);
 
         if (window->priv->action != action) {
                 window->priv->action = action;
                 action_changed (window);
+        } else {
+                update_window (window);
+        }
+}
+
+void
+gsd_media_keys_window_set_action_custom (GsdMediaKeysWindow      *window,
+                                         const char              *icon_name,
+                                         gboolean                 show_level)
+{
+        g_return_if_fail (GSD_IS_MEDIA_KEYS_WINDOW (window));
+        g_return_if_fail (icon_name != NULL);
+
+        if (window->priv->action != GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM ||
+            g_strcmp0 (window->priv->icon_name, icon_name) != 0 ||
+            window->priv->show_level != show_level) {
+                window->priv->action = GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM;
+                g_free (window->priv->icon_name);
+                window->priv->icon_name = g_strdup (icon_name);
+                window->priv->show_level = show_level;
+                action_changed (window);
+        } else {
+                update_window (window);
         }
 }
 
@@ -356,36 +379,6 @@ load_pixbuf (GsdMediaKeysWindow *window,
         return pixbuf;
 }
 
-static gboolean
-render_eject (GsdMediaKeysWindow *window,
-              cairo_t            *cr,
-              double              x0,
-              double              y0,
-              double              width,
-              double              height)
-{
-        GdkPixbuf  *pixbuf;
-        int         icon_size;
-        const char *icon_name;
-
-        icon_name = "media-eject";
-
-        icon_size = (int)width;
-
-        pixbuf = load_pixbuf (window, icon_name, icon_size);
-
-        if (pixbuf == NULL) {
-                return FALSE;
-        }
-
-        gdk_cairo_set_source_pixbuf (cr, pixbuf, x0, y0);
-        cairo_paint_with_alpha (cr, FG_ALPHA);
-
-        g_object_unref (pixbuf);
-
-        return TRUE;
-}
-
 static void
 draw_eject (cairo_t *cr,
             double   x0,
@@ -417,43 +410,6 @@ draw_eject (cairo_t *cr,
 }
 
 static void
-draw_action_eject (GsdMediaKeysWindow *window,
-                   cairo_t            *cr)
-{
-        int      window_width;
-        int      window_height;
-        double   width;
-        double   height;
-        double   x0;
-        double   y0;
-        gboolean res;
-
-        gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height);
-
-        width = window_width * 0.65;
-        height = window_height * 0.65;
-        x0 = (window_width - width) / 2;
-        y0 = (window_height - height) / 2;
-
-#if 0
-        g_message ("eject box: w=%f h=%f x0=%f y0=%f",
-                   width,
-                   height,
-                   x0,
-                   y0);
-#endif
-
-        res = render_eject (window,
-                            cr,
-                            x0, y0,
-                            width, height);
-        if (! res) {
-                /* draw eject symbol */
-                draw_eject (cr, x0, y0, width, height);
-        }
-}
-
-static void
 draw_waves (cairo_t *cr,
             double   cx,
             double   cy,
@@ -752,25 +708,25 @@ draw_action_volume (GsdMediaKeysWindow *
 }
 
 static gboolean
-render_brightness (GsdMediaKeysWindow *window,
-                   cairo_t            *cr,
-                   double              x0,
-                   double              y0,
-                   double              width,
-                   double              height)
+render_custom (GsdMediaKeysWindow *window,
+               cairo_t            *cr,
+               double              _x0,
+               double              _y0,
+               double              width,
+               double              height)
 {
         GdkPixbuf         *pixbuf;
         int                icon_size;
 
         icon_size = (int)width;
 
-        pixbuf = load_pixbuf (window, "gpm-brightness-lcd", icon_size);
+	pixbuf = load_pixbuf (window, window->priv->icon_name, icon_size);
 
         if (pixbuf == NULL) {
                 return FALSE;
         }
 
-        gdk_cairo_set_source_pixbuf (cr, pixbuf, x0, y0);
+        gdk_cairo_set_source_pixbuf (cr, pixbuf, _x0, _y0);
         cairo_paint_with_alpha (cr, FG_ALPHA);
 
         g_object_unref (pixbuf);
@@ -779,8 +735,8 @@ render_brightness (GsdMediaKeysWindow *w
 }
 
 static void
-draw_action_brightness (GsdMediaKeysWindow *window,
-                        cairo_t            *cr)
+draw_action_custom (GsdMediaKeysWindow *window,
+                    cairo_t            *cr)
 {
         int window_width;
         int window_height;
@@ -819,19 +775,27 @@ draw_action_brightness (GsdMediaKeysWind
                    bright_box_y0);
 #endif
 
-        res = render_brightness (window,
-                                 cr,
-                                 icon_box_x0, icon_box_y0,
-                                 icon_box_width, icon_box_height);
+        res = render_custom (window,
+                             cr,
+                             icon_box_x0, icon_box_y0,
+                             icon_box_width, icon_box_height);
+        if (! res && g_strcmp0 (window->priv->icon_name, "media-eject") == 0) {
+                /* draw eject symbol */
+                draw_eject (cr,
+                            icon_box_x0, icon_box_y0,
+                            icon_box_width, icon_box_height);
+        }
 
-        /* draw volume meter */
-        draw_volume_boxes (window,
-                           cr,
-                           (double)window->priv->volume_level / 100.0,
-                           bright_box_x0,
-                           bright_box_y0,
-                           bright_box_width,
-                           bright_box_height);
+        if (window->priv->show_level != FALSE) {
+                /* draw volume meter */
+                draw_volume_boxes (window,
+                                   cr,
+                                   (double)window->priv->volume_level / 100.0,
+                                   bright_box_x0,
+                                   bright_box_y0,
+                                   bright_box_width,
+                                   bright_box_height);
+        }
 }
 
 static void
@@ -842,11 +806,8 @@ draw_action (GsdMediaKeysWindow *window,
         case GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME:
                 draw_action_volume (window, cr);
                 break;
-        case GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT:
-                draw_action_eject (window, cr);
-                break;
-        case GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS:
-                draw_action_brightness (window, cr);
+        case GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM:
+                draw_action_custom (window, cr);
                 break;
         default:
                 break;
Index: gnome-settings-daemon-2.28.2/plugins/media-keys/gsd-media-keys-window.h
===================================================================
--- gnome-settings-daemon-2.28.2.orig/plugins/media-keys/gsd-media-keys-window.h
+++ gnome-settings-daemon-2.28.2/plugins/media-keys/gsd-media-keys-window.h
@@ -49,8 +49,7 @@ struct GsdMediaKeysWindowClass {
 
 typedef enum {
         GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME,
-        GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT,
-        GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS
+        GSD_MEDIA_KEYS_WINDOW_ACTION_CUSTOM
 } GsdMediaKeysWindowAction;
 
 GType                 gsd_media_keys_window_get_type          (void);
@@ -58,6 +57,9 @@ GType                 gsd_media_keys_win
 GtkWidget *           gsd_media_keys_window_new               (void);
 void                  gsd_media_keys_window_set_action        (GsdMediaKeysWindow      *window,
                                                                GsdMediaKeysWindowAction action);
+void                  gsd_media_keys_window_set_action_custom (GsdMediaKeysWindow      *window,
+                                                               const char              *icon_name,
+                                                               gboolean                 show_level);
 void                  gsd_media_keys_window_set_volume_muted  (GsdMediaKeysWindow      *window,
                                                                gboolean                 muted);
 void                  gsd_media_keys_window_set_volume_level  (GsdMediaKeysWindow      *window,
Index: gnome-settings-daemon-2.28.2/plugins/media-keys/test-media-window.c
===================================================================
--- gnome-settings-daemon-2.28.2.orig/plugins/media-keys/test-media-window.c
+++ gnome-settings-daemon-2.28.2/plugins/media-keys/test-media-window.c
@@ -62,32 +62,36 @@ update_state (GtkWidget *window)
                 gtk_widget_show (window);
                 break;
         case 4:
-                gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window),
-                                                  GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT);
+                gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window),
+                                                         "media-eject",
+                                                         FALSE);
 
                 gtk_widget_show (window);
                 break;
         case 5:
                 gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window),
                                                         0);
-                gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window),
-                                                  GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS);
+                gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window),
+                                                         "gpm-brightness-lcd",
+                                                         TRUE);
 
                 gtk_widget_show (window);
                 break;
         case 6:
                 gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window),
                                                         50);
-                gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window),
-                                                  GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS);
+                gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window),
+                                                         "gpm-brightness-lcd",
+                                                         TRUE);
 
                 gtk_widget_show (window);
                 break;
         case 7:
                 gsd_media_keys_window_set_volume_level (GSD_MEDIA_KEYS_WINDOW (window),
                                                         100);
-                gsd_media_keys_window_set_action (GSD_MEDIA_KEYS_WINDOW (window),
-                                                  GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS);
+                gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (window),
+                                                         "gpm-brightness-lcd",
+                                                         TRUE);
 
                 gtk_widget_show (window);
                 break;
