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 | a535ed310f756a57129683c9d81c6a65e8338977 (diff) | |
download | sway-cab2189aa64d04ba79dc2cbf19400435b47cdbd2.tar.xz |
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 @@ +#ifndef _SWAY_GESTURE_H +#define _SWAY_GESTURE_H + +#include <stdbool.h> +#include <stdint.h> + +/** + * A gesture type used in binding. + */ +enum gesture_type { + GESTURE_TYPE_NONE = 0, + GESTURE_TYPE_HOLD, + GESTURE_TYPE_PINCH, + GESTURE_TYPE_SWIPE, +}; + +// Turns single type enum value to constant string representation. +const char *gesture_type_string(enum gesture_type direction); + +// Value to use to accept any finger count +extern const uint8_t GESTURE_FINGERS_ANY; + +/** + * A gesture direction used in binding. + */ +enum gesture_direction { + GESTURE_DIRECTION_NONE = 0, + // Directions based on delta x and y + GESTURE_DIRECTION_UP = 1 << 0, + GESTURE_DIRECTION_DOWN = 1 << 1, + GESTURE_DIRECTION_LEFT = 1 << 2, + GESTURE_DIRECTION_RIGHT = 1 << 3, + // Directions based on scale + GESTURE_DIRECTION_INWARD = 1 << 4, + GESTURE_DIRECTION_OUTWARD = 1 << 5, + // Directions based on rotation + GESTURE_DIRECTION_CLOCKWISE = 1 << 6, + GESTURE_DIRECTION_COUNTERCLOCKWISE = 1 << 7, +}; + +// Turns single direction enum value to constant string representation. +const char *gesture_direction_string(enum gesture_direction direction); + +/** + * Struct representing a pointer gesture + */ +struct gesture { + enum gesture_type type; + uint8_t fingers; + uint32_t directions; +}; + +/** + * Parses gesture from <gesture>[:<fingers>][:<directions>] string. + * + * Return NULL on success, otherwise error message string + */ +char *gesture_parse(const char *input, struct gesture *output); + +// Turns gesture into string representation +char *gesture_to_string(struct gesture *gesture); + +// Check if gesture is of certain type and finger count. +bool gesture_check(struct gesture *target, + enum gesture_type type, uint8_t fingers); + +// Check if a gesture target/binding is match by other gesture/input +bool gesture_match(struct gesture *target, + struct gesture *to_match, bool exact); + +// Returns true if gesture are exactly the same +bool gesture_equal(struct gesture *a, struct gesture *b); + +// Compare distance between two matched target gestures. +int8_t gesture_compare(struct gesture *a, struct gesture *b); + +// Small helper struct to track gestures over time +struct gesture_tracker { + enum gesture_type type; + uint8_t fingers; + double dx, dy; + double scale; + double rotation; +}; + +// Begin gesture tracking +void gesture_tracker_begin(struct gesture_tracker *tracker, + enum gesture_type type, uint8_t fingers); + +// Check if the provides type is currently being tracked +bool gesture_tracker_check(struct gesture_tracker *tracker, + enum gesture_type type); + +// Update gesture track with new data point +void gesture_tracker_update(struct gesture_tracker *tracker, double dx, + double dy, double scale, double rotation); + +// Reset tracker +void gesture_tracker_cancel(struct gesture_tracker *tracker); + +// Reset tracker and return gesture tracked +struct gesture *gesture_tracker_end(struct gesture_tracker *tracker); + +#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 @@ #define _SWAY_STRINGOP_H #include <stdbool.h> +#include <stddef.h> #include "list.h" 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; sway_cmd cmd_assign; sway_cmd cmd_bar; sway_cmd cmd_bindcode; +sway_cmd cmd_bindgesture; sway_cmd cmd_bindswitch; sway_cmd cmd_bindsym; sway_cmd cmd_border; @@ -191,6 +192,7 @@ sway_cmd cmd_titlebar_border_thickness; sway_cmd cmd_titlebar_padding; sway_cmd cmd_unbindcode; sway_cmd cmd_unbindswitch; +sway_cmd cmd_unbindgesture; sway_cmd cmd_unbindsym; sway_cmd cmd_unmark; 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 @@ #include <xkbcommon/xkbcommon.h> #include <xf86drmMode.h> #include "../include/config.h" +#include "gesture.h" #include "list.h" #include "swaynag.h" #include "tree/container.h" @@ -32,7 +33,8 @@ enum binding_input_type { BINDING_KEYSYM, BINDING_MOUSECODE, BINDING_MOUSESYM, - BINDING_SWITCH + BINDING_SWITCH, // dummy, only used to call seat_execute_command + BINDING_GESTURE // dummy, only used to call seat_execute_command }; enum binding_flags { @@ -45,6 +47,7 @@ enum binding_flags { BINDING_RELOAD = 1 << 6, // switch only; (re)trigger binding on reload BINDING_INHIBITED = 1 << 7, // keyboard only: ignore shortcut inhibitor BINDING_NOREPEAT = 1 << 8, // keyboard only; do not trigger when repeating a held key + BINDING_EXACT = 1 << 9, // gesture only; only trigger on exact match }; /** @@ -79,6 +82,16 @@ struct sway_switch_binding { }; /** + * A gesture binding and an associated command. + */ +struct sway_gesture_binding { + char *input; + uint32_t flags; + struct gesture gesture; + char *command; +}; + +/** * Focus on window activation. */ enum sway_fowa { @@ -97,6 +110,7 @@ struct sway_mode { list_t *keycode_bindings; list_t *mouse_bindings; list_t *switch_bindings; + list_t *gesture_bindings; bool pango; }; @@ -689,6 +703,8 @@ void free_sway_binding(struct sway_binding *sb); void free_switch_binding(struct sway_switch_binding *binding); +void free_gesture_binding(struct sway_gesture_binding *binding); + void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding); 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 { bool active_confine_requires_warp; struct wlr_pointer_gestures_v1 *pointer_gestures; + struct wl_listener hold_begin; + struct wl_listener hold_end; struct wl_listener pinch_begin; struct wl_listener pinch_update; struct wl_listener pinch_end; struct wl_listener swipe_begin; struct wl_listener swipe_update; struct wl_listener swipe_end; - struct wl_listener hold_begin; - struct wl_listener hold_end; struct wl_listener motion; 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 { void (*pointer_motion)(struct sway_seat *seat, uint32_t time_msec); void (*pointer_axis)(struct sway_seat *seat, struct wlr_pointer_axis_event *event); + void (*hold_begin)(struct sway_seat *seat, + struct wlr_pointer_hold_begin_event *event); + void (*hold_end)(struct sway_seat *seat, + struct wlr_pointer_hold_end_event *event); + void (*pinch_begin)(struct sway_seat *seat, + struct wlr_pointer_pinch_begin_event *event); + void (*pinch_update)(struct sway_seat *seat, + struct wlr_pointer_pinch_update_event *event); + void (*pinch_end)(struct sway_seat *seat, + struct wlr_pointer_pinch_end_event *event); + void (*swipe_begin)(struct sway_seat *seat, + struct wlr_pointer_swipe_begin_event *event); + void (*swipe_update)(struct sway_seat *seat, + struct wlr_pointer_swipe_update_event *event); + void (*swipe_end)(struct sway_seat *seat, + struct wlr_pointer_swipe_end_event *event); void (*rebase)(struct sway_seat *seat, uint32_t time_msec); void (*tablet_tool_motion)(struct sway_seat *seat, struct sway_tablet_tool *tool, uint32_t time_msec); @@ -287,6 +303,25 @@ void seatop_tablet_tool_tip(struct sway_seat *seat, void seatop_tablet_tool_motion(struct sway_seat *seat, struct sway_tablet_tool *tool, uint32_t time_msec); +void seatop_hold_begin(struct sway_seat *seat, + struct wlr_pointer_hold_begin_event *event); +void seatop_hold_end(struct sway_seat *seat, + struct wlr_pointer_hold_end_event *event); + +void seatop_pinch_begin(struct sway_seat *seat, + struct wlr_pointer_pinch_begin_event *event); +void seatop_pinch_update(struct sway_seat *seat, + struct wlr_pointer_pinch_update_event *event); +void seatop_pinch_end(struct sway_seat *seat, + struct wlr_pointer_pinch_end_event *event); + +void seatop_swipe_begin(struct sway_seat *seat, + struct wlr_pointer_swipe_begin_event *event); +void seatop_swipe_update(struct sway_seat *seat, + struct wlr_pointer_swipe_update_event *event); +void seatop_swipe_end(struct sway_seat *seat, + struct wlr_pointer_swipe_end_event *event); + void seatop_rebase(struct sway_seat *seat, uint32_t time_msec); /** |