From 642d7fd8ecfe30c4bb0bf420fde53c2ed8b1c711 Mon Sep 17 00:00:00 2001 From: grahnen Date: Tue, 15 Jan 2019 03:08:11 +0100 Subject: [PATCH 01/17] Link against libtouch --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 3ed0c5515..94123f916 100644 --- a/meson.build +++ b/meson.build @@ -58,7 +58,7 @@ xcb = dependency('xcb', required: get_option('xwayland')) math = cc.find_library('m') rt = cc.find_library('rt') git = find_program('git', native: true, required: false) - +libtouch = dependency('libtouch') # Try first to find wlroots as a subproject, then as a system dependency wlroots_version = '>=0.4.1' wlroots_proj = subproject( From 6a099a753e668b8d326e1b844583d4ee53f5ec83 Mon Sep 17 00:00:00 2001 From: grahnen Date: Tue, 15 Jan 2019 03:45:04 +0100 Subject: [PATCH 02/17] Integrate libtouch into sway and cursor.(c|h) --- include/sway/input/cursor.h | 2 ++ meson.build | 1 + sway/input/cursor.c | 20 ++++++++++++++++---- sway/meson.build | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 516718c97..4362a878e 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -36,6 +36,8 @@ struct sway_cursor { struct wl_listener axis; struct wl_listener frame; + + struct libtouch_engine *gesture_engine; struct wl_listener touch_down; struct wl_listener touch_up; struct wl_listener touch_motion; diff --git a/meson.build b/meson.build index 94123f916..1a122995f 100644 --- a/meson.build +++ b/meson.build @@ -37,6 +37,7 @@ if is_freebsd add_project_arguments('-D_C11_SOURCE', language: 'c') endif +libtouch = dependency('libtouch') jsonc = dependency('json-c', version: '>=0.13') pcre = dependency('libpcre') wayland_server = dependency('wayland-server') diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 610844479..6d5c315f5 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -28,6 +28,7 @@ #include "sway/tree/view.h" #include "sway/tree/workspace.h" #include "wlr-layer-shell-unstable-v1-protocol.h" +#include "libtouch.h" static uint32_t get_current_time_msec(void) { struct timespec now; @@ -335,7 +336,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_down *event = data; - + struct libtouch_engine *engine = cursor->gesture_engine; struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; @@ -354,21 +355,29 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { return; } - // TODO: fall back to cursor simulation if client has not bound to touch + // TODO: fall back to cursor simulation if client has not bound to touch if (seat_is_input_allowed(seat, surface)) { wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, event->touch_id, sx, sy); cursor_set_image(cursor, NULL, NULL); } + + libtouch_engine_register_touch(engine, event->time_msec, event->touch_id, + LIBTOUCH_TOUCH_DOWN, event->x, event->y); + + } static void handle_touch_up(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); + struct libtouch_engine *engine = cursor->gesture_engine; wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_up *event = data; struct wlr_seat *seat = cursor->seat->wlr_seat; // TODO: fall back to cursor simulation if client has not bound to touch wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); + libtouch_engine_register_touch(engine, event->time_msec, event->touch_id, + LIBTOUCH_TOUCH_UP, 0,0); } static void handle_touch_motion(struct wl_listener *listener, void *data) { @@ -376,7 +385,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wl_container_of(listener, cursor, touch_motion); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_motion *event = data; - + struct libtouch_engine *engine = cursor->gesture_engine; struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; @@ -402,12 +411,15 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { if (!surface) { return; } - + // TODO: fall back to cursor simulation if client has not bound to touch if (seat_is_input_allowed(cursor->seat, surface)) { wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, event->touch_id, sx, sy); } + + libtouch_engine_register_move(engine, event->time_msec, event->touch_id, + event->x, event->y); } static double apply_mapping_from_coord(double low, double high, double value) { diff --git a/sway/meson.build b/sway/meson.build index 8254fb5c3..d1742b7a5 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -185,6 +185,7 @@ sway_sources = files( ) sway_deps = [ + libtouch, cairo, gdk_pixbuf, jsonc, From bccc14e01bbd0bce4ade5e37cc05e02743c0a1a0 Mon Sep 17 00:00:00 2001 From: grahnen Date: Tue, 15 Jan 2019 04:05:45 +0100 Subject: [PATCH 03/17] Register touch events in libtouch engine --- include/sway/input/cursor.h | 3 +++ sway/input/cursor.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 4362a878e..ad2a25076 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -36,7 +36,10 @@ struct sway_cursor { struct wl_listener axis; struct wl_listener frame; +<<<<<<< HEAD +======= +>>>>>>> Register touch events in libtouch engine struct libtouch_engine *gesture_engine; struct wl_listener touch_down; struct wl_listener touch_up; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 6d5c315f5..2b2f4000e 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -362,10 +362,16 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { cursor_set_image(cursor, NULL, NULL); } +<<<<<<< HEAD libtouch_engine_register_touch(engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_DOWN, event->x, event->y); +======= + libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, + event->touch_id, LIBTOUCH_TOUCH_DOWN, + event->x, event->y); +>>>>>>> Register touch events in libtouch engine } static void handle_touch_up(struct wl_listener *listener, void *data) { @@ -376,8 +382,14 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { struct wlr_seat *seat = cursor->seat->wlr_seat; // TODO: fall back to cursor simulation if client has not bound to touch wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); +<<<<<<< HEAD libtouch_engine_register_touch(engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_UP, 0,0); +======= + + libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, + event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0); +>>>>>>> Register touch events in libtouch engine } static void handle_touch_motion(struct wl_listener *listener, void *data) { @@ -418,8 +430,13 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { event->touch_id, sx, sy); } +<<<<<<< HEAD libtouch_engine_register_move(engine, event->time_msec, event->touch_id, event->x, event->y); +======= + libtouch_engine_register_move(cursor->gesture_engine, event->time_msec, + event->touch_id, event->x, event->y); +>>>>>>> Register touch events in libtouch engine } static double apply_mapping_from_coord(double low, double high, double value) { From 79f3cf88a792d7f76d1b08cfd6131107ebba91df Mon Sep 17 00:00:00 2001 From: grahnen Date: Wed, 16 Jan 2019 00:23:41 +0100 Subject: [PATCH 04/17] Declare cmd_gesture and create an empty body. --- include/sway/commands.h | 1 + sway/commands.c | 1 + sway/commands/gesture.c | 14 ++++++++++++++ sway/input/cursor.c | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 sway/commands/gesture.c diff --git a/include/sway/commands.h b/include/sway/commands.h index cfe2aa079..599665bcf 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -134,6 +134,7 @@ sway_cmd cmd_force_display_urgency_hint; sway_cmd cmd_force_focus_wrapping; sway_cmd cmd_fullscreen; sway_cmd cmd_gaps; +sway_cmd cmd_gesture; sway_cmd cmd_hide_edge_borders; sway_cmd cmd_include; sway_cmd cmd_inhibit_idle; diff --git a/sway/commands.c b/sway/commands.c index 237bfc281..c5d70242d 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -72,6 +72,7 @@ static struct cmd_handler handlers[] = { { "force_focus_wrapping", cmd_force_focus_wrapping }, { "fullscreen", cmd_fullscreen }, { "gaps", cmd_gaps }, + { "gesture", cmd_gesture }, { "hide_edge_borders", cmd_hide_edge_borders }, { "include", cmd_include }, { "input", cmd_input }, diff --git a/sway/commands/gesture.c b/sway/commands/gesture.c new file mode 100644 index 000000000..23f431f92 --- /dev/null +++ b/sway/commands/gesture.c @@ -0,0 +1,14 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" + +struct cmd_results *cmd_gesture(int argc, char **argv) { + return NULL; +} diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 2b2f4000e..098470289 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -28,7 +28,7 @@ #include "sway/tree/view.h" #include "sway/tree/workspace.h" #include "wlr-layer-shell-unstable-v1-protocol.h" -#include "libtouch.h" +#include "" static uint32_t get_current_time_msec(void) { struct timespec now; From cb94176e27bab441761ec7dff5ceb48fe9119b50 Mon Sep 17 00:00:00 2001 From: grahnen Date: Wed, 16 Jan 2019 19:15:39 +0100 Subject: [PATCH 05/17] Try to incorporate touch in config --- include/sway/commands.h | 1 + include/sway/config.h | 6 ++++++ sway/commands.c | 1 + sway/commands/gesture.c | 36 +++++++++++++++++++++++++++++++++++- sway/input/cursor.c | 2 +- sway/meson.build | 1 + 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/sway/commands.h b/include/sway/commands.h index 599665bcf..815889eb4 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -185,6 +185,7 @@ sway_cmd cmd_titlebar_padding; sway_cmd cmd_unbindcode; sway_cmd cmd_unbindswitch; sway_cmd cmd_unbindsym; +sway_cmd cmd_touch; sway_cmd cmd_unmark; sway_cmd cmd_urgent; sway_cmd cmd_workspace; diff --git a/include/sway/config.h b/include/sway/config.h index 864105442..e285f2863 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -54,6 +54,11 @@ struct sway_binding { char *command; }; +struct sway_gesture_binding { + struct libtouch_gesture *gesture; + char *command; +}; + /** * A mouse binding and an associated command. */ @@ -91,6 +96,7 @@ struct sway_mode { list_t *keycode_bindings; list_t *mouse_bindings; list_t *switch_bindings; + list_t *gesture_bindings; bool pango; }; diff --git a/sway/commands.c b/sway/commands.c index c5d70242d..fffaf7bc8 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -93,6 +93,7 @@ static struct cmd_handler handlers[] = { { "title_align", cmd_title_align }, { "titlebar_border_thickness", cmd_titlebar_border_thickness }, { "titlebar_padding", cmd_titlebar_padding }, + { "touch", cmd_touch }, { "unbindcode", cmd_unbindcode }, { "unbindswitch", cmd_unbindswitch }, { "unbindsym", cmd_unbindsym }, diff --git a/sway/commands/gesture.c b/sway/commands/gesture.c index 23f431f92..e0075ae36 100644 --- a/sway/commands/gesture.c +++ b/sway/commands/gesture.c @@ -8,7 +8,41 @@ #include "list.h" #include "log.h" #include "stringop.h" +#include + + +void free_sway_gesture_binding(struct sway_gesture_binding *binding) { + if(!binding) { + return; + } + free(binding->command); + free(binding); +} + + +struct cmd_results *cmd_touch(int argc, char **argv) { + return NULL; +} struct cmd_results *cmd_gesture(int argc, char **argv) { - return NULL; + struct cmd_results *error = NULL; + + struct sway_gesture_binding *binding = calloc(1, sizeof(struct sway_gesture_binding)); + if(!binding) { + return cmd_results_new(CMD_FAILURE, "Unable to allocate binding"); + } + + if(argc < 2) { + free_sway_gesture_binding(binding); + return cmd_results_new(CMD_FAILURE, "Invalid gesture command " + "(expected at least 2 arguments, got %d)", argc); + } + + + binding->command = join_args(argv+1, argc -1); + //list_t *bindings = config->current_mode->gesture_bindings; + + + + return error; } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 098470289..5bc67de08 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -28,7 +28,7 @@ #include "sway/tree/view.h" #include "sway/tree/workspace.h" #include "wlr-layer-shell-unstable-v1-protocol.h" -#include "" +#include static uint32_t get_current_time_msec(void) { struct timespec now; diff --git a/sway/meson.build b/sway/meson.build index d1742b7a5..14fe1f130 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -62,6 +62,7 @@ sway_sources = files( 'commands/force_focus_wrapping.c', 'commands/fullscreen.c', 'commands/gaps.c', + 'commands/gesture.c', 'commands/hide_edge_borders.c', 'commands/inhibit_idle.c', 'commands/kill.c', From ba2020aebdb769570e9a2be97e4f43645c493019 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Wed, 23 Jan 2019 03:41:29 +0100 Subject: [PATCH 06/17] Restructure and add a hiearchy of commands --- include/sway/commands.h | 6 ++++ include/sway/config.h | 27 +++++++++++----- sway/commands.c | 2 +- sway/commands/gesture.c | 48 ----------------------------- sway/commands/touch.c | 35 +++++++++++++++++++++ sway/commands/touch/binding.c | 15 +++++++++ sway/commands/touch/gesture.c | 41 ++++++++++++++++++++++++ sway/commands/touch/gesture/touch.c | 15 +++++++++ sway/config/gesture.c | 38 +++++++++++++++++++++++ sway/meson.build | 7 ++++- 10 files changed, 177 insertions(+), 57 deletions(-) delete mode 100644 sway/commands/gesture.c create mode 100644 sway/commands/touch.c create mode 100644 sway/commands/touch/binding.c create mode 100644 sway/commands/touch/gesture.c create mode 100644 sway/commands/touch/gesture/touch.c create mode 100644 sway/config/gesture.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 815889eb4..06c7802ec 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -280,6 +280,12 @@ sway_cmd seat_cmd_fallback; sway_cmd seat_cmd_hide_cursor; sway_cmd seat_cmd_pointer_constraint; +sway_cmd touch_cmd_gesture; +sway_cmd touch_cmd_binding; + +sway_cmd touch_gesture_cmd_touch; + + sway_cmd cmd_ipc_cmd; sway_cmd cmd_ipc_events; sway_cmd cmd_ipc_event_cmd; diff --git a/include/sway/config.h b/include/sway/config.h index e285f2863..2f12fe969 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -53,12 +53,6 @@ struct sway_binding { uint32_t modifiers; char *command; }; - -struct sway_gesture_binding { - struct libtouch_gesture *gesture; - char *command; -}; - /** * A mouse binding and an associated command. */ @@ -106,6 +100,13 @@ struct input_config_mapped_from_region { bool mm; }; +struct gesture_config { + char *identifier; + struct libtouch_gesture *gesture; + char *command; +}; + + /** * options for input devices */ @@ -426,6 +427,7 @@ struct sway_config { list_t *output_configs; list_t *input_configs; list_t *input_type_configs; + list_t *gesture_configs; list_t *seat_configs; list_t *criteria; list_t *no_focus; @@ -513,7 +515,8 @@ struct sway_config { list_t *command_policies; list_t *feature_policies; list_t *ipc_policies; - + + struct libtouch_engine *gesture_engine; // Context for command handlers struct { struct input_config *input_config; @@ -523,6 +526,10 @@ struct sway_config { struct sway_node *node; struct sway_container *container; struct sway_workspace *workspace; + + struct gesture_config *current_gesture; + + bool using_criteria; struct { int argc; @@ -647,6 +654,12 @@ void free_bar_binding(struct bar_binding *binding); void free_workspace_config(struct workspace_config *wsc); +int gesture_identifier_cmp(const void *item, const void *data); + +struct gesture_config *get_gesture_config(const char *identifier); + +struct gesture_config *new_gesture_config(const char *identifier); + /** * Updates the value of config->font_height based on the max title height * reported by each container. If recalculate is true, the containers will diff --git a/sway/commands.c b/sway/commands.c index fffaf7bc8..98b6650a2 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -72,7 +72,7 @@ static struct cmd_handler handlers[] = { { "force_focus_wrapping", cmd_force_focus_wrapping }, { "fullscreen", cmd_fullscreen }, { "gaps", cmd_gaps }, - { "gesture", cmd_gesture }, + { "touch", cmd_touch }, { "hide_edge_borders", cmd_hide_edge_borders }, { "include", cmd_include }, { "input", cmd_input }, diff --git a/sway/commands/gesture.c b/sway/commands/gesture.c deleted file mode 100644 index e0075ae36..000000000 --- a/sway/commands/gesture.c +++ /dev/null @@ -1,48 +0,0 @@ -#define _POSIX_C_SOURCE 200809L -#include -#include -#include -#include "sway/commands.h" -#include "sway/config.h" -#include "sway/ipc-server.h" -#include "list.h" -#include "log.h" -#include "stringop.h" -#include - - -void free_sway_gesture_binding(struct sway_gesture_binding *binding) { - if(!binding) { - return; - } - free(binding->command); - free(binding); -} - - -struct cmd_results *cmd_touch(int argc, char **argv) { - return NULL; -} - -struct cmd_results *cmd_gesture(int argc, char **argv) { - struct cmd_results *error = NULL; - - struct sway_gesture_binding *binding = calloc(1, sizeof(struct sway_gesture_binding)); - if(!binding) { - return cmd_results_new(CMD_FAILURE, "Unable to allocate binding"); - } - - if(argc < 2) { - free_sway_gesture_binding(binding); - return cmd_results_new(CMD_FAILURE, "Invalid gesture command " - "(expected at least 2 arguments, got %d)", argc); - } - - - binding->command = join_args(argv+1, argc -1); - //list_t *bindings = config->current_mode->gesture_bindings; - - - - return error; -} diff --git a/sway/commands/touch.c b/sway/commands/touch.c new file mode 100644 index 000000000..859d58d31 --- /dev/null +++ b/sway/commands/touch.c @@ -0,0 +1,35 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +static struct cmd_handler touch_handlers[] = { + { "gesture", touch_cmd_gesture }, + { "binding", touch_cmd_binding }, +}; + + +struct cmd_results *cmd_touch(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "touch", EXPECTED_AT_LEAST, 2))) { + return error; + } + if(!config->gesture_engine) { + config->gesture_engine = libtouch_engine_create(); + } + struct cmd_handler *cmd = find_handler(argv[0], touch_handlers, sizeof(touch_handlers)); + if( cmd ) { + return config_subcommand(argv, argc, touch_handlers, sizeof(touch_handlers)); + } + return cmd_results_new(CMD_FAILURE, + "Invalid subcommand"); + + +}; diff --git a/sway/commands/touch/binding.c b/sway/commands/touch/binding.c new file mode 100644 index 000000000..5b240be49 --- /dev/null +++ b/sway/commands/touch/binding.c @@ -0,0 +1,15 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_cmd_binding(int argc, char **argv) { + return NULL; +}; diff --git a/sway/commands/touch/gesture.c b/sway/commands/touch/gesture.c new file mode 100644 index 000000000..11221211c --- /dev/null +++ b/sway/commands/touch/gesture.c @@ -0,0 +1,41 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +static struct cmd_handler gesture_handlers[] = { + { "touch", touch_gesture_cmd_touch }, +}; + +struct cmd_results *touch_cmd_gesture(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "gesture", EXPECTED_AT_LEAST, 1))) { + return error; + } + + sway_log(SWAY_DEBUG, "entering gesture block: %s", argv[0]); + struct gesture_config *gesture = get_gesture_config(argv[0]); + + if(!gesture) { + return cmd_results_new(CMD_FAILURE, + "Could not create/find gesture config"); + } + + config->handler_context.current_gesture = gesture; + + struct cmd_handler *cmd = find_handler(argv[1], gesture_handlers, sizeof(gesture_handlers)); + if (cmd) { + return config_subcommand(argv,argc,gesture_handlers, sizeof(gesture_handlers)); + } + + + return cmd_results_new(CMD_FAILURE, + "Invalid Subcommand"); +}; diff --git a/sway/commands/touch/gesture/touch.c b/sway/commands/touch/gesture/touch.c new file mode 100644 index 000000000..539ebd8f1 --- /dev/null +++ b/sway/commands/touch/gesture/touch.c @@ -0,0 +1,15 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_touch(int argc, char **argv) { + return NULL; +}; diff --git a/sway/config/gesture.c b/sway/config/gesture.c new file mode 100644 index 000000000..153e9d18e --- /dev/null +++ b/sway/config/gesture.c @@ -0,0 +1,38 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/config.h" +#include "log.h" +#include + +struct gesture_config *get_gesture_config(const char* identifier) { + int i = list_seq_find(config->gesture_configs, gesture_identifier_cmp, identifier); + + struct gesture_config *cfg = NULL; + if(i >= 0) { + sway_log(SWAY_DEBUG, "Retrieving existing gesture"); + cfg = config->gesture_configs->items[i]; + } else { + sway_log(SWAY_DEBUG, "Adding new gesture"); + cfg = new_gesture_config(identifier); + list_add(config->gesture_configs, cfg); + } + + return cfg; + +} + +struct gesture_config *new_gesture_config(const char *identifier) { + struct gesture_config *cfg = calloc(sizeof(struct gesture_config), 1); + cfg->identifier = strdup(identifier); + cfg->gesture = libtouch_gesture_create(config->gesture_engine); + + return cfg; +} + +int gesture_identifier_cmp(const void *item, const void *data) { + const struct gesture_config *gc = item; + const char *identifier = data; + return strcmp(gc->identifier, identifier); +} diff --git a/sway/meson.build b/sway/meson.build index 14fe1f130..9f890ed88 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -36,6 +36,7 @@ sway_sources = files( 'config/output.c', 'config/seat.c', 'config/input.c', + 'config/gesture.c', 'commands/assign.c', 'commands/bar.c', @@ -62,7 +63,7 @@ sway_sources = files( 'commands/force_focus_wrapping.c', 'commands/fullscreen.c', 'commands/gaps.c', - 'commands/gesture.c', + 'commands/touch.c', 'commands/hide_edge_borders.c', 'commands/inhibit_idle.c', 'commands/kill.c', @@ -176,6 +177,10 @@ sway_sources = files( 'commands/output/subpixel.c', 'commands/output/transform.c', + 'commands/touch/binding.c', + 'commands/touch/gesture.c', + 'commands/touch/gesture/touch.c', + 'tree/arrange.c', 'tree/container.c', 'tree/node.c', From 6ccc01e9ef271238c626c578e291de23b6392f29 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Thu, 24 Jan 2019 00:50:10 +0100 Subject: [PATCH 07/17] Fix the failed rebase. --- include/sway/input/cursor.h | 4 ---- sway/input/cursor.c | 22 ++-------------------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index ad2a25076..1e06c4c31 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -36,10 +36,6 @@ struct sway_cursor { struct wl_listener axis; struct wl_listener frame; -<<<<<<< HEAD - -======= ->>>>>>> Register touch events in libtouch engine struct libtouch_engine *gesture_engine; struct wl_listener touch_down; struct wl_listener touch_up; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 5bc67de08..a1beeeb7c 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -361,17 +361,10 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { event->touch_id, sx, sy); cursor_set_image(cursor, NULL, NULL); } - -<<<<<<< HEAD - libtouch_engine_register_touch(engine, event->time_msec, event->touch_id, - LIBTOUCH_TOUCH_DOWN, event->x, event->y); - - -======= libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_DOWN, event->x, event->y); ->>>>>>> Register touch events in libtouch engine + } static void handle_touch_up(struct wl_listener *listener, void *data) { @@ -382,14 +375,8 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { struct wlr_seat *seat = cursor->seat->wlr_seat; // TODO: fall back to cursor simulation if client has not bound to touch wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); -<<<<<<< HEAD - libtouch_engine_register_touch(engine, event->time_msec, event->touch_id, - LIBTOUCH_TOUCH_UP, 0,0); -======= - libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0); ->>>>>>> Register touch events in libtouch engine } static void handle_touch_motion(struct wl_listener *listener, void *data) { @@ -429,14 +416,9 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, event->touch_id, sx, sy); } - -<<<<<<< HEAD - libtouch_engine_register_move(engine, event->time_msec, event->touch_id, - event->x, event->y); -======= libtouch_engine_register_move(cursor->gesture_engine, event->time_msec, event->touch_id, event->x, event->y); ->>>>>>> Register touch events in libtouch engine + } static double apply_mapping_from_coord(double low, double high, double value) { From dda3ac15aeae42185c50d4eeb6e4da21eab68166 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Thu, 24 Jan 2019 01:10:44 +0100 Subject: [PATCH 08/17] Implement binding --- sway/commands/touch/binding.c | 16 +++++++++++++++- sway/input/cursor.c | 3 --- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sway/commands/touch/binding.c b/sway/commands/touch/binding.c index 5b240be49..3a7d66e20 100644 --- a/sway/commands/touch/binding.c +++ b/sway/commands/touch/binding.c @@ -11,5 +11,19 @@ #include struct cmd_results *touch_cmd_binding(int argc, char **argv) { - return NULL; + struct cmd_results *error = NULL; + + if((error = checkarg(argc, "binding", EXPECTED_AT_LEAST, 2))) { + return error; + } + + struct gesture_config *config = get_gesture_config(argv[1]); + + if (!config) { + return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[1]); + } + + config->command = join_args(argv+2, argc); + return cmd_results_new(CMD_SUCCESS, NULL); + }; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index a1beeeb7c..0962c3efa 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -336,7 +336,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_down *event = data; - struct libtouch_engine *engine = cursor->gesture_engine; struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; @@ -369,7 +368,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { static void handle_touch_up(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); - struct libtouch_engine *engine = cursor->gesture_engine; wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_up *event = data; struct wlr_seat *seat = cursor->seat->wlr_seat; @@ -384,7 +382,6 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wl_container_of(listener, cursor, touch_motion); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_motion *event = data; - struct libtouch_engine *engine = cursor->gesture_engine; struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; From 40811a0e4df9635d7c3461120c74ebb832c437b8 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Thu, 24 Jan 2019 03:57:15 +0100 Subject: [PATCH 09/17] Add calling actions on gesture --- include/sway/commands.h | 2 +- include/sway/config.h | 4 +++- sway/commands/touch.c | 8 +++++-- sway/commands/touch/binding.c | 6 ++--- sway/commands/touch/gesture.c | 14 ++++++----- sway/commands/touch/gesture/threshold.c | 31 +++++++++++++++++++++++++ sway/commands/touch/gesture/touch.c | 27 ++++++++++++++++++++- sway/config/gesture.c | 8 ++++++- sway/input/cursor.c | 20 ++++++++++++++++ sway/meson.build | 1 + 10 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 sway/commands/touch/gesture/threshold.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 06c7802ec..3e7a03eb3 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -284,7 +284,7 @@ sway_cmd touch_cmd_gesture; sway_cmd touch_cmd_binding; sway_cmd touch_gesture_cmd_touch; - +sway_cmd touch_gesture_cmd_threshold; sway_cmd cmd_ipc_cmd; sway_cmd cmd_ipc_events; diff --git a/include/sway/config.h b/include/sway/config.h index 2f12fe969..d8f8189d3 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -528,7 +528,7 @@ struct sway_config { struct sway_workspace *workspace; struct gesture_config *current_gesture; - + struct libtouch_action *current_gesture_action; bool using_criteria; struct { @@ -656,6 +656,8 @@ void free_workspace_config(struct workspace_config *wsc); int gesture_identifier_cmp(const void *item, const void *data); +int gesture_libtouch_cmp(const void *item, const void *data); + struct gesture_config *get_gesture_config(const char *identifier); struct gesture_config *new_gesture_config(const char *identifier); diff --git a/sway/commands/touch.c b/sway/commands/touch.c index 859d58d31..0b08aa09b 100644 --- a/sway/commands/touch.c +++ b/sway/commands/touch.c @@ -10,9 +10,10 @@ #include "stringop.h" #include +// Must be in alphabetical order for bsearch static struct cmd_handler touch_handlers[] = { - { "gesture", touch_cmd_gesture }, { "binding", touch_cmd_binding }, + { "gesture", touch_cmd_gesture }, }; @@ -21,15 +22,18 @@ struct cmd_results *cmd_touch(int argc, char **argv) { if ((error = checkarg(argc, "touch", EXPECTED_AT_LEAST, 2))) { return error; } + if(!config->gesture_engine) { config->gesture_engine = libtouch_engine_create(); + sway_log(SWAY_DEBUG, "Created a new gesture engine"); } struct cmd_handler *cmd = find_handler(argv[0], touch_handlers, sizeof(touch_handlers)); if( cmd ) { return config_subcommand(argv, argc, touch_handlers, sizeof(touch_handlers)); } return cmd_results_new(CMD_FAILURE, - "Invalid subcommand"); + "Invalid subcommand: %s", + argv[0]); }; diff --git a/sway/commands/touch/binding.c b/sway/commands/touch/binding.c index 3a7d66e20..dacd26601 100644 --- a/sway/commands/touch/binding.c +++ b/sway/commands/touch/binding.c @@ -17,13 +17,13 @@ struct cmd_results *touch_cmd_binding(int argc, char **argv) { return error; } - struct gesture_config *config = get_gesture_config(argv[1]); + struct gesture_config *config = get_gesture_config(argv[0]); if (!config) { - return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[1]); + return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[0]); } - config->command = join_args(argv+2, argc); + config->command = join_args(argv + 1, argc - 1); return cmd_results_new(CMD_SUCCESS, NULL); }; diff --git a/sway/commands/touch/gesture.c b/sway/commands/touch/gesture.c index 11221211c..4450a2764 100644 --- a/sway/commands/touch/gesture.c +++ b/sway/commands/touch/gesture.c @@ -11,31 +11,33 @@ #include static struct cmd_handler gesture_handlers[] = { + { "threshold", touch_gesture_cmd_threshold }, { "touch", touch_gesture_cmd_touch }, }; struct cmd_results *touch_cmd_gesture(int argc, char **argv) { struct cmd_results *error = NULL; - if((error = checkarg(argc, "gesture", EXPECTED_AT_LEAST, 1))) { + if((error = checkarg(argc, "gesture", EXPECTED_AT_LEAST, 2))) { return error; } + sway_log(SWAY_DEBUG, "Getting gesture conf"); - sway_log(SWAY_DEBUG, "entering gesture block: %s", argv[0]); struct gesture_config *gesture = get_gesture_config(argv[0]); - + if(!gesture) { return cmd_results_new(CMD_FAILURE, "Could not create/find gesture config"); } config->handler_context.current_gesture = gesture; - + struct cmd_handler *cmd = find_handler(argv[1], gesture_handlers, sizeof(gesture_handlers)); if (cmd) { - return config_subcommand(argv,argc,gesture_handlers, sizeof(gesture_handlers)); + return config_subcommand(argv + 1,argc - 1,gesture_handlers, sizeof(gesture_handlers)); } return cmd_results_new(CMD_FAILURE, - "Invalid Subcommand"); + "Invalid Subcommand: %s", + argv[1]); }; diff --git a/sway/commands/touch/gesture/threshold.c b/sway/commands/touch/gesture/threshold.c new file mode 100644 index 000000000..c0510e147 --- /dev/null +++ b/sway/commands/touch/gesture/threshold.c @@ -0,0 +1,31 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_threshold(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct libtouch_action *current = config->handler_context.current_gesture_action; + if(!current) { + return cmd_results_new(CMD_FAILURE, "No action created"); + } + + int threshold = atoi(argv[0]); + if(threshold < 0) { + return cmd_results_new(CMD_INVALID, + "Invalid threshold: %s", argv[0]); + } + libtouch_action_set_threshold(current, threshold); + return cmd_results_new(CMD_SUCCESS, + "Set threshold"); +} diff --git a/sway/commands/touch/gesture/touch.c b/sway/commands/touch/gesture/touch.c index 539ebd8f1..546d1f443 100644 --- a/sway/commands/touch/gesture/touch.c +++ b/sway/commands/touch/gesture/touch.c @@ -11,5 +11,30 @@ #include struct cmd_results *touch_gesture_cmd_touch(int argc, char **argv) { - return NULL; + struct cmd_results *error = NULL; + if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + uint32_t mode; + if(strcmp(argv[0],"down") == 0) { + mode = LIBTOUCH_TOUCH_DOWN; + } else if (strcmp(argv[0],"up") == 0) { + mode = LIBTOUCH_TOUCH_UP; + } else { + return cmd_results_new(CMD_FAILURE, "Touch: %s is not up or down", argv[0]); + } + + if(!config->handler_context.current_gesture) { + return cmd_results_new(CMD_FAILURE, "No current gesture"); + } else if (!config->handler_context.current_gesture->gesture) { + return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); + } + struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; + + struct libtouch_action *action = libtouch_gesture_add_touch(gesture, mode); + + config->handler_context.current_gesture_action = action; + + return cmd_results_new(CMD_SUCCESS, "Created new action"); }; diff --git a/sway/config/gesture.c b/sway/config/gesture.c index 153e9d18e..5514098c5 100644 --- a/sway/config/gesture.c +++ b/sway/config/gesture.c @@ -8,7 +8,7 @@ struct gesture_config *get_gesture_config(const char* identifier) { int i = list_seq_find(config->gesture_configs, gesture_identifier_cmp, identifier); - + struct gesture_config *cfg = NULL; if(i >= 0) { sway_log(SWAY_DEBUG, "Retrieving existing gesture"); @@ -36,3 +36,9 @@ int gesture_identifier_cmp(const void *item, const void *data) { const char *identifier = data; return strcmp(gc->identifier, identifier); } + +int gesture_libtouch_cmp(const void *item, const void *data) { + const struct gesture_config *gc = item; + const struct libtouch_gesture *g = data; + return gc->gesture == g; +} diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 0962c3efa..5468c404b 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -332,6 +332,21 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) { wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); } +static void handle_gestures(struct libtouch_engine *engine, struct sway_seat *seat) { + struct libtouch_gesture *complete; + struct gesture_config *cfg; + int idx; + while((complete = libtouch_handle_finished_gesture(engine))){ + idx = list_seq_find(config->gesture_configs, gesture_libtouch_cmp, complete); + if(idx >= 0) { + cfg = config->gesture_configs->items[idx]; + if(cfg->command) { + execute_command(cfg->command, seat, seat_get_focused_container(seat)); + } + } + } +} + static void handle_touch_down(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); @@ -363,6 +378,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_DOWN, event->x, event->y); + handle_gestures(cursor->gesture_engine, seat); } @@ -375,6 +391,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0); + handle_gestures(cursor->gesture_engine, seat); } static void handle_touch_motion(struct wl_listener *listener, void *data) { @@ -416,8 +433,11 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { libtouch_engine_register_move(cursor->gesture_engine, event->time_msec, event->touch_id, event->x, event->y); + handle_gestures(cursor->gesture_engine, seat); } + + static double apply_mapping_from_coord(double low, double high, double value) { if (isnan(value)) { return value; diff --git a/sway/meson.build b/sway/meson.build index 9f890ed88..3c6ce0385 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -180,6 +180,7 @@ sway_sources = files( 'commands/touch/binding.c', 'commands/touch/gesture.c', 'commands/touch/gesture/touch.c', + 'commands/touch/gesture/threshold.c', 'tree/arrange.c', 'tree/container.c', From f89f45e58da08109188219ac0ab31ecc09b2cc17 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Thu, 24 Jan 2019 04:02:24 +0100 Subject: [PATCH 10/17] Use the right seat pointer --- sway/input/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 5468c404b..376891e60 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -391,7 +391,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0); - handle_gestures(cursor->gesture_engine, seat); + handle_gestures(cursor->gesture_engine, cursor->seat); } static void handle_touch_motion(struct wl_listener *listener, void *data) { From 7873a0f13c4d2c1f89e44adc261fe6d5082ffd80 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Sun, 3 Feb 2019 03:38:44 +0100 Subject: [PATCH 11/17] Implement remaining actions, split touch for different seats --- include/sway/commands.h | 6 +++ include/sway/config.h | 12 ++++++ include/sway/input/cursor.h | 2 +- sway/commands/touch.c | 1 + sway/commands/touch/binding.c | 2 + sway/commands/touch/gesture.c | 5 +++ sway/commands/touch/gesture/delay.c | 33 ++++++++++++++++ sway/commands/touch/gesture/pinch.c | 40 ++++++++++++++++++++ sway/commands/touch/gesture/rotate.c | 40 ++++++++++++++++++++ sway/commands/touch/gesture/swipe.c | 45 ++++++++++++++++++++++ sway/commands/touch/gesture/target.c | 38 +++++++++++++++++++ sway/commands/touch/gesture/threshold.c | 1 + sway/commands/touch/gesture/touch.c | 4 +- sway/commands/touch/target.c | 50 +++++++++++++++++++++++++ sway/config.c | 5 ++- sway/config/gesture.c | 5 ++- sway/config/target.c | 41 ++++++++++++++++++++ sway/input/cursor.c | 49 +++++++++++++++++------- sway/input/seat.c | 15 +++++++- sway/meson.build | 11 +++++- 20 files changed, 385 insertions(+), 20 deletions(-) create mode 100644 sway/commands/touch/gesture/delay.c create mode 100644 sway/commands/touch/gesture/pinch.c create mode 100644 sway/commands/touch/gesture/rotate.c create mode 100644 sway/commands/touch/gesture/swipe.c create mode 100644 sway/commands/touch/gesture/target.c create mode 100644 sway/commands/touch/target.c create mode 100644 sway/config/target.c diff --git a/include/sway/commands.h b/include/sway/commands.h index 3e7a03eb3..5883fa925 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -282,9 +282,15 @@ sway_cmd seat_cmd_pointer_constraint; sway_cmd touch_cmd_gesture; sway_cmd touch_cmd_binding; +sway_cmd touch_cmd_target; sway_cmd touch_gesture_cmd_touch; sway_cmd touch_gesture_cmd_threshold; +sway_cmd touch_gesture_cmd_target; +sway_cmd touch_gesture_cmd_swipe; +sway_cmd touch_gesture_cmd_pinch; +sway_cmd touch_gesture_cmd_rotate; +sway_cmd touch_gesture_cmd_delay; sway_cmd cmd_ipc_cmd; sway_cmd cmd_ipc_events; diff --git a/include/sway/config.h b/include/sway/config.h index d8f8189d3..abaf7439c 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -106,6 +106,11 @@ struct gesture_config { char *command; }; +struct gesture_target_config { + char *identifier; + struct libtouch_target *target; +}; + /** * options for input devices @@ -428,6 +433,7 @@ struct sway_config { list_t *input_configs; list_t *input_type_configs; list_t *gesture_configs; + list_t *gesture_target_configs; list_t *seat_configs; list_t *criteria; list_t *no_focus; @@ -658,10 +664,16 @@ int gesture_identifier_cmp(const void *item, const void *data); int gesture_libtouch_cmp(const void *item, const void *data); +int gesture_target_identifier_cmp(const void *item, const void *data); + struct gesture_config *get_gesture_config(const char *identifier); struct gesture_config *new_gesture_config(const char *identifier); +struct gesture_target_config *get_gesture_target_config(const char* identifier); + +struct gesture_target_config *create_gesture_target_config(const char* identifier); + /** * Updates the value of config->font_height based on the max title height * reported by each container. If recalculate is true, the containers will diff --git a/include/sway/input/cursor.h b/include/sway/input/cursor.h index 1e06c4c31..2185bc601 100644 --- a/include/sway/input/cursor.h +++ b/include/sway/input/cursor.h @@ -36,7 +36,7 @@ struct sway_cursor { struct wl_listener axis; struct wl_listener frame; - struct libtouch_engine *gesture_engine; + struct libtouch_progress_tracker *gesture_tracker; struct wl_listener touch_down; struct wl_listener touch_up; struct wl_listener touch_motion; diff --git a/sway/commands/touch.c b/sway/commands/touch.c index 0b08aa09b..b0df71f3a 100644 --- a/sway/commands/touch.c +++ b/sway/commands/touch.c @@ -14,6 +14,7 @@ static struct cmd_handler touch_handlers[] = { { "binding", touch_cmd_binding }, { "gesture", touch_cmd_gesture }, + { "target", touch_cmd_target }, }; diff --git a/sway/commands/touch/binding.c b/sway/commands/touch/binding.c index dacd26601..3ff92dda6 100644 --- a/sway/commands/touch/binding.c +++ b/sway/commands/touch/binding.c @@ -23,6 +23,8 @@ struct cmd_results *touch_cmd_binding(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[0]); } + sway_log(SWAY_DEBUG, "libtouch: Bound gesture %s", argv[0]); + config->command = join_args(argv + 1, argc - 1); return cmd_results_new(CMD_SUCCESS, NULL); diff --git a/sway/commands/touch/gesture.c b/sway/commands/touch/gesture.c index 4450a2764..b2f44c3f6 100644 --- a/sway/commands/touch/gesture.c +++ b/sway/commands/touch/gesture.c @@ -11,6 +11,11 @@ #include static struct cmd_handler gesture_handlers[] = { + { "delay", touch_gesture_cmd_delay }, + { "pinch", touch_gesture_cmd_pinch }, + { "rotate", touch_gesture_cmd_rotate }, + { "swipe", touch_gesture_cmd_swipe }, + { "target", touch_gesture_cmd_target }, { "threshold", touch_gesture_cmd_threshold }, { "touch", touch_gesture_cmd_touch }, }; diff --git a/sway/commands/touch/gesture/delay.c b/sway/commands/touch/gesture/delay.c new file mode 100644 index 000000000..9487ad9cc --- /dev/null +++ b/sway/commands/touch/gesture/delay.c @@ -0,0 +1,33 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_delay(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + uint32_t mode = atoi(argv[0]); + + if(!config->handler_context.current_gesture) { + return cmd_results_new(CMD_FAILURE, "No current gesture"); + } else if (!config->handler_context.current_gesture->gesture) { + return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); + } + struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; + + struct libtouch_action *action = libtouch_gesture_add_delay(gesture, mode); + + config->handler_context.current_gesture_action = action; + + return cmd_results_new(CMD_SUCCESS, "Created new delay"); +}; diff --git a/sway/commands/touch/gesture/pinch.c b/sway/commands/touch/gesture/pinch.c new file mode 100644 index 000000000..eecad421a --- /dev/null +++ b/sway/commands/touch/gesture/pinch.c @@ -0,0 +1,40 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_pinch(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "pinch", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + uint32_t mode; + if(strcmp(argv[0],"in") == 0) { + mode = LIBTOUCH_PINCH_IN; + } else if (strcmp(argv[0],"out") == 0) { + mode = LIBTOUCH_PINCH_OUT; + } else { + return cmd_results_new(CMD_FAILURE, "pinch: %s is not in or out", argv[0]); + } + + if(!config->handler_context.current_gesture) { + return cmd_results_new(CMD_FAILURE, "No current gesture"); + } else if (!config->handler_context.current_gesture->gesture) { + return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); + } + struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; + + struct libtouch_action *action = libtouch_gesture_add_pinch(gesture, mode); + + config->handler_context.current_gesture_action = action; + + return cmd_results_new(CMD_SUCCESS, "Created new touch"); +}; diff --git a/sway/commands/touch/gesture/rotate.c b/sway/commands/touch/gesture/rotate.c new file mode 100644 index 000000000..0efabdda8 --- /dev/null +++ b/sway/commands/touch/gesture/rotate.c @@ -0,0 +1,40 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_rotate(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "rotate", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + uint32_t mode; + if(strcmp(argv[0],"clockwise") == 0) { + mode = LIBTOUCH_ROTATE_CLOCKWISE; + } else if (strcmp(argv[0],"counterclockwise") == 0) { + mode = LIBTOUCH_ROTATE_ANTICLOCKWISE; + } else { + return cmd_results_new(CMD_FAILURE, "rotate %s is not (anti)clockwise", argv[0]); + } + + if(!config->handler_context.current_gesture) { + return cmd_results_new(CMD_FAILURE, "No current gesture"); + } else if (!config->handler_context.current_gesture->gesture) { + return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); + } + struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; + + struct libtouch_action *action = libtouch_gesture_add_rotate(gesture, mode); + + config->handler_context.current_gesture_action = action; + + return cmd_results_new(CMD_SUCCESS, "Created new rotation"); +}; diff --git a/sway/commands/touch/gesture/swipe.c b/sway/commands/touch/gesture/swipe.c new file mode 100644 index 000000000..4d5e61574 --- /dev/null +++ b/sway/commands/touch/gesture/swipe.c @@ -0,0 +1,45 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_swipe(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "swipe", EXPECTED_EQUAL_TO, 1))) { + return error; + } + + uint32_t direction = 0; + if (strstr(argv[0], "west")) { + direction |= LIBTOUCH_MOVE_NEGATIVE_X; + } + if (strstr(argv[0], "east")) { + direction |= LIBTOUCH_MOVE_POSITIVE_X; + } + if (strstr(argv[0], "north")) { + direction |= LIBTOUCH_MOVE_POSITIVE_Y; + } + if (strstr(argv[0], "south")) { + direction |= LIBTOUCH_MOVE_NEGATIVE_Y; + } + + sway_log(SWAY_DEBUG, "Direction: %d", direction); + if (direction == 0) { + return cmd_results_new(CMD_FAILURE, "Direction %s invalid", argv[0]); + } + + struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; + + struct libtouch_action *action = libtouch_gesture_add_move(gesture, direction); + + config->handler_context.current_gesture_action = action; + + return cmd_results_new(CMD_SUCCESS, "Created new swipe"); +} diff --git a/sway/commands/touch/gesture/target.c b/sway/commands/touch/gesture/target.c new file mode 100644 index 000000000..3262e25ee --- /dev/null +++ b/sway/commands/touch/gesture/target.c @@ -0,0 +1,38 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_gesture_cmd_target(int argc, char **argv) { + struct cmd_results *error = NULL; + if((error = checkarg(argc, "target", EXPECTED_AT_LEAST, 1))) { + return error; + } + + struct gesture_target_config *target = get_gesture_target_config(argv[0]); + + if(!target) { + return cmd_results_new(CMD_FAILURE, "Could not find gesture target %s", argv[0]); + } + + if(!config->handler_context.current_gesture_action) { + return cmd_results_new(CMD_FAILURE, + "No action created for target %s", argv[0]); + + } + + libtouch_action_set_target( + config->handler_context.current_gesture_action, + target->target); + + return cmd_results_new(CMD_SUCCESS, "Bound target %s to action", argv[0]); + + +} diff --git a/sway/commands/touch/gesture/threshold.c b/sway/commands/touch/gesture/threshold.c index c0510e147..912302194 100644 --- a/sway/commands/touch/gesture/threshold.c +++ b/sway/commands/touch/gesture/threshold.c @@ -25,6 +25,7 @@ struct cmd_results *touch_gesture_cmd_threshold(int argc, char **argv) { return cmd_results_new(CMD_INVALID, "Invalid threshold: %s", argv[0]); } + sway_log(SWAY_DEBUG, "Set threshold %d", threshold); libtouch_action_set_threshold(current, threshold); return cmd_results_new(CMD_SUCCESS, "Set threshold"); diff --git a/sway/commands/touch/gesture/touch.c b/sway/commands/touch/gesture/touch.c index 546d1f443..447f4a9b6 100644 --- a/sway/commands/touch/gesture/touch.c +++ b/sway/commands/touch/gesture/touch.c @@ -33,8 +33,8 @@ struct cmd_results *touch_gesture_cmd_touch(int argc, char **argv) { struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; struct libtouch_action *action = libtouch_gesture_add_touch(gesture, mode); - + config->handler_context.current_gesture_action = action; - return cmd_results_new(CMD_SUCCESS, "Created new action"); + return cmd_results_new(CMD_SUCCESS, "Created new touch"); }; diff --git a/sway/commands/touch/target.c b/sway/commands/touch/target.c new file mode 100644 index 000000000..bdbdfd0c2 --- /dev/null +++ b/sway/commands/touch/target.c @@ -0,0 +1,50 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/ipc-server.h" +#include "list.h" +#include "log.h" +#include "stringop.h" +#include + +struct cmd_results *touch_cmd_target(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "target", EXPECTED_EQUAL_TO, 5))) { + return error; + } + sway_log(SWAY_DEBUG, "Trying to convert"); + double x = atoi(argv[1]); + double y = atoi(argv[2]); + double w = atoi(argv[3]); + double h = atoi(argv[4]); + sway_log(SWAY_DEBUG, "Converted: %f, %f, %f, %f", x,y,w,h); + + if(!config->gesture_engine) { + return cmd_results_new(CMD_FAILURE, "No engine exists!"); + } + + struct gesture_target_config *conf = get_gesture_target_config(argv[0]); + + if(!conf) { + return cmd_results_new(CMD_FAILURE, "Could not create target: %s", argv[0]); + } + + if(conf->target != NULL) { + return cmd_results_new(CMD_FAILURE, "target %s already bound", argv[0]); + } + + struct libtouch_target *target = libtouch_target_create(config->gesture_engine, x,y,w,h); + + if(!target) { + return cmd_results_new(CMD_FAILURE, "Could not create target"); + } + + conf->target = target; + + + return cmd_results_new(CMD_SUCCESS, "Created target: %s", argv[0]); + +}; diff --git a/sway/config.c b/sway/config.c index e14ea83a8..4ae828c40 100644 --- a/sway/config.c +++ b/sway/config.c @@ -30,6 +30,7 @@ #include "stringop.h" #include "list.h" #include "log.h" +#include struct sway_config *config = NULL; @@ -188,7 +189,8 @@ static void config_defaults(struct sway_config *config) { "--button-no-terminal 'Exit sway' 'swaymsg exit' " "--button-no-terminal 'Reload sway' 'swaymsg reload'"; config->swaynag_config_errors.detailed = true; - + if (!(config->gesture_configs = create_list())) goto cleanup; + if (!(config->gesture_target_configs = create_list())) goto cleanup; if (!(config->symbols = create_list())) goto cleanup; if (!(config->modes = create_list())) goto cleanup; if (!(config->bars = create_list())) goto cleanup; @@ -312,6 +314,7 @@ static void config_defaults(struct sway_config *config) { set_color(config->border_colors.background, 0xFFFFFF); + config->gesture_engine = libtouch_engine_create(); // Security if (!(config->command_policies = create_list())) goto cleanup; if (!(config->feature_policies = create_list())) goto cleanup; diff --git a/sway/config/gesture.c b/sway/config/gesture.c index 5514098c5..ddcdf23c5 100644 --- a/sway/config/gesture.c +++ b/sway/config/gesture.c @@ -40,5 +40,8 @@ int gesture_identifier_cmp(const void *item, const void *data) { int gesture_libtouch_cmp(const void *item, const void *data) { const struct gesture_config *gc = item; const struct libtouch_gesture *g = data; - return gc->gesture == g; + if(gc->gesture == g) + return 0; + else + return -1; } diff --git a/sway/config/target.c b/sway/config/target.c new file mode 100644 index 000000000..5e2c33737 --- /dev/null +++ b/sway/config/target.c @@ -0,0 +1,41 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include "sway/config.h" +#include "log.h" +#include + +struct gesture_target_config *get_gesture_target_config(const char* identifier) { + int i = list_seq_find(config->gesture_target_configs, gesture_target_identifier_cmp, identifier); + struct gesture_target_config *cfg = NULL; + if(i >= 0) { + cfg = config->gesture_target_configs->items[i]; + } else { + cfg = create_gesture_target_config(identifier); + list_add(config->gesture_target_configs, cfg); + } + + return cfg; +} + +struct gesture_target_config *create_gesture_target_config(const char* identifier) { + int i = list_seq_find(config->gesture_target_configs, gesture_target_identifier_cmp, identifier); + if(i >= 0) { + sway_log(SWAY_DEBUG, "Gesture target %s already created", identifier); + return NULL; + } + + struct gesture_target_config *cfg = calloc(sizeof(struct gesture_target_config), 1); + cfg->identifier = strdup(identifier); + + return cfg; +} + + +int gesture_target_identifier_cmp(const void *item, const void *data) { + const struct gesture_target_config *tc = item; + const char* identifier = data; + + return strcmp(identifier, tc->identifier); +} diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 376891e60..0e79398d0 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -332,19 +332,32 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) { wlr_seat_pointer_notify_frame(cursor->seat->wlr_seat); } -static void handle_gestures(struct libtouch_engine *engine, struct sway_seat *seat) { +static void handle_gestures(struct libtouch_progress_tracker *tracker, struct sway_seat *seat) { struct libtouch_gesture *complete; struct gesture_config *cfg; int idx; - while((complete = libtouch_handle_finished_gesture(engine))){ + cfg = (struct gesture_config*) config->gesture_configs->items[0]; + sway_log(SWAY_DEBUG, "Tracking %d gestures", libtouch_progress_tracker_n_gestures(tracker)); + for(uint32_t i = 0; i < libtouch_progress_tracker_n_gestures(tracker); i++) { + sway_log(SWAY_DEBUG, "Progress %d: %f", i, libtouch_gesture_progress_get_progress(libtouch_gesture_get_progress(tracker, i))); + } + while((complete = libtouch_handle_finished_gesture(tracker)) != NULL){ + + idx = list_seq_find(config->gesture_configs, gesture_libtouch_cmp, complete); if(idx >= 0) { + sway_log(SWAY_DEBUG, "Completed gesture %s", cfg->identifier); cfg = config->gesture_configs->items[idx]; + if(cfg->command) { - execute_command(cfg->command, seat, seat_get_focused_container(seat)); + execute_command(cfg->command, seat, NULL); } + } else { + sway_log(SWAY_DEBUG, "Gesture unbound!"); } } + + } static void handle_touch_down(struct wl_listener *listener, void *data) { @@ -365,6 +378,13 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { seat->touch_x = lx; seat->touch_y = ly; + + sway_log(SWAY_DEBUG, "Touch pos: (%f, %f)", lx,ly); + libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec, + event->touch_id, LIBTOUCH_TOUCH_DOWN, + lx, ly); + handle_gestures(cursor->gesture_tracker, seat); + if (!surface) { return; } @@ -375,10 +395,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { event->touch_id, sx, sy); cursor_set_image(cursor, NULL, NULL); } - libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, - event->touch_id, LIBTOUCH_TOUCH_DOWN, - event->x, event->y); - handle_gestures(cursor->gesture_engine, seat); + } @@ -389,9 +406,10 @@ static void handle_touch_up(struct wl_listener *listener, void *data) { struct wlr_seat *seat = cursor->seat->wlr_seat; // TODO: fall back to cursor simulation if client has not bound to touch wlr_seat_touch_notify_up(seat, event->time_msec, event->touch_id); - libtouch_engine_register_touch(cursor->gesture_engine, event->time_msec, + + libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_UP, 0, 0); - handle_gestures(cursor->gesture_engine, cursor->seat); + handle_gestures(cursor->gesture_tracker, cursor->seat); } static void handle_touch_motion(struct wl_listener *listener, void *data) { @@ -403,12 +421,20 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; + double lx, ly; wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, event->x, event->y, &lx, &ly); double sx, sy; node_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); + + sway_log(SWAY_DEBUG, "move gesture"); + libtouch_progress_register_move(cursor->gesture_tracker, event->time_msec, + event->touch_id, lx,ly); + + handle_gestures(cursor->gesture_tracker, seat); + if (seat->touch_id == event->touch_id) { seat->touch_x = lx; seat->touch_y = ly; @@ -430,10 +456,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, event->touch_id, sx, sy); } - libtouch_engine_register_move(cursor->gesture_engine, event->time_msec, - event->touch_id, event->x, event->y); - - handle_gestures(cursor->gesture_engine, seat); + } diff --git a/sway/input/seat.c b/sway/input/seat.c index ce009d7e4..de2352c8a 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -24,6 +24,7 @@ #include "sway/tree/root.h" #include "sway/tree/view.h" #include "sway/tree/workspace.h" +#include static void seat_device_destroy(struct sway_seat_device *seat_device) { if (!seat_device) { @@ -599,8 +600,11 @@ static void seat_configure_touch(struct sway_seat *seat, wlr_cursor_attach_input_device(seat->cursor->cursor, sway_device->input_device->wlr_device); seat_apply_input_config(seat, sway_device); + + } + static void seat_configure_tablet_tool(struct sway_seat *seat, struct sway_seat_device *sway_device) { seat_configure_xcursor(seat); @@ -1189,7 +1193,16 @@ void seat_apply_config(struct sway_seat *seat, wl_list_for_each(seat_device, &seat->devices, link) { seat_configure_device(seat, seat_device->input_device); } - + if(config->gesture_engine) { + sway_log(SWAY_DEBUG, "gesture engine exists"); + if(seat->cursor->gesture_tracker) { + free(seat->cursor->gesture_tracker); + } + sway_log(SWAY_DEBUG, "Gesture progress tracker created"); + seat->cursor->gesture_tracker = libtouch_progress_tracker_create( + config->gesture_engine); + + } cursor_handle_activity(seat->cursor); } diff --git a/sway/meson.build b/sway/meson.build index 3c6ce0385..f4e2cb8ec 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -37,7 +37,8 @@ sway_sources = files( 'config/seat.c', 'config/input.c', 'config/gesture.c', - + 'config/target.c', + 'commands/assign.c', 'commands/bar.c', 'commands/bind.c', @@ -179,8 +180,16 @@ sway_sources = files( 'commands/touch/binding.c', 'commands/touch/gesture.c', + 'commands/touch/target.c', 'commands/touch/gesture/touch.c', 'commands/touch/gesture/threshold.c', + 'commands/touch/gesture/target.c', + 'commands/touch/gesture/swipe.c', + 'commands/touch/gesture/rotate.c', + 'commands/touch/gesture/pinch.c', + 'commands/touch/gesture/delay.c', + + 'tree/arrange.c', 'tree/container.c', From a3e32426213bee1e3d604ff1a626d477f73cbfeb Mon Sep 17 00:00:00 2001 From: grahnen Date: Tue, 15 Jan 2019 03:45:04 +0100 Subject: [PATCH 12/17] Integrate libtouch into sway and cursor.(c|h) --- sway/input/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 0e79398d0..312841ae0 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -395,12 +395,12 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { event->touch_id, sx, sy); cursor_set_image(cursor, NULL, NULL); } - } static void handle_touch_up(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); + struct libtouch_engine *engine = cursor->gesture_engine; wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_up *event = data; struct wlr_seat *seat = cursor->seat->wlr_seat; From 16e60f2ea58ed01de6fca266023f4116f80601fe Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Sat, 20 Apr 2019 17:42:00 +0200 Subject: [PATCH 13/17] Switch to progress tracker --- sway/input/cursor.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 312841ae0..7d936de8d 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -378,8 +378,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { seat->touch_x = lx; seat->touch_y = ly; - - sway_log(SWAY_DEBUG, "Touch pos: (%f, %f)", lx,ly); libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec, event->touch_id, LIBTOUCH_TOUCH_DOWN, lx, ly); @@ -400,7 +398,6 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { static void handle_touch_up(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up); - struct libtouch_engine *engine = cursor->gesture_engine; wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_up *event = data; struct wlr_seat *seat = cursor->seat->wlr_seat; @@ -456,7 +453,6 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, event->touch_id, sx, sy); } - } From 068c777de2d49bee6b5690557b335d7bfedf3b65 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Mon, 22 Apr 2019 14:10:02 +0200 Subject: [PATCH 14/17] Follow style guide --- include/sway/config.h | 4 +- sway/commands.c | 1 - sway/commands/touch.c | 15 +++---- sway/commands/touch/binding.c | 9 ++-- sway/commands/touch/gesture.c | 11 ++--- sway/commands/touch/gesture/delay.c | 25 ++++++----- sway/commands/touch/gesture/pinch.c | 4 +- sway/commands/touch/gesture/rotate.c | 13 ++++-- sway/commands/touch/gesture/swipe.c | 2 +- sway/commands/touch/gesture/threshold.c | 11 ++--- sway/commands/touch/target.c | 18 ++++---- sway/config.c | 4 +- sway/config/gesture.c | 58 +++++++++++++------------ sway/config/target.c | 12 +++-- sway/input/cursor.c | 34 ++++++--------- 15 files changed, 112 insertions(+), 109 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index abaf7439c..751701579 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -53,6 +53,7 @@ struct sway_binding { uint32_t modifiers; char *command; }; + /** * A mouse binding and an associated command. */ @@ -111,7 +112,6 @@ struct gesture_target_config { struct libtouch_target *target; }; - /** * options for input devices */ @@ -521,7 +521,7 @@ struct sway_config { list_t *command_policies; list_t *feature_policies; list_t *ipc_policies; - + struct libtouch_engine *gesture_engine; // Context for command handlers struct { diff --git a/sway/commands.c b/sway/commands.c index 98b6650a2..a30590252 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -72,7 +72,6 @@ static struct cmd_handler handlers[] = { { "force_focus_wrapping", cmd_force_focus_wrapping }, { "fullscreen", cmd_fullscreen }, { "gaps", cmd_gaps }, - { "touch", cmd_touch }, { "hide_edge_borders", cmd_hide_edge_borders }, { "include", cmd_include }, { "input", cmd_input }, diff --git a/sway/commands/touch.c b/sway/commands/touch.c index b0df71f3a..dcf2c5151 100644 --- a/sway/commands/touch.c +++ b/sway/commands/touch.c @@ -2,13 +2,13 @@ #include #include #include +#include #include "sway/commands.h" #include "sway/config.h" #include "sway/ipc-server.h" #include "list.h" #include "log.h" #include "stringop.h" -#include // Must be in alphabetical order for bsearch static struct cmd_handler touch_handlers[] = { @@ -28,13 +28,10 @@ struct cmd_results *cmd_touch(int argc, char **argv) { config->gesture_engine = libtouch_engine_create(); sway_log(SWAY_DEBUG, "Created a new gesture engine"); } - struct cmd_handler *cmd = find_handler(argv[0], touch_handlers, sizeof(touch_handlers)); - if( cmd ) { - return config_subcommand(argv, argc, touch_handlers, sizeof(touch_handlers)); - } - return cmd_results_new(CMD_FAILURE, - "Invalid subcommand: %s", - argv[0]); - + if (find_handler(argv[0], touch_handlers, sizeof(touch_handlers))) { + return config_subcommand( + argv,argc,touch_handlers, sizeof(touch_handlers)); + } + return cmd_results_new(CMD_INVALID, "Invalid subcommand: %s", argv[0]); }; diff --git a/sway/commands/touch/binding.c b/sway/commands/touch/binding.c index 3ff92dda6..af6858704 100644 --- a/sway/commands/touch/binding.c +++ b/sway/commands/touch/binding.c @@ -2,29 +2,28 @@ #include #include #include +#include #include "sway/commands.h" #include "sway/config.h" #include "sway/ipc-server.h" #include "list.h" #include "log.h" #include "stringop.h" -#include struct cmd_results *touch_cmd_binding(int argc, char **argv) { struct cmd_results *error = NULL; - if((error = checkarg(argc, "binding", EXPECTED_AT_LEAST, 2))) { return error; } struct gesture_config *config = get_gesture_config(argv[0]); - if (!config) { - return cmd_results_new(CMD_FAILURE, "Unable to bind gesture %s", argv[0]); + return cmd_results_new( + CMD_INVALID, "Unknown gesture %s", argv[0]); } sway_log(SWAY_DEBUG, "libtouch: Bound gesture %s", argv[0]); - + config->command = join_args(argv + 1, argc - 1); return cmd_results_new(CMD_SUCCESS, NULL); diff --git a/sway/commands/touch/gesture.c b/sway/commands/touch/gesture.c index b2f44c3f6..db5e64e0e 100644 --- a/sway/commands/touch/gesture.c +++ b/sway/commands/touch/gesture.c @@ -25,7 +25,6 @@ struct cmd_results *touch_cmd_gesture(int argc, char **argv) { if((error = checkarg(argc, "gesture", EXPECTED_AT_LEAST, 2))) { return error; } - sway_log(SWAY_DEBUG, "Getting gesture conf"); struct gesture_config *gesture = get_gesture_config(argv[0]); @@ -36,12 +35,14 @@ struct cmd_results *touch_cmd_gesture(int argc, char **argv) { config->handler_context.current_gesture = gesture; - struct cmd_handler *cmd = find_handler(argv[1], gesture_handlers, sizeof(gesture_handlers)); + struct cmd_handler *cmd = find_handler( + argv[1], gesture_handlers, sizeof(gesture_handlers)); if (cmd) { - return config_subcommand(argv + 1,argc - 1,gesture_handlers, sizeof(gesture_handlers)); + return config_subcommand( + argv + 1,argc - 1, + gesture_handlers, sizeof(gesture_handlers)); } - - + return cmd_results_new(CMD_FAILURE, "Invalid Subcommand: %s", argv[1]); diff --git a/sway/commands/touch/gesture/delay.c b/sway/commands/touch/gesture/delay.c index 9487ad9cc..235cb9ab7 100644 --- a/sway/commands/touch/gesture/delay.c +++ b/sway/commands/touch/gesture/delay.c @@ -12,22 +12,27 @@ struct cmd_results *touch_gesture_cmd_delay(int argc, char **argv) { struct cmd_results *error = NULL; - if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) { + if((error = checkarg(argc, "delay", EXPECTED_EQUAL_TO, 1))) { return error; } - uint32_t mode = atoi(argv[0]); - - if(!config->handler_context.current_gesture) { - return cmd_results_new(CMD_FAILURE, "No current gesture"); - } else if (!config->handler_context.current_gesture->gesture) { - return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); + long int delay = strtol(argv[0],NULL,10); + if(delay == 0) { + return cmd_results_new( + CMD_INVALID, "Invalid delay %s", argv[0]); + } + if(!config->handler_context.current_gesture) { + return cmd_results_new( + CMD_FAILURE, "No current gesture"); } - struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; - struct libtouch_action *action = libtouch_gesture_add_delay(gesture, mode); + struct libtouch_gesture *gesture = + config->handler_context.current_gesture->gesture; + + struct libtouch_action *action = + libtouch_gesture_add_delay(gesture, mode); config->handler_context.current_gesture_action = action; - return cmd_results_new(CMD_SUCCESS, "Created new delay"); + return cmd_results_new(CMD_SUCCESS, NULL); }; diff --git a/sway/commands/touch/gesture/pinch.c b/sway/commands/touch/gesture/pinch.c index eecad421a..ae9eab7ae 100644 --- a/sway/commands/touch/gesture/pinch.c +++ b/sway/commands/touch/gesture/pinch.c @@ -22,13 +22,11 @@ struct cmd_results *touch_gesture_cmd_pinch(int argc, char **argv) { } else if (strcmp(argv[0],"out") == 0) { mode = LIBTOUCH_PINCH_OUT; } else { - return cmd_results_new(CMD_FAILURE, "pinch: %s is not in or out", argv[0]); + return cmd_results_new(CMD_INVALID, "pinch: %s is not in or out", argv[0]); } if(!config->handler_context.current_gesture) { return cmd_results_new(CMD_FAILURE, "No current gesture"); - } else if (!config->handler_context.current_gesture->gesture) { - return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); } struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; diff --git a/sway/commands/touch/gesture/rotate.c b/sway/commands/touch/gesture/rotate.c index 0efabdda8..3e450ef16 100644 --- a/sway/commands/touch/gesture/rotate.c +++ b/sway/commands/touch/gesture/rotate.c @@ -22,17 +22,22 @@ struct cmd_results *touch_gesture_cmd_rotate(int argc, char **argv) { } else if (strcmp(argv[0],"counterclockwise") == 0) { mode = LIBTOUCH_ROTATE_ANTICLOCKWISE; } else { - return cmd_results_new(CMD_FAILURE, "rotate %s is not (anti)clockwise", argv[0]); + return cmd_results_new( + CMD_INVALID, + "rotate %s is not (anti)clockwise", argv[0]); } if(!config->handler_context.current_gesture) { return cmd_results_new(CMD_FAILURE, "No current gesture"); } else if (!config->handler_context.current_gesture->gesture) { - return cmd_results_new(CMD_FAILURE, "No gesture in gesture config"); + return cmd_results_new( + CMD_FAILURE, "No gesture in gesture config"); } - struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; + struct libtouch_gesture *gesture = + config->handler_context.current_gesture->gesture; - struct libtouch_action *action = libtouch_gesture_add_rotate(gesture, mode); + struct libtouch_action *action = + libtouch_gesture_add_rotate(gesture, mode); config->handler_context.current_gesture_action = action; diff --git a/sway/commands/touch/gesture/swipe.c b/sway/commands/touch/gesture/swipe.c index 4d5e61574..be69dccf4 100644 --- a/sway/commands/touch/gesture/swipe.c +++ b/sway/commands/touch/gesture/swipe.c @@ -32,7 +32,7 @@ struct cmd_results *touch_gesture_cmd_swipe(int argc, char **argv) { sway_log(SWAY_DEBUG, "Direction: %d", direction); if (direction == 0) { - return cmd_results_new(CMD_FAILURE, "Direction %s invalid", argv[0]); + return cmd_results_new(CMD_INVALID, "Direction %s invalid", argv[0]); } struct libtouch_gesture *gesture = config->handler_context.current_gesture->gesture; diff --git a/sway/commands/touch/gesture/threshold.c b/sway/commands/touch/gesture/threshold.c index 912302194..bce1d3a27 100644 --- a/sway/commands/touch/gesture/threshold.c +++ b/sway/commands/touch/gesture/threshold.c @@ -15,15 +15,16 @@ struct cmd_results *touch_gesture_cmd_threshold(int argc, char **argv) { if((error = checkarg(argc, "touch", EXPECTED_EQUAL_TO, 1))) { return error; } - struct libtouch_action *current = config->handler_context.current_gesture_action; + struct libtouch_action *current = + config->handler_context.current_gesture_action; if(!current) { return cmd_results_new(CMD_FAILURE, "No action created"); } - int threshold = atoi(argv[0]); - if(threshold < 0) { - return cmd_results_new(CMD_INVALID, - "Invalid threshold: %s", argv[0]); + long int threshold = strtol(argv[0], NULL, 10); + if(threshold == 0) { + return cmd_results_new( + CMD_INVALID, "Invalid threshold: %s", argv[0]); } sway_log(SWAY_DEBUG, "Set threshold %d", threshold); libtouch_action_set_threshold(current, threshold); diff --git a/sway/commands/touch/target.c b/sway/commands/touch/target.c index bdbdfd0c2..17af3499f 100644 --- a/sway/commands/touch/target.c +++ b/sway/commands/touch/target.c @@ -16,10 +16,10 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) { return error; } sway_log(SWAY_DEBUG, "Trying to convert"); - double x = atoi(argv[1]); - double y = atoi(argv[2]); - double w = atoi(argv[3]); - double h = atoi(argv[4]); + double x = strtod(argv[1], NULL); + double y = strtod(argv[2], NULL); + double w = strtod(argv[3], NULL); + double h = strtod(argv[4], NULL); sway_log(SWAY_DEBUG, "Converted: %f, %f, %f, %f", x,y,w,h); if(!config->gesture_engine) { @@ -29,14 +29,17 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) { struct gesture_target_config *conf = get_gesture_target_config(argv[0]); if(!conf) { - return cmd_results_new(CMD_FAILURE, "Could not create target: %s", argv[0]); + return cmd_results_new( + CMD_FAILURE, "Could not create target: %s", argv[0]); } if(conf->target != NULL) { - return cmd_results_new(CMD_FAILURE, "target %s already bound", argv[0]); + return cmd_results_new( + CMD_FAILURE, "target %s already bound", argv[0]); } - struct libtouch_target *target = libtouch_target_create(config->gesture_engine, x,y,w,h); + struct libtouch_target *target = + libtouch_target_create(config->gesture_engine, x,y,w,h); if(!target) { return cmd_results_new(CMD_FAILURE, "Could not create target"); @@ -46,5 +49,4 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, "Created target: %s", argv[0]); - }; diff --git a/sway/config.c b/sway/config.c index 4ae828c40..51159c55c 100644 --- a/sway/config.c +++ b/sway/config.c @@ -132,6 +132,7 @@ void free_config(struct sway_config *config) { } list_free(config->criteria); } + list_free(config->no_focus); list_free(config->active_bar_modifiers); list_free_items_and_destroy(config->config_chain); @@ -143,6 +144,7 @@ void free_config(struct sway_config *config) { free(config->floating_scroll_left_cmd); free(config->floating_scroll_right_cmd); free(config->font); + free(config->gesture_engine); free(config->swaybg_command); free(config->swaynag_command); free((char *)config->current_config_path); @@ -314,7 +316,7 @@ static void config_defaults(struct sway_config *config) { set_color(config->border_colors.background, 0xFFFFFF); - config->gesture_engine = libtouch_engine_create(); + if (!(config->gesture_engine = libtouch_engine_create())) goto cleanup; // Security if (!(config->command_policies = create_list())) goto cleanup; if (!(config->feature_policies = create_list())) goto cleanup; diff --git a/sway/config/gesture.c b/sway/config/gesture.c index ddcdf23c5..362878e5d 100644 --- a/sway/config/gesture.c +++ b/sway/config/gesture.c @@ -6,42 +6,46 @@ #include "log.h" #include -struct gesture_config *get_gesture_config(const char* identifier) { - int i = list_seq_find(config->gesture_configs, gesture_identifier_cmp, identifier); - - struct gesture_config *cfg = NULL; - if(i >= 0) { - sway_log(SWAY_DEBUG, "Retrieving existing gesture"); - cfg = config->gesture_configs->items[i]; - } else { - sway_log(SWAY_DEBUG, "Adding new gesture"); - cfg = new_gesture_config(identifier); - list_add(config->gesture_configs, cfg); - } +struct gesture_config *get_gesture_config(const char *identifier) { + int i = list_seq_find( + config->gesture_configs, gesture_identifier_cmp, identifier); + + struct gesture_config *cfg = NULL; + if(i >= 0) { + sway_log(SWAY_DEBUG, "Retrieving existing gesture"); + cfg = config->gesture_configs->items[i]; + } else { + sway_log(SWAY_DEBUG, "Adding new gesture"); + cfg = new_gesture_config(identifier); + } - return cfg; - + return cfg; } struct gesture_config *new_gesture_config(const char *identifier) { - struct gesture_config *cfg = calloc(sizeof(struct gesture_config), 1); - cfg->identifier = strdup(identifier); - cfg->gesture = libtouch_gesture_create(config->gesture_engine); + struct gesture_config *cfg = calloc(sizeof(struct gesture_config), 1); + if (!cfg) { + sway_log(SWAY_ERROR, "Failed to allocate gesture_config"); + return NULL; + } + cfg->identifier = strdup(identifier); + cfg->gesture = libtouch_gesture_create(config->gesture_engine); - return cfg; + return cfg; } int gesture_identifier_cmp(const void *item, const void *data) { - const struct gesture_config *gc = item; - const char *identifier = data; - return strcmp(gc->identifier, identifier); + const struct gesture_config *gc = item; + const char *identifier = data; + return strcmp(gc->identifier, identifier); } int gesture_libtouch_cmp(const void *item, const void *data) { - const struct gesture_config *gc = item; - const struct libtouch_gesture *g = data; - if(gc->gesture == g) - return 0; - else - return -1; + const struct gesture_config *gc = item; + const struct libtouch_gesture *g = data; + if(gc->gesture == g) { + return 0; + } else { + return -1; + } } diff --git a/sway/config/target.c b/sway/config/target.c index 5e2c33737..d1848b4a6 100644 --- a/sway/config/target.c +++ b/sway/config/target.c @@ -20,19 +20,17 @@ struct gesture_target_config *get_gesture_target_config(const char* identifier) } struct gesture_target_config *create_gesture_target_config(const char* identifier) { - int i = list_seq_find(config->gesture_target_configs, gesture_target_identifier_cmp, identifier); - if(i >= 0) { - sway_log(SWAY_DEBUG, "Gesture target %s already created", identifier); - return NULL; + struct gesture_target_config *cfg = + calloc(sizeof(struct gesture_target_config), 1); + if (!cfg) { + sway_log( + SWAY_ERROR, "Could not allocate gesture_target_config"); } - - struct gesture_target_config *cfg = calloc(sizeof(struct gesture_target_config), 1); cfg->identifier = strdup(identifier); return cfg; } - int gesture_target_identifier_cmp(const void *item, const void *data) { const struct gesture_target_config *tc = item; const char* identifier = data; diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 7d936de8d..a030cf6ea 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -334,30 +334,19 @@ static void handle_cursor_frame(struct wl_listener *listener, void *data) { static void handle_gestures(struct libtouch_progress_tracker *tracker, struct sway_seat *seat) { struct libtouch_gesture *complete; - struct gesture_config *cfg; - int idx; - cfg = (struct gesture_config*) config->gesture_configs->items[0]; - sway_log(SWAY_DEBUG, "Tracking %d gestures", libtouch_progress_tracker_n_gestures(tracker)); - for(uint32_t i = 0; i < libtouch_progress_tracker_n_gestures(tracker); i++) { - sway_log(SWAY_DEBUG, "Progress %d: %f", i, libtouch_gesture_progress_get_progress(libtouch_gesture_get_progress(tracker, i))); - } - while((complete = libtouch_handle_finished_gesture(tracker)) != NULL){ - - - idx = list_seq_find(config->gesture_configs, gesture_libtouch_cmp, complete); - if(idx >= 0) { - sway_log(SWAY_DEBUG, "Completed gesture %s", cfg->identifier); + while ((complete = libtouch_handle_finished_gesture(tracker)) != NULL) { + int idx = list_seq_find(config->gesture_configs, + gesture_libtouch_cmp, complete); + if (idx >= 0) { + struct gesture_config *cfg; cfg = config->gesture_configs->items[idx]; - - if(cfg->command) { + if (cfg->command) { execute_command(cfg->command, seat, NULL); } } else { - sway_log(SWAY_DEBUG, "Gesture unbound!"); + sway_log(SWAY_ERROR, "Gesture unbound!"); } } - - } static void handle_touch_down(struct wl_listener *listener, void *data) { @@ -378,9 +367,12 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { seat->touch_x = lx; seat->touch_y = ly; - libtouch_progress_register_touch(cursor->gesture_tracker, event->time_msec, - event->touch_id, LIBTOUCH_TOUCH_DOWN, - lx, ly); + libtouch_progress_register_touch( + cursor->gesture_tracker, + event->time_msec, + event->touch_id, LIBTOUCH_TOUCH_DOWN, + lx, ly); + handle_gestures(cursor->gesture_tracker, seat); if (!surface) { From 76ec7d94333e703f0fa9ac09c67eb29b622bdebe Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Mon, 22 Apr 2019 14:12:00 +0200 Subject: [PATCH 15/17] Fix errors --- sway/commands/touch/gesture/delay.c | 2 +- sway/commands/touch/gesture/threshold.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/commands/touch/gesture/delay.c b/sway/commands/touch/gesture/delay.c index 235cb9ab7..0d52f3deb 100644 --- a/sway/commands/touch/gesture/delay.c +++ b/sway/commands/touch/gesture/delay.c @@ -30,7 +30,7 @@ struct cmd_results *touch_gesture_cmd_delay(int argc, char **argv) { config->handler_context.current_gesture->gesture; struct libtouch_action *action = - libtouch_gesture_add_delay(gesture, mode); + libtouch_gesture_add_delay(gesture, delay); config->handler_context.current_gesture_action = action; diff --git a/sway/commands/touch/gesture/threshold.c b/sway/commands/touch/gesture/threshold.c index bce1d3a27..e4e1c7445 100644 --- a/sway/commands/touch/gesture/threshold.c +++ b/sway/commands/touch/gesture/threshold.c @@ -26,7 +26,7 @@ struct cmd_results *touch_gesture_cmd_threshold(int argc, char **argv) { return cmd_results_new( CMD_INVALID, "Invalid threshold: %s", argv[0]); } - sway_log(SWAY_DEBUG, "Set threshold %d", threshold); + sway_log(SWAY_DEBUG, "Set threshold %ld", threshold); libtouch_action_set_threshold(current, threshold); return cmd_results_new(CMD_SUCCESS, "Set threshold"); From d70e55e0ef758d4c2798880001a4d530a7da647a Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Mon, 22 Apr 2019 14:14:05 +0200 Subject: [PATCH 16/17] Fix duplicated dependency --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 1a122995f..1f292cf9e 100644 --- a/meson.build +++ b/meson.build @@ -59,7 +59,7 @@ xcb = dependency('xcb', required: get_option('xwayland')) math = cc.find_library('m') rt = cc.find_library('rt') git = find_program('git', native: true, required: false) -libtouch = dependency('libtouch') + # Try first to find wlroots as a subproject, then as a system dependency wlroots_version = '>=0.4.1' wlroots_proj = subproject( From 90cbe9ce03e5dce6deb87dc87dc3cd81d5b5e6b9 Mon Sep 17 00:00:00 2001 From: Samuel Grahn Date: Mon, 22 Apr 2019 14:40:23 +0200 Subject: [PATCH 17/17] Remove empty lines --- sway/commands/touch.c | 1 - sway/commands/touch/binding.c | 3 +-- sway/commands/touch/target.c | 2 -- sway/config.c | 3 +-- sway/input/cursor.c | 10 ++++------ sway/input/seat.c | 4 +--- sway/meson.build | 2 -- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/sway/commands/touch.c b/sway/commands/touch.c index dcf2c5151..bd67bb7c8 100644 --- a/sway/commands/touch.c +++ b/sway/commands/touch.c @@ -17,7 +17,6 @@ static struct cmd_handler touch_handlers[] = { { "target", touch_cmd_target }, }; - struct cmd_results *cmd_touch(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "touch", EXPECTED_AT_LEAST, 2))) { diff --git a/sway/commands/touch/binding.c b/sway/commands/touch/binding.c index af6858704..f23c986b3 100644 --- a/sway/commands/touch/binding.c +++ b/sway/commands/touch/binding.c @@ -25,6 +25,5 @@ struct cmd_results *touch_cmd_binding(int argc, char **argv) { sway_log(SWAY_DEBUG, "libtouch: Bound gesture %s", argv[0]); config->command = join_args(argv + 1, argc - 1); - return cmd_results_new(CMD_SUCCESS, NULL); - + return cmd_results_new(CMD_SUCCESS, NULL); }; diff --git a/sway/commands/touch/target.c b/sway/commands/touch/target.c index 17af3499f..86ca8121f 100644 --- a/sway/commands/touch/target.c +++ b/sway/commands/touch/target.c @@ -46,7 +46,5 @@ struct cmd_results *touch_cmd_target(int argc, char **argv) { } conf->target = target; - - return cmd_results_new(CMD_SUCCESS, "Created target: %s", argv[0]); }; diff --git a/sway/config.c b/sway/config.c index 51159c55c..8c4d03ac0 100644 --- a/sway/config.c +++ b/sway/config.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include "stringop.h" #include "list.h" #include "log.h" -#include struct sway_config *config = NULL; @@ -132,7 +132,6 @@ void free_config(struct sway_config *config) { } list_free(config->criteria); } - list_free(config->no_focus); list_free(config->active_bar_modifiers); list_free_items_and_destroy(config->config_chain); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index a030cf6ea..a7aa44611 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -353,6 +353,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_down *event = data; + struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; @@ -379,7 +380,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) { return; } - // TODO: fall back to cursor simulation if client has not bound to touch + // TODO: fall back to cursor simulation if client has not bound to touch if (seat_is_input_allowed(seat, surface)) { wlr_seat_touch_notify_down(wlr_seat, surface, event->time_msec, event->touch_id, sx, sy); @@ -406,18 +407,17 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { wl_container_of(listener, cursor, touch_motion); wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat); struct wlr_event_touch_motion *event = data; + struct sway_seat *seat = cursor->seat; struct wlr_seat *wlr_seat = seat->wlr_seat; struct wlr_surface *surface = NULL; - double lx, ly; wlr_cursor_absolute_to_layout_coords(cursor->cursor, event->device, event->x, event->y, &lx, &ly); double sx, sy; node_at_coords(cursor->seat, lx, ly, &surface, &sx, &sy); - sway_log(SWAY_DEBUG, "move gesture"); libtouch_progress_register_move(cursor->gesture_tracker, event->time_msec, event->touch_id, lx,ly); @@ -439,7 +439,7 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { if (!surface) { return; } - + // TODO: fall back to cursor simulation if client has not bound to touch if (seat_is_input_allowed(cursor->seat, surface)) { wlr_seat_touch_notify_motion(wlr_seat, event->time_msec, @@ -447,8 +447,6 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) { } } - - static double apply_mapping_from_coord(double low, double high, double value) { if (isnan(value)) { return value; diff --git a/sway/input/seat.c b/sway/input/seat.c index de2352c8a..251d1892e 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -600,11 +600,8 @@ static void seat_configure_touch(struct sway_seat *seat, wlr_cursor_attach_input_device(seat->cursor->cursor, sway_device->input_device->wlr_device); seat_apply_input_config(seat, sway_device); - - } - static void seat_configure_tablet_tool(struct sway_seat *seat, struct sway_seat_device *sway_device) { seat_configure_xcursor(seat); @@ -1193,6 +1190,7 @@ void seat_apply_config(struct sway_seat *seat, wl_list_for_each(seat_device, &seat->devices, link) { seat_configure_device(seat, seat_device->input_device); } + if(config->gesture_engine) { sway_log(SWAY_DEBUG, "gesture engine exists"); if(seat->cursor->gesture_tracker) { diff --git a/sway/meson.build b/sway/meson.build index f4e2cb8ec..b5e43f264 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -188,8 +188,6 @@ sway_sources = files( 'commands/touch/gesture/rotate.c', 'commands/touch/gesture/pinch.c', 'commands/touch/gesture/delay.c', - - 'tree/arrange.c', 'tree/container.c',