[Goodies-commits] r6939 - in xfce4-power-manager/trunk: . src
Ali Abdallah
aliov at xfce.org
Wed Mar 18 08:48:02 CET 2009
Author: aliov
Date: 2009-03-18 07:48:02 +0000 (Wed, 18 Mar 2009)
New Revision: 6939
Added:
xfce4-power-manager/trunk/src/org.freedesktop.PowerManagement.Inhibit.xml
xfce4-power-manager/trunk/src/xfpm-inhibit.c
xfce4-power-manager/trunk/src/xfpm-inhibit.h
xfce4-power-manager/trunk/src/xfpm-screen-saver.c
xfce4-power-manager/trunk/src/xfpm-screen-saver.h
Modified:
xfce4-power-manager/trunk/ChangeLog
xfce4-power-manager/trunk/src/Makefile.am
xfce4-power-manager/trunk/src/xfpm-brightness-hal.c
xfce4-power-manager/trunk/src/xfpm-button-xf86.c
xfce4-power-manager/trunk/src/xfpm-dpms.c
xfce4-power-manager/trunk/src/xfpm-engine.c
xfce4-power-manager/trunk/src/xfpm-lid-hal.c
xfce4-power-manager/trunk/src/xfpm-manager.c
Log:
Added Inhibit interface+monitor ScreenSaver Inhibit messages to catch inhibition and inhibit xfpm
Modified: xfce4-power-manager/trunk/ChangeLog
===================================================================
--- xfce4-power-manager/trunk/ChangeLog 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/ChangeLog 2009-03-18 07:48:02 UTC (rev 6939)
@@ -1,4 +1,7 @@
+2009-03-18 8:47 Ali aliov at xfce.org
+ * : Added Inhibit interface+monitor ScreenSaver Inhibit messages to catch inhibition and inhibit xfpm
+
2009-03-17 19:54 Ali aliov at xfce.org
* : Some optimization in the battery code+added GetOnBattery and on LowBattery DBus methods
Modified: xfce4-power-manager/trunk/src/Makefile.am
===================================================================
--- xfce4-power-manager/trunk/src/Makefile.am 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/Makefile.am 2009-03-18 07:48:02 UTC (rev 6939)
@@ -5,7 +5,8 @@
xfpm-enum-types.h \
xfpm-marshal.c \
xfpm-marshal.h \
- org.freedestop.PowerManagement-server.h \
+ org.freedesktop.PowerManagement.h \
+ org.freedesktop.PowerManagement.Inhibit.h\
xfce-power-manager-dbus-server.h \
xfce-power-manager-dbus-client.h \
xfpm-main.c \
@@ -35,6 +36,10 @@
xfpm-brightness-hal.h \
xfpm-idle.c \
xfpm-idle.h \
+ xfpm-inhibit.c \
+ xfpm-inhibit.h \
+ xfpm-screen-saver.c \
+ xfpm-screen-saver.h \
xfpm-tray-icon.c \
xfpm-tray-icon.h \
xfpm-notify.c \
@@ -79,13 +84,14 @@
if MAINTAINER_MODE
-BUILT_SOURCES = \
- xfce-power-manager-dbus-server.h \
- xfce-power-manager-dbus-client.h \
- org.freedesktop.PowerManagement-server.h\
- xfpm-marshal.c \
- xfpm-marshal.h \
- xfpm-enum-types.c \
+BUILT_SOURCES = \
+ xfce-power-manager-dbus-server.h \
+ xfce-power-manager-dbus-client.h \
+ org.freedesktop.PowerManagement.h \
+ org.freedesktop.PowerManagement.Inhibit.h \
+ xfpm-marshal.c \
+ xfpm-marshal.h \
+ xfpm-enum-types.c \
xfpm-enum-types.h
xfpm-enum-types.h: $(xfpm_glib_headers)
@@ -128,9 +134,12 @@
xfce-power-manager-dbus-client.h: $(srcdir)/org.xfce.Power.Manager.xml
dbus-binding-tool --mode=glib-client --prefix=xfpm_manager $< >$@
-org.freedesktop.PowerManagement-server.h: $(srcdir)/org.freedesktop.PowerManagement.xml
+org.freedesktop.PowerManagement.h: $(srcdir)/org.freedesktop.PowerManagement.xml
dbus-binding-tool --mode=glib-server --prefix=xfpm_engine $< >$@
+org.freedesktop.PowerManagement.Inhibit.h: $(srcdir)/org.freedesktop.PowerManagement.Inhibit.xml
+ dbus-binding-tool --mode=glib-server --prefix=xfpm_inhibit $< >$@
+
endif
@INTLTOOL_DESKTOP_RULE@
Added: xfce4-power-manager/trunk/src/org.freedesktop.PowerManagement.Inhibit.xml
===================================================================
--- xfce4-power-manager/trunk/src/org.freedesktop.PowerManagement.Inhibit.xml (rev 0)
+++ xfce4-power-manager/trunk/src/org.freedesktop.PowerManagement.Inhibit.xml 2009-03-18 07:48:02 UTC (rev 6939)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/org/freedesktop/PowerManagement">
+ <interface name="org.freedesktop.PowerManagement">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol"
+ value="xfpm_inhibit_dbus"/>
+ <annotation name="org.freedesktop.DBus.GLib.ClientCSymbol"
+ value="xfpm_inhibit_dbus_client"/>
+
+ <method name="Inhibit">
+ <arg type="s" name="application" direction="in"/>
+ <arg type="s" name="reason" direction="in"/>
+ <arg type="u" name="cookie" direction="out"/>
+ </method>
+
+ <method name="UnInhibit">
+ <arg type="u" name="cookie" direction="in"/>
+ </method>
+
+ <method name="HasInhibit">
+ <arg type="b" name="has_inhibit" direction="out"/>
+ </method>
+
+ <signal name="HasInhibitChanged"/>
+
+ </interface>
+
+</node>
Modified: xfce4-power-manager/trunk/src/xfpm-brightness-hal.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-brightness-hal.c 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/xfpm-brightness-hal.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -52,6 +52,7 @@
#include "xfpm-idle.h"
#include "xfpm-config.h"
#include "xfpm-adapter.h"
+#include "xfpm-inhibit.h"
/* Init */
static void xfpm_brightness_hal_class_init (XfpmBrightnessHalClass *klass);
@@ -69,12 +70,14 @@
XfpmIdle *idle;
XfpmButtonXf86 *button;
XfpmAdapter *adapter;
+ XfpmInhibit *inhibit;
gint max_level;
gint hw_level;
gboolean brightness_in_hw;
gboolean hw_found;
gboolean block;
+ gboolean inhibited;
gboolean on_battery;
@@ -113,6 +116,7 @@
brg->priv->block = FALSE;
brg->priv->brightness_in_hw = FALSE;
brg->priv->max_level = 0;
+ brg->priv->inhibited = FALSE;
}
static void
@@ -134,6 +138,9 @@
if (brg->priv->adapter)
g_object_unref (brg->priv->adapter);
+ if ( brg->priv->inhibit )
+ g_object_unref (brg->priv->inhibit);
+
G_OBJECT_CLASS(xfpm_brightness_hal_parent_class)->finalize(object);
}
@@ -299,6 +306,9 @@
if (brg->priv->block )
return;
+ if ( brg->priv->inhibited )
+ return;
+
level = xfpm_brightness_hal_get_level(brg);
if ( level != brg->priv->hw_level )
@@ -316,6 +326,9 @@
level = xfpm_brightness_hal_get_level(brg);
TRACE("Alarm timeout id=%d\n", id);
+ if ( brg->priv->inhibited )
+ return;
+
if ( id == TIMEOUT_ON_AC_ID && brg->priv->on_ac_timeout != 9)
{
if ( brg->priv->on_battery )
@@ -344,7 +357,6 @@
xfpm_brightness_hal_adapter_changed_cb (XfpmAdapter *adapter, gboolean present, XfpmBrightnessHal *brg)
{
brg->priv->on_battery = !present;
-
}
static void
@@ -370,6 +382,12 @@
}
static void
+xfpm_brightness_hal_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmBrightnessHal *brg)
+{
+ brg->priv->inhibited = inhibited;
+}
+
+static void
xfpm_brightness_hal_set_timeouts (XfpmBrightnessHal *brg )
{
xfpm_idle_set_alarm (brg->priv->idle, TIMEOUT_ON_AC_ID, brg->priv->on_ac_timeout * 1000);
@@ -433,6 +451,11 @@
brg->priv->conf = xfpm_xfconf_new ();
brg->priv->button = xfpm_button_xf86_new ();
brg->priv->adapter = xfpm_adapter_new ();
+ brg->priv->inhibit = xfpm_inhibit_new ();
+
+ g_signal_connect (brg->priv->inhibit, "inhibit-changed",
+ G_CALLBACK(xfpm_brightness_hal_inhibit_changed_cb), brg);
+
brg->priv->on_battery = !xfpm_adapter_get_present (brg->priv->adapter);
g_signal_connect (brg->priv->adapter, "adapter-changed",
Modified: xfce4-power-manager/trunk/src/xfpm-button-xf86.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-button-xf86.c 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/xfpm-button-xf86.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -49,6 +49,8 @@
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
+#include <glib.h>
+
#include <libxfce4util/libxfce4util.h>
#include "xfpm-button-xf86.h"
@@ -69,6 +71,8 @@
GdkScreen *screen;
GdkWindow *window;
GHashTable *hash;
+
+ GTimer *timer;
};
enum
@@ -77,6 +81,8 @@
LAST_SIGNAL
};
+#define DUPLICATE_SHUTDOWN_TIMEOUT 4.0f
+
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(XfpmButtonXf86, xfpm_button_xf86, G_TYPE_OBJECT)
@@ -95,7 +101,7 @@
if ( !key_hash )
{
- g_print("Key %d not found in hash\n", xev->xkey.keycode);
+ TRACE("Key %d not found in hash\n", xev->xkey.keycode);
return GDK_FILTER_CONTINUE;
}
@@ -103,8 +109,21 @@
TRACE("Found key in hash %d", type);
+ if ( (type == BUTTON_POWER_OFF || type == BUTTON_SLEEP) )
+
+ {
+ if ( g_timer_elapsed (button->priv->timer, NULL ) < DUPLICATE_SHUTDOWN_TIMEOUT )
+ {
+ TRACE("Button %d duplicated", type);
+ goto out;
+ }
+ else
+ g_timer_reset (button->priv->timer);
+ }
+
g_signal_emit (G_OBJECT(button), signals[XF86_BUTTON_PRESSED], 0, type);
-
+
+out:
return GDK_FILTER_REMOVE;
}
@@ -131,8 +150,8 @@
}
ret = XGrabKey (display, keycode, LockMask | modmask,
- GDK_WINDOW_XID (button->priv->window), True,
- GrabModeAsync, GrabModeAsync);
+ GDK_WINDOW_XID (button->priv->window), True,
+ GrabModeAsync, GrabModeAsync);
if (ret == BadAccess)
{
@@ -217,6 +236,7 @@
button->priv->screen = NULL;
button->priv->window = NULL;
+ button->priv->timer = g_timer_new ();
button->priv->hash = g_hash_table_new (NULL, NULL);
@@ -229,6 +249,9 @@
XfpmButtonXf86 *button;
button = XFPM_BUTTON_XF86 (object);
+
+ g_hash_table_destroy (button->priv->hash);
+ g_timer_destroy (button->priv->timer);
G_OBJECT_CLASS(xfpm_button_xf86_parent_class)->finalize(object);
}
@@ -245,6 +268,5 @@
xfpm_button_xf86_object = g_object_new (XFPM_TYPE_BUTTON_XF86, NULL);
g_object_add_weak_pointer (xfpm_button_xf86_object, &xfpm_button_xf86_object);
}
-
return XFPM_BUTTON_XF86 (xfpm_button_xf86_object);
}
Modified: xfce4-power-manager/trunk/src/xfpm-dpms.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-dpms.c 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/xfpm-dpms.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -51,6 +51,7 @@
#include "xfpm-dpms.h"
#include "xfpm-adapter.h"
#include "xfpm-xfconf.h"
+#include "xfpm-inhibit.h"
#include "xfpm-config.h"
#ifdef HAVE_DPMS
@@ -69,10 +70,13 @@
{
XfpmXfconf *conf;
XfpmAdapter *adapter;
+ XfpmInhibit *inhibit;
gboolean dpms_capable;
gboolean dpms_enabled;
+ gboolean inhibited;
+
guint16 sleep_on_battery;
guint16 off_on_battery;
guint16 sleep_on_ac;
@@ -145,6 +149,13 @@
if ( !dpms->priv->dpms_capable )
return FALSE;
+ if ( dpms->priv->inhibited )
+ {
+ TRACE("DPMS is inhibited");
+ DPMSDisable (GDK_DISPLAY());
+ return TRUE;
+ }
+
BOOL on_off;
CARD16 state = 0;
@@ -160,7 +171,6 @@
TRACE("DPMS is enabled, disabling it: user settings");
DPMSDisable(GDK_DISPLAY());
}
-
return TRUE;
}
@@ -280,6 +290,13 @@
}
static void
+xfpm_dpms_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmDpms *dpms)
+{
+ dpms->priv->inhibited = inhibited;
+ xfpm_dpms_enable_disable (dpms);
+}
+
+static void
xfpm_dpms_class_init(XfpmDpmsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
@@ -296,7 +313,11 @@
dpms->priv->dpms_capable = DPMSCapable (GDK_DISPLAY());
dpms->priv->adapter = xfpm_adapter_new ();
+ dpms->priv->inhibit = xfpm_inhibit_new ();
+ g_signal_connect (dpms->priv->inhibit, "inhibit-changed",
+ G_CALLBACK(xfpm_dpms_inhibit_changed_cb), dpms);
+
g_signal_connect (dpms->priv->adapter, "adapter-changed",
G_CALLBACK(xfpm_dpms_adapter_changed_cb), dpms);
Modified: xfce4-power-manager/trunk/src/xfpm-engine.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-engine.c 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/xfpm-engine.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -57,11 +57,11 @@
#include "xfpm-network-manager.h"
#include "xfpm-button-xf86.h"
#include "xfpm-lid-hal.h"
+#include "xfpm-inhibit.h"
#include "xfpm-brightness-hal.h"
+#include "xfpm-screen-saver.h"
#include "xfpm-config.h"
-#define DUPLICATE_SHUTDOWN_TIMEOUT 4.0f
-
/* Init */
static void xfpm_engine_class_init (XfpmEngineClass *klass);
static void xfpm_engine_init (XfpmEngine *engine);
@@ -82,13 +82,14 @@
XfpmLidHal *lid;
XfpmBrightnessHal *brg_hal;
XfpmAdapter *adapter;
+ XfpmInhibit *inhibit;
HalIface *iface;
#ifdef HAVE_DPMS
XfpmDpms *dpms;
#endif
- GTimer *button_timer;
-
+ gboolean inhibited;
+
guint8 power_management;
gboolean on_battery;
@@ -104,78 +105,6 @@
G_DEFINE_TYPE(XfpmEngine, xfpm_engine, G_TYPE_OBJECT)
static void
-xfpm_engine_class_init(XfpmEngineClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- object_class->finalize = xfpm_engine_finalize;
-
- g_type_class_add_private(klass,sizeof(XfpmEnginePrivate));
-
- xfpm_engine_dbus_class_init (klass);
-}
-
-static void
-xfpm_engine_init (XfpmEngine *engine)
-{
- engine->priv = XFPM_ENGINE_GET_PRIVATE(engine);
-
- engine->priv->iface = hal_iface_new ();
-
- engine->priv->button_timer= g_timer_new ();
-
- engine->priv->conf = NULL;
- engine->priv->supply = NULL;
-#ifdef HAVE_DPMS
- engine->priv->dpms = NULL;
-#endif
- engine->priv->cpu = NULL;
- engine->priv->xf86_button = NULL;
- engine->priv->lid = NULL;
- engine->priv->brg_hal = NULL;
-
- engine->priv->power_management = 0;
-
- xfpm_engine_dbus_init (engine);
-}
-
-static void
-xfpm_engine_finalize (GObject *object)
-{
- XfpmEngine *engine;
-
- engine = XFPM_ENGINE(object);
-
- if ( engine->priv->conf )
- g_object_unref (engine->priv->conf);
-
- if ( engine->priv->supply )
- g_object_unref (engine->priv->supply);
-
-#ifdef HAVE_DPMS
- if ( engine->priv->dpms )
- g_object_unref (engine->priv->dpms);
-#endif
-
- if ( engine->priv->cpu )
- g_object_unref (engine->priv->cpu);
-
- if ( engine->priv->lid)
- g_object_unref(engine->priv->lid);
-
- if ( engine->priv->iface)
- g_object_unref(engine->priv->iface);
-
- if ( engine->priv->adapter)
- g_object_unref (engine->priv->adapter);
-
- if ( engine->priv->button_timer)
- g_timer_destroy (engine->priv->button_timer);
-
- G_OBJECT_CLASS(xfpm_engine_parent_class)->finalize(object);
-}
-
-static void
xfpm_engine_shutdown_request (XfpmEngine *engine, XfpmShutdownRequest shutdown)
{
GError *error = NULL;
@@ -220,18 +149,9 @@
if ( engine->priv->block_shutdown )
return;
- if ( g_timer_elapsed (engine->priv->button_timer, NULL ) < DUPLICATE_SHUTDOWN_TIMEOUT )
- {
- TRACE ("Not accepting shutdown request");
- return;
- }
- else
- {
- TRACE("Accepting shutdown request");
- xfpm_engine_shutdown_request (engine, engine->priv->sleep_button);
- }
+ TRACE("Accepting shutdown request");
+ xfpm_engine_shutdown_request (engine, engine->priv->sleep_button);
}
- g_timer_reset (engine->priv->button_timer);
}
static void
@@ -255,19 +175,11 @@
if ( engine->priv->block_shutdown )
return;
- if ( g_timer_elapsed (engine->priv->button_timer, NULL ) < DUPLICATE_SHUTDOWN_TIMEOUT )
- {
- TRACE ("Not accepting shutdown request");
- return;
- }
-
TRACE("Accepting shutdown request");
xfpm_engine_shutdown_request (engine, engine->priv->on_battery ?
engine->priv->lid_button_battery :
engine->priv->lid_button_ac);
-
- g_timer_reset (engine->priv->button_timer);
}
static void
@@ -434,6 +346,85 @@
engine->priv->on_battery = !present;
}
+static void
+xfpm_engine_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmEngine *engine)
+{
+ engine->priv->inhibited = inhibited;
+}
+
+static void
+xfpm_engine_class_init(XfpmEngineClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->finalize = xfpm_engine_finalize;
+
+ g_type_class_add_private (klass, sizeof(XfpmEnginePrivate));
+
+ xfpm_engine_dbus_class_init (klass);
+}
+
+static void
+xfpm_engine_init (XfpmEngine *engine)
+{
+ engine->priv = XFPM_ENGINE_GET_PRIVATE(engine);
+
+ engine->priv->iface = hal_iface_new ();
+
+ engine->priv->inhibit = xfpm_inhibit_new ();
+ engine->priv->inhibited = FALSE;
+
+ g_signal_connect (engine->priv->inhibit, "inhibit-changed",
+ G_CALLBACK(xfpm_engine_inhibit_changed_cb), engine);
+
+ engine->priv->conf = NULL;
+ engine->priv->supply = NULL;
+#ifdef HAVE_DPMS
+ engine->priv->dpms = NULL;
+#endif
+ engine->priv->cpu = NULL;
+ engine->priv->xf86_button = NULL;
+ engine->priv->lid = NULL;
+ engine->priv->brg_hal = NULL;
+
+ engine->priv->power_management = 0;
+
+ xfpm_engine_dbus_init (engine);
+}
+
+static void
+xfpm_engine_finalize (GObject *object)
+{
+ XfpmEngine *engine;
+
+ engine = XFPM_ENGINE(object);
+
+ if ( engine->priv->conf )
+ g_object_unref (engine->priv->conf);
+
+ if ( engine->priv->supply )
+ g_object_unref (engine->priv->supply);
+
+#ifdef HAVE_DPMS
+ if ( engine->priv->dpms )
+ g_object_unref (engine->priv->dpms);
+#endif
+
+ if ( engine->priv->cpu )
+ g_object_unref (engine->priv->cpu);
+
+ if ( engine->priv->lid)
+ g_object_unref(engine->priv->lid);
+
+ if ( engine->priv->iface)
+ g_object_unref(engine->priv->iface);
+
+ if ( engine->priv->adapter)
+ g_object_unref (engine->priv->adapter);
+
+ G_OBJECT_CLASS(xfpm_engine_parent_class)->finalize(object);
+}
+
XfpmEngine *
xfpm_engine_new(void)
{
@@ -492,7 +483,7 @@
gboolean *OUT_low_battery,
GError **error);
-#include "org.freedesktop.PowerManagement-server.h"
+#include "org.freedesktop.PowerManagement.h"
static void
xfpm_engine_dbus_class_init(XfpmEngineClass *klass)
Added: xfce4-power-manager/trunk/src/xfpm-inhibit.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-inhibit.c (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-inhibit.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -0,0 +1,210 @@
+/*
+ * * Copyright (C) 2008-2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <glib.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "xfpm-inhibit.h"
+#include "xfpm-screen-saver.h"
+
+/* Init */
+static void xfpm_inhibit_class_init (XfpmInhibitClass *klass);
+static void xfpm_inhibit_init (XfpmInhibit *inhibit);
+static void xfpm_inhibit_finalize (GObject *object);
+
+static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass);
+static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit);
+
+#define XFPM_INHIBIT_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_INHIBIT, XfpmInhibitPrivate))
+
+struct XfpmInhibitPrivate
+{
+ XfpmScreenSaver *srv;
+ gboolean inhibited;
+};
+
+enum
+{
+ INHIBIT_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static gpointer xfpm_inhibit_object = NULL;
+
+G_DEFINE_TYPE(XfpmInhibit, xfpm_inhibit, G_TYPE_OBJECT)
+
+static void
+xfpm_inhibit_screen_saver_inhibited_cb (XfpmScreenSaver *srv, gboolean is_inhibited, XfpmInhibit *inhibit)
+{
+ inhibit->priv->inhibited = is_inhibited;
+ g_signal_emit (G_OBJECT(inhibit), signals[INHIBIT_CHANGED], 0, is_inhibited);
+}
+
+static void
+xfpm_inhibit_class_init(XfpmInhibitClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ signals[INHIBIT_CHANGED] =
+ g_signal_new("inhibit-changed",
+ XFPM_TYPE_INHIBIT,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(XfpmInhibitClass, inhibit_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ object_class->finalize = xfpm_inhibit_finalize;
+
+ g_type_class_add_private(klass,sizeof(XfpmInhibitPrivate));
+
+ xfpm_inhibit_dbus_class_init (klass);
+}
+
+static void
+xfpm_inhibit_init(XfpmInhibit *inhibit)
+{
+ inhibit->priv = XFPM_INHIBIT_GET_PRIVATE(inhibit);
+
+ inhibit->priv->srv = xfpm_screen_saver_new ();
+
+ g_signal_connect (inhibit->priv->srv, "screen-saver-inhibited",
+ G_CALLBACK(xfpm_inhibit_screen_saver_inhibited_cb), inhibit);
+
+ xfpm_inhibit_dbus_init (inhibit);
+}
+
+static void
+xfpm_inhibit_finalize(GObject *object)
+{
+ XfpmInhibit *inhibit;
+
+ inhibit = XFPM_INHIBIT(object);
+
+ G_OBJECT_CLASS(xfpm_inhibit_parent_class)->finalize(object);
+}
+
+XfpmInhibit *
+xfpm_inhibit_new(void)
+{
+ if ( 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);
+}
+
+/*
+ *
+ * DBus server implementation for org.freedesktop.PowerManagement.Inhibit
+ *
+ */
+static gboolean xfpm_inhibit_dbus_inhibit (XfpmInhibit *inhibit,
+ const gchar *IN_appname,
+ const gchar *IN_reason,
+ guint *OUT_cookie,
+ GError **error);
+
+static gboolean xfpm_inhibit_dbus_un_inhibit (XfpmInhibit *inhibit,
+ guint IN_cookie,
+ GError **error);
+
+static gboolean xfpm_inhibit_dbus_has_inhibit (XfpmInhibit *inhibit,
+ gboolean *OUT_has_inhibit,
+ GError **error);
+
+#include "org.freedesktop.PowerManagement.Inhibit.h"
+
+static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass)
+{
+ dbus_g_object_type_install_info(G_TYPE_FROM_CLASS(klass),
+ &dbus_glib_xfpm_inhibit_object_info);
+}
+
+static void xfpm_inhibit_dbus_init (XfpmInhibit *inhibit)
+{
+ DBusGConnection *bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+
+ dbus_g_connection_register_g_object (bus,
+ "/org/freedesktop/PowerManagement/Inhibit",
+ G_OBJECT(inhibit));
+}
+
+static gboolean xfpm_inhibit_dbus_inhibit (XfpmInhibit *inhibit,
+ const gchar *IN_appname,
+ const gchar *IN_reason,
+ guint *OUT_cookie,
+ GError **error)
+{
+ TRACE("application name=%s reason=%s", IN_appname, IN_reason);
+
+ inhibit->priv->inhibited = TRUE;
+ g_signal_emit (G_OBJECT(inhibit), signals[INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
+
+ *OUT_cookie = 1;//FIXME support cookies
+
+ return TRUE;
+}
+
+static gboolean xfpm_inhibit_dbus_un_inhibit (XfpmInhibit *inhibit,
+ guint IN_cookie,
+ GError **error)
+{
+ inhibit->priv->inhibited = FALSE;
+ g_signal_emit (G_OBJECT(inhibit), signals[INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
+
+ return TRUE;
+}
+
+static gboolean xfpm_inhibit_dbus_has_inhibit (XfpmInhibit *inhibit,
+ gboolean *OUT_has_inhibit,
+ GError **error)
+{
+
+ return TRUE;
+}
Added: xfce4-power-manager/trunk/src/xfpm-inhibit.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-inhibit.h (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-inhibit.h 2009-03-18 07:48:02 UTC (rev 6939)
@@ -0,0 +1,55 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFPM_INHIBIT_H
+#define __XFPM_INHIBIT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_INHIBIT (xfpm_inhibit_get_type () )
+#define XFPM_INHIBIT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_INHIBIT, XfpmInhibit))
+#define XFPM_IS_INHIBIT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_INHIBIT))
+
+typedef struct XfpmInhibitPrivate XfpmInhibitPrivate;
+
+typedef struct
+{
+ GObject parent;
+ XfpmInhibitPrivate *priv;
+
+} XfpmInhibit;
+
+typedef struct
+{
+ GObjectClass parent_class;
+
+ void (*inhibit_changed) (XfpmInhibit *inhibit,
+ gboolean is_inhibit);
+
+} XfpmInhibitClass;
+
+GType xfpm_inhibit_get_type (void) G_GNUC_CONST;
+XfpmInhibit *xfpm_inhibit_new (void);
+
+G_END_DECLS
+
+#endif /* __XFPM_INHIBIT_H */
Modified: xfce4-power-manager/trunk/src/xfpm-lid-hal.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-lid-hal.c 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/xfpm-lid-hal.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -56,6 +56,8 @@
{
HalManager *manager;
HalDevice *device;
+
+ GTimer *timer;
gboolean hw_found;
};
@@ -65,6 +67,8 @@
LAST_SIGNAL
};
+#define DUPLICATE_SHUTDOWN_TIMEOUT 4.0f
+
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE(XfpmLidHal, xfpm_lid_hal, G_TYPE_OBJECT)
@@ -98,6 +102,7 @@
lid->priv->manager = NULL;
lid->priv->device = NULL;
lid->priv->hw_found = FALSE;
+ lid->priv->timer = g_timer_new ();
}
static void
@@ -113,6 +118,8 @@
if ( lid->priv->device )
g_object_unref (lid->priv->device);
+ g_timer_destroy (lid->priv->timer);
+
G_OBJECT_CLASS(xfpm_lid_hal_parent_class)->finalize(object);
}
@@ -134,8 +141,17 @@
if ( pressed )
{
- TRACE("Emitting signal lid closed");
- g_signal_emit ( G_OBJECT(lid), signals[LID_CLOSED], 0);
+ if ( g_timer_elapsed (lid->priv->timer, NULL ) < DUPLICATE_SHUTDOWN_TIMEOUT )
+ {
+ TRACE("Duplicated lid closed");
+ return;
+ }
+ else
+ {
+ TRACE("Emitting signal lid closed");
+ g_signal_emit ( G_OBJECT(lid), signals[LID_CLOSED], 0);
+ g_timer_reset (lid->priv->timer);
+ }
}
}
Modified: xfce4-power-manager/trunk/src/xfpm-manager.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-manager.c 2009-03-18 02:21:24 UTC (rev 6938)
+++ xfce4-power-manager/trunk/src/xfpm-manager.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -150,6 +150,12 @@
g_critical ("Unable to reserve bus name\n");
}
+ if (!xfpm_dbus_register_name (dbus_g_connection_get_connection(manager->priv->session_bus),
+ "org.freedesktop.PowerManagement.Inhibit") )
+ {
+
+ g_critical ("Unable to reserve bus name\n");
+ }
manager->priv->hproxy = hal_proxy_new ();
g_signal_connect (manager->priv->hproxy, "hal-disconnected",
Added: xfce4-power-manager/trunk/src/xfpm-screen-saver.c
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-screen-saver.c (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-screen-saver.c 2009-03-18 07:48:02 UTC (rev 6939)
@@ -0,0 +1,204 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
+#include <glib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include "libxfpm/xfpm-dbus.h"
+
+#include "xfpm-screen-saver.h"
+
+/* Init */
+static void xfpm_screen_saver_class_init (XfpmScreenSaverClass *klass);
+static void xfpm_screen_saver_init (XfpmScreenSaver *srv);
+static void xfpm_screen_saver_finalize (GObject *object);
+
+#define XFPM_SCREEN_SAVER_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE((o), XFPM_TYPE_SCREEN_SAVER, XfpmScreenSaverPrivate))
+
+struct XfpmScreenSaverPrivate
+{
+ DBusConnection *bus;
+};
+
+enum
+{
+ SCREEN_SAVER_INHIBITED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static gpointer xfpm_screen_saver_object = NULL;
+
+G_DEFINE_TYPE(XfpmScreenSaver, xfpm_screen_saver, G_TYPE_OBJECT)
+
+static DBusHandlerResult
+xfpm_screen_saver_filter (DBusConnection *connection, DBusMessage *message, void *data)
+{
+ XfpmScreenSaver *srv = ( XfpmScreenSaver *)data;
+
+ if ( dbus_message_is_method_call (message, "org.gnome.ScreenSaver", "Inhibit") )
+ {
+ g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, TRUE);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ else if ( dbus_message_is_method_call (message, "org.gnome.ScreenSaver", "UnInhibit") )
+ {
+ g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, FALSE);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ else if ( dbus_message_is_method_call (message, "org.freedesktop.ScreenSaver", "Inhibit") )
+ {
+ g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, TRUE);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+ else if ( dbus_message_is_method_call (message, "org.freedesktop.ScreenSaver", "UnInhibit") )
+ {
+ g_signal_emit (G_OBJECT(srv), signals[SCREEN_SAVER_INHIBITED], 0, FALSE);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void
+xfpm_screen_saver_class_init(XfpmScreenSaverClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ signals[SCREEN_SAVER_INHIBITED] =
+ g_signal_new("screen-saver-inhibited",
+ XFPM_TYPE_SCREEN_SAVER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(XfpmScreenSaverClass, screen_saver_inhibited),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ object_class->finalize = xfpm_screen_saver_finalize;
+
+ g_type_class_add_private(klass,sizeof(XfpmScreenSaverPrivate));
+}
+
+static void
+xfpm_screen_saver_init(XfpmScreenSaver *srv)
+{
+ DBusError error;
+ dbus_error_init (&error);
+
+ srv->priv = XFPM_SCREEN_SAVER_GET_PRIVATE(srv);
+
+ srv->priv->bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
+
+ if ( dbus_error_is_set (&error) )
+ {
+ g_critical ("Unable to get session bus: %s", error.message);
+ dbus_error_free (&error);
+ goto out;
+ }
+
+ dbus_bus_add_match (srv->priv->bus,
+ "type='method_call',interface='org.gnome.ScreenSaver'",
+ &error);
+
+ if ( dbus_error_is_set (&error) )
+ {
+ g_warning ("Failed to add match for interface org.gnome.ScreenSaver: %s", error.message);
+ dbus_error_free (&error);
+ }
+
+ dbus_error_init (&error);
+
+ dbus_bus_add_match (srv->priv->bus,
+ "type='method_call',interface='org.freedesktop.ScreenSaver'",
+ &error);
+
+ if ( dbus_error_is_set (&error) )
+ {
+ g_warning ("Failed to add match for interface org.freedesktop.ScreenSaver: %s", error.message);
+ dbus_error_free (&error);
+ }
+
+ if (!dbus_connection_add_filter (srv->priv->bus, xfpm_screen_saver_filter, srv, NULL) )
+ {
+ g_warning ("Couldn't add filter");
+ }
+out:
+ ;
+}
+
+static void
+xfpm_screen_saver_finalize(GObject *object)
+{
+ XfpmScreenSaver *srv;
+
+ srv = XFPM_SCREEN_SAVER(object);
+
+ dbus_bus_remove_match (srv->priv->bus,
+ "type='method_call',interface='org.gnome.ScreenSaver'",
+ NULL);
+
+ dbus_bus_remove_match (srv->priv->bus,
+ "type='method_call',interface='org.freedesktop.ScreenSaver'",
+ NULL);
+
+ dbus_connection_unref (srv->priv->bus);
+
+ G_OBJECT_CLASS(xfpm_screen_saver_parent_class)->finalize(object);
+}
+
+XfpmScreenSaver *
+xfpm_screen_saver_new(void)
+{
+ if ( xfpm_screen_saver_object != NULL )
+ {
+ g_object_ref (xfpm_screen_saver_object);
+ }
+ else
+ {
+ xfpm_screen_saver_object = g_object_new (XFPM_TYPE_SCREEN_SAVER, NULL);
+ g_object_add_weak_pointer (xfpm_screen_saver_object, &xfpm_screen_saver_object);
+ }
+ return XFPM_SCREEN_SAVER (xfpm_screen_saver_object);
+}
Added: xfce4-power-manager/trunk/src/xfpm-screen-saver.h
===================================================================
--- xfce4-power-manager/trunk/src/xfpm-screen-saver.h (rev 0)
+++ xfce4-power-manager/trunk/src/xfpm-screen-saver.h 2009-03-18 07:48:02 UTC (rev 6939)
@@ -0,0 +1,55 @@
+/*
+ * * Copyright (C) 2009 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFPM_SCREEN_SAVER_H
+#define __XFPM_SCREEN_SAVER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFPM_TYPE_SCREEN_SAVER (xfpm_screen_saver_get_type () )
+#define XFPM_SCREEN_SAVER(o) (G_TYPE_CHECK_INSTANCE_CAST((o), XFPM_TYPE_SCREEN_SAVER, XfpmScreenSaver))
+#define XFPM_IS_SCREEN_SAVER(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), XFPM_TYPE_SCREEN_SAVER))
+
+typedef struct XfpmScreenSaverPrivate XfpmScreenSaverPrivate;
+
+typedef struct
+{
+ GObject parent;
+ XfpmScreenSaverPrivate *priv;
+
+} XfpmScreenSaver;
+
+typedef struct
+{
+ GObjectClass parent_class;
+
+ void (*screen_saver_inhibited) (XfpmScreenSaver *srv,
+ gboolean is_inhibited);
+
+} XfpmScreenSaverClass;
+
+GType xfpm_screen_saver_get_type (void) G_GNUC_CONST;
+XfpmScreenSaver *xfpm_screen_saver_new (void);
+
+G_END_DECLS
+
+#endif /* __XFPM_SCREEN_SAVER_H */
More information about the Goodies-commits
mailing list