Merge pull request #662 from Hummer12007/scroll

Support floating_scroll sideways
This commit is contained in:
Drew DeVault 2016-05-14 16:47:45 -04:00
commit ae027aad5a
5 changed files with 32 additions and 6 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -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;
}

View File

@ -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** <up|down> [command]::
Sets the command to be executed on scrolling up and down
(respectively) while holding the floating modifier. Resets the
**floating_scroll** <up|down|left|right> [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** <yes|no>::