Changeset ed267bc in mainline
- Timestamp:
- 2013-04-15T06:30:48Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 077bc931
- Parents:
- 166a1f57 (diff), c80be58 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace
- Files:
-
- 1 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/cat/cat.c
r166a1f57 red267bc 117 117 static void waitkey() 118 118 { 119 kbd_event_t ev; 119 cons_event_t ev; 120 kbd_event_t *kev; 120 121 121 122 while (true) { 122 if (!console_get_ kbd_event(console, &ev)) {123 if (!console_get_event(console, &ev)) { 123 124 return; 124 125 } 125 if (ev.type == KEY_PRESS) { 126 if (ev.key == KC_ESCAPE || ev.key == KC_Q) { 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) { 127 130 should_quit = true; 128 131 return; 129 132 } 130 if ( ev.key == KC_C) {133 if (kev->key == KC_C) { 131 134 paging_enabled = false; 132 135 return; 133 136 } 134 if ( ev.key == KC_ENTER || ev.key == KC_SPACE ||135 ev.key == KC_PAGE_DOWN) {137 if (kev->key == KC_ENTER || kev->key == KC_SPACE || 138 kev->key == KC_PAGE_DOWN) { 136 139 return; 137 140 } -
uspace/app/bdsh/cmds/modules/cp/cp.c
r166a1f57 red267bc 152 152 153 153 while (true) { 154 kbd_event_t ev;154 cons_event_t ev; 155 155 console_flush(con); 156 console_get_ kbd_event(con, &ev);157 if ( (ev.type != KEY_PRESS)158 || (ev.mods & (KM_CTRL | KM_ALT)) != 0) {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) { 159 159 continue; 160 160 } 161 161 162 switch(ev. key) {162 switch(ev.ev.key.key) { 163 163 case KC_Y: 164 164 printf("y\n"); -
uspace/app/edit/edit.c
r166a1f57 red267bc 80 80 tag_t sel_start; 81 81 82 /** Active keyboard modifiers */ 83 keymod_t keymod; 84 82 85 /** 83 86 * Ideal column where the caret should try to get. This is used … … 119 122 static void cursor_setvis(bool visible); 120 123 124 static void key_handle_press(kbd_event_t *ev); 121 125 static void key_handle_unmod(kbd_event_t const *ev); 122 126 static void key_handle_ctrl(kbd_event_t const *ev); … … 124 128 static void key_handle_shift_ctrl(kbd_event_t const *ev); 125 129 static void key_handle_movement(unsigned int key, bool shift); 130 131 static void pos_handle(pos_event_t *ev); 126 132 127 133 static int file_save(char const *fname); … … 182 188 int main(int argc, char *argv[]) 183 189 { 184 kbd_event_t ev;190 cons_event_t ev; 185 191 bool new_file; 186 192 int rc; … … 245 251 246 252 while (!done) { 247 console_get_ kbd_event(con, &ev);253 console_get_event(con, &ev); 248 254 pane.rflags = 0; 249 255 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 } 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; 267 265 } 268 266 … … 286 284 287 285 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 } 288 306 } 289 307 … … 462 480 } 463 481 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 464 499 /** Move caret while preserving or resetting selection. */ 465 500 static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column) … … 592 627 static char *prompt(char const *prompt, char const *init_value) 593 628 { 594 kbd_event_t ev; 629 cons_event_t ev; 630 kbd_event_t *kev; 595 631 char *str; 596 632 wchar_t buffer[INFNAME_MAX_LEN + 1]; … … 612 648 613 649 while (!done) { 614 console_get_kbd_event(con, &ev); 615 616 if (ev.type == KEY_PRESS) { 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 617 655 /* Handle key press. */ 618 if ((( ev.mods & KM_ALT) == 0) &&619 ( ev.mods & KM_CTRL) != 0) {656 if (((kev->mods & KM_ALT) == 0) && 657 (kev->mods & KM_CTRL) != 0) { 620 658 ; 621 } else if (( ev.mods & (KM_CTRL | KM_ALT)) == 0) {622 switch ( ev.key) {659 } else if ((kev->mods & (KM_CTRL | KM_ALT)) == 0) { 660 switch (kev->key) { 623 661 case KC_ESCAPE: 624 662 return NULL; … … 634 672 break; 635 673 default: 636 if ( ev.c >= 32 && nc < max_len) {637 putchar( ev.c);674 if (kev->c >= 32 && nc < max_len) { 675 putchar(kev->c); 638 676 console_flush(con); 639 buffer[nc++] = ev.c;677 buffer[nc++] = kev->c; 640 678 } 641 679 break; -
uspace/app/mkbd/main.c
r166a1f57 red267bc 178 178 179 179 while (1) { 180 kbd_event_t ev;181 bool ok = console_get_ kbd_event(con, &ev);180 cons_event_t ev; 181 bool ok = console_get_event(con, &ev); 182 182 if (!ok) { 183 183 printf("Connection with console broken: %s.\n", … … 186 186 } 187 187 188 if (ev.key == KC_ESCAPE) { 188 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS && 189 ev.ev.key.key == KC_ESCAPE) { 189 190 break; 190 191 } -
uspace/app/msim/arch_helenos/input.c
r166a1f57 red267bc 91 91 bool stdin_poll(char *key) 92 92 { 93 kbd_event_t ev;93 cons_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_ kbd_event_timeout(input_prompt->console, &ev, &timeout);97 bool has_input = console_get_event_timeout(input_prompt->console, &ev, &timeout); 98 98 if (!has_input) { 99 99 return false; 100 100 } 101 101 102 if (ev.type != KEY_PRESS)102 if (ev.type != CEV_KEY || ev.ev.key.type != KEY_PRESS) 103 103 return false; 104 104 105 *key = ev. c;105 *key = ev.ev.key.c; 106 106 107 107 return true; -
uspace/app/nterm/nterm.c
r166a1f57 red267bc 109 109 int main(int argc, char *argv[]) 110 110 { 111 kbd_event_t ev;111 cons_event_t ev; 112 112 int rc; 113 113 … … 129 129 done = false; 130 130 while (!done) { 131 console_get_ kbd_event(con, &ev);132 if (ev.type == KEY_PRESS)133 key_handle(&ev );131 console_get_event(con, &ev); 132 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) 133 key_handle(&ev.ev.key); 134 134 } 135 135 -
uspace/app/ping/ping.c
r166a1f57 red267bc 188 188 { 189 189 console_ctrl_t *con; 190 kbd_event_t ev;190 cons_event_t ev; 191 191 192 192 con = console_init(stdin, stdout); … … 194 194 195 195 while (true) { 196 if (!console_get_ kbd_event(con, &ev))196 if (!console_get_event(con, &ev)) 197 197 break; 198 198 199 if (ev.type == KEY_PRESS && (ev.mods & (KM_ALT | KM_SHIFT)) == 200 0 && (ev.mods & KM_CTRL) != 0) { 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) { 201 202 /* Ctrl+key */ 202 if (ev. key == KC_Q) {203 if (ev.ev.key.key == KC_Q) { 203 204 ping_signal_done(); 204 205 return 0; -
uspace/app/tester/ipc/starve.c
r166a1f57 red267bc 62 62 break; 63 63 64 kbd_event_t ev;64 cons_event_t ev; 65 65 suseconds_t timeout = 0; 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);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); 69 69 break; 70 70 } -
uspace/app/tetris/scores.c
r166a1f57 red267bc 125 125 int j; 126 126 size_t off; 127 kbd_event_t ev; 127 cons_event_t ev; 128 kbd_event_t *kev; 128 129 129 130 clear_screen(); … … 141 142 while (1) { 142 143 console_flush(console); 143 if (!console_get_ kbd_event(console, &ev))144 if (!console_get_event(console, &ev)) 144 145 exit(1); 145 146 146 if (ev.type == KEY_RELEASE)147 if (ev.type != CEV_KEY || ev.ev.key.type == KEY_RELEASE) 147 148 continue; 148 149 149 if (ev.key == KC_ENTER || ev.key == KC_NENTER) 150 kev = &ev.ev.key; 151 152 if (kev->key == KC_ENTER || kev->key == KC_NENTER) 150 153 break; 151 154 152 if ( ev.key == KC_BACKSPACE) {155 if (kev->key == KC_BACKSPACE) { 153 156 if (i > 0) { 154 157 wchar_t uc; … … 166 169 scores[NUMSPOTS - 1].hs_name[off] = '\0'; 167 170 } 168 } else if ( ev.c != '\0') {171 } else if (kev->c != '\0') { 169 172 if (i < (MAXLOGNAME - 1)) { 170 if (chr_encode( ev.c, scores[NUMSPOTS - 1].hs_name,173 if (chr_encode(kev->c, scores[NUMSPOTS - 1].hs_name, 171 174 &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { 172 175 ++i; -
uspace/app/tetris/screen.c
r166a1f57 red267bc 344 344 345 345 while (timeout > 0) { 346 kbd_event_t event;347 348 if (!console_get_ kbd_event_timeout(console, &event, &timeout))346 cons_event_t event; 347 348 if (!console_get_event_timeout(console, &event, &timeout)) 349 349 break; 350 350 } … … 376 376 377 377 while (c == 0) { 378 kbd_event_t event;379 380 if (!console_get_ kbd_event_timeout(console, &event, &timeleft)) {378 cons_event_t event; 379 380 if (!console_get_event_timeout(console, &event, &timeleft)) { 381 381 timeleft = 0; 382 382 return -1; 383 383 } 384 384 385 if (event.type == KEY_PRESS)386 c = event. c;385 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 386 c = event.ev.key.c; 387 387 } 388 388 … … 398 398 399 399 while (c == 0) { 400 kbd_event_t event;401 402 if (!console_get_ kbd_event(console, &event))400 cons_event_t event; 401 402 if (!console_get_event(console, &event)) 403 403 return -1; 404 404 405 if (event.type == KEY_PRESS)406 c = event. c;405 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 406 c = event.ev.key.c; 407 407 } 408 408 -
uspace/app/top/screen.c
r166a1f57 red267bc 556 556 557 557 while (c == 0) { 558 kbd_event_t event;558 cons_event_t event; 559 559 560 560 warning_timeleft -= timeleft; 561 if (!console_get_ kbd_event_timeout(console, &event, &timeleft)) {561 if (!console_get_event_timeout(console, &event, &timeleft)) { 562 562 timeleft = 0; 563 563 return -1; … … 565 565 warning_timeleft += timeleft; 566 566 567 if (event.type == KEY_PRESS)568 c = event. c;567 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 568 c = event.ev.key.c; 569 569 } 570 570 -
uspace/app/trace/trace.c
r166a1f57 red267bc 565 565 static int cev_fibril(void *arg) 566 566 { 567 cons_event_t event; 568 567 569 (void) arg; 568 570 … … 575 577 fibril_mutex_unlock(&state_lock); 576 578 577 if (!console_get_ kbd_event(console, &cev))579 if (!console_get_event(console, &event)) 578 580 return -1; 579 581 580 fibril_mutex_lock(&state_lock); 581 cev_valid = true; 582 fibril_condvar_broadcast(&state_cv); 583 fibril_mutex_unlock(&state_lock); 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 } 584 589 } 585 590 } -
uspace/dist/src/c/demos/tetris/scores.c
r166a1f57 red267bc 125 125 int j; 126 126 size_t off; 127 kbd_event_t ev; 127 cons_event_t ev; 128 kbd_event_t *kev; 128 129 129 130 clear_screen(); … … 141 142 while (1) { 142 143 console_flush(console); 143 if (!console_get_ kbd_event(console, &ev))144 if (!console_get_event(console, &ev)) 144 145 exit(1); 145 146 146 if (ev.type == KEY_RELEASE)147 if (ev.type != CEV_KEY || ev.ev.key.type == KEY_RELEASE) 147 148 continue; 148 149 149 if (ev.key == KC_ENTER || ev.key == KC_NENTER) 150 kev = &ev.ev.key; 151 152 if (kev->key == KC_ENTER || kev->key == KC_NENTER) 150 153 break; 151 154 152 if ( ev.key == KC_BACKSPACE) {155 if (kev->key == KC_BACKSPACE) { 153 156 if (i > 0) { 154 157 wchar_t uc; … … 166 169 scores[NUMSPOTS - 1].hs_name[off] = '\0'; 167 170 } 168 } else if ( ev.c != '\0') {171 } else if (kev->c != '\0') { 169 172 if (i < (MAXLOGNAME - 1)) { 170 if (chr_encode( ev.c, scores[NUMSPOTS - 1].hs_name,173 if (chr_encode(kev->c, scores[NUMSPOTS - 1].hs_name, 171 174 &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) { 172 175 ++i; -
uspace/dist/src/c/demos/top/screen.c
r166a1f57 red267bc 553 553 554 554 while (c == 0) { 555 kbd_event_t event;556 557 if (!console_get_ kbd_event_timeout(console, &event, &timeleft)) {555 cons_event_t event; 556 557 if (!console_get_event_timeout(console, &event, &timeleft)) { 558 558 timeleft = 0; 559 559 return -1; 560 560 } 561 561 562 if (event.type == KEY_PRESS)563 c = event. c;562 if (event.type == CEV_KEY && event.ev.key.type == KEY_PRESS) 563 c = event.ev.key.c; 564 564 } 565 565 -
uspace/lib/c/generic/io/con_srv.c
r166a1f57 red267bc 35 35 */ 36 36 #include <errno.h> 37 #include <io/cons_event.h> 37 38 #include <ipc/console.h> 38 39 #include <stdlib.h> … … 40 41 41 42 #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 } 42 67 43 68 static void con_read_srv(con_srv_t *srv, ipc_callid_t callid, … … 273 298 { 274 299 int rc; 275 kbd_event_t event; 300 cons_event_t event; 301 ipc_call_t result; 276 302 277 303 if (srv->srvs->ops->get_event == NULL) { … … 281 307 282 308 rc = srv->srvs->ops->get_event(srv, &event); 283 async_answer_4(callid, rc, event.type, event.key, event.mods, event.c); 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)); 284 322 } 285 323 -
uspace/lib/c/generic/io/console.c
r166a1f57 red267bc 154 154 } 155 155 156 bool console_get_kbd_event(console_ctrl_t *ctrl, kbd_event_t *event) 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) 157 182 { 158 183 if (ctrl->input_aid == 0) { 159 sysarg_t type; 160 sysarg_t key; 161 sysarg_t mods; 162 sysarg_t c; 184 ipc_call_t result; 163 185 164 186 async_exch_t *exch = async_exchange_begin(ctrl->input_sess); 165 int rc = async_req_0_4(exch, CONSOLE_GET_EVENT, &type, &key, &mods, &c);187 aid_t aid = async_send_0(exch, CONSOLE_GET_EVENT, &result); 166 188 async_exchange_end(exch); 189 190 sysarg_t rc; 191 async_wait_for(aid, &rc); 167 192 168 193 if (rc != EOK) { … … 171 196 } 172 197 173 event->type = type; 174 event->key = key; 175 event->mods = mods; 176 event->c = c; 198 rc = console_ev_decode(&result, event); 199 if (rc != EOK) { 200 errno = rc; 201 return false; 202 } 177 203 } else { 178 204 sysarg_t retval; … … 186 212 } 187 213 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); 214 int rc = console_ev_decode(&ctrl->input_call, event); 215 if (rc != EOK) { 216 errno = rc; 217 return false; 218 } 192 219 } 193 220 … … 195 222 } 196 223 197 bool console_get_ kbd_event_timeout(console_ctrl_t *ctrl, kbd_event_t *event,224 bool console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event, 198 225 suseconds_t *timeout) 199 226 { … … 223 250 } 224 251 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); 252 rc = console_ev_decode(&ctrl->input_call, event); 253 if (rc != EOK) { 254 errno = rc; 255 return false; 256 } 229 257 230 258 /* Update timeout */ -
uspace/lib/c/include/io/con_srv.h
r166a1f57 red267bc 41 41 #include <io/color.h> 42 42 #include <io/concaps.h> 43 #include <io/ kbd_event.h>43 #include <io/cons_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 *, kbd_event_t *);84 int (*get_event)(con_srv_t *, cons_event_t *); 85 85 } con_ops_t; 86 86 -
uspace/lib/c/include/io/console.h
r166a1f57 red267bc 39 39 #include <io/concaps.h> 40 40 #include <io/kbd_event.h> 41 #include <io/cons_event.h> 41 42 #include <io/keycode.h> 42 43 #include <async.h> … … 82 83 extern void console_cursor_visibility(console_ctrl_t *, bool); 83 84 extern int console_get_color_cap(console_ctrl_t *, sysarg_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 *,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 *, 86 87 suseconds_t *); 87 88 -
uspace/lib/clui/tinput.c
r166a1f57 red267bc 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) 47 48 48 49 /** Seek direction */ … … 383 384 } 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 else 396 ti->pos = 0; 397 if (ti->pos > ti->nc) 398 ti->pos = ti->nc; 399 400 tinput_post_seek(ti, shift_held); 401 } 402 385 403 static void tinput_seek_max(tinput_t *ti, seek_dir_t dir, bool shift_held) 386 404 { … … 787 805 } 788 806 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 789 855 /** Read in one line of input. 790 856 * … … 816 882 console_flush(ti->console); 817 883 818 kbd_event_t ev;819 if (!console_get_ kbd_event(ti->console, &ev))884 cons_event_t ev; 885 if (!console_get_event(ti->console, &ev)) 820 886 return EIO; 821 887 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); 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; 844 898 } 845 899 } -
uspace/lib/clui/tinput.h
r166a1f57 red267bc 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; 148 154 } tinput_t; 149 155 -
uspace/lib/gui/terminal.c
r166a1f57 red267bc 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 *, kbd_event_t *);79 static int term_get_event(con_srv_t *, cons_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 kbd_event_t *event = list_get_instance(link, kbd_event_t, link);422 cons_event_t *event = list_get_instance(link, cons_event_t, link); 423 423 424 424 /* Accept key presses of printable chars only. */ 425 if ((event->type == KEY_PRESS) && (event->c != 0)) { 425 if (event->type == CEV_KEY && event->ev.key.type == KEY_PRESS && 426 event->ev.key.c != 0) { 426 427 wchar_t tmp[2] = { 427 event-> c,428 event->ev.key.c, 428 429 0 429 430 }; … … 579 580 } 580 581 581 static int term_get_event(con_srv_t *srv, kbd_event_t *event)582 static int term_get_event(con_srv_t *srv, cons_event_t *event) 582 583 { 583 584 terminal_t *term = srv_to_terminal(srv); 584 585 link_t *link = prodcons_consume(&term->input_pc); 585 kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link);586 587 *event = * kevent;588 free( kevent);586 cons_event_t *ev = list_get_instance(link, cons_event_t, link); 587 588 *event = *ev; 589 free(ev); 589 590 return EOK; 590 591 } … … 634 635 } 635 636 637 static void terminal_queue_cons_event(terminal_t *term, cons_event_t *ev) 638 { 639 /* Got key press/release event */ 640 cons_event_t *event = 641 (cons_event_t *) malloc(sizeof(cons_event_t)); 642 if (event == NULL) 643 return; 644 645 *event = *ev; 646 link_initialize(&event->link); 647 648 prodcons_produce(&term->input_pc, &event->link); 649 } 650 651 /* Got key press/release event */ 636 652 static void terminal_handle_keyboard_event(widget_t *widget, 637 653 kbd_event_t kbd_event) 638 654 { 639 655 terminal_t *term = (terminal_t *) widget; 640 641 /* Got key press/release event */ 642 kbd_event_t *event = 643 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 644 if (event == NULL) 645 return; 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; 652 653 prodcons_produce(&term->input_pc, &event->link); 654 } 655 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 */ 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 } 662 681 } 663 682 -
uspace/srv/hid/console/console.c
r166a1f57 red267bc 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 *, kbd_event_t *);131 static int cons_get_event(con_srv_t *, cons_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, kbd_event_t *event)492 static int cons_get_event(con_srv_t *srv, cons_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 = *kevent; 498 event->type = CEV_KEY; 499 event->ev.key = *kevent; 499 500 free(kevent); 500 501 return EOK; -
uspace/srv/hid/remcons/remcons.c
r166a1f57 red267bc 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 *, kbd_event_t *);82 static int remcons_get_event(con_srv_t *, cons_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, kbd_event_t *event) 188 { 189 telnet_user_t *user = srv_to_user(srv); 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; 190 191 int rc; 191 192 192 rc = telnet_user_get_next_keyboard_event(user, event);193 rc = telnet_user_get_next_keyboard_event(user, &kevent); 193 194 if (rc != EOK) { 194 195 /* XXX What? */ … … 196 197 return EOK; 197 198 } 199 200 event->type = CEV_KEY; 201 event->ev.key = kevent; 198 202 199 203 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.