int ev_init(void)
{
    DIR *dir;
    struct dirent *de;
    int fd;

    dir = opendir("/dev/input");
    if(dir != 0) {
        while((de = readdir(dir))) {
            if(strncmp(de->d_name,"event",5)) continue;
            fd = openat(dirfd(dir), de->d_name, O_RDONLY);
            if(fd < 0) continue;

            ev_fds[ev_count].fd = fd;
            ev_fds[ev_count].events = POLLIN;
            evs[ev_count].fd = &ev_fds[ev_count];

            /* Load virtualkeys if there are any */
            vk_init(&evs[ev_count]);

            ev_count++;
            if(ev_count == MAX_DEVICES) break;
        }
    }

    return 0;
}
int ev_init(void)
{
    DIR *dir;
    struct dirent *de;
    int fd;

    if (ev_count == 0) {
       memset(evs, 0, sizeof(struct ev) * MAX_DEVICES);
    } else {
       //do it only once
       return 0;
    }

	dir = opendir("/dev/input");
    if(dir != 0) {
        while((de = readdir(dir))) {
//            fprintf(stderr,"/dev/input/%s\n", de->d_name);
            if(strncmp(de->d_name,"event",5)) continue;
            fd = openat(dirfd(dir), de->d_name, O_RDONLY);
            if(fd < 0) continue;

			ev_fds[ev_count].fd = fd;
            ev_fds[ev_count].events = POLLIN;
            evs[ev_count].fd = &ev_fds[ev_count];

            /* Load virtualkeys if there are any */
			vk_init(&evs[ev_count]);

            ev_count++;
            if(ev_count == MAX_DEVICES) break;
        }
    }

    return 0;
}
Esempio n. 3
0
int ev_init(void)
{
    DIR *dir;
    struct dirent *de;
    int fd;

    has_mouse = 0;

    dir = opendir("/dev/input");
    if (dir) {
        while ((de = readdir(dir))) {
//            fprintf(stderr,"/dev/input/%s\n", de->d_name);
            if (strncmp(de->d_name, "event", 5)) {
                continue;
            }
            fd = openat(dirfd(dir), de->d_name, O_RDONLY);
            if (fd < 0) {
                continue;
            }

            ev_fds[ev_count].fd = fd;
            ev_fds[ev_count].events = POLLIN;
            evs[ev_count].fd = &ev_fds[ev_count];

            /* Load virtualkeys if there are any */
            vk_init(&evs[ev_count]);

            check_mouse(fd);

            ev_count++;
            if (ev_count == MAX_DEVICES) {
                break;
            }
        }
        closedir(dir);
    }

    struct stat st;
    if (stat("/dev/input", &st) >= 0) {
        lastInputMTime = st.st_mtime;
    }
    clock_gettime(CLOCK_MONOTONIC, &lastInputStat);

    return 0;
}