diff --git a/ChangeLog b/ChangeLog index 42eb83ca2ccb87dc66e28bc5b93da5159c838e5d..c93de12bfab633c1f5f37543df132d2592ab569f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-05-19 12:00 + * : check brightness value and only display relevent values in + the brightness popup. + * : Load the brightness object in idle, seems to fix the issue + of wrong num_level sent from HAL on aspire one machine. + * : Provides LowBattery DBus signal. + * : Doesn't show funny estimated battery time to be fully charged + in case of wrong value estimated. + 2009-05-18 19:40 * : Fix inactivity sleep string in the settings dialog to Suspend instead of suspend (same for hibernate). diff --git a/TODO b/TODO index 0b43b122f63841d2ba83f76dbb00d9e50a828d2a..3f29941e3c006331439fd5d26c5838f06c99ff97 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,5 @@ * : Solve the problem of possible multiple sleep requests between us and the session manager. -* : OnLowBattery DBus signals (currently there is only OnBattery DBus signal). - * : Support Suspend Hybrid! ( DeviceKit power will not support this! ). * : Translations need to be updated. diff --git a/src/org.freedesktop.PowerManagement.xml b/src/org.freedesktop.PowerManagement.xml index 437a6e9fd0e23d155d7e465704680028a9dea077..3080ad850c04d20226141359d272cab3849d6586 100644 --- a/src/org.freedesktop.PowerManagement.xml +++ b/src/org.freedesktop.PowerManagement.xml @@ -36,5 +36,9 @@ <arg type="b" name="on_battery" direction="out"/> </signal> + <signal name="LowBatteryChanged"> + <arg type="b" name="low_battery" direction="out"/> + </signal> + </interface> </node> diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c index d322b7992b61e78077841db57c2910c7bcf70e39..d6f28684e14a9f0d55359fc7de8b6fbce1d16156 100644 --- a/src/xfpm-battery.c +++ b/src/xfpm-battery.c @@ -222,28 +222,40 @@ xfpm_battery_refresh_icon (XfpmBattery *battery, } } +static gboolean +xfpm_battery_notify_idle (gpointer data) +{ + XfpmBattery *battery; + const gchar *message; + + battery = XFPM_BATTERY (data); + + message = xfpm_battery_get_message_from_battery_state (battery->priv->state, battery->priv->adapter_present); + if ( !message ) + return FALSE; + + xfpm_notify_show_notification (battery->priv->notify, + _("Xfce power manager"), + message, + xfpm_tray_icon_get_icon_name (battery->priv->icon), + 8000, + battery->priv->type == HAL_DEVICE_TYPE_PRIMARY ? FALSE : TRUE, + XFPM_NOTIFY_NORMAL, + xfpm_tray_icon_get_tray_icon(battery->priv->icon)); + + return FALSE; +} + static void xfpm_battery_notify (XfpmBattery *battery) { - const gchar *message; gboolean notify; notify = xfpm_xfconf_get_property_bool (battery->priv->conf, GENERAL_NOTIFICATION_CFG); if ( notify ) { - message = xfpm_battery_get_message_from_battery_state (battery->priv->state, battery->priv->adapter_present); - if ( !message ) - return; - - xfpm_notify_show_notification (battery->priv->notify, - _("Xfce power manager"), - message, - xfpm_tray_icon_get_icon_name (battery->priv->icon), - 8000, - battery->priv->type == HAL_DEVICE_TYPE_PRIMARY ? FALSE : TRUE, - XFPM_NOTIFY_NORMAL, - xfpm_tray_icon_get_tray_icon(battery->priv->icon)); + g_idle_add ((GSourceFunc) xfpm_battery_notify_idle, battery); } } @@ -394,13 +406,22 @@ xfpm_battery_refresh_primary (XfpmBattery *battery, gboolean is_present, state != BATTERY_FULLY_CHARGED && state != BATTERY_NOT_FULLY_CHARGED ) { gchar *time_str; - const gchar *est_time; + gchar *tip_no_time; + const gchar *est_time; gint minutes, hours, minutes_left; hours = time_per / 3600; minutes = time_per / 60; minutes_left = minutes % 60; - + + tip_no_time = g_strdup_printf ("%i%% %s %s\n%s", + percentage, + _("Battery"), + str, + battery->priv->adapter_present ? + _("System is running on AC power") : + _("System is running on battery power")); + if ( state == BATTERY_IS_DISCHARGING || state == BATTERY_CHARGE_LOW || state == BATTERY_CHARGE_CRITICAL ) @@ -415,15 +436,12 @@ xfpm_battery_refresh_primary (XfpmBattery *battery, gboolean is_present, time_str = g_strdup_printf("%s: %d %s %d %s",est_time, hours,hours > 1 ? _("hours") : _("hour") , minutes_left, minutes_left > 1 ? _("minutes") : _("minute")); - - tip = g_strdup_printf ("%i%% %s %s\n%s\n%s", - percentage, - _("Battery"), - str, - battery->priv->adapter_present ? - _("System is running on AC power") : - _("System is running on battery power"), - time_str); + + tip = hours != 0 && minutes_left != 0 ? + g_strdup_printf ("%s\n%s", tip_no_time, time_str) : + g_strdup (tip_no_time); + + g_free (tip_no_time); g_free (time_str); } else @@ -479,6 +497,7 @@ xfpm_battery_refresh (XfpmBattery *battery) is_charging, is_discharging, last_full, current_charge, percentage, time_per); + xfpm_battery_refresh_visible_icon (battery); } diff --git a/src/xfpm-brightness-hal.c b/src/xfpm-brightness-hal.c index 66a9a943f72d805f21e0056cc76e745ec12815a2..305d248a89557590e6f3672432824905864c16f0 100644 --- a/src/xfpm-brightness-hal.c +++ b/src/xfpm-brightness-hal.c @@ -207,12 +207,9 @@ xfpm_brightness_hal_up (XfpmBrightnessHal *brg) { gboolean enable_brightness = xfpm_xfconf_get_property_bool (brg->priv->conf, ENABLE_BRIGHTNESS_CONTROL); - if ( !enable_brightness ) - return; - - if ( brg->priv->brightness_in_hw ) + if ( enable_brightness == FALSE || brg->priv->brightness_in_hw) goto signal; - + if ( brg->priv->hw_level <= brg->priv->max_level -1 ) { TRACE ("Brightness key up"); @@ -221,7 +218,8 @@ xfpm_brightness_hal_up (XfpmBrightnessHal *brg) signal: brg->priv->hw_level = xfpm_brightness_hal_get_level (brg); - g_signal_emit (G_OBJECT (brg), signals [BRIGHTNESS_UP], 0, brg->priv->hw_level); + if ( G_LIKELY ( brg->priv->hw_level != 0 ) ) + g_signal_emit (G_OBJECT (brg), signals [BRIGHTNESS_UP], 0, brg->priv->hw_level); } static void @@ -229,10 +227,7 @@ xfpm_brightness_hal_down (XfpmBrightnessHal *brg) { gboolean enable_brightness = xfpm_xfconf_get_property_bool (brg->priv->conf, ENABLE_BRIGHTNESS_CONTROL); - if ( !enable_brightness ) - return; - - if ( brg->priv->brightness_in_hw ) + if ( enable_brightness == FALSE || brg->priv->brightness_in_hw) goto signal; if ( brg->priv->hw_level != 0) @@ -243,7 +238,8 @@ xfpm_brightness_hal_down (XfpmBrightnessHal *brg) signal: brg->priv->hw_level = xfpm_brightness_hal_get_level (brg); - g_signal_emit (G_OBJECT (brg), signals [BRIGHTNESS_DOWN], 0, brg->priv->hw_level); + if ( G_LIKELY ( brg->priv->hw_level != 0 ) ) + g_signal_emit (G_OBJECT (brg), signals [BRIGHTNESS_DOWN], 0, brg->priv->hw_level); } static void diff --git a/src/xfpm-engine.c b/src/xfpm-engine.c index 558231cbae212e0fe5ab9ceedf5fb6a85c67b44c..be4260863728ed4a379f81aacc40fcb4f6da9628 100644 --- a/src/xfpm-engine.c +++ b/src/xfpm-engine.c @@ -94,6 +94,7 @@ struct XfpmEnginePrivate enum { ON_BATTERY_CHANGED, + LOW_BATTERY_CHANGED, LAST_SIGNAL }; @@ -259,10 +260,26 @@ xfpm_engine_check_hal_iface (XfpmEngine * engine) } static void -xfpm_engine_load_all (XfpmEngine * engine) +xfpm_engine_supply_notify_cb (GObject *object, GParamSpec *spec, XfpmEngine *engine) { + gboolean low_power; + + if ( xfpm_strequal (spec->name, "on-low-battery") ) + { + g_object_get (object, "on-low-battery", &low_power, NULL); + TRACE ("On low battery changed %s", xfpm_bool_to_string (low_power)); + g_signal_emit (G_OBJECT (engine), signals [LOW_BATTERY_CHANGED], 0, low_power); + } +} + +static gboolean +xfpm_engine_load_all (gpointer data) +{ + XfpmEngine *engine; HalManager *manager; + engine = XFPM_ENGINE (data); + xfpm_engine_check_hal_iface (engine); manager = hal_manager_new (); @@ -287,6 +304,10 @@ xfpm_engine_load_all (XfpmEngine * engine) g_signal_connect (G_OBJECT (engine->priv->supply), "shutdown-request", G_CALLBACK (xfpm_engine_shutdown_request_battery_cb), engine); + + g_signal_connect (G_OBJECT (engine->priv->supply), "notify", + G_CALLBACK (xfpm_engine_supply_notify_cb), engine); + xfpm_supply_monitor (engine->priv->supply); engine->priv->button = xfpm_button_new (); @@ -303,6 +324,7 @@ xfpm_engine_load_all (XfpmEngine * engine) engine->priv->has_lcd_brightness = xfpm_backlight_has_hw (engine->priv->bk); } + return FALSE; } static void @@ -411,6 +433,15 @@ xfpm_engine_class_init (XfpmEngineClass * klass) g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + signals [LOW_BATTERY_CHANGED] = + g_signal_new("low-battery-changed", + XFPM_TYPE_ENGINE, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(XfpmEngineClass, low_battery_changed), + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + object_class->finalize = xfpm_engine_finalize; g_type_class_add_private (klass, sizeof (XfpmEnginePrivate)); @@ -458,8 +489,6 @@ xfpm_engine_init (XfpmEngine * engine) g_signal_connect (engine->priv->adapter, "adapter-changed", G_CALLBACK (xfpm_engine_adapter_changed_cb), engine); - xfpm_engine_load_all (engine); - engine->priv->idle = xfpm_idle_new (); g_signal_connect (engine->priv->idle, "alarm-timeout", @@ -469,6 +498,14 @@ xfpm_engine_init (XfpmEngine * engine) G_CALLBACK (xfpm_engine_inactivity_timeout_changed_cb), engine); xfpm_engine_set_inactivity_timeouts (engine); + + /* + * We load other objects in idle, in princilpe we shouldn't do that + * but it turns out that some time for some reason the HAL brightness + * object is failing to get correct brightness num_levels, and the idle + * seems to fix this. + */ + g_idle_add ((GSourceFunc)xfpm_engine_load_all, engine); } static void diff --git a/src/xfpm-engine.h b/src/xfpm-engine.h index 556cddc94571107a243edd18fbc3b420939b8010..3c98c16496f26a56237ff12224a9b05d0f774f9c 100644 --- a/src/xfpm-engine.h +++ b/src/xfpm-engine.h @@ -45,6 +45,9 @@ typedef struct void (*on_battery_changed) (XfpmEngine *engine, gboolean on_battery); + void (*low_battery_changed) (XfpmEngine *engine, + gboolean low_battery); + } XfpmEngineClass; GType xfpm_engine_get_type (void) G_GNUC_CONST; diff --git a/src/xfpm-idle.c b/src/xfpm-idle.c index 48fb681dbfd5e1933a4572c8bbc062306de0baf8..be25657198ac9bb77cd27d52a4cbc4c99c1cb7d9 100644 --- a/src/xfpm-idle.c +++ b/src/xfpm-idle.c @@ -45,6 +45,10 @@ static void xfpm_idle_finalize (GObject *object); #define XFPM_IDLE_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_IDLE, XfpmIdlePrivate)) +/* + * Undef and use the function instead of the macro + * as the macro is buggy. + */ #ifdef XSyncValueAdd #undef XSyncValueAdd #endif diff --git a/src/xfpm-supply.c b/src/xfpm-supply.c index 9047298291b3fd6de1c53d97b509bae712a3382b..d309e5976dbb292f7cd09249b52a3182944d196e 100644 --- a/src/xfpm-supply.c +++ b/src/xfpm-supply.c @@ -69,6 +69,13 @@ struct XfpmSupplyPrivate guint8 power_management; }; +enum +{ + PROP_O, + PROP_ON_BATTERY, + PROP_ON_LOW_BATTERY +}; + enum { SHUTDOWN_REQUEST, @@ -79,6 +86,31 @@ static guint signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE(XfpmSupply, xfpm_supply, G_TYPE_OBJECT) +static void +xfpm_supply_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + XfpmSupply *supply; + + supply = XFPM_SUPPLY (object); + + switch ( prop_id ) + { + case PROP_ON_BATTERY: + g_value_set_boolean (value, !supply->priv->adapter_present); + break; + case PROP_ON_LOW_BATTERY: + g_value_set_boolean (value, supply->priv->low_power); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + +} + static void xfpm_supply_has_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmSupply *supply) { @@ -90,6 +122,8 @@ xfpm_supply_class_init(XfpmSupplyClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS(klass); + object_class->get_property = xfpm_supply_get_property; + signals[SHUTDOWN_REQUEST] = g_signal_new("shutdown-request", XFPM_TYPE_SUPPLY, @@ -100,6 +134,20 @@ xfpm_supply_class_init(XfpmSupplyClass *klass) G_TYPE_NONE, 2, G_TYPE_BOOLEAN, XFPM_TYPE_SHUTDOWN_REQUEST); + + g_object_class_install_property(object_class, + PROP_ON_BATTERY, + g_param_spec_boolean("on-battery", + NULL, NULL, + FALSE, + G_PARAM_READABLE)); + + g_object_class_install_property(object_class, + PROP_ON_LOW_BATTERY, + g_param_spec_boolean("on-low-battery", + NULL, NULL, + FALSE, + G_PARAM_READABLE)); object_class->finalize = xfpm_supply_finalize; @@ -318,41 +366,40 @@ xfpm_supply_handle_primary_critical (XfpmSupply *supply, XfpmBattery *battery) XfpmShutdownRequest critical_action = xfpm_xfconf_get_property_enum (supply->priv->conf, CRITICAL_BATT_ACTION_CFG); - if ( xfpm_supply_on_low_power (supply) ) + TRACE ("System is running on low power"); + + if ( supply->priv->inhibited ) { - TRACE ("System is running on low power"); - supply->priv->low_power = TRUE; - if ( supply->priv->inhibited ) - { - xfpm_supply_show_critical_action_inhibited (supply, battery); - } - else if ( critical_action == XFPM_DO_NOTHING ) - { - xfpm_supply_show_critical_action (supply, battery); - } - else - { - xfpm_supply_process_critical_action (supply); - } + xfpm_supply_show_critical_action_inhibited (supply, battery); + } + else if ( critical_action == XFPM_DO_NOTHING ) + { + xfpm_supply_show_critical_action (supply, battery); + } + else + { + xfpm_supply_process_critical_action (supply); } } static void xfpm_supply_battery_state_changed_cb (XfpmBattery *battery, XfpmBatteryState state, XfpmSupply *supply) { - if ( state == BATTERY_CHARGE_CRITICAL ) + gboolean low_power; + + low_power = xfpm_supply_on_low_power (supply); + + if ( state == BATTERY_CHARGE_CRITICAL && low_power ) + { + supply->priv->low_power = TRUE; + g_object_notify (G_OBJECT (supply), "on-low-battery"); xfpm_supply_handle_primary_critical (supply, battery); - else if ( supply->priv->low_power == TRUE ) + } + else if ( !low_power && supply->priv->low_power ) { - if ( xfpm_supply_on_low_power (supply) ) - { - xfpm_supply_handle_primary_critical (supply, battery); - } - else - { - supply->priv->low_power = FALSE; - xfpm_notify_close_critical (supply->priv->notify); - } + supply->priv->low_power = FALSE; + g_object_notify (G_OBJECT (supply), "on-low-battery"); + xfpm_notify_close_critical (supply->priv->notify); } } @@ -397,7 +444,6 @@ xfpm_supply_remove_battery (XfpmSupply *supply, const HalBattery *device) if (!g_hash_table_remove (supply->priv->hash, udi)) g_critical ("Unable to remove battery object from hash"); } -// g_object_unref (battery); xfpm_supply_refresh_tray_icon (supply); } @@ -460,6 +506,16 @@ static void xfpm_supply_adapter_changed_cb (XfpmAdapter *adapter, gboolean present, XfpmSupply *supply) { supply->priv->adapter_present = present; + + g_object_notify (G_OBJECT (supply), "on-battery"); + + if ( supply->priv->adapter_present && supply->priv->low_power ) + { + supply->priv->low_power = FALSE; + g_object_notify (G_OBJECT (supply), "on-low-battery"); + xfpm_notify_close_critical (supply->priv->notify); + } + xfpm_supply_save_power (supply); } @@ -487,13 +543,18 @@ void xfpm_supply_monitor (XfpmSupply *supply) xfpm_supply_monitor_start (supply); xfpm_supply_refresh_tray_icon (supply); + + supply->priv->low_power = xfpm_supply_on_low_power (supply); + + if ( supply->priv->low_power ) + g_object_notify (G_OBJECT (supply), "on-low-battery"); } gboolean xfpm_supply_on_low_battery (XfpmSupply *supply) { g_return_val_if_fail (XFPM_IS_SUPPLY(supply), FALSE); - return xfpm_supply_on_low_power(supply); + return supply->priv->low_power; } void xfpm_supply_reload (XfpmSupply *supply) diff --git a/src/xfpm-supply.h b/src/xfpm-supply.h index cd074101860a733c149d0c385f2bf85f56fc4420..982060b07e6ef8d0f8cef2b22b04279f51f186da 100644 --- a/src/xfpm-supply.h +++ b/src/xfpm-supply.h @@ -57,7 +57,7 @@ XfpmSupply *xfpm_supply_new (guint8 power_management_inf void xfpm_supply_monitor (XfpmSupply *supply); -gboolean xfpm_supply_on_low_battery (XfpmSupply *supply); +gboolean xfpm_supply_on_low_battery (XfpmSupply *supply) G_GNUC_PURE; void xfpm_supply_reload (XfpmSupply *supply);