[Goodies-commits] r5549 - xfce4-power-manager/trunk/src
Ali Abdallah
aliov at xfce.org
Fri Oct 10 07:28:32 CEST 2008
Author: aliov
Date: 2008-10-10 05:28:32 +0000 (Fri, 10 Oct 2008)
New Revision: 5549
Modified:
xfce4-power-manager/trunk/src/xfpm-ac-adapter.c
xfce4-power-manager/trunk/src/xfpm-battery.c
xfce4-power-manager/trunk/src/xfpm-button.c
xfce4-power-manager/trunk/src/xfpm-button.h
xfce4-power-manager/trunk/src/xfpm-driver.c
xfce4-power-manager/trunk/src/xfpm-hal.c
xfce4-power-manager/trunk/src/xfpm-hal.h
xfce4-power-manager/trunk/src/xfpm-settings.c
Log:
Sleep,lid and power buttons support
Modified: xfce4-power-manager/trunk/src/xfpm-ac-adapter.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-ac-adapter.c 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-ac-adapter.c 2008-10-10 05:28:32 UTC (rev 5549)
@@ -208,7 +208,7 @@
int i;
for ( i = 0 ; udi[i]; i++)
{
- if ( xfpm_hal_device_has_key(priv->hal,udi[i],"ac_adapter.present"))
+ if ( xfpm_hal_device_have_key(priv->hal,udi[i],"ac_adapter.present"))
{
priv->present = xfpm_hal_get_bool_info(priv->hal,
udi[i],
@@ -235,7 +235,7 @@
const gchar *key,gboolean is_removed,
gboolean is_added,XfpmAcAdapter *adapter)
{
- if ( xfpm_hal_device_has_key(hal,udi,"ac_adapter.present"))
+ if ( xfpm_hal_device_have_key(hal,udi,"ac_adapter.present"))
{
XfpmAcAdapterPrivate *priv;
priv = XFPM_AC_ADAPTER_GET_PRIVATE(adapter);
Modified: xfce4-power-manager/trunk/src/xfpm-battery.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-battery.c 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-battery.c 2008-10-10 05:28:32 UTC (rev 5549)
@@ -566,7 +566,7 @@
XfpmBatteryPrivate *priv;
priv = XFPM_BATTERY_GET_PRIVATE(batt);
- if ( xfpm_hal_device_has_key(priv->hal,udi,"battery.is_rechargeable") )
+ if ( xfpm_hal_device_have_key(priv->hal,udi,"battery.is_rechargeable") )
{
xfpm_battery_new_device(batt,udi);
xfpm_battery_refresh(batt);
@@ -607,7 +607,7 @@
}
/* A device can have a battery key but is useless to monitor unless it's rechargeable*/
- if ( xfpm_hal_device_has_key(priv->hal,udi,"battery.is_rechargeable") )
+ if ( xfpm_hal_device_have_key(priv->hal,udi,"battery.is_rechargeable") )
{
GtkStatusIcon *icon;
icon = g_hash_table_lookup(priv->batteries,udi);
@@ -989,12 +989,12 @@
priv = XFPM_BATTERY_GET_PRIVATE(batt);
// Sanity check
- if ( !xfpm_hal_device_has_key(priv->hal,udi,"battery.reporting.last_full") ||
- !xfpm_hal_device_has_key(priv->hal,udi,"battery.reporting.current") ||
- !xfpm_hal_device_has_key(priv->hal,udi,"battery.charge_level.percentage") ||
- !xfpm_hal_device_has_key(priv->hal,udi,"battery.present") ||
- !xfpm_hal_device_has_key(priv->hal,udi,"battery.rechargeable.is_charging") ||
- !xfpm_hal_device_has_key(priv->hal,udi,"battery.type") )
+ if ( !xfpm_hal_device_have_key(priv->hal,udi,"battery.reporting.last_full") ||
+ !xfpm_hal_device_have_key(priv->hal,udi,"battery.reporting.current") ||
+ !xfpm_hal_device_have_key(priv->hal,udi,"battery.charge_level.percentage") ||
+ !xfpm_hal_device_have_key(priv->hal,udi,"battery.present") ||
+ !xfpm_hal_device_have_key(priv->hal,udi,"battery.rechargeable.is_charging") ||
+ !xfpm_hal_device_have_key(priv->hal,udi,"battery.type") )
{
return FALSE;
}
@@ -1133,7 +1133,7 @@
}
for ( i = 0 ; udi[i]; i++)
{
- if ( xfpm_hal_device_has_key(priv->hal,udi[i],"battery.is_rechargeable"))
+ if ( xfpm_hal_device_have_key(priv->hal,udi[i],"battery.is_rechargeable"))
{
XFPM_DEBUG("found battery %s\n",udi[i]);
xfpm_battery_new_device(batt,udi[i]);
Modified: xfce4-power-manager/trunk/src/xfpm-button.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-button.c 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-button.c 2008-10-10 05:28:32 UTC (rev 5549)
@@ -47,6 +47,7 @@
#include "xfpm-hal.h"
#include "xfpm-debug.h"
#include "xfpm-common.h"
+#include "xfpm-notify.h"
#include "xfpm-enum-types.h"
#define XFPM_BUTTON_GET_PRIVATE(o) \
@@ -64,6 +65,13 @@
guint prop_id,
GValue *value,
GParamSpec *pspec);
+static void xfpm_button_do_suspend(XfpmButton *bt);
+static void xfpm_button_do_hibernate(XfpmButton *bt);
+static gboolean xfpm_button_hibernate(XfpmButton *bt);
+static gboolean xfpm_button_suspend(XfpmButton *bt);
+
+static void xfpm_button_handle_condition_detail(XfpmButton *bt,
+ const gchar *condition_detail);
static void xfpm_button_handle_device_condition_cb(XfpmHal *hal,
const gchar *udi,
@@ -72,13 +80,24 @@
XfpmButton *bt);
static void xfpm_button_load_config(XfpmButton *bt);
+static void xfpm_button_get_switches(XfpmButton *bt);
struct XfpmButtonPrivate
{
XfpmHal *hal;
+ GHashTable *buttons;
+ gulong handler_id;
};
+typedef enum
+{
+ LID,
+ SLEEP,
+ POWER
+
+} XfpmSwitchButton;
+
G_DEFINE_TYPE(XfpmButton,xfpm_button,G_TYPE_OBJECT)
enum
@@ -132,16 +151,18 @@
XfpmButtonPrivate *priv;
priv = XFPM_BUTTON_GET_PRIVATE(bt);
+ priv->buttons = g_hash_table_new(g_str_hash,g_str_equal);
+
priv->hal = xfpm_hal_new();
xfpm_button_load_config(bt);
+ xfpm_button_get_switches(bt);
+ priv->handler_id =
g_signal_connect(priv->hal,"xfpm-device-condition",
G_CALLBACK(xfpm_button_handle_device_condition_cb),bt);
-
}
-
static void xfpm_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -221,18 +242,129 @@
G_OBJECT_CLASS(xfpm_button_parent_class)->finalize(object);
}
+static gboolean
+_unblock_handler(XfpmButtonPrivate *priv)
+{
+ g_signal_handler_unblock(priv->hal,priv->handler_id);
+ return FALSE;
+}
+
+static gboolean
+xfpm_button_suspend(XfpmButton *bt)
+{
+ XfpmButtonPrivate *priv;
+ priv = XFPM_BUTTON_GET_PRIVATE(bt);
+
+ guint8 critical;
+
+ xfpm_hal_suspend(priv->hal,NULL,&critical);
+ g_timeout_add(10,(GSourceFunc)_unblock_handler,priv);
+
+ return FALSE;
+}
+
+static gboolean
+xfpm_button_hibernate(XfpmButton *bt)
+{
+ XfpmButtonPrivate *priv;
+ priv = XFPM_BUTTON_GET_PRIVATE(bt);
+ guint8 critical;
+
+ xfpm_hal_hibernate(priv->hal,NULL,&critical);
+ g_timeout_add(10,(GSourceFunc)_unblock_handler,priv);
+
+ return FALSE;
+}
+
static void
+xfpm_button_do_hibernate(XfpmButton *bt)
+{
+ XfpmButtonPrivate *priv;
+ priv = XFPM_BUTTON_GET_PRIVATE(bt);
+
+ g_signal_handler_block(priv->hal,priv->handler_id);
+ g_timeout_add_seconds(2,(GSourceFunc)xfpm_button_hibernate,bt);
+
+}
+
+static void
+xfpm_button_do_suspend(XfpmButton *bt)
+{
+ XfpmButtonPrivate *priv;
+ priv = XFPM_BUTTON_GET_PRIVATE(bt);
+
+ g_signal_handler_block(priv->hal,priv->handler_id);
+ g_timeout_add_seconds(2,(GSourceFunc)xfpm_button_suspend,bt);
+}
+
+static void
+xfpm_button_handle_condition_detail(XfpmButton *bt,const gchar *condition_detail)
+{
+ if ( !strcmp(condition_detail,"lid") && bt->lid_action != BUTTON_DO_NOTHING )
+ {
+ if ( bt->lid_action == BUTTON_DO_SUSPEND )
+ {
+ xfpm_lock_screen();
+ xfpm_button_do_suspend(bt);
+ }
+ else if ( bt->lid_action == BUTTON_DO_HIBERNATE )
+ {
+ xfpm_lock_screen();
+ xfpm_button_do_hibernate(bt);
+ }
+ }
+
+ else if ( !strcmp(condition_detail,"sleep") && bt->sleep_action != BUTTON_DO_NOTHING )
+ {
+ if ( bt->sleep_action == BUTTON_DO_SUSPEND )
+ {
+ xfpm_lock_screen();
+ xfpm_button_do_suspend(bt);
+ }
+ else if ( bt->sleep_action == BUTTON_DO_HIBERNATE )
+ {
+ xfpm_lock_screen();
+ xfpm_button_do_hibernate(bt);
+ }
+ }
+
+ else if ( !strcmp(condition_detail,"power") && bt->lid_action != BUTTON_DO_NOTHING )
+ {
+ if ( bt->power_action == BUTTON_DO_SUSPEND )
+ {
+ xfpm_lock_screen();
+ xfpm_button_do_suspend(bt);
+ }
+ else if ( bt->power_action == BUTTON_DO_HIBERNATE )
+ {
+ xfpm_lock_screen();
+ xfpm_button_do_hibernate(bt);
+ }
+ }
+}
+
+static void
xfpm_button_handle_device_condition_cb(XfpmHal *hal,
const gchar *udi,
const gchar *condition_name,
const gchar *condition_detail,
XfpmButton *bt)
{
- XFPM_DEBUG("condition name=%s detail=%s\n",condition_name,condition_detail);
+ XfpmButtonPrivate *priv;
+ priv = XFPM_BUTTON_GET_PRIVATE(bt);
+ if ( xfpm_hal_device_have_capability(priv->hal,udi,"button") )
+ {
+ if ( strcmp(condition_name,"ButtonPressed") )
+ {
+ XFPM_DEBUG("Not processing event with condition_name=%s\n",condition_name);
+ return;
+ }
+ XFPM_DEBUG("proccessing event: %s %s\n",condition_name,condition_detail);
+ xfpm_button_handle_condition_detail(bt,condition_detail);
+ }
}
-
static void
xfpm_button_load_config(XfpmButton *bt)
{
@@ -253,14 +385,39 @@
channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
- bt->lid_action = xfconf_channel_get_bool(channel,LID_SWITCH_CFG,BUTTON_DO_NOTHING);
- bt->sleep_action = xfconf_channel_get_bool(channel,SLEEP_SWITCH_CFG,BUTTON_DO_NOTHING);
- bt->power_action = xfconf_channel_get_bool(channel,POWER_SWITCH_CFG,BUTTON_DO_NOTHING);
+ bt->lid_action = xfconf_channel_get_uint(channel,LID_SWITCH_CFG,BUTTON_DO_NOTHING);
+ bt->sleep_action = xfconf_channel_get_uint(channel,SLEEP_SWITCH_CFG,BUTTON_DO_NOTHING);
+ bt->power_action = xfconf_channel_get_uint(channel,POWER_SWITCH_CFG,BUTTON_DO_NOTHING);
g_object_unref(channel);
xfconf_shutdown();
}
+static void
+xfpm_button_get_switches(XfpmButton *bt)
+{
+ XfpmButtonPrivate *priv;
+ priv = XFPM_BUTTON_GET_PRIVATE(bt);
+
+ gchar **udi;
+ gint dummy;
+ GError *error = NULL;
+
+ udi = xfpm_hal_get_device_udi_by_capability(priv->hal,"button",&dummy,&error);
+
+ if ( !udi )
+ {
+ XFPM_DEBUG("No buttons found\n");
+ }
+ int i = 0 ;
+ for ( i = 0 ; udi[i] ; i++)
+ {
+
+ }
+
+ libhal_free_string_array(udi);
+}
+
XfpmButton *
xfpm_button_new(void)
{
Modified: xfce4-power-manager/trunk/src/xfpm-button.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-button.h 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-button.h 2008-10-10 05:28:32 UTC (rev 5549)
@@ -48,6 +48,7 @@
typedef struct
{
GObjectClass parent_class;
+
} XfpmButtonClass;
GType xfpm_button_get_type(void) G_GNUC_CONST;
Modified: xfce4-power-manager/trunk/src/xfpm-driver.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-driver.c 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-driver.c 2008-10-10 05:28:32 UTC (rev 5549)
@@ -412,6 +412,11 @@
XfpmDriverPrivate *priv;
priv = XFPM_DRIVER_GET_PRIVATE(drv);
+ if ( priv->dialog_opened )
+ {
+ return FALSE;
+ }
+
XfconfChannel *channel;
GtkWidget *dialog;
Modified: xfce4-power-manager/trunk/src/xfpm-hal.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-hal.c 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-hal.c 2008-10-10 05:28:32 UTC (rev 5549)
@@ -429,7 +429,7 @@
}
gboolean
-xfpm_hal_device_has_key (XfpmHal *xfpm_hal,const gchar *udi,
+xfpm_hal_device_have_key (XfpmHal *xfpm_hal,const gchar *udi,
const gchar *key)
{
g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
@@ -453,6 +453,32 @@
return ret;
}
+gboolean
+xfpm_hal_device_have_capability(XfpmHal *xfpm_hal,
+ const gchar *udi,
+ const gchar *capability)
+{
+ g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
+ XfpmHalPrivate *priv;
+ priv = XFPM_HAL_GET_PRIVATE(xfpm_hal);
+ DBusError error;
+ dbus_error_init(&error);
+
+ gboolean ret = libhal_device_query_capability(priv->ctx,
+ udi,
+ capability,
+ &error);
+
+ if ( dbus_error_is_set(&error) )
+ {
+ g_printerr("Error query device capability %s\n",error.message);
+ dbus_error_free(&error);
+ return FALSE;
+ }
+
+ return ret;
+}
+
gboolean xfpm_hal_shutdown(XfpmHal *xfpm_hal)
{
XfpmHalPrivate *priv;
@@ -632,6 +658,25 @@
return TRUE;
}
+gboolean
+xfpm_hal_set_brightness (XfpmHal *xfpm_hal,
+ gint level)
+
+{
+ g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),FALSE);
+
+ return TRUE;
+}
+
+gint
+xfpm_hal_get_brightness (XfpmHal *xfpm_hal)
+{
+ g_return_val_if_fail(XFPM_IS_HAL(xfpm_hal),0);
+
+
+ return 1;
+}
+
gchar
**xfpm_hal_get_available_cpu_governors(XfpmHal *xfpm_hal)
{
Modified: xfce4-power-manager/trunk/src/xfpm-hal.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-hal.h 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-hal.h 2008-10-10 05:28:32 UTC (rev 5549)
@@ -101,10 +101,12 @@
const gchar *udi,
const gchar *property,
GError **gerror);
-gboolean xfpm_hal_device_has_key (XfpmHal *xfpm_hal,
+gboolean xfpm_hal_device_have_key (XfpmHal *xfpm_hal,
const gchar *udi,
const gchar *key);
-
+gboolean xfpm_hal_device_have_capability (XfpmHal *xfpm_hal,
+ const gchar *udi,
+ const gchar *capability);
gboolean xfpm_hal_shutdown (XfpmHal *xfpm_hal);
gboolean xfpm_hal_hibernate (XfpmHal *xfpm_hal,
@@ -113,8 +115,10 @@
gboolean xfpm_hal_suspend (XfpmHal *xfpm_hal,
GError **gerror,
guint8 *critical);
+gboolean xfpm_hal_set_brightness (XfpmHal *xfpm_hal,
+ gint level);
+gint xfpm_hal_get_brightness (XfpmHal *xfpm_hal);
-
gchar **xfpm_hal_get_available_cpu_governors (XfpmHal *xfpm_hal);
gchar *xfpm_hal_get_current_cpu_governor (XfpmHal *xfpm_hal);
void xfpm_hal_set_cpu_governor (XfpmHal *xfpm_hal,
Modified: xfce4-power-manager/trunk/src/xfpm-settings.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-settings.c 2008-10-10 02:45:44 UTC (rev 5548)
+++ xfce4-power-manager/trunk/src/xfpm-settings.c 2008-10-10 05:28:32 UTC (rev 5549)
@@ -778,10 +778,10 @@
default_config = xfconf_channel_get_uint(channel,POWER_SWITCH_CFG,0);
power_button = gtk_combo_box_new_text();
gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Nothing"));
- if ( can_hibernate )
- gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Hibernate"));
if ( can_suspend )
gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Suspend"));
+ if ( can_hibernate )
+ gtk_combo_box_append_text(GTK_COMBO_BOX(power_button),_("Hibernate"));
gtk_combo_box_set_active(GTK_COMBO_BOX(power_button),default_config);
gtk_widget_show(power_button);
gtk_table_attach(GTK_TABLE(table),power_button,1,2,0,1,GTK_SHRINK,GTK_SHRINK,0,0);
@@ -796,10 +796,10 @@
default_config = xfconf_channel_get_uint(channel,SLEEP_SWITCH_CFG,0);
sleep_button = gtk_combo_box_new_text();
gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Nothing"));
+ if ( can_suspend )
+ gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Suspend"));
if ( can_hibernate )
gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Hibernate"));
- if ( can_suspend )
- gtk_combo_box_append_text(GTK_COMBO_BOX(sleep_button),_("Suspend"));
gtk_combo_box_set_active(GTK_COMBO_BOX(sleep_button),default_config);
gtk_widget_show(sleep_button);
gtk_table_attach(GTK_TABLE(table),sleep_button,1,2,1,2,GTK_SHRINK,GTK_SHRINK,0,0);
@@ -815,10 +815,10 @@
default_config = xfconf_channel_get_uint(channel,LID_SWITCH_CFG,0);
lid_button = gtk_combo_box_new_text();
gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Nothing"));
+ if ( can_suspend )
+ gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Suspend"));
if ( can_hibernate )
gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Hibernate"));
- if ( can_suspend )
- gtk_combo_box_append_text(GTK_COMBO_BOX(lid_button),_("Suspend"));
gtk_combo_box_set_active(GTK_COMBO_BOX(lid_button),default_config);
gtk_widget_show(lid_button);
gtk_table_attach(GTK_TABLE(table),lid_button,1,2,2,3,GTK_SHRINK,GTK_SHRINK,0,0);
More information about the Goodies-commits
mailing list