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',