Added workspace_gesture_wrap_around config option

This commit is contained in:
Erik Reider 2024-01-22 18:13:05 +01:00
parent 519bfc4ecc
commit 0b521abe88
8 changed files with 48 additions and 23 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_wrap_around;
sway_cmd cmd_xwayland; sway_cmd cmd_xwayland;
sway_cmd bar_cmd_bindcode; sway_cmd bar_cmd_bindcode;

View file

@ -508,6 +508,7 @@ struct sway_config {
bool scratchpad_minimize; bool scratchpad_minimize;
int workspace_gesture_spring_size; int workspace_gesture_spring_size;
bool workspace_gesture_wrap_around;
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_wrap_around", cmd_ws_gesture_wrap_around },
}; };
/* Config-time only commands. Keep alphabetized */ /* Config-time only commands. Keep alphabetized */

View file

@ -1,6 +1,7 @@
#define _POSIX_C_SOURCE 200809L #define _POSIX_C_SOURCE 200809L
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/config.h" #include "sway/config.h"
#include "util.h"
struct cmd_results *cmd_ws_gesture_spring_size(int argc, char **argv) { struct cmd_results *cmd_ws_gesture_spring_size(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
@ -18,3 +19,14 @@ struct cmd_results *cmd_ws_gesture_spring_size(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL); return cmd_results_new(CMD_SUCCESS, NULL);
} }
struct cmd_results *cmd_ws_gesture_wrap_around(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "workspace_gesture_wrap_around", EXPECTED_EQUAL_TO, 1))) {
return error;
}
config->workspace_gesture_wrap_around = parse_boolean(argv[0], true);
return cmd_results_new(CMD_SUCCESS, NULL);
}

View file

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

View file

@ -33,6 +33,9 @@
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
#include "util.h" #include "util.h"
#define PREV_WS_LIMIT -1.0f
#define NEXT_WS_LIMIT 1.0f
struct sway_output *output_by_name_or_id(const char *name_or_id) { struct sway_output *output_by_name_or_id(const char *name_or_id) {
for (int i = 0; i < root->outputs->length; ++i) { for (int i = 0; i < root->outputs->length; ++i) {
struct sway_output *output = root->outputs->items[i]; struct sway_output *output = root->outputs->items[i];
@ -1130,26 +1133,25 @@ void update_workspace_scroll_percent(struct sway_seat *seat, int gesture_percent
return; return;
} }
// TODO: Make the threshold configurable?? float min = PREV_WS_LIMIT, max = NEXT_WS_LIMIT;
const float THRESHOLD = MAX(0.35 - 0.1, 0); if (!config->workspace_gesture_wrap_around) {
// TODO: Make the threshold configurable??
const float THRESHOLD = MAX(0.35 - 0.1, 0);
// TODO: Make configurable? // 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 spring_limit = MIN(THRESHOLD, spring_limit);
spring_limit = MIN(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) {
float min = -1.0f, max = 1.0f; max = spring_limit;
if (visible_index + 1 >= output->workspaces->length) { }
// NOTE: Can be adjusted in the future to wrap around workspaces if (visible_index == 0) {
max = spring_limit; min = -spring_limit;
} }
if (visible_index == 0) {
// NOTE: Can be adjusted in the future to wrap around workspaces
min = -spring_limit;
} }
output->workspace_scroll.percent = MIN(max, MAX(min, percent)); output->workspace_scroll.percent = MIN(max, MAX(min, percent));
output->workspace_scroll.direction = direction; output->workspace_scroll.direction = direction;
@ -1170,9 +1172,9 @@ void snap_workspace_scroll_percent(struct sway_seat *seat) {
int dir = 0; int dir = 0;
if (output->workspace_scroll.percent < 0) { if (output->workspace_scroll.percent < 0) {
dir = -1; dir = PREV_WS_LIMIT;
} else if (output->workspace_scroll.percent > 0) { } else if (output->workspace_scroll.percent > 0) {
dir = 1; dir = NEXT_WS_LIMIT;
} else { } else {
// Skip setting workspace if the percentage is zero // Skip setting workspace if the percentage is zero
goto reset_state; goto reset_state;

View file

@ -2058,9 +2058,11 @@ void output_render(struct sway_output *output, struct timespec *when,
// Get the sibling workspaces // Get the sibling workspaces
struct sway_workspace *other_ws = NULL; struct sway_workspace *other_ws = NULL;
if (output->workspace_scroll.percent < 0) { if (output->workspace_scroll.percent < 0) {
other_ws = workspace_output_prev_wrap(workspace, false); other_ws = workspace_output_prev_wrap(workspace,
config->workspace_gesture_wrap_around);
} else { } else {
other_ws = workspace_output_next_wrap(workspace, false); other_ws = workspace_output_next_wrap(workspace,
config->workspace_gesture_wrap_around);
} }
struct sway_container *fullscreen_con = root->fullscreen_global; struct sway_container *fullscreen_con = root->fullscreen_global;

View file

@ -592,6 +592,11 @@ runtime.
Adjusts the workspace gestures spring size. Can use values between Adjusts the workspace gestures spring size. Can use values between
0 (disabled) and 100 while 50 is the default value. 0 (disabled) and 100 while 50 is the default value.
*workspace_gesture_wrap_around* <enable|disable>
Sets whether or not the workspace gesture should wrap around when trying to
swipe past the first/last workspace. Disables the
_workspace_gesture_spring_size_ config option. Disabled by default.
*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.