[Xfce4-commits] [xfce/xfce4-power-manager] 40/64: Add presentation mode back in
noreply at xfce.org
noreply at xfce.org
Mon May 26 06:00:35 CEST 2014
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.
commit 0ad035cce1578ac0b354ae691af224b534e9fbc3
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Mon May 12 19:38:04 2014 +0300
Add presentation mode back in
---
common/xfpm-enum-glib.h | 7 ---
panel-plugins/battery/Makefile.am | 2 +
panel-plugins/battery/battery-button.c | 29 ++++++++++
src/xfpm-backlight.c | 2 +-
src/xfpm-config.h | 3 +
src/xfpm-dpms.c | 2 +-
src/xfpm-manager.c | 2 +-
src/xfpm-power.c | 96 ++++++++++++++++++++++++++++++--
src/xfpm-power.h | 2 +-
src/xfpm-xfconf.c | 4 ++
10 files changed, 132 insertions(+), 17 deletions(-)
diff --git a/common/xfpm-enum-glib.h b/common/xfpm-enum-glib.h
index a6964b0..65a3a4e 100644
--- a/common/xfpm-enum-glib.h
+++ b/common/xfpm-enum-glib.h
@@ -83,13 +83,6 @@ typedef enum
} XfpmShowIcon;
-typedef enum
-{
- XFPM_POWER_MODE_NORMAL,
- XFPM_POWER_MODE_PRESENTATION
-
-} XfpmPowerMode;
-
G_END_DECLS
#endif /* __XFPM_ENUM_GLIB_H */
diff --git a/panel-plugins/battery/Makefile.am b/panel-plugins/battery/Makefile.am
index dcbff72..47bf91f 100644
--- a/panel-plugins/battery/Makefile.am
+++ b/panel-plugins/battery/Makefile.am
@@ -25,6 +25,7 @@ libxfce4battery_la_CFLAGS = \
$(LIBXFCE4PANEL_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
+ $(XFCONF_CFLAGS) \
$(GTK_CFLAGS) \
$(GLIB_CFLAGS) \
$(PLATFORM_CPPFLAGS) \
@@ -44,6 +45,7 @@ libxfce4battery_la_LIBADD = \
$(LIBXFCE4PANEL_LIBS) \
$(LIBXFCE4UI_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
+ $(XFCONF_LIBS) \
$(GTK_LIBS) \
$(GLIB_LIBS) \
$(DBUS_GLIB_LIBS) \
diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index caa1bc1..f7c3519 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -31,6 +31,7 @@
#include <libxfce4ui/libxfce4ui.h>
#include <dbus/dbus-glib.h>
#include <upower.h>
+#include <xfconf/xfconf.h>
#include "common/xfpm-common.h"
#include "common/xfpm-icons.h"
@@ -44,6 +45,7 @@
struct BatteryButtonPrivate
{
XfcePanelPlugin *plugin;
+ XfconfChannel *channel;
UpClient *upower;
@@ -496,11 +498,23 @@ battery_button_class_init (BatteryButtonClass *klass)
static void
battery_button_init (BatteryButton *button)
{
+ GError *error = NULL;
+
button->priv = BATTERY_BUTTON_GET_PRIVATE (button);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
button->priv->upower = up_client_new ();
+ if ( !xfconf_init (&error) )
+ {
+ g_critical ("xfconf_init failed: %s\n", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ button->priv->channel = xfconf_channel_get ("xfce4-power-manager");
+ }
+
/* Sane defaults for the panel icon */
button->priv->panel_icon_name = g_strdup(XFPM_AC_ADAPTER_ICON);
button->priv->panel_icon_width = 24;
@@ -590,6 +604,12 @@ help_cb (GtkMenuItem *menuitem, gpointer user_data)
xfce_dialog_show_help (NULL, "xfce4-power-manager", "start", NULL);
}
+static void
+presentation_cb (GtkMenuItem *menuitem, gpointer user_data)
+{
+ DBG("toggled");
+}
+
void
battery_button_show (BatteryButton *button)
{
@@ -720,6 +740,15 @@ battery_button_show_menu (BatteryButton *button)
gtk_widget_show(mi);
gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ /* Presentation mode checkbox */
+ mi = gtk_check_menu_item_new_with_mnemonic (_("Presentation _mode"));
+ gtk_widget_set_sensitive (mi, TRUE);
+ gtk_widget_show (mi);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ xfconf_g_property_bind(button->priv->channel,
+ "/xfce4-power-manager/presentation-mode",
+ G_TYPE_BOOLEAN, G_OBJECT(mi), "active");
+
/* Preferences option */
mi = gtk_menu_item_new_with_mnemonic ("_Preferences...");
gtk_widget_show(mi);
diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index a13ab84..1bff0a6 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -77,7 +77,7 @@ xfpm_backlight_dim_brightness (XfpmBacklight *backlight)
{
gboolean ret;
- if (xfpm_power_get_mode (backlight->priv->power) == XFPM_POWER_MODE_NORMAL )
+ if (xfpm_power_is_in_presentation_mode (backlight->priv->power) == FALSE )
{
gint32 dim_level;
diff --git a/src/xfpm-config.h b/src/xfpm-config.h
index 1965384..6f7c52b 100644
--- a/src/xfpm-config.h
+++ b/src/xfpm-config.h
@@ -88,6 +88,9 @@ G_BEGIN_DECLS
#define LOGIND_HANDLE_SUSPEND_KEY "logind-handle-suspend-key"
#define LOGIND_HANDLE_HIBERNATE_KEY "logind-handle-hibernate-key"
#define LOGIND_HANDLE_LID_SWITCH "logind-handle-lid-switch"
+
+#define PRESENTATION_MODE "presentation-mode"
+
G_END_DECLS
#endif /* __XFPM_CONFIG_H */
diff --git a/src/xfpm-dpms.c b/src/xfpm-dpms.c
index 95b63f5..41825e1 100644
--- a/src/xfpm-dpms.c
+++ b/src/xfpm-dpms.c
@@ -158,7 +158,7 @@ xfpm_dpms_refresh (XfpmDpms *dpms)
gboolean sleep_mode;
gboolean presentation_mode;
- presentation_mode = (xfpm_power_get_mode (dpms->priv->power) == XFPM_POWER_MODE_PRESENTATION);
+ presentation_mode = (xfpm_power_is_in_presentation_mode (dpms->priv->power) == TRUE);
if ( dpms->priv->inhibited || presentation_mode)
{
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index 0a6e42f..465c2e7 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -402,7 +402,7 @@ xfpm_manager_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmM
static void
xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager)
{
- if (xfpm_power_get_mode (manager->priv->power) == XFPM_POWER_MODE_PRESENTATION)
+ if (xfpm_power_is_in_presentation_mode (manager->priv->power) == TRUE)
return;
XFPM_DEBUG ("Alarm inactivity timeout id %d", id);
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index e8bf9d3..a04170b 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -66,6 +66,14 @@ static void xfpm_power_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
+static void xfpm_power_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void xfpm_power_change_presentation_mode (XfpmPower *power,
+ gboolean presentation_mode);
+
static void xfpm_power_dbus_class_init (XfpmPowerClass * klass);
static void xfpm_power_dbus_init (XfpmPower *power);
@@ -91,7 +99,7 @@ struct XfpmPowerPrivate
XfpmBatteryCharge overall_state;
gboolean critical_action_done;
- XfpmPowerMode power_mode;
+ gboolean presentation_mode;
EggIdletime *idletime;
gboolean inhibited;
@@ -130,7 +138,9 @@ enum
PROP_AUTH_HIBERNATE,
PROP_CAN_SUSPEND,
PROP_CAN_HIBERNATE,
- PROP_HAS_LID
+ PROP_HAS_LID,
+ PROP_PRESENTATION_MODE,
+ N_PROPERTIES
};
enum
@@ -936,6 +946,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
object_class->finalize = xfpm_power_finalize;
object_class->get_property = xfpm_power_get_property;
+ object_class->set_property = xfpm_power_set_property;
signals [ON_BATTERY_CHANGED] =
g_signal_new ("on-battery-changed",
@@ -1000,6 +1011,12 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
+#define XFPM_PARAM_FLAGS ( G_PARAM_READWRITE \
+ | G_PARAM_CONSTRUCT \
+ | G_PARAM_STATIC_NAME \
+ | G_PARAM_STATIC_NICK \
+ | G_PARAM_STATIC_BLURB)
+
g_object_class_install_property (object_class,
PROP_ON_BATTERY,
g_param_spec_boolean ("on-battery",
@@ -1049,6 +1066,14 @@ xfpm_power_class_init (XfpmPowerClass *klass)
FALSE,
G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_PRESENTATION_MODE,
+ g_param_spec_boolean (PRESENTATION_MODE,
+ NULL, NULL,
+ FALSE,
+ XFPM_PARAM_FLAGS));
+#undef XFPM_PARAM_FLAGS
+
g_type_class_add_private (klass, sizeof (XfpmPowerPrivate));
xfpm_power_dbus_class_init (klass);
@@ -1074,7 +1099,7 @@ xfpm_power_init (XfpmPower *power)
power->priv->dialog = NULL;
power->priv->overall_state = XFPM_BATTERY_CHARGE_OK;
power->priv->critical_action_done = FALSE;
- power->priv->power_mode = XFPM_POWER_MODE_NORMAL;
+ power->priv->presentation_mode = FALSE;
power->priv->suspend = xfpm_suspend_get ();
power->priv->inhibit = xfpm_inhibit_new ();
@@ -1120,6 +1145,10 @@ xfpm_power_init (XfpmPower *power)
xfpm_power_check_polkit_auth (power);
#endif
+ xfconf_g_property_bind(xfpm_xfconf_get_channel(power->priv->conf),
+ PROPERTIES_PREFIX PRESENTATION_MODE, G_TYPE_BOOLEAN,
+ G_OBJECT(power), PRESENTATION_MODE);
+
out:
xfpm_power_dbus_init (power);
@@ -1157,6 +1186,27 @@ static void xfpm_power_get_property (GObject *object,
case PROP_HAS_LID:
g_value_set_boolean (value, power->priv->lid_is_present);
break;
+ case PROP_PRESENTATION_MODE:
+ g_value_set_boolean (value, power->priv->presentation_mode);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void xfpm_power_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ XfpmPower *power = XFPM_POWER (object);
+
+ switch (prop_id)
+ {
+ case PROP_PRESENTATION_MODE:
+ xfpm_power_change_presentation_mode (power, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1247,11 +1297,43 @@ gboolean xfpm_power_has_battery (XfpmPower *power)
return ret;
}
-XfpmPowerMode xfpm_power_get_mode (XfpmPower *power)
+static void
+xfpm_power_change_presentation_mode (XfpmPower *power, gboolean presentation_mode)
+{
+ #ifdef HAVE_DPMS
+ XfpmDpms *dpms;
+
+ /* no change, exit */
+ if (power->priv->presentation_mode == presentation_mode)
+ return;
+
+ XFPM_DEBUG ("presentation mode %s, changing to %s",
+ power->priv->presentation_mode ? "TRUE" : "FALSE",
+ presentation_mode ? "TRUE" : "FALSE");
+
+ power->priv->presentation_mode = presentation_mode;
+
+ dpms = xfpm_dpms_new ();
+ xfpm_dpms_refresh (dpms);
+ g_object_unref (dpms);
+
+ if (presentation_mode == FALSE)
+ {
+ EggIdletime *idletime;
+ idletime = egg_idletime_new ();
+ egg_idletime_alarm_reset_all (idletime);
+
+ g_object_unref (idletime);
+ }
+#endif
+}
+
+gboolean
+xfpm_power_is_in_presentation_mode (XfpmPower *power)
{
- g_return_val_if_fail (XFPM_IS_POWER (power), XFPM_POWER_MODE_NORMAL);
+ g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
- return power->priv->power_mode;
+ return power->priv->presentation_mode;
}
@@ -1372,6 +1454,8 @@ xfpm_power_dbus_init (XfpmPower *power)
{
DBusGConnection *bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+ TRACE ("entering");
+
dbus_g_connection_register_g_object (bus,
"/org/freedesktop/PowerManagement",
G_OBJECT (power));
diff --git a/src/xfpm-power.h b/src/xfpm-power.h
index d9798b0..b3a1860 100644
--- a/src/xfpm-power.h
+++ b/src/xfpm-power.h
@@ -75,7 +75,7 @@ void xfpm_power_hibernate (XfpmPower *power,
gboolean xfpm_power_has_battery (XfpmPower *power);
-XfpmPowerMode xfpm_power_get_mode (XfpmPower *power);
+gboolean xfpm_power_is_in_presentation_mode (XfpmPower *power);
G_END_DECLS
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index 8c8e3b3..364d665 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -188,6 +188,10 @@ xfpm_xfconf_property_changed_cb (XfconfChannel *channel, gchar *property,
if ( !g_str_has_prefix (property, PROPERTIES_PREFIX) || strlen (property) <= strlen (PROPERTIES_PREFIX) )
return;
+ /* We handle presentation mode in xfpm-power directly */
+ if ( g_strcmp0 (property, "/xfce4-power-manager/presentation-mode") == 0 )
+ return;
+
XFPM_DEBUG ("Property modified: %s\n", property);
g_object_set_property (G_OBJECT (conf), property + strlen (PROPERTIES_PREFIX), value);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list