diff options
author | Ali Abdallah <ali.slackware@gmail.com> | 2009-03-30 19:21:22 +0000 |
---|---|---|
committer | Ali Abdallah <ali.slackware@gmail.com> | 2009-03-30 19:21:22 +0000 |
commit | 83aa17c9aed47c1b1cd680fcd53775c07a3b2f45 (patch) | |
tree | 93968f3e66a45076d2f6fc502411fdafed3916e1 | |
parent | 63ecdeb37e90a3af9bfcc283cdce20392ade3908 (diff) | |
download | ixfce4-power-manager-83aa17c9aed47c1b1cd680fcd53775c07a3b2f45.tar.gz |
Added brightness popup+fix in XSyncAlarm error iin idle function+Fix reacration of popup window in the brightness plugin
(Old svn revision: 7053)
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | panel-plugins/brightness/brightness-plugin.c | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/xfpm-backlight.c | 39 | ||||
-rw-r--r-- | src/xfpm-brightness-hal.c | 54 | ||||
-rw-r--r-- | src/xfpm-brightness-hal.h | 9 | ||||
-rw-r--r-- | src/xfpm-brightness-widget.c | 218 | ||||
-rw-r--r-- | src/xfpm-brightness-widget.h | 59 | ||||
-rw-r--r-- | src/xfpm-idle.c | 5 |
10 files changed, 371 insertions, 22 deletions
@@ -1,4 +1,7 @@ +2009-03-30 21:21 Ali aliov@xfce.org + * : Added brightness popup+fix in XSyncAlarm error iin idle function+Fix reacration of popup window in the brightness plugin + 2009-03-30 14:58 Ali aliov@xfce.org * : Fix some typos, Thanks to Per Kongstad @@ -1,7 +1,5 @@ * : Should we inhibit the power manager when a screensaver is inhibited by a movie player? -* : Brightness popup indicating the current level. - * : Search for leacks if any. * : Option to sleep when system is idle for a long time (does anybody needs this?). diff --git a/panel-plugins/brightness/brightness-plugin.c b/panel-plugins/brightness/brightness-plugin.c index 50bd8664..3090875c 100644 --- a/panel-plugins/brightness/brightness-plugin.c +++ b/panel-plugins/brightness/brightness-plugin.c @@ -347,8 +347,6 @@ brightness_plugin_create_popup (brightness_t *plugin) gtk_box_pack_start (GTK_BOX(box), plugin->scale, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX(box), plugin->minus, FALSE, FALSE, 0); - - plugin->win = gtk_window_new (GTK_WINDOW_POPUP); gtk_window_set_type_hint (GTK_WINDOW(plugin->win), GDK_WINDOW_TYPE_HINT_UTILITY ); gtk_container_add (GTK_CONTAINER(plugin->win), box); diff --git a/src/Makefile.am b/src/Makefile.am index 9fbc2c55..4603f8d2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,6 +37,8 @@ xfce4_power_manager_SOURCES = \ xfpm-backlight.h \ xfpm-brightness-hal.c \ xfpm-brightness-hal.h \ + xfpm-brightness-widget.c \ + xfpm-brightness-widget.h \ xfpm-idle.c \ xfpm-idle.h \ xfpm-inhibit.c \ diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c index 7eca1f68..2a76f9c0 100644 --- a/src/xfpm-backlight.c +++ b/src/xfpm-backlight.c @@ -30,6 +30,7 @@ #include "xfpm-backlight.h" #include "xfpm-brightness-hal.h" +#include "xfpm-brightness-widget.h" /* Init */ static void xfpm_backlight_class_init (XfpmBacklightClass *klass); @@ -44,13 +45,27 @@ static void xfpm_backlight_dbus_init (XfpmBacklight *bk); struct XfpmBacklightPrivate { - XfpmBrightnessHal *br; + XfpmBrightnessHal *br; + XfpmBrightnessWidget *widget; + gboolean has_hw; }; G_DEFINE_TYPE(XfpmBacklight, xfpm_backlight, G_TYPE_OBJECT) static void +xfpm_backlight_brightness_up (XfpmBrightnessHal *brg, guint level, XfpmBacklight *bk) +{ + xfpm_brightness_widget_set_level (bk->priv->widget, level); +} + +static void +xfpm_backlight_brightness_down (XfpmBrightnessHal *brg, guint level, XfpmBacklight *bk) +{ + xfpm_brightness_widget_set_level (bk->priv->widget, level); +} + +static void xfpm_backlight_class_init(XfpmBacklightClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); @@ -65,13 +80,28 @@ xfpm_backlight_class_init(XfpmBacklightClass *klass) static void xfpm_backlight_init(XfpmBacklight *bk) { + guint max_level; + bk->priv = XFPM_BACKLIGHT_GET_PRIVATE(bk); bk->priv->br = xfpm_brightness_hal_new (); bk->priv->has_hw = xfpm_brightness_hal_has_hw (bk->priv->br); - if (!bk->priv->has_hw ) + if ( bk->priv->has_hw == FALSE ) g_object_unref (bk->priv->br); + else + { + bk->priv->widget = xfpm_brightness_widget_new (); + g_signal_connect (G_OBJECT(bk->priv->br), "brigthness-up", + G_CALLBACK (xfpm_backlight_brightness_up), bk); + + g_signal_connect (G_OBJECT(bk->priv->br), "brigthness-down", + G_CALLBACK (xfpm_backlight_brightness_down), bk); + + max_level = xfpm_brightness_hal_get_max_level (bk->priv->br); + xfpm_brightness_widget_set_max_level (bk->priv->widget, + max_level -1 ); + } xfpm_backlight_dbus_init (bk); } @@ -83,8 +113,11 @@ xfpm_backlight_finalize(GObject *object) bk = XFPM_BACKLIGHT(object); - if ( bk->priv->has_hw ) + if ( bk->priv->has_hw == TRUE ) + { g_object_unref (bk->priv->br); + g_object_unref (bk->priv->widget); + } G_OBJECT_CLASS(xfpm_backlight_parent_class)->finalize(object); } diff --git a/src/xfpm-brightness-hal.c b/src/xfpm-brightness-hal.c index 84e99669..0972c4c0 100644 --- a/src/xfpm-brightness-hal.c +++ b/src/xfpm-brightness-hal.c @@ -23,18 +23,8 @@ #endif #include <stdio.h> - -#ifdef HAVE_STDLIB_H #include <stdlib.h> -#endif - -#ifdef HAVE_STRING_H #include <string.h> -#endif - -#ifdef HAVE_ERRNO_H -#include <errno.h> -#endif #include <dbus/dbus-glib.h> @@ -72,8 +62,8 @@ struct XfpmBrightnessHalPrivate XfpmAdapter *adapter; XfpmScreenSaver *saver; - gint max_level; - gint hw_level; + guint max_level; + guint hw_level; gboolean brightness_in_hw; gboolean hw_found; gboolean block; @@ -90,6 +80,15 @@ enum TIMEOUT_ON_BATTERY_ID }; +enum +{ + BRIGHTNESS_UP, + BRIGHTNESS_DOWN, + LAST_SIGNAL +}; + +static guint signals [LAST_SIGNAL] = { 0 }; + G_DEFINE_TYPE(XfpmBrightnessHal, xfpm_brightness_hal, G_TYPE_OBJECT) static gint @@ -218,6 +217,7 @@ xfpm_brightness_hal_up (XfpmBrightnessHal *brg) TRACE ("Brightness key up"); xfpm_brightness_hal_set_level (brg, brg->priv->hw_level + 1 ); brg->priv->hw_level = xfpm_brightness_hal_get_level (brg); + g_signal_emit (G_OBJECT (brg), signals [BRIGHTNESS_UP], 0, brg->priv->hw_level); } } @@ -232,6 +232,7 @@ xfpm_brightness_hal_down (XfpmBrightnessHal *brg) TRACE("Brightness key down"); xfpm_brightness_hal_set_level (brg, brg->priv->hw_level - 1 ); brg->priv->hw_level = xfpm_brightness_hal_get_level (brg); + g_signal_emit (G_OBJECT (brg), signals [BRIGHTNESS_DOWN], 0, brg->priv->hw_level); } } @@ -367,6 +368,24 @@ xfpm_brightness_hal_class_init(XfpmBrightnessHalClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); + signals [BRIGHTNESS_UP] = + g_signal_new("brigthness-up", + XFPM_TYPE_BRIGHTNESS_HAL, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XfpmBrightnessHalClass, brightness_up), + NULL, NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); + + signals [BRIGHTNESS_DOWN] = + g_signal_new("brigthness-down", + XFPM_TYPE_BRIGHTNESS_HAL, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XfpmBrightnessHalClass, brightness_down), + NULL, NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); + object_class->finalize = xfpm_brightness_hal_finalize; g_type_class_add_private(klass,sizeof(XfpmBrightnessHalPrivate)); @@ -434,13 +453,13 @@ xfpm_brightness_hal_finalize (GObject *object) if ( brg->priv->proxy ) g_object_unref (brg->priv->proxy); - g_object_unref (brg->priv->idle); - g_object_unref (brg->priv->conf); g_object_unref (brg->priv->adapter); g_object_unref (brg->priv->saver); + + g_object_unref (brg->priv->idle); G_OBJECT_CLASS(xfpm_brightness_hal_parent_class)->finalize(object); } @@ -466,3 +485,10 @@ void xfpm_brightness_hal_update_level (XfpmBrightnessHal *brg, guint level) brg->priv->hw_level = level; } + +guint xfpm_brightness_hal_get_max_level (XfpmBrightnessHal *brg) +{ + g_return_val_if_fail (XFPM_IS_BRIGHTNESS_HAL (brg), 0); + + return brg->priv->max_level; +} diff --git a/src/xfpm-brightness-hal.h b/src/xfpm-brightness-hal.h index aba4ca81..b574677c 100644 --- a/src/xfpm-brightness-hal.h +++ b/src/xfpm-brightness-hal.h @@ -42,14 +42,23 @@ typedef struct { GObjectClass parent_class; + void (*brightness_up) (XfpmBrightnessHal *brg, + guint level); + + void (*brightness_down) (XfpmBrightnessHal *brg, + guint level); + } XfpmBrightnessHalClass; GType xfpm_brightness_hal_get_type (void) G_GNUC_CONST; XfpmBrightnessHal *xfpm_brightness_hal_new (void); gboolean xfpm_brightness_hal_has_hw (XfpmBrightnessHal *brg) G_GNUC_PURE; + void xfpm_brightness_hal_update_level (XfpmBrightnessHal *brg, guint level); + +guint xfpm_brightness_hal_get_max_level (XfpmBrightnessHal *brg) G_GNUC_PURE; G_END_DECLS #endif /* __XFPM_BRIGHTNESS_HAL_H */ diff --git a/src/xfpm-brightness-widget.c b/src/xfpm-brightness-widget.c new file mode 100644 index 00000000..386cba80 --- /dev/null +++ b/src/xfpm-brightness-widget.c @@ -0,0 +1,218 @@ +/* * + * Copyright (C) 2009 Ali <aliov@xfce.org> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <math.h> + +#include <gtk/gtk.h> +#include <glib.h> +#include <cairo.h> + +#include <libxfce4util/libxfce4util.h> + +#include "libxfpm/xfpm-common.h" + +#include "xfpm-brightness-widget.h" + + +/* Init */ +static void xfpm_brightness_widget_class_init (XfpmBrightnessWidgetClass *klass); +static void xfpm_brightness_widget_init (XfpmBrightnessWidget *widget); +static void xfpm_brightness_widget_finalize (GObject *object); + +#define XFPM_BRIGHTNESS_WIDGET_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_BRIGHTNESS_WIDGET, XfpmBrightnessWidgetPrivate)) + +#define WINDOW_HIDE_TIMEOUT 1.f + +struct XfpmBrightnessWidgetPrivate +{ + GtkWidget *window; + GTimer *timer; + guint level; + guint max_level; + + gboolean timeout_added; +}; + +G_DEFINE_TYPE (XfpmBrightnessWidget, xfpm_brightness_widget, G_TYPE_OBJECT) + +static gboolean +xfpm_brightness_widget_timeout (XfpmBrightnessWidget *widget) +{ + if ( g_timer_elapsed (widget->priv->timer, NULL) > WINDOW_HIDE_TIMEOUT ) + { + gtk_widget_hide_all (widget->priv->window); + widget->priv->timeout_added = FALSE; + return FALSE; + } + return TRUE; +} + +static gboolean +xfpm_brightness_widget_expose_event_cb (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 ); + + 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_set_source_rgb (cr, 0.9f, 0.9f, 0.9f); + cairo_paint (cr); + + x = widget->priv->window->allocation.width / 2; + y = widget->priv->window->allocation.height / 2; + + 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); + + cairo_destroy (cr); + + return FALSE; +} + +static void +xfpm_brightness_widget_set_colormap ( GtkWidget *widget) +{ + GdkScreen *screen = gtk_widget_get_screen (widget); + GdkColormap* colmap = gdk_screen_get_rgba_colormap (screen); + + if (!colmap) + colmap = gdk_screen_get_rgb_colormap (screen); + + gtk_widget_set_colormap (widget, colmap); +} + +static void +xfpm_brightness_widget_class_init (XfpmBrightnessWidgetClass *klass) +{ + 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->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); + + pix = xfpm_load_icon ("gpm-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); + } + + g_signal_connect (widget->priv->window, "expose-event", + G_CALLBACK (xfpm_brightness_widget_expose_event_cb), widget); + + xfpm_brightness_widget_set_colormap (widget->priv->window); + + widget->priv->timer = g_timer_new (); +} + +static void +xfpm_brightness_widget_finalize (GObject *object) +{ + XfpmBrightnessWidget *widget; + + widget = XFPM_BRIGHTNESS_WIDGET (object); + + gtk_widget_destroy (widget->priv->window); + + g_timer_destroy (widget->priv->timer); + + G_OBJECT_CLASS (xfpm_brightness_widget_parent_class)->finalize (object); +} + +XfpmBrightnessWidget * +xfpm_brightness_widget_new (void) +{ + XfpmBrightnessWidget *widget = NULL; + widget = g_object_new (XFPM_TYPE_BRIGHTNESS_WIDGET, NULL); + return widget; +} + +void xfpm_brightness_widget_set_max_level (XfpmBrightnessWidget *widget, guint level) +{ + g_return_if_fail (XFPM_IS_BRIGHTNESS_WIDGET (widget)); + + widget->priv->max_level = level; +} + +void xfpm_brightness_widget_set_level (XfpmBrightnessWidget *widget, guint level) +{ + g_return_if_fail (XFPM_IS_BRIGHTNESS_WIDGET (widget)); + + widget->priv->level = level; + + gtk_widget_queue_draw (widget->priv->window); + gtk_widget_show_all (widget->priv->window); + + if ( widget->priv->timeout_added == FALSE ) + { + g_timeout_add (100, (GSourceFunc) xfpm_brightness_widget_timeout, widget); + widget->priv->timeout_added = TRUE; + } + + g_timer_reset (widget->priv->timer); +} diff --git a/src/xfpm-brightness-widget.h b/src/xfpm-brightness-widget.h new file mode 100644 index 00000000..6f284664 --- /dev/null +++ b/src/xfpm-brightness-widget.h @@ -0,0 +1,59 @@ +/* * + * Copyright (C) 2009 Ali <aliov@xfce.org> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __XFPM_BRIGHTNESS_WIDGET_H +#define __XFPM_BRIGHTNESS_WIDGET_H + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define XFPM_TYPE_BRIGHTNESS_WIDGET (xfpm_brightness_widget_get_type () ) +#define XFPM_BRIGHTNESS_WIDGET(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_BRIGHTNESS_WIDGET, XfpmBrightnessWidget)) +#define XFPM_IS_BRIGHTNESS_WIDGET(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_BRIGHTNESS_WIDGET)) + +typedef struct XfpmBrightnessWidgetPrivate XfpmBrightnessWidgetPrivate; + +typedef struct +{ + GObject parent; + XfpmBrightnessWidgetPrivate *priv; + +} XfpmBrightnessWidget; + +typedef struct +{ + GObjectClass parent_class; + +} XfpmBrightnessWidgetClass; + +GType xfpm_brightness_widget_get_type (void) G_GNUC_CONST; + +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); + +G_END_DECLS + +#endif /* __XFPM_BRIGHTNESS_WIDGET_H */ diff --git a/src/xfpm-idle.c b/src/xfpm-idle.c index 282f48c3..daf4c199 100644 --- a/src/xfpm-idle.c +++ b/src/xfpm-idle.c @@ -280,7 +280,10 @@ xfpm_idle_init (XfpmIdle *idle) static void xfpm_idle_free_alarm (XfpmIdle *idle, IdleAlarm *alarm) { + gdk_error_trap_push (); XSyncDestroyAlarm (GDK_DISPLAY(), alarm->xalarm); + gdk_flush (); + gdk_error_trap_pop (); g_free(alarm); g_ptr_array_remove (idle->priv->array, alarm); } @@ -293,7 +296,7 @@ xfpm_idle_finalize(GObject *object) IdleAlarm *alarm; idle = XFPM_IDLE(object); - + for ( i = 0; i<idle->priv->array->len; i++) { alarm = g_ptr_array_index (idle->priv->array, i); |