[gnome-settings-daemon] media-keys: Remove old-style OSD



commit 5a8f80dc8d2a5ca755b0cc1c53ed489ce22ed1e7
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jun 10 13:48:58 2011 +0100

    media-keys: Remove old-style OSD
    
    We now draw all the time with cairo, and make the border square
    when we don't have compositing.

 plugins/media-keys/Makefile.am             |    6 --
 plugins/media-keys/acme.ui                 |   33 -------
 plugins/media-keys/gsd-media-keys-window.c |  131 +++++----------------------
 plugins/media-keys/gsd-osd-window.c        |   65 ++++----------
 4 files changed, 43 insertions(+), 192 deletions(-)
---
diff --git a/plugins/media-keys/Makefile.am b/plugins/media-keys/Makefile.am
index 6cc3a1a..3607725 100644
--- a/plugins/media-keys/Makefile.am
+++ b/plugins/media-keys/Makefile.am
@@ -183,17 +183,11 @@ if HAVE_PULSE
 test_media_keys_LDADD += $(top_builddir)/plugins/media-keys/cut-n-paste/libgvc.la
 endif
 
-gtkbuilderdir = $(pkgdatadir)
-gtkbuilder_DATA =	\
-	acme.ui		\
-	$(NULL)
-
 DIST_SUBDIRS = cut-n-paste
 
 EXTRA_DIST = 				\
 	gsd-marshal.list		\
 	$(plugin_in_files)		\
-	$(gtkbuilder_DATA)		\
 	$(pixmaps_DATA)			\
 	touchpad-enabled-template.svg	\
 	touchpad-disabled-template.svg	\
diff --git a/plugins/media-keys/gsd-media-keys-window.c b/plugins/media-keys/gsd-media-keys-window.c
index 01cf5e0..c74e2f8 100644
--- a/plugins/media-keys/gsd-media-keys-window.c
+++ b/plugins/media-keys/gsd-media-keys-window.c
@@ -42,63 +42,41 @@ struct GsdMediaKeysWindowPrivate
 
         guint                    volume_muted : 1;
         int                      volume_level;
-
-        GtkImage                *image;
-        GtkWidget               *progress;
 };
 
 G_DEFINE_TYPE (GsdMediaKeysWindow, gsd_media_keys_window, GSD_TYPE_OSD_WINDOW)
 
-static void
-volume_controls_set_visible (GsdMediaKeysWindow *window,
-                             gboolean            visible)
+static const char *
+get_image_name_for_volume (gboolean muted,
+			   int volume)
 {
-        if (window->priv->progress == NULL)
-                return;
+        static const char *icon_names[] = {
+                "audio-volume-muted-symbolic",
+                "audio-volume-low-symbolic",
+                "audio-volume-medium-symbolic",
+                "audio-volume-high-symbolic",
+                NULL
+        };
+        int n;
 
-        if (visible) {
-                gtk_widget_show (window->priv->progress);
+        if (muted) {
+                n = 0;
         } else {
-                gtk_widget_hide (window->priv->progress);
+                /* select image */
+                n = 3 * volume / 100 + 1;
+                if (n < 1) {
+                        n = 1;
+                } else if (n > 3) {
+                        n = 3;
+                }
         }
-}
 
-static void
-window_set_icon_name (GsdMediaKeysWindow *window,
-                      const char         *name)
-{
-        if (window->priv->image == NULL)
-                return;
-
-        gtk_image_set_from_icon_name (window->priv->image,
-                                      name, GTK_ICON_SIZE_DIALOG);
+	return icon_names[n];
 }
 
 static void
 action_changed (GsdMediaKeysWindow *window)
 {
-        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) {
-                switch (window->priv->action) {
-                case GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME:
-                        volume_controls_set_visible (window, TRUE);
-
-                        if (window->priv->volume_muted) {
-                                window_set_icon_name (window, "audio-volume-muted-symbolic");
-                        } else {
-                                window_set_icon_name (window, "audio-volume-high-symbolic");
-                        }
-
-                        break;
-                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;
-                }
-        }
-
         gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
 }
 
@@ -106,29 +84,12 @@ static void
 volume_level_changed (GsdMediaKeysWindow *window)
 {
         gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
-
-        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window)) && window->priv->progress != NULL) {
-                double fraction;
-
-                fraction = (double) window->priv->volume_level / 100.0;
-
-                gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (window->priv->progress),
-                                               fraction);
-        }
 }
 
 static void
 volume_muted_changed (GsdMediaKeysWindow *window)
 {
         gsd_osd_window_update_and_hide (GSD_OSD_WINDOW (window));
-
-        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) {
-                if (window->priv->volume_muted) {
-                        window_set_icon_name (window, "audio-volume-muted-symbolic");
-                } else {
-                        window_set_icon_name (window, "audio-volume-high-symbolic");
-                }
-        }
 }
 
 void
@@ -372,31 +333,15 @@ render_speaker (GsdMediaKeysWindow *window,
                 double              height)
 {
         GdkPixbuf         *pixbuf;
+        const char        *icon_name;
         int                icon_size;
-        int                n;
-        static const char *icon_names[] = {
-                "audio-volume-muted-symbolic",
-                "audio-volume-low-symbolic",
-                "audio-volume-medium-symbolic",
-                "audio-volume-high-symbolic",
-                NULL
-        };
 
-        if (window->priv->volume_muted) {
-                n = 0;
-        } else {
-                /* select image */
-                n = 3 * window->priv->volume_level / 100 + 1;
-                if (n < 1) {
-                        n = 1;
-                } else if (n > 3) {
-                        n = 3;
-                }
-        }
+	icon_name = get_image_name_for_volume (window->priv->volume_muted,
+					       window->priv->volume_level);
 
         icon_size = (int)width;
 
-        pixbuf = load_pixbuf (window, icon_names[n], icon_size);
+        pixbuf = load_pixbuf (window, icon_name, icon_size);
 
         if (pixbuf == NULL) {
                 return FALSE;
@@ -694,32 +639,6 @@ static void
 gsd_media_keys_window_init (GsdMediaKeysWindow *window)
 {
         window->priv = GSD_MEDIA_KEYS_WINDOW_GET_PRIVATE (window);
-
-        if (!gsd_osd_window_is_composited (GSD_OSD_WINDOW (window))) {
-                GtkBuilder *builder;
-                const gchar *objects[] = {"acme_box", NULL};
-                GtkWidget *box;
-
-                builder = gtk_builder_new ();
-                gtk_builder_add_objects_from_file (builder,
-                                                   GTKBUILDERDIR "/acme.ui",
-                                                   (char **) objects,
-                                                   NULL);
-
-                window->priv->image = GTK_IMAGE (gtk_builder_get_object (builder, "acme_image"));
-                g_object_set (G_OBJECT (window->priv->image), "use-fallback", TRUE, NULL);
-                window->priv->progress = GTK_WIDGET (gtk_builder_get_object (builder, "acme_volume_progressbar"));
-                box = GTK_WIDGET (gtk_builder_get_object (builder, "acme_box"));
-
-                if (box != NULL) {
-                        gtk_container_add (GTK_CONTAINER (window), box);
-                        gtk_widget_show_all (box);
-                }
-
-                /* The builder needs to stay alive until the window
-                   takes ownership of the box (and its children)  */
-                g_object_unref (builder);
-        }
 }
 
 GtkWidget *
diff --git a/plugins/media-keys/gsd-osd-window.c b/plugins/media-keys/gsd-osd-window.c
index db52c1a..60dfa11 100644
--- a/plugins/media-keys/gsd-osd-window.c
+++ b/plugins/media-keys/gsd-osd-window.c
@@ -422,6 +422,7 @@ draw_when_composited (GtkWidget *widget, cairo_t *orig_cr)
         int              height;
         GtkStyleContext *context;
         GdkRGBA          acolor;
+        gdouble          corner_radius;
 
         window = GSD_OSD_WINDOW (widget);
 
@@ -447,7 +448,11 @@ draw_when_composited (GtkWidget *widget, cairo_t *orig_cr)
         cairo_paint (cr);
 
         /* draw a box */
-        gsd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1);
+        if (window->priv->is_composited)
+                corner_radius = height / 10;
+        else
+                corner_radius = 0.0;
+        gsd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, corner_radius, width-1, height-1);
         gtk_style_context_get_background_color (context, GTK_STATE_NORMAL, &acolor);
         gsd_osd_window_color_reverse (&acolor);
         acolor.alpha = BG_ALPHA;
@@ -480,32 +485,6 @@ draw_when_composited (GtkWidget *widget, cairo_t *orig_cr)
         }
 }
 
-/* This is our draw handler when the window is *not* in a compositing manager.
- * We just draw a rectangular frame by hand.  We do this with hardcoded drawing code,
- * instead of GtkFrame, to avoid changing the window's internal widget hierarchy:  in
- * either case (composited or non-composited), callers can assume that this works
- * identically to a GtkWindow without any intermediate widgetry.
- */
-static void
-draw_when_not_composited (GtkWidget *widget, cairo_t *cr)
-{
-        GtkStyleContext *context;
-        int width;
-        int height;
-
-        width = gtk_widget_get_allocated_width (widget);
-        height = gtk_widget_get_allocated_width (widget);
-        context = gtk_widget_get_style_context (widget);
-
-        gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
-        gtk_render_frame (context,
-                          cr,
-                          0,
-                          0,
-                          width,
-                          height);
-}
-
 static gboolean
 gsd_osd_window_draw (GtkWidget *widget,
                      cairo_t   *cr)
@@ -515,10 +494,7 @@ gsd_osd_window_draw (GtkWidget *widget,
 
         window = GSD_OSD_WINDOW (widget);
 
-        if (window->priv->is_composited)
-                draw_when_composited (widget, cr);
-        else
-                draw_when_not_composited (widget, cr);
+        draw_when_composited (widget, cr);
 
         child = gtk_bin_get_child (GTK_BIN (window));
         if (child)
@@ -721,6 +697,8 @@ static void
 gsd_osd_window_init (GsdOsdWindow *window)
 {
         GdkScreen *screen;
+        gdouble scalew, scaleh, scale;
+        gint size;
 
         window->priv = GSD_OSD_WINDOW_GET_PRIVATE (window);
 
@@ -730,25 +708,18 @@ gsd_osd_window_init (GsdOsdWindow *window)
         window->priv->screen_width = gdk_screen_get_width (screen);
         window->priv->screen_height = gdk_screen_get_height (screen);
 
-        if (window->priv->is_composited) {
-                gdouble scalew, scaleh, scale;
-                gint size;
+        gtk_window_set_decorated (GTK_WINDOW (window), FALSE);
+        gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
 
-                gtk_window_set_decorated (GTK_WINDOW (window), FALSE);
-                gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
+        /* assume 130x130 on a 640x480 display and scale from there */
+        scalew = gdk_screen_get_width (screen) / 640.0;
+        scaleh = gdk_screen_get_height (screen) / 480.0;
+        scale = MIN (scalew, scaleh);
+        size = 130 * MAX (1, scale);
 
-                /* assume 130x130 on a 640x480 display and scale from there */
-                scalew = gdk_screen_get_width (screen) / 640.0;
-                scaleh = gdk_screen_get_height (screen) / 480.0;
-                scale = MIN (scalew, scaleh);
-                size = 130 * MAX (1, scale);
+        gtk_window_set_default_size (GTK_WINDOW (window), size, size);
 
-                gtk_window_set_default_size (GTK_WINDOW (window), size, size);
-
-                window->priv->fade_out_alpha = 1.0;
-        } else {
-                gtk_container_set_border_width (GTK_CONTAINER (window), 12);
-        }
+        window->priv->fade_out_alpha = 1.0;
 }
 
 GtkWidget *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]