diff options
Diffstat (limited to 'include/sway/input_state.h')
-rw-r--r-- | include/sway/input_state.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/include/sway/input_state.h b/include/sway/input_state.h new file mode 100644 index 00000000..903301fb --- /dev/null +++ b/include/sway/input_state.h | |||
@@ -0,0 +1,102 @@ | |||
1 | #ifndef _SWAY_KEY_STATE_H | ||
2 | #define _SWAY_KEY_STATE_H | ||
3 | #include <stdbool.h> | ||
4 | #include <stdint.h> | ||
5 | #include "container.h" | ||
6 | |||
7 | /* Keyboard state */ | ||
8 | |||
9 | // returns true if key has been pressed, otherwise false | ||
10 | bool check_key(uint32_t key_sym, uint32_t key_code); | ||
11 | |||
12 | // returns true if key_sym matches latest released key. | ||
13 | bool check_released_key(uint32_t key_sym); | ||
14 | |||
15 | // sets a key as pressed | ||
16 | void press_key(uint32_t key_sym, uint32_t key_code); | ||
17 | |||
18 | // unsets a key as pressed | ||
19 | void release_key(uint32_t key_sym, uint32_t key_code); | ||
20 | |||
21 | |||
22 | /* Pointer state */ | ||
23 | |||
24 | enum pointer_values { | ||
25 | M_LEFT_CLICK = 272, | ||
26 | M_RIGHT_CLICK = 273, | ||
27 | M_SCROLL_CLICK = 274, | ||
28 | M_SCROLL_UP = 275, | ||
29 | M_SCROLL_DOWN = 276, | ||
30 | }; | ||
31 | |||
32 | enum pointer_mode { | ||
33 | // Target | ||
34 | M_FLOATING = 1, | ||
35 | M_TILING = 2, | ||
36 | // Action | ||
37 | M_DRAGGING = 4, | ||
38 | M_RESIZING = 8, | ||
39 | }; | ||
40 | |||
41 | struct pointer_button_state { | ||
42 | bool held; | ||
43 | // state at the point it was pressed | ||
44 | int x, y; | ||
45 | swayc_t *view; | ||
46 | }; | ||
47 | |||
48 | extern struct pointer_state { | ||
49 | // mouse clicks | ||
50 | struct pointer_button_state left; | ||
51 | struct pointer_button_state right; | ||
52 | struct pointer_button_state scroll; | ||
53 | |||
54 | // change in pointer position | ||
55 | struct { | ||
56 | int x, y; | ||
57 | } delta; | ||
58 | |||
59 | // view pointer is currently over | ||
60 | swayc_t *view; | ||
61 | |||
62 | // Pointer mode | ||
63 | int mode; | ||
64 | } pointer_state; | ||
65 | |||
66 | enum modifier_state { | ||
67 | MOD_STATE_UNCHANGED = 0, | ||
68 | MOD_STATE_PRESSED = 1, | ||
69 | MOD_STATE_RELEASED = 2 | ||
70 | }; | ||
71 | |||
72 | void pointer_position_set(struct wlc_origin *new_origin, bool force_focus); | ||
73 | void center_pointer_on(swayc_t *view); | ||
74 | |||
75 | // on button release unset mode depending on the button. | ||
76 | // on button press set mode conditionally depending on the button | ||
77 | void pointer_mode_set(uint32_t button, bool condition); | ||
78 | |||
79 | // Update mode in mouse motion | ||
80 | void pointer_mode_update(void); | ||
81 | |||
82 | // Reset mode on any keypress; | ||
83 | void pointer_mode_reset(void); | ||
84 | |||
85 | void input_init(void); | ||
86 | |||
87 | /** | ||
88 | * Check if state of mod changed from current state to new_state. | ||
89 | * | ||
90 | * Returns MOD_STATE_UNCHANGED if the state didn't change, MOD_STATE_PRESSED if | ||
91 | * the state changed to pressed and MOD_STATE_RELEASED if the state changed to | ||
92 | * released. | ||
93 | */ | ||
94 | uint32_t modifier_state_changed(uint32_t new_state, uint32_t mod); | ||
95 | |||
96 | /** | ||
97 | * Update the current modifiers state to new_state. | ||
98 | */ | ||
99 | void modifiers_state_update(uint32_t new_state); | ||
100 | |||
101 | #endif | ||
102 | |||