diff options
author | Dima Zavin <dima@android.com> | 2011-10-12 15:53:29 -0700 |
---|---|---|
committer | Dima Zavin <dima@android.com> | 2011-10-12 15:53:32 -0700 |
commit | 441031dadc4f5e8c1487468229781702bc08fb14 (patch) | |
tree | adf5c20706637eaa5fe978a00d3cde71023f4b02 /minui/events.c | |
parent | f6abd409bb2b80dfa0c1c03c26bc83141f52c673 (diff) | |
download | bootable_recovery-441031dadc4f5e8c1487468229781702bc08fb14.zip bootable_recovery-441031dadc4f5e8c1487468229781702bc08fb14.tar.gz bootable_recovery-441031dadc4f5e8c1487468229781702bc08fb14.tar.bz2 |
minui: add ability to synchronize current key state
If a key is down prior to the time of initialization, we would not get the
down event for the key, and thus think that the key is not pressed.
Add an interface that allows one to provide a callback to execute
on all keys that are currently down.
Change-Id: I2a4096c0cb4c7c7a9a80d207835f168a0b418413
Signed-off-by: Dima Zavin <dima@android.com>
Diffstat (limited to 'minui/events.c')
-rw-r--r-- | minui/events.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/minui/events.c b/minui/events.c index c533a48..2918afa 100644 --- a/minui/events.c +++ b/minui/events.c @@ -27,7 +27,11 @@ #define MAX_DEVICES 16 #define MAX_MISC_FDS 16 -#define test_bit(bit, array) ((array)[(bit)/8] & (1<<((bit)%8))) +#define BITS_PER_LONG (sizeof(unsigned long) * 8) +#define BITS_TO_LONGS(x) (((x) + BITS_PER_LONG - 1) / BITS_PER_LONG) + +#define test_bit(bit, array) \ + ((array)[(bit)/BITS_PER_LONG] & (1 << ((bit) % BITS_PER_LONG))) struct fd_info { ev_callback cb; @@ -50,7 +54,7 @@ int ev_init(ev_callback input_cb, void *data) dir = opendir("/dev/input"); if(dir != 0) { while((de = readdir(dir))) { - uint8_t ev_bits[(EV_MAX + 1) / 8]; + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; // fprintf(stderr,"/dev/input/%s\n", de->d_name); if(strncmp(de->d_name,"event",5)) continue; @@ -139,3 +143,33 @@ int ev_get_input(int fd, short revents, struct input_event *ev) } return -1; } + +int ev_sync_key_state(ev_set_key_callback set_key_cb, void *data) +{ + unsigned long key_bits[BITS_TO_LONGS(KEY_MAX)]; + unsigned long ev_bits[BITS_TO_LONGS(EV_MAX)]; + unsigned i; + int ret; + + for (i = 0; i < ev_dev_count; i++) { + int code; + + memset(key_bits, 0, sizeof(key_bits)); + memset(ev_bits, 0, sizeof(ev_bits)); + + ret = ioctl(ev_fds[i].fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits); + if (ret < 0 || !test_bit(EV_KEY, ev_bits)) + continue; + + ret = ioctl(ev_fds[i].fd, EVIOCGKEY(sizeof(key_bits)), key_bits); + if (ret < 0) + continue; + + for (code = 0; code <= KEY_MAX; code++) { + if (test_bit(code, key_bits)) + set_key_cb(code, 1, data); + } + } + + return 0; +} |