Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-5.2-pull-request...
[qemu.git] / include / ui / kbd-state.h
1 /*
2 * This work is licensed under the terms of the GNU GPL, version 2 or
3 * (at your option) any later version. See the COPYING file in the
4 * top-level directory.
5 */
6
7 #ifndef QEMU_UI_KBD_STATE_H
8 #define QEMU_UI_KBD_STATE_H
9
10 #include "qapi/qapi-types-ui.h"
11
12 typedef enum QKbdModifier QKbdModifier;
13
14 enum QKbdModifier {
15 QKBD_MOD_NONE = 0,
16
17 QKBD_MOD_SHIFT,
18 QKBD_MOD_CTRL,
19 QKBD_MOD_ALT,
20 QKBD_MOD_ALTGR,
21
22 QKBD_MOD_NUMLOCK,
23 QKBD_MOD_CAPSLOCK,
24
25 QKBD_MOD__MAX
26 };
27
28 typedef struct QKbdState QKbdState;
29
30 /**
31 * qkbd_state_init: init keyboard state tracker.
32 *
33 * Allocates and initializes keyboard state struct.
34 *
35 * @con: QemuConsole for this state tracker. Gets passed down to
36 * qemu_input_*() functions when sending key events to the guest.
37 */
38 QKbdState *qkbd_state_init(QemuConsole *con);
39
40 /**
41 * qkbd_state_free: free keyboard tracker state.
42 *
43 * @kbd: state tracker state.
44 */
45 void qkbd_state_free(QKbdState *kbd);
46
47 /**
48 * qkbd_state_key_event: process key event.
49 *
50 * Update keyboard state, send event to the guest.
51 *
52 * This function takes care to not send suspious events (keyup event
53 * for a key not pressed for example).
54 *
55 * @kbd: state tracker state.
56 * @qcode: the key pressed or released.
57 * @down: true for key down events, false otherwise.
58 */
59 void qkbd_state_key_event(QKbdState *kbd, QKeyCode qcode, bool down);
60
61 /**
62 * qkbd_state_set_delay: set key press delay.
63 *
64 * When set the specified delay will be added after each key event,
65 * using qemu_input_event_send_key_delay().
66 *
67 * @kbd: state tracker state.
68 * @delay_ms: the delay in miliseconds.
69 */
70 void qkbd_state_set_delay(QKbdState *kbd, int delay_ms);
71
72 /**
73 * qkbd_state_key_get: get key state.
74 *
75 * Returns true when the key is down.
76 *
77 * @kbd: state tracker state.
78 * @qcode: the key to query.
79 */
80 bool qkbd_state_key_get(QKbdState *kbd, QKeyCode qcode);
81
82 /**
83 * qkbd_state_modifier_get: get modifier state.
84 *
85 * Returns true when the modifier is active.
86 *
87 * @kbd: state tracker state.
88 * @mod: the modifier to query.
89 */
90 bool qkbd_state_modifier_get(QKbdState *kbd, QKbdModifier mod);
91
92 /**
93 * qkbd_state_lift_all_keys: lift all pressed keys.
94 *
95 * This sends key up events to the guest for all keys which are in
96 * down state.
97 *
98 * @kbd: state tracker state.
99 */
100 void qkbd_state_lift_all_keys(QKbdState *kbd);
101
102 #endif /* QEMU_UI_KBD_STATE_H */