Changeset 2f7a564 in mainline for uspace/srv/hid/input/generic/input.c


Ignore:
Timestamp:
2011-06-13T22:05:30Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ef15fbb
Parents:
a07a454
Message:

Make key lock/modifier state as well as layout state per-device.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/generic/input.c

    ra07a454 r2f7a564  
    7070int client_phone = -1;
    7171
    72 /** Currently active modifiers. */
    73 static unsigned mods = KM_NUM_LOCK;
    74 
    75 /** Currently pressed lock keys. We track these to tackle autorepeat. */
    76 static unsigned lock_keys;
    77 
    7872/** List of keyboard devices */
    7973static link_t kbd_devs;
     
    8478#define NUM_LAYOUTS 3
    8579
    86 static layout_op_t *layout[NUM_LAYOUTS] = {
    87         &us_qwerty_op,
    88         &us_dvorak_op,
    89         &cz_op
     80static layout_ops_t *layout[NUM_LAYOUTS] = {
     81        &us_qwerty_ops,
     82        &us_dvorak_ops,
     83        &cz_ops
    9084};
    91 
    92 static int active_layout = 0;
    9385
    9486void kbd_push_scancode(kbd_dev_t *kdev, int scancode)
     
    115107        if (mod_mask != 0) {
    116108                if (type == KEY_PRESS)
    117                         mods = mods | mod_mask;
     109                        kdev->mods = kdev->mods | mod_mask;
    118110                else
    119                         mods = mods & ~mod_mask;
     111                        kdev->mods = kdev->mods & ~mod_mask;
    120112        }
    121113
     
    134126                         * up the lock state.
    135127                         */
    136                         mods = mods ^ (mod_mask & ~lock_keys);
    137                         lock_keys = lock_keys | mod_mask;
     128                        kdev->mods = kdev->mods ^ (mod_mask & ~kdev->lock_keys);
     129                        kdev->lock_keys = kdev->lock_keys | mod_mask;
    138130
    139131                        /* Update keyboard lock indicator lights. */
    140                         (*kdev->ctl_ops->set_ind)(kdev, mods);
     132                        (*kdev->ctl_ops->set_ind)(kdev, kdev->mods);
    141133                } else {
    142                         lock_keys = lock_keys & ~mod_mask;
     134                        kdev->lock_keys = kdev->lock_keys & ~mod_mask;
    143135                }
    144136        }
     
    148140        printf("keycode: %u\n", key);
    149141*/
    150         if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     142        if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) &&
    151143                key == KC_F1) {
    152                 active_layout = 0;
    153                 layout[active_layout]->reset();
     144                layout_destroy(kdev->active_layout);
     145                kdev->active_layout = layout_create(layout[0]);
    154146                return;
    155147        }
    156148
    157         if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     149        if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) &&
    158150                key == KC_F2) {
    159                 active_layout = 1;
    160                 layout[active_layout]->reset();
     151                layout_destroy(kdev->active_layout);
     152                kdev->active_layout = layout_create(layout[1]);
    161153                return;
    162154        }
    163155
    164         if (type == KEY_PRESS && (mods & KM_LCTRL) &&
     156        if (type == KEY_PRESS && (kdev->mods & KM_LCTRL) &&
    165157                key == KC_F3) {
    166                 active_layout = 2;
    167                 layout[active_layout]->reset();
     158                layout_destroy(kdev->active_layout);
     159                kdev->active_layout = layout_create(layout[2]);
    168160                return;
    169161        }
     
    171163        ev.type = type;
    172164        ev.key = key;
    173         ev.mods = mods;
    174 
    175         ev.c = layout[active_layout]->parse_ev(&ev);
     165        ev.mods = kdev->mods;
     166
     167        ev.c = layout_parse_ev(kdev->active_layout, &ev);
    176168
    177169        async_obsolete_msg_4(client_phone, INPUT_EVENT, ev.type, ev.key, ev.mods, ev.c);
     
    223215}
    224216
     217static kbd_dev_t *kbd_dev_new(void)
     218{
     219        kbd_dev_t *kdev;
     220
     221        kdev = calloc(1, sizeof(kbd_dev_t));
     222        if (kdev == NULL) {
     223                printf(NAME ": Allocating keyboard device. Out of memory.\n");
     224                return NULL;
     225        }
     226
     227        link_initialize(&kdev->kbd_devs);
     228
     229        kdev->mods = KM_NUM_LOCK;
     230        kdev->lock_keys = 0;
     231        kdev->active_layout = layout_create(layout[0]);
     232
     233        return kdev;
     234}
     235
    225236/** Add new legacy keyboard device. */
    226237static void kbd_add_dev(kbd_port_ops_t *port, kbd_ctl_ops_t *ctl)
     
    228239        kbd_dev_t *kdev;
    229240
    230         kdev = malloc(sizeof(kbd_dev_t));
    231         if (kdev == NULL) {
    232                 printf(NAME ": Failed adding keyboard device. Out of memory.\n");
     241        kdev = kbd_dev_new();
     242        if (kdev == NULL)
    233243                return;
    234         }
    235 
    236         link_initialize(&kdev->kbd_devs);
    237         kdev->dev_path = NULL;
     244
    238245        kdev->port_ops = port;
    239246        kdev->ctl_ops = ctl;
     247        kdev->dev_path = NULL;
    240248
    241249        /* Initialize port driver. */
     
    263271        kbd_dev_t *kdev;
    264272
    265         kdev = malloc(sizeof(kbd_dev_t));
    266         if (kdev == NULL) {
    267                 printf(NAME ": Failed adding keyboard device. Out of memory.\n");
     273        kdev = kbd_dev_new();
     274        if (kdev == NULL)
    268275                return -1;
    269         }
    270 
    271         link_initialize(&kdev->kbd_devs);
     276
    272277        kdev->dev_path = dev_path;
    273278        kdev->port_ops = NULL;
     
    435440        kbd_add_legacy_devs();
    436441
    437         /* Initialize (reset) layout. */
    438         layout[active_layout]->reset();
    439442       
    440443        /* Register driver */
Note: See TracChangeset for help on using the changeset viewer.