mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 06:24:20 +01:00
Implemented configurable floating scroll behavior
This commit is contained in:
parent
6abdc07559
commit
0423c41a0f
@ -168,9 +168,8 @@ enum edge_border_types {
|
|||||||
|
|
||||||
enum floating_scroll_behavior {
|
enum floating_scroll_behavior {
|
||||||
FSB_GAPS_OUTER, /**< Adjust outer gaps */
|
FSB_GAPS_OUTER, /**< Adjust outer gaps */
|
||||||
FSB_GAPS_INNER /**< Adjust inner gaps */
|
FSB_GAPS_INNER, /**< Adjust inner gaps */
|
||||||
// Note: in the future I expect to see more things you can do with the scroll
|
FSB_CUSTOM /**< Perform a user-defined action */
|
||||||
// wheel than maniuplating gaps
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,7 +190,9 @@ struct sway_config {
|
|||||||
uint32_t floating_mod;
|
uint32_t floating_mod;
|
||||||
uint32_t dragging_key;
|
uint32_t dragging_key;
|
||||||
uint32_t resizing_key;
|
uint32_t resizing_key;
|
||||||
enum floating_scroll_behavior floating_scroll; // TODO: command to set this
|
enum floating_scroll_behavior floating_scroll;
|
||||||
|
char *fsb_up;
|
||||||
|
char *fsb_down;
|
||||||
enum swayc_layouts default_orientation;
|
enum swayc_layouts default_orientation;
|
||||||
enum swayc_layouts default_layout;
|
enum swayc_layouts default_layout;
|
||||||
char *font;
|
char *font;
|
||||||
|
@ -58,6 +58,7 @@ static sway_cmd cmd_exec_always;
|
|||||||
static sway_cmd cmd_exit;
|
static sway_cmd cmd_exit;
|
||||||
static sway_cmd cmd_floating;
|
static sway_cmd cmd_floating;
|
||||||
static sway_cmd cmd_floating_mod;
|
static sway_cmd cmd_floating_mod;
|
||||||
|
static sway_cmd cmd_floating_scroll;
|
||||||
static sway_cmd cmd_focus;
|
static sway_cmd cmd_focus;
|
||||||
static sway_cmd cmd_focus_follows_mouse;
|
static sway_cmd cmd_focus_follows_mouse;
|
||||||
static sway_cmd cmd_font;
|
static sway_cmd cmd_font;
|
||||||
@ -705,6 +706,47 @@ static struct cmd_results *cmd_floating_mod(int argc, char **argv) {
|
|||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
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("behavior", argv[0])) {
|
||||||
|
if (argc < 2) {
|
||||||
|
error = cmd_results_new(CMD_INVALID, "floating_scroll", "Insufficient parameters given");
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (!strcasecmp("gaps_inner", argv[1])) {
|
||||||
|
config->floating_scroll = FSB_GAPS_INNER;
|
||||||
|
} else if (!strcasecmp("gaps_outer", argv[1])) {
|
||||||
|
config->floating_scroll = FSB_GAPS_OUTER;
|
||||||
|
} else if (!strcasecmp("custom", argv[1])) {
|
||||||
|
config->floating_scroll = FSB_CUSTOM;
|
||||||
|
} else {
|
||||||
|
error = cmd_results_new(CMD_INVALID, "floating_scroll", "Unknown behavior: '%s'", argv[1]);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
} else if (!strcasecmp("up", argv[0])) {
|
||||||
|
free(config->fsb_up);
|
||||||
|
if (argc < 2) {
|
||||||
|
config->fsb_up = strdup("");
|
||||||
|
} else {
|
||||||
|
config->fsb_up = join_args(argv + 1, argc - 1);
|
||||||
|
}
|
||||||
|
} else if (!strcasecmp("down", argv[0])) {
|
||||||
|
free(config->fsb_down);
|
||||||
|
if (argc < 2) {
|
||||||
|
config->fsb_down = strdup("");
|
||||||
|
} else {
|
||||||
|
config->fsb_down = 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) {
|
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.");
|
if (config->reading) return cmd_results_new(CMD_FAILURE, "focus", "Can't be used in config file.");
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
@ -2377,6 +2419,7 @@ static struct cmd_handler handlers[] = {
|
|||||||
{ "exit", cmd_exit },
|
{ "exit", cmd_exit },
|
||||||
{ "floating", cmd_floating },
|
{ "floating", cmd_floating },
|
||||||
{ "floating_modifier", cmd_floating_mod },
|
{ "floating_modifier", cmd_floating_mod },
|
||||||
|
{ "floating_scroll", cmd_floating_scroll },
|
||||||
{ "focus", cmd_focus },
|
{ "focus", cmd_focus },
|
||||||
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
{ "focus_follows_mouse", cmd_focus_follows_mouse },
|
||||||
{ "font", cmd_font },
|
{ "font", cmd_font },
|
||||||
|
@ -131,6 +131,8 @@ void free_config(struct sway_config *config) {
|
|||||||
list_free(config->active_bar_modifiers);
|
list_free(config->active_bar_modifiers);
|
||||||
free_flat_list(config->config_chain);
|
free_flat_list(config->config_chain);
|
||||||
free(config->font);
|
free(config->font);
|
||||||
|
free(config->fsb_up);
|
||||||
|
free(config->fsb_down);
|
||||||
free(config);
|
free(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +162,8 @@ static void config_defaults(struct sway_config *config) {
|
|||||||
config->dragging_key = M_LEFT_CLICK;
|
config->dragging_key = M_LEFT_CLICK;
|
||||||
config->resizing_key = M_RIGHT_CLICK;
|
config->resizing_key = M_RIGHT_CLICK;
|
||||||
config->floating_scroll = FSB_GAPS_INNER;
|
config->floating_scroll = FSB_GAPS_INNER;
|
||||||
|
config->fsb_up = strdup("");
|
||||||
|
config->fsb_down = strdup("");
|
||||||
config->default_layout = L_NONE;
|
config->default_layout = L_NONE;
|
||||||
config->default_orientation = L_NONE;
|
config->default_orientation = L_NONE;
|
||||||
config->font = strdup("monospace 10");
|
config->font = strdup("monospace 10");
|
||||||
|
@ -743,6 +743,16 @@ bool handle_pointer_scroll(wlc_handle view, uint32_t time, const struct wlc_modi
|
|||||||
arrange_windows(&root_container, -1, -1);
|
arrange_windows(&root_container, -1, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case FSB_CUSTOM:
|
||||||
|
{
|
||||||
|
int amount = (int)_amount[0];
|
||||||
|
if (amount > 0) {
|
||||||
|
handle_command(config->fsb_up);
|
||||||
|
} else if (amount < 0) {
|
||||||
|
handle_command(config->fsb_down);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return EVENT_PASSTHROUGH;
|
return EVENT_PASSTHROUGH;
|
||||||
|
Loading…
Reference in New Issue
Block a user