Changes in / [166a1f57:ed267bc] in mainline


Ignore:
Location:
uspace
Files:
1 added
23 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r166a1f57 red267bc  
    117117static void waitkey()
    118118{
    119         kbd_event_t ev;
     119        cons_event_t ev;
     120        kbd_event_t *kev;
    120121       
    121122        while (true) {
    122                 if (!console_get_kbd_event(console, &ev)) {
     123                if (!console_get_event(console, &ev)) {
    123124                        return;
    124125                }
    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) {
    127130                                should_quit = true;
    128131                                return;
    129132                        }
    130                         if (ev.key == KC_C) {
     133                        if (kev->key == KC_C) {
    131134                                paging_enabled = false;
    132135                                return;
    133136                        }
    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) {
    136139                                return;
    137140                        }
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r166a1f57 red267bc  
    152152
    153153        while (true) {
    154                 kbd_event_t ev;
     154                cons_event_t ev;
    155155                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) {
    159159                        continue;
    160160                }
    161161
    162                 switch(ev.key) {
     162                switch(ev.ev.key.key) {
    163163                case KC_Y:
    164164                        printf("y\n");
  • uspace/app/edit/edit.c

    r166a1f57 red267bc  
    8080        tag_t sel_start;
    8181
     82        /** Active keyboard modifiers */
     83        keymod_t keymod;
     84
    8285        /**
    8386         * Ideal column where the caret should try to get. This is used
     
    119122static void cursor_setvis(bool visible);
    120123
     124static void key_handle_press(kbd_event_t *ev);
    121125static void key_handle_unmod(kbd_event_t const *ev);
    122126static void key_handle_ctrl(kbd_event_t const *ev);
     
    124128static void key_handle_shift_ctrl(kbd_event_t const *ev);
    125129static void key_handle_movement(unsigned int key, bool shift);
     130
     131static void pos_handle(pos_event_t *ev);
    126132
    127133static int file_save(char const *fname);
     
    182188int main(int argc, char *argv[])
    183189{
    184         kbd_event_t ev;
     190        cons_event_t ev;
    185191        bool new_file;
    186192        int rc;
     
    245251
    246252        while (!done) {
    247                 console_get_kbd_event(con, &ev);
     253                console_get_event(con, &ev);
    248254                pane.rflags = 0;
    249255
    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;
    267265                }
    268266
     
    286284
    287285        return 0;
     286}
     287
     288/* Handle key press. */
     289static 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        }
    288306}
    289307
     
    462480}
    463481
     482static 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
    464499/** Move caret while preserving or resetting selection. */
    465500static void caret_move(spt_t new_caret_pt, bool select, bool update_ideal_column)
     
    592627static char *prompt(char const *prompt, char const *init_value)
    593628{
    594         kbd_event_t ev;
     629        cons_event_t ev;
     630        kbd_event_t *kev;
    595631        char *str;
    596632        wchar_t buffer[INFNAME_MAX_LEN + 1];
     
    612648
    613649        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
    617655                        /* 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) {
    620658                                ;
    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) {
    623661                                case KC_ESCAPE:
    624662                                        return NULL;
     
    634672                                        break;
    635673                                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);
    638676                                                console_flush(con);
    639                                                 buffer[nc++] = ev.c;
     677                                                buffer[nc++] = kev->c;
    640678                                        }
    641679                                        break;
  • uspace/app/mkbd/main.c

    r166a1f57 red267bc  
    178178
    179179        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);
    182182                if (!ok) {
    183183                        printf("Connection with console broken: %s.\n",
     
    186186                }
    187187
    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) {
    189190                        break;
    190191                }
  • uspace/app/msim/arch_helenos/input.c

    r166a1f57 red267bc  
    9191bool stdin_poll(char *key)
    9292{
    93         kbd_event_t ev;
     93        cons_event_t ev;
    9494        suseconds_t timeout = 0;
    9595        errno = EOK;
    9696        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);
    9898        if (!has_input) {
    9999                return false;
    100100        }
    101101
    102         if (ev.type != KEY_PRESS)
     102        if (ev.type != CEV_KEY || ev.ev.key.type != KEY_PRESS)
    103103                return false;
    104104
    105         *key = ev.c;
     105        *key = ev.ev.key.c;
    106106
    107107        return true;
  • uspace/app/nterm/nterm.c

    r166a1f57 red267bc  
    109109int main(int argc, char *argv[])
    110110{
    111         kbd_event_t ev;
     111        cons_event_t ev;
    112112        int rc;
    113113
     
    129129        done = false;
    130130        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);
    134134        }
    135135
  • uspace/app/ping/ping.c

    r166a1f57 red267bc  
    188188{
    189189        console_ctrl_t *con;
    190         kbd_event_t ev;
     190        cons_event_t ev;
    191191
    192192        con = console_init(stdin, stdout);
     
    194194
    195195        while (true) {
    196                 if (!console_get_kbd_event(con, &ev))
     196                if (!console_get_event(con, &ev))
    197197                        break;
    198198
    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) {
    201202                        /* Ctrl+key */
    202                         if (ev.key == KC_Q) {
     203                        if (ev.ev.key.key == KC_Q) {
    203204                                ping_signal_done();
    204205                                return 0;
  • uspace/app/tester/ipc/starve.c

    r166a1f57 red267bc  
    6262                        break;
    6363               
    64                 kbd_event_t ev;
     64                cons_event_t ev;
    6565                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);
    6969                        break;
    7070                }
  • uspace/app/tetris/scores.c

    r166a1f57 red267bc  
    125125        int j;
    126126        size_t off;
    127         kbd_event_t ev;
     127        cons_event_t ev;
     128        kbd_event_t *kev;
    128129       
    129130        clear_screen();
     
    141142        while (1) {
    142143                console_flush(console);
    143                 if (!console_get_kbd_event(console, &ev))
     144                if (!console_get_event(console, &ev))
    144145                        exit(1);
    145146               
    146                 if (ev.type == KEY_RELEASE)
     147                if (ev.type != CEV_KEY || ev.ev.key.type == KEY_RELEASE)
    147148                        continue;
    148149               
    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)
    150153                        break;
    151154               
    152                 if (ev.key == KC_BACKSPACE) {
     155                if (kev->key == KC_BACKSPACE) {
    153156                        if (i > 0) {
    154157                                wchar_t uc;
     
    166169                                scores[NUMSPOTS - 1].hs_name[off] = '\0';
    167170                        }
    168                 } else if (ev.c != '\0') {
     171                } else if (kev->c != '\0') {
    169172                        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,
    171174                                    &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) {
    172175                                        ++i;
  • uspace/app/tetris/screen.c

    r166a1f57 red267bc  
    344344       
    345345        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))
    349349                        break;
    350350        }
     
    376376       
    377377        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)) {
    381381                        timeleft = 0;
    382382                        return -1;
    383383                }
    384384               
    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;
    387387        }
    388388       
     
    398398       
    399399        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))
    403403                        return -1;
    404404               
    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;
    407407        }
    408408       
  • uspace/app/top/screen.c

    r166a1f57 red267bc  
    556556       
    557557        while (c == 0) {
    558                 kbd_event_t event;
     558                cons_event_t event;
    559559               
    560560                warning_timeleft -= timeleft;
    561                 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) {
     561                if (!console_get_event_timeout(console, &event, &timeleft)) {
    562562                        timeleft = 0;
    563563                        return -1;
     
    565565                warning_timeleft += timeleft;
    566566               
    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;
    569569        }
    570570       
  • uspace/app/trace/trace.c

    r166a1f57 red267bc  
    565565static int cev_fibril(void *arg)
    566566{
     567        cons_event_t event;
     568
    567569        (void) arg;
    568570       
     
    575577                fibril_mutex_unlock(&state_lock);
    576578               
    577                 if (!console_get_kbd_event(console, &cev))
     579                if (!console_get_event(console, &event))
    578580                        return -1;
    579581               
    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                }
    584589        }
    585590}
  • uspace/dist/src/c/demos/tetris/scores.c

    r166a1f57 red267bc  
    125125        int j;
    126126        size_t off;
    127         kbd_event_t ev;
     127        cons_event_t ev;
     128        kbd_event_t *kev;
    128129       
    129130        clear_screen();
     
    141142        while (1) {
    142143                console_flush(console);
    143                 if (!console_get_kbd_event(console, &ev))
     144                if (!console_get_event(console, &ev))
    144145                        exit(1);
    145146               
    146                 if (ev.type == KEY_RELEASE)
     147                if (ev.type != CEV_KEY || ev.ev.key.type == KEY_RELEASE)
    147148                        continue;
    148149               
    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)
    150153                        break;
    151154               
    152                 if (ev.key == KC_BACKSPACE) {
     155                if (kev->key == KC_BACKSPACE) {
    153156                        if (i > 0) {
    154157                                wchar_t uc;
     
    166169                                scores[NUMSPOTS - 1].hs_name[off] = '\0';
    167170                        }
    168                 } else if (ev.c != '\0') {
     171                } else if (kev->c != '\0') {
    169172                        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,
    171174                                    &off, STR_BOUNDS(MAXLOGNAME) + 1) == EOK) {
    172175                                        ++i;
  • uspace/dist/src/c/demos/top/screen.c

    r166a1f57 red267bc  
    553553       
    554554        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)) {
    558558                        timeleft = 0;
    559559                        return -1;
    560560                }
    561561               
    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;
    564564        }
    565565       
  • uspace/lib/c/generic/io/con_srv.c

    r166a1f57 red267bc  
    3535 */
    3636#include <errno.h>
     37#include <io/cons_event.h>
    3738#include <ipc/console.h>
    3839#include <stdlib.h>
     
    4041
    4142#include <io/con_srv.h>
     43
     44static 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}
    4267
    4368static void con_read_srv(con_srv_t *srv, ipc_callid_t callid,
     
    273298{
    274299        int rc;
    275         kbd_event_t event;
     300        cons_event_t event;
     301        ipc_call_t result;
    276302
    277303        if (srv->srvs->ops->get_event == NULL) {
     
    281307
    282308        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));
    284322}
    285323
  • uspace/lib/c/generic/io/console.c

    r166a1f57 red267bc  
    154154}
    155155
    156 bool console_get_kbd_event(console_ctrl_t *ctrl, kbd_event_t *event)
     156static 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
     181bool console_get_event(console_ctrl_t *ctrl, cons_event_t *event)
    157182{
    158183        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;
    163185               
    164186                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);
    166188                async_exchange_end(exch);
     189               
     190                sysarg_t rc;
     191                async_wait_for(aid, &rc);
    167192               
    168193                if (rc != EOK) {
     
    171196                }
    172197               
    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                }
    177203        } else {
    178204                sysarg_t retval;
     
    186212                }
    187213               
    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                }
    192219        }
    193220       
     
    195222}
    196223
    197 bool console_get_kbd_event_timeout(console_ctrl_t *ctrl, kbd_event_t *event,
     224bool console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event,
    198225    suseconds_t *timeout)
    199226{
     
    223250        }
    224251       
    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        }
    229257       
    230258        /* Update timeout */
  • uspace/lib/c/include/io/con_srv.h

    r166a1f57 red267bc  
    4141#include <io/color.h>
    4242#include <io/concaps.h>
    43 #include <io/kbd_event.h>
     43#include <io/cons_event.h>
    4444#include <io/pixel.h>
    4545#include <io/style.h>
     
    8282        void (*set_rgb_color)(con_srv_t *, pixel_t, pixel_t);
    8383        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 *);
    8585} con_ops_t;
    8686
  • uspace/lib/c/include/io/console.h

    r166a1f57 red267bc  
    3939#include <io/concaps.h>
    4040#include <io/kbd_event.h>
     41#include <io/cons_event.h>
    4142#include <io/keycode.h>
    4243#include <async.h>
     
    8283extern void console_cursor_visibility(console_ctrl_t *, bool);
    8384extern 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 *,
     85extern bool console_get_event(console_ctrl_t *, cons_event_t *);
     86extern bool console_get_event_timeout(console_ctrl_t *, cons_event_t *,
    8687    suseconds_t *);
    8788
  • uspace/lib/clui/tinput.c

    r166a1f57 red267bc  
    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->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. */
     838static 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 */
     847static 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
    789855/** Read in one line of input.
    790856 *
     
    816882                console_flush(ti->console);
    817883               
    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))
    820886                        return EIO;
    821887               
    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;
    844898                }
    845899        }
  • uspace/lib/clui/tinput.h

    r166a1f57 red267bc  
    146146        /** @c true if user requested to abort interactive loop */
    147147        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;
    148154} tinput_t;
    149155
  • uspace/lib/gui/terminal.c

    r166a1f57 red267bc  
    7777static void term_set_rgb_color(con_srv_t *, pixel_t, pixel_t);
    7878static void term_set_cursor_visibility(con_srv_t *, bool);
    79 static int term_get_event(con_srv_t *, kbd_event_t *);
     79static int term_get_event(con_srv_t *, cons_event_t *);
    8080
    8181static con_ops_t con_ops = {
     
    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                                };
     
    579580}
    580581
    581 static int term_get_event(con_srv_t *srv, kbd_event_t *event)
     582static int term_get_event(con_srv_t *srv, cons_event_t *event)
    582583{
    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 = *kevent;
    588         free(kevent);
     586        cons_event_t *ev = list_get_instance(link, cons_event_t, link);
     587       
     588        *event = *ev;
     589        free(ev);
    589590        return EOK;
    590591}
     
    634635}
    635636
     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 */
    636652static void terminal_handle_keyboard_event(widget_t *widget,
    637653    kbd_event_t kbd_event)
    638654{
    639655        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
     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        }
    662681}
    663682
  • uspace/srv/hid/console/console.c

    r166a1f57 red267bc  
    129129static void cons_set_rgb_color(con_srv_t *, pixel_t, pixel_t);
    130130static void cons_set_cursor_visibility(con_srv_t *, bool);
    131 static int cons_get_event(con_srv_t *, kbd_event_t *);
     131static int cons_get_event(con_srv_t *, cons_event_t *);
    132132
    133133static con_ops_t con_ops = {
     
    490490}
    491491
    492 static int cons_get_event(con_srv_t *srv, kbd_event_t *event)
     492static int cons_get_event(con_srv_t *srv, cons_event_t *event)
    493493{
    494494        console_t *cons = srv_to_console(srv);
     
    496496        kbd_event_t *kevent = list_get_instance(link, kbd_event_t, link);
    497497       
    498         *event = *kevent;
     498        event->type = CEV_KEY;
     499        event->ev.key = *kevent;
    499500        free(kevent);
    500501        return EOK;
  • uspace/srv/hid/remcons/remcons.c

    r166a1f57 red267bc  
    8080static int remcons_get_size(con_srv_t *, sysarg_t *, sysarg_t *);
    8181static int remcons_get_color_cap(con_srv_t *, console_caps_t *);
    82 static int remcons_get_event(con_srv_t *, kbd_event_t *);
     82static int remcons_get_event(con_srv_t *, cons_event_t *);
    8383
    8484static con_ops_t con_ops = {
     
    185185}
    186186
    187 static int remcons_get_event(con_srv_t *srv, kbd_event_t *event)
    188 {
    189         telnet_user_t *user = srv_to_user(srv);
     187static 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;
    190191        int rc;
    191192
    192         rc = telnet_user_get_next_keyboard_event(user, event);
     193        rc = telnet_user_get_next_keyboard_event(user, &kevent);
    193194        if (rc != EOK) {
    194195                /* XXX What? */
     
    196197                return EOK;
    197198        }
     199
     200        event->type = CEV_KEY;
     201        event->ev.key = kevent;
    198202
    199203        return EOK;
Note: See TracChangeset for help on using the changeset viewer.