Lines Matching defs:vi

83 bool vc_input_process(vc_input_t* vi, uint8_t report[8]) {
90 hid_kbd_parse_report(report, &vi->state[vi->cur_idx]);
92 hid_kbd_pressed_keys(&vi->state[vi->prev_idx], &vi->state[vi->cur_idx], &keys);
94 vi->modifiers |= modifiers_from_keycode(keycode);
96 vi->modifiers ^= MOD_CAPSLOCK;
97 set_caps_lock_led(vi->fd, vi->modifiers & MOD_CAPSLOCK);
99 vi->handler(keycode, vi->modifiers);
103 hid_kbd_released_keys(&vi->state[vi->prev_idx], &vi->state[vi->cur_idx], &keys);
105 vi->modifiers &= ~modifiers_from_keycode(keycode);
110 vi->cur_idx = 1 - vi->cur_idx;
111 vi->prev_idx = 1 - vi->prev_idx;
117 static void vc_input_destroy(vc_input_t* vi) {
118 port_cancel(&port, &vi->th);
119 if (vi->fd >= 0) {
120 port_fd_handler_done(&vi->fh);
121 close(vi->fd);
123 zx_handle_close(vi->timer);
124 free(vi);
128 vc_input_t* vi = containerof(ph, vc_input_t, th);
131 if (vi->repeat_interval != ZX_TIME_INFINITE) {
132 vc_input_process(vi, vi->previous_report_buf);
133 vc_input_process(vi, vi->report_buf);
136 if ((vi->repeat_interval = vi->repeat_interval * 3 / 4) < HIGH_REPEAT_KEY_FREQ) {
137 vi->repeat_interval = HIGH_REPEAT_KEY_FREQ;
140 zx_timer_set(vi->timer, zx_deadline_after(vi->repeat_interval), 0);
148 vc_input_t* vi = containerof(fh, vc_input_t, fh);
154 memcpy(vi->previous_report_buf, vi->report_buf, sizeof(vi->report_buf));
155 r = read(vi->fd, vi->report_buf, sizeof(vi->report_buf));
158 vc_input_destroy(vi);
161 if ((size_t)(r) != sizeof(vi->report_buf)) {
162 vi->repeat_interval = ZX_TIME_INFINITE;
166 if (vc_input_process(vi, vi->report_buf) && vi->repeat_enabled) {
167 vi->repeat_interval = LOW_REPEAT_KEY_FREQ;
168 zx_timer_set(vi->timer, zx_deadline_after(vi->repeat_interval), 0);
170 vi->repeat_interval = ZX_TIME_INFINITE;
177 vc_input_t* vi = reinterpret_cast<vc_input_t*>(calloc(1, sizeof(vc_input_t)));
178 if (vi == NULL) {
182 vi->fd = fd;
183 vi->handler = handler;
185 vi->cur_idx = 0;
186 vi->prev_idx = 1;
187 vi->modifiers = 0;
188 vi->repeat_interval = ZX_TIME_INFINITE;
189 vi->repeat_enabled = true;
194 vi->repeat_enabled = false;
199 if ((r = zx_timer_create(0, ZX_CLOCK_MONOTONIC, &vi->timer)) < 0) {
200 free(vi);
204 vi->fh.func = vc_input_cb;
205 if ((r = port_fd_handler_init(&vi->fh, fd, POLLIN | POLLHUP | POLLRDHUP)) < 0) {
206 zx_handle_close(vi->timer);
207 free(vi);
211 if ((r = port_wait(&port, &vi->fh.ph)) < 0) {
212 port_fd_handler_done(&vi->fh);
213 zx_handle_close(vi->timer);
214 free(vi);
218 vi->th.handle = vi->timer;
219 vi->th.waitfor = ZX_TIMER_SIGNALED;
220 vi->th.func = vc_timer_cb;
221 port_wait_repeating(&port, &vi->th);
224 *out = vi;
240 vc_input_t* vi;
241 if ((r = vc_input_create(&vi, handler, fd)) < 0) {