diff --git a/include/config.h b/include/config.h index 8e5e33c3..e15ba311 100644 --- a/include/config.h +++ b/include/config.h @@ -166,13 +166,6 @@ enum edge_border_types { E_BOTH /**< hide vertical and horizontal edge borders */ }; -enum floating_scroll_behavior { - FSB_GAPS_OUTER, /**< Adjust outer gaps */ - FSB_GAPS_INNER /**< Adjust inner gaps */ - // Note: in the future I expect to see more things you can do with the scroll - // wheel than maniuplating gaps -}; - /** * The configuration struct. The result of loading a config file. */ @@ -191,7 +184,8 @@ struct sway_config { uint32_t floating_mod; uint32_t dragging_key; uint32_t resizing_key; - enum floating_scroll_behavior floating_scroll; // TODO: command to set this + char *floating_scroll_up_cmd; + char *floating_scroll_down_cmd; enum swayc_layouts default_orientation; enum swayc_layouts default_layout; char *font; diff --git a/sway/commands.c b/sway/commands.c index 9b0356c4..5a592555 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -58,6 +58,7 @@ static sway_cmd cmd_exec_always; static sway_cmd cmd_exit; static sway_cmd cmd_floating; static sway_cmd cmd_floating_mod; +static sway_cmd cmd_floating_scroll; static sway_cmd cmd_focus; static sway_cmd cmd_focus_follows_mouse; static sway_cmd cmd_font; @@ -705,6 +706,32 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static struct cmd_results *cmd_floating_scroll(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "floating_scroll", EXPECTED_AT_LEAST, 1))) { + return error; + } + if (!strcasecmp("up", argv[0])) { + free(config->floating_scroll_up_cmd); + if (argc < 2) { + config->floating_scroll_up_cmd = strdup(""); + } else { + config->floating_scroll_up_cmd = join_args(argv + 1, argc - 1); + } + } else if (!strcasecmp("down", argv[0])) { + free(config->floating_scroll_down_cmd); + if (argc < 2) { + config->floating_scroll_down_cmd = strdup(""); + } else { + config->floating_scroll_down_cmd = join_args(argv + 1, argc - 1); + } + } else { + error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown command: '%s'", argv[0]); + return error; + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} + static struct cmd_results *cmd_focus(int argc, char **argv) { if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file."); struct cmd_results *error = NULL; @@ -2377,6 +2404,7 @@ static struct cmd_handler handlers[] = { { "exit", cmd_exit }, { "floating", cmd_floating }, { "floating_modifier", cmd_floating_mod }, + { "floating_scroll", cmd_floating_scroll }, { "focus", cmd_focus }, { "focus_follows_mouse", cmd_focus_follows_mouse }, { "font", cmd_font }, diff --git a/sway/config.c b/sway/config.c index 237d8996..6c1d21c8 100644 --- a/sway/config.c +++ b/sway/config.c @@ -131,6 +131,8 @@ void free_config(struct sway_config *config) { list_free(config->active_bar_modifiers); free_flat_list(config->config_chain); free(config->font); + free(config->floating_scroll_up_cmd); + free(config->floating_scroll_down_cmd); free(config); } @@ -159,7 +161,8 @@ static void config_defaults(struct sway_config *config) { config->floating_mod = 0; config->dragging_key = M_LEFT_CLICK; config->resizing_key = M_RIGHT_CLICK; - config->floating_scroll = FSB_GAPS_INNER; + config->floating_scroll_up_cmd = strdup(""); + config->floating_scroll_down_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 b82456e2..67275575 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -723,26 +723,11 @@ 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)) { - switch (config->floating_scroll) { - case FSB_GAPS_INNER: - case FSB_GAPS_OUTER: - { - int amount = (int)_amount[0]; - int i,j; - for (i = 0; i < root_container.children->length; ++i) { - swayc_t *op = root_container.children->items[i]; - for (j = 0; j < op->children->length; ++j) { - swayc_t *ws = op->children->items[j]; - if (config->floating_scroll == FSB_GAPS_INNER) { - container_map(ws, add_gaps, &amount); - } else { - ws->gaps += amount; - } - } - } - arrange_windows(&root_container, -1, -1); - break; - } + int amount = (int)_amount[0]; + if (amount > 0) { + handle_command(config->floating_scroll_up_cmd); + } else if (amount < 0) { + handle_command(config->floating_scroll_down_cmd); } } return EVENT_PASSTHROUGH; diff --git a/sway/sway.5.txt b/sway/sway.5.txt index a2570dcd..25229033 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt @@ -156,6 +156,11 @@ 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 + command, when given no arguments. + **focus_follows_mouse** :: If set to _yes_, the currently focused view will change as you move your mouse around the screen to the view that ends up underneath your mouse.