Changeset 07b7c48 in mainline


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

Extend console library API to support different event types.

Location:
uspace
Files:
1 added
17 edited

Legend:

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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    182182int main(int argc, char *argv[])
    183183{
    184         kbd_event_t ev;
     184        cons_event_t ev;
     185        kbd_event_t *kev;
    185186        bool new_file;
    186187        int rc;
     
    245246
    246247        while (!done) {
    247                 console_get_kbd_event(con, &ev);
     248                console_get_event(con, &ev);
    248249                pane.rflags = 0;
    249250
    250                 if (ev.type == KEY_PRESS) {
     251                if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) {
     252                        kev = &ev.ev.key;
     253
    251254                        /* 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);
     255                        if (((kev->mods & KM_ALT) == 0) &&
     256                            ((kev->mods & KM_SHIFT) == 0) &&
     257                             (kev->mods & KM_CTRL) != 0) {
     258                                key_handle_ctrl(kev);
     259                        } else if (((kev->mods & KM_ALT) == 0) &&
     260                            ((kev->mods & KM_CTRL) == 0) &&
     261                             (kev->mods & KM_SHIFT) != 0) {
     262                                key_handle_shift(kev);
     263                        } else if (((kev->mods & KM_ALT) == 0) &&
     264                            ((kev->mods & KM_CTRL) != 0) &&
     265                             (kev->mods & KM_SHIFT) != 0) {
     266                                key_handle_shift_ctrl(kev);
     267                        } else if ((kev->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
     268                                key_handle_unmod(kev);
    266269                        }
    267270                }
     
    592595static char *prompt(char const *prompt, char const *init_value)
    593596{
    594         kbd_event_t ev;
     597        cons_event_t ev;
     598        kbd_event_t *kev;
    595599        char *str;
    596600        wchar_t buffer[INFNAME_MAX_LEN + 1];
     
    612616
    613617        while (!done) {
    614                 console_get_kbd_event(con, &ev);
    615 
    616                 if (ev.type == KEY_PRESS) {
     618                console_get_event(con, &ev);
     619
     620                if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) {
     621                        kev = &ev.ev.key;
     622
    617623                        /* Handle key press. */
    618                         if (((ev.mods & KM_ALT) == 0) &&
    619                              (ev.mods & KM_CTRL) != 0) {
     624                        if (((kev->mods & KM_ALT) == 0) &&
     625                             (kev->mods & KM_CTRL) != 0) {
    620626                                ;
    621                         } else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) {
    622                                 switch (ev.key) {
     627                        } else if ((kev->mods & (KM_CTRL | KM_ALT)) == 0) {
     628                                switch (kev->key) {
    623629                                case KC_ESCAPE:
    624630                                        return NULL;
     
    634640                                        break;
    635641                                default:
    636                                         if (ev.c >= 32 && nc < max_len) {
    637                                                 putchar(ev.c);
     642                                        if (kev->c >= 32 && nc < max_len) {
     643                                                putchar(kev->c);
    638644                                                console_flush(con);
    639                                                 buffer[nc++] = ev.c;
     645                                                buffer[nc++] = kev->c;
    640646                                        }
    641647                                        break;
  • uspace/app/mkbd/main.c

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    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/console.c

    rbc4bf97 r07b7c48  
    154154}
    155155
    156 bool console_get_kbd_event(console_ctrl_t *ctrl, kbd_event_t *event)
     156bool console_get_event(console_ctrl_t *ctrl, cons_event_t *event)
    157157{
    158158        if (ctrl->input_aid == 0) {
     
    171171                }
    172172               
    173                 event->type = type;
    174                 event->key = key;
    175                 event->mods = mods;
    176                 event->c = c;
     173                event->type = CEV_KEY;
     174                event->ev.key.type = type;
     175                event->ev.key.key = key;
     176                event->ev.key.mods = mods;
     177                event->ev.key.c = c;
    177178        } else {
    178179                sysarg_t retval;
     
    186187                }
    187188               
    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);
     189                event->type = CEV_KEY;
     190                event->ev.key.type = IPC_GET_ARG1(ctrl->input_call);
     191                event->ev.key.key = IPC_GET_ARG2(ctrl->input_call);
     192                event->ev.key.mods = IPC_GET_ARG3(ctrl->input_call);
     193                event->ev.key.c = IPC_GET_ARG4(ctrl->input_call);
    192194        }
    193195       
     
    195197}
    196198
    197 bool console_get_kbd_event_timeout(console_ctrl_t *ctrl, kbd_event_t *event,
     199bool console_get_event_timeout(console_ctrl_t *ctrl, cons_event_t *event,
    198200    suseconds_t *timeout)
    199201{
     
    223225        }
    224226       
    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);
     227        event->type = CEV_KEY;
     228        event->ev.key.type = IPC_GET_ARG1(ctrl->input_call);
     229        event->ev.key.key = IPC_GET_ARG2(ctrl->input_call);
     230        event->ev.key.mods = IPC_GET_ARG3(ctrl->input_call);
     231        event->ev.key.c = IPC_GET_ARG4(ctrl->input_call);
    229232       
    230233        /* Update timeout */
  • uspace/lib/c/include/io/console.h

    rbc4bf97 r07b7c48  
    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

    rbc4bf97 r07b7c48  
    816816                console_flush(ti->console);
    817817               
    818                 kbd_event_t ev;
    819                 if (!console_get_kbd_event(ti->console, &ev))
     818                cons_event_t ev;
     819                if (!console_get_event(ti->console, &ev))
    820820                        return EIO;
    821821               
    822                 if (ev.type != KEY_PRESS)
     822                if (ev.type != CEV_KEY || ev.ev.key.type != KEY_PRESS)
    823823                        continue;
    824824               
    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 >= ' ') {
     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 >= ' ') {
    842844                        tinput_sel_delete(ti);
    843                         tinput_insert_char(ti, ev.c);
     845                        tinput_insert_char(ti, kev->c);
    844846                }
    845847        }
Note: See TracChangeset for help on using the changeset viewer.