Changeset e89dc0b in mainline


Ignore:
Timestamp:
2019-05-15T18:53:09Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
9fe1635
Parents:
8f16ede6
Message:

implementing IPC for changing kb layout

Location:
uspace
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/ipc/input.h

    r8f16ede6 re89dc0b  
    3939
    4040typedef enum {
    41         INPUT_ACTIVATE = IPC_FIRST_USER_METHOD
     41        INPUT_ACTIVATE = IPC_FIRST_USER_METHOD,
     42        INPUT_CHANGE_LAYOUT
    4243} input_request_t;
    4344
  • uspace/srv/hid/input/input.c

    r8f16ede6 re89dc0b  
    5656#include <str.h>
    5757#include <str_error.h>
     58#include <dlfcn.h>
    5859
    5960#include "input.h"
     
    9798
    9899static FIBRIL_MUTEX_INITIALIZE(discovery_lock);
     100
     101static void layout_change(layout_ops_t *layout)
     102{
     103        list_foreach(kbd_devs, link, kbd_dev_t, kdev) {
     104                layout_t *ret = layout_create(layout);
     105                if (ret != NULL) {
     106                        layout_destroy(kdev->active_layout);
     107                        kdev->active_layout = ret;
     108                }
     109        }
     110}
     111
     112static void layout_load(const char *layout_name)
     113{
     114/*
     115        async_get_call(ipc_call_t *);
     116ipc_get_arg1(ipc_call_t *);
     117*/     
     118        const char *prefix = "/lib/layouts/";
     119        const char *suffix = ".so";
     120        size_t length = 1;
     121        length += str_size(prefix);
     122        length += str_size(suffix);
     123        length += str_size(layout_name);
     124        char *path = malloc(sizeof(char) * length);
     125
     126        if (path == NULL) {
     127                printf("%s: Error allocating layout path. Out of memory.\n", NAME);
     128                return;
     129        }
     130
     131        str_append(path, length, prefix);
     132        str_append(path, length, layout_name);
     133        str_append(path, length, suffix);
     134
     135        void *handle = dlopen(path, 0);
     136        if (handle == NULL) {
     137                printf("%s: Keyboard layout could not be found.\n", NAME);
     138                return;
     139        }
     140
     141        layout_ops_t (*get_layout)(void) = dlsym(handle, "dl_get_constant");
     142
     143        if (get_layout == NULL) {
     144                printf("%s: Keyboard layout constructor could not be found.\n", NAME);
     145                return;
     146        }
     147
     148        layout_active = get_layout();
     149        layout_change(&layout_active);
     150}
    99151
    100152static void *client_data_create(void)
     
    198250
    199251        if ((type == KEY_PRESS) && (kdev->mods & KM_LCTRL) && (key == KC_F1)) {
    200                 layout_destroy(kdev->active_layout);
    201                 kdev->active_layout = layout_create(&layout_default);
     252                layout_active = layout_default;
     253                layout_change(&layout_default);
    202254                return;
    203255        }
     
    326378                                async_answer_0(&call, EOK);
    327379                                break;
     380                        case INPUT_CHANGE_LAYOUT: {
     381                                char * layout_name = (char *)ipc_get_arg1(&call);
     382                                layout_load(layout_name);
     383                                free(layout_name);
     384                                break;
     385                        }
    328386                        default:
    329387                                async_answer_0(&call, EINVAL);
     
    359417        kdev->mods = KM_NUM_LOCK;
    360418        kdev->lock_keys = 0;
    361         kdev->active_layout = layout_create(&layout_default);
     419        kdev->active_layout = layout_create(&layout_active);
    362420
    363421        return kdev;
Note: See TracChangeset for help on using the changeset viewer.