[Goodies-commits] r7629 - in xfce4-power-manager/trunk: . src
Ali Abdallah
aliov at xfce.org
Fri Jun 26 12:15:27 CEST 2009
Author: aliov
Date: 2009-06-26 10:15:27 +0000 (Fri, 26 Jun 2009)
New Revision: 7629
Modified:
xfce4-power-manager/trunk/ChangeLog
xfce4-power-manager/trunk/src/xfpm-brightness-widget.c
xfce4-power-manager/trunk/src/xfpm-brightness-widget.h
Log:
* Change the style of the brightness popup indicator.
Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog 2009-06-24 04:41:56 UTC (rev 7628)
+++ xfce4-power-manager/trunk/ChangeLog 2009-06-26 10:15:27 UTC (rev 7629)
@@ -1,3 +1,6 @@
+2009-06-26: 12:00 Ali aliov at xfce.org
+ * Change the style of the brightness popup indicator.
+
2009-06-21: 14:00 Ali aliov at xfce.org
* Make the generic common pointers static in the *_new functions.
* src/xfpm-xfconf.c free specs list after usage.
Modified: xfce4-power-manager/trunk/src/xfpm-brightness-widget.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-brightness-widget.c 2009-06-24 04:41:56 UTC (rev 7628)
+++ xfce4-power-manager/trunk/src/xfpm-brightness-widget.c 2009-06-26 10:15:27 UTC (rev 7629)
@@ -43,15 +43,17 @@
#define XFPM_BRIGHTNESS_WIDGET_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_BRIGHTNESS_WIDGET, XfpmBrightnessWidgetPrivate))
-#define WINDOW_HIDE_TIMEOUT 1.f
+#define WINDOW_HIDE_TIMEOUT 1.0f
+#define BRIGHTNESS_POPUP_SIZE 180
struct XfpmBrightnessWidgetPrivate
{
GtkWidget *window;
GTimer *timer;
+ GdkPixbuf *pix;
+
guint level;
guint max_level;
-
gboolean timeout_added;
};
@@ -62,7 +64,7 @@
{
if ( g_timer_elapsed (widget->priv->timer, NULL) > WINDOW_HIDE_TIMEOUT )
{
- gtk_widget_hide_all (widget->priv->window);
+ gtk_widget_hide (widget->priv->window);
widget->priv->timeout_added = FALSE;
return FALSE;
}
@@ -70,47 +72,59 @@
}
static gboolean
-xfpm_brightness_widget_expose_event_cb (GtkWidget *w, GdkEventExpose *ev, XfpmBrightnessWidget *widget)
+xfpm_brightness_widget_expose_event (GtkWidget *w, GdkEventExpose *ev, XfpmBrightnessWidget *widget)
{
cairo_t *cr;
- gdouble x, y;
- gdouble arc;
-
- g_return_val_if_fail ( widget->priv->max_level != 0, FALSE );
-
+ gdouble width;
+ gdouble padding;
+ guint i;
+
+ g_return_val_if_fail (widget->priv->max_level != 0, FALSE );
+
cr = gdk_cairo_create (widget->priv->window->window);
-
+
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 0.0f);
-
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_paint (cr);
+ cairo_paint (cr);
- //cairo_set_source_rgb (cr, 0.9f, 0.9f, 0.9f);
+ gdk_cairo_set_source_pixbuf (cr, widget->priv->pix, (180 - 128)/2, 0);
cairo_paint (cr);
- x = widget->priv->window->allocation.width / 2;
- y = widget->priv->window->allocation.height / 2;
+ width = (gdouble) (180-20) / widget->priv->max_level;
+ padding = width /10;
+ cairo_translate (cr, 10, 0);
- cairo_set_line_width (cr, 0);
-
- cairo_move_to (cr, x, y);
-
- arc = ( 2 * M_PI * (gdouble)widget->priv->level ) / (gdouble)widget->priv->max_level;
-
- cairo_arc (cr, x, y, x, 0, arc);
-
- cairo_set_source_rgb (cr, 0.9f, 0.8f, 0.0f);
-
- cairo_fill_preserve (cr);
- cairo_stroke (cr);
+ for ( i = 0; i < widget->priv->max_level; i++)
+ {
+ if ( i >= widget->priv->level )
+ {
+ cairo_set_source_rgb (cr, 0.3, 0.3, 0.4);
+ }
+ else
+ {
+ cairo_set_source_rgb (cr, 0.6, 1.0, 0.4);
+ }
+ cairo_rectangle (cr, (gdouble)i*width, 140, width - padding , 10);
+ cairo_fill (cr);
+
+ if ( i >= widget->priv->level )
+ {
+ cairo_set_source_rgb (cr, 0.3, 0.3, 0.3);
+ }
+ else
+ {
+ cairo_set_source_rgb (cr, 0.6, 1.0, 0.);
+ }
+ cairo_rectangle (cr, (gdouble)i*width, 150, width - padding , 10);
+ cairo_fill (cr);
+ }
cairo_destroy (cr);
-
- return FALSE;
+ return TRUE;
}
static void
-xfpm_brightness_widget_set_colormap ( GtkWidget *widget)
+xfpm_brightness_widget_set_colormap (GtkWidget *widget)
{
GdkScreen *screen = gtk_widget_get_screen (widget);
GdkColormap* colmap = gdk_screen_get_rgba_colormap (screen);
@@ -127,43 +141,39 @@
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = xfpm_brightness_widget_finalize;
-
+
g_type_class_add_private (klass, sizeof (XfpmBrightnessWidgetPrivate));
}
static void
xfpm_brightness_widget_init (XfpmBrightnessWidget *widget)
{
- GdkPixbuf *pix;
- GtkWidget *image;
+ widget->priv = XFPM_BRIGHTNESS_WIDGET_GET_PRIVATE (widget);
- widget->priv = XFPM_BRIGHTNESS_WIDGET_GET_PRIVATE (widget);
+ widget->priv->window = gtk_window_new (GTK_WINDOW_POPUP);
+ g_object_set (G_OBJECT (widget->priv->window),
+ "window-position", GTK_WIN_POS_CENTER_ALWAYS,
+ "decorated", FALSE,
+ "resizable", FALSE,
+ "type-hint", GDK_WINDOW_TYPE_HINT_UTILITY,
+ "app-paintable", TRUE,
+ NULL);
+
+
widget->priv->level = 0;
widget->priv->max_level = 0;
- widget->priv->window = gtk_window_new(GTK_WINDOW_POPUP);
- gtk_window_set_decorated (GTK_WINDOW (widget->priv->window), FALSE);
- gtk_window_set_resizable (GTK_WINDOW (widget->priv->window), TRUE);
- gtk_window_set_position (GTK_WINDOW (widget->priv->window), GTK_WIN_POS_CENTER_ALWAYS);
- gtk_widget_set_app_paintable (widget->priv->window, TRUE);
- gtk_widget_set_size_request (widget->priv->window, 148, 148);
- gtk_window_set_type_hint (GTK_WINDOW (widget->priv->window), GDK_WINDOW_TYPE_HINT_UTILITY);
+ gtk_widget_set_size_request (GTK_WIDGET (widget->priv->window), BRIGHTNESS_POPUP_SIZE, BRIGHTNESS_POPUP_SIZE);
- pix = xfpm_load_icon ("xfpm-brightness-lcd", 128 );
- if ( pix )
- {
- image = gtk_image_new_from_pixbuf (pix);
- g_object_unref (pix);
- gtk_container_add (GTK_CONTAINER (widget->priv->window), image);
- }
+ widget->priv->pix = xfpm_load_icon ("xfpm-brightness-lcd", 128);
- g_signal_connect (widget->priv->window, "expose-event",
- G_CALLBACK (xfpm_brightness_widget_expose_event_cb), widget);
+ xfpm_brightness_widget_set_colormap (GTK_WIDGET (widget->priv->window));
+
+ widget->priv->timer = g_timer_new ();
- xfpm_brightness_widget_set_colormap (widget->priv->window);
-
- widget->priv->timer = g_timer_new ();
+ g_signal_connect (widget->priv->window, "expose_event",
+ G_CALLBACK (xfpm_brightness_widget_expose_event), widget);
}
static void
@@ -173,9 +183,9 @@
widget = XFPM_BRIGHTNESS_WIDGET (object);
- gtk_widget_destroy (widget->priv->window);
-
g_timer_destroy (widget->priv->timer);
+ if ( widget->priv->pix )
+ gdk_pixbuf_unref (widget->priv->pix);
G_OBJECT_CLASS (xfpm_brightness_widget_parent_class)->finalize (object);
}
@@ -185,6 +195,7 @@
{
XfpmBrightnessWidget *widget = NULL;
widget = g_object_new (XFPM_TYPE_BRIGHTNESS_WIDGET, NULL);
+
return widget;
}
@@ -200,9 +211,9 @@
g_return_if_fail (XFPM_IS_BRIGHTNESS_WIDGET (widget));
widget->priv->level = level;
-
+
+ gtk_window_present (GTK_WINDOW (widget->priv->window));
gtk_widget_queue_draw (widget->priv->window);
- gtk_widget_show_all (widget->priv->window);
if ( widget->priv->timeout_added == FALSE )
{
Modified: xfce4-power-manager/trunk/src/xfpm-brightness-widget.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-brightness-widget.h 2009-06-24 04:41:56 UTC (rev 7628)
+++ xfce4-power-manager/trunk/src/xfpm-brightness-widget.h 2009-06-26 10:15:27 UTC (rev 7629)
@@ -21,6 +21,7 @@
#ifndef __XFPM_BRIGHTNESS_WIDGET_H
#define __XFPM_BRIGHTNESS_WIDGET_H
+#include <gtk/gtk.h>
#include <glib-object.h>
G_BEGIN_DECLS
@@ -44,15 +45,15 @@
} XfpmBrightnessWidgetClass;
-GType xfpm_brightness_widget_get_type (void) G_GNUC_CONST;
+GType xfpm_brightness_widget_get_type (void) G_GNUC_CONST;
-XfpmBrightnessWidget *xfpm_brightness_widget_new (void);
+XfpmBrightnessWidget *xfpm_brightness_widget_new (void);
void xfpm_brightness_widget_set_max_level (XfpmBrightnessWidget *widget,
guint level);
-void xfpm_brightness_widget_set_level (XfpmBrightnessWidget *widget,
- guint level);
+void xfpm_brightness_widget_set_level (XfpmBrightnessWidget *widget,
+ guint level);
G_END_DECLS
More information about the Goodies-commits
mailing list