diff options
author | Florian Franzen <Florian.Franzen@gmail.com> | 2022-04-23 10:27:47 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-05-30 12:20:43 +0200 |
commit | cab2189aa64d04ba79dc2cbf19400435b47cdbd2 (patch) | |
tree | 450ac51fbc75c73ed1dc6728bc05b08366ace785 /include | |
parent | Add a Hindi (हिन्दी) translation to the README (diff) | |
download | sway-cab2189aa64d04ba79dc2cbf19400435b47cdbd2.tar.gz sway-cab2189aa64d04ba79dc2cbf19400435b47cdbd2.tar.zst sway-cab2189aa64d04ba79dc2cbf19400435b47cdbd2.zip |
sway: add bindgesture command
Co-authored-by: Michael Weiser <michael.weiser@gmx.de>
Diffstat (limited to 'include')
-rw-r--r-- | include/gesture.h | 104 | ||||
-rw-r--r-- | include/stringop.h | 1 | ||||
-rw-r--r-- | include/sway/commands.h | 2 | ||||
-rw-r--r-- | include/sway/config.h | 18 | ||||
-rw-r--r-- | include/sway/input/cursor.h | 4 | ||||
-rw-r--r-- | include/sway/input/seat.h | 35 |
6 files changed, 161 insertions, 3 deletions
diff --git a/include/gesture.h b/include/gesture.h new file mode 100644 index 00000000..9c6b0f91 --- /dev/null +++ b/include/gesture.h | |||
@@ -0,0 +1,104 @@ | |||
1 | #ifndef _SWAY_GESTURE_H | ||
2 | #define _SWAY_GESTURE_H | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | #include <stdint.h> | ||
6 | |||
7 | /** | ||
8 | * A gesture type used in binding. | ||
9 | */ | ||
10 | enum gesture_type { | ||
11 | GESTURE_TYPE_NONE = 0, | ||
12 | GESTURE_TYPE_HOLD, | ||
13 | GESTURE_TYPE_PINCH, | ||
14 | GESTURE_TYPE_SWIPE, | ||
15 | }; | ||
16 | |||
17 | // Turns single type enum value to constant string representation. | ||
18 | const char *gesture_type_string(enum gesture_type direction); | ||
19 | |||
20 | // Value to use to accept any finger count | ||
21 | extern const uint8_t GESTURE_FINGERS_ANY; | ||
22 | |||
23 | /** | ||
24 | * A gesture direction used in binding. | ||
25 | */ | ||
26 | enum gesture_direction { | ||
27 | GESTURE_DIRECTION_NONE = 0, | ||
28 | // Directions based on delta x and y | ||
29 | GESTURE_DIRECTION_UP = 1 << 0, | ||
30 | GESTURE_DIRECTION_DOWN = 1 << 1, | ||
31 | GESTURE_DIRECTION_LEFT = 1 << 2, | ||
32 | GESTURE_DIRECTION_RIGHT = 1 << 3, | ||
33 | // Directions based on scale | ||
34 | GESTURE_DIRECTION_INWARD = 1 << 4, | ||
35 | GESTURE_DIRECTION_OUTWARD = 1 << 5, | ||
36 | // Directions based on rotation | ||
37 | GESTURE_DIRECTION_CLOCKWISE = 1 << 6, | ||
38 | GESTURE_DIRECTION_COUNTERCLOCKWISE = 1 << 7, | ||
39 | }; | ||
40 | |||
41 | // Turns single direction enum value to constant string representation. | ||
42 | const char *gesture_direction_string(enum gesture_direction direction); | ||
43 | |||
44 | /** | ||
45 | * Struct representing a pointer gesture | ||
46 | */ | ||
47 | struct gesture { | ||
48 | enum gesture_type type; | ||
49 | uint8_t fingers; | ||
50 | uint32_t directions; | ||
51 | }; | ||
52 | |||
53 | /** | ||
54 | * Parses gesture from <gesture>[:<fingers>][:<directions>] string. | ||
55 | * | ||
56 | * Return NULL on success, otherwise error message string | ||
57 | */ | ||
58 | char *gesture_parse(const char *input, struct gesture *output); | ||
59 | |||
60 | // Turns gesture into string representation | ||
61 | char *gesture_to_string(struct gesture *gesture); | ||
62 | |||
63 | // Check if gesture is of certain type and finger count. | ||
64 | bool gesture_check(struct gesture *target, | ||
65 | enum gesture_type type, uint8_t fingers); | ||
66 | |||
67 | // Check if a gesture target/binding is match by other gesture/input | ||
68 | bool gesture_match(struct gesture *target, | ||
69 | struct gesture *to_match, bool exact); | ||
70 | |||
71 | // Returns true if gesture are exactly the same | ||
72 | bool gesture_equal(struct gesture *a, struct gesture *b); | ||
73 | |||
74 | // Compare distance between two matched target gestures. | ||
75 | int8_t gesture_compare(struct gesture *a, struct gesture *b); | ||
76 | |||
77 | // Small helper struct to track gestures over time | ||
78 | struct gesture_tracker { | ||
79 | enum gesture_type type; | ||
80 | uint8_t fingers; | ||
81 | double dx, dy; | ||
82 | double scale; | ||
83 | double rotation; | ||
84 | }; | ||
85 | |||
86 | // Begin gesture tracking | ||
87 | void gesture_tracker_begin(struct gesture_tracker *tracker, | ||
88 | enum gesture_type type, uint8_t fingers); | ||
89 | |||
90 | // Check if the provides type is currently being tracked | ||
91 | bool gesture_tracker_check(struct gesture_tracker *tracker, | ||
92 | enum gesture_type type); | ||
93 | |||
94 | // Update gesture track with new data point | ||
95 | void gesture_tracker_update(struct gesture_tracker *tracker, double dx, | ||
96 | double dy, double scale, double rotation); | ||
97 | |||
98 | // Reset tracker | ||
99 | void gesture_tracker_cancel(struct gesture_tracker *tracker); | ||
100 | |||
101 | // Reset tracker and return gesture tracked | ||
102 | struct gesture *gesture_tracker_end(struct gesture_tracker *tracker); | ||
103 | |||
104 | #endif | ||
diff --git a/include/stringop.h b/include/stringop.h index 8d7089e9..b29f59b2 100644 --- a/include/stringop.h +++ b/include/stringop.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _SWAY_STRINGOP_H | 2 | #define _SWAY_STRINGOP_H |
3 | 3 | ||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include <stddef.h> | ||
5 | #include "list.h" | 6 | #include "list.h" |
6 | 7 | ||
7 | void strip_whitespace(char *str); | 8 | void strip_whitespace(char *str); |
diff --git a/include/sway/commands.h b/include/sway/commands.h index 2746ef28..5f71a79d 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -106,6 +106,7 @@ sway_cmd cmd_exec_process; | |||
106 | sway_cmd cmd_assign; | 106 | sway_cmd cmd_assign; |
107 | sway_cmd cmd_bar; | 107 | sway_cmd cmd_bar; |
108 | sway_cmd cmd_bindcode; | 108 | sway_cmd cmd_bindcode; |
109 | sway_cmd cmd_bindgesture; | ||
109 | sway_cmd cmd_bindswitch; | 110 | sway_cmd cmd_bindswitch; |
110 | sway_cmd cmd_bindsym; | 111 | sway_cmd cmd_bindsym; |
111 | sway_cmd cmd_border; | 112 | sway_cmd cmd_border; |
@@ -191,6 +192,7 @@ sway_cmd cmd_titlebar_border_thickness; | |||
191 | sway_cmd cmd_titlebar_padding; | 192 | sway_cmd cmd_titlebar_padding; |
192 | sway_cmd cmd_unbindcode; | 193 | sway_cmd cmd_unbindcode; |
193 | sway_cmd cmd_unbindswitch; | 194 | sway_cmd cmd_unbindswitch; |
195 | sway_cmd cmd_unbindgesture; | ||
194 | sway_cmd cmd_unbindsym; | 196 | sway_cmd cmd_unbindsym; |
195 | sway_cmd cmd_unmark; | 197 | sway_cmd cmd_unmark; |
196 | sway_cmd cmd_urgent; | 198 | sway_cmd cmd_urgent; |
diff --git a/include/sway/config.h b/include/sway/config.h index 2e24c3ae..05678c33 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <xkbcommon/xkbcommon.h> | 10 | #include <xkbcommon/xkbcommon.h> |
11 | #include <xf86drmMode.h> | 11 | #include <xf86drmMode.h> |
12 | #include "../include/config.h" | 12 | #include "../include/config.h" |
13 | #include "gesture.h" | ||
13 | #include "list.h" | 14 | #include "list.h" |
14 | #include "swaynag.h" | 15 | #include "swaynag.h" |
15 | #include "tree/container.h" | 16 | #include "tree/container.h" |
@@ -32,7 +33,8 @@ enum binding_input_type { | |||
32 | BINDING_KEYSYM, | 33 | BINDING_KEYSYM, |
33 | BINDING_MOUSECODE, | 34 | BINDING_MOUSECODE, |
34 | BINDING_MOUSESYM, | 35 | BINDING_MOUSESYM, |
35 | BINDING_SWITCH | 36 | BINDING_SWITCH, // dummy, only used to call seat_execute_command |
37 | BINDING_GESTURE // dummy, only used to call seat_execute_command | ||
36 | }; | 38 | }; |
37 | 39 | ||
38 | enum binding_flags { | 40 | enum binding_flags { |
@@ -45,6 +47,7 @@ enum binding_flags { | |||
45 | BINDING_RELOAD = 1 << 6, // switch only; (re)trigger binding on reload | 47 | BINDING_RELOAD = 1 << 6, // switch only; (re)trigger binding on reload |
46 | BINDING_INHIBITED = 1 << 7, // keyboard only: ignore shortcut inhibitor | 48 | BINDING_INHIBITED = 1 << 7, // keyboard only: ignore shortcut inhibitor |
47 | BINDING_NOREPEAT = 1 << 8, // keyboard only; do not trigger when repeating a held key | 49 | BINDING_NOREPEAT = 1 << 8, // keyboard only; do not trigger when repeating a held key |
50 | BINDING_EXACT = 1 << 9, // gesture only; only trigger on exact match | ||
48 | }; | 51 | }; |
49 | 52 | ||
50 | /** | 53 | /** |
@@ -79,6 +82,16 @@ struct sway_switch_binding { | |||
79 | }; | 82 | }; |
80 | 83 | ||
81 | /** | 84 | /** |
85 | * A gesture binding and an associated command. | ||
86 | */ | ||
87 | struct sway_gesture_binding { | ||
88 | char *input; | ||
89 | uint32_t flags; | ||
90 | struct gesture gesture; | ||
91 | char *command; | ||
92 | }; | ||
93 | |||
94 | /** | ||
82 | * Focus on window activation. | 95 | * Focus on window activation. |
83 | */ | 96 | */ |
84 | enum sway_fowa { | 97 | enum sway_fowa { |
@@ -97,6 +110,7 @@ struct sway_mode { | |||
97 | list_t *keycode_bindings; | 110 | list_t *keycode_bindings; |
98 | list_t *mouse_bindings; | 111 | list_t *mouse_bindings; |
99 | list_t *switch_bindings; | 112 | list_t *switch_bindings; |
113 | list_t *gesture_bindings; | ||
100 | bool pango; | 114 | bool pango; |
101 | }; | 115 | }; |
102 | 116 | ||
@@ -689,6 +703,8 @@ void free_sway_binding(struct sway_binding *sb); | |||
689 | 703 | ||
690 | void free_switch_binding(struct sway_switch_binding *binding); | 704 | void free_switch_binding(struct sway_switch_binding *binding); |
691 | 705 | ||
706 | void free_gesture_binding(struct sway_gesture_binding *binding); | ||
707 | |||
692 | void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding); | 708 | void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding); |
693 | 709 | ||
694 | void load_swaybar(struct bar_config *bar); | 710 | void load_swaybar(struct bar_config *bar); |
diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 3a71a35f..8a2898dd 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h | |||
@@ -36,14 +36,14 @@ struct sway_cursor { | |||
36 | bool active_confine_requires_warp; | 36 | bool active_confine_requires_warp; |
37 | 37 | ||
38 | struct wlr_pointer_gestures_v1 *pointer_gestures; | 38 | struct wlr_pointer_gestures_v1 *pointer_gestures; |
39 | struct wl_listener hold_begin; | ||
40 | struct wl_listener hold_end; | ||
39 | struct wl_listener pinch_begin; | 41 | struct wl_listener pinch_begin; |
40 | struct wl_listener pinch_update; | 42 | struct wl_listener pinch_update; |
41 | struct wl_listener pinch_end; | 43 | struct wl_listener pinch_end; |
42 | struct wl_listener swipe_begin; | 44 | struct wl_listener swipe_begin; |
43 | struct wl_listener swipe_update; | 45 | struct wl_listener swipe_update; |
44 | struct wl_listener swipe_end; | 46 | struct wl_listener swipe_end; |
45 | struct wl_listener hold_begin; | ||
46 | struct wl_listener hold_end; | ||
47 | 47 | ||
48 | struct wl_listener motion; | 48 | struct wl_listener motion; |
49 | struct wl_listener motion_absolute; | 49 | struct wl_listener motion_absolute; |
diff --git a/include/sway/input/seat.h b/include/sway/input/seat.h index 47726159..c2041742 100644 --- a/include/sway/input/seat.h +++ b/include/sway/input/seat.h | |||
@@ -19,6 +19,22 @@ struct sway_seatop_impl { | |||
19 | void (*pointer_motion)(struct sway_seat *seat, uint32_t time_msec); | 19 | void (*pointer_motion)(struct sway_seat *seat, uint32_t time_msec); |
20 | void (*pointer_axis)(struct sway_seat *seat, | 20 | void (*pointer_axis)(struct sway_seat *seat, |
21 | struct wlr_pointer_axis_event *event); | 21 | struct wlr_pointer_axis_event *event); |
22 | void (*hold_begin)(struct sway_seat *seat, | ||
23 | struct wlr_pointer_hold_begin_event *event); | ||
24 | void (*hold_end)(struct sway_seat *seat, | ||
25 | struct wlr_pointer_hold_end_event *event); | ||
26 | void (*pinch_begin)(struct sway_seat *seat, | ||
27 | struct wlr_pointer_pinch_begin_event *event); | ||
28 | void (*pinch_update)(struct sway_seat *seat, | ||
29 | struct wlr_pointer_pinch_update_event *event); | ||
30 | void (*pinch_end)(struct sway_seat *seat, | ||
31 | struct wlr_pointer_pinch_end_event *event); | ||
32 | void (*swipe_begin)(struct sway_seat *seat, | ||
33 | struct wlr_pointer_swipe_begin_event *event); | ||
34 | void (*swipe_update)(struct sway_seat *seat, | ||
35 | struct wlr_pointer_swipe_update_event *event); | ||
36 | void (*swipe_end)(struct sway_seat *seat, | ||
37 | struct wlr_pointer_swipe_end_event *event); | ||
22 | void (*rebase)(struct sway_seat *seat, uint32_t time_msec); | 38 | void (*rebase)(struct sway_seat *seat, uint32_t time_msec); |
23 | void (*tablet_tool_motion)(struct sway_seat *seat, | 39 | void (*tablet_tool_motion)(struct sway_seat *seat, |
24 | struct sway_tablet_tool *tool, uint32_t time_msec); | 40 | struct sway_tablet_tool *tool, uint32_t time_msec); |
@@ -287,6 +303,25 @@ void seatop_tablet_tool_tip(struct sway_seat *seat, | |||
287 | void seatop_tablet_tool_motion(struct sway_seat *seat, | 303 | void seatop_tablet_tool_motion(struct sway_seat *seat, |
288 | struct sway_tablet_tool *tool, uint32_t time_msec); | 304 | struct sway_tablet_tool *tool, uint32_t time_msec); |
289 | 305 | ||
306 | void seatop_hold_begin(struct sway_seat *seat, | ||
307 | struct wlr_pointer_hold_begin_event *event); | ||
308 | void seatop_hold_end(struct sway_seat *seat, | ||
309 | struct wlr_pointer_hold_end_event *event); | ||
310 | |||
311 | void seatop_pinch_begin(struct sway_seat *seat, | ||
312 | struct wlr_pointer_pinch_begin_event *event); | ||
313 | void seatop_pinch_update(struct sway_seat *seat, | ||
314 | struct wlr_pointer_pinch_update_event *event); | ||
315 | void seatop_pinch_end(struct sway_seat *seat, | ||
316 | struct wlr_pointer_pinch_end_event *event); | ||
317 | |||
318 | void seatop_swipe_begin(struct sway_seat *seat, | ||
319 | struct wlr_pointer_swipe_begin_event *event); | ||
320 | void seatop_swipe_update(struct sway_seat *seat, | ||
321 | struct wlr_pointer_swipe_update_event *event); | ||
322 | void seatop_swipe_end(struct sway_seat *seat, | ||
323 | struct wlr_pointer_swipe_end_event *event); | ||
324 | |||
290 | void seatop_rebase(struct sway_seat *seat, uint32_t time_msec); | 325 | void seatop_rebase(struct sway_seat *seat, uint32_t time_msec); |
291 | 326 | ||
292 | /** | 327 | /** |