license some code GPL compatible to use in PCSX
[libpicofe.git] / common / input.c
index 182e9fb..7bbb39c 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * (C) GraÅžvydas "notaz" Ignotas, 2008-2010
+ *
+ * This work is licensed under the terms of any of these licenses
+ * (at your option):
+ *  - GNU GPL, version 2 or later.
+ *  - GNU LGPL, version 2.1 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -355,9 +365,6 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
 
                drv = &DRV(in_devices[dev_id].drv_id);
                result = drv->update_keycode(in_devices[dev_id].drv_data, &is_down);
-
-               /* update_keycode() might return -1 when some not interesting
-                * event happened, like sync event for evdev. */
                if (result >= 0)
                        break;
 
@@ -370,7 +377,7 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
                }
        }
 
-       if (result == -1)
+       if (result < 0)
                return -1;
 finish:
        /* keep track of menu key state, to allow mixing
@@ -611,6 +618,28 @@ const char *in_get_key_name(int dev_id, int keycode)
        return xname;
 }
 
+int in_get_key_code(int dev_id, const char *key_name)
+{
+       in_dev_t *dev;
+       int i;
+
+       if (dev_id < 0)         /* want last used dev? */
+               dev_id = menu_last_used_dev;
+
+       if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
+               return -1;
+
+       dev = &in_devices[dev_id];
+       if (dev->key_names == NULL)
+               return -1;
+
+       for (i = 0; i < dev->key_count; i++)
+               if (dev->key_names[i] && strcasecmp(dev->key_names[i], key_name) == 0)
+                       return i;
+
+       return -1;
+}
+
 int in_bind_key(int dev_id, int keycode, int mask, int bind_type, int force_unbind)
 {
        int ret, count;