Index: hald/linux2/addons/Makefile.am =================================================================== RCS file: /cvs/hal/hal/hald/linux2/addons/Makefile.am,v retrieving revision 1.8 diff -u -p -u -p -r1.8 Makefile.am --- hald/linux2/addons/Makefile.am 8 Feb 2006 13:54:44 -0000 1.8 +++ hald/linux2/addons/Makefile.am 24 Apr 2006 22:28:30 -0000 @@ -9,7 +9,7 @@ INCLUDES = \ @PACKAGE_CFLAGS@ if HALD_COMPILE_LINUX2 -libexec_PROGRAMS = hald-addon-hid-ups hald-addon-acpi hald-addon-storage hald-addon-pmu hald-addon-keyboard +libexec_PROGRAMS = hald-addon-hid-ups hald-addon-acpi hald-addon-storage hald-addon-pmu hald-addon-keyboard hald-addon-sonypi if HAVE_LIBUSB libexec_PROGRAMS += hald-addon-usb-csr @@ -31,6 +31,9 @@ hald_addon_storage_LDADD = $(top_builddi hald_addon_keyboard_SOURCES = addon-keyboard.c hald_addon_keyboard_LDADD = $(top_builddir)/libhal/libhal.la +hald_addon_sonypi_SOURCES = addon-sonypi.c +hald_addon_sonypi_LDADD = $(top_builddir)/libhal/libhal.la + if HAVE_LIBUSB hald_addon_usb_csr_SOURCES = addon-usb-csr.c hald_addon_usb_csr_LDADD = $(top_builddir)/libhal/libhal.la -lusb @PACKAGE_LIBS@ --- /dev/null 2006-04-24 22:08:39.900985500 +0100 +++ fdi/policy/10osvendor/10-sonypi-buttons.fdi 2006-04-24 22:26:07.000000000 +0100 @@ -0,0 +1,16 @@ + + + + + + + + + hald-addon-sonypi + button + + + + + + --- /dev/null 2006-04-24 22:08:39.900985500 +0100 +++ hald/linux2/addons/addon-sonypi.c 2006-04-24 22:28:08.000000000 +0100 @@ -0,0 +1,130 @@ +/*************************************************************************** + * CVSID: $Id$ + * + * addon-sonypi.c : Listen to key events through sonypi and modify hal + * device objects + * + * Copyright (C) 2005 David Zeuthen, + * Copyright (C) 2005 Ryan Lortie + * Copyright (C) 2006 Matthew Garrett + * Copyright (C) 2006 Bastien Nocera + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libhal/libhal.h" + +#include "../probing/shared.h" + +static char *udi; + +#define SONYPI_EVENT_KEYMAX SONYPI_EVENT_PKEY_P3 + 1 + +static char *key_name[SONYPI_EVENT_KEYMAX + 1] = { + [0 ... SONYPI_EVENT_KEYMAX] = NULL, + [SONYPI_EVENT_FNKEY_F2] = "mute", + [SONYPI_EVENT_FNKEY_F3] = "volume-down", + [SONYPI_EVENT_FNKEY_F4] = "volume-up", + [SONYPI_EVENT_FNKEY_F5] = "brightnessdown", + [SONYPI_EVENT_FNKEY_F6] = "brightnessup", + [SONYPI_EVENT_FNKEY_F7] = "switch-videomode", + [SONYPI_EVENT_FNKEY_F12] = "hibernate", + [SONYPI_EVENT_PKEY_P1] = "prog1" +}; + +static void +main_loop (LibHalContext *ctx, FILE* eventfp) +{ + DBusError error; + unsigned char event; + + dbus_error_init (&error); + + while (fread (&event, sizeof(event), 1, eventfp)) { + if (key_name[event] != NULL) { + libhal_device_emit_condition (ctx, udi, + "ButtonPressed", + key_name[event], + &error); + } + } + + dbus_error_free (&error); +} + +int +main (int argc, char **argv) +{ + LibHalContext *ctx = NULL; + DBusError error; + FILE *eventfp; + + if (getenv ("HALD_VERBOSE") != NULL) + is_verbose = TRUE; + + dbus_error_init (&error); + + if ((udi = getenv ("UDI")) == NULL) + goto out; + + if ((ctx = libhal_ctx_init_direct (&error)) == NULL) + goto out; + + eventfp = fopen("/dev/sonypi", "r"); + + if (!eventfp) + goto out; + + drop_privileges (0); + + while (1) + { + main_loop (ctx, eventfp); + + /* If main_loop exits sleep for 5s and try to reconnect ( + again). */ + sleep (5); + } + + return 0; + + out: + if (ctx != NULL) { + dbus_error_init (&error); + libhal_ctx_shutdown (ctx, &error); + libhal_ctx_free (ctx); + } + + return 0; +} + +/* vim:set sw=8 noet: */