[Xfce4-commits] [xfce/xfce4-power-manager] 01/01: Fix indentation
noreply at xfce.org
noreply at xfce.org
Sat Nov 16 00:50:18 CET 2019
This is an automated email from the git hooks/post-receive script.
o c h o s i p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository xfce/xfce4-power-manager.
commit 90dc136450cc2878619a19aaca0357bee016dd1f
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date: Mon Nov 11 10:26:01 2019 +0100
Fix indentation
---
common/xfpm-brightness.c | 865 ++---
common/xfpm-brightness.h | 57 +-
common/xfpm-common.c | 207 +-
common/xfpm-common.h | 28 +-
common/xfpm-debug.c | 101 +-
common/xfpm-debug.h | 48 +-
common/xfpm-enum-glib.h | 72 +-
common/xfpm-enum.h | 37 +-
common/xfpm-power-common.c | 574 ++--
common/xfpm-power-common.h | 16 +-
libdbus/xfpm-dbus-monitor.c | 405 ++-
libdbus/xfpm-dbus-monitor.h | 87 +-
libdbus/xfpm-dbus.c | 178 +-
libdbus/xfpm-dbus.h | 14 +-
.../power-manager-plugin/power-manager-button.c | 2317 ++++++-------
.../power-manager-plugin/power-manager-button.h | 26 +-
panel-plugins/power-manager-plugin/scalemenuitem.h | 9 +-
.../xfce/xfce-power-manager-plugin.c | 115 +-
settings/xfpm-settings-app.c | 516 +--
settings/xfpm-settings-app.h | 7 +-
settings/xfpm-settings-main.c | 5 +-
settings/xfpm-settings.c | 3611 ++++++++++----------
settings/xfpm-settings.h | 33 +-
src/egg-idletime.c | 846 ++---
src/egg-idletime.h | 57 +-
src/xfce-screensaver.c | 765 ++---
src/xfce-screensaver.h | 9 +-
src/xfpm-backlight-helper.c | 1078 +++---
src/xfpm-backlight.c | 667 ++--
src/xfpm-backlight.h | 16 +-
src/xfpm-battery.c | 664 ++--
src/xfpm-battery.h | 37 +-
src/xfpm-button.c | 266 +-
src/xfpm-button.h | 21 +-
src/xfpm-console-kit.c | 510 +--
src/xfpm-console-kit.h | 33 +-
src/xfpm-dpms.c | 342 +-
src/xfpm-dpms.h | 25 +-
src/xfpm-errors.c | 34 +-
src/xfpm-errors.h | 12 +-
src/xfpm-inhibit.c | 523 +--
src/xfpm-inhibit.h | 28 +-
src/xfpm-kbd-backlight.c | 424 +--
src/xfpm-kbd-backlight.h | 8 +-
src/xfpm-main.c | 644 ++--
src/xfpm-manager.c | 1446 ++++----
src/xfpm-manager.h | 24 +-
src/xfpm-network-manager.c | 65 +-
src/xfpm-network-manager.h | 2 +-
src/xfpm-notify.c | 393 +--
src/xfpm-notify.h | 72 +-
src/xfpm-pm-helper.c | 87 +-
src/xfpm-polkit.c | 577 ++--
src/xfpm-polkit.h | 20 +-
src/xfpm-power.c | 2434 ++++++-------
src/xfpm-power.h | 54 +-
src/xfpm-suspend.c | 194 +-
src/xfpm-suspend.h | 9 +-
src/xfpm-xfconf.c | 1122 +++---
src/xfpm-xfconf.h | 16 +-
60 files changed, 11375 insertions(+), 11477 deletions(-)
diff --git a/common/xfpm-brightness.c b/common/xfpm-brightness.c
index 1c263c2..50e9411 100644
--- a/common/xfpm-brightness.c
+++ b/common/xfpm-brightness.c
@@ -43,16 +43,16 @@ static void xfpm_brightness_finalize (GObject *object);
struct XfpmBrightnessPrivate
{
- XRRScreenResources *resource;
- Atom backlight;
- gint output;
- gboolean xrandr_has_hw;
- gboolean helper_has_hw;
-
- gint32 max_level;
- gint32 current_level;
- gint32 min_level;
- gint32 step;
+ XRRScreenResources *resource;
+ Atom backlight;
+ gint output;
+ gboolean xrandr_has_hw;
+ gboolean helper_has_hw;
+
+ gint32 max_level;
+ gint32 current_level;
+ gint32 min_level;
+ gint32 step;
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmBrightness, xfpm_brightness, G_TYPE_OBJECT)
@@ -60,259 +60,258 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmBrightness, xfpm_brightness, G_TYPE_OBJECT)
static gboolean
xfpm_brightness_xrand_get_limit (XfpmBrightness *brightness, RROutput output, gint *min, gint *max)
{
- XRRPropertyInfo *info;
- gboolean ret = TRUE;
- GdkDisplay *gdisplay;
+ XRRPropertyInfo *info;
+ gboolean ret = TRUE;
+ GdkDisplay *gdisplay;
- gdisplay = gdk_display_get_default ();
+ gdisplay = gdk_display_get_default ();
- gdk_x11_display_error_trap_push (gdisplay);
- info = XRRQueryOutputProperty (gdk_x11_get_default_xdisplay (), output, brightness->priv->backlight);
+ gdk_x11_display_error_trap_push (gdisplay);
+ info = XRRQueryOutputProperty (gdk_x11_get_default_xdisplay (), output, brightness->priv->backlight);
- if (gdk_x11_display_error_trap_pop (gdisplay) != 0
- || info == NULL)
- {
- g_warning ("could not get output property");
- return FALSE;
- }
+ if (gdk_x11_display_error_trap_pop (gdisplay) != 0
+ || info == NULL)
+ {
+ g_warning ("could not get output property");
+ return FALSE;
+ }
- if (!info->range || info->num_values != 2)
- {
- g_warning ("no range found");
- ret = FALSE;
- goto out;
- }
+ if (!info->range || info->num_values != 2)
+ {
+ g_warning ("no range found");
+ ret = FALSE;
+ goto out;
+ }
- *min = info->values[0];
- *max = info->values[1];
+ *min = info->values[0];
+ *max = info->values[1];
out:
- XFree (info);
- return ret;
+ XFree (info);
+ return ret;
}
static gboolean
xfpm_brightness_xrandr_get_level (XfpmBrightness *brightness, RROutput output, gint32 *current)
{
- unsigned long nitems;
- unsigned long bytes_after;
- gint32 *prop;
- Atom actual_type;
- int actual_format;
- gboolean ret = FALSE;
- GdkDisplay *gdisplay;
-
- gdisplay = gdk_display_get_default ();
-
- gdk_x11_display_error_trap_push (gdisplay);
- if (XRRGetOutputProperty (gdk_x11_get_default_xdisplay (), output, brightness->priv->backlight,
- 0, 4, False, False, None,
- &actual_type, &actual_format,
- &nitems, &bytes_after, ((unsigned char **)&prop)) != Success
- || gdk_x11_display_error_trap_pop (gdisplay) != 0)
- {
- g_warning ("failed to get property");
- return FALSE;
- }
+ unsigned long nitems;
+ unsigned long bytes_after;
+ gint32 *prop;
+ Atom actual_type;
+ int actual_format;
+ gboolean ret = FALSE;
+ GdkDisplay *gdisplay;
+
+ gdisplay = gdk_display_get_default ();
+
+ gdk_x11_display_error_trap_push (gdisplay);
+ if (XRRGetOutputProperty (gdk_x11_get_default_xdisplay (), output, brightness->priv->backlight,
+ 0, 4, False, False, None,
+ &actual_type, &actual_format,
+ &nitems, &bytes_after, ((unsigned char **)&prop)) != Success
+ || gdk_x11_display_error_trap_pop (gdisplay) != 0)
+ {
+ g_warning ("failed to get property");
+ return FALSE;
+ }
- if (actual_type == XA_INTEGER && nitems == 1 && actual_format == 32)
- {
- memcpy (current, prop, sizeof (*current));
- ret = TRUE;
- }
+ if (actual_type == XA_INTEGER && nitems == 1 && actual_format == 32)
+ {
+ memcpy (current, prop, sizeof (*current));
+ ret = TRUE;
+ }
- XFree (prop);
+ XFree (prop);
- return ret;
+ return ret;
}
static gboolean
xfpm_brightness_xrandr_set_level (XfpmBrightness *brightness, RROutput output, gint32 level)
{
- gboolean ret = TRUE;
- Display *display;
- GdkDisplay *gdisplay;
+ gboolean ret = TRUE;
+ Display *display;
+ GdkDisplay *gdisplay;
- display = gdk_x11_get_default_xdisplay ();
- gdisplay = gdk_display_get_default ();
+ display = gdk_x11_get_default_xdisplay ();
+ gdisplay = gdk_display_get_default ();
- gdk_x11_display_error_trap_push (gdisplay);
- XRRChangeOutputProperty (display, output, brightness->priv->backlight, XA_INTEGER, 32,
- PropModeReplace, (unsigned char *) &level, 1);
+ gdk_x11_display_error_trap_push (gdisplay);
+ XRRChangeOutputProperty (display, output, brightness->priv->backlight, XA_INTEGER, 32,
+ PropModeReplace, (unsigned char *) &level, 1);
- XFlush (display);
- gdk_display_flush (gdisplay);
+ XFlush (display);
+ gdk_display_flush (gdisplay);
- if ( gdk_x11_display_error_trap_pop (gdisplay) )
- {
- g_warning ("failed to XRRChangeOutputProperty for brightness %d", level);
- ret = FALSE;
- }
+ if ( gdk_x11_display_error_trap_pop (gdisplay) )
+ {
+ g_warning ("failed to XRRChangeOutputProperty for brightness %d", level);
+ ret = FALSE;
+ }
- return ret;
+ return ret;
}
static gboolean
xfpm_brightness_setup_xrandr (XfpmBrightness *brightness)
{
- GdkScreen *screen;
- GdkDisplay *gdisplay;
- XRROutputInfo *info;
- Window window;
- gint major, minor, screen_num;
- int event_base, error_base;
- gint32 min, max;
- gboolean ret = FALSE;
- gint i;
-
- gdisplay = gdk_display_get_default ();
-
- gdk_x11_display_error_trap_push (gdisplay);
- if (!XRRQueryExtension (gdk_x11_get_default_xdisplay (), &event_base, &error_base) ||
- !XRRQueryVersion (gdk_x11_get_default_xdisplay (), &major, &minor) )
- {
- gdk_x11_display_error_trap_pop_ignored (gdisplay);
- g_warning ("No XRANDR extension found");
- return FALSE;
- }
+ GdkScreen *screen;
+ GdkDisplay *gdisplay;
+ XRROutputInfo *info;
+ Window window;
+ gint major, minor, screen_num;
+ int event_base, error_base;
+ gint32 min, max;
+ gboolean ret = FALSE;
+ gint i;
+
+ gdisplay = gdk_display_get_default ();
+
+ gdk_x11_display_error_trap_push (gdisplay);
+ if (!XRRQueryExtension (gdk_x11_get_default_xdisplay (), &event_base, &error_base) ||
+ !XRRQueryVersion (gdk_x11_get_default_xdisplay (), &major, &minor) )
+ {
gdk_x11_display_error_trap_pop_ignored (gdisplay);
+ g_warning ("No XRANDR extension found");
+ return FALSE;
+ }
+ gdk_x11_display_error_trap_pop_ignored (gdisplay);
- if (major == 1 && minor < 2)
- {
- g_warning ("XRANDR version < 1.2");
- return FALSE;
- }
+ if (major == 1 && minor < 2)
+ {
+ g_warning ("XRANDR version < 1.2");
+ return FALSE;
+ }
#ifdef RR_PROPERTY_BACKLIGHT
- brightness->priv->backlight = XInternAtom (gdk_x11_get_default_xdisplay (), RR_PROPERTY_BACKLIGHT, True);
- if (brightness->priv->backlight == None) /* fall back to deprecated name */
+ brightness->priv->backlight = XInternAtom (gdk_x11_get_default_xdisplay (), RR_PROPERTY_BACKLIGHT, True);
+ if (brightness->priv->backlight == None) /* fall back to deprecated name */
#endif
- brightness->priv->backlight = XInternAtom (gdk_x11_get_default_xdisplay (), "BACKLIGHT", True);
+ brightness->priv->backlight = XInternAtom (gdk_x11_get_default_xdisplay (), "BACKLIGHT", True);
- if (brightness->priv->backlight == None)
- {
- g_warning ("No outputs have backlight property");
- return FALSE;
- }
+ if (brightness->priv->backlight == None)
+ {
+ g_warning ("No outputs have backlight property");
+ return FALSE;
+ }
- screen = gdk_display_get_default_screen (gdisplay);
+ screen = gdk_display_get_default_screen (gdisplay);
- screen_num = gdk_x11_screen_get_screen_number (screen);
+ screen_num = gdk_x11_screen_get_screen_number (screen);
- gdk_x11_display_error_trap_push (gdisplay);
+ gdk_x11_display_error_trap_push (gdisplay);
- window = RootWindow (gdk_x11_get_default_xdisplay (), screen_num);
+ window = RootWindow (gdk_x11_get_default_xdisplay (), screen_num);
#if (RANDR_MAJOR == 1 && RANDR_MINOR >=3 )
- if (major > 1 || minor >= 3)
- brightness->priv->resource = XRRGetScreenResourcesCurrent (gdk_x11_get_default_xdisplay (), window);
- else
+ if (major > 1 || minor >= 3)
+ brightness->priv->resource = XRRGetScreenResourcesCurrent (gdk_x11_get_default_xdisplay (), window);
+ else
#endif
- brightness->priv->resource = XRRGetScreenResources (gdk_x11_get_default_xdisplay (), window);
+ brightness->priv->resource = XRRGetScreenResources (gdk_x11_get_default_xdisplay (), window);
- for ( i = 0; i < brightness->priv->resource->noutput; i++)
- {
- info = XRRGetOutputInfo (gdk_x11_get_default_xdisplay (), brightness->priv->resource, brightness->priv->resource->outputs[i]);
+ for ( i = 0; i < brightness->priv->resource->noutput; i++)
+ {
+ info = XRRGetOutputInfo (gdk_x11_get_default_xdisplay (), brightness->priv->resource, brightness->priv->resource->outputs[i]);
- if ( g_str_has_prefix (info->name, "LVDS") || g_str_has_prefix (info->name, "eDP") )
- {
-
- if ( xfpm_brightness_xrand_get_limit (brightness, brightness->priv->resource->outputs[i], &min, &max) &&
- min != max )
- {
- ret = TRUE;
- brightness->priv->output = brightness->priv->resource->outputs[i];
- brightness->priv->step = max <= 20 ? 1 : max / 10;
- }
-
- }
- XRRFreeOutputInfo (info);
+ if ( g_str_has_prefix (info->name, "LVDS") || g_str_has_prefix (info->name, "eDP") )
+ {
+ if ( xfpm_brightness_xrand_get_limit (brightness, brightness->priv->resource->outputs[i], &min, &max) &&
+ min != max )
+ {
+ ret = TRUE;
+ brightness->priv->output = brightness->priv->resource->outputs[i];
+ brightness->priv->step = max <= 20 ? 1 : max / 10;
+ }
}
- if (gdk_x11_display_error_trap_pop (gdisplay) != 0)
- g_critical ("Failed to get output/resource info");
+ XRRFreeOutputInfo (info);
+ }
- return ret;
+ if (gdk_x11_display_error_trap_pop (gdisplay) != 0)
+ g_critical ("Failed to get output/resource info");
+
+ return ret;
}
static gboolean
xfpm_brightness_xrand_up (XfpmBrightness *brightness, gint32 *new_level)
{
- gint32 hw_level;
- gboolean ret = FALSE;
- gint32 set_level;
+ gint32 hw_level;
+ gboolean ret = FALSE;
+ gint32 set_level;
- ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, &hw_level);
+ ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, &hw_level);
- if ( !ret )
- return FALSE;
+ if ( !ret )
+ return FALSE;
- if ( hw_level == brightness->priv->max_level )
- {
- *new_level = brightness->priv->max_level;
- return TRUE;
- }
+ if ( hw_level == brightness->priv->max_level )
+ {
+ *new_level = brightness->priv->max_level;
+ return TRUE;
+ }
- set_level = MIN (hw_level + brightness->priv->step, brightness->priv->max_level );
+ set_level = MIN (hw_level + brightness->priv->step, brightness->priv->max_level );
- g_warn_if_fail (xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, set_level));
+ g_warn_if_fail (xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, set_level));
- ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, new_level);
+ ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, new_level);
- if ( !ret )
- {
- g_warning ("xfpm_brightness_xrand_up failed for %d", set_level);
- return FALSE;
- }
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_xrand_up failed for %d", set_level);
+ return FALSE;
+ }
- /* Nothing changed in the hardware*/
- if ( *new_level == hw_level )
- {
- g_warning ("xfpm_brightness_xrand_up did not change the hw level to %d", set_level);
- return FALSE;
- }
+ /* Nothing changed in the hardware*/
+ if ( *new_level == hw_level )
+ {
+ g_warning ("xfpm_brightness_xrand_up did not change the hw level to %d", set_level);
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
xfpm_brightness_xrand_down (XfpmBrightness *brightness, gint32 *new_level)
{
- gint32 hw_level;
- gboolean ret;
- gint32 set_level;
+ gint32 hw_level;
+ gboolean ret;
+ gint32 set_level;
- ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, &hw_level);
+ ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, &hw_level);
- if ( !ret )
- return FALSE;
+ if ( !ret )
+ return FALSE;
- if ( hw_level == brightness->priv->min_level )
- {
- *new_level = brightness->priv->min_level;
- return TRUE;
- }
+ if ( hw_level == brightness->priv->min_level )
+ {
+ *new_level = brightness->priv->min_level;
+ return TRUE;
+ }
- set_level = MAX (hw_level - brightness->priv->step, brightness->priv->min_level);
+ set_level = MAX (hw_level - brightness->priv->step, brightness->priv->min_level);
- g_warn_if_fail (xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, set_level));
+ g_warn_if_fail (xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, set_level));
- ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, new_level);
+ ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, new_level);
- if ( !ret )
- {
- g_warning ("xfpm_brightness_xrand_down failed for %d", set_level);
- return FALSE;
- }
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_xrand_down failed for %d", set_level);
+ return FALSE;
+ }
- /* Nothing changed in the hardware*/
- if ( *new_level == hw_level )
- {
- g_warning ("xfpm_brightness_xrand_down did not change the hw level to %d", set_level);
- return FALSE;
- }
+ /* Nothing changed in the hardware*/
+ if ( *new_level == hw_level )
+ {
+ g_warning ("xfpm_brightness_xrand_down did not change the hw level to %d", set_level);
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
/*
@@ -324,225 +323,229 @@ xfpm_brightness_xrand_down (XfpmBrightness *brightness, gint32 *new_level)
static gint
xfpm_brightness_helper_get_value (const gchar *argument)
{
- gboolean ret;
- GError *error = NULL;
- gchar *stdout_data = NULL;
- gint exit_status = 0;
- gint value = -1;
- gchar *command = NULL;
-
- command = g_strdup_printf (SBINDIR "/xfpm-power-backlight-helper --%s", argument);
- ret = g_spawn_command_line_sync (command,
- &stdout_data, NULL, &exit_status, &error);
- if ( !ret )
- {
- g_warning ("failed to get value: %s", error->message);
- g_error_free (error);
- goto out;
- }
- g_debug ("executed %s; retval: %i", command, exit_status);
- if ( exit_status != 0 )
- goto out;
+ gboolean ret;
+ GError *error = NULL;
+ gchar *stdout_data = NULL;
+ gint exit_status = 0;
+ gint value = -1;
+ gchar *command = NULL;
+
+ command = g_strdup_printf (SBINDIR "/xfpm-power-backlight-helper --%s", argument);
+ ret = g_spawn_command_line_sync (command,
+ &stdout_data, NULL, &exit_status, &error);
+ if ( !ret )
+ {
+ g_warning ("failed to get value: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ g_debug ("executed %s; retval: %i", command, exit_status);
+
+ if ( exit_status != 0 )
+ goto out;
#if !defined(BACKEND_TYPE_FREEBSD)
- if ( stdout_data[0] == 'N' )
- value = 0;
- else if ( stdout_data[0] == 'Y' )
- value = 1;
- else
- value = atoi (stdout_data);
-#else
+ if ( stdout_data[0] == 'N' )
+ value = 0;
+ else if ( stdout_data[0] == 'Y' )
+ value = 1;
+ else
value = atoi (stdout_data);
+#else
+ value = atoi (stdout_data);
#endif
out:
- g_free (command);
- g_free (stdout_data);
- return value;
+ g_free (command);
+ g_free (stdout_data);
+ return value;
}
static gboolean
xfpm_brightness_setup_helper (XfpmBrightness *brightness)
{
- gint32 ret;
-
- ret = (gint32) xfpm_brightness_helper_get_value ("get-max-brightness");
- g_debug ("xfpm_brightness_setup_helper: get-max-brightness returned %i", ret);
- if ( ret < 0 ) {
- brightness->priv->helper_has_hw = FALSE;
- } else {
- brightness->priv->helper_has_hw = TRUE;
- brightness->priv->min_level = 0;
- brightness->priv->max_level = ret;
- brightness->priv->step = ret <= 20 ? 1 : ret / 10;
- }
+ gint32 ret;
- return brightness->priv->helper_has_hw;
+ ret = (gint32) xfpm_brightness_helper_get_value ("get-max-brightness");
+ g_debug ("xfpm_brightness_setup_helper: get-max-brightness returned %i", ret);
+ if ( ret < 0 )
+ {
+ brightness->priv->helper_has_hw = FALSE;
+ }
+ else
+ {
+ brightness->priv->helper_has_hw = TRUE;
+ brightness->priv->min_level = 0;
+ brightness->priv->max_level = ret;
+ brightness->priv->step = ret <= 20 ? 1 : ret / 10;
+ }
+
+ return brightness->priv->helper_has_hw;
}
static gboolean
xfpm_brightness_helper_get_level (XfpmBrightness *brg, gint32 *level)
{
- gint32 ret;
+ gint32 ret;
- if ( ! brg->priv->helper_has_hw )
- return FALSE;
+ if ( ! brg->priv->helper_has_hw )
+ return FALSE;
- ret = (gint32) xfpm_brightness_helper_get_value ("get-brightness");
+ ret = (gint32) xfpm_brightness_helper_get_value ("get-brightness");
- g_debug ("xfpm_brightness_helper_get_level: get-brightness returned %i", ret);
+ g_debug ("xfpm_brightness_helper_get_level: get-brightness returned %i", ret);
- if ( ret >= 0 )
- {
- *level = ret;
- return TRUE;
- }
+ if ( ret >= 0 )
+ {
+ *level = ret;
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
xfpm_brightness_helper_set_level (XfpmBrightness *brg, gint32 level)
{
- gboolean ret;
- GError *error = NULL;
- gint exit_status = 0;
- gchar *command = NULL;
-
- command = g_strdup_printf ("pkexec " SBINDIR "/xfpm-power-backlight-helper --set-brightness %i", level);
- ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
- if ( !ret )
- {
- g_warning ("xfpm_brightness_helper_set_level: failed to set value: %s", error->message);
- g_error_free (error);
- goto out;
- }
- g_debug ("executed %s; retval: %i", command, exit_status);
- ret = (exit_status == 0);
+ gboolean ret;
+ GError *error = NULL;
+ gint exit_status = 0;
+ gchar *command = NULL;
+
+ command = g_strdup_printf ("pkexec " SBINDIR "/xfpm-power-backlight-helper --set-brightness %i", level);
+ ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_helper_set_level: failed to set value: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ g_debug ("executed %s; retval: %i", command, exit_status);
+ ret = (exit_status == 0);
out:
- g_free (command);
- return ret;
+ g_free (command);
+ return ret;
}
static gboolean
xfpm_brightness_helper_get_switch (XfpmBrightness *brg, gint *brightness_switch)
{
- gint ret;
+ gint ret;
- ret = xfpm_brightness_helper_get_value ("get-brightness-switch");
+ ret = xfpm_brightness_helper_get_value ("get-brightness-switch");
- if ( ret >= 0 )
- {
- *brightness_switch = ret;
- return TRUE;
- }
+ if ( ret >= 0 )
+ {
+ *brightness_switch = ret;
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
xfpm_brightness_helper_set_switch (XfpmBrightness *brg, gint brightness_switch)
{
- gboolean ret;
- GError *error = NULL;
- gint exit_status = 0;
- gchar *command = NULL;
-
- command = g_strdup_printf ("pkexec " SBINDIR "/xfpm-power-backlight-helper --set-brightness-switch %i", brightness_switch);
- ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
- if ( !ret )
- {
- g_warning ("xfpm_brightness_helper_set_switch: failed to set value: %s", error->message);
- g_error_free (error);
- goto out;
- }
- g_debug ("executed %s; retval: %i", command, exit_status);
- ret = (exit_status == 0);
+ gboolean ret;
+ GError *error = NULL;
+ gint exit_status = 0;
+ gchar *command = NULL;
+
+ command = g_strdup_printf ("pkexec " SBINDIR "/xfpm-power-backlight-helper --set-brightness-switch %i", brightness_switch);
+ ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_helper_set_switch: failed to set value: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ g_debug ("executed %s; retval: %i", command, exit_status);
+ ret = (exit_status == 0);
out:
- g_free (command);
- return ret;
+ g_free (command);
+ return ret;
}
static gboolean
xfpm_brightness_helper_up (XfpmBrightness *brightness, gint32 *new_level)
{
- gint32 hw_level;
- gboolean ret = FALSE;
- gint32 set_level;
+ gint32 hw_level;
+ gboolean ret = FALSE;
+ gint32 set_level;
- ret = xfpm_brightness_helper_get_level (brightness, &hw_level);
+ ret = xfpm_brightness_helper_get_level (brightness, &hw_level);
- if ( !ret )
- return FALSE;
+ if ( !ret )
+ return FALSE;
- if ( hw_level >= brightness->priv->max_level )
- {
- *new_level = brightness->priv->max_level;
- return TRUE;
- }
+ if ( hw_level >= brightness->priv->max_level )
+ {
+ *new_level = brightness->priv->max_level;
+ return TRUE;
+ }
- set_level = MIN (hw_level + brightness->priv->step, brightness->priv->max_level );
+ set_level = MIN (hw_level + brightness->priv->step, brightness->priv->max_level );
- g_warn_if_fail (xfpm_brightness_helper_set_level (brightness, set_level));
+ g_warn_if_fail (xfpm_brightness_helper_set_level (brightness, set_level));
- ret = xfpm_brightness_helper_get_level (brightness, new_level);
+ ret = xfpm_brightness_helper_get_level (brightness, new_level);
- if ( !ret )
- {
- g_warning ("xfpm_brightness_helper_up failed for %d", set_level);
- return FALSE;
- }
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_helper_up failed for %d", set_level);
+ return FALSE;
+ }
- /* Nothing changed in the hardware*/
- if ( *new_level == hw_level )
- {
- g_warning ("xfpm_brightness_helper_up did not change the hw level to %d", set_level);
- return FALSE;
- }
+ /* Nothing changed in the hardware*/
+ if ( *new_level == hw_level )
+ {
+ g_warning ("xfpm_brightness_helper_up did not change the hw level to %d", set_level);
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
xfpm_brightness_helper_down (XfpmBrightness *brightness, gint32 *new_level)
{
- gint32 hw_level;
- gboolean ret;
- gint32 set_level;
+ gint32 hw_level;
+ gboolean ret;
+ gint32 set_level;
- ret = xfpm_brightness_helper_get_level (brightness, &hw_level);
+ ret = xfpm_brightness_helper_get_level (brightness, &hw_level);
- if ( !ret )
- return FALSE;
+ if ( !ret )
+ return FALSE;
- if ( hw_level <= brightness->priv->min_level )
- {
- *new_level = brightness->priv->min_level;
- return TRUE;
- }
+ if ( hw_level <= brightness->priv->min_level )
+ {
+ *new_level = brightness->priv->min_level;
+ return TRUE;
+ }
- set_level = MAX (hw_level - brightness->priv->step, brightness->priv->min_level);
+ set_level = MAX (hw_level - brightness->priv->step, brightness->priv->min_level);
- g_warn_if_fail (xfpm_brightness_helper_set_level (brightness, set_level));
+ g_warn_if_fail (xfpm_brightness_helper_set_level (brightness, set_level));
- ret = xfpm_brightness_helper_get_level (brightness, new_level);
+ ret = xfpm_brightness_helper_get_level (brightness, new_level);
- if ( !ret )
- {
- g_warning ("xfpm_brightness_helper_down failed for %d", set_level);
- return FALSE;
- }
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_helper_down failed for %d", set_level);
+ return FALSE;
+ }
- /* Nothing changed in the hardware*/
- if ( *new_level == hw_level )
- {
- g_warning ("xfpm_brightness_helper_down did not change the hw level to %d", set_level);
- return FALSE;
- }
+ /* Nothing changed in the hardware*/
+ if ( *new_level == hw_level )
+ {
+ g_warning ("xfpm_brightness_helper_down did not change the hw level to %d", set_level);
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
#endif
@@ -550,198 +553,198 @@ xfpm_brightness_helper_down (XfpmBrightness *brightness, gint32 *new_level)
static void
xfpm_brightness_class_init (XfpmBrightnessClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = xfpm_brightness_finalize;
+ object_class->finalize = xfpm_brightness_finalize;
}
static void
xfpm_brightness_init (XfpmBrightness *brightness)
{
- brightness->priv = xfpm_brightness_get_instance_private (brightness);
-
- brightness->priv->resource = NULL;
- brightness->priv->xrandr_has_hw = FALSE;
- brightness->priv->helper_has_hw = FALSE;
- brightness->priv->max_level = 0;
- brightness->priv->min_level = 0;
- brightness->priv->current_level = 0;
- brightness->priv->output = 0;
- brightness->priv->step = 0;
+ brightness->priv = xfpm_brightness_get_instance_private (brightness);
+
+ brightness->priv->resource = NULL;
+ brightness->priv->xrandr_has_hw = FALSE;
+ brightness->priv->helper_has_hw = FALSE;
+ brightness->priv->max_level = 0;
+ brightness->priv->min_level = 0;
+ brightness->priv->current_level = 0;
+ brightness->priv->output = 0;
+ brightness->priv->step = 0;
}
static void
xfpm_brightness_free_data (XfpmBrightness *brightness)
{
- if ( brightness->priv->resource )
- XRRFreeScreenResources (brightness->priv->resource);
+ if ( brightness->priv->resource )
+ XRRFreeScreenResources (brightness->priv->resource);
}
static void
xfpm_brightness_finalize (GObject *object)
{
- XfpmBrightness *brightness;
+ XfpmBrightness *brightness;
- brightness = XFPM_BRIGHTNESS (object);
+ brightness = XFPM_BRIGHTNESS (object);
- xfpm_brightness_free_data (brightness);
+ xfpm_brightness_free_data (brightness);
- G_OBJECT_CLASS (xfpm_brightness_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_brightness_parent_class)->finalize (object);
}
XfpmBrightness *
xfpm_brightness_new (void)
{
- XfpmBrightness *brightness = NULL;
- brightness = g_object_new (XFPM_TYPE_BRIGHTNESS, NULL);
- return brightness;
+ XfpmBrightness *brightness = NULL;
+ brightness = g_object_new (XFPM_TYPE_BRIGHTNESS, NULL);
+ return brightness;
}
gboolean
xfpm_brightness_setup (XfpmBrightness *brightness)
{
- xfpm_brightness_free_data (brightness);
- brightness->priv->xrandr_has_hw = xfpm_brightness_setup_xrandr (brightness);
+ xfpm_brightness_free_data (brightness);
+ brightness->priv->xrandr_has_hw = xfpm_brightness_setup_xrandr (brightness);
+
+ if ( brightness->priv->xrandr_has_hw )
+ {
+ xfpm_brightness_xrand_get_limit (brightness,
+ brightness->priv->output,
+ &brightness->priv->min_level,
+ &brightness->priv->max_level);
+ g_debug ("Brightness controlled by xrandr, min_level=%d max_level=%d",
+ brightness->priv->min_level,
+ brightness->priv->max_level);
- if ( brightness->priv->xrandr_has_hw )
- {
- xfpm_brightness_xrand_get_limit (brightness,
- brightness->priv->output,
- &brightness->priv->min_level,
- &brightness->priv->max_level);
- g_debug ("Brightness controlled by xrandr, min_level=%d max_level=%d",
- brightness->priv->min_level,
- brightness->priv->max_level);
-
- return TRUE;
- }
+ return TRUE;
+ }
#ifdef ENABLE_POLKIT
- else
- {
- if ( xfpm_brightness_setup_helper (brightness) ) {
+ else
+ {
+ if ( xfpm_brightness_setup_helper (brightness) ) {
#if defined(BACKEND_TYPE_FREEBSD)
- g_debug ("xrandr not available, brightness controlled by sysctl helper; min_level=%d max_level=%d",
+ g_debug ("xrandr not available, brightness controlled by sysctl helper; min_level=%d max_level=%d",
#else
- g_debug ("xrandr not available, brightness controlled by sysfs helper; min_level=%d max_level=%d",
+ g_debug ("xrandr not available, brightness controlled by sysfs helper; min_level=%d max_level=%d",
#endif
- brightness->priv->min_level,
- brightness->priv->max_level);
- return TRUE;
- }
+ brightness->priv->min_level,
+ brightness->priv->max_level);
+ return TRUE;
}
+ }
#endif
- g_debug ("no brightness controls available");
- return FALSE;
+ g_debug ("no brightness controls available");
+ return FALSE;
}
gboolean xfpm_brightness_up (XfpmBrightness *brightness, gint32 *new_level)
{
- gboolean ret = FALSE;
+ gboolean ret = FALSE;
- if ( brightness->priv->xrandr_has_hw )
- {
- ret = xfpm_brightness_xrand_up (brightness, new_level);
- }
+ if ( brightness->priv->xrandr_has_hw )
+ {
+ ret = xfpm_brightness_xrand_up (brightness, new_level);
+ }
#ifdef ENABLE_POLKIT
- else if ( brightness->priv->helper_has_hw )
- {
- ret = xfpm_brightness_helper_up (brightness, new_level);
- }
+ else if ( brightness->priv->helper_has_hw )
+ {
+ ret = xfpm_brightness_helper_up (brightness, new_level);
+ }
#endif
- return ret;
+ return ret;
}
gboolean xfpm_brightness_down (XfpmBrightness *brightness, gint32 *new_level)
{
- gboolean ret = FALSE;
-
- if ( brightness->priv->xrandr_has_hw )
- {
- ret = xfpm_brightness_xrand_down (brightness, new_level);
- if ( ret )
- ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, new_level);
- }
+ gboolean ret = FALSE;
+
+ if ( brightness->priv->xrandr_has_hw )
+ {
+ ret = xfpm_brightness_xrand_down (brightness, new_level);
+ if ( ret )
+ ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, new_level);
+ }
#ifdef ENABLE_POLKIT
- else if ( brightness->priv->helper_has_hw )
- {
- ret = xfpm_brightness_helper_down (brightness, new_level);
- }
+ else if ( brightness->priv->helper_has_hw )
+ {
+ ret = xfpm_brightness_helper_down (brightness, new_level);
+ }
#endif
- return ret;
+ return ret;
}
gboolean xfpm_brightness_has_hw (XfpmBrightness *brightness)
{
- return brightness->priv->xrandr_has_hw || brightness->priv->helper_has_hw;
+ return brightness->priv->xrandr_has_hw || brightness->priv->helper_has_hw;
}
gint32 xfpm_brightness_get_max_level (XfpmBrightness *brightness)
{
- return brightness->priv->max_level;
+ return brightness->priv->max_level;
}
-gboolean xfpm_brightness_get_level (XfpmBrightness *brightness, gint32 *level)
+gboolean xfpm_brightness_get_level (XfpmBrightness *brightness, gint32 *level)
{
- gboolean ret = FALSE;
+ gboolean ret = FALSE;
- if ( brightness->priv->xrandr_has_hw )
- ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, level);
+ if ( brightness->priv->xrandr_has_hw )
+ ret = xfpm_brightness_xrandr_get_level (brightness, brightness->priv->output, level);
#ifdef ENABLE_POLKIT
- else if ( brightness->priv->helper_has_hw )
- ret = xfpm_brightness_helper_get_level (brightness, level);
+ else if ( brightness->priv->helper_has_hw )
+ ret = xfpm_brightness_helper_get_level (brightness, level);
#endif
- return ret;
+ return ret;
}
gboolean xfpm_brightness_set_level (XfpmBrightness *brightness, gint32 level)
{
- gboolean ret = FALSE;
+ gboolean ret = FALSE;
- if (brightness->priv->xrandr_has_hw )
- ret = xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, level);
+ if (brightness->priv->xrandr_has_hw )
+ ret = xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, level);
#ifdef ENABLE_POLKIT
- else if ( brightness->priv->helper_has_hw )
- ret = xfpm_brightness_helper_set_level (brightness, level);
+ else if ( brightness->priv->helper_has_hw )
+ ret = xfpm_brightness_helper_set_level (brightness, level);
#endif
- return ret;
+ return ret;
}
gboolean xfpm_brightness_dim_down (XfpmBrightness *brightness)
{
- gboolean ret = FALSE;
+ gboolean ret = FALSE;
- if (brightness->priv->xrandr_has_hw )
- ret = xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, brightness->priv->min_level);
+ if (brightness->priv->xrandr_has_hw )
+ ret = xfpm_brightness_xrandr_set_level (brightness, brightness->priv->output, brightness->priv->min_level);
#ifdef ENABLE_POLKIT
- else if ( brightness->priv->helper_has_hw )
- ret = xfpm_brightness_helper_set_level (brightness, brightness->priv->min_level);
+ else if ( brightness->priv->helper_has_hw )
+ ret = xfpm_brightness_helper_set_level (brightness, brightness->priv->min_level);
#endif
- return ret;
+ return ret;
}
gboolean xfpm_brightness_get_switch (XfpmBrightness *brightness, gint *brightness_switch)
{
- gboolean ret = FALSE;
+ gboolean ret = FALSE;
#ifdef ENABLE_POLKIT
- if ( brightness->priv->helper_has_hw )
+ if ( brightness->priv->helper_has_hw )
ret = xfpm_brightness_helper_get_switch (brightness, brightness_switch);
#endif
- return ret;
+ return ret;
}
gboolean xfpm_brightness_set_switch (XfpmBrightness *brightness, gint brightness_switch)
{
- gboolean ret = FALSE;
+ gboolean ret = FALSE;
#ifdef ENABLE_POLKIT
- if ( brightness->priv->helper_has_hw )
- ret = xfpm_brightness_helper_set_switch (brightness, brightness_switch);
+ if ( brightness->priv->helper_has_hw )
+ ret = xfpm_brightness_helper_set_switch (brightness, brightness_switch);
#endif
- return ret;
+ return ret;
}
diff --git a/common/xfpm-brightness.h b/common/xfpm-brightness.h
index 990927d..2e07240 100644
--- a/common/xfpm-brightness.h
+++ b/common/xfpm-brightness.h
@@ -33,46 +33,35 @@ typedef struct XfpmBrightnessPrivate XfpmBrightnessPrivate;
typedef struct
{
- GObject parent;
- XfpmBrightnessPrivate *priv;
-
+ GObject parent;
+ XfpmBrightnessPrivate *priv;
+
} XfpmBrightness;
typedef struct
{
- GObjectClass parent_class;
-
-} XfpmBrightnessClass;
-
-GType xfpm_brightness_get_type (void) G_GNUC_CONST;
-
-XfpmBrightness *xfpm_brightness_new (void);
-
-gboolean xfpm_brightness_setup (XfpmBrightness *brightness);
-
-gboolean xfpm_brightness_up (XfpmBrightness *brightness,
- gint32 *new_level);
-
-gboolean xfpm_brightness_down (XfpmBrightness *brightness,
- gint32 *new_level);
+ GObjectClass parent_class;
-gboolean xfpm_brightness_has_hw (XfpmBrightness *brightness);
-
-gint32 xfpm_brightness_get_max_level (XfpmBrightness *brightness);
-
-gboolean xfpm_brightness_get_level (XfpmBrightness *brightness,
- gint32 *level);
-
-gboolean xfpm_brightness_set_level (XfpmBrightness *brightness,
- gint32 level);
-
-gboolean xfpm_brightness_dim_down (XfpmBrightness *brightness);
-
-gboolean xfpm_brightness_get_switch (XfpmBrightness *brightness,
- gint *brightness_switch);
+} XfpmBrightnessClass;
-gboolean xfpm_brightness_set_switch (XfpmBrightness *brightness,
- gint brightness_switch);
+GType xfpm_brightness_get_type (void) G_GNUC_CONST;
+XfpmBrightness *xfpm_brightness_new (void);
+gboolean xfpm_brightness_setup (XfpmBrightness *brightness);
+gboolean xfpm_brightness_up (XfpmBrightness *brightness,
+ gint32 *new_level);
+gboolean xfpm_brightness_down (XfpmBrightness *brightness,
+ gint32 *new_level);
+gboolean xfpm_brightness_has_hw (XfpmBrightness *brightness);
+gint32 xfpm_brightness_get_max_level (XfpmBrightness *brightness);
+gboolean xfpm_brightness_get_level (XfpmBrightness *brightness,
+ gint32 *level);
+gboolean xfpm_brightness_set_level (XfpmBrightness *brightness,
+ gint32 level);
+gboolean xfpm_brightness_dim_down (XfpmBrightness *brightness);
+gboolean xfpm_brightness_get_switch (XfpmBrightness *brightness,
+ gint *brightness_switch);
+gboolean xfpm_brightness_set_switch (XfpmBrightness *brightness,
+ gint brightness_switch);
G_END_DECLS
diff --git a/common/xfpm-common.c b/common/xfpm-common.c
index 243baf2..e4eea0a 100644
--- a/common/xfpm-common.c
+++ b/common/xfpm-common.c
@@ -24,145 +24,152 @@
#include "xfpm-common.h"
-const gchar *xfpm_bool_to_string (gboolean value)
+const gchar
+*xfpm_bool_to_string (gboolean value)
{
- if ( value == TRUE ) return "TRUE";
- else return "FALSE";
+ if ( value == TRUE )
+ return "TRUE";
+ else
+ return "FALSE";
}
-gboolean xfpm_string_to_bool (const gchar *string)
+gboolean
+xfpm_string_to_bool (const gchar *string)
{
- if ( !g_strcmp0 (string, "TRUE") ) return TRUE;
- else if ( !g_strcmp0 (string, "FALSE") ) return FALSE;
-
+ if ( !g_strcmp0 (string, "TRUE") )
+ return TRUE;
+ else if ( !g_strcmp0 (string, "FALSE") )
return FALSE;
+
+ return FALSE;
}
-GtkBuilder *xfpm_builder_new_from_string (const gchar *ui, GError **error)
+GtkBuilder
+*xfpm_builder_new_from_string (const gchar *ui, GError **error)
{
- GtkBuilder *builder;
-
- builder = gtk_builder_new ();
-
- gtk_builder_add_from_string (GTK_BUILDER (builder),
- ui,
- -1,
- error);
-
- return builder;
+ GtkBuilder *builder;
+
+ builder = gtk_builder_new ();
+
+ gtk_builder_add_from_string (GTK_BUILDER (builder),
+ ui,
+ -1,
+ error);
+
+ return builder;
}
-void
-xfpm_preferences (void)
+void
+xfpm_preferences (void)
{
- g_spawn_command_line_async ("xfce4-power-manager-settings", NULL);
+ g_spawn_command_line_async ("xfce4-power-manager-settings", NULL);
}
void
xfpm_preferences_device_id (const gchar* object_path)
{
- gchar *string = g_strdup_printf("xfce4-power-manager-settings -d %s", object_path);
+ gchar *string = g_strdup_printf("xfce4-power-manager-settings -d %s", object_path);
- if (string)
- g_spawn_command_line_async (string, NULL);
+ if (string)
+ g_spawn_command_line_async (string, NULL);
- g_free (string);
+ g_free (string);
}
void
xfpm_quit (void)
{
- g_spawn_command_line_async ("xfce4-power-manager -q", NULL);
+ g_spawn_command_line_async ("xfce4-power-manager -q", NULL);
}
-void
+void
xfpm_about (gpointer data)
{
- gchar *package = (gchar *)data;
-
- const gchar* authors[] =
- {
- "Ali Abdallah <aliov at xfce.org>",
- NULL,
- };
-
- static const gchar *documenters[] =
- {
- "Ali Abdallah <aliov at xfce.org>",
- NULL,
- };
-
- static const gchar *artists[] =
- {
- "Simon Steinbeiß <simon at xfce.org>",
- NULL,
- };
-
- gtk_show_about_dialog (NULL,
- "copyright", "Copyright \302\251 2008-2011 Ali Abdallah\nCopyright \302\251 2011-2012 Nick Schermer\nCopyright \302\251 2013-2015 Eric Koegel, Harald Judt, Simon Steinbeiß",
- "destroy-with-parent", TRUE,
- "authors", authors,
- "artists", artists,
- "documenters", documenters,
- "license", XFCE_LICENSE_GPL,
- "program-name", package,
- "translator-credits", _("translator-credits"),
- "version", PACKAGE_VERSION,
- "website", "http://docs.xfce.org/xfce/xfce4-power-manager/1.4/start",
- "logo-icon-name", "xfce4-power-manager-settings",
- NULL);
-
+ gchar *package = (gchar *)data;
+
+ const gchar* authors[] =
+ {
+ "Ali Abdallah <aliov at xfce.org>",
+ NULL,
+ };
+
+ static const gchar *documenters[] =
+ {
+ "Ali Abdallah <aliov at xfce.org>",
+ NULL,
+ };
+
+ static const gchar *artists[] =
+ {
+ "Simon Steinbeiß <simon at xfce.org>",
+ NULL,
+ };
+
+ gtk_show_about_dialog (NULL,
+ "copyright", "Copyright \302\251 2008-2011 Ali Abdallah\nCopyright \302\251 2011-2012 Nick Schermer\nCopyright \302\251 2013-2015 Eric Koegel, Harald Judt, Simon Steinbeiß",
+ "destroy-with-parent", TRUE,
+ "authors", authors,
+ "artists", artists,
+ "documenters", documenters,
+ "license", XFCE_LICENSE_GPL,
+ "program-name", package,
+ "translator-credits", _("translator-credits"),
+ "version", PACKAGE_VERSION,
+ "website", "http://docs.xfce.org/xfce/xfce4-power-manager/1.4/start",
+ "logo-icon-name", "xfce4-power-manager-settings",
+ NULL);
}
-gboolean xfpm_is_multihead_connected (void)
+gboolean
+xfpm_is_multihead_connected (void)
{
- GdkDisplay *dpy;
+ GdkDisplay *dpy;
#if !GTK_CHECK_VERSION (3, 22, 0)
- GdkScreen *screen;
+ GdkScreen *screen;
#endif
- gint nmonitor;
-
- dpy = gdk_display_get_default ();
+ gint nmonitor;
+
+ dpy = gdk_display_get_default ();
#if !GTK_CHECK_VERSION (3, 22, 0)
- nmonitor = 1;
- screen = gdk_display_get_screen (dpy, 0);
- if ( screen )
- nmonitor = gdk_screen_get_n_monitors (screen);
+ nmonitor = 1;
+ screen = gdk_display_get_screen (dpy, 0);
+ if ( screen )
+ nmonitor = gdk_screen_get_n_monitors (screen);
#else
- nmonitor = gdk_display_get_n_monitors (dpy);
+ nmonitor = gdk_display_get_n_monitors (dpy);
#endif
- if ( nmonitor > 1 )
- {
- g_debug ("Multiple monitor connected");
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-
+ if ( nmonitor > 1 )
+ {
+ g_debug ("Multiple monitors connected");
+ return TRUE;
+ }
+ else
+ {
return FALSE;
+ }
+
+ return FALSE;
}
-GdkPixbuf *xfpm_icon_load (const gchar *icon_name, gint size)
+GdkPixbuf *
+xfpm_icon_load (const gchar *icon_name, gint size)
{
- GdkPixbuf *pix = NULL;
- GError *error = NULL;
-
- pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- icon_name,
- size,
- GTK_ICON_LOOKUP_FORCE_SIZE,
- &error);
-
- if ( error )
- {
- g_warning ("Unable to load icon : %s : %s", icon_name, error->message);
- g_error_free (error);
- }
-
- return pix;
+ GdkPixbuf *pix = NULL;
+ GError *error = NULL;
+
+ pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ icon_name,
+ size,
+ GTK_ICON_LOOKUP_FORCE_SIZE,
+ &error);
+
+ if ( error )
+ {
+ g_warning ("Unable to load icon : %s : %s", icon_name, error->message);
+ g_error_free (error);
+ }
+
+ return pix;
}
-
diff --git a/common/xfpm-common.h b/common/xfpm-common.h
index 10c0b4d..3f2ab37 100644
--- a/common/xfpm-common.h
+++ b/common/xfpm-common.h
@@ -30,25 +30,17 @@
G_BEGIN_DECLS
-GdkPixbuf *xfpm_icon_load (const gchar *icon_name,
- gint size);
-
-const gchar *xfpm_bool_to_string (gboolean value) G_GNUC_PURE;
-
-gboolean xfpm_string_to_bool (const gchar *string) G_GNUC_PURE;
-
-GtkBuilder *xfpm_builder_new_from_string (const gchar *file,
- GError **error);
-
-void xfpm_preferences (void);
-
-void xfpm_preferences_device_id (const gchar* object_path);
-
+GdkPixbuf *xfpm_icon_load (const gchar *icon_name,
+ gint size);
+const gchar *xfpm_bool_to_string (gboolean value) G_GNUC_PURE;
+gboolean xfpm_string_to_bool (const gchar *string) G_GNUC_PURE;
+GtkBuilder *xfpm_builder_new_from_string (const gchar *file,
+ GError **error);
+void xfpm_preferences (void);
+void xfpm_preferences_device_id (const gchar *object_path);
void xfpm_quit (void);
-
-void xfpm_about (gpointer data);
-
-gboolean xfpm_is_multihead_connected (void);
+void xfpm_about (gpointer data);
+gboolean xfpm_is_multihead_connected (void);
G_END_DECLS
diff --git a/common/xfpm-debug.c b/common/xfpm-debug.c
index a9f4bfd..41c8120 100644
--- a/common/xfpm-debug.c
+++ b/common/xfpm-debug.c
@@ -39,71 +39,72 @@ static gboolean enable_debug = FALSE;
void
xfpm_debug (const char *func, const char *file, int line, const char *format, ...)
{
- va_list args;
-
- if ( !enable_debug )
- return;
+ va_list args;
- va_start (args, format);
+ if ( !enable_debug )
+ return;
- fprintf (stdout, "TRACE[%s:%d] %s(): ", file, line, func);
- vfprintf (stdout, format, args);
- fprintf (stdout, "\n");
-
- va_end (args);
+ va_start (args, format);
+ fprintf (stdout, "TRACE[%s:%d] %s(): ", file, line, func);
+ vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+
+ va_end (args);
}
void
xfpm_warn (const char *func, const char *file, int line, const char *format, ...)
{
- va_list args;
-
- if ( !enable_debug )
- return;
-
- va_start (args, format);
-
- fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func);
- fprintf (stdout, "***WARNING***: ");
- vfprintf (stdout, format, args);
- fprintf (stdout, "\n");
- va_end (args);
+ va_list args;
+
+ if ( !enable_debug )
+ return;
+
+ va_start (args, format);
+
+ fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func);
+ fprintf (stdout, "***WARNING***: ");
+ vfprintf (stdout, format, args);
+ fprintf (stdout, "\n");
+ va_end (args);
}
-void xfpm_debug_enum (const gchar *func, const gchar *file, gint line,
- gint v_enum, GType type, const gchar *format, ...)
+void
+xfpm_debug_enum (const gchar *func, const gchar *file, gint line,
+ gint v_enum, GType type, const gchar *format, ...)
{
- va_list args;
- gchar *buffer;
-
- gchar *content = NULL;
- GValue __value__ = { 0, };
-
- if ( !enable_debug )
- return;
-
- g_value_init (&__value__, type);
- g_value_set_enum (&__value__, v_enum);
-
- content = g_strdup_value_contents (&__value__);
-
- va_start (args, format);
- g_vasprintf (&buffer, format, args);
- va_end (args);
-
- fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func);
- fprintf(stdout, "%s: %s", buffer, content);
- fprintf(stdout, "\n");
-
- g_value_unset (&__value__);
- g_free (content);
- g_free (buffer);
+ va_list args;
+ gchar *buffer;
+
+ gchar *content = NULL;
+ GValue __value__ = { 0, };
+
+ if ( !enable_debug )
+ return;
+
+ g_value_init (&__value__, type);
+ g_value_set_enum (&__value__, v_enum);
+
+ content = g_strdup_value_contents (&__value__);
+
+ va_start (args, format);
+ g_vasprintf (&buffer, format, args);
+ va_end (args);
+
+ fprintf(stdout, "TRACE[%s:%d] %s(): ", file, line, func);
+ fprintf(stdout, "%s: %s", buffer, content);
+ fprintf(stdout, "\n");
+
+ g_value_unset (&__value__);
+ g_free (content);
+ g_free (buffer);
}
#endif /*defined(G_HAVE_ISO_VARARGS)*/
-void xfpm_debug_init (gboolean debug)
+void
+xfpm_debug_init (gboolean debug)
{
enable_debug = debug;
}
diff --git a/common/xfpm-debug.h b/common/xfpm-debug.h
index 6ad151b..33538b2 100644
--- a/common/xfpm-debug.h
+++ b/common/xfpm-debug.h
@@ -33,34 +33,32 @@ G_BEGIN_DECLS
#if defined(G_HAVE_ISO_VARARGS)
#define XFPM_DEBUG(...)\
- xfpm_debug (__func__, __FILE__, __LINE__, __VA_ARGS__)
+ xfpm_debug (__func__, __FILE__, __LINE__, __VA_ARGS__)
#define XFPM_WARNING(...)\
- xfpm_warn (__func__, __FILE__, __LINE__, __VA_ARGS__)
+ xfpm_warn (__func__, __FILE__, __LINE__, __VA_ARGS__)
#define XFPM_DEBUG_ENUM(_value, _type, ...)\
- xfpm_debug_enum (__func__, __FILE__, __LINE__, _value, _type, __VA_ARGS__)
-
-
-void xfpm_debug_enum (const gchar *func,
- const gchar *file,
- gint line,
- gint v_enum,
- GType type,
- const gchar *format,
- ...) __attribute__((format (printf,6,7)));
-
-void xfpm_debug (const char *func,
- const char *file,
- int line,
- const char *format,
- ...) __attribute__((format (printf,4,5)));
-
-void xfpm_warn (const char *func,
- const char *file,
- int line,
- const char *format,
- ...) __attribute__((format (printf,4,5)));
+ xfpm_debug_enum (__func__, __FILE__, __LINE__, _value, _type, __VA_ARGS__)
+
+
+void xfpm_debug_enum (const gchar *func,
+ const gchar *file,
+ gint line,
+ gint v_enum,
+ GType type,
+ const gchar *format,
+ ...) __attribute__((format (printf,6,7)));
+void xfpm_debug (const char *func,
+ const char *file,
+ int line,
+ const char *format,
+ ...) __attribute__((format (printf,4,5)));
+void xfpm_warn (const char *func,
+ const char *file,
+ int line,
+ const char *format,
+ ...) __attribute__((format (printf,4,5)));
#else
@@ -70,7 +68,7 @@ void xfpm_warn (const char *func,
#endif
-void xfpm_debug_init (gboolean debug);
+void xfpm_debug_init (gboolean debug);
G_END_DECLS
diff --git a/common/xfpm-enum-glib.h b/common/xfpm-enum-glib.h
index c7cfe3f..d9c8383 100644
--- a/common/xfpm-enum-glib.h
+++ b/common/xfpm-enum-glib.h
@@ -32,64 +32,58 @@ G_BEGIN_DECLS
*/
typedef enum
{
- XFPM_BATTERY_CHARGE_UNKNOWN,
- XFPM_BATTERY_CHARGE_CRITICAL,
- XFPM_BATTERY_CHARGE_LOW,
- XFPM_BATTERY_CHARGE_OK
-
+ XFPM_BATTERY_CHARGE_UNKNOWN,
+ XFPM_BATTERY_CHARGE_CRITICAL,
+ XFPM_BATTERY_CHARGE_LOW,
+ XFPM_BATTERY_CHARGE_OK
} XfpmBatteryCharge;
typedef enum
{
- XFPM_DO_NOTHING,
- XFPM_DO_SUSPEND,
- XFPM_DO_HIBERNATE,
- XFPM_ASK,
- XFPM_DO_SHUTDOWN
-
+ XFPM_DO_NOTHING,
+ XFPM_DO_SUSPEND,
+ XFPM_DO_HIBERNATE,
+ XFPM_ASK,
+ XFPM_DO_SHUTDOWN
} XfpmShutdownRequest;
typedef enum
{
- LID_TRIGGER_NOTHING,
- LID_TRIGGER_SUSPEND,
- LID_TRIGGER_HIBERNATE,
- LID_TRIGGER_LOCK_SCREEN,
-
+ LID_TRIGGER_NOTHING,
+ LID_TRIGGER_SUSPEND,
+ LID_TRIGGER_HIBERNATE,
+ LID_TRIGGER_LOCK_SCREEN,
} XfpmLidTriggerAction;
typedef enum
{
- BUTTON_UNKNOWN = 0,
- BUTTON_POWER_OFF,
- BUTTON_HIBERNATE,
- BUTTON_SLEEP,
- BUTTON_MON_BRIGHTNESS_UP,
- BUTTON_MON_BRIGHTNESS_DOWN,
- BUTTON_LID_CLOSED,
- BUTTON_BATTERY,
- BUTTON_KBD_BRIGHTNESS_UP,
- BUTTON_KBD_BRIGHTNESS_DOWN,
- NUMBER_OF_BUTTONS
-
+ BUTTON_UNKNOWN = 0,
+ BUTTON_POWER_OFF,
+ BUTTON_HIBERNATE,
+ BUTTON_SLEEP,
+ BUTTON_MON_BRIGHTNESS_UP,
+ BUTTON_MON_BRIGHTNESS_DOWN,
+ BUTTON_LID_CLOSED,
+ BUTTON_BATTERY,
+ BUTTON_KBD_BRIGHTNESS_UP,
+ BUTTON_KBD_BRIGHTNESS_DOWN,
+ NUMBER_OF_BUTTONS
} XfpmButtonKey;
typedef enum
- {
- SPIN_DOWN_HDD_NEVER,
- SPIN_DOWN_HDD_ON_BATTERY,
- SPIN_DOWN_HDD_PLUGGED_IN,
- SPIN_DOWN_HDD_ALWAYS
-
+{
+ SPIN_DOWN_HDD_NEVER,
+ SPIN_DOWN_HDD_ON_BATTERY,
+ SPIN_DOWN_HDD_PLUGGED_IN,
+ SPIN_DOWN_HDD_ALWAYS
} XfpmSpindownRequest;
typedef enum
{
- SHOW_ICON_ALWAYS,
- SHOW_ICON_WHEN_BATTERY_PRESENT,
- SHOW_ICON_WHEN_BATTERY_CHARGING_DISCHARGING,
- NEVER_SHOW_ICON
-
+ SHOW_ICON_ALWAYS,
+ SHOW_ICON_WHEN_BATTERY_PRESENT,
+ SHOW_ICON_WHEN_BATTERY_CHARGING_DISCHARGING,
+ NEVER_SHOW_ICON
} XfpmShowIcon;
G_END_DECLS
diff --git a/common/xfpm-enum.h b/common/xfpm-enum.h
index ce5d5f7..0394473 100644
--- a/common/xfpm-enum.h
+++ b/common/xfpm-enum.h
@@ -31,34 +31,31 @@ G_BEGIN_DECLS
typedef enum
{
- SYSTEM_LAPTOP,
- SYSTEM_DESKTOP,
- SYSTEM_SERVER,
- SYSTEM_UNKNOWN
-
+ SYSTEM_LAPTOP,
+ SYSTEM_DESKTOP,
+ SYSTEM_SERVER,
+ SYSTEM_UNKNOWN
} SystemFormFactor;
typedef enum
{
- LID_KEY = (1 << 0),
- BRIGHTNESS_KEY_UP = (1 << 1),
- BRIGHTNESS_KEY_DOWN = (1 << 2),
- SLEEP_KEY = (1 << 3),
- HIBERNATE_KEY = (1 << 4),
- POWER_KEY = (1 << 5),
- KBD_BRIGHTNESS_KEY_UP = (1 << 6),
- KBD_BRIGHTNESS_KEY_DOWN = (1 << 7),
- BATTERY_KEY = (1 << 8)
-
+ LID_KEY = (1 << 0),
+ BRIGHTNESS_KEY_UP = (1 << 1),
+ BRIGHTNESS_KEY_DOWN = (1 << 2),
+ SLEEP_KEY = (1 << 3),
+ HIBERNATE_KEY = (1 << 4),
+ POWER_KEY = (1 << 5),
+ KBD_BRIGHTNESS_KEY_UP = (1 << 6),
+ KBD_BRIGHTNESS_KEY_DOWN = (1 << 7),
+ BATTERY_KEY = (1 << 8)
} XfpmKeys;
typedef enum
{
- CPU_UNKNOWN = (1 << 0),
- CPU_POWERSAVE = (1 << 1),
- CPU_ONDEMAND = (1 << 2),
- CPU_PERFORMANCE = (1 << 3)
-
+ CPU_UNKNOWN = (1 << 0),
+ CPU_POWERSAVE = (1 << 1),
+ CPU_ONDEMAND = (1 << 2),
+ CPU_PERFORMANCE = (1 << 3)
} XfpmCpuGovernor;
G_END_DECLS
diff --git a/common/xfpm-power-common.c b/common/xfpm-power-common.c
index fd525dd..c34b98b 100644
--- a/common/xfpm-power-common.c
+++ b/common/xfpm-power-common.c
@@ -39,33 +39,33 @@
const gchar *
xfpm_power_translate_device_type (guint type)
{
- switch (type)
- {
- case UP_DEVICE_KIND_BATTERY:
- return _("Battery");
- case UP_DEVICE_KIND_UPS:
- return _("Uninterruptible Power Supply");
- case UP_DEVICE_KIND_LINE_POWER:
- return _("Line power");
- case UP_DEVICE_KIND_MOUSE:
- return _("Mouse");
- case UP_DEVICE_KIND_KEYBOARD:
- return _("Keyboard");
- case UP_DEVICE_KIND_MONITOR:
- return _("Monitor");
- case UP_DEVICE_KIND_PDA:
- return _("PDA");
- case UP_DEVICE_KIND_PHONE:
- return _("Phone");
- case UP_DEVICE_KIND_TABLET:
- return _("Tablet");
- case UP_DEVICE_KIND_COMPUTER:
- return _("Computer");
- case UP_DEVICE_KIND_UNKNOWN:
- return _("Unknown");
- }
-
- return _("Battery");
+ switch (type)
+ {
+ case UP_DEVICE_KIND_BATTERY:
+ return _("Battery");
+ case UP_DEVICE_KIND_UPS:
+ return _("Uninterruptible Power Supply");
+ case UP_DEVICE_KIND_LINE_POWER:
+ return _("Line power");
+ case UP_DEVICE_KIND_MOUSE:
+ return _("Mouse");
+ case UP_DEVICE_KIND_KEYBOARD:
+ return _("Keyboard");
+ case UP_DEVICE_KIND_MONITOR:
+ return _("Monitor");
+ case UP_DEVICE_KIND_PDA:
+ return _("PDA");
+ case UP_DEVICE_KIND_PHONE:
+ return _("Phone");
+ case UP_DEVICE_KIND_TABLET:
+ return _("Tablet");
+ case UP_DEVICE_KIND_COMPUTER:
+ return _("Computer");
+ case UP_DEVICE_KIND_UNKNOWN:
+ return _("Unknown");
+ }
+
+ return _("Battery");
}
/**
@@ -75,25 +75,25 @@ xfpm_power_translate_device_type (guint type)
const gchar *
xfpm_power_translate_technology (guint value)
{
- switch (value)
- {
- case 0:
- return _("Unknown");
- case 1:
- return _("Lithium ion");
- case 2:
- return _("Lithium polymer");
- case 3:
- return _("Lithium iron phosphate");
- case 4:
- return _("Lead acid");
- case 5:
- return _("Nickel cadmium");
- case 6:
- return _("Nickel metal hybride");
- }
-
- return _("Unknown");
+ switch (value)
+ {
+ case 0:
+ return _("Unknown");
+ case 1:
+ return _("Lithium ion");
+ case 2:
+ return _("Lithium polymer");
+ case 3:
+ return _("Lithium iron phosphate");
+ case 4:
+ return _("Lead acid");
+ case 5:
+ return _("Nickel cadmium");
+ case 6:
+ return _("Nickel metal hybride");
+ }
+
+ return _("Unknown");
}
/*
@@ -102,293 +102,293 @@ xfpm_power_translate_technology (guint value)
gchar *
xfpm_battery_get_time_string (guint seconds)
{
- char* timestring = NULL;
- gint hours;
- gint minutes;
+ char* timestring = NULL;
+ gint hours;
+ gint minutes;
- /* Add 0.5 to do rounding */
- minutes = (int) ( ( seconds / 60.0 ) + 0.5 );
+ /* Add 0.5 to do rounding */
+ minutes = (int) ( ( seconds / 60.0 ) + 0.5 );
- if (minutes == 0)
- {
- timestring = g_strdup (_("Unknown time"));
- return timestring;
- }
-
- if (minutes < 60)
- {
- timestring = g_strdup_printf (ngettext ("%i minute",
- "%i minutes",
- minutes), minutes);
- return timestring;
- }
-
- hours = minutes / 60;
- minutes = minutes % 60;
+ if (minutes == 0)
+ {
+ timestring = g_strdup (_("Unknown time"));
+ return timestring;
+ }
- if (minutes == 0)
- timestring = g_strdup_printf (ngettext (
- "%i hour",
- "%i hours",
- hours), hours);
- else
- /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes"
- * Swap order with "%2$s %2$i %1$s %1$i if needed */
- timestring = g_strdup_printf (_("%i %s %i %s"),
- hours, ngettext ("hour", "hours", hours),
- minutes, ngettext ("minute", "minutes", minutes));
+ if (minutes < 60)
+ {
+ timestring = g_strdup_printf (ngettext ("%i minute",
+ "%i minutes",
+ minutes), minutes);
return timestring;
+ }
+
+ hours = minutes / 60;
+ minutes = minutes % 60;
+
+ if (minutes == 0)
+ timestring = g_strdup_printf (ngettext (
+ "%i hour",
+ "%i hours",
+ hours), hours);
+ else
+ /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes"
+ * Swap order with "%2$s %2$i %1$s %1$i if needed */
+ timestring = g_strdup_printf (_("%i %s %i %s"),
+ hours, ngettext ("hour", "hours", hours),
+ minutes, ngettext ("minute", "minutes", minutes));
+ return timestring;
}
static gboolean
is_display_device (UpClient *upower, UpDevice *device)
{
- UpDevice *display_device = NULL;
- gboolean ret = FALSE;
+ UpDevice *display_device = NULL;
+ gboolean ret = FALSE;
#if UP_CHECK_VERSION(0, 99, 0)
- display_device = up_client_get_display_device (upower);
+ display_device = up_client_get_display_device (upower);
#else
- return FALSE;
+ return FALSE;
#endif
- ret = g_strcmp0(up_device_get_object_path(device), up_device_get_object_path(display_device)) == 0 ? TRUE : FALSE;
+ ret = g_strcmp0 (up_device_get_object_path(device), up_device_get_object_path(display_device)) == 0 ? TRUE : FALSE;
- g_object_unref (display_device);
+ g_object_unref (display_device);
- return ret;
+ return ret;
}
gchar*
get_device_icon_name (UpClient *upower, UpDevice *device)
{
- gchar *icon_name = NULL;
- gchar *icon_suffix;
- gsize icon_base_length;
- gchar *upower_icon;
- guint type = 0;
-
- /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
- g_object_get (device,
- "kind", &type,
- "icon-name", &upower_icon,
- NULL);
-
- /* Strip away the symbolic suffix for the device icons for the devices tab
- * and the panel plugin's menu */
- icon_suffix = g_strrstr (upower_icon, "-symbolic");
- if (icon_suffix != NULL)
- {
- icon_base_length = icon_suffix - upower_icon;
- }
- else
- {
- icon_base_length = G_MAXINT;
- }
-
- XFPM_DEBUG ("icon_suffix %s, icon_base_length %ld, upower_icon %s",
- icon_suffix, icon_base_length, upower_icon);
-
- /* mapped from
- * http://cgit.freedesktop.org/upower/tree/libupower-glib/up-types.h
- * because UPower doesn't return device-specific icon-names
- */
- if ( type == UP_DEVICE_KIND_UPS )
- icon_name = g_strdup (XFPM_UPS_ICON);
- else if ( type == UP_DEVICE_KIND_MOUSE )
- icon_name = g_strdup (XFPM_MOUSE_ICON);
- else if ( type == UP_DEVICE_KIND_KEYBOARD )
- icon_name = g_strdup (XFPM_KBD_ICON);
- else if ( type == UP_DEVICE_KIND_PHONE )
- icon_name = g_strdup (XFPM_PHONE_ICON);
- else if ( type == UP_DEVICE_KIND_PDA )
- icon_name = g_strdup (XFPM_PDA_ICON);
- else if ( type == UP_DEVICE_KIND_MEDIA_PLAYER )
- icon_name = g_strdup (XFPM_MEDIA_PLAYER_ICON);
- else if ( type == UP_DEVICE_KIND_LINE_POWER )
- icon_name = g_strdup (XFPM_AC_ADAPTER_ICON);
- else if ( type == UP_DEVICE_KIND_MONITOR )
- icon_name = g_strdup (XFPM_MONITOR_ICON);
- else if ( type == UP_DEVICE_KIND_TABLET )
- icon_name = g_strdup (XFPM_TABLET_ICON);
- else if ( type == UP_DEVICE_KIND_COMPUTER )
- icon_name = g_strdup (XFPM_COMPUTER_ICON);
- /* As UPower does not tell us whether a system is a desktop or a laptop we
- decide this based on whether there is a battery and/or a a lid */
- else if (!up_client_get_lid_is_present (upower) &&
- !up_client_get_on_battery (upower) &&
- g_strcmp0 (upower_icon, "battery-missing-symbolic") == 0)
- icon_name = g_strdup (XFPM_AC_ADAPTER_ICON);
- else if ( g_strcmp0 (upower_icon, "") != 0 )
- icon_name = g_strndup (upower_icon, icon_base_length);
-
- return icon_name;
+ gchar *icon_name = NULL;
+ gchar *icon_suffix;
+ gsize icon_base_length;
+ gchar *upower_icon;
+ guint type = 0;
+
+ /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
+ g_object_get (device,
+ "kind", &type,
+ "icon-name", &upower_icon,
+ NULL);
+
+ /* Strip away the symbolic suffix for the device icons for the devices tab
+ * and the panel plugin's menu */
+ icon_suffix = g_strrstr (upower_icon, "-symbolic");
+ if (icon_suffix != NULL)
+ {
+ icon_base_length = icon_suffix - upower_icon;
+ }
+ else
+ {
+ icon_base_length = G_MAXINT;
+ }
+
+ XFPM_DEBUG ("icon_suffix %s, icon_base_length %ld, upower_icon %s",
+ icon_suffix, icon_base_length, upower_icon);
+
+ /* mapped from
+ * http://cgit.freedesktop.org/upower/tree/libupower-glib/up-types.h
+ * because UPower doesn't return device-specific icon-names
+ */
+ if ( type == UP_DEVICE_KIND_UPS )
+ icon_name = g_strdup (XFPM_UPS_ICON);
+ else if ( type == UP_DEVICE_KIND_MOUSE )
+ icon_name = g_strdup (XFPM_MOUSE_ICON);
+ else if ( type == UP_DEVICE_KIND_KEYBOARD )
+ icon_name = g_strdup (XFPM_KBD_ICON);
+ else if ( type == UP_DEVICE_KIND_PHONE )
+ icon_name = g_strdup (XFPM_PHONE_ICON);
+ else if ( type == UP_DEVICE_KIND_PDA )
+ icon_name = g_strdup (XFPM_PDA_ICON);
+ else if ( type == UP_DEVICE_KIND_MEDIA_PLAYER )
+ icon_name = g_strdup (XFPM_MEDIA_PLAYER_ICON);
+ else if ( type == UP_DEVICE_KIND_LINE_POWER )
+ icon_name = g_strdup (XFPM_AC_ADAPTER_ICON);
+ else if ( type == UP_DEVICE_KIND_MONITOR )
+ icon_name = g_strdup (XFPM_MONITOR_ICON);
+ else if ( type == UP_DEVICE_KIND_TABLET )
+ icon_name = g_strdup (XFPM_TABLET_ICON);
+ else if ( type == UP_DEVICE_KIND_COMPUTER )
+ icon_name = g_strdup (XFPM_COMPUTER_ICON);
+ /* As UPower does not tell us whether a system is a desktop or a laptop we
+ decide this based on whether there is a battery and/or a a lid */
+ else if (!up_client_get_lid_is_present (upower) &&
+ !up_client_get_on_battery (upower) &&
+ g_strcmp0 (upower_icon, "battery-missing-symbolic") == 0)
+ icon_name = g_strdup (XFPM_AC_ADAPTER_ICON);
+ else if ( g_strcmp0 (upower_icon, "") != 0 )
+ icon_name = g_strndup (upower_icon, icon_base_length);
+
+ return icon_name;
}
gchar*
get_device_description (UpClient *upower, UpDevice *device)
{
- gchar *tip = NULL;
- gchar *est_time_str = NULL;
- guint type = 0, state = 0;
- gchar *model = NULL, *vendor = NULL;
- gboolean present, online;
- gdouble percentage;
- guint64 time_to_empty, time_to_full;
-
- /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
- g_object_get (device,
- "kind", &type,
- "vendor", &vendor,
- "model", &model,
- "state", &state,
- "is-present", &present,
- "percentage", &percentage,
- "time-to-empty", &time_to_empty,
- "time-to-full", &time_to_full,
- "online", &online,
- NULL);
-
- if (is_display_device (upower, device))
+ gchar *tip = NULL;
+ gchar *est_time_str = NULL;
+ guint type = 0, state = 0;
+ gchar *model = NULL, *vendor = NULL;
+ gboolean present, online;
+ gdouble percentage;
+ guint64 time_to_empty, time_to_full;
+
+ /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
+ g_object_get (device,
+ "kind", &type,
+ "vendor", &vendor,
+ "model", &model,
+ "state", &state,
+ "is-present", &present,
+ "percentage", &percentage,
+ "time-to-empty", &time_to_empty,
+ "time-to-full", &time_to_full,
+ "online", &online,
+ NULL);
+
+ if (is_display_device (upower, device))
+ {
+ g_free (vendor);
+ vendor = g_strdup (_("Computer"));
+
+ g_free (model);
+ model = g_strdup ("");
+ }
+
+ if (vendor == NULL)
+ vendor = g_strdup ("");
+ else
+ vendor = g_strstrip (vendor);
+ if (model == NULL)
+ model = g_strdup ("");
+ else
+ model = g_strstrip (model);
+
+ /* If we get a vendor or model we can use it, otherwise translate the
+ * device type into something readable (works for things like ac_power)
+ */
+ if (g_strcmp0(vendor, "") == 0 && g_strcmp0(model, "") == 0)
+ vendor = g_strdup_printf ("%s", xfpm_power_translate_device_type (type));
+
+ /* If the device is unknown to the kernel (maybe no-name stuff or
+ * whatever), then vendor and model will have a hex ID of 31
+ * characters each. We do not want to show them, they are neither
+ * useful nor human-readable, so translate and use the device
+ * type instead of the hex IDs (see bug #11217).
+ */
+ else if (strlen(vendor) == 31 && strlen(model) == 31)
+ {
+ g_free (vendor);
+ g_free (model);
+ vendor = g_strdup_printf ("%s", xfpm_power_translate_device_type (type));
+ model = g_strdup("");
+ }
+
+ if ( state == UP_DEVICE_STATE_FULLY_CHARGED )
+ {
+ if ( time_to_empty > 0 )
{
- g_free (vendor);
- vendor = g_strdup (_("Computer"));
-
- g_free (model);
- model = g_strdup ("");
+ est_time_str = xfpm_battery_get_time_string (time_to_empty);
+ tip = g_strdup_printf (_("<b>%s %s</b>\nFully charged (%0.0f%%, %s runtime)"),
+ vendor, model,
+ percentage,
+ est_time_str);
+ g_free (est_time_str);
}
-
- if (vendor == NULL)
- vendor = g_strdup ("");
- else
- vendor = g_strstrip (vendor);
- if (model == NULL)
- model = g_strdup ("");
else
- model = g_strstrip (model);
-
- /* If we get a vendor or model we can use it, otherwise translate the
- * device type into something readable (works for things like ac_power)
- */
- if (g_strcmp0(vendor, "") == 0 && g_strcmp0(model, "") == 0)
- vendor = g_strdup_printf ("%s", xfpm_power_translate_device_type (type));
-
- /* If the device is unknown to the kernel (maybe no-name stuff or
- * whatever), then vendor and model will have a hex ID of 31
- * characters each. We do not want to show them, they are neither
- * useful nor human-readable, so translate and use the device
- * type instead of the hex IDs (see bug #11217).
- */
- else if (strlen(vendor) == 31 && strlen(model) == 31)
{
- g_free (vendor);
- g_free (model);
- vendor = g_strdup_printf ("%s", xfpm_power_translate_device_type (type));
- model = g_strdup("");
+ tip = g_strdup_printf (_("<b>%s %s</b>\nFully charged (%0.0f%%)"),
+ vendor, model,
+ percentage);
}
-
- if ( state == UP_DEVICE_STATE_FULLY_CHARGED )
- {
- if ( time_to_empty > 0 )
- {
- est_time_str = xfpm_battery_get_time_string (time_to_empty);
- tip = g_strdup_printf (_("<b>%s %s</b>\nFully charged (%0.0f%%, %s runtime)"),
- vendor, model,
- percentage,
- est_time_str);
- g_free (est_time_str);
- }
- else
- {
- tip = g_strdup_printf (_("<b>%s %s</b>\nFully charged (%0.0f%%)"),
- vendor, model,
- percentage);
- }
- }
- else if ( state == UP_DEVICE_STATE_CHARGING )
+ }
+ else if ( state == UP_DEVICE_STATE_CHARGING )
+ {
+ if ( time_to_full != 0 )
{
- if ( time_to_full != 0 )
- {
- est_time_str = xfpm_battery_get_time_string (time_to_full);
- tip = g_strdup_printf (_("<b>%s %s</b>\nCharging (%0.0f%%, %s)"),
- vendor, model,
- percentage,
- est_time_str);
- g_free (est_time_str);
- }
- else
- {
- tip = g_strdup_printf (_("<b>%s %s</b>\nCharging (%0.0f%%)"),
- vendor, model,
- percentage);
- }
+ est_time_str = xfpm_battery_get_time_string (time_to_full);
+ tip = g_strdup_printf (_("<b>%s %s</b>\nCharging (%0.0f%%, %s)"),
+ vendor, model,
+ percentage,
+ est_time_str);
+ g_free (est_time_str);
}
- else if ( state == UP_DEVICE_STATE_DISCHARGING )
+ else
{
- if ( time_to_empty != 0 )
- {
- est_time_str = xfpm_battery_get_time_string (time_to_empty);
- tip = g_strdup_printf (_("<b>%s %s</b>\nDischarging (%0.0f%%, %s)"),
- vendor, model,
- percentage,
- est_time_str);
- g_free (est_time_str);
- }
- else
- {
- tip = g_strdup_printf (_("<b>%s %s</b>\nDischarging (%0.0f%%)"),
- vendor, model,
- percentage);
- }
+ tip = g_strdup_printf (_("<b>%s %s</b>\nCharging (%0.0f%%)"),
+ vendor, model,
+ percentage);
}
- else if ( state == UP_DEVICE_STATE_PENDING_CHARGE )
+ }
+ else if ( state == UP_DEVICE_STATE_DISCHARGING )
+ {
+ if ( time_to_empty != 0 )
{
- tip = g_strdup_printf (_("<b>%s %s</b>\nWaiting to discharge (%0.0f%%)"),
- vendor, model,
- percentage);
+ est_time_str = xfpm_battery_get_time_string (time_to_empty);
+ tip = g_strdup_printf (_("<b>%s %s</b>\nDischarging (%0.0f%%, %s)"),
+ vendor, model,
+ percentage,
+ est_time_str);
+ g_free (est_time_str);
}
- else if ( state == UP_DEVICE_STATE_PENDING_DISCHARGE )
+ else
{
- tip = g_strdup_printf (_("<b>%s %s</b>\nWaiting to charge (%0.0f%%)"),
- vendor, model,
- percentage);
+ tip = g_strdup_printf (_("<b>%s %s</b>\nDischarging (%0.0f%%)"),
+ vendor, model,
+ percentage);
}
- else if ( state == UP_DEVICE_STATE_EMPTY )
+ }
+ else if ( state == UP_DEVICE_STATE_PENDING_CHARGE )
+ {
+ tip = g_strdup_printf (_("<b>%s %s</b>\nWaiting to discharge (%0.0f%%)"),
+ vendor, model,
+ percentage);
+ }
+ else if ( state == UP_DEVICE_STATE_PENDING_DISCHARGE )
+ {
+ tip = g_strdup_printf (_("<b>%s %s</b>\nWaiting to charge (%0.0f%%)"),
+ vendor, model,
+ percentage);
+ }
+ else if ( state == UP_DEVICE_STATE_EMPTY )
+ {
+ tip = g_strdup_printf (_("<b>%s %s</b>\nis empty"),
+ vendor, model);
+ }
+ else if ( state == UP_DEVICE_STATE_UNKNOWN && percentage != 0.0 )
+ {
+ tip = g_strdup_printf (_("<b>%s %s</b>\nCurrent charge: %0.0f%%"),
+ vendor, model,
+ percentage);
+ }
+ else
+ {
+ if (type == UP_DEVICE_KIND_LINE_POWER)
{
- tip = g_strdup_printf (_("<b>%s %s</b>\nis empty"),
- vendor, model);
+ /* On the 2nd line we want to know if the power cord is plugged
+ * in or not */
+ tip = g_strdup_printf (_("<b>%s %s</b>\n%s"),
+ vendor, model, online ? _("Plugged in") : _("Not plugged in"));
}
- else if ( state == UP_DEVICE_STATE_UNKNOWN && percentage != 0.0 )
+ else if (is_display_device (upower, device))
{
- tip = g_strdup_printf (_("<b>%s %s</b>\nCurrent charge: %0.0f%%"),
- vendor, model,
- percentage);
+ /* Desktop pc with no battery, just display the vendor and model,
+ * which will probably just be Computer */
+ tip = g_strdup_printf (_("<b>%s %s</b>"), vendor, model);
}
else
{
- if (type == UP_DEVICE_KIND_LINE_POWER)
- {
- /* On the 2nd line we want to know if the power cord is plugged
- * in or not */
- tip = g_strdup_printf (_("<b>%s %s</b>\n%s"),
- vendor, model, online ? _("Plugged in") : _("Not plugged in"));
- }
- else if (is_display_device (upower, device))
- {
- /* Desktop pc with no battery, just display the vendor and model,
- * which will probably just be Computer */
- tip = g_strdup_printf (_("<b>%s %s</b>"), vendor, model);
- }
- else
- {
- /* unknown device state, just display the percentage */
- tip = g_strdup_printf (_("<b>%s %s</b>\nUnknown state"),
- vendor, model);
- }
+ /* unknown device state, just display the percentage */
+ tip = g_strdup_printf (_("<b>%s %s</b>\nUnknown state"),
+ vendor, model);
}
+ }
- g_free(model);
- g_free(vendor);
+ g_free(model);
+ g_free(vendor);
- return tip;
+ return tip;
}
diff --git a/common/xfpm-power-common.h b/common/xfpm-power-common.h
index 6272c5a..484fe68 100644
--- a/common/xfpm-power-common.h
+++ b/common/xfpm-power-common.h
@@ -43,14 +43,12 @@
#define POLKIT_AUTH_SUSPEND_CONSOLEKIT2 "org.freedesktop.consolekit.system.suspend"
#define POLKIT_AUTH_HIBERNATE_CONSOLEKIT2 "org.freedesktop.consolekit.system.hibernate"
-const gchar *xfpm_power_translate_device_type (guint type);
-
-const gchar *xfpm_power_translate_technology (guint value);
-
-gchar *xfpm_battery_get_time_string (guint seconds);
-
-gchar *get_device_icon_name (UpClient *upower, UpDevice *device);
-
-gchar *get_device_description (UpClient *upower, UpDevice *device);
+const gchar *xfpm_power_translate_device_type (guint type);
+const gchar *xfpm_power_translate_technology (guint value);
+gchar *xfpm_battery_get_time_string (guint seconds);
+gchar *get_device_icon_name (UpClient *upower,
+ UpDevice *device);
+gchar *get_device_description (UpClient *upower,
+ UpDevice *device);
#endif /* XFPM_UPOWER_COMMON */
diff --git a/libdbus/xfpm-dbus-monitor.c b/libdbus/xfpm-dbus-monitor.c
index 06d77d2..8626a96 100644
--- a/libdbus/xfpm-dbus-monitor.c
+++ b/libdbus/xfpm-dbus-monitor.c
@@ -41,29 +41,28 @@ static void xfpm_dbus_monitor_finalize (GObject *object);
struct XfpmDBusMonitorPrivate
{
- GDBusConnection *system_bus;
- GDBusConnection *session_bus;
-
- guint system_signal;
- guint session_signal;
-
- GPtrArray *names_array;
- GPtrArray *services_array;
+ GDBusConnection *system_bus;
+ GDBusConnection *session_bus;
+
+ guint system_signal;
+ guint session_signal;
+
+ GPtrArray *names_array;
+ GPtrArray *services_array;
};
typedef struct
{
- gchar *name;
- GBusType bus_type;
-
+ gchar *name;
+ GBusType bus_type;
} XfpmWatchData;
enum
{
- UNIQUE_NAME_LOST,
- SERVICE_CONNECTION_CHANGED,
- SYSTEM_BUS_CONNECTION_CHANGED,
- LAST_SIGNAL
+ UNIQUE_NAME_LOST,
+ SERVICE_CONNECTION_CHANGED,
+ SYSTEM_BUS_CONNECTION_CHANGED,
+ LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0 };
@@ -73,87 +72,87 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmDBusMonitor, xfpm_dbus_monitor, G_TYPE_OBJECT)
static void
xfpm_dbus_monitor_free_watch_data (XfpmWatchData *data)
{
- g_free (data->name);
- g_free (data);
+ g_free (data->name);
+ g_free (data);
}
static XfpmWatchData *
xfpm_dbus_monitor_get_watch_data (GPtrArray *array, const gchar *name, GBusType bus_type)
{
- XfpmWatchData *data;
- guint i;
-
- for ( i = 0; i < array->len; i++)
- {
- data = g_ptr_array_index (array, i);
- if ( !g_strcmp0 (data->name, name) && data->bus_type == bus_type )
- return data;
- }
- return NULL;
+ XfpmWatchData *data;
+ guint i;
+
+ for ( i = 0; i < array->len; i++)
+ {
+ data = g_ptr_array_index (array, i);
+ if ( !g_strcmp0 (data->name, name) && data->bus_type == bus_type )
+ return data;
+ }
+ return NULL;
}
static void
xfpm_dbus_monitor_unique_connection_name_lost (XfpmDBusMonitor *monitor, GBusType bus_type, const gchar *name)
{
- XfpmWatchData *watch;
- guint i = 0;
-
- for ( i = 0; i < monitor->priv->names_array->len; i++ )
+ XfpmWatchData *watch;
+ guint i = 0;
+
+ for ( i = 0; i < monitor->priv->names_array->len; i++ )
+ {
+ watch = g_ptr_array_index (monitor->priv->names_array, i);
+
+ if ( !g_strcmp0 (watch->name, name) && bus_type == watch->bus_type )
{
- watch = g_ptr_array_index (monitor->priv->names_array, i);
-
- if ( !g_strcmp0 (watch->name, name) && bus_type == watch->bus_type )
- {
- g_signal_emit (G_OBJECT(monitor), signals [UNIQUE_NAME_LOST], 0,
- watch->name, bus_type == G_BUS_TYPE_SESSION ? TRUE : FALSE);
- g_ptr_array_remove (monitor->priv->names_array, watch);
- xfpm_dbus_monitor_free_watch_data (watch);
- }
+ g_signal_emit (G_OBJECT(monitor), signals [UNIQUE_NAME_LOST], 0,
+ watch->name, bus_type == G_BUS_TYPE_SESSION ? TRUE : FALSE);
+ g_ptr_array_remove (monitor->priv->names_array, watch);
+ xfpm_dbus_monitor_free_watch_data (watch);
}
+ }
}
static void
-xfpm_dbus_monitor_service_connection_changed (XfpmDBusMonitor *monitor, GBusType bus_type,
- const gchar *name, gboolean connected)
+xfpm_dbus_monitor_service_connection_changed (XfpmDBusMonitor *monitor, GBusType bus_type,
+ const gchar *name, gboolean connected)
{
- XfpmWatchData *watch;
- guint i;
-
- for ( i = 0; i < monitor->priv->services_array->len; i++)
+ XfpmWatchData *watch;
+ guint i;
+
+ for ( i = 0; i < monitor->priv->services_array->len; i++)
+ {
+ watch = g_ptr_array_index (monitor->priv->services_array, i);
+
+ if ( !g_strcmp0 (watch->name, name) && watch->bus_type == bus_type)
{
- watch = g_ptr_array_index (monitor->priv->services_array, i);
-
- if ( !g_strcmp0 (watch->name, name) && watch->bus_type == bus_type)
- {
- g_signal_emit (G_OBJECT (monitor), signals [SERVICE_CONNECTION_CHANGED], 0,
- name, connected, bus_type == G_BUS_TYPE_SESSION ? TRUE : FALSE);
- }
+ g_signal_emit (G_OBJECT (monitor), signals [SERVICE_CONNECTION_CHANGED], 0,
+ name, connected, bus_type == G_BUS_TYPE_SESSION ? TRUE : FALSE);
}
+ }
}
static void
xfpm_dbus_monitor_name_owner_changed (XfpmDBusMonitor *monitor, const gchar *name,
- const gchar *prev, const gchar *new, GBusType bus_type)
+ const gchar *prev, const gchar *new, GBusType bus_type)
{
- if ( strlen (prev) != 0 )
- {
- xfpm_dbus_monitor_unique_connection_name_lost (monitor, bus_type, prev);
-
- /* Connection has name */
- if ( strlen (name) != 0 )
- xfpm_dbus_monitor_service_connection_changed (monitor, bus_type, name, FALSE);
- }
- else if ( strlen (name) != 0 && strlen (new) != 0)
- {
- xfpm_dbus_monitor_service_connection_changed (monitor, bus_type, name, TRUE);
- }
+ if ( strlen (prev) != 0 )
+ {
+ xfpm_dbus_monitor_unique_connection_name_lost (monitor, bus_type, prev);
+
+ /* Connection has name */
+ if ( strlen (name) != 0 )
+ xfpm_dbus_monitor_service_connection_changed (monitor, bus_type, name, FALSE);
+ }
+ else if ( strlen (name) != 0 && strlen (new) != 0)
+ {
+ xfpm_dbus_monitor_service_connection_changed (monitor, bus_type, name, TRUE);
+ }
}
static void
xfpm_dbus_monitor_session_name_owner_changed_cb (GDBusConnection *connection, const gchar *sender,
- const gchar *object_path, const gchar *interface_name,
- const gchar *signal_name, GVariant *parameters,
- gpointer monitor)
+ const gchar *object_path, const gchar *interface_name,
+ const gchar *signal_name, GVariant *parameters,
+ gpointer monitor)
{
const gchar *name, *prev, *new;
@@ -168,9 +167,9 @@ xfpm_dbus_monitor_session_name_owner_changed_cb (GDBusConnection *connection, co
static void
xfpm_dbus_monitor_system_name_owner_changed_cb (GDBusConnection *connection, const gchar *sender,
- const gchar *object_path, const gchar *interface_name,
- const gchar *signal_name, GVariant *parameters,
- gpointer monitor)
+ const gchar *object_path, const gchar *interface_name,
+ const gchar *signal_name, GVariant *parameters,
+ gpointer monitor)
{
const gchar *name, *prev, *new;
@@ -188,14 +187,14 @@ xfpm_dbus_monitor_session (XfpmDBusMonitor *monitor)
{
monitor->priv->session_signal =
g_dbus_connection_signal_subscribe (monitor->priv->session_bus,
- "org.freedesktop.DBus",
- "org.freedesktop.DBus",
+ "org.freedesktop.DBus",
+ "org.freedesktop.DBus",
"NameOwnerChanged",
- "/org/freedesktop/DBus",
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- xfpm_dbus_monitor_session_name_owner_changed_cb,
- monitor, NULL);
+ "/org/freedesktop/DBus",
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ xfpm_dbus_monitor_session_name_owner_changed_cb,
+ monitor, NULL);
}
static void
@@ -203,172 +202,172 @@ xfpm_dbus_monitor_system (XfpmDBusMonitor *monitor)
{
monitor->priv->system_signal =
g_dbus_connection_signal_subscribe (monitor->priv->system_bus,
- "org.freedesktop.DBus",
- "org.freedesktop.DBus",
+ "org.freedesktop.DBus",
+ "org.freedesktop.DBus",
"NameOwnerChanged",
- "/org/freedesktop/DBus",
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- xfpm_dbus_monitor_system_name_owner_changed_cb,
- monitor, NULL);
+ "/org/freedesktop/DBus",
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ xfpm_dbus_monitor_system_name_owner_changed_cb,
+ monitor, NULL);
}
static void
xfpm_dbus_monitor_class_init (XfpmDBusMonitorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- signals [UNIQUE_NAME_LOST] =
- g_signal_new ("unique-name-lost",
- XFPM_TYPE_DBUS_MONITOR,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (XfpmDBusMonitorClass, unique_name_lost),
- NULL, NULL,
- _xfpm_dbus_marshal_VOID__STRING_BOOLEAN,
- G_TYPE_NONE, 2,
- G_TYPE_STRING, G_TYPE_BOOLEAN);
-
- signals [SERVICE_CONNECTION_CHANGED] =
- g_signal_new ("service-connection-changed",
- XFPM_TYPE_DBUS_MONITOR,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (XfpmDBusMonitorClass, service_connection_changed),
- NULL, NULL,
- _xfpm_dbus_marshal_VOID__STRING_BOOLEAN_BOOLEAN,
- G_TYPE_NONE, 3, G_TYPE_STRING,
- G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
-
- signals [SYSTEM_BUS_CONNECTION_CHANGED] =
- g_signal_new ("system-bus-connection-changed",
- XFPM_TYPE_DBUS_MONITOR,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (XfpmDBusMonitorClass, system_bus_connection_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- object_class->finalize = xfpm_dbus_monitor_finalize;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ signals [UNIQUE_NAME_LOST] =
+ g_signal_new ("unique-name-lost",
+ XFPM_TYPE_DBUS_MONITOR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (XfpmDBusMonitorClass, unique_name_lost),
+ NULL, NULL,
+ _xfpm_dbus_marshal_VOID__STRING_BOOLEAN,
+ G_TYPE_NONE, 2,
+ G_TYPE_STRING, G_TYPE_BOOLEAN);
+
+ signals [SERVICE_CONNECTION_CHANGED] =
+ g_signal_new ("service-connection-changed",
+ XFPM_TYPE_DBUS_MONITOR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (XfpmDBusMonitorClass, service_connection_changed),
+ NULL, NULL,
+ _xfpm_dbus_marshal_VOID__STRING_BOOLEAN_BOOLEAN,
+ G_TYPE_NONE, 3, G_TYPE_STRING,
+ G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
+
+ signals [SYSTEM_BUS_CONNECTION_CHANGED] =
+ g_signal_new ("system-bus-connection-changed",
+ XFPM_TYPE_DBUS_MONITOR,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (XfpmDBusMonitorClass, system_bus_connection_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ object_class->finalize = xfpm_dbus_monitor_finalize;
}
static void
xfpm_dbus_monitor_init (XfpmDBusMonitor *monitor)
{
- monitor->priv = xfpm_dbus_monitor_get_instance_private (monitor);
-
- monitor->priv->names_array = g_ptr_array_new ();
- monitor->priv->services_array = g_ptr_array_new ();
-
- monitor->priv->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
- monitor->priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
-
- xfpm_dbus_monitor_session (monitor);
- xfpm_dbus_monitor_system (monitor);
+ monitor->priv = xfpm_dbus_monitor_get_instance_private (monitor);
+
+ monitor->priv->names_array = g_ptr_array_new ();
+ monitor->priv->services_array = g_ptr_array_new ();
+
+ monitor->priv->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ monitor->priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
+
+ xfpm_dbus_monitor_session (monitor);
+ xfpm_dbus_monitor_system (monitor);
}
static void
xfpm_dbus_monitor_finalize (GObject *object)
{
- XfpmDBusMonitor *monitor;
+ XfpmDBusMonitor *monitor;
- monitor = XFPM_DBUS_MONITOR (object);
-
- g_dbus_connection_signal_unsubscribe (monitor->priv->session_bus, monitor->priv->session_signal);
+ monitor = XFPM_DBUS_MONITOR (object);
- g_dbus_connection_signal_unsubscribe (monitor->priv->system_bus, monitor->priv->system_signal);
+ g_dbus_connection_signal_unsubscribe (monitor->priv->session_bus, monitor->priv->session_signal);
- g_object_unref (monitor->priv->system_bus);
- g_object_unref (monitor->priv->session_bus);
+ g_dbus_connection_signal_unsubscribe (monitor->priv->system_bus, monitor->priv->system_signal);
- g_ptr_array_foreach (monitor->priv->names_array, (GFunc) xfpm_dbus_monitor_free_watch_data, NULL);
- g_ptr_array_foreach (monitor->priv->services_array, (GFunc) xfpm_dbus_monitor_free_watch_data, NULL);
+ g_object_unref (monitor->priv->system_bus);
+ g_object_unref (monitor->priv->session_bus);
- g_ptr_array_free (monitor->priv->names_array, TRUE);
- g_ptr_array_free (monitor->priv->services_array, TRUE);
+ g_ptr_array_foreach (monitor->priv->names_array, (GFunc) xfpm_dbus_monitor_free_watch_data, NULL);
+ g_ptr_array_foreach (monitor->priv->services_array, (GFunc) xfpm_dbus_monitor_free_watch_data, NULL);
- G_OBJECT_CLASS (xfpm_dbus_monitor_parent_class)->finalize (object);
+ g_ptr_array_free (monitor->priv->names_array, TRUE);
+ g_ptr_array_free (monitor->priv->services_array, TRUE);
+
+ G_OBJECT_CLASS (xfpm_dbus_monitor_parent_class)->finalize (object);
}
XfpmDBusMonitor *
xfpm_dbus_monitor_new (void)
{
- static gpointer xfpm_dbus_monitor_object = NULL;
-
- if ( G_LIKELY (xfpm_dbus_monitor_object != NULL) )
- {
- g_object_ref (xfpm_dbus_monitor_object);
- }
- else
- {
- xfpm_dbus_monitor_object = g_object_new (XFPM_TYPE_DBUS_MONITOR, NULL);
- g_object_add_weak_pointer (xfpm_dbus_monitor_object, &xfpm_dbus_monitor_object);
- }
-
- return XFPM_DBUS_MONITOR (xfpm_dbus_monitor_object);
+ static gpointer xfpm_dbus_monitor_object = NULL;
+
+ if ( G_LIKELY (xfpm_dbus_monitor_object != NULL) )
+ {
+ g_object_ref (xfpm_dbus_monitor_object);
+ }
+ else
+ {
+ xfpm_dbus_monitor_object = g_object_new (XFPM_TYPE_DBUS_MONITOR, NULL);
+ g_object_add_weak_pointer (xfpm_dbus_monitor_object, &xfpm_dbus_monitor_object);
+ }
+
+ return XFPM_DBUS_MONITOR (xfpm_dbus_monitor_object);
}
gboolean xfpm_dbus_monitor_add_unique_name (XfpmDBusMonitor *monitor, GBusType bus_type, const gchar *unique_name)
{
- XfpmWatchData *watch;
-
- g_return_val_if_fail (XFPM_IS_DBUS_MONITOR (monitor), FALSE);
- g_return_val_if_fail (unique_name != NULL, FALSE);
-
- /* We have it already */
- if ( xfpm_dbus_monitor_get_watch_data (monitor->priv->names_array, unique_name, bus_type) )
- return FALSE;
-
- watch = g_new0 (XfpmWatchData , 1);
- watch->name = g_strdup (unique_name);
- watch->bus_type = bus_type;
-
- g_ptr_array_add (monitor->priv->names_array, watch);
- return TRUE;
+ XfpmWatchData *watch;
+
+ g_return_val_if_fail (XFPM_IS_DBUS_MONITOR (monitor), FALSE);
+ g_return_val_if_fail (unique_name != NULL, FALSE);
+
+ /* We have it already */
+ if ( xfpm_dbus_monitor_get_watch_data (monitor->priv->names_array, unique_name, bus_type) )
+ return FALSE;
+
+ watch = g_new0 (XfpmWatchData , 1);
+ watch->name = g_strdup (unique_name);
+ watch->bus_type = bus_type;
+
+ g_ptr_array_add (monitor->priv->names_array, watch);
+ return TRUE;
}
void xfpm_dbus_monitor_remove_unique_name (XfpmDBusMonitor *monitor, GBusType bus_type, const gchar *unique_name)
{
- XfpmWatchData *watch;
-
- g_return_if_fail (XFPM_IS_DBUS_MONITOR (monitor));
+ XfpmWatchData *watch;
- watch = xfpm_dbus_monitor_get_watch_data (monitor->priv->names_array, unique_name, bus_type);
-
- if ( watch )
- {
- g_ptr_array_remove (monitor->priv->names_array, watch);
- xfpm_dbus_monitor_free_watch_data (watch);
- }
+ g_return_if_fail (XFPM_IS_DBUS_MONITOR (monitor));
+
+ watch = xfpm_dbus_monitor_get_watch_data (monitor->priv->names_array, unique_name, bus_type);
+
+ if ( watch )
+ {
+ g_ptr_array_remove (monitor->priv->names_array, watch);
+ xfpm_dbus_monitor_free_watch_data (watch);
+ }
}
gboolean xfpm_dbus_monitor_add_service (XfpmDBusMonitor *monitor, GBusType bus_type, const gchar *service_name)
{
- XfpmWatchData *watch;
-
- g_return_val_if_fail (XFPM_IS_DBUS_MONITOR (monitor), FALSE);
-
- if ( xfpm_dbus_monitor_get_watch_data (monitor->priv->services_array, service_name, bus_type ) )
- return FALSE;
-
- watch = g_new0 (XfpmWatchData , 1);
- watch->name = g_strdup (service_name);
- watch->bus_type = bus_type;
-
- g_ptr_array_add (monitor->priv->services_array, watch);
-
- return TRUE;
+ XfpmWatchData *watch;
+
+ g_return_val_if_fail (XFPM_IS_DBUS_MONITOR (monitor), FALSE);
+
+ if ( xfpm_dbus_monitor_get_watch_data (monitor->priv->services_array, service_name, bus_type ) )
+ return FALSE;
+
+ watch = g_new0 (XfpmWatchData , 1);
+ watch->name = g_strdup (service_name);
+ watch->bus_type = bus_type;
+
+ g_ptr_array_add (monitor->priv->services_array, watch);
+
+ return TRUE;
}
void xfpm_dbus_monitor_remove_service (XfpmDBusMonitor *monitor, GBusType bus_type, const gchar *service_name)
{
- XfpmWatchData *watch;
-
- g_return_if_fail (XFPM_IS_DBUS_MONITOR (monitor));
-
- watch = xfpm_dbus_monitor_get_watch_data (monitor->priv->services_array, service_name, bus_type);
-
- if ( watch )
- {
- g_ptr_array_remove (monitor->priv->services_array, watch);
- xfpm_dbus_monitor_free_watch_data (watch);
- }
+ XfpmWatchData *watch;
+
+ g_return_if_fail (XFPM_IS_DBUS_MONITOR (monitor));
+
+ watch = xfpm_dbus_monitor_get_watch_data (monitor->priv->services_array, service_name, bus_type);
+
+ if ( watch )
+ {
+ g_ptr_array_remove (monitor->priv->services_array, watch);
+ xfpm_dbus_monitor_free_watch_data (watch);
+ }
}
diff --git a/libdbus/xfpm-dbus-monitor.h b/libdbus/xfpm-dbus-monitor.h
index 2ffedd8..6241dd0 100644
--- a/libdbus/xfpm-dbus-monitor.h
+++ b/libdbus/xfpm-dbus-monitor.h
@@ -1,4 +1,4 @@
-/* *
+/* *
* Copyright (C) 2009-2011 Ali <aliov at xfce.org>
*
* Licensed under the GNU General Public License Version 2
@@ -34,59 +34,50 @@ typedef struct XfpmDBusMonitorPrivate XfpmDBusMonitorPrivate;
typedef struct
{
- GObject parent;
- XfpmDBusMonitorPrivate *priv;
-
+ GObject parent;
+ XfpmDBusMonitorPrivate *priv;
+
} XfpmDBusMonitor;
typedef struct
{
- GObjectClass parent_class;
-
- /*
- * Unique name connection lost.
- */
- void (*unique_name_lost) (XfpmDBusMonitor *monitor,
- gchar *unique_name,
- gboolean on_session);
-
- /*
- * A Service connection changed.
- */
- void (*service_connection_changed) (XfpmDBusMonitor *monitor,
- gchar *service_name,
- gboolean connected,
- gboolean on_session);
-
- /*
- * DBus: system bus disconnected
- */
- void (*system_bus_connection_changed) (XfpmDBusMonitor *monitor,
- gboolean connected);
-
-} XfpmDBusMonitorClass;
-
-GType xfpm_dbus_monitor_get_type (void) G_GNUC_CONST;
-
-XfpmDBusMonitor *xfpm_dbus_monitor_new (void);
+ GObjectClass parent_class;
-void xfpm_dbus_monitor_watch_system_bus (XfpmDBusMonitor *monitor);
-
-gboolean xfpm_dbus_monitor_add_unique_name (XfpmDBusMonitor *monitor,
- GBusType bus_type,
- const gchar *unique_name);
-
-void xfpm_dbus_monitor_remove_unique_name (XfpmDBusMonitor *monitor,
- GBusType bus_type,
- const gchar *unique_name);
-
-gboolean xfpm_dbus_monitor_add_service (XfpmDBusMonitor *monitor,
- GBusType bus_type,
- const gchar *service_name);
+ /*
+ * Unique name connection lost.
+ */
+ void (*unique_name_lost) (XfpmDBusMonitor *monitor,
+ gchar *unique_name,
+ gboolean on_session);
+ /*
+ * A Service connection changed.
+ */
+ void (*service_connection_changed) (XfpmDBusMonitor *monitor,
+ gchar *service_name,
+ gboolean connected,
+ gboolean on_session);
+ /*
+ * DBus: system bus disconnected
+ */
+ void (*system_bus_connection_changed) (XfpmDBusMonitor *monitor,
+ gboolean connected);
+} XfpmDBusMonitorClass;
-void xfpm_dbus_monitor_remove_service (XfpmDBusMonitor *monitor,
- GBusType bus_type,
- const gchar *service_name);
+GType xfpm_dbus_monitor_get_type (void) G_GNUC_CONST;
+XfpmDBusMonitor *xfpm_dbus_monitor_new (void);
+void xfpm_dbus_monitor_watch_system_bus (XfpmDBusMonitor *monitor);
+gboolean xfpm_dbus_monitor_add_unique_name (XfpmDBusMonitor *monitor,
+ GBusType bus_type,
+ const gchar *unique_name);
+void xfpm_dbus_monitor_remove_unique_name (XfpmDBusMonitor *monitor,
+ GBusType bus_type,
+ const gchar *unique_name);
+gboolean xfpm_dbus_monitor_add_service (XfpmDBusMonitor *monitor,
+ GBusType bus_type,
+ const gchar *service_name);
+void xfpm_dbus_monitor_remove_service (XfpmDBusMonitor *monitor,
+ GBusType bus_type,
+ const gchar *service_name);
G_END_DECLS
#endif /* __XFPM_DBUS_MONITOR_H */
diff --git a/libdbus/xfpm-dbus.c b/libdbus/xfpm-dbus.c
index 6a41894..8038389 100644
--- a/libdbus/xfpm-dbus.c
+++ b/libdbus/xfpm-dbus.c
@@ -23,105 +23,105 @@
gboolean
xfpm_dbus_name_has_owner (GDBusConnection *connection, const gchar *name)
{
- GError *error = NULL;
- const gchar *owner = NULL;
- gboolean ret;
- GVariant *var;
+ GError *error = NULL;
+ const gchar *owner = NULL;
+ gboolean ret;
+ GVariant *var;
- var = g_dbus_connection_call_sync (connection,
- "org.freedesktop.DBus", /* name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface */
- "GetNameOwner",
- g_variant_new ("(s)", name),
- G_VARIANT_TYPE ("(s)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1, /* timeout */
- NULL,
- &error);
- if (var)
- {
- g_variant_get (var, "(&s)", &owner);
- g_variant_unref (var);
- }
- ret = (owner != NULL);
-
- if ( error )
- {
- g_warning("Failed to get name owner: %s\n",error->message);
- g_error_free(error);
- return FALSE;
- }
-
- return ret;
+ var = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.DBus", /* name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface */
+ "GetNameOwner",
+ g_variant_new ("(s)", name),
+ G_VARIANT_TYPE ("(s)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, /* timeout */
+ NULL,
+ &error);
+ if (var)
+ {
+ g_variant_get (var, "(&s)", &owner);
+ g_variant_unref (var);
+ }
+ ret = (owner != NULL);
+
+ if ( error )
+ {
+ g_warning("Failed to get name owner: %s\n",error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+
+ return ret;
}
gboolean xfpm_dbus_register_name(GDBusConnection *connection, const gchar *name)
{
- GError *error = NULL;
- guint32 ret = 0;
- GVariant *var;
-
- var = g_dbus_connection_call_sync (connection,
- "org.freedesktop.DBus", /* bus name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface name */
- "RequestName", /* method name */
- g_variant_new ("(su)",
- name,
- 0x4), /* DBUS_NAME_FLAG_DO_NOT_QUEUE */
- G_VARIANT_TYPE ("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
+ GError *error = NULL;
+ guint32 ret = 0;
+ GVariant *var;
- if (var)
- {
- g_variant_get (var, "(u)", &ret);
- g_variant_unref (var);
- }
+ var = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.DBus", /* bus name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface name */
+ "RequestName", /* method name */
+ g_variant_new ("(su)",
+ name,
+ 0x4), /* DBUS_NAME_FLAG_DO_NOT_QUEUE */
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
- if ( error )
- {
- g_warning("Error: %s\n",error->message);
- g_error_free(error);
- return FALSE;
- }
-
- if ( ret == 1 ) /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
- {
- return TRUE;
- }
-
+ if (var)
+ {
+ g_variant_get (var, "(u)", &ret);
+ g_variant_unref (var);
+ }
+
+ if ( error )
+ {
+ g_warning("Error: %s\n",error->message);
+ g_error_free(error);
return FALSE;
+ }
+
+ if ( ret == 1 ) /* DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER */
+ {
+ return TRUE;
+ }
+
+ return FALSE;
}
gboolean xfpm_dbus_release_name(GDBusConnection *connection, const gchar *name)
{
- GError *error = NULL;
- GVariant *var;
-
- var = g_dbus_connection_call_sync (connection,
- "org.freedesktop.DBus", /* bus name */
- "/org/freedesktop/DBus", /* object path */
- "org.freedesktop.DBus", /* interface name */
- "ReleaseName", /* method name */
- g_variant_new ("(s)", name),
- G_VARIANT_TYPE ("(u)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
- if (var)
- g_variant_unref (var);
-
- if ( error )
- {
- g_warning("Error: %s\n",error->message);
- g_error_free(error);
- return FALSE;
- }
-
- return TRUE;
+ GError *error = NULL;
+ GVariant *var;
+
+ var = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.DBus", /* bus name */
+ "/org/freedesktop/DBus", /* object path */
+ "org.freedesktop.DBus", /* interface name */
+ "ReleaseName", /* method name */
+ g_variant_new ("(s)", name),
+ G_VARIANT_TYPE ("(u)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (var)
+ g_variant_unref (var);
+
+ if ( error )
+ {
+ g_warning("Error: %s\n",error->message);
+ g_error_free(error);
+ return FALSE;
+ }
+
+ return TRUE;
}
diff --git a/libdbus/xfpm-dbus.h b/libdbus/xfpm-dbus.h
index 788eb8e..5944aa5 100644
--- a/libdbus/xfpm-dbus.h
+++ b/libdbus/xfpm-dbus.h
@@ -24,12 +24,10 @@
#include <glib.h>
#include <gio/gio.h>
-gboolean xfpm_dbus_name_has_owner (GDBusConnection *bus,
- const gchar *name);
-
-gboolean xfpm_dbus_register_name (GDBusConnection *bus,
- const gchar *name);
-
-gboolean xfpm_dbus_release_name (GDBusConnection *bus,
- const gchar *name);
+gboolean xfpm_dbus_name_has_owner (GDBusConnection *bus,
+ const gchar *name);
+gboolean xfpm_dbus_register_name (GDBusConnection *bus,
+ const gchar *name);
+gboolean xfpm_dbus_release_name (GDBusConnection *bus,
+ const gchar *name);
#endif /* __XFPM_DBUS_H */
diff --git a/panel-plugins/power-manager-plugin/power-manager-button.c b/panel-plugins/power-manager-plugin/power-manager-button.c
index 83017cc..c71ce21 100644
--- a/panel-plugins/power-manager-plugin/power-manager-button.c
+++ b/panel-plugins/power-manager-plugin/power-manager-button.c
@@ -56,232 +56,240 @@
struct PowerManagerButtonPrivate
{
#ifdef XFCE_PLUGIN
- XfcePanelPlugin *plugin;
- GDBusProxy *inhibit_proxy;
+ XfcePanelPlugin *plugin;
+ GDBusProxy *inhibit_proxy;
#else
- XfpmInhibit *inhibit;
+ XfpmInhibit *inhibit;
#endif
- XfconfChannel *channel;
-
- UpClient *upower;
-
- /* A list of BatteryDevices */
- GList *devices;
-
- /* The left-click popup menu, if one is being displayed */
- GtkWidget *menu;
-
- /* The actual panel icon image */
- GtkWidget *panel_icon_image;
- GtkWidget *panel_presentation_mode;
- GtkWidget *panel_label;
- GtkWidget *hbox;
- /* Keep track of icon name to redisplay during size changes */
- gchar *panel_icon_name;
- /* Keep track of the last icon size for use during updates */
- gint panel_icon_width;
- /* Keep track of the tooltip */
- gchar *tooltip;
-
- /* Upower 0.99 has a display device that can be used for the
- * panel image and tooltip description */
- UpDevice *display_device;
-
- XfpmBrightness *brightness;
-
- /* display brightness slider widget */
- GtkWidget *range;
- /* Some laptops (and mostly newer ones with intel graphics) can turn off the
- * backlight completely. If the user is not careful and sets the brightness
- * very low using the slider, he might not be able to see the screen contents
- * anymore. Brightness keys do not work on every laptop, so it's better to use
- * a safe default minimum level that the user can change via the settings
- * editor if desired.
- */
- gint32 brightness_min_level;
-
- gint show_panel_label;
- gboolean presentation_mode;
- gboolean show_presentation_indicator;
-
- /* filter range value changed events for snappier UI feedback */
- guint set_level_timeout;
+ XfconfChannel *channel;
+
+ UpClient *upower;
+
+ /* A list of BatteryDevices */
+ GList *devices;
+
+ /* The left-click popup menu, if one is being displayed */
+ GtkWidget *menu;
+
+ /* The actual panel icon image */
+ GtkWidget *panel_icon_image;
+ GtkWidget *panel_presentation_mode;
+ GtkWidget *panel_label;
+ GtkWidget *hbox;
+ /* Keep track of icon name to redisplay during size changes */
+ gchar *panel_icon_name;
+ /* Keep track of the last icon size for use during updates */
+ gint panel_icon_width;
+ /* Keep track of the tooltip */
+ gchar *tooltip;
+
+ /* Upower 0.99 has a display device that can be used for the
+ * panel image and tooltip description */
+ UpDevice *display_device;
+
+ XfpmBrightness *brightness;
+
+ /* display brightness slider widget */
+ GtkWidget *range;
+ /* Some laptops (and mostly newer ones with intel graphics) can turn off the
+ * backlight completely. If the user is not careful and sets the brightness
+ * very low using the slider, he might not be able to see the screen contents
+ * anymore. Brightness keys do not work on every laptop, so it's better to use
+ * a safe default minimum level that the user can change via the settings
+ * editor if desired.
+ */
+ gint32 brightness_min_level;
+
+ gint show_panel_label;
+ gboolean presentation_mode;
+ gboolean show_presentation_indicator;
+
+ /* filter range value changed events for snappier UI feedback */
+ guint set_level_timeout;
};
typedef struct
{
- GdkPixbuf *pix; /* Icon */
- GtkWidget *img; /* Icon image in the menu */
- gchar *details; /* Description of the device + state */
- gchar *object_path; /* UpDevice object path */
- UpDevice *device; /* Pointer to the UpDevice */
- gulong changed_signal_id; /* device changed callback id */
- gulong expose_signal_id; /* expose-event callback id */
- GtkWidget *menu_item; /* The device's item on the menu (if shown) */
+ GdkPixbuf *pix; /* Icon */
+ GtkWidget *img; /* Icon image in the menu */
+ gchar *details; /* Description of the device + state */
+ gchar *object_path; /* UpDevice object path */
+ UpDevice *device; /* Pointer to the UpDevice */
+ gulong changed_signal_id; /* device changed callback id */
+ gulong expose_signal_id; /* expose-event callback id */
+ GtkWidget *menu_item; /* The device's item on the menu (if shown) */
} BatteryDevice;
typedef enum
{
- PROP_0 = 0,
- PROP_BRIGHTNESS_MIN_LEVEL,
- PROP_SHOW_PANEL_LABEL,
- PROP_PRESENTATION_MODE,
- PROP_SHOW_PRESENTATION_INDICATOR,
+ PROP_0 = 0,
+ PROP_BRIGHTNESS_MIN_LEVEL,
+ PROP_SHOW_PANEL_LABEL,
+ PROP_PRESENTATION_MODE,
+ PROP_SHOW_PRESENTATION_INDICATOR,
} POWER_MANAGER_BUTTON_PROPERTIES;
enum {
- SIG_ICON_NAME_CHANGED = 0,
- SIG_TOOLTIP_CHANGED,
- SIG_N_SIGNALS,
+ SIG_ICON_NAME_CHANGED = 0,
+ SIG_TOOLTIP_CHANGED,
+ SIG_N_SIGNALS,
};
static guint __signals[SIG_N_SIGNALS] = { 0, };
G_DEFINE_TYPE_WITH_PRIVATE (PowerManagerButton, power_manager_button, GTK_TYPE_TOGGLE_BUTTON)
-static void power_manager_button_finalize (GObject *object);
-static GList* find_device_in_list (PowerManagerButton *button, const gchar *object_path);
-static gboolean power_manager_button_device_icon_draw (GtkWidget *img, cairo_t *cr, gpointer userdata);
-static void power_manager_button_set_icon (PowerManagerButton *button);
-static void power_manager_button_set_label (PowerManagerButton *button, gdouble percentage, guint64 time_to_empty_or_full);
-static void power_manager_button_update_presentation_indicator (PowerManagerButton *button);
-static void power_manager_button_update_label (PowerManagerButton *button, UpDevice *device);
-static gboolean power_manager_button_press_event (GtkWidget *widget, GdkEventButton *event);
-static gboolean power_manager_button_menu_add_device (PowerManagerButton *button, BatteryDevice *battery_device, gboolean append);
-static void increase_brightness (PowerManagerButton *button);
-static void decrease_brightness (PowerManagerButton *button);
-static void battery_device_remove_pix (BatteryDevice *battery_device);
+static void power_manager_button_finalize (GObject *object);
+static GList* find_device_in_list (PowerManagerButton *button,
+ const gchar *object_path);
+static gboolean power_manager_button_device_icon_draw (GtkWidget *img,
+ cairo_t *cr,
+ gpointer userdata);
+static void power_manager_button_set_icon (PowerManagerButton *button);
+static void power_manager_button_set_label (PowerManagerButton *button,
+ gdouble percentage,
+ guint64 time_to_empty_or_full);
+static void power_manager_button_update_presentation_indicator (PowerManagerButton *button);
+static void power_manager_button_update_label (PowerManagerButton *button,
+ UpDevice *device);
+static gboolean power_manager_button_press_event (GtkWidget *widget,
+ GdkEventButton *event);
+static gboolean power_manager_button_menu_add_device (PowerManagerButton *button,
+ BatteryDevice *battery_device,
+ gboolean append);
+static void increase_brightness (PowerManagerButton *button);
+static void decrease_brightness (PowerManagerButton *button);
+static void battery_device_remove_pix (BatteryDevice *battery_device);
static BatteryDevice*
get_display_device (PowerManagerButton *button)
{
- GList *item = NULL;
- gdouble highest_percentage = 0;
- BatteryDevice *display_device = NULL;
+ GList *item = NULL;
+ gdouble highest_percentage = 0;
+ BatteryDevice *display_device = NULL;
- TRACE("entering");
+ TRACE("entering");
- g_return_val_if_fail (POWER_MANAGER_IS_BUTTON(button), NULL);
+ g_return_val_if_fail (POWER_MANAGER_IS_BUTTON(button), NULL);
- if (button->priv->display_device)
+ if (button->priv->display_device)
+ {
+ item = find_device_in_list (button, up_device_get_object_path (button->priv->display_device));
+ if (item)
{
- item = find_device_in_list (button, up_device_get_object_path (button->priv->display_device));
- if (item)
- {
- return item->data;
- }
+ return item->data;
}
+ }
- /* We want to find the battery or ups device with the highest percentage
- * and use that to get our tooltip from */
- for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ /* We want to find the battery or ups device with the highest percentage
+ * and use that to get our tooltip from */
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
+ guint type = 0;
+ gdouble percentage;
+
+ if (!battery_device->device || !UP_IS_DEVICE(battery_device->device))
+ {
+ continue;
+ }
+
+ g_object_get (battery_device->device,
+ "kind", &type,
+ "percentage", &percentage,
+ NULL);
+
+ if (type == UP_DEVICE_KIND_BATTERY || type == UP_DEVICE_KIND_UPS)
{
- BatteryDevice *battery_device = item->data;
- guint type = 0;
- gdouble percentage;
-
- if (!battery_device->device || !UP_IS_DEVICE(battery_device->device))
- {
- continue;
- }
-
- g_object_get (battery_device->device,
- "kind", &type,
- "percentage", &percentage,
- NULL);
-
- if (type == UP_DEVICE_KIND_BATTERY || type == UP_DEVICE_KIND_UPS)
- {
- if (highest_percentage < percentage)
- {
- display_device = battery_device;
- highest_percentage = percentage;
- }
- }
+ if (highest_percentage < percentage)
+ {
+ display_device = battery_device;
+ highest_percentage = percentage;
+ }
}
+ }
- return display_device;
+ return display_device;
}
static GList*
find_device_in_list (PowerManagerButton *button, const gchar *object_path)
{
- GList *item = NULL;
+ GList *item = NULL;
- TRACE("entering");
+ TRACE("entering");
- g_return_val_if_fail ( POWER_MANAGER_IS_BUTTON(button), NULL );
+ g_return_val_if_fail ( POWER_MANAGER_IS_BUTTON(button), NULL );
- for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
+ if (battery_device == NULL)
{
- BatteryDevice *battery_device = item->data;
- if (battery_device == NULL)
- {
- DBG("!battery_device");
- continue;
- }
-
- if (g_strcmp0 (battery_device->object_path, object_path) == 0)
- return item;
+ DBG("!battery_device");
+ continue;
}
- return NULL;
+ if (g_strcmp0 (battery_device->object_path, object_path) == 0)
+ return item;
+ }
+
+ return NULL;
}
static void
power_manager_button_set_icon (PowerManagerButton *button)
{
- g_return_if_fail (GTK_IS_WIDGET (button->priv->panel_presentation_mode));
+ g_return_if_fail (GTK_IS_WIDGET (button->priv->panel_presentation_mode));
- gtk_image_set_from_icon_name (GTK_IMAGE (button->priv->panel_icon_image), button->priv->panel_icon_name, GTK_ICON_SIZE_BUTTON);
- gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_icon_image), button->priv->panel_icon_width);
+ gtk_image_set_from_icon_name (GTK_IMAGE (button->priv->panel_icon_image), button->priv->panel_icon_name, GTK_ICON_SIZE_BUTTON);
+ gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_icon_image), button->priv->panel_icon_width);
- gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_presentation_mode), button->priv->panel_icon_width);
-
- /* Notify others the icon name changed */
- g_signal_emit (button, __signals[SIG_ICON_NAME_CHANGED], 0);
+ gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_presentation_mode), button->priv->panel_icon_width);
+ /* Notify others the icon name changed */
+ g_signal_emit (button, __signals[SIG_ICON_NAME_CHANGED], 0);
}
static void
power_manager_button_set_tooltip (PowerManagerButton *button)
{
- BatteryDevice *display_device = get_display_device (button);
-
- TRACE("entering");
-
- if (!GTK_IS_WIDGET (button))
+ BatteryDevice *display_device = get_display_device (button);
+
+ TRACE("entering");
+
+ if (!GTK_IS_WIDGET (button))
+ {
+ g_critical ("power_manager_button_set_tooltip: !GTK_IS_WIDGET (button)");
+ return;
+ }
+
+ if (button->priv->tooltip != NULL)
+ {
+ g_free (button->priv->tooltip);
+ button->priv->tooltip = NULL;
+ }
+
+ if (display_device)
+ {
+ /* if we have something, display it */
+ if( display_device->details )
{
- g_critical ("power_manager_button_set_tooltip: !GTK_IS_WIDGET (button)");
- return;
+ button->priv->tooltip = g_strdup(display_device->details);
+ gtk_widget_set_tooltip_markup (GTK_WIDGET (button), display_device->details);
+ /* Tooltip changed! */
+ g_signal_emit (button, __signals[SIG_TOOLTIP_CHANGED], 0);
+ return;
}
+ }
- if (button->priv->tooltip != NULL)
- {
- g_free (button->priv->tooltip);
- button->priv->tooltip = NULL;
- }
-
- if (display_device)
- {
- /* if we have something, display it */
- if( display_device->details )
- {
- button->priv->tooltip = g_strdup(display_device->details);
- gtk_widget_set_tooltip_markup (GTK_WIDGET (button), display_device->details);
- /* Tooltip changed! */
- g_signal_emit (button, __signals[SIG_TOOLTIP_CHANGED], 0);
- return;
- }
- }
-
- /* Odds are this is a desktop without any batteries attached */
- button->priv->tooltip = g_strdup (_("Display battery levels for attached devices"));
- gtk_widget_set_tooltip_text (GTK_WIDGET (button), button->priv->tooltip);
- /* Tooltip changed! */
- g_signal_emit (button, __signals[SIG_TOOLTIP_CHANGED], 0);
+ /* Odds are this is a desktop without any batteries attached */
+ button->priv->tooltip = g_strdup (_("Display battery levels for attached devices"));
+ gtk_widget_set_tooltip_text (GTK_WIDGET (button), button->priv->tooltip);
+ /* Tooltip changed! */
+ g_signal_emit (button, __signals[SIG_TOOLTIP_CHANGED], 0);
}
const gchar *
@@ -300,235 +308,237 @@ static void
power_manager_button_set_label (PowerManagerButton *button, gdouble percentage,
guint64 time_to_empty_or_full)
{
- gchar *label_string = NULL;
- gint hours;
- gint minutes;
- gchar *remaining_time = NULL;
-
- /* Create the short timestring in the format hh:mm */
- minutes = (int) ( ( time_to_empty_or_full / 60.0 ) + 0.5 );
- if (minutes < 60)
- {
- if (minutes < 10)
- remaining_time = g_strdup_printf ("0:0%d", minutes);
- else
- remaining_time = g_strdup_printf ("0:%d", minutes);
- }
+ gchar *label_string = NULL;
+ gint hours;
+ gint minutes;
+ gchar *remaining_time = NULL;
+
+ /* Create the short timestring in the format hh:mm */
+ minutes = (int) ( ( time_to_empty_or_full / 60.0 ) + 0.5 );
+ if (minutes < 60)
+ {
+ if (minutes < 10)
+ remaining_time = g_strdup_printf ("0:0%d", minutes);
else
- {
- hours = minutes / 60;
- minutes = minutes % 60;
- if (minutes < 10)
- remaining_time = g_strdup_printf ("%d:0%d", hours, minutes);
- else
- remaining_time = g_strdup_printf ("%d:%d", hours, minutes);
- }
+ remaining_time = g_strdup_printf ("0:%d", minutes);
+ }
+ else
+ {
+ hours = minutes / 60;
+ minutes = minutes % 60;
+ if (minutes < 10)
+ remaining_time = g_strdup_printf ("%d:0%d", hours, minutes);
+ else
+ remaining_time = g_strdup_printf ("%d:%d", hours, minutes);
+ }
- /* Set the label accordingly or hide it if the battery is full */
- if (button->priv->show_panel_label == 1)
- label_string = g_strdup_printf ("%d%%", (int) percentage);
- else if (button->priv->show_panel_label == 2)
- label_string = g_strdup_printf ("%s", remaining_time);
- else if (button->priv->show_panel_label == 3)
- label_string = g_strdup_printf ("(%s, %d%%)", remaining_time, (int) percentage);
+ /* Set the label accordingly or hide it if the battery is full */
+ if (button->priv->show_panel_label == 1)
+ label_string = g_strdup_printf ("%d%%", (int) percentage);
+ else if (button->priv->show_panel_label == 2)
+ label_string = g_strdup_printf ("%s", remaining_time);
+ else if (button->priv->show_panel_label == 3)
+ label_string = g_strdup_printf ("(%s, %d%%)", remaining_time, (int) percentage);
- gtk_label_set_text (GTK_LABEL (button->priv->panel_label), label_string);
+ gtk_label_set_text (GTK_LABEL (button->priv->panel_label), label_string);
- g_free (label_string);
- g_free (remaining_time);
+ g_free (label_string);
+ g_free (remaining_time);
}
static gboolean
power_manager_button_device_icon_draw (GtkWidget *img, cairo_t *cr, gpointer userdata)
{
- UpDevice *device = NULL;
- guint type = 0, state = 0;
- gdouble percentage;
- gint height, width;
- gdouble min_height = 2;
- PangoLayout *layout = NULL;
- PangoRectangle ink_extent, log_extent;
- GtkAllocation allocation;
-
- TRACE("entering");
-
- /* sanity checks */
- if (!img || !GTK_IS_WIDGET (img))
- return FALSE;
+ UpDevice *device = NULL;
+ guint type = 0, state = 0;
+ gdouble percentage;
+ gint height, width;
+ gdouble min_height = 2;
+ PangoLayout *layout = NULL;
+ PangoRectangle ink_extent, log_extent;
+ GtkAllocation allocation;
+
+ TRACE("entering");
+
+ /* sanity checks */
+ if (!img || !GTK_IS_WIDGET (img))
+ return FALSE;
- if (UP_IS_DEVICE (userdata))
- {
- device = UP_DEVICE(userdata);
+ if (UP_IS_DEVICE (userdata))
+ {
+ device = UP_DEVICE(userdata);
- g_object_get (device,
- "kind", &type,
- "state", &state,
- "percentage", &percentage,
- NULL);
+ g_object_get (device,
+ "kind", &type,
+ "state", &state,
+ "percentage", &percentage,
+ NULL);
- /* Don't draw the progressbar for Battery */
- if (type == UP_DEVICE_KIND_BATTERY)
- return FALSE;
- }
+ /* Don't draw the progressbar for Battery */
+ if (type == UP_DEVICE_KIND_BATTERY)
+ return FALSE;
+ }
+ else
+ {
+ /* If the UpDevice hasn't fully updated yet it then we'll want
+ * a question mark for sure. */
+ state = UP_DEVICE_STATE_UNKNOWN;
+ }
+
+ gtk_widget_get_allocation (img, &allocation);
+
+ width = allocation.width;
+ height = allocation.height;
+
+ if (state != UP_DEVICE_STATE_UNKNOWN)
+ {
+ /* Draw the trough of the progressbar */
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_line_width (cr, 1.0);
+ cairo_rectangle (cr, width - 3.5, allocation.y + 1.5, 5, height - 2);
+ cairo_set_source_rgb (cr, 0.87, 0.87, 0.87);
+ cairo_fill_preserve (cr);
+ cairo_set_source_rgb (cr, 0.53, 0.54, 0.52);
+ cairo_stroke (cr);
+
+ /* Draw the fill of the progressbar
+ Use yellow for 20% and below, green for 100%, red for 5% and below and blue for the rest */
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+
+ if ((height * (percentage / 100)) > min_height)
+ min_height = (height - 3) * (percentage / 100);
+
+ cairo_rectangle (cr, width - 3, allocation.y + height - min_height - 1, 4, min_height);
+ if (percentage > 5 && percentage < 20)
+ cairo_set_source_rgb (cr, 0.93, 0.83, 0.0);
+ else if (percentage > 20 && percentage < 100)
+ cairo_set_source_rgb (cr, 0.2, 0.4, 0.64);
+ else if (percentage == 100)
+ cairo_set_source_rgb (cr, 0.45, 0.82, 0.08);
else
- {
- /* If the UpDevice hasn't fully updated yet it then we'll want
- * a question mark for sure. */
- state = UP_DEVICE_STATE_UNKNOWN;
- }
-
- gtk_widget_get_allocation (img, &allocation);
-
- width = allocation.width;
- height = allocation.height;
-
- if (state != UP_DEVICE_STATE_UNKNOWN)
- {
- /* Draw the trough of the progressbar */
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_line_width (cr, 1.0);
- cairo_rectangle (cr, width - 3.5, allocation.y + 1.5, 5, height - 2);
- cairo_set_source_rgb (cr, 0.87, 0.87, 0.87);
- cairo_fill_preserve (cr);
- cairo_set_source_rgb (cr, 0.53, 0.54, 0.52);
- cairo_stroke (cr);
-
- /* Draw the fill of the progressbar
- Use yellow for 20% and below, green for 100%, red for 5% and below and blue for the rest */
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-
- if ((height * (percentage / 100)) > min_height)
- min_height = (height - 3) * (percentage / 100);
-
- cairo_rectangle (cr, width - 3, allocation.y + height - min_height - 1, 4, min_height);
- if (percentage > 5 && percentage < 20)
- cairo_set_source_rgb (cr, 0.93, 0.83, 0.0);
- else if (percentage > 20 && percentage < 100)
- cairo_set_source_rgb (cr, 0.2, 0.4, 0.64);
- else if (percentage == 100)
- cairo_set_source_rgb (cr, 0.45, 0.82, 0.08);
- else
- cairo_set_source_rgb (cr, 0.94, 0.16, 0.16);
- cairo_fill (cr);
-
- cairo_rectangle (cr, width - 2.5, allocation.y + 2.5, 3, height - 4);
- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.75);
- cairo_stroke (cr);
- }
- else
- {
- /* Draw a bubble with a question mark for devices with unknown state */
- cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_line_width (cr, 1.0);
- cairo_arc(cr, width - 4.5, allocation.y + 6.5, 6, 0, 2*3.14159);
- cairo_set_source_rgb (cr, 0.2, 0.54, 0.9);
- cairo_fill_preserve (cr);
- cairo_set_source_rgb (cr, 0.1, 0.37, 0.6);
- cairo_stroke (cr);
-
- layout = gtk_widget_create_pango_layout (GTK_WIDGET (img), "?");
- pango_layout_set_font_description (layout, pango_font_description_from_string ("Sans Bold 9"));
- pango_layout_get_pixel_extents (layout, &ink_extent, &log_extent);
- cairo_move_to (cr, (width - 5.5) - (log_extent.width / 2), (allocation.y + 5.5) - (log_extent.height / 2));
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- pango_cairo_show_layout (cr, layout);
- }
-
- if (layout)
- g_object_unref (layout);
- return FALSE;
+ cairo_set_source_rgb (cr, 0.94, 0.16, 0.16);
+ cairo_fill (cr);
+
+ cairo_rectangle (cr, width - 2.5, allocation.y + 2.5, 3, height - 4);
+ cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.75);
+ cairo_stroke (cr);
+ }
+ else
+ {
+ /* Draw a bubble with a question mark for devices with unknown state */
+ cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_line_width (cr, 1.0);
+ cairo_arc(cr, width - 4.5, allocation.y + 6.5, 6, 0, 2*3.14159);
+ cairo_set_source_rgb (cr, 0.2, 0.54, 0.9);
+ cairo_fill_preserve (cr);
+ cairo_set_source_rgb (cr, 0.1, 0.37, 0.6);
+ cairo_stroke (cr);
+
+ layout = gtk_widget_create_pango_layout (GTK_WIDGET (img), "?");
+ pango_layout_set_font_description (layout, pango_font_description_from_string ("Sans Bold 9"));
+ pango_layout_get_pixel_extents (layout, &ink_extent, &log_extent);
+ cairo_move_to (cr, (width - 5.5) - (log_extent.width / 2), (allocation.y + 5.5) - (log_extent.height / 2));
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ pango_cairo_show_layout (cr, layout);
+ }
+
+ if (layout)
+ g_object_unref (layout);
+
+ return FALSE;
}
static void
power_manager_button_update_device_icon_and_details (PowerManagerButton *button, UpDevice *device)
{
- GList *item;
- BatteryDevice *battery_device;
- BatteryDevice *display_device;
- const gchar *object_path = up_device_get_object_path(device);
- gchar *details;
- gchar *icon_name;
- GdkPixbuf *pix = NULL;
+ GList *item;
+ BatteryDevice *battery_device;
+ BatteryDevice *display_device;
+ const gchar *object_path = up_device_get_object_path(device);
+ gchar *details;
+ gchar *icon_name;
+ GdkPixbuf *pix = NULL;
- XFPM_DEBUG("entering for %s", object_path);
+ XFPM_DEBUG("entering for %s", object_path);
- if (!POWER_MANAGER_IS_BUTTON (button))
- return;
+ if (!POWER_MANAGER_IS_BUTTON (button))
+ return;
- item = find_device_in_list (button, object_path);
+ item = find_device_in_list (button, object_path);
- if (item == NULL)
- return;
+ if (item == NULL)
+ return;
- battery_device = item->data;
+ battery_device = item->data;
- icon_name = get_device_icon_name (button->priv->upower, device);
- details = get_device_description (button->priv->upower, device);
+ icon_name = get_device_icon_name (button->priv->upower, device);
+ details = get_device_description (button->priv->upower, device);
- /* If UPower doesn't give us an icon, just use the default */
- if (g_strcmp0(icon_name, "") == 0)
- {
- /* ignore empty icon names */
- g_free (icon_name);
- icon_name = NULL;
- }
+ /* If UPower doesn't give us an icon, just use the default */
+ if (g_strcmp0(icon_name, "") == 0)
+ {
+ /* ignore empty icon names */
+ g_free (icon_name);
+ icon_name = NULL;
+ }
- if (icon_name == NULL)
- icon_name = g_strdup (PANEL_DEFAULT_ICON);
+ if (icon_name == NULL)
+ icon_name = g_strdup (PANEL_DEFAULT_ICON);
- pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- icon_name,
- 32,
- GTK_ICON_LOOKUP_USE_BUILTIN,
- NULL);
+ pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ icon_name,
+ 32,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ NULL);
- if (battery_device->details)
- g_free (battery_device->details);
- battery_device->details = details;
+ if (battery_device->details)
+ g_free (battery_device->details);
- /* If we had an image before, remove it and the callback */
- battery_device_remove_pix(battery_device);
+ battery_device->details = details;
- battery_device->pix = pix;
+ /* If we had an image before, remove it and the callback */
+ battery_device_remove_pix(battery_device);
- /* Get the display device, which may now be this one */
- display_device = get_display_device (button);
- if (battery_device == display_device)
- {
- DBG("this is the display device, updating");
- /* update the icon */
- g_free (button->priv->panel_icon_name);
+ battery_device->pix = pix;
+
+ /* Get the display device, which may now be this one */
+ display_device = get_display_device (button);
+ if (battery_device == display_device)
+ {
+ DBG("this is the display device, updating");
+ /* update the icon */
+ g_free (button->priv->panel_icon_name);
#ifdef XFCE_PLUGIN
- button->priv->panel_icon_name = g_strdup_printf ("%s-%s", icon_name, "symbolic");
+ button->priv->panel_icon_name = g_strdup_printf ("%s-%s", icon_name, "symbolic");
#else
- button->priv->panel_icon_name = g_strdup (icon_name);
+ button->priv->panel_icon_name = g_strdup (icon_name);
#endif
- power_manager_button_set_icon (button);
- /* update the tooltip */
- power_manager_button_set_tooltip (button);
- /* update the label */
- power_manager_button_update_label (button, device);
- }
- g_free (icon_name);
-
- /* If the menu is being displayed, update it */
- if (button->priv->menu && battery_device->menu_item)
- {
- gtk_menu_item_set_label (GTK_MENU_ITEM (battery_device->menu_item), details);
-
- /* update the image, keep track of the signal ids and the img
- * so we can disconnect it later */
- battery_device->img = gtk_image_new_from_pixbuf (battery_device->pix);
+ power_manager_button_set_icon (button);
+ /* update the tooltip */
+ power_manager_button_set_tooltip (button);
+ /* update the label */
+ power_manager_button_update_label (button, device);
+ }
+ g_free (icon_name);
+
+ /* If the menu is being displayed, update it */
+ if (button->priv->menu && battery_device->menu_item)
+ {
+ gtk_menu_item_set_label (GTK_MENU_ITEM (battery_device->menu_item), details);
+
+ /* update the image, keep track of the signal ids and the img
+ * so we can disconnect it later */
+ battery_device->img = gtk_image_new_from_pixbuf (battery_device->pix);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(battery_device->menu_item), battery_device->img);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(battery_device->menu_item), battery_device->img);
G_GNUC_END_IGNORE_DEPRECATIONS
- battery_device->expose_signal_id = g_signal_connect_after (G_OBJECT (battery_device->img),
- "draw",
- G_CALLBACK (power_manager_button_device_icon_draw),
- device);
- }
+ battery_device->expose_signal_id = g_signal_connect_after (G_OBJECT (battery_device->img),
+ "draw",
+ G_CALLBACK (power_manager_button_device_icon_draw),
+ device);
+ }
}
static void
@@ -540,44 +550,44 @@ device_changed_cb (UpDevice *device, GParamSpec *pspec, PowerManagerButton *butt
static void
power_manager_button_add_device (UpDevice *device, PowerManagerButton *button)
{
- BatteryDevice *battery_device;
- guint type = 0;
- const gchar *object_path = up_device_get_object_path(device);
- gulong signal_id;
+ BatteryDevice *battery_device;
+ guint type = 0;
+ const gchar *object_path = up_device_get_object_path(device);
+ gulong signal_id;
- XFPM_DEBUG("entering for %s", object_path);
+ XFPM_DEBUG("entering for %s", object_path);
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button ));
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button ));
- /* don't add the same device twice */
- if (find_device_in_list (button, object_path))
- return;
+ /* don't add the same device twice */
+ if (find_device_in_list (button, object_path))
+ return;
- battery_device = g_new0 (BatteryDevice, 1);
+ battery_device = g_new0 (BatteryDevice, 1);
- /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
- g_object_get (device,
- "kind", &type,
- NULL);
+ /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
+ g_object_get (device,
+ "kind", &type,
+ NULL);
- signal_id = g_signal_connect (device, "notify", G_CALLBACK (device_changed_cb), button);
+ signal_id = g_signal_connect (device, "notify", G_CALLBACK (device_changed_cb), button);
- /* populate the struct */
- battery_device->object_path = g_strdup (object_path);
- battery_device->changed_signal_id = signal_id;
- battery_device->device = g_object_ref(device);
+ /* populate the struct */
+ battery_device->object_path = g_strdup (object_path);
+ battery_device->changed_signal_id = signal_id;
+ battery_device->device = g_object_ref(device);
- /* add it to the list */
- button->priv->devices = g_list_append (button->priv->devices, battery_device);
+ /* add it to the list */
+ button->priv->devices = g_list_append (button->priv->devices, battery_device);
- /* Add the icon and description for the device */
- power_manager_button_update_device_icon_and_details (button, device);
+ /* Add the icon and description for the device */
+ power_manager_button_update_device_icon_and_details (button, device);
- /* If the menu is being shown, add this new device to it */
- if (button->priv->menu)
- {
- power_manager_button_menu_add_device (button, battery_device, FALSE);
- }
+ /* If the menu is being shown, add this new device to it */
+ if (button->priv->menu)
+ {
+ power_manager_button_menu_add_device (button, battery_device, FALSE);
+ }
}
/* This function unrefs the pix and img from the battery device and
@@ -586,221 +596,221 @@ power_manager_button_add_device (UpDevice *device, PowerManagerButton *button)
static void
battery_device_remove_pix (BatteryDevice *battery_device)
{
- TRACE("entering");
+ TRACE("entering");
- if (battery_device == NULL)
- return;
+ if (battery_device == NULL)
+ return;
- if (G_IS_OBJECT (battery_device->pix))
+ if (G_IS_OBJECT (battery_device->pix))
+ {
+ if (GTK_IS_WIDGET (battery_device->img))
{
- if (GTK_IS_WIDGET (battery_device->img))
- {
- if (battery_device->expose_signal_id != 0)
- {
- g_signal_handler_disconnect (battery_device->img, battery_device->expose_signal_id);
- battery_device->expose_signal_id = 0;
- }
- g_object_unref (battery_device->img);
- battery_device->img = NULL;
- }
- g_object_unref (battery_device->pix);
- battery_device->pix = NULL;
+ if (battery_device->expose_signal_id != 0)
+ {
+ g_signal_handler_disconnect (battery_device->img, battery_device->expose_signal_id);
+ battery_device->expose_signal_id = 0;
+ }
+ g_object_unref (battery_device->img);
+ battery_device->img = NULL;
}
+ g_object_unref (battery_device->pix);
+ battery_device->pix = NULL;
+ }
}
static void
remove_battery_device (PowerManagerButton *button, BatteryDevice *battery_device)
{
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
- g_return_if_fail (battery_device != NULL);
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+ g_return_if_fail (battery_device != NULL);
- /* If it is being shown in the menu, remove it */
- if(battery_device->menu_item && button->priv->menu)
- gtk_container_remove (GTK_CONTAINER (button->priv->menu), battery_device->menu_item);
+ /* If it is being shown in the menu, remove it */
+ if (battery_device->menu_item && button->priv->menu)
+ gtk_container_remove (GTK_CONTAINER (button->priv->menu), battery_device->menu_item);
- g_free (battery_device->details);
- g_free (battery_device->object_path);
+ g_free (battery_device->details);
+ g_free (battery_device->object_path);
- battery_device_remove_pix (battery_device);
+ battery_device_remove_pix (battery_device);
- if (battery_device->device != NULL && UP_IS_DEVICE(battery_device->device))
- {
- /* disconnect the signal handler if we were using it */
- if (battery_device->changed_signal_id != 0)
- g_signal_handler_disconnect (battery_device->device, battery_device->changed_signal_id);
- battery_device->changed_signal_id = 0;
+ if (battery_device->device != NULL && UP_IS_DEVICE(battery_device->device))
+ {
+ /* disconnect the signal handler if we were using it */
+ if (battery_device->changed_signal_id != 0)
+ g_signal_handler_disconnect (battery_device->device, battery_device->changed_signal_id);
+ battery_device->changed_signal_id = 0;
- g_object_unref (battery_device->device);
- battery_device->device = NULL;
- }
+ g_object_unref (battery_device->device);
+ battery_device->device = NULL;
+ }
- g_free (battery_device);
+ g_free (battery_device);
}
static void
power_manager_button_remove_device (PowerManagerButton *button, const gchar *object_path)
{
- GList *item;
- BatteryDevice *battery_device;
+ GList *item;
+ BatteryDevice *battery_device;
- TRACE("entering for %s", object_path);
+ TRACE("entering for %s", object_path);
- item = find_device_in_list (button, object_path);
+ item = find_device_in_list (button, object_path);
- if (item == NULL)
- return;
+ if (item == NULL)
+ return;
- battery_device = item->data;
+ battery_device = item->data;
- /* Remove its resources */
- remove_battery_device (button, battery_device);
+ /* Remove its resources */
+ remove_battery_device (button, battery_device);
- /* remove it item and free the battery device */
- button->priv->devices = g_list_delete_link (button->priv->devices, item);
+ /* remove it item and free the battery device */
+ button->priv->devices = g_list_delete_link (button->priv->devices, item);
}
static void
device_added_cb (UpClient *upower, UpDevice *device, PowerManagerButton *button)
{
- power_manager_button_add_device (device, button);
+ power_manager_button_add_device (device, button);
}
static void
device_removed_cb (UpClient *upower, const gchar *object_path, PowerManagerButton *button)
{
- power_manager_button_remove_device (button, object_path);
+ power_manager_button_remove_device (button, object_path);
}
static void
power_manager_button_add_all_devices (PowerManagerButton *button)
{
- GPtrArray *array = NULL;
- guint i;
+ GPtrArray *array = NULL;
+ guint i;
- button->priv->display_device = up_client_get_display_device (button->priv->upower);
- power_manager_button_add_device (button->priv->display_device, button);
+ button->priv->display_device = up_client_get_display_device (button->priv->upower);
+ power_manager_button_add_device (button->priv->display_device, button);
#if UP_CHECK_VERSION(0, 99, 8)
- array = up_client_get_devices2 (button->priv->upower);
+ array = up_client_get_devices2 (button->priv->upower);
#else
- array = up_client_get_devices (button->priv->upower);
+ array = up_client_get_devices (button->priv->upower);
#endif
- if (array)
+ if (array)
+ {
+ for (i = 0; i < array->len; i++)
{
- for (i = 0; i < array->len; i++)
- {
- UpDevice *device = g_ptr_array_index (array, i);
+ UpDevice *device = g_ptr_array_index (array, i);
- power_manager_button_add_device (device, button);
- }
- g_ptr_array_free (array, TRUE);
+ power_manager_button_add_device (device, button);
}
+ g_ptr_array_free (array, TRUE);
+ }
}
static void
power_manager_button_remove_all_devices (PowerManagerButton *button)
{
- GList *item = NULL;
+ GList *item = NULL;
- TRACE("entering");
+ TRACE("entering");
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
- for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
+ if (battery_device == NULL)
{
- BatteryDevice *battery_device = item->data;
- if (battery_device == NULL)
- {
- DBG("!battery_device");
- continue;
- }
-
- /* Remove its resources */
- remove_battery_device (button, battery_device);
+ DBG("!battery_device");
+ continue;
}
+
+ /* Remove its resources */
+ remove_battery_device (button, battery_device);
+ }
}
static void
brightness_up (PowerManagerButton *button)
{
- gint32 level;
- gint32 max_level;
+ gint32 level;
+ gint32 max_level;
- xfpm_brightness_get_level (button->priv->brightness, &level);
- max_level = xfpm_brightness_get_max_level (button->priv->brightness);
+ xfpm_brightness_get_level (button->priv->brightness, &level);
+ max_level = xfpm_brightness_get_max_level (button->priv->brightness);
- if ( level < max_level )
- {
- increase_brightness (button);
- }
+ if ( level < max_level )
+ {
+ increase_brightness (button);
+ }
}
static void
brightness_down (PowerManagerButton *button)
{
- gint32 level;
- xfpm_brightness_get_level (button->priv->brightness, &level);
+ gint32 level;
+ xfpm_brightness_get_level (button->priv->brightness, &level);
- if ( level > button->priv->brightness_min_level )
- {
- decrease_brightness (button);
- }
+ if ( level > button->priv->brightness_min_level )
+ {
+ decrease_brightness (button);
+ }
}
static gboolean
power_manager_button_scroll_event (GtkWidget *widget, GdkEventScroll *ev)
{
- gboolean hw_found;
- PowerManagerButton *button;
-
- button = POWER_MANAGER_BUTTON (widget);
+ gboolean hw_found;
+ PowerManagerButton *button;
- hw_found = xfpm_brightness_has_hw (button->priv->brightness);
+ button = POWER_MANAGER_BUTTON (widget);
- if (!hw_found)
- return FALSE;
+ hw_found = xfpm_brightness_has_hw (button->priv->brightness);
- if (ev->direction == GDK_SCROLL_UP)
- {
- brightness_up (button);
- return TRUE;
- }
- else if (ev->direction == GDK_SCROLL_DOWN)
- {
- brightness_down (button);
- return TRUE;
- }
+ if (!hw_found)
return FALSE;
+
+ if (ev->direction == GDK_SCROLL_UP)
+ {
+ brightness_up (button);
+ return TRUE;
+ }
+ else if (ev->direction == GDK_SCROLL_DOWN)
+ {
+ brightness_down (button);
+ return TRUE;
+ }
+ return FALSE;
}
static void
set_brightness_min_level (PowerManagerButton *button, gint32 new_brightness_level)
{
- gint32 max_level = xfpm_brightness_get_max_level (button->priv->brightness);
-
- /* sanity check */
- if (new_brightness_level > max_level)
- new_brightness_level = -1;
-
- /* -1 = auto, we set the step value to a hopefully sane default */
- if (new_brightness_level == -1)
- {
- button->priv->brightness_min_level = (max_level > 100) ? SAFE_SLIDER_MIN_LEVEL : 0;
- }
- else
- {
- button->priv->brightness_min_level = new_brightness_level;
- }
-
- DBG("button->priv->brightness_min_level : %d", button->priv->brightness_min_level);
-
- /* update the range if it's being shown */
- if (button->priv->range)
- {
- gtk_range_set_range (GTK_RANGE (button->priv->range), button->priv->brightness_min_level, max_level);
- }
+ gint32 max_level = xfpm_brightness_get_max_level (button->priv->brightness);
+
+ /* sanity check */
+ if (new_brightness_level > max_level)
+ new_brightness_level = -1;
+
+ /* -1 = auto, we set the step value to a hopefully sane default */
+ if (new_brightness_level == -1)
+ {
+ button->priv->brightness_min_level = (max_level > 100) ? SAFE_SLIDER_MIN_LEVEL : 0;
+ }
+ else
+ {
+ button->priv->brightness_min_level = new_brightness_level;
+ }
+
+ DBG("button->priv->brightness_min_level : %d", button->priv->brightness_min_level);
+
+ /* update the range if it's being shown */
+ if (button->priv->range)
+ {
+ gtk_range_set_range (GTK_RANGE (button->priv->range), button->priv->brightness_min_level, max_level);
+ }
}
static void
@@ -809,35 +819,35 @@ power_manager_button_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- PowerManagerButton *button;
+ PowerManagerButton *button;
- button = POWER_MANAGER_BUTTON (object);
+ button = POWER_MANAGER_BUTTON (object);
- switch (property_id)
- {
- case PROP_BRIGHTNESS_MIN_LEVEL:
- set_brightness_min_level (button, g_value_get_int (value));
- break;
+ switch (property_id)
+ {
+ case PROP_BRIGHTNESS_MIN_LEVEL:
+ set_brightness_min_level (button, g_value_get_int (value));
+ break;
#ifdef XFCE_PLUGIN
- case PROP_SHOW_PANEL_LABEL:
- button->priv->show_panel_label = g_value_get_int (value);
- power_manager_button_update_label (button, button->priv->display_device);
- break;
- case PROP_PRESENTATION_MODE:
- button->priv->presentation_mode = g_value_get_boolean (value);
- if (GTK_IS_WIDGET (button->priv->panel_presentation_mode))
- power_manager_button_update_presentation_indicator (button);
- break;
- case PROP_SHOW_PRESENTATION_INDICATOR:
- button->priv->show_presentation_indicator = g_value_get_boolean (value);
- if (GTK_IS_WIDGET (button->priv->panel_presentation_mode))
- power_manager_button_update_presentation_indicator (button);
- break;
+ case PROP_SHOW_PANEL_LABEL:
+ button->priv->show_panel_label = g_value_get_int (value);
+ power_manager_button_update_label (button, button->priv->display_device);
+ break;
+ case PROP_PRESENTATION_MODE:
+ button->priv->presentation_mode = g_value_get_boolean (value);
+ if (GTK_IS_WIDGET (button->priv->panel_presentation_mode))
+ power_manager_button_update_presentation_indicator (button);
+ break;
+ case PROP_SHOW_PRESENTATION_INDICATOR:
+ button->priv->show_presentation_indicator = g_value_get_boolean (value);
+ if (GTK_IS_WIDGET (button->priv->panel_presentation_mode))
+ power_manager_button_update_presentation_indicator (button);
+ break;
#endif
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
static void
@@ -846,95 +856,95 @@ power_manager_button_get_property(GObject *object,
GValue *value,
GParamSpec *pspec)
{
- PowerManagerButton *button;
+ PowerManagerButton *button;
- button = POWER_MANAGER_BUTTON (object);
+ button = POWER_MANAGER_BUTTON (object);
- switch(property_id)
- {
- case PROP_BRIGHTNESS_MIN_LEVEL:
- g_value_set_int (value, button->priv->brightness_min_level);
- break;
+ switch(property_id)
+ {
+ case PROP_BRIGHTNESS_MIN_LEVEL:
+ g_value_set_int (value, button->priv->brightness_min_level);
+ break;
#ifdef XFCE_PLUGIN
- case PROP_SHOW_PANEL_LABEL:
- g_value_set_int (value, button->priv->show_panel_label);
- break;
- case PROP_PRESENTATION_MODE:
- g_value_set_boolean (value, button->priv->presentation_mode);
- break;
- case PROP_SHOW_PRESENTATION_INDICATOR:
- g_value_set_boolean (value, button->priv->show_presentation_indicator);
- break;
+ case PROP_SHOW_PANEL_LABEL:
+ g_value_set_int (value, button->priv->show_panel_label);
+ break;
+ case PROP_PRESENTATION_MODE:
+ g_value_set_boolean (value, button->priv->presentation_mode);
+ break;
+ case PROP_SHOW_PRESENTATION_INDICATOR:
+ g_value_set_boolean (value, button->priv->show_presentation_indicator);
+ break;
#endif
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
}
static void
power_manager_button_class_init (PowerManagerButtonClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- object_class->finalize = power_manager_button_finalize;
- object_class->set_property = power_manager_button_set_property;
- object_class->get_property = power_manager_button_get_property;
-
- widget_class->button_press_event = power_manager_button_press_event;
- widget_class->scroll_event = power_manager_button_scroll_event;
-
- __signals[SIG_TOOLTIP_CHANGED] = g_signal_new ("tooltip-changed",
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = power_manager_button_finalize;
+ object_class->set_property = power_manager_button_set_property;
+ object_class->get_property = power_manager_button_get_property;
+
+ widget_class->button_press_event = power_manager_button_press_event;
+ widget_class->scroll_event = power_manager_button_scroll_event;
+
+ __signals[SIG_TOOLTIP_CHANGED] = g_signal_new ("tooltip-changed",
+ POWER_MANAGER_TYPE_BUTTON,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(PowerManagerButtonClass,
+ tooltip_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ __signals[SIG_ICON_NAME_CHANGED] = g_signal_new ("icon-name-changed",
POWER_MANAGER_TYPE_BUTTON,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(PowerManagerButtonClass,
- tooltip_changed),
+ icon_name_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- __signals[SIG_ICON_NAME_CHANGED] = g_signal_new ("icon-name-changed",
- POWER_MANAGER_TYPE_BUTTON,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(PowerManagerButtonClass,
- icon_name_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
#define XFPM_PARAM_FLAGS (G_PARAM_READWRITE \
| G_PARAM_CONSTRUCT \
| G_PARAM_STATIC_NAME \
| G_PARAM_STATIC_NICK \
| G_PARAM_STATIC_BLURB)
- /* We allow and default to -1 only so that we can automagically set a
- * sane value if the user hasn't selected one already */
- g_object_class_install_property (object_class, PROP_BRIGHTNESS_MIN_LEVEL,
- g_param_spec_int(BRIGHTNESS_SLIDER_MIN_LEVEL,
- BRIGHTNESS_SLIDER_MIN_LEVEL,
- BRIGHTNESS_SLIDER_MIN_LEVEL,
- -1, G_MAXINT32, -1,
- XFPM_PARAM_FLAGS));
-
- g_object_class_install_property (object_class, PROP_SHOW_PANEL_LABEL,
- g_param_spec_int (SHOW_PANEL_LABEL,
- NULL, NULL,
- 0, G_MAXINT16, 3,
- XFPM_PARAM_FLAGS));
-
- g_object_class_install_property (object_class, PROP_PRESENTATION_MODE,
- g_param_spec_boolean (PRESENTATION_MODE,
- NULL, NULL,
- FALSE,
- XFPM_PARAM_FLAGS));
-
- g_object_class_install_property (object_class, PROP_SHOW_PRESENTATION_INDICATOR,
- g_param_spec_boolean (SHOW_PRESENTATION_INDICATOR,
- NULL, NULL,
- FALSE,
- XFPM_PARAM_FLAGS));
+ /* We allow and default to -1 only so that we can automagically set a
+ * sane value if the user hasn't selected one already */
+ g_object_class_install_property (object_class, PROP_BRIGHTNESS_MIN_LEVEL,
+ g_param_spec_int(BRIGHTNESS_SLIDER_MIN_LEVEL,
+ BRIGHTNESS_SLIDER_MIN_LEVEL,
+ BRIGHTNESS_SLIDER_MIN_LEVEL,
+ -1, G_MAXINT32, -1,
+ XFPM_PARAM_FLAGS));
+
+ g_object_class_install_property (object_class, PROP_SHOW_PANEL_LABEL,
+ g_param_spec_int (SHOW_PANEL_LABEL,
+ NULL, NULL,
+ 0, G_MAXINT16, 3,
+ XFPM_PARAM_FLAGS));
+
+ g_object_class_install_property (object_class, PROP_PRESENTATION_MODE,
+ g_param_spec_boolean (PRESENTATION_MODE,
+ NULL, NULL,
+ FALSE,
+ XFPM_PARAM_FLAGS));
+
+ g_object_class_install_property (object_class, PROP_SHOW_PRESENTATION_INDICATOR,
+ g_param_spec_boolean (SHOW_PRESENTATION_INDICATOR,
+ NULL, NULL,
+ FALSE,
+ XFPM_PARAM_FLAGS));
#undef XFPM_PARAM_FLAGS
}
@@ -944,115 +954,115 @@ inhibit_proxy_ready_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
- PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
-
- button->priv->inhibit_proxy = g_dbus_proxy_new_finish (res, &error);
- if (error != NULL)
- {
- g_warning ("error getting inhibit proxy: %s", error->message);
- g_clear_error (&error);
- }
+ GError *error = NULL;
+ PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
+
+ button->priv->inhibit_proxy = g_dbus_proxy_new_finish (res, &error);
+ if (error != NULL)
+ {
+ g_warning ("error getting inhibit proxy: %s", error->message);
+ g_clear_error (&error);
+ }
}
#endif
static void
power_manager_button_init (PowerManagerButton *button)
{
- GError *error = NULL;
- GtkCssProvider *css_provider;
+ GError *error = NULL;
+ GtkCssProvider *css_provider;
- button->priv = power_manager_button_get_instance_private (button);
+ button->priv = power_manager_button_get_instance_private (button);
- gtk_widget_set_can_default (GTK_WIDGET (button), FALSE);
- gtk_widget_set_can_focus (GTK_WIDGET (button), FALSE);
- gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+ gtk_widget_set_can_default (GTK_WIDGET (button), FALSE);
+ gtk_widget_set_can_focus (GTK_WIDGET (button), FALSE);
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
#if !GTK_CHECK_VERSION (3, 20, 0)
- gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
+ gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
#else
- gtk_widget_set_focus_on_click (GTK_WIDGET (button), FALSE);
+ gtk_widget_set_focus_on_click (GTK_WIDGET (button), FALSE);
#endif
- gtk_widget_set_name (GTK_WIDGET (button), "xfce4-power-manager-plugin");
-
- button->priv->brightness = xfpm_brightness_new ();
- xfpm_brightness_setup (button->priv->brightness);
- button->priv->set_level_timeout = 0;
-
- 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 (XFPM_CHANNEL);
- }
+ gtk_widget_set_name (GTK_WIDGET (button), "xfce4-power-manager-plugin");
+
+ button->priv->brightness = xfpm_brightness_new ();
+ xfpm_brightness_setup (button->priv->brightness);
+ button->priv->set_level_timeout = 0;
+
+ 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 (XFPM_CHANNEL);
+ }
#ifdef XFCE_PLUGIN
- g_dbus_proxy_new (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.PowerManagement",
- "/org/freedesktop/PowerManagement/Inhibit",
- "org.freedesktop.PowerManagement.Inhibit",
- NULL,
- inhibit_proxy_ready_cb,
- button);
+ g_dbus_proxy_new (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.PowerManagement",
+ "/org/freedesktop/PowerManagement/Inhibit",
+ "org.freedesktop.PowerManagement.Inhibit",
+ NULL,
+ inhibit_proxy_ready_cb,
+ button);
#else
- button->priv->inhibit = xfpm_inhibit_new ();
+ button->priv->inhibit = xfpm_inhibit_new ();
#endif
- /* Sane defaults for the systray and panel icon */
+ /* Sane defaults for the systray and panel icon */
#ifdef XFCE_PLUGIN
- button->priv->panel_icon_name = g_strdup (PANEL_DEFAULT_ICON_SYMBOLIC);
+ button->priv->panel_icon_name = g_strdup (PANEL_DEFAULT_ICON_SYMBOLIC);
#else
- button->priv->panel_icon_name = g_strdup (PANEL_DEFAULT_ICON);
+ button->priv->panel_icon_name = g_strdup (PANEL_DEFAULT_ICON);
#endif
- button->priv->panel_icon_width = 24;
-
- /* Sane default Gtk style */
- css_provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (css_provider,
- "#xfce4-power-manager-plugin {"
- "padding: 1px;"
- "border-width: 1px;}",
- -1, NULL);
- gtk_style_context_add_provider (GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (button))),
- GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- /* Intercept scroll events */
- gtk_widget_add_events (GTK_WIDGET (button), GDK_SCROLL_MASK);
-
- g_signal_connect (button->priv->upower, "device-added", G_CALLBACK (device_added_cb), button);
- g_signal_connect (button->priv->upower, "device-removed", G_CALLBACK (device_removed_cb), button);
+ button->priv->panel_icon_width = 24;
+
+ /* Sane default Gtk style */
+ css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (css_provider,
+ "#xfce4-power-manager-plugin {"
+ "padding: 1px;"
+ "border-width: 1px;}",
+ -1, NULL);
+ gtk_style_context_add_provider (GTK_STYLE_CONTEXT (gtk_widget_get_style_context (GTK_WIDGET (button))),
+ GTK_STYLE_PROVIDER (css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ /* Intercept scroll events */
+ gtk_widget_add_events (GTK_WIDGET (button), GDK_SCROLL_MASK);
+
+ g_signal_connect (button->priv->upower, "device-added", G_CALLBACK (device_added_cb), button);
+ g_signal_connect (button->priv->upower, "device-removed", G_CALLBACK (device_removed_cb), button);
}
static void
power_manager_button_finalize (GObject *object)
{
- PowerManagerButton *button;
+ PowerManagerButton *button;
- DBG("entering");
+ DBG("entering");
- button = POWER_MANAGER_BUTTON (object);
+ button = POWER_MANAGER_BUTTON (object);
- g_free(button->priv->panel_icon_name);
+ g_free(button->priv->panel_icon_name);
- if (button->priv->set_level_timeout)
- {
- g_source_remove(button->priv->set_level_timeout);
- button->priv->set_level_timeout = 0;
- }
+ if (button->priv->set_level_timeout)
+ {
+ g_source_remove(button->priv->set_level_timeout);
+ button->priv->set_level_timeout = 0;
+ }
- g_signal_handlers_disconnect_by_data (button->priv->upower, button);
+ g_signal_handlers_disconnect_by_data (button->priv->upower, button);
- power_manager_button_remove_all_devices (button);
+ power_manager_button_remove_all_devices (button);
#ifdef XFCE_PLUGIN
- g_object_unref (button->priv->plugin);
+ g_object_unref (button->priv->plugin);
#endif
- G_OBJECT_CLASS (power_manager_button_parent_class)->finalize (object);
+ G_OBJECT_CLASS (power_manager_button_parent_class)->finalize (object);
}
GtkWidget *
@@ -1063,47 +1073,47 @@ power_manager_button_new (XfcePanelPlugin *plugin)
power_manager_button_new (void)
#endif
{
- PowerManagerButton *button = NULL;
- button = g_object_new (POWER_MANAGER_TYPE_BUTTON, NULL, NULL);
+ PowerManagerButton *button = NULL;
+ button = g_object_new (POWER_MANAGER_TYPE_BUTTON, NULL, NULL);
#ifdef XFCE_PLUGIN
- button->priv->plugin = XFCE_PANEL_PLUGIN (g_object_ref (plugin));
+ button->priv->plugin = XFCE_PANEL_PLUGIN (g_object_ref (plugin));
#endif
- xfconf_g_property_bind (button->priv->channel,
- XFPM_PROPERTIES_PREFIX BRIGHTNESS_SLIDER_MIN_LEVEL, G_TYPE_INT,
- G_OBJECT (button), BRIGHTNESS_SLIDER_MIN_LEVEL);
- xfconf_g_property_bind (button->priv->channel, XFPM_PROPERTIES_PREFIX SHOW_PANEL_LABEL, G_TYPE_INT,
- G_OBJECT (button), SHOW_PANEL_LABEL);
- xfconf_g_property_bind (button->priv->channel, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, G_TYPE_BOOLEAN,
- G_OBJECT (button), PRESENTATION_MODE);
- xfconf_g_property_bind (button->priv->channel, XFPM_PROPERTIES_PREFIX SHOW_PRESENTATION_INDICATOR, G_TYPE_BOOLEAN,
- G_OBJECT (button), SHOW_PRESENTATION_INDICATOR);
- return GTK_WIDGET (button);
+ xfconf_g_property_bind (button->priv->channel,
+ XFPM_PROPERTIES_PREFIX BRIGHTNESS_SLIDER_MIN_LEVEL, G_TYPE_INT,
+ G_OBJECT (button), BRIGHTNESS_SLIDER_MIN_LEVEL);
+ xfconf_g_property_bind (button->priv->channel, XFPM_PROPERTIES_PREFIX SHOW_PANEL_LABEL, G_TYPE_INT,
+ G_OBJECT (button), SHOW_PANEL_LABEL);
+ xfconf_g_property_bind (button->priv->channel, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, G_TYPE_BOOLEAN,
+ G_OBJECT (button), PRESENTATION_MODE);
+ xfconf_g_property_bind (button->priv->channel, XFPM_PROPERTIES_PREFIX SHOW_PRESENTATION_INDICATOR, G_TYPE_BOOLEAN,
+ G_OBJECT (button), SHOW_PRESENTATION_INDICATOR);
+ return GTK_WIDGET (button);
}
static gboolean
power_manager_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
- PowerManagerButton *button = POWER_MANAGER_BUTTON (widget);
+ PowerManagerButton *button = POWER_MANAGER_BUTTON (widget);
- if (event->button == 1 && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
- {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
- power_manager_button_show_menu (button);
- return TRUE;
- }
+ if (event->button == 1 && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+ power_manager_button_show_menu (button);
+ return TRUE;
+ }
- if (event->button == 2)
- {
- gboolean state;
+ if (event->button == 2)
+ {
+ gboolean state;
- state = xfconf_channel_get_bool (button->priv->channel, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, FALSE);
- xfconf_channel_set_bool (button->priv->channel, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, !state);
- return TRUE;
- }
+ state = xfconf_channel_get_bool (button->priv->channel, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, FALSE);
+ xfconf_channel_set_bool (button->priv->channel, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, !state);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
#ifdef XFCE_PLUGIN
@@ -1111,546 +1121,545 @@ static void
power_manager_button_size_changed_cb (XfcePanelPlugin *plugin, gint size, PowerManagerButton *button)
{
#if !LIBXFCE4PANEL_CHECK_VERSION (4, 13, 0)
- GtkStyleContext *context;
- GtkBorder padding, border;
- gint width;
- gint xthickness;
- gint ythickness;
+ GtkStyleContext *context;
+ GtkBorder padding, border;
+ gint width;
+ gint xthickness;
+ gint ythickness;
#endif
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
- g_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
- g_return_if_fail (size > 0);
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+ g_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
+ g_return_if_fail (size > 0);
- size /= xfce_panel_plugin_get_nrows (plugin);
+ size /= xfce_panel_plugin_get_nrows (plugin);
#if LIBXFCE4PANEL_CHECK_VERSION (4, 13, 0)
- button->priv->panel_icon_width = xfce_panel_plugin_get_icon_size (plugin);
+ button->priv->panel_icon_width = xfce_panel_plugin_get_icon_size (plugin);
#else
- /* Calculate the size of the widget because the theme can override it */
- context = gtk_widget_get_style_context (GTK_WIDGET (button));
- gtk_style_context_get_padding (context, gtk_widget_get_state_flags (GTK_WIDGET (button)), &padding);
- gtk_style_context_get_border (context, gtk_widget_get_state_flags (GTK_WIDGET (button)), &border);
- xthickness = padding.left + padding.right + border.left + border.right;
- ythickness = padding.top + padding.bottom + border.top + border.bottom;
-
- /* Calculate the size of the space left for the icon */
- width = size - 2 * MAX (xthickness, ythickness);
-
- /* Since symbolic icons are usually only provided in 16px we
- * try to be clever and use size steps */
- if (width <= 21)
- button->priv->panel_icon_width = 16;
- else if (width >=22 && width <= 29)
- button->priv->panel_icon_width = 24;
- else if (width >= 30 && width <= 40)
- button->priv->panel_icon_width = 32;
- else
- button->priv->panel_icon_width = width;
+ /* Calculate the size of the widget because the theme can override it */
+ context = gtk_widget_get_style_context (GTK_WIDGET (button));
+ gtk_style_context_get_padding (context, gtk_widget_get_state_flags (GTK_WIDGET (button)), &padding);
+ gtk_style_context_get_border (context, gtk_widget_get_state_flags (GTK_WIDGET (button)), &border);
+ xthickness = padding.left + padding.right + border.left + border.right;
+ ythickness = padding.top + padding.bottom + border.top + border.bottom;
+
+ /* Calculate the size of the space left for the icon */
+ width = size - 2 * MAX (xthickness, ythickness);
+
+ /* Since symbolic icons are usually only provided in 16px we
+ * try to be clever and use size steps */
+ if (width <= 21)
+ button->priv->panel_icon_width = 16;
+ else if (width >=22 && width <= 29)
+ button->priv->panel_icon_width = 24;
+ else if (width >= 30 && width <= 40)
+ button->priv->panel_icon_width = 32;
+ else
+ button->priv->panel_icon_width = width;
#endif
- /* resize the plugin */
- gtk_widget_set_size_request (GTK_WIDGET (plugin), size, size);
- power_manager_button_set_icon (button);
+ /* resize the plugin */
+ gtk_widget_set_size_request (GTK_WIDGET (plugin), size, size);
+ power_manager_button_set_icon (button);
- /* resize the plugin button too */
- gtk_widget_set_size_request (GTK_WIDGET (button), -1, -1);
+ /* resize the plugin button too */
+ gtk_widget_set_size_request (GTK_WIDGET (button), -1, -1);
}
static void
power_manager_button_style_update_cb (XfcePanelPlugin *plugin, PowerManagerButton *button)
{
- gtk_widget_reset_style (GTK_WIDGET (plugin));
- power_manager_button_size_changed_cb (plugin, xfce_panel_plugin_get_size (plugin), button);
+ gtk_widget_reset_style (GTK_WIDGET (plugin));
+ power_manager_button_size_changed_cb (plugin, xfce_panel_plugin_get_size (plugin), button);
}
static void
power_manager_button_free_data_cb (XfcePanelPlugin *plugin, PowerManagerButton *button)
{
- gtk_widget_destroy (GTK_WIDGET (button));
+ gtk_widget_destroy (GTK_WIDGET (button));
}
#endif
static void
help_cb (GtkMenuItem *menuitem, gpointer user_data)
{
- xfce_dialog_show_help_with_version (NULL, "xfce4-power-manager", "start", NULL, XFPM_VERSION_SHORT);
+ xfce_dialog_show_help_with_version (NULL, "xfce4-power-manager", "start", NULL, XFPM_VERSION_SHORT);
}
static void
about_cb (GtkMenuItem *menuitem, gpointer user_data)
{
- xfpm_about ("xfce4-power-manager");
+ xfpm_about ("xfce4-power-manager");
}
void
power_manager_button_show (PowerManagerButton *button)
{
- GtkWidget *mi;
- GtkWidget *hbox;
- GtkStyleContext *context;
- GtkCssProvider *css_provider;
+ GtkWidget *mi;
+ GtkWidget *hbox;
+ GtkStyleContext *context;
+ GtkCssProvider *css_provider;
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
#ifdef XFCE_PLUGIN
- xfce_panel_plugin_add_action_widget (button->priv->plugin, GTK_WIDGET (button));
- xfce_panel_plugin_set_small (button->priv->plugin, TRUE);
+ xfce_panel_plugin_add_action_widget (button->priv->plugin, GTK_WIDGET (button));
+ xfce_panel_plugin_set_small (button->priv->plugin, TRUE);
#endif
- button->priv->panel_icon_image = gtk_image_new ();
- button->priv->panel_presentation_mode = gtk_image_new_from_icon_name (PRESENTATION_MODE_ICON, GTK_ICON_SIZE_BUTTON);
- gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_presentation_mode), button->priv->panel_icon_width);
- context = gtk_widget_get_style_context (button->priv->panel_presentation_mode);
- css_provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (css_provider,
- ".presentation-mode { color: @warning_color; }",
- -1, NULL);
- gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- g_object_unref (css_provider);
- gtk_style_context_add_class (context, "presentation-mode");
- button->priv->panel_label = gtk_label_new ("");
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button->priv->panel_presentation_mode), TRUE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button->priv->panel_icon_image), TRUE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button->priv->panel_label), TRUE, FALSE, 0);
-
- gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (hbox));
-
- /* help dialog */
- mi = gtk_menu_item_new_with_mnemonic (_("_Help"));
- gtk_widget_set_sensitive (mi, TRUE);
- gtk_widget_show (mi);
- g_signal_connect (mi, "activate", G_CALLBACK (help_cb), button);
-
- /* about dialog */
- mi = gtk_menu_item_new_with_mnemonic (_("_About"));
- gtk_widget_set_sensitive (mi, TRUE);
- gtk_widget_show (mi);
- g_signal_connect (mi, "activate", G_CALLBACK (about_cb), button);
+ button->priv->panel_icon_image = gtk_image_new ();
+ button->priv->panel_presentation_mode = gtk_image_new_from_icon_name (PRESENTATION_MODE_ICON, GTK_ICON_SIZE_BUTTON);
+ gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_presentation_mode), button->priv->panel_icon_width);
+ context = gtk_widget_get_style_context (button->priv->panel_presentation_mode);
+ css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (css_provider,
+ ".presentation-mode { color: @warning_color; }",
+ -1, NULL);
+ gtk_style_context_add_provider (context,
+ GTK_STYLE_PROVIDER (css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (css_provider);
+ gtk_style_context_add_class (context, "presentation-mode");
+ button->priv->panel_label = gtk_label_new ("");
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button->priv->panel_presentation_mode), TRUE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button->priv->panel_icon_image), TRUE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (button->priv->panel_label), TRUE, FALSE, 0);
+
+ gtk_container_add (GTK_CONTAINER (button), GTK_WIDGET (hbox));
+
+ /* help dialog */
+ mi = gtk_menu_item_new_with_mnemonic (_("_Help"));
+ gtk_widget_set_sensitive (mi, TRUE);
+ gtk_widget_show (mi);
+ g_signal_connect (mi, "activate", G_CALLBACK (help_cb), button);
+
+ /* about dialog */
+ mi = gtk_menu_item_new_with_mnemonic (_("_About"));
+ gtk_widget_set_sensitive (mi, TRUE);
+ gtk_widget_show (mi);
+ g_signal_connect (mi, "activate", G_CALLBACK (about_cb), button);
#ifdef XFCE_PLUGIN
- xfce_panel_plugin_menu_insert_item (button->priv->plugin, GTK_MENU_ITEM (mi));
+ xfce_panel_plugin_menu_insert_item (button->priv->plugin, GTK_MENU_ITEM (mi));
- g_signal_connect (button->priv->plugin, "size-changed",
- G_CALLBACK (power_manager_button_size_changed_cb), button);
+ g_signal_connect (button->priv->plugin, "size-changed",
+ G_CALLBACK (power_manager_button_size_changed_cb), button);
- g_signal_connect (button->priv->plugin, "style-updated",
- G_CALLBACK (power_manager_button_style_update_cb), button);
+ g_signal_connect (button->priv->plugin, "style-updated",
+ G_CALLBACK (power_manager_button_style_update_cb), button);
- g_signal_connect (button->priv->plugin, "free-data",
- G_CALLBACK (power_manager_button_free_data_cb), button);
+ g_signal_connect (button->priv->plugin, "free-data",
+ G_CALLBACK (power_manager_button_free_data_cb), button);
#endif
- gtk_widget_show_all (GTK_WIDGET(button));
+ gtk_widget_show_all (GTK_WIDGET(button));
- gtk_widget_set_visible (button->priv->panel_presentation_mode, button->priv->presentation_mode &&
- button->priv->show_presentation_indicator);
- power_manager_button_update_label (button, button->priv->display_device);
- power_manager_button_set_tooltip (button);
+ gtk_widget_set_visible (button->priv->panel_presentation_mode, button->priv->presentation_mode &&
+ button->priv->show_presentation_indicator);
+ power_manager_button_update_label (button, button->priv->display_device);
+ power_manager_button_set_tooltip (button);
- /* Add all the devcies currently attached to the system */
- power_manager_button_add_all_devices (button);
+ /* Add all the devcies currently attached to the system */
+ power_manager_button_add_all_devices (button);
}
static void
power_manager_button_update_presentation_indicator (PowerManagerButton *button)
{
- gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_presentation_mode), button->priv->panel_icon_width);
+ gtk_image_set_pixel_size (GTK_IMAGE (button->priv->panel_presentation_mode), button->priv->panel_icon_width);
- gtk_widget_set_visible (button->priv->panel_presentation_mode, button->priv->presentation_mode &&
- button->priv->show_presentation_indicator);
+ gtk_widget_set_visible (button->priv->panel_presentation_mode, button->priv->presentation_mode &&
+ button->priv->show_presentation_indicator);
}
static void
power_manager_button_update_label (PowerManagerButton *button, UpDevice *device)
{
- guint state;
- gdouble percentage;
- guint64 time_to_empty;
- guint64 time_to_full;
+ guint state;
+ gdouble percentage;
+ guint64 time_to_empty;
+ guint64 time_to_full;
- if (!POWER_MANAGER_IS_BUTTON (button) || !UP_IS_DEVICE (device))
- return;
+ if (!POWER_MANAGER_IS_BUTTON (button) || !UP_IS_DEVICE (device))
+ return;
#ifdef XFCE_PLUGIN
- if (button->priv->show_panel_label <= 0 || button->priv->show_panel_label >3)
- {
- gtk_widget_hide (GTK_WIDGET (button->priv->panel_label));
- power_manager_button_size_changed_cb (button->priv->plugin,
- xfce_panel_plugin_get_size (button->priv->plugin),
- button);
- return;
- }
- else
- gtk_widget_show (GTK_WIDGET (button->priv->panel_label));
+ if (button->priv->show_panel_label <= 0 || button->priv->show_panel_label >3)
+ {
+ gtk_widget_hide (GTK_WIDGET (button->priv->panel_label));
+ power_manager_button_size_changed_cb (button->priv->plugin,
+ xfce_panel_plugin_get_size (button->priv->plugin),
+ button);
+ return;
+ }
+ else
+ gtk_widget_show (GTK_WIDGET (button->priv->panel_label));
#endif
- g_object_get (device,
- "state", &state,
- "percentage", &percentage,
- "time-to-empty", &time_to_empty,
- "time-to-full", &time_to_full,
- NULL);
-
- /* Hide the label if the battery is fully charged,
- * if the state is unknown (no battery available)
- or if it's a desktop system */
- if (state == UP_DEVICE_STATE_CHARGING)
- power_manager_button_set_label (button, percentage, time_to_full);
- else if (state == UP_DEVICE_STATE_FULLY_CHARGED
- || state == UP_DEVICE_STATE_UNKNOWN
- || g_strcmp0 (button->priv->panel_icon_name, "ac-adapter-symbolic") == 0)
- gtk_widget_hide (GTK_WIDGET (button->priv->panel_label));
- else
- power_manager_button_set_label (button, percentage, time_to_empty);
+ g_object_get (device,
+ "state", &state,
+ "percentage", &percentage,
+ "time-to-empty", &time_to_empty,
+ "time-to-full", &time_to_full,
+ NULL);
+
+ /* Hide the label if the battery is fully charged,
+ * if the state is unknown (no battery available)
+ or if it's a desktop system */
+ if (state == UP_DEVICE_STATE_CHARGING)
+ power_manager_button_set_label (button, percentage, time_to_full);
+ else if (state == UP_DEVICE_STATE_FULLY_CHARGED
+ || state == UP_DEVICE_STATE_UNKNOWN
+ || g_strcmp0 (button->priv->panel_icon_name, "ac-adapter-symbolic") == 0)
+ gtk_widget_hide (GTK_WIDGET (button->priv->panel_label));
+ else
+ power_manager_button_set_label (button, percentage, time_to_empty);
}
static void
menu_destroyed_cb(GtkMenuShell *menu, gpointer user_data)
{
- PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
+ PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
- TRACE("entering");
+ TRACE("entering");
- /* menu destroyed, range slider is gone */
- button->priv->range = NULL;
+ /* menu destroyed, range slider is gone */
+ button->priv->range = NULL;
- /* untoggle panel icon */
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), FALSE);
+ /* untoggle panel icon */
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), FALSE);
- gtk_menu_detach (GTK_MENU (button->priv->menu));
+ gtk_menu_detach (GTK_MENU (button->priv->menu));
- button->priv->menu = NULL;
+ button->priv->menu = NULL;
}
static void
menu_item_destroyed_cb(GtkWidget *object, gpointer user_data)
{
- PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
- GList *item;
+ PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
+ GList *item;
- for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
- {
- BatteryDevice *battery_device = item->data;
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
- if (battery_device->menu_item == object)
- {
- battery_device->menu_item = NULL;
- return;
- }
+ if (battery_device->menu_item == object)
+ {
+ battery_device->menu_item = NULL;
+ return;
}
+ }
}
static void
menu_item_activate_cb(GtkWidget *object, gpointer user_data)
{
- PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
- GList *item;
+ PowerManagerButton *button = POWER_MANAGER_BUTTON (user_data);
+ GList *item;
+
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
- for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ if (battery_device->menu_item == object)
{
- BatteryDevice *battery_device = item->data;
-
- if (battery_device->menu_item == object)
- {
- /* Call xfpm settings with the device id */
- xfpm_preferences_device_id (battery_device->object_path);
- return;
- }
+ /* Call xfpm settings with the device id */
+ xfpm_preferences_device_id (battery_device->object_path);
+ return;
}
+ }
}
static gboolean
power_manager_button_menu_add_device (PowerManagerButton *button, BatteryDevice *battery_device, gboolean append)
{
- GtkWidget *mi, *label;
- guint type = 0;
+ GtkWidget *mi, *label;
+ guint type = 0;
- g_return_val_if_fail (POWER_MANAGER_IS_BUTTON (button), FALSE);
+ g_return_val_if_fail (POWER_MANAGER_IS_BUTTON (button), FALSE);
- /* We need a menu to attach it to */
- g_return_val_if_fail (button->priv->menu, FALSE);
+ /* We need a menu to attach it to */
+ g_return_val_if_fail (button->priv->menu, FALSE);
- if (UP_IS_DEVICE (battery_device->device))
+ if (UP_IS_DEVICE (battery_device->device))
+ {
+ g_object_get (battery_device->device,
+ "kind", &type,
+ NULL);
+
+ /* Don't add the display device or line power to the menu */
+ if (type == UP_DEVICE_KIND_LINE_POWER || battery_device->device == button->priv->display_device)
{
- g_object_get (battery_device->device,
- "kind", &type,
- NULL);
-
- /* Don't add the display device or line power to the menu */
- if (type == UP_DEVICE_KIND_LINE_POWER || battery_device->device == button->priv->display_device)
- {
- DBG("filtering device from menu (display or line power device)");
- return FALSE;
- }
+ DBG("filtering device from menu (display or line power device)");
+ return FALSE;
}
+ }
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- mi = gtk_image_menu_item_new_with_label(battery_device->details);
+ mi = gtk_image_menu_item_new_with_label(battery_device->details);
G_GNUC_END_IGNORE_DEPRECATIONS
- /* Make the menu item be bold and multi-line */
- label = gtk_bin_get_child (GTK_BIN (mi));
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- /* add the image */
- battery_device->img = gtk_image_new_from_pixbuf (battery_device->pix);
- g_object_ref (battery_device->img);
+ /* Make the menu item be bold and multi-line */
+ label = gtk_bin_get_child (GTK_BIN (mi));
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ /* add the image */
+ battery_device->img = gtk_image_new_from_pixbuf (battery_device->pix);
+ g_object_ref (battery_device->img);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), battery_device->img);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), battery_device->img);
G_GNUC_END_IGNORE_DEPRECATIONS
- /* keep track of the menu item in the battery_device so we can update it */
- battery_device->menu_item = mi;
- g_signal_connect(G_OBJECT (mi), "destroy", G_CALLBACK (menu_item_destroyed_cb), button);
- battery_device->expose_signal_id = g_signal_connect_after (G_OBJECT (battery_device->img),
- "draw",
- G_CALLBACK (power_manager_button_device_icon_draw),
- battery_device->device);
-
- /* Active calls xfpm settings with the device's id to display details */
- g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menu_item_activate_cb), button);
-
- /* Add it to the menu */
- gtk_widget_show (mi);
- if (append)
- gtk_menu_shell_append (GTK_MENU_SHELL(button->priv->menu), mi);
- else
- gtk_menu_shell_prepend (GTK_MENU_SHELL(button->priv->menu), mi);
+ /* keep track of the menu item in the battery_device so we can update it */
+ battery_device->menu_item = mi;
+ g_signal_connect(G_OBJECT (mi), "destroy", G_CALLBACK (menu_item_destroyed_cb), button);
+ battery_device->expose_signal_id = g_signal_connect_after (G_OBJECT (battery_device->img),
+ "draw",
+ G_CALLBACK (power_manager_button_device_icon_draw),
+ battery_device->device);
+
+ /* Active calls xfpm settings with the device's id to display details */
+ g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(menu_item_activate_cb), button);
+
+ /* Add it to the menu */
+ gtk_widget_show (mi);
+ if (append)
+ gtk_menu_shell_append (GTK_MENU_SHELL(button->priv->menu), mi);
+ else
+ gtk_menu_shell_prepend (GTK_MENU_SHELL(button->priv->menu), mi);
- return TRUE;
+ return TRUE;
}
static void
add_inhibitor_to_menu (PowerManagerButton *button, const gchar *text)
{
- GtkWidget *mi, *img;
+ GtkWidget *mi, *img;
- /* Translators this is to display which app is inhibiting
- * power in the plugin menu. Example:
- * VLC is currently inhibiting power management
- */
- gchar *label = g_strdup_printf (_("%s is currently inhibiting power management"), text);
+ /* Translators this is to display which app is inhibiting
+ * power in the plugin menu. Example:
+ * VLC is currently inhibiting power management
+ */
+ gchar *label = g_strdup_printf (_("%s is currently inhibiting power management"), text);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- mi = gtk_image_menu_item_new_with_label(label);
+ mi = gtk_image_menu_item_new_with_label(label);
G_GNUC_END_IGNORE_DEPRECATIONS
- /* add the image */
- img = gtk_image_new_from_icon_name ("dialog-information", GTK_ICON_SIZE_MENU);
+ /* add the image */
+ img = gtk_image_new_from_icon_name ("dialog-information", GTK_ICON_SIZE_MENU);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
G_GNUC_END_IGNORE_DEPRECATIONS
- gtk_widget_set_can_focus (mi, FALSE);
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL(button->priv->menu), mi);
- g_free (label);
+ gtk_widget_set_can_focus (mi, FALSE);
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL(button->priv->menu), mi);
+ g_free (label);
}
#ifdef XFCE_PLUGIN
static void
display_inhibitors (PowerManagerButton *button, GtkWidget *menu)
{
- GtkWidget *separator_mi;
- gboolean needs_seperator = FALSE;
-
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
- g_return_if_fail (GTK_IS_MENU (menu));
-
- if (button->priv->inhibit_proxy)
+ GtkWidget *separator_mi;
+ gboolean needs_seperator = FALSE;
+
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+ g_return_if_fail (GTK_IS_MENU (menu));
+
+ if (button->priv->inhibit_proxy)
+ {
+ GVariant *reply;
+ GError *error = NULL;
+
+ reply = g_dbus_proxy_call_sync (button->priv->inhibit_proxy,
+ "GetInhibitors",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ 1000,
+ NULL,
+ &error);
+
+ if (reply != NULL)
{
- GVariant *reply;
- GError *error = NULL;
-
- reply = g_dbus_proxy_call_sync (button->priv->inhibit_proxy,
- "GetInhibitors",
- g_variant_new ("()"),
- G_DBUS_CALL_FLAGS_NONE,
- 1000,
- NULL,
- &error);
-
- if (reply != NULL)
- {
- GVariantIter *iter;
- gchar *value;
-
- g_variant_get (reply, "(as)", &iter);
-
- if (g_variant_iter_n_children (iter) > 0)
- {
- needs_seperator = TRUE;
- }
-
- /* Add the list of programs to the menu */
- while (g_variant_iter_next (iter, "s", &value))
- {
- add_inhibitor_to_menu (button, value);
- }
- g_variant_iter_free (iter);
- g_variant_unref (reply);
-
- } else {
- g_warning ("failed calling GetInhibitors: %s", error->message);
- g_clear_error (&error);
- }
-
- if (needs_seperator)
- {
- /* add a separator */
- separator_mi = gtk_separator_menu_item_new ();
- gtk_widget_show (separator_mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator_mi);
- }
+ GVariantIter *iter;
+ gchar *value;
+
+ g_variant_get (reply, "(as)", &iter);
+
+ if (g_variant_iter_n_children (iter) > 0)
+ {
+ needs_seperator = TRUE;
+ }
+
+ /* Add the list of programs to the menu */
+ while (g_variant_iter_next (iter, "s", &value))
+ {
+ add_inhibitor_to_menu (button, value);
+ }
+ g_variant_iter_free (iter);
+ g_variant_unref (reply);
+
+ } else {
+ g_warning ("failed calling GetInhibitors: %s", error->message);
+ g_clear_error (&error);
+ }
+ if (needs_seperator)
+ {
+ /* add a separator */
+ separator_mi = gtk_separator_menu_item_new ();
+ gtk_widget_show (separator_mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator_mi);
}
+ }
}
#else
static void
display_inhibitors (PowerManagerButton *button, GtkWidget *menu)
{
- guint i;
- GtkWidget *separator_mi;
- const gchar **inhibitors;
+ guint i;
+ GtkWidget *separator_mi;
+ const gchar **inhibitors;
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
- g_return_if_fail (GTK_IS_MENU (menu));
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+ g_return_if_fail (GTK_IS_MENU (menu));
- inhibitors = xfpm_inhibit_get_inhibit_list (button->priv->inhibit);
- if (inhibitors != NULL && inhibitors[0] != NULL)
+ inhibitors = xfpm_inhibit_get_inhibit_list (button->priv->inhibit);
+ if (inhibitors != NULL && inhibitors[0] != NULL)
+ {
+ for (i=0; inhibitors[i] != NULL; i++)
{
- for (i=0; inhibitors[i] != NULL; i++)
- {
- add_inhibitor_to_menu (button, inhibitors[i]);
- }
-
- /* add a separator */
- separator_mi = gtk_separator_menu_item_new ();
- gtk_widget_show (separator_mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator_mi);
+ add_inhibitor_to_menu (button, inhibitors[i]);
}
- g_free (inhibitors);
+ /* add a separator */
+ separator_mi = gtk_separator_menu_item_new ();
+ gtk_widget_show (separator_mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator_mi);
+ }
+
+ g_free (inhibitors);
}
#endif
static void
decrease_brightness (PowerManagerButton *button)
{
- gint32 level;
+ gint32 level;
- TRACE("entering");
+ TRACE("entering");
- if ( !xfpm_brightness_has_hw (button->priv->brightness) )
- return;
+ if ( !xfpm_brightness_has_hw (button->priv->brightness) )
+ return;
- xfpm_brightness_get_level (button->priv->brightness, &level);
+ xfpm_brightness_get_level (button->priv->brightness, &level);
- if ( level > button->priv->brightness_min_level )
- {
- xfpm_brightness_down (button->priv->brightness, &level);
- if (button->priv->range)
- gtk_range_set_value (GTK_RANGE (button->priv->range), level);
- }
+ if ( level > button->priv->brightness_min_level )
+ {
+ xfpm_brightness_down (button->priv->brightness, &level);
+ if (button->priv->range)
+ gtk_range_set_value (GTK_RANGE (button->priv->range), level);
+ }
}
static void
increase_brightness (PowerManagerButton *button)
{
- gint32 level, max_level;
+ gint32 level, max_level;
- TRACE("entering");
+ TRACE("entering");
- if (!xfpm_brightness_has_hw (button->priv->brightness))
- return;
+ if (!xfpm_brightness_has_hw (button->priv->brightness))
+ return;
- max_level = xfpm_brightness_get_max_level (button->priv->brightness);
- xfpm_brightness_get_level (button->priv->brightness, &level);
+ max_level = xfpm_brightness_get_max_level (button->priv->brightness);
+ xfpm_brightness_get_level (button->priv->brightness, &level);
- if (level < max_level)
- {
- xfpm_brightness_up (button->priv->brightness, &level);
- if (button->priv->range)
- gtk_range_set_value (GTK_RANGE (button->priv->range), level);
- }
+ if (level < max_level)
+ {
+ xfpm_brightness_up (button->priv->brightness, &level);
+ if (button->priv->range)
+ gtk_range_set_value (GTK_RANGE (button->priv->range), level);
+ }
}
static gboolean
brightness_set_level_with_timeout (PowerManagerButton *button)
{
- gint32 range_level, hw_level;
+ gint32 range_level, hw_level;
- TRACE("entering");
+ TRACE("entering");
- range_level = (gint32) gtk_range_get_value (GTK_RANGE (button->priv->range));
+ range_level = (gint32) gtk_range_get_value (GTK_RANGE (button->priv->range));
- xfpm_brightness_get_level (button->priv->brightness, &hw_level);
+ xfpm_brightness_get_level (button->priv->brightness, &hw_level);
- if (hw_level != range_level)
- {
- xfpm_brightness_set_level (button->priv->brightness, range_level);
- }
+ if (hw_level != range_level)
+ {
+ xfpm_brightness_set_level (button->priv->brightness, range_level);
+ }
- if (button->priv->set_level_timeout)
- {
- g_source_remove(button->priv->set_level_timeout);
- button->priv->set_level_timeout = 0;
- }
+ if (button->priv->set_level_timeout)
+ {
+ g_source_remove(button->priv->set_level_timeout);
+ button->priv->set_level_timeout = 0;
+ }
- return FALSE;
+ return FALSE;
}
static void
range_value_changed_cb (PowerManagerButton *button, GtkWidget *widget)
{
- TRACE("entering");
+ TRACE("entering");
- if (button->priv->set_level_timeout)
- return;
+ if (button->priv->set_level_timeout)
+ return;
- button->priv->set_level_timeout =
- g_timeout_add (SET_LEVEL_TIMEOUT,
- (GSourceFunc) brightness_set_level_with_timeout, button);
+ button->priv->set_level_timeout =
+ g_timeout_add (SET_LEVEL_TIMEOUT,
+ (GSourceFunc) brightness_set_level_with_timeout, button);
}
static void
range_scroll_cb (GtkWidget *widget, GdkEvent *event, PowerManagerButton *button)
{
- GdkEventScroll *scroll_event;
+ GdkEventScroll *scroll_event;
- TRACE("entering");
+ TRACE("entering");
- scroll_event = (GdkEventScroll*)event;
+ scroll_event = (GdkEventScroll*)event;
- if (scroll_event->direction == GDK_SCROLL_UP)
- increase_brightness (button);
- else if (scroll_event->direction == GDK_SCROLL_DOWN)
- decrease_brightness (button);
+ if (scroll_event->direction == GDK_SCROLL_UP)
+ increase_brightness (button);
+ else if (scroll_event->direction == GDK_SCROLL_DOWN)
+ decrease_brightness (button);
}
static void
range_show_cb (GtkWidget *widget, PowerManagerButton *button)
{
#if !GTK_CHECK_VERSION (3, 20, 0)
- GdkDeviceManager* manager = gdk_display_get_device_manager (gdk_display_get_default());
- GdkDevice* pointer = gdk_device_manager_get_client_pointer (manager);
+ GdkDeviceManager* manager = gdk_display_get_device_manager (gdk_display_get_default());
+ GdkDevice* pointer = gdk_device_manager_get_client_pointer (manager);
#else
- GdkSeat *seat = gdk_display_get_default_seat (gdk_display_get_default());
- GdkDevice *pointer = gdk_seat_get_pointer (seat);
+ GdkSeat *seat = gdk_display_get_default_seat (gdk_display_get_default());
+ GdkDevice *pointer = gdk_seat_get_pointer (seat);
#endif
- TRACE("entering");
- /* Release these grabs as they will cause a lockup if pkexec is called
- * for the brightness helper */
- if (pointer)
- {
+ TRACE("entering");
+ /* Release these grabs as they will cause a lockup if pkexec is called
+ * for the brightness helper */
+ if (pointer)
+ {
#if !GTK_CHECK_VERSION (3, 20, 0)
- gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
+ gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
#else
- gdk_seat_ungrab (seat);
+ gdk_seat_ungrab (seat);
#endif
- }
+ }
- gtk_grab_remove (widget);
+ gtk_grab_remove (widget);
}
void
@@ -1665,136 +1674,136 @@ power_manager_button_toggle_presentation_mode (GtkMenuItem *mi, GtkSwitch *sw)
void
power_manager_button_show_menu (PowerManagerButton *button)
{
- GtkWidget *menu, *mi, *img = NULL;
- GtkWidget *box, *label, *sw;
- GdkScreen *gscreen;
- GList *item;
- gboolean show_separator_flag = FALSE;
- gint32 max_level, current_level = 0;
-
- TRACE("entering");
-
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
-
- if (gtk_widget_has_screen (GTK_WIDGET (button)))
- gscreen = gtk_widget_get_screen(GTK_WIDGET(button));
- else
- gscreen = gdk_display_get_default_screen(gdk_display_get_default());
-
- menu = gtk_menu_new ();
- gtk_menu_set_screen(GTK_MENU(menu), gscreen);
- /* keep track of the menu while it's being displayed */
- button->priv->menu = menu;
- g_signal_connect(GTK_MENU_SHELL(menu), "deactivate", G_CALLBACK(menu_destroyed_cb), button);
- gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (button), NULL);
-
- for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ GtkWidget *menu, *mi, *img = NULL;
+ GtkWidget *box, *label, *sw;
+ GdkScreen *gscreen;
+ GList *item;
+ gboolean show_separator_flag = FALSE;
+ gint32 max_level, current_level = 0;
+
+ TRACE("entering");
+
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+
+ if (gtk_widget_has_screen (GTK_WIDGET (button)))
+ gscreen = gtk_widget_get_screen(GTK_WIDGET(button));
+ else
+ gscreen = gdk_display_get_default_screen(gdk_display_get_default());
+
+ menu = gtk_menu_new ();
+ gtk_menu_set_screen(GTK_MENU(menu), gscreen);
+ /* keep track of the menu while it's being displayed */
+ button->priv->menu = menu;
+ g_signal_connect(GTK_MENU_SHELL(menu), "deactivate", G_CALLBACK(menu_destroyed_cb), button);
+ gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (button), NULL);
+
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
+
+ if (power_manager_button_menu_add_device (button, battery_device, TRUE))
{
- BatteryDevice *battery_device = item->data;
-
- if (power_manager_button_menu_add_device (button, battery_device, TRUE))
- {
- /* If we add an item to the menu, show the separator */
- show_separator_flag = TRUE;
- }
+ /* If we add an item to the menu, show the separator */
+ show_separator_flag = TRUE;
}
+ }
- if (show_separator_flag)
- {
- /* separator */
- mi = gtk_separator_menu_item_new ();
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- }
+ if (show_separator_flag)
+ {
+ /* separator */
+ mi = gtk_separator_menu_item_new ();
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ }
- /* Display brightness slider - show if there's hardware support for it */
- if ( xfpm_brightness_has_hw (button->priv->brightness) )
- {
- max_level = xfpm_brightness_get_max_level (button->priv->brightness);
+ /* Display brightness slider - show if there's hardware support for it */
+ if ( xfpm_brightness_has_hw (button->priv->brightness) )
+ {
+ max_level = xfpm_brightness_get_max_level (button->priv->brightness);
- mi = scale_menu_item_new_with_range (button->priv->brightness_min_level, max_level, 1);
+ mi = scale_menu_item_new_with_range (button->priv->brightness_min_level, max_level, 1);
- scale_menu_item_set_description_label (SCALE_MENU_ITEM (mi), _("<b>Display brightness</b>"));
+ scale_menu_item_set_description_label (SCALE_MENU_ITEM (mi), _("<b>Display brightness</b>"));
- /* range slider */
- button->priv->range = scale_menu_item_get_scale (SCALE_MENU_ITEM (mi));
+ /* range slider */
+ button->priv->range = scale_menu_item_get_scale (SCALE_MENU_ITEM (mi));
- /* update the slider to the current brightness level */
- xfpm_brightness_get_level (button->priv->brightness, ¤t_level);
- gtk_range_set_value (GTK_RANGE (button->priv->range), current_level);
+ /* update the slider to the current brightness level */
+ xfpm_brightness_get_level (button->priv->brightness, ¤t_level);
+ gtk_range_set_value (GTK_RANGE (button->priv->range), current_level);
- g_signal_connect_swapped (mi, "value-changed", G_CALLBACK (range_value_changed_cb), button);
- g_signal_connect (mi, "scroll-event", G_CALLBACK (range_scroll_cb), button);
- g_signal_connect (menu, "show", G_CALLBACK (range_show_cb), button);
+ g_signal_connect_swapped (mi, "value-changed", G_CALLBACK (range_value_changed_cb), button);
+ g_signal_connect (mi, "scroll-event", G_CALLBACK (range_scroll_cb), button);
+ g_signal_connect (menu, "show", G_CALLBACK (range_show_cb), button);
- /* load and display the brightness icon and force it to 32px size */
- img = gtk_image_new_from_icon_name (XFPM_DISPLAY_BRIGHTNESS_ICON, GTK_ICON_SIZE_DND);
+ /* load and display the brightness icon and force it to 32px size */
+ img = gtk_image_new_from_icon_name (XFPM_DISPLAY_BRIGHTNESS_ICON, GTK_ICON_SIZE_DND);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), img);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(mi), img);
G_GNUC_END_IGNORE_DEPRECATIONS
- gtk_image_set_pixel_size (GTK_IMAGE (img), 32);
- gtk_widget_show_all (mi);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
- }
-
- /* Presentation mode checkbox */
- mi = gtk_menu_item_new ();
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- label = gtk_label_new_with_mnemonic (_("Presentation _mode"));
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- sw = gtk_switch_new ();
- gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
- gtk_box_pack_start (GTK_BOX (box), sw, FALSE, FALSE, 0);
- gtk_container_add (GTK_CONTAINER (mi), box);
+ gtk_image_set_pixel_size (GTK_IMAGE (img), 32);
gtk_widget_show_all (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (power_manager_button_toggle_presentation_mode), sw);
- g_object_bind_property (G_OBJECT (button), PRESENTATION_MODE,
- G_OBJECT (sw), "active",
- G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
-
- /* Show any applications currently inhibiting now */
- display_inhibitors (button, menu);
-
- /* Power manager settings */
- mi = gtk_menu_item_new_with_mnemonic (_("_Power manager settings..."));
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL(menu), mi);
- g_signal_connect (G_OBJECT(mi), "activate", G_CALLBACK(xfpm_preferences), NULL);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ }
+
+ /* Presentation mode checkbox */
+ mi = gtk_menu_item_new ();
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ label = gtk_label_new_with_mnemonic (_("Presentation _mode"));
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ sw = gtk_switch_new ();
+ gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), sw, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (mi), box);
+ gtk_widget_show_all (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (power_manager_button_toggle_presentation_mode), sw);
+ g_object_bind_property (G_OBJECT (button), PRESENTATION_MODE,
+ G_OBJECT (sw), "active",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
+ /* Show any applications currently inhibiting now */
+ display_inhibitors (button, menu);
+
+ /* Power manager settings */
+ mi = gtk_menu_item_new_with_mnemonic (_("_Power manager settings..."));
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL(menu), mi);
+ g_signal_connect (G_OBJECT(mi), "activate", G_CALLBACK(xfpm_preferences), NULL);
#if GTK_CHECK_VERSION (3, 22, 0)
- gtk_menu_popup_at_widget (GTK_MENU (menu),
- GTK_WIDGET (button),
+ gtk_menu_popup_at_widget (GTK_MENU (menu),
+ GTK_WIDGET (button),
#ifdef XFCE_PLUGIN
- xfce_panel_plugin_get_orientation (button->priv->plugin) == GTK_ORIENTATION_VERTICAL
- ? GDK_GRAVITY_WEST : GDK_GRAVITY_NORTH,
- xfce_panel_plugin_get_orientation (button->priv->plugin) == GTK_ORIENTATION_VERTICAL
- ? GDK_GRAVITY_EAST : GDK_GRAVITY_SOUTH,
+ xfce_panel_plugin_get_orientation (button->priv->plugin) == GTK_ORIENTATION_VERTICAL
+ ? GDK_GRAVITY_WEST : GDK_GRAVITY_NORTH,
+ xfce_panel_plugin_get_orientation (button->priv->plugin) == GTK_ORIENTATION_VERTICAL
+ ? GDK_GRAVITY_EAST : GDK_GRAVITY_SOUTH,
#else
- GDK_GRAVITY_NORTH,
- GDK_GRAVITY_SOUTH,
+ GDK_GRAVITY_NORTH,
+ GDK_GRAVITY_SOUTH,
#endif
- NULL);
+ NULL);
#else
- gtk_menu_popup (GTK_MENU (menu),
- NULL,
- NULL,
+ gtk_menu_popup (GTK_MENU (menu),
+ NULL,
+ NULL,
#ifdef XFCE_PLUGIN
- xfce_panel_plugin_position_menu,
+ xfce_panel_plugin_position_menu,
#else
- NULL,
+ NULL,
#endif
#ifdef XFCE_PLUGIN
- button->priv->plugin,
+ button->priv->plugin,
#else
- NULL,
+ NULL,
#endif
- 0,
- gtk_get_current_event_time ());
+ 0,
+ gtk_get_current_event_time ());
#endif
#ifdef XFCE_PLUGIN
- xfce_panel_plugin_register_menu (button->priv->plugin,
- GTK_MENU (menu));
+ xfce_panel_plugin_register_menu (button->priv->plugin,
+ GTK_MENU (menu));
#endif
}
diff --git a/panel-plugins/power-manager-plugin/power-manager-button.h b/panel-plugins/power-manager-plugin/power-manager-button.h
index 810295c..49ba762 100644
--- a/panel-plugins/power-manager-plugin/power-manager-button.h
+++ b/panel-plugins/power-manager-plugin/power-manager-button.h
@@ -37,33 +37,29 @@ typedef struct PowerManagerButtonPrivate PowerManagerButtonPrivate;
typedef struct
{
- GtkToggleButton parent;
- PowerManagerButtonPrivate *priv;
+ GtkToggleButton parent;
+ PowerManagerButtonPrivate *priv;
} PowerManagerButton;
typedef struct
{
- GtkToggleButtonClass parent_class;
+ GtkToggleButtonClass parent_class;
- /*< Signals >*/
- void (*tooltip_changed) (PowerManagerButton *button);
- void (*icon_name_changed)(PowerManagerButton *button);
+ /*< Signals >*/
+ void (*tooltip_changed) (PowerManagerButton *button);
+ void (*icon_name_changed)(PowerManagerButton *button);
} PowerManagerButtonClass;
-GType power_manager_button_get_type (void) G_GNUC_CONST;
-
+GType power_manager_button_get_type (void) G_GNUC_CONST;
#ifdef XFCE_PLUGIN
-GtkWidget *power_manager_button_new (XfcePanelPlugin *plugin);
+GtkWidget *power_manager_button_new (XfcePanelPlugin *plugin);
#endif
#ifdef XFPM_SYSTRAY
-GtkWidget *power_manager_button_new (void);
+GtkWidget *power_manager_button_new (void);
#endif
-
-void power_manager_button_show (PowerManagerButton *button);
-
-void power_manager_button_show_menu (PowerManagerButton *button);
-
+void power_manager_button_show (PowerManagerButton *button);
+void power_manager_button_show_menu (PowerManagerButton *button);
const gchar *power_manager_button_get_icon_name (PowerManagerButton *button);
const gchar *power_manager_button_get_tooltip (PowerManagerButton *button);
diff --git a/panel-plugins/power-manager-plugin/scalemenuitem.h b/panel-plugins/power-manager-plugin/scalemenuitem.h
index 772419a..481b6ba 100644
--- a/panel-plugins/power-manager-plugin/scalemenuitem.h
+++ b/panel-plugins/power-manager-plugin/scalemenuitem.h
@@ -58,23 +58,18 @@ struct _ScaleMenuItemClass
GType scale_menu_item_get_type (void) G_GNUC_CONST;
-
GtkWidget *scale_menu_item_new_with_range (gdouble min,
gdouble max,
gdouble step);
-
GtkWidget *scale_menu_item_get_scale (ScaleMenuItem *menuitem);
-
const gchar *scale_menu_item_get_description_label (ScaleMenuItem *menuitem);
const gchar *scale_menu_item_get_percentage_label (ScaleMenuItem *menuitem);
-
void scale_menu_item_set_description_label (ScaleMenuItem *menuitem,
const gchar *label);
void scale_menu_item_set_percentage_label (ScaleMenuItem *menuitem,
const gchar *label);
-
-void scale_menu_item_set_value (ScaleMenuItem *item,
- gdouble value);
+void scale_menu_item_set_value (ScaleMenuItem *item,
+ gdouble value);
G_END_DECLS
diff --git a/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c b/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c
index 488ba6e..0d6f7cf 100644
--- a/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c
+++ b/panel-plugins/power-manager-plugin/xfce/xfce-power-manager-plugin.c
@@ -44,11 +44,11 @@
/* plugin structure */
typedef struct
{
- XfcePanelPlugin *plugin;
+ XfcePanelPlugin *plugin;
- /* panel widgets */
- GtkWidget *ebox;
- GtkWidget *power_manager_button;
+ /* panel widgets */
+ GtkWidget *ebox;
+ GtkWidget *power_manager_button;
}
PowerManagerPlugin;
@@ -71,18 +71,18 @@ power_manager_plugin_configure_response (GtkWidget *dialog,
gboolean result;
if (response == GTK_RESPONSE_HELP)
- {
- result = g_spawn_command_line_async ("exo-open --launch WebBrowser " "http://docs.xfce.org/xfce/xfce4-power-manager/1.6/start", NULL);
+ {
+ result = g_spawn_command_line_async ("exo-open --launch WebBrowser " "http://docs.xfce.org/xfce/xfce4-power-manager/1.6/start", NULL);
- if (G_UNLIKELY (result == FALSE))
- g_warning (_("Unable to open the following url: %s"), "http://docs.xfce.org/xfce/xfce4-power-manager/1.6/start");
- }
+ if (G_UNLIKELY (result == FALSE))
+ g_warning (_("Unable to open the following url: %s"), "http://docs.xfce.org/xfce/xfce4-power-manager/1.6/start");
+ }
else
- {
- g_object_set_data (G_OBJECT (power_manager_plugin->plugin), "dialog", NULL);
- xfce_panel_plugin_unblock_menu (power_manager_plugin->plugin);
- gtk_widget_destroy (dialog);
- }
+ {
+ g_object_set_data (G_OBJECT (power_manager_plugin->plugin), "dialog", NULL);
+ xfce_panel_plugin_unblock_menu (power_manager_plugin->plugin);
+ gtk_widget_destroy (dialog);
+ }
}
/* Update combo if property in channel changes */
@@ -107,12 +107,12 @@ power_manager_plugin_panel_label_changed (XfconfChannel *channel,
for (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
gtk_list_store_iter_is_valid (list_store, &iter);
gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter))
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &show_panel_label, -1);
- if (show_panel_label == current_setting)
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo),
- &iter);
- }
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 0, &show_panel_label, -1);
+ if (show_panel_label == current_setting)
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo),
+ &iter);
+ }
}
/* Update xfconf property if combobox selection is changed */
@@ -156,11 +156,11 @@ power_manager_plugin_configure (XfcePanelPlugin *plugin,
/* create the dialog */
dialog = xfce_titled_dialog_new_with_mixed_buttons (_("Power Manager Plugin Settings"),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- "help-browser", _("_Help"), GTK_RESPONSE_HELP,
- "window-close-symbolic", _("_Close"), GTK_RESPONSE_OK,
- NULL);
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ "help-browser", _("_Help"), GTK_RESPONSE_HELP,
+ "window-close-symbolic", _("_Close"), GTK_RESPONSE_OK,
+ NULL);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_window_set_icon_name (GTK_WINDOW (dialog), "xfce4-power-manager-settings");
@@ -175,7 +175,7 @@ power_manager_plugin_configure (XfcePanelPlugin *plugin,
gtk_widget_set_margin_top (grid, 12);
gtk_widget_set_margin_bottom (grid, 12);
gtk_container_add_with_properties (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
- grid, "expand", TRUE, "fill", TRUE, NULL);
+ grid, "expand", TRUE, "fill", TRUE, NULL);
/* show-panel-label setting */
label = gtk_label_new (_("Show label:"));
@@ -187,7 +187,8 @@ power_manager_plugin_configure (XfcePanelPlugin *plugin,
G_TYPE_INT,
G_TYPE_STRING);
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++)
+ {
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
COLUMN_INT, i,
@@ -236,50 +237,50 @@ power_manager_plugin_configure (XfcePanelPlugin *plugin,
static PowerManagerPlugin *
power_manager_plugin_new (XfcePanelPlugin *plugin)
{
- PowerManagerPlugin *power_manager_plugin;
- XfconfChannel *channel;
+ PowerManagerPlugin *power_manager_plugin;
+ XfconfChannel *channel;
- /* allocate memory for the plugin structure */
- power_manager_plugin = g_slice_new0 (PowerManagerPlugin);
+ /* allocate memory for the plugin structure */
+ power_manager_plugin = g_slice_new0 (PowerManagerPlugin);
- /* pointer to plugin */
- power_manager_plugin->plugin = plugin;
+ /* pointer to plugin */
+ power_manager_plugin->plugin = plugin;
- /* create some panel ebox */
- power_manager_plugin->ebox = gtk_event_box_new ();
- gtk_widget_show (power_manager_plugin->ebox);
- gtk_event_box_set_visible_window (GTK_EVENT_BOX(power_manager_plugin->ebox), FALSE);
+ /* create some panel ebox */
+ power_manager_plugin->ebox = gtk_event_box_new ();
+ gtk_widget_show (power_manager_plugin->ebox);
+ gtk_event_box_set_visible_window (GTK_EVENT_BOX(power_manager_plugin->ebox), FALSE);
- power_manager_plugin->power_manager_button = power_manager_button_new (plugin);
- gtk_container_add (GTK_CONTAINER (power_manager_plugin->ebox), power_manager_plugin->power_manager_button);
- power_manager_button_show (POWER_MANAGER_BUTTON (power_manager_plugin->power_manager_button));
+ power_manager_plugin->power_manager_button = power_manager_button_new (plugin);
+ gtk_container_add (GTK_CONTAINER (power_manager_plugin->ebox), power_manager_plugin->power_manager_button);
+ power_manager_button_show (POWER_MANAGER_BUTTON (power_manager_plugin->power_manager_button));
- /* disable the systray item when the plugin is started, allowing the user to
- later manually enable it, e.g. for testing purposes. */
- channel = xfconf_channel_get (XFPM_CHANNEL);
- if (xfconf_channel_get_bool (channel, "/xfce4-power-manager/show-tray-icon", TRUE))
- g_warning ("Xfce4-power-manager: The panel plugin is present, so the tray icon gets disabled.");
- xfconf_channel_set_bool (channel, "/xfce4-power-manager/show-tray-icon", FALSE);
+ /* disable the systray item when the plugin is started, allowing the user to
+ later manually enable it, e.g. for testing purposes. */
+ channel = xfconf_channel_get (XFPM_CHANNEL);
+ if (xfconf_channel_get_bool (channel, "/xfce4-power-manager/show-tray-icon", TRUE))
+ g_warning ("Xfce4-power-manager: The panel plugin is present, so the tray icon gets disabled.");
+ xfconf_channel_set_bool (channel, "/xfce4-power-manager/show-tray-icon", FALSE);
- return power_manager_plugin;
+ return power_manager_plugin;
}
static void
power_manager_plugin_construct (XfcePanelPlugin *plugin)
{
- PowerManagerPlugin *power_manager_plugin;
+ PowerManagerPlugin *power_manager_plugin;
- xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+ xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
- /* create the plugin */
- power_manager_plugin = power_manager_plugin_new (plugin);
+ /* create the plugin */
+ power_manager_plugin = power_manager_plugin_new (plugin);
- /* show the configure menu item and connect signal */
- xfce_panel_plugin_menu_show_configure (plugin);
- g_signal_connect (G_OBJECT (plugin), "configure-plugin",
- G_CALLBACK (power_manager_plugin_configure), power_manager_plugin);
+ /* show the configure menu item and connect signal */
+ xfce_panel_plugin_menu_show_configure (plugin);
+ g_signal_connect (G_OBJECT (plugin), "configure-plugin",
+ G_CALLBACK (power_manager_plugin_configure), power_manager_plugin);
- /* add the ebox to the panel */
- gtk_container_add (GTK_CONTAINER (plugin), power_manager_plugin->ebox);
+ /* add the ebox to the panel */
+ gtk_container_add (GTK_CONTAINER (plugin), power_manager_plugin->ebox);
}
diff --git a/settings/xfpm-settings-app.c b/settings/xfpm-settings-app.c
index f1b4fa4..872b6c3 100644
--- a/settings/xfpm-settings-app.c
+++ b/settings/xfpm-settings-app.c
@@ -40,9 +40,9 @@
struct _XfpmSettingsAppPrivate
{
- gboolean debug;
- Window socket_id;
- gchar *device_id;
+ gboolean debug;
+ Window socket_id;
+ gchar *device_id;
};
static void xfpm_settings_app_launch (GApplication *app);
@@ -70,202 +70,202 @@ G_DEFINE_TYPE_WITH_PRIVATE(XfpmSettingsApp, xfpm_settings_app, GTK_TYPE_APPLICAT
static void
xfpm_settings_app_init (XfpmSettingsApp *app)
{
- const GOptionEntry option_entries[] = {
- { "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, NULL, N_("Settings manager socket"), N_("SOCKET ID") },
- { "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, NULL, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") },
- { "debug", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Enable debugging"), NULL },
- { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Display version information"), NULL },
- { "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Cause xfce4-power-manager-settings to quit"), NULL },
- { NULL, },
- };
-
- g_application_add_main_option_entries (G_APPLICATION (app), option_entries);
+ const GOptionEntry option_entries[] = {
+ { "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, NULL, N_("Settings manager socket"), N_("SOCKET ID") },
+ { "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, NULL, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") },
+ { "debug", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Enable debugging"), NULL },
+ { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Display version information"), NULL },
+ { "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, NULL, N_("Cause xfce4-power-manager-settings to quit"), NULL },
+ { NULL, },
+ };
+
+ g_application_add_main_option_entries (G_APPLICATION (app), option_entries);
}
static void
xfpm_settings_app_startup (GApplication *app)
{
- const GActionEntry action_entries[] = {
- { "socket-id", activate_socket, "i" },
- { "device-id", activate_device, "s" },
- { "debug", activate_debug, NULL },
- { "activate", activate_window, NULL },
- { "quit", activate_quit, NULL },
- };
-
- TRACE ("entering");
-
- g_action_map_add_action_entries (G_ACTION_MAP (app),
- action_entries,
- G_N_ELEMENTS (action_entries),
- app);
-
- /* keep the app running until we've launched our window */
- g_application_hold (app);
-
- /* let the parent class do it's startup as well */
- G_APPLICATION_CLASS(xfpm_settings_app_parent_class)->startup(app);
+ const GActionEntry action_entries[] = {
+ { "socket-id", activate_socket, "i" },
+ { "device-id", activate_device, "s" },
+ { "debug", activate_debug, NULL },
+ { "activate", activate_window, NULL },
+ { "quit", activate_quit, NULL },
+ };
+
+ TRACE ("entering");
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ action_entries,
+ G_N_ELEMENTS (action_entries),
+ app);
+
+ /* keep the app running until we've launched our window */
+ g_application_hold (app);
+
+ /* let the parent class do it's startup as well */
+ G_APPLICATION_CLASS(xfpm_settings_app_parent_class)->startup(app);
}
static void
xfpm_settings_app_activate (GApplication *app)
{
- TRACE ("entering");
+ TRACE ("entering");
}
static void
xfpm_settings_app_launch (GApplication *app)
{
- XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (XFPM_SETTINGS_APP (app));
-
- XfpmPowerManager *manager;
- XfconfChannel *channel;
- GError *error = NULL;
- GtkWidget *dialog;
- GHashTable *hash;
- GVariant *config;
- GVariantIter *iter;
- gchar *key, *value;
- GList *windows;
-
- gboolean has_battery;
- gboolean auth_suspend;
- gboolean auth_hibernate;
- gboolean can_suspend;
- gboolean can_hibernate;
- gboolean can_shutdown;
- gboolean has_lcd_brightness;
- gboolean has_sleep_button;
- gboolean has_hibernate_button;
- gboolean has_power_button;
- gboolean has_battery_button;
- gboolean has_lid;
- gint start_xfpm_if_not_running;
-
- TRACE ("entering");
-
- windows = gtk_application_get_windows (GTK_APPLICATION (app));
-
- if (windows != NULL)
+ XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (XFPM_SETTINGS_APP (app));
+
+ XfpmPowerManager *manager;
+ XfconfChannel *channel;
+ GError *error = NULL;
+ GtkWidget *dialog;
+ GHashTable *hash;
+ GVariant *config;
+ GVariantIter *iter;
+ gchar *key, *value;
+ GList *windows;
+
+ gboolean has_battery;
+ gboolean auth_suspend;
+ gboolean auth_hibernate;
+ gboolean can_suspend;
+ gboolean can_hibernate;
+ gboolean can_shutdown;
+ gboolean has_lcd_brightness;
+ gboolean has_sleep_button;
+ gboolean has_hibernate_button;
+ gboolean has_power_button;
+ gboolean has_battery_button;
+ gboolean has_lid;
+ gint start_xfpm_if_not_running;
+
+ TRACE ("entering");
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (app));
+
+ if (windows != NULL)
+ {
+ XFPM_DEBUG ("window already opened");
+
+ gdk_notify_startup_complete ();
+
+ if (priv->device_id != NULL)
{
- XFPM_DEBUG ("window already opened");
-
- gdk_notify_startup_complete ();
-
- if (priv->device_id != NULL)
- {
- xfpm_settings_show_device_id (priv->device_id);
- }
-
- return;
- }
-
- manager = xfpm_power_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- NULL,
- &error);
-
- if (error != NULL)
- {
- g_critical("xfpm_power_manager_proxy_new_sync failed: %s\n", error->message);
- xfce_dialog_show_warning (NULL,
- _("Xfce Power Manager"),
- "%s",
- _("Failed to connect to power manager"));
- g_clear_error (&error);
- return;
- }
-
-
- while ( !xfpm_power_manager_call_get_config_sync (manager, &config, NULL, NULL) )
- {
- GtkWidget *startw;
-
- startw = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("Xfce4 Power Manager is not running, do you want to launch it now?"));
- start_xfpm_if_not_running = gtk_dialog_run (GTK_DIALOG (startw));
- gtk_widget_destroy (startw);
-
- if (start_xfpm_if_not_running == GTK_RESPONSE_YES)
- {
- GAppInfo *app_info;
-
- app_info = g_app_info_create_from_commandline ("xfce4-power-manager", "Xfce4 Power Manager",
- G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION, NULL);
- if (!g_app_info_launch (app_info, NULL, NULL, &error)) {
- if (error != NULL) {
- g_warning ("xfce4-power-manager could not be launched. %s", error->message);
- g_error_free (error);
- error = NULL;
- }
- }
- /* wait 2 seconds for xfpm to startup */
- g_usleep ( 2 * 1000000 );
- }
- else
- {
- /* exit without starting xfpm */
- return;
- }
+ xfpm_settings_show_device_id (priv->device_id);
}
- if ( !xfconf_init(&error) )
+ return;
+ }
+
+ manager = xfpm_power_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ "org.xfce.PowerManager",
+ "/org/xfce/PowerManager",
+ NULL,
+ &error);
+
+ if (error != NULL)
+ {
+ g_critical("xfpm_power_manager_proxy_new_sync failed: %s\n", error->message);
+ xfce_dialog_show_warning (NULL,
+ _("Xfce Power Manager"),
+ "%s",
+ _("Failed to connect to power manager"));
+ g_clear_error (&error);
+ return;
+ }
+
+
+ while ( !xfpm_power_manager_call_get_config_sync (manager, &config, NULL, NULL) )
+ {
+ GtkWidget *startw;
+
+ startw = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("Xfce4 Power Manager is not running, do you want to launch it now?"));
+ start_xfpm_if_not_running = gtk_dialog_run (GTK_DIALOG (startw));
+ gtk_widget_destroy (startw);
+
+ if (start_xfpm_if_not_running == GTK_RESPONSE_YES)
{
- g_critical("xfconf init failed: %s using default settings\n", error->message);
- xfce_dialog_show_warning (NULL,
- _("Xfce Power Manager"),
- "%s",
- _("Failed to load power manager configuration, using defaults"));
- g_clear_error (&error);
+ GAppInfo *app_info;
+
+ app_info = g_app_info_create_from_commandline ("xfce4-power-manager", "Xfce4 Power Manager",
+ G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION, NULL);
+ if (!g_app_info_launch (app_info, NULL, NULL, &error)) {
+ if (error != NULL) {
+ g_warning ("xfce4-power-manager could not be launched. %s", error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+ /* wait 2 seconds for xfpm to startup */
+ g_usleep ( 2 * 1000000 );
}
-
-
- channel = xfconf_channel_new(XFPM_CHANNEL);
-
- xfpm_debug_init (priv->debug);
-
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- g_variant_get (config, "a{ss}", &iter);
- while (g_variant_iter_next (iter, "{ss}", &key, &value))
+ else
{
- g_hash_table_insert (hash, key, value);
+ /* exit without starting xfpm */
+ return;
}
- g_variant_iter_free (iter);
- g_variant_unref (config);
-
-
- has_battery = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-battery"));
- has_lid = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-lid"));
- can_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-suspend"));
- can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-hibernate"));
- auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-suspend"));
- auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-hibernate"));
- has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-brightness"));
- has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "sleep-button"));
- has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "power-button"));
- has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "hibernate-button"));
- has_battery_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "battery-button"));
- can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-shutdown"));
-
- DBG("socket_id %i", (int)priv->socket_id);
- DBG("device id %s", priv->device_id);
-
- dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate,
- can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness,
- has_lid, has_sleep_button, has_hibernate_button, has_power_button, has_battery_button,
- priv->socket_id, priv->device_id, GTK_APPLICATION (app));
-
- g_hash_table_destroy (hash);
-
- gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (dialog));
- g_application_release (app);
-
- g_object_unref (manager);
+ }
+
+ if ( !xfconf_init(&error) )
+ {
+ g_critical("xfconf init failed: %s using default settings\n", error->message);
+ xfce_dialog_show_warning (NULL,
+ _("Xfce Power Manager"),
+ "%s",
+ _("Failed to load power manager configuration, using defaults"));
+ g_clear_error (&error);
+ }
+
+
+ channel = xfconf_channel_new(XFPM_CHANNEL);
+
+ xfpm_debug_init (priv->debug);
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ g_variant_get (config, "a{ss}", &iter);
+ while (g_variant_iter_next (iter, "{ss}", &key, &value))
+ {
+ g_hash_table_insert (hash, key, value);
+ }
+ g_variant_iter_free (iter);
+ g_variant_unref (config);
+
+
+ has_battery = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-battery"));
+ has_lid = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-lid"));
+ can_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-suspend"));
+ can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-hibernate"));
+ auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-suspend"));
+ auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-hibernate"));
+ has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-brightness"));
+ has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "sleep-button"));
+ has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "power-button"));
+ has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "hibernate-button"));
+ has_battery_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "battery-button"));
+ can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-shutdown"));
+
+ DBG("socket_id %i", (int)priv->socket_id);
+ DBG("device id %s", priv->device_id);
+
+ dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate,
+ can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness,
+ has_lid, has_sleep_button, has_hibernate_button, has_power_button, has_battery_button,
+ priv->socket_id, priv->device_id, GTK_APPLICATION (app));
+
+ g_hash_table_destroy (hash);
+
+ gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (dialog));
+ g_application_release (app);
+
+ g_object_unref (manager);
}
static void
@@ -273,14 +273,14 @@ activate_socket (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
- XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
- XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (app);
+ XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
+ XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (app);
- TRACE ("entering");
+ TRACE ("entering");
- priv->socket_id = g_variant_get_int32 (parameter);
+ priv->socket_id = g_variant_get_int32 (parameter);
- xfpm_settings_app_launch (G_APPLICATION (app));
+ xfpm_settings_app_launch (G_APPLICATION (app));
}
static void
@@ -288,14 +288,14 @@ activate_device (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
- XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
- XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (app);
+ XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
+ XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (app);
- TRACE ("entering");
+ TRACE ("entering");
- priv->device_id = g_strdup(g_variant_get_string (parameter, NULL));
+ priv->device_id = g_strdup(g_variant_get_string (parameter, NULL));
- xfpm_settings_app_launch (G_APPLICATION (app));
+ xfpm_settings_app_launch (G_APPLICATION (app));
}
static void
@@ -303,14 +303,14 @@ activate_debug (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
- XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
- XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (app);
+ XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
+ XfpmSettingsAppPrivate *priv = xfpm_settings_app_get_instance_private (app);
- TRACE ("entering");
+ TRACE ("entering");
- priv->debug = TRUE;
+ priv->debug = TRUE;
- xfpm_settings_app_launch (G_APPLICATION (app));
+ xfpm_settings_app_launch (G_APPLICATION (app));
}
static void
@@ -318,11 +318,11 @@ activate_window (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
- XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
+ XfpmSettingsApp *app = XFPM_SETTINGS_APP (data);
- TRACE ("entering");
+ TRACE ("entering");
- xfpm_settings_app_launch (G_APPLICATION (app));
+ xfpm_settings_app_launch (G_APPLICATION (app));
}
static void
@@ -330,99 +330,99 @@ activate_quit (GSimpleAction *action,
GVariant *parameter,
gpointer data)
{
- GtkApplication *app = GTK_APPLICATION (data);
- GList *windows;
+ GtkApplication *app = GTK_APPLICATION (data);
+ GList *windows;
- TRACE ("entering");
+ TRACE ("entering");
- windows = gtk_application_get_windows (app);
+ windows = gtk_application_get_windows (app);
- if (windows)
- {
- /* Remove our window if we've attahced one */
- gtk_application_remove_window (app, GTK_WINDOW (windows->data));
- }
+ if (windows)
+ {
+ /* Remove our window if we've attached one */
+ gtk_application_remove_window (app, GTK_WINDOW (windows->data));
+ }
}
static gboolean
xfpm_settings_app_local_options (GApplication *g_application,
GVariantDict *options)
{
- TRACE ("entering");
+ TRACE ("entering");
+
+ /* --version */
+ if (g_variant_dict_contains (options, "version"))
+ {
+ g_print(_("This is %s version %s, running on Xfce %s.\n"), PACKAGE,
+ VERSION, xfce_version_string());
+ g_print(_("Built with GTK+ %d.%d.%d, linked with GTK+ %d.%d.%d."),
+ GTK_MAJOR_VERSION,GTK_MINOR_VERSION, GTK_MICRO_VERSION,
+ gtk_major_version, gtk_minor_version, gtk_micro_version);
+ g_print("\n");
- /* --version */
- if (g_variant_dict_contains (options, "version"))
- {
- g_print(_("This is %s version %s, running on Xfce %s.\n"), PACKAGE,
- VERSION, xfce_version_string());
- g_print(_("Built with GTK+ %d.%d.%d, linked with GTK+ %d.%d.%d."),
- GTK_MAJOR_VERSION,GTK_MINOR_VERSION, GTK_MICRO_VERSION,
- gtk_major_version, gtk_minor_version, gtk_micro_version);
- g_print("\n");
-
- return 0;
- }
+ return 0;
+ }
- /* This will call xfpm_settings_app_startup if it needs to */
- g_application_register (g_application, NULL, NULL);
+ /* This will call xfpm_settings_app_startup if it needs to */
+ g_application_register (g_application, NULL, NULL);
- /* --debug */
- if (g_variant_dict_contains (options, "debug"))
- {
- g_action_group_activate_action(G_ACTION_GROUP(g_application), "debug", NULL);
- return 0;
- }
+ /* --debug */
+ if (g_variant_dict_contains (options, "debug"))
+ {
+ g_action_group_activate_action(G_ACTION_GROUP(g_application), "debug", NULL);
+ return 0;
+ }
- /* --socket-id */
- if (g_variant_dict_contains (options, "socket-id") || g_variant_dict_contains (options, "s"))
- {
- GVariant *var;
+ /* --socket-id */
+ if (g_variant_dict_contains (options, "socket-id") || g_variant_dict_contains (options, "s"))
+ {
+ GVariant *var;
- var = g_variant_dict_lookup_value (options, "socket-id", G_VARIANT_TYPE_INT32);
+ var = g_variant_dict_lookup_value (options, "socket-id", G_VARIANT_TYPE_INT32);
- g_action_group_activate_action(G_ACTION_GROUP(g_application), "socket-id", var);
- return 0;
- }
+ g_action_group_activate_action(G_ACTION_GROUP(g_application), "socket-id", var);
+ return 0;
+ }
- /* --device-id */
- if (g_variant_dict_contains (options, "device-id") || g_variant_dict_contains (options, "d"))
- {
- GVariant *var;
+ /* --device-id */
+ if (g_variant_dict_contains (options, "device-id") || g_variant_dict_contains (options, "d"))
+ {
+ GVariant *var;
- var = g_variant_dict_lookup_value (options, "device-id", G_VARIANT_TYPE_STRING);
+ var = g_variant_dict_lookup_value (options, "device-id", G_VARIANT_TYPE_STRING);
- g_action_group_activate_action(G_ACTION_GROUP(g_application), "device-id", var);
- return 0;
- }
+ g_action_group_activate_action(G_ACTION_GROUP(g_application), "device-id", var);
+ return 0;
+ }
- /* --quit */
- if (g_variant_dict_contains (options, "quit") || g_variant_dict_contains (options, "q"))
- {
- g_action_group_activate_action(G_ACTION_GROUP(g_application), "quit", NULL);
- return 0;
- }
+ /* --quit */
+ if (g_variant_dict_contains (options, "quit") || g_variant_dict_contains (options, "q"))
+ {
+ g_action_group_activate_action(G_ACTION_GROUP(g_application), "quit", NULL);
+ return 0;
+ }
- /* default action */
- g_action_group_activate_action(G_ACTION_GROUP(g_application), "activate", NULL);
+ /* default action */
+ g_action_group_activate_action(G_ACTION_GROUP(g_application), "activate", NULL);
- return 0;
+ return 0;
}
static void
xfpm_settings_app_class_init (XfpmSettingsAppClass *class)
{
- GApplicationClass *gapplication_class = G_APPLICATION_CLASS (class);
+ GApplicationClass *gapplication_class = G_APPLICATION_CLASS (class);
- gapplication_class->handle_local_options = xfpm_settings_app_local_options;
- gapplication_class->startup = xfpm_settings_app_startup;
- gapplication_class->activate = xfpm_settings_app_activate;
+ gapplication_class->handle_local_options = xfpm_settings_app_local_options;
+ gapplication_class->startup = xfpm_settings_app_startup;
+ gapplication_class->activate = xfpm_settings_app_activate;
}
XfpmSettingsApp *
xfpm_settings_app_new (void)
{
- return g_object_new (XFPM_TYPE_SETTINGS_APP,
- "application-id", "org.xfce.PowerManager.Settings",
- "flags", G_APPLICATION_FLAGS_NONE,
- NULL);
+ return g_object_new (XFPM_TYPE_SETTINGS_APP,
+ "application-id", "org.xfce.PowerManager.Settings",
+ "flags", G_APPLICATION_FLAGS_NONE,
+ NULL);
}
diff --git a/settings/xfpm-settings-app.h b/settings/xfpm-settings-app.h
index b6517d3..9816d40 100644
--- a/settings/xfpm-settings-app.h
+++ b/settings/xfpm-settings-app.h
@@ -41,18 +41,17 @@ typedef struct _XfpmSettingsAppPrivate XfpmSettingsAppPrivate;
struct _XfpmSettingsApp
{
- GtkApplication parent;
- XfpmSettingsAppPrivate *priv;
+ GtkApplication parent;
+ XfpmSettingsAppPrivate *priv;
};
struct _XfpmSettingsAppClass
{
- GtkApplicationClass parent_class;
+ GtkApplicationClass parent_class;
};
GType xfpm_settings_app_get_type (void) G_GNUC_CONST;
-
XfpmSettingsApp *xfpm_settings_app_new (void);
diff --git a/settings/xfpm-settings-main.c b/settings/xfpm-settings-main.c
index 88c71c8..555b19c 100644
--- a/settings/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -38,8 +38,7 @@
int main (int argc, char **argv)
{
+ xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
- xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
-
- return g_application_run (G_APPLICATION (xfpm_settings_app_new ()), argc, argv);
+ return g_application_run (G_APPLICATION (xfpm_settings_app_new ()), argc, argv);
}
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 18498de..5e86a93 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -50,18 +50,18 @@
#include "xfpm-enum-glib.h"
#include "xfpm-enum.h"
-#define BRIGHTNESS_DISABLED 9
-
-static GtkApplication *app = NULL;
-static GtkBuilder *xml = NULL;
-static GtkWidget *nt = NULL;
-
-static GtkWidget *on_battery_display_blank = NULL;
-static GtkWidget *on_battery_dpms_sleep = NULL;
-static GtkWidget *on_battery_dpms_off = NULL;
-static GtkWidget *on_ac_display_blank = NULL;
-static GtkWidget *on_ac_dpms_sleep = NULL;
-static GtkWidget *on_ac_dpms_off = NULL;
+#define BRIGHTNESS_DISABLED 9
+
+static GtkApplication *app = NULL;
+static GtkBuilder *xml = NULL;
+static GtkWidget *nt = NULL;
+
+static GtkWidget *on_battery_display_blank = NULL;
+static GtkWidget *on_battery_dpms_sleep = NULL;
+static GtkWidget *on_battery_dpms_off = NULL;
+static GtkWidget *on_ac_display_blank = NULL;
+static GtkWidget *on_ac_dpms_sleep = NULL;
+static GtkWidget *on_ac_dpms_off = NULL;
static GtkWidget *sideview = NULL; /* Sidebar tree view - all devices are in the sideview */
static GtkWidget *device_details_notebook = NULL; /* Displays the details of a deivce */
@@ -96,566 +96,535 @@ static gint devices_page_num;
enum
{
- COL_SIDEBAR_ICON,
- COL_SIDEBAR_NAME,
- COL_SIDEBAR_INT,
- COL_SIDEBAR_BATTERY_DEVICE, /* Pointer to the UpDevice */
- COL_SIDEBAR_OBJECT_PATH, /* UpDevice object path */
- COL_SIDEBAR_SIGNAL_ID, /* device changed callback id */
- COL_SIDEBAR_VIEW, /* Pointer to GtkTreeView of the devcie details */
- NCOLS_SIDEBAR
+ COL_SIDEBAR_ICON,
+ COL_SIDEBAR_NAME,
+ COL_SIDEBAR_INT,
+ COL_SIDEBAR_BATTERY_DEVICE, /* Pointer to the UpDevice */
+ COL_SIDEBAR_OBJECT_PATH, /* UpDevice object path */
+ COL_SIDEBAR_SIGNAL_ID, /* device changed callback id */
+ COL_SIDEBAR_VIEW, /* Pointer to GtkTreeView of the devcie details */
+ NCOLS_SIDEBAR
};
enum
{
- XFPM_DEVICE_INFO_NAME,
- XFPM_DEVICE_INFO_VALUE,
- XFPM_DEVICE_INFO_LAST
+ XFPM_DEVICE_INFO_NAME,
+ XFPM_DEVICE_INFO_VALUE,
+ XFPM_DEVICE_INFO_LAST
};
/*
* GtkBuilder callbacks
*/
-void brightness_level_on_ac (GtkWidget *w,
- XfconfChannel *channel);
-
-void brightness_level_on_battery (GtkWidget *w,
- XfconfChannel *channel);
-
-void battery_critical_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void inactivity_on_ac_value_changed_cb (GtkWidget *widget,
- XfconfChannel *channel);
-
-void inactivity_on_battery_value_changed_cb (GtkWidget *widget,
- XfconfChannel *channel);
-
-void button_sleep_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void button_power_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void button_hibernate_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void button_battery_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void on_sleep_mode_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void dpms_toggled_cb (GtkWidget *w,
- gboolean is_active,
- XfconfChannel *channel);
-
-void sleep_on_battery_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void display_blank_on_battery_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void off_on_battery_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void display_blank_on_ac_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void sleep_on_ac_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void off_on_ac_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-gchar *format_dpms_value_cb (gint value);
-
-gchar *format_inactivity_value_cb (gint value);
-
-gchar *format_brightness_value_cb (gint value);
-
-gchar *format_brightness_percentage_cb (gint value);
-
-void brightness_on_battery_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void brightness_on_ac_value_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void on_battery_lid_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void on_ac_lid_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void critical_level_value_changed_cb (GtkSpinButton *w,
- XfconfChannel *channel);
-
-void lock_screen_toggled_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-static void view_cursor_changed_cb (GtkTreeView *view,
- gpointer *user_data);
-void on_ac_sleep_mode_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-void on_battery_sleep_mode_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
+void brightness_level_on_ac (GtkWidget *w,
+ XfconfChannel *channel);
+void brightness_level_on_battery (GtkWidget *w,
+ XfconfChannel *channel);
+void battery_critical_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void inactivity_on_ac_value_changed_cb (GtkWidget *widget,
+ XfconfChannel *channel);
+void inactivity_on_battery_value_changed_cb (GtkWidget *widget,
+ XfconfChannel *channel);
+void button_sleep_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void button_power_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void button_hibernate_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void button_battery_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void on_sleep_mode_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void dpms_toggled_cb (GtkWidget *w,
+ gboolean is_active,
+ XfconfChannel *channel);
+void sleep_on_battery_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void display_blank_on_battery_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void off_on_battery_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void display_blank_on_ac_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void sleep_on_ac_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void off_on_ac_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+gchar *format_dpms_value_cb (gint value);
+gchar *format_inactivity_value_cb (gint value);
+gchar *format_brightness_value_cb (gint value);
+gchar *format_brightness_percentage_cb (gint value);
+void brightness_on_battery_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void brightness_on_ac_value_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void on_battery_lid_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void on_ac_lid_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void critical_level_value_changed_cb (GtkSpinButton *w,
+ XfconfChannel *channel);
+void lock_screen_toggled_cb (GtkWidget *w,
+ XfconfChannel *channel);
+static void view_cursor_changed_cb (GtkTreeView *view,
+ gpointer *user_data);
+void on_ac_sleep_mode_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void on_battery_sleep_mode_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
/* Light Locker Integration */
-gchar *format_light_locker_value_cb (gint value);
-
+gchar *format_light_locker_value_cb (gint value);
void light_locker_late_locking_value_changed_cb (GtkWidget *w,
XfconfChannel *channel);
-
-void light_locker_automatic_locking_changed_cb (GtkWidget *w,
- XfconfChannel *channel);
-
-void xfpm_update_logind_handle_lid_switch (XfconfChannel *channel);
+void light_locker_automatic_locking_changed_cb (GtkWidget *w,
+ XfconfChannel *channel);
+void xfpm_update_logind_handle_lid_switch (XfconfChannel *channel);
/* END Light Locker Integration */
static void
update_label (GtkWidget *label, GtkWidget *scale, gchar* (*format)(gint))
{
- gint value = (gint) gtk_range_get_value (GTK_RANGE (scale));
+ gint value = (gint) gtk_range_get_value (GTK_RANGE (scale));
- gchar *formatted_value = format (value);
- gtk_label_set_text (GTK_LABEL (label), formatted_value);
- g_free (formatted_value);
+ gchar *formatted_value = format (value);
+ gtk_label_set_text (GTK_LABEL (label), formatted_value);
+ g_free (formatted_value);
}
void brightness_level_on_ac (GtkWidget *w, XfconfChannel *channel)
{
- guint val = (guint) gtk_range_get_value (GTK_RANGE (w));
+ guint val = (guint) gtk_range_get_value (GTK_RANGE (w));
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_AC, val) )
- {
- g_critical ("Unable to set value %u for property %s\n", val, BRIGHTNESS_LEVEL_ON_AC);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_AC, val) )
+ {
+ g_critical ("Unable to set value %u for property %s\n", val, BRIGHTNESS_LEVEL_ON_AC);
+ }
- update_label (label_brightness_level_on_ac, w, format_brightness_percentage_cb);
+ update_label (label_brightness_level_on_ac, w, format_brightness_percentage_cb);
}
void brightness_level_on_battery (GtkWidget *w, XfconfChannel *channel)
{
- guint val = (guint) gtk_range_get_value (GTK_RANGE (w));
+ guint val = (guint) gtk_range_get_value (GTK_RANGE (w));
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_BATTERY, val) )
- {
- g_critical ("Unable to set value %u for property %s\n", val, BRIGHTNESS_LEVEL_ON_BATTERY);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_BATTERY, val) )
+ {
+ g_critical ("Unable to set value %u for property %s\n", val, BRIGHTNESS_LEVEL_ON_BATTERY);
+ }
- update_label (label_brightness_level_on_battery, w, format_brightness_percentage_cb);
+ update_label (label_brightness_level_on_battery, w, format_brightness_percentage_cb);
}
void
battery_critical_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get(model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_BATT_ACTION_CFG, value) )
- {
- g_critical ("Cannot set value for property %s\n", CRITICAL_BATT_ACTION_CFG);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_BATT_ACTION_CFG, value) )
+ {
+ g_critical ("Cannot set value for property %s\n", CRITICAL_BATT_ACTION_CFG);
+ }
}
void
inactivity_on_ac_value_changed_cb (GtkWidget *widget, XfconfChannel *channel)
{
- gint value = (gint)gtk_range_get_value (GTK_RANGE (widget));
+ gint value = (gint)gtk_range_get_value (GTK_RANGE (widget));
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_INACTIVITY_TIMEOUT, value))
- {
- g_critical ("Cannot set value for property %s\n", ON_AC_INACTIVITY_TIMEOUT);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_INACTIVITY_TIMEOUT, value))
+ {
+ g_critical ("Cannot set value for property %s\n", ON_AC_INACTIVITY_TIMEOUT);
+ }
- update_label (label_inactivity_on_ac, widget, format_inactivity_value_cb);
+ update_label (label_inactivity_on_ac, widget, format_inactivity_value_cb);
}
void
inactivity_on_battery_value_changed_cb (GtkWidget *widget, XfconfChannel *channel)
{
- gint value = (gint)gtk_range_get_value (GTK_RANGE (widget));
+ gint value = (gint)gtk_range_get_value (GTK_RANGE (widget));
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_INACTIVITY_TIMEOUT, value))
- {
- g_critical ("Cannot set value for property %s\n", ON_BATTERY_INACTIVITY_TIMEOUT);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_INACTIVITY_TIMEOUT, value))
+ {
+ g_critical ("Cannot set value for property %s\n", ON_BATTERY_INACTIVITY_TIMEOUT);
+ }
- update_label (label_inactivity_on_battery, widget, format_inactivity_value_cb);
+ update_label (label_inactivity_on_battery, widget, format_inactivity_value_cb);
}
void
button_sleep_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get(model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX SLEEP_SWITCH_CFG, value ) )
- {
- g_critical ("Cannot set value for property %s\n", SLEEP_SWITCH_CFG);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX SLEEP_SWITCH_CFG, value ) )
+ {
+ g_critical ("Cannot set value for property %s\n", SLEEP_SWITCH_CFG);
+ }
}
void
button_power_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get(model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX POWER_SWITCH_CFG, value) )
- {
- g_critical ("Cannot set value for property %s\n", POWER_SWITCH_CFG);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX POWER_SWITCH_CFG, value) )
+ {
+ g_critical ("Cannot set value for property %s\n", POWER_SWITCH_CFG);
+ }
}
void
button_hibernate_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get (model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX HIBERNATE_SWITCH_CFG, value ) )
- {
- g_critical ("Cannot set value for property %s\n", HIBERNATE_SWITCH_CFG);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX HIBERNATE_SWITCH_CFG, value ) )
+ {
+ g_critical ("Cannot set value for property %s\n", HIBERNATE_SWITCH_CFG);
+ }
}
void
button_battery_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get (model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BATTERY_SWITCH_CFG, value ) )
- {
- g_critical ("Cannot set value for property %s\n", BATTERY_SWITCH_CFG);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BATTERY_SWITCH_CFG, value ) )
+ {
+ g_critical ("Cannot set value for property %s\n", BATTERY_SWITCH_CFG);
+ }
}
void
on_ac_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- guint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ guint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get(model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_AC, value) )
- {
- g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE_ON_AC);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_AC, value) )
+ {
+ g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE_ON_AC);
+ }
}
void
on_battery_sleep_mode_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- guint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ guint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get(model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_BATTERY, value) )
- {
- g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE_ON_BATTERY);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_BATTERY, value) )
+ {
+ g_critical ("Cannot set value for property %s\n", INACTIVITY_SLEEP_MODE_ON_BATTERY);
+ }
}
void
dpms_toggled_cb (GtkWidget *w, gboolean is_active, XfconfChannel *channel)
{
- xfconf_channel_set_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, is_active);
-
- gtk_widget_set_sensitive (on_ac_dpms_off, is_active);
- gtk_widget_set_sensitive (on_ac_dpms_sleep, is_active);
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-label")), is_active);
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-label")), is_active);
-
- if ( GTK_IS_WIDGET (on_battery_dpms_off ) )
- {
- gtk_widget_set_sensitive (on_battery_dpms_off, is_active);
- gtk_widget_set_sensitive (on_battery_dpms_sleep, is_active);
- }
+ xfconf_channel_set_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, is_active);
+
+ gtk_widget_set_sensitive (on_ac_dpms_off, is_active);
+ gtk_widget_set_sensitive (on_ac_dpms_sleep, is_active);
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-label")), is_active);
+ gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-label")), is_active);
+
+ if ( GTK_IS_WIDGET (on_battery_dpms_off ) )
+ {
+ gtk_widget_set_sensitive (on_battery_dpms_off, is_active);
+ gtk_widget_set_sensitive (on_battery_dpms_sleep, is_active);
+ }
}
void
display_blank_on_battery_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkWidget *brg;
- gint blank_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_display_blank));
- gint sleep_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_dpms_sleep));
- gint brightness_value;
+ GtkWidget *brg;
+ gint blank_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_display_blank));
+ gint sleep_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_dpms_sleep));
+ gint brightness_value;
- if ( sleep_value != 0 )
+ if ( sleep_value != 0 )
+ {
+ if ( blank_value >= sleep_value )
{
- if ( blank_value >= sleep_value )
- {
- gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), blank_value + 1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), blank_value + 1 );
}
+ }
- if ( lcd_brightness )
- {
- brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-battery"));
- brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
+ if ( lcd_brightness )
+ {
+ brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-battery"));
+ brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
- if ( blank_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
- {
- gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
- }
+ if ( blank_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
+ {
+ gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
}
+ }
- update_label (label_display_blank_on_battery, w, format_dpms_value_cb);
+ update_label (label_display_blank_on_battery, w, format_dpms_value_cb);
}
void
sleep_on_battery_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkWidget *brg;
- gint off_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_dpms_off));
- gint sleep_value = (gint) gtk_range_get_value (GTK_RANGE (w));
- gint blank_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_display_blank));
- gint brightness_value;
+ GtkWidget *brg;
+ gint off_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_dpms_off));
+ gint sleep_value = (gint) gtk_range_get_value (GTK_RANGE (w));
+ gint blank_value = (gint) gtk_range_get_value (GTK_RANGE (on_battery_display_blank));
+ gint brightness_value;
- if ( off_value != 0 )
+ if ( off_value != 0 )
+ {
+ if ( sleep_value >= off_value )
{
- if ( sleep_value >= off_value )
- {
- gtk_range_set_value (GTK_RANGE(on_battery_dpms_off), sleep_value + 1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_battery_dpms_off), sleep_value + 1 );
}
+ }
- if ( blank_value != 0 )
+ if ( blank_value != 0 )
+ {
+ if ( blank_value >= sleep_value )
{
- if ( blank_value >= sleep_value )
- {
- gtk_range_set_value (GTK_RANGE(on_battery_display_blank), sleep_value - 1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_battery_display_blank), sleep_value - 1 );
}
+ }
- if ( lcd_brightness )
- {
- brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-battery"));
- brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
-
- if ( sleep_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
- {
- gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
- }
- }
+ if ( lcd_brightness )
+ {
+ brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-battery"));
+ brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_SLEEP, sleep_value))
+ if ( sleep_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
{
- g_critical ("Cannot set value for property %s\n", ON_BATT_DPMS_SLEEP);
+ gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
}
+ }
- update_label (label_dpms_sleep_on_battery, w, format_dpms_value_cb);
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_SLEEP, sleep_value))
+ {
+ g_critical ("Cannot set value for property %s\n", ON_BATT_DPMS_SLEEP);
+ }
+
+ update_label (label_dpms_sleep_on_battery, w, format_dpms_value_cb);
}
void
off_on_battery_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- gint off_value = (gint)gtk_range_get_value (GTK_RANGE(w));
- gint sleep_value = (gint)gtk_range_get_value (GTK_RANGE(on_battery_dpms_sleep));
+ gint off_value = (gint)gtk_range_get_value (GTK_RANGE(w));
+ gint sleep_value = (gint)gtk_range_get_value (GTK_RANGE(on_battery_dpms_sleep));
- if ( sleep_value != 0 )
+ if ( sleep_value != 0 )
+ {
+ if ( off_value <= sleep_value )
{
- if ( off_value <= sleep_value )
- {
- gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), off_value -1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), off_value -1 );
}
+ }
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_OFF, off_value))
- {
- g_critical ("Cannot set value for property %s\n", ON_BATT_DPMS_OFF);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_OFF, off_value))
+ {
+ g_critical ("Cannot set value for property %s\n", ON_BATT_DPMS_OFF);
+ }
- update_label (label_dpms_off_on_battery, w, format_dpms_value_cb);
+ update_label (label_dpms_off_on_battery, w, format_dpms_value_cb);
}
void
display_blank_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkWidget *brg;
- gint blank_value = (gint) gtk_range_get_value (GTK_RANGE (on_ac_display_blank));
- gint sleep_value = (gint) gtk_range_get_value (GTK_RANGE (on_ac_dpms_sleep));
- gint brightness_value;
+ GtkWidget *brg;
+ gint blank_value = (gint) gtk_range_get_value (GTK_RANGE (on_ac_display_blank));
+ gint sleep_value = (gint) gtk_range_get_value (GTK_RANGE (on_ac_dpms_sleep));
+ gint brightness_value;
- if ( sleep_value != 0 )
+ if ( sleep_value != 0 )
+ {
+ if ( blank_value >= sleep_value )
{
- if ( blank_value >= sleep_value )
- {
- gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), blank_value + 1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), blank_value + 1 );
}
+ }
- if ( lcd_brightness )
- {
- brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-ac"));
- brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
+ if ( lcd_brightness )
+ {
+ brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-ac"));
+ brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
- if ( blank_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
- {
- gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
- }
+ if ( blank_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
+ {
+ gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
}
+ }
- update_label (label_display_blank_on_ac, w, format_dpms_value_cb);
+ update_label (label_display_blank_on_ac, w, format_dpms_value_cb);
}
void
sleep_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkWidget *brg;
+ GtkWidget *brg;
- gint brightness_value;
- gint off_value = (gint)gtk_range_get_value (GTK_RANGE (on_ac_dpms_off));
- gint sleep_value = (gint)gtk_range_get_value (GTK_RANGE (w));
- gint blank_value = (gint)gtk_range_get_value (GTK_RANGE (on_ac_display_blank));
+ gint brightness_value;
+ gint off_value = (gint)gtk_range_get_value (GTK_RANGE (on_ac_dpms_off));
+ gint sleep_value = (gint)gtk_range_get_value (GTK_RANGE (w));
+ gint blank_value = (gint)gtk_range_get_value (GTK_RANGE (on_ac_display_blank));
- if ( off_value > 60 || sleep_value > 60 )
- return;
+ if ( off_value > 60 || sleep_value > 60 )
+ return;
- if ( off_value != 0 )
+ if ( off_value != 0 )
+ {
+ if ( sleep_value >= off_value )
{
- if ( sleep_value >= off_value )
- {
- gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), sleep_value + 1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), sleep_value + 1 );
}
+ }
- if ( blank_value != 0 )
+ if ( blank_value != 0 )
+ {
+ if ( blank_value >= sleep_value )
{
- if ( blank_value >= sleep_value )
- {
- gtk_range_set_value (GTK_RANGE(on_ac_display_blank), sleep_value - 1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_ac_display_blank), sleep_value - 1 );
}
+ }
- if ( lcd_brightness )
- {
- brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-ac"));
+ if ( lcd_brightness )
+ {
+ brg = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-ac"));
- brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
+ brightness_value = (gint) gtk_range_get_value (GTK_RANGE (brg));
- if ( sleep_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
- {
- gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
- }
- }
-
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_SLEEP, sleep_value))
+ if ( sleep_value * 60 <= brightness_value && brightness_value != BRIGHTNESS_DISABLED)
{
- g_critical ("Cannot set value for property %s\n", ON_AC_DPMS_SLEEP);
+ gtk_range_set_value (GTK_RANGE (brg), BRIGHTNESS_DISABLED);
}
+ }
+
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_SLEEP, sleep_value))
+ {
+ g_critical ("Cannot set value for property %s\n", ON_AC_DPMS_SLEEP);
+ }
- update_label (label_dpms_sleep_on_ac, w, format_dpms_value_cb);
+ update_label (label_dpms_sleep_on_ac, w, format_dpms_value_cb);
}
void
off_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- gint off_value = (gint)gtk_range_get_value (GTK_RANGE(w));
- gint sleep_value = (gint)gtk_range_get_value (GTK_RANGE(on_ac_dpms_sleep));
+ gint off_value = (gint)gtk_range_get_value (GTK_RANGE(w));
+ gint sleep_value = (gint)gtk_range_get_value (GTK_RANGE(on_ac_dpms_sleep));
- if ( off_value > 60 || sleep_value > 60 )
- return;
+ if ( off_value > 60 || sleep_value > 60 )
+ return;
- if ( sleep_value != 0 )
+ if ( sleep_value != 0 )
+ {
+ if ( off_value <= sleep_value )
{
- if ( off_value <= sleep_value )
- {
- gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), off_value -1 );
- }
+ gtk_range_set_value (GTK_RANGE(on_ac_dpms_sleep), off_value -1 );
}
+ }
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_OFF, off_value))
- {
- g_critical ("Cannot set value for property %s\n", ON_AC_DPMS_OFF);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_OFF, off_value))
+ {
+ g_critical ("Cannot set value for property %s\n", ON_AC_DPMS_OFF);
+ }
- update_label (label_dpms_off_on_ac, w, format_dpms_value_cb);
+ update_label (label_dpms_off_on_ac, w, format_dpms_value_cb);
}
/*
@@ -664,40 +633,40 @@ off_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
gchar *
format_dpms_value_cb (gint value)
{
- if ( value == 0 )
- return g_strdup (_("Never"));
+ if ( value == 0 )
+ return g_strdup (_("Never"));
- if ( value == 1 )
- return g_strdup (_("One minute"));
+ if ( value == 1 )
+ return g_strdup (_("One minute"));
- return g_strdup_printf ("%d %s", value, _("minutes"));
+ return g_strdup_printf ("%d %s", value, _("minutes"));
}
gchar *
format_inactivity_value_cb (gint value)
{
- gint h, min;
-
- if ( value <= 14 )
- return g_strdup (_("Never"));
- else if ( value < 60 )
- return g_strdup_printf ("%d %s", value, _("minutes"));
- else if ( value == 60 )
- return g_strdup (_("One hour"));
-
- /* value > 60 */
- h = value/60;
- min = value%60;
-
- if ( h <= 1 )
- if ( min == 0 ) return g_strdup_printf ("%s", _("One hour"));
- else if ( min == 1 ) return g_strdup_printf ("%s %s", _("One hour"), _("one minute"));
- else return g_strdup_printf ("%s %d %s", _("One hour"), min, _("minutes"));
- else
- if ( min == 0 ) return g_strdup_printf ("%d %s", h, _("hours"));
- else if ( min == 1 ) return g_strdup_printf ("%d %s %s", h, _("hours"), _("one minute"));
- else return g_strdup_printf ("%d %s %d %s", h, _("hours"), min, _("minutes"));
+ gint h, min;
+
+ if ( value <= 14 )
+ return g_strdup (_("Never"));
+ else if ( value < 60 )
+ return g_strdup_printf ("%d %s", value, _("minutes"));
+ else if ( value == 60 )
+ return g_strdup (_("One hour"));
+
+ /* value > 60 */
+ h = value/60;
+ min = value%60;
+
+ if ( h <= 1 )
+ if ( min == 0 ) return g_strdup_printf ("%s", _("One hour"));
+ else if ( min == 1 ) return g_strdup_printf ("%s %s", _("One hour"), _("one minute"));
+ else return g_strdup_printf ("%s %d %s", _("One hour"), min, _("minutes"));
+ else
+ if ( min == 0 ) return g_strdup_printf ("%d %s", h, _("hours"));
+ else if ( min == 1 ) return g_strdup_printf ("%d %s %s", h, _("hours"), _("one minute"));
+ else return g_strdup_printf ("%d %s %d %s", h, _("hours"), min, _("minutes"));
}
/*
@@ -706,162 +675,162 @@ format_inactivity_value_cb (gint value)
gchar *
format_brightness_value_cb (gint value)
{
- if ( value <= 9 )
- return g_strdup (_("Never"));
+ if ( value <= 9 )
+ return g_strdup (_("Never"));
- return g_strdup_printf ("%d %s", value, _("seconds"));
+ return g_strdup_printf ("%d %s", value, _("seconds"));
}
gchar *
format_brightness_percentage_cb (gint value)
{
- return g_strdup_printf ("%d %s", value, _("%"));
+ return g_strdup_printf ("%d %s", value, _("%"));
}
void
brightness_on_battery_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- gint value = (gint)gtk_range_get_value (GTK_RANGE (w));
- gint dpms_sleep = (gint) gtk_range_get_value (GTK_RANGE (on_battery_dpms_sleep) );
+ gint value = (gint)gtk_range_get_value (GTK_RANGE (w));
+ gint dpms_sleep = (gint) gtk_range_get_value (GTK_RANGE (on_battery_dpms_sleep) );
- if ( value != BRIGHTNESS_DISABLED )
+ if ( value != BRIGHTNESS_DISABLED )
+ {
+ if ( dpms_sleep != 0 && dpms_sleep * 60 <= value)
{
- if ( dpms_sleep != 0 && dpms_sleep * 60 <= value)
- {
- gtk_range_set_value (GTK_RANGE (on_battery_dpms_sleep), (value / 60) + 1);
- }
+ gtk_range_set_value (GTK_RANGE (on_battery_dpms_sleep), (value / 60) + 1);
}
+ }
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_BATTERY, value))
- {
- g_critical ("Cannot set value for property %s\n", BRIGHTNESS_ON_BATTERY);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_BATTERY, value))
+ {
+ g_critical ("Cannot set value for property %s\n", BRIGHTNESS_ON_BATTERY);
+ }
- update_label (label_brightness_inactivity_on_battery, w, format_brightness_value_cb);
+ update_label (label_brightness_inactivity_on_battery, w, format_brightness_value_cb);
}
void
brightness_on_ac_value_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- gint value = (gint)gtk_range_get_value (GTK_RANGE (w));
- gint dpms_sleep = (gint) gtk_range_get_value (GTK_RANGE (on_ac_dpms_sleep) );
+ gint value = (gint)gtk_range_get_value (GTK_RANGE (w));
+ gint dpms_sleep = (gint) gtk_range_get_value (GTK_RANGE (on_ac_dpms_sleep) );
- if ( value != BRIGHTNESS_DISABLED )
+ if ( value != BRIGHTNESS_DISABLED )
+ {
+ if ( dpms_sleep != 0 && dpms_sleep * 60 <= value)
{
- if ( dpms_sleep != 0 && dpms_sleep * 60 <= value)
- {
- gtk_range_set_value (GTK_RANGE (on_ac_dpms_sleep), (value / 60) + 1);
- }
+ gtk_range_set_value (GTK_RANGE (on_ac_dpms_sleep), (value / 60) + 1);
}
+ }
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_AC, value))
- {
- g_critical ("Cannot set value for property %s\n", BRIGHTNESS_ON_AC);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_AC, value))
+ {
+ g_critical ("Cannot set value for property %s\n", BRIGHTNESS_ON_AC);
+ }
- update_label (label_brightness_inactivity_on_ac, w, format_brightness_value_cb);
+ update_label (label_brightness_inactivity_on_ac, w, format_brightness_value_cb);
}
void
on_battery_lid_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get (model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, value) )
- {
- g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_BATTERY_CFG);
- }
- xfpm_update_logind_handle_lid_switch (channel);
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, value) )
+ {
+ g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_BATTERY_CFG);
+ }
+ xfpm_update_logind_handle_lid_switch (channel);
}
void
on_ac_lid_changed_cb (GtkWidget *w, XfconfChannel *channel)
{
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint value = 0;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint value = 0;
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
- return;
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &selected_row))
+ return;
- model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX(w));
- gtk_tree_model_get(model,
- &selected_row,
- 1,
- &value,
- -1);
+ gtk_tree_model_get (model,
+ &selected_row,
+ 1,
+ &value,
+ -1);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, value) )
- {
- g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_AC_CFG);
- }
- xfpm_update_logind_handle_lid_switch (channel);
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, value) )
+ {
+ g_critical ("Cannot set value for property %s\n", LID_SWITCH_ON_AC_CFG);
+ }
+ xfpm_update_logind_handle_lid_switch (channel);
}
void
critical_level_value_changed_cb (GtkSpinButton *w, XfconfChannel *channel)
{
- guint val = (guint) gtk_spin_button_get_value (w);
+ guint val = (guint) gtk_spin_button_get_value (w);
- if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_POWER_LEVEL, val) )
- {
- g_critical ("Unable to set value %d for property %s\n", val, CRITICAL_POWER_LEVEL);
- }
+ if (!xfconf_channel_set_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_POWER_LEVEL, val) )
+ {
+ g_critical ("Unable to set value %d for property %s\n", val, CRITICAL_POWER_LEVEL);
+ }
}
void
lock_screen_toggled_cb (GtkWidget *w, XfconfChannel *channel)
{
- XfconfChannel *session_channel = xfconf_channel_get ("xfce4-session");
- gboolean val = (gint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
-
- if ( !xfconf_channel_set_bool (session_channel, "/shutdown/LockScreen", val) )
- {
- g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
- }
-
- if ( !xfconf_channel_set_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, val) )
- {
- g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
- }
-
- /* Light Locker Integration */
- if ( light_locker_settings )
- {
- GVariant *variant;
- variant = g_variant_new_boolean (val);
- if (!g_settings_set_value (light_locker_settings, "lock-on-suspend", variant))
- g_critical ("Cannot set value for property lock-on-suspend\n");
+ XfconfChannel *session_channel = xfconf_channel_get ("xfce4-session");
+ gboolean val = (gint) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
+
+ if ( !xfconf_channel_set_bool (session_channel, "/shutdown/LockScreen", val) )
+ {
+ g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
+ }
+
+ if ( !xfconf_channel_set_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, val) )
+ {
+ g_critical ("Unable to set value for property %s\n", LOCK_SCREEN_ON_SLEEP);
+ }
+
+ /* Light Locker Integration */
+ if ( light_locker_settings )
+ {
+ GVariant *variant;
+ variant = g_variant_new_boolean (val);
+ if (!g_settings_set_value (light_locker_settings, "lock-on-suspend", variant))
+ g_critical ("Cannot set value for property lock-on-suspend\n");
- xfpm_update_logind_handle_lid_switch (channel);
- }
- /* END Light Locker Integration */
+ xfpm_update_logind_handle_lid_switch (channel);
+ }
+ /* END Light Locker Integration */
}
/* Light Locker Integration */
void
xfpm_update_logind_handle_lid_switch (XfconfChannel *channel)
{
- gboolean lock_on_suspend = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
- guint lid_switch_on_ac = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, LID_TRIGGER_LOCK_SCREEN);
- guint lid_switch_on_battery = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, LID_TRIGGER_LOCK_SCREEN);
+ gboolean lock_on_suspend = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
+ guint lid_switch_on_ac = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, LID_TRIGGER_LOCK_SCREEN);
+ guint lid_switch_on_battery = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, LID_TRIGGER_LOCK_SCREEN);
- // logind-handle-lid-switch = true when: lock_on_suspend == true and (lid_switch_on_ac == suspend or lid_switch_on_battery == suspend)
- xfconf_channel_set_bool (channel, XFPM_PROPERTIES_PREFIX LOGIND_HANDLE_LID_SWITCH, lock_on_suspend && (lid_switch_on_ac == 1 || lid_switch_on_battery == 1));
+ // logind-handle-lid-switch = true when: lock_on_suspend == true and (lid_switch_on_ac == suspend or lid_switch_on_battery == suspend)
+ xfconf_channel_set_bool (channel, XFPM_PROPERTIES_PREFIX LOGIND_HANDLE_LID_SWITCH, lock_on_suspend && (lid_switch_on_ac == 1 || lid_switch_on_battery == 1));
}
/* END Light Locker Integration */
@@ -871,236 +840,236 @@ xfpm_settings_on_battery (XfconfChannel *channel, gboolean auth_suspend,
gboolean can_hibernate, gboolean can_shutdown,
gboolean has_lcd_brightness, gboolean has_lid)
{
- gboolean valid, handle_dpms;
- gint list_value;
- gint val;
- GtkListStore *list_store;
- GtkTreeIter iter;
- GtkWidget *inact_timeout, *inact_action;
- GtkWidget *battery_critical;
- GtkWidget *lid;
- GtkWidget *brg;
- GtkWidget *brg_level;
-
- /*
- * Inactivity sleep mode on battery
- */
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- inact_action = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode-on-battery"));
- gtk_combo_box_set_model (GTK_COMBO_BOX(inact_action), GTK_TREE_MODEL(list_store));
-
- if ( can_suspend )
- {
+ gboolean valid, handle_dpms;
+ gint list_value;
+ gint val;
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+ GtkWidget *inact_timeout, *inact_action;
+ GtkWidget *battery_critical;
+ GtkWidget *lid;
+ GtkWidget *brg;
+ GtkWidget *brg_level;
+
+ /*
+ * Inactivity sleep mode on battery
+ */
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ inact_action = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode-on-battery"));
+ gtk_combo_box_set_model (GTK_COMBO_BOX(inact_action), GTK_TREE_MODEL(list_store));
+
+ if ( can_suspend )
+ {
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
- else if ( !auth_suspend )
- {
+ }
+ else if ( !auth_suspend )
+ {
gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not permitted"));
- }
- else
- {
+ }
+ else
+ {
gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not supported"));
- }
+ }
- if ( can_hibernate )
- {
+ if ( can_hibernate )
+ {
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
- else if ( !auth_hibernate )
- {
+ }
+ else if ( !auth_hibernate )
+ {
gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not permitted"));
- }
- else
- {
+ }
+ else
+ {
gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not supported"));
- }
+ }
- gtk_combo_box_set_active (GTK_COMBO_BOX (inact_action), 0);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (inact_action), 0);
- val = xfconf_channel_get_uint (channel,
- XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_BATTERY,
- XFPM_DO_HIBERNATE);
+ val = xfconf_channel_get_uint (channel,
+ XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_BATTERY,
+ XFPM_DO_HIBERNATE);
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( val == list_value )
{
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( val == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (inact_action), &iter);
- break;
- }
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (inact_action), &iter);
+ break;
}
+ }
- /*
- * Inactivity timeout on battery
- */
- inact_timeout = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-battery"));
+ /*
+ * Inactivity timeout on battery
+ */
+ inact_timeout = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-battery"));
- if ( !can_suspend && !can_hibernate )
- {
+ if ( !can_suspend && !can_hibernate )
+ {
gtk_widget_set_sensitive (inact_timeout, FALSE);
gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not supported"));
- }
- else if ( !auth_suspend && !auth_hibernate )
- {
+ }
+ else if ( !auth_suspend && !auth_hibernate )
+ {
gtk_widget_set_sensitive (inact_timeout, FALSE);
gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not permitted"));
- }
+ }
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_INACTIVITY_TIMEOUT, 14);
- gtk_range_set_value (GTK_RANGE (inact_timeout), val);
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_INACTIVITY_TIMEOUT, 14);
+ gtk_range_set_value (GTK_RANGE (inact_timeout), val);
- /*
- * Battery critical
- */
- battery_critical = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-action-combo"));
+ /*
+ * Battery critical
+ */
+ battery_critical = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-action-combo"));
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- gtk_combo_box_set_model (GTK_COMBO_BOX(battery_critical), GTK_TREE_MODEL(list_store));
+ gtk_combo_box_set_model (GTK_COMBO_BOX(battery_critical), GTK_TREE_MODEL(list_store));
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
- if ( can_suspend && auth_suspend )
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate )
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
+ if ( can_suspend && auth_suspend )
+ {
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
+ }
- if ( can_shutdown )
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
- }
+ if ( can_hibernate && auth_hibernate )
+ {
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
+ }
+ if ( can_shutdown )
+ {
gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+ gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
+ }
+
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_BATT_ACTION_CFG, XFPM_DO_NOTHING);
+
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( val == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (battery_critical), &iter);
+ break;
+ }
+ }
+
+ /*
+ * DPMS settings when running on battery power
+ */
+ handle_dpms = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, TRUE);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_SLEEP, 5);
+ gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), val);
+ gtk_widget_set_sensitive (on_battery_dpms_sleep, handle_dpms);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_OFF, 10);
+ gtk_range_set_value (GTK_RANGE(on_battery_dpms_off), val);
+ gtk_widget_set_sensitive (on_battery_dpms_off, handle_dpms);
+
+ /*
+ * Lid switch settings on battery
+ */
+ lid = GTK_WIDGET (gtk_builder_get_object (xml, "lid-on-battery-combo"));
+ if ( has_lid )
+ {
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_BATT_ACTION_CFG, XFPM_DO_NOTHING);
+ gtk_combo_box_set_model (GTK_COMBO_BOX(lid), GTK_TREE_MODEL(list_store));
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Switch off display"), 1, LID_TRIGGER_NOTHING, -1);
+
+ if ( can_suspend && auth_suspend )
{
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( val == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (battery_critical), &iter);
- break;
- }
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, LID_TRIGGER_SUSPEND, -1);
}
- /*
- * DPMS settings when running on battery power
- */
- handle_dpms = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, TRUE);
+ if ( can_hibernate && auth_hibernate)
+ {
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, LID_TRIGGER_HIBERNATE, -1);
+ }
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_SLEEP, 5);
- gtk_range_set_value (GTK_RANGE(on_battery_dpms_sleep), val);
- gtk_widget_set_sensitive (on_battery_dpms_sleep, handle_dpms);
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Lock screen"), 1, LID_TRIGGER_LOCK_SCREEN, -1);
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATT_DPMS_OFF, 10);
- gtk_range_set_value (GTK_RANGE(on_battery_dpms_off), val);
- gtk_widget_set_sensitive (on_battery_dpms_off, handle_dpms);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (lid), 0);
- /*
- * Lid switch settings on battery
- */
- lid = GTK_WIDGET (gtk_builder_get_object (xml, "lid-on-battery-combo"));
- if ( has_lid )
- {
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
-
- gtk_combo_box_set_model (GTK_COMBO_BOX(lid), GTK_TREE_MODEL(list_store));
-
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Switch off display"), 1, LID_TRIGGER_NOTHING, -1);
-
- if ( can_suspend && auth_suspend )
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, LID_TRIGGER_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate)
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, LID_TRIGGER_HIBERNATE, -1);
- }
-
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Lock screen"), 1, LID_TRIGGER_LOCK_SCREEN, -1);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (lid), 0);
-
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, LID_TRIGGER_LOCK_SCREEN);
-
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( val == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (lid), &iter);
- break;
- }
- }
- }
- else
- {
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-action-label")));
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-on-battery-header")));
- gtk_widget_hide (lid);
- }
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_BATTERY_CFG, LID_TRIGGER_LOCK_SCREEN);
- /*
- * Brightness on battery
- */
- brg = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-inactivity-on-battery"));
- brg_level = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-level-on-battery"));
- if ( has_lcd_brightness )
- {
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( val == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (lid), &iter);
+ break;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-action-label")));
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-on-battery-header")));
+ gtk_widget_hide (lid);
+ }
+
+ /*
+ * Brightness on battery
+ */
+ brg = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-inactivity-on-battery"));
+ brg_level = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-level-on-battery"));
+ if ( has_lcd_brightness )
+ {
val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_BATTERY, 120);
gtk_range_set_value (GTK_RANGE(brg), val);
val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_BATTERY, 20);
gtk_range_set_value (GTK_RANGE (brg_level), val);
- }
- else
- {
+ }
+ else
+ {
gtk_widget_hide (brg);
gtk_widget_hide (brg_level);
- }
-
- label_inactivity_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-battery-label"));
- label_display_blank_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-battery-label"));
- label_dpms_sleep_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-battery-label"));
- label_dpms_off_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-battery-label"));
- label_brightness_level_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-level-on-battery-label"));
- label_brightness_inactivity_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-battery-label"));
-
- update_label (label_inactivity_on_battery, inact_timeout, format_inactivity_value_cb);
- update_label (label_display_blank_on_battery, on_battery_display_blank, format_dpms_value_cb);
- update_label (label_dpms_sleep_on_battery, on_battery_dpms_sleep, format_dpms_value_cb);
- update_label (label_dpms_off_on_battery, on_battery_dpms_off, format_dpms_value_cb);
- update_label (label_brightness_level_on_battery, brg_level, format_brightness_percentage_cb);
- update_label (label_brightness_inactivity_on_battery, brg, format_brightness_value_cb);
+ }
+
+ label_inactivity_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-battery-label"));
+ label_display_blank_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-battery-label"));
+ label_dpms_sleep_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-battery-label"));
+ label_dpms_off_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-battery-label"));
+ label_brightness_level_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-level-on-battery-label"));
+ label_brightness_inactivity_on_battery = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-battery-label"));
+
+ update_label (label_inactivity_on_battery, inact_timeout, format_inactivity_value_cb);
+ update_label (label_display_blank_on_battery, on_battery_display_blank, format_dpms_value_cb);
+ update_label (label_dpms_sleep_on_battery, on_battery_dpms_sleep, format_dpms_value_cb);
+ update_label (label_dpms_off_on_battery, on_battery_dpms_off, format_dpms_value_cb);
+ update_label (label_brightness_level_on_battery, brg_level, format_brightness_percentage_cb);
+ update_label (label_brightness_inactivity_on_battery, brg, format_brightness_value_cb);
}
static void
@@ -1109,186 +1078,185 @@ xfpm_settings_on_ac (XfconfChannel *channel, gboolean auth_suspend,
gboolean can_hibernate, gboolean has_lcd_brightness,
gboolean has_lid)
{
- gboolean valid, handle_dpms;
- GtkWidget *inact_timeout, *inact_action;
- GtkWidget *lid;
- GtkWidget *brg;
- GtkWidget *brg_level;
- GtkListStore *list_store;
- GtkTreeIter iter;
- guint val;
- guint list_value;
-
- /*
- * Inactivity sleep mode on AC
- */
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- inact_action = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode-on-ac"));
- gtk_combo_box_set_model (GTK_COMBO_BOX(inact_action), GTK_TREE_MODEL(list_store));
-
- if ( can_suspend )
- {
+ gboolean valid, handle_dpms;
+ GtkWidget *inact_timeout, *inact_action;
+ GtkWidget *lid;
+ GtkWidget *brg;
+ GtkWidget *brg_level;
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+ guint val;
+ guint list_value;
+
+ /*
+ * Inactivity sleep mode on AC
+ */
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ inact_action = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-mode-on-ac"));
+ gtk_combo_box_set_model (GTK_COMBO_BOX(inact_action), GTK_TREE_MODEL(list_store));
+
+ if ( can_suspend )
+ {
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
- else if ( !auth_suspend )
- {
+ }
+ else if ( !auth_suspend )
+ {
gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not permitted"));
- }
- else
- {
+ }
+ else
+ {
gtk_widget_set_tooltip_text (inact_action, _("Suspend operation not supported"));
- }
+ }
- if ( can_hibernate )
- {
+ if ( can_hibernate )
+ {
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
- else if ( !auth_hibernate )
- {
+ }
+ else if ( !auth_hibernate )
+ {
gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not permitted"));
- }
- else
- {
+ }
+ else
+ {
gtk_widget_set_tooltip_text (inact_action, _("Hibernate operation not supported"));
- }
+ }
- gtk_combo_box_set_active (GTK_COMBO_BOX (inact_action), 0);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (inact_action), 0);
- val = xfconf_channel_get_uint (channel,
- XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_AC,
- XFPM_DO_SUSPEND);
+ val = xfconf_channel_get_uint (channel,
+ XFPM_PROPERTIES_PREFIX INACTIVITY_SLEEP_MODE_ON_AC,
+ XFPM_DO_SUSPEND);
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( val == list_value )
{
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( val == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (inact_action), &iter);
- break;
- }
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (inact_action), &iter);
+ break;
}
+ }
- /*
- * Inactivity timeout on AC
- */
- inact_timeout = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-ac"));
+ /*
+ * Inactivity timeout on AC
+ */
+ inact_timeout = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-ac"));
- if ( !can_suspend && !can_hibernate )
- {
+ if ( !can_suspend && !can_hibernate )
+ {
gtk_widget_set_sensitive (inact_timeout, FALSE);
gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not supported"));
- }
- else if ( !auth_suspend && !auth_hibernate )
- {
+ }
+ else if ( !auth_suspend && !auth_hibernate )
+ {
gtk_widget_set_sensitive (inact_timeout, FALSE);
gtk_widget_set_tooltip_text (inact_timeout, _("Hibernate and suspend operations not permitted"));
- }
-
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_INACTIVITY_TIMEOUT, 14);
- gtk_range_set_value (GTK_RANGE (inact_timeout), val);
-
- /*
- * DPMS settings when running on AC power
- */
- handle_dpms = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, TRUE);
+ }
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_INACTIVITY_TIMEOUT, 14);
+ gtk_range_set_value (GTK_RANGE (inact_timeout), val);
+
+ /*
+ * DPMS settings when running on AC power
+ */
+ handle_dpms = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, TRUE);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_SLEEP, 10);
+ gtk_range_set_value (GTK_RANGE (on_ac_dpms_sleep), val);
+ gtk_widget_set_sensitive (on_ac_dpms_sleep, handle_dpms);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_OFF, 15);
+ gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), val);
+ gtk_widget_set_sensitive (on_ac_dpms_off, handle_dpms);
+
+ /*
+ * Lid switch settings on AC power
+ */
+ lid = GTK_WIDGET (gtk_builder_get_object (xml, "lid-on-ac-combo"));
+ if ( has_lid )
+ {
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_SLEEP, 10);
- gtk_range_set_value (GTK_RANGE (on_ac_dpms_sleep), val);
- gtk_widget_set_sensitive (on_ac_dpms_sleep, handle_dpms);
+ gtk_combo_box_set_model (GTK_COMBO_BOX(lid), GTK_TREE_MODEL(list_store));
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_AC_DPMS_OFF, 15);
- gtk_range_set_value (GTK_RANGE(on_ac_dpms_off), val);
- gtk_widget_set_sensitive (on_ac_dpms_off, handle_dpms);
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Switch off display"), 1, LID_TRIGGER_NOTHING, -1);
- /*
- * Lid switch settings on AC power
- */
- lid = GTK_WIDGET (gtk_builder_get_object (xml, "lid-on-ac-combo"));
- if ( has_lid )
+ if ( can_suspend && auth_suspend )
{
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
-
- gtk_combo_box_set_model (GTK_COMBO_BOX(lid), GTK_TREE_MODEL(list_store));
-
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Switch off display"), 1, LID_TRIGGER_NOTHING, -1);
-
- if ( can_suspend && auth_suspend )
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, LID_TRIGGER_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate )
- {
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, LID_TRIGGER_HIBERNATE, -1);
- }
-
- gtk_list_store_append(list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Lock screen"), 1, LID_TRIGGER_LOCK_SCREEN, -1);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (lid), 0);
-
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, LID_TRIGGER_LOCK_SCREEN);
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( val == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (lid), &iter);
- break;
- }
- }
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, LID_TRIGGER_SUSPEND, -1);
}
- else
+
+ if ( can_hibernate && auth_hibernate )
{
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-action-label1")));
- gtk_widget_hide (lid);
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-plugged-in-header")));
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, LID_TRIGGER_HIBERNATE, -1);
}
- /*
- * Brightness on AC power
- */
- brg = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-inactivity-on-ac"));
- brg_level = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-level-on-ac"));
- if ( has_lcd_brightness )
- {
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_AC, 9);
- gtk_range_set_value (GTK_RANGE(brg), val);
-
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_AC, 80);
- gtk_range_set_value (GTK_RANGE (brg_level), val);
-
- }
- else
- {
- gtk_widget_hide (brg);
- gtk_widget_hide (brg_level);
- }
-
- label_inactivity_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-ac-label"));
- label_display_blank_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-ac-label"));
- label_dpms_sleep_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-ac-label"));
- label_dpms_off_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-ac-label"));
- label_brightness_level_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-level-on-ac-label"));
- label_brightness_inactivity_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-ac-label"));
-
- update_label (label_inactivity_on_ac, inact_timeout, format_inactivity_value_cb);
- update_label (label_display_blank_on_ac, on_ac_display_blank, format_dpms_value_cb);
- update_label (label_dpms_sleep_on_ac, on_ac_dpms_sleep, format_dpms_value_cb);
- update_label (label_dpms_off_on_ac, on_ac_dpms_off, format_dpms_value_cb);
- update_label (label_brightness_level_on_ac, brg_level, format_brightness_percentage_cb);
- update_label (label_brightness_inactivity_on_ac, brg, format_brightness_value_cb);
+ gtk_list_store_append(list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Lock screen"), 1, LID_TRIGGER_LOCK_SCREEN, -1);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (lid), 0);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX LID_SWITCH_ON_AC_CFG, LID_TRIGGER_LOCK_SCREEN);
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( val == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (lid), &iter);
+ break;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-action-label1")));
+ gtk_widget_hide (lid);
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "lid-plugged-in-header")));
+ }
+
+ /*
+ * Brightness on AC power
+ */
+ brg = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-inactivity-on-ac"));
+ brg_level = GTK_WIDGET (gtk_builder_get_object (xml ,"brightness-level-on-ac"));
+ if ( has_lcd_brightness )
+ {
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_ON_AC, 9);
+ gtk_range_set_value (GTK_RANGE(brg), val);
+
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BRIGHTNESS_LEVEL_ON_AC, 80);
+ gtk_range_set_value (GTK_RANGE (brg_level), val);
+ }
+ else
+ {
+ gtk_widget_hide (brg);
+ gtk_widget_hide (brg_level);
+ }
+
+ label_inactivity_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "system-sleep-inactivity-on-ac-label"));
+ label_display_blank_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-ac-label"));
+ label_dpms_sleep_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-ac-label"));
+ label_dpms_off_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-ac-label"));
+ label_brightness_level_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-level-on-ac-label"));
+ label_brightness_inactivity_on_ac = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-inactivity-on-ac-label"));
+
+ update_label (label_inactivity_on_ac, inact_timeout, format_inactivity_value_cb);
+ update_label (label_display_blank_on_ac, on_ac_display_blank, format_dpms_value_cb);
+ update_label (label_dpms_sleep_on_ac, on_ac_dpms_sleep, format_dpms_value_cb);
+ update_label (label_dpms_off_on_ac, on_ac_dpms_off, format_dpms_value_cb);
+ update_label (label_brightness_level_on_ac, brg_level, format_brightness_percentage_cb);
+ update_label (label_brightness_inactivity_on_ac, brg, format_brightness_value_cb);
}
static void
@@ -1298,242 +1266,243 @@ xfpm_settings_general (XfconfChannel *channel, gboolean auth_suspend,
gboolean has_sleep_button, gboolean has_hibernate_button,
gboolean has_power_button, gboolean has_battery_button)
{
- GtkWidget *power;
- GtkWidget *power_label;
- GtkWidget *hibernate;
- GtkWidget *hibernate_label;
- GtkWidget *sleep_w;
- GtkWidget *sleep_label;
- GtkWidget *battery_w;
- GtkWidget *battery_label;
- GtkWidget *dpms;
-
- guint value;
- guint list_value;
- gboolean valid;
- gboolean val;
-
- GtkListStore *list_store;
- GtkTreeIter iter;
-
- dpms = GTK_WIDGET (gtk_builder_get_object (xml, "handle-dpms"));
-
- /*
- * Global dpms settings (enable/disable)
- */
- val = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, TRUE);
- gtk_switch_set_state (GTK_SWITCH (dpms), val);
-
- /*
- * Power button
- */
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- power = GTK_WIDGET (gtk_builder_get_object (xml, "button-power-combo"));
- power_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-power-label"));
+ GtkWidget *power;
+ GtkWidget *power_label;
+ GtkWidget *hibernate;
+ GtkWidget *hibernate_label;
+ GtkWidget *sleep_w;
+ GtkWidget *sleep_label;
+ GtkWidget *battery_w;
+ GtkWidget *battery_label;
+ GtkWidget *dpms;
+
+ guint value;
+ guint list_value;
+ gboolean valid;
+ gboolean val;
+
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+
+ dpms = GTK_WIDGET (gtk_builder_get_object (xml, "handle-dpms"));
+
+ /*
+ * Global dpms settings (enable/disable)
+ */
+ val = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX DPMS_ENABLED_CFG, TRUE);
+ gtk_switch_set_state (GTK_SWITCH (dpms), val);
+
+ /*
+ * Power button
+ */
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ power = GTK_WIDGET (gtk_builder_get_object (xml, "button-power-combo"));
+ power_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-power-label"));
+
+ if ( has_power_button )
+ {
+ gtk_combo_box_set_model (GTK_COMBO_BOX(power), GTK_TREE_MODEL(list_store));
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
- if ( has_power_button )
+ if ( can_suspend && auth_suspend)
{
- gtk_combo_box_set_model (GTK_COMBO_BOX(power), GTK_TREE_MODEL(list_store));
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
-
- if ( can_suspend && auth_suspend)
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate )
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
-
- if ( can_shutdown )
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
- }
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (power), 0);
-
- value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX POWER_SWITCH_CFG, XFPM_DO_NOTHING);
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( value == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (power), &iter);
- break;
- }
- }
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
}
- else
+
+ if ( can_hibernate && auth_hibernate )
{
- gtk_widget_hide (power);
- gtk_widget_hide (power_label);
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
}
- /*
- * Hibernate button
- */
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- hibernate = GTK_WIDGET (gtk_builder_get_object (xml, "button-hibernate-combo"));
- hibernate_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-hibernate-label"));
+ if ( can_shutdown )
+ {
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Shutdown"), 1, XFPM_DO_SHUTDOWN, -1);
+ }
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (power), 0);
+
+ value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX POWER_SWITCH_CFG, XFPM_DO_NOTHING);
+
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( value == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (power), &iter);
+ break;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (power);
+ gtk_widget_hide (power_label);
+ }
+
+ /*
+ * Hibernate button
+ */
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ hibernate = GTK_WIDGET (gtk_builder_get_object (xml, "button-hibernate-combo"));
+ hibernate_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-hibernate-label"));
+
+ if (has_hibernate_button )
+ {
+ gtk_combo_box_set_model (GTK_COMBO_BOX(hibernate), GTK_TREE_MODEL(list_store));
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
- if (has_hibernate_button )
+ if ( can_suspend && auth_suspend)
{
- gtk_combo_box_set_model (GTK_COMBO_BOX(hibernate), GTK_TREE_MODEL(list_store));
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
-
- if ( can_suspend && auth_suspend)
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate )
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
-
- value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX HIBERNATE_SWITCH_CFG, XFPM_DO_NOTHING);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (hibernate), 0);
-
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( value == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (hibernate), &iter);
- break;
- }
- }
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
}
- else
+
+ if ( can_hibernate && auth_hibernate )
{
- gtk_widget_hide (hibernate);
- gtk_widget_hide (hibernate_label);
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
}
- /*
- * Sleep button
- */
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- sleep_w = GTK_WIDGET (gtk_builder_get_object (xml, "button-sleep-combo"));
- sleep_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-sleep-label"));
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+
+ value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX HIBERNATE_SWITCH_CFG, XFPM_DO_NOTHING);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (hibernate), 0);
+
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( value == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (hibernate), &iter);
+ break;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (hibernate);
+ gtk_widget_hide (hibernate_label);
+ }
+
+ /*
+ * Sleep button
+ */
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ sleep_w = GTK_WIDGET (gtk_builder_get_object (xml, "button-sleep-combo"));
+ sleep_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-sleep-label"));
+
+ if ( has_sleep_button )
+ {
+ gtk_combo_box_set_model (GTK_COMBO_BOX(sleep_w), GTK_TREE_MODEL(list_store));
- if ( has_sleep_button )
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
+
+ if ( can_suspend && auth_suspend )
{
- gtk_combo_box_set_model (GTK_COMBO_BOX(sleep_w), GTK_TREE_MODEL(list_store));
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
-
- if ( can_suspend && auth_suspend )
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate)
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (sleep_w), 0);
-
- value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX SLEEP_SWITCH_CFG, XFPM_DO_NOTHING);
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( value == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (sleep_w), &iter);
- break;
- }
- }
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
}
- else
+
+ if ( can_hibernate && auth_hibernate)
{
- gtk_widget_hide (sleep_w);
- gtk_widget_hide (sleep_label);
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
}
- /*
- * Battery button
- */
- list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
- battery_w = GTK_WIDGET (gtk_builder_get_object (xml, "button-battery-combo"));
- battery_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-battery-label"));
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (sleep_w), 0);
+
+ value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX SLEEP_SWITCH_CFG, XFPM_DO_NOTHING);
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( value == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (sleep_w), &iter);
+ break;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (sleep_w);
+ gtk_widget_hide (sleep_label);
+ }
+
+ /*
+ * Battery button
+ */
+ list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
+ battery_w = GTK_WIDGET (gtk_builder_get_object (xml, "button-battery-combo"));
+ battery_label = GTK_WIDGET (gtk_builder_get_object (xml, "button-battery-label"));
+
+ if ( has_battery_button )
+ {
+ gtk_combo_box_set_model (GTK_COMBO_BOX(battery_w), GTK_TREE_MODEL(list_store));
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
- if ( has_battery_button )
+ if ( can_suspend && auth_suspend )
{
- gtk_combo_box_set_model (GTK_COMBO_BOX(battery_w), GTK_TREE_MODEL(list_store));
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Do nothing"), 1, XFPM_DO_NOTHING, -1);
-
- if ( can_suspend && auth_suspend )
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
- }
-
- if ( can_hibernate && auth_hibernate)
- {
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
- }
-
- gtk_list_store_append (list_store, &iter);
- gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (battery_w), 0);
-
- value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BATTERY_SWITCH_CFG, XFPM_DO_NOTHING);
- for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
- valid;
- valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
- {
- gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
- 1, &list_value, -1);
- if ( value == list_value )
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (battery_w), &iter);
- break;
- }
- }
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Suspend"), 1, XFPM_DO_SUSPEND, -1);
}
- else
+
+ if ( can_hibernate && auth_hibernate)
{
- gtk_widget_hide (battery_w);
- gtk_widget_hide (battery_label);
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Hibernate"), 1, XFPM_DO_HIBERNATE, -1);
}
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter, 0, _("Ask"), 1, XFPM_ASK, -1);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (battery_w), 0);
+
+ value = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX BATTERY_SWITCH_CFG, XFPM_DO_NOTHING);
+ for ( valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter) )
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter,
+ 1, &list_value, -1);
+ if ( value == list_value )
+ {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (battery_w), &iter);
+ break;
+ }
+ }
+ }
+ else
+ {
+ gtk_widget_hide (battery_w);
+ gtk_widget_hide (battery_label);
+ }
}
static void
@@ -1541,234 +1510,246 @@ xfpm_settings_advanced (XfconfChannel *channel, gboolean auth_suspend,
gboolean auth_hibernate, gboolean can_suspend,
gboolean can_hibernate, gboolean has_battery)
{
- guint val;
- GtkWidget *critical_level;
- GtkWidget *lock;
- GtkWidget *label;
-
- /*
- * Critical battery level
- */
- critical_level = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-level-spin"));
- if ( has_battery )
- {
- gtk_widget_set_tooltip_text (critical_level,
- _("When all the power sources of the computer reach this charge level"));
-
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_POWER_LEVEL, 10);
-
- if ( val > 20 || val < 1)
- {
- g_critical ("Value %d if out of range for property %s\n", val, CRITICAL_POWER_LEVEL);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON(critical_level), 10);
- }
- else
- gtk_spin_button_set_value (GTK_SPIN_BUTTON(critical_level), val);
- }
- else
- {
- label = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-level-label" ));
- gtk_widget_hide (critical_level);
- gtk_widget_hide (label);
- }
+ guint val;
+ GtkWidget *critical_level;
+ GtkWidget *lock;
+ GtkWidget *label;
- /*
- * Lock screen for suspend/hibernate
- */
- lock = GTK_WIDGET (gtk_builder_get_object (xml, "lock-screen"));
+ /*
+ * Critical battery level
+ */
+ critical_level = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-level-spin"));
+ if ( has_battery )
+ {
+ gtk_widget_set_tooltip_text (critical_level,
+ _("When all the power sources of the computer reach this charge level"));
- if ( !can_suspend && !can_hibernate )
- {
- gtk_widget_set_sensitive (lock, FALSE);
- gtk_widget_set_tooltip_text (lock, _("Hibernate and suspend operations not supported"));
- }
- else if ( !auth_hibernate && !auth_suspend)
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX CRITICAL_POWER_LEVEL, 10);
+
+ if ( val > 20 || val < 1)
{
- gtk_widget_set_sensitive (lock, FALSE);
- gtk_widget_set_tooltip_text (lock, _("Hibernate and suspend operations not permitted"));
+ g_critical ("Value %d if out of range for property %s\n", val, CRITICAL_POWER_LEVEL);
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON(critical_level), 10);
}
-
- val = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(lock), val);
+ else
+ gtk_spin_button_set_value (GTK_SPIN_BUTTON(critical_level), val);
+ }
+ else
+ {
+ label = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-level-label" ));
+ gtk_widget_hide (critical_level);
+ gtk_widget_hide (label);
+ }
+
+ /*
+ * Lock screen for suspend/hibernate
+ */
+ lock = GTK_WIDGET (gtk_builder_get_object (xml, "lock-screen"));
+
+ if ( !can_suspend && !can_hibernate )
+ {
+ gtk_widget_set_sensitive (lock, FALSE);
+ gtk_widget_set_tooltip_text (lock, _("Hibernate and suspend operations not supported"));
+ }
+ else if ( !auth_hibernate && !auth_suspend)
+ {
+ gtk_widget_set_sensitive (lock, FALSE);
+ gtk_widget_set_tooltip_text (lock, _("Hibernate and suspend operations not permitted"));
+ }
+
+ val = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(lock), val);
}
/* Light Locker Integration */
static gchar*
get_light_locker_path (void)
{
- gchar** paths = NULL;
- gchar* path = NULL;
- unsigned int i = 0;
-
- /* Check if executable in path */
- paths = g_strsplit(g_getenv("PATH"), ":", 0);
- for (i = 0; i < g_strv_length(paths); i++) {
- path = g_strdup(g_build_filename(paths[i], "light-locker", NULL));
- if (g_file_test(path, G_FILE_TEST_EXISTS))
- {
- break;
- }
- g_free(path);
- path = NULL;
+ gchar** paths = NULL;
+ gchar* path = NULL;
+ unsigned int i = 0;
+
+ /* Check if executable is in path */
+ paths = g_strsplit (g_getenv ("PATH"), ":", 0);
+ for (i = 0; i < g_strv_length (paths); i++) {
+ path = g_strdup (g_build_filename (paths[i], "light-locker", NULL));
+ if (g_file_test (path, G_FILE_TEST_EXISTS))
+ {
+ break;
}
- g_strfreev(paths);
+ g_free (path);
+ path = NULL;
+ }
+ g_strfreev (paths);
- return path;
+ return path;
}
gchar *
format_light_locker_value_cb (gint value)
{
- gint min;
+ gint min;
- if ( value <= 0 )
- return g_strdup (_("Never"));
- else if ( value < 60 )
- return g_strdup_printf ("%d %s", value, _("seconds"));
+ if ( value <= 0 )
+ return g_strdup (_("Never"));
+ else if ( value < 60 )
+ return g_strdup_printf ("%d %s", value, _("seconds"));
+ else
+ {
+ min = value - 60;
+ if (min == 0)
+ return g_strdup_printf ("%d %s", min + 1, _("minute"));
else
- {
- min = value - 60;
- if (min == 0)
- return g_strdup_printf ("%d %s", min + 1, _("minute"));
- else
- return g_strdup_printf ("%d %s", min + 1, _("minutes"));
- }
+ return g_strdup_printf ("%d %s", min + 1, _("minutes"));
+ }
}
void
light_locker_late_locking_value_changed_cb (GtkWidget *widget, XfconfChannel *channel)
{
- GVariant *variant;
- gint value = (gint)gtk_range_get_value (GTK_RANGE (widget));
+ GVariant *variant;
+ gint value = (gint)gtk_range_get_value (GTK_RANGE (widget));
- if (value > 60) {
- value = ((value - 60) + 1) * 60;
- }
+ if (value > 60) {
+ value = ((value - 60) + 1) * 60;
+ }
- variant = g_variant_new_uint32 (value);
+ variant = g_variant_new_uint32 (value);
- if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
- {
- g_critical ("Cannot set value for property lock-after-screensaver\n");
- }
+ if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
+ {
+ g_critical ("Cannot set value for property lock-after-screensaver\n");
+ }
- update_label (label_light_locker_late_locking_scale, widget, format_light_locker_value_cb);
+ update_label (label_light_locker_late_locking_scale, widget, format_light_locker_value_cb);
}
void
light_locker_automatic_locking_changed_cb (GtkWidget *widget, XfconfChannel *channel)
{
- GVariant *variant;
- gint value;
- gint lock_after_screensaver;
- gboolean late_locking = FALSE;
-
- value = gtk_combo_box_get_active (GTK_COMBO_BOX(widget));
- gtk_widget_set_sensitive (light_locker_delay, value != 0);
-
- if (value == 0)
- lock_after_screensaver = 0;
- else {
- lock_after_screensaver = (gint)gtk_range_get_value (GTK_RANGE (light_locker_delay));
- if (lock_after_screensaver > 60) {
- lock_after_screensaver = (lock_after_screensaver - 60) * 60;
- }
+ GVariant *variant;
+ gint value;
+ gint lock_after_screensaver;
+ gboolean late_locking = FALSE;
+
+ value = gtk_combo_box_get_active (GTK_COMBO_BOX(widget));
+ gtk_widget_set_sensitive (light_locker_delay, value != 0);
+
+ if (value == 0)
+ lock_after_screensaver = 0;
+ else {
+ lock_after_screensaver = (gint)gtk_range_get_value (GTK_RANGE (light_locker_delay));
+ if (lock_after_screensaver > 60) {
+ lock_after_screensaver = (lock_after_screensaver - 60) * 60;
}
+ }
- if (value == 2)
- late_locking = TRUE;
+ if (value == 2)
+ late_locking = TRUE;
- variant = g_variant_new_uint32 (lock_after_screensaver);
- if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
- g_critical ("Cannot set value for property lock-after-screensaver\n");
+ variant = g_variant_new_uint32 (lock_after_screensaver);
+ if (!g_settings_set_value (light_locker_settings, "lock-after-screensaver", variant))
+ g_critical ("Cannot set value for property lock-after-screensaver\n");
- variant = g_variant_new_boolean (late_locking);
- if (!g_settings_set_value (light_locker_settings, "late-locking", variant))
- g_critical ("Cannot set value for property late-locking\n");
+ variant = g_variant_new_boolean (late_locking);
+ if (!g_settings_set_value (light_locker_settings, "late-locking", variant))
+ g_critical ("Cannot set value for property late-locking\n");
}
static void xfpm_settings_light_locker (XfconfChannel *channel,
gboolean auth_suspend, gboolean auth_hibernate,
gboolean can_suspend, gboolean can_hibernate)
{
- GSettingsSchemaSource *schema_source;
- GSettingsSchema *schema;
- GVariant *variant;
- gboolean late_locking, lock_on_suspend, xfpm_lock_on_suspend;
- guint32 lock_after_screensaver;
- GtkWidget *security_frame;
-
- /* Collect the Light Locker widgets */
- light_locker_tab = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-vbox1"));
- light_locker_autolock = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-automatic-locking-combo"));
- light_locker_delay = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-late-locking-scale"));
- light_locker_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-suspend"));
-
- if ( !can_suspend && !can_hibernate )
+ GSettingsSchemaSource *schema_source;
+ GSettingsSchema *schema;
+ GVariant *variant;
+ gboolean late_locking, lock_on_suspend, xfpm_lock_on_suspend;
+ guint32 lock_after_screensaver;
+ GtkWidget *security_frame;
+
+ /* Collect the Light Locker widgets */
+ light_locker_tab = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-vbox1"));
+ light_locker_autolock = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-automatic-locking-combo"));
+ light_locker_delay = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-late-locking-scale"));
+ light_locker_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-suspend"));
+
+ if ( !can_suspend && !can_hibernate )
+ {
+ gtk_widget_set_sensitive (light_locker_sleep, FALSE);
+ gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not supported"));
+ }
+ else if ( !auth_hibernate && !auth_suspend)
+ {
+ gtk_widget_set_sensitive (light_locker_sleep, FALSE);
+ gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not permitted"));
+ }
+
+ schema_source = g_settings_schema_source_get_default();
+ schema = g_settings_schema_source_lookup (schema_source, "apps.light-locker", TRUE);
+
+ if (schema != NULL && get_light_locker_path() != NULL)
+ {
+ security_frame = GTK_WIDGET (gtk_builder_get_object (xml, "security-frame"));
+ gtk_widget_hide (security_frame);
+ /* Load the settings (Light Locker compiled with GSettings backend required) */
+ light_locker_settings = g_settings_new ("apps.light-locker");
+
+ variant = g_settings_get_value (light_locker_settings, "late-locking");
+ late_locking = g_variant_get_boolean (variant);
+
+ variant = g_settings_get_value (light_locker_settings, "lock-on-suspend");
+ lock_on_suspend = g_variant_get_boolean (variant);
+ xfpm_lock_on_suspend = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
+ if (lock_on_suspend != xfpm_lock_on_suspend)
{
- gtk_widget_set_sensitive (light_locker_sleep, FALSE);
- gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not supported"));
+ variant = g_variant_new_boolean (xfpm_lock_on_suspend);
+ if (!g_settings_set_value (light_locker_settings, "lock-on-suspend", variant))
+ {
+ g_critical ("Cannot set value for property lock-on-suspend\n");
+ }
+ lock_on_suspend = xfpm_lock_on_suspend;
}
- else if ( !auth_hibernate && !auth_suspend)
+
+ variant = g_settings_get_value (light_locker_settings, "lock-after-screensaver");
+ lock_after_screensaver = g_variant_get_uint32 (variant);
+
+ gtk_widget_set_sensitive (light_locker_delay, lock_after_screensaver != 0);
+
+ if (lock_after_screensaver > 60)
{
- gtk_widget_set_sensitive (light_locker_sleep, FALSE);
- gtk_widget_set_tooltip_text (light_locker_sleep, _("Hibernate and suspend operations not permitted"));
+ lock_after_screensaver = (lock_after_screensaver / 60) + 60;
}
- schema_source = g_settings_schema_source_get_default();
- schema = g_settings_schema_source_lookup (schema_source, "apps.light-locker", TRUE);
-
- if (schema != NULL && get_light_locker_path() != NULL) {
- security_frame = GTK_WIDGET (gtk_builder_get_object (xml, "security-frame"));
- gtk_widget_hide(security_frame);
- /* Load the settings (Light Locker compiled with GSettings backend required) */
- light_locker_settings = g_settings_new ("apps.light-locker");
-
- variant = g_settings_get_value (light_locker_settings, "late-locking");
- late_locking = g_variant_get_boolean (variant);
-
- variant = g_settings_get_value (light_locker_settings, "lock-on-suspend");
- lock_on_suspend = g_variant_get_boolean (variant);
- xfpm_lock_on_suspend = xfconf_channel_get_bool (channel, XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP, TRUE);
- if (lock_on_suspend != xfpm_lock_on_suspend) {
- variant = g_variant_new_boolean (xfpm_lock_on_suspend);
- if (!g_settings_set_value (light_locker_settings, "lock-on-suspend", variant)) {
- g_critical ("Cannot set value for property lock-on-suspend\n");
- }
- lock_on_suspend = xfpm_lock_on_suspend;
- }
-
- variant = g_settings_get_value (light_locker_settings, "lock-after-screensaver");
- lock_after_screensaver = g_variant_get_uint32 (variant);
-
- gtk_widget_set_sensitive (light_locker_delay, lock_after_screensaver != 0);
-
- if (lock_after_screensaver > 60) {
- lock_after_screensaver = (lock_after_screensaver / 60) + 60;
- }
-
- /* Apply the settings */
- if (lock_after_screensaver == 0) {
- gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 0);
- } else {
- if (!late_locking) {
- gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 1);
- } else {
- gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 2);
- }
- gtk_range_set_value (GTK_RANGE(light_locker_delay), lock_after_screensaver);
- }
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(light_locker_sleep), lock_on_suspend);
-
- g_settings_schema_unref (schema);
- } else {
- XFPM_DEBUG ("Schema \"apps.light-locker\" not found. Not configuring Light Locker.");
- gtk_widget_hide (light_locker_tab);
+ /* Apply the settings */
+ if (lock_after_screensaver == 0)
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 0);
}
-
- label_light_locker_late_locking_scale = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-late-locking-scale-label"));
- update_label (label_light_locker_late_locking_scale, light_locker_delay, format_light_locker_value_cb);
+ else
+ {
+ if (!late_locking)
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 1);
+ }
+ else
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX(light_locker_autolock), 2);
+ }
+ gtk_range_set_value (GTK_RANGE(light_locker_delay), lock_after_screensaver);
+ }
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(light_locker_sleep), lock_on_suspend);
+
+ g_settings_schema_unref (schema);
+ }
+ else
+ {
+ XFPM_DEBUG ("Schema \"apps.light-locker\" not found. Not configuring Light Locker.");
+ gtk_widget_hide (light_locker_tab);
+ }
+
+ label_light_locker_late_locking_scale = GTK_WIDGET (gtk_builder_get_object (xml, "light-locker-late-locking-scale-label"));
+ update_label (label_light_locker_late_locking_scale, light_locker_delay, format_light_locker_value_cb);
}
/* END Light Locker Integration */
@@ -1776,74 +1757,76 @@ static void xfpm_settings_light_locker (XfconfChannel *channel,
static GtkTreeIter*
find_device_in_tree (const gchar *object_path)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
- if ( !sideview )
- return NULL;
+ if ( !sideview )
+ return NULL;
- model = gtk_tree_view_get_model(GTK_TREE_VIEW(sideview));
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(sideview));
- if (!model)
- return NULL;
+ if (!model)
+ return NULL;
- if(gtk_tree_model_get_iter_first(model, &iter)) {
- do {
- gchar *path = NULL;
- gtk_tree_model_get(model, &iter, COL_SIDEBAR_OBJECT_PATH, &path, -1);
+ if(gtk_tree_model_get_iter_first(model, &iter))
+ {
+ do {
+ gchar *path = NULL;
+ gtk_tree_model_get(model, &iter, COL_SIDEBAR_OBJECT_PATH, &path, -1);
- if(g_strcmp0(path, object_path) == 0) {
- g_free(path);
- return gtk_tree_iter_copy(&iter);
- }
+ if(g_strcmp0(path, object_path) == 0)
+ {
+ g_free(path);
+ return gtk_tree_iter_copy(&iter);
+ }
- g_free(path);
- } while(gtk_tree_model_iter_next(model, &iter));
- }
+ g_free (path);
+ } while (gtk_tree_model_iter_next(model, &iter));
+ }
- return NULL;
+ return NULL;
}
/* Call gtk_tree_iter_free when done with the tree iter */
static GtkTreeIter*
find_device_info_name_in_tree (GtkTreeView *view, const gchar *device_info_name)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
- if ( !view )
- return NULL;
+ if ( !view )
+ return NULL;
- model = gtk_tree_view_get_model(view);
+ model = gtk_tree_view_get_model (view);
- if (!model)
- return NULL;
+ if (!model)
+ return NULL;
- if(gtk_tree_model_get_iter_first(model, &iter)) {
- do {
- gchar *name = NULL;
- gtk_tree_model_get(model, &iter, XFPM_DEVICE_INFO_NAME, &name, -1);
+ if (gtk_tree_model_get_iter_first (model, &iter)) {
+ do {
+ gchar *name = NULL;
+ gtk_tree_model_get (model, &iter, XFPM_DEVICE_INFO_NAME, &name, -1);
- if(g_strcmp0(name, device_info_name) == 0) {
- g_free(name);
- return gtk_tree_iter_copy(&iter);
- }
+ if(g_strcmp0 (name, device_info_name) == 0) {
+ g_free (name);
+ return gtk_tree_iter_copy (&iter);
+ }
- g_free(name);
- } while(gtk_tree_model_iter_next(model, &iter));
- }
+ g_free (name);
+ } while(gtk_tree_model_iter_next(model, &iter));
+ }
- return NULL;
+ return NULL;
}
static gchar *
xfpm_info_get_energy_property (gdouble energy, const gchar *unit)
{
- gchar *val = NULL;
+ gchar *val = NULL;
- val = g_strdup_printf ("%.1f %s", energy, unit);
+ val = g_strdup_printf ("%.1f %s", energy, unit);
- return val;
+ return val;
}
static void
@@ -1852,232 +1835,232 @@ update_device_info_value_for_name (GtkTreeView *view,
const gchar *name,
const gchar *value)
{
- GtkTreeIter *iter;
-
- g_return_if_fail (GTK_IS_TREE_VIEW(view));
- g_return_if_fail (GTK_IS_LIST_STORE(list_store));
- g_return_if_fail (name != NULL);
- /* Value can be NULL */
-
- DBG ("updating name %s with value %s", name, value);
-
- iter = find_device_info_name_in_tree (view, name);
- if (iter == NULL)
- {
- /* The row doesn't exist yet, add it */
- GtkTreeIter new_iter;
- gtk_list_store_append (list_store, &new_iter);
- iter = gtk_tree_iter_copy (&new_iter);
- }
-
- if (value != NULL)
- {
- gtk_list_store_set (list_store, iter,
- XFPM_DEVICE_INFO_NAME, name,
- XFPM_DEVICE_INFO_VALUE, value,
- -1);
- }
- else
- {
- /* The value no longer applies, remove the row */
- gtk_list_store_remove (list_store, iter);
- }
+ GtkTreeIter *iter;
+
+ g_return_if_fail (GTK_IS_TREE_VIEW(view));
+ g_return_if_fail (GTK_IS_LIST_STORE(list_store));
+ g_return_if_fail (name != NULL);
+ /* Value can be NULL */
+
+ DBG ("updating name %s with value %s", name, value);
+
+ iter = find_device_info_name_in_tree (view, name);
+ if (iter == NULL)
+ {
+ /* The row doesn't exist yet, add it */
+ GtkTreeIter new_iter;
+ gtk_list_store_append (list_store, &new_iter);
+ iter = gtk_tree_iter_copy (&new_iter);
+ }
+
+ if (value != NULL)
+ {
+ gtk_list_store_set (list_store, iter,
+ XFPM_DEVICE_INFO_NAME, name,
+ XFPM_DEVICE_INFO_VALUE, value,
+ -1);
+ }
+ else
+ {
+ /* The value no longer applies, remove the row */
+ gtk_list_store_remove (list_store, iter);
+ }
- gtk_tree_iter_free (iter);
+ gtk_tree_iter_free (iter);
}
static void
update_sideview_icon (UpDevice *device)
{
- GtkListStore *list_store;
- GtkTreeIter *iter;
- GdkPixbuf *pix;
- guint type = 0;
- gchar *name = NULL, *icon_name = NULL, *model = NULL, *vendor = NULL;
- const gchar *object_path = up_device_get_object_path(device);
+ GtkListStore *list_store;
+ GtkTreeIter *iter;
+ GdkPixbuf *pix;
+ guint type = 0;
+ gchar *name = NULL, *icon_name = NULL, *model = NULL, *vendor = NULL;
+ const gchar *object_path = up_device_get_object_path(device);
- list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (sideview)));
+ list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (sideview)));
- TRACE("entering for %s", object_path);
+ TRACE("entering for %s", object_path);
- iter = find_device_in_tree (object_path);
+ iter = find_device_in_tree (object_path);
- /* quit if device doesn't exist in the sidebar */
- if (!iter)
- return;
+ /* quit if device doesn't exist in the sidebar */
+ if (!iter)
+ return;
- /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
- g_object_get (device,
- "kind", &type,
- "vendor", &vendor,
- "model", &model,
- NULL);
+ /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
+ g_object_get (device,
+ "kind", &type,
+ "vendor", &vendor,
+ "model", &model,
+ NULL);
- name = get_device_description (upower, device);
- icon_name = get_device_icon_name (upower, device);
+ name = get_device_description (upower, device);
+ icon_name = get_device_icon_name (upower, device);
- pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
- icon_name,
- 48,
- GTK_ICON_LOOKUP_USE_BUILTIN,
- NULL);
+ pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+ icon_name,
+ 48,
+ GTK_ICON_LOOKUP_USE_BUILTIN,
+ NULL);
- gtk_list_store_set (list_store, iter,
- COL_SIDEBAR_ICON, pix,
- COL_SIDEBAR_NAME, name,
- -1);
+ gtk_list_store_set (list_store, iter,
+ COL_SIDEBAR_ICON, pix,
+ COL_SIDEBAR_NAME, name,
+ -1);
- if ( pix )
- g_object_unref (pix);
+ if ( pix )
+ g_object_unref (pix);
- g_free (name);
- g_free (icon_name);
+ g_free (name);
+ g_free (icon_name);
- gtk_tree_iter_free (iter);
+ gtk_tree_iter_free (iter);
}
static void
update_device_details (UpDevice *device)
{
- GtkTreeView *view;
- GtkListStore *list_store;
- GtkTreeIter *sideview_iter;
- gchar *str;
- guint type = 0, tech = 0;
- gdouble energy_full_design = -1.0, energy_full = -1.0, energy_empty = -1.0, voltage = -1.0, percent = -1.0;
- gboolean p_supply = FALSE;
- gchar *model = NULL, *vendor = NULL, *serial = NULL;
- const gchar *battery_type = NULL;
- const gchar *object_path = up_device_get_object_path(device);
-
- TRACE("entering for %s", object_path);
-
- sideview_iter = find_device_in_tree (object_path);
-
- /* quit if device doesn't exist in the sidebar */
- if (sideview_iter == NULL)
- return;
-
- gtk_tree_model_get (gtk_tree_view_get_model(GTK_TREE_VIEW(sideview)), sideview_iter,
- COL_SIDEBAR_VIEW, &view,
- -1);
+ GtkTreeView *view;
+ GtkListStore *list_store;
+ GtkTreeIter *sideview_iter;
+ gchar *str;
+ guint type = 0, tech = 0;
+ gdouble energy_full_design = -1.0, energy_full = -1.0, energy_empty = -1.0, voltage = -1.0, percent = -1.0;
+ gboolean p_supply = FALSE;
+ gchar *model = NULL, *vendor = NULL, *serial = NULL;
+ const gchar *battery_type = NULL;
+ const gchar *object_path = up_device_get_object_path(device);
+
+ TRACE("entering for %s", object_path);
+
+ sideview_iter = find_device_in_tree (object_path);
+
+ /* quit if device doesn't exist in the sidebar */
+ if (sideview_iter == NULL)
+ return;
- list_store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
-
- /**
- * Add/Update Device information:
- **/
- /*Device*/
- update_device_info_value_for_name (view,
- list_store,
- _("Device"),
- g_str_has_prefix (object_path, UPOWER_PATH_DEVICE) ? object_path + strlen (UPOWER_PATH_DEVICE) : object_path);
-
- /*Type*/
- /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
- g_object_get (device,
- "kind", &type,
- "power-supply", &p_supply,
- "model", &model,
- "vendor", &vendor,
- "serial", &serial,
- "technology", &tech,
- "energy-full-design", &energy_full_design,
- "energy-full", &energy_full,
- "energy-empty", &energy_empty,
- "voltage", &voltage,
- "percentage", &percent,
- NULL);
-
- if (type != UP_DEVICE_KIND_UNKNOWN)
- {
- battery_type = xfpm_power_translate_device_type (type);
- update_device_info_value_for_name (view, list_store, _("Type"), battery_type);
- }
+ gtk_tree_model_get (gtk_tree_view_get_model (GTK_TREE_VIEW(sideview)), sideview_iter,
+ COL_SIDEBAR_VIEW, &view,
+ -1);
+
+ list_store = GTK_LIST_STORE (gtk_tree_view_get_model (view));
+
+ /**
+ * Add/Update Device information:
+ **/
+ /*Device*/
+ update_device_info_value_for_name (view,
+ list_store,
+ _("Device"),
+ g_str_has_prefix (object_path, UPOWER_PATH_DEVICE) ? object_path + strlen (UPOWER_PATH_DEVICE) : object_path);
+
+ /*Type*/
+ /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
+ g_object_get (device,
+ "kind", &type,
+ "power-supply", &p_supply,
+ "model", &model,
+ "vendor", &vendor,
+ "serial", &serial,
+ "technology", &tech,
+ "energy-full-design", &energy_full_design,
+ "energy-full", &energy_full,
+ "energy-empty", &energy_empty,
+ "voltage", &voltage,
+ "percentage", &percent,
+ NULL);
+
+ if (type != UP_DEVICE_KIND_UNKNOWN)
+ {
+ battery_type = xfpm_power_translate_device_type (type);
+ update_device_info_value_for_name (view, list_store, _("Type"), battery_type);
+ }
- update_device_info_value_for_name (view,
- list_store,
- _("PowerSupply"),
- p_supply == TRUE ? _("True") : _("False"));
+ update_device_info_value_for_name (view,
+ list_store,
+ _("PowerSupply"),
+ p_supply == TRUE ? _("True") : _("False"));
- if ( type != UP_DEVICE_KIND_LINE_POWER )
+ if ( type != UP_DEVICE_KIND_LINE_POWER )
+ {
+ /*Model*/
+ if (model && strlen (model) > 0)
{
- /*Model*/
- if (model && strlen (model) > 0)
- {
- update_device_info_value_for_name (view, list_store, _("Model"), model);
- }
+ update_device_info_value_for_name (view, list_store, _("Model"), model);
+ }
- update_device_info_value_for_name (view, list_store, _("Technology"), xfpm_power_translate_technology (tech));
+ update_device_info_value_for_name (view, list_store, _("Technology"), xfpm_power_translate_technology (tech));
- /*Percentage*/
- if (percent >= 0)
- {
- str = g_strdup_printf("%d%%", (guint) percent);
+ /*Percentage*/
+ if (percent >= 0)
+ {
+ str = g_strdup_printf("%d%%", (guint) percent);
- update_device_info_value_for_name (view, list_store, _("Current charge"), str);
+ update_device_info_value_for_name (view, list_store, _("Current charge"), str);
- g_free(str);
- }
+ g_free(str);
+ }
- if (energy_full_design > 0)
- {
- /* TRANSLATORS: Unit here is Watt hour*/
- str = xfpm_info_get_energy_property (energy_full_design, _("Wh"));
+ if (energy_full_design > 0)
+ {
+ /* TRANSLATORS: Unit here is Watt hour*/
+ str = xfpm_info_get_energy_property (energy_full_design, _("Wh"));
- update_device_info_value_for_name (view, list_store, _("Fully charged (design)"), str);
+ update_device_info_value_for_name (view, list_store, _("Fully charged (design)"), str);
- g_free (str);
- }
+ g_free (str);
+ }
- if (energy_full > 0)
- {
- gchar *str2;
+ if (energy_full > 0)
+ {
+ gchar *str2;
- /* TRANSLATORS: Unit here is Watt hour*/
- str = xfpm_info_get_energy_property (energy_full, _("Wh"));
- str2 = g_strdup_printf ("%s (%d%%)", str, (guint) (energy_full / energy_full_design *100));
+ /* TRANSLATORS: Unit here is Watt hour*/
+ str = xfpm_info_get_energy_property (energy_full, _("Wh"));
+ str2 = g_strdup_printf ("%s (%d%%)", str, (guint) (energy_full / energy_full_design *100));
- update_device_info_value_for_name (view, list_store, _("Fully charged"), str2);
+ update_device_info_value_for_name (view, list_store, _("Fully charged"), str2);
- g_free (str);
- g_free (str2);
- }
+ g_free (str);
+ g_free (str2);
+ }
- if (energy_empty > 0)
- {
- /* TRANSLATORS: Unit here is Watt hour*/
- str = xfpm_info_get_energy_property (energy_empty, _("Wh"));
+ if (energy_empty > 0)
+ {
+ /* TRANSLATORS: Unit here is Watt hour*/
+ str = xfpm_info_get_energy_property (energy_empty, _("Wh"));
- update_device_info_value_for_name (view, list_store, _("Energy empty"), str);
+ update_device_info_value_for_name (view, list_store, _("Energy empty"), str);
- g_free (str);
- }
+ g_free (str);
+ }
- if (voltage > 0)
- {
- /* TRANSLATORS: Unit here is Volt*/
- str = xfpm_info_get_energy_property (voltage, _("V"));
+ if (voltage > 0)
+ {
+ /* TRANSLATORS: Unit here is Volt*/
+ str = xfpm_info_get_energy_property (voltage, _("V"));
- update_device_info_value_for_name (view, list_store, _("Voltage"), str);
+ update_device_info_value_for_name (view, list_store, _("Voltage"), str);
- g_free (str);
- }
+ g_free (str);
+ }
- if (vendor && strlen (vendor) > 0)
- {
- update_device_info_value_for_name (view, list_store, _("Vendor"), vendor);
- }
+ if (vendor && strlen (vendor) > 0)
+ {
+ update_device_info_value_for_name (view, list_store, _("Vendor"), vendor);
+ }
- if (serial && strlen (serial) > 0)
- {
- update_device_info_value_for_name (view, list_store, _("Serial"), serial);
- }
+ if (serial && strlen (serial) > 0)
+ {
+ update_device_info_value_for_name (view, list_store, _("Serial"), serial);
}
+ }
- update_sideview_icon (device);
- gtk_widget_show_all (GTK_WIDGET(view));
+ update_sideview_icon (device);
+ gtk_widget_show_all (GTK_WIDGET(view));
}
static void
@@ -2089,222 +2072,222 @@ device_changed_cb (UpDevice *device, GParamSpec *pspec, gpointer user_data)
static void
add_device (UpDevice *device)
{
- GtkTreeIter iter, *device_iter;
- GtkListStore *sideview_store, *devices_store;
- GtkTreeViewColumn *col;
- GtkCellRenderer *renderer;
- GtkWidget *frame, *view;
- const gchar *object_path = up_device_get_object_path(device);
- gulong signal_id;
- guint index;
- static gboolean first_run = TRUE;
-
- TRACE("entering for %s", object_path);
-
- /* don't add the same device twice */
- device_iter = find_device_in_tree (object_path);
- if (device_iter)
- {
- gtk_tree_iter_free (device_iter);
- return;
- }
-
- /* Make sure the devices tab is shown */
- gtk_widget_show (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
-
- signal_id = g_signal_connect (device, "notify", G_CALLBACK (device_changed_cb), NULL);
-
- sideview_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (sideview)));
-
- index = gtk_notebook_get_n_pages (GTK_NOTEBOOK (device_details_notebook));
-
- /* Create the page that the update_device_details will update/replace */
- frame = gtk_frame_new (NULL);
- view = gtk_tree_view_new ();
- gtk_container_add (GTK_CONTAINER (frame), view);
- gtk_widget_show_all (frame);
- gtk_notebook_append_page (GTK_NOTEBOOK (device_details_notebook), frame, NULL);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
-
- /* Create the list store that the devices view will display */
- devices_store = gtk_list_store_new (XFPM_DEVICE_INFO_LAST, G_TYPE_STRING, G_TYPE_STRING);
- gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (devices_store));
-
- /* Create the headers for this item in the device details tab */
- renderer = gtk_cell_renderer_text_new ();
-
- /*Device Attribute*/
- col = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start (col, renderer, FALSE);
- gtk_tree_view_column_set_attributes (col, renderer, "text", XFPM_DEVICE_INFO_NAME, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
-
- /*Device Attribute Value*/
- col = gtk_tree_view_column_new();
- gtk_tree_view_column_pack_start (col, renderer, FALSE);
- gtk_tree_view_column_set_attributes (col, renderer, "text", XFPM_DEVICE_INFO_VALUE, NULL);
-
- gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
-
- /* Add the new device to the sidebar */
- gtk_list_store_append (sideview_store, &iter);
- gtk_list_store_set (sideview_store, &iter,
- COL_SIDEBAR_INT, index,
- COL_SIDEBAR_BATTERY_DEVICE, device,
- COL_SIDEBAR_OBJECT_PATH, object_path,
- COL_SIDEBAR_SIGNAL_ID, signal_id,
- COL_SIDEBAR_VIEW, view,
- -1);
-
- /* Add the icon and description for the device */
- update_device_details (device);
-
- /* See if we're to select this device, for it to be selected,
- * the starting_device_id must be unset and the this is the first
- * time add_device is called (i.e. select the first device) or
- * our current device matches starting_device_id. */
- if ((starting_device_id == NULL && first_run == TRUE) ||
- (g_strcmp0 (object_path, starting_device_id) == 0))
- {
- GtkTreeSelection *selection;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sideview));
-
- gtk_tree_selection_select_iter (selection, &iter);
- view_cursor_changed_cb (GTK_TREE_VIEW (sideview), NULL);
- }
-
- first_run = FALSE;
+ GtkTreeIter iter, *device_iter;
+ GtkListStore *sideview_store, *devices_store;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GtkWidget *frame, *view;
+ const gchar *object_path = up_device_get_object_path(device);
+ gulong signal_id;
+ guint index;
+ static gboolean first_run = TRUE;
+
+ TRACE("entering for %s", object_path);
+
+ /* don't add the same device twice */
+ device_iter = find_device_in_tree (object_path);
+ if (device_iter)
+ {
+ gtk_tree_iter_free (device_iter);
+ return;
+ }
+
+ /* Make sure the devices tab is shown */
+ gtk_widget_show (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
+
+ signal_id = g_signal_connect (device, "notify", G_CALLBACK (device_changed_cb), NULL);
+
+ sideview_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (sideview)));
+
+ index = gtk_notebook_get_n_pages (GTK_NOTEBOOK (device_details_notebook));
+
+ /* Create the page that the update_device_details will update/replace */
+ frame = gtk_frame_new (NULL);
+ view = gtk_tree_view_new ();
+ gtk_container_add (GTK_CONTAINER (frame), view);
+ gtk_widget_show_all (frame);
+ gtk_notebook_append_page (GTK_NOTEBOOK (device_details_notebook), frame, NULL);
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
+
+ /* Create the list store that the devices view will display */
+ devices_store = gtk_list_store_new (XFPM_DEVICE_INFO_LAST, G_TYPE_STRING, G_TYPE_STRING);
+ gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (devices_store));
+
+ /* Create the headers for this item in the device details tab */
+ renderer = gtk_cell_renderer_text_new ();
+
+ /*Device Attribute*/
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "text", XFPM_DEVICE_INFO_NAME, NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
+
+ /*Device Attribute Value*/
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "text", XFPM_DEVICE_INFO_VALUE, NULL);
+
+ gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
+
+ /* Add the new device to the sidebar */
+ gtk_list_store_append (sideview_store, &iter);
+ gtk_list_store_set (sideview_store, &iter,
+ COL_SIDEBAR_INT, index,
+ COL_SIDEBAR_BATTERY_DEVICE, device,
+ COL_SIDEBAR_OBJECT_PATH, object_path,
+ COL_SIDEBAR_SIGNAL_ID, signal_id,
+ COL_SIDEBAR_VIEW, view,
+ -1);
+
+ /* Add the icon and description for the device */
+ update_device_details (device);
+
+ /* See if we're to select this device, for it to be selected,
+ * the starting_device_id must be unset and the this is the first
+ * time add_device is called (i.e. select the first device) or
+ * our current device matches starting_device_id. */
+ if ((starting_device_id == NULL && first_run == TRUE) ||
+ (g_strcmp0 (object_path, starting_device_id) == 0))
+ {
+ GtkTreeSelection *selection;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sideview));
+
+ gtk_tree_selection_select_iter (selection, &iter);
+ view_cursor_changed_cb (GTK_TREE_VIEW (sideview), NULL);
+ }
+
+ first_run = FALSE;
}
static void
remove_device (const gchar *object_path)
{
- GtkTreeIter *iter;
- GtkListStore *list_store;
- gulong signal_id;
- UpDevice *device;
+ GtkTreeIter *iter;
+ GtkListStore *list_store;
+ gulong signal_id;
+ UpDevice *device;
- TRACE("entering for %s", object_path);
+ TRACE("entering for %s", object_path);
- iter = find_device_in_tree (object_path);
+ iter = find_device_in_tree (object_path);
- if (iter == NULL)
- return;
+ if (iter == NULL)
+ return;
- list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sideview)));
+ list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sideview)));
- gtk_tree_model_get (GTK_TREE_MODEL(list_store), iter,
- COL_SIDEBAR_SIGNAL_ID, &signal_id,
- COL_SIDEBAR_BATTERY_DEVICE, &device,
- -1);
+ gtk_tree_model_get (GTK_TREE_MODEL(list_store), iter,
+ COL_SIDEBAR_SIGNAL_ID, &signal_id,
+ COL_SIDEBAR_BATTERY_DEVICE, &device,
+ -1);
- gtk_list_store_remove (list_store, iter);
+ gtk_list_store_remove (list_store, iter);
- if (device)
- g_signal_handler_disconnect (device, signal_id);
+ if (device)
+ g_signal_handler_disconnect (device, signal_id);
- /* If there are no devices left, hide the devices tab */
- if(!gtk_tree_model_get_iter_first (GTK_TREE_MODEL(list_store), iter))
- gtk_widget_hide (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
+ /* If there are no devices left, hide the devices tab */
+ if(!gtk_tree_model_get_iter_first (GTK_TREE_MODEL(list_store), iter))
+ gtk_widget_hide (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
}
static void
device_added_cb (UpClient *upclient, UpDevice *device, gpointer user_data)
{
- add_device (device);
+ add_device (device);
}
static void
device_removed_cb (UpClient *upclient, const gchar *object_path, gpointer user_data)
{
- remove_device (object_path);
+ remove_device (object_path);
}
static void
add_all_devices (void)
{
- GPtrArray *array = NULL;
- guint i;
+ GPtrArray *array = NULL;
+ guint i;
#if UP_CHECK_VERSION(0, 99, 8)
- array = up_client_get_devices2 (upower);
+ array = up_client_get_devices2 (upower);
#else
- array = up_client_get_devices (upower);
+ array = up_client_get_devices (upower);
#endif
- if ( array )
+ if ( array )
+ {
+ for ( i = 0; i < array->len; i++)
{
- for ( i = 0; i < array->len; i++)
- {
- UpDevice *device = g_ptr_array_index (array, i);
+ UpDevice *device = g_ptr_array_index (array, i);
- add_device (device);
- }
- g_ptr_array_free (array, TRUE);
+ add_device (device);
}
+ g_ptr_array_free (array, TRUE);
+ }
}
static void
settings_create_devices_list (void)
{
- upower = up_client_new ();
+ upower = up_client_new ();
- g_signal_connect (upower, "device-added", G_CALLBACK (device_added_cb), NULL);
- g_signal_connect (upower, "device-removed", G_CALLBACK (device_removed_cb), NULL);
+ g_signal_connect (upower, "device-added", G_CALLBACK (device_added_cb), NULL);
+ g_signal_connect (upower, "device-removed", G_CALLBACK (device_removed_cb), NULL);
- add_all_devices ();
+ add_all_devices ();
}
static void
view_cursor_changed_cb (GtkTreeView *view, gpointer *user_data)
{
- GtkTreeSelection *sel;
- GtkTreeModel *model;
- GtkTreeIter selected_row;
- gint int_data = 0;
+ GtkTreeSelection *sel;
+ GtkTreeModel *model;
+ GtkTreeIter selected_row;
+ gint int_data = 0;
- sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
- if ( !gtk_tree_selection_get_selected (sel, &model, &selected_row))
- return;
+ if ( !gtk_tree_selection_get_selected (sel, &model, &selected_row))
+ return;
- gtk_tree_model_get(model,
- &selected_row,
- COL_SIDEBAR_INT,
- &int_data,
- -1);
+ gtk_tree_model_get (model,
+ &selected_row,
+ COL_SIDEBAR_INT,
+ &int_data,
+ -1);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (device_details_notebook), int_data);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (device_details_notebook), int_data);
}
static void
settings_quit (GtkWidget *widget, XfconfChannel *channel)
{
- g_object_unref (channel);
- xfconf_shutdown();
- gtk_widget_destroy (widget);
- /* initiate the quit action on the application so it terminates */
- g_action_group_activate_action(G_ACTION_GROUP(app), "quit", NULL);
+ g_object_unref (channel);
+ xfconf_shutdown ();
+ gtk_widget_destroy (widget);
+ /* initiate the quit action on the application so it terminates */
+ g_action_group_activate_action (G_ACTION_GROUP(app), "quit", NULL);
}
static void dialog_response_cb (GtkDialog *dialog, gint response, XfconfChannel *channel)
{
- switch(response)
- {
- case GTK_RESPONSE_HELP:
- xfce_dialog_show_help_with_version (NULL, "xfce4-power-manager", "start", NULL, XFPM_VERSION_SHORT);
- break;
- default:
- settings_quit (GTK_WIDGET (dialog), channel);
- break;
- }
+ switch(response)
+ {
+ case GTK_RESPONSE_HELP:
+ xfce_dialog_show_help_with_version (NULL, "xfce4-power-manager", "start", NULL, XFPM_VERSION_SHORT);
+ break;
+ default:
+ settings_quit (GTK_WIDGET (dialog), channel);
+ break;
+ }
}
static void
delete_event_cb (GtkWidget *plug, GdkEvent *ev, XfconfChannel *channel)
{
- settings_quit (plug, channel);
+ settings_quit (plug, channel);
}
GtkWidget *
@@ -2317,251 +2300,251 @@ xfpm_settings_dialog_new (XfconfChannel *channel, gboolean auth_suspend,
gboolean has_battery_button, Window id, gchar *device_id,
GtkApplication *gtk_app)
{
- GtkWidget *plug;
- GtkWidget *parent;
- GtkWidget *dialog;
- GtkWidget *plugged_box;
- GtkWidget *viewport;
- GtkWidget *hbox;
- GtkWidget *frame;
- GtkWidget *switch_widget;
- GtkWidget *stack;
- GtkStyleContext *context;
- GtkListStore *list_store;
- GtkTreeViewColumn *col;
- GtkCellRenderer *renderer;
- GError *error = NULL;
- guint val;
- GtkCssProvider *css_provider;
-
- XFPM_DEBUG ("auth_hibernate=%s auth_suspend=%s can_shutdown=%s can_suspend=%s can_hibernate=%s " \
- "has_battery=%s has_lcd_brightness=%s has_lid=%s has_sleep_button=%s " \
- "has_hibernate_button=%s has_power_button=%s has_battery_button=%s",
- xfpm_bool_to_string (has_battery), xfpm_bool_to_string (auth_hibernate),
- xfpm_bool_to_string (can_shutdown), xfpm_bool_to_string (auth_suspend),
- xfpm_bool_to_string (can_suspend), xfpm_bool_to_string (can_hibernate),
- xfpm_bool_to_string (has_lcd_brightness), xfpm_bool_to_string (has_lid),
- xfpm_bool_to_string (has_sleep_button), xfpm_bool_to_string (has_hibernate_button),
- xfpm_bool_to_string (has_power_button), xfpm_bool_to_string (has_battery_button));
-
- xml = xfpm_builder_new_from_string (xfpm_settings_ui, &error);
-
- if ( G_UNLIKELY (error) )
- {
- xfce_dialog_show_error (NULL, error, "%s", _("Check your power manager installation"));
- g_error ("%s", error->message);
- }
-
- lcd_brightness = has_lcd_brightness;
- starting_device_id = device_id;
-
- on_battery_dpms_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-battery"));
- on_battery_dpms_off = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-battery"));
- on_ac_dpms_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-ac"));
- on_ac_dpms_off = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-ac"));
-
- on_battery_display_blank = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-battery"));
- val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK, 1);
- gtk_range_set_value (GTK_RANGE (on_battery_display_blank), val);
- xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK,
- G_TYPE_INT, gtk_range_get_adjustment (GTK_RANGE (on_battery_display_blank)),
- "value");
-
- on_ac_display_blank = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-ac"));
- xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX ON_AC_BLANK,
- G_TYPE_INT, gtk_range_get_adjustment (GTK_RANGE (on_ac_display_blank)),
- "value");
-
- switch_widget = GTK_WIDGET (gtk_builder_get_object (xml, "handle-brightness-keys"));
- xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX HANDLE_BRIGHTNESS_KEYS,
- G_TYPE_BOOLEAN, switch_widget, "active");
-
- switch_widget = GTK_WIDGET (gtk_builder_get_object (xml, "show-notifications"));
- xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX GENERAL_NOTIFICATION_CFG,
- G_TYPE_BOOLEAN, switch_widget, "active");
-
- switch_widget = GTK_WIDGET (gtk_builder_get_object (xml, "show-systray"));
- xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX SHOW_TRAY_ICON_CFG,
- G_TYPE_BOOLEAN, switch_widget, "active");
-
- dialog = GTK_WIDGET (gtk_builder_get_object (xml, "xfpm-settings-dialog"));
- nt = GTK_WIDGET (gtk_builder_get_object (xml, "main-notebook"));
-
- /* Set Gtk style */
- css_provider = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (css_provider,
- ".xfce4-scale-label { padding-bottom: 0; }",
- -1, NULL);
- gtk_style_context_add_provider_for_screen (gdk_screen_get_default(),
- GTK_STYLE_PROVIDER(css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- g_object_unref (css_provider);
-
- /* Devices listview */
- sideview = gtk_tree_view_new ();
- list_store = gtk_list_store_new (NCOLS_SIDEBAR,
- GDK_TYPE_PIXBUF, /* COL_SIDEBAR_ICON */
- G_TYPE_STRING, /* COL_SIDEBAR_NAME */
- G_TYPE_INT, /* COL_SIDEBAR_INT */
- G_TYPE_POINTER, /* COL_SIDEBAR_BATTERY_DEVICE */
- G_TYPE_STRING, /* COL_SIDEBAR_OBJECT_PATH */
- G_TYPE_ULONG, /* COL_SIDEBAR_SIGNAL_ID */
- G_TYPE_POINTER /* COL_SIDEBAR_VIEW */
- );
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (sideview), GTK_TREE_MODEL (list_store));
-
- col = gtk_tree_view_column_new ();
-
- renderer = gtk_cell_renderer_pixbuf_new ();
-
- gtk_tree_view_column_pack_start (col, renderer, FALSE);
- gtk_tree_view_column_set_attributes (col, renderer, "pixbuf", 0, NULL);
-
- /* The device label */
- renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (col, renderer, FALSE);
- gtk_tree_view_column_set_attributes (col, renderer, "markup", 1, NULL);
-
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (sideview), FALSE);
- gtk_tree_view_append_column (GTK_TREE_VIEW (sideview), col);
-
- g_signal_connect (sideview, "cursor-changed", G_CALLBACK (view_cursor_changed_cb), NULL);
-
- /* Pack the content of the devices tab */
- device_details_notebook = gtk_notebook_new ();
-
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (device_details_notebook), FALSE);
- context = gtk_widget_get_style_context (GTK_WIDGET (device_details_notebook));
- gtk_style_context_add_class (context, "frame");
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
-
- viewport = gtk_viewport_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (viewport), sideview);
- gtk_box_pack_start (GTK_BOX (hbox), viewport, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), device_details_notebook, TRUE, TRUE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
- devices_page_num = gtk_notebook_append_page (GTK_NOTEBOOK (nt), hbox, gtk_label_new (_("Devices")) );
-
- gtk_widget_show_all (sideview);
- gtk_widget_show_all (viewport);
- gtk_widget_show_all (hbox);
- gtk_widget_hide (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
-
- settings_create_devices_list ();
-
- xfpm_settings_on_ac (channel,
- auth_suspend,
- auth_hibernate,
- can_suspend,
- can_hibernate,
- has_lcd_brightness,
- has_lid);
-
- if ( has_battery )
- xfpm_settings_on_battery (channel,
- auth_suspend,
- auth_hibernate,
- can_suspend,
- can_hibernate,
- can_shutdown,
- has_lcd_brightness,
- has_lid);
- else
- {
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml ,"critical-power-frame")));
- stack = GTK_WIDGET (gtk_builder_get_object (xml ,"system-stack"));
- gtk_widget_hide (gtk_stack_get_child_by_name (GTK_STACK (stack), "page0"));
- stack = GTK_WIDGET (gtk_builder_get_object (xml ,"display-stack"));
- gtk_widget_hide (gtk_stack_get_child_by_name (GTK_STACK (stack), "page0"));
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml ,"system-stack-switcher")));
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml ,"display-stack-switcher")));
- }
-
- xfpm_settings_general (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, can_shutdown,
- has_sleep_button, has_hibernate_button, has_power_button, has_battery_button);
-
- xfpm_settings_advanced (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, has_battery);
-
- /* Light Locker Integration */
- xfpm_settings_light_locker (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate);
- /* END Light Locker Integration */
-
- if ( !has_lcd_brightness )
- {
+ GtkWidget *plug;
+ GtkWidget *parent;
+ GtkWidget *dialog;
+ GtkWidget *plugged_box;
+ GtkWidget *viewport;
+ GtkWidget *hbox;
+ GtkWidget *frame;
+ GtkWidget *switch_widget;
+ GtkWidget *stack;
+ GtkStyleContext *context;
+ GtkListStore *list_store;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GError *error = NULL;
+ guint val;
+ GtkCssProvider *css_provider;
+
+ XFPM_DEBUG ("auth_hibernate=%s auth_suspend=%s can_shutdown=%s can_suspend=%s can_hibernate=%s " \
+ "has_battery=%s has_lcd_brightness=%s has_lid=%s has_sleep_button=%s " \
+ "has_hibernate_button=%s has_power_button=%s has_battery_button=%s",
+ xfpm_bool_to_string (has_battery), xfpm_bool_to_string (auth_hibernate),
+ xfpm_bool_to_string (can_shutdown), xfpm_bool_to_string (auth_suspend),
+ xfpm_bool_to_string (can_suspend), xfpm_bool_to_string (can_hibernate),
+ xfpm_bool_to_string (has_lcd_brightness), xfpm_bool_to_string (has_lid),
+ xfpm_bool_to_string (has_sleep_button), xfpm_bool_to_string (has_hibernate_button),
+ xfpm_bool_to_string (has_power_button), xfpm_bool_to_string (has_battery_button));
+
+ xml = xfpm_builder_new_from_string (xfpm_settings_ui, &error);
+
+ if ( G_UNLIKELY (error) )
+ {
+ xfce_dialog_show_error (NULL, error, "%s", _("Check your power manager installation"));
+ g_error ("%s", error->message);
+ }
+
+ lcd_brightness = has_lcd_brightness;
+ starting_device_id = device_id;
+
+ on_battery_dpms_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-battery"));
+ on_battery_dpms_off = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-battery"));
+ on_ac_dpms_sleep = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-sleep-on-ac"));
+ on_ac_dpms_off = GTK_WIDGET (gtk_builder_get_object (xml, "dpms-off-on-ac"));
+
+ on_battery_display_blank = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-battery"));
+ val = xfconf_channel_get_uint (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK, 1);
+ gtk_range_set_value (GTK_RANGE (on_battery_display_blank), val);
+ xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK,
+ G_TYPE_INT, gtk_range_get_adjustment (GTK_RANGE (on_battery_display_blank)),
+ "value");
+
+ on_ac_display_blank = GTK_WIDGET (gtk_builder_get_object (xml, "display-blank-on-ac"));
+ xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX ON_AC_BLANK,
+ G_TYPE_INT, gtk_range_get_adjustment (GTK_RANGE (on_ac_display_blank)),
+ "value");
+
+ switch_widget = GTK_WIDGET (gtk_builder_get_object (xml, "handle-brightness-keys"));
+ xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX HANDLE_BRIGHTNESS_KEYS,
+ G_TYPE_BOOLEAN, switch_widget, "active");
+
+ switch_widget = GTK_WIDGET (gtk_builder_get_object (xml, "show-notifications"));
+ xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX GENERAL_NOTIFICATION_CFG,
+ G_TYPE_BOOLEAN, switch_widget, "active");
+
+ switch_widget = GTK_WIDGET (gtk_builder_get_object (xml, "show-systray"));
+ xfconf_g_property_bind (channel, XFPM_PROPERTIES_PREFIX SHOW_TRAY_ICON_CFG,
+ G_TYPE_BOOLEAN, switch_widget, "active");
+
+ dialog = GTK_WIDGET (gtk_builder_get_object (xml, "xfpm-settings-dialog"));
+ nt = GTK_WIDGET (gtk_builder_get_object (xml, "main-notebook"));
+
+ /* Set Gtk style */
+ css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (css_provider,
+ ".xfce4-scale-label { padding-bottom: 0; }",
+ -1, NULL);
+ gtk_style_context_add_provider_for_screen (gdk_screen_get_default(),
+ GTK_STYLE_PROVIDER(css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ g_object_unref (css_provider);
+
+ /* Devices listview */
+ sideview = gtk_tree_view_new ();
+ list_store = gtk_list_store_new (NCOLS_SIDEBAR,
+ GDK_TYPE_PIXBUF, /* COL_SIDEBAR_ICON */
+ G_TYPE_STRING, /* COL_SIDEBAR_NAME */
+ G_TYPE_INT, /* COL_SIDEBAR_INT */
+ G_TYPE_POINTER, /* COL_SIDEBAR_BATTERY_DEVICE */
+ G_TYPE_STRING, /* COL_SIDEBAR_OBJECT_PATH */
+ G_TYPE_ULONG, /* COL_SIDEBAR_SIGNAL_ID */
+ G_TYPE_POINTER /* COL_SIDEBAR_VIEW */
+ );
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (sideview), GTK_TREE_MODEL (list_store));
+
+ col = gtk_tree_view_column_new ();
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "pixbuf", 0, NULL);
+
+ /* The device label */
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes (col, renderer, "markup", 1, NULL);
+
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (sideview), FALSE);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (sideview), col);
+
+ g_signal_connect (sideview, "cursor-changed", G_CALLBACK (view_cursor_changed_cb), NULL);
+
+ /* Pack the content of the devices tab */
+ device_details_notebook = gtk_notebook_new ();
+
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (device_details_notebook), FALSE);
+ context = gtk_widget_get_style_context (GTK_WIDGET (device_details_notebook));
+ gtk_style_context_add_class (context, "frame");
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
+
+ viewport = gtk_viewport_new (NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (viewport), sideview);
+ gtk_box_pack_start (GTK_BOX (hbox), viewport, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), device_details_notebook, TRUE, TRUE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
+ devices_page_num = gtk_notebook_append_page (GTK_NOTEBOOK (nt), hbox, gtk_label_new (_("Devices")) );
+
+ gtk_widget_show_all (sideview);
+ gtk_widget_show_all (viewport);
+ gtk_widget_show_all (hbox);
+ gtk_widget_hide (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
+
+ settings_create_devices_list ();
+
+ xfpm_settings_on_ac (channel,
+ auth_suspend,
+ auth_hibernate,
+ can_suspend,
+ can_hibernate,
+ has_lcd_brightness,
+ has_lid);
+
+ if ( has_battery )
+ xfpm_settings_on_battery (channel,
+ auth_suspend,
+ auth_hibernate,
+ can_suspend,
+ can_hibernate,
+ can_shutdown,
+ has_lcd_brightness,
+ has_lid);
+ else
+ {
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml ,"critical-power-frame")));
+ stack = GTK_WIDGET (gtk_builder_get_object (xml ,"system-stack"));
+ gtk_widget_hide (gtk_stack_get_child_by_name (GTK_STACK (stack), "page0"));
+ stack = GTK_WIDGET (gtk_builder_get_object (xml ,"display-stack"));
+ gtk_widget_hide (gtk_stack_get_child_by_name (GTK_STACK (stack), "page0"));
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml ,"system-stack-switcher")));
+ gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml ,"display-stack-switcher")));
+ }
+
+ xfpm_settings_general (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, can_shutdown,
+ has_sleep_button, has_hibernate_button, has_power_button, has_battery_button);
+
+ xfpm_settings_advanced (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate, has_battery);
+
+ /* Light Locker Integration */
+ xfpm_settings_light_locker (channel, auth_suspend, auth_hibernate, can_suspend, can_hibernate);
+ /* END Light Locker Integration */
+
+ if ( !has_lcd_brightness )
+ {
frame = GTK_WIDGET (gtk_builder_get_object (xml, "brightness-frame"));
gtk_widget_hide (frame);
frame = GTK_WIDGET (gtk_builder_get_object (xml, "handle-brightness-keys"));
gtk_widget_hide (frame);
frame = GTK_WIDGET (gtk_builder_get_object (xml, "handle-brightness-keys-label"));
gtk_widget_hide (frame);
- }
+ }
- if ( id != 0 )
- {
- plugged_box = GTK_WIDGET (gtk_builder_get_object (xml, "plug-child"));
- plug = gtk_plug_new (id);
- gtk_widget_show (plug);
+ if ( id != 0 )
+ {
+ plugged_box = GTK_WIDGET (gtk_builder_get_object (xml, "plug-child"));
+ plug = gtk_plug_new (id);
+ gtk_widget_show (plug);
parent = gtk_widget_get_parent (plugged_box);
if (parent)
{
- g_object_ref (plugged_box);
- gtk_container_remove (GTK_CONTAINER (parent), plugged_box);
- gtk_container_add (GTK_CONTAINER (plug), plugged_box);
- g_object_unref (plugged_box);
+ g_object_ref (plugged_box);
+ gtk_container_remove (GTK_CONTAINER (parent), plugged_box);
+ gtk_container_add (GTK_CONTAINER (plug), plugged_box);
+ g_object_unref (plugged_box);
}
- g_signal_connect (plug, "delete-event",
- G_CALLBACK (delete_event_cb), channel);
- gdk_notify_startup_complete ();
- }
- else
- {
- g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), channel);
- gtk_widget_show (dialog);
- }
+ g_signal_connect (plug, "delete-event",
+ G_CALLBACK (delete_event_cb), channel);
+ gdk_notify_startup_complete ();
+ }
+ else
+ {
+ g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), channel);
+ gtk_widget_show (dialog);
+ }
- gtk_builder_connect_signals (xml, channel);
+ gtk_builder_connect_signals (xml, channel);
- /* If we passed in a device to display, show the devices tab now, otherwise hide it */
- if (device_id != NULL)
- {
- gtk_widget_show (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
- gtk_notebook_set_current_page (GTK_NOTEBOOK (nt), devices_page_num);
- }
+ /* If we passed in a device to display, show the devices tab now, otherwise hide it */
+ if (device_id != NULL)
+ {
+ gtk_widget_show (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (nt), devices_page_num);
+ }
- /* keep a pointer to the GtkApplication instance so we can signal a
- * quit message */
- app = gtk_app;
+ /* keep a pointer to the GtkApplication instance so we can signal a
+ * quit message */
+ app = gtk_app;
- return dialog;
+ return dialog;
}
void
xfpm_settings_show_device_id (gchar *device_id)
{
- GtkTreeIter *device_iter;
+ GtkTreeIter *device_iter;
- if (device_id == NULL)
- return;
+ if (device_id == NULL)
+ return;
- gtk_widget_show (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
- gtk_notebook_set_current_page (GTK_NOTEBOOK (nt), devices_page_num);
+ gtk_widget_show (gtk_notebook_get_nth_page (GTK_NOTEBOOK (nt), devices_page_num));
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (nt), devices_page_num);
- DBG("device_id %s", device_id);
+ DBG("device_id %s", device_id);
- device_iter = find_device_in_tree (device_id);
- if (device_iter)
- {
- GtkTreeSelection *selection;
+ device_iter = find_device_in_tree (device_id);
+ if (device_iter)
+ {
+ GtkTreeSelection *selection;
- DBG("device found");
+ DBG("device found");
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sideview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sideview));
- gtk_tree_selection_select_iter (selection, device_iter);
- view_cursor_changed_cb (GTK_TREE_VIEW (sideview), NULL);
- gtk_tree_iter_free (device_iter);
- }
+ gtk_tree_selection_select_iter (selection, device_iter);
+ view_cursor_changed_cb (GTK_TREE_VIEW (sideview), NULL);
+ gtk_tree_iter_free (device_iter);
+ }
}
diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h
index 1588849..426b208 100644
--- a/settings/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -24,23 +24,22 @@
#include <gtk/gtkx.h>
#include <xfconf/xfconf.h>
-GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel,
- gboolean auth_suspend,
- gboolean auth_hibernate,
- gboolean can_suspend,
- gboolean can_hibernate,
- gboolean can_shutdown,
- gboolean has_battery,
- gboolean has_lcd_brightness,
- gboolean has_lid,
- gboolean has_sleep_button,
- gboolean has_hibernate_button,
- gboolean has_power_button,
- gboolean has_battery_button,
- Window id,
- gchar *device_id,
- GtkApplication *gtk_app);
-
+GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel,
+ gboolean auth_suspend,
+ gboolean auth_hibernate,
+ gboolean can_suspend,
+ gboolean can_hibernate,
+ gboolean can_shutdown,
+ gboolean has_battery,
+ gboolean has_lcd_brightness,
+ gboolean has_lid,
+ gboolean has_sleep_button,
+ gboolean has_hibernate_button,
+ gboolean has_power_button,
+ gboolean has_battery_button,
+ Window id,
+ gchar *device_id,
+ GtkApplication *gtk_app);
void xfpm_settings_show_device_id (gchar *device_id);
#endif /* __XFPM_SETTINGS_H */
diff --git a/src/egg-idletime.c b/src/egg-idletime.c
index c5d2b6d..36e9c41 100644
--- a/src/egg-idletime.c
+++ b/src/egg-idletime.c
@@ -51,31 +51,31 @@ static void egg_idletime_finalize (GObject *object);
struct EggIdletimePrivate
{
- gint sync_event;
- gboolean reset_set;
- XSyncCounter idle_counter;
- GPtrArray *array;
- Display *dpy;
+ gint sync_event;
+ gboolean reset_set;
+ XSyncCounter idle_counter;
+ GPtrArray *array;
+ Display *dpy;
};
typedef struct
{
- guint id;
- XSyncValue timeout;
- XSyncAlarm xalarm;
- EggIdletime *idletime;
+ guint id;
+ XSyncValue timeout;
+ XSyncAlarm xalarm;
+ EggIdletime *idletime;
} EggIdletimeAlarm;
enum {
- SIGNAL_ALARM_EXPIRED,
- SIGNAL_RESET,
- LAST_SIGNAL
+ SIGNAL_ALARM_EXPIRED,
+ SIGNAL_RESET,
+ LAST_SIGNAL
};
typedef enum {
- EGG_IDLETIME_ALARM_TYPE_POSITIVE,
- EGG_IDLETIME_ALARM_TYPE_NEGATIVE,
- EGG_IDLETIME_ALARM_TYPE_DISABLED
+ EGG_IDLETIME_ALARM_TYPE_POSITIVE,
+ EGG_IDLETIME_ALARM_TYPE_NEGATIVE,
+ EGG_IDLETIME_ALARM_TYPE_DISABLED
} EggIdletimeAlarmType;
static guint signals [LAST_SIGNAL] = { 0 };
@@ -89,7 +89,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (EggIdletime, egg_idletime, G_TYPE_OBJECT)
static gint64
egg_idletime_xsyncvalue_to_int64 (XSyncValue value)
{
- return ((guint64) XSyncValueHigh32 (value)) << 32 | (guint64) XSyncValueLow32 (value);
+ return ((guint64) XSyncValueHigh32 (value)) << 32 | (guint64) XSyncValueLow32 (value);
}
/**
@@ -98,9 +98,9 @@ egg_idletime_xsyncvalue_to_int64 (XSyncValue value)
gint64
egg_idletime_get_time (EggIdletime *idletime)
{
- XSyncValue value;
- XSyncQueryCounter (idletime->priv->dpy, idletime->priv->idle_counter, &value);
- return egg_idletime_xsyncvalue_to_int64 (value);
+ XSyncValue value;
+ XSyncQueryCounter (idletime->priv->dpy, idletime->priv->idle_counter, &value);
+ return egg_idletime_xsyncvalue_to_int64 (value);
}
/**
@@ -109,40 +109,40 @@ egg_idletime_get_time (EggIdletime *idletime)
static void
egg_idletime_xsync_alarm_set (EggIdletime *idletime, EggIdletimeAlarm *eggalarm, EggIdletimeAlarmType alarm_type)
{
- XSyncAlarmAttributes attr;
- XSyncValue delta;
- unsigned int flags;
- XSyncTestType test;
-
- /* just remove it */
- if (alarm_type == EGG_IDLETIME_ALARM_TYPE_DISABLED) {
- if (eggalarm->xalarm) {
- XSyncDestroyAlarm (idletime->priv->dpy, eggalarm->xalarm);
- eggalarm->xalarm = None;
- }
- return;
- }
-
- /* which way do we do the test? */
- if (alarm_type == EGG_IDLETIME_ALARM_TYPE_POSITIVE)
- test = XSyncPositiveTransition;
- else
- test = XSyncNegativeTransition;
-
- XSyncIntToValue (&delta, 0);
-
- attr.trigger.counter = idletime->priv->idle_counter;
- attr.trigger.value_type = XSyncAbsolute;
- attr.trigger.test_type = test;
- attr.trigger.wait_value = eggalarm->timeout;
- attr.delta = delta;
-
- flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType | XSyncCAValue | XSyncCADelta;
-
- if (eggalarm->xalarm)
- XSyncChangeAlarm (idletime->priv->dpy, eggalarm->xalarm, flags, &attr);
- else
- eggalarm->xalarm = XSyncCreateAlarm (idletime->priv->dpy, flags, &attr);
+ XSyncAlarmAttributes attr;
+ XSyncValue delta;
+ unsigned int flags;
+ XSyncTestType test;
+
+ /* just remove it */
+ if (alarm_type == EGG_IDLETIME_ALARM_TYPE_DISABLED) {
+ if (eggalarm->xalarm) {
+ XSyncDestroyAlarm (idletime->priv->dpy, eggalarm->xalarm);
+ eggalarm->xalarm = None;
+ }
+ return;
+ }
+
+ /* which way do we do the test? */
+ if (alarm_type == EGG_IDLETIME_ALARM_TYPE_POSITIVE)
+ test = XSyncPositiveTransition;
+ else
+ test = XSyncNegativeTransition;
+
+ XSyncIntToValue (&delta, 0);
+
+ attr.trigger.counter = idletime->priv->idle_counter;
+ attr.trigger.value_type = XSyncAbsolute;
+ attr.trigger.test_type = test;
+ attr.trigger.wait_value = eggalarm->timeout;
+ attr.delta = delta;
+
+ flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType | XSyncCAValue | XSyncCADelta;
+
+ if (eggalarm->xalarm)
+ XSyncChangeAlarm (idletime->priv->dpy, eggalarm->xalarm, flags, &attr);
+ else
+ eggalarm->xalarm = XSyncCreateAlarm (idletime->priv->dpy, flags, &attr);
}
/**
@@ -151,26 +151,26 @@ egg_idletime_xsync_alarm_set (EggIdletime *idletime, EggIdletimeAlarm *eggalarm,
void
egg_idletime_alarm_reset_all (EggIdletime *idletime)
{
- guint i;
- EggIdletimeAlarm *eggalarm;
+ guint i;
+ EggIdletimeAlarm *eggalarm;
- g_return_if_fail (EGG_IS_IDLETIME (idletime));
+ g_return_if_fail (EGG_IS_IDLETIME (idletime));
- /* reset all the alarms (except the reset alarm) to their timeouts */
- for (i=1; i<idletime->priv->array->len; i++) {
- eggalarm = g_ptr_array_index (idletime->priv->array, i);
- egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_POSITIVE);
- }
+ /* reset all the alarms (except the reset alarm) to their timeouts */
+ for (i=1; i<idletime->priv->array->len; i++) {
+ eggalarm = g_ptr_array_index (idletime->priv->array, i);
+ egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_POSITIVE);
+ }
- /* set the reset alarm to be disabled */
- eggalarm = g_ptr_array_index (idletime->priv->array, 0);
- egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_DISABLED);
+ /* set the reset alarm to be disabled */
+ eggalarm = g_ptr_array_index (idletime->priv->array, 0);
+ egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_DISABLED);
- /* emit signal so say we've reset all timers */
- g_signal_emit (idletime, signals [SIGNAL_RESET], 0);
+ /* emit signal so say we've reset all timers */
+ g_signal_emit (idletime, signals [SIGNAL_RESET], 0);
- /* we need to be reset again on the next event */
- idletime->priv->reset_set = FALSE;
+ /* we need to be reset again on the next event */
+ idletime->priv->reset_set = FALSE;
}
/**
@@ -179,14 +179,14 @@ egg_idletime_alarm_reset_all (EggIdletime *idletime)
static EggIdletimeAlarm *
egg_idletime_alarm_find_id (EggIdletime *idletime, guint id)
{
- guint i;
- EggIdletimeAlarm *eggalarm;
- for (i=0; i<idletime->priv->array->len; i++) {
- eggalarm = g_ptr_array_index (idletime->priv->array, i);
- if (eggalarm->id == id)
- return eggalarm;
- }
- return NULL;
+ guint i;
+ EggIdletimeAlarm *eggalarm;
+ for (i=0; i<idletime->priv->array->len; i++) {
+ eggalarm = g_ptr_array_index (idletime->priv->array, i);
+ if (eggalarm->id == id)
+ return eggalarm;
+ }
+ return NULL;
}
/**
@@ -195,25 +195,25 @@ egg_idletime_alarm_find_id (EggIdletime *idletime, guint id)
static void
egg_idletime_set_reset_alarm (EggIdletime *idletime, XSyncAlarmNotifyEvent *alarm_event)
{
- EggIdletimeAlarm *eggalarm;
- int overflow;
- XSyncValue add;
+ EggIdletimeAlarm *eggalarm;
+ int overflow;
+ XSyncValue add;
- eggalarm = egg_idletime_alarm_find_id (idletime, 0);
+ eggalarm = egg_idletime_alarm_find_id (idletime, 0);
- if (!idletime->priv->reset_set) {
- /* don't match on the current value because
- * XSyncNegativeComparison means less or equal. */
- XSyncIntToValue (&add, -1);
- XSyncValueAdd (&eggalarm->timeout, alarm_event->counter_value, add, &overflow);
+ if (!idletime->priv->reset_set) {
+ /* don't match on the current value because
+ * XSyncNegativeComparison means less or equal. */
+ XSyncIntToValue (&add, -1);
+ XSyncValueAdd (&eggalarm->timeout, alarm_event->counter_value, add, &overflow);
- /* set the reset alarm to fire the next time
- * idletime->priv->idle_counter < the current counter value */
- egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_NEGATIVE);
+ /* set the reset alarm to fire the next time
+ * idletime->priv->idle_counter < the current counter value */
+ egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_NEGATIVE);
- /* don't try to set this again if multiple timers are going off in sequence */
- idletime->priv->reset_set = TRUE;
- }
+ /* don't try to set this again if multiple timers are going off in sequence */
+ idletime->priv->reset_set = TRUE;
+ }
}
/**
@@ -222,14 +222,14 @@ egg_idletime_set_reset_alarm (EggIdletime *idletime, XSyncAlarmNotifyEvent *alar
static EggIdletimeAlarm *
egg_idletime_alarm_find_event (EggIdletime *idletime, XSyncAlarmNotifyEvent *alarm_event)
{
- guint i;
- EggIdletimeAlarm *eggalarm;
- for (i=0; i<idletime->priv->array->len; i++) {
- eggalarm = g_ptr_array_index (idletime->priv->array, i);
- if (alarm_event->alarm == eggalarm->xalarm)
- return eggalarm;
- }
- return NULL;
+ guint i;
+ EggIdletimeAlarm *eggalarm;
+ for (i=0; i<idletime->priv->array->len; i++) {
+ eggalarm = g_ptr_array_index (idletime->priv->array, i);
+ if (alarm_event->alarm == eggalarm->xalarm)
+ return eggalarm;
+ }
+ return NULL;
}
/**
@@ -238,36 +238,36 @@ egg_idletime_alarm_find_event (EggIdletime *idletime, XSyncAlarmNotifyEvent *ala
static GdkFilterReturn
egg_idletime_event_filter_cb (GdkXEvent *gdkxevent, GdkEvent *event, gpointer data)
{
- EggIdletimeAlarm *eggalarm;
- XEvent *xevent = (XEvent *) gdkxevent;
- EggIdletime *idletime = (EggIdletime *) data;
- XSyncAlarmNotifyEvent *alarm_event;
+ EggIdletimeAlarm *eggalarm;
+ XEvent *xevent = (XEvent *) gdkxevent;
+ EggIdletime *idletime = (EggIdletime *) data;
+ XSyncAlarmNotifyEvent *alarm_event;
- /* no point continuing */
- if (xevent->type != idletime->priv->sync_event + XSyncAlarmNotify)
- return GDK_FILTER_CONTINUE;
+ /* no point continuing */
+ if (xevent->type != idletime->priv->sync_event + XSyncAlarmNotify)
+ return GDK_FILTER_CONTINUE;
- alarm_event = (XSyncAlarmNotifyEvent *) xevent;
+ alarm_event = (XSyncAlarmNotifyEvent *) xevent;
- /* did we match one of our alarms? */
- eggalarm = egg_idletime_alarm_find_event (idletime, alarm_event);
- if (eggalarm == NULL)
- return GDK_FILTER_CONTINUE;
+ /* did we match one of our alarms? */
+ eggalarm = egg_idletime_alarm_find_event (idletime, alarm_event);
+ if (eggalarm == NULL)
+ return GDK_FILTER_CONTINUE;
- /* are we the reset alarm? */
- if (eggalarm->id == 0) {
- egg_idletime_alarm_reset_all (idletime);
- goto out;
- }
+ /* are we the reset alarm? */
+ if (eggalarm->id == 0) {
+ egg_idletime_alarm_reset_all (idletime);
+ goto out;
+ }
- /* emit */
- g_signal_emit (eggalarm->idletime, signals [SIGNAL_ALARM_EXPIRED], 0, eggalarm->id);
+ /* emit */
+ g_signal_emit (eggalarm->idletime, signals [SIGNAL_ALARM_EXPIRED], 0, eggalarm->id);
- /* we need the first alarm to go off to set the reset alarm */
- egg_idletime_set_reset_alarm (idletime, alarm_event);
+ /* we need the first alarm to go off to set the reset alarm */
+ egg_idletime_set_reset_alarm (idletime, alarm_event);
out:
- /* don't propagate */
- return GDK_FILTER_REMOVE;
+ /* don't propagate */
+ return GDK_FILTER_REMOVE;
}
/**
@@ -276,17 +276,17 @@ out:
static EggIdletimeAlarm *
egg_idletime_alarm_new (EggIdletime *idletime, guint id)
{
- EggIdletimeAlarm *eggalarm;
+ EggIdletimeAlarm *eggalarm;
- /* create a new alarm */
- eggalarm = g_new0 (EggIdletimeAlarm, 1);
+ /* create a new alarm */
+ eggalarm = g_new0 (EggIdletimeAlarm, 1);
- /* set the default values */
- eggalarm->id = id;
- eggalarm->xalarm = None;
- eggalarm->idletime = g_object_ref (idletime);
+ /* set the default values */
+ eggalarm->id = id;
+ eggalarm->xalarm = None;
+ eggalarm->idletime = g_object_ref (idletime);
- return eggalarm;
+ return eggalarm;
}
/**
@@ -295,28 +295,28 @@ egg_idletime_alarm_new (EggIdletime *idletime, guint id)
gboolean
egg_idletime_alarm_set (EggIdletime *idletime, guint id, guint timeout)
{
- EggIdletimeAlarm *eggalarm;
+ EggIdletimeAlarm *eggalarm;
- g_return_val_if_fail (EGG_IS_IDLETIME (idletime), FALSE);
- g_return_val_if_fail (id != 0, FALSE);
- g_return_val_if_fail (timeout != 0, FALSE);
+ g_return_val_if_fail (EGG_IS_IDLETIME (idletime), FALSE);
+ g_return_val_if_fail (id != 0, FALSE);
+ g_return_val_if_fail (timeout != 0, FALSE);
- /* see if we already created an alarm with this ID */
- eggalarm = egg_idletime_alarm_find_id (idletime, id);
- if (eggalarm == NULL) {
- /* create a new alarm */
- eggalarm = egg_idletime_alarm_new (idletime, id);
+ /* see if we already created an alarm with this ID */
+ eggalarm = egg_idletime_alarm_find_id (idletime, id);
+ if (eggalarm == NULL) {
+ /* create a new alarm */
+ eggalarm = egg_idletime_alarm_new (idletime, id);
- /* add to array */
- g_ptr_array_add (idletime->priv->array, eggalarm);
- }
+ /* add to array */
+ g_ptr_array_add (idletime->priv->array, eggalarm);
+ }
- /* set the timeout */
- XSyncIntToValue (&eggalarm->timeout, (gint)timeout);
+ /* set the timeout */
+ XSyncIntToValue (&eggalarm->timeout, (gint)timeout);
- /* set, and start the timer */
- egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_POSITIVE);
- return TRUE;
+ /* set, and start the timer */
+ egg_idletime_xsync_alarm_set (idletime, eggalarm, EGG_IDLETIME_ALARM_TYPE_POSITIVE);
+ return TRUE;
}
/**
@@ -325,15 +325,15 @@ egg_idletime_alarm_set (EggIdletime *idletime, guint id, guint timeout)
static gboolean
egg_idletime_alarm_free (EggIdletime *idletime, EggIdletimeAlarm *eggalarm)
{
- g_return_val_if_fail (EGG_IS_IDLETIME (idletime), FALSE);
- g_return_val_if_fail (eggalarm != NULL, FALSE);
-
- if (eggalarm->xalarm)
- XSyncDestroyAlarm (idletime->priv->dpy, eggalarm->xalarm);
- g_object_unref (eggalarm->idletime);
- g_free (eggalarm);
- g_ptr_array_remove (idletime->priv->array, eggalarm);
- return TRUE;
+ g_return_val_if_fail (EGG_IS_IDLETIME (idletime), FALSE);
+ g_return_val_if_fail (eggalarm != NULL, FALSE);
+
+ if (eggalarm->xalarm)
+ XSyncDestroyAlarm (idletime->priv->dpy, eggalarm->xalarm);
+ g_object_unref (eggalarm->idletime);
+ g_free (eggalarm);
+ g_ptr_array_remove (idletime->priv->array, eggalarm);
+ return TRUE;
}
/**
@@ -342,15 +342,15 @@ egg_idletime_alarm_free (EggIdletime *idletime, EggIdletimeAlarm *eggalarm)
gboolean
egg_idletime_alarm_remove (EggIdletime *idletime, guint id)
{
- EggIdletimeAlarm *eggalarm;
+ EggIdletimeAlarm *eggalarm;
- g_return_val_if_fail (EGG_IS_IDLETIME (idletime), FALSE);
+ g_return_val_if_fail (EGG_IS_IDLETIME (idletime), FALSE);
- eggalarm = egg_idletime_alarm_find_id (idletime, id);
- if (eggalarm == NULL)
- return FALSE;
- egg_idletime_alarm_free (idletime, eggalarm);
- return TRUE;
+ eggalarm = egg_idletime_alarm_find_id (idletime, id);
+ if (eggalarm == NULL)
+ return FALSE;
+ egg_idletime_alarm_free (idletime, eggalarm);
+ return TRUE;
}
/**
@@ -359,23 +359,23 @@ egg_idletime_alarm_remove (EggIdletime *idletime, guint id)
static void
egg_idletime_class_init (EggIdletimeClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = egg_idletime_finalize;
-
- signals [SIGNAL_ALARM_EXPIRED] =
- g_signal_new ("alarm-expired",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggIdletimeClass, alarm_expired),
- NULL, NULL, g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [SIGNAL_RESET] =
- g_signal_new ("reset",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EggIdletimeClass, reset),
- NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = egg_idletime_finalize;
+
+ signals [SIGNAL_ALARM_EXPIRED] =
+ g_signal_new ("alarm-expired",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EggIdletimeClass, alarm_expired),
+ NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ signals [SIGNAL_RESET] =
+ g_signal_new ("reset",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EggIdletimeClass, reset),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
/**
@@ -384,47 +384,47 @@ egg_idletime_class_init (EggIdletimeClass *klass)
static void
egg_idletime_init (EggIdletime *idletime)
{
- int sync_error;
- int ncounters;
- XSyncSystemCounter *counters;
- EggIdletimeAlarm *eggalarm;
- guint i;
-
- idletime->priv = egg_idletime_get_instance_private (idletime);
-
- idletime->priv->array = g_ptr_array_new ();
-
- idletime->priv->reset_set = FALSE;
- idletime->priv->idle_counter = None;
- idletime->priv->sync_event = 0;
- idletime->priv->dpy = gdk_x11_get_default_xdisplay ();
-
- /* get the sync event */
- if (!XSyncQueryExtension (idletime->priv->dpy, &idletime->priv->sync_event, &sync_error)) {
- g_warning ("No Sync extension.");
- return;
- }
-
- /* gtk_init should do XSyncInitialize for us */
- counters = XSyncListSystemCounters (idletime->priv->dpy, &ncounters);
- for (i=0; i < (guint)ncounters && !idletime->priv->idle_counter; i++) {
- if (strcmp(counters[i].name, "IDLETIME") == 0)
- idletime->priv->idle_counter = counters[i].counter;
- }
- XSyncFreeSystemCounterList (counters);
-
- /* arh. we don't have IDLETIME support */
- if (!idletime->priv->idle_counter) {
- g_warning ("No idle counter.");
- return;
- }
-
- /* catch the timer alarm */
- gdk_window_add_filter (NULL, egg_idletime_event_filter_cb, idletime);
-
- /* create a reset alarm */
- eggalarm = egg_idletime_alarm_new (idletime, 0);
- g_ptr_array_add (idletime->priv->array, eggalarm);
+ int sync_error;
+ int ncounters;
+ XSyncSystemCounter *counters;
+ EggIdletimeAlarm *eggalarm;
+ guint i;
+
+ idletime->priv = egg_idletime_get_instance_private (idletime);
+
+ idletime->priv->array = g_ptr_array_new ();
+
+ idletime->priv->reset_set = FALSE;
+ idletime->priv->idle_counter = None;
+ idletime->priv->sync_event = 0;
+ idletime->priv->dpy = gdk_x11_get_default_xdisplay ();
+
+ /* get the sync event */
+ if (!XSyncQueryExtension (idletime->priv->dpy, &idletime->priv->sync_event, &sync_error)) {
+ g_warning ("No Sync extension.");
+ return;
+ }
+
+ /* gtk_init should do XSyncInitialize for us */
+ counters = XSyncListSystemCounters (idletime->priv->dpy, &ncounters);
+ for (i=0; i < (guint)ncounters && !idletime->priv->idle_counter; i++) {
+ if (strcmp(counters[i].name, "IDLETIME") == 0)
+ idletime->priv->idle_counter = counters[i].counter;
+ }
+ XSyncFreeSystemCounterList (counters);
+
+ /* arh. we don't have IDLETIME support */
+ if (!idletime->priv->idle_counter) {
+ g_warning ("No idle counter.");
+ return;
+ }
+
+ /* catch the timer alarm */
+ gdk_window_add_filter (NULL, egg_idletime_event_filter_cb, idletime);
+
+ /* create a reset alarm */
+ eggalarm = egg_idletime_alarm_new (idletime, 0);
+ g_ptr_array_add (idletime->priv->array, eggalarm);
}
/**
@@ -433,24 +433,24 @@ egg_idletime_init (EggIdletime *idletime)
static void
egg_idletime_finalize (GObject *object)
{
- guint i;
- EggIdletime *idletime;
- EggIdletimeAlarm *eggalarm;
+ guint i;
+ EggIdletime *idletime;
+ EggIdletimeAlarm *eggalarm;
- g_return_if_fail (object != NULL);
- g_return_if_fail (EGG_IS_IDLETIME (object));
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (EGG_IS_IDLETIME (object));
- idletime = EGG_IDLETIME (object);
- idletime->priv = egg_idletime_get_instance_private (idletime);
+ idletime = EGG_IDLETIME (object);
+ idletime->priv = egg_idletime_get_instance_private (idletime);
- /* free all counters, including reset counter */
- for (i=0; i<idletime->priv->array->len; i++) {
- eggalarm = g_ptr_array_index (idletime->priv->array, i);
- egg_idletime_alarm_free (idletime, eggalarm);
- }
- g_ptr_array_free (idletime->priv->array, TRUE);
+ /* free all counters, including reset counter */
+ for (i=0; i<idletime->priv->array->len; i++) {
+ eggalarm = g_ptr_array_index (idletime->priv->array, i);
+ egg_idletime_alarm_free (idletime, eggalarm);
+ }
+ g_ptr_array_free (idletime->priv->array, TRUE);
- G_OBJECT_CLASS (egg_idletime_parent_class)->finalize (object);
+ G_OBJECT_CLASS (egg_idletime_parent_class)->finalize (object);
}
/**
@@ -459,13 +459,13 @@ egg_idletime_finalize (GObject *object)
EggIdletime *
egg_idletime_new (void)
{
- if (egg_idletime_object != NULL) {
- g_object_ref (egg_idletime_object);
- } else {
- egg_idletime_object = g_object_new (EGG_IDLETIME_TYPE, NULL);
- g_object_add_weak_pointer (egg_idletime_object, &egg_idletime_object);
- }
- return EGG_IDLETIME (egg_idletime_object);
+ if (egg_idletime_object != NULL) {
+ g_object_ref (egg_idletime_object);
+ } else {
+ egg_idletime_object = g_object_new (EGG_IDLETIME_TYPE, NULL);
+ g_object_add_weak_pointer (egg_idletime_object, &egg_idletime_object);
+ }
+ return EGG_IDLETIME (egg_idletime_object);
}
/***************************************************************************
@@ -477,12 +477,12 @@ egg_idletime_new (void)
static void
egg_test_egg_idletime_wait (guint time_ms)
{
- GTimer *ltimer = g_timer_new ();
- gfloat goal = time_ms / (gfloat) 1000.0f;
- do {
- g_main_context_iteration (NULL, FALSE);
- } while (g_timer_elapsed (ltimer, NULL) < goal);
- g_timer_destroy (ltimer);
+ GTimer *ltimer = g_timer_new ();
+ gfloat goal = time_ms / (gfloat) 1000.0f;
+ do {
+ g_main_context_iteration (NULL, FALSE);
+ } while (g_timer_elapsed (ltimer, NULL) < goal);
+ g_timer_destroy (ltimer);
}
static guint last_alarm = 0;
@@ -492,196 +492,196 @@ GTimer *timer;
static void
gpm_alarm_expired_cb (EggIdletime *idletime, guint alarm, gpointer data)
{
- last_alarm = alarm;
- event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
-// g_print ("[evt %i in %ims]\n", alarm, event_time);
+ last_alarm = alarm;
+ event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
+// g_print ("[evt %i in %ims]\n", alarm, event_time);
}
static void
wait_until_alarm (void)
{
- g_print ("*****************************\n");
- g_print ("*** DO NOT MOVE THE MOUSE ***\n");
- g_print ("*****************************\n");
- while (last_alarm == 0)
- g_main_context_iteration (NULL, FALSE);
+ g_print ("*****************************\n");
+ g_print ("*** DO NOT MOVE THE MOUSE ***\n");
+ g_print ("*****************************\n");
+ while (last_alarm == 0)
+ g_main_context_iteration (NULL, FALSE);
}
static void
wait_until_reset (void)
{
- if (last_alarm == 0)
- return;
- g_print ("*****************************\n");
- g_print ("*** MOVE THE MOUSE ***\n");
- g_print ("*****************************\n");
- while (last_alarm != 0)
- g_main_context_iteration (NULL, FALSE);
- egg_test_egg_idletime_wait (1000);
+ if (last_alarm == 0)
+ return;
+ g_print ("*****************************\n");
+ g_print ("*** MOVE THE MOUSE ***\n");
+ g_print ("*****************************\n");
+ while (last_alarm != 0)
+ g_main_context_iteration (NULL, FALSE);
+ egg_test_egg_idletime_wait (1000);
}
void
egg_idletime_test (gpointer data)
{
- EggIdletime *idletime;
- gboolean ret;
- guint i;
- EggTest *test = (EggTest *) data;
-
- if (egg_test_start (test, "EggIdletime") == FALSE)
- return;
-
- timer = g_timer_new ();
- gdk_init (NULL, NULL);
-
- /* warn */
-
- g_timer_start (timer);
- /************************************************************/
- egg_test_title (test, "check to see if delay works as expected");
- egg_test_egg_idletime_wait (2000);
- event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
- if (event_time > 1800 && event_time < 2200) {
- egg_test_success (test, "time %i~=%i", 2000, event_time);
- } else {
- egg_test_failed (test, "time not the same! %i != %i", event_time, 2000);
- }
-
- /************************************************************/
- egg_test_title (test, "make sure we get a non null device");
- idletime = egg_idletime_new ();
- if (idletime != NULL) {
- egg_test_success (test, "got EggIdletime");
- } else {
- egg_test_failed (test, "could not get EggIdletime");
- }
- g_signal_connect (idletime, "alarm-expired",
- G_CALLBACK (gpm_alarm_expired_cb), NULL);
-
- /************************************************************/
- egg_test_title (test, "check if we are alarm zero with no alarms");
- if (last_alarm == 0) {
- egg_test_success (test, NULL);
- } else {
- egg_test_failed (test, "alarm %i set!", last_alarm);
- }
-
- /************************************************************/
- egg_test_title (test, "check if we can set an reset alarm");
- ret = egg_idletime_alarm_set (idletime, 0, 100);
- if (!ret) {
- egg_test_success (test, "ignored reset alarm");
- } else {
- egg_test_failed (test, "did not ignore reset alarm");
- }
-
- /************************************************************/
- egg_test_title (test, "check if we can set an alarm timeout of zero");
- ret = egg_idletime_alarm_set (idletime, 999, 0);
- if (!ret) {
- egg_test_success (test, "ignored invalid alarm");
- } else {
- egg_test_failed (test, "did not ignore invalid alarm");
- }
-
- /************************************************************/
- g_timer_start (timer);
- egg_test_title (test, "check if we can set an alarm");
- ret = egg_idletime_alarm_set (idletime, 101, 5000);
- if (ret) {
- egg_test_success (test, "set alarm okay");
- } else {
- egg_test_failed (test, "could not set alarm");
- }
-
- egg_idletime_alarm_set (idletime, 101, 5000);
- wait_until_alarm ();
-
- /* loop this two times */
- for (i=0; i<2; i++) {
- /* just let it time out, and wait for human input */
- wait_until_reset ();
- g_timer_start (timer);
-
- /************************************************************/
- g_timer_start (timer);
- egg_test_title (test, "check if we can set an alarm");
- ret = egg_idletime_alarm_set (idletime, 101, 5000);
- if (ret) {
- egg_test_success (test, "set alarm 5000ms okay");
- } else {
- egg_test_failed (test, "could not set alarm 5000ms");
- }
-
- /* wait for alarm to go off */
- wait_until_alarm ();
- g_timer_start (timer);
-
- /************************************************************/
- egg_test_title (test, "check if correct alarm has gone off");
- if (last_alarm == 101) {
- egg_test_success (test, "correct alarm");
- } else {
- egg_test_failed (test, "alarm %i set!", last_alarm);
- }
-
- /************************************************************/
- egg_test_title (test, "check if alarm has gone off in correct time");
- if (event_time > 3000 && event_time < 6000) {
- egg_test_success (test, "correct, timeout ideally %ims (we did after %ims)", 5000, event_time);
- } else {
- egg_test_failed (test, "alarm %i did not timeout correctly !", last_alarm);
- }
- }
-
- /* just let it time out, and wait for human input */
- wait_until_reset ();
- g_timer_start (timer);
-
- /************************************************************/
- g_timer_start (timer);
- egg_test_title (test, "check if we can set an existing alarm");
- ret = egg_idletime_alarm_set (idletime, 101, 10000);
- if (ret) {
- egg_test_success (test, "set alarm 10000ms okay");
- } else {
- egg_test_failed (test, "could not set alarm 10000ms");
- }
-
- /* wait for alarm to go off */
- wait_until_alarm ();
- g_timer_start (timer);
-
- /************************************************************/
- egg_test_title (test, "check if alarm has gone off in the old time");
- if (event_time > 5000) {
- egg_test_success (test, "last timeout value used");
- } else {
- egg_test_failed (test, "incorrect timeout used %ims", event_time);
- }
-
- /************************************************************/
- egg_test_title (test, "check if we can remove an invalid alarm");
- ret = egg_idletime_alarm_remove (idletime, 202);
- if (!ret) {
- egg_test_success (test, "ignored invalid alarm");
- } else {
- egg_test_failed (test, "removed invalid alarm");
- }
-
- /************************************************************/
- egg_test_title (test, "check if we can remove an valid alarm");
- ret = egg_idletime_alarm_remove (idletime, 101);
- if (ret) {
- egg_test_success (test, "removed valid alarm");
- } else {
- egg_test_failed (test, "failed to remove valid alarm");
- }
-
- g_timer_destroy (timer);
- g_object_unref (idletime);
-
- egg_test_end (test);
+ EggIdletime *idletime;
+ gboolean ret;
+ guint i;
+ EggTest *test = (EggTest *) data;
+
+ if (egg_test_start (test, "EggIdletime") == FALSE)
+ return;
+
+ timer = g_timer_new ();
+ gdk_init (NULL, NULL);
+
+ /* warn */
+
+ g_timer_start (timer);
+ /************************************************************/
+ egg_test_title (test, "check to see if delay works as expected");
+ egg_test_egg_idletime_wait (2000);
+ event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
+ if (event_time > 1800 && event_time < 2200) {
+ egg_test_success (test, "time %i~=%i", 2000, event_time);
+ } else {
+ egg_test_failed (test, "time not the same! %i != %i", event_time, 2000);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "make sure we get a non null device");
+ idletime = egg_idletime_new ();
+ if (idletime != NULL) {
+ egg_test_success (test, "got EggIdletime");
+ } else {
+ egg_test_failed (test, "could not get EggIdletime");
+ }
+ g_signal_connect (idletime, "alarm-expired",
+ G_CALLBACK (gpm_alarm_expired_cb), NULL);
+
+ /************************************************************/
+ egg_test_title (test, "check if we are alarm zero with no alarms");
+ if (last_alarm == 0) {
+ egg_test_success (test, NULL);
+ } else {
+ egg_test_failed (test, "alarm %i set!", last_alarm);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "check if we can set an reset alarm");
+ ret = egg_idletime_alarm_set (idletime, 0, 100);
+ if (!ret) {
+ egg_test_success (test, "ignored reset alarm");
+ } else {
+ egg_test_failed (test, "did not ignore reset alarm");
+ }
+
+ /************************************************************/
+ egg_test_title (test, "check if we can set an alarm timeout of zero");
+ ret = egg_idletime_alarm_set (idletime, 999, 0);
+ if (!ret) {
+ egg_test_success (test, "ignored invalid alarm");
+ } else {
+ egg_test_failed (test, "did not ignore invalid alarm");
+ }
+
+ /************************************************************/
+ g_timer_start (timer);
+ egg_test_title (test, "check if we can set an alarm");
+ ret = egg_idletime_alarm_set (idletime, 101, 5000);
+ if (ret) {
+ egg_test_success (test, "set alarm okay");
+ } else {
+ egg_test_failed (test, "could not set alarm");
+ }
+
+ egg_idletime_alarm_set (idletime, 101, 5000);
+ wait_until_alarm ();
+
+ /* loop this two times */
+ for (i=0; i<2; i++) {
+ /* just let it time out, and wait for human input */
+ wait_until_reset ();
+ g_timer_start (timer);
+
+ /************************************************************/
+ g_timer_start (timer);
+ egg_test_title (test, "check if we can set an alarm");
+ ret = egg_idletime_alarm_set (idletime, 101, 5000);
+ if (ret) {
+ egg_test_success (test, "set alarm 5000ms okay");
+ } else {
+ egg_test_failed (test, "could not set alarm 5000ms");
+ }
+
+ /* wait for alarm to go off */
+ wait_until_alarm ();
+ g_timer_start (timer);
+
+ /************************************************************/
+ egg_test_title (test, "check if correct alarm has gone off");
+ if (last_alarm == 101) {
+ egg_test_success (test, "correct alarm");
+ } else {
+ egg_test_failed (test, "alarm %i set!", last_alarm);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "check if alarm has gone off in correct time");
+ if (event_time > 3000 && event_time < 6000) {
+ egg_test_success (test, "correct, timeout ideally %ims (we did after %ims)", 5000, event_time);
+ } else {
+ egg_test_failed (test, "alarm %i did not timeout correctly !", last_alarm);
+ }
+ }
+
+ /* just let it time out, and wait for human input */
+ wait_until_reset ();
+ g_timer_start (timer);
+
+ /************************************************************/
+ g_timer_start (timer);
+ egg_test_title (test, "check if we can set an existing alarm");
+ ret = egg_idletime_alarm_set (idletime, 101, 10000);
+ if (ret) {
+ egg_test_success (test, "set alarm 10000ms okay");
+ } else {
+ egg_test_failed (test, "could not set alarm 10000ms");
+ }
+
+ /* wait for alarm to go off */
+ wait_until_alarm ();
+ g_timer_start (timer);
+
+ /************************************************************/
+ egg_test_title (test, "check if alarm has gone off in the old time");
+ if (event_time > 5000) {
+ egg_test_success (test, "last timeout value used");
+ } else {
+ egg_test_failed (test, "incorrect timeout used %ims", event_time);
+ }
+
+ /************************************************************/
+ egg_test_title (test, "check if we can remove an invalid alarm");
+ ret = egg_idletime_alarm_remove (idletime, 202);
+ if (!ret) {
+ egg_test_success (test, "ignored invalid alarm");
+ } else {
+ egg_test_failed (test, "removed invalid alarm");
+ }
+
+ /************************************************************/
+ egg_test_title (test, "check if we can remove an valid alarm");
+ ret = egg_idletime_alarm_remove (idletime, 101);
+ if (ret) {
+ egg_test_success (test, "removed valid alarm");
+ } else {
+ egg_test_failed (test, "failed to remove valid alarm");
+ }
+
+ g_timer_destroy (timer);
+ g_object_unref (idletime);
+
+ egg_test_end (test);
}
#endif
diff --git a/src/egg-idletime.h b/src/egg-idletime.h
index d8d801b..0eb3fa2 100644
--- a/src/egg-idletime.h
+++ b/src/egg-idletime.h
@@ -26,52 +26,51 @@
G_BEGIN_DECLS
-#define EGG_IDLETIME_TYPE (egg_idletime_get_type ())
-#define EGG_IDLETIME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_IDLETIME_TYPE, EggIdletime))
-#define EGG_IDLETIME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_IDLETIME_TYPE, EggIdletimeClass))
-#define EGG_IS_IDLETIME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_IDLETIME_TYPE))
-#define EGG_IS_IDLETIME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_IDLETIME_TYPE))
-#define EGG_IDLETIME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_IDLETIME_TYPE, EggIdletimeClass))
+#define EGG_IDLETIME_TYPE (egg_idletime_get_type ())
+#define EGG_IDLETIME(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_IDLETIME_TYPE, EggIdletime))
+#define EGG_IDLETIME_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_IDLETIME_TYPE, EggIdletimeClass))
+#define EGG_IS_IDLETIME(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_IDLETIME_TYPE))
+#define EGG_IS_IDLETIME_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_IDLETIME_TYPE))
+#define EGG_IDLETIME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_IDLETIME_TYPE, EggIdletimeClass))
enum
{
- TIMEOUT_INPUT = 0,
- TIMEOUT_BRIGHTNESS_ON_AC,
- TIMEOUT_BRIGHTNESS_ON_BATTERY,
- TIMEOUT_INACTIVITY_ON_AC,
- TIMEOUT_INACTIVITY_ON_BATTERY
+ TIMEOUT_INPUT = 0,
+ TIMEOUT_BRIGHTNESS_ON_AC,
+ TIMEOUT_BRIGHTNESS_ON_BATTERY,
+ TIMEOUT_INACTIVITY_ON_AC,
+ TIMEOUT_INACTIVITY_ON_BATTERY
};
typedef struct EggIdletimePrivate EggIdletimePrivate;
typedef struct
{
- GObject parent;
- EggIdletimePrivate *priv;
+ GObject parent;
+ EggIdletimePrivate *priv;
} EggIdletime;
typedef struct
{
- GObjectClass parent_class;
- void (* alarm_expired) (EggIdletime *idletime,
- guint timer_id);
- void (* reset) (EggIdletime *idletime);
+ GObjectClass parent_class;
+ void (* alarm_expired) (EggIdletime *idletime,
+ guint timer_id);
+ void (* reset) (EggIdletime *idletime);
} EggIdletimeClass;
-GType egg_idletime_get_type (void);
-EggIdletime *egg_idletime_new (void);
-
-void egg_idletime_alarm_reset_all (EggIdletime *idletime);
-gboolean egg_idletime_alarm_set (EggIdletime *idletime,
- guint alarm_id,
- guint timeout);
-gboolean egg_idletime_alarm_remove (EggIdletime *idletime,
- guint alarm_id);
-gint64 egg_idletime_get_time (EggIdletime *idletime);
+GType egg_idletime_get_type (void);
+EggIdletime *egg_idletime_new (void);
+void egg_idletime_alarm_reset_all (EggIdletime *idletime);
+gboolean egg_idletime_alarm_set (EggIdletime *idletime,
+ guint alarm_id,
+ guint timeout);
+gboolean egg_idletime_alarm_remove (EggIdletime *idletime,
+ guint alarm_id);
+gint64 egg_idletime_get_time (EggIdletime *idletime);
#ifdef EGG_TEST
-void egg_idletime_test (gpointer data);
+void egg_idletime_test (gpointer data);
#endif
G_END_DECLS
-#endif /* __EGG_IDLETIME_H */
+#endif /* __EGG_IDLETIME_H */
diff --git a/src/xfce-screensaver.c b/src/xfce-screensaver.c
index 6d8d98a..39c6cff 100644
--- a/src/xfce-screensaver.c
+++ b/src/xfce-screensaver.c
@@ -64,33 +64,33 @@ static void xfce_screensaver_get_property(GObject *object,
typedef enum
{
- SCREENSAVER_TYPE_NONE,
- SCREENSAVER_TYPE_FREEDESKTOP,
- SCREENSAVER_TYPE_CINNAMON,
- SCREENSAVER_TYPE_MATE,
- SCREENSAVER_TYPE_GNOME,
- SCREENSAVER_TYPE_XFCE,
- SCREENSAVER_TYPE_OTHER,
- N_SCREENSAVER_TYPE
+ SCREENSAVER_TYPE_NONE,
+ SCREENSAVER_TYPE_FREEDESKTOP,
+ SCREENSAVER_TYPE_CINNAMON,
+ SCREENSAVER_TYPE_MATE,
+ SCREENSAVER_TYPE_GNOME,
+ SCREENSAVER_TYPE_XFCE,
+ SCREENSAVER_TYPE_OTHER,
+ N_SCREENSAVER_TYPE
} ScreenSaverType;
enum
{
- PROP_0 = 0,
- PROP_HEARTBEAT_COMMAND,
- PROP_LOCK_COMMAND
+ PROP_0 = 0,
+ PROP_HEARTBEAT_COMMAND,
+ PROP_LOCK_COMMAND
};
struct XfceScreenSaverPrivate
{
- guint cookie;
- gchar *heartbeat_command;
- gchar *lock_command;
- GDBusProxy *proxy;
- guint screensaver_id;
- ScreenSaverType screensaver_type;
- XfconfChannel *xfpm_channel;
- XfconfChannel *xfsm_channel;
+ guint cookie;
+ gchar *heartbeat_command;
+ gchar *lock_command;
+ GDBusProxy *proxy;
+ guint screensaver_id;
+ ScreenSaverType screensaver_type;
+ XfconfChannel *xfpm_channel;
+ XfconfChannel *xfsm_channel;
};
@@ -100,31 +100,31 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfceScreenSaver, xfce_screensaver, G_TYPE_OBJECT)
static void
xfce_screensaver_class_init (XfceScreenSaverClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
- object_class->finalize = xfce_screensvaer_finalize;
- object_class->set_property = xfce_screensaver_set_property;
- object_class->get_property = xfce_screensaver_get_property;
+ object_class->finalize = xfce_screensvaer_finalize;
+ object_class->set_property = xfce_screensaver_set_property;
+ object_class->get_property = xfce_screensaver_get_property;
#define XFCE_PARAM_FLAGS (G_PARAM_READWRITE \
- | G_PARAM_CONSTRUCT \
- | G_PARAM_STATIC_NAME \
- | G_PARAM_STATIC_NICK \
- | G_PARAM_STATIC_BLURB)
-
- /* heartbeat command - to inhibit the screensaver from activating,
- * i.e. xscreensaver-command -deactivate */
- g_object_class_install_property(object_class, PROP_HEARTBEAT_COMMAND,
- g_param_spec_string(HEARTBEAT_COMMAND,
+ | G_PARAM_CONSTRUCT \
+ | G_PARAM_STATIC_NAME \
+ | G_PARAM_STATIC_NICK \
+ | G_PARAM_STATIC_BLURB)
+
+ /* heartbeat command - to inhibit the screensaver from activating,
+ * i.e. xscreensaver-command -deactivate */
+ g_object_class_install_property (object_class, PROP_HEARTBEAT_COMMAND,
+ g_param_spec_string (HEARTBEAT_COMMAND,
HEARTBEAT_COMMAND,
"Inhibit the screensaver from activating, "
"i.e. xscreensaver-command -deactivate",
"xscreensaver-command -deactivate",
XFCE_PARAM_FLAGS));
- /* lock command - to lock the desktop, i.e. xscreensaver-command -lock */
- g_object_class_install_property(object_class, PROP_LOCK_COMMAND,
- g_param_spec_string(LOCK_COMMAND,
+ /* lock command - to lock the desktop, i.e. xscreensaver-command -lock */
+ g_object_class_install_property (object_class, PROP_LOCK_COMMAND,
+ g_param_spec_string (LOCK_COMMAND,
LOCK_COMMAND,
"Lock the desktop, i.e. "
"xscreensaver-command -lock",
@@ -139,29 +139,29 @@ xfce_screensaver_set_property(GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- XfceScreenSaver *saver = XFCE_SCREENSAVER (object);
+ XfceScreenSaver *saver = XFCE_SCREENSAVER (object);
- switch(property_id) {
- case PROP_HEARTBEAT_COMMAND:
- {
- g_free (saver->priv->heartbeat_command);
- saver->priv->heartbeat_command = g_value_dup_string (value);
- DBG ("saver->priv->heartbeat_command %s", saver->priv->heartbeat_command);
- break;
- }
- case PROP_LOCK_COMMAND:
- {
- g_free (saver->priv->lock_command);
- saver->priv->lock_command = g_value_dup_string (value);
- DBG ("saver->priv->lock_command %s", saver->priv->lock_command);
- break;
- }
- default:
- {
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
+ switch(property_id) {
+ case PROP_HEARTBEAT_COMMAND:
+ {
+ g_free (saver->priv->heartbeat_command);
+ saver->priv->heartbeat_command = g_value_dup_string (value);
+ DBG ("saver->priv->heartbeat_command %s", saver->priv->heartbeat_command);
+ break;
+ }
+ case PROP_LOCK_COMMAND:
+ {
+ g_free (saver->priv->lock_command);
+ saver->priv->lock_command = g_value_dup_string (value);
+ DBG ("saver->priv->lock_command %s", saver->priv->lock_command);
+ break;
}
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
+ }
}
static void
@@ -170,21 +170,21 @@ xfce_screensaver_get_property(GObject *object,
GValue *value,
GParamSpec *pspec)
{
- XfceScreenSaver *saver = XFCE_SCREENSAVER (object);
+ XfceScreenSaver *saver = XFCE_SCREENSAVER (object);
- switch(property_id) {
- case PROP_HEARTBEAT_COMMAND:
- g_value_set_string (value, saver->priv->heartbeat_command);
- break;
+ switch(property_id) {
+ case PROP_HEARTBEAT_COMMAND:
+ g_value_set_string (value, saver->priv->heartbeat_command);
+ break;
- case PROP_LOCK_COMMAND:
- g_value_set_string (value, saver->priv->lock_command);
- break;
+ case PROP_LOCK_COMMAND:
+ g_value_set_string (value, saver->priv->lock_command);
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
- }
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
+ }
}
static gboolean
@@ -193,136 +193,135 @@ screen_saver_proxy_setup(XfceScreenSaver *saver,
const gchar *object_path,
const gchar *interface)
{
- GDBusProxy *proxy;
-
- proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- name,
- object_path,
- interface,
- NULL,
- NULL);
-
- if (proxy != NULL)
+ GDBusProxy *proxy;
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ name,
+ object_path,
+ interface,
+ NULL,
+ NULL);
+
+ if (proxy != NULL)
+ {
+ gchar *owner = NULL;
+ /* is there anyone actually providing a service? */
+ owner = g_dbus_proxy_get_name_owner (proxy);
+ if (owner != NULL)
{
- gchar *owner = NULL;
- /* is there anyone actually providing a service? */
- owner = g_dbus_proxy_get_name_owner (proxy);
- if (owner != NULL)
- {
- DBG ("proxy owner: %s", owner);
- saver->priv->proxy = proxy;
- g_free (owner);
- return TRUE;
- }
- else
- {
- /* not using this proxy, nobody's home */
- g_object_unref (proxy);
- }
+ DBG ("proxy owner: %s", owner);
+ saver->priv->proxy = proxy;
+ g_free (owner);
+ return TRUE;
+ }
+ else
+ {
+ /* not using this proxy, nobody's home */
+ g_object_unref (proxy);
}
+ }
- return FALSE;
+ return FALSE;
}
static void
xfce_screensaver_setup(XfceScreenSaver *saver)
{
- /* Try to use the freedesktop dbus API */
- if (screen_saver_proxy_setup (saver,
- "org.freedesktop.ScreenSaver",
- "/org/freedesktop/ScreenSaver",
- "org.freedesktop.ScreenSaver"))
- {
- DBG ("using freedesktop compliant screensaver daemon");
- saver->priv->screensaver_type = SCREENSAVER_TYPE_FREEDESKTOP;
- } else if (screen_saver_proxy_setup (saver,
- "org.cinnamon.ScreenSaver",
- "/org/cinnamon/ScreenSaver",
- "org.cinnamon.ScreenSaver"))
- {
- DBG ("using cinnamon screensaver daemon");
- saver->priv->screensaver_type = SCREENSAVER_TYPE_CINNAMON;
- } else if (screen_saver_proxy_setup (saver,
- "org.mate.ScreenSaver",
- "/org/mate/ScreenSaver",
- "org.mate.ScreenSaver"))
- {
- DBG ("using mate screensaver daemon");
- saver->priv->screensaver_type = SCREENSAVER_TYPE_MATE;
- } else if (screen_saver_proxy_setup (saver,
- "org.gnome.ScreenSaver",
- "/org/gnome/ScreenSaver",
- "org.gnome.ScreenSaver"))
- {
- DBG ("using gnome screensaver daemon");
- saver->priv->screensaver_type = SCREENSAVER_TYPE_GNOME;
- } else if (screen_saver_proxy_setup (saver,
- "org.xfce.ScreenSaver",
- "/org.xfce/ScreenSaver",
- "org.xfce.ScreenSaver"))
- {
- DBG ("using Xfce screensaver daemon");
- saver->priv->screensaver_type = SCREENSAVER_TYPE_XFCE;
- }
- else
- {
- DBG ("using command line screensaver interface");
- saver->priv->screensaver_type = SCREENSAVER_TYPE_OTHER;
- }
+ /* Try to use the freedesktop dbus API */
+ if (screen_saver_proxy_setup (saver,
+ "org.freedesktop.ScreenSaver",
+ "/org/freedesktop/ScreenSaver",
+ "org.freedesktop.ScreenSaver"))
+ {
+ DBG ("using freedesktop compliant screensaver daemon");
+ saver->priv->screensaver_type = SCREENSAVER_TYPE_FREEDESKTOP;
+ } else if (screen_saver_proxy_setup (saver,
+ "org.cinnamon.ScreenSaver",
+ "/org/cinnamon/ScreenSaver",
+ "org.cinnamon.ScreenSaver"))
+ {
+ DBG ("using cinnamon screensaver daemon");
+ saver->priv->screensaver_type = SCREENSAVER_TYPE_CINNAMON;
+ } else if (screen_saver_proxy_setup (saver,
+ "org.mate.ScreenSaver",
+ "/org/mate/ScreenSaver",
+ "org.mate.ScreenSaver"))
+ {
+ DBG ("using mate screensaver daemon");
+ saver->priv->screensaver_type = SCREENSAVER_TYPE_MATE;
+ } else if (screen_saver_proxy_setup (saver,
+ "org.gnome.ScreenSaver",
+ "/org/gnome/ScreenSaver",
+ "org.gnome.ScreenSaver"))
+ {
+ DBG ("using gnome screensaver daemon");
+ saver->priv->screensaver_type = SCREENSAVER_TYPE_GNOME;
+ } else if (screen_saver_proxy_setup (saver,
+ "org.xfce.ScreenSaver",
+ "/org.xfce/ScreenSaver",
+ "org.xfce.ScreenSaver"))
+ {
+ DBG ("using Xfce screensaver daemon");
+ saver->priv->screensaver_type = SCREENSAVER_TYPE_XFCE;
+ }
+ else
+ {
+ DBG ("using command line screensaver interface");
+ saver->priv->screensaver_type = SCREENSAVER_TYPE_OTHER;
+ }
}
static void
xfce_screensaver_init (XfceScreenSaver *saver)
{
- GError *error = NULL;
-
- saver->priv = xfce_screensaver_get_instance_private (saver);
-
- if ( !xfconf_init (&error) )
- {
- g_critical ("xfconf_init failed: %s\n", error->message);
- g_clear_error (&error);
- }
- else
- {
- saver->priv->xfpm_channel = xfconf_channel_get (XFPM_CHANNEL);
- saver->priv->xfsm_channel = xfconf_channel_get (XFSM_CHANNEL);
-
- }
-
- xfce_screensaver_setup (saver);
+ GError *error = NULL;
+
+ saver->priv = xfce_screensaver_get_instance_private (saver);
+
+ if ( !xfconf_init (&error) )
+ {
+ g_critical ("xfconf_init failed: %s\n", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ saver->priv->xfpm_channel = xfconf_channel_get (XFPM_CHANNEL);
+ saver->priv->xfsm_channel = xfconf_channel_get (XFSM_CHANNEL);
+ }
+
+ xfce_screensaver_setup (saver);
}
static void
xfce_screensvaer_finalize (GObject *object)
{
- XfceScreenSaver *saver = XFCE_SCREENSAVER (object);
-
- if (saver->priv->screensaver_id != 0)
- {
- g_source_remove (saver->priv->screensaver_id);
- saver->priv->screensaver_id = 0;
- }
-
- if (saver->priv->proxy)
- {
- g_object_unref (saver->priv->proxy);
- saver->priv->proxy = NULL;
- }
-
- if (saver->priv->heartbeat_command)
- {
- g_free (saver->priv->heartbeat_command);
- saver->priv->heartbeat_command = NULL;
- }
-
- if (saver->priv->lock_command)
- {
- g_free (saver->priv->heartbeat_command);
- saver->priv->heartbeat_command = NULL;
- }
+ XfceScreenSaver *saver = XFCE_SCREENSAVER (object);
+
+ if (saver->priv->screensaver_id != 0)
+ {
+ g_source_remove (saver->priv->screensaver_id);
+ saver->priv->screensaver_id = 0;
+ }
+
+ if (saver->priv->proxy)
+ {
+ g_object_unref (saver->priv->proxy);
+ saver->priv->proxy = NULL;
+ }
+
+ if (saver->priv->heartbeat_command)
+ {
+ g_free (saver->priv->heartbeat_command);
+ saver->priv->heartbeat_command = NULL;
+ }
+
+ if (saver->priv->lock_command)
+ {
+ g_free (saver->priv->heartbeat_command);
+ saver->priv->heartbeat_command = NULL;
+ }
}
/**
@@ -336,61 +335,61 @@ xfce_screensvaer_finalize (GObject *object)
XfceScreenSaver *
xfce_screensaver_new (void)
{
- static gpointer *saver = NULL;
-
- if (saver != NULL)
- {
- g_object_ref (saver);
- }
- else
- {
- saver = g_object_new (XFCE_TYPE_SCREENSAVER, NULL);
-
- g_object_add_weak_pointer (G_OBJECT (saver), (gpointer *) &saver);
-
- xfconf_g_property_bind (XFCE_SCREENSAVER (saver)->priv->xfpm_channel,
- XFPM_PROPERTIES_PREFIX HEARTBEAT_COMMAND,
- G_TYPE_STRING,
- G_OBJECT(saver),
- HEARTBEAT_COMMAND);
-
- xfconf_g_property_bind (XFCE_SCREENSAVER (saver)->priv->xfsm_channel,
- XFSM_PROPERTIES_PREFIX LOCK_COMMAND,
- G_TYPE_STRING,
- G_OBJECT(saver),
- LOCK_COMMAND);
- }
-
- return XFCE_SCREENSAVER (saver);
+ static gpointer *saver = NULL;
+
+ if (saver != NULL)
+ {
+ g_object_ref (saver);
+ }
+ else
+ {
+ saver = g_object_new (XFCE_TYPE_SCREENSAVER, NULL);
+
+ g_object_add_weak_pointer (G_OBJECT (saver), (gpointer *) &saver);
+
+ xfconf_g_property_bind (XFCE_SCREENSAVER (saver)->priv->xfpm_channel,
+ XFPM_PROPERTIES_PREFIX HEARTBEAT_COMMAND,
+ G_TYPE_STRING,
+ G_OBJECT(saver),
+ HEARTBEAT_COMMAND);
+
+ xfconf_g_property_bind (XFCE_SCREENSAVER (saver)->priv->xfsm_channel,
+ XFSM_PROPERTIES_PREFIX LOCK_COMMAND,
+ G_TYPE_STRING,
+ G_OBJECT(saver),
+ LOCK_COMMAND);
+ }
+
+ return XFCE_SCREENSAVER (saver);
}
static gboolean
xfce_reset_screen_saver (XfceScreenSaver *saver)
{
- TRACE("entering");
-
- /* If we found an interface during the setup, use it */
- if (saver->priv->proxy)
+ TRACE("entering");
+
+ /* If we found an interface during the setup, use it */
+ if (saver->priv->proxy)
+ {
+ GVariant *response = g_dbus_proxy_call_sync (saver->priv->proxy,
+ "SimulateUserActivity",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+ if (response != NULL)
{
- GVariant *response = g_dbus_proxy_call_sync (saver->priv->proxy,
- "SimulateUserActivity",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (response != NULL)
- {
- g_variant_unref (response);
- }
- } else if (saver->priv->heartbeat_command)
- {
- DBG ("running heartbeat command: %s", saver->priv->heartbeat_command);
- g_spawn_command_line_async (saver->priv->heartbeat_command, NULL);
+ g_variant_unref (response);
}
-
- /* continue until we're removed */
- return TRUE;
+ } else if (saver->priv->heartbeat_command)
+ {
+ DBG ("running heartbeat command: %s", saver->priv->heartbeat_command);
+ g_spawn_command_line_async (saver->priv->heartbeat_command, NULL);
+ }
+
+ /* continue until we're removed */
+ return TRUE;
}
/**
@@ -410,79 +409,80 @@ void
xfce_screensaver_inhibit (XfceScreenSaver *saver,
gboolean inhibit)
{
- /* SCREENSAVER_TYPE_FREEDESKTOP, SCREENSAVER_TYPE_MATE,
- * SCREENSAVER_TYPE_GNOME and SCREENSAVER_TYPE_XFCE
- * don't need a periodic timer because they have an actual
- * inhibit/uninhibit setup */
- switch (saver->priv->screensaver_type) {
- case SCREENSAVER_TYPE_FREEDESKTOP:
- case SCREENSAVER_TYPE_MATE:
- case SCREENSAVER_TYPE_GNOME:
- case SCREENSAVER_TYPE_XFCE:
- {
- if (inhibit)
- {
- GVariant *response = NULL;
- response = g_dbus_proxy_call_sync (saver->priv->proxy,
- "Inhibit",
- g_variant_new ("(ss)",
- PACKAGE_NAME,
- "Inhibit requested"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL, NULL);
- if (response != NULL)
- {
- g_variant_get (response, "(u)",
- &saver->priv->cookie);
- g_variant_unref (response);
- }
- }
- else
- {
- GVariant *response = NULL;
- response = g_dbus_proxy_call_sync (saver->priv->proxy,
- "UnInhibit",
- g_variant_new ("(u)",
- saver->priv->cookie),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL, NULL);
-
- saver->priv->cookie = 0;
- if (response != NULL)
- {
- g_variant_unref (response);
- }
- }
- break;
- }
- case SCREENSAVER_TYPE_OTHER:
- case SCREENSAVER_TYPE_CINNAMON:
+ /* SCREENSAVER_TYPE_FREEDESKTOP, SCREENSAVER_TYPE_MATE,
+ * SCREENSAVER_TYPE_GNOME and SCREENSAVER_TYPE_XFCE
+ * don't need a periodic timer because they have an actual
+ * inhibit/uninhibit setup */
+ switch (saver->priv->screensaver_type)
+ {
+ case SCREENSAVER_TYPE_FREEDESKTOP:
+ case SCREENSAVER_TYPE_MATE:
+ case SCREENSAVER_TYPE_GNOME:
+ case SCREENSAVER_TYPE_XFCE:
+ {
+ if (inhibit)
+ {
+ GVariant *response = NULL;
+ response = g_dbus_proxy_call_sync (saver->priv->proxy,
+ "Inhibit",
+ g_variant_new ("(ss)",
+ PACKAGE_NAME,
+ "Inhibit requested"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, NULL);
+ if (response != NULL)
{
- /* remove any existing keepalive */
- if (saver->priv->screensaver_id != 0)
- {
- g_source_remove (saver->priv->screensaver_id);
- saver->priv->screensaver_id = 0;
- }
-
- if (inhibit)
- {
- /* Reset the screensaver timers every so often
- * so they don't activate */
- saver->priv->screensaver_id = g_timeout_add_seconds (20,
- (GSourceFunc)xfce_reset_screen_saver,
- saver);
- }
- break;
+ g_variant_get (response, "(u)",
+ &saver->priv->cookie);
+ g_variant_unref (response);
}
- default:
+ }
+ else
+ {
+ GVariant *response = NULL;
+ response = g_dbus_proxy_call_sync (saver->priv->proxy,
+ "UnInhibit",
+ g_variant_new ("(u)",
+ saver->priv->cookie),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL, NULL);
+
+ saver->priv->cookie = 0;
+ if (response != NULL)
{
- g_warning("Not able to inhibit or uninhibit screensaver");
- break;
+ g_variant_unref (response);
}
+ }
+ break;
+ }
+ case SCREENSAVER_TYPE_OTHER:
+ case SCREENSAVER_TYPE_CINNAMON:
+ {
+ /* remove any existing keepalive */
+ if (saver->priv->screensaver_id != 0)
+ {
+ g_source_remove (saver->priv->screensaver_id);
+ saver->priv->screensaver_id = 0;
+ }
+
+ if (inhibit)
+ {
+ /* Reset the screensaver timers every so often
+ * so they don't activate */
+ saver->priv->screensaver_id = g_timeout_add_seconds (20,
+ (GSourceFunc)xfce_reset_screen_saver,
+ saver);
+ }
+ break;
}
+ default:
+ {
+ g_warning ("Not able to inhibit or uninhibit screensaver");
+ break;
+ }
+ }
}
/**
@@ -498,92 +498,93 @@ xfce_screensaver_inhibit (XfceScreenSaver *saver,
gboolean
xfce_screensaver_lock (XfceScreenSaver *saver)
{
- switch (saver->priv->screensaver_type) {
- case SCREENSAVER_TYPE_FREEDESKTOP:
- case SCREENSAVER_TYPE_MATE:
- case SCREENSAVER_TYPE_GNOME:
- case SCREENSAVER_TYPE_XFCE:
- {
- GVariant *response = NULL;
- response = g_dbus_proxy_call_sync (saver->priv->proxy,
- "Lock",
- g_variant_new ("()"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (response != NULL)
- {
- g_variant_unref (response);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- break;
- }
- case SCREENSAVER_TYPE_CINNAMON:
- {
- GVariant *response = NULL;
- response = g_dbus_proxy_call_sync (saver->priv->proxy,
- "Lock",
- g_variant_new ("(s)", PACKAGE_NAME),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
- if (response != NULL)
- {
- g_variant_unref (response);
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- break;
- }
- case SCREENSAVER_TYPE_OTHER:
- {
- gboolean ret = FALSE;
-
- if (saver->priv->lock_command != NULL)
- {
- DBG ("running lock command: %s", saver->priv->lock_command);
- ret = g_spawn_command_line_async (saver->priv->lock_command, NULL);
- }
-
- if (!ret)
- {
- g_warning ("Screensaver lock command not set when attempting to lock the screen.\n"
- "Please set the xfconf property %s%s in xfce4-session to the desired lock command",
- XFSM_PROPERTIES_PREFIX, LOCK_COMMAND);
-
- ret = g_spawn_command_line_async ("xflock4", NULL);
- }
-
- if (!ret)
- {
- ret = g_spawn_command_line_async ("xdg-screensaver lock", NULL);
- }
-
- if (!ret)
- {
- ret = g_spawn_command_line_async ("xscreensaver-command -lock", NULL);
- }
-
- return ret;
- /* obviously we don't need this break statement but I'm sure some
- * compiler or static analysis tool will complain */
- break;
- }
- default:
- {
- g_warning ("Unknown screensaver type set when calling xfce_screensaver_lock");
- break;
- }
+ switch (saver->priv->screensaver_type)
+ {
+ case SCREENSAVER_TYPE_FREEDESKTOP:
+ case SCREENSAVER_TYPE_MATE:
+ case SCREENSAVER_TYPE_GNOME:
+ case SCREENSAVER_TYPE_XFCE:
+ {
+ GVariant *response = NULL;
+ response = g_dbus_proxy_call_sync (saver->priv->proxy,
+ "Lock",
+ g_variant_new ("()"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+ if (response != NULL)
+ {
+ g_variant_unref (response);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ break;
+ }
+ case SCREENSAVER_TYPE_CINNAMON:
+ {
+ GVariant *response = NULL;
+ response = g_dbus_proxy_call_sync (saver->priv->proxy,
+ "Lock",
+ g_variant_new ("(s)", PACKAGE_NAME),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL);
+ if (response != NULL)
+ {
+ g_variant_unref (response);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ break;
+ }
+ case SCREENSAVER_TYPE_OTHER:
+ {
+ gboolean ret = FALSE;
+
+ if (saver->priv->lock_command != NULL)
+ {
+ DBG ("running lock command: %s", saver->priv->lock_command);
+ ret = g_spawn_command_line_async (saver->priv->lock_command, NULL);
+ }
+
+ if (!ret)
+ {
+ g_warning ("Screensaver lock command not set when attempting to lock the screen.\n"
+ "Please set the xfconf property %s%s in xfce4-session to the desired lock command",
+ XFSM_PROPERTIES_PREFIX, LOCK_COMMAND);
+
+ ret = g_spawn_command_line_async ("xflock4", NULL);
+ }
+
+ if (!ret)
+ {
+ ret = g_spawn_command_line_async ("xdg-screensaver lock", NULL);
+ }
+
+ if (!ret)
+ {
+ ret = g_spawn_command_line_async ("xscreensaver-command -lock", NULL);
+ }
+
+ return ret;
+ /* obviously we don't need this break statement but I'm sure some
+ * compiler or static analysis tool will complain */
+ break;
+ }
+ default:
+ {
+ g_warning ("Unknown screensaver type set when calling xfce_screensaver_lock");
+ break;
}
+ }
- return FALSE;
+ return FALSE;
}
diff --git a/src/xfce-screensaver.h b/src/xfce-screensaver.h
index 260e1c2..5866c29 100644
--- a/src/xfce-screensaver.h
+++ b/src/xfce-screensaver.h
@@ -33,22 +33,19 @@ typedef struct XfceScreenSaverPrivate XfceScreenSaverPrivate;
typedef struct
{
- GObject parent;
- XfceScreenSaverPrivate *priv;
+ GObject parent;
+ XfceScreenSaverPrivate *priv;
} XfceScreenSaver;
typedef struct
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
} XfceScreenSaverClass;
GType xfce_screensaver_get_type (void) G_GNUC_CONST;
-
XfceScreenSaver *xfce_screensaver_new (void);
-
void xfce_screensaver_inhibit (XfceScreenSaver *saver,
gboolean suspend);
-
gboolean xfce_screensaver_lock (XfceScreenSaver *saver);
diff --git a/src/xfpm-backlight-helper.c b/src/xfpm-backlight-helper.c
index 9b5aecc..c39e8b5 100644
--- a/src/xfpm-backlight-helper.c
+++ b/src/xfpm-backlight-helper.c
@@ -43,15 +43,15 @@
#include <sys/sysctl.h>
#endif
-#define EXIT_CODE_SUCCESS 0
-#define EXIT_CODE_FAILED 1
-#define EXIT_CODE_ARGUMENTS_INVALID 3
-#define EXIT_CODE_INVALID_USER 4
-#define EXIT_CODE_NO_BRIGHTNESS_SWITCH 5
+#define EXIT_CODE_SUCCESS 0
+#define EXIT_CODE_FAILED 1
+#define EXIT_CODE_ARGUMENTS_INVALID 3
+#define EXIT_CODE_INVALID_USER 4
+#define EXIT_CODE_NO_BRIGHTNESS_SWITCH 5
#if !defined(BACKEND_TYPE_FREEBSD)
-#define BACKLIGHT_SYSFS_LOCATION "/sys/class/backlight"
-#define BRIGHTNESS_SWITCH_LOCATION "/sys/module/video/parameters/brightness_switch_enabled"
+#define BACKLIGHT_SYSFS_LOCATION "/sys/class/backlight"
+#define BRIGHTNESS_SWITCH_LOCATION "/sys/module/video/parameters/brightness_switch_enabled"
#endif
@@ -59,140 +59,140 @@
gboolean
acpi_video_is_enabled (gchar *device)
{
- return (backlight_helper_get_switch (device) == 1) ? TRUE : FALSE;
+ return (backlight_helper_get_switch (device) == 1) ? TRUE : FALSE;
}
gint
backlight_helper_get_switch (gchar *device)
{
- size_t size;
- gint buf, res = -1;
- gchar *name;
+ size_t size;
+ gint buf, res = -1;
+ gchar *name;
- name = g_strdup_printf ("hw.acpi.video.%s.active", device);
- size = sizeof (buf);
+ name = g_strdup_printf ("hw.acpi.video.%s.active", device);
+ size = sizeof (buf);
- if (sysctlbyname (name, &buf, &size, NULL, 0) == 0)
- res = buf;
+ if (sysctlbyname (name, &buf, &size, NULL, 0) == 0)
+ res = buf;
- g_free (name);
- return res;
+ g_free (name);
+ return res;
}
gint
backlight_helper_get_brightness (gchar *device)
{
- size_t size;
- gint buf, res = -1;
- gchar *name;
+ size_t size;
+ gint buf, res = -1;
+ gchar *name;
- name = g_strdup_printf ("hw.acpi.video.%s.brightness", device);
- size = sizeof (buf);
+ name = g_strdup_printf ("hw.acpi.video.%s.brightness", device);
+ size = sizeof (buf);
- if (sysctlbyname (name, &buf, &size, NULL, 0) == 0)
- res = buf;
+ if (sysctlbyname (name, &buf, &size, NULL, 0) == 0)
+ res = buf;
- g_free (name);
- return res;
+ g_free (name);
+ return res;
}
gint
int_cmp (gconstpointer a, gconstpointer b)
{
- return (gint) a < (gint) b ? -1 : ((gint) a == (gint) b ? 0 : 1);
+ return (gint) a < (gint) b ? -1 : ((gint) a == (gint) b ? 0 : 1);
}
GList *
backlight_helper_get_levels (gchar *device)
{
- size_t size;
- gint *levels;
- gint nlevels, i;
- GList *list = NULL, *item;
- gchar *name;
+ size_t size;
+ gint *levels;
+ gint nlevels, i;
+ GList *list = NULL, *item;
+ gchar *name;
- name = g_strdup_printf ("hw.acpi.video.%s.levels", device);
+ name = g_strdup_printf ("hw.acpi.video.%s.levels", device);
- /* allocate memory */
- sysctlbyname (name, NULL, &size, NULL, 0);
- levels = (int *) malloc (size);
+ /* allocate memory */
+ sysctlbyname (name, NULL, &size, NULL, 0);
+ levels = (int *) malloc (size);
- if (sysctlbyname (name, levels, &size, NULL, 0) == 0) {
- nlevels = size / sizeof (gint);
+ if (sysctlbyname (name, levels, &size, NULL, 0) == 0) {
+ nlevels = size / sizeof (gint);
- for (i = 0; i < nlevels; i++) {
- /* no duplicate item */
- item = g_list_find (list, GINT_TO_POINTER (levels[i]));
- if (item == NULL)
- list = g_list_append (list,
- GINT_TO_POINTER (levels[i]));
- }
- }
+ for (i = 0; i < nlevels; i++) {
+ /* no duplicate item */
+ item = g_list_find (list, GINT_TO_POINTER (levels[i]));
+ if (item == NULL)
+ list = g_list_append (list,
+ GINT_TO_POINTER (levels[i]));
+ }
+ }
- g_free (levels);
- g_free (name);
+ g_free (levels);
+ g_free (name);
- if (list != NULL)
- list = g_list_sort (list, int_cmp);
+ if (list != NULL)
+ list = g_list_sort (list, int_cmp);
- return list;
+ return list;
}
gboolean
backlight_helper_set_switch (gchar *device, gint value)
{
- size_t size;
- gint buf, old_buf;
- gchar *name;
- gint res = -1;
- gboolean result = FALSE;
-
- name = g_strdup_printf ("hw.acpi.video.%s.active", device);
-
- res = backlight_helper_get_switch (device);
- if (res != -1) {
- old_buf = res;
- size = sizeof (buf);
-
- /* we change value and check if it's really different */
- if (sysctlbyname (name, &buf, &size, &value, sizeof (value)) == 0) {
- res = backlight_helper_get_switch (device);
- if (res != -1 && res != old_buf)
- result = TRUE;
- }
- }
- g_free (name);
-
- return result;
+ size_t size;
+ gint buf, old_buf;
+ gchar *name;
+ gint res = -1;
+ gboolean result = FALSE;
+
+ name = g_strdup_printf ("hw.acpi.video.%s.active", device);
+
+ res = backlight_helper_get_switch (device);
+ if (res != -1) {
+ old_buf = res;
+ size = sizeof (buf);
+
+ /* we change value and check if it's really different */
+ if (sysctlbyname (name, &buf, &size, &value, sizeof (value)) == 0) {
+ res = backlight_helper_get_switch (device);
+ if (res != -1 && res != old_buf)
+ result = TRUE;
+ }
+ }
+ g_free (name);
+
+ return result;
}
gboolean
backlight_helper_set_brightness (gchar *device, gint value)
{
- size_t size;
- gint buf, old_buf;
- gchar *name;
- gint res = -1;
- gboolean result = FALSE;
-
- name = g_strdup_printf ("hw.acpi.video.%s.brightness", device);
-
- res = backlight_helper_get_brightness (device);
- if (res != -1) {
- old_buf = res;
- size = sizeof (buf);
-
- /* we change value, and check if it's really different */
- if (sysctlbyname (name, &buf, &size, &value, sizeof (value)) == 0) {
- res = backlight_helper_get_brightness (device);
- if (res != -1 && res != old_buf)
- result = TRUE;
- }
- }
-
- g_free (name);
-
- return result;
+ size_t size;
+ gint buf, old_buf;
+ gchar *name;
+ gint res = -1;
+ gboolean result = FALSE;
+
+ name = g_strdup_printf ("hw.acpi.video.%s.brightness", device);
+
+ res = backlight_helper_get_brightness (device);
+ if (res != -1) {
+ old_buf = res;
+ size = sizeof (buf);
+
+ /* we change value, and check if it's really different */
+ if (sysctlbyname (name, &buf, &size, &value, sizeof (value)) == 0) {
+ res = backlight_helper_get_brightness (device);
+ if (res != -1 && res != old_buf)
+ result = TRUE;
+ }
+ }
+
+ g_free (name);
+
+ return result;
}
/*
@@ -201,22 +201,22 @@ backlight_helper_set_brightness (gchar *device, gint value)
static gchar *
backlight_helper_get_device (void)
{
- /* devices in priority order */
- gchar *types[] = { "lcd", "crt", "out", "ext", "tv", NULL };
- gchar *device = NULL;
- gint i;
+ /* devices in priority order */
+ gchar *types[] = { "lcd", "crt", "out", "ext", "tv", NULL };
+ gchar *device = NULL;
+ gint i;
- device = (gchar *) g_malloc (sizeof (gchar));
+ device = (gchar *) g_malloc (sizeof (gchar));
- for (i = 0; types[i] != NULL; i++) {
- g_snprintf (device, (gulong) strlen (types[i]), "%s0", types[i]);
+ for (i = 0; types[i] != NULL; i++) {
+ g_snprintf (device, (gulong) strlen (types[i]), "%s0", types[i]);
- /* stop, when first device is found */
- if (acpi_video_is_enabled (device))
- break;
- }
+ /* stop, when first device is found */
+ if (acpi_video_is_enabled (device))
+ break;
+ }
- return device;
+ return device;
}
/*
@@ -225,191 +225,191 @@ backlight_helper_get_device (void)
gint
main (gint argc, gchar *argv[])
{
- GOptionContext *context;
- gint uid;
- gint euid;
- guint retval = 0;
- const gchar *pkexec_uid_str;
- gint ret = -1;
- gint set_brightness = -1;
- gboolean get_brightness = FALSE;
- gboolean get_max_brightness = FALSE;
- gint set_brightness_switch = -1;
- gboolean get_brightness_switch = FALSE;
- gchar *device = NULL;
- GList *list = NULL;
-
- const GOptionEntry options[] = {
- { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness,
- /* command line argument */
- "Set the current brightness", NULL },
- { "get-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_brightness,
- /* command line argument */
- "Get the current brightness", NULL },
- { "get-max-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_max_brightness,
- /* command line argument */
- "Get the number of brightness levels supported", NULL },
- { "set-brightness-switch", '\0', 0, G_OPTION_ARG_INT, &set_brightness_switch,
+ GOptionContext *context;
+ gint uid;
+ gint euid;
+ guint retval = 0;
+ const gchar *pkexec_uid_str;
+ gint ret = -1;
+ gint set_brightness = -1;
+ gboolean get_brightness = FALSE;
+ gboolean get_max_brightness = FALSE;
+ gint set_brightness_switch = -1;
+ gboolean get_brightness_switch = FALSE;
+ gchar *device = NULL;
+ GList *list = NULL;
+
+ const GOptionEntry options[] = {
+ { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness,
+ /* command line argument */
+ "Set the current brightness", NULL },
+ { "get-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_brightness,
+ /* command line argument */
+ "Get the current brightness", NULL },
+ { "get-max-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_max_brightness,
+ /* command line argument */
+ "Get the number of brightness levels supported", NULL },
+ { "set-brightness-switch", '\0', 0, G_OPTION_ARG_INT, &set_brightness_switch,
/* command line argument */
- "Enable or disable ACPI video brightness switch handling", NULL },
- { "get-brightness-switch", '\0', 0, G_OPTION_ARG_NONE, &get_brightness_switch,
+ "Enable or disable ACPI video brightness switch handling", NULL },
+ { "get-brightness-switch", '\0', 0, G_OPTION_ARG_NONE, &get_brightness_switch,
/* command line argument */
- "Get the current setting of the ACPI video brightness switch handling", NULL },
- { NULL }
- };
-
- context = g_option_context_new (NULL);
- g_option_context_set_summary (context, "XFCE Power Manager Backlight Helper");
- g_option_context_add_main_entries (context, options, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
-
- /* no input */
- if (set_brightness == -1 && !get_brightness && !get_max_brightness &&
- set_brightness_switch == -1 && !get_brightness_switch) {
- g_print ("No valid option was specifiedi\n");
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* find backlight device */
- device = backlight_helper_get_device ();
-
- if (device != NULL) {
- /* get the current setting of the ACPI video brightness switch handling */
- if (get_brightness_switch) {
- ret = backlight_helper_get_switch (device);
- /* just print result to stdout */
- g_print ("%d", ret);
- if (ret == -1)
- retval = EXIT_CODE_FAILED;
- else
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
-
- /* get current brightness level */
- if (get_brightness) {
- ret = backlight_helper_get_brightness (device);
- /* just print result to stdout */
- g_print ("%d", ret);
- if (ret == -1)
- retval = EXIT_CODE_FAILED;
- else
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
-
- /* get maximum brightness level */
- if (get_max_brightness) {
- list = backlight_helper_get_levels (device);
- if (list != NULL) {
- /* just print result to stdout */
- g_print ("%d", (gint) g_list_last (list)->data);
- g_list_free (list);
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
- else {
- g_print ("Could not get the maximum value of the backlight\n");
- retval = EXIT_CODE_FAILED;
- goto out;
- }
- }
-
- /* get calling process */
- uid = getuid ();
- euid = geteuid ();
- if (uid != 0 || euid != 0) {
- g_print ("This program can only be used by the root user\n");
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* check we're not being spoofed */
- pkexec_uid_str = g_getenv ("PKEXEC_UID");
- if (pkexec_uid_str == NULL) {
- g_print ("This program must only be run through pkexec\n");
- retval = EXIT_CODE_INVALID_USER;
- goto out;
- }
-
- /* set the brightness level */
- if (set_brightness != -1) {
- if (backlight_helper_set_brightness (device, set_brightness)) {
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
- else {
- g_print ("Could not set the value of the backlight\n");
- retval = EXIT_CODE_FAILED;
- goto out;
- }
- }
-
- /* enable or disable ACPI video brightness switch handling */
- if (set_brightness_switch != -1) {
- if (backlight_helper_set_switch (device, set_brightness_switch)) {
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
- else {
- g_print ("Could not set the value of the brightness switch\n");
- retval = EXIT_CODE_FAILED;
- goto out;
- }
- }
- }
- else {
- retval = ret;
- goto out;
- }
+ "Get the current setting of the ACPI video brightness switch handling", NULL },
+ { NULL }
+ };
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "XFCE Power Manager Backlight Helper");
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ /* no input */
+ if (set_brightness == -1 && !get_brightness && !get_max_brightness &&
+ set_brightness_switch == -1 && !get_brightness_switch) {
+ g_print ("No valid option was specifiedi\n");
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* find backlight device */
+ device = backlight_helper_get_device ();
+
+ if (device != NULL) {
+ /* get the current setting of the ACPI video brightness switch handling */
+ if (get_brightness_switch) {
+ ret = backlight_helper_get_switch (device);
+ /* just print result to stdout */
+ g_print ("%d", ret);
+ if (ret == -1)
+ retval = EXIT_CODE_FAILED;
+ else
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+
+ /* get current brightness level */
+ if (get_brightness) {
+ ret = backlight_helper_get_brightness (device);
+ /* just print result to stdout */
+ g_print ("%d", ret);
+ if (ret == -1)
+ retval = EXIT_CODE_FAILED;
+ else
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+
+ /* get maximum brightness level */
+ if (get_max_brightness) {
+ list = backlight_helper_get_levels (device);
+ if (list != NULL) {
+ /* just print result to stdout */
+ g_print ("%d", (gint) g_list_last (list)->data);
+ g_list_free (list);
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+ else {
+ g_print ("Could not get the maximum value of the backlight\n");
+ retval = EXIT_CODE_FAILED;
+ goto out;
+ }
+ }
+
+ /* get calling process */
+ uid = getuid ();
+ euid = geteuid ();
+ if (uid != 0 || euid != 0) {
+ g_print ("This program can only be used by the root user\n");
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* check we're not being spoofed */
+ pkexec_uid_str = g_getenv ("PKEXEC_UID");
+ if (pkexec_uid_str == NULL) {
+ g_print ("This program must only be run through pkexec\n");
+ retval = EXIT_CODE_INVALID_USER;
+ goto out;
+ }
+
+ /* set the brightness level */
+ if (set_brightness != -1) {
+ if (backlight_helper_set_brightness (device, set_brightness)) {
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+ else {
+ g_print ("Could not set the value of the backlight\n");
+ retval = EXIT_CODE_FAILED;
+ goto out;
+ }
+ }
+
+ /* enable or disable ACPI video brightness switch handling */
+ if (set_brightness_switch != -1) {
+ if (backlight_helper_set_switch (device, set_brightness_switch)) {
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+ else {
+ g_print ("Could not set the value of the brightness switch\n");
+ retval = EXIT_CODE_FAILED;
+ goto out;
+ }
+ }
+ }
+ else {
+ retval = ret;
+ goto out;
+ }
out:
- return retval;
+ return retval;
}
#else
typedef enum {
- BACKLIGHT_TYPE_UNKNOWN,
- BACKLIGHT_TYPE_FIRMWARE,
- BACKLIGHT_TYPE_PLATFORM,
- BACKLIGHT_TYPE_RAW
+ BACKLIGHT_TYPE_UNKNOWN,
+ BACKLIGHT_TYPE_FIRMWARE,
+ BACKLIGHT_TYPE_PLATFORM,
+ BACKLIGHT_TYPE_RAW
} BacklightType;
static BacklightType
backlight_helper_get_type (const gchar *sysfs_path)
{
- gboolean ret;
- gchar *filename = NULL;
- GError *error = NULL;
- gchar *type_tmp = NULL;
- BacklightType type = BACKLIGHT_TYPE_UNKNOWN;
-
- filename = g_build_filename (sysfs_path,
- "type", NULL);
- ret = g_file_get_contents (filename,
- &type_tmp,
- NULL, &error);
- if (!ret) {
- g_warning ("failed to get type: %s", error->message);
- g_error_free (error);
- goto out;
- }
- if (g_str_has_prefix (type_tmp, "platform")) {
- type = BACKLIGHT_TYPE_PLATFORM;
- goto out;
- }
- if (g_str_has_prefix (type_tmp, "firmware")) {
- type = BACKLIGHT_TYPE_FIRMWARE;
- goto out;
- }
- if (g_str_has_prefix (type_tmp, "raw")) {
- type = BACKLIGHT_TYPE_RAW;
- goto out;
- }
+ gboolean ret;
+ gchar *filename = NULL;
+ GError *error = NULL;
+ gchar *type_tmp = NULL;
+ BacklightType type = BACKLIGHT_TYPE_UNKNOWN;
+
+ filename = g_build_filename (sysfs_path,
+ "type", NULL);
+ ret = g_file_get_contents (filename,
+ &type_tmp,
+ NULL, &error);
+ if (!ret) {
+ g_warning ("failed to get type: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ if (g_str_has_prefix (type_tmp, "platform")) {
+ type = BACKLIGHT_TYPE_PLATFORM;
+ goto out;
+ }
+ if (g_str_has_prefix (type_tmp, "firmware")) {
+ type = BACKLIGHT_TYPE_FIRMWARE;
+ goto out;
+ }
+ if (g_str_has_prefix (type_tmp, "raw")) {
+ type = BACKLIGHT_TYPE_RAW;
+ goto out;
+ }
out:
- g_free (filename);
- g_free (type_tmp);
- return type;
+ g_free (filename);
+ g_free (type_tmp);
+ return type;
}
/*
@@ -418,70 +418,70 @@ out:
static gchar *
backlight_helper_get_best_backlight (void)
{
- const gchar *device_name;
- const gchar *filename_tmp;
- gchar *best_device = NULL;
- gchar *filename = NULL;
- GDir *dir = NULL;
- GError *error = NULL;
- GPtrArray *sysfs_paths = NULL;
- BacklightType *backlight_types = NULL;
- guint i;
-
- /* search the backlight devices and prefer the types:
- * firmware -> platform -> raw */
- dir = g_dir_open (BACKLIGHT_SYSFS_LOCATION, 0, &error);
- if (dir == NULL) {
- g_warning ("failed to find any devices: %s", error->message);
- g_error_free (error);
- goto out;
- }
- sysfs_paths = g_ptr_array_new_with_free_func (g_free);
- device_name = g_dir_read_name (dir);
- while (device_name != NULL) {
- filename = g_build_filename (BACKLIGHT_SYSFS_LOCATION,
- device_name, NULL);
- g_ptr_array_add (sysfs_paths, filename);
- device_name = g_dir_read_name (dir);
- }
-
- /* no backlights */
- if (sysfs_paths->len == 0)
- goto out;
-
- /* find out the type of each backlight */
- backlight_types = g_new0 (BacklightType, sysfs_paths->len);
- for (i = 0; i < sysfs_paths->len; i++) {
- filename_tmp = g_ptr_array_index (sysfs_paths, i);
- backlight_types[i] = backlight_helper_get_type (filename_tmp);
- }
-
- /* any devices of type firmware -> platform -> raw? */
- for (i = 0; i < sysfs_paths->len; i++) {
- if (backlight_types[i] == BACKLIGHT_TYPE_FIRMWARE) {
- best_device = g_strdup (g_ptr_array_index (sysfs_paths, i));
- goto out;
- }
- }
- for (i = 0; i < sysfs_paths->len; i++) {
- if (backlight_types[i] == BACKLIGHT_TYPE_PLATFORM) {
- best_device = g_strdup (g_ptr_array_index (sysfs_paths, i));
- goto out;
- }
- }
- for (i = 0; i < sysfs_paths->len; i++) {
- if (backlight_types[i] == BACKLIGHT_TYPE_RAW) {
- best_device = g_strdup (g_ptr_array_index (sysfs_paths, i));
- goto out;
- }
- }
+ const gchar *device_name;
+ const gchar *filename_tmp;
+ gchar *best_device = NULL;
+ gchar *filename = NULL;
+ GDir *dir = NULL;
+ GError *error = NULL;
+ GPtrArray *sysfs_paths = NULL;
+ BacklightType *backlight_types = NULL;
+ guint i;
+
+ /* search the backlight devices and prefer the types:
+ * firmware -> platform -> raw */
+ dir = g_dir_open (BACKLIGHT_SYSFS_LOCATION, 0, &error);
+ if (dir == NULL) {
+ g_warning ("failed to find any devices: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ sysfs_paths = g_ptr_array_new_with_free_func (g_free);
+ device_name = g_dir_read_name (dir);
+ while (device_name != NULL) {
+ filename = g_build_filename (BACKLIGHT_SYSFS_LOCATION,
+ device_name, NULL);
+ g_ptr_array_add (sysfs_paths, filename);
+ device_name = g_dir_read_name (dir);
+ }
+
+ /* no backlights */
+ if (sysfs_paths->len == 0)
+ goto out;
+
+ /* find out the type of each backlight */
+ backlight_types = g_new0 (BacklightType, sysfs_paths->len);
+ for (i = 0; i < sysfs_paths->len; i++) {
+ filename_tmp = g_ptr_array_index (sysfs_paths, i);
+ backlight_types[i] = backlight_helper_get_type (filename_tmp);
+ }
+
+ /* any devices of type firmware -> platform -> raw? */
+ for (i = 0; i < sysfs_paths->len; i++) {
+ if (backlight_types[i] == BACKLIGHT_TYPE_FIRMWARE) {
+ best_device = g_strdup (g_ptr_array_index (sysfs_paths, i));
+ goto out;
+ }
+ }
+ for (i = 0; i < sysfs_paths->len; i++) {
+ if (backlight_types[i] == BACKLIGHT_TYPE_PLATFORM) {
+ best_device = g_strdup (g_ptr_array_index (sysfs_paths, i));
+ goto out;
+ }
+ }
+ for (i = 0; i < sysfs_paths->len; i++) {
+ if (backlight_types[i] == BACKLIGHT_TYPE_RAW) {
+ best_device = g_strdup (g_ptr_array_index (sysfs_paths, i));
+ goto out;
+ }
+ }
out:
- g_free (backlight_types);
- if (sysfs_paths != NULL)
- g_ptr_array_unref (sysfs_paths);
- if (dir != NULL)
- g_dir_close (dir);
- return best_device;
+ g_free (backlight_types);
+ if (sysfs_paths != NULL)
+ g_ptr_array_unref (sysfs_paths);
+ if (dir != NULL)
+ g_dir_close (dir);
+ return best_device;
}
/*
@@ -490,35 +490,35 @@ out:
static gboolean
backlight_helper_write (const gchar *filename, gint value, GError **error)
{
- gchar *text = NULL;
- gint retval;
- gint length;
- gint fd = -1;
- gboolean ret = TRUE;
-
- fd = open (filename, O_WRONLY);
- if (fd < 0) {
- ret = FALSE;
- g_set_error (error, 1, 0, "failed to open filename: %s", filename);
- goto out;
- }
-
- /* convert to text */
- text = g_strdup_printf ("%i", value);
- length = strlen (text);
-
- /* write to device file */
- retval = write (fd, text, length);
- if (retval != length) {
- ret = FALSE;
- g_set_error (error, 1, 0, "writing '%s' to %s failed", text, filename);
- goto out;
- }
+ gchar *text = NULL;
+ gint retval;
+ gint length;
+ gint fd = -1;
+ gboolean ret = TRUE;
+
+ fd = open (filename, O_WRONLY);
+ if (fd < 0) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "failed to open filename: %s", filename);
+ goto out;
+ }
+
+ /* convert to text */
+ text = g_strdup_printf ("%i", value);
+ length = strlen (text);
+
+ /* write to device file */
+ retval = write (fd, text, length);
+ if (retval != length) {
+ ret = FALSE;
+ g_set_error (error, 1, 0, "writing '%s' to %s failed", text, filename);
+ goto out;
+ }
out:
- if (fd >= 0)
- close (fd);
- g_free (text);
- return ret;
+ if (fd >= 0)
+ close (fd);
+ g_free (text);
+ return ret;
}
/*
@@ -527,173 +527,173 @@ out:
gint
main (gint argc, gchar *argv[])
{
- GOptionContext *context;
- gint uid;
- gint euid;
- guint retval = 0;
- const gchar *pkexec_uid_str;
- GError *error = NULL;
- gboolean ret = FALSE;
- gint set_brightness = -1;
- gboolean get_brightness = FALSE;
- gboolean get_max_brightness = FALSE;
- gint set_brightness_switch = -1;
- gboolean get_brightness_switch = FALSE;
- gchar *filename = NULL;
- gchar *filename_file = NULL;
- gchar *contents = NULL;
-
- const GOptionEntry options[] = {
- { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness,
- /* command line argument */
- "Set the current brightness", NULL },
- { "get-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_brightness,
- /* command line argument */
- "Get the current brightness", NULL },
- { "get-max-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_max_brightness,
- /* command line argument */
- "Get the number of brightness levels supported", NULL },
- { "set-brightness-switch", '\0', 0, G_OPTION_ARG_INT, &set_brightness_switch,
+ GOptionContext *context;
+ gint uid;
+ gint euid;
+ guint retval = 0;
+ const gchar *pkexec_uid_str;
+ GError *error = NULL;
+ gboolean ret = FALSE;
+ gint set_brightness = -1;
+ gboolean get_brightness = FALSE;
+ gboolean get_max_brightness = FALSE;
+ gint set_brightness_switch = -1;
+ gboolean get_brightness_switch = FALSE;
+ gchar *filename = NULL;
+ gchar *filename_file = NULL;
+ gchar *contents = NULL;
+
+ const GOptionEntry options[] = {
+ { "set-brightness", '\0', 0, G_OPTION_ARG_INT, &set_brightness,
+ /* command line argument */
+ "Set the current brightness", NULL },
+ { "get-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_brightness,
+ /* command line argument */
+ "Get the current brightness", NULL },
+ { "get-max-brightness", '\0', 0, G_OPTION_ARG_NONE, &get_max_brightness,
+ /* command line argument */
+ "Get the number of brightness levels supported", NULL },
+ { "set-brightness-switch", '\0', 0, G_OPTION_ARG_INT, &set_brightness_switch,
/* command line argument */
- "Enable or disable ACPI video brightness switch handling", NULL },
- { "get-brightness-switch", '\0', 0, G_OPTION_ARG_NONE, &get_brightness_switch,
+ "Enable or disable ACPI video brightness switch handling", NULL },
+ { "get-brightness-switch", '\0', 0, G_OPTION_ARG_NONE, &get_brightness_switch,
/* command line argument */
- "Get the current setting of the ACPI video brightness switch handling", NULL },
- { NULL }
- };
-
- context = g_option_context_new (NULL);
- g_option_context_set_summary (context, "XFCE Power Manager Backlight Helper");
- g_option_context_add_main_entries (context, options, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
-
- /* no input */
- if (set_brightness == -1 && !get_brightness && !get_max_brightness &&
- set_brightness_switch == -1 && !get_brightness_switch) {
- puts ("No valid option was specified");
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* for brightness switch modifications, check for existence of the sysfs entry */
- if (set_brightness_switch != -1 || get_brightness_switch) {
- ret = g_file_test (BRIGHTNESS_SWITCH_LOCATION, G_FILE_TEST_EXISTS);
- if (!ret) {
- g_print ("Video brightness switch setting not available.\n");
- retval = EXIT_CODE_NO_BRIGHTNESS_SWITCH;
- goto out;
- }
- } else { /* find backlight device */
- filename = backlight_helper_get_best_backlight ();
- if (filename == NULL) {
- puts ("No backlights were found on your system");
- retval = EXIT_CODE_INVALID_USER;
- goto out;
- }
- }
-
- /* get the current setting of the ACPI video brightness switch handling */
- if (get_brightness_switch) {
- ret = g_file_get_contents (BRIGHTNESS_SWITCH_LOCATION, &contents, NULL, &error);
- if (!ret) {
- g_print ("Could not get the value of the brightness switch: %s\n",
- error->message);
- g_error_free (error);
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* just print the contents to stdout */
- g_print ("%s", contents);
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
-
- /* get current brightness level */
- if (get_brightness) {
- filename_file = g_build_filename (filename, "brightness", NULL);
- ret = g_file_get_contents (filename_file, &contents, NULL, &error);
- if (!ret) {
- g_print ("Could not get the value of the backlight: %s\n", error->message);
- g_error_free (error);
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* just print the contents to stdout */
- g_print ("%s", contents);
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
-
- /* get maximum brightness level */
- if (get_max_brightness) {
- filename_file = g_build_filename (filename, "max_brightness", NULL);
- ret = g_file_get_contents (filename_file, &contents, NULL, &error);
- if (!ret) {
- g_print ("Could not get the maximum value of the backlight: %s\n", error->message);
- g_error_free (error);
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* just print the contents to stdout */
- g_print ("%s", contents);
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
-
- /* get calling process */
- uid = getuid ();
- euid = geteuid ();
- if (uid != 0 || euid != 0) {
- puts ("This program can only be used by the root user");
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
-
- /* check we're not being spoofed */
- pkexec_uid_str = g_getenv ("PKEXEC_UID");
- if (pkexec_uid_str == NULL) {
- puts ("This program must only be run through pkexec");
- retval = EXIT_CODE_INVALID_USER;
- goto out;
- }
-
- /* set the brightness level */
- if (set_brightness != -1) {
- filename_file = g_build_filename (filename, "brightness", NULL);
- ret = backlight_helper_write (filename_file, set_brightness, &error);
- if (!ret) {
- g_print ("Could not set the value of the backlight: %s\n", error->message);
- g_error_free (error);
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
- retval = EXIT_CODE_SUCCESS;
- goto out;
- }
-
- /* enable or disable ACPI video brightness switch handling */
- if (set_brightness_switch != -1) {
- ret = backlight_helper_write (BRIGHTNESS_SWITCH_LOCATION,
- set_brightness_switch, &error);
- if (!ret) {
- g_print ("Could not set the value of the brightness switch: %s\n",
- error->message);
- g_error_free (error);
- retval = EXIT_CODE_ARGUMENTS_INVALID;
- goto out;
- }
- }
-
- /* success */
- retval = EXIT_CODE_SUCCESS;
+ "Get the current setting of the ACPI video brightness switch handling", NULL },
+ { NULL }
+ };
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "XFCE Power Manager Backlight Helper");
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ /* no input */
+ if (set_brightness == -1 && !get_brightness && !get_max_brightness &&
+ set_brightness_switch == -1 && !get_brightness_switch) {
+ puts ("No valid option was specified");
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* for brightness switch modifications, check for existence of the sysfs entry */
+ if (set_brightness_switch != -1 || get_brightness_switch) {
+ ret = g_file_test (BRIGHTNESS_SWITCH_LOCATION, G_FILE_TEST_EXISTS);
+ if (!ret) {
+ g_print ("Video brightness switch setting not available.\n");
+ retval = EXIT_CODE_NO_BRIGHTNESS_SWITCH;
+ goto out;
+ }
+ } else { /* find backlight device */
+ filename = backlight_helper_get_best_backlight ();
+ if (filename == NULL) {
+ puts ("No backlights were found on your system");
+ retval = EXIT_CODE_INVALID_USER;
+ goto out;
+ }
+ }
+
+ /* get the current setting of the ACPI video brightness switch handling */
+ if (get_brightness_switch) {
+ ret = g_file_get_contents (BRIGHTNESS_SWITCH_LOCATION, &contents, NULL, &error);
+ if (!ret) {
+ g_print ("Could not get the value of the brightness switch: %s\n",
+ error->message);
+ g_error_free (error);
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* just print the contents to stdout */
+ g_print ("%s", contents);
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+
+ /* get current brightness level */
+ if (get_brightness) {
+ filename_file = g_build_filename (filename, "brightness", NULL);
+ ret = g_file_get_contents (filename_file, &contents, NULL, &error);
+ if (!ret) {
+ g_print ("Could not get the value of the backlight: %s\n", error->message);
+ g_error_free (error);
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* just print the contents to stdout */
+ g_print ("%s", contents);
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+
+ /* get maximum brightness level */
+ if (get_max_brightness) {
+ filename_file = g_build_filename (filename, "max_brightness", NULL);
+ ret = g_file_get_contents (filename_file, &contents, NULL, &error);
+ if (!ret) {
+ g_print ("Could not get the maximum value of the backlight: %s\n", error->message);
+ g_error_free (error);
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* just print the contents to stdout */
+ g_print ("%s", contents);
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+
+ /* get calling process */
+ uid = getuid ();
+ euid = geteuid ();
+ if (uid != 0 || euid != 0) {
+ puts ("This program can only be used by the root user");
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+
+ /* check we're not being spoofed */
+ pkexec_uid_str = g_getenv ("PKEXEC_UID");
+ if (pkexec_uid_str == NULL) {
+ puts ("This program must only be run through pkexec");
+ retval = EXIT_CODE_INVALID_USER;
+ goto out;
+ }
+
+ /* set the brightness level */
+ if (set_brightness != -1) {
+ filename_file = g_build_filename (filename, "brightness", NULL);
+ ret = backlight_helper_write (filename_file, set_brightness, &error);
+ if (!ret) {
+ g_print ("Could not set the value of the backlight: %s\n", error->message);
+ g_error_free (error);
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+ retval = EXIT_CODE_SUCCESS;
+ goto out;
+ }
+
+ /* enable or disable ACPI video brightness switch handling */
+ if (set_brightness_switch != -1) {
+ ret = backlight_helper_write (BRIGHTNESS_SWITCH_LOCATION,
+ set_brightness_switch, &error);
+ if (!ret) {
+ g_print ("Could not set the value of the brightness switch: %s\n",
+ error->message);
+ g_error_free (error);
+ retval = EXIT_CODE_ARGUMENTS_INVALID;
+ goto out;
+ }
+ }
+
+ /* success */
+ retval = EXIT_CODE_SUCCESS;
out:
- g_free (filename);
- g_free (filename_file);
- g_free (contents);
- return retval;
+ g_free (filename);
+ g_free (filename_file);
+ g_free (contents);
+ return retval;
}
#endif
diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index c72386f..55a9dc2 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -64,35 +64,35 @@ static void xfpm_backlight_set_property (GObject *object,
struct XfpmBacklightPrivate
{
- XfpmBrightness *brightness;
- XfpmPower *power;
- EggIdletime *idle;
- XfpmXfconf *conf;
- XfpmButton *button;
- XfpmNotify *notify;
+ XfpmBrightness *brightness;
+ XfpmPower *power;
+ EggIdletime *idle;
+ XfpmXfconf *conf;
+ XfpmButton *button;
+ XfpmNotify *notify;
- NotifyNotification *n;
+ NotifyNotification *n;
- gboolean has_hw;
- gboolean on_battery;
+ gboolean has_hw;
+ gboolean on_battery;
- gint32 last_level;
- gint32 max_level;
+ gint32 last_level;
+ gint32 max_level;
- gint brightness_switch;
- gint brightness_switch_save;
- gboolean brightness_switch_initialized;
+ gint brightness_switch;
+ gint brightness_switch_save;
+ gboolean brightness_switch_initialized;
- gboolean dimmed;
- gboolean block;
+ gboolean dimmed;
+ gboolean block;
};
enum
{
- PROP_0,
- PROP_BRIGHTNESS_SWITCH,
- PROP_BRIGHTNESS_SWITCH_SAVE,
- N_PROPERTIES
+ PROP_0,
+ PROP_BRIGHTNESS_SWITCH,
+ PROP_BRIGHTNESS_SWITCH_SAVE,
+ N_PROPERTIES
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmBacklight, xfpm_backlight, G_TYPE_OBJECT)
@@ -101,339 +101,335 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmBacklight, xfpm_backlight, G_TYPE_OBJECT)
static void
xfpm_backlight_dim_brightness (XfpmBacklight *backlight)
{
- gboolean ret;
+ gboolean ret;
- if (xfpm_power_is_in_presentation_mode (backlight->priv->power) == FALSE )
+ if (xfpm_power_is_in_presentation_mode (backlight->priv->power) == FALSE )
+ {
+ gint32 dim_level;
+
+ g_object_get (G_OBJECT (backlight->priv->conf),
+ backlight->priv->on_battery ? BRIGHTNESS_LEVEL_ON_BATTERY : BRIGHTNESS_LEVEL_ON_AC, &dim_level,
+ NULL);
+
+ ret = xfpm_brightness_get_level (backlight->priv->brightness, &backlight->priv->last_level);
+
+ if ( !ret )
{
- gint32 dim_level;
-
- g_object_get (G_OBJECT (backlight->priv->conf),
- backlight->priv->on_battery ? BRIGHTNESS_LEVEL_ON_BATTERY : BRIGHTNESS_LEVEL_ON_AC, &dim_level,
- NULL);
-
- ret = xfpm_brightness_get_level (backlight->priv->brightness, &backlight->priv->last_level);
-
- if ( !ret )
- {
- g_warning ("Unable to get current brightness level");
- return;
- }
-
- dim_level = dim_level * backlight->priv->max_level / 100;
-
- /**
- * Only reduce if the current level is brighter than
- * the configured dim_level
- **/
- if (backlight->priv->last_level > dim_level)
- {
- XFPM_DEBUG ("Current brightness level before dimming : %d, new %d", backlight->priv->last_level, dim_level);
- backlight->priv->dimmed = xfpm_brightness_set_level (backlight->priv->brightness, dim_level);
- }
+ g_warning ("Unable to get current brightness level");
+ return;
}
+
+ dim_level = dim_level * backlight->priv->max_level / 100;
+
+ /**
+ * Only reduce if the current level is brighter than
+ * the configured dim_level
+ **/
+ if (backlight->priv->last_level > dim_level)
+ {
+ XFPM_DEBUG ("Current brightness level before dimming : %d, new %d", backlight->priv->last_level, dim_level);
+ backlight->priv->dimmed = xfpm_brightness_set_level (backlight->priv->brightness, dim_level);
+ }
+ }
}
static gboolean
xfpm_backlight_destroy_popup (gpointer data)
{
- XfpmBacklight *backlight;
+ XfpmBacklight *backlight;
- backlight = XFPM_BACKLIGHT (data);
+ backlight = XFPM_BACKLIGHT (data);
- if ( backlight->priv->n )
- {
- g_object_unref (backlight->priv->n);
- backlight->priv->n = NULL;
- }
+ if ( backlight->priv->n )
+ {
+ g_object_unref (backlight->priv->n);
+ backlight->priv->n = NULL;
+ }
- return FALSE;
+ return FALSE;
}
static void
xfpm_backlight_show_notification (XfpmBacklight *backlight, gfloat value)
{
- gchar *summary;
-
- /* create the notification on demand */
- if ( backlight->priv->n == NULL )
- {
- /* generate a human-readable summary for the notification */
- summary = g_strdup_printf (_("Brightness: %.0f percent"), value);
- backlight->priv->n = xfpm_notify_new_notification (backlight->priv->notify,
- _("Power Manager"),
- summary,
- XFPM_DISPLAY_BRIGHTNESS_ICON,
- 0,
- XFPM_NOTIFY_NORMAL);
- g_free (summary);
- }
-
- /* add the brightness value to the notification */
- notify_notification_set_hint (backlight->priv->n, "value", g_variant_new_int32 (value));
-
- /* show the notification */
- notify_notification_show (backlight->priv->n, NULL);
+ gchar *summary;
+
+ /* create the notification on demand */
+ if ( backlight->priv->n == NULL )
+ {
+ /* generate a human-readable summary for the notification */
+ summary = g_strdup_printf (_("Brightness: %.0f percent"), value);
+ backlight->priv->n = xfpm_notify_new_notification (backlight->priv->notify,
+ _("Power Manager"),
+ summary,
+ XFPM_DISPLAY_BRIGHTNESS_ICON,
+ 0,
+ XFPM_NOTIFY_NORMAL);
+ g_free (summary);
+ }
+
+ /* add the brightness value to the notification */
+ notify_notification_set_hint (backlight->priv->n, "value", g_variant_new_int32 (value));
+
+ /* show the notification */
+ notify_notification_show (backlight->priv->n, NULL);
}
static void
xfpm_backlight_show (XfpmBacklight *backlight, gint level)
{
- gfloat value;
+ gfloat value;
- XFPM_DEBUG ("Level %u", level);
+ XFPM_DEBUG ("Level %u", level);
- value = (gfloat) 100 * level / backlight->priv->max_level;
- xfpm_backlight_show_notification (backlight, value);
+ value = (gfloat) 100 * level / backlight->priv->max_level;
+ xfpm_backlight_show_notification (backlight, value);
}
static void
xfpm_backlight_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmBacklight *backlight)
{
- backlight->priv->block = FALSE;
+ backlight->priv->block = FALSE;
- if ( id == TIMEOUT_BRIGHTNESS_ON_AC && !backlight->priv->on_battery)
- xfpm_backlight_dim_brightness (backlight);
- else if ( id == TIMEOUT_BRIGHTNESS_ON_BATTERY && backlight->priv->on_battery)
- xfpm_backlight_dim_brightness (backlight);
+ if ( id == TIMEOUT_BRIGHTNESS_ON_AC && !backlight->priv->on_battery)
+ xfpm_backlight_dim_brightness (backlight);
+ else if ( id == TIMEOUT_BRIGHTNESS_ON_BATTERY && backlight->priv->on_battery)
+ xfpm_backlight_dim_brightness (backlight);
}
static void
xfpm_backlight_reset_cb (EggIdletime *idle, XfpmBacklight *backlight)
{
- if ( backlight->priv->dimmed)
+ if ( backlight->priv->dimmed)
+ {
+ if ( !backlight->priv->block)
{
- if ( !backlight->priv->block)
- {
- XFPM_DEBUG ("Alarm reset, setting level to %d", backlight->priv->last_level);
- xfpm_brightness_set_level (backlight->priv->brightness, backlight->priv->last_level);
- }
- backlight->priv->dimmed = FALSE;
+ XFPM_DEBUG ("Alarm reset, setting level to %d", backlight->priv->last_level);
+ xfpm_brightness_set_level (backlight->priv->brightness, backlight->priv->last_level);
}
+ backlight->priv->dimmed = FALSE;
+ }
}
static void
xfpm_backlight_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmBacklight *backlight)
{
- gint32 level;
- gboolean ret = TRUE;
-
- gboolean handle_brightness_keys, show_popup;
-
- g_object_get (G_OBJECT (backlight->priv->conf),
- HANDLE_BRIGHTNESS_KEYS, &handle_brightness_keys,
- SHOW_BRIGHTNESS_POPUP, &show_popup,
- NULL);
-
- if ( type != BUTTON_MON_BRIGHTNESS_UP && type != BUTTON_MON_BRIGHTNESS_DOWN )
- return; /* sanity check, can this ever happen? */
-
- backlight->priv->block = TRUE;
- if ( !handle_brightness_keys )
- ret = xfpm_brightness_get_level (backlight->priv->brightness, &level);
+ gint32 level;
+ gboolean ret = TRUE;
+
+ gboolean handle_brightness_keys, show_popup;
+
+ g_object_get (G_OBJECT (backlight->priv->conf),
+ HANDLE_BRIGHTNESS_KEYS, &handle_brightness_keys,
+ SHOW_BRIGHTNESS_POPUP, &show_popup,
+ NULL);
+
+ if ( type != BUTTON_MON_BRIGHTNESS_UP && type != BUTTON_MON_BRIGHTNESS_DOWN )
+ return; /* sanity check, can this ever happen? */
+
+ backlight->priv->block = TRUE;
+ if ( !handle_brightness_keys )
+ ret = xfpm_brightness_get_level (backlight->priv->brightness, &level);
+ else
+ {
+ if ( type == BUTTON_MON_BRIGHTNESS_UP )
+ ret = xfpm_brightness_up (backlight->priv->brightness, &level);
else
- {
- if ( type == BUTTON_MON_BRIGHTNESS_UP )
- ret = xfpm_brightness_up (backlight->priv->brightness, &level);
- else
- ret = xfpm_brightness_down (backlight->priv->brightness, &level);
- }
- if ( ret && show_popup)
- xfpm_backlight_show (backlight, level);
+ ret = xfpm_brightness_down (backlight->priv->brightness, &level);
+ }
+ if ( ret && show_popup)
+ xfpm_backlight_show (backlight, level);
}
static void
xfpm_backlight_brightness_on_ac_settings_changed (XfpmBacklight *backlight)
{
- guint timeout_on_ac;
-
- g_object_get (G_OBJECT (backlight->priv->conf),
- BRIGHTNESS_ON_AC, &timeout_on_ac,
- NULL);
-
- XFPM_DEBUG ("Alarm on ac timeout changed %u", timeout_on_ac);
-
- if ( timeout_on_ac == ALARM_DISABLED )
- {
- egg_idletime_alarm_remove (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_AC );
- }
- else
- {
- egg_idletime_alarm_set (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_AC, timeout_on_ac * 1000);
- }
+ guint timeout_on_ac;
+
+ g_object_get (G_OBJECT (backlight->priv->conf),
+ BRIGHTNESS_ON_AC, &timeout_on_ac,
+ NULL);
+
+ XFPM_DEBUG ("Alarm on ac timeout changed %u", timeout_on_ac);
+
+ if ( timeout_on_ac == ALARM_DISABLED )
+ {
+ egg_idletime_alarm_remove (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_AC );
+ }
+ else
+ {
+ egg_idletime_alarm_set (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_AC, timeout_on_ac * 1000);
+ }
}
static void
xfpm_backlight_brightness_on_battery_settings_changed (XfpmBacklight *backlight)
{
- guint timeout_on_battery ;
-
- g_object_get (G_OBJECT (backlight->priv->conf),
- BRIGHTNESS_ON_BATTERY, &timeout_on_battery,
- NULL);
-
- XFPM_DEBUG ("Alarm on battery timeout changed %u", timeout_on_battery);
-
- if ( timeout_on_battery == ALARM_DISABLED )
- {
- egg_idletime_alarm_remove (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_BATTERY );
- }
- else
- {
- egg_idletime_alarm_set (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_BATTERY, timeout_on_battery * 1000);
- }
+ guint timeout_on_battery ;
+
+ g_object_get (G_OBJECT (backlight->priv->conf),
+ BRIGHTNESS_ON_BATTERY, &timeout_on_battery,
+ NULL);
+
+ XFPM_DEBUG ("Alarm on battery timeout changed %u", timeout_on_battery);
+
+ if ( timeout_on_battery == ALARM_DISABLED )
+ {
+ egg_idletime_alarm_remove (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_BATTERY );
+ }
+ else
+ {
+ egg_idletime_alarm_set (backlight->priv->idle, TIMEOUT_BRIGHTNESS_ON_BATTERY, timeout_on_battery * 1000);
+ }
}
static void
xfpm_backlight_set_timeouts (XfpmBacklight *backlight)
{
- xfpm_backlight_brightness_on_ac_settings_changed (backlight);
- xfpm_backlight_brightness_on_battery_settings_changed (backlight);
+ xfpm_backlight_brightness_on_ac_settings_changed (backlight);
+ xfpm_backlight_brightness_on_battery_settings_changed (backlight);
}
static void
xfpm_backlight_on_battery_changed_cb (XfpmPower *power, gboolean on_battery, XfpmBacklight *backlight)
{
- backlight->priv->on_battery = on_battery;
+ backlight->priv->on_battery = on_battery;
}
static void
xfpm_backlight_class_init (XfpmBacklightClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = xfpm_backlight_get_property;
- object_class->set_property = xfpm_backlight_set_property;
- object_class->finalize = xfpm_backlight_finalize;
-
- g_object_class_install_property (object_class,
- PROP_BRIGHTNESS_SWITCH,
- g_param_spec_int (BRIGHTNESS_SWITCH,
- NULL, NULL,
- -1,
- 1,
- -1,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_BRIGHTNESS_SWITCH_SAVE,
- g_param_spec_int (BRIGHTNESS_SWITCH_SAVE,
- NULL, NULL,
- -1,
- 1,
- -1,
- G_PARAM_READWRITE));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = xfpm_backlight_get_property;
+ object_class->set_property = xfpm_backlight_set_property;
+ object_class->finalize = xfpm_backlight_finalize;
+
+ g_object_class_install_property (object_class,
+ PROP_BRIGHTNESS_SWITCH,
+ g_param_spec_int (BRIGHTNESS_SWITCH,
+ NULL, NULL,
+ -1,
+ 1,
+ -1,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_BRIGHTNESS_SWITCH_SAVE,
+ g_param_spec_int (BRIGHTNESS_SWITCH_SAVE,
+ NULL, NULL,
+ -1,
+ 1,
+ -1,
+ G_PARAM_READWRITE));
}
static void
xfpm_backlight_init (XfpmBacklight *backlight)
{
- backlight->priv = xfpm_backlight_get_instance_private (backlight);
-
- backlight->priv->brightness = xfpm_brightness_new ();
- backlight->priv->has_hw = xfpm_brightness_setup (backlight->priv->brightness);
-
- backlight->priv->notify = NULL;
- backlight->priv->idle = NULL;
- backlight->priv->conf = NULL;
- backlight->priv->button = NULL;
- backlight->priv->power = NULL;
- backlight->priv->dimmed = FALSE;
- backlight->priv->block = FALSE;
- backlight->priv->brightness_switch_initialized = FALSE;
+ backlight->priv = xfpm_backlight_get_instance_private (backlight);
+
+ backlight->priv->brightness = xfpm_brightness_new ();
+ backlight->priv->has_hw = xfpm_brightness_setup (backlight->priv->brightness);
+
+ backlight->priv->notify = NULL;
+ backlight->priv->idle = NULL;
+ backlight->priv->conf = NULL;
+ backlight->priv->button = NULL;
+ backlight->priv->power = NULL;
+ backlight->priv->dimmed = FALSE;
+ backlight->priv->block = FALSE;
+ backlight->priv->brightness_switch_initialized = FALSE;
+
+ if ( !backlight->priv->has_hw )
+ {
+ g_object_unref (backlight->priv->brightness);
+ backlight->priv->brightness = NULL;
+ }
+ else
+ {
+ gboolean ret, handle_keys;
+
+ backlight->priv->idle = egg_idletime_new ();
+ backlight->priv->conf = xfpm_xfconf_new ();
+ backlight->priv->button = xfpm_button_new ();
+ backlight->priv->power = xfpm_power_get ();
+ backlight->priv->notify = xfpm_notify_new ();
+ backlight->priv->max_level = xfpm_brightness_get_max_level (backlight->priv->brightness);
+ backlight->priv->brightness_switch = -1;
+
+ xfconf_g_property_bind (xfpm_xfconf_get_channel (backlight->priv->conf),
+ XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH, G_TYPE_INT,
+ G_OBJECT (backlight), BRIGHTNESS_SWITCH);
+
+ ret = xfpm_brightness_get_switch (backlight->priv->brightness,
+ &backlight->priv->brightness_switch);
- if ( !backlight->priv->has_hw )
+ if (ret)
+ g_object_set (G_OBJECT (backlight),
+ BRIGHTNESS_SWITCH,
+ backlight->priv->brightness_switch,
+ NULL);
+ backlight->priv->brightness_switch_initialized = TRUE;
+
+ /*
+ * If power manager has crashed last time, the brightness switch
+ * saved value will be set to the original value. In that case, we
+ * will use this saved value instead of the one found at the
+ * current startup so the setting is restored properly.
+ */
+ backlight->priv->brightness_switch_save =
+ xfconf_channel_get_int (xfpm_xfconf_get_channel(backlight->priv->conf),
+ XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE,
+ -1);
+
+ if (backlight->priv->brightness_switch_save == -1)
{
- g_object_unref (backlight->priv->brightness);
- backlight->priv->brightness = NULL;
+ if (!xfconf_channel_set_int (xfpm_xfconf_get_channel(backlight->priv->conf),
+ XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE,
+ backlight->priv->brightness_switch))
+ g_critical ("Cannot set value for property %s\n", BRIGHTNESS_SWITCH_SAVE);
+
+ backlight->priv->brightness_switch_save = backlight->priv->brightness_switch;
}
else
{
- gboolean ret, handle_keys;
-
- backlight->priv->idle = egg_idletime_new ();
- backlight->priv->conf = xfpm_xfconf_new ();
- backlight->priv->button = xfpm_button_new ();
- backlight->priv->power = xfpm_power_get ();
- backlight->priv->notify = xfpm_notify_new ();
- backlight->priv->max_level = xfpm_brightness_get_max_level (backlight->priv->brightness);
- backlight->priv->brightness_switch = -1;
-
- xfconf_g_property_bind (xfpm_xfconf_get_channel(backlight->priv->conf),
- XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH, G_TYPE_INT,
- G_OBJECT(backlight), BRIGHTNESS_SWITCH);
-
- ret = xfpm_brightness_get_switch (backlight->priv->brightness,
- &backlight->priv->brightness_switch);
-
- if (ret)
- g_object_set (G_OBJECT (backlight),
- BRIGHTNESS_SWITCH,
- backlight->priv->brightness_switch,
- NULL);
- backlight->priv->brightness_switch_initialized = TRUE;
-
- /*
- * If power manager has crashed last time, the brightness switch
- * saved value will be set to the original value. In that case, we
- * will use this saved value instead of the one found at the
- * current startup so the setting is restored properly.
- */
- backlight->priv->brightness_switch_save =
- xfconf_channel_get_int (xfpm_xfconf_get_channel(backlight->priv->conf),
- XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE,
- -1);
-
- if (backlight->priv->brightness_switch_save == -1)
- {
- if (!xfconf_channel_set_int (xfpm_xfconf_get_channel(backlight->priv->conf),
- XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE,
- backlight->priv->brightness_switch))
- g_critical ("Cannot set value for property %s\n", BRIGHTNESS_SWITCH_SAVE);
-
- backlight->priv->brightness_switch_save = backlight->priv->brightness_switch;
- }
- else
- {
- g_warning ("It seems the kernel brightness switch handling value was "
- "not restored properly on exit last time, xfce4-power-manager "
- "will try to restore it this time.");
- }
-
- /* check whether to change the brightness switch */
- handle_keys = xfconf_channel_get_bool (xfpm_xfconf_get_channel(backlight->priv->conf),
- XFPM_PROPERTIES_PREFIX HANDLE_BRIGHTNESS_KEYS,
- TRUE);
- backlight->priv->brightness_switch = handle_keys ? 0 : 1;
- g_object_set (G_OBJECT (backlight),
- BRIGHTNESS_SWITCH,
- backlight->priv->brightness_switch,
- NULL);
-
- g_signal_connect (backlight->priv->idle, "alarm-expired",
- G_CALLBACK (xfpm_backlight_alarm_timeout_cb), backlight);
-
- g_signal_connect (backlight->priv->idle, "reset",
- G_CALLBACK(xfpm_backlight_reset_cb), backlight);
-
- g_signal_connect (backlight->priv->button, "button-pressed",
- G_CALLBACK (xfpm_backlight_button_pressed_cb), backlight);
-
- g_signal_connect_swapped (backlight->priv->conf, "notify::" BRIGHTNESS_ON_AC,
- G_CALLBACK (xfpm_backlight_brightness_on_ac_settings_changed), backlight);
-
- g_signal_connect_swapped (backlight->priv->conf, "notify::" BRIGHTNESS_ON_BATTERY,
- G_CALLBACK (xfpm_backlight_brightness_on_battery_settings_changed), backlight);
-
- g_signal_connect (backlight->priv->power, "on-battery-changed",
- G_CALLBACK (xfpm_backlight_on_battery_changed_cb), backlight);
- g_object_get (G_OBJECT (backlight->priv->power),
- "on-battery", &backlight->priv->on_battery,
- NULL);
- xfpm_brightness_get_level (backlight->priv->brightness, &backlight->priv->last_level);
- xfpm_backlight_set_timeouts (backlight);
+ g_warning ("It seems the kernel brightness switch handling value was "
+ "not restored properly on exit last time, xfce4-power-manager "
+ "will try to restore it this time.");
}
+
+ /* check whether to change the brightness switch */
+ handle_keys = xfconf_channel_get_bool (xfpm_xfconf_get_channel(backlight->priv->conf),
+ XFPM_PROPERTIES_PREFIX HANDLE_BRIGHTNESS_KEYS,
+ TRUE);
+ backlight->priv->brightness_switch = handle_keys ? 0 : 1;
+ g_object_set (G_OBJECT (backlight),
+ BRIGHTNESS_SWITCH,
+ backlight->priv->brightness_switch,
+ NULL);
+
+ g_signal_connect (backlight->priv->idle, "alarm-expired",
+ G_CALLBACK (xfpm_backlight_alarm_timeout_cb), backlight);
+ g_signal_connect (backlight->priv->idle, "reset",
+ G_CALLBACK(xfpm_backlight_reset_cb), backlight);
+ g_signal_connect (backlight->priv->button, "button-pressed",
+ G_CALLBACK (xfpm_backlight_button_pressed_cb), backlight);
+ g_signal_connect_swapped (backlight->priv->conf, "notify::" BRIGHTNESS_ON_AC,
+ G_CALLBACK (xfpm_backlight_brightness_on_ac_settings_changed), backlight);
+ g_signal_connect_swapped (backlight->priv->conf, "notify::" BRIGHTNESS_ON_BATTERY,
+ G_CALLBACK (xfpm_backlight_brightness_on_battery_settings_changed), backlight);
+ g_signal_connect (backlight->priv->power, "on-battery-changed",
+ G_CALLBACK (xfpm_backlight_on_battery_changed_cb), backlight);
+
+ g_object_get (G_OBJECT (backlight->priv->power),
+ "on-battery", &backlight->priv->on_battery,
+ NULL);
+ xfpm_brightness_get_level (backlight->priv->brightness, &backlight->priv->last_level);
+ xfpm_backlight_set_timeouts (backlight);
+ }
}
static void
@@ -442,20 +438,20 @@ xfpm_backlight_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- XfpmBacklight *backlight = XFPM_BACKLIGHT (object);
+ XfpmBacklight *backlight = XFPM_BACKLIGHT (object);
- switch (prop_id)
- {
+ switch (prop_id)
+ {
case PROP_BRIGHTNESS_SWITCH:
- g_value_set_int (value, backlight->priv->brightness_switch);
- break;
+ g_value_set_int (value, backlight->priv->brightness_switch);
+ break;
case PROP_BRIGHTNESS_SWITCH_SAVE:
- g_value_set_int (value, backlight->priv->brightness_switch_save);
- break;
+ g_value_set_int (value, backlight->priv->brightness_switch_save);
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
@@ -464,51 +460,51 @@ xfpm_backlight_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- XfpmBacklight *backlight = XFPM_BACKLIGHT (object);
- gboolean ret;
+ XfpmBacklight *backlight = XFPM_BACKLIGHT (object);
+ gboolean ret;
- switch (prop_id)
- {
- case PROP_BRIGHTNESS_SWITCH:
- backlight->priv->brightness_switch = g_value_get_int (value);
- if (!backlight->priv->brightness_switch_initialized)
- break;
- ret = xfpm_brightness_set_switch (backlight->priv->brightness,
- backlight->priv->brightness_switch);
- if (!ret)
- g_warning ("Unable to set the kernel brightness switch parameter to %d.",
- backlight->priv->brightness_switch);
- else
- g_message ("Set kernel brightness switch to %d",
- backlight->priv->brightness_switch);
-
- break;
- case PROP_BRIGHTNESS_SWITCH_SAVE:
- backlight->priv->brightness_switch_save = g_value_get_int (value);
- break;
+ switch (prop_id)
+ {
+ case PROP_BRIGHTNESS_SWITCH:
+ backlight->priv->brightness_switch = g_value_get_int (value);
+ if (!backlight->priv->brightness_switch_initialized)
+ break;
+ ret = xfpm_brightness_set_switch (backlight->priv->brightness,
+ backlight->priv->brightness_switch);
+ if (!ret)
+ g_warning ("Unable to set the kernel brightness switch parameter to %d.",
+ backlight->priv->brightness_switch);
+ else
+ g_message ("Set kernel brightness switch to %d",
+ backlight->priv->brightness_switch);
+
+ break;
+ case PROP_BRIGHTNESS_SWITCH_SAVE:
+ backlight->priv->brightness_switch_save = g_value_get_int (value);
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
xfpm_backlight_finalize (GObject *object)
{
- XfpmBacklight *backlight;
+ XfpmBacklight *backlight;
- backlight = XFPM_BACKLIGHT (object);
+ backlight = XFPM_BACKLIGHT (object);
- xfpm_backlight_destroy_popup (backlight);
+ xfpm_backlight_destroy_popup (backlight);
- if ( backlight->priv->idle )
- g_object_unref (backlight->priv->idle);
+ if ( backlight->priv->idle )
+ g_object_unref (backlight->priv->idle);
- if ( backlight->priv->conf )
- {
- /* restore video module brightness switch setting */
- if ( backlight->priv->brightness_switch_save != -1 )
- {
+ if ( backlight->priv->conf )
+ {
+ /* restore video module brightness switch setting */
+ if ( backlight->priv->brightness_switch_save != -1 )
+ {
gboolean ret =
xfpm_brightness_set_switch (backlight->priv->brightness,
backlight->priv->brightness_switch_save);
@@ -519,41 +515,40 @@ xfpm_backlight_finalize (GObject *object)
if (ret)
{
- backlight->priv->brightness_switch = backlight->priv->brightness_switch_save;
- g_message ("Restored brightness switch value to: %d", backlight->priv->brightness_switch);
+ backlight->priv->brightness_switch = backlight->priv->brightness_switch_save;
+ g_message ("Restored brightness switch value to: %d", backlight->priv->brightness_switch);
}
else
- g_warning ("Unable to restore the kernel brightness switch parameter to its original value, "
- "still resetting the saved value.");
+ g_warning ("Unable to restore the kernel brightness switch parameter to its original value, "
+ "still resetting the saved value.");
}
-
g_object_unref (backlight->priv->conf);
- }
+ }
- if ( backlight->priv->brightness )
- g_object_unref (backlight->priv->brightness);
+ if ( backlight->priv->brightness )
+ g_object_unref (backlight->priv->brightness);
- if ( backlight->priv->button )
- g_object_unref (backlight->priv->button);
+ if ( backlight->priv->button )
+ g_object_unref (backlight->priv->button);
- if ( backlight->priv->power )
- g_object_unref (backlight->priv->power);
+ if ( backlight->priv->power )
+ g_object_unref (backlight->priv->power);
- if ( backlight->priv->notify)
- g_object_unref (backlight->priv->notify);
+ if ( backlight->priv->notify)
+ g_object_unref (backlight->priv->notify);
- G_OBJECT_CLASS (xfpm_backlight_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_backlight_parent_class)->finalize (object);
}
XfpmBacklight *
xfpm_backlight_new (void)
{
- XfpmBacklight *backlight = NULL;
- backlight = g_object_new (XFPM_TYPE_BACKLIGHT, NULL);
- return backlight;
+ XfpmBacklight *backlight = NULL;
+ backlight = g_object_new (XFPM_TYPE_BACKLIGHT, NULL);
+ return backlight;
}
gboolean xfpm_backlight_has_hw (XfpmBacklight *backlight)
{
- return backlight->priv->has_hw;
+ return backlight->priv->has_hw;
}
diff --git a/src/xfpm-backlight.h b/src/xfpm-backlight.h
index 9741fec..1178732 100644
--- a/src/xfpm-backlight.h
+++ b/src/xfpm-backlight.h
@@ -33,22 +33,18 @@ typedef struct XfpmBacklightPrivate XfpmBacklightPrivate;
typedef struct
{
- GObject parent;
- XfpmBacklightPrivate *priv;
-
+ GObject parent;
+ XfpmBacklightPrivate *priv;
} XfpmBacklight;
typedef struct
{
- GObjectClass parent_class;
-
+ GObjectClass parent_class;
} XfpmBacklightClass;
-GType xfpm_backlight_get_type (void) G_GNUC_CONST;
-
-XfpmBacklight *xfpm_backlight_new (void);
-
-gboolean xfpm_backlight_has_hw (XfpmBacklight *backlight);
+GType xfpm_backlight_get_type (void) G_GNUC_CONST;
+XfpmBacklight *xfpm_backlight_new (void);
+gboolean xfpm_backlight_has_hw (XfpmBacklight *backlight);
G_END_DECLS
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 4d204d6..cc73363 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -52,42 +52,42 @@ static void xfpm_battery_finalize (GObject *object);
struct XfpmBatteryPrivate
{
- XfpmXfconf *conf;
- XfpmNotify *notify;
- XfpmButton *button;
- UpDevice *device;
- UpClient *client;
-
- XfpmBatteryCharge charge;
- UpDeviceState state;
- UpDeviceKind type;
- gboolean ac_online;
- gboolean present;
- guint percentage;
- gint64 time_to_full;
- gint64 time_to_empty;
-
- const gchar *battery_name;
-
- gulong sig;
- gulong sig_bt;
- gulong sig_up;
-
- guint notify_idle;
+ XfpmXfconf *conf;
+ XfpmNotify *notify;
+ XfpmButton *button;
+ UpDevice *device;
+ UpClient *client;
+
+ XfpmBatteryCharge charge;
+ UpDeviceState state;
+ UpDeviceKind type;
+ gboolean ac_online;
+ gboolean present;
+ guint percentage;
+ gint64 time_to_full;
+ gint64 time_to_empty;
+
+ const gchar *battery_name;
+
+ gulong sig;
+ gulong sig_bt;
+ gulong sig_up;
+
+ guint notify_idle;
};
enum
{
- PROP_0,
- PROP_AC_ONLINE,
- PROP_CHARGE_STATUS,
- PROP_DEVICE_TYPE
+ PROP_0,
+ PROP_AC_ONLINE,
+ PROP_CHARGE_STATUS,
+ PROP_DEVICE_TYPE
};
enum
{
- BATTERY_CHARGE_CHANGED,
- LAST_SIGNAL
+ BATTERY_CHARGE_CHANGED,
+ LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0 };
@@ -98,414 +98,422 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmBattery, xfpm_battery, GTK_TYPE_WIDGET)
static gchar *
xfpm_battery_get_message_from_battery_state (XfpmBattery *battery)
{
- gchar *msg = NULL;
+ gchar *msg = NULL;
- if (battery->priv->type == UP_DEVICE_KIND_BATTERY || battery->priv->type == UP_DEVICE_KIND_UPS)
+ if (battery->priv->type == UP_DEVICE_KIND_BATTERY || battery->priv->type == UP_DEVICE_KIND_UPS)
+ {
+ switch (battery->priv->state)
{
- switch (battery->priv->state)
- {
- case UP_DEVICE_STATE_FULLY_CHARGED:
- msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
- break;
- case UP_DEVICE_STATE_CHARGING:
- msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
-
- if ( battery->priv->time_to_full != 0 )
- {
- gchar *tmp, *est_time_str;
- tmp = g_strdup (msg);
- g_free (msg);
-
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_full);
-
- msg = g_strdup_printf (_("%s (%i%%)\n%s until fully charged"), tmp, battery->priv->percentage, est_time_str);
- g_free (est_time_str);
- g_free (tmp);
- }
-
- break;
- case UP_DEVICE_STATE_DISCHARGING:
- if (battery->priv->ac_online)
- msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
- else
- msg = g_strdup_printf (_("System is running on %s power"), battery->priv->battery_name);
-
- if ( battery->priv->time_to_empty != 0 )
- {
- gchar *tmp, *est_time_str;
- tmp = g_strdup (msg);
- g_free (msg);
-
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_empty);
-
- msg = g_strdup_printf (_("%s (%i%%)\nEstimated time left is %s"), tmp, battery->priv->percentage, est_time_str);
- g_free (tmp);
- g_free (est_time_str);
- }
- break;
- case UP_DEVICE_STATE_EMPTY:
- msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
- break;
- default:
- break;
- }
-
+ case UP_DEVICE_STATE_FULLY_CHARGED:
+ msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
+ break;
+ case UP_DEVICE_STATE_CHARGING:
+ msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
+
+ if ( battery->priv->time_to_full != 0 )
+ {
+ gchar *tmp, *est_time_str;
+ tmp = g_strdup (msg);
+ g_free (msg);
+
+ est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_full);
+
+ msg = g_strdup_printf (_("%s (%i%%)\n%s until fully charged"), tmp, battery->priv->percentage, est_time_str);
+ g_free (est_time_str);
+ g_free (tmp);
+ }
+
+ break;
+ case UP_DEVICE_STATE_DISCHARGING:
+ if (battery->priv->ac_online)
+ msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
+ else
+ msg = g_strdup_printf (_("System is running on %s power"), battery->priv->battery_name);
+
+ if ( battery->priv->time_to_empty != 0 )
+ {
+ gchar *tmp, *est_time_str;
+ tmp = g_strdup (msg);
+ g_free (msg);
+
+ est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_empty);
+
+ msg = g_strdup_printf (_("%s (%i%%)\nEstimated time left is %s"), tmp, battery->priv->percentage, est_time_str);
+ g_free (tmp);
+ g_free (est_time_str);
+ }
+ break;
+ case UP_DEVICE_STATE_EMPTY:
+ msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
+ break;
+ default:
+ break;
}
- else if (battery->priv->type >= UP_DEVICE_KIND_MONITOR)
+
+ }
+ else if (battery->priv->type >= UP_DEVICE_KIND_MONITOR)
+ {
+ switch (battery->priv->state)
{
- switch (battery->priv->state)
- {
- case UP_DEVICE_STATE_FULLY_CHARGED:
- msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
- break;
- case UP_DEVICE_STATE_CHARGING:
- msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
- break;
- case UP_DEVICE_STATE_DISCHARGING:
- msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
- break;
- case UP_DEVICE_STATE_EMPTY:
- msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
- break;
- default:
- break;
- }
+ case UP_DEVICE_STATE_FULLY_CHARGED:
+ msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
+ break;
+ case UP_DEVICE_STATE_CHARGING:
+ msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
+ break;
+ case UP_DEVICE_STATE_DISCHARGING:
+ msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
+ break;
+ case UP_DEVICE_STATE_EMPTY:
+ msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
+ break;
+ default:
+ break;
}
+ }
- return msg;
+ return msg;
}
static void
xfpm_battery_notify (XfpmBattery *battery)
{
- gchar *message = NULL;
+ gchar *message = NULL;
- message = xfpm_battery_get_message_from_battery_state (battery);
+ message = xfpm_battery_get_message_from_battery_state (battery);
- if ( !message )
- return;
+ if ( !message )
+ return;
- xfpm_notify_show_notification (battery->priv->notify,
- _("Power Manager"),
- message,
- xfpm_battery_get_icon_name (battery),
- 8000,
- XFPM_NOTIFY_NORMAL);
+ xfpm_notify_show_notification (battery->priv->notify,
+ _("Power Manager"),
+ message,
+ xfpm_battery_get_icon_name (battery),
+ 8000,
+ XFPM_NOTIFY_NORMAL);
- g_free (message);
+ g_free (message);
}
static gboolean
xfpm_battery_notify_idle (gpointer data)
{
- XfpmBattery *battery = XFPM_BATTERY (data);
+ XfpmBattery *battery = XFPM_BATTERY (data);
- xfpm_battery_notify (battery);
- battery->priv->notify_idle = 0;
+ xfpm_battery_notify (battery);
+ battery->priv->notify_idle = 0;
- return FALSE;
+ return FALSE;
}
static void
xfpm_battery_notify_state (XfpmBattery *battery)
{
- gboolean notify;
- static gboolean starting_up = TRUE;
+ gboolean notify;
+ static gboolean starting_up = TRUE;
- if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
- battery->priv->type == UP_DEVICE_KIND_UPS )
+ if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
+ battery->priv->type == UP_DEVICE_KIND_UPS )
+ {
+ if ( starting_up )
{
- if ( starting_up )
- {
- starting_up = FALSE;
- return;
- }
-
- g_object_get (G_OBJECT (battery->priv->conf),
- GENERAL_NOTIFICATION_CFG, ¬ify,
- NULL);
-
- if ( notify )
- {
- if (battery->priv->notify_idle == 0)
- battery->priv->notify_idle = g_idle_add (xfpm_battery_notify_idle, battery);
- }
+ starting_up = FALSE;
+ return;
}
-}
-
-static void
-xfpm_battery_check_charge (XfpmBattery *battery)
-{
- XfpmBatteryCharge charge;
- guint critical_level, low_level;
g_object_get (G_OBJECT (battery->priv->conf),
- CRITICAL_POWER_LEVEL, &critical_level,
- NULL);
-
- low_level = critical_level + 10;
+ GENERAL_NOTIFICATION_CFG, ¬ify,
+ NULL);
- if ( battery->priv->percentage > low_level )
- charge = XFPM_BATTERY_CHARGE_OK;
- else if ( battery->priv->percentage <= low_level && battery->priv->percentage > critical_level )
- charge = XFPM_BATTERY_CHARGE_LOW;
- else if ( battery->priv->percentage <= critical_level )
- charge = XFPM_BATTERY_CHARGE_CRITICAL;
- else
- charge = XFPM_BATTERY_CHARGE_UNKNOWN;
-
- if ( charge != battery->priv->charge)
+ if ( notify )
{
- battery->priv->charge = charge;
- /*
- * only emit signal when when battery charge changes from ok->low->critical
- * and not the other way round.
- */
- if ( battery->priv->charge != XFPM_BATTERY_CHARGE_CRITICAL || charge != XFPM_BATTERY_CHARGE_LOW )
- g_signal_emit (G_OBJECT (battery), signals [BATTERY_CHARGE_CHANGED], 0);
+ if (battery->priv->notify_idle == 0)
+ battery->priv->notify_idle = g_idle_add (xfpm_battery_notify_idle, battery);
}
+ }
}
static void
-xfpm_battery_refresh (XfpmBattery *battery, UpDevice *device)
+xfpm_battery_check_charge (XfpmBattery *battery)
{
- gboolean present;
- guint state;
- gdouble percentage;
- guint64 to_empty, to_full;
- g_object_get(device,
- "is-present", &present,
- "percentage", &percentage,
- "state", &state,
- "time-to-empty", &to_empty,
- "time-to-full", &to_full,
- NULL);
-
- battery->priv->present = present;
- if ( state != battery->priv->state )
- {
- battery->priv->state = state;
- xfpm_battery_notify_state (battery);
- }
- battery->priv->percentage = (guint) percentage;
-
- xfpm_battery_check_charge (battery);
+ XfpmBatteryCharge charge;
+ guint critical_level, low_level;
+
+ g_object_get (G_OBJECT (battery->priv->conf),
+ CRITICAL_POWER_LEVEL, &critical_level,
+ NULL);
+
+ low_level = critical_level + 10;
+
+ if ( battery->priv->percentage > low_level )
+ charge = XFPM_BATTERY_CHARGE_OK;
+ else if ( battery->priv->percentage <= low_level && battery->priv->percentage > critical_level )
+ charge = XFPM_BATTERY_CHARGE_LOW;
+ else if ( battery->priv->percentage <= critical_level )
+ charge = XFPM_BATTERY_CHARGE_CRITICAL;
+ else
+ charge = XFPM_BATTERY_CHARGE_UNKNOWN;
+
+ if ( charge != battery->priv->charge)
+ {
+ battery->priv->charge = charge;
+ /*
+ * only emit signal when when battery charge changes from ok->low->critical
+ * and not the other way round.
+ */
+ if ( battery->priv->charge != XFPM_BATTERY_CHARGE_CRITICAL || charge != XFPM_BATTERY_CHARGE_LOW )
+ g_signal_emit (G_OBJECT (battery), signals [BATTERY_CHARGE_CHANGED], 0);
+ }
+}
- if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
- battery->priv->type == UP_DEVICE_KIND_UPS )
- {
- battery->priv->time_to_empty = to_empty;
- battery->priv->time_to_full = to_empty;
- }
+static void
+xfpm_battery_refresh (XfpmBattery *battery, UpDevice *device)
+{
+ gboolean present;
+ guint state;
+ gdouble percentage;
+ guint64 to_empty, to_full;
+
+ g_object_get (device,
+ "is-present", &present,
+ "percentage", &percentage,
+ "state", &state,
+ "time-to-empty", &to_empty,
+ "time-to-full", &to_full,
+ NULL);
+
+ battery->priv->present = present;
+ if ( state != battery->priv->state )
+ {
+ battery->priv->state = state;
+ xfpm_battery_notify_state (battery);
+ }
+ battery->priv->percentage = (guint) percentage;
+
+ xfpm_battery_check_charge (battery);
+
+ if ( battery->priv->type == UP_DEVICE_KIND_BATTERY ||
+ battery->priv->type == UP_DEVICE_KIND_UPS )
+ {
+ battery->priv->time_to_empty = to_empty;
+ battery->priv->time_to_full = to_empty;
+ }
}
static void
xfpm_battery_changed_cb (UpDevice *device,
- GParamSpec *pspec,
- XfpmBattery *battery)
+ GParamSpec *pspec,
+ XfpmBattery *battery)
{
- xfpm_battery_refresh (battery, device);
+ xfpm_battery_refresh (battery, device);
}
-static void xfpm_battery_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+static void
+xfpm_battery_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- XfpmBattery *battery;
-
- battery = XFPM_BATTERY (object);
-
- switch (prop_id)
- {
- case PROP_AC_ONLINE:
- g_value_set_boolean (value, battery->priv->ac_online);
- break;
- case PROP_DEVICE_TYPE:
- g_value_set_uint (value, battery->priv->type);
- break;
- case PROP_CHARGE_STATUS:
- g_value_set_enum (value, battery->priv->charge);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ XfpmBattery *battery;
+
+ battery = XFPM_BATTERY (object);
+
+ switch (prop_id)
+ {
+ case PROP_AC_ONLINE:
+ g_value_set_boolean (value, battery->priv->ac_online);
+ break;
+ case PROP_DEVICE_TYPE:
+ g_value_set_uint (value, battery->priv->type);
+ break;
+ case PROP_CHARGE_STATUS:
+ g_value_set_enum (value, battery->priv->charge);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
-static void xfpm_battery_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+static void
+xfpm_battery_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- XfpmBattery *battery;
-
- battery = XFPM_BATTERY (object);
-
- switch (prop_id)
- {
- case PROP_AC_ONLINE:
- battery->priv->ac_online = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ XfpmBattery *battery;
+
+ battery = XFPM_BATTERY (object);
+
+ switch (prop_id)
+ {
+ case PROP_AC_ONLINE:
+ battery->priv->ac_online = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
xfpm_battery_class_init (XfpmBatteryClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = xfpm_battery_finalize;
- object_class->get_property = xfpm_battery_get_property;
- object_class->set_property = xfpm_battery_set_property;
-
- signals [BATTERY_CHARGE_CHANGED] =
- g_signal_new ("battery-charge-changed",
- XFPM_TYPE_BATTERY,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmBatteryClass, battery_charge_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0, G_TYPE_NONE);
-
- g_object_class_install_property (object_class,
- PROP_AC_ONLINE,
- g_param_spec_boolean("ac-online",
- NULL, NULL,
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_DEVICE_TYPE,
- g_param_spec_uint ("device-type",
- NULL, NULL,
- UP_DEVICE_KIND_UNKNOWN,
- UP_DEVICE_KIND_LAST,
- UP_DEVICE_KIND_UNKNOWN,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CHARGE_STATUS,
- g_param_spec_enum ("charge-status",
- NULL, NULL,
- XFPM_TYPE_BATTERY_CHARGE,
- XFPM_BATTERY_CHARGE_UNKNOWN,
- G_PARAM_READABLE));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = xfpm_battery_finalize;
+ object_class->get_property = xfpm_battery_get_property;
+ object_class->set_property = xfpm_battery_set_property;
+
+ signals [BATTERY_CHARGE_CHANGED] =
+ g_signal_new ("battery-charge-changed",
+ XFPM_TYPE_BATTERY,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(XfpmBatteryClass, battery_charge_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0, G_TYPE_NONE);
+
+ g_object_class_install_property (object_class,
+ PROP_AC_ONLINE,
+ g_param_spec_boolean ("ac-online",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (object_class,
+ PROP_DEVICE_TYPE,
+ g_param_spec_uint ("device-type",
+ NULL, NULL,
+ UP_DEVICE_KIND_UNKNOWN,
+ UP_DEVICE_KIND_LAST,
+ UP_DEVICE_KIND_UNKNOWN,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_CHARGE_STATUS,
+ g_param_spec_enum ("charge-status",
+ NULL, NULL,
+ XFPM_TYPE_BATTERY_CHARGE,
+ XFPM_BATTERY_CHARGE_UNKNOWN,
+ G_PARAM_READABLE));
}
static void
xfpm_battery_init (XfpmBattery *battery)
{
- battery->priv = xfpm_battery_get_instance_private (battery);
-
- battery->priv->conf = xfpm_xfconf_new ();
- battery->priv->notify = xfpm_notify_new ();
- battery->priv->device = NULL;
- battery->priv->client = NULL;
- battery->priv->state = UP_DEVICE_STATE_UNKNOWN;
- battery->priv->type = UP_DEVICE_KIND_UNKNOWN;
- battery->priv->charge = XFPM_BATTERY_CHARGE_UNKNOWN;
- battery->priv->time_to_full = 0;
- battery->priv->time_to_empty = 0;
- battery->priv->button = xfpm_button_new ();
- battery->priv->ac_online = TRUE;
+ battery->priv = xfpm_battery_get_instance_private (battery);
+
+ battery->priv->conf = xfpm_xfconf_new ();
+ battery->priv->notify = xfpm_notify_new ();
+ battery->priv->device = NULL;
+ battery->priv->client = NULL;
+ battery->priv->state = UP_DEVICE_STATE_UNKNOWN;
+ battery->priv->type = UP_DEVICE_KIND_UNKNOWN;
+ battery->priv->charge = XFPM_BATTERY_CHARGE_UNKNOWN;
+ battery->priv->time_to_full = 0;
+ battery->priv->time_to_empty = 0;
+ battery->priv->button = xfpm_button_new ();
+ battery->priv->ac_online = TRUE;
}
static void
xfpm_battery_finalize (GObject *object)
{
- XfpmBattery *battery;
+ XfpmBattery *battery;
- battery = XFPM_BATTERY (object);
+ battery = XFPM_BATTERY (object);
- if (battery->priv->notify_idle != 0)
- g_source_remove (battery->priv->notify_idle);
+ if (battery->priv->notify_idle != 0)
+ g_source_remove (battery->priv->notify_idle);
- if ( g_signal_handler_is_connected (battery->priv->device, battery->priv->sig_up ) )
- g_signal_handler_disconnect (G_OBJECT (battery->priv->device), battery->priv->sig_up);
+ if ( g_signal_handler_is_connected (battery->priv->device, battery->priv->sig_up ) )
+ g_signal_handler_disconnect (G_OBJECT (battery->priv->device), battery->priv->sig_up);
- if ( g_signal_handler_is_connected (battery->priv->conf, battery->priv->sig ) )
- g_signal_handler_disconnect (G_OBJECT (battery->priv->conf), battery->priv->sig);
+ if ( g_signal_handler_is_connected (battery->priv->conf, battery->priv->sig ) )
+ g_signal_handler_disconnect (G_OBJECT (battery->priv->conf), battery->priv->sig);
- if ( g_signal_handler_is_connected (battery->priv->button, battery->priv->sig_bt ) )
- g_signal_handler_disconnect (G_OBJECT (battery->priv->button), battery->priv->sig_bt);
+ if ( g_signal_handler_is_connected (battery->priv->button, battery->priv->sig_bt ) )
+ g_signal_handler_disconnect (G_OBJECT (battery->priv->button), battery->priv->sig_bt);
- g_object_unref (battery->priv->device);
- g_object_unref (battery->priv->conf);
- g_object_unref (battery->priv->notify);
- g_object_unref (battery->priv->button);
+ g_object_unref (battery->priv->device);
+ g_object_unref (battery->priv->conf);
+ g_object_unref (battery->priv->notify);
+ g_object_unref (battery->priv->button);
- G_OBJECT_CLASS (xfpm_battery_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_battery_parent_class)->finalize (object);
}
GtkWidget *
xfpm_battery_new (void)
{
- XfpmBattery *battery = NULL;
+ XfpmBattery *battery = NULL;
- battery = g_object_new (XFPM_TYPE_BATTERY, NULL);
+ battery = g_object_new (XFPM_TYPE_BATTERY, NULL);
- return GTK_WIDGET (battery);
+ return GTK_WIDGET (battery);
}
-void xfpm_battery_monitor_device (XfpmBattery *battery,
- const char *object_path,
- UpDeviceKind device_type)
+void
+xfpm_battery_monitor_device (XfpmBattery *battery,
+ const char *object_path,
+ UpDeviceKind device_type)
{
- UpDevice *device;
- battery->priv->type = device_type;
- battery->priv->client = up_client_new();
- battery->priv->battery_name = xfpm_power_translate_device_type (device_type);
+ UpDevice *device;
+ battery->priv->type = device_type;
+ battery->priv->client = up_client_new();
+ battery->priv->battery_name = xfpm_power_translate_device_type (device_type);
- device = up_device_new();
- up_device_set_object_path_sync (device, object_path, NULL, NULL);
- battery->priv->device = device;
- battery->priv->sig_up = g_signal_connect (battery->priv->device, "notify", G_CALLBACK (xfpm_battery_changed_cb), battery);
+ device = up_device_new();
+ up_device_set_object_path_sync (device, object_path, NULL, NULL);
+ battery->priv->device = device;
+ battery->priv->sig_up = g_signal_connect (battery->priv->device, "notify", G_CALLBACK (xfpm_battery_changed_cb), battery);
- g_object_set (G_OBJECT (battery),
- "has-tooltip", TRUE,
- NULL);
+ g_object_set (G_OBJECT (battery),
+ "has-tooltip", TRUE,
+ NULL);
- xfpm_battery_refresh (battery, device);
+ xfpm_battery_refresh (battery, device);
}
-UpDeviceKind xfpm_battery_get_device_type (XfpmBattery *battery)
+UpDeviceKind
+xfpm_battery_get_device_type (XfpmBattery *battery)
{
- g_return_val_if_fail (XFPM_IS_BATTERY (battery), UP_DEVICE_KIND_UNKNOWN );
+ g_return_val_if_fail (XFPM_IS_BATTERY (battery), UP_DEVICE_KIND_UNKNOWN );
- return battery->priv->type;
+ return battery->priv->type;
}
-XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery)
+XfpmBatteryCharge
+xfpm_battery_get_charge (XfpmBattery *battery)
{
- g_return_val_if_fail (XFPM_IS_BATTERY (battery), XFPM_BATTERY_CHARGE_UNKNOWN);
+ g_return_val_if_fail (XFPM_IS_BATTERY (battery), XFPM_BATTERY_CHARGE_UNKNOWN);
- return battery->priv->charge;
+ return battery->priv->charge;
}
-const gchar *xfpm_battery_get_battery_name (XfpmBattery *battery)
+const gchar *
+xfpm_battery_get_battery_name (XfpmBattery *battery)
{
- g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
+ g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
- return battery->priv->battery_name;
+ return battery->priv->battery_name;
}
-gchar *xfpm_battery_get_time_left (XfpmBattery *battery)
+gchar *
+xfpm_battery_get_time_left (XfpmBattery *battery)
{
- g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
+ g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
- return xfpm_battery_get_time_string (battery->priv->time_to_empty);
+ return xfpm_battery_get_time_string (battery->priv->time_to_empty);
}
const gchar*
xfpm_battery_get_icon_name (XfpmBattery *battery)
{
- g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
+ g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
- return get_device_icon_name (battery->priv->client, battery->priv->device);
+ return get_device_icon_name (battery->priv->client, battery->priv->device);
}
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 4d3e912..e4f89dc 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -37,37 +37,26 @@ typedef struct XfpmBatteryPrivate XfpmBatteryPrivate;
typedef struct
{
- GtkWidget parent;
-
+ GtkWidget parent;
XfpmBatteryPrivate *priv;
-
} XfpmBattery;
typedef struct
{
- GtkWidgetClass parent_class;
-
- void (*battery_charge_changed) (XfpmBattery *battery);
-
+ GtkWidgetClass parent_class;
+ void (*battery_charge_changed) (XfpmBattery *battery);
} XfpmBatteryClass;
-GType xfpm_battery_get_type (void) G_GNUC_CONST;
-
-GtkWidget *xfpm_battery_new (void);
-
-void xfpm_battery_monitor_device (XfpmBattery *battery,
- const char *object_path,
- UpDeviceKind device_type);
-
-UpDeviceKind xfpm_battery_get_device_type (XfpmBattery *battery);
-
-XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery);
-
-const gchar *xfpm_battery_get_battery_name(XfpmBattery *battery);
-
-gchar *xfpm_battery_get_time_left (XfpmBattery *battery);
-
-const gchar *xfpm_battery_get_icon_name (XfpmBattery *battery);
+GType xfpm_battery_get_type (void) G_GNUC_CONST;
+GtkWidget *xfpm_battery_new (void);
+void xfpm_battery_monitor_device (XfpmBattery *battery,
+ const char *object_path,
+ UpDeviceKind device_type);
+UpDeviceKind xfpm_battery_get_device_type (XfpmBattery *battery);
+XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery);
+const gchar *xfpm_battery_get_battery_name (XfpmBattery *battery);
+gchar *xfpm_battery_get_time_left (XfpmBattery *battery);
+const gchar *xfpm_battery_get_icon_name (XfpmBattery *battery);
G_END_DECLS
diff --git a/src/xfpm-button.c b/src/xfpm-button.c
index ed72ea8..e15922b 100644
--- a/src/xfpm-button.c
+++ b/src/xfpm-button.c
@@ -56,22 +56,21 @@ static void xfpm_button_finalize (GObject *object);
static struct
{
- XfpmButtonKey key;
- guint key_code;
+ XfpmButtonKey key;
+ guint key_code;
} xfpm_key_map [NUMBER_OF_BUTTONS] = { {0, 0}, };
struct XfpmButtonPrivate
{
- GdkScreen *screen;
- GdkWindow *window;
-
- guint16 mapped_buttons;
+ GdkScreen *screen;
+ GdkWindow *window;
+ guint16 mapped_buttons;
};
enum
{
- BUTTON_PRESSED,
- LAST_SIGNAL
+ BUTTON_PRESSED,
+ LAST_SIGNAL
};
#define DUPLICATE_SHUTDOWN_TIMEOUT 4.0f
@@ -83,207 +82,206 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmButton, xfpm_button, G_TYPE_OBJECT)
static guint
xfpm_button_get_key (unsigned int keycode)
{
- XfpmButtonKey key = BUTTON_UNKNOWN;
- guint i;
+ XfpmButtonKey key = BUTTON_UNKNOWN;
+ guint i;
- for ( i = 0; i < G_N_ELEMENTS (xfpm_key_map); i++)
- {
- if ( xfpm_key_map [i].key_code == keycode )
- key = xfpm_key_map [i].key;
- }
+ for ( i = 0; i < G_N_ELEMENTS (xfpm_key_map); i++)
+ {
+ if ( xfpm_key_map [i].key_code == keycode )
+ key = xfpm_key_map [i].key;
+ }
- return key;
+ return key;
}
static GdkFilterReturn
xfpm_button_filter_x_events (GdkXEvent *xevent, GdkEvent *ev, gpointer data)
{
- XfpmButtonKey key;
- XfpmButton *button;
+ XfpmButtonKey key;
+ XfpmButton *button;
- XEvent *xev = (XEvent *) xevent;
+ XEvent *xev = (XEvent *) xevent;
- if ( xev->type != KeyPress )
- return GDK_FILTER_CONTINUE;
+ if ( xev->type != KeyPress )
+ return GDK_FILTER_CONTINUE;
- key = xfpm_button_get_key (xev->xkey.keycode);
+ key = xfpm_button_get_key (xev->xkey.keycode);
- if ( key != BUTTON_UNKNOWN )
- {
- button = (XfpmButton *) data;
+ if ( key != BUTTON_UNKNOWN )
+ {
+ button = (XfpmButton *) data;
- XFPM_DEBUG_ENUM (key, XFPM_TYPE_BUTTON_KEY, "Key press");
+ XFPM_DEBUG_ENUM (key, XFPM_TYPE_BUTTON_KEY, "Key press");
- g_signal_emit (G_OBJECT(button), signals[BUTTON_PRESSED], 0, key);
- return GDK_FILTER_REMOVE;
- }
+ g_signal_emit (G_OBJECT(button), signals[BUTTON_PRESSED], 0, key);
+ return GDK_FILTER_REMOVE;
+ }
- return GDK_FILTER_CONTINUE;
+ return GDK_FILTER_CONTINUE;
}
static gboolean
xfpm_button_grab_keystring (XfpmButton *button, guint keycode)
{
- Display *display;
- GdkDisplay *gdisplay;
- guint ret;
- guint modmask = AnyModifier;
-
- display = gdk_x11_get_default_xdisplay ();
- gdisplay = gdk_display_get_default ();
-
- gdk_x11_display_error_trap_push (gdisplay);
-
- ret = XGrabKey (display, keycode, modmask,
- GDK_WINDOW_XID (button->priv->window), True,
- GrabModeAsync, GrabModeAsync);
-
- if ( ret == BadAccess )
- {
- g_warning ("Failed to grab modmask=%u, keycode=%li",
- modmask, (long int) keycode);
- return FALSE;
- }
-
- ret = XGrabKey (display, keycode, LockMask | modmask,
- GDK_WINDOW_XID (button->priv->window), True,
- GrabModeAsync, GrabModeAsync);
-
- if (ret == BadAccess)
- {
- g_warning ("Failed to grab modmask=%u, keycode=%li",
- LockMask | modmask, (long int) keycode);
- return FALSE;
- }
-
- gdk_display_flush (gdisplay);
- gdk_x11_display_error_trap_pop_ignored (gdisplay);
- return TRUE;
+ Display *display;
+ GdkDisplay *gdisplay;
+ guint ret;
+ guint modmask = AnyModifier;
+
+ display = gdk_x11_get_default_xdisplay ();
+ gdisplay = gdk_display_get_default ();
+
+ gdk_x11_display_error_trap_push (gdisplay);
+
+ ret = XGrabKey (display, keycode, modmask,
+ GDK_WINDOW_XID (button->priv->window), True,
+ GrabModeAsync, GrabModeAsync);
+
+ if ( ret == BadAccess )
+ {
+ g_warning ("Failed to grab modmask=%u, keycode=%li", modmask, (long int) keycode);
+ return FALSE;
+ }
+
+ ret = XGrabKey (display, keycode, LockMask | modmask,
+ GDK_WINDOW_XID (button->priv->window), True,
+ GrabModeAsync, GrabModeAsync);
+
+ if (ret == BadAccess)
+ {
+ g_warning ("Failed to grab modmask=%u, keycode=%li", LockMask | modmask, (long int) keycode);
+ return FALSE;
+ }
+
+ gdk_display_flush (gdisplay);
+ gdk_x11_display_error_trap_pop_ignored (gdisplay);
+
+ return TRUE;
}
static gboolean
xfpm_button_xevent_key (XfpmButton *button, guint keysym , XfpmButtonKey key)
{
- guint keycode = XKeysymToKeycode (gdk_x11_get_default_xdisplay(), keysym);
+ guint keycode = XKeysymToKeycode (gdk_x11_get_default_xdisplay(), keysym);
- if ( keycode == 0 )
- {
- g_warning ("could not map keysym %x to keycode\n", keysym);
- return FALSE;
- }
+ if ( keycode == 0 )
+ {
+ g_warning ("could not map keysym %x to keycode\n", keysym);
+ return FALSE;
+ }
- if ( !xfpm_button_grab_keystring(button, keycode))
- {
- g_warning ("Failed to grab %i\n", keycode);
- return FALSE;
- }
+ if ( !xfpm_button_grab_keystring(button, keycode))
+ {
+ g_warning ("Failed to grab %i\n", keycode);
+ return FALSE;
+ }
- XFPM_DEBUG_ENUM (key, XFPM_TYPE_BUTTON_KEY, "Grabbed key %li ", (long int) keycode);
+ XFPM_DEBUG_ENUM (key, XFPM_TYPE_BUTTON_KEY, "Grabbed key %li ", (long int) keycode);
- xfpm_key_map [key].key_code = keycode;
- xfpm_key_map [key].key = key;
+ xfpm_key_map [key].key_code = keycode;
+ xfpm_key_map [key].key = key;
- return TRUE;
+ return TRUE;
}
static void
xfpm_button_setup (XfpmButton *button)
{
- button->priv->screen = gdk_screen_get_default ();
- button->priv->window = gdk_screen_get_root_window (button->priv->screen);
+ button->priv->screen = gdk_screen_get_default ();
+ button->priv->window = gdk_screen_get_root_window (button->priv->screen);
- if ( xfpm_button_xevent_key (button, XF86XK_PowerOff, BUTTON_POWER_OFF) )
- button->priv->mapped_buttons |= POWER_KEY;
+ if ( xfpm_button_xevent_key (button, XF86XK_PowerOff, BUTTON_POWER_OFF) )
+ button->priv->mapped_buttons |= POWER_KEY;
#ifdef HAVE_XF86XK_HIBERNATE
- if ( xfpm_button_xevent_key (button, XF86XK_Hibernate, BUTTON_HIBERNATE) )
- button->priv->mapped_buttons |= HIBERNATE_KEY;
+ if ( xfpm_button_xevent_key (button, XF86XK_Hibernate, BUTTON_HIBERNATE) )
+ button->priv->mapped_buttons |= HIBERNATE_KEY;
#endif
#ifdef HAVE_XF86XK_SUSPEND
- if ( xfpm_button_xevent_key (button, XF86XK_Suspend, BUTTON_HIBERNATE) )
- button->priv->mapped_buttons |= HIBERNATE_KEY;
+ if ( xfpm_button_xevent_key (button, XF86XK_Suspend, BUTTON_HIBERNATE) )
+ button->priv->mapped_buttons |= HIBERNATE_KEY;
#endif
- if ( xfpm_button_xevent_key (button, XF86XK_Sleep, BUTTON_SLEEP) )
- button->priv->mapped_buttons |= SLEEP_KEY;
+ if ( xfpm_button_xevent_key (button, XF86XK_Sleep, BUTTON_SLEEP) )
+ button->priv->mapped_buttons |= SLEEP_KEY;
- if ( xfpm_button_xevent_key (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP) )
- button->priv->mapped_buttons |= BRIGHTNESS_KEY_UP;
+ if ( xfpm_button_xevent_key (button, XF86XK_MonBrightnessUp, BUTTON_MON_BRIGHTNESS_UP) )
+ button->priv->mapped_buttons |= BRIGHTNESS_KEY_UP;
- if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN) )
- button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
+ if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN) )
+ button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
- if (xfpm_button_xevent_key (button, XF86XK_Battery, BUTTON_BATTERY))
- button->priv->mapped_buttons |= BATTERY_KEY;
+ if (xfpm_button_xevent_key (button, XF86XK_Battery, BUTTON_BATTERY))
+ button->priv->mapped_buttons |= BATTERY_KEY;
- if ( xfpm_button_xevent_key (button, XF86XK_KbdBrightnessUp, BUTTON_KBD_BRIGHTNESS_UP) )
- button->priv->mapped_buttons |= KBD_BRIGHTNESS_KEY_UP;
+ if ( xfpm_button_xevent_key (button, XF86XK_KbdBrightnessUp, BUTTON_KBD_BRIGHTNESS_UP) )
+ button->priv->mapped_buttons |= KBD_BRIGHTNESS_KEY_UP;
- if (xfpm_button_xevent_key (button, XF86XK_KbdBrightnessDown, BUTTON_KBD_BRIGHTNESS_DOWN) )
- button->priv->mapped_buttons |= KBD_BRIGHTNESS_KEY_DOWN;
+ if (xfpm_button_xevent_key (button, XF86XK_KbdBrightnessDown, BUTTON_KBD_BRIGHTNESS_DOWN) )
+ button->priv->mapped_buttons |= KBD_BRIGHTNESS_KEY_DOWN;
- gdk_window_add_filter (button->priv->window,
- xfpm_button_filter_x_events, button);
+ gdk_window_add_filter (button->priv->window, xfpm_button_filter_x_events, button);
}
static void
xfpm_button_class_init(XfpmButtonClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- signals [BUTTON_PRESSED] =
- g_signal_new ("button-pressed",
- XFPM_TYPE_BUTTON,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (XfpmButtonClass, button_pressed),
- NULL, NULL,
- g_cclosure_marshal_VOID__ENUM,
- G_TYPE_NONE, 1, XFPM_TYPE_BUTTON_KEY);
-
- object_class->finalize = xfpm_button_finalize;
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ signals [BUTTON_PRESSED] =
+ g_signal_new ("button-pressed",
+ XFPM_TYPE_BUTTON,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (XfpmButtonClass, button_pressed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__ENUM,
+ G_TYPE_NONE, 1, XFPM_TYPE_BUTTON_KEY);
+
+ object_class->finalize = xfpm_button_finalize;
}
static void
xfpm_button_init (XfpmButton *button)
{
- button->priv = xfpm_button_get_instance_private (button);
+ button->priv = xfpm_button_get_instance_private (button);
- button->priv->mapped_buttons = 0;
- button->priv->screen = NULL;
- button->priv->window = NULL;
+ button->priv->mapped_buttons = 0;
+ button->priv->screen = NULL;
+ button->priv->window = NULL;
- xfpm_button_setup (button);
+ xfpm_button_setup (button);
}
static void
xfpm_button_finalize (GObject *object)
{
- G_OBJECT_CLASS(xfpm_button_parent_class)->finalize(object);
+ G_OBJECT_CLASS(xfpm_button_parent_class)->finalize(object);
}
XfpmButton *
xfpm_button_new (void)
{
- static gpointer xfpm_button_object = NULL;
-
- if ( G_LIKELY (xfpm_button_object != NULL) )
- {
- g_object_ref (xfpm_button_object);
- }
- else
- {
- xfpm_button_object = g_object_new (XFPM_TYPE_BUTTON, NULL);
- g_object_add_weak_pointer (xfpm_button_object, &xfpm_button_object);
- }
+ static gpointer xfpm_button_object = NULL;
+
+ if ( G_LIKELY (xfpm_button_object != NULL) )
+ {
+ g_object_ref (xfpm_button_object);
+ }
+ else
+ {
+ xfpm_button_object = g_object_new (XFPM_TYPE_BUTTON, NULL);
+ g_object_add_weak_pointer (xfpm_button_object, &xfpm_button_object);
+ }
return XFPM_BUTTON (xfpm_button_object);
}
-guint16 xfpm_button_get_mapped (XfpmButton *button)
+guint16
+xfpm_button_get_mapped (XfpmButton *button)
{
- g_return_val_if_fail (XFPM_IS_BUTTON (button), 0);
+ g_return_val_if_fail (XFPM_IS_BUTTON (button), 0);
- return button->priv->mapped_buttons;
+ return button->priv->mapped_buttons;
}
diff --git a/src/xfpm-button.h b/src/xfpm-button.h
index 9458517..b02409c 100644
--- a/src/xfpm-button.h
+++ b/src/xfpm-button.h
@@ -35,25 +35,20 @@ typedef struct XfpmButtonPrivate XfpmButtonPrivate;
typedef struct
{
- GObject parent;
- XfpmButtonPrivate *priv;
-
+ GObject parent;
+ XfpmButtonPrivate *priv;
} XfpmButton;
typedef struct
{
- GObjectClass parent_class;
-
- void (*button_pressed) (XfpmButton *button,
- XfpmButtonKey type);
-
+ GObjectClass parent_class;
+ void (*button_pressed) (XfpmButton *button,
+ XfpmButtonKey type);
} XfpmButtonClass;
-GType xfpm_button_get_type (void) G_GNUC_CONST;
-
-XfpmButton *xfpm_button_new (void);
-
-guint16 xfpm_button_get_mapped (XfpmButton *button) G_GNUC_PURE;
+GType xfpm_button_get_type (void) G_GNUC_CONST;
+XfpmButton *xfpm_button_new (void);
+guint16 xfpm_button_get_mapped (XfpmButton *button) G_GNUC_PURE;
G_END_DECLS
diff --git a/src/xfpm-console-kit.c b/src/xfpm-console-kit.c
index fc317e6..ed9b157 100644
--- a/src/xfpm-console-kit.c
+++ b/src/xfpm-console-kit.c
@@ -34,33 +34,33 @@
#include "xfpm-dbus-monitor.h"
-static void xfpm_console_kit_finalize (GObject *object);
+static void xfpm_console_kit_finalize (GObject *object);
static void xfpm_console_kit_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
struct XfpmConsoleKitPrivate
{
- GDBusConnection *bus;
- GDBusProxy *proxy;
+ GDBusConnection *bus;
+ GDBusProxy *proxy;
- XfpmDBusMonitor *monitor;
+ XfpmDBusMonitor *monitor;
- gboolean can_shutdown;
- gboolean can_restart;
- gboolean can_suspend;
- gboolean can_hibernate;
+ gboolean can_shutdown;
+ gboolean can_restart;
+ gboolean can_suspend;
+ gboolean can_hibernate;
};
enum
{
- PROP_0,
- PROP_CAN_RESTART,
- PROP_CAN_SHUTDOWN,
- PROP_CAN_SUSPEND,
- PROP_CAN_HIBERNATE
+ PROP_0,
+ PROP_CAN_RESTART,
+ PROP_CAN_SHUTDOWN,
+ PROP_CAN_SUSPEND,
+ PROP_CAN_HIBERNATE
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmConsoleKit, xfpm_console_kit, G_TYPE_OBJECT)
@@ -68,307 +68,307 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmConsoleKit, xfpm_console_kit, G_TYPE_OBJECT)
static void
xfpm_console_kit_get_info (XfpmConsoleKit *console)
{
- GError *error = NULL;
- gchar *tmp = NULL;
- GVariant *var;
-
- var = g_dbus_proxy_call_sync (console->priv->proxy, "CanStop",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if (var)
- {
- g_variant_get (var,
- "(b)",
- &console->priv->can_shutdown);
- g_variant_unref (var);
- }
-
- if ( error )
- {
- g_warning ("'CanStop' method failed : %s", error->message);
- g_clear_error (&error);
- }
-
- var = g_dbus_proxy_call_sync (console->priv->proxy, "CanRestart",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if (var)
- {
- g_variant_get (var,
- "(b)",
- &console->priv->can_restart);
- g_variant_unref (var);
- }
-
- if ( error )
- {
- g_warning ("'CanRestart' method failed : %s", error->message);
- g_clear_error (&error);
- }
-
- /* start with FALSE */
- console->priv->can_suspend = FALSE;
-
- var = g_dbus_proxy_call_sync (console->priv->proxy, "CanSuspend",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if ( error )
+ GError *error = NULL;
+ gchar *tmp = NULL;
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanStop",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ {
+ g_variant_get (var,
+ "(b)",
+ &console->priv->can_shutdown);
+ g_variant_unref (var);
+ }
+
+ if ( error )
+ {
+ g_warning ("'CanStop' method failed : %s", error->message);
+ g_clear_error (&error);
+ }
+
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanRestart",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ {
+ g_variant_get (var,
+ "(b)",
+ &console->priv->can_restart);
+ g_variant_unref (var);
+ }
+
+ if ( error )
+ {
+ g_warning ("'CanRestart' method failed : %s", error->message);
+ g_clear_error (&error);
+ }
+
+ /* start with FALSE */
+ console->priv->can_suspend = FALSE;
+
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanSuspend",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if ( error )
+ {
+ g_debug ("'CanSuspend' method failed : %s", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_variant_get (var,
+ "(&s)",
+ &tmp);
+ if (g_strcmp0 (tmp, "yes") == 0 || g_strcmp0 (tmp, "challenge") == 0)
{
- g_debug ("'CanSuspend' method failed : %s", error->message);
- g_clear_error (&error);
+ console->priv->can_suspend = TRUE;
}
- else
- {
- g_variant_get (var,
- "(&s)",
- &tmp);
- if (g_strcmp0 (tmp, "yes") == 0 || g_strcmp0 (tmp, "challenge") == 0)
- {
- console->priv->can_suspend = TRUE;
- }
- g_variant_unref (var);
- }
-
- /* start with FALSE */
- console->priv->can_hibernate = FALSE;
-
- var = g_dbus_proxy_call_sync (console->priv->proxy, "CanHibernate",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if ( error )
+ g_variant_unref (var);
+ }
+
+ /* start with FALSE */
+ console->priv->can_hibernate = FALSE;
+
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "CanHibernate",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if ( error )
+ {
+ g_debug ("'CanHibernate' method failed : %s", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ g_variant_get (var,
+ "(&s)",
+ &tmp);
+ if (g_strcmp0 (tmp, "yes") == 0 || g_strcmp0 (tmp, "challenge") == 0)
{
- g_debug ("'CanHibernate' method failed : %s", error->message);
- g_clear_error (&error);
- }
- else
- {
- g_variant_get (var,
- "(&s)",
- &tmp);
- if (g_strcmp0 (tmp, "yes") == 0 || g_strcmp0 (tmp, "challenge") == 0)
- {
- console->priv->can_hibernate = TRUE;
- }
- g_variant_unref (var);
+ console->priv->can_hibernate = TRUE;
}
+ g_variant_unref (var);
+ }
}
static void
xfpm_console_kit_class_init (XfpmConsoleKitClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = xfpm_console_kit_finalize;
-
- object_class->get_property = xfpm_console_kit_get_property;
-
- g_object_class_install_property (object_class,
- PROP_CAN_RESTART,
- g_param_spec_boolean ("can-restart",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_SHUTDOWN,
- g_param_spec_boolean ("can-shutdown",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_SUSPEND,
- g_param_spec_boolean ("can-suspend",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_HIBERNATE,
- g_param_spec_boolean ("can-hibernate",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = xfpm_console_kit_finalize;
+
+ object_class->get_property = xfpm_console_kit_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_CAN_RESTART,
+ g_param_spec_boolean ("can-restart",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_CAN_SHUTDOWN,
+ g_param_spec_boolean ("can-shutdown",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_CAN_SUSPEND,
+ g_param_spec_boolean ("can-suspend",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_CAN_HIBERNATE,
+ g_param_spec_boolean ("can-hibernate",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
}
static void
xfpm_console_kit_init (XfpmConsoleKit *console)
{
- GError *error = NULL;
-
- console->priv = xfpm_console_kit_get_instance_private (console);
- console->priv->can_shutdown = FALSE;
- console->priv->can_restart = FALSE;
-
- console->priv->bus = NULL;
- console->priv->proxy = NULL;
-
- console->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
-
- if ( error )
- {
- g_critical ("Unable to get system bus connection : %s", error->message);
- g_error_free (error);
- return;
- }
-
- console->priv->proxy = g_dbus_proxy_new_sync (console->priv->bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- NULL,
- "org.freedesktop.ConsoleKit",
- "/org/freedesktop/ConsoleKit/Manager",
- "org.freedesktop.ConsoleKit.Manager",
- NULL,
- NULL);
-
- if ( !console->priv->proxy )
- {
- g_warning ("Unable to create proxy for 'org.freedesktop.ConsoleKit'");
- return;
- }
-
- xfpm_console_kit_get_info (console);
+ GError *error = NULL;
+
+ console->priv = xfpm_console_kit_get_instance_private (console);
+ console->priv->can_shutdown = FALSE;
+ console->priv->can_restart = FALSE;
+
+ console->priv->bus = NULL;
+ console->priv->proxy = NULL;
+
+ console->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+
+ if ( error )
+ {
+ g_critical ("Unable to get system bus connection : %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ console->priv->proxy = g_dbus_proxy_new_sync (console->priv->bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.ConsoleKit",
+ "/org/freedesktop/ConsoleKit/Manager",
+ "org.freedesktop.ConsoleKit.Manager",
+ NULL,
+ NULL);
+
+ if ( !console->priv->proxy )
+ {
+ g_warning ("Unable to create proxy for 'org.freedesktop.ConsoleKit'");
+ return;
+ }
+
+ xfpm_console_kit_get_info (console);
}
static void xfpm_console_kit_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- XfpmConsoleKit *console;
- console = XFPM_CONSOLE_KIT (object);
-
- switch (prop_id)
- {
- case PROP_CAN_SHUTDOWN:
- g_value_set_boolean (value, console->priv->can_shutdown);
- break;
- case PROP_CAN_RESTART:
- g_value_set_boolean (value, console->priv->can_restart);
- break;
- case PROP_CAN_SUSPEND:
- g_value_set_boolean (value, console->priv->can_suspend);
- break;
- case PROP_CAN_HIBERNATE:
- g_value_set_boolean (value, console->priv->can_hibernate);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ XfpmConsoleKit *console;
+ console = XFPM_CONSOLE_KIT (object);
+
+ switch (prop_id)
+ {
+ case PROP_CAN_SHUTDOWN:
+ g_value_set_boolean (value, console->priv->can_shutdown);
+ break;
+ case PROP_CAN_RESTART:
+ g_value_set_boolean (value, console->priv->can_restart);
+ break;
+ case PROP_CAN_SUSPEND:
+ g_value_set_boolean (value, console->priv->can_suspend);
+ break;
+ case PROP_CAN_HIBERNATE:
+ g_value_set_boolean (value, console->priv->can_hibernate);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
xfpm_console_kit_finalize (GObject *object)
{
- XfpmConsoleKit *console;
+ XfpmConsoleKit *console;
- console = XFPM_CONSOLE_KIT (object);
+ console = XFPM_CONSOLE_KIT (object);
- if ( console->priv->bus )
- g_object_unref (console->priv->bus);
+ if ( console->priv->bus )
+ g_object_unref (console->priv->bus);
- if ( console->priv->proxy )
- g_object_unref (console->priv->proxy);
+ if ( console->priv->proxy )
+ g_object_unref (console->priv->proxy);
- G_OBJECT_CLASS (xfpm_console_kit_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_console_kit_parent_class)->finalize (object);
}
XfpmConsoleKit *
xfpm_console_kit_new (void)
{
- static gpointer console_obj = NULL;
-
- if ( G_LIKELY (console_obj != NULL ) )
- {
- g_object_ref (console_obj);
- }
- else
- {
- console_obj = g_object_new (XFPM_TYPE_CONSOLE_KIT, NULL);
- g_object_add_weak_pointer (console_obj, &console_obj);
- }
-
- return XFPM_CONSOLE_KIT (console_obj);
+ static gpointer console_obj = NULL;
+
+ if ( G_LIKELY (console_obj != NULL ) )
+ {
+ g_object_ref (console_obj);
+ }
+ else
+ {
+ console_obj = g_object_new (XFPM_TYPE_CONSOLE_KIT, NULL);
+ g_object_add_weak_pointer (console_obj, &console_obj);
+ }
+
+ return XFPM_CONSOLE_KIT (console_obj);
}
void xfpm_console_kit_shutdown (XfpmConsoleKit *console, GError **error)
{
- GVariant *var;
+ GVariant *var;
- g_return_if_fail (console->priv->proxy != NULL );
+ g_return_if_fail (console->priv->proxy != NULL );
- var = g_dbus_proxy_call_sync (console->priv->proxy, "Stop",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- error);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Stop",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
- if (var)
- g_variant_unref (var);
+ if (var)
+ g_variant_unref (var);
}
void xfpm_console_kit_reboot (XfpmConsoleKit *console, GError **error)
{
- GVariant *var;
+ GVariant *var;
- g_return_if_fail (console->priv->proxy != NULL );
+ g_return_if_fail (console->priv->proxy != NULL );
- var = g_dbus_proxy_call_sync (console->priv->proxy, "Restart",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- error);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Restart",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
- if (var)
- g_variant_unref (var);
+ if (var)
+ g_variant_unref (var);
}
void
xfpm_console_kit_suspend (XfpmConsoleKit *console,
GError **error)
{
- GVariant *var;
+ GVariant *var;
- g_return_if_fail (console->priv->proxy != NULL );
+ g_return_if_fail (console->priv->proxy != NULL );
- var = g_dbus_proxy_call_sync (console->priv->proxy, "Suspend",
- g_variant_new ("(b)", TRUE),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- error);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Suspend",
+ g_variant_new ("(b)", TRUE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
- if (var)
- g_variant_unref (var);
+ if (var)
+ g_variant_unref (var);
}
void
xfpm_console_kit_hibernate (XfpmConsoleKit *console,
GError **error)
{
- GVariant *var;
+ GVariant *var;
- g_return_if_fail (console->priv->proxy != NULL );
+ g_return_if_fail (console->priv->proxy != NULL );
- var = g_dbus_proxy_call_sync (console->priv->proxy, "Hibernate",
- g_variant_new ("(b)", TRUE),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- error);
+ var = g_dbus_proxy_call_sync (console->priv->proxy, "Hibernate",
+ g_variant_new ("(b)", TRUE),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ error);
- if (var)
- g_variant_unref (var);
+ if (var)
+ g_variant_unref (var);
}
diff --git a/src/xfpm-console-kit.h b/src/xfpm-console-kit.h
index b4910ae..63c6df8 100644
--- a/src/xfpm-console-kit.h
+++ b/src/xfpm-console-kit.h
@@ -33,32 +33,25 @@ typedef struct XfpmConsoleKitPrivate XfpmConsoleKitPrivate;
typedef struct
{
- GObject parent;
- XfpmConsoleKitPrivate *priv;
-
+ GObject parent;
+ XfpmConsoleKitPrivate *priv;
} XfpmConsoleKit;
typedef struct
{
- GObjectClass parent_class;
-
+ GObjectClass parent_class;
} XfpmConsoleKitClass;
-GType xfpm_console_kit_get_type (void) G_GNUC_CONST;
-
-XfpmConsoleKit *xfpm_console_kit_new (void);
-
-void xfpm_console_kit_shutdown (XfpmConsoleKit *console,
- GError **error);
-
-void xfpm_console_kit_reboot (XfpmConsoleKit *console,
- GError **error);
-
-void xfpm_console_kit_suspend (XfpmConsoleKit *console,
- GError **error);
-
-void xfpm_console_kit_hibernate (XfpmConsoleKit *console,
- GError **error);
+GType xfpm_console_kit_get_type (void) G_GNUC_CONST;
+XfpmConsoleKit *xfpm_console_kit_new (void);
+void xfpm_console_kit_shutdown (XfpmConsoleKit *console,
+ GError **error);
+void xfpm_console_kit_reboot (XfpmConsoleKit *console,
+ GError **error);
+void xfpm_console_kit_suspend (XfpmConsoleKit *console,
+ GError **error);
+void xfpm_console_kit_hibernate (XfpmConsoleKit *console,
+ GError **error);
G_END_DECLS
diff --git a/src/xfpm-dpms.c b/src/xfpm-dpms.c
index 2e3b72b..9b2efa9 100644
--- a/src/xfpm-dpms.c
+++ b/src/xfpm-dpms.c
@@ -47,15 +47,15 @@ static void xfpm_dpms_finalize (GObject *object);
struct XfpmDpmsPrivate
{
- XfpmXfconf *conf;
+ XfpmXfconf *conf;
- gboolean dpms_capable;
- gboolean inhibited;
+ gboolean dpms_capable;
+ gboolean inhibited;
- gboolean on_battery;
+ gboolean on_battery;
- gulong switch_off_timeout_id;
- gulong switch_on_timeout_id;
+ gulong switch_off_timeout_id;
+ gulong switch_on_timeout_id;
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmDpms, xfpm_dpms, G_TYPE_OBJECT)
@@ -63,17 +63,17 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmDpms, xfpm_dpms, G_TYPE_OBJECT)
static void
xfpm_dpms_set_timeouts (XfpmDpms *dpms, guint16 standby, guint16 suspend, guint off)
{
- CARD16 x_standby = 0 , x_suspend = 0, x_off = 0;
+ CARD16 x_standby = 0 , x_suspend = 0, x_off = 0;
- DPMSGetTimeouts (gdk_x11_get_default_xdisplay(), &x_standby, &x_suspend, &x_off);
+ DPMSGetTimeouts (gdk_x11_get_default_xdisplay(), &x_standby, &x_suspend, &x_off);
- if ( standby != x_standby || suspend != x_suspend || off != x_off )
- {
- XFPM_DEBUG ("Settings dpms: standby=%d suspend=%d off=%d\n", standby, suspend, off);
- DPMSSetTimeouts (gdk_x11_get_default_xdisplay(), standby,
- suspend,
- off );
- }
+ if ( standby != x_standby || suspend != x_suspend || off != x_off )
+ {
+ XFPM_DEBUG ("Settings dpms: standby=%d suspend=%d off=%d\n", standby, suspend, off);
+ DPMSSetTimeouts (gdk_x11_get_default_xdisplay(), standby,
+ suspend,
+ off );
+ }
}
/*
@@ -82,14 +82,14 @@ xfpm_dpms_set_timeouts (XfpmDpms *dpms, guint16 standby, guint16 suspend, guint
static void
xfpm_dpms_disable (XfpmDpms *dpms)
{
- BOOL state;
- CARD16 power_level;
+ BOOL state;
+ CARD16 power_level;
- if (!DPMSInfo (gdk_x11_get_default_xdisplay(), &power_level, &state) )
- g_warning ("Cannot get DPMSInfo");
+ if (!DPMSInfo (gdk_x11_get_default_xdisplay(), &power_level, &state) )
+ g_warning ("Cannot get DPMSInfo");
- if ( state )
- DPMSDisable (gdk_x11_get_default_xdisplay());
+ if ( state )
+ DPMSDisable (gdk_x11_get_default_xdisplay());
}
/*
@@ -98,113 +98,113 @@ xfpm_dpms_disable (XfpmDpms *dpms)
static void
xfpm_dpms_enable (XfpmDpms *dpms)
{
- BOOL state;
- CARD16 power_level;
+ BOOL state;
+ CARD16 power_level;
- if (!DPMSInfo (gdk_x11_get_default_xdisplay(), &power_level, &state) )
- g_warning ("Cannot get DPMSInfo");
+ if (!DPMSInfo (gdk_x11_get_default_xdisplay(), &power_level, &state) )
+ g_warning ("Cannot get DPMSInfo");
- if ( !state )
- DPMSEnable (gdk_x11_get_default_xdisplay());
+ if ( !state )
+ DPMSEnable (gdk_x11_get_default_xdisplay());
}
static void
xfpm_dpms_get_enabled (XfpmDpms *dpms, gboolean *dpms_enabled)
{
- g_object_get (G_OBJECT (dpms->priv->conf),
- DPMS_ENABLED_CFG, dpms_enabled,
- NULL);
+ g_object_get (G_OBJECT (dpms->priv->conf),
+ DPMS_ENABLED_CFG, dpms_enabled,
+ NULL);
}
static void
xfpm_dpms_get_sleep_mode (XfpmDpms *dpms, gboolean *ret_standby_mode)
{
- gchar *sleep_mode;
+ gchar *sleep_mode;
- g_object_get (G_OBJECT (dpms->priv->conf),
- DPMS_SLEEP_MODE, &sleep_mode,
- NULL);
+ g_object_get (G_OBJECT (dpms->priv->conf),
+ DPMS_SLEEP_MODE, &sleep_mode,
+ NULL);
- if ( !g_strcmp0 (sleep_mode, "Standby"))
- *ret_standby_mode = TRUE;
- else
- *ret_standby_mode = FALSE;
+ if ( !g_strcmp0 (sleep_mode, "Standby"))
+ *ret_standby_mode = TRUE;
+ else
+ *ret_standby_mode = FALSE;
- g_free (sleep_mode);
+ g_free (sleep_mode);
}
static void
xfpm_dpms_get_configuration_timeouts (XfpmDpms *dpms, guint16 *ret_sleep, guint16 *ret_off )
{
- guint sleep_time, off_time;
+ guint sleep_time, off_time;
- g_object_get (G_OBJECT (dpms->priv->conf),
- dpms->priv->on_battery ? ON_BATT_DPMS_SLEEP : ON_AC_DPMS_SLEEP, &sleep_time,
- dpms->priv->on_battery ? ON_BATT_DPMS_OFF : ON_AC_DPMS_OFF, &off_time,
- NULL);
+ g_object_get (G_OBJECT (dpms->priv->conf),
+ dpms->priv->on_battery ? ON_BATT_DPMS_SLEEP : ON_AC_DPMS_SLEEP, &sleep_time,
+ dpms->priv->on_battery ? ON_BATT_DPMS_OFF : ON_AC_DPMS_OFF, &off_time,
+ NULL);
- *ret_sleep = sleep_time * 60;
- *ret_off = off_time * 60;
+ *ret_sleep = sleep_time * 60;
+ *ret_off = off_time * 60;
}
void
xfpm_dpms_refresh (XfpmDpms *dpms)
{
- gboolean enabled;
- guint16 off_timeout;
- guint16 sleep_timeout;
- gboolean sleep_mode;
-
- if ( dpms->priv->inhibited)
- {
- xfpm_dpms_disable (dpms);
- return;
- }
-
- xfpm_dpms_get_enabled (dpms, &enabled);
-
- if ( !enabled )
- {
- xfpm_dpms_disable (dpms);
- return;
- }
-
- xfpm_dpms_enable (dpms);
- xfpm_dpms_get_configuration_timeouts (dpms, &sleep_timeout, &off_timeout);
- xfpm_dpms_get_sleep_mode (dpms, &sleep_mode);
-
- if (sleep_mode == TRUE )
- {
- xfpm_dpms_set_timeouts (dpms,
- sleep_timeout,
- 0,
- off_timeout);
- }
- else
- {
- xfpm_dpms_set_timeouts (dpms,
- 0,
- sleep_timeout,
- off_timeout );
- }
+ gboolean enabled;
+ guint16 off_timeout;
+ guint16 sleep_timeout;
+ gboolean sleep_mode;
+
+ if ( dpms->priv->inhibited)
+ {
+ xfpm_dpms_disable (dpms);
+ return;
+ }
+
+ xfpm_dpms_get_enabled (dpms, &enabled);
+
+ if ( !enabled )
+ {
+ xfpm_dpms_disable (dpms);
+ return;
+ }
+
+ xfpm_dpms_enable (dpms);
+ xfpm_dpms_get_configuration_timeouts (dpms, &sleep_timeout, &off_timeout);
+ xfpm_dpms_get_sleep_mode (dpms, &sleep_mode);
+
+ if (sleep_mode == TRUE )
+ {
+ xfpm_dpms_set_timeouts (dpms,
+ sleep_timeout,
+ 0,
+ off_timeout);
+ }
+ else
+ {
+ xfpm_dpms_set_timeouts (dpms,
+ 0,
+ sleep_timeout,
+ off_timeout );
+ }
}
static void
xfpm_dpms_settings_changed_cb (GObject *obj, GParamSpec *spec, XfpmDpms *dpms)
{
- if ( g_str_has_prefix (spec->name, "dpms"))
- {
- XFPM_DEBUG ("Configuration changed");
- xfpm_dpms_refresh (dpms);
- }
+ if ( g_str_has_prefix (spec->name, "dpms"))
+ {
+ XFPM_DEBUG ("Configuration changed");
+ xfpm_dpms_refresh (dpms);
+ }
}
static void
xfpm_dpms_class_init(XfpmDpmsClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
- object_class->finalize = xfpm_dpms_finalize;
+ object_class->finalize = xfpm_dpms_finalize;
}
/*
@@ -213,132 +213,136 @@ xfpm_dpms_class_init(XfpmDpmsClass *klass)
static void
xfpm_dpms_init(XfpmDpms *dpms)
{
- dpms->priv = xfpm_dpms_get_instance_private(dpms);
+ dpms->priv = xfpm_dpms_get_instance_private(dpms);
- dpms->priv->dpms_capable = DPMSCapable (gdk_x11_get_default_xdisplay());
- dpms->priv->switch_off_timeout_id = 0;
- dpms->priv->switch_on_timeout_id = 0;
+ dpms->priv->dpms_capable = DPMSCapable (gdk_x11_get_default_xdisplay());
+ dpms->priv->switch_off_timeout_id = 0;
+ dpms->priv->switch_on_timeout_id = 0;
- if ( dpms->priv->dpms_capable )
- {
- dpms->priv->conf = xfpm_xfconf_new ();
+ if ( dpms->priv->dpms_capable )
+ {
+ dpms->priv->conf = xfpm_xfconf_new ();
- g_signal_connect (dpms->priv->conf, "notify",
- G_CALLBACK (xfpm_dpms_settings_changed_cb), dpms);
+ g_signal_connect (dpms->priv->conf, "notify",
+ G_CALLBACK (xfpm_dpms_settings_changed_cb), dpms);
- xfpm_dpms_refresh (dpms);
- }
- else
- {
- g_warning ("Monitor is not DPMS capable");
- }
+ xfpm_dpms_refresh (dpms);
+ }
+ else
+ {
+ g_warning ("Monitor is not DPMS capable");
+ }
}
static void
xfpm_dpms_finalize(GObject *object)
{
- XfpmDpms *dpms;
+ XfpmDpms *dpms;
- dpms = XFPM_DPMS (object);
+ dpms = XFPM_DPMS (object);
- g_object_unref (dpms->priv->conf);
+ g_object_unref (dpms->priv->conf);
- G_OBJECT_CLASS(xfpm_dpms_parent_class)->finalize(object);
+ G_OBJECT_CLASS(xfpm_dpms_parent_class)->finalize(object);
}
XfpmDpms *
xfpm_dpms_new (void)
{
- static gpointer xfpm_dpms_object = NULL;
-
- if ( G_LIKELY (xfpm_dpms_object != NULL ) )
- {
- g_object_ref (xfpm_dpms_object);
- }
- else
- {
- xfpm_dpms_object = g_object_new (XFPM_TYPE_DPMS, NULL);
- g_object_add_weak_pointer (xfpm_dpms_object, &xfpm_dpms_object);
- }
-
- return XFPM_DPMS (xfpm_dpms_object);
+ static gpointer xfpm_dpms_object = NULL;
+
+ if ( G_LIKELY (xfpm_dpms_object != NULL ) )
+ {
+ g_object_ref (xfpm_dpms_object);
+ }
+ else
+ {
+ xfpm_dpms_object = g_object_new (XFPM_TYPE_DPMS, NULL);
+ g_object_add_weak_pointer (xfpm_dpms_object, &xfpm_dpms_object);
+ }
+
+ return XFPM_DPMS (xfpm_dpms_object);
}
-gboolean xfpm_dpms_capable (XfpmDpms *dpms)
+gboolean
+xfpm_dpms_capable (XfpmDpms *dpms)
{
- g_return_val_if_fail (XFPM_IS_DPMS(dpms), FALSE);
+ g_return_val_if_fail (XFPM_IS_DPMS(dpms), FALSE);
- return dpms->priv->dpms_capable;
+ return dpms->priv->dpms_capable;
}
-void xfpm_dpms_force_level (XfpmDpms *dpms, CARD16 level)
+void
+xfpm_dpms_force_level (XfpmDpms *dpms, CARD16 level)
{
- CARD16 current_level;
- BOOL current_state;
+ CARD16 current_level;
+ BOOL current_state;
- XFPM_DEBUG ("start");
+ XFPM_DEBUG ("start");
- if ( !dpms->priv->dpms_capable )
- goto out;
+ if ( !dpms->priv->dpms_capable )
+ goto out;
- if ( G_UNLIKELY (!DPMSInfo (gdk_x11_get_default_xdisplay (), ¤t_level, ¤t_state)) )
- {
- g_warning ("Cannot get DPMSInfo");
- goto out;
- }
+ if ( G_UNLIKELY (!DPMSInfo (gdk_x11_get_default_xdisplay (), ¤t_level, ¤t_state)) )
+ {
+ g_warning ("Cannot get DPMSInfo");
+ goto out;
+ }
- if ( !current_state )
- {
- XFPM_DEBUG ("DPMS is disabled");
- goto out;
- }
+ if ( !current_state )
+ {
+ XFPM_DEBUG ("DPMS is disabled");
+ goto out;
+ }
- if ( current_level != level )
- {
- XFPM_DEBUG ("Forcing DPMS mode %d", level);
-
- if ( !DPMSForceLevel (gdk_x11_get_default_xdisplay (), level ) )
- {
- g_warning ("Cannot set Force DPMS level %d", level);
- goto out;
- }
- if ( level == DPMSModeOn )
- XResetScreenSaver (gdk_x11_get_default_xdisplay ());
- XSync (gdk_x11_get_default_xdisplay (), FALSE);
- }
- else
+ if ( current_level != level )
+ {
+ XFPM_DEBUG ("Forcing DPMS mode %d", level);
+
+ if ( !DPMSForceLevel (gdk_x11_get_default_xdisplay (), level ) )
{
- XFPM_DEBUG ("No need to change DPMS mode, current_level=%d requested_level=%d", current_level, level);
+ g_warning ("Cannot set Force DPMS level %d", level);
+ goto out;
}
- out:
- ;
+ if ( level == DPMSModeOn )
+ XResetScreenSaver (gdk_x11_get_default_xdisplay ());
+
+ XSync (gdk_x11_get_default_xdisplay (), FALSE);
+ }
+ else
+ {
+ XFPM_DEBUG ("No need to change DPMS mode, current_level=%d requested_level=%d", current_level, level);
+ }
+
+ out:
+ ;
}
gboolean
xfpm_dpms_is_inhibited (XfpmDpms *dpms)
{
- return dpms->priv->inhibited;
+ return dpms->priv->inhibited;
}
void
xfpm_dpms_inhibit (XfpmDpms *dpms, gboolean inhibit)
{
- if ( dpms->priv->inhibited == inhibit )
- return;
+ if ( dpms->priv->inhibited == inhibit )
+ return;
- dpms->priv->inhibited = inhibit;
- xfpm_dpms_refresh (dpms);
- XFPM_DEBUG ("dpms inhibited %s", inhibit ? "TRUE" : "FALSE");
+ dpms->priv->inhibited = inhibit;
+ xfpm_dpms_refresh (dpms);
+ XFPM_DEBUG ("dpms inhibited %s", inhibit ? "TRUE" : "FALSE");
}
void
xfpm_dpms_set_on_battery (XfpmDpms *dpms, gboolean on_battery)
{
- if ( dpms->priv->on_battery == on_battery )
- return;
+ if ( dpms->priv->on_battery == on_battery )
+ return;
- dpms->priv->on_battery = on_battery;
- xfpm_dpms_refresh (dpms);
- XFPM_DEBUG ("dpms on battery %s", on_battery ? "TRUE" : "FALSE");
+ dpms->priv->on_battery = on_battery;
+ xfpm_dpms_refresh (dpms);
+ XFPM_DEBUG ("dpms on battery %s", on_battery ? "TRUE" : "FALSE");
}
diff --git a/src/xfpm-dpms.h b/src/xfpm-dpms.h
index 5fa0085..f8f8116 100644
--- a/src/xfpm-dpms.h
+++ b/src/xfpm-dpms.h
@@ -43,32 +43,23 @@ typedef struct XfpmDpmsPrivate XfpmDpmsPrivate;
typedef struct
{
- GObject parent;
- XfpmDpmsPrivate *priv;
-
+ GObject parent;
+ XfpmDpmsPrivate *priv;
} XfpmDpms;
typedef struct
{
- GObjectClass parent_class;
-
+ GObjectClass parent_class;
} XfpmDpmsClass;
GType xfpm_dpms_get_type (void) G_GNUC_CONST;
-
XfpmDpms *xfpm_dpms_new (void);
-
gboolean xfpm_dpms_capable (XfpmDpms *dpms) G_GNUC_PURE;
-
-void xfpm_dpms_force_level (XfpmDpms *dpms, CARD16 level);
-
-void xfpm_dpms_refresh (XfpmDpms *dpms);
-
-void xfpm_dpms_inhibit (XfpmDpms *dpms, gboolean inhibit);
-
-gboolean xfpm_dpms_is_inhibited (XfpmDpms *dpms);
-
-void xfpm_dpms_set_on_battery (XfpmDpms *dpms, gboolean on_battery);
+void xfpm_dpms_force_level (XfpmDpms *dpms, CARD16 level);
+void xfpm_dpms_refresh (XfpmDpms *dpms);
+void xfpm_dpms_inhibit (XfpmDpms *dpms, gboolean inhibit);
+gboolean xfpm_dpms_is_inhibited (XfpmDpms *dpms);
+void xfpm_dpms_set_on_battery (XfpmDpms *dpms, gboolean on_battery);
G_END_DECLS
diff --git a/src/xfpm-errors.c b/src/xfpm-errors.c
index aed55ee..5701946 100644
--- a/src/xfpm-errors.c
+++ b/src/xfpm-errors.c
@@ -29,24 +29,24 @@
GQuark
xfpm_get_error_quark (void)
{
- static volatile gsize xfpm_error_quark = 0;
- if (xfpm_error_quark == 0)
+ static volatile gsize xfpm_error_quark = 0;
+ if (xfpm_error_quark == 0)
+ {
+ static const GDBusErrorEntry values[] =
{
- static const GDBusErrorEntry values[] =
- {
- { XFPM_ERROR_UNKNOWN, "org.xfce.PowerManager.Error.Unknown" },
- { XFPM_ERROR_PERMISSION_DENIED, "org.xfce.PowerManager.Error.PermissionDenied" },
- { XFPM_ERROR_NO_HARDWARE_SUPPORT, "org.xfce.PowerManager.Error.NoHardwareSupport" },
- { XFPM_ERROR_COOKIE_NOT_FOUND, "org.xfce.PowerManager.Error.CookieNotFound" },
- { XFPM_ERROR_INVALID_ARGUMENTS, "org.xfce.PowerManager.Error.InvalidArguments" },
- { XFPM_ERROR_SLEEP_FAILED, "org.xfce.PowerManager.Error.SleepFailed" },
- };
+ { XFPM_ERROR_UNKNOWN, "org.xfce.PowerManager.Error.Unknown" },
+ { XFPM_ERROR_PERMISSION_DENIED, "org.xfce.PowerManager.Error.PermissionDenied" },
+ { XFPM_ERROR_NO_HARDWARE_SUPPORT, "org.xfce.PowerManager.Error.NoHardwareSupport" },
+ { XFPM_ERROR_COOKIE_NOT_FOUND, "org.xfce.PowerManager.Error.CookieNotFound" },
+ { XFPM_ERROR_INVALID_ARGUMENTS, "org.xfce.PowerManager.Error.InvalidArguments" },
+ { XFPM_ERROR_SLEEP_FAILED, "org.xfce.PowerManager.Error.SleepFailed" },
+ };
- g_dbus_error_register_error_domain ("xfpm-error-quark",
- &xfpm_error_quark,
- values,
- G_N_ELEMENTS (values));
- }
+ g_dbus_error_register_error_domain ("xfpm-error-quark",
+ &xfpm_error_quark,
+ values,
+ G_N_ELEMENTS (values));
+ }
- return (GQuark) xfpm_error_quark;
+ return (GQuark) xfpm_error_quark;
}
diff --git a/src/xfpm-errors.h b/src/xfpm-errors.h
index 8485936..7baf3d7 100644
--- a/src/xfpm-errors.h
+++ b/src/xfpm-errors.h
@@ -30,12 +30,12 @@ G_BEGIN_DECLS
typedef enum
{
- XFPM_ERROR_UNKNOWN = 0,
- XFPM_ERROR_PERMISSION_DENIED,
- XFPM_ERROR_NO_HARDWARE_SUPPORT,
- XFPM_ERROR_COOKIE_NOT_FOUND,
- XFPM_ERROR_INVALID_ARGUMENTS,
- XFPM_ERROR_SLEEP_FAILED
+ XFPM_ERROR_UNKNOWN = 0,
+ XFPM_ERROR_PERMISSION_DENIED,
+ XFPM_ERROR_NO_HARDWARE_SUPPORT,
+ XFPM_ERROR_COOKIE_NOT_FOUND,
+ XFPM_ERROR_INVALID_ARGUMENTS,
+ XFPM_ERROR_SLEEP_FAILED
} XfpmError;
diff --git a/src/xfpm-inhibit.c b/src/xfpm-inhibit.c
index 4a66332..1514119 100644
--- a/src/xfpm-inhibit.c
+++ b/src/xfpm-inhibit.c
@@ -39,31 +39,29 @@
#include "xfpm-errors.h"
#include "xfpm-debug.h"
-static void xfpm_inhibit_finalize (GObject *object);
-
+static void xfpm_inhibit_finalize (GObject *object);
static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass);
-static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit);
+static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit);
struct XfpmInhibitPrivate
{
- XfpmDBusMonitor *monitor;
- GPtrArray *array;
- gboolean inhibited;
+ XfpmDBusMonitor *monitor;
+ GPtrArray *array;
+ gboolean inhibited;
};
typedef struct
{
- gchar *app_name;
- gchar *unique_name;
- guint cookie;
-
+ gchar *app_name;
+ gchar *unique_name;
+ guint cookie;
} Inhibitor;
enum
{
- HAS_INHIBIT_CHANGED,
- INHIBIT_LIST_CHANGED,
- LAST_SIGNAL
+ HAS_INHIBIT_CHANGED,
+ INHIBIT_LIST_CHANGED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
@@ -73,218 +71,221 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmInhibit, xfpm_inhibit, G_TYPE_OBJECT)
static void
xfpm_inhibit_free_inhibitor (XfpmInhibit *inhibit, Inhibitor *inhibitor)
{
- g_return_if_fail (inhibitor != NULL );
+ g_return_if_fail (inhibitor != NULL );
- g_ptr_array_remove (inhibit->priv->array, inhibitor);
+ g_ptr_array_remove (inhibit->priv->array, inhibitor);
- g_free (inhibitor->app_name);
- g_free (inhibitor->unique_name);
- g_free (inhibitor);
+ g_free (inhibitor->app_name);
+ g_free (inhibitor->unique_name);
+ g_free (inhibitor);
}
static gboolean
xfpm_inhibit_has_inhibit_changed (XfpmInhibit *inhibit)
{
- if ( inhibit->priv->array->len == 0 && inhibit->priv->inhibited == TRUE )
- {
- XFPM_DEBUG("Inhibit removed");
- inhibit->priv->inhibited = FALSE;
- g_signal_emit (G_OBJECT(inhibit), signals[HAS_INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
- }
- else if ( inhibit->priv->array->len != 0 && inhibit->priv->inhibited == FALSE )
- {
- XFPM_DEBUG("Inhibit added");
- inhibit->priv->inhibited = TRUE;
- g_signal_emit (G_OBJECT(inhibit), signals[HAS_INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
- }
-
- /* Always emite the INHIBIT_LIST_CHANGED for any change so the panel plugin
- * stays in sync */
- g_signal_emit (G_OBJECT(inhibit), signals[INHIBIT_LIST_CHANGED], 0, inhibit->priv->inhibited);
-
- return inhibit->priv->inhibited;
+ if ( inhibit->priv->array->len == 0 && inhibit->priv->inhibited == TRUE )
+ {
+ XFPM_DEBUG("Inhibit removed");
+ inhibit->priv->inhibited = FALSE;
+ g_signal_emit (G_OBJECT(inhibit), signals[HAS_INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
+ }
+ else if ( inhibit->priv->array->len != 0 && inhibit->priv->inhibited == FALSE )
+ {
+ XFPM_DEBUG("Inhibit added");
+ inhibit->priv->inhibited = TRUE;
+ g_signal_emit (G_OBJECT(inhibit), signals[HAS_INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
+ }
+
+ /* Always emite the INHIBIT_LIST_CHANGED for any change so the panel plugin
+ * stays in sync */
+ g_signal_emit (G_OBJECT(inhibit), signals[INHIBIT_LIST_CHANGED], 0, inhibit->priv->inhibited);
+
+ return inhibit->priv->inhibited;
}
static guint
xfpm_inhibit_get_cookie (XfpmInhibit *inhibit)
{
- guint max = 0;
- guint i;
- Inhibitor *inhibitor;
+ guint max = 0;
+ guint i;
+ Inhibitor *inhibitor;
- for ( i = 0; i<inhibit->priv->array->len; i++)
- {
- inhibitor = g_ptr_array_index (inhibit->priv->array, i);
- max = MAX (max, inhibitor->cookie);
- }
- return (guint) g_random_int_range ( max + 1, max + 40);
+ for ( i = 0; i<inhibit->priv->array->len; i++)
+ {
+ inhibitor = g_ptr_array_index (inhibit->priv->array, i);
+ max = MAX (max, inhibitor->cookie);
+ }
+
+ return (guint) g_random_int_range ( max + 1, max + 40);
}
static guint
xfpm_inhibit_add_application (XfpmInhibit *inhibit, const gchar *app_name, const gchar *unique_name)
{
- guint cookie;
- Inhibitor *inhibitor;
+ guint cookie;
+ Inhibitor *inhibitor;
- inhibitor = g_new0 (Inhibitor, 1);
+ inhibitor = g_new0 (Inhibitor, 1);
- cookie = xfpm_inhibit_get_cookie (inhibit);
+ cookie = xfpm_inhibit_get_cookie (inhibit);
- inhibitor->cookie = cookie;
- inhibitor->app_name = g_strdup (app_name);
- inhibitor->unique_name = g_strdup (unique_name);
+ inhibitor->cookie = cookie;
+ inhibitor->app_name = g_strdup (app_name);
+ inhibitor->unique_name = g_strdup (unique_name);
- g_ptr_array_add (inhibit->priv->array, inhibitor);
+ g_ptr_array_add (inhibit->priv->array, inhibitor);
- return cookie;
+ return cookie;
}
static Inhibitor *
xfpm_inhibit_find_application_by_cookie (XfpmInhibit *inhibit, guint cookie)
{
- guint i;
- Inhibitor *inhibitor;
- for ( i = 0; i < inhibit->priv->array->len; i++)
+ guint i;
+ Inhibitor *inhibitor;
+ for ( i = 0; i < inhibit->priv->array->len; i++)
+ {
+ inhibitor = g_ptr_array_index (inhibit->priv->array, i);
+ if ( inhibitor->cookie == cookie )
{
- inhibitor = g_ptr_array_index (inhibit->priv->array, i);
- if ( inhibitor->cookie == cookie )
- {
- return inhibitor;
- }
+ return inhibitor;
}
- return NULL;
+ }
+
+ return NULL;
}
static Inhibitor *
xfpm_inhibit_find_application_by_unique_connection_name (XfpmInhibit *inhibit, const gchar *unique_name)
{
- guint i;
- Inhibitor *inhibitor;
- for ( i = 0; i < inhibit->priv->array->len; i++)
+ guint i;
+ Inhibitor *inhibitor;
+ for ( i = 0; i < inhibit->priv->array->len; i++)
+ {
+ inhibitor = g_ptr_array_index (inhibit->priv->array, i);
+ if ( g_strcmp0 (inhibitor->unique_name, unique_name ) == 0 )
{
- inhibitor = g_ptr_array_index (inhibit->priv->array, i);
- if ( g_strcmp0 (inhibitor->unique_name, unique_name ) == 0 )
- {
- return inhibitor;
- }
+ return inhibitor;
}
- return NULL;
+ }
+
+ return NULL;
}
static gboolean
xfpm_inhibit_remove_application_by_cookie (XfpmInhibit *inhibit, guint cookie)
{
- Inhibitor *inhibitor;
+ Inhibitor *inhibitor;
- inhibitor = xfpm_inhibit_find_application_by_cookie (inhibit, cookie);
+ inhibitor = xfpm_inhibit_find_application_by_cookie (inhibit, cookie);
- if ( inhibitor )
- {
- xfpm_dbus_monitor_remove_unique_name (inhibit->priv->monitor, G_BUS_TYPE_SESSION, inhibitor->unique_name);
- xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
- return TRUE;
- }
- return FALSE;
+ if ( inhibitor )
+ {
+ xfpm_dbus_monitor_remove_unique_name (inhibit->priv->monitor, G_BUS_TYPE_SESSION, inhibitor->unique_name);
+ xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
+ return TRUE;
+ }
+ return FALSE;
}
static void
xfpm_inhibit_connection_lost_cb (XfpmDBusMonitor *monitor, gchar *unique_name,
- gboolean on_session, XfpmInhibit *inhibit)
+ gboolean on_session, XfpmInhibit *inhibit)
{
- Inhibitor *inhibitor;
+ Inhibitor *inhibitor;
- if ( !on_session)
- return;
+ if ( !on_session)
+ return;
- inhibitor = xfpm_inhibit_find_application_by_unique_connection_name (inhibit, unique_name );
+ inhibitor = xfpm_inhibit_find_application_by_unique_connection_name (inhibit, unique_name );
- if ( inhibitor )
- {
- XFPM_DEBUG ("Application=%s with unique connection name=%s disconnected", inhibitor->app_name, inhibitor->unique_name);
- xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
- xfpm_inhibit_has_inhibit_changed (inhibit);
- }
+ if ( inhibitor )
+ {
+ XFPM_DEBUG ("Application=%s with unique connection name=%s disconnected", inhibitor->app_name, inhibitor->unique_name);
+ xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
+ xfpm_inhibit_has_inhibit_changed (inhibit);
+ }
}
static void
xfpm_inhibit_class_init(XfpmInhibitClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- signals[HAS_INHIBIT_CHANGED] =
- g_signal_new ("has-inhibit-changed",
- XFPM_TYPE_INHIBIT,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmInhibitClass, has_inhibit_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- signals[INHIBIT_LIST_CHANGED] =
- g_signal_new ("inhibitors-list-changed",
- XFPM_TYPE_INHIBIT,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmInhibitClass, inhibitors_list_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- object_class->finalize = xfpm_inhibit_finalize;
-
- xfpm_inhibit_dbus_class_init (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ signals[HAS_INHIBIT_CHANGED] =
+ g_signal_new ("has-inhibit-changed",
+ XFPM_TYPE_INHIBIT,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(XfpmInhibitClass, has_inhibit_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ signals[INHIBIT_LIST_CHANGED] =
+ g_signal_new ("inhibitors-list-changed",
+ XFPM_TYPE_INHIBIT,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(XfpmInhibitClass, inhibitors_list_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ object_class->finalize = xfpm_inhibit_finalize;
+
+ xfpm_inhibit_dbus_class_init (klass);
}
static void
xfpm_inhibit_init (XfpmInhibit *inhibit)
{
- inhibit->priv = xfpm_inhibit_get_instance_private (inhibit);
+ inhibit->priv = xfpm_inhibit_get_instance_private (inhibit);
- inhibit->priv->array = g_ptr_array_new ();
- inhibit->priv->monitor = xfpm_dbus_monitor_new ();
+ inhibit->priv->array = g_ptr_array_new ();
+ inhibit->priv->monitor = xfpm_dbus_monitor_new ();
- g_signal_connect (inhibit->priv->monitor, "unique-name-lost",
- G_CALLBACK (xfpm_inhibit_connection_lost_cb), inhibit);
+ g_signal_connect (inhibit->priv->monitor, "unique-name-lost",
+ G_CALLBACK (xfpm_inhibit_connection_lost_cb), inhibit);
- xfpm_inhibit_dbus_init (inhibit);
+ xfpm_inhibit_dbus_init (inhibit);
}
static void
xfpm_inhibit_finalize (GObject *object)
{
- XfpmInhibit *inhibit;
- Inhibitor *inhibitor;
- guint i;
+ XfpmInhibit *inhibit;
+ Inhibitor *inhibitor;
+ guint i;
- inhibit = XFPM_INHIBIT(object);
+ inhibit = XFPM_INHIBIT(object);
- g_object_unref (inhibit->priv->monitor);
+ g_object_unref (inhibit->priv->monitor);
- for ( i = 0; i<inhibit->priv->array->len; i++)
- {
- inhibitor = g_ptr_array_index (inhibit->priv->array, i);
- xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
- }
+ for ( i = 0; i<inhibit->priv->array->len; i++)
+ {
+ inhibitor = g_ptr_array_index (inhibit->priv->array, i);
+ xfpm_inhibit_free_inhibitor (inhibit, inhibitor);
+ }
- g_ptr_array_free (inhibit->priv->array, TRUE);
+ g_ptr_array_free (inhibit->priv->array, TRUE);
- G_OBJECT_CLASS(xfpm_inhibit_parent_class)->finalize(object);
+ G_OBJECT_CLASS (xfpm_inhibit_parent_class)->finalize(object);
}
XfpmInhibit *
-xfpm_inhibit_new(void)
+xfpm_inhibit_new (void)
{
- static gpointer xfpm_inhibit_object = NULL;
-
- if ( G_LIKELY (xfpm_inhibit_object != NULL) )
- {
- g_object_ref (xfpm_inhibit_object);
- }
- else
- {
- xfpm_inhibit_object = g_object_new (XFPM_TYPE_INHIBIT, NULL);
- g_object_add_weak_pointer (xfpm_inhibit_object, &xfpm_inhibit_object);
- }
- return XFPM_INHIBIT (xfpm_inhibit_object);
+ static gpointer xfpm_inhibit_object = NULL;
+
+ if ( G_LIKELY (xfpm_inhibit_object != NULL) )
+ {
+ g_object_ref (xfpm_inhibit_object);
+ }
+ else
+ {
+ xfpm_inhibit_object = g_object_new (XFPM_TYPE_INHIBIT, NULL);
+ g_object_add_weak_pointer (xfpm_inhibit_object, &xfpm_inhibit_object);
+ }
+ return XFPM_INHIBIT (xfpm_inhibit_object);
}
/***
@@ -297,23 +298,23 @@ xfpm_inhibit_new(void)
const gchar **
xfpm_inhibit_get_inhibit_list (XfpmInhibit *inhibit)
{
- guint i;
- Inhibitor *inhibitor;
- const gchar **OUT_inhibitors;
+ guint i;
+ Inhibitor *inhibitor;
+ const gchar **OUT_inhibitors;
- XFPM_DEBUG ("entering xfpm_inhibit_get_inhibit_list");
+ XFPM_DEBUG ("entering xfpm_inhibit_get_inhibit_list");
- OUT_inhibitors = g_new (const gchar *, inhibit->priv->array->len + 1);
+ OUT_inhibitors = g_new (const gchar *, inhibit->priv->array->len + 1);
- for ( i = 0; i<inhibit->priv->array->len; i++)
- {
- inhibitor = g_ptr_array_index (inhibit->priv->array, i);
- OUT_inhibitors[i] = inhibitor->app_name;
- }
+ for ( i = 0; i<inhibit->priv->array->len; i++)
+ {
+ inhibitor = g_ptr_array_index (inhibit->priv->array, i);
+ OUT_inhibitors[i] = inhibitor->app_name;
+ }
- OUT_inhibitors[inhibit->priv->array->len] = NULL;
+ OUT_inhibitors[inhibit->priv->array->len] = NULL;
- return OUT_inhibitors;
+ return OUT_inhibitors;
}
/*
@@ -321,146 +322,152 @@ xfpm_inhibit_get_inhibit_list (XfpmInhibit *inhibit)
* DBus server implementation for org.freedesktop.PowerManagement.Inhibit
*
*/
-static gboolean xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- const gchar *IN_appname,
- const gchar *IN_reason,
- gpointer user_data);
+static gboolean xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
+ const gchar *IN_appname,
+ const gchar *IN_reason,
+ gpointer user_data);
static gboolean xfpm_inhibit_un_inhibit (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- guint IN_cookie,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ guint IN_cookie,
+ gpointer user_data);
-static gboolean xfpm_inhibit_has_inhibit(XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+static gboolean xfpm_inhibit_has_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_inhibit_get_inhibitors (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
#include "org.freedesktop.PowerManagement.Inhibit.h"
-static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass)
+static void
+xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass)
{
}
-static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit)
+static void
+xfpm_inhibit_dbus_init (XfpmInhibit *inhibit)
{
- GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
- XfpmPowerManagementInhibit *inhibit_dbus;
-
- inhibit_dbus = xfpm_power_management_inhibit_skeleton_new ();
- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (inhibit_dbus),
- bus,
- "/org/freedesktop/PowerManagement/Inhibit",
- NULL);
-
- g_signal_connect_swapped (inhibit_dbus,
- "handle-inhibit",
- G_CALLBACK (xfpm_inhibit_inhibit),
- inhibit);
- g_signal_connect_swapped (inhibit_dbus,
- "handle-un-inhibit",
- G_CALLBACK (xfpm_inhibit_un_inhibit),
- inhibit);
- g_signal_connect_swapped (inhibit_dbus,
- "handle-has-inhibit",
- G_CALLBACK (xfpm_inhibit_has_inhibit),
- inhibit);
- g_signal_connect_swapped (inhibit_dbus,
- "handle-get-inhibitors",
- G_CALLBACK (xfpm_inhibit_get_inhibitors),
- inhibit);
+ GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ XfpmPowerManagementInhibit *inhibit_dbus;
+
+ inhibit_dbus = xfpm_power_management_inhibit_skeleton_new ();
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (inhibit_dbus),
+ bus,
+ "/org/freedesktop/PowerManagement/Inhibit",
+ NULL);
+
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-inhibit",
+ G_CALLBACK (xfpm_inhibit_inhibit),
+ inhibit);
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-un-inhibit",
+ G_CALLBACK (xfpm_inhibit_un_inhibit),
+ inhibit);
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-has-inhibit",
+ G_CALLBACK (xfpm_inhibit_has_inhibit),
+ inhibit);
+ g_signal_connect_swapped (inhibit_dbus,
+ "handle-get-inhibitors",
+ G_CALLBACK (xfpm_inhibit_get_inhibitors),
+ inhibit);
}
-static gboolean xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- const gchar *IN_appname,
- const gchar *IN_reason,
- gpointer user_data)
+static gboolean
+xfpm_inhibit_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
+ const gchar *IN_appname,
+ const gchar *IN_reason,
+ gpointer user_data)
{
- const gchar *sender;
- guint cookie;
+ const gchar *sender;
+ guint cookie;
- if ( IN_appname == NULL || IN_reason == NULL )
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_INVALID_ARGUMENTS,
- _("Invalid arguments"));
+ if ( IN_appname == NULL || IN_reason == NULL )
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_INVALID_ARGUMENTS,
+ _("Invalid arguments"));
- return TRUE;
- }
+ return TRUE;
+ }
- sender = g_dbus_method_invocation_get_sender (invocation);
- cookie = xfpm_inhibit_add_application (inhibit, IN_appname, sender);
+ sender = g_dbus_method_invocation_get_sender (invocation);
+ cookie = xfpm_inhibit_add_application (inhibit, IN_appname, sender);
- XFPM_DEBUG("Inhibit send application name=%s reason=%s sender=%s", IN_appname, IN_reason ,sender);
+ XFPM_DEBUG("Inhibit send application name=%s reason=%s sender=%s", IN_appname, IN_reason ,sender);
- xfpm_inhibit_has_inhibit_changed (inhibit);
+ xfpm_inhibit_has_inhibit_changed (inhibit);
- xfpm_dbus_monitor_add_unique_name (inhibit->priv->monitor, G_BUS_TYPE_SESSION, sender);
+ xfpm_dbus_monitor_add_unique_name (inhibit->priv->monitor, G_BUS_TYPE_SESSION, sender);
- xfpm_power_management_inhibit_complete_inhibit (user_data,
- invocation,
- cookie);
+ xfpm_power_management_inhibit_complete_inhibit (user_data,
+ invocation,
+ cookie);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_inhibit_un_inhibit (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- guint IN_cookie,
- gpointer user_data)
+static gboolean
+xfpm_inhibit_un_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
+ guint IN_cookie,
+ gpointer user_data)
{
- XFPM_DEBUG("UnHibit message received");
-
- if (!xfpm_inhibit_remove_application_by_cookie (inhibit, IN_cookie))
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_COOKIE_NOT_FOUND,
- _("Invalid cookie"));
- return TRUE;
- }
+ XFPM_DEBUG("UnHibit message received");
+
+ if (!xfpm_inhibit_remove_application_by_cookie (inhibit, IN_cookie))
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_COOKIE_NOT_FOUND,
+ _("Invalid cookie"));
+ return TRUE;
+ }
- xfpm_inhibit_has_inhibit_changed (inhibit);
+ xfpm_inhibit_has_inhibit_changed (inhibit);
- xfpm_power_management_inhibit_complete_un_inhibit (user_data, invocation);
+ xfpm_power_management_inhibit_complete_un_inhibit (user_data, invocation);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_inhibit_has_inhibit (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_inhibit_has_inhibit (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- XFPM_DEBUG("Has Inhibit message received");
+ XFPM_DEBUG("Has Inhibit message received");
- xfpm_power_management_inhibit_complete_has_inhibit (user_data,
- invocation,
- inhibit->priv->inhibited);
+ xfpm_power_management_inhibit_complete_has_inhibit (user_data,
+ invocation,
+ inhibit->priv->inhibited);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_inhibit_get_inhibitors (XfpmInhibit *inhibit,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_inhibit_get_inhibitors (XfpmInhibit *inhibit,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- const gchar **OUT_inhibitors;
+ const gchar **OUT_inhibitors;
- XFPM_DEBUG ("Get Inhibitors message received");
+ XFPM_DEBUG ("Get Inhibitors message received");
- OUT_inhibitors = xfpm_inhibit_get_inhibit_list (inhibit);
+ OUT_inhibitors = xfpm_inhibit_get_inhibit_list (inhibit);
- xfpm_power_management_inhibit_complete_get_inhibitors (user_data,
- invocation,
- OUT_inhibitors);
+ xfpm_power_management_inhibit_complete_get_inhibitors (user_data,
+ invocation,
+ OUT_inhibitors);
- g_free (OUT_inhibitors);
+ g_free (OUT_inhibitors);
- return TRUE;
+ return TRUE;
}
diff --git a/src/xfpm-inhibit.h b/src/xfpm-inhibit.h
index 66de5bf..b9b1b95 100644
--- a/src/xfpm-inhibit.h
+++ b/src/xfpm-inhibit.h
@@ -33,30 +33,26 @@ typedef struct XfpmInhibitPrivate XfpmInhibitPrivate;
typedef struct
{
- GObject parent;
- XfpmInhibitPrivate *priv;
-
+ GObject parent;
+ XfpmInhibitPrivate *priv;
} XfpmInhibit;
typedef struct
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
/* signals */
- void (*has_inhibit_changed) (XfpmInhibit *inhibit,
- gboolean is_inhibit);
- void (*inhibitors_list_changed) (XfpmInhibit *inhibit,
- gboolean is_inhibit);
-
+ void (*has_inhibit_changed) (XfpmInhibit *inhibit,
+ gboolean is_inhibit);
+ void (*inhibitors_list_changed) (XfpmInhibit *inhibit,
+ gboolean is_inhibit);
} XfpmInhibitClass;
-GType xfpm_inhibit_get_type (void) G_GNUC_CONST;
-GType xfpm_inhibit_error_get_type (void) G_GNUC_CONST;
-GQuark xfpm_inhibit_get_error_quark ();
-
-XfpmInhibit *xfpm_inhibit_new (void);
-
-const gchar **xfpm_inhibit_get_inhibit_list (XfpmInhibit *inhibit);
+GType xfpm_inhibit_get_type (void) G_GNUC_CONST;
+GType xfpm_inhibit_error_get_type (void) G_GNUC_CONST;
+GQuark xfpm_inhibit_get_error_quark ();
+XfpmInhibit *xfpm_inhibit_new (void);
+const gchar **xfpm_inhibit_get_inhibit_list (XfpmInhibit *inhibit);
G_END_DECLS
diff --git a/src/xfpm-kbd-backlight.c b/src/xfpm-kbd-backlight.c
index f450fa3..c3ef8d7 100644
--- a/src/xfpm-kbd-backlight.c
+++ b/src/xfpm-kbd-backlight.c
@@ -37,20 +37,20 @@ static void xfpm_kbd_backlight_finalize (GObject *object);
struct XfpmKbdBacklightPrivate
{
- XfpmPower *power;
- XfpmButton *button;
+ XfpmPower *power;
+ XfpmButton *button;
- GDBusConnection *bus;
- GDBusProxy *proxy;
+ GDBusConnection *bus;
+ GDBusProxy *proxy;
- gboolean dimmed;
- gboolean on_battery;
- gint32 max_level;
- gint min_level;
- gint step;
+ gboolean dimmed;
+ gboolean on_battery;
+ gint32 max_level;
+ gint min_level;
+ gint step;
- XfpmNotify *notify;
- NotifyNotification *n;
+ XfpmNotify *notify;
+ NotifyNotification *n;
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmKbdBacklight, xfpm_kbd_backlight, G_TYPE_OBJECT)
@@ -59,304 +59,304 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmKbdBacklight, xfpm_kbd_backlight, G_TYPE_OBJECT)
static gint
calculate_step( gint max_level )
{
- if ( max_level < 20 )
- return 1;
- else
- return max_level / 20;
+ if ( max_level < 20 )
+ return 1;
+ else
+ return max_level / 20;
}
static void
xfpm_kbd_backlight_on_battery_changed_cb (XfpmPower *power, gboolean on_battery, XfpmKbdBacklight *backlight)
{
- backlight->priv->on_battery = on_battery;
+ backlight->priv->on_battery = on_battery;
}
static void
xfpm_kbd_backlight_init_max_level (XfpmKbdBacklight *backlight)
{
- GError *error = NULL;
- GVariant *var;
-
- var = g_dbus_proxy_call_sync (backlight->priv->proxy, "GetMaxBrightness",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if (var)
- {
- g_variant_get (var,
- "(i)",
- &backlight->priv->max_level);
- g_variant_unref (var);
- }
-
- if ( error )
- {
- g_warning ("Failed to get keyboard max brightness level : %s", error->message);
- g_error_free (error);
- }
+ GError *error = NULL;
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (backlight->priv->proxy, "GetMaxBrightness",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ {
+ g_variant_get (var,
+ "(i)",
+ &backlight->priv->max_level);
+ g_variant_unref (var);
+ }
+
+ if ( error )
+ {
+ g_warning ("Failed to get keyboard max brightness level : %s", error->message);
+ g_error_free (error);
+ }
}
static void
xfpm_kbd_backlight_show_notification (XfpmKbdBacklight *self, gfloat value)
{
- gchar *summary;
-
- if ( self->priv->n == NULL )
- {
- /* generate a human-readable summary for the notification */
- summary = g_strdup_printf (_("Keyboard Brightness: %.0f percent"), value);
- self->priv->n = xfpm_notify_new_notification (self->priv->notify,
- _("Power Manager"),
- summary,
- "keyboard-brightness",
- 0,
- XFPM_NOTIFY_NORMAL);
- g_free (summary);
- }
-
- /* add the brightness value to the notification */
- notify_notification_set_hint (self->priv->n, "value", g_variant_new_int32 (value));
-
- /* show the notification */
- notify_notification_show (self->priv->n, NULL);
+ gchar *summary;
+
+ if ( self->priv->n == NULL )
+ {
+ /* generate a human-readable summary for the notification */
+ summary = g_strdup_printf (_("Keyboard Brightness: %.0f percent"), value);
+ self->priv->n = xfpm_notify_new_notification (self->priv->notify,
+ _("Power Manager"),
+ summary,
+ "keyboard-brightness",
+ 0,
+ XFPM_NOTIFY_NORMAL);
+ g_free (summary);
+ }
+
+ /* add the brightness value to the notification */
+ notify_notification_set_hint (self->priv->n, "value", g_variant_new_int32 (value));
+
+ /* show the notification */
+ notify_notification_show (self->priv->n, NULL);
}
static gint
xfpm_kbd_backlight_get_level (XfpmKbdBacklight *backlight)
{
- GError *error = NULL;
- gint32 level = -1;
- GVariant *var;
-
- var = g_dbus_proxy_call_sync (backlight->priv->proxy, "GetBrightness",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
- if (var)
- {
- g_variant_get (var,
- "(i)",
- &level);
- g_variant_unref (var);
- }
-
- if ( error )
- {
- g_warning ("Failed to get keyboard brightness level : %s", error->message);
- g_error_free (error);
- }
- return level;
+ GError *error = NULL;
+ gint32 level = -1;
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (backlight->priv->proxy, "GetBrightness",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+ if (var)
+ {
+ g_variant_get (var,
+ "(i)",
+ &level);
+ g_variant_unref (var);
+ }
+
+ if ( error )
+ {
+ g_warning ("Failed to get keyboard brightness level : %s", error->message);
+ g_error_free (error);
+ }
+ return level;
}
static void
xfpm_kbd_backlight_set_level (XfpmKbdBacklight *backlight, gint32 level)
{
- GError *error = NULL;
- gfloat percent;
- GVariant *var;
-
- var = g_dbus_proxy_call_sync (backlight->priv->proxy, "SetBrightness",
- g_variant_new("(i)", level),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if (var)
- g_variant_unref (var);
-
- if ( error )
- {
- g_warning ("Failed to set keyboard brightness level : %s", error->message);
- g_error_free (error);
- }
- else
- {
- percent = 100.0 * ((gfloat)level / (gfloat)backlight->priv->max_level);
- xfpm_kbd_backlight_show_notification (backlight, percent);
- }
+ GError *error = NULL;
+ gfloat percent;
+ GVariant *var;
+
+ var = g_dbus_proxy_call_sync (backlight->priv->proxy, "SetBrightness",
+ g_variant_new("(i)", level),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if (var)
+ g_variant_unref (var);
+
+ if ( error )
+ {
+ g_warning ("Failed to set keyboard brightness level : %s", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ percent = 100.0 * ((gfloat)level / (gfloat)backlight->priv->max_level);
+ xfpm_kbd_backlight_show_notification (backlight, percent);
+ }
}
static void
xfpm_kbd_backlight_up (XfpmKbdBacklight *backlight)
{
- gint level;
+ gint level;
- level = xfpm_kbd_backlight_get_level(backlight);
+ level = xfpm_kbd_backlight_get_level (backlight);
- if ( level == -1)
- return;
+ if ( level == -1)
+ return;
- if ( level == backlight->priv->max_level )
- return;
+ if ( level == backlight->priv->max_level )
+ return;
- level += backlight->priv->step;
+ level += backlight->priv->step;
- if ( level > backlight->priv->max_level )
- level = backlight->priv->max_level;
+ if ( level > backlight->priv->max_level )
+ level = backlight->priv->max_level;
- xfpm_kbd_backlight_set_level(backlight, level);
+ xfpm_kbd_backlight_set_level (backlight, level);
}
static void
xfpm_kbd_backlight_down (XfpmKbdBacklight *backlight)
{
- gint level;
+ gint level;
- level = xfpm_kbd_backlight_get_level(backlight);
+ level = xfpm_kbd_backlight_get_level (backlight);
- if ( level == -1)
- return;
+ if ( level == -1)
+ return;
- if ( level == backlight->priv->min_level )
- return;
+ if ( level == backlight->priv->min_level )
+ return;
- level -= backlight->priv->step;
+ level -= backlight->priv->step;
- if ( level < backlight->priv->min_level )
- level = backlight->priv->min_level;
+ if ( level < backlight->priv->min_level )
+ level = backlight->priv->min_level;
- xfpm_kbd_backlight_set_level(backlight, level);
+ xfpm_kbd_backlight_set_level (backlight, level);
}
static void
xfpm_kbd_backlight_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmKbdBacklight *backlight)
{
- if ( type == BUTTON_KBD_BRIGHTNESS_UP )
- {
- xfpm_kbd_backlight_up (backlight);
- }
- else if ( type == BUTTON_KBD_BRIGHTNESS_DOWN )
- {
- xfpm_kbd_backlight_down (backlight);
- }
+ if ( type == BUTTON_KBD_BRIGHTNESS_UP )
+ {
+ xfpm_kbd_backlight_up (backlight);
+ }
+ else if ( type == BUTTON_KBD_BRIGHTNESS_DOWN )
+ {
+ xfpm_kbd_backlight_down (backlight);
+ }
}
static void
xfpm_kbd_backlight_class_init (XfpmKbdBacklightClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = xfpm_kbd_backlight_finalize;
+ object_class->finalize = xfpm_kbd_backlight_finalize;
}
static void
xfpm_kbd_backlight_init (XfpmKbdBacklight *backlight)
{
- GError *error = NULL;
-
- backlight->priv = xfpm_kbd_backlight_get_instance_private (backlight);
-
- backlight->priv->bus = NULL;
- backlight->priv->proxy = NULL;
- backlight->priv->power = NULL;
- backlight->priv->button = NULL;
- backlight->priv->dimmed = FALSE;
- backlight->priv->on_battery = FALSE;
- backlight->priv->max_level = 0;
- backlight->priv->min_level = 0;
- backlight->priv->notify = NULL;
- backlight->priv->n = NULL;
-
- backlight->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
-
- if ( error )
- {
- g_critical ("Unable to get system bus connection : %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- backlight->priv->proxy = g_dbus_proxy_new_sync (backlight->priv->bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- NULL,
- "org.freedesktop.UPower",
- "/org/freedesktop/UPower/KbdBacklight",
- "org.freedesktop.UPower.KbdBacklight",
- NULL,
- NULL);
- if ( backlight->priv->proxy == NULL )
- {
- g_warning ("Unable to get the interface, org.freedesktop.UPower.KbdBacklight");
- goto out;
- }
-
- xfpm_kbd_backlight_init_max_level (backlight);
-
- if ( backlight->priv->max_level == 0 )
- goto out;
-
- backlight->priv->step = calculate_step (backlight->priv->max_level);
- backlight->priv->power = xfpm_power_get ();
- backlight->priv->button = xfpm_button_new ();
- backlight->priv->notify = xfpm_notify_new ();
-
- g_signal_connect (backlight->priv->button, "button-pressed",
- G_CALLBACK (xfpm_kbd_backlight_button_pressed_cb), backlight);
-
- g_signal_connect (backlight->priv->power, "on-battery-changed",
- G_CALLBACK (xfpm_kbd_backlight_on_battery_changed_cb), backlight);
-
- g_object_get (G_OBJECT (backlight->priv->power),
- "on-battery", &backlight->priv->on_battery,
- NULL);
+ GError *error = NULL;
+
+ backlight->priv = xfpm_kbd_backlight_get_instance_private (backlight);
+
+ backlight->priv->bus = NULL;
+ backlight->priv->proxy = NULL;
+ backlight->priv->power = NULL;
+ backlight->priv->button = NULL;
+ backlight->priv->dimmed = FALSE;
+ backlight->priv->on_battery = FALSE;
+ backlight->priv->max_level = 0;
+ backlight->priv->min_level = 0;
+ backlight->priv->notify = NULL;
+ backlight->priv->n = NULL;
+
+ backlight->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+
+ if ( error )
+ {
+ g_critical ("Unable to get system bus connection : %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ backlight->priv->proxy = g_dbus_proxy_new_sync (backlight->priv->bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower/KbdBacklight",
+ "org.freedesktop.UPower.KbdBacklight",
+ NULL,
+ NULL);
+ if ( backlight->priv->proxy == NULL )
+ {
+ g_warning ("Unable to get the interface, org.freedesktop.UPower.KbdBacklight");
+ goto out;
+ }
+
+ xfpm_kbd_backlight_init_max_level (backlight);
+
+ if ( backlight->priv->max_level == 0 )
+ goto out;
+
+ backlight->priv->step = calculate_step (backlight->priv->max_level);
+ backlight->priv->power = xfpm_power_get ();
+ backlight->priv->button = xfpm_button_new ();
+ backlight->priv->notify = xfpm_notify_new ();
+
+ g_signal_connect (backlight->priv->button, "button-pressed",
+ G_CALLBACK (xfpm_kbd_backlight_button_pressed_cb), backlight);
+
+ g_signal_connect (backlight->priv->power, "on-battery-changed",
+ G_CALLBACK (xfpm_kbd_backlight_on_battery_changed_cb), backlight);
+
+ g_object_get (G_OBJECT (backlight->priv->power),
+ "on-battery", &backlight->priv->on_battery,
+ NULL);
out:
- ;
+ ;
}
static void
xfpm_kbd_backlight_finalize (GObject *object)
{
- XfpmKbdBacklight *backlight = NULL;
+ XfpmKbdBacklight *backlight = NULL;
- backlight = XFPM_KBD_BACKLIGHT (object);
+ backlight = XFPM_KBD_BACKLIGHT (object);
- if ( backlight->priv->power )
- g_object_unref (backlight->priv->power );
+ if ( backlight->priv->power )
+ g_object_unref (backlight->priv->power );
- if ( backlight->priv->button )
- g_object_unref (backlight->priv->button);
+ if ( backlight->priv->button )
+ g_object_unref (backlight->priv->button);
- if ( backlight->priv->notify )
- g_object_unref (backlight->priv->notify);
+ if ( backlight->priv->notify )
+ g_object_unref (backlight->priv->notify);
- if ( backlight->priv->n )
- g_object_unref (backlight->priv->n);
+ if ( backlight->priv->n )
+ g_object_unref (backlight->priv->n);
- if ( backlight->priv->proxy )
- g_object_unref (backlight->priv->proxy);
+ if ( backlight->priv->proxy )
+ g_object_unref (backlight->priv->proxy);
- if ( backlight->priv->bus )
- g_object_unref (backlight->priv->bus);
+ if ( backlight->priv->bus )
+ g_object_unref (backlight->priv->bus);
- G_OBJECT_CLASS (xfpm_kbd_backlight_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_kbd_backlight_parent_class)->finalize (object);
}
XfpmKbdBacklight *
xfpm_kbd_backlight_new (void)
{
- XfpmKbdBacklight *backlight = NULL;
- backlight = g_object_new (XFPM_TYPE_KBD_BACKLIGHT, NULL);
- return backlight;
+ XfpmKbdBacklight *backlight = NULL;
+ backlight = g_object_new (XFPM_TYPE_KBD_BACKLIGHT, NULL);
+ return backlight;
}
gboolean xfpm_kbd_backlight_has_hw (XfpmKbdBacklight *backlight)
{
- return ( backlight->priv->proxy == NULL ) ? FALSE : TRUE;
+ return ( backlight->priv->proxy == NULL ) ? FALSE : TRUE;
}
diff --git a/src/xfpm-kbd-backlight.h b/src/xfpm-kbd-backlight.h
index 99569d7..5326f6c 100644
--- a/src/xfpm-kbd-backlight.h
+++ b/src/xfpm-kbd-backlight.h
@@ -33,21 +33,19 @@ typedef struct XfpmKbdBacklightPrivate XfpmKbdBacklightPrivate;
typedef struct
{
- GObject parent;
- XfpmKbdBacklightPrivate *priv;
+ GObject parent;
+ XfpmKbdBacklightPrivate *priv;
} XfpmKbdBacklight;
typedef struct
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
} XfpmKbdBacklightClass;
GType xfpm_kbd_backlight_get_type (void) G_GNUC_CONST;
-
XfpmKbdBacklight *xfpm_kbd_backlight_new (void);
-
gboolean xfpm_kbd_backlight_has_hw (XfpmKbdBacklight *backlight);
G_END_DECLS
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index fe4aa43..7c7aa60 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -51,406 +51,406 @@
static void G_GNUC_NORETURN
show_version (void)
{
- g_print (_("\n"
- "Xfce Power Manager %s\n\n"
- "Part of the Xfce Goodies Project\n"
- "http://goodies.xfce.org\n\n"
- "Licensed under the GNU GPL.\n\n"), VERSION);
+ g_print (_("\n"
+ "Xfce Power Manager %s\n\n"
+ "Part of the Xfce Goodies Project\n"
+ "http://goodies.xfce.org\n\n"
+ "Licensed under the GNU GPL.\n\n"), VERSION);
- exit (EXIT_SUCCESS);
+ exit (EXIT_SUCCESS);
}
static void
xfpm_quit_signal (gint sig, gpointer data)
{
- XfpmManager *manager = (XfpmManager *) data;
+ XfpmManager *manager = (XfpmManager *) data;
- XFPM_DEBUG ("sig %d", sig);
+ XFPM_DEBUG ("sig %d", sig);
- if ( sig != SIGHUP )
- xfpm_manager_stop (manager);
+ if ( sig != SIGHUP )
+ xfpm_manager_stop (manager);
}
static const gchar *
xfpm_bool_to_local_string (gboolean value)
{
- return value == TRUE ? _("True") : _("False");
+ return value == TRUE ? _("True") : _("False");
}
static void
xfpm_dump (GHashTable *hash)
{
- gboolean has_battery;
- gboolean auth_suspend;
- gboolean auth_hibernate;
- gboolean can_suspend;
- gboolean can_hibernate;
- gboolean can_shutdown;
- gboolean has_lcd_brightness;
- gboolean has_sleep_button;
- gboolean has_hibernate_button;
- gboolean has_power_button;
- gboolean has_battery_button;
- gboolean has_lid;
-
- has_battery = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-battery"));
- has_lid = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-lid"));
- can_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-suspend"));
- can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-hibernate"));
- auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-suspend"));
- auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-hibernate"));
- has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-brightness"));
- has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "sleep-button"));
- has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "power-button"));
- has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "hibernate-button"));
- has_battery_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "battery-button"));
- can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-shutdown"));
-
- g_print ("---------------------------------------------------\n");
- g_print (" Xfce power manager version %s\n", VERSION);
+ gboolean has_battery;
+ gboolean auth_suspend;
+ gboolean auth_hibernate;
+ gboolean can_suspend;
+ gboolean can_hibernate;
+ gboolean can_shutdown;
+ gboolean has_lcd_brightness;
+ gboolean has_sleep_button;
+ gboolean has_hibernate_button;
+ gboolean has_power_button;
+ gboolean has_battery_button;
+ gboolean has_lid;
+
+ has_battery = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-battery"));
+ has_lid = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-lid"));
+ can_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-suspend"));
+ can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-hibernate"));
+ auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-suspend"));
+ auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-hibernate"));
+ has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-brightness"));
+ has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "sleep-button"));
+ has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "power-button"));
+ has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "hibernate-button"));
+ has_battery_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "battery-button"));
+ can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-shutdown"));
+
+ g_print ("---------------------------------------------------\n");
+ g_print (" Xfce power manager version %s\n", VERSION);
#ifdef ENABLE_POLKIT
- g_print (_("With policykit support\n"));
+ g_print (_("With policykit support\n"));
#else
- g_print (_("Without policykit support\n"));
+ g_print (_("Without policykit support\n"));
#endif
#ifdef WITH_NETWORK_MANAGER
- g_print (_("With network manager support\n"));
+ g_print (_("With network manager support\n"));
#else
- g_print (_("Without network manager support\n"));
+ g_print (_("Without network manager support\n"));
#endif
- g_print ("---------------------------------------------------\n");
- g_print ( "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n"
- "%s: %s\n",
- _("Can suspend"),
- xfpm_bool_to_local_string (can_suspend),
- _("Can hibernate"),
- xfpm_bool_to_local_string (can_hibernate),
- _("Authorized to suspend"),
- xfpm_bool_to_local_string (auth_suspend),
- _("Authorized to hibernate"),
- xfpm_bool_to_local_string (auth_hibernate),
- _("Authorized to shutdown"),
- xfpm_bool_to_local_string (can_shutdown),
- _("Has battery"),
- xfpm_bool_to_local_string (has_battery),
- _("Has brightness panel"),
- xfpm_bool_to_local_string (has_lcd_brightness),
- _("Has power button"),
- xfpm_bool_to_local_string (has_power_button),
- _("Has hibernate button"),
- xfpm_bool_to_local_string (has_hibernate_button),
- _("Has sleep button"),
- xfpm_bool_to_local_string (has_sleep_button),
- _("Has battery button"),
- xfpm_bool_to_local_string (has_battery_button),
- _("Has LID"),
- xfpm_bool_to_local_string (has_lid));
+ g_print ("---------------------------------------------------\n");
+ g_print ( "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n"
+ "%s: %s\n",
+ _("Can suspend"),
+ xfpm_bool_to_local_string (can_suspend),
+ _("Can hibernate"),
+ xfpm_bool_to_local_string (can_hibernate),
+ _("Authorized to suspend"),
+ xfpm_bool_to_local_string (auth_suspend),
+ _("Authorized to hibernate"),
+ xfpm_bool_to_local_string (auth_hibernate),
+ _("Authorized to shutdown"),
+ xfpm_bool_to_local_string (can_shutdown),
+ _("Has battery"),
+ xfpm_bool_to_local_string (has_battery),
+ _("Has brightness panel"),
+ xfpm_bool_to_local_string (has_lcd_brightness),
+ _("Has power button"),
+ xfpm_bool_to_local_string (has_power_button),
+ _("Has hibernate button"),
+ xfpm_bool_to_local_string (has_hibernate_button),
+ _("Has sleep button"),
+ xfpm_bool_to_local_string (has_sleep_button),
+ _("Has battery button"),
+ xfpm_bool_to_local_string (has_battery_button),
+ _("Has LID"),
+ xfpm_bool_to_local_string (has_lid));
}
static void
xfpm_dump_remote (GDBusConnection *bus)
{
- XfpmPowerManager *proxy;
- GError *error = NULL;
- GVariant *config;
- GVariantIter *iter;
- GHashTable *hash;
- gchar *key, *value;
-
- proxy = xfpm_power_manager_proxy_new_sync (bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- NULL,
- NULL);
-
- xfpm_power_manager_call_get_config_sync (proxy,
- &config,
- NULL,
- &error);
-
- g_object_unref (proxy);
-
- if ( error )
- {
- g_error ("%s", error->message);
- exit (EXIT_FAILURE);
- }
-
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- g_variant_get (config, "a{ss}", &iter);
- while (g_variant_iter_next (iter, "{ss}", &key, &value))
- {
- g_hash_table_insert (hash, key, value);
- }
- g_variant_iter_free (iter);
- g_variant_unref (config);
-
- xfpm_dump (hash);
- g_hash_table_destroy (hash);
+ XfpmPowerManager *proxy;
+ GError *error = NULL;
+ GVariant *config;
+ GVariantIter *iter;
+ GHashTable *hash;
+ gchar *key, *value;
+
+ proxy = xfpm_power_manager_proxy_new_sync (bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ "org.xfce.PowerManager",
+ "/org/xfce/PowerManager",
+ NULL,
+ NULL);
+
+ xfpm_power_manager_call_get_config_sync (proxy,
+ &config,
+ NULL,
+ &error);
+
+ g_object_unref (proxy);
+
+ if ( error )
+ {
+ g_error ("%s", error->message);
+ exit (EXIT_FAILURE);
+ }
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ g_variant_get (config, "a{ss}", &iter);
+ while (g_variant_iter_next (iter, "{ss}", &key, &value))
+ {
+ g_hash_table_insert (hash, key, value);
+ }
+ g_variant_iter_free (iter);
+ g_variant_unref (config);
+
+ xfpm_dump (hash);
+ g_hash_table_destroy (hash);
}
static void G_GNUC_NORETURN
xfpm_start (GDBusConnection *bus, const gchar *client_id, gboolean dump)
{
- XfpmManager *manager;
- GError *error = NULL;
+ XfpmManager *manager;
+ GError *error = NULL;
- XFPM_DEBUG ("Starting the power manager");
+ XFPM_DEBUG ("Starting the power manager");
- manager = xfpm_manager_new (bus, client_id);
+ manager = xfpm_manager_new (bus, client_id);
- if ( xfce_posix_signal_handler_init (&error))
- {
- xfce_posix_signal_handler_set_handler (SIGHUP,
- xfpm_quit_signal,
- manager, NULL);
+ if ( xfce_posix_signal_handler_init (&error))
+ {
+ xfce_posix_signal_handler_set_handler (SIGHUP,
+ xfpm_quit_signal,
+ manager, NULL);
- xfce_posix_signal_handler_set_handler (SIGINT,
- xfpm_quit_signal,
- manager, NULL);
+ xfce_posix_signal_handler_set_handler (SIGINT,
+ xfpm_quit_signal,
+ manager, NULL);
- xfce_posix_signal_handler_set_handler (SIGTERM,
- xfpm_quit_signal,
- manager, NULL);
- }
- else
- {
- g_warning ("Unable to set up POSIX signal handlers: %s", error->message);
- g_error_free (error);
- }
+ xfce_posix_signal_handler_set_handler (SIGTERM,
+ xfpm_quit_signal,
+ manager, NULL);
+ }
+ else
+ {
+ g_warning ("Unable to set up POSIX signal handlers: %s", error->message);
+ g_error_free (error);
+ }
- xfpm_manager_start (manager);
+ xfpm_manager_start (manager);
- if ( dump )
- {
- GHashTable *hash;
- hash = xfpm_manager_get_config (manager);
- xfpm_dump (hash);
- g_hash_table_destroy (hash);
- }
+ if ( dump )
+ {
+ GHashTable *hash;
+ hash = xfpm_manager_get_config (manager);
+ xfpm_dump (hash);
+ g_hash_table_destroy (hash);
+ }
- gtk_main ();
+ gtk_main ();
- g_object_unref (manager);
+ g_object_unref (manager);
- exit (EXIT_SUCCESS);
+ exit (EXIT_SUCCESS);
}
int main (int argc, char **argv)
{
- GDBusConnection *bus;
- GError *error = NULL;
- XfpmPowerManager *proxy;
- GOptionContext *octx;
-
- gboolean run = FALSE;
- gboolean quit = FALSE;
- gboolean config = FALSE;
- gboolean version = FALSE;
- gboolean reload = FALSE;
- gboolean no_daemon = FALSE;
- gboolean debug = FALSE;
- gboolean dump = FALSE;
- gchar *client_id = NULL;
-
- GOptionEntry option_entries[] =
- {
- { "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &run, NULL, NULL },
- { "no-daemon",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_daemon, N_("Do not daemonize"), NULL },
- { "debug",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL },
- { "dump",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &dump, N_("Dump all information"), NULL },
- { "restart", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &reload, N_("Restart the running instance of Xfce power manager"), NULL},
- { "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL },
- { "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL },
- { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
- { "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &client_id, NULL, NULL },
- { NULL, },
- };
-
- /* Parse the options */
- octx = g_option_context_new("");
- g_option_context_set_ignore_unknown_options(octx, TRUE);
- g_option_context_add_main_entries(octx, option_entries, NULL);
- g_option_context_add_group(octx, xfce_sm_client_get_option_group(argc, argv));
- /* We can't add the following command because it will invoke gtk_init
- before we have a chance to fork.
- g_option_context_add_group(octx, gtk_get_option_group(TRUE));
- */
-
- if(!g_option_context_parse(octx, &argc, &argv, &error)) {
- g_printerr(_("Failed to parse arguments: %s\n"), error->message);
- g_option_context_free(octx);
- g_error_free(error);
+ GDBusConnection *bus;
+ GError *error = NULL;
+ XfpmPowerManager *proxy;
+ GOptionContext *octx;
+
+ gboolean run = FALSE;
+ gboolean quit = FALSE;
+ gboolean config = FALSE;
+ gboolean version = FALSE;
+ gboolean reload = FALSE;
+ gboolean no_daemon = FALSE;
+ gboolean debug = FALSE;
+ gboolean dump = FALSE;
+ gchar *client_id = NULL;
+
+ GOptionEntry option_entries[] =
+ {
+ { "run",'r', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &run, NULL, NULL },
+ { "no-daemon",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &no_daemon, N_("Do not daemonize"), NULL },
+ { "debug",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL },
+ { "dump",'\0' , G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &dump, N_("Dump all information"), NULL },
+ { "restart", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &reload, N_("Restart the running instance of Xfce power manager"), NULL},
+ { "customize", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &config, N_("Show the configuration dialog"), NULL },
+ { "quit", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &quit, N_("Quit any running xfce power manager"), NULL },
+ { "version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &version, N_("Version information"), NULL },
+ { "sm-client-id", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &client_id, NULL, NULL },
+ { NULL, },
+ };
+
+ /* Parse the options */
+ octx = g_option_context_new("");
+ g_option_context_set_ignore_unknown_options(octx, TRUE);
+ g_option_context_add_main_entries(octx, option_entries, NULL);
+ g_option_context_add_group(octx, xfce_sm_client_get_option_group(argc, argv));
+ /* We can't add the following command because it will invoke gtk_init
+ before we have a chance to fork.
+ g_option_context_add_group(octx, gtk_get_option_group(TRUE));
+ */
+
+ if (!g_option_context_parse(octx, &argc, &argv, &error))
+ {
+ g_printerr(_("Failed to parse arguments: %s\n"), error->message);
+ g_option_context_free(octx);
+ g_error_free(error);
- return EXIT_FAILURE;
- }
+ return EXIT_FAILURE;
+ }
- g_option_context_free(octx);
+ g_option_context_free(octx);
- if ( version )
- show_version ();
+ if ( version )
+ show_version ();
- /* Fork if needed */
- if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) )
- {
- g_critical ("Could not daemonize");
- }
+ /* Fork if needed */
+ if ( dump == FALSE && debug == FALSE && no_daemon == FALSE && daemon(0,0) )
+ {
+ g_critical ("Could not daemonize");
+ }
- /* Initialize */
- xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
+ /* Initialize */
+ xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
- g_set_application_name (PACKAGE_NAME);
+ g_set_application_name (PACKAGE_NAME);
- if (!gtk_init_check (&argc, &argv))
+ if (!gtk_init_check (&argc, &argv))
+ {
+ if (G_LIKELY (error))
{
- if (G_LIKELY (error))
- {
- g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
- g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
- g_printerr ("\n");
- g_error_free (error);
- }
- else
- {
- g_error ("Unable to open display.");
- }
-
- return EXIT_FAILURE;
+ g_printerr ("%s: %s.\n", G_LOG_DOMAIN, error->message);
+ g_printerr (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
+ g_printerr ("\n");
+ g_error_free (error);
+ }
+ else
+ {
+ g_error ("Unable to open display.");
}
- xfpm_debug_init (debug);
+ return EXIT_FAILURE;
+ }
- bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ xfpm_debug_init (debug);
- if ( error )
- {
- xfce_dialog_show_error (NULL,
- error,
- "%s",
- _("Unable to get connection to the message bus session"));
- g_error ("%s: \n", error->message);
- }
+ bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
- if ( quit )
+ if ( error )
+ {
+ xfce_dialog_show_error (NULL,
+ error,
+ "%s",
+ _("Unable to get connection to the message bus session"));
+ g_error ("%s: \n", error->message);
+ }
+
+ if ( quit )
+ {
+ if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") )
{
- if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") )
- {
- g_print (_("Xfce power manager is not running"));
- g_print ("\n");
- return EXIT_SUCCESS;
- }
- else
- {
- proxy = xfpm_power_manager_proxy_new_sync (bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- NULL,
- NULL);
- if ( !proxy )
- {
- g_critical ("Failed to get proxy");
- g_object_unref(bus);
- return EXIT_FAILURE;
- }
- xfpm_power_manager_call_quit_sync (proxy, NULL, &error);
- g_object_unref (proxy);
-
- if ( error)
- {
- g_critical ("Failed to send quit message %s:\n", error->message);
- g_error_free (error);
- }
- }
- return EXIT_SUCCESS;
+ g_print (_("Xfce power manager is not running"));
+ g_print ("\n");
+ return EXIT_SUCCESS;
}
-
- if ( config )
+ else
{
- g_spawn_command_line_async ("xfce4-power-manager-settings", &error);
-
- if ( error )
- {
- g_critical ("Failed to execute xfce4-power-manager-settings: %s", error->message);
- g_error_free (error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
+ proxy = xfpm_power_manager_proxy_new_sync (bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ "org.xfce.PowerManager",
+ "/org/xfce/PowerManager",
+ NULL,
+ NULL);
+ if ( !proxy )
+ {
+ g_critical ("Failed to get proxy");
+ g_object_unref(bus);
+ return EXIT_FAILURE;
+ }
+ xfpm_power_manager_call_quit_sync (proxy, NULL, &error);
+ g_object_unref (proxy);
+
+ if ( error)
+ {
+ g_critical ("Failed to send quit message %s:\n", error->message);
+ g_error_free (error);
+ }
}
+ return EXIT_SUCCESS;
+ }
- if ( reload )
+ if ( config )
+ {
+ g_spawn_command_line_async ("xfce4-power-manager-settings", &error);
+
+ if ( error )
{
- if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") &&
- !xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement"))
- {
- g_print ("Xfce power manager is not running\n");
- xfpm_start (bus, client_id, dump);
- }
-
- proxy = xfpm_power_manager_proxy_new_sync (bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- "org.xfce.PowerManager",
- "/org/xfce/PowerManager",
- NULL,
- NULL);
- if ( !proxy )
- {
- g_critical ("Failed to get proxy");
- g_object_unref (bus);
- return EXIT_FAILURE;
- }
-
- if ( !xfpm_power_manager_call_restart_sync (proxy, NULL, NULL) )
- {
- g_critical ("Unable to send reload message");
- g_object_unref (proxy);
- g_object_unref (bus);
- return EXIT_SUCCESS;
- }
- return EXIT_SUCCESS;
+ g_critical ("Failed to execute xfce4-power-manager-settings: %s", error->message);
+ g_error_free (error);
+ return EXIT_FAILURE;
}
+ return EXIT_SUCCESS;
+ }
- if (dump)
+ if ( reload )
+ {
+ if (!xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager") &&
+ !xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement"))
{
- if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
- {
- xfpm_dump_remote (bus);
- return EXIT_SUCCESS;
- }
+ g_print ("Xfce power manager is not running\n");
+ xfpm_start (bus, client_id, dump);
}
- if (xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement") )
+ proxy = xfpm_power_manager_proxy_new_sync (bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ "org.xfce.PowerManager",
+ "/org/xfce/PowerManager",
+ NULL,
+ NULL);
+ if ( !proxy )
{
- g_print ("%s: %s\n",
- _("Xfce Power Manager"),
- _("Another power manager is already running"));
-
+ g_critical ("Failed to get proxy");
+ g_object_unref (bus);
+ return EXIT_FAILURE;
}
- else if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
+
+ if ( !xfpm_power_manager_call_restart_sync (proxy, NULL, NULL) )
{
- g_print (_("Xfce power manager is already running"));
- g_print ("\n");
- return EXIT_SUCCESS;
+ g_critical ("Unable to send reload message");
+ g_object_unref (proxy);
+ g_object_unref (bus);
+ return EXIT_SUCCESS;
}
- else
+ return EXIT_SUCCESS;
+ }
+
+ if (dump)
+ {
+ if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
{
- xfpm_start (bus, client_id, dump);
+ xfpm_dump_remote (bus);
+ return EXIT_SUCCESS;
}
-
+ }
+
+ if (xfpm_dbus_name_has_owner (bus, "org.freedesktop.PowerManagement") )
+ {
+ g_print ("%s: %s\n",
+ _("Xfce Power Manager"),
+ _("Another power manager is already running"));
+ }
+ else if (xfpm_dbus_name_has_owner (bus, "org.xfce.PowerManager"))
+ {
+ g_print (_("Xfce power manager is already running"));
+ g_print ("\n");
return EXIT_SUCCESS;
+ }
+ else
+ {
+ xfpm_start (bus, client_id, dump);
+ }
+
+ return EXIT_SUCCESS;
}
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index 88231f3..0153700 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -67,16 +67,16 @@
static void xfpm_manager_finalize (GObject *object);
static void xfpm_manager_set_property(GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
static void xfpm_manager_get_property(GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
static void xfpm_manager_dbus_class_init (XfpmManagerClass *klass);
-static void xfpm_manager_dbus_init (XfpmManager *manager);
+static void xfpm_manager_dbus_init (XfpmManager *manager);
static gboolean xfpm_manager_quit (XfpmManager *manager);
@@ -87,40 +87,40 @@ static void xfpm_manager_hide_tray_icon (XfpmManager *manager);
struct XfpmManagerPrivate
{
- GDBusConnection *session_bus;
- GDBusConnection *system_bus;
-
- XfceSMClient *client;
-
- XfpmPower *power;
- XfpmButton *button;
- XfpmXfconf *conf;
- XfpmBacklight *backlight;
- XfpmKbdBacklight *kbd_backlight;
- XfpmConsoleKit *console;
- XfpmSystemd *systemd;
- XfpmDBusMonitor *monitor;
- XfpmInhibit *inhibit;
- XfceScreenSaver *screensaver;
- EggIdletime *idle;
- GtkStatusIcon *adapter_icon;
- GtkWidget *power_button;
- gint show_tray_icon;
-
- XfpmDpms *dpms;
-
- GTimer *timer;
-
- gboolean inhibited;
- gboolean session_managed;
-
- gint inhibit_fd;
+ GDBusConnection *session_bus;
+ GDBusConnection *system_bus;
+
+ XfceSMClient *client;
+
+ XfpmPower *power;
+ XfpmButton *button;
+ XfpmXfconf *conf;
+ XfpmBacklight *backlight;
+ XfpmKbdBacklight *kbd_backlight;
+ XfpmConsoleKit *console;
+ XfpmSystemd *systemd;
+ XfpmDBusMonitor *monitor;
+ XfpmInhibit *inhibit;
+ XfceScreenSaver *screensaver;
+ EggIdletime *idle;
+ GtkStatusIcon *adapter_icon;
+ GtkWidget *power_button;
+ gint show_tray_icon;
+
+ XfpmDpms *dpms;
+
+ GTimer *timer;
+
+ gboolean inhibited;
+ gboolean session_managed;
+
+ gint inhibit_fd;
};
enum
{
- PROP_0 = 0,
- PROP_SHOW_TRAY_ICON
+ PROP_0 = 0,
+ PROP_SHOW_TRAY_ICON
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmManager, xfpm_manager, G_TYPE_OBJECT)
@@ -128,892 +128,884 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmManager, xfpm_manager, G_TYPE_OBJECT)
static void
xfpm_manager_class_init (XfpmManagerClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
- object_class->finalize = xfpm_manager_finalize;
- object_class->set_property = xfpm_manager_set_property;
- object_class->get_property = xfpm_manager_get_property;
+ object_class->finalize = xfpm_manager_finalize;
+ object_class->set_property = xfpm_manager_set_property;
+ object_class->get_property = xfpm_manager_get_property;
#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_SHOW_TRAY_ICON,
- g_param_spec_int(SHOW_TRAY_ICON_CFG,
- SHOW_TRAY_ICON_CFG,
- SHOW_TRAY_ICON_CFG,
- 0, 5, 0,
- XFPM_PARAM_FLAGS));
+ | G_PARAM_CONSTRUCT \
+ | G_PARAM_STATIC_NAME \
+ | G_PARAM_STATIC_NICK \
+ | G_PARAM_STATIC_BLURB)
+
+ g_object_class_install_property (object_class, PROP_SHOW_TRAY_ICON,
+ g_param_spec_int (SHOW_TRAY_ICON_CFG,
+ SHOW_TRAY_ICON_CFG,
+ SHOW_TRAY_ICON_CFG,
+ 0, 5, 0,
+ XFPM_PARAM_FLAGS));
#undef XFPM_PARAM_FLAGS
}
static void
xfpm_manager_init (XfpmManager *manager)
{
- manager->priv = xfpm_manager_get_instance_private (manager);
+ manager->priv = xfpm_manager_get_instance_private (manager);
- manager->priv->timer = g_timer_new ();
+ manager->priv->timer = g_timer_new ();
- notify_init ("xfce4-power-manager");
+ notify_init ("xfce4-power-manager");
}
static void
xfpm_manager_finalize (GObject *object)
{
- XfpmManager *manager;
+ XfpmManager *manager;
- manager = XFPM_MANAGER(object);
+ manager = XFPM_MANAGER(object);
- if ( manager->priv->session_bus )
- g_object_unref (manager->priv->session_bus);
+ if ( manager->priv->session_bus )
+ g_object_unref (manager->priv->session_bus);
- if ( manager->priv->system_bus )
- g_object_unref (manager->priv->system_bus);
+ if ( manager->priv->system_bus )
+ g_object_unref (manager->priv->system_bus);
- g_object_unref (manager->priv->power);
- g_object_unref (manager->priv->button);
- g_object_unref (manager->priv->conf);
- g_object_unref (manager->priv->client);
- if ( manager->priv->systemd != NULL )
- g_object_unref (manager->priv->systemd);
- if ( manager->priv->console != NULL )
- g_object_unref (manager->priv->console);
- g_object_unref (manager->priv->monitor);
- g_object_unref (manager->priv->inhibit);
- g_object_unref (manager->priv->idle);
+ g_object_unref (manager->priv->power);
+ g_object_unref (manager->priv->button);
+ g_object_unref (manager->priv->conf);
+ g_object_unref (manager->priv->client);
+ if ( manager->priv->systemd != NULL )
+ g_object_unref (manager->priv->systemd);
+ if ( manager->priv->console != NULL )
+ g_object_unref (manager->priv->console);
+ g_object_unref (manager->priv->monitor);
+ g_object_unref (manager->priv->inhibit);
+ g_object_unref (manager->priv->idle);
- g_timer_destroy (manager->priv->timer);
+ g_timer_destroy (manager->priv->timer);
- g_object_unref (manager->priv->dpms);
+ g_object_unref (manager->priv->dpms);
- g_object_unref (manager->priv->backlight);
+ g_object_unref (manager->priv->backlight);
- g_object_unref (manager->priv->kbd_backlight);
+ g_object_unref (manager->priv->kbd_backlight);
- G_OBJECT_CLASS (xfpm_manager_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_manager_parent_class)->finalize (object);
}
static void
-xfpm_manager_set_property(GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+xfpm_manager_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- XfpmManager *manager = XFPM_MANAGER(object);
- gint new_value;
-
- switch(property_id) {
- case PROP_SHOW_TRAY_ICON:
- new_value = g_value_get_int (value);
- if (new_value != manager->priv->show_tray_icon)
- {
- manager->priv->show_tray_icon = new_value;
- if (new_value > 0)
- {
- xfpm_manager_show_tray_icon (manager);
- }
- else
- {
- xfpm_manager_hide_tray_icon (manager);
- }
- }
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
+ XfpmManager *manager = XFPM_MANAGER(object);
+ gint new_value;
+
+ switch(property_id) {
+ case PROP_SHOW_TRAY_ICON:
+ new_value = g_value_get_int (value);
+ if (new_value != manager->priv->show_tray_icon)
+ {
+ manager->priv->show_tray_icon = new_value;
+ if (new_value > 0)
+ {
+ xfpm_manager_show_tray_icon (manager);
+ }
+ else
+ {
+ xfpm_manager_hide_tray_icon (manager);
+ }
+ }
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
static void
-xfpm_manager_get_property(GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+xfpm_manager_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- XfpmManager *manager = XFPM_MANAGER(object);
+ XfpmManager *manager = XFPM_MANAGER(object);
- switch(property_id) {
- case PROP_SHOW_TRAY_ICON:
- g_value_set_int (value, manager->priv->show_tray_icon);
- break;
+ switch(property_id) {
+ case PROP_SHOW_TRAY_ICON:
+ g_value_set_int (value, manager->priv->show_tray_icon);
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
- break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
+ break;
}
}
static void
xfpm_manager_release_names (XfpmManager *manager)
{
- xfpm_dbus_release_name (manager->priv->session_bus,
- "org.xfce.PowerManager");
+ xfpm_dbus_release_name (manager->priv->session_bus,
+ "org.xfce.PowerManager");
- xfpm_dbus_release_name (manager->priv->session_bus,
- "org.freedesktop.PowerManagement");
+ xfpm_dbus_release_name (manager->priv->session_bus,
+ "org.freedesktop.PowerManagement");
}
static gboolean
xfpm_manager_quit (XfpmManager *manager)
{
- XFPM_DEBUG ("Exiting");
+ XFPM_DEBUG ("Exiting");
- xfpm_manager_release_names (manager);
+ xfpm_manager_release_names (manager);
- if (manager->priv->inhibit_fd >= 0)
- close (manager->priv->inhibit_fd);
+ if (manager->priv->inhibit_fd >= 0)
+ close (manager->priv->inhibit_fd);
- gtk_main_quit ();
- return TRUE;
+ gtk_main_quit ();
+ return TRUE;
}
static void
xfpm_manager_system_bus_connection_changed_cb (XfpmDBusMonitor *monitor, gboolean connected, XfpmManager *manager)
{
- if ( connected == TRUE )
- {
- XFPM_DEBUG ("System bus connection changed to TRUE, restarting the power manager");
- xfpm_manager_quit (manager);
- g_spawn_command_line_async ("xfce4-power-manager", NULL);
- }
+ if ( connected == TRUE )
+ {
+ XFPM_DEBUG ("System bus connection changed to TRUE, restarting the power manager");
+ xfpm_manager_quit (manager);
+ g_spawn_command_line_async ("xfce4-power-manager", NULL);
+ }
}
static gboolean
xfpm_manager_reserve_names (XfpmManager *manager)
{
- if ( !xfpm_dbus_register_name (manager->priv->session_bus,
- "org.xfce.PowerManager") ||
- !xfpm_dbus_register_name (manager->priv->session_bus,
- "org.freedesktop.PowerManagement") )
- {
- g_warning ("Unable to reserve bus name: Maybe any already running instance?\n");
-
- g_object_unref (G_OBJECT (manager));
- gtk_main_quit ();
+ if ( !xfpm_dbus_register_name (manager->priv->session_bus,
+ "org.xfce.PowerManager") ||
+ !xfpm_dbus_register_name (manager->priv->session_bus,
+ "org.freedesktop.PowerManagement") )
+ {
+ g_warning ("Unable to reserve bus name: Maybe any already running instance?\n");
+
+ g_object_unref (G_OBJECT (manager));
+ gtk_main_quit ();
- return FALSE;
- }
- return TRUE;
+ return FALSE;
+ }
+ return TRUE;
}
static void
xfpm_manager_shutdown (XfpmManager *manager)
{
- GError *error = NULL;
+ GError *error = NULL;
- if ( LOGIND_RUNNING () )
- xfpm_systemd_shutdown (manager->priv->systemd, &error );
- else
- xfpm_console_kit_shutdown (manager->priv->console, &error );
+ if ( LOGIND_RUNNING () )
+ xfpm_systemd_shutdown (manager->priv->systemd, &error );
+ else
+ xfpm_console_kit_shutdown (manager->priv->console, &error );
- if ( error )
- {
- g_warning ("Failed to shutdown the system : %s", error->message);
- g_error_free (error);
- /* Try with the session then */
- if ( manager->priv->session_managed )
- xfce_sm_client_request_shutdown (manager->priv->client, XFCE_SM_CLIENT_SHUTDOWN_HINT_HALT);
- }
+ if ( error )
+ {
+ g_warning ("Failed to shutdown the system : %s", error->message);
+ g_error_free (error);
+ /* Try with the session then */
+ if ( manager->priv->session_managed )
+ xfce_sm_client_request_shutdown (manager->priv->client, XFCE_SM_CLIENT_SHUTDOWN_HINT_HALT);
+ }
}
static void
xfpm_manager_ask_shutdown (XfpmManager *manager)
{
- if ( manager->priv->session_managed )
- xfce_sm_client_request_shutdown (manager->priv->client, XFCE_SM_CLIENT_SHUTDOWN_HINT_ASK);
+ if ( manager->priv->session_managed )
+ xfce_sm_client_request_shutdown (manager->priv->client, XFCE_SM_CLIENT_SHUTDOWN_HINT_ASK);
}
static void
xfpm_manager_sleep_request (XfpmManager *manager, XfpmShutdownRequest req, gboolean force)
{
- switch (req)
- {
- case XFPM_DO_NOTHING:
- break;
- case XFPM_DO_SUSPEND:
- xfpm_power_suspend (manager->priv->power, force);
- break;
- case XFPM_DO_HIBERNATE:
- xfpm_power_hibernate (manager->priv->power, force);
- break;
- case XFPM_DO_SHUTDOWN:
- xfpm_manager_shutdown (manager);
- break;
- case XFPM_ASK:
- xfpm_manager_ask_shutdown (manager);
- break;
- default:
- g_warn_if_reached ();
- break;
- }
+ switch (req)
+ {
+ case XFPM_DO_NOTHING:
+ break;
+ case XFPM_DO_SUSPEND:
+ xfpm_power_suspend (manager->priv->power, force);
+ break;
+ case XFPM_DO_HIBERNATE:
+ xfpm_power_hibernate (manager->priv->power, force);
+ break;
+ case XFPM_DO_SHUTDOWN:
+ xfpm_manager_shutdown (manager);
+ break;
+ case XFPM_ASK:
+ xfpm_manager_ask_shutdown (manager);
+ break;
+ default:
+ g_warn_if_reached ();
+ break;
+ }
}
static void
xfpm_manager_reset_sleep_timer (XfpmManager *manager)
{
- g_timer_reset (manager->priv->timer);
+ g_timer_reset (manager->priv->timer);
}
static void
xfpm_manager_button_pressed_cb (XfpmButton *bt, XfpmButtonKey type, XfpmManager *manager)
{
- XfpmShutdownRequest req = XFPM_DO_NOTHING;
+ XfpmShutdownRequest req = XFPM_DO_NOTHING;
- XFPM_DEBUG_ENUM (type, XFPM_TYPE_BUTTON_KEY, "Received button press event");
+ XFPM_DEBUG_ENUM (type, XFPM_TYPE_BUTTON_KEY, "Received button press event");
- if ( type == BUTTON_MON_BRIGHTNESS_DOWN || type == BUTTON_MON_BRIGHTNESS_UP )
- return;
+ if ( type == BUTTON_MON_BRIGHTNESS_DOWN || type == BUTTON_MON_BRIGHTNESS_UP )
+ return;
- if ( type == BUTTON_KBD_BRIGHTNESS_DOWN || type == BUTTON_KBD_BRIGHTNESS_UP )
- return;
+ if ( type == BUTTON_KBD_BRIGHTNESS_DOWN || type == BUTTON_KBD_BRIGHTNESS_UP )
+ return;
- if ( type == BUTTON_POWER_OFF )
- {
- g_object_get (G_OBJECT (manager->priv->conf),
- POWER_SWITCH_CFG, &req,
- NULL);
- }
- else if ( type == BUTTON_SLEEP )
- {
- g_object_get (G_OBJECT (manager->priv->conf),
- SLEEP_SWITCH_CFG, &req,
- NULL);
- }
- else if ( type == BUTTON_HIBERNATE )
- {
- g_object_get (G_OBJECT (manager->priv->conf),
- HIBERNATE_SWITCH_CFG, &req,
- NULL);
- }
- else if ( type == BUTTON_BATTERY )
- {
- g_object_get (G_OBJECT (manager->priv->conf),
- BATTERY_SWITCH_CFG, &req,
- NULL);
- }
- else
+ if ( type == BUTTON_POWER_OFF )
+ {
+ g_object_get (G_OBJECT (manager->priv->conf),
+ POWER_SWITCH_CFG, &req,
+ NULL);
+ }
+ else if ( type == BUTTON_SLEEP )
+ {
+ g_object_get (G_OBJECT (manager->priv->conf),
+ SLEEP_SWITCH_CFG, &req,
+ NULL);
+ }
+ else if ( type == BUTTON_HIBERNATE )
{
- g_return_if_reached ();
- }
-
- XFPM_DEBUG_ENUM (req, XFPM_TYPE_SHUTDOWN_REQUEST, "Shutdown request : ");
-
- if ( req == XFPM_ASK )
- xfpm_manager_ask_shutdown (manager);
- else
+ g_object_get (G_OBJECT (manager->priv->conf),
+ HIBERNATE_SWITCH_CFG, &req,
+ NULL);
+ }
+ else if ( type == BUTTON_BATTERY )
+ {
+ g_object_get (G_OBJECT (manager->priv->conf),
+ BATTERY_SWITCH_CFG, &req,
+ NULL);
+ }
+ else
+ {
+ g_return_if_reached ();
+ }
+
+ XFPM_DEBUG_ENUM (req, XFPM_TYPE_SHUTDOWN_REQUEST, "Shutdown request : ");
+
+ if ( req == XFPM_ASK )
+ xfpm_manager_ask_shutdown (manager);
+ else
+ {
+ if ( g_timer_elapsed (manager->priv->timer, NULL) > SLEEP_KEY_TIMEOUT )
{
- if ( g_timer_elapsed (manager->priv->timer, NULL) > SLEEP_KEY_TIMEOUT )
- {
- g_timer_reset (manager->priv->timer);
- xfpm_manager_sleep_request (manager, req, FALSE);
- }
+ g_timer_reset (manager->priv->timer);
+ xfpm_manager_sleep_request (manager, req, FALSE);
}
+ }
}
static void
xfpm_manager_lid_changed_cb (XfpmPower *power, gboolean lid_is_closed, XfpmManager *manager)
{
- XfpmLidTriggerAction action;
- gboolean on_battery, logind_handle_lid_switch;
+ XfpmLidTriggerAction action;
+ gboolean on_battery, logind_handle_lid_switch;
- if ( LOGIND_RUNNING() )
- {
- g_object_get (G_OBJECT (manager->priv->conf),
- LOGIND_HANDLE_LID_SWITCH, &logind_handle_lid_switch,
- NULL);
+ if ( LOGIND_RUNNING() )
+ {
+ g_object_get (G_OBJECT (manager->priv->conf),
+ LOGIND_HANDLE_LID_SWITCH, &logind_handle_lid_switch,
+ NULL);
- if (logind_handle_lid_switch)
- return;
- }
+ if (logind_handle_lid_switch)
+ return;
+ }
- g_object_get (G_OBJECT (power),
- "on-battery", &on_battery,
- NULL);
+ g_object_get (G_OBJECT (power),
+ "on-battery", &on_battery,
+ NULL);
- g_object_get (G_OBJECT (manager->priv->conf),
- on_battery ? LID_SWITCH_ON_BATTERY_CFG : LID_SWITCH_ON_AC_CFG, &action,
- NULL);
+ g_object_get (G_OBJECT (manager->priv->conf),
+ on_battery ? LID_SWITCH_ON_BATTERY_CFG : LID_SWITCH_ON_AC_CFG, &action,
+ NULL);
- if ( lid_is_closed )
- {
- XFPM_DEBUG_ENUM (action, XFPM_TYPE_LID_TRIGGER_ACTION, "LID close event");
-
- if ( action == LID_TRIGGER_NOTHING )
- {
- if ( !xfpm_is_multihead_connected () )
- xfpm_dpms_force_level (manager->priv->dpms, DPMSModeOff);
- }
- else if ( action == LID_TRIGGER_LOCK_SCREEN )
- {
- if ( !xfpm_is_multihead_connected () )
- {
- if (!xfce_screensaver_lock (manager->priv->screensaver))
- {
- xfce_dialog_show_error (NULL, NULL,
- _("None of the screen lock tools ran "
- "successfully, the screen will not "
- "be locked."));
- }
- }
- }
- else
- {
- /*
- * Force sleep here as lid is closed and no point of asking the
- * user for confirmation in case of an application is inhibiting
- * the power manager.
- */
- xfpm_manager_sleep_request (manager, action, TRUE);
- }
+ if ( lid_is_closed )
+ {
+ XFPM_DEBUG_ENUM (action, XFPM_TYPE_LID_TRIGGER_ACTION, "LID close event");
+ if ( action == LID_TRIGGER_NOTHING )
+ {
+ if ( !xfpm_is_multihead_connected () )
+ xfpm_dpms_force_level (manager->priv->dpms, DPMSModeOff);
+ }
+ else if ( action == LID_TRIGGER_LOCK_SCREEN )
+ {
+ if ( !xfpm_is_multihead_connected () )
+ {
+ if (!xfce_screensaver_lock (manager->priv->screensaver))
+ {
+ xfce_dialog_show_error (NULL, NULL,
+ _("None of the screen lock tools ran "
+ "successfully, the screen will not "
+ "be locked."));
+ }
+ }
}
else
{
- XFPM_DEBUG_ENUM (action, XFPM_TYPE_LID_TRIGGER_ACTION, "LID opened");
-
- xfpm_dpms_force_level (manager->priv->dpms, DPMSModeOn);
+ /*
+ * Force sleep here as lid is closed and no point of asking the
+ * user for confirmation in case of an application is inhibiting
+ * the power manager.
+ */
+ xfpm_manager_sleep_request (manager, action, TRUE);
}
+ }
+ else
+ {
+ XFPM_DEBUG_ENUM (action, XFPM_TYPE_LID_TRIGGER_ACTION, "LID opened");
+
+ xfpm_dpms_force_level (manager->priv->dpms, DPMSModeOn);
+ }
}
static void
xfpm_manager_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmManager *manager)
{
- manager->priv->inhibited = inhibited;
+ manager->priv->inhibited = inhibited;
}
static void
xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager)
{
- if (xfpm_power_is_in_presentation_mode (manager->priv->power) == TRUE)
- return;
+ if (xfpm_power_is_in_presentation_mode (manager->priv->power) == TRUE)
+ return;
+
+ XFPM_DEBUG ("Alarm inactivity timeout id %d", id);
- XFPM_DEBUG ("Alarm inactivity timeout id %d", id);
+ if ( id == TIMEOUT_INACTIVITY_ON_AC || id == TIMEOUT_INACTIVITY_ON_BATTERY )
+ {
+ XfpmShutdownRequest sleep_mode = XFPM_DO_NOTHING;
+ gboolean on_battery;
- if ( id == TIMEOUT_INACTIVITY_ON_AC || id == TIMEOUT_INACTIVITY_ON_BATTERY )
+ if ( manager->priv->inhibited )
{
- XfpmShutdownRequest sleep_mode = XFPM_DO_NOTHING;
- gboolean on_battery;
-
- if ( manager->priv->inhibited )
- {
- XFPM_DEBUG ("Idle sleep alarm timeout, but power manager is currently inhibited, action ignored");
- return;
- }
-
- if ( id == TIMEOUT_INACTIVITY_ON_AC)
- g_object_get (G_OBJECT (manager->priv->conf),
- INACTIVITY_SLEEP_MODE_ON_AC, &sleep_mode,
- NULL);
- else
- g_object_get (G_OBJECT (manager->priv->conf),
- INACTIVITY_SLEEP_MODE_ON_BATTERY, &sleep_mode,
- NULL);
-
- g_object_get (G_OBJECT (manager->priv->power),
- "on-battery", &on_battery,
- NULL);
-
- if ( id == TIMEOUT_INACTIVITY_ON_AC && on_battery == FALSE )
- xfpm_manager_sleep_request (manager, sleep_mode, FALSE);
- else if ( id == TIMEOUT_INACTIVITY_ON_BATTERY && on_battery )
- xfpm_manager_sleep_request (manager, sleep_mode, FALSE);
+ XFPM_DEBUG ("Idle sleep alarm timeout, but power manager is currently inhibited, action ignored");
+ return;
}
+
+ if ( id == TIMEOUT_INACTIVITY_ON_AC)
+ g_object_get (G_OBJECT (manager->priv->conf),
+ INACTIVITY_SLEEP_MODE_ON_AC, &sleep_mode,
+ NULL);
+ else
+ g_object_get (G_OBJECT (manager->priv->conf),
+ INACTIVITY_SLEEP_MODE_ON_BATTERY, &sleep_mode,
+ NULL);
+
+ g_object_get (G_OBJECT (manager->priv->power),
+ "on-battery", &on_battery,
+ NULL);
+
+ if ( id == TIMEOUT_INACTIVITY_ON_AC && on_battery == FALSE )
+ xfpm_manager_sleep_request (manager, sleep_mode, FALSE);
+ else if ( id == TIMEOUT_INACTIVITY_ON_BATTERY && on_battery )
+ xfpm_manager_sleep_request (manager, sleep_mode, FALSE);
+ }
}
static void
xfpm_manager_set_idle_alarm_on_ac (XfpmManager *manager)
{
- guint on_ac;
+ guint on_ac;
- g_object_get (G_OBJECT (manager->priv->conf),
- ON_AC_INACTIVITY_TIMEOUT, &on_ac,
- NULL);
+ g_object_get (G_OBJECT (manager->priv->conf),
+ ON_AC_INACTIVITY_TIMEOUT, &on_ac,
+ NULL);
#ifdef DEBUG
- if ( on_ac == 14 )
- TRACE ("setting inactivity sleep timeout on ac to never");
- else
- TRACE ("setting inactivity sleep timeout on ac to %d", on_ac);
+ if ( on_ac == 14 )
+ TRACE ("setting inactivity sleep timeout on ac to never");
+ else
+ TRACE ("setting inactivity sleep timeout on ac to %d", on_ac);
#endif
- if ( on_ac == 14 )
- {
- egg_idletime_alarm_remove (manager->priv->idle, TIMEOUT_INACTIVITY_ON_AC );
- }
- else
- {
- egg_idletime_alarm_set (manager->priv->idle, TIMEOUT_INACTIVITY_ON_AC, on_ac * 1000 * 60);
- }
+ if ( on_ac == 14 )
+ {
+ egg_idletime_alarm_remove (manager->priv->idle, TIMEOUT_INACTIVITY_ON_AC );
+ }
+ else
+ {
+ egg_idletime_alarm_set (manager->priv->idle, TIMEOUT_INACTIVITY_ON_AC, on_ac * 1000 * 60);
+ }
}
static void
xfpm_manager_set_idle_alarm_on_battery (XfpmManager *manager)
{
- guint on_battery;
+ guint on_battery;
- g_object_get (G_OBJECT (manager->priv->conf),
- ON_BATTERY_INACTIVITY_TIMEOUT, &on_battery,
- NULL);
+ g_object_get (G_OBJECT (manager->priv->conf),
+ ON_BATTERY_INACTIVITY_TIMEOUT, &on_battery,
+ NULL);
#ifdef DEBUG
- if ( on_battery == 14 )
- TRACE ("setting inactivity sleep timeout on battery to never");
- else
- TRACE ("setting inactivity sleep timeout on battery to %d", on_battery);
+ if ( on_battery == 14 )
+ TRACE ("setting inactivity sleep timeout on battery to never");
+ else
+ TRACE ("setting inactivity sleep timeout on battery to %d", on_battery);
#endif
- if ( on_battery == 14 )
- {
- egg_idletime_alarm_remove (manager->priv->idle, TIMEOUT_INACTIVITY_ON_BATTERY );
- }
- else
- {
- egg_idletime_alarm_set (manager->priv->idle, TIMEOUT_INACTIVITY_ON_BATTERY, on_battery * 1000 * 60);
- }
+ if ( on_battery == 14 )
+ {
+ egg_idletime_alarm_remove (manager->priv->idle, TIMEOUT_INACTIVITY_ON_BATTERY );
+ }
+ else
+ {
+ egg_idletime_alarm_set (manager->priv->idle, TIMEOUT_INACTIVITY_ON_BATTERY, on_battery * 1000 * 60);
+ }
}
static void
xfpm_manager_on_battery_changed_cb (XfpmPower *power, gboolean on_battery, XfpmManager *manager)
{
- egg_idletime_alarm_reset_all (manager->priv->idle);
+ egg_idletime_alarm_reset_all (manager->priv->idle);
}
static void
xfpm_manager_set_idle_alarm (XfpmManager *manager)
{
- xfpm_manager_set_idle_alarm_on_ac (manager);
- xfpm_manager_set_idle_alarm_on_battery (manager);
-
+ xfpm_manager_set_idle_alarm_on_ac (manager);
+ xfpm_manager_set_idle_alarm_on_battery (manager);
}
static gchar*
xfpm_manager_get_systemd_events(XfpmManager *manager)
{
- GSList *events = NULL;
- gchar *what = "";
- gboolean logind_handle_power_key, logind_handle_suspend_key, logind_handle_hibernate_key, logind_handle_lid_switch;
-
- g_object_get (G_OBJECT (manager->priv->conf),
- LOGIND_HANDLE_POWER_KEY, &logind_handle_power_key,
- LOGIND_HANDLE_SUSPEND_KEY, &logind_handle_suspend_key,
- LOGIND_HANDLE_HIBERNATE_KEY, &logind_handle_hibernate_key,
- LOGIND_HANDLE_LID_SWITCH, &logind_handle_lid_switch,
- NULL);
-
- if (!logind_handle_power_key)
- events = g_slist_append(events, "handle-power-key");
- if (!logind_handle_suspend_key)
- events = g_slist_append(events, "handle-suspend-key");
- if (!logind_handle_hibernate_key)
- events = g_slist_append(events, "handle-hibernate-key");
- if (!logind_handle_lid_switch)
- events = g_slist_append(events, "handle-lid-switch");
-
- while (events != NULL)
- {
- if ( g_strcmp0(what, "") == 0 )
- what = g_strdup( (gchar *) events->data );
- else
- what = g_strconcat(what, ":", (gchar *) events->data, NULL);
- events = g_slist_next(events);
- }
- g_slist_free(events);
+ GSList *events = NULL;
+ gchar *what = "";
+ gboolean logind_handle_power_key, logind_handle_suspend_key, logind_handle_hibernate_key, logind_handle_lid_switch;
+
+ g_object_get (G_OBJECT (manager->priv->conf),
+ LOGIND_HANDLE_POWER_KEY, &logind_handle_power_key,
+ LOGIND_HANDLE_SUSPEND_KEY, &logind_handle_suspend_key,
+ LOGIND_HANDLE_HIBERNATE_KEY, &logind_handle_hibernate_key,
+ LOGIND_HANDLE_LID_SWITCH, &logind_handle_lid_switch,
+ NULL);
+
+ if (!logind_handle_power_key)
+ events = g_slist_append(events, "handle-power-key");
+ if (!logind_handle_suspend_key)
+ events = g_slist_append(events, "handle-suspend-key");
+ if (!logind_handle_hibernate_key)
+ events = g_slist_append(events, "handle-hibernate-key");
+ if (!logind_handle_lid_switch)
+ events = g_slist_append(events, "handle-lid-switch");
+
+ while (events != NULL)
+ {
+ if ( g_strcmp0 (what, "") == 0 )
+ what = g_strdup ( (gchar *) events->data );
+ else
+ what = g_strconcat (what, ":", (gchar *) events->data, NULL);
+ events = g_slist_next (events);
+ }
+ g_slist_free(events);
- return what;
+ return what;
}
static gint
xfpm_manager_inhibit_sleep_systemd (XfpmManager *manager)
{
- GDBusConnection *bus_connection;
- GVariant *reply;
- GError *error = NULL;
- GUnixFDList *fd_list = NULL;
- gint fd = -1;
- char *what = xfpm_manager_get_systemd_events(manager);
- const char *who = "xfce4-power-manager";
- const char *why = "xfce4-power-manager handles these events";
- const char *mode = "block";
-
- if (g_strcmp0(what, "") == 0)
- return -1;
-
- if (!(LOGIND_RUNNING()))
- return -1;
-
- XFPM_DEBUG ("Inhibiting systemd sleep: %s", what);
-
- bus_connection = manager->priv->system_bus;
- if (!xfpm_dbus_name_has_owner (bus_connection, "org.freedesktop.login1"))
- return -1;
-
- reply = g_dbus_connection_call_with_unix_fd_list_sync (bus_connection,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Inhibit",
- g_variant_new ("(ssss)",
- what, who, why, mode),
- G_VARIANT_TYPE ("(h)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &fd_list,
- NULL,
- &error);
-
- if (!reply)
- {
- g_warning ("Unable to inhibit systemd sleep: %s", error->message);
- g_error_free (error);
- return -1;
- }
+ GDBusConnection *bus_connection;
+ GVariant *reply;
+ GError *error = NULL;
+ GUnixFDList *fd_list = NULL;
+ gint fd = -1;
+ char *what = xfpm_manager_get_systemd_events(manager);
+ const char *who = "xfce4-power-manager";
+ const char *why = "xfce4-power-manager handles these events";
+ const char *mode = "block";
+
+ if (g_strcmp0(what, "") == 0)
+ return -1;
+
+ if (!(LOGIND_RUNNING()))
+ return -1;
+
+ XFPM_DEBUG ("Inhibiting systemd sleep: %s", what);
+
+ bus_connection = manager->priv->system_bus;
+ if (!xfpm_dbus_name_has_owner (bus_connection, "org.freedesktop.login1"))
+ return -1;
+
+ reply = g_dbus_connection_call_with_unix_fd_list_sync (bus_connection,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "Inhibit",
+ g_variant_new ("(ssss)",
+ what, who, why, mode),
+ G_VARIANT_TYPE ("(h)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &fd_list,
+ NULL,
+ &error);
+
+ if (!reply)
+ {
+ g_warning ("Unable to inhibit systemd sleep: %s", error->message);
+ g_error_free (error);
+ return -1;
+ }
- g_variant_unref (reply);
+ g_variant_unref (reply);
- fd = g_unix_fd_list_get (fd_list, 0, &error);
- if (fd == -1)
- {
- g_warning ("Inhibit() reply parsing failed: %s", error->message);
- }
+ fd = g_unix_fd_list_get (fd_list, 0, &error);
+ if (fd == -1)
+ {
+ g_warning ("Inhibit() reply parsing failed: %s", error->message);
+ }
- g_object_unref (fd_list);
+ g_object_unref (fd_list);
- g_error_free (error);
+ g_error_free (error);
- g_free (what);
+ g_free (what);
- return fd;
+ return fd;
}
static void
xfpm_manager_systemd_events_changed (XfpmManager *manager)
{
- if (manager->priv->inhibit_fd >= 0)
- close (manager->priv->inhibit_fd);
+ if (manager->priv->inhibit_fd >= 0)
+ close (manager->priv->inhibit_fd);
- if (manager->priv->system_bus)
- manager->priv->inhibit_fd = xfpm_manager_inhibit_sleep_systemd (manager);
+ if (manager->priv->system_bus)
+ manager->priv->inhibit_fd = xfpm_manager_inhibit_sleep_systemd (manager);
}
static void
xfpm_manager_tray_update_tooltip (PowerManagerButton *button, XfpmManager *manager)
{
- g_return_if_fail (XFPM_IS_MANAGER (manager));
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (manager->priv->power_button));
- g_return_if_fail (GTK_IS_STATUS_ICON (manager->priv->adapter_icon));
+ g_return_if_fail (XFPM_IS_MANAGER (manager));
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (manager->priv->power_button));
+ g_return_if_fail (GTK_IS_STATUS_ICON (manager->priv->adapter_icon));
- XFPM_DEBUG ("updating tooltip");
+ XFPM_DEBUG ("updating tooltip");
- if (power_manager_button_get_tooltip (POWER_MANAGER_BUTTON(manager->priv->power_button)) == NULL)
- return;
+ if (power_manager_button_get_tooltip (POWER_MANAGER_BUTTON(manager->priv->power_button)) == NULL)
+ return;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_status_icon_set_tooltip_markup (manager->priv->adapter_icon, power_manager_button_get_tooltip (POWER_MANAGER_BUTTON(manager->priv->power_button)));
+ gtk_status_icon_set_tooltip_markup (manager->priv->adapter_icon, power_manager_button_get_tooltip (POWER_MANAGER_BUTTON(manager->priv->power_button)));
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
xfpm_manager_tray_update_icon (PowerManagerButton *button, XfpmManager *manager)
{
- g_return_if_fail (XFPM_IS_MANAGER (manager));
- g_return_if_fail (POWER_MANAGER_IS_BUTTON (manager->priv->power_button));
+ g_return_if_fail (XFPM_IS_MANAGER (manager));
+ g_return_if_fail (POWER_MANAGER_IS_BUTTON (manager->priv->power_button));
- XFPM_DEBUG ("updating icon");
+ XFPM_DEBUG ("updating icon");
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_status_icon_set_from_icon_name (manager->priv->adapter_icon, power_manager_button_get_icon_name (POWER_MANAGER_BUTTON(manager->priv->power_button)));
+ gtk_status_icon_set_from_icon_name (manager->priv->adapter_icon, power_manager_button_get_icon_name (POWER_MANAGER_BUTTON(manager->priv->power_button)));
G_GNUC_END_IGNORE_DEPRECATIONS
}
static void
xfpm_manager_show_tray_menu (GtkStatusIcon *icon, guint button, guint activate_time, XfpmManager *manager)
{
- power_manager_button_show_menu (POWER_MANAGER_BUTTON(manager->priv->power_button));
+ power_manager_button_show_menu (POWER_MANAGER_BUTTON(manager->priv->power_button));
}
static void
xfpm_manager_show_tray_icon (XfpmManager *manager)
{
- if (manager->priv->adapter_icon != NULL) {
- XFPM_DEBUG ("tray icon already being shown");
- return;
- }
+ if (manager->priv->adapter_icon != NULL)
+ {
+ XFPM_DEBUG ("tray icon already being shown");
+ return;
+ }
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- manager->priv->adapter_icon = gtk_status_icon_new ();
- manager->priv->power_button = power_manager_button_new ();
+ manager->priv->adapter_icon = gtk_status_icon_new ();
+ manager->priv->power_button = power_manager_button_new ();
G_GNUC_END_IGNORE_DEPRECATIONS
- XFPM_DEBUG ("Showing tray icon");
+ XFPM_DEBUG ("Showing tray icon");
- /* send a show event to startup the button */
- power_manager_button_show (POWER_MANAGER_BUTTON(manager->priv->power_button));
+ /* send a show event to startup the button */
+ power_manager_button_show (POWER_MANAGER_BUTTON(manager->priv->power_button));
- /* initial update the tray icon + tooltip */
- xfpm_manager_tray_update_icon (POWER_MANAGER_BUTTON(manager->priv->power_button), manager);
- xfpm_manager_tray_update_tooltip (POWER_MANAGER_BUTTON(manager->priv->power_button), manager);
+ /* initial update the tray icon + tooltip */
+ xfpm_manager_tray_update_icon (POWER_MANAGER_BUTTON(manager->priv->power_button), manager);
+ xfpm_manager_tray_update_tooltip (POWER_MANAGER_BUTTON(manager->priv->power_button), manager);
- /* Listen to the tooltip and icon changes */
- g_signal_connect (G_OBJECT(manager->priv->power_button), "tooltip-changed", G_CALLBACK(xfpm_manager_tray_update_tooltip), manager);
- g_signal_connect (G_OBJECT(manager->priv->power_button), "icon-name-changed", G_CALLBACK(xfpm_manager_tray_update_icon), manager);
+ /* Listen to the tooltip and icon changes */
+ g_signal_connect (G_OBJECT(manager->priv->power_button), "tooltip-changed", G_CALLBACK(xfpm_manager_tray_update_tooltip), manager);
+ g_signal_connect (G_OBJECT(manager->priv->power_button), "icon-name-changed", G_CALLBACK(xfpm_manager_tray_update_icon), manager);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_status_icon_set_visible (manager->priv->adapter_icon, TRUE);
+ gtk_status_icon_set_visible (manager->priv->adapter_icon, TRUE);
G_GNUC_END_IGNORE_DEPRECATIONS
- g_signal_connect (manager->priv->adapter_icon, "popup-menu", G_CALLBACK (xfpm_manager_show_tray_menu), manager);
+ g_signal_connect (manager->priv->adapter_icon, "popup-menu", G_CALLBACK (xfpm_manager_show_tray_menu), manager);
}
static void
xfpm_manager_hide_tray_icon (XfpmManager *manager)
{
- if (manager->priv->adapter_icon == NULL)
- return;
+ if (manager->priv->adapter_icon == NULL)
+ return;
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- gtk_status_icon_set_visible (manager->priv->adapter_icon, FALSE);
+ gtk_status_icon_set_visible (manager->priv->adapter_icon, FALSE);
G_GNUC_END_IGNORE_DEPRECATIONS
/* disconnect from all the signals */
- g_signal_handlers_disconnect_by_func (G_OBJECT(manager->priv->power_button), G_CALLBACK(xfpm_manager_tray_update_tooltip), manager);
- g_signal_handlers_disconnect_by_func (G_OBJECT(manager->priv->power_button), G_CALLBACK(xfpm_manager_tray_update_icon), manager);
- g_signal_handlers_disconnect_by_func (G_OBJECT(manager->priv->adapter_icon), G_CALLBACK(xfpm_manager_show_tray_menu), manager);
+ g_signal_handlers_disconnect_by_func (G_OBJECT(manager->priv->power_button), G_CALLBACK(xfpm_manager_tray_update_tooltip), manager);
+ g_signal_handlers_disconnect_by_func (G_OBJECT(manager->priv->power_button), G_CALLBACK(xfpm_manager_tray_update_icon), manager);
+ g_signal_handlers_disconnect_by_func (G_OBJECT(manager->priv->adapter_icon), G_CALLBACK(xfpm_manager_show_tray_menu), manager);
- g_object_unref (manager->priv->power_button);
- g_object_unref (manager->priv->adapter_icon);
+ g_object_unref (manager->priv->power_button);
+ g_object_unref (manager->priv->adapter_icon);
- manager->priv->power_button = NULL;
- manager->priv->adapter_icon = NULL;
+ manager->priv->power_button = NULL;
+ manager->priv->adapter_icon = NULL;
}
XfpmManager *
xfpm_manager_new (GDBusConnection *bus, const gchar *client_id)
{
- XfpmManager *manager = NULL;
- GError *error = NULL;
- gchar *current_dir;
+ XfpmManager *manager = NULL;
+ GError *error = NULL;
+ gchar *current_dir;
- const gchar *restart_command[] =
- {
- "xfce4-power-manager",
- "--restart",
- NULL
- };
+ const gchar *restart_command[] =
+ {
+ "xfce4-power-manager",
+ "--restart",
+ NULL
+ };
- manager = g_object_new (XFPM_TYPE_MANAGER, NULL);
+ manager = g_object_new (XFPM_TYPE_MANAGER, NULL);
- manager->priv->session_bus = bus;
+ manager->priv->session_bus = bus;
- current_dir = g_get_current_dir ();
- manager->priv->client = xfce_sm_client_get_full (XFCE_SM_CLIENT_RESTART_NORMAL,
- XFCE_SM_CLIENT_PRIORITY_DEFAULT,
- client_id,
- current_dir,
- restart_command,
- SYSCONFDIR "/xdg/autostart/" PACKAGE_NAME ".desktop");
+ current_dir = g_get_current_dir ();
+ manager->priv->client = xfce_sm_client_get_full (XFCE_SM_CLIENT_RESTART_NORMAL,
+ XFCE_SM_CLIENT_PRIORITY_DEFAULT,
+ client_id,
+ current_dir,
+ restart_command,
+ SYSCONFDIR "/xdg/autostart/" PACKAGE_NAME ".desktop");
- g_free (current_dir);
+ g_free (current_dir);
- manager->priv->session_managed = xfce_sm_client_connect (manager->priv->client, &error);
+ manager->priv->session_managed = xfce_sm_client_connect (manager->priv->client, &error);
- if ( error )
- {
- g_warning ("Unable to connect to session manager : %s", error->message);
- g_error_free (error);
- }
- else
- {
- g_signal_connect_swapped (manager->priv->client, "quit",
- G_CALLBACK (xfpm_manager_quit), manager);
- }
+ if ( error )
+ {
+ g_warning ("Unable to connect to session manager : %s", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ g_signal_connect_swapped (manager->priv->client, "quit",
+ G_CALLBACK (xfpm_manager_quit), manager);
+ }
- xfpm_manager_dbus_class_init (XFPM_MANAGER_GET_CLASS (manager));
- xfpm_manager_dbus_init (manager);
+ xfpm_manager_dbus_class_init (XFPM_MANAGER_GET_CLASS (manager));
+ xfpm_manager_dbus_init (manager);
- return manager;
+ return manager;
}
void xfpm_manager_start (XfpmManager *manager)
{
- GError *error = NULL;
+ GError *error = NULL;
- if ( !xfpm_manager_reserve_names (manager) )
- goto out;
+ if ( !xfpm_manager_reserve_names (manager) )
+ goto out;
- manager->priv->power = xfpm_power_get ();
- manager->priv->button = xfpm_button_new ();
- manager->priv->conf = xfpm_xfconf_new ();
- manager->priv->screensaver = xfce_screensaver_new ();
- manager->priv->console = NULL;
- manager->priv->systemd = NULL;
+ manager->priv->power = xfpm_power_get ();
+ manager->priv->button = xfpm_button_new ();
+ manager->priv->conf = xfpm_xfconf_new ();
+ manager->priv->screensaver = xfce_screensaver_new ();
+ manager->priv->console = NULL;
+ manager->priv->systemd = NULL;
- if ( LOGIND_RUNNING () )
- manager->priv->systemd = xfpm_systemd_new ();
- else
- manager->priv->console = xfpm_console_kit_new ();
+ if ( LOGIND_RUNNING () )
+ manager->priv->systemd = xfpm_systemd_new ();
+ else
+ manager->priv->console = xfpm_console_kit_new ();
- manager->priv->monitor = xfpm_dbus_monitor_new ();
- manager->priv->inhibit = xfpm_inhibit_new ();
- manager->priv->idle = egg_idletime_new ();
+ manager->priv->monitor = xfpm_dbus_monitor_new ();
+ manager->priv->inhibit = xfpm_inhibit_new ();
+ manager->priv->idle = egg_idletime_new ();
/* Don't allow systemd to handle power/suspend/hibernate buttons
* and lid-switch */
- manager->priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
- if (manager->priv->system_bus)
- manager->priv->inhibit_fd = xfpm_manager_inhibit_sleep_systemd (manager);
- else
- {
- g_warning ("Unable connect to system bus: %s", error->message);
- g_clear_error (&error);
- }
-
- g_signal_connect (manager->priv->idle, "alarm-expired",
- G_CALLBACK (xfpm_manager_alarm_timeout_cb), manager);
-
- g_signal_connect_swapped (manager->priv->conf, "notify::" ON_AC_INACTIVITY_TIMEOUT,
- G_CALLBACK (xfpm_manager_set_idle_alarm_on_ac), manager);
-
- g_signal_connect_swapped (manager->priv->conf, "notify::" ON_BATTERY_INACTIVITY_TIMEOUT,
- G_CALLBACK (xfpm_manager_set_idle_alarm_on_battery), manager);
-
- g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_POWER_KEY,
- G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
-
- g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_SUSPEND_KEY,
- G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
-
- g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_HIBERNATE_KEY,
- G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
-
- g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_LID_SWITCH,
- G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
-
- xfpm_manager_set_idle_alarm (manager);
-
- g_signal_connect (manager->priv->inhibit, "has-inhibit-changed",
- G_CALLBACK (xfpm_manager_inhibit_changed_cb), manager);
-
- g_signal_connect (manager->priv->monitor, "system-bus-connection-changed",
- G_CALLBACK (xfpm_manager_system_bus_connection_changed_cb), manager);
-
- manager->priv->backlight = xfpm_backlight_new ();
-
- manager->priv->kbd_backlight = xfpm_kbd_backlight_new ();
-
- manager->priv->dpms = xfpm_dpms_new ();
-
- g_signal_connect (manager->priv->button, "button_pressed",
- G_CALLBACK (xfpm_manager_button_pressed_cb), manager);
-
- g_signal_connect (manager->priv->power, "lid-changed",
- G_CALLBACK (xfpm_manager_lid_changed_cb), manager);
-
- g_signal_connect (manager->priv->power, "on-battery-changed",
- G_CALLBACK (xfpm_manager_on_battery_changed_cb), manager);
-
- g_signal_connect_swapped (manager->priv->power, "waking-up",
- G_CALLBACK (xfpm_manager_reset_sleep_timer), manager);
-
- g_signal_connect_swapped (manager->priv->power, "sleeping",
- G_CALLBACK (xfpm_manager_reset_sleep_timer), manager);
-
- g_signal_connect_swapped (manager->priv->power, "ask-shutdown",
- G_CALLBACK (xfpm_manager_ask_shutdown), manager);
-
- g_signal_connect_swapped (manager->priv->power, "shutdown",
- G_CALLBACK (xfpm_manager_shutdown), manager);
-
- xfconf_g_property_bind(xfpm_xfconf_get_channel (manager->priv->conf),
- XFPM_PROPERTIES_PREFIX SHOW_TRAY_ICON_CFG,
- G_TYPE_INT,
- G_OBJECT(manager),
- SHOW_TRAY_ICON_CFG);
+ manager->priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (manager->priv->system_bus)
+ manager->priv->inhibit_fd = xfpm_manager_inhibit_sleep_systemd (manager);
+ else
+ {
+ g_warning ("Unable connect to system bus: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ g_signal_connect (manager->priv->idle, "alarm-expired",
+ G_CALLBACK (xfpm_manager_alarm_timeout_cb), manager);
+ g_signal_connect_swapped (manager->priv->conf, "notify::" ON_AC_INACTIVITY_TIMEOUT,
+ G_CALLBACK (xfpm_manager_set_idle_alarm_on_ac), manager);
+ g_signal_connect_swapped (manager->priv->conf, "notify::" ON_BATTERY_INACTIVITY_TIMEOUT,
+ G_CALLBACK (xfpm_manager_set_idle_alarm_on_battery), manager);
+ g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_POWER_KEY,
+ G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
+ g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_SUSPEND_KEY,
+ G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
+ g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_HIBERNATE_KEY,
+ G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
+ g_signal_connect_swapped (manager->priv->conf, "notify::" LOGIND_HANDLE_LID_SWITCH,
+ G_CALLBACK (xfpm_manager_systemd_events_changed), manager);
+
+ xfpm_manager_set_idle_alarm (manager);
+
+ g_signal_connect (manager->priv->inhibit, "has-inhibit-changed",
+ G_CALLBACK (xfpm_manager_inhibit_changed_cb), manager);
+ g_signal_connect (manager->priv->monitor, "system-bus-connection-changed",
+ G_CALLBACK (xfpm_manager_system_bus_connection_changed_cb), manager);
+
+ manager->priv->backlight = xfpm_backlight_new ();
+
+ manager->priv->kbd_backlight = xfpm_kbd_backlight_new ();
+
+ manager->priv->dpms = xfpm_dpms_new ();
+
+ g_signal_connect (manager->priv->button, "button_pressed",
+ G_CALLBACK (xfpm_manager_button_pressed_cb), manager);
+
+ g_signal_connect (manager->priv->power, "lid-changed",
+ G_CALLBACK (xfpm_manager_lid_changed_cb), manager);
+
+ g_signal_connect (manager->priv->power, "on-battery-changed",
+ G_CALLBACK (xfpm_manager_on_battery_changed_cb), manager);
+
+ g_signal_connect_swapped (manager->priv->power, "waking-up",
+ G_CALLBACK (xfpm_manager_reset_sleep_timer), manager);
+
+ g_signal_connect_swapped (manager->priv->power, "sleeping",
+ G_CALLBACK (xfpm_manager_reset_sleep_timer), manager);
+
+ g_signal_connect_swapped (manager->priv->power, "ask-shutdown",
+ G_CALLBACK (xfpm_manager_ask_shutdown), manager);
+
+ g_signal_connect_swapped (manager->priv->power, "shutdown",
+ G_CALLBACK (xfpm_manager_shutdown), manager);
+
+ xfconf_g_property_bind (xfpm_xfconf_get_channel (manager->priv->conf),
+ XFPM_PROPERTIES_PREFIX SHOW_TRAY_ICON_CFG,
+ G_TYPE_INT,
+ G_OBJECT(manager),
+ SHOW_TRAY_ICON_CFG);
out:
- ;
+ ;
}
void xfpm_manager_stop (XfpmManager *manager)
{
- XFPM_DEBUG ("Stopping");
- g_return_if_fail (XFPM_IS_MANAGER (manager));
- xfpm_manager_quit (manager);
+ XFPM_DEBUG ("Stopping");
+ g_return_if_fail (XFPM_IS_MANAGER (manager));
+ xfpm_manager_quit (manager);
}
GHashTable *xfpm_manager_get_config (XfpmManager *manager)
{
- GHashTable *hash;
-
- guint16 mapped_buttons;
- gboolean auth_hibernate = FALSE;
- gboolean auth_suspend = FALSE;
- gboolean can_suspend = FALSE;
- gboolean can_hibernate = FALSE;
- gboolean has_sleep_button = FALSE;
- gboolean has_hibernate_button = FALSE;
- gboolean has_power_button = FALSE;
- gboolean has_battery_button = FALSE;
- gboolean has_battery = TRUE;
- gboolean has_lcd_brightness = TRUE;
- gboolean can_shutdown = TRUE;
- gboolean has_lid = FALSE;
-
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (manager->priv->systemd),
- "can-shutdown", &can_shutdown,
- NULL);
- }
- else
- {
- g_object_get (G_OBJECT (manager->priv->console),
- "can-shutdown", &can_shutdown,
- NULL);
- }
-
- g_object_get (G_OBJECT (manager->priv->power),
- "auth-suspend", &auth_suspend,
- "auth-hibernate", &auth_hibernate,
- "can-suspend", &can_suspend,
- "can-hibernate", &can_hibernate,
- "has-lid", &has_lid,
- NULL);
-
- has_battery = xfpm_power_has_battery (manager->priv->power);
- has_lcd_brightness = xfpm_backlight_has_hw (manager->priv->backlight);
-
- mapped_buttons = xfpm_button_get_mapped (manager->priv->button);
-
- if ( mapped_buttons & SLEEP_KEY )
- has_sleep_button = TRUE;
- if ( mapped_buttons & HIBERNATE_KEY )
- has_hibernate_button = TRUE;
- if ( mapped_buttons & POWER_KEY )
- has_power_button = TRUE;
- if ( mapped_buttons & BATTERY_KEY )
- has_battery_button = TRUE;
-
- g_hash_table_insert (hash, g_strdup ("sleep-button"), g_strdup (xfpm_bool_to_string (has_sleep_button)));
- g_hash_table_insert (hash, g_strdup ("power-button"), g_strdup (xfpm_bool_to_string (has_power_button)));
- g_hash_table_insert (hash, g_strdup ("hibernate-button"), g_strdup (xfpm_bool_to_string (has_hibernate_button)));
- g_hash_table_insert (hash, g_strdup ("battery-button"), g_strdup (xfpm_bool_to_string (has_battery_button)));
- g_hash_table_insert (hash, g_strdup ("auth-suspend"), g_strdup (xfpm_bool_to_string (auth_suspend)));
- g_hash_table_insert (hash, g_strdup ("auth-hibernate"), g_strdup (xfpm_bool_to_string (auth_hibernate)));
- g_hash_table_insert (hash, g_strdup ("can-suspend"), g_strdup (xfpm_bool_to_string (can_suspend)));
- g_hash_table_insert (hash, g_strdup ("can-hibernate"), g_strdup (xfpm_bool_to_string (can_hibernate)));
- g_hash_table_insert (hash, g_strdup ("can-shutdown"), g_strdup (xfpm_bool_to_string (can_shutdown)));
-
- g_hash_table_insert (hash, g_strdup ("has-battery"), g_strdup (xfpm_bool_to_string (has_battery)));
- g_hash_table_insert (hash, g_strdup ("has-lid"), g_strdup (xfpm_bool_to_string (has_lid)));
-
- g_hash_table_insert (hash, g_strdup ("has-brightness"), g_strdup (xfpm_bool_to_string (has_lcd_brightness)));
-
- return hash;
+ GHashTable *hash;
+
+ guint16 mapped_buttons;
+ gboolean auth_hibernate = FALSE;
+ gboolean auth_suspend = FALSE;
+ gboolean can_suspend = FALSE;
+ gboolean can_hibernate = FALSE;
+ gboolean has_sleep_button = FALSE;
+ gboolean has_hibernate_button = FALSE;
+ gboolean has_power_button = FALSE;
+ gboolean has_battery_button = FALSE;
+ gboolean has_battery = TRUE;
+ gboolean has_lcd_brightness = TRUE;
+ gboolean can_shutdown = TRUE;
+ gboolean has_lid = FALSE;
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (manager->priv->systemd),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (manager->priv->console),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
+
+ g_object_get (G_OBJECT (manager->priv->power),
+ "auth-suspend", &auth_suspend,
+ "auth-hibernate", &auth_hibernate,
+ "can-suspend", &can_suspend,
+ "can-hibernate", &can_hibernate,
+ "has-lid", &has_lid,
+ NULL);
+
+ has_battery = xfpm_power_has_battery (manager->priv->power);
+ has_lcd_brightness = xfpm_backlight_has_hw (manager->priv->backlight);
+
+ mapped_buttons = xfpm_button_get_mapped (manager->priv->button);
+
+ if ( mapped_buttons & SLEEP_KEY )
+ has_sleep_button = TRUE;
+ if ( mapped_buttons & HIBERNATE_KEY )
+ has_hibernate_button = TRUE;
+ if ( mapped_buttons & POWER_KEY )
+ has_power_button = TRUE;
+ if ( mapped_buttons & BATTERY_KEY )
+ has_battery_button = TRUE;
+
+ g_hash_table_insert (hash, g_strdup ("sleep-button"), g_strdup (xfpm_bool_to_string (has_sleep_button)));
+ g_hash_table_insert (hash, g_strdup ("power-button"), g_strdup (xfpm_bool_to_string (has_power_button)));
+ g_hash_table_insert (hash, g_strdup ("hibernate-button"), g_strdup (xfpm_bool_to_string (has_hibernate_button)));
+ g_hash_table_insert (hash, g_strdup ("battery-button"), g_strdup (xfpm_bool_to_string (has_battery_button)));
+ g_hash_table_insert (hash, g_strdup ("auth-suspend"), g_strdup (xfpm_bool_to_string (auth_suspend)));
+ g_hash_table_insert (hash, g_strdup ("auth-hibernate"), g_strdup (xfpm_bool_to_string (auth_hibernate)));
+ g_hash_table_insert (hash, g_strdup ("can-suspend"), g_strdup (xfpm_bool_to_string (can_suspend)));
+ g_hash_table_insert (hash, g_strdup ("can-hibernate"), g_strdup (xfpm_bool_to_string (can_hibernate)));
+ g_hash_table_insert (hash, g_strdup ("can-shutdown"), g_strdup (xfpm_bool_to_string (can_shutdown)));
+
+ g_hash_table_insert (hash, g_strdup ("has-battery"), g_strdup (xfpm_bool_to_string (has_battery)));
+ g_hash_table_insert (hash, g_strdup ("has-lid"), g_strdup (xfpm_bool_to_string (has_lid)));
+
+ g_hash_table_insert (hash, g_strdup ("has-brightness"), g_strdup (xfpm_bool_to_string (has_lcd_brightness)));
+
+ return hash;
}
/*
@@ -1022,20 +1014,20 @@ GHashTable *xfpm_manager_get_config (XfpmManager *manager)
*
*/
static gboolean xfpm_manager_dbus_quit (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_manager_dbus_get_info (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
#include "xfce-power-manager-dbus.h"
@@ -1047,29 +1039,29 @@ xfpm_manager_dbus_class_init (XfpmManagerClass *klass)
static void
xfpm_manager_dbus_init (XfpmManager *manager)
{
- XfpmPowerManager *manager_dbus;
- manager_dbus = xfpm_power_manager_skeleton_new ();
- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager_dbus),
- manager->priv->session_bus,
- "/org/xfce/PowerManager",
- NULL);
-
- g_signal_connect_swapped (manager_dbus,
- "handle-quit",
- G_CALLBACK (xfpm_manager_dbus_quit),
- manager);
- g_signal_connect_swapped (manager_dbus,
- "handle-restart",
- G_CALLBACK (xfpm_manager_dbus_restart),
- manager);
- g_signal_connect_swapped (manager_dbus,
- "handle-get-config",
- G_CALLBACK (xfpm_manager_dbus_get_config),
- manager);
- g_signal_connect_swapped (manager_dbus,
- "handle-get-info",
- G_CALLBACK (xfpm_manager_dbus_get_info),
- manager);
+ XfpmPowerManager *manager_dbus;
+ manager_dbus = xfpm_power_manager_skeleton_new ();
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager_dbus),
+ manager->priv->session_bus,
+ "/org/xfce/PowerManager",
+ NULL);
+
+ g_signal_connect_swapped (manager_dbus,
+ "handle-quit",
+ G_CALLBACK (xfpm_manager_dbus_quit),
+ manager);
+ g_signal_connect_swapped (manager_dbus,
+ "handle-restart",
+ G_CALLBACK (xfpm_manager_dbus_restart),
+ manager);
+ g_signal_connect_swapped (manager_dbus,
+ "handle-get-config",
+ G_CALLBACK (xfpm_manager_dbus_get_config),
+ manager);
+ g_signal_connect_swapped (manager_dbus,
+ "handle-get-info",
+ G_CALLBACK (xfpm_manager_dbus_get_info),
+ manager);
}
static gboolean
@@ -1077,71 +1069,73 @@ xfpm_manager_dbus_quit (XfpmManager *manager,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
- XFPM_DEBUG("Quit message received\n");
+ XFPM_DEBUG("Quit message received\n");
- xfpm_manager_quit (manager);
+ xfpm_manager_quit (manager);
- xfpm_power_manager_complete_quit (user_data, invocation);
+ xfpm_power_manager_complete_quit (user_data, invocation);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_manager_dbus_restart (XfpmManager *manager,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- XFPM_DEBUG("Restart message received");
+ XFPM_DEBUG("Restart message received");
- xfpm_manager_quit (manager);
+ xfpm_manager_quit (manager);
- g_spawn_command_line_async ("xfce4-power-manager", NULL);
+ g_spawn_command_line_async ("xfce4-power-manager", NULL);
- xfpm_power_manager_complete_restart (user_data, invocation);
+ xfpm_power_manager_complete_restart (user_data, invocation);
- return TRUE;
+ return TRUE;
}
static void hash_to_variant (gpointer key, gpointer value, gpointer user_data)
{
- g_variant_builder_add (user_data, "{ss}", key, value);
+ g_variant_builder_add (user_data, "{ss}", key, value);
}
-static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_manager_dbus_get_config (XfpmManager *manager,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- GHashTable *config;
- GVariantBuilder builder;
- GVariant *variant;
+ GHashTable *config;
+ GVariantBuilder builder;
+ GVariant *variant;
- config = xfpm_manager_get_config (manager);
+ config = xfpm_manager_get_config (manager);
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
- g_hash_table_foreach (config, hash_to_variant, &builder);
+ g_hash_table_foreach (config, hash_to_variant, &builder);
- g_hash_table_unref (config);
+ g_hash_table_unref (config);
- variant = g_variant_builder_end (&builder);
+ variant = g_variant_builder_end (&builder);
- xfpm_power_manager_complete_get_config (user_data,
- invocation,
- variant);
+ xfpm_power_manager_complete_get_config (user_data,
+ invocation,
+ variant);
- return TRUE;
+ return TRUE;
}
static gboolean
xfpm_manager_dbus_get_info (XfpmManager *manager,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- xfpm_power_manager_complete_get_info (user_data,
- invocation,
- PACKAGE,
- VERSION,
- "Xfce-goodies");
+ xfpm_power_manager_complete_get_info (user_data,
+ invocation,
+ PACKAGE,
+ VERSION,
+ "Xfce-goodies");
- return TRUE;
+ return TRUE;
}
diff --git a/src/xfpm-manager.h b/src/xfpm-manager.h
index a56840b..7347cc3 100644
--- a/src/xfpm-manager.h
+++ b/src/xfpm-manager.h
@@ -34,27 +34,21 @@ typedef struct XfpmManagerPrivate XfpmManagerPrivate;
typedef struct
{
- GObject parent;
- XfpmManagerPrivate *priv;
-
+ GObject parent;
+ XfpmManagerPrivate *priv;
} XfpmManager;
typedef struct
{
- GObjectClass parent_class;
-
+ GObjectClass parent_class;
} XfpmManagerClass;
-GType xfpm_manager_get_type (void) G_GNUC_CONST;
-
-XfpmManager *xfpm_manager_new (GDBusConnection *bus,
- const gchar *client_id);
-
-void xfpm_manager_start (XfpmManager *manager);
-
-void xfpm_manager_stop (XfpmManager *manager);
-
-GHashTable *xfpm_manager_get_config (XfpmManager *manager);
+GType xfpm_manager_get_type (void) G_GNUC_CONST;
+XfpmManager *xfpm_manager_new (GDBusConnection *bus,
+ const gchar *client_id);
+void xfpm_manager_start (XfpmManager *manager);
+void xfpm_manager_stop (XfpmManager *manager);
+GHashTable *xfpm_manager_get_config (XfpmManager *manager);
G_END_DECLS
diff --git a/src/xfpm-network-manager.c b/src/xfpm-network-manager.c
index 2883665..a9d790f 100644
--- a/src/xfpm-network-manager.c
+++ b/src/xfpm-network-manager.c
@@ -30,47 +30,48 @@
/*
* Inform the Network Manager when we do suspend/hibernate
*/
-gboolean xfpm_network_manager_sleep (gboolean sleep)
+gboolean
+xfpm_network_manager_sleep (gboolean sleep)
{
#ifdef WITH_NETWORK_MANAGER
- GDBusConnection *bus = NULL;
- GDBusProxy *proxy = NULL;
- GError *error = NULL;
+ GDBusConnection *bus = NULL;
+ GDBusProxy *proxy = NULL;
+ GError *error = NULL;
- bus = g_bus_get_sync ( G_BUS_TYPE_SYSTEM, NULL, &error);
+ bus = g_bus_get_sync ( G_BUS_TYPE_SYSTEM, NULL, &error);
- if ( error )
- {
- g_warning("%s", error->message);
- g_error_free (error);
- return FALSE;
- }
+ if ( error )
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
- proxy = g_dbus_proxy_new_sync (bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
- G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
- NULL,
- "org.freedesktop.NetworkManager",
- "/org/freedesktop/NetworkManager",
- "org.freedesktop.NetworkManager",
- NULL,
- NULL);
+ proxy = g_dbus_proxy_new_sync (bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.NetworkManager",
+ "/org/freedesktop/NetworkManager",
+ "org.freedesktop.NetworkManager",
+ NULL,
+ NULL);
- if (!proxy)
- {
- g_warning ("Failed to create proxy for Network Manager interface");
- return FALSE;
- }
+ if (!proxy)
+ {
+ g_warning ("Failed to create proxy for Network Manager interface");
+ return FALSE;
+ }
- g_dbus_proxy_call (proxy, "Sleep", g_variant_new("(b)", sleep),
- G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
- g_object_unref (G_OBJECT(proxy));
- g_object_unref (bus);
+ g_dbus_proxy_call (proxy, "Sleep", g_variant_new("(b)", sleep),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
+ g_object_unref (G_OBJECT(proxy));
+ g_object_unref (bus);
- /* Sleep 0.5 second to allow the nm applet to disconnect*/
- g_usleep (500000);
+ /* Sleep 0.5 second to allow the nm applet to disconnect*/
+ g_usleep (500000);
#endif /* WITH_NETWORK_MANAGER */
- return TRUE;
+ return TRUE;
}
diff --git a/src/xfpm-network-manager.h b/src/xfpm-network-manager.h
index 51d0987..05f32f8 100644
--- a/src/xfpm-network-manager.h
+++ b/src/xfpm-network-manager.h
@@ -23,7 +23,7 @@
G_BEGIN_DECLS
-gboolean xfpm_network_manager_sleep (gboolean sleep);
+gboolean xfpm_network_manager_sleep (gboolean sleep);
G_END_DECLS
diff --git a/src/xfpm-notify.c b/src/xfpm-notify.c
index fc19d85..997021f 100644
--- a/src/xfpm-notify.c
+++ b/src/xfpm-notify.c
@@ -49,30 +49,30 @@
static void xfpm_notify_finalize (GObject *object);
static NotifyNotification * xfpm_notify_new_notification_internal (const gchar *title,
- const gchar *message,
- const gchar *icon_name,
- guint timeout,
- XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
+ const gchar *message,
+ const gchar *icon_name,
+ guint timeout,
+ XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
struct XfpmNotifyPrivate
{
- XfpmDBusMonitor *monitor;
+ XfpmDBusMonitor *monitor;
- NotifyNotification *notification;
- NotifyNotification *critical;
+ NotifyNotification *notification;
+ NotifyNotification *critical;
- gulong critical_id;
- gulong notify_id;
+ gulong critical_id;
+ gulong notify_id;
- gboolean supports_actions;
- gboolean supports_sync; /* For x-canonical-private-synchronous */
+ gboolean supports_actions;
+ gboolean supports_sync; /* For x-canonical-private-synchronous */
};
enum
{
- PROP_0,
- PROP_ACTIONS,
- PROP_SYNC
+ PROP_0,
+ PROP_ACTIONS,
+ PROP_SYNC
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmNotify, xfpm_notify, G_TYPE_OBJECT)
@@ -80,297 +80,304 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmNotify, xfpm_notify, G_TYPE_OBJECT)
static void
xfpm_notify_get_server_caps (XfpmNotify *notify)
{
- GList *caps = NULL;
- notify->priv->supports_actions = FALSE;
- notify->priv->supports_sync = FALSE;
+ GList *caps = NULL;
+ notify->priv->supports_actions = FALSE;
+ notify->priv->supports_sync = FALSE;
- caps = notify_get_server_caps ();
+ caps = notify_get_server_caps ();
- if (caps != NULL)
- {
- if (g_list_find_custom (caps, "x-canonical-private-synchronous", (GCompareFunc) g_strcmp0) != NULL)
- notify->priv->supports_sync = TRUE;
+ if (caps != NULL)
+ {
+ if (g_list_find_custom (caps, "x-canonical-private-synchronous", (GCompareFunc) g_strcmp0) != NULL)
+ notify->priv->supports_sync = TRUE;
- if (g_list_find_custom (caps, "actions", (GCompareFunc) g_strcmp0) != NULL)
- notify->priv->supports_actions = TRUE;
+ if (g_list_find_custom (caps, "actions", (GCompareFunc) g_strcmp0) != NULL)
+ notify->priv->supports_actions = TRUE;
- g_list_foreach(caps, (GFunc)g_free, NULL);
- g_list_free(caps);
- }
+ g_list_foreach (caps, (GFunc) g_free, NULL);
+ g_list_free (caps);
+ }
}
static void
xfpm_notify_check_server (XfpmDBusMonitor *monitor,
- gchar *service_name,
- gboolean connected,
- gboolean on_session,
- XfpmNotify *notify)
+ gchar *service_name,
+ gboolean connected,
+ gboolean on_session,
+ XfpmNotify *notify)
{
- if ( !g_strcmp0 (service_name, "org.freedesktop.Notifications") && on_session && connected )
- xfpm_notify_get_server_caps (notify);
+ if ( !g_strcmp0 (service_name, "org.freedesktop.Notifications") && on_session && connected )
+ xfpm_notify_get_server_caps (notify);
}
static void xfpm_notify_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- XfpmNotify *notify;
-
- notify = XFPM_NOTIFY (object);
-
- switch (prop_id)
- {
- case PROP_ACTIONS:
- g_value_set_boolean (value, notify->priv->supports_actions);
- break;
- case PROP_SYNC:
- g_value_set_boolean (value, notify->priv->supports_sync);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ XfpmNotify *notify;
+
+ notify = XFPM_NOTIFY (object);
+
+ switch (prop_id)
+ {
+ case PROP_ACTIONS:
+ g_value_set_boolean (value, notify->priv->supports_actions);
+ break;
+ case PROP_SYNC:
+ g_value_set_boolean (value, notify->priv->supports_sync);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
xfpm_notify_class_init (XfpmNotifyClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = xfpm_notify_finalize;
- object_class->get_property = xfpm_notify_get_property;
-
- g_object_class_install_property (object_class,
- PROP_ACTIONS,
- g_param_spec_boolean ("actions",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_SYNC,
- g_param_spec_boolean ("sync",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = xfpm_notify_finalize;
+ object_class->get_property = xfpm_notify_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ACTIONS,
+ g_param_spec_boolean ("actions",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_SYNC,
+ g_param_spec_boolean ("sync",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
}
static void
xfpm_notify_init (XfpmNotify *notify)
{
- notify->priv = xfpm_notify_get_instance_private (notify);
+ notify->priv = xfpm_notify_get_instance_private (notify);
- notify->priv->notification = NULL;
- notify->priv->critical = NULL;
+ notify->priv->notification = NULL;
+ notify->priv->critical = NULL;
- notify->priv->critical_id = 0;
- notify->priv->notify_id = 0;
+ notify->priv->critical_id = 0;
+ notify->priv->notify_id = 0;
- notify->priv->monitor = xfpm_dbus_monitor_new ();
- xfpm_dbus_monitor_add_service (notify->priv->monitor, G_BUS_TYPE_SESSION, "org.freedesktop.Notifications");
- g_signal_connect (notify->priv->monitor, "service-connection-changed",
- G_CALLBACK (xfpm_notify_check_server), notify);
+ notify->priv->monitor = xfpm_dbus_monitor_new ();
+ xfpm_dbus_monitor_add_service (notify->priv->monitor, G_BUS_TYPE_SESSION, "org.freedesktop.Notifications");
+ g_signal_connect (notify->priv->monitor, "service-connection-changed",
+ G_CALLBACK (xfpm_notify_check_server), notify);
- xfpm_notify_get_server_caps (notify);
+ xfpm_notify_get_server_caps (notify);
}
static void
xfpm_notify_finalize (GObject *object)
{
- XfpmNotify *notify;
+ XfpmNotify *notify;
- notify = XFPM_NOTIFY (object);
+ notify = XFPM_NOTIFY (object);
- xfpm_notify_close_normal (notify);
- xfpm_notify_close_critical (notify);
+ xfpm_notify_close_normal (notify);
+ xfpm_notify_close_critical (notify);
- G_OBJECT_CLASS (xfpm_notify_parent_class)->finalize(object);
+ G_OBJECT_CLASS (xfpm_notify_parent_class)->finalize(object);
}
static NotifyNotification *
xfpm_notify_new_notification_internal (const gchar *title, const gchar *message,
- const gchar *icon_name, guint timeout,
- XfpmNotifyUrgency urgency)
+ const gchar *icon_name, guint timeout,
+ XfpmNotifyUrgency urgency)
{
- NotifyNotification *n;
+ NotifyNotification *n;
#ifdef NOTIFY_CHECK_VERSION
#if NOTIFY_CHECK_VERSION (0, 7, 0)
- n = notify_notification_new (title, message, icon_name);
+ n = notify_notification_new (title, message, icon_name);
#else
- n = notify_notification_new (title, message, icon_name, NULL);
+ n = notify_notification_new (title, message, icon_name, NULL);
#endif
#else
- n = notify_notification_new (title, message, icon_name, NULL);
+ n = notify_notification_new (title, message, icon_name, NULL);
#endif
- /* Only set transient hint on non-critical notifications, so that the critical
- ones also end up in the notification server's log */
- if (urgency != XFPM_NOTIFY_CRITICAL)
- notify_notification_set_hint (n, "transient", g_variant_new_boolean (FALSE));
- notify_notification_set_hint (n, "image-path", g_variant_new_string (icon_name));
+ /* Only set transient hint on non-critical notifications, so that the critical
+ ones also end up in the notification server's log */
+ if (urgency != XFPM_NOTIFY_CRITICAL)
+ notify_notification_set_hint (n, "transient", g_variant_new_boolean (FALSE));
+ notify_notification_set_hint (n, "image-path", g_variant_new_string (icon_name));
- notify_notification_set_urgency (n, (NotifyUrgency)urgency);
+ notify_notification_set_urgency (n, (NotifyUrgency)urgency);
- if (timeout != 0)
- notify_notification_set_timeout (n, timeout);
+ if (timeout != 0)
+ notify_notification_set_timeout (n, timeout);
- return n;
+ return n;
}
static void
xfpm_notify_close_critical_cb (NotifyNotification *n, XfpmNotify *notify)
{
- notify->priv->critical = NULL;
- g_object_unref (G_OBJECT (n));
+ notify->priv->critical = NULL;
+ g_object_unref (G_OBJECT (n));
}
static gboolean
xfpm_notify_show (NotifyNotification *n)
{
- notify_notification_show (n, NULL);
- return FALSE;
+ notify_notification_show (n, NULL);
+
+ return FALSE;
}
static void
xfpm_notify_close_notification (XfpmNotify *notify )
{
- if (notify->priv->notify_id != 0)
- {
- g_source_remove (notify->priv->notify_id);
- notify->priv->notify_id = 0;
- }
-
- if ( notify->priv->notification )
- {
- if (!notify_notification_close (notify->priv->notification, NULL))
- g_warning ("Failed to close notification\n");
-
- g_object_unref (G_OBJECT(notify->priv->notification) );
- notify->priv->notification = NULL;
- }
+ if (notify->priv->notify_id != 0)
+ {
+ g_source_remove (notify->priv->notify_id);
+ notify->priv->notify_id = 0;
+ }
+
+ if ( notify->priv->notification )
+ {
+ if (!notify_notification_close (notify->priv->notification, NULL))
+ g_warning ("Failed to close notification\n");
+
+ g_object_unref (G_OBJECT(notify->priv->notification) );
+ notify->priv->notification = NULL;
+ }
}
XfpmNotify *
xfpm_notify_new (void)
{
- static gpointer xfpm_notify_object = NULL;
-
- if ( xfpm_notify_object != NULL )
- {
- g_object_ref (xfpm_notify_object);
- }
- else
- {
- xfpm_notify_object = g_object_new (XFPM_TYPE_NOTIFY, NULL);
- g_object_add_weak_pointer (xfpm_notify_object, &xfpm_notify_object);
- }
- return XFPM_NOTIFY (xfpm_notify_object);
+ static gpointer xfpm_notify_object = NULL;
+
+ if ( xfpm_notify_object != NULL )
+ {
+ g_object_ref (xfpm_notify_object);
+ }
+ else
+ {
+ xfpm_notify_object = g_object_new (XFPM_TYPE_NOTIFY, NULL);
+ g_object_add_weak_pointer (xfpm_notify_object, &xfpm_notify_object);
+ }
+ return XFPM_NOTIFY (xfpm_notify_object);
}
-void xfpm_notify_show_notification (XfpmNotify *notify, const gchar *title,
- const gchar *text, const gchar *icon_name,
- gint timeout, XfpmNotifyUrgency urgency)
+void
+xfpm_notify_show_notification (XfpmNotify *notify, const gchar *title,
+ const gchar *text, const gchar *icon_name,
+ gint timeout, XfpmNotifyUrgency urgency)
{
- NotifyNotification *n;
+ NotifyNotification *n;
- xfpm_notify_close_notification (notify);
+ xfpm_notify_close_notification (notify);
- n = xfpm_notify_new_notification_internal (title,
- text, icon_name,
- timeout, urgency);
+ n = xfpm_notify_new_notification_internal (title,
+ text, icon_name,
+ timeout, urgency);
- xfpm_notify_present_notification (notify, n);
+ xfpm_notify_present_notification (notify, n);
}
-NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
- const gchar *title,
- const gchar *text,
- const gchar *icon_name,
- guint timeout,
- XfpmNotifyUrgency urgency)
+NotifyNotification *
+xfpm_notify_new_notification (XfpmNotify *notify,
+ const gchar *title,
+ const gchar *text,
+ const gchar *icon_name,
+ guint timeout,
+ XfpmNotifyUrgency urgency)
{
- NotifyNotification *n = xfpm_notify_new_notification_internal (title,
- text, icon_name,
- timeout, urgency);
- return n;
+ NotifyNotification *n = xfpm_notify_new_notification_internal (title,
+ text, icon_name,
+ timeout, urgency);
+ return n;
}
-void xfpm_notify_add_action_to_notification (XfpmNotify *notify, NotifyNotification *n,
- const gchar *id, const gchar *action_label,
- NotifyActionCallback callback, gpointer data)
+void
+xfpm_notify_add_action_to_notification (XfpmNotify *notify, NotifyNotification *n,
+ const gchar *id, const gchar *action_label,
+ NotifyActionCallback callback, gpointer data)
{
- g_return_if_fail (XFPM_IS_NOTIFY(notify));
-
- notify_notification_add_action (n, id, action_label,
- (NotifyActionCallback)callback,
- data, NULL);
+ g_return_if_fail (XFPM_IS_NOTIFY(notify));
+ notify_notification_add_action (n, id, action_label,
+ (NotifyActionCallback)callback,
+ data, NULL);
}
static void
xfpm_notify_closed_cb (NotifyNotification *n, XfpmNotify *notify)
{
- notify->priv->notification = NULL;
- g_object_unref (G_OBJECT (n));
+ notify->priv->notification = NULL;
+ g_object_unref (G_OBJECT (n));
}
-void xfpm_notify_present_notification (XfpmNotify *notify, NotifyNotification *n)
+void
+xfpm_notify_present_notification (XfpmNotify *notify, NotifyNotification *n)
{
- g_return_if_fail (XFPM_IS_NOTIFY(notify));
+ g_return_if_fail (XFPM_IS_NOTIFY(notify));
- xfpm_notify_close_notification (notify);
+ xfpm_notify_close_notification (notify);
- g_signal_connect (G_OBJECT(n),"closed",
- G_CALLBACK(xfpm_notify_closed_cb), notify);
- notify->priv->notification = n;
+ g_signal_connect (G_OBJECT(n),"closed",
+ G_CALLBACK(xfpm_notify_closed_cb), notify);
+ notify->priv->notification = n;
- notify->priv->notify_id = g_idle_add ((GSourceFunc) xfpm_notify_show, n);
+ notify->priv->notify_id = g_idle_add ((GSourceFunc) xfpm_notify_show, n);
}
-void xfpm_notify_critical (XfpmNotify *notify, NotifyNotification *n)
+void
+xfpm_notify_critical (XfpmNotify *notify, NotifyNotification *n)
{
- g_return_if_fail (XFPM_IS_NOTIFY (notify));
+ g_return_if_fail (XFPM_IS_NOTIFY (notify));
- xfpm_notify_close_critical (notify);
+ xfpm_notify_close_critical (notify);
- notify->priv->critical = n;
+ notify->priv->critical = n;
- g_signal_connect (G_OBJECT (n), "closed",
- G_CALLBACK (xfpm_notify_close_critical_cb), notify);
+ g_signal_connect (G_OBJECT (n), "closed",
+ G_CALLBACK (xfpm_notify_close_critical_cb), notify);
- notify->priv->critical_id = g_idle_add ((GSourceFunc) xfpm_notify_show, n);
+ notify->priv->critical_id = g_idle_add ((GSourceFunc) xfpm_notify_show, n);
}
-void xfpm_notify_close_critical (XfpmNotify *notify)
+void
+xfpm_notify_close_critical (XfpmNotify *notify)
{
- GError *error = NULL;
+ GError *error = NULL;
- g_return_if_fail (XFPM_IS_NOTIFY (notify));
+ g_return_if_fail (XFPM_IS_NOTIFY (notify));
- if (notify->priv->critical_id != 0)
- {
- g_source_remove (notify->priv->critical_id);
- notify->priv->critical_id = 0;
- }
+ if (notify->priv->critical_id != 0)
+ {
+ g_source_remove (notify->priv->critical_id);
+ notify->priv->critical_id = 0;
+ }
- if ( notify->priv->critical )
+ if ( notify->priv->critical )
+ {
+ if (!notify_notification_close (notify->priv->critical, &error))
{
- if (!notify_notification_close (notify->priv->critical, &error))
- {
- g_warning ("Failed to close critical notification: %s", error->message);
- g_error_free (error);
- }
-
- g_object_unref (G_OBJECT(notify->priv->critical) );
- notify->priv->critical = NULL;
+ g_warning ("Failed to close critical notification: %s", error->message);
+ g_error_free (error);
}
+
+ g_object_unref (G_OBJECT(notify->priv->critical) );
+ notify->priv->critical = NULL;
+ }
}
-void xfpm_notify_close_normal (XfpmNotify *notify)
+void
+xfpm_notify_close_normal (XfpmNotify *notify)
{
- g_return_if_fail (XFPM_IS_NOTIFY (notify));
+ g_return_if_fail (XFPM_IS_NOTIFY (notify));
- xfpm_notify_close_notification (notify);
+ xfpm_notify_close_notification (notify);
}
diff --git a/src/xfpm-notify.h b/src/xfpm-notify.h
index 0420a48..3294673 100644
--- a/src/xfpm-notify.h
+++ b/src/xfpm-notify.h
@@ -34,60 +34,50 @@ G_BEGIN_DECLS
typedef enum
{
- XFPM_NOTIFY_LOW = 0,
- XFPM_NOTIFY_NORMAL,
- XFPM_NOTIFY_CRITICAL
-
+ XFPM_NOTIFY_LOW = 0,
+ XFPM_NOTIFY_NORMAL,
+ XFPM_NOTIFY_CRITICAL
} XfpmNotifyUrgency;
typedef struct XfpmNotifyPrivate XfpmNotifyPrivate;
typedef struct
{
- GObject parent;
- XfpmNotifyPrivate *priv;
-
+ GObject parent;
+ XfpmNotifyPrivate *priv;
} XfpmNotify;
typedef struct
{
GObjectClass parent_class;
-
} XfpmNotifyClass;
-GType xfpm_notify_get_type (void) G_GNUC_CONST;
-XfpmNotify *xfpm_notify_new (void);
-
-void xfpm_notify_show_notification (XfpmNotify *notify,
- const gchar *title,
- const gchar *text,
- const gchar *icon_name,
- gint timeout,
- XfpmNotifyUrgency urgency);
-
-NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
- const gchar *title,
- const gchar *text,
- const gchar *icon_name,
- guint timeout,
- XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
-
-void xfpm_notify_add_action_to_notification (XfpmNotify *notify,
- NotifyNotification *n,
- const gchar *id,
- const gchar *action_label,
- NotifyActionCallback callback,
- gpointer data);
-
-void xfpm_notify_present_notification (XfpmNotify *notify,
- NotifyNotification *n);
-
-void xfpm_notify_critical (XfpmNotify *notify,
- NotifyNotification *n);
-
-void xfpm_notify_close_critical (XfpmNotify *notify);
-
-void xfpm_notify_close_normal (XfpmNotify *notify);
+GType xfpm_notify_get_type (void) G_GNUC_CONST;
+XfpmNotify *xfpm_notify_new (void);
+void xfpm_notify_show_notification (XfpmNotify *notify,
+ const gchar *title,
+ const gchar *text,
+ const gchar *icon_name,
+ gint timeout,
+ XfpmNotifyUrgency urgency);
+NotifyNotification *xfpm_notify_new_notification (XfpmNotify *notify,
+ const gchar *title,
+ const gchar *text,
+ const gchar *icon_name,
+ guint timeout,
+ XfpmNotifyUrgency urgency) G_GNUC_MALLOC;
+void xfpm_notify_add_action_to_notification (XfpmNotify *notify,
+ NotifyNotification *n,
+ const gchar *id,
+ const gchar *action_label,
+ NotifyActionCallback callback,
+ gpointer data);
+void xfpm_notify_present_notification (XfpmNotify *notify,
+ NotifyNotification *n);
+void xfpm_notify_critical (XfpmNotify *notify,
+ NotifyNotification *n);
+void xfpm_notify_close_critical (XfpmNotify *notify);
+void xfpm_notify_close_normal (XfpmNotify *notify);
G_END_DECLS
diff --git a/src/xfpm-pm-helper.c b/src/xfpm-pm-helper.c
index 6802094..93d2284 100644
--- a/src/xfpm-pm-helper.c
+++ b/src/xfpm-pm-helper.c
@@ -74,7 +74,7 @@
#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/pm-hibernate"
#endif
#ifdef BACKEND_TYPE_OPENBSD
-#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/zzz"
+#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/zzz"
#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/ZZZ"
#endif
@@ -132,44 +132,47 @@ int
main (int argc, char **argv)
{
GOptionContext *context;
- gint uid;
- gint euid;
- const gchar *pkexec_uid_str;
+ gint uid;
+ gint euid;
+ const gchar *pkexec_uid_str;
gboolean suspend = FALSE;
gboolean hibernate = FALSE;
- const GOptionEntry options[] = {
- { "suspend", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &suspend, "Suspend the system", NULL },
- { "hibernate", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &hibernate, "Hibernate the system", NULL },
- { NULL }
- };
-
- context = g_option_context_new (NULL);
- g_option_context_set_summary (context, "XFCE Power Management Helper");
- g_option_context_add_main_entries (context, options, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
-
- /* no input */
- if (!suspend && !hibernate) {
- puts ("No valid option was specified");
- return EXIT_CODE_ARGUMENTS_INVALID;
- }
-
- /* get calling process */
- uid = getuid ();
- euid = geteuid ();
- if (uid != 0 || euid != 0) {
- puts ("This program can only be used by the root user");
- return EXIT_CODE_ARGUMENTS_INVALID;
- }
-
- /* check we're not being spoofed */
- pkexec_uid_str = g_getenv ("PKEXEC_UID");
- if (pkexec_uid_str == NULL) {
- puts ("This program must only be run through pkexec");
- return EXIT_CODE_INVALID_USER;
- }
+ const GOptionEntry options[] = {
+ { "suspend", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &suspend, "Suspend the system", NULL },
+ { "hibernate", '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &hibernate, "Hibernate the system", NULL },
+ { NULL }
+ };
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "XFCE Power Management Helper");
+ g_option_context_add_main_entries (context, options, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ /* no input */
+ if (!suspend && !hibernate)
+ {
+ puts ("No valid option was specified");
+ return EXIT_CODE_ARGUMENTS_INVALID;
+ }
+
+ /* get calling process */
+ uid = getuid ();
+ euid = geteuid ();
+ if (uid != 0 || euid != 0)
+ {
+ puts ("This program can only be used by the root user");
+ return EXIT_CODE_ARGUMENTS_INVALID;
+ }
+
+ /* check we're not being spoofed */
+ pkexec_uid_str = g_getenv ("PKEXEC_UID");
+ if (pkexec_uid_str == NULL)
+ {
+ puts ("This program must only be run through pkexec");
+ return EXIT_CODE_INVALID_USER;
+ }
/* run the command */
if(suspend)
@@ -177,7 +180,9 @@ main (int argc, char **argv)
if (run (UP_BACKEND_SUSPEND_COMMAND))
{
return EXIT_CODE_SUCCESS;
- } else {
+ }
+ else
+ {
return EXIT_CODE_FAILED;
}
}
@@ -186,11 +191,13 @@ main (int argc, char **argv)
if(run (UP_BACKEND_HIBERNATE_COMMAND))
{
return EXIT_CODE_SUCCESS;
- } else {
+ }
+ else
+ {
return EXIT_CODE_FAILED;
}
}
- /* how did we get here? */
- return EXIT_CODE_FAILED;
+ /* how did we get here? */
+ return EXIT_CODE_FAILED;
}
diff --git a/src/xfpm-polkit.c b/src/xfpm-polkit.c
index 12d60f9..c2ab601 100644
--- a/src/xfpm-polkit.c
+++ b/src/xfpm-polkit.c
@@ -66,22 +66,22 @@ static void xfpm_polkit_finalize (GObject *object);
struct XfpmPolkitPrivate
{
- GDBusConnection *bus;
+ GDBusConnection *bus;
#ifdef ENABLE_POLKIT
- GDBusProxy *proxy;
- GVariant *subject;
- GVariant *details;
+ GDBusProxy *proxy;
+ GVariant *subject;
+ GVariant *details;
- gulong destroy_id;
- gboolean subject_valid;
+ gulong destroy_id;
+ gboolean subject_valid;
#endif
};
enum
{
- AUTH_CHANGED,
- LAST_SIGNAL
+ AUTH_CHANGED,
+ LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0 };
@@ -100,130 +100,130 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmPolkit, xfpm_polkit, G_TYPE_OBJECT)
static gboolean
get_kinfo_proc (pid_t pid, struct kinfo_proc *p)
{
- int mib[4];
- size_t len;
+ int mib[4];
+ size_t len;
- len = 4;
- sysctlnametomib ("kern.proc.pid", mib, &len);
+ len = 4;
+ sysctlnametomib ("kern.proc.pid", mib, &len);
- len = sizeof (struct kinfo_proc);
- mib[3] = pid;
+ len = sizeof (struct kinfo_proc);
+ mib[3] = pid;
- if (sysctl (mib, 4, p, &len, NULL, 0) == -1)
- return FALSE;
+ if (sysctl (mib, 4, p, &len, NULL, 0) == -1)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
#endif /*if defined(__FreeBSD__)*/
static guint64
get_start_time_for_pid (pid_t pid)
{
- guint64 start_time = 0;
+ guint64 start_time = 0;
#if defined(__linux)
- gchar *filename;
- gchar *contents;
- size_t length;
- gchar **tokens;
- guint num_tokens;
- gchar *p;
- gchar *endp;
-
- start_time = 0;
- contents = NULL;
-
- filename = g_strdup_printf ("/proc/%d/stat", pid);
-
- if (!g_file_get_contents (filename, &contents, &length, NULL))
- goto out;
-
- /* start time is the token at index 19 after the '(process name)' entry - since only this
- * field can contain the ')' character, search backwards for this to avoid malicious
- * processes trying to fool us
- */
- p = strrchr (contents, ')');
- if (p == NULL)
- {
- goto out;
- }
-
- p += 2; /* skip ') ' */
-
- if (p - contents >= (int) length)
- {
- g_warning ("Error parsing file %s", filename);
- goto out;
- }
-
- tokens = g_strsplit (p, " ", 0);
-
- num_tokens = g_strv_length (tokens);
-
- if (num_tokens < 20)
- {
- g_warning ("Error parsing file %s", filename);
- goto out;
- }
-
- start_time = strtoull (tokens[19], &endp, 10);
- if (endp == tokens[19])
- {
- g_warning ("Error parsing file %s", filename);
- goto out;
- }
- g_strfreev (tokens);
+ gchar *filename;
+ gchar *contents;
+ size_t length;
+ gchar **tokens;
+ guint num_tokens;
+ gchar *p;
+ gchar *endp;
+
+ start_time = 0;
+ contents = NULL;
+
+ filename = g_strdup_printf ("/proc/%d/stat", pid);
+
+ if (!g_file_get_contents (filename, &contents, &length, NULL))
+ goto out;
+
+ /* start time is the token at index 19 after the '(process name)' entry - since only this
+ * field can contain the ')' character, search backwards for this to avoid malicious
+ * processes trying to fool us
+ */
+ p = strrchr (contents, ')');
+ if (p == NULL)
+ {
+ goto out;
+ }
+
+ p += 2; /* skip ') ' */
+
+ if (p - contents >= (int) length)
+ {
+ g_warning ("Error parsing file %s", filename);
+ goto out;
+ }
+
+ tokens = g_strsplit (p, " ", 0);
+
+ num_tokens = g_strv_length (tokens);
+
+ if (num_tokens < 20)
+ {
+ g_warning ("Error parsing file %s", filename);
+ goto out;
+ }
+
+ start_time = strtoull (tokens[19], &endp, 10);
+ if (endp == tokens[19])
+ {
+ g_warning ("Error parsing file %s", filename);
+ goto out;
+ }
+ g_strfreev (tokens);
out:
- g_free (filename);
- g_free (contents);
+ g_free (filename);
+ g_free (contents);
#elif defined(__FreeBSD__)
- struct kinfo_proc p;
+ struct kinfo_proc p;
- start_time = 0;
+ start_time = 0;
- if (! get_kinfo_proc (pid, &p))
- {
- g_warning ("Error obtaining start time for %d (%s)",
- (gint) pid,
- g_strerror (errno));
- goto out;
- }
+ if (! get_kinfo_proc (pid, &p))
+ {
+ g_warning ("Error obtaining start time for %d (%s)",
+ (gint) pid,
+ g_strerror (errno));
+ goto out;
+ }
- start_time = (guint64) p.ki_start.tv_sec;
+ start_time = (guint64) p.ki_start.tv_sec;
out:
#elif defined(__SVR4) && defined(__sun)
- psinfo_t p;
- gchar *filename;
- int fd;
-
- start_time = 0;
-
- filename = g_strdup_printf ("/proc/%d/psinfo", (int) pid);
- if ((fd = open(filename, O_RDONLY)) < 0)
- {
- g_warning ("Error opening %s (%s)",
- filename,
- g_strerror (errno));
- goto out;
- }
- if (read(fd, &p, sizeof (p)) != sizeof (p))
- {
- g_warning ("Error reading %s",
- filename);
- close(fd);
- goto out;
- }
- start_time = (guint64) p.pr_start.tv_sec;
- close(fd);
+ psinfo_t p;
+ gchar *filename;
+ int fd;
+
+ start_time = 0;
+
+ filename = g_strdup_printf ("/proc/%d/psinfo", (int) pid);
+ if ((fd = open (filename, O_RDONLY)) < 0)
+ {
+ g_warning ("Error opening %s (%s)",
+ filename,
+ g_strerror (errno));
+ goto out;
+ }
+ if (read (fd, &p, sizeof (p)) != sizeof (p))
+ {
+ g_warning ("Error reading %s",
+ filename);
+ close (fd);
+ goto out;
+ }
+ start_time = (guint64) p.pr_start.tv_sec;
+ close(fd);
out:
- g_free (filename);
+ g_free (filename);
#endif
- return start_time;
+ return start_time;
}
#endif /*ENABLE_POLKIT*/
@@ -232,80 +232,80 @@ out:
static gboolean
xfpm_polkit_free_data (gpointer data)
{
- XfpmPolkit *polkit;
+ XfpmPolkit *polkit;
- polkit = XFPM_POLKIT (data);
+ polkit = XFPM_POLKIT (data);
- g_assert (polkit->priv->subject_valid);
+ g_assert (polkit->priv->subject_valid);
- XFPM_DEBUG ("Destroying Polkit data");
+ XFPM_DEBUG ("Destroying Polkit data");
- g_variant_unref (polkit->priv->details);
- g_variant_unref (polkit->priv->subject);
+ g_variant_unref (polkit->priv->details);
+ g_variant_unref (polkit->priv->subject);
- polkit->priv->details = NULL;
- polkit->priv->subject = NULL;
+ polkit->priv->details = NULL;
+ polkit->priv->subject = NULL;
- polkit->priv->destroy_id = 0;
- polkit->priv->subject_valid = FALSE;
+ polkit->priv->destroy_id = 0;
+ polkit->priv->subject_valid = FALSE;
- return FALSE;
+ return FALSE;
}
static void
xfpm_polkit_init_data (XfpmPolkit *polkit)
{
- gint pid;
- guint64 start_time;
- GVariantBuilder builder;
- const gchar *subject_kind = NULL;
+ gint pid;
+ guint64 start_time;
+ GVariantBuilder builder;
+ const gchar *subject_kind = NULL;
- if (polkit->priv->subject_valid)
- return;
+ if (polkit->priv->subject_valid)
+ return;
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
- pid = getpid ();
+ pid = getpid ();
- start_time = get_start_time_for_pid (pid);
+ start_time = get_start_time_for_pid (pid);
- if ( G_LIKELY (start_time != 0 ) )
- {
- GVariant *var;
+ if ( G_LIKELY (start_time != 0 ) )
+ {
+ GVariant *var;
- subject_kind = "unix-process";
+ subject_kind = "unix-process";
- var = g_variant_new ("u", (guint32)pid);
- g_variant_builder_add (&builder, "{sv}", "pid", var);
+ var = g_variant_new ("u", (guint32)pid);
+ g_variant_builder_add (&builder, "{sv}", "pid", var);
- var = g_variant_new ("t", start_time);
- g_variant_builder_add (&builder, "{sv}", "start-time", var);
+ var = g_variant_new ("t", start_time);
+ g_variant_builder_add (&builder, "{sv}", "start-time", var);
- XFPM_DEBUG ("Using unix session polkit subject");
- }
- else
- {
- g_warning ("Unable to create polkit subject");
- }
+ XFPM_DEBUG ("Using unix session polkit subject");
+ }
+ else
+ {
+ g_warning ("Unable to create polkit subject");
+ }
- polkit->priv->subject =
- g_variant_ref_sink (g_variant_new ("(sa{sv})",
- subject_kind,
- &builder));
+ polkit->priv->subject =
+ g_variant_ref_sink (g_variant_new ("(sa{sv})",
+ subject_kind,
+ &builder));
- /**
- * Polkit details, will leave it empty.
- **/
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
- polkit->priv->details =
- g_variant_ref_sink (g_variant_new ("a{ss}",
- &builder));
+ /**
+ * Polkit details, will leave it empty.
+ **/
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ polkit->priv->details = g_variant_ref_sink (g_variant_new ("a{ss}",
+ &builder));
- /*Clean these data after 1 minute*/
- polkit->priv->destroy_id =
- g_timeout_add_seconds (60, (GSourceFunc) xfpm_polkit_free_data, polkit);
+ /*Clean these data after 1 minute*/
+ polkit->priv->destroy_id = g_timeout_add_seconds (60,
+ (GSourceFunc) xfpm_polkit_free_data,
+ polkit);
- polkit->priv->subject_valid = TRUE;
+ polkit->priv->subject_valid = TRUE;
}
#endif /*ENABLE_POLKIT*/
@@ -313,188 +313,189 @@ static gboolean
xfpm_polkit_check_auth_intern (XfpmPolkit *polkit, const gchar *action_id)
{
#ifdef ENABLE_POLKIT
- GError *error = NULL;
- gboolean is_authorized = FALSE;
- GVariant *var;
-
- /**
- * <method name="CheckAuthorization">
- * <arg type="(sa{sv})" name="subject" direction="in"/>
- * <arg type="s" name="action_id" direction="in"/>
- * <arg type="a{ss}" name="details" direction="in"/>
- * <arg type="u" name="flags" direction="in"/>
- * <arg type="s" name="cancellation_id" direction="in"/>
- * <arg type="(bba{ss})" name="result" direction="out"/>
- * </method>
- *
- **/
-
- g_return_val_if_fail (polkit->priv->proxy != NULL, FALSE);
- g_return_val_if_fail (polkit->priv->subject_valid, FALSE);
-
- var = g_variant_new ("(@(sa{sv})s at a{ss}us)",
- polkit->priv->subject,
- action_id,
- polkit->priv->details,
- 0,
- "");
-
- XFPM_DEBUG ("polkit request: %s", g_variant_print (var, TRUE));
-
- var = g_dbus_proxy_call_sync (polkit->priv->proxy, "CheckAuthorization",
- var,
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL,
- &error);
-
- if ( G_LIKELY (var) )
- {
- g_variant_get (var, "((bba{ss}))",
- &is_authorized, NULL, NULL);
-
- g_variant_unref (var);
- }
- else if ( error )
- {
- g_warning ("'CheckAuthorization' failed with %s", error->message);
- g_error_free (error);
- }
-
- XFPM_DEBUG ("Action=%s is authorized=%s", action_id, xfpm_bool_to_string (is_authorized));
-
- return is_authorized;
+ GError *error = NULL;
+ gboolean is_authorized = FALSE;
+ GVariant *var;
+
+ /**
+ * <method name="CheckAuthorization">
+ * <arg type="(sa{sv})" name="subject" direction="in"/>
+ * <arg type="s" name="action_id" direction="in"/>
+ * <arg type="a{ss}" name="details" direction="in"/>
+ * <arg type="u" name="flags" direction="in"/>
+ * <arg type="s" name="cancellation_id" direction="in"/>
+ * <arg type="(bba{ss})" name="result" direction="out"/>
+ * </method>
+ *
+ **/
+
+ g_return_val_if_fail (polkit->priv->proxy != NULL, FALSE);
+ g_return_val_if_fail (polkit->priv->subject_valid, FALSE);
+
+ var = g_variant_new ("(@(sa{sv})s at a{ss}us)",
+ polkit->priv->subject,
+ action_id,
+ polkit->priv->details,
+ 0,
+ "");
+
+ XFPM_DEBUG ("polkit request: %s", g_variant_print (var, TRUE));
+
+ var = g_dbus_proxy_call_sync (polkit->priv->proxy, "CheckAuthorization",
+ var,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+
+ if ( G_LIKELY (var) )
+ {
+ g_variant_get (var, "((bba{ss}))",
+ &is_authorized, NULL, NULL);
+
+ g_variant_unref (var);
+ }
+ else if ( error )
+ {
+ g_warning ("'CheckAuthorization' failed with %s", error->message);
+ g_error_free (error);
+ }
+
+ XFPM_DEBUG ("Action=%s is authorized=%s", action_id, xfpm_bool_to_string (is_authorized));
+
+ return is_authorized;
#endif /*ENABLE_POLKIT*/
- return TRUE;
+ return TRUE;
}
#ifdef ENABLE_POLKIT
static void
xfpm_polkit_changed_cb (GDBusProxy *proxy, XfpmPolkit *polkit)
{
- XFPM_DEBUG ("Auth changed");
- g_signal_emit (G_OBJECT (polkit), signals [AUTH_CHANGED], 0);
+ XFPM_DEBUG ("Auth changed");
+ g_signal_emit (G_OBJECT (polkit), signals [AUTH_CHANGED], 0);
}
#endif
static void
xfpm_polkit_class_init (XfpmPolkitClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = xfpm_polkit_finalize;
-
- signals [AUTH_CHANGED] =
- g_signal_new ("auth-changed",
- XFPM_TYPE_POLKIT,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPolkitClass, auth_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0, G_TYPE_NONE);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = xfpm_polkit_finalize;
+
+ signals [AUTH_CHANGED] =
+ g_signal_new ("auth-changed",
+ XFPM_TYPE_POLKIT,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(XfpmPolkitClass, auth_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0, G_TYPE_NONE);
}
static void
xfpm_polkit_init (XfpmPolkit *polkit)
{
- GError *error = NULL;
+ GError *error = NULL;
- polkit->priv = xfpm_polkit_get_instance_private (polkit);
+ polkit->priv = xfpm_polkit_get_instance_private (polkit);
#ifdef ENABLE_POLKIT
- polkit->priv->destroy_id = 0;
- polkit->priv->subject_valid = FALSE;
- polkit->priv->proxy = NULL;
- polkit->priv->subject = NULL;
- polkit->priv->details = NULL;
+ polkit->priv->destroy_id = 0;
+ polkit->priv->subject_valid = FALSE;
+ polkit->priv->proxy = NULL;
+ polkit->priv->subject = NULL;
+ polkit->priv->details = NULL;
#endif /*ENABLE_POLKIT*/
- polkit->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ polkit->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
- if ( error )
- {
- g_critical ("Error getting system bus connection : %s", error->message);
- g_error_free (error);
- goto out;
- }
+ if ( error )
+ {
+ g_critical ("Error getting system bus connection : %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
#ifdef ENABLE_POLKIT
- polkit->priv->proxy =
- g_dbus_proxy_new_sync (polkit->priv->bus,
- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
- NULL,
- "org.freedesktop.PolicyKit1",
- "/org/freedesktop/PolicyKit1/Authority",
- "org.freedesktop.PolicyKit1.Authority",
- NULL,
- NULL);
-
- if (G_LIKELY (polkit->priv->proxy) )
- {
- g_signal_connect (polkit->priv->proxy, "Changed",
- G_CALLBACK (xfpm_polkit_changed_cb), polkit);
- }
- else
- {
- g_warning ("Failed to create proxy for 'org.freedesktop.PolicyKit1'");
- }
+ polkit->priv->proxy =
+ g_dbus_proxy_new_sync (polkit->priv->bus,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.freedesktop.PolicyKit1",
+ "/org/freedesktop/PolicyKit1/Authority",
+ "org.freedesktop.PolicyKit1.Authority",
+ NULL,
+ NULL);
+
+ if (G_LIKELY (polkit->priv->proxy) )
+ {
+ g_signal_connect (polkit->priv->proxy, "Changed",
+ G_CALLBACK (xfpm_polkit_changed_cb), polkit);
+ }
+ else
+ {
+ g_warning ("Failed to create proxy for 'org.freedesktop.PolicyKit1'");
+ }
#endif /*ENABLE_POLKIT*/
out:
- ;
+ ;
}
static void
xfpm_polkit_finalize (GObject *object)
{
- XfpmPolkit *polkit;
+ XfpmPolkit *polkit;
- polkit = XFPM_POLKIT (object);
+ polkit = XFPM_POLKIT (object);
#ifdef ENABLE_POLKIT
- if ( polkit->priv->proxy )
- {
- g_signal_handlers_disconnect_by_func (polkit->priv->proxy,
- G_CALLBACK (xfpm_polkit_changed_cb), polkit);
- g_object_unref (polkit->priv->proxy);
- }
-
- if ( polkit->priv->subject_valid )
- {
- xfpm_polkit_free_data (polkit);
- if (polkit->priv->destroy_id != 0 )
- g_source_remove (polkit->priv->destroy_id);
- }
+ if ( polkit->priv->proxy )
+ {
+ g_signal_handlers_disconnect_by_func (polkit->priv->proxy,
+ G_CALLBACK (xfpm_polkit_changed_cb), polkit);
+ g_object_unref (polkit->priv->proxy);
+ }
+
+ if ( polkit->priv->subject_valid )
+ {
+ xfpm_polkit_free_data (polkit);
+ if (polkit->priv->destroy_id != 0 )
+ g_source_remove (polkit->priv->destroy_id);
+ }
#endif /*ENABLE_POLKIT*/
- if ( polkit->priv->bus )
- g_object_unref (polkit->priv->bus);
+ if ( polkit->priv->bus )
+ g_object_unref (polkit->priv->bus);
- G_OBJECT_CLASS (xfpm_polkit_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_polkit_parent_class)->finalize (object);
}
XfpmPolkit *
xfpm_polkit_get (void)
{
- static gpointer xfpm_polkit_obj = NULL;
-
- if ( G_LIKELY (xfpm_polkit_obj) )
- {
- g_object_ref (xfpm_polkit_obj);
- }
- else
- {
- xfpm_polkit_obj = g_object_new (XFPM_TYPE_POLKIT, NULL);
- g_object_add_weak_pointer (xfpm_polkit_obj, &xfpm_polkit_obj);
- }
-
- return XFPM_POLKIT (xfpm_polkit_obj);
+ static gpointer xfpm_polkit_obj = NULL;
+
+ if ( G_LIKELY (xfpm_polkit_obj) )
+ {
+ g_object_ref (xfpm_polkit_obj);
+ }
+ else
+ {
+ xfpm_polkit_obj = g_object_new (XFPM_TYPE_POLKIT, NULL);
+ g_object_add_weak_pointer (xfpm_polkit_obj, &xfpm_polkit_obj);
+ }
+
+ return XFPM_POLKIT (xfpm_polkit_obj);
}
-gboolean xfpm_polkit_check_auth (XfpmPolkit *polkit, const gchar *action_id)
+gboolean
+xfpm_polkit_check_auth (XfpmPolkit *polkit, const gchar *action_id)
{
#ifdef ENABLE_POLKIT
- xfpm_polkit_init_data (polkit);
+ xfpm_polkit_init_data (polkit);
#endif
- return xfpm_polkit_check_auth_intern (polkit, action_id);
+ return xfpm_polkit_check_auth_intern (polkit, action_id);
}
diff --git a/src/xfpm-polkit.h b/src/xfpm-polkit.h
index 6cc082d..56389c2 100644
--- a/src/xfpm-polkit.h
+++ b/src/xfpm-polkit.h
@@ -33,25 +33,21 @@ typedef struct XfpmPolkitPrivate XfpmPolkitPrivate;
typedef struct
{
- GObject parent;
- XfpmPolkitPrivate *priv;
-
+ GObject parent;
+ XfpmPolkitPrivate *priv;
} XfpmPolkit;
typedef struct
{
- GObjectClass parent_class;
-
- void (*auth_changed) (XfpmPolkit *polkit);
+ GObjectClass parent_class;
+ void (*auth_changed) (XfpmPolkit *polkit);
} XfpmPolkitClass;
-GType xfpm_polkit_get_type (void) G_GNUC_CONST;
-
-XfpmPolkit *xfpm_polkit_get (void);
-
-gboolean xfpm_polkit_check_auth (XfpmPolkit *polkit,
- const gchar *action_id);
+GType xfpm_polkit_get_type (void) G_GNUC_CONST;
+XfpmPolkit *xfpm_polkit_get (void);
+gboolean xfpm_polkit_check_auth (XfpmPolkit *polkit,
+ const gchar *action_id);
G_END_DECLS
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index 4919f47..f6087ad 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -66,17 +66,17 @@
static void xfpm_power_finalize (GObject *object);
static void xfpm_power_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
static void xfpm_power_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
static void xfpm_power_change_presentation_mode (XfpmPower *power,
- gboolean presentation_mode);
+ gboolean presentation_mode);
static void xfpm_update_blank_time (XfpmPower *power);
@@ -85,80 +85,80 @@ static void xfpm_power_dbus_init (XfpmPower *power);
struct XfpmPowerPrivate
{
- GDBusConnection *bus;
+ GDBusConnection *bus;
- UpClient *upower;
+ UpClient *upower;
- GHashTable *hash;
+ GHashTable *hash;
- XfpmSystemd *systemd;
- XfpmConsoleKit *console;
- XfpmInhibit *inhibit;
- XfpmXfconf *conf;
+ XfpmSystemd *systemd;
+ XfpmConsoleKit *console;
+ XfpmInhibit *inhibit;
+ XfpmXfconf *conf;
- XfpmBatteryCharge overall_state;
- gboolean critical_action_done;
+ XfpmBatteryCharge overall_state;
+ gboolean critical_action_done;
- XfpmDpms *dpms;
- gboolean presentation_mode;
- gint on_ac_blank;
- gint on_battery_blank;
- EggIdletime *idletime;
+ XfpmDpms *dpms;
+ gboolean presentation_mode;
+ gint on_ac_blank;
+ gint on_battery_blank;
+ EggIdletime *idletime;
- gboolean inhibited;
- gboolean screensaver_inhibited;
- XfceScreenSaver *screensaver;
+ gboolean inhibited;
+ gboolean screensaver_inhibited;
+ XfceScreenSaver *screensaver;
- XfpmNotify *notify;
+ XfpmNotify *notify;
#ifdef ENABLE_POLKIT
- XfpmPolkit *polkit;
+ XfpmPolkit *polkit;
#endif
- gboolean auth_suspend;
- gboolean auth_hibernate;
-
- /* Properties */
- gboolean on_low_battery;
- gboolean lid_is_present;
- gboolean lid_is_closed;
- gboolean on_battery;
- gchar *daemon_version;
- gboolean can_suspend;
- gboolean can_hibernate;
-
- /**
- * Warning dialog to use when notification daemon
- * doesn't support actions.
- **/
- GtkWidget *dialog;
+ gboolean auth_suspend;
+ gboolean auth_hibernate;
+
+ /* Properties */
+ gboolean on_low_battery;
+ gboolean lid_is_present;
+ gboolean lid_is_closed;
+ gboolean on_battery;
+ gchar *daemon_version;
+ gboolean can_suspend;
+ gboolean can_hibernate;
+
+ /**
+ * Warning dialog to use when notification daemon
+ * doesn't support actions.
+ **/
+ GtkWidget *dialog;
};
enum
{
- PROP_0,
- PROP_ON_LOW_BATTERY,
- PROP_ON_BATTERY,
- PROP_AUTH_SUSPEND,
- PROP_AUTH_HIBERNATE,
- PROP_CAN_SUSPEND,
- PROP_CAN_HIBERNATE,
- PROP_HAS_LID,
- PROP_PRESENTATION_MODE,
- PROP_ON_AC_BLANK,
- PROP_ON_BATTERY_BLANK,
- N_PROPERTIES
+ PROP_0,
+ PROP_ON_LOW_BATTERY,
+ PROP_ON_BATTERY,
+ PROP_AUTH_SUSPEND,
+ PROP_AUTH_HIBERNATE,
+ PROP_CAN_SUSPEND,
+ PROP_CAN_HIBERNATE,
+ PROP_HAS_LID,
+ PROP_PRESENTATION_MODE,
+ PROP_ON_AC_BLANK,
+ PROP_ON_BATTERY_BLANK,
+ N_PROPERTIES
};
enum
{
- ON_BATTERY_CHANGED,
- LOW_BATTERY_CHANGED,
- LID_CHANGED,
- WAKING_UP,
- SLEEPING,
- ASK_SHUTDOWN,
- SHUTDOWN,
- LAST_SIGNAL
+ ON_BATTERY_CHANGED,
+ LOW_BATTERY_CHANGED,
+ LID_CHANGED,
+ WAKING_UP,
+ SLEEPING,
+ ASK_SHUTDOWN,
+ SHUTDOWN,
+ LAST_SIGNAL
};
static guint signals [LAST_SIGNAL] = { 0 };
@@ -174,110 +174,110 @@ G_DEFINE_TYPE_WITH_PRIVATE (XfpmPower, xfpm_power, G_TYPE_OBJECT)
static gboolean
check_for_consolekit2 (XfpmPower *power)
{
- XfpmConsoleKit *console;
- gboolean can_suspend, can_hibernate;
+ XfpmConsoleKit *console;
+ gboolean can_suspend, can_hibernate;
- g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
+ g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
- if (power->priv->console == NULL)
- return FALSE;
+ if (power->priv->console == NULL)
+ return FALSE;
- console = power->priv->console;
+ console = power->priv->console;
- g_object_get (G_OBJECT (console),
- "can-suspend", &can_suspend,
- NULL);
- g_object_get (G_OBJECT (console),
- "can-hibernate", &can_hibernate,
- NULL);
+ g_object_get (G_OBJECT (console),
+ "can-suspend", &can_suspend,
+ NULL);
+ g_object_get (G_OBJECT (console),
+ "can-hibernate", &can_hibernate,
+ NULL);
/* ConsoleKit2 supports suspend and hibernate */
- if (can_suspend || can_hibernate)
- {
- return TRUE;
- }
+ if (can_suspend || can_hibernate)
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
#ifdef ENABLE_POLKIT
static void
xfpm_power_check_polkit_auth (XfpmPower *power)
{
- const char *suspend = NULL, *hibernate = NULL;
- if (LOGIND_RUNNING())
+ const char *suspend = NULL, *hibernate = NULL;
+ if (LOGIND_RUNNING())
+ {
+ XFPM_DEBUG ("using logind suspend backend");
+ suspend = POLKIT_AUTH_SUSPEND_LOGIND;
+ hibernate = POLKIT_AUTH_HIBERNATE_LOGIND;
+ }
+ else
+ {
+ if (power->priv->console != NULL)
{
- XFPM_DEBUG ("using logind suspend backend");
- suspend = POLKIT_AUTH_SUSPEND_LOGIND;
- hibernate = POLKIT_AUTH_HIBERNATE_LOGIND;
+ /* ConsoleKit2 supports suspend and hibernate */
+ if (check_for_consolekit2 (power))
+ {
+ XFPM_DEBUG ("using consolekit2 suspend backend");
+ suspend = POLKIT_AUTH_SUSPEND_CONSOLEKIT2;
+ hibernate = POLKIT_AUTH_HIBERNATE_CONSOLEKIT2;
+ }
+ else
+ {
+ XFPM_DEBUG ("using xfpm internal suspend backend");
+ suspend = POLKIT_AUTH_SUSPEND_XFPM;
+ hibernate = POLKIT_AUTH_HIBERNATE_XFPM;
+ }
}
- else
- {
- if (power->priv->console != NULL)
- {
- /* ConsoleKit2 supports suspend and hibernate */
- if (check_for_consolekit2 (power))
- {
- XFPM_DEBUG ("using consolekit2 suspend backend");
- suspend = POLKIT_AUTH_SUSPEND_CONSOLEKIT2;
- hibernate = POLKIT_AUTH_HIBERNATE_CONSOLEKIT2;
- }
- else
- {
- XFPM_DEBUG ("using xfpm internal suspend backend");
- suspend = POLKIT_AUTH_SUSPEND_XFPM;
- hibernate = POLKIT_AUTH_HIBERNATE_XFPM;
- }
- }
- }
- power->priv->auth_suspend = xfpm_polkit_check_auth (power->priv->polkit,
- suspend);
+ }
+ power->priv->auth_suspend = xfpm_polkit_check_auth (power->priv->polkit,
+ suspend);
- power->priv->auth_hibernate = xfpm_polkit_check_auth (power->priv->polkit,
- hibernate);
+ power->priv->auth_hibernate = xfpm_polkit_check_auth (power->priv->polkit,
+ hibernate);
}
#endif
static void
xfpm_power_check_power (XfpmPower *power, gboolean on_battery)
{
- if (on_battery != power->priv->on_battery )
- {
- GList *list;
- guint len, i;
- g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, on_battery);
-
- xfpm_dpms_set_on_battery (power->priv->dpms, on_battery);
-
- /* Dismiss critical notifications on battery state changes */
- xfpm_notify_close_critical (power->priv->notify);
-
- power->priv->on_battery = on_battery;
- list = g_hash_table_get_values (power->priv->hash);
- len = g_list_length (list);
- for ( i = 0; i < len; i++)
- {
- g_object_set (G_OBJECT (g_list_nth_data (list, i)),
- "ac-online", !on_battery,
- NULL);
- xfpm_update_blank_time (power);
- }
- }
+ if (on_battery != power->priv->on_battery )
+ {
+ GList *list;
+ guint len, i;
+ g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, on_battery);
+
+ xfpm_dpms_set_on_battery (power->priv->dpms, on_battery);
+
+ /* Dismiss critical notifications on battery state changes */
+ xfpm_notify_close_critical (power->priv->notify);
+
+ power->priv->on_battery = on_battery;
+ list = g_hash_table_get_values (power->priv->hash);
+ len = g_list_length (list);
+ for ( i = 0; i < len; i++)
+ {
+ g_object_set (G_OBJECT (g_list_nth_data (list, i)),
+ "ac-online", !on_battery,
+ NULL);
+ xfpm_update_blank_time (power);
+ }
+ }
}
static void
xfpm_power_check_lid (XfpmPower *power, gboolean present, gboolean closed)
{
- power->priv->lid_is_present = present;
+ power->priv->lid_is_present = present;
- if (power->priv->lid_is_present)
+ if (power->priv->lid_is_present)
+ {
+ if (closed != power->priv->lid_is_closed )
{
- if (closed != power->priv->lid_is_closed )
- {
- power->priv->lid_is_closed = closed;
- g_signal_emit (G_OBJECT (power), signals [LID_CHANGED], 0, power->priv->lid_is_closed);
- }
+ power->priv->lid_is_closed = closed;
+ g_signal_emit (G_OBJECT (power), signals [LID_CHANGED], 0, power->priv->lid_is_closed);
}
+ }
}
/*
@@ -294,156 +294,154 @@ xfpm_power_check_lid (XfpmPower *power, gboolean present, gboolean closed)
static void
xfpm_power_get_properties (XfpmPower *power)
{
- gboolean on_battery;
- gboolean lid_is_closed;
- gboolean lid_is_present;
-
- if ( LOGIND_RUNNING () )
+ gboolean on_battery;
+ gboolean lid_is_closed;
+ gboolean lid_is_present;
+
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-suspend", &power->priv->can_suspend,
+ NULL);
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-hibernate", &power->priv->can_hibernate,
+ NULL);
+ }
+ else
+ {
+ if (check_for_consolekit2 (power))
{
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-suspend", &power->priv->can_suspend,
- NULL);
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-hibernate", &power->priv->can_hibernate,
- NULL);
- }
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-suspend", &power->priv->can_suspend,
+ NULL);
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-hibernate", &power->priv->can_hibernate,
+ NULL);
+ }
else
{
- if (check_for_consolekit2 (power))
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-suspend", &power->priv->can_suspend,
- NULL);
- g_object_get (G_OBJECT (power->priv->console),
- "can-hibernate", &power->priv->can_hibernate,
- NULL);
- }
- else
- {
- power->priv->can_suspend = xfpm_suspend_can_suspend ();
- power->priv->can_hibernate = xfpm_suspend_can_hibernate ();
- }
+ power->priv->can_suspend = xfpm_suspend_can_suspend ();
+ power->priv->can_hibernate = xfpm_suspend_can_hibernate ();
}
-
- g_object_get (power->priv->upower,
- "on-battery", &on_battery,
- "lid-is-closed", &lid_is_closed,
- "lid-is-present", &lid_is_present,
- NULL);
- xfpm_power_check_lid (power, lid_is_present, lid_is_closed);
- xfpm_power_check_power (power, on_battery);
+ }
+
+ g_object_get (power->priv->upower,
+ "on-battery", &on_battery,
+ "lid-is-closed", &lid_is_closed,
+ "lid-is-present", &lid_is_present,
+ NULL);
+ xfpm_power_check_lid (power, lid_is_present, lid_is_closed);
+ xfpm_power_check_power (power, on_battery);
}
static void
xfpm_power_report_error (XfpmPower *power, const gchar *error, const gchar *icon_name)
{
- GtkStatusIcon *battery = NULL;
- guint i, len;
- GList *list;
-
- list = g_hash_table_get_values (power->priv->hash);
- len = g_list_length (list);
-
- for ( i = 0; i < len; i++)
- {
- UpDeviceKind type;
- battery = g_list_nth_data (list, i);
- type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
- if ( type == UP_DEVICE_KIND_BATTERY ||
- type == UP_DEVICE_KIND_UPS )
- break;
- }
-
- xfpm_notify_show_notification (power->priv->notify,
- _("Power Manager"),
- error,
- icon_name,
- 10000,
- XFPM_NOTIFY_CRITICAL);
-
+ GtkStatusIcon *battery = NULL;
+ guint i, len;
+ GList *list;
+
+ list = g_hash_table_get_values (power->priv->hash);
+ len = g_list_length (list);
+
+ for ( i = 0; i < len; i++)
+ {
+ UpDeviceKind type;
+ battery = g_list_nth_data (list, i);
+ type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
+ if ( type == UP_DEVICE_KIND_BATTERY ||
+ type == UP_DEVICE_KIND_UPS )
+ break;
+ }
+
+ xfpm_notify_show_notification (power->priv->notify,
+ _("Power Manager"),
+ error,
+ icon_name,
+ 10000,
+ XFPM_NOTIFY_CRITICAL);
}
static void
xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
{
- GError *error = NULL;
- gboolean lock_screen;
+ GError *error = NULL;
+ gboolean lock_screen;
#ifdef WITH_NETWORK_MANAGER
- gboolean network_manager_sleep;
+ gboolean network_manager_sleep;
#endif
- XfpmBrightness *brightness;
- gint32 brightness_level;
-
- if ( power->priv->inhibited && force == FALSE)
- {
- GtkWidget *dialog;
- gboolean ret;
-
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("An application is currently disabling the automatic sleep. "
- "Doing this action now may damage the working state of this application.\n"
- "Are you sure you want to hibernate the system?"));
- ret = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
-
- if ( !ret || ret == GTK_RESPONSE_NO)
- return;
- }
+ XfpmBrightness *brightness;
+ gint32 brightness_level;
- g_signal_emit (G_OBJECT (power), signals [SLEEPING], 0);
+ if ( power->priv->inhibited && force == FALSE)
+ {
+ GtkWidget *dialog;
+ gboolean ret;
+
+ dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("An application is currently disabling the automatic sleep. "
+ "Doing this action now may damage the working state of this application.\n"
+ "Are you sure you want to hibernate the system?"));
+ ret = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ if ( !ret || ret == GTK_RESPONSE_NO)
+ return;
+ }
+
+ g_signal_emit (G_OBJECT (power), signals [SLEEPING], 0);
/* Get the current brightness level so we can use it after we suspend */
- brightness = xfpm_brightness_new();
- xfpm_brightness_setup (brightness);
- xfpm_brightness_get_level (brightness, &brightness_level);
+ brightness = xfpm_brightness_new();
+ xfpm_brightness_setup (brightness);
+ xfpm_brightness_get_level (brightness, &brightness_level);
#ifdef WITH_NETWORK_MANAGER
- g_object_get (G_OBJECT (power->priv->conf),
- NETWORK_MANAGER_SLEEP, &network_manager_sleep,
- NULL);
+ g_object_get (G_OBJECT (power->priv->conf),
+ NETWORK_MANAGER_SLEEP, &network_manager_sleep,
+ NULL);
+
+ if ( network_manager_sleep )
+ {
+ xfpm_network_manager_sleep (TRUE);
+ }
+#endif
+
+ g_object_get (G_OBJECT (power->priv->conf),
+ LOCK_SCREEN_ON_SLEEP, &lock_screen,
+ NULL);
+ if ( lock_screen )
+ {
+#ifdef WITH_NETWORK_MANAGER
if ( network_manager_sleep )
{
- xfpm_network_manager_sleep (TRUE);
+ /* 2 seconds, to give network manager time to sleep */
+ g_usleep (2000000);
}
#endif
-
- g_object_get (G_OBJECT (power->priv->conf),
- LOCK_SCREEN_ON_SLEEP, &lock_screen,
- NULL);
-
- if ( lock_screen )
+ if (!xfce_screensaver_lock (power->priv->screensaver))
{
-#ifdef WITH_NETWORK_MANAGER
- if ( network_manager_sleep )
- {
- /* 2 seconds, to give network manager time to sleep */
- g_usleep (2000000);
- }
-#endif
- if (!xfce_screensaver_lock (power->priv->screensaver))
- {
- GtkWidget *dialog;
- gboolean ret;
-
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("None of the screen lock tools ran "
- "successfully, the screen will not "
- "be locked.\n"
- "Do you still want to continue to "
- "suspend the system?"));
- ret = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- if ( !ret || ret == GTK_RESPONSE_NO)
- return;
- }
+ GtkWidget *dialog;
+ gboolean ret;
+
+ dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("None of the screen lock tools ran "
+ "successfully, the screen will not "
+ "be locked.\n"
+ "Do you still want to continue to "
+ "suspend the system?"));
+ ret = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ if ( !ret || ret == GTK_RESPONSE_NO)
+ return;
+ }
}
/* This is fun, here's the order of operations:
@@ -452,582 +450,578 @@ xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
* - if ConsoleKit2 is running then use it
* - if everything else fails use our built-in fallback
*/
- if ( LOGIND_RUNNING () )
+ if ( LOGIND_RUNNING () )
+ {
+ xfpm_systemd_sleep (power->priv->systemd, sleep_time, &error);
+ }
+ else
+ {
+ if (!g_strcmp0 (sleep_time, "Hibernate"))
{
- xfpm_systemd_sleep (power->priv->systemd, sleep_time, &error);
+ if (check_for_consolekit2 (power))
+ {
+ xfpm_console_kit_hibernate (power->priv->console, &error);
+ }
+ else
+ {
+ xfpm_suspend_try_action (XFPM_HIBERNATE);
+ }
}
else
{
- if (!g_strcmp0 (sleep_time, "Hibernate"))
- {
- if (check_for_consolekit2 (power))
- {
- xfpm_console_kit_hibernate (power->priv->console, &error);
- }
- else
- {
- xfpm_suspend_try_action (XFPM_HIBERNATE);
- }
- }
- else
- {
- if (check_for_consolekit2 (power))
- {
- xfpm_console_kit_suspend (power->priv->console, &error);
- }
- else
- {
- xfpm_suspend_try_action (XFPM_SUSPEND);
- }
- }
+ if (check_for_consolekit2 (power))
+ {
+ xfpm_console_kit_suspend (power->priv->console, &error);
+ }
+ else
+ {
+ xfpm_suspend_try_action (XFPM_SUSPEND);
+ }
}
+ }
- if ( error )
+ if ( error )
+ {
+ if ( g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY) )
+ {
+ XFPM_DEBUG ("D-Bus time out, but should be harmless");
+ }
+ else
{
- if ( g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_NO_REPLY) )
- {
- XFPM_DEBUG ("D-Bus time out, but should be harmless");
- }
- else
- {
- xfpm_power_report_error (power, error->message, "dialog-error");
- g_error_free (error);
- }
+ xfpm_power_report_error (power, error->message, "dialog-error");
+ g_error_free (error);
}
+ }
- g_signal_emit (G_OBJECT (power), signals [WAKING_UP], 0);
+ g_signal_emit (G_OBJECT (power), signals [WAKING_UP], 0);
/* Check/update any changes while we slept */
- xfpm_power_get_properties (power);
+ xfpm_power_get_properties (power);
/* Restore the brightness level from before we suspended */
- xfpm_brightness_set_level (brightness, brightness_level);
+ xfpm_brightness_set_level (brightness, brightness_level);
#ifdef WITH_NETWORK_MANAGER
- if ( network_manager_sleep )
- {
- xfpm_network_manager_sleep (FALSE);
- }
+ if ( network_manager_sleep )
+ {
+ xfpm_network_manager_sleep (FALSE);
+ }
#endif
}
static void
xfpm_power_hibernate_clicked (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog );
- power->priv->dialog = NULL;
- xfpm_power_sleep (power, "Hibernate", TRUE);
+ gtk_widget_destroy (power->priv->dialog );
+ power->priv->dialog = NULL;
+ xfpm_power_sleep (power, "Hibernate", TRUE);
}
static void
xfpm_power_suspend_clicked (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog );
- power->priv->dialog = NULL;
- xfpm_power_sleep (power, "Suspend", TRUE);
+ gtk_widget_destroy (power->priv->dialog );
+ power->priv->dialog = NULL;
+ xfpm_power_sleep (power, "Suspend", TRUE);
}
static void
xfpm_power_shutdown_clicked (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog );
- power->priv->dialog = NULL;
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
+ gtk_widget_destroy (power->priv->dialog );
+ power->priv->dialog = NULL;
+ g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
}
static XfpmBatteryCharge
xfpm_power_get_current_charge_state (XfpmPower *power)
{
- GList *list;
- guint len, i;
- gboolean power_supply;
- XfpmBatteryCharge max_charge_status = XFPM_BATTERY_CHARGE_UNKNOWN;
-
- list = g_hash_table_get_values (power->priv->hash);
- len = g_list_length (list);
+ GList *list;
+ guint len, i;
+ gboolean power_supply;
+ XfpmBatteryCharge max_charge_status = XFPM_BATTERY_CHARGE_UNKNOWN;
- for ( i = 0; i < len; i++ )
- {
- XfpmBatteryCharge battery_charge;
- UpDeviceKind type;
+ list = g_hash_table_get_values (power->priv->hash);
+ len = g_list_length (list);
- g_object_get (G_OBJECT (g_list_nth_data (list, i)),
- "charge-status", &battery_charge,
- "device-type", &type,
- "ac-online", &power_supply,
- NULL);
- if ( type != UP_DEVICE_KIND_BATTERY &&
- type != UP_DEVICE_KIND_UPS &&
- power_supply != TRUE)
- continue;
-
- max_charge_status = MAX (max_charge_status, battery_charge);
- }
-
- return max_charge_status;
+ for ( i = 0; i < len; i++ )
+ {
+ XfpmBatteryCharge battery_charge;
+ UpDeviceKind type;
+
+ g_object_get (G_OBJECT (g_list_nth_data (list, i)),
+ "charge-status", &battery_charge,
+ "device-type", &type,
+ "ac-online", &power_supply,
+ NULL);
+ if ( type != UP_DEVICE_KIND_BATTERY &&
+ type != UP_DEVICE_KIND_UPS &&
+ power_supply != TRUE)
+ continue;
+
+ max_charge_status = MAX (max_charge_status, battery_charge);
+ }
+
+ return max_charge_status;
}
static void
xfpm_power_notify_action_callback (NotifyNotification *n, gchar *action, XfpmPower *power)
{
- if ( !g_strcmp0 (action, "Shutdown") )
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
- else
- xfpm_power_sleep (power, action, TRUE);
+ if ( !g_strcmp0 (action, "Shutdown") )
+ g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
+ else
+ xfpm_power_sleep (power, action, TRUE);
}
static void
xfpm_power_add_actions_to_notification (XfpmPower *power, NotifyNotification *n)
{
- gboolean can_shutdown;
+ gboolean can_shutdown;
-
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-shutdown", &can_shutdown,
- NULL);
- }
- else
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_shutdown,
- NULL);
- }
-
- if ( power->priv->can_hibernate && power->priv->auth_hibernate )
- {
- xfpm_notify_add_action_to_notification(
- power->priv->notify,
- n,
- "Hibernate",
- _("Hibernate the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
- }
-
- if ( power->priv->can_suspend && power->priv->auth_suspend )
- {
- xfpm_notify_add_action_to_notification(
- power->priv->notify,
- n,
- "Suspend",
- _("Suspend the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
- }
-
- if (can_shutdown )
- xfpm_notify_add_action_to_notification(
- power->priv->notify,
- n,
- "Shutdown",
- _("Shutdown the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
+
+ if ( power->priv->can_hibernate && power->priv->auth_hibernate )
+ {
+ xfpm_notify_add_action_to_notification(
+ power->priv->notify,
+ n,
+ "Hibernate",
+ _("Hibernate the system"),
+ (NotifyActionCallback)xfpm_power_notify_action_callback,
+ power);
+ }
+
+ if ( power->priv->can_suspend && power->priv->auth_suspend )
+ {
+ xfpm_notify_add_action_to_notification(
+ power->priv->notify,
+ n,
+ "Suspend",
+ _("Suspend the system"),
+ (NotifyActionCallback)xfpm_power_notify_action_callback,
+ power);
+ }
+
+ if ( can_shutdown )
+ xfpm_notify_add_action_to_notification (power->priv->notify,
+ n,
+ "Shutdown",
+ _("Shutdown the system"),
+ (NotifyActionCallback)xfpm_power_notify_action_callback,
+ power);
}
static void
xfpm_power_show_critical_action_notification (XfpmPower *power, XfpmBattery *battery)
{
- const gchar *message;
- NotifyNotification *n;
+ const gchar *message;
+ NotifyNotification *n;
- message = _("System is running on low power. "\
+ message = _("System is running on low power. "\
"Save your work to avoid losing data");
- n =
- xfpm_notify_new_notification (power->priv->notify,
- _("Power Manager"),
- message,
- xfpm_battery_get_icon_name (battery),
- 20000,
- XFPM_NOTIFY_CRITICAL);
+ n =
+ xfpm_notify_new_notification (power->priv->notify,
+ _("Power Manager"),
+ message,
+ xfpm_battery_get_icon_name (battery),
+ 20000,
+ XFPM_NOTIFY_CRITICAL);
- xfpm_power_add_actions_to_notification (power, n);
- xfpm_notify_critical (power->priv->notify, n);
+ xfpm_power_add_actions_to_notification (power, n);
+ xfpm_notify_critical (power->priv->notify, n);
}
static void
xfpm_power_close_critical_dialog (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog);
- power->priv->dialog = NULL;
+ gtk_widget_destroy (power->priv->dialog);
+ power->priv->dialog = NULL;
}
static void
xfpm_power_show_critical_action_gtk (XfpmPower *power)
{
- GtkWidget *dialog;
- GtkWidget *content_area;
- GtkWidget *cancel;
- const gchar *message;
- gboolean can_shutdown;
-
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-shutdown", &can_shutdown,
- NULL);
- }
- else
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_shutdown,
- NULL);
- }
+ GtkWidget *dialog;
+ GtkWidget *content_area;
+ GtkWidget *cancel;
+ const gchar *message;
+ gboolean can_shutdown;
+
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
- message = _("System is running on low power. "\
- "Save your work to avoid losing data");
+ message = _("System is running on low power. "\
+ "Save your work to avoid losing data");
- dialog = gtk_dialog_new_with_buttons (_("Power Manager"), NULL, GTK_DIALOG_MODAL,
- NULL, NULL);
+ dialog = gtk_dialog_new_with_buttons (_("Power Manager"), NULL, GTK_DIALOG_MODAL,
+ NULL, NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- GTK_RESPONSE_CANCEL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_CANCEL);
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+ content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_box_pack_start (GTK_BOX (content_area), gtk_label_new (message),
- TRUE, TRUE, 8);
+ gtk_box_pack_start (GTK_BOX (content_area), gtk_label_new (message),
+ TRUE, TRUE, 8);
- if ( power->priv->can_hibernate && power->priv->auth_hibernate )
- {
- GtkWidget *hibernate;
- hibernate = gtk_button_new_with_label (_("Hibernate"));
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), hibernate, GTK_RESPONSE_NONE);
+ if ( power->priv->can_hibernate && power->priv->auth_hibernate )
+ {
+ GtkWidget *hibernate;
+ hibernate = gtk_button_new_with_label (_("Hibernate"));
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog), hibernate, GTK_RESPONSE_NONE);
- g_signal_connect_swapped (hibernate, "clicked",
- G_CALLBACK (xfpm_power_hibernate_clicked), power);
- }
+ g_signal_connect_swapped (hibernate, "clicked",
+ G_CALLBACK (xfpm_power_hibernate_clicked), power);
+ }
- if ( power->priv->can_suspend && power->priv->auth_suspend )
- {
- GtkWidget *suspend;
+ if ( power->priv->can_suspend && power->priv->auth_suspend )
+ {
+ GtkWidget *suspend;
- suspend = gtk_button_new_with_label (_("Suspend"));
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), suspend, GTK_RESPONSE_NONE);
+ suspend = gtk_button_new_with_label (_("Suspend"));
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog), suspend, GTK_RESPONSE_NONE);
- g_signal_connect_swapped (suspend, "clicked",
- G_CALLBACK (xfpm_power_suspend_clicked), power);
+ g_signal_connect_swapped (suspend, "clicked",
+ G_CALLBACK (xfpm_power_suspend_clicked), power);
}
- if ( can_shutdown )
- {
- GtkWidget *shutdown;
-
- shutdown = gtk_button_new_with_label (_("Shutdown"));
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), shutdown, GTK_RESPONSE_NONE);
+ if ( can_shutdown )
+ {
+ GtkWidget *shutdown;
- g_signal_connect_swapped (shutdown, "clicked",
- G_CALLBACK (xfpm_power_shutdown_clicked), power);
- }
+ shutdown = gtk_button_new_with_label (_("Shutdown"));
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog), shutdown, GTK_RESPONSE_NONE);
- cancel = gtk_button_new_with_label (_("_Cancel"));
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancel, GTK_RESPONSE_NONE);
+ g_signal_connect_swapped (shutdown, "clicked",
+ G_CALLBACK (xfpm_power_shutdown_clicked), power);
+ }
- g_signal_connect_swapped (cancel, "clicked",
- G_CALLBACK (xfpm_power_close_critical_dialog), power);
+ cancel = gtk_button_new_with_label (_("_Cancel"));
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancel, GTK_RESPONSE_NONE);
- g_signal_connect_swapped (dialog, "destroy",
- G_CALLBACK (xfpm_power_close_critical_dialog), power);
- if ( power->priv->dialog )
- {
- gtk_widget_destroy (power->priv->dialog);
- power->priv->dialog = NULL;
+ g_signal_connect_swapped (cancel, "clicked",
+ G_CALLBACK (xfpm_power_close_critical_dialog), power);
- }
- power->priv->dialog = dialog;
- gtk_widget_show_all (dialog);
+ g_signal_connect_swapped (dialog, "destroy",
+ G_CALLBACK (xfpm_power_close_critical_dialog), power);
+ if ( power->priv->dialog )
+ {
+ gtk_widget_destroy (power->priv->dialog);
+ power->priv->dialog = NULL;
+ }
+ power->priv->dialog = dialog;
+ gtk_widget_show_all (dialog);
}
static void
xfpm_power_show_critical_action (XfpmPower *power, XfpmBattery *battery)
{
- gboolean supports_actions;
+ gboolean supports_actions;
- g_object_get (G_OBJECT (power->priv->notify),
- "actions", &supports_actions,
- NULL);
+ g_object_get (G_OBJECT (power->priv->notify),
+ "actions", &supports_actions,
+ NULL);
- if ( supports_actions )
- xfpm_power_show_critical_action_notification (power, battery);
- else
- xfpm_power_show_critical_action_gtk (power);
+ if ( supports_actions )
+ xfpm_power_show_critical_action_notification (power, battery);
+ else
+ xfpm_power_show_critical_action_gtk (power);
}
static void
xfpm_power_process_critical_action (XfpmPower *power, XfpmShutdownRequest req)
{
- if ( req == XFPM_ASK )
- g_signal_emit (G_OBJECT (power), signals [ASK_SHUTDOWN], 0);
- else if ( req == XFPM_DO_SUSPEND )
- xfpm_power_sleep (power, "Suspend", TRUE);
- else if ( req == XFPM_DO_HIBERNATE )
- xfpm_power_sleep (power, "Hibernate", TRUE);
- else if ( req == XFPM_DO_SHUTDOWN )
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
+ if ( req == XFPM_ASK )
+ g_signal_emit (G_OBJECT (power), signals [ASK_SHUTDOWN], 0);
+ else if ( req == XFPM_DO_SUSPEND )
+ xfpm_power_sleep (power, "Suspend", TRUE);
+ else if ( req == XFPM_DO_HIBERNATE )
+ xfpm_power_sleep (power, "Hibernate", TRUE);
+ else if ( req == XFPM_DO_SHUTDOWN )
+ g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
}
static void
xfpm_power_system_on_critical_power (XfpmPower *power, XfpmBattery *battery)
{
- XfpmShutdownRequest critical_action;
-
- g_object_get (G_OBJECT (power->priv->conf),
- CRITICAL_BATT_ACTION_CFG, &critical_action,
- NULL);
-
- XFPM_DEBUG ("System is running on low power");
- XFPM_DEBUG_ENUM (critical_action, XFPM_TYPE_SHUTDOWN_REQUEST, "Critical battery action");
-
- if ( critical_action == XFPM_DO_NOTHING )
+ XfpmShutdownRequest critical_action;
+
+ g_object_get (G_OBJECT (power->priv->conf),
+ CRITICAL_BATT_ACTION_CFG, &critical_action,
+ NULL);
+
+ XFPM_DEBUG ("System is running on low power");
+ XFPM_DEBUG_ENUM (critical_action, XFPM_TYPE_SHUTDOWN_REQUEST, "Critical battery action");
+
+ if ( critical_action == XFPM_DO_NOTHING )
+ {
+ xfpm_power_show_critical_action (power, battery);
+ }
+ else
+ {
+ if (power->priv->critical_action_done == FALSE)
{
- xfpm_power_show_critical_action (power, battery);
+ power->priv->critical_action_done = TRUE;
+ xfpm_power_process_critical_action (power, critical_action);
}
else
{
- if (power->priv->critical_action_done == FALSE)
- {
- power->priv->critical_action_done = TRUE;
- xfpm_power_process_critical_action (power, critical_action);
- }
- else
- {
- xfpm_power_show_critical_action (power, battery);
- }
+ xfpm_power_show_critical_action (power, battery);
}
+ }
}
static void
xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
{
- gboolean notify;
- XfpmBatteryCharge battery_charge;
- XfpmBatteryCharge current_charge;
+ gboolean notify;
+ XfpmBatteryCharge battery_charge;
+ XfpmBatteryCharge current_charge;
- battery_charge = xfpm_battery_get_charge (battery);
- current_charge = xfpm_power_get_current_charge_state (power);
+ battery_charge = xfpm_battery_get_charge (battery);
+ current_charge = xfpm_power_get_current_charge_state (power);
- XFPM_DEBUG_ENUM (current_charge, XFPM_TYPE_BATTERY_CHARGE, "Current system charge status");
+ XFPM_DEBUG_ENUM (current_charge, XFPM_TYPE_BATTERY_CHARGE, "Current system charge status");
- if (current_charge == power->priv->overall_state)
- return;
+ if (current_charge == power->priv->overall_state)
+ return;
- if (current_charge >= XFPM_BATTERY_CHARGE_LOW)
- power->priv->critical_action_done = FALSE;
+ if (current_charge >= XFPM_BATTERY_CHARGE_LOW)
+ power->priv->critical_action_done = FALSE;
- power->priv->overall_state = current_charge;
+ power->priv->overall_state = current_charge;
- if ( current_charge == XFPM_BATTERY_CHARGE_CRITICAL && power->priv->on_battery)
- {
- xfpm_power_system_on_critical_power (power, battery);
+ if ( current_charge == XFPM_BATTERY_CHARGE_CRITICAL && power->priv->on_battery)
+ {
+ xfpm_power_system_on_critical_power (power, battery);
- power->priv->on_low_battery = TRUE;
- g_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->priv->on_low_battery);
- return;
- }
+ power->priv->on_low_battery = TRUE;
+ g_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->priv->on_low_battery);
+ return;
+ }
- if ( power->priv->on_low_battery )
- {
- power->priv->on_low_battery = FALSE;
- g_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->priv->on_low_battery);
- }
+ if ( power->priv->on_low_battery )
+ {
+ power->priv->on_low_battery = FALSE;
+ g_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->priv->on_low_battery);
+ }
- g_object_get (G_OBJECT (power->priv->conf),
- GENERAL_NOTIFICATION_CFG, ¬ify,
- NULL);
+ g_object_get (G_OBJECT (power->priv->conf),
+ GENERAL_NOTIFICATION_CFG, ¬ify,
+ NULL);
- if ( power->priv->on_battery )
+ if ( power->priv->on_battery )
+ {
+ if ( current_charge == XFPM_BATTERY_CHARGE_LOW )
{
- if ( current_charge == XFPM_BATTERY_CHARGE_LOW )
- {
- if ( notify )
- xfpm_notify_show_notification (power->priv->notify,
- _("Power Manager"),
- _("System is running on low power"),
- xfpm_battery_get_icon_name (battery),
- 10000,
- XFPM_NOTIFY_NORMAL);
-
- }
- else if ( battery_charge == XFPM_BATTERY_CHARGE_LOW )
- {
- if ( notify )
- {
- gchar *msg;
- gchar *time_str;
-
- const gchar *battery_name = xfpm_battery_get_battery_name (battery);
-
- time_str = xfpm_battery_get_time_left (battery);
-
- msg = g_strdup_printf (_("Your %s charge level is low\nEstimated time left %s"), battery_name, time_str);
-
-
- xfpm_notify_show_notification (power->priv->notify,
- _("Power Manager"),
- msg,
- xfpm_battery_get_icon_name (battery),
- 10000,
- XFPM_NOTIFY_NORMAL);
- g_free (msg);
- g_free (time_str);
- }
- }
+ if ( notify )
+ xfpm_notify_show_notification (power->priv->notify,
+ _("Power Manager"),
+ _("System is running on low power"),
+ xfpm_battery_get_icon_name (battery),
+ 10000,
+ XFPM_NOTIFY_NORMAL);
+
+ }
+ else if ( battery_charge == XFPM_BATTERY_CHARGE_LOW )
+ {
+ if ( notify )
+ {
+ gchar *msg;
+ gchar *time_str;
+
+ const gchar *battery_name = xfpm_battery_get_battery_name (battery);
+
+ time_str = xfpm_battery_get_time_left (battery);
+
+ msg = g_strdup_printf (_("Your %s charge level is low\nEstimated time left %s"), battery_name, time_str);
+
+
+ xfpm_notify_show_notification (power->priv->notify,
+ _("Power Manager"),
+ msg,
+ xfpm_battery_get_icon_name (battery),
+ 10000,
+ XFPM_NOTIFY_NORMAL);
+ g_free (msg);
+ g_free (time_str);
+ }
}
+ }
/*Current charge is okay now, then close the dialog*/
- if ( power->priv->dialog )
- {
- gtk_widget_destroy (power->priv->dialog);
- power->priv->dialog = NULL;
- }
+ if ( power->priv->dialog )
+ {
+ gtk_widget_destroy (power->priv->dialog);
+ power->priv->dialog = NULL;
+ }
}
static void
xfpm_power_add_device (UpDevice *device, XfpmPower *power)
{
- guint device_type = UP_DEVICE_KIND_UNKNOWN;
- const gchar *object_path = up_device_get_object_path(device);
+ guint device_type = UP_DEVICE_KIND_UNKNOWN;
+ const gchar *object_path = up_device_get_object_path(device);
/* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
- g_object_get (device,
- "kind", &device_type,
- NULL);
-
- XFPM_DEBUG ("'%s' device added", up_device_kind_to_string(device_type));
-
- if ( device_type == UP_DEVICE_KIND_BATTERY ||
- device_type == UP_DEVICE_KIND_UPS ||
- device_type == UP_DEVICE_KIND_MOUSE ||
- device_type == UP_DEVICE_KIND_KEYBOARD ||
- device_type == UP_DEVICE_KIND_PHONE)
- {
- GtkWidget *battery;
- XFPM_DEBUG( "Battery device type '%s' detected at: %s",
- up_device_kind_to_string(device_type), object_path);
- battery = xfpm_battery_new ();
-
- xfpm_battery_monitor_device (XFPM_BATTERY (battery),
- object_path,
- device_type);
- g_hash_table_insert (power->priv->hash, g_strdup (object_path), battery);
-
- g_signal_connect (battery, "battery-charge-changed",
- G_CALLBACK (xfpm_power_battery_charge_changed_cb), power);
-
- }
+ g_object_get (device,
+ "kind", &device_type,
+ NULL);
+
+ XFPM_DEBUG ("'%s' device added", up_device_kind_to_string(device_type));
+
+ if ( device_type == UP_DEVICE_KIND_BATTERY ||
+ device_type == UP_DEVICE_KIND_UPS ||
+ device_type == UP_DEVICE_KIND_MOUSE ||
+ device_type == UP_DEVICE_KIND_KEYBOARD ||
+ device_type == UP_DEVICE_KIND_PHONE)
+ {
+ GtkWidget *battery;
+ XFPM_DEBUG( "Battery device type '%s' detected at: %s",
+ up_device_kind_to_string(device_type), object_path);
+ battery = xfpm_battery_new ();
+
+ xfpm_battery_monitor_device (XFPM_BATTERY (battery),
+ object_path,
+ device_type);
+ g_hash_table_insert (power->priv->hash, g_strdup (object_path), battery);
+
+ g_signal_connect (battery, "battery-charge-changed",
+ G_CALLBACK (xfpm_power_battery_charge_changed_cb), power);
+ }
}
static void
xfpm_power_get_power_devices (XfpmPower *power)
{
- GPtrArray *array = NULL;
- guint i;
+ GPtrArray *array = NULL;
+ guint i;
#if UP_CHECK_VERSION(0, 99, 8)
- array = up_client_get_devices2 (power->priv->upower);
+ array = up_client_get_devices2 (power->priv->upower);
#else
- array = up_client_get_devices (power->priv->upower);
+ array = up_client_get_devices (power->priv->upower);
#endif
- if ( array )
+ if ( array )
+ {
+ for ( i = 0; i < array->len; i++)
{
- for ( i = 0; i < array->len; i++)
- {
- UpDevice *device = g_ptr_array_index (array, i);
- const gchar *object_path = up_device_get_object_path(device);
- XFPM_DEBUG ("Power device detected at : %s", object_path);
- xfpm_power_add_device (device, power);
- }
- g_ptr_array_free (array, TRUE);
+ UpDevice *device = g_ptr_array_index (array, i);
+ const gchar *object_path = up_device_get_object_path(device);
+ XFPM_DEBUG ("Power device detected at : %s", object_path);
+ xfpm_power_add_device (device, power);
}
+ g_ptr_array_free (array, TRUE);
+ }
}
static void
xfpm_power_remove_device (XfpmPower *power, const gchar *object_path)
{
- g_hash_table_remove (power->priv->hash, object_path);
+ g_hash_table_remove (power->priv->hash, object_path);
}
static void
xfpm_power_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean is_inhibit, XfpmPower *power)
{
- if (power->priv->inhibited != is_inhibit)
+ if (power->priv->inhibited != is_inhibit)
+ {
+ power->priv->inhibited = is_inhibit;
+
+ XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
+ power->priv->inhibited ? "TRUE" : "FALSE",
+ power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
+ power->priv->presentation_mode ? "TRUE" : "FALSE");
+
+ /* If we are inhibited make sure we inhibit the screensaver too */
+ if (is_inhibit)
+ {
+ if (!power->priv->screensaver_inhibited)
+ {
+ xfce_screensaver_inhibit (power->priv->screensaver, TRUE);
+ power->priv->screensaver_inhibited = TRUE;
+ }
+ }
+ else
{
- power->priv->inhibited = is_inhibit;
-
- XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
- power->priv->inhibited ? "TRUE" : "FALSE",
- power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
- power->priv->presentation_mode ? "TRUE" : "FALSE");
-
- /* If we are inhibited make sure we inhibit the screensaver too */
- if (is_inhibit)
- {
- if (!power->priv->screensaver_inhibited)
- {
- xfce_screensaver_inhibit (power->priv->screensaver, TRUE);
- power->priv->screensaver_inhibited = TRUE;
- }
- }
- else
- {
- /* Or make sure we remove the screensaver inhibit */
- if (power->priv->screensaver_inhibited && !power->priv->presentation_mode)
- {
- xfce_screensaver_inhibit (power->priv->screensaver, FALSE);
- power->priv->screensaver_inhibited = FALSE;
- }
- }
+ /* Or make sure we remove the screensaver inhibit */
+ if (power->priv->screensaver_inhibited && !power->priv->presentation_mode)
+ {
+ xfce_screensaver_inhibit (power->priv->screensaver, FALSE);
+ power->priv->screensaver_inhibited = FALSE;
+ }
}
+ }
- XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
- power->priv->inhibited ? "TRUE" : "FALSE",
- power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
- power->priv->presentation_mode ? "TRUE" : "FALSE");
+ XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
+ power->priv->inhibited ? "TRUE" : "FALSE",
+ power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
+ power->priv->presentation_mode ? "TRUE" : "FALSE");
}
static void
xfpm_power_changed_cb (UpClient *upower,
- GParamSpec *pspec,
- XfpmPower *power)
+ GParamSpec *pspec,
+ XfpmPower *power)
{
- xfpm_power_get_properties (power);
+ xfpm_power_get_properties (power);
}
static void
xfpm_power_device_added_cb (UpClient *upower, UpDevice *device, XfpmPower *power)
{
- xfpm_power_add_device (device, power);
+ xfpm_power_add_device (device, power);
}
static void
xfpm_power_device_removed_cb (UpClient *upower, const gchar *object_path, XfpmPower *power)
{
- xfpm_power_remove_device (power, object_path);
+ xfpm_power_remove_device (power, object_path);
}
#ifdef ENABLE_POLKIT
static void
xfpm_power_polkit_auth_changed_cb (XfpmPower *power)
{
- XFPM_DEBUG ("Auth configuration changed");
- xfpm_power_check_polkit_auth (power);
+ XFPM_DEBUG ("Auth configuration changed");
+ xfpm_power_check_polkit_auth (power);
}
#endif
static void
xfpm_power_class_init (XfpmPowerClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = xfpm_power_finalize;
+ object_class->finalize = xfpm_power_finalize;
- object_class->get_property = xfpm_power_get_property;
- object_class->set_property = xfpm_power_set_property;
+ object_class->get_property = xfpm_power_get_property;
+ object_class->set_property = xfpm_power_set_property;
- signals [ON_BATTERY_CHANGED] =
+ signals [ON_BATTERY_CHANGED] =
g_signal_new ("on-battery-changed",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1036,7 +1030,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [LOW_BATTERY_CHANGED] =
+ signals [LOW_BATTERY_CHANGED] =
g_signal_new ("low-battery-changed",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1045,7 +1039,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [LID_CHANGED] =
+ signals [LID_CHANGED] =
g_signal_new ("lid-changed",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1054,7 +1048,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [WAKING_UP] =
+ signals [WAKING_UP] =
g_signal_new ("waking-up",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1063,7 +1057,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- signals [SLEEPING] =
+ signals [SLEEPING] =
g_signal_new ("sleeping",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1072,7 +1066,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- signals [ASK_SHUTDOWN] =
+ signals [ASK_SHUTDOWN] =
g_signal_new ("ask-shutdown",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1081,7 +1075,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- signals [SHUTDOWN] =
+ signals [SHUTDOWN] =
g_signal_new ("shutdown",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
@@ -1096,420 +1090,421 @@ xfpm_power_class_init (XfpmPowerClass *klass)
| G_PARAM_STATIC_NICK \
| G_PARAM_STATIC_BLURB)
- 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));
-
- g_object_class_install_property (object_class,
- PROP_AUTH_SUSPEND,
- g_param_spec_boolean ("auth-suspend",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_AUTH_HIBERNATE,
- g_param_spec_boolean ("auth-hibernate",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_HIBERNATE,
- g_param_spec_boolean ("can-hibernate",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_SUSPEND,
- g_param_spec_boolean ("can-suspend",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_HAS_LID,
- g_param_spec_boolean ("has-lid",
- NULL, NULL,
- 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));
-
- g_object_class_install_property (object_class,
- PROP_ON_AC_BLANK,
- g_param_spec_int (ON_AC_BLANK,
- NULL, NULL,
- 0,
- G_MAXINT16,
- 10,
- XFPM_PARAM_FLAGS));
-
- g_object_class_install_property (object_class,
- PROP_ON_BATTERY_BLANK,
- g_param_spec_int (ON_BATTERY_BLANK,
- NULL, NULL,
- 0,
- G_MAXINT16,
- 10,
- XFPM_PARAM_FLAGS));
+ 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));
+
+ g_object_class_install_property (object_class,
+ PROP_AUTH_SUSPEND,
+ g_param_spec_boolean ("auth-suspend",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_AUTH_HIBERNATE,
+ g_param_spec_boolean ("auth-hibernate",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_CAN_HIBERNATE,
+ g_param_spec_boolean ("can-hibernate",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_CAN_SUSPEND,
+ g_param_spec_boolean ("can-suspend",
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_HAS_LID,
+ g_param_spec_boolean ("has-lid",
+ NULL, NULL,
+ 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));
+
+ g_object_class_install_property (object_class,
+ PROP_ON_AC_BLANK,
+ g_param_spec_int (ON_AC_BLANK,
+ NULL, NULL,
+ 0,
+ G_MAXINT16,
+ 10,
+ XFPM_PARAM_FLAGS));
+
+ g_object_class_install_property (object_class,
+ PROP_ON_BATTERY_BLANK,
+ g_param_spec_int (ON_BATTERY_BLANK,
+ NULL, NULL,
+ 0,
+ G_MAXINT16,
+ 10,
+ XFPM_PARAM_FLAGS));
#undef XFPM_PARAM_FLAGS
- xfpm_power_dbus_class_init (klass);
+ xfpm_power_dbus_class_init (klass);
}
static void
xfpm_power_init (XfpmPower *power)
{
- GError *error = NULL;
-
- power->priv = xfpm_power_get_instance_private (power);
-
- power->priv->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- power->priv->lid_is_present = FALSE;
- power->priv->lid_is_closed = FALSE;
- power->priv->on_battery = FALSE;
- power->priv->on_low_battery = FALSE;
- power->priv->daemon_version = NULL;
- power->priv->can_suspend = FALSE;
- power->priv->can_hibernate = FALSE;
- power->priv->auth_hibernate = TRUE;
- power->priv->auth_suspend = TRUE;
- power->priv->dialog = NULL;
- power->priv->overall_state = XFPM_BATTERY_CHARGE_OK;
- power->priv->critical_action_done = FALSE;
-
- power->priv->dpms = xfpm_dpms_new ();
-
- power->priv->presentation_mode = FALSE;
- power->priv->on_ac_blank = 15;
- power->priv->on_battery_blank = 10;
-
- power->priv->inhibit = xfpm_inhibit_new ();
- power->priv->notify = xfpm_notify_new ();
- power->priv->conf = xfpm_xfconf_new ();
- power->priv->upower = up_client_new ();
- power->priv->screensaver = xfce_screensaver_new ();
-
- power->priv->systemd = NULL;
- power->priv->console = NULL;
- if ( LOGIND_RUNNING () )
- power->priv->systemd = xfpm_systemd_new ();
- else
- power->priv->console = xfpm_console_kit_new ();
+ GError *error = NULL;
+
+ power->priv = xfpm_power_get_instance_private (power);
+
+ power->priv->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ power->priv->lid_is_present = FALSE;
+ power->priv->lid_is_closed = FALSE;
+ power->priv->on_battery = FALSE;
+ power->priv->on_low_battery = FALSE;
+ power->priv->daemon_version = NULL;
+ power->priv->can_suspend = FALSE;
+ power->priv->can_hibernate = FALSE;
+ power->priv->auth_hibernate = TRUE;
+ power->priv->auth_suspend = TRUE;
+ power->priv->dialog = NULL;
+ power->priv->overall_state = XFPM_BATTERY_CHARGE_OK;
+ power->priv->critical_action_done = FALSE;
+
+ power->priv->dpms = xfpm_dpms_new ();
+
+ power->priv->presentation_mode = FALSE;
+ power->priv->on_ac_blank = 15;
+ power->priv->on_battery_blank = 10;
+
+ power->priv->inhibit = xfpm_inhibit_new ();
+ power->priv->notify = xfpm_notify_new ();
+ power->priv->conf = xfpm_xfconf_new ();
+ power->priv->upower = up_client_new ();
+ power->priv->screensaver = xfce_screensaver_new ();
+
+ power->priv->systemd = NULL;
+ power->priv->console = NULL;
+ if ( LOGIND_RUNNING () )
+ power->priv->systemd = xfpm_systemd_new ();
+ else
+ power->priv->console = xfpm_console_kit_new ();
#ifdef ENABLE_POLKIT
- power->priv->polkit = xfpm_polkit_get ();
- g_signal_connect_swapped (power->priv->polkit, "auth-changed",
- G_CALLBACK (xfpm_power_polkit_auth_changed_cb), power);
+ power->priv->polkit = xfpm_polkit_get ();
+ g_signal_connect_swapped (power->priv->polkit, "auth-changed",
+ G_CALLBACK (xfpm_power_polkit_auth_changed_cb), power);
#endif
- g_signal_connect (power->priv->inhibit, "has-inhibit-changed",
- G_CALLBACK (xfpm_power_inhibit_changed_cb), power);
+ g_signal_connect (power->priv->inhibit, "has-inhibit-changed",
+ G_CALLBACK (xfpm_power_inhibit_changed_cb), power);
- power->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ power->priv->bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
- if ( error )
- {
- g_critical ("Unable to connect to the system bus : %s", error->message);
- g_error_free (error);
- goto out;
- }
+ if ( error )
+ {
+ g_critical ("Unable to connect to the system bus : %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
- g_signal_connect (power->priv->upower, "device-added", G_CALLBACK (xfpm_power_device_added_cb), power);
- g_signal_connect (power->priv->upower, "device-removed", G_CALLBACK (xfpm_power_device_removed_cb), power);
- g_signal_connect (power->priv->upower, "notify", G_CALLBACK (xfpm_power_changed_cb), power);
+ g_signal_connect (power->priv->upower, "device-added", G_CALLBACK (xfpm_power_device_added_cb), power);
+ g_signal_connect (power->priv->upower, "device-removed", G_CALLBACK (xfpm_power_device_removed_cb), power);
+ g_signal_connect (power->priv->upower, "notify", G_CALLBACK (xfpm_power_changed_cb), power);
- xfpm_power_get_power_devices (power);
- xfpm_power_get_properties (power);
+ xfpm_power_get_power_devices (power);
+ xfpm_power_get_properties (power);
#ifdef ENABLE_POLKIT
- xfpm_power_check_polkit_auth (power);
+ xfpm_power_check_polkit_auth (power);
#endif
out:
- xfpm_power_dbus_init (power);
+ xfpm_power_dbus_init (power);
- /*
- * Emit org.freedesktop.PowerManagement session signals on startup
- */
- g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, power->priv->on_battery);
+ /*
+ * Emit org.freedesktop.PowerManagement session signals on startup
+ */
+ g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, power->priv->on_battery);
}
-static void xfpm_power_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+static void
+xfpm_power_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- XfpmPower *power;
- power = XFPM_POWER (object);
+ XfpmPower *power;
+ power = XFPM_POWER (object);
- switch (prop_id)
- {
+ switch (prop_id)
+ {
case PROP_ON_BATTERY:
- g_value_set_boolean (value, power->priv->on_battery);
- break;
+ g_value_set_boolean (value, power->priv->on_battery);
+ break;
case PROP_AUTH_HIBERNATE:
- g_value_set_boolean (value, power->priv->auth_hibernate);
- break;
+ g_value_set_boolean (value, power->priv->auth_hibernate);
+ break;
case PROP_AUTH_SUSPEND:
- g_value_set_boolean (value, power->priv->auth_suspend);
- break;
+ g_value_set_boolean (value, power->priv->auth_suspend);
+ break;
case PROP_CAN_SUSPEND:
- g_value_set_boolean (value, power->priv->can_suspend);
- break;
+ g_value_set_boolean (value, power->priv->can_suspend);
+ break;
case PROP_CAN_HIBERNATE:
- g_value_set_boolean (value, power->priv->can_hibernate);
- break;
+ g_value_set_boolean (value, power->priv->can_hibernate);
+ break;
case PROP_HAS_LID:
- g_value_set_boolean (value, power->priv->lid_is_present);
- break;
+ 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;
+ g_value_set_boolean (value, power->priv->presentation_mode);
+ break;
case PROP_ON_AC_BLANK:
- g_value_set_int (value, power->priv->on_ac_blank);
- break;
+ g_value_set_int (value, power->priv->on_ac_blank);
+ break;
case PROP_ON_BATTERY_BLANK:
- g_value_set_int (value, power->priv->on_battery_blank);
- break;
+ g_value_set_int (value, power->priv->on_battery_blank);
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ 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)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- XfpmPower *power = XFPM_POWER (object);
- gint on_ac_blank, on_battery_blank;
+ XfpmPower *power = XFPM_POWER (object);
+ gint on_ac_blank, on_battery_blank;
- switch (prop_id)
- {
+ switch (prop_id)
+ {
case PROP_PRESENTATION_MODE:
- xfpm_power_change_presentation_mode (power, g_value_get_boolean (value));
- break;
+ xfpm_power_change_presentation_mode (power, g_value_get_boolean (value));
+ break;
case PROP_ON_AC_BLANK:
- on_ac_blank = g_value_get_int (value);
- power->priv->on_ac_blank = on_ac_blank;
- xfpm_update_blank_time (power);
- break;
+ on_ac_blank = g_value_get_int (value);
+ power->priv->on_ac_blank = on_ac_blank;
+ xfpm_update_blank_time (power);
+ break;
case PROP_ON_BATTERY_BLANK:
- on_battery_blank = g_value_get_int (value);
- power->priv->on_battery_blank = on_battery_blank;
- xfpm_update_blank_time (power);
- break;
+ on_battery_blank = g_value_get_int (value);
+ power->priv->on_battery_blank = on_battery_blank;
+ xfpm_update_blank_time (power);
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
xfpm_power_finalize (GObject *object)
{
- XfpmPower *power;
+ XfpmPower *power;
- power = XFPM_POWER (object);
+ power = XFPM_POWER (object);
- g_free (power->priv->daemon_version);
+ g_free (power->priv->daemon_version);
- g_object_unref (power->priv->inhibit);
- g_object_unref (power->priv->notify);
- g_object_unref (power->priv->conf);
- g_object_unref (power->priv->screensaver);
+ g_object_unref (power->priv->inhibit);
+ g_object_unref (power->priv->notify);
+ g_object_unref (power->priv->conf);
+ g_object_unref (power->priv->screensaver);
- if ( power->priv->systemd != NULL )
- g_object_unref (power->priv->systemd);
- if ( power->priv->console != NULL )
- g_object_unref (power->priv->console);
+ if ( power->priv->systemd != NULL )
+ g_object_unref (power->priv->systemd);
+ if ( power->priv->console != NULL )
+ g_object_unref (power->priv->console);
- g_object_unref (power->priv->bus);
+ g_object_unref (power->priv->bus);
- g_hash_table_destroy (power->priv->hash);
+ g_hash_table_destroy (power->priv->hash);
#ifdef ENABLE_POLKIT
- g_object_unref (power->priv->polkit);
+ g_object_unref (power->priv->polkit);
#endif
- g_object_unref(power->priv->dpms);
+ g_object_unref(power->priv->dpms);
- G_OBJECT_CLASS (xfpm_power_parent_class)->finalize (object);
+ G_OBJECT_CLASS (xfpm_power_parent_class)->finalize (object);
}
static XfpmPower*
xfpm_power_new (void)
{
- XfpmPower *power = XFPM_POWER(g_object_new (XFPM_TYPE_POWER, NULL));
+ XfpmPower *power = XFPM_POWER(g_object_new (XFPM_TYPE_POWER, NULL));
- xfconf_g_property_bind (xfpm_xfconf_get_channel(power->priv->conf),
- XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, G_TYPE_BOOLEAN,
- G_OBJECT(power), PRESENTATION_MODE);
+ xfconf_g_property_bind (xfpm_xfconf_get_channel(power->priv->conf),
+ XFPM_PROPERTIES_PREFIX PRESENTATION_MODE, G_TYPE_BOOLEAN,
+ G_OBJECT(power), PRESENTATION_MODE);
- xfconf_g_property_bind (xfpm_xfconf_get_channel(power->priv->conf),
- XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK, G_TYPE_INT,
- G_OBJECT (power), ON_BATTERY_BLANK);
+ xfconf_g_property_bind (xfpm_xfconf_get_channel(power->priv->conf),
+ XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK, G_TYPE_INT,
+ G_OBJECT (power), ON_BATTERY_BLANK);
- xfconf_g_property_bind (xfpm_xfconf_get_channel(power->priv->conf),
- XFPM_PROPERTIES_PREFIX ON_AC_BLANK, G_TYPE_INT,
- G_OBJECT (power), ON_AC_BLANK);
+ xfconf_g_property_bind (xfpm_xfconf_get_channel(power->priv->conf),
+ XFPM_PROPERTIES_PREFIX ON_AC_BLANK, G_TYPE_INT,
+ G_OBJECT (power), ON_AC_BLANK);
- return power;
+ return power;
}
XfpmPower *
xfpm_power_get (void)
{
- static gpointer xfpm_power_object = NULL;
-
- if ( G_LIKELY (xfpm_power_object != NULL ) )
- {
- g_object_ref (xfpm_power_object);
- }
- else
- {
- xfpm_power_object = xfpm_power_new ();
- g_object_add_weak_pointer (xfpm_power_object, &xfpm_power_object);
- }
-
- return XFPM_POWER (xfpm_power_object);
+ static gpointer xfpm_power_object = NULL;
+
+ if ( G_LIKELY (xfpm_power_object != NULL ) )
+ {
+ g_object_ref (xfpm_power_object);
+ }
+ else
+ {
+ xfpm_power_object = xfpm_power_new ();
+ g_object_add_weak_pointer (xfpm_power_object, &xfpm_power_object);
+ }
+
+ return XFPM_POWER (xfpm_power_object);
}
void xfpm_power_suspend (XfpmPower *power, gboolean force)
{
- xfpm_power_sleep (power, "Suspend", force);
+ xfpm_power_sleep (power, "Suspend", force);
}
void xfpm_power_hibernate (XfpmPower *power, gboolean force)
{
- xfpm_power_sleep (power, "Hibernate", force);
+ xfpm_power_sleep (power, "Hibernate", force);
}
gboolean xfpm_power_has_battery (XfpmPower *power)
{
- GtkStatusIcon *battery = NULL;
- guint i, len;
- GList *list;
-
- gboolean ret = FALSE;
-
- list = g_hash_table_get_values (power->priv->hash);
- len = g_list_length (list);
-
- for ( i = 0; i < len; i++)
+ GtkStatusIcon *battery = NULL;
+ guint i, len;
+ GList *list;
+
+ gboolean ret = FALSE;
+
+ list = g_hash_table_get_values (power->priv->hash);
+ len = g_list_length (list);
+
+ for ( i = 0; i < len; i++)
+ {
+ UpDeviceKind type;
+ battery = g_list_nth_data (list, i);
+ type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
+ if ( type == UP_DEVICE_KIND_BATTERY ||
+ type == UP_DEVICE_KIND_UPS )
{
- UpDeviceKind type;
- battery = g_list_nth_data (list, i);
- type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
- if ( type == UP_DEVICE_KIND_BATTERY ||
- type == UP_DEVICE_KIND_UPS )
- {
- ret = TRUE;
- break;
- }
+ ret = TRUE;
+ break;
}
+ }
- return ret;
+ return ret;
}
static void
xfpm_update_blank_time (XfpmPower *power)
{
- int prev_timeout, prev_interval, prev_prefer_blanking, prev_allow_exposures;
- Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default ());
- guint screensaver_timeout;
+ int prev_timeout, prev_interval, prev_prefer_blanking, prev_allow_exposures;
+ Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default ());
+ guint screensaver_timeout;
- if (power->priv->on_battery)
- screensaver_timeout = power->priv->on_battery_blank;
- else
- screensaver_timeout = power->priv->on_ac_blank;
+ if (power->priv->on_battery)
+ screensaver_timeout = power->priv->on_battery_blank;
+ else
+ screensaver_timeout = power->priv->on_ac_blank;
/* Presentation mode disables blanking */
- if (power->priv->presentation_mode)
- screensaver_timeout = 0;
+ if (power->priv->presentation_mode)
+ screensaver_timeout = 0;
- XFPM_DEBUG ("Timeout: %d", screensaver_timeout);
+ XFPM_DEBUG ("Timeout: %d", screensaver_timeout);
- XGetScreenSaver(display, &prev_timeout, &prev_interval, &prev_prefer_blanking, &prev_allow_exposures);
- XSetScreenSaver(display, screensaver_timeout * 60, prev_interval, prev_prefer_blanking, prev_allow_exposures);
+ XGetScreenSaver(display, &prev_timeout, &prev_interval, &prev_prefer_blanking, &prev_allow_exposures);
+ XSetScreenSaver(display, screensaver_timeout * 60, prev_interval, prev_prefer_blanking, prev_allow_exposures);
}
static void
xfpm_power_change_presentation_mode (XfpmPower *power, gboolean presentation_mode)
{
/* no change, exit */
- if (power->priv->presentation_mode == presentation_mode)
- return;
+ if (power->priv->presentation_mode == presentation_mode)
+ return;
- power->priv->presentation_mode = presentation_mode;
+ power->priv->presentation_mode = presentation_mode;
- /* presentation mode inhibits dpms */
- xfpm_dpms_inhibit (power->priv->dpms, presentation_mode);
+ /* presentation mode inhibits dpms */
+ xfpm_dpms_inhibit (power->priv->dpms, presentation_mode);
- XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
- power->priv->inhibited ? "TRUE" : "FALSE",
- power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
- power->priv->presentation_mode ? "TRUE" : "FALSE");
+ XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
+ power->priv->inhibited ? "TRUE" : "FALSE",
+ power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
+ power->priv->presentation_mode ? "TRUE" : "FALSE");
- if (presentation_mode)
+ if (presentation_mode)
+ {
+ /* presentation mode inhibits the screensaver */
+ if (!power->priv->screensaver_inhibited)
{
- /* presentation mode inhibits the screensaver */
- if (!power->priv->screensaver_inhibited)
- {
- xfce_screensaver_inhibit (power->priv->screensaver, TRUE);
- power->priv->screensaver_inhibited = TRUE;
- }
+ xfce_screensaver_inhibit (power->priv->screensaver, TRUE);
+ power->priv->screensaver_inhibited = TRUE;
}
- else
- {
- EggIdletime *idletime;
+ }
+ else
+ {
+ EggIdletime *idletime;
- /* make sure we remove the screensaver inhibit */
- if (power->priv->screensaver_inhibited && !power->priv->inhibited)
- {
- xfce_screensaver_inhibit (power->priv->screensaver, FALSE);
- power->priv->screensaver_inhibited = FALSE;
- }
+ /* make sure we remove the screensaver inhibit */
+ if (power->priv->screensaver_inhibited && !power->priv->inhibited)
+ {
+ xfce_screensaver_inhibit (power->priv->screensaver, FALSE);
+ power->priv->screensaver_inhibited = FALSE;
+ }
- /* reset the timers */
- idletime = egg_idletime_new ();
- egg_idletime_alarm_reset_all (idletime);
+ /* reset the timers */
+ idletime = egg_idletime_new ();
+ egg_idletime_alarm_reset_all (idletime);
- g_object_unref (idletime);
- }
+ g_object_unref (idletime);
+ }
- XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
- power->priv->inhibited ? "TRUE" : "FALSE",
- power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
- power->priv->presentation_mode ? "TRUE" : "FALSE");
+ XFPM_DEBUG ("is_inhibit %s, screensaver_inhibited %s, presentation_mode %s",
+ power->priv->inhibited ? "TRUE" : "FALSE",
+ power->priv->screensaver_inhibited ? "TRUE" : "FALSE",
+ power->priv->presentation_mode ? "TRUE" : "FALSE");
- xfpm_update_blank_time (power);
+ xfpm_update_blank_time (power);
}
gboolean
xfpm_power_is_in_presentation_mode (XfpmPower *power)
{
- g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
+ g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
- return power->priv->presentation_mode || power->priv->inhibited;
+ return power->priv->presentation_mode || power->priv->inhibited;
}
@@ -1519,44 +1514,44 @@ xfpm_power_is_in_presentation_mode (XfpmPower *power)
*
*/
static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_hibernate (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_suspend (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_reboot (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_shutdown (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_hibernate (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_can_suspend (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_get_on_battery (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
static gboolean xfpm_power_dbus_get_low_battery (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data);
+ GDBusMethodInvocation *invocation,
+ gpointer user_data);
#include "org.freedesktop.PowerManagement.h"
@@ -1568,302 +1563,311 @@ xfpm_power_dbus_class_init (XfpmPowerClass * klass)
static void
xfpm_power_dbus_init (XfpmPower *power)
{
- GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
- XfpmPowerManagement *power_dbus;
-
- TRACE ("entering");
-
- power_dbus = xfpm_power_management_skeleton_new ();
- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (power_dbus),
- bus,
- "/org/freedesktop/PowerManagement",
- NULL);
-
- g_signal_connect_swapped (power_dbus,
- "handle-shutdown",
- G_CALLBACK (xfpm_power_dbus_shutdown),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-reboot",
- G_CALLBACK (xfpm_power_dbus_reboot),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-hibernate",
- G_CALLBACK (xfpm_power_dbus_hibernate),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-suspend",
- G_CALLBACK (xfpm_power_dbus_suspend),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-can-reboot",
- G_CALLBACK (xfpm_power_dbus_can_reboot),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-can-shutdown",
- G_CALLBACK (xfpm_power_dbus_can_shutdown),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-can-hibernate",
- G_CALLBACK (xfpm_power_dbus_can_hibernate),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-can-suspend",
- G_CALLBACK (xfpm_power_dbus_can_suspend),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-get-on-battery",
- G_CALLBACK (xfpm_power_dbus_get_on_battery),
- power);
- g_signal_connect_swapped (power_dbus,
- "handle-get-low-battery",
- G_CALLBACK (xfpm_power_dbus_get_low_battery),
- power);
+ GDBusConnection *bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ XfpmPowerManagement *power_dbus;
+
+ TRACE ("entering");
+
+ power_dbus = xfpm_power_management_skeleton_new ();
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (power_dbus),
+ bus,
+ "/org/freedesktop/PowerManagement",
+ NULL);
+
+ g_signal_connect_swapped (power_dbus,
+ "handle-shutdown",
+ G_CALLBACK (xfpm_power_dbus_shutdown),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-reboot",
+ G_CALLBACK (xfpm_power_dbus_reboot),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-hibernate",
+ G_CALLBACK (xfpm_power_dbus_hibernate),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-suspend",
+ G_CALLBACK (xfpm_power_dbus_suspend),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-reboot",
+ G_CALLBACK (xfpm_power_dbus_can_reboot),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-shutdown",
+ G_CALLBACK (xfpm_power_dbus_can_shutdown),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-hibernate",
+ G_CALLBACK (xfpm_power_dbus_can_hibernate),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-can-suspend",
+ G_CALLBACK (xfpm_power_dbus_can_suspend),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-get-on-battery",
+ G_CALLBACK (xfpm_power_dbus_get_on_battery),
+ power);
+ g_signal_connect_swapped (power_dbus,
+ "handle-get-low-battery",
+ G_CALLBACK (xfpm_power_dbus_get_low_battery),
+ power);
}
static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- GError *error = NULL;
- gboolean can_reboot;
-
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-shutdown", &can_reboot,
- NULL);
- }
- else
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_reboot,
- NULL);
- }
-
- if ( !can_reboot)
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return TRUE;
- }
-
- if ( LOGIND_RUNNING () )
- xfpm_systemd_shutdown (power->priv->systemd, &error);
- else
- xfpm_console_kit_shutdown (power->priv->console, &error);
-
- if (error)
- {
- g_dbus_method_invocation_return_gerror (invocation, error);
- g_error_free (error);
- }
- else
- {
- xfpm_power_management_complete_shutdown (user_data, invocation);
- }
+ GError *error = NULL;
+ gboolean can_reboot;
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-shutdown", &can_reboot,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-shutdown", &can_reboot,
+ NULL);
+ }
+
+ if ( !can_reboot)
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
return TRUE;
+ }
+
+ if ( LOGIND_RUNNING () )
+ xfpm_systemd_shutdown (power->priv->systemd, &error);
+ else
+ xfpm_console_kit_shutdown (power->priv->console, &error);
+
+ if (error)
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ }
+ else
+ {
+ xfpm_power_management_complete_shutdown (user_data, invocation);
+ }
+
+ return TRUE;
}
-static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_reboot (XfpmPower *power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- GError *error = NULL;
- gboolean can_reboot;
-
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-restart", &can_reboot,
- NULL);
- }
- else
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-restart", &can_reboot,
- NULL);
- }
-
- if ( !can_reboot)
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return TRUE;
- }
-
- if ( LOGIND_RUNNING () )
- xfpm_systemd_reboot (power->priv->systemd, &error);
- else
- xfpm_console_kit_reboot (power->priv->console, &error);
-
- if (error)
- {
- g_dbus_method_invocation_return_gerror (invocation, error);
- g_error_free (error);
- }
- else
- {
- xfpm_power_management_complete_reboot (user_data, invocation);
- }
+ GError *error = NULL;
+ gboolean can_reboot;
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-restart", &can_reboot,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-restart", &can_reboot,
+ NULL);
+ }
+
+ if ( !can_reboot)
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
return TRUE;
+ }
+
+ if ( LOGIND_RUNNING () )
+ xfpm_systemd_reboot (power->priv->systemd, &error);
+ else
+ xfpm_console_kit_reboot (power->priv->console, &error);
+
+ if (error)
+ {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ }
+ else
+ {
+ xfpm_power_management_complete_reboot (user_data, invocation);
+ }
+
+ return TRUE;
}
-static gboolean xfpm_power_dbus_hibernate (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_hibernate (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- if ( !power->priv->auth_hibernate )
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return TRUE;
- }
-
- if (!power->priv->can_hibernate )
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_NO_HARDWARE_SUPPORT,
- _("Suspend not supported"));
- return TRUE;
- }
+ if ( !power->priv->auth_hibernate )
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
+ return TRUE;
+ }
+
+ if (!power->priv->can_hibernate )
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_NO_HARDWARE_SUPPORT,
+ _("Suspend not supported"));
+ return TRUE;
+ }
- xfpm_power_sleep (power, "Hibernate", FALSE);
+ xfpm_power_sleep (power, "Hibernate", FALSE);
- xfpm_power_management_complete_hibernate (user_data, invocation);
+ xfpm_power_management_complete_hibernate (user_data, invocation);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_power_dbus_suspend (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_suspend (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- if ( !power->priv->auth_suspend )
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return TRUE;
- }
-
- if (!power->priv->can_suspend )
- {
- g_dbus_method_invocation_return_error (invocation,
- XFPM_ERROR,
- XFPM_ERROR_NO_HARDWARE_SUPPORT,
- _("Suspend not supported"));
- return TRUE;
- }
+ if ( !power->priv->auth_suspend )
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_PERMISSION_DENIED,
+ _("Permission denied"));
+ return TRUE;
+ }
+
+ if (!power->priv->can_suspend )
+ {
+ g_dbus_method_invocation_return_error (invocation,
+ XFPM_ERROR,
+ XFPM_ERROR_NO_HARDWARE_SUPPORT,
+ _("Suspend not supported"));
+ return TRUE;
+ }
- xfpm_power_sleep (power, "Suspend", FALSE);
+ xfpm_power_sleep (power, "Suspend", FALSE);
- xfpm_power_management_complete_suspend (user_data, invocation);
+ xfpm_power_management_complete_suspend (user_data, invocation);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_power_dbus_can_reboot (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_can_reboot (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- gboolean can_reboot;
+ gboolean can_reboot;
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (power->priv->systemd),
- "can-reboot", &can_reboot,
- NULL);
- }
- else
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-reboot", &can_reboot,
- NULL);
- }
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
+ "can-reboot", &can_reboot,
+ NULL);
+ }
+ else
+ {
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-reboot", &can_reboot,
+ NULL);
+ }
- xfpm_power_management_complete_can_reboot (user_data,
- invocation,
- can_reboot);
+ xfpm_power_management_complete_can_reboot (user_data,
+ invocation,
+ can_reboot);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_power_dbus_can_shutdown (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_can_shutdown (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- gboolean can_shutdown;
+ gboolean can_shutdown;
- if ( LOGIND_RUNNING () )
- {
- g_object_get (G_OBJECT (power->priv->systemd),
+ if ( LOGIND_RUNNING () )
+ {
+ g_object_get (G_OBJECT (power->priv->systemd),
"can-shutdown", &can_shutdown,
NULL);
- }
- else
- {
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_shutdown,
- NULL);
- }
+ }
+ else
+ {
+ g_object_get (G_OBJECT (power->priv->console),
+ "can-shutdown", &can_shutdown,
+ NULL);
+ }
- xfpm_power_management_complete_can_shutdown (user_data,
- invocation,
- can_shutdown);
+ xfpm_power_management_complete_can_shutdown (user_data,
+ invocation,
+ can_shutdown);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_power_dbus_can_hibernate (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_can_hibernate (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- xfpm_power_management_complete_can_hibernate (user_data,
- invocation,
- power->priv->can_hibernate);
- return TRUE;
+ xfpm_power_management_complete_can_hibernate (user_data,
+ invocation,
+ power->priv->can_hibernate);
+ return TRUE;
}
-static gboolean xfpm_power_dbus_can_suspend (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_can_suspend (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- xfpm_power_management_complete_can_suspend (user_data,
- invocation,
- power->priv->can_suspend);
+ xfpm_power_management_complete_can_suspend (user_data,
+ invocation,
+ power->priv->can_suspend);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_power_dbus_get_on_battery (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_get_on_battery (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- xfpm_power_management_complete_get_on_battery (user_data,
- invocation,
- power->priv->on_battery);
+ xfpm_power_management_complete_get_on_battery (user_data,
+ invocation,
+ power->priv->on_battery);
- return TRUE;
+ return TRUE;
}
-static gboolean xfpm_power_dbus_get_low_battery (XfpmPower * power,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
+static gboolean
+xfpm_power_dbus_get_low_battery (XfpmPower * power,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
{
- xfpm_power_management_complete_get_low_battery (user_data,
- invocation,
- power->priv->on_low_battery);
+ xfpm_power_management_complete_get_low_battery (user_data,
+ invocation,
+ power->priv->on_low_battery);
- return TRUE;
+ return TRUE;
}
diff --git a/src/xfpm-power.h b/src/xfpm-power.h
index 7d5bbcb..f95c4e3 100644
--- a/src/xfpm-power.h
+++ b/src/xfpm-power.h
@@ -34,48 +34,34 @@ typedef struct XfpmPowerPrivate XfpmPowerPrivate;
typedef struct
{
- GObject parent;
-
+ GObject parent;
XfpmPowerPrivate *priv;
-
} XfpmPower;
typedef struct
{
- GObjectClass parent_class;
-
- void (*on_battery_changed) (XfpmPower *power,
- gboolean on_battery);
-
- void (*low_battery_changed) (XfpmPower *power,
- gboolean low_battery);
-
- void (*lid_changed) (XfpmPower *power,
- gboolean lid_is_closed);
-
- void (*waking_up) (XfpmPower *power);
-
- void (*sleeping) (XfpmPower *power);
-
- void (*ask_shutdown) (XfpmPower *power);
-
- void (*shutdown) (XfpmPower *power);
+ GObjectClass parent_class;
+ void (*on_battery_changed) (XfpmPower *power,
+ gboolean on_battery);
+ void (*low_battery_changed) (XfpmPower *power,
+ gboolean low_battery);
+ void (*lid_changed) (XfpmPower *power,
+ gboolean lid_is_closed);
+ void (*waking_up) (XfpmPower *power);
+ void (*sleeping) (XfpmPower *power);
+ void (*ask_shutdown) (XfpmPower *power);
+ void (*shutdown) (XfpmPower *power);
} XfpmPowerClass;
-GType xfpm_power_get_type (void) G_GNUC_CONST;
-
-XfpmPower *xfpm_power_get (void);
-
-void xfpm_power_suspend (XfpmPower *power,
- gboolean force);
-
-void xfpm_power_hibernate (XfpmPower *power,
- gboolean force);
-
-gboolean xfpm_power_has_battery (XfpmPower *power);
-
-gboolean xfpm_power_is_in_presentation_mode (XfpmPower *power);
+GType xfpm_power_get_type (void) G_GNUC_CONST;
+XfpmPower *xfpm_power_get (void);
+void xfpm_power_suspend (XfpmPower *power,
+ gboolean force);
+void xfpm_power_hibernate (XfpmPower *power,
+ gboolean force);
+gboolean xfpm_power_has_battery (XfpmPower *power);
+gboolean xfpm_power_is_in_presentation_mode (XfpmPower *power);
G_END_DECLS
diff --git a/src/xfpm-suspend.c b/src/xfpm-suspend.c
index 464dd44..aec2496 100644
--- a/src/xfpm-suspend.c
+++ b/src/xfpm-suspend.c
@@ -53,51 +53,55 @@
static gchar *
get_string_sysctl (GError **err, const gchar *format, ...)
{
- va_list args;
- gchar *name;
- size_t value_len;
- gchar *str = NULL;
-
- g_return_val_if_fail(format != NULL, FALSE);
-
- va_start (args, format);
- name = g_strdup_vprintf (format, args);
- va_end (args);
-
- if (sysctlbyname (name, NULL, &value_len, NULL, 0) == 0) {
- str = g_new (char, value_len + 1);
- if (sysctlbyname (name, str, &value_len, NULL, 0) == 0)
- str[value_len] = 0;
- else {
- g_free (str);
- str = NULL;
- }
- }
-
- if (!str)
- g_set_error (err, 0, 0, "%s", g_strerror(errno));
-
- g_free(name);
- return str;
+ va_list args;
+ gchar *name;
+ size_t value_len;
+ gchar *str = NULL;
+
+ g_return_val_if_fail(format != NULL, FALSE);
+
+ va_start (args, format);
+ name = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ if (sysctlbyname (name, NULL, &value_len, NULL, 0) == 0)
+ {
+ str = g_new (char, value_len + 1);
+
+ if (sysctlbyname (name, str, &value_len, NULL, 0) == 0)
+ str[value_len] = 0;
+ else {
+ g_free (str);
+ str = NULL;
+ }
+ }
+
+ if (!str)
+ g_set_error (err, 0, 0, "%s", g_strerror(errno));
+
+ g_free(name);
+
+ return str;
}
static gboolean
freebsd_supports_sleep_state (const gchar *state)
{
- gboolean ret = FALSE;
- gchar *sleep_states;
+ gboolean ret = FALSE;
+ gchar *sleep_states;
- XFPM_DEBUG("entering");
+ XFPM_DEBUG("entering");
- sleep_states = get_string_sysctl (NULL, "hw.acpi.supported_sleep_state");
- if (sleep_states != NULL) {
- if (strstr (sleep_states, state) != NULL)
- ret = TRUE;
- }
+ sleep_states = get_string_sysctl (NULL, "hw.acpi.supported_sleep_state");
+
+ if (sleep_states != NULL) {
+ if (strstr (sleep_states, state) != NULL)
+ ret = TRUE;
+ }
- g_free (sleep_states);
+ g_free (sleep_states);
- return ret;
+ return ret;
}
#endif
@@ -105,28 +109,29 @@ freebsd_supports_sleep_state (const gchar *state)
static gboolean
linux_supports_sleep_state (const gchar *state)
{
- gboolean ret = FALSE;
- gchar *command;
- GError *error = NULL;
- gint exit_status;
-
- XFPM_DEBUG("entering");
-
- /* run script from pm-utils */
- command = g_strdup_printf ("/usr/bin/pm-is-supported --%s", state);
- g_debug ("executing command: %s", command);
- ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
- if (!ret) {
- g_warning ("failed to run script: %s", error->message);
- g_error_free (error);
- goto out;
- }
- ret = (WIFEXITED(exit_status) && (WEXITSTATUS(exit_status) == EXIT_SUCCESS));
+ gboolean ret = FALSE;
+ gchar *command;
+ GError *error = NULL;
+ gint exit_status;
+
+ XFPM_DEBUG("entering");
+
+ /* run script from pm-utils */
+ command = g_strdup_printf ("/usr/bin/pm-is-supported --%s", state);
+ g_debug ("executing command: %s", command);
+ ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
+
+ if (!ret) {
+ g_warning ("failed to run script: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ ret = (WIFEXITED(exit_status) && (WEXITSTATUS(exit_status) == EXIT_SUCCESS));
out:
- g_free (command);
+ g_free (command);
- return ret;
+ return ret;
}
#endif
@@ -134,68 +139,69 @@ out:
gboolean
xfpm_suspend_can_suspend (void)
{
- XFPM_DEBUG("entering");
+ XFPM_DEBUG("entering");
#ifdef BACKEND_TYPE_FREEBSD
- return freebsd_supports_sleep_state ("S3");
+ return freebsd_supports_sleep_state ("S3");
#endif
#ifdef BACKEND_TYPE_LINUX
- return linux_supports_sleep_state ("suspend");
+ return linux_supports_sleep_state ("suspend");
#endif
#ifdef BACKEND_TYPE_OPENBSD
- return TRUE;
+ return TRUE;
#endif
- return FALSE;
+ return FALSE;
}
gboolean
xfpm_suspend_can_hibernate (void)
{
- XFPM_DEBUG("entering");
+ XFPM_DEBUG("entering");
#ifdef BACKEND_TYPE_FREEBSD
- return freebsd_supports_sleep_state ("S4");
+ return freebsd_supports_sleep_state ("S4");
#endif
#ifdef BACKEND_TYPE_LINUX
- return linux_supports_sleep_state ("hibernate");
+ return linux_supports_sleep_state ("hibernate");
#endif
#ifdef BACKEND_TYPE_OPENBSD
- return TRUE;
+ return TRUE;
#endif
- return FALSE;
+ return FALSE;
}
gboolean
xfpm_suspend_try_action (XfpmActionType type)
{
- const gchar *action;
- gboolean ret;
- GError *error = NULL;
- gint exit_status = 0;
- gchar *command = NULL;
-
- TRACE("entering");
-
- if (type == XFPM_SUSPEND)
- action = "suspend";
- else if (type == XFPM_HIBERNATE)
- action = "hibernate";
- else
- return FALSE;
-
- command = g_strdup_printf ("pkexec " SBINDIR "/xfce4-pm-helper --%s", action);
- ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
- if ( !ret )
- {
- g_warning ("xfce4-pm-helper: failed to suspend/hibernate: %s", error->message);
- g_error_free (error);
- }
- else
- {
- XFPM_DEBUG ("executed %s; retval: %i", command, exit_status);
- ret = (exit_status == 0);
- }
+ const gchar *action;
+ gboolean ret;
+ GError *error = NULL;
+ gint exit_status = 0;
+ gchar *command = NULL;
+
+ TRACE("entering");
+
+ if (type == XFPM_SUSPEND)
+ action = "suspend";
+ else if (type == XFPM_HIBERNATE)
+ action = "hibernate";
+ else
+ return FALSE;
- g_free (command);
- return ret;
+ command = g_strdup_printf ("pkexec " SBINDIR "/xfce4-pm-helper --%s", action);
+ ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
+
+ if ( !ret )
+ {
+ g_warning ("xfce4-pm-helper: failed to suspend/hibernate: %s", error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ XFPM_DEBUG ("executed %s; retval: %i", command, exit_status);
+ ret = (exit_status == 0);
+ }
+
+ g_free (command);
+ return ret;
}
diff --git a/src/xfpm-suspend.h b/src/xfpm-suspend.h
index 02dfa47..8d16df0 100644
--- a/src/xfpm-suspend.h
+++ b/src/xfpm-suspend.h
@@ -24,14 +24,13 @@
typedef enum
{
- XFPM_ASK_0 = 0,
- XFPM_SUSPEND,
- XFPM_HIBERNATE,
+ XFPM_ASK_0 = 0,
+ XFPM_SUSPEND,
+ XFPM_HIBERNATE,
} XfpmActionType;
gboolean xfpm_suspend_can_suspend (void);
gboolean xfpm_suspend_can_hibernate (void);
-
-gboolean xfpm_suspend_try_action (XfpmActionType type);
+gboolean xfpm_suspend_try_action (XfpmActionType type);
#endif /* __XFPM_SUSPEND_H */
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index df4f4fb..961911c 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -45,663 +45,665 @@ static void xfpm_xfconf_finalize (GObject *object);
struct XfpmXfconfPrivate
{
- XfconfChannel *channel;
- XfconfChannel *session_channel;
- GValue *values;
+ XfconfChannel *channel;
+ XfconfChannel *session_channel;
+ GValue *values;
};
enum
{
- PROP_0,
- PROP_GENERAL_NOTIFICATION,
- PROP_LOCK_SCREEN_ON_SLEEP,
- PROP_CRITICAL_LEVEL,
- PROP_SHOW_BRIGHTNESS_POPUP,
- PROP_HANDLE_BRIGHTNESS_KEYS,
- PROP_TRAY_ICON,
- PROP_CRITICAL_BATTERY_ACTION,
- PROP_POWER_BUTTON,
- PROP_HIBERNATE_BUTTON,
- PROP_SLEEP_BUTTON,
- PROP_BATTERY_BUTTON,
- PROP_LID_ACTION_ON_AC,
- PROP_LID_ACTION_ON_BATTERY,
- PROP_BRIGHTNESS_LEVEL_ON_AC,
- PROP_BRIGHTNESS_LEVEL_ON_BATTERY,
- PROP_BRIGHTNESS_SLIDER_MIN_LEVEL,
-
- PROP_ENABLE_DPMS,
- PROP_DPMS_SLEEP_ON_AC,
- PROP_DPMS_OFF_ON_AC,
- PROP_DPMS_SLEEP_ON_BATTERY,
- PROP_DPMS_OFF_ON_BATTERY,
- PROP_DPMS_SLEEP_MODE,
-
- PROP_IDLE_ON_AC,
- PROP_IDLE_ON_BATTERY,
- PROP_IDLE_SLEEP_MODE_ON_AC,
- PROP_IDLE_SLEEP_MODE_ON_BATTERY,
- PROP_DIM_ON_AC_TIMEOUT,
- PROP_DIM_ON_BATTERY_TIMEOUT,
+ PROP_0,
+ PROP_GENERAL_NOTIFICATION,
+ PROP_LOCK_SCREEN_ON_SLEEP,
+ PROP_CRITICAL_LEVEL,
+ PROP_SHOW_BRIGHTNESS_POPUP,
+ PROP_HANDLE_BRIGHTNESS_KEYS,
+ PROP_TRAY_ICON,
+ PROP_CRITICAL_BATTERY_ACTION,
+ PROP_POWER_BUTTON,
+ PROP_HIBERNATE_BUTTON,
+ PROP_SLEEP_BUTTON,
+ PROP_BATTERY_BUTTON,
+ PROP_LID_ACTION_ON_AC,
+ PROP_LID_ACTION_ON_BATTERY,
+ PROP_BRIGHTNESS_LEVEL_ON_AC,
+ PROP_BRIGHTNESS_LEVEL_ON_BATTERY,
+ PROP_BRIGHTNESS_SLIDER_MIN_LEVEL,
+
+ PROP_ENABLE_DPMS,
+ PROP_DPMS_SLEEP_ON_AC,
+ PROP_DPMS_OFF_ON_AC,
+ PROP_DPMS_SLEEP_ON_BATTERY,
+ PROP_DPMS_OFF_ON_BATTERY,
+ PROP_DPMS_SLEEP_MODE,
+
+ PROP_IDLE_ON_AC,
+ PROP_IDLE_ON_BATTERY,
+ PROP_IDLE_SLEEP_MODE_ON_AC,
+ PROP_IDLE_SLEEP_MODE_ON_BATTERY,
+ PROP_DIM_ON_AC_TIMEOUT,
+ PROP_DIM_ON_BATTERY_TIMEOUT,
#ifdef WITH_NETWORK_MANAGER
- PROP_NETWORK_MANAGER_SLEEP,
+ PROP_NETWORK_MANAGER_SLEEP,
#endif
- PROP_LOGIND_HANDLE_POWER_KEY,
- PROP_LOGIND_HANDLE_SUSPEND_KEY,
- PROP_LOGIND_HANDLE_HIBERNATE_KEY,
- PROP_LOGIND_HANDLE_LID_SWITCH,
- PROP_HEARTBEAT_COMMAND,
- N_PROPERTIES
+ PROP_LOGIND_HANDLE_POWER_KEY,
+ PROP_LOGIND_HANDLE_SUSPEND_KEY,
+ PROP_LOGIND_HANDLE_HIBERNATE_KEY,
+ PROP_LOGIND_HANDLE_LID_SWITCH,
+ PROP_HEARTBEAT_COMMAND,
+ N_PROPERTIES
};
G_DEFINE_TYPE_WITH_PRIVATE (XfpmXfconf, xfpm_xfconf, G_TYPE_OBJECT)
static void
xfpm_xfconf_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- XfpmXfconf *conf;
- GValue *dst;
+ XfpmXfconf *conf;
+ GValue *dst;
- conf = XFPM_XFCONF (object);
+ conf = XFPM_XFCONF (object);
- dst = conf->priv->values + prop_id;
+ dst = conf->priv->values + prop_id;
- if ( !G_IS_VALUE (dst) )
- {
- g_value_init (dst, pspec->value_type);
- g_param_value_set_default (pspec, dst);
- }
+ if ( !G_IS_VALUE (dst) )
+ {
+ g_value_init (dst, pspec->value_type);
+ g_param_value_set_default (pspec, dst);
+ }
- if ( g_param_values_cmp (pspec, value, dst) != 0)
- {
- g_value_copy (value, dst);
- g_object_notify (object, pspec->name);
- }
+ if ( g_param_values_cmp (pspec, value, dst) != 0)
+ {
+ g_value_copy (value, dst);
+ g_object_notify (object, pspec->name);
+ }
}
static void
xfpm_xfconf_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- XfpmXfconf *conf;
- GValue *src;
+ XfpmXfconf *conf;
+ GValue *src;
- conf = XFPM_XFCONF (object);
+ conf = XFPM_XFCONF (object);
- src = conf->priv->values + prop_id;
+ src = conf->priv->values + prop_id;
- if ( G_VALUE_HOLDS (src, pspec->value_type) )
- g_value_copy (src, value);
- else
- g_param_value_set_default (pspec, value);
+ if ( G_VALUE_HOLDS (src, pspec->value_type) )
+ g_value_copy (src, value);
+ else
+ g_param_value_set_default (pspec, value);
}
static void
xfpm_xfconf_load (XfpmXfconf *conf, gboolean channel_valid)
{
- GParamSpec **specs;
- GValue value = { 0, };
- guint nspecs;
- guint i;
+ GParamSpec **specs;
+ GValue value = { 0, };
+ guint nspecs;
+ guint i;
+
+ specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (conf), &nspecs);
- specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (conf), &nspecs);
+ for ( i = 0; i < nspecs; i++)
+ {
+ gchar *prop_name;
+ prop_name = g_strdup_printf ("%s%s", XFPM_PROPERTIES_PREFIX, specs[i]->name);
+ g_value_init (&value, specs[i]->value_type);
- for ( i = 0; i < nspecs; i++)
+ if (channel_valid)
{
- gchar *prop_name;
- prop_name = g_strdup_printf ("%s%s", XFPM_PROPERTIES_PREFIX, specs[i]->name);
- g_value_init (&value, specs[i]->value_type);
-
- if (channel_valid)
- {
- if ( !xfconf_channel_get_property (conf->priv->channel, prop_name, &value) )
- {
- XFPM_DEBUG ("Using default configuration for %s", specs[i]->name);
- g_param_value_set_default (specs[i], &value);
- }
- }
- else
- {
- XFPM_DEBUG ("Using default configuration for %s", specs[i]->name);
- g_param_value_set_default (specs[i], &value);
- }
- g_free (prop_name);
- g_object_set_property (G_OBJECT (conf), specs[i]->name, &value);
- g_value_unset (&value);
+ if ( !xfconf_channel_get_property (conf->priv->channel, prop_name, &value) )
+ {
+ XFPM_DEBUG ("Using default configuration for %s", specs[i]->name);
+ g_param_value_set_default (specs[i], &value);
+ }
}
- g_free (specs);
+ else
+ {
+ XFPM_DEBUG ("Using default configuration for %s", specs[i]->name);
+ g_param_value_set_default (specs[i], &value);
+ }
+ g_free (prop_name);
+ g_object_set_property (G_OBJECT (conf), specs[i]->name, &value);
+ g_value_unset (&value);
+ }
+ g_free (specs);
}
static void
xfpm_xfconf_property_changed_cb (XfconfChannel *channel, gchar *property,
- GValue *value, XfpmXfconf *conf)
+ GValue *value, XfpmXfconf *conf)
{
- /*FIXME: Set default for this key*/
- if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
- return;
+ /*FIXME: Set default for this key*/
+ if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
+ return;
- if ( !g_str_has_prefix (property, XFPM_PROPERTIES_PREFIX) || strlen (property) <= strlen (XFPM_PROPERTIES_PREFIX) )
- return;
+ if ( !g_str_has_prefix (property, XFPM_PROPERTIES_PREFIX) || strlen (property) <= strlen (XFPM_PROPERTIES_PREFIX) )
+ return;
- /* We handle presentation mode and blank-times in xfpm-power directly */
- if ( g_strcmp0 (property, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE) == 0 ||
- g_strcmp0 (property, XFPM_PROPERTIES_PREFIX ON_AC_BLANK) == 0 ||
- g_strcmp0 (property, XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK) == 0)
- return;
+ /* We handle presentation mode and blank-times in xfpm-power directly */
+ if ( g_strcmp0 (property, XFPM_PROPERTIES_PREFIX PRESENTATION_MODE) == 0 ||
+ g_strcmp0 (property, XFPM_PROPERTIES_PREFIX ON_AC_BLANK) == 0 ||
+ g_strcmp0 (property, XFPM_PROPERTIES_PREFIX ON_BATTERY_BLANK) == 0)
+ return;
- /* We handle brightness switch in xfpm-backlight directly */
- if ( g_strcmp0 (property, XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH) == 0 ||
- g_strcmp0 (property, XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE) == 0 )
- return;
+ /* We handle brightness switch in xfpm-backlight directly */
+ if ( g_strcmp0 (property, XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH) == 0 ||
+ g_strcmp0 (property, XFPM_PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE) == 0 )
+ return;
- XFPM_DEBUG ("Property modified: %s\n", property);
+ XFPM_DEBUG ("Property modified: %s\n", property);
- g_object_set_property (G_OBJECT (conf), property + strlen (XFPM_PROPERTIES_PREFIX), value);
+ g_object_set_property (G_OBJECT (conf), property + strlen (XFPM_PROPERTIES_PREFIX), value);
}
static void
xfpm_xfsession_property_changed_cb (XfconfChannel *channel, gchar *property,
- GValue *value, XfpmXfconf *conf)
+ GValue *value, XfpmXfconf *conf)
{
- /*FIXME: Set default for this key*/
- if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
- return;
+ /*FIXME: Set default for this key*/
+ if ( G_VALUE_TYPE(value) == G_TYPE_INVALID )
+ return;
- XFPM_DEBUG ("property %s\n", property);
+ XFPM_DEBUG ("property %s\n", property);
- if ( g_strcmp0 (property, "/shutdown/LockScreen") != 0)
- return;
+ if ( g_strcmp0 (property, "/shutdown/LockScreen") != 0)
+ return;
- /* sanity check */
- if ( !G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) )
- return;
+ /* sanity check */
+ if ( !G_VALUE_HOLDS (value, G_TYPE_BOOLEAN) )
+ return;
- XFPM_DEBUG ("Property modified: %s\n", property);
+ XFPM_DEBUG ("Property modified: %s\n", property);
- /* update xfconf which will update xfpm and keep things in sync */
- xfconf_channel_set_bool (conf->priv->channel,
- XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP,
- g_value_get_boolean(value));
+ /* update xfconf which will update xfpm and keep things in sync */
+ xfconf_channel_set_bool (conf->priv->channel,
+ XFPM_PROPERTIES_PREFIX LOCK_SCREEN_ON_SLEEP,
+ g_value_get_boolean(value));
}
static void
xfpm_xfconf_class_init (XfpmXfconfClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- object_class->set_property = xfpm_xfconf_set_property;
- object_class->get_property = xfpm_xfconf_get_property;
-
- object_class->finalize = xfpm_xfconf_finalize;
-
- /**
- * XfpmXfconf::general-notification
- **/
- g_object_class_install_property (object_class,
- PROP_GENERAL_NOTIFICATION,
- g_param_spec_boolean (GENERAL_NOTIFICATION_CFG,
- NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::lock-screen-suspend-hibernate
- **/
- g_object_class_install_property (object_class,
- PROP_LOCK_SCREEN_ON_SLEEP,
- g_param_spec_boolean (LOCK_SCREEN_ON_SLEEP,
- NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::critical-power-level
- **/
- g_object_class_install_property (object_class,
- PROP_CRITICAL_LEVEL,
- g_param_spec_uint (CRITICAL_POWER_LEVEL,
- NULL, NULL,
- 1,
- 20,
- 5,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::show-brightness-popup
- **/
- g_object_class_install_property (object_class,
- PROP_SHOW_BRIGHTNESS_POPUP,
- g_param_spec_boolean (SHOW_BRIGHTNESS_POPUP,
- NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::handle-brightness-keys
- **/
- g_object_class_install_property (object_class,
- PROP_HANDLE_BRIGHTNESS_KEYS,
- g_param_spec_boolean (HANDLE_BRIGHTNESS_KEYS,
- NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::show-tray-icon
- **/
- g_object_class_install_property (object_class,
- PROP_TRAY_ICON,
- g_param_spec_uint (SHOW_TRAY_ICON_CFG,
- NULL, NULL,
- SHOW_ICON_ALWAYS,
- NEVER_SHOW_ICON,
- SHOW_ICON_WHEN_BATTERY_PRESENT,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::critical-battery-action
- **/
- g_object_class_install_property (object_class,
- PROP_CRITICAL_BATTERY_ACTION,
- g_param_spec_uint (CRITICAL_BATT_ACTION_CFG,
- NULL, NULL,
- XFPM_DO_NOTHING,
- XFPM_DO_SHUTDOWN,
- XFPM_DO_NOTHING,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::power-switch-action
- **/
- g_object_class_install_property (object_class,
- PROP_POWER_BUTTON,
- g_param_spec_uint (POWER_SWITCH_CFG,
- NULL, NULL,
- XFPM_DO_NOTHING,
- XFPM_DO_SHUTDOWN,
- XFPM_DO_NOTHING,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::sleep-switch-action
- **/
- g_object_class_install_property (object_class,
- PROP_SLEEP_BUTTON,
- g_param_spec_uint (SLEEP_SWITCH_CFG,
- NULL, NULL,
- XFPM_DO_NOTHING,
- XFPM_DO_SHUTDOWN,
- XFPM_DO_NOTHING,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::hibernate-switch-action
- **/
- g_object_class_install_property (object_class,
- PROP_HIBERNATE_BUTTON,
- g_param_spec_uint (HIBERNATE_SWITCH_CFG,
- NULL, NULL,
- XFPM_DO_NOTHING,
- XFPM_DO_SHUTDOWN,
- XFPM_DO_NOTHING,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::battery-switch-action
- **/
- g_object_class_install_property (object_class,
- PROP_BATTERY_BUTTON,
- g_param_spec_uint (BATTERY_SWITCH_CFG,
- NULL, NULL,
- XFPM_DO_NOTHING,
- XFPM_DO_SHUTDOWN,
- XFPM_DO_NOTHING,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::lid-action-on-ac
- **/
- g_object_class_install_property (object_class,
- PROP_LID_ACTION_ON_AC,
- g_param_spec_uint (LID_SWITCH_ON_AC_CFG,
- NULL, NULL,
- LID_TRIGGER_NOTHING,
- LID_TRIGGER_LOCK_SCREEN,
- LID_TRIGGER_LOCK_SCREEN,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::brightness-level-on-ac
- **/
- g_object_class_install_property (object_class,
- PROP_BRIGHTNESS_LEVEL_ON_AC,
- g_param_spec_uint (BRIGHTNESS_LEVEL_ON_AC,
- NULL, NULL,
- 1,
- 100,
- 80,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::brightness-level-on-battery
- **/
- g_object_class_install_property (object_class,
- PROP_BRIGHTNESS_LEVEL_ON_BATTERY,
- g_param_spec_uint (BRIGHTNESS_LEVEL_ON_BATTERY,
- NULL, NULL,
- 1,
- 100,
- 20,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::lid-action-on-battery
- **/
- g_object_class_install_property (object_class,
- PROP_LID_ACTION_ON_BATTERY,
- g_param_spec_uint (LID_SWITCH_ON_BATTERY_CFG,
- NULL, NULL,
- LID_TRIGGER_NOTHING,
- LID_TRIGGER_LOCK_SCREEN,
- LID_TRIGGER_LOCK_SCREEN,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::dpms-enabled
- **/
- g_object_class_install_property (object_class,
- PROP_ENABLE_DPMS,
- g_param_spec_boolean (DPMS_ENABLED_CFG,
- NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::dpms-on-ac-sleep
- **/
- g_object_class_install_property (object_class,
- PROP_DPMS_SLEEP_ON_AC,
- g_param_spec_uint (ON_AC_DPMS_SLEEP,
- NULL, NULL,
- 0,
- G_MAXUINT16,
- 10,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::dpms-on-ac-off
- **/
- g_object_class_install_property (object_class,
- PROP_DPMS_OFF_ON_AC,
- g_param_spec_uint (ON_AC_DPMS_OFF,
- NULL, NULL,
- 0,
- G_MAXUINT16,
- 15,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::dpms-on-battery-sleep
- **/
- g_object_class_install_property (object_class,
- PROP_DPMS_SLEEP_ON_BATTERY,
- g_param_spec_uint (ON_BATT_DPMS_SLEEP,
- NULL, NULL,
- 0,
- G_MAXUINT16,
- 5,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::dpms-on-battery-off
- **/
- g_object_class_install_property (object_class,
- PROP_DPMS_OFF_ON_BATTERY,
- g_param_spec_uint (ON_BATT_DPMS_OFF,
- NULL, NULL,
- 0,
- G_MAXUINT16,
- 10,
- G_PARAM_READWRITE));
- /**
- * XfpmXfconf::dpms-sleep-mode
- **/
- g_object_class_install_property (object_class,
- PROP_DPMS_SLEEP_MODE,
- g_param_spec_string (DPMS_SLEEP_MODE,
- NULL, NULL,
- "Standby",
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::inactivity-on-ac
- **/
- g_object_class_install_property (object_class,
- PROP_IDLE_ON_AC,
- g_param_spec_uint (ON_AC_INACTIVITY_TIMEOUT,
- NULL, NULL,
- 0,
- G_MAXUINT,
- 14,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::inactivity-on-battery
- **/
- g_object_class_install_property (object_class,
- PROP_IDLE_ON_BATTERY,
- g_param_spec_uint (ON_BATTERY_INACTIVITY_TIMEOUT,
- NULL, NULL,
- 0,
- G_MAXUINT,
- 14,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::inactivity-sleep-mode-on-battery
- **/
- g_object_class_install_property (object_class,
- PROP_IDLE_SLEEP_MODE_ON_BATTERY,
- g_param_spec_uint (INACTIVITY_SLEEP_MODE_ON_BATTERY,
- NULL, NULL,
- XFPM_DO_SUSPEND,
- XFPM_DO_HIBERNATE,
- XFPM_DO_HIBERNATE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::inactivity-sleep-mode-on-ac
- **/
- g_object_class_install_property (object_class,
- PROP_IDLE_SLEEP_MODE_ON_AC,
- g_param_spec_uint (INACTIVITY_SLEEP_MODE_ON_AC,
- NULL, NULL,
- XFPM_DO_SUSPEND,
- XFPM_DO_HIBERNATE,
- XFPM_DO_SUSPEND,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::brightness-on-ac
- **/
- g_object_class_install_property (object_class,
- PROP_DIM_ON_AC_TIMEOUT,
- g_param_spec_uint (BRIGHTNESS_ON_AC,
- NULL, NULL,
- 9,
- G_MAXUINT,
- 9,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::brightness-on-battery
- **/
- g_object_class_install_property (object_class,
- PROP_DIM_ON_BATTERY_TIMEOUT,
- g_param_spec_uint (BRIGHTNESS_ON_BATTERY,
- NULL, NULL,
- 9,
- G_MAXUINT,
- 120,
- G_PARAM_READWRITE));
-
-
- /**
- * XfpmXfconf::brightness-slider-min-level
- **/
- g_object_class_install_property (object_class,
- PROP_BRIGHTNESS_SLIDER_MIN_LEVEL,
- g_param_spec_int (BRIGHTNESS_SLIDER_MIN_LEVEL,
- NULL, NULL,
- -1,
- G_MAXINT32,
- -1,
- G_PARAM_READWRITE));
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->set_property = xfpm_xfconf_set_property;
+ object_class->get_property = xfpm_xfconf_get_property;
+
+ object_class->finalize = xfpm_xfconf_finalize;
+
+ /**
+ * XfpmXfconf::general-notification
+ **/
+ g_object_class_install_property (object_class,
+ PROP_GENERAL_NOTIFICATION,
+ g_param_spec_boolean (GENERAL_NOTIFICATION_CFG,
+ NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::lock-screen-suspend-hibernate
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LOCK_SCREEN_ON_SLEEP,
+ g_param_spec_boolean (LOCK_SCREEN_ON_SLEEP,
+ NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::critical-power-level
+ **/
+ g_object_class_install_property (object_class,
+ PROP_CRITICAL_LEVEL,
+ g_param_spec_uint (CRITICAL_POWER_LEVEL,
+ NULL, NULL,
+ 1,
+ 20,
+ 5,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::show-brightness-popup
+ **/
+ g_object_class_install_property (object_class,
+ PROP_SHOW_BRIGHTNESS_POPUP,
+ g_param_spec_boolean (SHOW_BRIGHTNESS_POPUP,
+ NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::handle-brightness-keys
+ **/
+ g_object_class_install_property (object_class,
+ PROP_HANDLE_BRIGHTNESS_KEYS,
+ g_param_spec_boolean (HANDLE_BRIGHTNESS_KEYS,
+ NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::show-tray-icon
+ **/
+ g_object_class_install_property (object_class,
+ PROP_TRAY_ICON,
+ g_param_spec_uint (SHOW_TRAY_ICON_CFG,
+ NULL, NULL,
+ SHOW_ICON_ALWAYS,
+ NEVER_SHOW_ICON,
+ SHOW_ICON_WHEN_BATTERY_PRESENT,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::critical-battery-action
+ **/
+ g_object_class_install_property (object_class,
+ PROP_CRITICAL_BATTERY_ACTION,
+ g_param_spec_uint (CRITICAL_BATT_ACTION_CFG,
+ NULL, NULL,
+ XFPM_DO_NOTHING,
+ XFPM_DO_SHUTDOWN,
+ XFPM_DO_NOTHING,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::power-switch-action
+ **/
+ g_object_class_install_property (object_class,
+ PROP_POWER_BUTTON,
+ g_param_spec_uint (POWER_SWITCH_CFG,
+ NULL, NULL,
+ XFPM_DO_NOTHING,
+ XFPM_DO_SHUTDOWN,
+ XFPM_DO_NOTHING,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::sleep-switch-action
+ **/
+ g_object_class_install_property (object_class,
+ PROP_SLEEP_BUTTON,
+ g_param_spec_uint (SLEEP_SWITCH_CFG,
+ NULL, NULL,
+ XFPM_DO_NOTHING,
+ XFPM_DO_SHUTDOWN,
+ XFPM_DO_NOTHING,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::hibernate-switch-action
+ **/
+ g_object_class_install_property (object_class,
+ PROP_HIBERNATE_BUTTON,
+ g_param_spec_uint (HIBERNATE_SWITCH_CFG,
+ NULL, NULL,
+ XFPM_DO_NOTHING,
+ XFPM_DO_SHUTDOWN,
+ XFPM_DO_NOTHING,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::battery-switch-action
+ **/
+ g_object_class_install_property (object_class,
+ PROP_BATTERY_BUTTON,
+ g_param_spec_uint (BATTERY_SWITCH_CFG,
+ NULL, NULL,
+ XFPM_DO_NOTHING,
+ XFPM_DO_SHUTDOWN,
+ XFPM_DO_NOTHING,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::lid-action-on-ac
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LID_ACTION_ON_AC,
+ g_param_spec_uint (LID_SWITCH_ON_AC_CFG,
+ NULL, NULL,
+ LID_TRIGGER_NOTHING,
+ LID_TRIGGER_LOCK_SCREEN,
+ LID_TRIGGER_LOCK_SCREEN,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::brightness-level-on-ac
+ **/
+ g_object_class_install_property (object_class,
+ PROP_BRIGHTNESS_LEVEL_ON_AC,
+ g_param_spec_uint (BRIGHTNESS_LEVEL_ON_AC,
+ NULL, NULL,
+ 1,
+ 100,
+ 80,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::brightness-level-on-battery
+ **/
+ g_object_class_install_property (object_class,
+ PROP_BRIGHTNESS_LEVEL_ON_BATTERY,
+ g_param_spec_uint (BRIGHTNESS_LEVEL_ON_BATTERY,
+ NULL, NULL,
+ 1,
+ 100,
+ 20,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::lid-action-on-battery
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LID_ACTION_ON_BATTERY,
+ g_param_spec_uint (LID_SWITCH_ON_BATTERY_CFG,
+ NULL, NULL,
+ LID_TRIGGER_NOTHING,
+ LID_TRIGGER_LOCK_SCREEN,
+ LID_TRIGGER_LOCK_SCREEN,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::dpms-enabled
+ **/
+ g_object_class_install_property (object_class,
+ PROP_ENABLE_DPMS,
+ g_param_spec_boolean (DPMS_ENABLED_CFG,
+ NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::dpms-on-ac-sleep
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DPMS_SLEEP_ON_AC,
+ g_param_spec_uint (ON_AC_DPMS_SLEEP,
+ NULL, NULL,
+ 0,
+ G_MAXUINT16,
+ 10,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::dpms-on-ac-off
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DPMS_OFF_ON_AC,
+ g_param_spec_uint (ON_AC_DPMS_OFF,
+ NULL, NULL,
+ 0,
+ G_MAXUINT16,
+ 15,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::dpms-on-battery-sleep
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DPMS_SLEEP_ON_BATTERY,
+ g_param_spec_uint (ON_BATT_DPMS_SLEEP,
+ NULL, NULL,
+ 0,
+ G_MAXUINT16,
+ 5,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::dpms-on-battery-off
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DPMS_OFF_ON_BATTERY,
+ g_param_spec_uint (ON_BATT_DPMS_OFF,
+ NULL, NULL,
+ 0,
+ G_MAXUINT16,
+ 10,
+ G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::dpms-sleep-mode
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DPMS_SLEEP_MODE,
+ g_param_spec_string (DPMS_SLEEP_MODE,
+ NULL, NULL,
+ "Standby",
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::inactivity-on-ac
+ **/
+ g_object_class_install_property (object_class,
+ PROP_IDLE_ON_AC,
+ g_param_spec_uint (ON_AC_INACTIVITY_TIMEOUT,
+ NULL, NULL,
+ 0,
+ G_MAXUINT,
+ 14,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::inactivity-on-battery
+ **/
+ g_object_class_install_property (object_class,
+ PROP_IDLE_ON_BATTERY,
+ g_param_spec_uint (ON_BATTERY_INACTIVITY_TIMEOUT,
+ NULL, NULL,
+ 0,
+ G_MAXUINT,
+ 14,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::inactivity-sleep-mode-on-battery
+ **/
+ g_object_class_install_property (object_class,
+ PROP_IDLE_SLEEP_MODE_ON_BATTERY,
+ g_param_spec_uint (INACTIVITY_SLEEP_MODE_ON_BATTERY,
+ NULL, NULL,
+ XFPM_DO_SUSPEND,
+ XFPM_DO_HIBERNATE,
+ XFPM_DO_HIBERNATE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::inactivity-sleep-mode-on-ac
+ **/
+ g_object_class_install_property (object_class,
+ PROP_IDLE_SLEEP_MODE_ON_AC,
+ g_param_spec_uint (INACTIVITY_SLEEP_MODE_ON_AC,
+ NULL, NULL,
+ XFPM_DO_SUSPEND,
+ XFPM_DO_HIBERNATE,
+ XFPM_DO_SUSPEND,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::brightness-on-ac
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DIM_ON_AC_TIMEOUT,
+ g_param_spec_uint (BRIGHTNESS_ON_AC,
+ NULL, NULL,
+ 9,
+ G_MAXUINT,
+ 9,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::brightness-on-battery
+ **/
+ g_object_class_install_property (object_class,
+ PROP_DIM_ON_BATTERY_TIMEOUT,
+ g_param_spec_uint (BRIGHTNESS_ON_BATTERY,
+ NULL, NULL,
+ 9,
+ G_MAXUINT,
+ 120,
+ G_PARAM_READWRITE));
+
+
+ /**
+ * XfpmXfconf::brightness-slider-min-level
+ **/
+ g_object_class_install_property (object_class,
+ PROP_BRIGHTNESS_SLIDER_MIN_LEVEL,
+ g_param_spec_int (BRIGHTNESS_SLIDER_MIN_LEVEL,
+ NULL, NULL,
+ -1,
+ G_MAXINT32,
+ -1,
+ G_PARAM_READWRITE));
#ifdef WITH_NETWORK_MANAGER
- /**
- * XfpmXfconf::network-manager-sleep
- **/
- g_object_class_install_property (object_class,
- PROP_NETWORK_MANAGER_SLEEP,
- g_param_spec_boolean (NETWORK_MANAGER_SLEEP,
- NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::network-manager-sleep
+ **/
+ g_object_class_install_property (object_class,
+ PROP_NETWORK_MANAGER_SLEEP,
+ g_param_spec_boolean (NETWORK_MANAGER_SLEEP,
+ NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
#endif
- /**
- * XfpmXfconf::logind-handle-power-key
- **/
- g_object_class_install_property (object_class,
- PROP_LOGIND_HANDLE_POWER_KEY,
- g_param_spec_boolean (LOGIND_HANDLE_POWER_KEY,
- NULL, NULL,
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::logind-handle-suspend-key
- **/
- g_object_class_install_property (object_class,
- PROP_LOGIND_HANDLE_SUSPEND_KEY,
- g_param_spec_boolean (LOGIND_HANDLE_SUSPEND_KEY,
- NULL, NULL,
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::logind-handle-hibernate-key
- **/
- g_object_class_install_property (object_class,
- PROP_LOGIND_HANDLE_HIBERNATE_KEY,
- g_param_spec_boolean (LOGIND_HANDLE_HIBERNATE_KEY,
- NULL, NULL,
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::logind-handle-lid-switch
- **/
- g_object_class_install_property (object_class,
- PROP_LOGIND_HANDLE_LID_SWITCH,
- g_param_spec_boolean (LOGIND_HANDLE_LID_SWITCH,
- NULL, NULL,
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * XfpmXfconf::heartbeat-command
- **/
- g_object_class_install_property (object_class,
- PROP_HEARTBEAT_COMMAND,
- g_param_spec_string (HEARTBEAT_COMMAND,
- NULL, NULL,
- NULL,
- G_PARAM_READWRITE));
+ /**
+ * XfpmXfconf::logind-handle-power-key
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LOGIND_HANDLE_POWER_KEY,
+ g_param_spec_boolean (LOGIND_HANDLE_POWER_KEY,
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::logind-handle-suspend-key
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LOGIND_HANDLE_SUSPEND_KEY,
+ g_param_spec_boolean (LOGIND_HANDLE_SUSPEND_KEY,
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::logind-handle-hibernate-key
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LOGIND_HANDLE_HIBERNATE_KEY,
+ g_param_spec_boolean (LOGIND_HANDLE_HIBERNATE_KEY,
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::logind-handle-lid-switch
+ **/
+ g_object_class_install_property (object_class,
+ PROP_LOGIND_HANDLE_LID_SWITCH,
+ g_param_spec_boolean (LOGIND_HANDLE_LID_SWITCH,
+ NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * XfpmXfconf::heartbeat-command
+ **/
+ g_object_class_install_property (object_class,
+ PROP_HEARTBEAT_COMMAND,
+ g_param_spec_string (HEARTBEAT_COMMAND,
+ NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE));
}
static void
xfpm_xfconf_init (XfpmXfconf *conf)
{
- GError *error = NULL;
- gboolean channel_valid;
- gboolean lock_screen;
-
- conf->priv = xfpm_xfconf_get_instance_private (conf);
-
- conf->priv->values = g_new0 (GValue, N_PROPERTIES);
-
- if ( !xfconf_init (&error) )
- {
- g_critical ("xfconf_init failed: %s\n", error->message);
- g_error_free (error);
- channel_valid = FALSE;
- }
- else
- {
+ GError *error = NULL;
+ gboolean channel_valid;
+ gboolean lock_screen;
+
+ conf->priv = xfpm_xfconf_get_instance_private (conf);
+
+ conf->priv->values = g_new0 (GValue, N_PROPERTIES);
+
+ if ( !xfconf_init (&error) )
+ {
+ g_critical ("xfconf_init failed: %s\n", error->message);
+ g_error_free (error);
+ channel_valid = FALSE;
+ }
+ else
+ {
conf->priv->channel = xfconf_channel_get (XFPM_CHANNEL);
conf->priv->session_channel = xfconf_channel_get ("xfce4-session");
/* if xfce4-session is around, sync to it on startup */
if ( xfconf_channel_has_property (conf->priv->session_channel, "/shutdown/LockScreen") )
{
- lock_screen = xfconf_channel_get_bool (conf->priv->session_channel,
- "/shutdown/LockScreen",
- TRUE);
+ lock_screen = xfconf_channel_get_bool (conf->priv->session_channel,
+ "/shutdown/LockScreen",
+ TRUE);
- XFPM_DEBUG("lock screen %s", lock_screen ? "TRUE" : "FALSE");
+ XFPM_DEBUG("lock screen %s", lock_screen ? "TRUE" : "FALSE");
- g_object_set (G_OBJECT (conf), LOCK_SCREEN_ON_SLEEP, lock_screen, NULL);
+ g_object_set (G_OBJECT (conf), LOCK_SCREEN_ON_SLEEP, lock_screen, NULL);
}
- g_signal_connect (conf->priv->channel, "property-changed",
- G_CALLBACK (xfpm_xfconf_property_changed_cb), conf);
+ g_signal_connect (conf->priv->channel, "property-changed",
+ G_CALLBACK (xfpm_xfconf_property_changed_cb), conf);
/* watch for session's property change so we can stay in sync */
g_signal_connect (conf->priv->session_channel, "property-changed",
- G_CALLBACK (xfpm_xfsession_property_changed_cb), conf);
+ G_CALLBACK (xfpm_xfsession_property_changed_cb), conf);
- channel_valid = TRUE;
- }
- xfpm_xfconf_load (conf, channel_valid);
+ channel_valid = TRUE;
+ }
+ xfpm_xfconf_load (conf, channel_valid);
}
static void
xfpm_xfconf_finalize(GObject *object)
{
- XfpmXfconf *conf;
- guint i;
+ XfpmXfconf *conf;
+ guint i;
- conf = XFPM_XFCONF(object);
+ conf = XFPM_XFCONF (object);
- for ( i = 0; i < N_PROPERTIES; i++)
- {
- if ( G_IS_VALUE (conf->priv->values + i) )
- g_value_unset (conf->priv->values + i);
- }
+ for ( i = 0; i < N_PROPERTIES; i++)
+ {
+ if ( G_IS_VALUE (conf->priv->values + i) )
+ g_value_unset (conf->priv->values + i);
+ }
- g_free (conf->priv->values);
+ g_free (conf->priv->values);
- G_OBJECT_CLASS(xfpm_xfconf_parent_class)->finalize(object);
+ G_OBJECT_CLASS (xfpm_xfconf_parent_class)->finalize(object);
}
XfpmXfconf *
xfpm_xfconf_new (void)
{
- static gpointer xfpm_xfconf_object = NULL;
-
- if ( G_LIKELY (xfpm_xfconf_object != NULL) )
- {
- g_object_ref (xfpm_xfconf_object);
- }
- else
- {
- xfpm_xfconf_object = g_object_new (XFPM_TYPE_XFCONF, NULL);
- g_object_add_weak_pointer (xfpm_xfconf_object, &xfpm_xfconf_object);
- }
- return XFPM_XFCONF (xfpm_xfconf_object);
+ static gpointer xfpm_xfconf_object = NULL;
+
+ if ( G_LIKELY (xfpm_xfconf_object != NULL) )
+ {
+ g_object_ref (xfpm_xfconf_object);
+ }
+ else
+ {
+ xfpm_xfconf_object = g_object_new (XFPM_TYPE_XFCONF, NULL);
+ g_object_add_weak_pointer (xfpm_xfconf_object, &xfpm_xfconf_object);
+ }
+
+ return XFPM_XFCONF (xfpm_xfconf_object);
}
-XfconfChannel *xfpm_xfconf_get_channel (XfpmXfconf *conf)
+XfconfChannel *
+xfpm_xfconf_get_channel (XfpmXfconf *conf)
{
- return conf->priv->channel;
+ return conf->priv->channel;
}
diff --git a/src/xfpm-xfconf.h b/src/xfpm-xfconf.h
index f593939..39c9945 100644
--- a/src/xfpm-xfconf.h
+++ b/src/xfpm-xfconf.h
@@ -34,22 +34,18 @@ typedef struct XfpmXfconfPrivate XfpmXfconfPrivate;
typedef struct
{
- GObject parent;
- XfpmXfconfPrivate *priv;
-
+ GObject parent;
+ XfpmXfconfPrivate *priv;
} XfpmXfconf;
typedef struct
{
- GObjectClass parent_class;
-
+ GObjectClass parent_class;
} XfpmXfconfClass;
-GType xfpm_xfconf_get_type (void) G_GNUC_CONST;
-
-XfpmXfconf *xfpm_xfconf_new (void);
-
-XfconfChannel *xfpm_xfconf_get_channel (XfpmXfconf *conf);
+GType xfpm_xfconf_get_type (void) G_GNUC_CONST;
+XfpmXfconf *xfpm_xfconf_new (void);
+XfconfChannel *xfpm_xfconf_get_channel (XfpmXfconf *conf);
G_END_DECLS
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list