aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2014-04-09 17:36:09 +0200
committerGerd Hoffmann <kraxel@redhat.com>2014-04-09 17:36:09 +0200
commit293adde407f0adfc9546fdbe3169f617f28771b7 (patch)
tree5722ddf12d0a52aa728dc70eec80eceab0da0a28
parent3481f7bc531a2010c7e83940b6ed1f1b5b6e8b6f (diff)
downloadinput-293adde407f0adfc9546fdbe3169f617f28771b7.tar.gz
lsinput overhaul
-rw-r--r--input-events.c3
-rw-r--r--input-kbd.c7
-rw-r--r--input-recv.c1
-rw-r--r--input-send.c1
-rw-r--r--input.c108
-rw-r--r--input.h4
-rw-r--r--lsinput.c52
-rwxr-xr-xname.sh9
8 files changed, 136 insertions, 49 deletions
diff --git a/input-events.c b/input-events.c
index c525757..38207c8 100644
--- a/input-events.c
+++ b/input-events.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@@ -21,7 +22,7 @@ static void show_events(int nr, int timeout, int grab)
fd = device_open(nr,1);
if (-1 == fd)
return;
- device_info(fd);
+ device_info(nr, fd, true);
if (grab) {
if (-1 == ioctl(fd,EVIOCGRAB,1)) {
diff --git a/input-kbd.c b/input-kbd.c
index 6825ea9..09d6022 100644
--- a/input-kbd.c
+++ b/input-kbd.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@@ -186,11 +187,11 @@ static void kbd_print_bits(int fd)
}
}
-static void show_kbd(int fd, unsigned int protocol_version)
+static void show_kbd(int nr, int fd, unsigned int protocol_version)
{
struct kbd_map *map;
- device_info(fd);
+ device_info(nr, fd, true);
map = kbd_map_read(fd, protocol_version);
if (map)
@@ -278,7 +279,7 @@ int main(int argc, char *argv[])
if (mapfile)
set_kbd(fd, protocol_version, mapfile);
else
- show_kbd(fd, protocol_version);
+ show_kbd(devnr, fd, protocol_version);
rc = EXIT_SUCCESS;
diff --git a/input-recv.c b/input-recv.c
index 4a59f3c..656e1ab 100644
--- a/input-recv.c
+++ b/input-recv.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
diff --git a/input-send.c b/input-send.c
index 1d0f14c..0796ff7 100644
--- a/input-send.c
+++ b/input-send.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
diff --git a/input.c b/input.c
index d2e3ab2..efa284b 100644
--- a/input.c
+++ b/input.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
@@ -80,7 +81,7 @@ char *BUS_NAME[] = {
/* ------------------------------------------------------------------ */
-int device_open(int nr, int verbose)
+int device_open(int nr, bool verbose)
{
char filename[32];
int fd;
@@ -99,41 +100,84 @@ int device_open(int nr, int verbose)
return fd;
}
-void device_info(int fd)
+int device_info(int nr, int fd, bool verbose)
{
struct input_id id;
- BITFIELD bits[32];
- char buf[32];
- int rc,bit;
+ char name[64];
+ char phys[64];
+ char buf[64];
+ BITFIELD evtmap[32];
+ BITFIELD bitmap[256];
+ int rc, pos, evts, evt, bits, bit, count;
rc = ioctl(fd,EVIOCGID,&id);
- if (rc >= 0)
- fprintf(stderr,
- " bustype : %s\n"
- " vendor : 0x%x\n"
- " product : 0x%x\n"
- " version : %d\n",
- BUS_NAME[id.bustype],
- id.vendor, id.product, id.version);
- rc = ioctl(fd,EVIOCGNAME(sizeof(buf)),buf);
- if (rc >= 0)
- fprintf(stderr," name : \"%.*s\"\n",rc,buf);
- rc = ioctl(fd,EVIOCGPHYS(sizeof(buf)),buf);
- if (rc >= 0)
- fprintf(stderr," phys : \"%.*s\"\n",rc,buf);
- rc = ioctl(fd,EVIOCGUNIQ(sizeof(buf)),buf);
- if (rc >= 0)
- fprintf(stderr," uniq : \"%.*s\"\n",rc,buf);
- rc = ioctl(fd,EVIOCGBIT(0,sizeof(bits)),bits);
- if (rc >= 0) {
- fprintf(stderr," bits ev :");
- for (bit = 0; bit < rc*8 && bit < EV_MAX; bit++) {
- if (test_bit(bit,bits))
- fprintf(stderr," %s", EV_NAME[bit]);
- }
- fprintf(stderr,"\n");
- }
- fprintf(stderr,"\n");
+ if (rc < 0)
+ return -1;
+
+ memset(name, 0, sizeof(name));
+ memset(phys, 0, sizeof(phys));
+ memset(evtmap, 0, sizeof(evtmap));
+
+ ioctl(fd, EVIOCGNAME(sizeof(name)-1), name);
+ ioctl(fd, EVIOCGPHYS(sizeof(phys)-1), phys);
+ evts = ioctl(fd, EVIOCGBIT(0,sizeof(evtmap)), evtmap);
+
+ if (!verbose) {
+ memset(buf, 0, sizeof(buf));
+ for (evt = 0, pos = 0;
+ evt < evts*8 && evt < EV_MAX;
+ evt++) {
+ if (evt == EV_SYN || evt == EV_REP)
+ continue;
+ if (!test_bit(evt,evtmap))
+ continue;
+ if (pos >= sizeof(buf))
+ continue;
+ pos += snprintf(buf+pos, sizeof(buf)-pos, "%s%s",
+ pos ? " " : "",
+ EV_NAME[evt]);
+ }
+ fprintf(stderr, "%2d: %04x:%04x %-6.6s %-16.16s %-24.24s %-16s\n", nr,
+ id.vendor, id.product, BUS_NAME[id.bustype],
+ phys, name, buf);
+ } else {
+ fprintf(stderr, " id : %04x:%04x, %s, v%d\n",
+ id.vendor, id.product, BUS_NAME[id.bustype], id.version);
+ fprintf(stderr, " phys : \"%s\"\n",phys);
+ fprintf(stderr, " name : \"%s\"\n",name);
+
+ for (evt = 0; evt < evts*8 && evt < EV_MAX; evt++) {
+ if (evt == EV_SYN || evt == EV_REP)
+ continue;
+ if (!test_bit(evt,evtmap))
+ continue;
+ bits = ioctl(fd, EVIOCGBIT(evt,sizeof(bitmap)), bitmap);
+ memset(buf, 0, sizeof(buf));
+ for (bit = 0, count = 0, pos = 0;
+ bit < bits*8 && bit < EV_TYPE_MAX[evt];
+ bit++) {
+ if (!test_bit(bit,bitmap))
+ continue;
+ count++;
+ if (pos >= sizeof(buf))
+ continue;
+ pos += snprintf(buf+pos, sizeof(buf)-pos, "%s%s",
+ pos ? " " : "",
+ EV_TYPE_NAME[evt][bit]);
+ }
+ if (pos >= sizeof(buf)) {
+ fprintf(stderr, " %-4.4s : [ %d codes ]\n",
+ EV_NAME[evt], count);
+ } else {
+ fprintf(stderr, " %-4.4s : %s\n",
+ EV_NAME[evt], buf);
+ }
+ }
+
+ fprintf(stderr,"\n");
+ }
+
+ return 0;
}
/* ------------------------------------------------------------------ */
diff --git a/input.h b/input.h
index 0576490..4fe6bac 100644
--- a/input.h
+++ b/input.h
@@ -24,6 +24,6 @@ static __inline__ int test_bit(int nr, BITFIELD * addr)
/* ------------------------------------------------------------------ */
-int device_open(int nr, int verbose);
-void device_info(int fd);
+int device_open(int nr, bool verbose);
+int device_info(int nr, int fd, bool verbose);
void print_event(struct input_event *event);
diff --git a/lsinput.c b/lsinput.c
index b500d03..efe95cb 100644
--- a/lsinput.c
+++ b/lsinput.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
@@ -8,29 +9,60 @@
/* ------------------------------------------------------------------ */
-static void list_devices(void)
+static void list_devices(int devnr, bool verbose)
{
int i,fd;
char filename[32];
struct stat statbuf;
for (i = 0; i < 32; i++) {
+ if (devnr > 0 && devnr != i)
+ continue;
snprintf(filename,sizeof(filename), "/dev/input/event%d",i);
- if (stat(filename, &statbuf) == 0) {
- /* try to open */
- fd = device_open(i,1);
- if (-1 == fd)
- return;
- device_info(fd);
- close(fd);
- }
+ if (stat(filename, &statbuf) != 0)
+ continue;
+ fd = device_open(i, verbose);
+ if (-1 == fd)
+ continue;
+ device_info(i, fd, verbose);
+ close(fd);
}
return;
}
+static int usage(char *prog, int error)
+{
+ fprintf(error ? stderr : stdout,
+ "usage: %s"
+ " [ -v ] [ -s <devnr> ]\n",
+ prog);
+ exit(error);
+}
+
int main(int argc, char *argv[])
{
- list_devices();
+ bool verbose = false;
+ int devnr = -1;
+ int c;
+
+ for (;;) {
+ if (-1 == (c = getopt(argc, argv, "hvs:")))
+ break;
+ switch (c) {
+ case 's':
+ devnr = atoi(optarg);
+ break;
+ case 'v':
+ verbose = true;
+ break;
+ case 'h':
+ usage(argv[0],0);
+ default:
+ usage(argv[0],1);
+ }
+ }
+
+ list_devices(devnr, verbose);
exit(0);
}
diff --git a/name.sh b/name.sh
index a8e709c..9da92fc 100755
--- a/name.sh
+++ b/name.sh
@@ -7,5 +7,12 @@ awk "
/KEY_MIN_INTERESTING/ {next};
/EV_VERSION/ { next };
/_MAX/ { next };
- /#define $1_/ { printf(\"\t[ %-16s ] = \\\"%s\\\",\n\", \$2, \$2); }
+ /_CNT/ { next };
+ /#define $1_/ {
+ name = \$2;
+ if (\"$TYPE\" != \"BTN\") {
+ sub(\"^${TYPE}_\", \"\", name);
+ }
+ printf(\"\t[ %-16s ] = \\\"%s\\\",\n\", \$2, name);
+ }
" < $INPUT