Added workspace_gesture_threshold config option

This commit is contained in:
Erik Reider 2024-01-22 18:25:00 +01:00
parent 0b521abe88
commit 1113e5653a
7 changed files with 31 additions and 8 deletions

View file

@ -231,6 +231,7 @@ sway_cmd cmd_workspace;
sway_cmd cmd_workspace_layout; sway_cmd cmd_workspace_layout;
sway_cmd cmd_ws_auto_back_and_forth; sway_cmd cmd_ws_auto_back_and_forth;
sway_cmd cmd_ws_gesture_spring_size; sway_cmd cmd_ws_gesture_spring_size;
sway_cmd cmd_ws_gesture_threshold;
sway_cmd cmd_ws_gesture_wrap_around; sway_cmd cmd_ws_gesture_wrap_around;
sway_cmd cmd_xwayland; sway_cmd cmd_xwayland;

View file

@ -509,6 +509,7 @@ struct sway_config {
int workspace_gesture_spring_size; int workspace_gesture_spring_size;
bool workspace_gesture_wrap_around; bool workspace_gesture_wrap_around;
float workspace_gesture_threshold;
list_t *layer_criteria; list_t *layer_criteria;

View file

@ -123,6 +123,7 @@ static const struct cmd_handler handlers[] = {
{ "workspace", cmd_workspace }, { "workspace", cmd_workspace },
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
{ "workspace_gesture_spring_size", cmd_ws_gesture_spring_size }, { "workspace_gesture_spring_size", cmd_ws_gesture_spring_size },
{ "workspace_gesture_threshold", cmd_ws_gesture_threshold },
{ "workspace_gesture_wrap_around", cmd_ws_gesture_wrap_around }, { "workspace_gesture_wrap_around", cmd_ws_gesture_wrap_around },
}; };

View file

@ -30,3 +30,20 @@ struct cmd_results *cmd_ws_gesture_wrap_around(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_ws_gesture_threshold(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "workspace_gesture_threshold", EXPECTED_EQUAL_TO, 1))) {
return error;
}
char *err;
float val = strtof(argv[0], &err);
if (*err || val < 0.1f || val > 0.9f) {
return cmd_results_new(CMD_INVALID, "workspace_gesture_threshold float invalid. "
"Should be between 0.1 and 0.9");
}
config->workspace_gesture_threshold = val;
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

@ -370,6 +370,7 @@ static void config_defaults(struct sway_config *config) {
config->workspace_gesture_spring_size = 50; config->workspace_gesture_spring_size = 50;
config->workspace_gesture_wrap_around = false; config->workspace_gesture_wrap_around = false;
config->workspace_gesture_threshold = 0.35;
if (!(config->layer_criteria = create_list())) goto cleanup; if (!(config->layer_criteria = create_list())) goto cleanup;

View file

@ -1135,15 +1135,14 @@ void update_workspace_scroll_percent(struct sway_seat *seat, int gesture_percent
float min = PREV_WS_LIMIT, max = NEXT_WS_LIMIT; float min = PREV_WS_LIMIT, max = NEXT_WS_LIMIT;
if (!config->workspace_gesture_wrap_around) { if (!config->workspace_gesture_wrap_around) {
// TODO: Make the threshold configurable??
const float THRESHOLD = MAX(0.35 - 0.1, 0);
// Visualized to the user that this is the last / first workspace by // Visualized to the user that this is the last / first workspace by
// allowing a small swipe, a "Spring effect" // allowing a small swipe, a "Spring effect"
float spring_limit = (float) config->workspace_gesture_spring_size / float spring_limit = (float) config->workspace_gesture_spring_size /
output->width * output->wlr_output->scale; output->width * output->wlr_output->scale;
// Make sure that the limit is always smaller than the threshold // Make sure that the limit is always smaller than the threshold to
spring_limit = MIN(THRESHOLD, spring_limit); // avoid accidental workspace switches
float small_threshold = MAX(config->workspace_gesture_threshold - 0.1, 0);
spring_limit = MIN(small_threshold, spring_limit);
// Limit the percent depending on if the workspace is the first/last or in // Limit the percent depending on if the workspace is the first/last or in
// the middle somewhere. // the middle somewhere.
if (visible_index + 1 >= output->workspaces->length) { if (visible_index + 1 >= output->workspaces->length) {
@ -1164,9 +1163,7 @@ void snap_workspace_scroll_percent(struct sway_seat *seat) {
struct sway_workspace *focused_ws = seat_get_focused_workspace(seat); struct sway_workspace *focused_ws = seat_get_focused_workspace(seat);
struct sway_output *output = focused_ws->output; struct sway_output *output = focused_ws->output;
// TODO: Make the threshold configurable?? if (fabs(output->workspace_scroll.percent) <= config->workspace_gesture_threshold) {
const float THRESHOLD = 0.35;
if (fabs(output->workspace_scroll.percent) <= THRESHOLD) {
goto reset_state; goto reset_state;
} }

View file

@ -597,6 +597,11 @@ runtime.
swipe past the first/last workspace. Disables the swipe past the first/last workspace. Disables the
_workspace_gesture_spring_size_ config option. Disabled by default. _workspace_gesture_spring_size_ config option. Disabled by default.
*workspace_gesture_spring_size* <value>
Adjusts the swipe threshold of switching workspaces. A lower value makes it
easier to switch workspaces. Accepts values between 0.1 (small swipes) and
0.9 (large swipes). The default value is set to 0.35.
*client.background* <color> *client.background* <color>
This command is ignored and is only present for i3 compatibility. This command is ignored and is only present for i3 compatibility.