Commit 8beeb1f9 authored by Lionel Le Folgoc's avatar Lionel Le Folgoc Committed by Simon Steinbeiss

Add optional upower-glib support for lid-open/closed events

Signed-off-by: default avatarSimon Steinbeiss <simon.steinbeiss@elfenbeinturm.at>
parent 7ef545b9
......@@ -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
......
......@@ -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
......
/*
* Copyright (C) 2012 Lionel Le Folgoc <lionel@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);
}
}
/*
* Copyright (C) 2012 Lionel Le Folgoc <lionel@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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment