input: only include stuff when needed
[libpicofe.git] / common / input.c
index b6df2ba..eda86d4 100644 (file)
@@ -4,8 +4,17 @@
 
 #include "input.h"
 #include "plat.h"
+#include "lprintf.h"
+
+#ifdef IN_EVDEV
 #include "../linux/in_evdev.h"
+#endif
+#ifdef IN_GP2X
 #include "../gp2x/in_gp2x.h"
+#endif
+#ifdef IN_VK
+#include "../win32/in_vk.h"
+#endif
 
 typedef struct
 {
@@ -89,7 +98,7 @@ void in_register(const char *nname, int drv_id, int drv_fd_hnd, void *drv_data,
                for (i = 0; i < IN_MAX_DEVS; i++)
                        if (!in_devices[i].probed) break;
                if (i >= IN_MAX_DEVS) {
-                       printf("input: too many devices, can't add %s\n", name);
+                       lprintf("input: too many devices, can't add %s\n", name);
                        return;
                }
                in_free(&in_devices[i]);
@@ -111,7 +120,7 @@ void in_register(const char *nname, int drv_id, int drv_fd_hnd, void *drv_data,
        if (i + 1 > in_dev_count)
                in_dev_count = i + 1;
 
-       printf("input: new device #%d \"%s\"\n", i, name);
+       lprintf("input: new device #%d \"%s\"\n", i, name);
 update:
        in_devices[i].probed = 1;
        in_devices[i].does_combos = combos;
@@ -226,7 +235,7 @@ void in_probe(void)
        }
 
        if (in_have_async_devs)
-               printf("input: async-only devices detected..\n");
+               lprintf("input: async-only devices detected..\n");
 }
 
 /* async update */
@@ -237,6 +246,7 @@ int in_update(int *result)
        for (i = 0; i < in_dev_count; i++) {
                in_dev_t *dev = &in_devices[i];
                if (dev->probed && dev->binds != NULL) {
+                       // FIXME: this is stupid, make it indirect
                        switch (dev->drv_id) {
 #ifdef IN_EVDEV
                        case IN_DRVID_EVDEV:
@@ -247,6 +257,11 @@ int in_update(int *result)
                        case IN_DRVID_GP2X:
                                ret |= in_gp2x_update(dev->drv_data, dev->binds, result);
                                break;
+#endif
+#ifdef IN_VK
+                       case IN_DRVID_VK:
+                               ret |= in_vk_update(dev->drv_data, dev->binds, result);
+                               break;
 #endif
                        }
                }
@@ -337,7 +352,7 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
 
        if (count == 0) {
                /* don't deadlock, fail */
-               printf("input: failed to find devices to read\n");
+               lprintf("input: failed to find devices to read\n");
                exit(1);
        }
 
@@ -599,7 +614,7 @@ int in_config_parse_dev(const char *name)
        }
 
        if (drv_id < 0) {
-               printf("input: missing driver for %s\n", name);
+               lprintf("input: missing driver for %s\n", name);
                return -1;
        }
 
@@ -617,7 +632,7 @@ int in_config_parse_dev(const char *name)
                for (i = 0; i < IN_MAX_DEVS; i++)
                        if (in_devices[i].name == NULL) break;
                if (i >= IN_MAX_DEVS) {
-                       printf("input: too many devices, can't add %s\n", name);
+                       lprintf("input: too many devices, can't add %s\n", name);
                        return -1;
                }
        }
@@ -696,7 +711,7 @@ int in_config_bind_key(int dev_id, const char *key, int acts, int bind_type)
        }
 
        if (kc < 0 || kc >= dev->key_count) {
-               printf("input: bad key: %s\n", key);
+               lprintf("input: bad key: %s\n", key);
                return -1;
        }
 
@@ -718,7 +733,7 @@ void in_config_end(void)
        int i;
 
        for (i = 0; i < IN_MAX_DEVS; i++) {
-               int n, ret, count, *binds, *def_binds;
+               int n, t, ret, count, *binds, *def_binds;
                in_dev_t *dev = &in_devices[i];
 
                if (dev->binds == NULL)
@@ -728,9 +743,18 @@ void in_config_end(void)
                binds = dev->binds;
                def_binds = binds + count * IN_BINDTYPE_COUNT;
 
-               for (n = 0; n < count * IN_BINDTYPE_COUNT; n++)
-                       if (binds[n] == -1)
-                               binds[n] = def_binds[n];
+               for (n = 0; n < count; n++) {
+                       int is_default = 1;
+                       for (t = 0; t < IN_BINDTYPE_COUNT; t++)
+                               if (binds[IN_BIND_OFFS(n, t)] == -1)
+                                       binds[IN_BIND_OFFS(n, t)] = 0;
+                               else
+                                       is_default = 0;
+
+                       if (is_default)
+                               for (t = 0; t < IN_BINDTYPE_COUNT; t++)
+                                       binds[IN_BIND_OFFS(n, t)] = def_binds[IN_BIND_OFFS(n, t)];
+               }
 
                if (dev->drv_data == NULL)
                        continue;
@@ -748,12 +772,12 @@ void in_debug_dump(void)
 {
        int i;
 
-       printf("# drv probed binds name\n");
+       lprintf("# drv probed binds name\n");
        for (i = 0; i < IN_MAX_DEVS; i++) {
                in_dev_t *d = &in_devices[i];
                if (!d->probed && d->name == NULL && d->binds == NULL)
                        continue;
-               printf("%d %3d %6c %5c %s\n", i, d->drv_id, d->probed ? 'y' : 'n',
+               lprintf("%d %3d %6c %5c %s\n", i, d->drv_id, d->probed ? 'y' : 'n',
                        d->binds ? 'y' : 'n', d->name);
        }
 }
@@ -799,6 +823,9 @@ void in_init(void)
 #ifdef IN_EVDEV
        in_evdev_init(&in_drivers[IN_DRVID_EVDEV]);
 #endif
+#ifdef IN_VK
+       in_vk_init(&in_drivers[IN_DRVID_VK]);
+#endif
 }
 
 #if 0
@@ -815,12 +842,12 @@ int main(void)
        while (1) {
                int dev = 0, down;
                ret = in_update_keycode(&dev, &down);
-               printf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret));
+               lprintf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret));
        }
 #else
        while (1) {
                ret = in_menu_wait_any();
-               printf("%08x\n", ret);
+               lprintf("%08x\n", ret);
        }
 #endif