[Xfce4-commits] <xfce4-settings:master> Add optional upower-glib support for lid-open/closed events

Simon Steinbeiss noreply at xfce.org
Thu Nov 8 00:22:02 CET 2012


Updating branch refs/heads/master
         to 8beeb1f9177a1fc454aa37ba251e2d5ff484963f (commit)
       from 7ef545b96688fd5797a3d422e50fa7be7c676af5 (commit)

commit 8beeb1f9177a1fc454aa37ba251e2d5ff484963f
Author: Lionel Le Folgoc <lionel at lefolgoc.net>
Date:   Wed Nov 7 19:26:26 2012 +0100

    Add optional upower-glib support for lid-open/closed events
    
    Signed-off-by: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>

 configure.ac.in               |   11 +++
 xfsettingsd/Makefile.am       |   12 ++++
 xfsettingsd/displays-upower.c |  143 +++++++++++++++++++++++++++++++++++++++++
 xfsettingsd/displays-upower.h |   38 +++++++++++
 4 files changed, 204 insertions(+), 0 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 042d376..0e7907d 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -134,6 +134,12 @@ AC_ARG_WITH([pnp-ids-path],
 PNP_IDS=$with_pnp_ids_path
 AC_SUBST(PNP_IDS)
 
+dnl ***********************************
+dnl *** Optional support for UPower ***
+dnl ***********************************
+XDT_CHECK_OPTIONAL_PACKAGE([UPOWERGLIB], [upower-glib], [0.9.8],
+                           [upower-glib], [UPower support])
+
 dnl **************************************
 dnl *** Optional support for Libnotify ***
 dnl **************************************
@@ -251,6 +257,11 @@ echo "* Xrandr support:            yes"
 else
 echo "* Xrandr support:            no"
 fi
+if test x"$UPOWERGLIB_FOUND" = x"yes"; then
+echo "* UPower support:            yes"
+else
+echo "* UPower support:            no"
+fi
 if test x"$LIBNOTIFY_FOUND" = x"yes"; then
 echo "* Libnotify support:         yes"
 else
diff --git a/xfsettingsd/Makefile.am b/xfsettingsd/Makefile.am
index 1b2dabe..3b1386b 100644
--- a/xfsettingsd/Makefile.am
+++ b/xfsettingsd/Makefile.am
@@ -88,6 +88,18 @@ xfsettingsd_CFLAGS += \
 
 xfsettingsd_LDADD += \
 	$(XRANDR_LIBS)
+
+if HAVE_UPOWERGLIB
+xfsettingsd_SOURCES += \
+	displays-upower.c \
+	displays-upower.h
+
+xfsettingsd_CFLAGS += \
+	$(UPOWERGLIB_CFLAGS)
+
+xfsettingsd_LDADD += \
+	$(UPOWERGLIB_LIBS)
+endif
 endif
 
 settingsdir = $(sysconfdir)/xdg/xfce4/xfconf/xfce-perchannel-xml
diff --git a/xfsettingsd/displays-upower.c b/xfsettingsd/displays-upower.c
new file mode 100644
index 0000000..bbb3028
--- /dev/null
+++ b/xfsettingsd/displays-upower.c
@@ -0,0 +1,143 @@
+/*
+ *  Copyright (C) 2012 Lionel Le Folgoc <lionel at lefolgoc.net>
+ *
+ *  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 Library 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
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <upower.h>
+
+#include <X11/extensions/Xrandr.h>
+
+#include "debug.h"
+#include "displays-upower.h"
+
+
+
+static void             xfce_displays_upower_dispose                        (GObject                 *object);
+static void             xfce_displays_upower_property_changed               (UpClient                *client,
+                                                                             XfceDisplaysUPower      *upower);
+
+
+
+struct _XfceDisplaysUPowerClass
+{
+    GObjectClass __parent__;
+
+    void         (*lid_changed)     (XfceDisplaysUPower *upower,
+                                     gboolean            lid_is_closed);
+};
+
+struct _XfceDisplaysUPower
+{
+    GObject   __parent__;
+
+    UpClient *client;
+    gint      handler;
+
+    guint     lid_is_closed : 1;
+};
+
+enum
+{
+    LID_CHANGED,
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = {0};
+
+
+
+G_DEFINE_TYPE (XfceDisplaysUPower, xfce_displays_upower, G_TYPE_OBJECT);
+
+
+
+static void
+xfce_displays_upower_class_init (XfceDisplaysUPowerClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+    gobject_class->dispose = xfce_displays_upower_dispose;
+
+    signals[LID_CHANGED] =
+        g_signal_new ("lid-changed",
+                      XFCE_TYPE_DISPLAYS_UPOWER,
+                      G_SIGNAL_RUN_LAST,
+                      G_STRUCT_OFFSET (XfceDisplaysUPowerClass, lid_changed),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__BOOLEAN,
+                      G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+}
+
+
+
+static void
+xfce_displays_upower_init (XfceDisplaysUPower *upower)
+{
+    upower->client = up_client_new ();
+    upower->lid_is_closed = up_client_get_lid_is_closed (upower->client);
+    upower->handler = g_signal_connect (G_OBJECT (upower->client),
+                                        "changed",
+                                        G_CALLBACK (xfce_displays_upower_property_changed),
+                                        upower);
+}
+
+
+
+static void
+xfce_displays_upower_dispose (GObject *object)
+{
+    XfceDisplaysUPower *upower = XFCE_DISPLAYS_UPOWER (object);
+
+    if (upower->handler > 0)
+    {
+        g_signal_handler_disconnect (G_OBJECT (upower->client),
+                                     upower->handler);
+        g_object_unref (upower->client);
+        upower->handler = 0;
+    }
+
+    (*G_OBJECT_CLASS (xfce_displays_upower_parent_class)->dispose) (object);
+}
+
+
+
+static void
+xfce_displays_upower_property_changed (UpClient           *client,
+                                       XfceDisplaysUPower *upower)
+{
+    gboolean lid_is_closed;
+
+    /* no lid, no chocolate */
+    if (!up_client_get_lid_is_present (client))
+        return;
+
+    lid_is_closed = up_client_get_lid_is_closed (client);
+    if (upower->lid_is_closed != lid_is_closed)
+    {
+        xfsettings_dbg (XFSD_DEBUG_DISPLAYS, "UPower lid event received (%s -> %s).",
+                        XFSD_LID_STR (upower->lid_is_closed), XFSD_LID_STR (lid_is_closed));
+
+        upower->lid_is_closed = lid_is_closed;
+        g_signal_emit (G_OBJECT (upower), signals[LID_CHANGED], 0, upower->lid_is_closed);
+    }
+}
diff --git a/xfsettingsd/displays-upower.h b/xfsettingsd/displays-upower.h
new file mode 100644
index 0000000..d42ea2e
--- /dev/null
+++ b/xfsettingsd/displays-upower.h
@@ -0,0 +1,38 @@
+/*
+ *  Copyright (C) 2012 Lionel Le Folgoc <lionel at lefolgoc.net>
+ *
+ *  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 Library 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 __DISPLAYS_UPOWER_H__
+#define __DISPLAYS_UPOWER_H__
+
+#include <glib-object.h>
+
+typedef struct _XfceDisplaysUPowerClass XfceDisplaysUPowerClass;
+typedef struct _XfceDisplaysUPower      XfceDisplaysUPower;
+
+#define XFCE_TYPE_DISPLAYS_UPOWER            (xfce_displays_upower_get_type ())
+#define XFCE_DISPLAYS_UPOWER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_DISPLAYS_UPOWER, XfceDisplaysUPower))
+#define XFCE_DISPLAYS_UPOWER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_DISPLAYS_UPOWER, XfceDisplaysUPowerClass))
+#define XFCE_IS_DISPLAYS_UPOWER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_DISPLAYS_UPOWER))
+#define XFCE_IS_DISPLAYS_UPOWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_DISPLAYS_UPOWER))
+#define XFCE_DISPLAYS_UPOWER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_DISPLAYS_UPOWER, XfceDisplaysUPowerClass))
+
+#define XFSD_LID_STR(b) (b ? "closed" : "open")
+
+GType xfce_displays_upower_get_type (void) G_GNUC_CONST;
+
+#endif /* !__DISPLAYS_UPOWER_H__ */


More information about the Xfce4-commits mailing list