hal/hald/linux2/addons Makefile.am, 1.7, 1.8 addon-acpi.c, 1.13, 1.14 addon-keyboard.c, NONE, 1.1

David Zeuthen david at freedesktop.org
Wed Feb 8 05:54:46 PST 2006


Update of /cvs/hal/hal/hald/linux2/addons
In directory gabe:/tmp/cvs-serv20696/hald/linux2/addons

Modified Files:
	Makefile.am addon-acpi.c 
Added Files:
	addon-keyboard.c 
Log Message:
2006-02-08  David Zeuthen  <davidz at redhat.com>

        Patch from Matthew Garrett <mjg59 at srcf.ucam.org>.

        Two patches attached: 1) Changes the ACPI addon to report the type
        of button pressed as well as the fact that a button has been
        pressed. 2) Adds a keyboard addon. The included fdi file will bind
        it to anything that has type input.keyboard. It adds the
        capability "button" to the keyboard devices, and on any keypress
        checks the key against a table. If the key is found there, a
        ButtonPressed event is generated with the name of the key in the
        details field (one exception - KEY_SUSPEND is given the name
        "hibernate").

        There's a couple of extra features that could be added (export a
        list of the available keys, for instance - not very helpful on
        PS/2, but useful on USB), but could these be applied as is for
        now?

        * hald/linux2/probing/shared.h: Move drop_privileges here so other
        code can use it too.

        * hald/linux2/addons/Makefile.am: Add build rules for
        hald-addon-keybaord

        * hald/linux2/addons/addon-acpi.c: Also send button.type as part
        of the event

        * hald/linux2/addons/addon-keyboard.c: New file. Also set
        button.type to "" and button.has_state to FALSE




Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Makefile.am	23 Jun 2005 14:50:05 -0000	1.7
+++ Makefile.am	8 Feb 2006 13:54:44 -0000	1.8
@@ -9,7 +9,7 @@
 	@PACKAGE_CFLAGS@
 
 if HALD_COMPILE_LINUX2
-libexec_PROGRAMS  = hald-addon-hid-ups hald-addon-acpi hald-addon-storage hald-addon-pmu
+libexec_PROGRAMS  = hald-addon-hid-ups hald-addon-acpi hald-addon-storage hald-addon-pmu hald-addon-keyboard
 
 if HAVE_LIBUSB
 libexec_PROGRAMS += hald-addon-usb-csr
@@ -28,6 +28,9 @@
 hald_addon_storage_SOURCES = addon-storage.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
 
+hald_addon_keyboard_SOURCES = addon-keyboard.c
+hald_addon_keyboard_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@

Index: addon-acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/addon-acpi.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- addon-acpi.c	9 Nov 2005 21:13:30 -0000	1.13
+++ addon-acpi.c	8 Feb 2006 13:54:44 -0000	1.14
@@ -114,13 +114,23 @@
 			snprintf (udi, sizeof (udi), "/org/freedesktop/Hal/devices/acpi_%s", acpi_name);
 
 			if (strncmp (acpi_path, "button", sizeof ("button") - 1) == 0) {
+				char *type;
+
 				dbg ("button event");
 
 				/* TODO: only rescan if button got state */
 				libhal_device_rescan (ctx, udi, &error);
 
-				libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error);
-
+				type = libhal_device_get_property_string(ctx, udi, 
+									 "button.type",
+									 &error);
+				if (type != NULL) {
+					libhal_device_emit_condition (ctx, udi, "ButtonPressed",
+								      type, &error);
+					libhal_free_string(type);
+				} else {
+					libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error);
+				}
 			} else if (strncmp (acpi_path, "ac_adapter", sizeof ("ac_adapter") - 1) == 0) {
 				dbg ("ac_adapter event");
 				libhal_device_rescan (ctx, udi, &error);

--- NEW FILE: addon-keyboard.c ---
/***************************************************************************
 * CVSID: $Id: addon-keyboard.c,v 1.1 2006/02/08 13:54:44 david Exp $
 *
 * addon-keyboard.c : Listen to key events and modify hal device objects
 *
 * Copyright (C) 2005 David Zeuthen, <david at fubar.dk>
 * Copyright (C) 2005 Ryan Lortie <desrt at desrt.ca>
 * Copyright (C) 2006 Matthew Garrett <mjg59 at srcf.ucam.org>
 *
 * 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 <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <linux/input.h>

#include "libhal/libhal.h"

#include "../probing/shared.h"

static char *udi;

static char *key_name[KEY_MAX + 1] = {
	[0 ... KEY_MAX] = NULL,
	[KEY_STOP] = "stop",
	[KEY_AGAIN] = "again",
	[KEY_PROPS] = "props",
	[KEY_UNDO] = "undo",
	[KEY_FRONT] = "front",
	[KEY_COPY] = "copy",
	[KEY_OPEN] = "open",
	[KEY_PASTE] = "paste",
	[KEY_FIND] = "find",
	[KEY_CUT] = "cut",
	[KEY_HELP] = "help",
	[KEY_MENU] = "menu",
	[KEY_CALC] = "calc",
	[KEY_SETUP] = "setup",
	[KEY_SLEEP] = "sleep",
	[KEY_WAKEUP] = "wakeup",
	[KEY_FILE] = "file",
	[KEY_SENDFILE] = "sendfile",
	[KEY_DELETEFILE] = "deletefile",
	[KEY_XFER] = "xfer",
	[KEY_PROG1] = "prog1",
	[KEY_PROG2] = "prog2",
	[KEY_WWW] = "www",
	[KEY_MSDOS] = "msdos",
	[KEY_COFFEE] = "coffee",
	[KEY_DIRECTION] = "direction",
	[KEY_CYCLEWINDOWS] = "cyclewindows",
	[KEY_MAIL] = "mail",
	[KEY_BOOKMARKS] = "bookmarks",
	[KEY_COMPUTER] = "computer",
	[KEY_BACK] = "back",
	[KEY_FORWARD] = "forward",
	[KEY_CLOSECD] = "closecd",
	[KEY_EJECTCD] = "ejectcd",
	[KEY_EJECTCLOSECD] = "ejectclosecd",
	[KEY_NEXTSONG] = "nextsong",
	[KEY_PLAYPAUSE] = "playpause",
	[KEY_PREVIOUSSONG] = "previoussong",
	[KEY_STOPCD] = "stopcd",
	[KEY_RECORD] = "record",
	[KEY_REWIND] = "rewind",
	[KEY_PHONE] = "phone",
	[KEY_ISO] = "iso",
	[KEY_CONFIG] = "config",
	[KEY_HOMEPAGE] = "homepage",
	[KEY_REFRESH] = "refresh",
	[KEY_EXIT] = "exit",
	[KEY_MOVE] = "move",
	[KEY_EDIT] = "edit",
	[KEY_SCROLLUP] = "scrollup",
	[KEY_SCROLLDOWN] = "scrolldown",
	[KEY_KPLEFTPAREN] = "kpleftparen",
	[KEY_KPRIGHTPAREN] = "kprightparen",
	[KEY_F13] = "f13",
	[KEY_F14] = "f14",
	[KEY_F15] = "f15",
	[KEY_F16] = "f16",
	[KEY_F17] = "f17",
	[KEY_F18] = "f18",
	[KEY_F19] = "f19",
	[KEY_F20] = "f20",
	[KEY_F21] = "f21",
	[KEY_F22] = "f22",
	[KEY_F23] = "f23",
	[KEY_F24] = "f24",
	[KEY_PLAYCD] = "playcd",
	[KEY_PAUSECD] = "pausecd",
	[KEY_PROG3] = "prog3",
	[KEY_PROG4] = "prog4",
	[KEY_SUSPEND] = "hibernate",
	[KEY_CLOSE] = "close",
	[KEY_PLAY] = "play",
	[KEY_FASTFORWARD] = "fastforward",
	[KEY_BASSBOOST] = "bassboost",
	[KEY_PRINT] = "print",
	[KEY_HP] = "hp",
	[KEY_CAMERA] = "camera",
	[KEY_SOUND] = "sound",
	[KEY_QUESTION] = "question",
	[KEY_EMAIL] = "email",
	[KEY_CHAT] = "chat",
	[KEY_SEARCH] = "search",
	[KEY_CONNECT] = "connect",
	[KEY_FINANCE] = "finance",
	[KEY_SPORT] = "sport",
	[KEY_SHOP] = "shop",
	[KEY_ALTERASE] = "alterase",
	[KEY_CANCEL] = "cancel",
	[KEY_BRIGHTNESSDOWN] = "brightnessdown",
	[KEY_BRIGHTNESSUP] = "brightnessup",
	[KEY_MEDIA] = "media"
};

static void
main_loop (LibHalContext *ctx, FILE* eventfp)
{
	DBusError error;
	struct input_event event;

	dbus_error_init (&error);

	while (fread (&event, sizeof(event), 1, eventfp)) {
		/* dbg ("event.code = %d (0x%02x)", event.code); */
		if (key_name[event.code] && event.value == 1) {
			libhal_device_emit_condition (ctx, udi, 
						      "ButtonPressed",
						      key_name[event.code],
						      &error);
		}
	}
	
	dbus_error_free (&error);
}

int
main (int argc, char **argv)
{
	LibHalContext *ctx = NULL;
	DBusError error;
	char *device_file;
	FILE *eventfp;

	dbus_error_init (&error);

	if (getenv ("HALD_VERBOSE") != NULL)
		is_verbose = TRUE;

	if ((udi = getenv ("UDI")) == NULL)
		goto out;
	
	if ((device_file = getenv ("HAL_PROP_INPUT_DEVICE")) == NULL)
		goto out;

	if ((ctx = libhal_ctx_init_direct (&error)) == NULL)
                goto out;

	eventfp = fopen(device_file, "r");	

	if (!eventfp)
		goto out;

	libhal_device_add_capability (ctx, udi, "button", &error);
	libhal_device_set_property_string (ctx, udi, "button.type", "", &error);
	libhal_device_set_property_bool (ctx, udi, "button.has_state", FALSE, &error);

	drop_privileges();

	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: */




More information about the hal-commit mailing list