Search
lxdream.org :: lxdream :: r1050:7d88277590d9
lxdream 0.9.1
released Jun 29
Download Now
changeset1050:7d88277590d9
parent1049:e723f379ec88
child1051:953fe4fa7f6b
authornkeynes
dateSun Jun 28 01:45:16 2009 +0000 (11 years ago)
Change LIRC data structure to use GData (patch by Wahrhaft)
src/drivers/input_lirc.c
1.1 --- a/src/drivers/input_lirc.c Sun Jun 28 01:34:55 2009 +0000
1.2 +++ b/src/drivers/input_lirc.c Sun Jun 28 01:45:16 2009 +0000
1.3 @@ -45,11 +45,15 @@
1.4 GIOChannel *channel;
1.5 } *input_lirc_t;
1.6
1.7 -#define MAX_KEYSYMS 256
1.8 -static char *keysyms[MAX_KEYSYMS];
1.9 +#define MAX_KEYSYMS 65536
1.10 +static GData *keysyms;
1.11 +static uint16_t last_keycode;
1.12 +static GQuark keysym_by_keycode_result;
1.13 +
1.14
1.15 static uint16_t input_lirc_resolve_keysym( input_driver_t dev, const gchar *str );
1.16 static gchar *input_lirc_keysym_for_keycode( input_driver_t dev, uint16_t keycode );
1.17 +static void get_keysym_by_keycode(GQuark key_id, gpointer data, gpointer user_data);
1.18 static gboolean input_lirc_callback( GIOChannel *source, GIOCondition condition, gpointer data );
1.19
1.20 input_driver_t system_lirc_driver;
1.21 @@ -68,11 +72,11 @@
1.22 WARN("Could not initialize LIRC. LIRC hotkeys will be disabled.");
1.23 return FALSE;
1.24 }
1.25 -
1.26 +
1.27 system_lirc_driver->channel = g_io_channel_unix_new(system_lirc_driver->fd);
1.28 g_io_channel_set_flags(system_lirc_driver->channel, G_IO_FLAG_IS_READABLE | G_IO_FLAG_NONBLOCK, NULL);
1.29 g_io_add_watch(system_lirc_driver->channel, G_IO_IN|G_IO_ERR|G_IO_HUP, input_lirc_callback, system_lirc_driver);
1.30 - memset(keysyms, 0, MAX_KEYSYMS);
1.31 + g_datalist_init(&keysyms);
1.32 input_register_device((input_driver_t)system_lirc_driver, MAX_KEYSYMS - 1);
1.33 return TRUE;
1.34 }
1.35 @@ -90,23 +94,18 @@
1.36 {
1.37 //LIRC uses keysyms but no keycodes. To generate a keycode, we'll just make them up as we go.
1.38 //As long as we store keysyms instead of keycodes in any config files, this should be fine.
1.39 - uint16_t i;
1.40 - for (i = 1; i < MAX_KEYSYMS && keysyms[i] != NULL; i++) {
1.41 - if (strcasecmp(str, keysyms[i]) == 0) {
1.42 - //keycode already exists
1.43 - return i;
1.44 - }
1.45 +
1.46 + uint16_t keycode;
1.47 + keycode = (uint16_t)GPOINTER_TO_INT(g_datalist_get_data(&keysyms, str));
1.48 +
1.49 + if (keycode == 0) {
1.50 + //this key is not in the list yet, so make a new keycode for it
1.51 + g_datalist_set_data(&keysyms, str, GINT_TO_POINTER(++last_keycode));
1.52 + return last_keycode;
1.53 + } else {
1.54 + return keycode;
1.55 }
1.56 -
1.57 - if (i < MAX_KEYSYMS) {
1.58 - //this key is not in the list yet, so make a new keycode for it
1.59 - keysyms[i] = g_strdup(str);
1.60 - return i;
1.61 - } else {
1.62 - //if your remote has more than 256 buttons, you may need to increase MAX_KEYSYMS
1.63 - ERROR("LIRC has too many keysyms!");
1.64 - return 0;
1.65 - }
1.66 +
1.67 }
1.68
1.69 static gchar *input_lirc_keysym_for_keycode( input_driver_t dev, uint16_t keycode )
1.70 @@ -114,21 +113,30 @@
1.71 //This won't work if you send in keycodes that haven't been fired by the callback
1.72 //or looked up using resolve_keysym yet. This shouldn't be a problem, since these
1.73 //two functions are the only way to get a keycode in the first place.
1.74 -
1.75 - if (keycode < MAX_KEYSYMS)
1.76 - return g_strdup(keysyms[keycode]);
1.77 - else
1.78 +
1.79 + if (keycode <= last_keycode) {
1.80 + //reverse lookup
1.81 + keysym_by_keycode_result = 0;
1.82 + g_datalist_foreach(&keysyms, get_keysym_by_keycode, GINT_TO_POINTER(keycode));
1.83 + return g_strdup(g_quark_to_string(keysym_by_keycode_result));
1.84 + } else {
1.85 return NULL;
1.86 + }
1.87 +}
1.88 +
1.89 +static void get_keysym_by_keycode(GQuark key_id, gpointer data, gpointer user_data)
1.90 +{
1.91 + if (data == user_data)
1.92 + keysym_by_keycode_result = key_id;
1.93 }
1.94
1.95 static gboolean input_lirc_callback( GIOChannel *source, GIOCondition condition, gpointer data )
1.96 {
1.97 int ret;
1.98 char *code, *c;
1.99 - char keysym[256];
1.100 -
1.101 +
1.102 input_lirc_t lirc = (input_lirc_t)data;
1.103 -
1.104 +
1.105 if (condition & G_IO_IN)
1.106 {
1.107 //loop through all queued commands
1.108 @@ -137,13 +145,13 @@
1.109 INFO("LIRC code (%s)", code);
1.110 //code contains id, repeat count, and keysym separated by spaces
1.111 gchar **code_split = g_strsplit(code, " ", 4);
1.112 -
1.113 +
1.114 //eliminate repeats by only accepting the first instance of a keysym
1.115 if (atoi(code_split[1]) == 0)
1.116 {
1.117 input_event_keydown((input_driver_t)lirc, input_lirc_resolve_keysym((input_driver_t)lirc, code_split[2]), MAX_PRESSURE);
1.118 }
1.119 -
1.120 +
1.121 g_strfreev(code_split);
1.122 free(code);
1.123 }
.