Changeset 3f06dae in mainline
- Timestamp:
- 2013-04-12T19:40:36Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2bdcf87
- Parents:
- 902f0906
- Location:
- uspace/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/clui/tinput.c
r902f0906 r3f06dae 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->mods & KM_CTRL) != 0) && 811 ((kev->mods & (KM_ALT | KM_SHIFT)) == 0)) 812 tinput_key_ctrl(ti, kev); 813 814 if (((kev->mods & KM_SHIFT) != 0) && 815 ((kev->mods & (KM_CTRL | KM_ALT)) == 0)) 816 tinput_key_shift(ti, kev); 817 818 if (((kev->mods & KM_CTRL) != 0) && 819 ((kev->mods & KM_SHIFT) != 0) && 820 ((kev->mods & KM_ALT) == 0)) 821 tinput_key_ctrl_shift(ti, kev); 822 823 if ((kev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) 824 tinput_key_unmod(ti, kev); 825 826 if (kev->c >= ' ') { 827 tinput_sel_delete(ti); 828 tinput_insert_char(ti, kev->c); 829 } 830 } 831 832 /** Position event */ 833 static void tinput_pos(tinput_t *ti, pos_event_t *ev) 834 { 835 if (ev->type == POS_PRESS) { 836 tinput_seek_scrpos(ti, ev->hpos, ev->vpos, false); 837 } 838 } 839 789 840 /** Read in one line of input. 790 841 * … … 820 871 return EIO; 821 872 822 if (ev.type != CEV_KEY || ev.ev.key.type != KEY_PRESS) 823 continue; 824 825 kbd_event_t *kev = &ev.ev.key; 826 827 if (((kev->mods & KM_CTRL) != 0) && 828 ((kev->mods & (KM_ALT | KM_SHIFT)) == 0)) 829 tinput_key_ctrl(ti, kev); 830 831 if (((kev->mods & KM_SHIFT) != 0) && 832 ((kev->mods & (KM_CTRL | KM_ALT)) == 0)) 833 tinput_key_shift(ti, kev); 834 835 if (((kev->mods & KM_CTRL) != 0) && 836 ((kev->mods & KM_SHIFT) != 0) && 837 ((kev->mods & KM_ALT) == 0)) 838 tinput_key_ctrl_shift(ti, kev); 839 840 if ((kev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) 841 tinput_key_unmod(ti, kev); 842 843 if (kev->c >= ' ') { 844 tinput_sel_delete(ti); 845 tinput_insert_char(ti, kev->c); 873 switch (ev.type) { 874 case CEV_KEY: 875 if (ev.ev.key.type == KEY_PRESS) 876 tinput_key_press(ti, &ev.ev.key); 877 break; 878 case CEV_POS: 879 tinput_pos(ti, &ev.ev.pos); 880 break; 846 881 } 847 882 } -
uspace/lib/gui/terminal.c
r902f0906 r3f06dae 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 }; … … 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->type = CEV_KEY; 588 event->ev.key = *kevent; 589 free(kevent); 586 cons_event_t *ev = list_get_instance(link, cons_event_t, link); 587 588 *event = *ev; 589 free(ev); 590 590 return EOK; 591 591 } … … 635 635 } 636 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 */ 637 652 static void terminal_handle_keyboard_event(widget_t *widget, 638 653 kbd_event_t kbd_event) 639 654 { 640 655 terminal_t *term = (terminal_t *) widget; 641 642 /* Got key press/release event */ 643 kbd_event_t *event = 644 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 645 if (event == NULL) 646 return; 647 648 link_initialize(&event->link); 649 event->type = kbd_event.type; 650 event->key = kbd_event.key; 651 event->mods = kbd_event.mods; 652 event->c = kbd_event.c; 653 654 prodcons_produce(&term->input_pc, &event->link); 655 } 656 657 static void terminal_handle_position_event(widget_t *widget, pos_event_t event) 658 { 659 /* 660 * Mouse events are ignored so far. 661 * There is no consumer for it. 662 */ 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 } 663 681 } 664 682
Note:
See TracChangeset
for help on using the changeset viewer.