Merge pull request #2823 from tarmack/fix_edge_gaps

Fix edge gaps
This commit is contained in:
Brian Ashworth 2018-10-13 18:49:31 -04:00 committed by GitHub
commit 350f7d3460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 53 deletions

View File

@ -389,7 +389,6 @@ struct sway_config {
bool show_marks;
bool tiling_drag;
bool edge_gaps;
bool smart_gaps;
int gaps_inner;
int gaps_outer;

View File

@ -20,31 +20,6 @@ struct gaps_data {
int amount;
};
// gaps edge_gaps on|off|toggle
static struct cmd_results *gaps_edge_gaps(int argc, char **argv) {
struct cmd_results *error;
if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
return error;
}
if (strcmp(argv[1], "on") == 0) {
config->edge_gaps = true;
} else if (strcmp(argv[1], "off") == 0) {
config->edge_gaps = false;
} else if (strcmp(argv[1], "toggle") == 0) {
if (!config->active) {
return cmd_results_new(CMD_INVALID, "gaps",
"Cannot toggle gaps while not running.");
}
config->edge_gaps = !config->edge_gaps;
} else {
return cmd_results_new(CMD_INVALID, "gaps",
"gaps edge_gaps on|off|toggle");
}
arrange_root();
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
// gaps inner|outer <px>
static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
@ -68,15 +43,17 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "gaps",
"Expected 'gaps inner|outer <px>'");
}
if (amount < 0) {
amount = 0;
}
if (inner) {
config->gaps_inner = amount;
config->gaps_inner = (amount >= 0) ? amount : 0;
} else {
config->gaps_outer = amount;
}
// Prevent negative outer gaps from moving windows out of the workspace.
if (config->gaps_outer < -config->gaps_inner) {
config->gaps_outer = -config->gaps_inner;
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
@ -95,8 +72,12 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) {
*prop -= data->amount;
break;
}
if (*prop < 0) {
*prop = 0;
// Prevent invalid gaps configurations.
if (ws->gaps_inner < 0) {
ws->gaps_inner = 0;
}
if (ws->gaps_outer < -ws->gaps_inner) {
ws->gaps_outer = -ws->gaps_inner;
}
arrange_workspace(ws);
}
@ -156,7 +137,6 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
// gaps edge_gaps on|off|toggle
// gaps inner|outer <px> - sets defaults for workspaces
// gaps inner|outer current|all set|plus|minus <px> - runtime only
struct cmd_results *cmd_gaps(int argc, char **argv) {
@ -165,10 +145,6 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
return error;
}
if (strcmp(argv[0], "edge_gaps") == 0) {
return gaps_edge_gaps(argc, argv);
}
if (argc == 2) {
return gaps_set_defaults(argc, argv);
}

View File

@ -1,5 +1,6 @@
#define _XOPEN_SOURCE 500
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
@ -20,8 +21,8 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
return NULL;
}
wsc->workspace = strdup(ws_name);
wsc->gaps_inner = -1;
wsc->gaps_outer = -1;
wsc->gaps_inner = INT_MIN;
wsc->gaps_outer = INT_MIN;
list_add(config->workspace_configs, wsc);
return wsc;
}
@ -94,7 +95,16 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "workspace gaps",
"Expected 'workspace <ws> gaps inner|outer <px>'");
}
*prop = val >= 0 ? val : 0;
*prop = val;
// Prevent invalid gaps configurations.
if (wsc->gaps_inner < 0) {
wsc->gaps_inner = 0;
}
if (wsc->gaps_outer < -wsc->gaps_inner) {
wsc->gaps_outer = -wsc->gaps_inner;
}
} else {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, "workspace", NULL);

View File

@ -234,7 +234,6 @@ static void config_defaults(struct sway_config *config) {
config->show_marks = true;
config->tiling_drag = true;
config->edge_gaps = true;
config->smart_gaps = false;
config->gaps_inner = 0;
config->gaps_outer = 0;

View File

@ -420,15 +420,11 @@ The default colors are:
_focus\_wrapping force_. This is only available for convenience. Please
use _focus\_wrapping_ instead when possible.
*gaps* edge\_gaps on|off|toggle
When _on_, gaps will be added between windows and workspace edges if the
inner gap is nonzero. When _off_, gaps will only be added between views.
_toggle_ cannot be used in the configuration file.
*gaps* inner|outer <amount>
Sets default _amount_ pixels of _inner_ or _outer_ gap, where the inner
affects spacing around each view and outer affects the spacing around each
workspace. Outer gaps are in addition to inner gaps.
workspace. Outer gaps are in addition to inner gaps. To reduce or remove
outer gaps, outer gaps can be set to a negative value.
This affects new workspaces only, and is used when the workspace doesn't
have its own gaps settings (see: workspace <ws> gaps inner|outer <amount>).

View File

@ -73,10 +73,10 @@ struct sway_workspace *workspace_create(struct sway_output *output,
if (name) {
struct workspace_config *wsc = workspace_find_config(name);
if (wsc) {
if (wsc->gaps_outer != -1) {
if (wsc->gaps_outer != INT_MIN) {
ws->gaps_outer = wsc->gaps_outer;
}
if (wsc->gaps_inner != -1) {
if (wsc->gaps_inner != INT_MIN) {
ws->gaps_inner = wsc->gaps_inner;
}
}
@ -618,9 +618,6 @@ void workspace_add_gaps(struct sway_workspace *ws) {
if (ws->current_gaps > 0) {
return;
}
if (!config->edge_gaps) {
return;
}
if (config->smart_gaps) {
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
struct sway_container *focus =