Merge pull request #524 from mikkeloscar/smart-gaps

Implement 'smart_gaps' feature from i3-gaps
This commit is contained in:
Drew DeVault 2016-03-20 07:45:51 -04:00
commit 599d6ab651
6 changed files with 27 additions and 2 deletions

View file

@ -181,6 +181,7 @@ struct sway_config {
bool seamless_mouse;
bool edge_gaps;
bool smart_gaps;
int gaps_inner;
int gaps_outer;
};

View file

@ -68,6 +68,7 @@ static sway_cmd cmd_reload;
static sway_cmd cmd_resize;
static sway_cmd cmd_scratchpad;
static sway_cmd cmd_set;
static sway_cmd cmd_smart_gaps;
static sway_cmd cmd_split;
static sway_cmd cmd_splith;
static sway_cmd cmd_splitt;
@ -1480,6 +1481,23 @@ static struct cmd_results *cmd_gaps(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
static struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "smart_gaps", EXPECTED_EQUAL_TO, 1))) {
return error;
}
if (strcasecmp(argv[0], "on") == 0) {
config->smart_gaps = true;
} else if (strcasecmp(argv[0], "off") == 0) {
config->smart_gaps = false;
} else {
return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps <on|off>'");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
static struct cmd_results *cmd_kill(int argc, char **argv) {
if (config->reading) return cmd_results_new(CMD_FAILURE, "kill", "Can't be used in config file.");
if (!config->active) return cmd_results_new(CMD_FAILURE, "kill", "Can only be used when sway is running.");
@ -2048,6 +2066,7 @@ static struct cmd_handler handlers[] = {
{ "scratchpad", cmd_scratchpad },
{ "seamless_mouse", cmd_seamless_mouse },
{ "set", cmd_set },
{ "smart_gaps", cmd_smart_gaps },
{ "split", cmd_split },
{ "splith", cmd_splith },
{ "splitt", cmd_splitt },

View file

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

View file

@ -675,7 +675,7 @@ int swayc_gap(swayc_t *container) {
return container->gaps >= 0 ? container->gaps : config->gaps_inner;
} else if (container->type == C_WORKSPACE) {
int base = container->gaps >= 0 ? container->gaps : config->gaps_outer;
if (config->edge_gaps) {
if (config->edge_gaps && !(config->smart_gaps && container->children->length == 1)) {
// the inner gap is created via a margin around each window which
// is half the gap size, so the workspace also needs half a gap
// size to make the outermost gap the same size (excluding the

View file

@ -406,7 +406,7 @@ void update_geometry(swayc_t *container) {
if (op->focused == ws) {
wlc_view_bring_to_front(container->handle);
}
} else if (!config->edge_gaps && gap > 0) {
} else if ((!config->edge_gaps && gap > 0) || (config->smart_gaps && ws->children->length == 1)) {
// Remove gap against the workspace edges. Because a pixel is not
// divisable, depending on gap size and the number of siblings our view
// might be at the workspace edge without being exactly so (thus test

View file

@ -154,6 +154,10 @@ or triggered at runtime.
workspace (or current workspace), and _current_ changes gaps for the current
view or workspace.
**smart_gaps** <on|off>::
If smart_gaps are _on_ then gaps will only be enabled if a workspace has more
than one child container.
**mode** <mode_name>::
Switches to the given mode_name. the default mode is simply _default_. To
create a new mode in config append _{_ to this command, the following lines