2
* Licensed under the GNU General Public License Version 2
4
* Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
32
#include <sys/ioctl.h>
34
#include <linux/input.h>
36
#include "libhal/libhal.h"
37
#include "hal-setup-keymap-hash-name.h"
39
static LibHalContext *ctx = NULL;
43
evdev_open (const char *dev)
47
/* requires root privs */
48
fd = open (dev, O_RDWR);
50
fprintf (stderr, "hal-setup-keymap: failed to open('%s'): %s\n",
51
dev, strerror (errno));
59
evdev_set_keycode (int fd, int scancode, int keycode)
67
ret = ioctl (fd, EVIOCSKEYCODE, codes);
69
fprintf (stderr, "hal-setup-keymap: failed to set scancode %x to keycode %d: %s\n",
70
scancode, keycode, strerror(errno));
78
main (int argc, char **argv)
83
unsigned int scancode = 0;
89
const struct key *name;
93
fprintf (stderr, "hal-setup-keymap: Failed to get UDI\n");
96
dbus_error_init (&error);
97
if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
98
fprintf (stderr, "hal-setup-keymap: Unable to initialise libhal context: %s\n", error.message);
102
dbus_error_init (&error);
103
if (!libhal_device_addon_is_ready (ctx, udi, &error)) {
107
/* get the string list data */
108
dbus_error_init (&error);
109
keymap_list = libhal_device_get_property_strlist (ctx, udi, "input.keymap.data", &error);
110
if (dbus_error_is_set (&error) == TRUE) {
111
fprintf (stderr, "hal-setup-keymap: Failed to get keymap list: '%s'\n", error.message);
116
device = libhal_device_get_property_string (ctx, udi, "input.device", &error);
117
if (dbus_error_is_set (&error) == TRUE) {
118
fprintf (stderr, "hal-setup-keymap: Failed to get input device list: '%s'\n", error.message);
122
/* get a file descriptor to the device */
123
fprintf (stderr, "hal-setup-keymap: Using device %s\n", device);
124
fd = evdev_open (device);
126
fprintf (stderr, "hal-setup-keymap: Could not open device\n");
130
/* add each of the keys */
132
values = sscanf (keymap_list[i], "%x:%s", &scancode, keyname);
134
/* fix for high scancodes on i8042 KBD - we do this here
135
* and not in the fdi as the high value is displayed in
136
* dmesg and we don't want the user to do more work */
137
if (scancode > 127) {
142
/* use gperf to convert as it's really quick */
143
name = lookup_key (keyname, strlen(keyname));
146
fprintf (stderr, "hal-setup-keymap: parsed %s to (0x%x, %i)\n",
147
keymap_list[i], scancode, keycode);
148
evdev_set_keycode (fd, scancode, keycode);
150
fprintf (stderr, "hal-setup-keymap: failed to find key '%s'\n", keyname);
153
fprintf (stderr, "hal-setup-keymap: Failed to parse %s\n", keymap_list[i]);
155
} while (keymap_list[++i] != NULL);
157
libhal_free_string_array (keymap_list);
160
/* we do not have to poll anything, so exit */