From e73dde3b1057c8248eb24b3c15c99f398472eeba Mon Sep 17 00:00:00 2001 From: Mykyta Holubakha Date: Sat, 14 May 2016 23:42:02 +0300 Subject: [PATCH] Support floating_scroll sideways --- include/config.h | 2 ++ sway/commands.c | 14 ++++++++++++++ sway/config.c | 4 ++++ sway/handlers.c | 12 +++++++++--- sway/sway.5.txt | 6 +++--- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/config.h b/include/config.h index e15ba311f..3c1957b6c 100644 --- a/include/config.h +++ b/include/config.h @@ -186,6 +186,8 @@ struct sway_config { uint32_t resizing_key; char *floating_scroll_up_cmd; char *floating_scroll_down_cmd; + char *floating_scroll_left_cmd; + char *floating_scroll_right_cmd; enum swayc_layouts default_orientation; enum swayc_layouts default_layout; char *font; diff --git a/sway/commands.c b/sway/commands.c index 226214531..9c5309f9e 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -726,6 +726,20 @@ static struct cmd_results *cmd_floating_scroll(int argc, char **argv) { } else { config->floating_scroll_down_cmd = join_args(argv + 1, argc - 1); } + } else if (!strcasecmp("left", argv[0])) { + free(config->floating_scroll_left_cmd); + if (argc < 2) { + config->floating_scroll_left_cmd = strdup(""); + } else { + config->floating_scroll_left_cmd = join_args(argv + 1, argc - 1); + } + } else if (!strcasecmp("right", argv[0])) { + free(config->floating_scroll_right_cmd); + if (argc < 2) { + config->floating_scroll_right_cmd = strdup(""); + } else { + config->floating_scroll_right_cmd = join_args(argv + 1, argc - 1); + } } else { error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown command: '%s'", argv[0]); return error; diff --git a/sway/config.c b/sway/config.c index 6c1d21c8d..14b657ef2 100644 --- a/sway/config.c +++ b/sway/config.c @@ -133,6 +133,8 @@ void free_config(struct sway_config *config) { free(config->font); free(config->floating_scroll_up_cmd); free(config->floating_scroll_down_cmd); + free(config->floating_scroll_left_cmd); + free(config->floating_scroll_right_cmd); free(config); } @@ -163,6 +165,8 @@ static void config_defaults(struct sway_config *config) { config->resizing_key = M_RIGHT_CLICK; config->floating_scroll_up_cmd = strdup(""); config->floating_scroll_down_cmd = strdup(""); + config->floating_scroll_left_cmd = strdup(""); + config->floating_scroll_right_cmd = strdup(""); config->default_layout = L_NONE; config->default_orientation = L_NONE; config->font = strdup("monospace 10"); diff --git a/sway/handlers.c b/sway/handlers.c index 67275575a..931e1340e 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -723,12 +723,18 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modifiers* modifiers, uint8_t axis_bits, double _amount[2]) { if (!(modifiers->mods ^ config->floating_mod)) { - int amount = (int)_amount[0]; - if (amount > 0) { + int x_amount = (int)_amount[0]; + int y_amount = (int)_amount[1]; + if (x_amount > 0) { handle_command(config->floating_scroll_up_cmd); - } else if (amount < 0) { + } else if (x_amount < 0) { handle_command(config->floating_scroll_down_cmd); } + if (y_amount > 0) { + handle_command(config->floating_scroll_right_cmd); + } else if (y_amount < 0) { + handle_command(config->floating_scroll_left_cmd); + } } return EVENT_PASSTHROUGH; } diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 252290335..32ff79d8f 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -156,9 +156,9 @@ or triggered at runtime. enabled, left click is used for resizing and right click for dragging. The mode paramenter is optional and defaults to _normal_ if it isn't defined. -**floating_scroll** [command]:: - Sets the command to be executed on scrolling up and down - (respectively) while holding the floating modifier. Resets the +**floating_scroll** [command]:: + Sets the command to be executed on scrolling in the specified + direction while holding the floating modifier. Resets the command, when given no arguments. **focus_follows_mouse** ::