[gnome-settings-daemon] Add brightness to the media-keys popup
- From: Bastien Nocera <hadess src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] Add brightness to the media-keys popup
- Date: Fri, 6 Nov 2009 18:19:02 +0000 (UTC)
commit 7e4ce82e633725f601da244b351e5ee890bc80df
Author: Bastien Nocera <hadess hadess net>
Date: Mon Oct 26 17:00:22 2009 +0000
Add brightness to the media-keys popup
So that gnome-power-manager can copy/paste the files instead
of forking our code.
https://bugzilla.gnome.org/show_bug.cgi?id=599677
plugins/media-keys/Makefile.am | 1 +
plugins/media-keys/gsd-media-keys-window.c | 90 ++++++++++++++++++++++++++++
plugins/media-keys/gsd-media-keys-window.h | 3 +-
plugins/media-keys/test-media-window.c | 27 ++++++++
4 files changed, 120 insertions(+), 1 deletions(-)
---
diff --git a/plugins/media-keys/Makefile.am b/plugins/media-keys/Makefile.am
index 6be5a86..b662da8 100644
--- a/plugins/media-keys/Makefile.am
+++ b/plugins/media-keys/Makefile.am
@@ -79,6 +79,7 @@ test_media_window_SOURCES = \
test_media_window_CPPFLAGS = \
-I$(top_srcdir)/gnome-settings-daemon \
-I$(top_srcdir)/plugins/media-keys/cut-n-paste \
+ -DDATADIR=\""$(datadir)"\" \
-DPIXMAPDIR=\""$(pkgdatadir)"\" \
-DGTKBUILDERDIR=\""$(pkgdatadir)"\" \
-DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \
diff --git a/plugins/media-keys/gsd-media-keys-window.c b/plugins/media-keys/gsd-media-keys-window.c
index ec69598..e575c34 100644
--- a/plugins/media-keys/gsd-media-keys-window.c
+++ b/plugins/media-keys/gsd-media-keys-window.c
@@ -186,6 +186,10 @@ action_changed (GsdMediaKeysWindow *window)
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");
+ break;
default:
break;
}
@@ -773,6 +777,89 @@ draw_action_volume (GsdMediaKeysWindow *window,
volume_box_height);
}
+static gboolean
+render_brightness (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);
+
+ 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_action_brightness (GsdMediaKeysWindow *window,
+ cairo_t *cr)
+{
+ int window_width;
+ int window_height;
+ double icon_box_width;
+ double icon_box_height;
+ double icon_box_x0;
+ double icon_box_y0;
+ double bright_box_x0;
+ double bright_box_y0;
+ double bright_box_width;
+ double bright_box_height;
+ gboolean res;
+
+ gtk_window_get_size (GTK_WINDOW (window), &window_width, &window_height);
+
+ icon_box_width = round (window_width * 0.65);
+ icon_box_height = round (window_height * 0.65);
+ bright_box_width = round (icon_box_width);
+ bright_box_height = round (window_height * 0.05);
+
+ icon_box_x0 = (window_width - icon_box_width) / 2;
+ icon_box_y0 = (window_height - icon_box_height - bright_box_height) / 2;
+ bright_box_x0 = round (icon_box_x0);
+ bright_box_y0 = round (icon_box_height + icon_box_y0);
+
+#if 0
+ g_message ("icon box: w=%f h=%f x0=%f y0=%f",
+ icon_box_width,
+ icon_box_height,
+ icon_box_x0,
+ icon_box_y0);
+ g_message ("brightness box: w=%f h=%f x0=%f y0=%f",
+ bright_box_width,
+ bright_box_height,
+ bright_box_x0,
+ bright_box_y0);
+#endif
+
+ res = render_brightness (window,
+ 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);
+}
+
static void
draw_action (GsdMediaKeysWindow *window,
cairo_t *cr)
@@ -784,6 +871,9 @@ draw_action (GsdMediaKeysWindow *window,
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);
+ break;
default:
break;
}
diff --git a/plugins/media-keys/gsd-media-keys-window.h b/plugins/media-keys/gsd-media-keys-window.h
index ad75923..dd4ae90 100644
--- a/plugins/media-keys/gsd-media-keys-window.h
+++ b/plugins/media-keys/gsd-media-keys-window.h
@@ -49,7 +49,8 @@ struct GsdMediaKeysWindowClass {
typedef enum {
GSD_MEDIA_KEYS_WINDOW_ACTION_VOLUME,
- GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT
+ GSD_MEDIA_KEYS_WINDOW_ACTION_EJECT,
+ GSD_MEDIA_KEYS_WINDOW_ACTION_BRIGHTNESS
} GsdMediaKeysWindowAction;
GType gsd_media_keys_window_get_type (void);
diff --git a/plugins/media-keys/test-media-window.c b/plugins/media-keys/test-media-window.c
index a2a5ae1..503cbf3 100644
--- a/plugins/media-keys/test-media-window.c
+++ b/plugins/media-keys/test-media-window.c
@@ -67,6 +67,30 @@ update_state (GtkWidget *window)
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);
+
+ 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);
+
+ 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);
+
+ gtk_widget_show (window);
+ break;
default:
gtk_main_quit ();
break;
@@ -113,6 +137,9 @@ main (int argc,
exit (1);
}
+ gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+ DATADIR G_DIR_SEPARATOR_S "gnome-power-manager" G_DIR_SEPARATOR_S "icons");
+
test_window ();
gtk_main ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]