Changeset 11e394f in mainline for uspace/srv/hid/input/input.c


Ignore:
Timestamp:
2020-12-31T21:19:51Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
19f60a38
Parents:
e037cf37
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-07-21 21:23:33)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-12-31 21:19:51)
Message:

Keyboard layouts can now identify itself

The structure layout_ops_t has been extended with the
parameter name which contains the name of the kb layout

File:
1 edited

Legend:

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

    re037cf37 r11e394f  
    6666#include "serial.h"
    6767
    68 #define NUM_LAYOUTS 5
     68static layout_ops_t *layout_active = &us_qwerty_ops;
     69
     70#define NUM_LAYOUTS  5
    6971
    7072static layout_ops_t *layout[NUM_LAYOUTS] = {
     
    107109
    108110static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
     111
     112/* changes all kb devices to the given layout */
     113static void layout_change(layout_ops_t *layout)
     114{
     115        list_foreach(kbd_devs, link, kbd_dev_t, kdev) {
     116                layout_t *ret = layout_create(layout);
     117                if (ret != NULL) {
     118                        layout_destroy(kdev->active_layout);
     119                        kdev->active_layout = ret;
     120                }
     121        }
     122}
     123
     124/* similiar like layout_change but takes as an argument the name of the layout */
     125static errno_t layout_load(const char *layout_name)
     126{
     127        /* TODO: change this into a loader for kb layout maps */
     128        for (int i = 0; i < NUM_LAYOUTS; i++) {
     129                if (str_cmp(layout[i]->name, layout_name) == 0) {
     130                        layout_active = layout[i];
     131                        layout_change(layout_active);
     132                        return EOK;
     133                }
     134        }
     135
     136        return ENOTSUP;
     137}
     138
     139/* Handler for IPC call INPUT_CHANGE_LAYOUT */
     140static void client_change_layout_handler(ipc_call_t *call)
     141{
     142        void *layout_name;
     143        errno_t ret = async_data_write_accept(&layout_name, true, 0, 0, 0, 0);
     144        if (ret != EOK) {
     145                async_answer_0(call, ret);
     146                return;
     147        }
     148
     149        errno_t retval = layout_load((char *)layout_name);
     150        free(layout_name);
     151        async_answer_0(call, retval);
     152}
     153
     154/* Handler for IPC call INPUT_GET_LAYOUT */
     155static void client_get_layout_handler(ipc_call_t *call)
     156{
     157        const char *layout_name = layout_active->name;
     158        size_t length = str_size(layout_name) + 1;
     159        ipc_call_t id;
     160
     161        async_answer_1(call, EOK, length);
     162        if (async_data_read_receive(&id, NULL)) {
     163                async_data_read_finalize(&id, layout_name, length);
     164        }
     165}
    109166
    110167static void *client_data_create(void)
     
    212269                switch (key) {
    213270                case KC_F1:
    214                         layout_destroy(kdev->active_layout);
    215                         kdev->active_layout = layout_create(layout[0]);
     271                        layout_change(layout[0]);
    216272                        break;
    217273                case KC_F2:
    218                         layout_destroy(kdev->active_layout);
    219                         kdev->active_layout = layout_create(layout[1]);
     274                        layout_change(layout[1]);
    220275                        break;
    221276                case KC_F3:
    222                         layout_destroy(kdev->active_layout);
    223                         kdev->active_layout = layout_create(layout[2]);
     277                        layout_change(layout[2]);
    224278                        break;
    225279                case KC_F4:
    226                         layout_destroy(kdev->active_layout);
    227                         kdev->active_layout = layout_create(layout[3]);
     280                        layout_change(layout[3]);
    228281                        break;
    229282                case KC_F5:
    230                         layout_destroy(kdev->active_layout);
    231                         kdev->active_layout = layout_create(layout[4]);
     283                        layout_change(layout[4]);
    232284                        break;
    233285                default: // default: is here to avoid compiler warning about unhandled cases
     
    367419                                async_answer_0(&call, EOK);
    368420                                break;
     421                        case INPUT_CHANGE_LAYOUT:
     422                                client_change_layout_handler(&call);
     423                                break;
     424                        case INPUT_GET_LAYOUT:
     425                                client_get_layout_handler(&call);
     426                                break;
    369427                        default:
    370428                                async_answer_0(&call, EINVAL);
     
    400458        kdev->mods = KM_NUM_LOCK;
    401459        kdev->lock_keys = 0;
    402         kdev->active_layout = layout_create(layout[0]);
     460        kdev->active_layout = layout_create(layout_active);
    403461
    404462        return kdev;
Note: See TracChangeset for help on using the changeset viewer.