Changeset 11e394f in mainline


Ignore:
Timestamp:
2020-12-31T21:19:51Z (3 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

Location:
uspace
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/init/init.c

    re037cf37 r11e394f  
    5050#include <vfs/vfs.h>
    5151#include <vol.h>
     52#include <ipc/services.h>
    5253#include "untar.h"
    5354#include "init.h"
     
    7071#define SRV_DISPLAY  "/srv/hid/display"
    7172
    72 #define HID_INPUT              "hid/input"
     73#define HID_INPUT              SERVICE_NAME_HID_INPUT
    7374#define HID_OUTPUT             "hid/output"
    7475
  • uspace/lib/c/include/ipc/input.h

    re037cf37 r11e394f  
    3939
    4040typedef enum {
    41         INPUT_ACTIVATE = IPC_FIRST_USER_METHOD
     41        INPUT_ACTIVATE = IPC_FIRST_USER_METHOD,
     42        INPUT_CHANGE_LAYOUT,
     43        INPUT_GET_LAYOUT
    4244} input_request_t;
    4345
  • uspace/lib/c/include/ipc/services.h

    re037cf37 r11e394f  
    5959#define SERVICE_NAME_INET     "net/inet"
    6060#define SERVICE_NAME_IPC_TEST "ipc-test"
     61#define SERVICE_NAME_HID_INPUT    "hid/input"
    6162#define SERVICE_NAME_NETCONF  "net/netconf"
    6263#define SERVICE_NAME_UDP      "net/udp"
  • 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;
  • uspace/srv/hid/input/input.h

    re037cf37 r11e394f  
    4141#include <stdbool.h>
    4242#include <async.h>
     43#include <ipc/services.h>
    4344
    44 #define NAME  "input"
     45#define NAME SERVICE_NAME_HID_INPUT
    4546
    4647extern bool irc_service;
  • uspace/srv/hid/input/layout.h

    re037cf37 r11e394f  
    5454        void (*destroy)(layout_t *);
    5555        char32_t (*parse_ev)(layout_t *, kbd_event_t *);
     56        const char *name;
    5657} layout_ops_t;
    5758
  • uspace/srv/hid/input/layout/ar.c

    re037cf37 r11e394f  
    4949        .create = ar_create,
    5050        .destroy = ar_destroy,
    51         .parse_ev = ar_parse_ev
     51        .parse_ev = ar_parse_ev,
     52        .name = "ar"
    5253};
    5354
  • uspace/srv/hid/input/layout/cz.c

    re037cf37 r11e394f  
    6060        .create = cz_create,
    6161        .destroy = cz_destroy,
    62         .parse_ev = cz_parse_ev
     62        .parse_ev = cz_parse_ev,
     63        .name = "cz"
    6364};
    6465
  • uspace/srv/hid/input/layout/fr_azerty.c

    re037cf37 r11e394f  
    4848        .create = fr_azerty_create,
    4949        .destroy = fr_azerty_destroy,
    50         .parse_ev = fr_azerty_parse_ev
     50        .parse_ev = fr_azerty_parse_ev,
     51        .name = "fr_azerty"
    5152};
    5253
  • uspace/srv/hid/input/layout/us_dvorak.c

    re037cf37 r11e394f  
    4848        .create = us_dvorak_create,
    4949        .destroy = us_dvorak_destroy,
    50         .parse_ev = us_dvorak_parse_ev
     50        .parse_ev = us_dvorak_parse_ev,
     51        .name = "us_dvorak"
    5152};
    5253
  • uspace/srv/hid/input/layout/us_qwerty.c

    re037cf37 r11e394f  
    4848        .create = us_qwerty_create,
    4949        .destroy = us_qwerty_destroy,
    50         .parse_ev = us_qwerty_parse_ev
     50        .parse_ev = us_qwerty_parse_ev,
     51        .name = "us_qwerty"
    5152};
    5253
Note: See TracChangeset for help on using the changeset viewer.