9 int uinputopen(
struct uinput_user_dev* indev,
int mouse){
10 int fd = open(
"/dev/uinput", O_RDWR);
13 fd = open(
"/dev/input/uinput", O_RDWR);
15 ckb_err(
"Failed to open uinput: %s\n", strerror(errno));
20 ioctl(fd, UI_SET_EVBIT, EV_KEY);
21 for(
int i = 0; i < KEY_CNT; i++)
22 ioctl(fd, UI_SET_KEYBIT, i);
25 ioctl(fd, UI_SET_EVBIT, EV_REL);
26 for(
int i = 0; i < REL_CNT; i++)
27 ioctl(fd, UI_SET_RELBIT, i);
30 ioctl(fd, UI_SET_EVBIT, EV_LED);
31 for(
int i = 0; i < LED_CNT; i++)
32 ioctl(fd, UI_SET_LEDBIT, i);
34 ioctl(fd, UI_SET_EVBIT, EV_REP);
37 ioctl(fd, UI_SET_EVBIT, EV_SYN);
39 if(write(fd, indev,
sizeof(*indev)) <= 0)
40 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
41 if(ioctl(fd, UI_DEV_CREATE)){
42 ckb_err(
"Failed to create uinput device: %s\n", strerror(errno));
58 struct uinput_user_dev indev;
59 memset(&indev, 0,
sizeof(indev));
60 snprintf(indev.name, UINPUT_MAX_NAME_SIZE,
"ckb%d: %s", index, kb->
name);
61 indev.id.bustype = BUS_USB;
62 indev.id.vendor = kb->
vendor;
80 struct input_event event;
81 memset(&event, 0,
sizeof(event));
85 if(write(kb->
uinput_kb - 1, &event,
sizeof(event)) <= 0)
86 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
87 if(write(kb->
uinput_mouse - 1, &event,
sizeof(event)) <= 0)
88 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
91 event.code = SYN_REPORT;
92 if(write(kb->
uinput_kb - 1, &event,
sizeof(event)) <= 0)
93 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
94 if(write(kb->
uinput_mouse - 1, &event,
sizeof(event)) <= 0)
95 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
108 struct input_event event;
109 memset(&event, 0,
sizeof(event));
111 event.code = SYN_REPORT;
112 if(write(kb->
uinput_kb - 1, &event,
sizeof(event)) <= 0)
113 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
114 if(write(kb->
uinput_mouse - 1, &event,
sizeof(event)) <= 0)
115 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
119 struct input_event event;
120 memset(&event, 0,
sizeof(event));
127 event.code = REL_WHEEL;
138 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
144 struct input_event event;
145 memset(&event, 0,
sizeof(event));
150 if(write(kb->
uinput_mouse - 1, &event,
sizeof(event)) <= 0)
151 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
158 if(write(kb->
uinput_mouse - 1, &event,
sizeof(event)) <= 0)
159 ckb_warn(
"uinput write failed: %s\n", strerror(errno));
169 struct input_event event;
170 while (read(kb->
uinput_kb - 1, &event,
sizeof(event)) > 0) {
171 if (event.type == EV_LED && event.code < 8){
172 char which = 1 <<
event.code;
179 pthread_mutex_lock(
dmutex(kb));
182 kb->
vtable->updateindicators(kb, 0);
184 pthread_mutex_unlock(
dmutex(kb));
194 int err = pthread_create(&thread, 0,
_ledthread, kb);
197 pthread_detach(thread);
#define ckb_err(fmt, args...)
usbdevice keyboard[9]
remember all usb devices. Needed for closeusb().
#define ckb_warn(fmt, args...)
#define INDEX_OF(entry, array)
const union devcmd * vtable