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) {