DIR *dir;
if ((dir = opendir(dirname))) {
struct dirent *de;
+ unsigned long caps[NBITS(SW_TABLET_MODE+1)];
while ((de = readdir(dir))) {
if (de->d_name[0] != 'e') // eventX
continue;
LOGE("could not open %s, %s", name, strerror(errno));
continue;
}
- name[sizeof(name) - 1] = '\0';
- if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
- LOGE("could not get device name for %s, %s\n", name, strerror(errno));
- name[0] = '\0';
+ memset(caps, 0, sizeof(caps));
+ if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(caps)), caps) < 1) {
+ LOGE("could not get device caps for %s, %s\n", name, strerror(errno));
+ continue;
}
- if (!strcmp(name, "ThinkPad Extra Buttons")) {
+ if (test_bit(SW_TABLET_MODE, caps)) {
LOGI("open %s(%s) ok", de->d_name, name);
return fd;
}
memset(&nev, 0, sizeof(struct input_event));
nev.type = EV_SW;
nev.code = SW_LID;
- nev.value = state;
+ nev.value = !!state;
write(ufd, &nev, sizeof(struct input_event));
nev.type = EV_SYN;
nev.code = SYN_REPORT;
{
int ifd = openfd();
if (ifd < 0) {
- LOGE("could not find ThinkPad Extra Buttons, exiting.");
+ LOGE("could not find any tablet mode switch, exiting.");
return -1;
}
- sleep(15); //wait some time or otherwise EventHub might not pick up our event!?
+ sleep(15); //wait some time or otherwise EventHub might not pick up our events correctly!?
int ufd = open("/dev/uinput", O_WRONLY | O_NDELAY);
if (ufd >= 0) {
}
// send initial switch state
- unsigned long sw_state[NBITS(SW_MAX+1)];
+ unsigned long sw_state[NBITS(SW_TABLET_MODE+1)];
memset(sw_state, 0, sizeof(sw_state));
if (ioctl(ifd, EVIOCGSW(sizeof(sw_state)), sw_state) >= 0) {
send_switch(ufd, test_bit(SW_TABLET_MODE, sw_state) ? 0 : 1);
LOGW("insufficient input data(%d)? fd=%d", res, ifd);
continue;
}
-// LOGV("type=%d scancode=%d value=%d from fd=%d", iev.type, iev.code, iev.value, fd);
+// LOGV("type=%d scancode=%d value=%d from fd=%d", iev.type, iev.code, iev.value, ifd);
if (iev.type == EV_SW && iev.code == SW_TABLET_MODE) {
send_switch(ufd, !iev.value);
}