Debian Codegraph @

src/x11/state.c

raw
1 /*
2 * Copyright © 2013 Ran Benita
3 * SPDX-License-Identifier: MIT
4 */
5
6 #include "config.h"
7
8 #include "x11-priv.h"
9
10 static bool
11 update_initial_state(struct xkb_state *state, xcb_connection_t *conn,
12 uint16_t device_id)
13 {
14 xcb_xkb_get_state_cookie_t cookie =
15 xcb_xkb_get_state(conn, device_id);
16 xcb_xkb_get_state_reply_t *reply =
17 xcb_xkb_get_state_reply(conn, cookie, NULL);
18
19 if (!reply)
20 return false;
21
22 xkb_state_update_mask(state,
23 reply->baseMods,
24 reply->latchedMods,
25 reply->lockedMods,
26 reply->baseGroup,
27 reply->latchedGroup,
28 reply->lockedGroup);
29
30 free(reply);
31 return true;
32 }
33
34 struct xkb_state *
35 xkb_x11_state_new_from_device(struct xkb_keymap *keymap,
36 xcb_connection_t *conn, int32_t device_id)
37 {
38 struct xkb_state *state;
39
40 if (device_id < 0 || device_id > 255) {
41 log_err_func(keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
42 "illegal device ID: %"PRId32, device_id);
43 return NULL;
44 }
45
46 state = xkb_state_new(keymap);
47 if (!state)
48 return NULL;
49
50 if (!update_initial_state(state, conn, device_id)) {
51 xkb_state_unref(state);
52 return NULL;
53 }
54
55 return state;
56 }