master
h 115 lines 2.77 KB
Raw
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 * This function drops events with key codes outside the defined range.
56 *
57 * @kbd: state tracker state.
58 * @lnx: the key pressed or released.
59 * @down: true for key down events, false otherwise.
60 */
61 void qkbd_state_key_event(QKbdState *kbd, unsigned int lnx, bool down);
62
63 /**
64 * qkbd_state_set_delay: set key press delay.
65 *
66 * When set the specified delay will be added after each key event,
67 * using qemu_input_event_send_key_delay().
68 *
69 * @kbd: state tracker state.
70 * @delay_ms: the delay in milliseconds.
71 */
72 void qkbd_state_set_delay(QKbdState *kbd, int delay_ms);
73
74 /**
75 * qkbd_state_key_get: get key state.
76 *
77 * Returns true when the key code is in the defined range and the key is down.
78 *
79 * @kbd: state tracker state.
80 * @lnx: the key to query.
81 */
82 bool qkbd_state_key_get(QKbdState *kbd, unsigned int lnx);
83
84 /**
85 * qkbd_state_modifier_get: get modifier state.
86 *
87 * Returns true when the modifier is active.
88 *
89 * @kbd: state tracker state.
90 * @mod: the modifier to query.
91 */
92 bool qkbd_state_modifier_get(QKbdState *kbd, QKbdModifier mod);
93
94 /**
95 * qkbd_state_lift_all_keys: lift all pressed keys.
96 *
97 * This sends key up events to the guest for all keys which are in
98 * down state.
99 *
100 * @kbd: state tracker state.
101 */
102 void qkbd_state_lift_all_keys(QKbdState *kbd);
103
104 /**
105 * qkbd_state_switch_console: Switch console.
106 *
107 * This sends key up events to the previous console for all keys which are in
108 * down state to prevent keys being stuck, and remembers the new console.
109 *
110 * @kbd: state tracker state.
111 * @con: new QemuConsole for this state tracker.
112 */
113 void qkbd_state_switch_console(QKbdState *kbd, QemuConsole *con);
114
115 #endif /* QEMU_UI_KBD_STATE_H */