Changes in / [ed267bc:166a1f57] in mainline
- Location:
- uspace
- Files:
-
- 1 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
red267bc r166a1f57 117 117 static void waitkey() 118 118 { 119 cons_event_t ev; 120 kbd_event_t *kev; 119 kbd_event_t ev; 121 120 122 121 while (true) { 123 if (!console_get_ event(console, &ev)) {122 if (!console_get_kbd_event(console, &ev)) { 124 123 return; 125 124 } 126 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 127 kev = &ev.ev.key; 128 129 if (kev->key == KC_ESCAPE || kev->key == KC_Q) { 125 if (ev.type == KEY_PRESS) { 126 if (ev.key == KC_ESCAPE || ev.key == KC_Q) { 130 127 should_quit = true; 131 128 return; 132 129 } 133 if ( kev->key == KC_C) {130 if (ev.key == KC_C) { 134 131 paging_enabled = false; 135 132 return; 136 133 } 137 if ( kev->key == KC_ENTER || kev->key == KC_SPACE ||138 kev->key == KC_PAGE_DOWN) {134 if (ev.key == KC_ENTER || ev.key == KC_SPACE || 135 ev.key == KC_PAGE_DOWN) { 139 136 return; 140 137 } -
uspace/app/bdsh/cmds/modules/cp/cp.c
red267bc r166a1f57 152 152 153 153 while (true) { 154 cons_event_t ev;154 kbd_event_t ev; 155 155 console_flush(con); 156 console_get_ event(con, &ev);157 if ( ev.type != CEV_KEY || ev.ev.key.type != KEY_PRESS ||158 (ev.ev.key.mods & (KM_CTRL | KM_ALT)) != 0) {156 console_get_kbd_event(con, &ev); 157 if ((ev.type != KEY_PRESS) 158 || (ev.mods & (KM_CTRL | KM_ALT)) != 0) { 159 159 continue; 160 160 } 161 161 162 switch(ev. ev.key.key) {162 switch(ev.key) { 163 163 case KC_Y: 164 164 printf("y\n"); -
uspace/app/edit/edit.c
red267bc r166a1f57 80 80 tag_t sel_start; 81 81 82 /** Active keyboard modifiers */83 keymod_t keymod;84 85 82 /** 86 83 * Ideal column where the caret should try to get. This is used … … 122 119 static void cursor_setvis(bool visible); 123 120 124 static void key_handle_press(kbd_event_t *ev);125 121 static void key_handle_unmod(kbd_event_t const *ev); 126 122 static void key_handle_ctrl(kbd_event_t const *ev); … … 128 124 static void key_handle_shift_ctrl(kbd_event_t const *ev); 129 125 static void key_handle_movement(unsigned int key, bool shift); 130 131 static void pos_handle(pos_event_t *ev);132 126 133 127 static int file_save(char const *fname); … … 188 182 int main(int argc, char *argv[]) 189 183 { 190 cons_event_t ev;184 kbd_event_t ev; 191 185 bool new_file; 192 186 int rc; … … 251 245 252 246 while (!done) { 253 console_get_ event(con, &ev);247 console_get_kbd_event(con, &ev); 254 248 pane.rflags = 0; 255 249 256 switch (ev.type) { 257 case CEV_KEY: 258 pane.keymod = ev.ev.key.mods; 259 if (ev.ev.key.type == KEY_PRESS) 260 key_handle_press(&ev.ev.key); 261 break; 262 case CEV_POS: 263 pos_handle(&ev.ev.pos); 264 break; 250 if (ev.type == KEY_PRESS) { 251 /* Handle key press. */ 252 if (((ev.mods & KM_ALT) == 0) && 253 ((ev.mods & KM_SHIFT) == 0) && 254 (ev.mods & KM_CTRL) != 0) { 255 key_handle_ctrl(&ev); 256 } else if (((ev.mods & KM_ALT) == 0) && 257 ((ev.mods & KM_CTRL) == 0) && 258 (ev.mods & KM_SHIFT) != 0) { 259 key_handle_shift(&ev); 260 } else if (((ev.mods & KM_ALT) == 0) && 261 ((ev.mods & KM_CTRL) != 0) && 262 (ev.mods & KM_SHIFT) != 0) { 263 key_handle_shift_ctrl(&ev); 264 } else if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { 265 key_handle_unmod(&ev); 266 } 265 267 } 266 268 … … 284 286 285 287 return 0; 286 }287 288 /* Handle key press. */289 static void key_handle_press(kbd_event_t *ev)290 {291 if (((ev->mods & KM_ALT) == 0) &&292 ((ev->mods & KM_SHIFT) == 0) &&293 (ev->mods & KM_CTRL) != 0) {294 key_handle_ctrl(ev);295 } else if (((ev->mods & KM_ALT) == 0) &&296 ((ev->mods & KM_CTRL) == 0) &&297 (ev->mods & KM_SHIFT) != 0) {298 key_handle_shift(ev);299 } else if (((ev->mods & KM_ALT) == 0) &&300 ((ev->mods & KM_CTRL) != 0) &&301 (ev->mods & KM_SHIFT) != 0) {302 key_handle_shift_ctrl(ev);303 } else if ((ev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {304 key_handle_unmod(ev);305 }306 288 } 307 289 … … 480 462 } 481 463 482 static void pos_handle(pos_event_t *ev)483 {484 coord_t bc;485 spt_t pt;486 bool select;487 488 if (ev->type == POS_PRESS && ev->vpos < (unsigned)pane.rows) {489 bc.row = pane.sh_row + ev->vpos;490 bc.column = pane.sh_column + ev->hpos;491 sheet_get_cell_pt(doc.sh, &bc, dir_before, &pt);492 493 select = (pane.keymod & KM_SHIFT) != 0;494 495 caret_move(pt, select, true);496 }497 }498 499 464 /** Move caret while preserving or resetting selection. */ 500 465 static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column) … … 627 592 static char *prompt(char const *prompt, char const *init_value) 628 593 { 629 cons_event_t ev; 630 kbd_event_t *kev; 594 kbd_event_t ev; 631 595 char *str; 632 596 wchar_t buffer[INFNAME_MAX_LEN + 1]; … … 648 612 649 613 while (!done) { 650 console_get_event(con, &ev); 651 652 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) { 653 kev = &ev.ev.key; 654 614 console_get_kbd_event(con, &ev); 615 616 if (ev.type == KEY_PRESS) { 655 617 /* Handle key press. */ 656 if ((( kev->mods & KM_ALT) == 0) &&657 ( kev->mods & KM_CTRL) != 0) {618 if (((ev.mods & KM_ALT) == 0) && 619 (ev.mods & KM_CTRL) != 0) { 658 620 ; 659 } else if (( kev->mods & (KM_CTRL | KM_ALT)) == 0) {660 switch ( kev->key) {621 } else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) { 622 switch (ev.key) { 661 623 case KC_ESCAPE: 662 624 return NULL; … … 672 634 break; 673 635 default: 674 if ( kev->c >= 32 && nc < max_len) {675 putchar( kev->c);636 if (ev.c >= 32 && nc < max_len) { 637 putchar(ev.c); 676 638 console_flush(con); 677 buffer[nc++] = kev->c;639 buffer[nc++] = ev.c; 678 640 } 679 641 break; -
uspace/app/mkbd/main.c
red267bc r166a1f57 178 178 179 179 while (1) { 180 cons_event_t ev;181 bool ok = console_get_ event(con, &ev);180 kbd_event_t ev; 181 bool ok = console_get_kbd_event(con, &ev); 182 182 if (!ok) { 183 183 printf("Connection with console broken: %s.\n", … … 186 186 } 187 187 188 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS && 189 ev.ev.key.key == KC_ESCAPE) { 188 if (ev.key == KC_ESCAPE) { 190 189 break; 191 190 } -
uspace/app/msim/arch_helenos/input.c
red267bc r166a1f57 91 91 bool stdin_poll(char *key) 92 92 { 93 cons_event_t ev;93 kbd_event_t ev; 94 94 suseconds_t timeout = 0; 95 95 errno = EOK; 96 96 console_flush(input_prompt->console); 97 bool has_input = console_get_ event_timeout(input_prompt->console, &ev, &timeout);97 bool has_input = console_get_kbd_event_timeout(input_prompt->console, &ev, &timeout); 98 98 if (!has_input) { 99 99 return false; 100 100 } 101 101 102 if (ev.type != CEV_KEY || ev.ev.key.type !=KEY_PRESS)102 if (ev.type != KEY_PRESS) 103 103 return false; 104 104 105 *key = ev. ev.key.c;105 *key = ev.c; 106 106 107 107 return true; -
uspace/app/nterm/nterm.c
red267bc r166a1f57 109 109 int main(int argc, char *argv[]) 110 110 { 111 cons_event_t ev;111 kbd_event_t ev; 112 112 int rc; 113 113 … … 129 129 done = false; 130 130 while (!done) { 131 console_get_ event(con, &ev);132 if (ev.type == CEV_KEY && ev.ev.key.type ==KEY_PRESS)133 key_handle(&ev .ev.key);131 console_get_kbd_event(con, &ev); 132 if (ev.type == KEY_PRESS) 133 key_handle(&ev); 134 134 } 135 135 -
uspace/app/ping/ping.c
red267bc r166a1f57 188 188 { 189 189 console_ctrl_t *con; 190 cons_event_t ev;190 kbd_event_t ev; 191 191 192 192 con = console_init(stdin, stdout); … … 194 194 195 195 while (true) { 196 if (!console_get_ event(con, &ev))196 if (!console_get_kbd_event(con, &ev)) 197 197 break; 198 198 199 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS && 200 (ev.ev.key.mods & (KM_ALT | KM_SHIFT)) == 201 0 && (ev.ev.key.mods & KM_CTRL) != 0) { 199 if (ev.type == KEY_PRESS && (ev.mods & (KM_ALT | KM_SHIFT)) == 200 0 && (ev.mods & KM_CTRL) != 0) { 202 201 /* Ctrl+key */ 203 if (ev. ev.key.key == KC_Q) {202 if (ev.key == KC_Q) { 204 203 ping_signal_done(); 205 204 return 0; -
uspace/app/tester/ipc/starve.c
red267bc r166a1f57 62 62 break; 63 63 64 cons_event_t ev;64 kbd_event_t ev; 65 65 suseconds_t timeout = 0; 66 bool has_event = console_get_ event_timeout(console, &ev, &timeout);67 if (has_event && ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) {68 TPRINTF("Key %d pressed, terminating.\n", ev. ev.key.key);66 bool has_event = console_get_kbd_event_timeout(console, &ev, &timeout); 67 if (has_event && (ev.type == KEY_PRESS)) { 68 TPRINTF("Key %d pressed, terminating.\n", ev.key); 69 69 break; 70 70 } -
uspace/app/tetris/scores.c
red267bc r166a1f57 125 125 int j; 126 126 size_t off; 127 cons_event_t ev; 128 kbd_event_t *kev; 127 kbd_event_t ev; 129 128 130 129 clear_screen(); … … 142 141 while (1) { 143 142 console_flush(console); 144 if (!console_get_ event(console, &ev))143 if (!console_get_kbd_event(console, &ev)) 145 144 exit(1); 146 145 147 if (ev.type != CEV_KEY || ev.ev.key.type== KEY_RELEASE)146 if (ev.type == KEY_RELEASE) 148 147 continue; 149 148 150 kev = &ev.ev.key; 151 152 if (kev->key == KC_ENTER || kev->key == KC_NENTER) 149 if (ev.key == KC_ENTER || ev.key == KC_NENTER) 153 150 break; 154 151 155 if ( kev->key == KC_BACKSPACE) {152 if (ev.key == KC_BACKSPACE) { 156 153 if (i > 0) { 157 154 wchar_t uc; … … 169 166 scores[NUMSPOTS - 1].hs_name[off] = '\0'; 170 167 } 171 } else if ( kev->c != '\0') {168 } else if (ev.c != '\0') { 172 169 if (i < (MAXLOGNAME - 1)) { 173 if (chr_encode( kev->c, scores[NUMSPOTS - 1].hs_name,170 if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, 174 171 &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { 175 172 ++i; -
uspace/app/tetris/screen.c
red267bc r166a1f57 344 344 345 345 while (timeout > 0) { 346 cons_event_t event;347 348 if (!console_get_ event_timeout(console, &event, &timeout))346 kbd_event_t event; 347 348 if (!console_get_kbd_event_timeout(console, &event, &timeout)) 349 349 break; 350 350 } … … 376 376 377 377 while (c == 0) { 378 cons_event_t event;379 380 if (!console_get_ event_timeout(console, &event, &timeleft)) {378 kbd_event_t event; 379 380 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) { 381 381 timeleft = 0; 382 382 return -1; 383 383 } 384 384 385 if (event.type == CEV_KEY && event.ev.key.type ==KEY_PRESS)386 c = event. ev.key.c;385 if (event.type == KEY_PRESS) 386 c = event.c; 387 387 } 388 388 … … 398 398 399 399 while (c == 0) { 400 cons_event_t event;401 402 if (!console_get_ event(console, &event))400 kbd_event_t event; 401 402 if (!console_get_kbd_event(console, &event)) 403 403 return -1; 404 404 405 if (event.type == CEV_KEY && event.ev.key.type ==KEY_PRESS)406 c = event. ev.key.c;405 if (event.type == KEY_PRESS) 406 c = event.c; 407 407 } 408 408 -
uspace/app/top/screen.c
red267bc r166a1f57 556 556 557 557 while (c == 0) { 558 cons_event_t event;558 kbd_event_t event; 559 559 560 560 warning_timeleft -= timeleft; 561 if (!console_get_ event_timeout(console, &event, &timeleft)) {561 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) { 562 562 timeleft = 0; 563 563 return -1; … … 565 565 warning_timeleft += timeleft; 566 566 567 if (event.type == CEV_KEY && event.ev.key.type ==KEY_PRESS)568 c = event. ev.key.c;567 if (event.type == KEY_PRESS) 568 c = event.c; 569 569 } 570 570 -
uspace/app/trace/trace.c
red267bc r166a1f57 565 565 static int cev_fibril(void *arg) 566 566 { 567 cons_event_t event;568 569 567 (void) arg; 570 568 … … 577 575 fibril_mutex_unlock(&state_lock); 578 576 579 if (!console_get_ event(console, &event))577 if (!console_get_kbd_event(console, &cev)) 580 578 return -1; 581 579 582 if (event.type == CEV_KEY) { 583 fibril_mutex_lock(&state_lock); 584 cev = event.ev.key; 585 cev_valid = true; 586 fibril_condvar_broadcast(&state_cv); 587 fibril_mutex_unlock(&state_lock); 588 } 580 fibril_mutex_lock(&state_lock); 581 cev_valid = true; 582 fibril_condvar_broadcast(&state_cv); 583 fibril_mutex_unlock(&state_lock); 589 584 } 590 585 } -
uspace/dist/src/c/demos/tetris/scores.c
red267bc r166a1f57 125 125 int j; 126 126 size_t off; 127 cons_event_t ev; 128 kbd_event_t *kev; 127 kbd_event_t ev; 129 128 130 129 clear_screen(); … … 142 141 while (1) { 143 142 console_flush(console); 144 if (!console_get_ event(console, &ev))143 if (!console_get_kbd_event(console, &ev)) 145 144 exit(1); 146 145 147 if (ev.type != CEV_KEY || ev.ev.key.type== KEY_RELEASE)146 if (ev.type == KEY_RELEASE) 148 147 continue; 149 148 150 kev = &ev.ev.key; 151 152 if (kev->key == KC_ENTER || kev->key == KC_NENTER) 149 if (ev.key == KC_ENTER || ev.key == KC_NENTER) 153 150 break; 154 151 155 if ( kev->key == KC_BACKSPACE) {152 if (ev.key == KC_BACKSPACE) { 156 153 if (i > 0) { 157 154 wchar_t uc; … … 169 166 scores[NUMSPOTS - 1].hs_name[off] = '\0'; 170 167 } 171 } else if ( kev->c != '\0') {168 } else if (ev.c != '\0') { 172 169 if (i < (MAXLOGNAME - 1)) { 173 if (chr_encode( kev->c, scores[NUMSPOTS - 1].hs_name,170 if (chr_encode(ev.c, scores[NUMSPOTS - 1].hs_name, 174 171 &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { 175 172 ++i; -
uspace/dist/src/c/demos/top/screen.c
red267bc r166a1f57 553 553 554 554 while (c == 0) { 555 cons_event_t event;556 557 if (!console_get_ event_timeout(console, &event, &timeleft)) {555 kbd_event_t event; 556 557 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) { 558 558 timeleft = 0; 559 559 return -1; 560 560 } 561 561 562 if (event.type == CEV_KEY && event.ev.key.type ==KEY_PRESS)563 c = event. ev.key.c;562 if (event.type == KEY_PRESS) 563 c = event.c; 564 564 } 565 565 -
uspace/lib/c/generic/io/con_srv.c
red267bc r166a1f57 35 35 */ 36 36 #include <errno.h> 37 #include <io/cons_event.h>38 37 #include <ipc/console.h> 39 38 #include <stdlib.h> … … 41 40 42 41 #include <io/con_srv.h> 43 44 static int console_ev_encode(cons_event_t *event, ipc_call_t *call)45 {46 IPC_SET_ARG1(*call, event->type);47 48 switch (event->type) {49 case CEV_KEY:50 IPC_SET_ARG2(*call, event->ev.key.type);51 IPC_SET_ARG3(*call, event->ev.key.key);52 IPC_SET_ARG4(*call, event->ev.key.mods);53 IPC_SET_ARG5(*call, event->ev.key.c);54 break;55 case CEV_POS:56 IPC_SET_ARG2(*call, (event->ev.pos.pos_id << 16) | (event->ev.pos.type & 0xffff));57 IPC_SET_ARG3(*call, event->ev.pos.btn_num);58 IPC_SET_ARG4(*call, event->ev.pos.hpos);59 IPC_SET_ARG5(*call, event->ev.pos.vpos);60 break;61 default:62 return EIO;63 }64 65 return EOK;66 }67 42 68 43 static void con_read_srv(con_srv_t *srv, ipc_callid_t callid, … … 298 273 { 299 274 int rc; 300 cons_event_t event; 301 ipc_call_t result; 275 kbd_event_t event; 302 276 303 277 if (srv->srvs->ops->get_event == NULL) { … … 307 281 308 282 rc = srv->srvs->ops->get_event(srv, &event); 309 if (rc != EOK) { 310 async_answer_0(callid, rc); 311 return; 312 } 313 314 rc = console_ev_encode(&event, &result); 315 if (rc != EOK) { 316 async_answer_0(callid, rc); 317 return; 318 } 319 320 async_answer_5(callid, rc, IPC_GET_ARG1(result), IPC_GET_ARG2(result), 321 IPC_GET_ARG3(result), IPC_GET_ARG4(result), IPC_GET_ARG5(result)); 283 async_answer_4(callid, rc, event.type, event.key, event.mods, event.c); 322 284 } 323 285 -
uspace/lib/c/generic/io/console.c
red267bc r166a1f57 154 154 } 155 155 156 static int console_ev_decode(ipc_call_t *call, cons_event_t *event) 157 { 158 event->type = IPC_GET_ARG1(*call); 159 160 switch (event->type) { 161 case CEV_KEY: 162 event->ev.key.type = IPC_GET_ARG2(*call); 163 event->ev.key.key = IPC_GET_ARG3(*call); 164 event->ev.key.mods = IPC_GET_ARG4(*call); 165 event->ev.key.c = IPC_GET_ARG5(*call); 166 break; 167 case CEV_POS: 168 event->ev.pos.pos_id = IPC_GET_ARG2(*call) >> 16; 169 event->ev.pos.type = IPC_GET_ARG2(*call) & 0xffff; 170 event->ev.pos.btn_num = IPC_GET_ARG3(*call); 171 event->ev.pos.hpos = IPC_GET_ARG4(*call); 172 event->ev.pos.vpos = IPC_GET_ARG5(*call); 173 break; 174 default: 175 return EIO; 176 } 177 178 return EOK; 179 } 180 181 bool console_get_event(console_ctrl_t *ctrl, cons_event_t *event) 156 bool console_get_kbd_event(console_ctrl_t *ctrl, kbd_event_t *event) 182 157 { 183 158 if (ctrl->input_aid == 0) { 184 ipc_call_t result; 159 sysarg_t type; 160 sysarg_t key; 161 sysarg_t mods; 162 sysarg_t c; 185 163 186 164 async_exch_t *exch = async_exchange_begin(ctrl->input_sess); 187 aid_t aid = async_send_0(exch, CONSOLE_GET_EVENT, &result);165 int rc = async_req_0_4(exch, CONSOLE_GET_EVENT, &type, &key, &mods, &c); 188 166 async_exchange_end(exch); 189 190 sysarg_t rc;191 async_wait_for(aid, &rc);192 167 193 168 if (rc != EOK) { … … 196 171 } 197 172 198 rc = console_ev_decode(&result, event); 199 if (rc != EOK) { 200 errno = rc; 201 return false; 202 } 173 event->type = type; 174 event->key = key; 175 event->mods = mods; 176 event->c = c; 203 177 } else { 204 178 sysarg_t retval; … … 212 186 } 213 187 214 int rc = console_ev_decode(&ctrl->input_call, event); 215 if (rc != EOK) { 216 errno = rc; 217 return false; 218 } 188 event->type = IPC_GET_ARG1(ctrl->input_call); 189 event->key = IPC_GET_ARG2(ctrl->input_call); 190 event->mods = IPC_GET_ARG3(ctrl->input_call); 191 event->c = IPC_GET_ARG4(ctrl->input_call); 219 192 } 220 193 … … 222 195 } 223 196 224 bool console_get_ event_timeout(console_ctrl_t *ctrl, cons_event_t *event,197 bool console_get_kbd_event_timeout(console_ctrl_t *ctrl, kbd_event_t *event, 225 198 suseconds_t *timeout) 226 199 { … … 250 223 } 251 224 252 rc = console_ev_decode(&ctrl->input_call, event); 253 if (rc != EOK) { 254 errno = rc; 255 return false; 256 } 225 event->type = IPC_GET_ARG1(ctrl->input_call); 226 event->key = IPC_GET_ARG2(ctrl->input_call); 227 event->mods = IPC_GET_ARG3(ctrl->input_call); 228 event->c = IPC_GET_ARG4(ctrl->input_call); 257 229 258 230 /* Update timeout */ -
uspace/lib/c/include/io/con_srv.h
red267bc r166a1f57 41 41 #include <io/color.h> 42 42 #include <io/concaps.h> 43 #include <io/ cons_event.h>43 #include <io/kbd_event.h> 44 44 #include <io/pixel.h> 45 45 #include <io/style.h> … … 82 82 void (*set_rgb_color)(con_srv_t *, pixel_t, pixel_t); 83 83 void (*set_cursor_visibility)(con_srv_t *, bool); 84 int (*get_event)(con_srv_t *, cons_event_t *);84 int (*get_event)(con_srv_t *, kbd_event_t *); 85 85 } con_ops_t; 86 86 -
uspace/lib/c/include/io/console.h
red267bc r166a1f57 39 39 #include <io/concaps.h> 40 40 #include <io/kbd_event.h> 41 #include <io/cons_event.h>42 41 #include <io/keycode.h> 43 42 #include <async.h> … … 83 82 extern void console_cursor_visibility(console_ctrl_t *, bool); 84 83 extern int console_get_color_cap(console_ctrl_t *, sysarg_t *); 85 extern bool console_get_ event(console_ctrl_t *, cons_event_t *);86 extern bool console_get_ event_timeout(console_ctrl_t *, cons_event_t *,84 extern bool console_get_kbd_event(console_ctrl_t *, kbd_event_t *); 85 extern bool console_get_kbd_event_timeout(console_ctrl_t *, kbd_event_t *, 87 86 suseconds_t *); 88 87 -
uspace/lib/clui/tinput.c
red267bc r166a1f57 45 45 #define LIN_TO_COL(ti, lpos) ((lpos) % ((ti)->con_cols)) 46 46 #define LIN_TO_ROW(ti, lpos) ((lpos) / ((ti)->con_cols)) 47 #define LIN_POS(ti, col, row) ((col) + (row) * (ti)->con_cols)48 47 49 48 /** Seek direction */ … … 381 380 } 382 381 383 tinput_post_seek(ti, shift_held);384 }385 386 static void tinput_seek_scrpos(tinput_t *ti, int col, int line, bool shift_held)387 {388 unsigned lpos;389 tinput_pre_seek(ti, shift_held);390 391 lpos = LIN_POS(ti, col, line);392 393 if (lpos > ti->text_coord)394 ti->pos = lpos - ti->text_coord;395 else396 ti->pos = 0;397 if (ti->pos > ti->nc)398 ti->pos = ti->nc;399 400 382 tinput_post_seek(ti, shift_held); 401 383 } … … 805 787 } 806 788 807 /** Handle key press event. */808 static void tinput_key_press(tinput_t *ti, kbd_event_t *kev)809 {810 if (kev->key == KC_LSHIFT)811 ti->lshift_held = true;812 if (kev->key == KC_RSHIFT)813 ti->rshift_held = true;814 815 if (((kev->mods & KM_CTRL) != 0) &&816 ((kev->mods & (KM_ALT | KM_SHIFT)) == 0))817 tinput_key_ctrl(ti, kev);818 819 if (((kev->mods & KM_SHIFT) != 0) &&820 ((kev->mods & (KM_CTRL | KM_ALT)) == 0))821 tinput_key_shift(ti, kev);822 823 if (((kev->mods & KM_CTRL) != 0) &&824 ((kev->mods & KM_SHIFT) != 0) &&825 ((kev->mods & KM_ALT) == 0))826 tinput_key_ctrl_shift(ti, kev);827 828 if ((kev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0)829 tinput_key_unmod(ti, kev);830 831 if (kev->c >= ' ') {832 tinput_sel_delete(ti);833 tinput_insert_char(ti, kev->c);834 }835 }836 837 /** Handle key release event. */838 static void tinput_key_release(tinput_t *ti, kbd_event_t *kev)839 {840 if (kev->key == KC_LSHIFT)841 ti->lshift_held = false;842 if (kev->key == KC_RSHIFT)843 ti->rshift_held = false;844 }845 846 /** Position event */847 static void tinput_pos(tinput_t *ti, pos_event_t *ev)848 {849 if (ev->type == POS_PRESS) {850 tinput_seek_scrpos(ti, ev->hpos, ev->vpos,851 ti->lshift_held || ti->rshift_held);852 }853 }854 855 789 /** Read in one line of input. 856 790 * … … 882 816 console_flush(ti->console); 883 817 884 cons_event_t ev;885 if (!console_get_ event(ti->console, &ev))818 kbd_event_t ev; 819 if (!console_get_kbd_event(ti->console, &ev)) 886 820 return EIO; 887 821 888 switch (ev.type) { 889 case CEV_KEY: 890 if (ev.ev.key.type == KEY_PRESS) 891 tinput_key_press(ti, &ev.ev.key); 892 else 893 tinput_key_release(ti, &ev.ev.key); 894 break; 895 case CEV_POS: 896 tinput_pos(ti, &ev.ev.pos); 897 break; 822 if (ev.type != KEY_PRESS) 823 continue; 824 825 if (((ev.mods & KM_CTRL) != 0) && 826 ((ev.mods & (KM_ALT | KM_SHIFT)) == 0)) 827 tinput_key_ctrl(ti, &ev); 828 829 if (((ev.mods & KM_SHIFT) != 0) && 830 ((ev.mods & (KM_CTRL | KM_ALT)) == 0)) 831 tinput_key_shift(ti, &ev); 832 833 if (((ev.mods & KM_CTRL) != 0) && 834 ((ev.mods & KM_SHIFT) != 0) && 835 ((ev.mods & KM_ALT) == 0)) 836 tinput_key_ctrl_shift(ti, &ev); 837 838 if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) 839 tinput_key_unmod(ti, &ev); 840 841 if (ev.c >= ' ') { 842 tinput_sel_delete(ti); 843 tinput_insert_char(ti, ev.c); 898 844 } 899 845 } -
uspace/lib/clui/tinput.h
red267bc r166a1f57 146 146 /** @c true if user requested to abort interactive loop */ 147 147 bool exit_clui; 148 149 /** @c true if left shift key is currently held */150 bool lshift_held;151 152 /** @c true if right shift key is currently held */153 bool rshift_held;154 148 } tinput_t; 155 149 -
uspace/lib/gui/terminal.c
red267bc r166a1f57 77 77 static void term_set_rgb_color(con_srv_t *, pixel_t, pixel_t); 78 78 static void term_set_cursor_visibility(con_srv_t *, bool); 79 static int term_get_event(con_srv_t *, cons_event_t *);79 static int term_get_event(con_srv_t *, kbd_event_t *); 80 80 81 81 static con_ops_t con_ops = { … … 420 420 if (pos < size) { 421 421 link_t *link = prodcons_consume(&term->input_pc); 422 cons_event_t *event = list_get_instance(link, cons_event_t, link);422 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 423 423 424 424 /* Accept key presses of printable chars only. */ 425 if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS && 426 event->ev.key.c != 0) { 425 if ((event->type == KEY_PRESS) && (event->c != 0)) { 427 426 wchar_t tmp[2] = { 428 event-> ev.key.c,427 event->c, 429 428 0 430 429 }; … … 580 579 } 581 580 582 static int term_get_event(con_srv_t *srv, cons_event_t *event)581 static int term_get_event(con_srv_t *srv, kbd_event_t *event) 583 582 { 584 583 terminal_t *term = srv_to_terminal(srv); 585 584 link_t *link = prodcons_consume(&term->input_pc); 586 cons_event_t *ev = list_get_instance(link, cons_event_t, link);587 588 *event = * ev;589 free( ev);585 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 586 587 *event = *kevent; 588 free(kevent); 590 589 return EOK; 591 590 } … … 635 634 } 636 635 637 static void terminal_queue_cons_event(terminal_t *term, cons_event_t *ev) 638 { 636 static void terminal_handle_keyboard_event(widget_t *widget, 637 kbd_event_t kbd_event) 638 { 639 terminal_t *term = (terminal_t *) widget; 640 639 641 /* Got key press/release event */ 640 cons_event_t *event =641 ( cons_event_t *) malloc(sizeof(cons_event_t));642 kbd_event_t *event = 643 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 642 644 if (event == NULL) 643 645 return; 644 646 645 *event = *ev;646 647 link_initialize(&event->link); 648 event->type = kbd_event.type; 649 event->key = kbd_event.key; 650 event->mods = kbd_event.mods; 651 event->c = kbd_event.c; 647 652 648 653 prodcons_produce(&term->input_pc, &event->link); 649 654 } 650 655 651 /* Got key press/release event */ 652 static void terminal_handle_keyboard_event(widget_t *widget, 653 kbd_event_t kbd_event) 654 { 655 terminal_t *term = (terminal_t *) widget; 656 cons_event_t event; 657 658 event.type = CEV_KEY; 659 event.ev.key = kbd_event; 660 661 terminal_queue_cons_event(term, &event); 662 } 663 664 static void terminal_handle_position_event(widget_t *widget, pos_event_t pos_event) 665 { 666 cons_event_t event; 667 terminal_t *term = (terminal_t *) widget; 668 sysarg_t sx = term->widget.hpos; 669 sysarg_t sy = term->widget.vpos; 670 671 if (pos_event.type == POS_PRESS) { 672 event.type = CEV_POS; 673 event.ev.pos.type = pos_event.type; 674 event.ev.pos.pos_id = pos_event.pos_id; 675 event.ev.pos.btn_num = pos_event.btn_num; 676 677 event.ev.pos.hpos = (pos_event.hpos - sx) / FONT_WIDTH; 678 event.ev.pos.vpos = (pos_event.vpos - sy) / FONT_SCANLINES; 679 terminal_queue_cons_event(term, &event); 680 } 656 static void terminal_handle_position_event(widget_t *widget, pos_event_t event) 657 { 658 /* 659 * Mouse events are ignored so far. 660 * There is no consumer for it. 661 */ 681 662 } 682 663 -
uspace/srv/hid/console/console.c
red267bc r166a1f57 129 129 static void cons_set_rgb_color(con_srv_t *, pixel_t, pixel_t); 130 130 static void cons_set_cursor_visibility(con_srv_t *, bool); 131 static int cons_get_event(con_srv_t *, cons_event_t *);131 static int cons_get_event(con_srv_t *, kbd_event_t *); 132 132 133 133 static con_ops_t con_ops = { … … 490 490 } 491 491 492 static int cons_get_event(con_srv_t *srv, cons_event_t *event)492 static int cons_get_event(con_srv_t *srv, kbd_event_t *event) 493 493 { 494 494 console_t *cons = srv_to_console(srv); … … 496 496 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link); 497 497 498 event->type = CEV_KEY; 499 event->ev.key = *kevent; 498 *event = *kevent; 500 499 free(kevent); 501 500 return EOK; -
uspace/srv/hid/remcons/remcons.c
red267bc r166a1f57 80 80 static int remcons_get_size(con_srv_t *, sysarg_t *, sysarg_t *); 81 81 static int remcons_get_color_cap(con_srv_t *, console_caps_t *); 82 static int remcons_get_event(con_srv_t *, cons_event_t *);82 static int remcons_get_event(con_srv_t *, kbd_event_t *); 83 83 84 84 static con_ops_t con_ops = { … … 185 185 } 186 186 187 static int remcons_get_event(con_srv_t *srv, cons_event_t *event) 188 { 189 telnet_user_t *user = srv_to_user(srv); 190 kbd_event_t kevent; 187 static int remcons_get_event(con_srv_t *srv, kbd_event_t *event) 188 { 189 telnet_user_t *user = srv_to_user(srv); 191 190 int rc; 192 191 193 rc = telnet_user_get_next_keyboard_event(user, &kevent);192 rc = telnet_user_get_next_keyboard_event(user, event); 194 193 if (rc != EOK) { 195 194 /* XXX What? */ … … 197 196 return EOK; 198 197 } 199 200 event->type = CEV_KEY;201 event->ev.key = kevent;202 198 203 199 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.