Changeset 3f06dae in mainline


Ignore:
Timestamp:
2013-04-12T19:40:36Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a2bdcf87
Parents:
902f0906
Message:

Button press support in terminal widget and tinput.

Location:
uspace/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/clui/tinput.c

    r902f0906 r3f06dae  
    4545#define LIN_TO_COL(ti, lpos) ((lpos) % ((ti)->con_cols))
    4646#define LIN_TO_ROW(ti, lpos) ((lpos) / ((ti)->con_cols))
     47#define LIN_POS(ti, col, row) ((col) + (row) * (ti)->con_cols)
    4748
    4849/** Seek direction */
     
    383384}
    384385
     386static 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
    385403static void tinput_seek_max(tinput_t *ti, seek_dir_t dir, bool shift_held)
    386404{
     
    787805}
    788806
     807/** Handle key press event. */
     808static 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 */
     833static 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
    789840/** Read in one line of input.
    790841 *
     
    820871                        return EIO;
    821872               
    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;
    846881                }
    847882        }
  • uspace/lib/gui/terminal.c

    r902f0906 r3f06dae  
    420420                if (pos < size) {
    421421                        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);
    423423                       
    424424                        /* 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) {
    426427                                wchar_t tmp[2] = {
    427                                         event->c,
     428                                        event->ev.key.c,
    428429                                        0
    429430                                };
     
    583584        terminal_t *term = srv_to_terminal(srv);
    584585        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);
    590590        return EOK;
    591591}
     
    635635}
    636636
     637static 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 */
    637652static void terminal_handle_keyboard_event(widget_t *widget,
    638653    kbd_event_t kbd_event)
    639654{
    640655        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
     664static 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        }
    663681}
    664682
Note: See TracChangeset for help on using the changeset viewer.