Changeset a76ba5f3 in mainline for uspace/lib/c/generic/io/input.c


Ignore:
Timestamp:
2020-12-31T21:27:13Z (4 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
6a208fc
Parents:
19f60a38
git-author:
Matthieu Riolo <matthieu.riolo@…> (2019-10-07 18:10:19)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-12-31 21:27:13)
Message:

Relocating IPC calls in the layout to io/input

The IPC calls for changing the layout was located in
the application layout. Now they have been relocated
into the library io/input. This commit also changes
the behaviour of layout when called without any
parameters (no error status is returned)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/input.c

    r19f60a38 ra76ba5f3  
    4242#include <ipc/input.h>
    4343#include <stdlib.h>
     44#include <str.h>
    4445
    4546static void input_cb_conn(ipc_call_t *icall, void *arg);
     
    202203}
    203204
     205/**
     206 * Retrieves the active keyboard layout
     207 * @param sess Active session to the input server
     208 * @param layout The name of the currently active layout,
     209 *        needs to be freed by the caller
     210 * @return EOK if sucessful or the corresponding error code.
     211 *         If a failure occurs the param layout is already freed
     212 */
     213errno_t input_layout_get(async_sess_t *sess, char **layout)
     214{
     215        errno_t rc;
     216        ipc_call_t call;
     217        async_exch_t *exch = async_exchange_begin(sess);
     218        aid_t mid = async_send_0(exch, INPUT_GET_LAYOUT, &call);
     219        async_wait_for(mid, &rc);
     220
     221        if (rc != EOK) {
     222                goto error;
     223        }
     224
     225        size_t length = ipc_get_arg1(&call);
     226
     227        *layout = malloc(length * sizeof(char *));
     228        if (layout == NULL) {
     229                rc = ENOMEM;
     230                free(*layout);
     231                goto error;
     232        }
     233
     234        rc = async_data_read_start(exch, *layout, length);
     235
     236        if (rc != EOK)
     237                free(*layout);
     238
     239error:
     240        async_exchange_end(exch);
     241        return rc;
     242}
     243
     244/**
     245 * Changes the keyboard layout
     246 * @param sess Active session to the input server
     247 * @param layout The name of the layout which should be activated
     248 * @return EOK if sucessful or the corresponding error code.
     249 */
     250errno_t input_layout_set(async_sess_t *sess, const char *layout)
     251{
     252        errno_t rc;
     253        ipc_call_t call;
     254        async_exch_t *exch = async_exchange_begin(sess);
     255
     256        aid_t mid = async_send_0(exch, INPUT_CHANGE_LAYOUT, &call);
     257        rc = async_data_write_start(exch, layout, str_size(layout));
     258
     259        if (rc == EOK)
     260                async_wait_for(mid, &rc);
     261
     262        async_exchange_end(exch);
     263        return rc;
     264}
     265
    204266/** @}
    205267 */
Note: See TracChangeset for help on using the changeset viewer.