|
|
@ -1,4 +1,5 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <strings.h>
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/config.h"
|
|
|
|
#include "sway/tree/arrange.h"
|
|
|
|
#include "sway/tree/arrange.h"
|
|
|
@ -13,19 +14,15 @@ enum gaps_op {
|
|
|
|
GAPS_OP_SUBTRACT
|
|
|
|
GAPS_OP_SUBTRACT
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum gaps_scope {
|
|
|
|
struct gaps_data {
|
|
|
|
GAPS_SCOPE_ALL,
|
|
|
|
bool inner;
|
|
|
|
GAPS_SCOPE_WORKSPACE,
|
|
|
|
enum gaps_op operation;
|
|
|
|
GAPS_SCOPE_CURRENT
|
|
|
|
int amount;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct cmd_results *cmd_gaps(int argc, char **argv) {
|
|
|
|
// gaps edge_gaps on|off|toggle
|
|
|
|
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1);
|
|
|
|
static struct cmd_results *gaps_edge_gaps(int argc, char **argv) {
|
|
|
|
if (error) {
|
|
|
|
struct cmd_results *error;
|
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(argv[0], "edge_gaps") == 0) {
|
|
|
|
|
|
|
|
if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
|
|
|
|
if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
|
|
|
|
return error;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -45,140 +42,145 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
|
|
|
|
"gaps edge_gaps on|off|toggle");
|
|
|
|
"gaps edge_gaps on|off|toggle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrange_root();
|
|
|
|
arrange_root();
|
|
|
|
} else {
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
|
|
int amount_idx = 0; // the current index in argv
|
|
|
|
}
|
|
|
|
enum gaps_op op = GAPS_OP_SET;
|
|
|
|
|
|
|
|
enum gaps_scope scope = GAPS_SCOPE_ALL;
|
|
|
|
|
|
|
|
bool inner = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(argv[0], "inner") == 0) {
|
|
|
|
|
|
|
|
amount_idx++;
|
|
|
|
|
|
|
|
inner = true;
|
|
|
|
|
|
|
|
} else if (strcmp(argv[0], "outer") == 0) {
|
|
|
|
|
|
|
|
amount_idx++;
|
|
|
|
|
|
|
|
inner = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If one of the long variants of the gaps command is used
|
|
|
|
// gaps inner|outer <px>
|
|
|
|
// (which starts with inner|outer) check the number of args
|
|
|
|
static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
|
|
|
|
if (amount_idx > 0) { // if we've seen inner|outer
|
|
|
|
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
|
|
|
|
if (argc > 2) { // check the longest variant
|
|
|
|
|
|
|
|
error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // check the next longest format
|
|
|
|
|
|
|
|
error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 1);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (argc == 4) {
|
|
|
|
bool inner;
|
|
|
|
// Long format: all|workspace|current.
|
|
|
|
if (strcasecmp(argv[0], "inner") == 0) {
|
|
|
|
if (strcmp(argv[amount_idx], "all") == 0) {
|
|
|
|
inner = true;
|
|
|
|
amount_idx++;
|
|
|
|
} else if (strcasecmp(argv[0], "outer") == 0) {
|
|
|
|
scope = GAPS_SCOPE_ALL;
|
|
|
|
inner = false;
|
|
|
|
} else if (strcmp(argv[amount_idx], "workspace") == 0) {
|
|
|
|
} else {
|
|
|
|
amount_idx++;
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
scope = GAPS_SCOPE_WORKSPACE;
|
|
|
|
"Expected 'gaps inner|outer <px>'");
|
|
|
|
} else if (strcmp(argv[amount_idx], "current") == 0) {
|
|
|
|
|
|
|
|
amount_idx++;
|
|
|
|
|
|
|
|
scope = GAPS_SCOPE_CURRENT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Long format: set|plus|minus
|
|
|
|
|
|
|
|
if (strcmp(argv[amount_idx], "set") == 0) {
|
|
|
|
|
|
|
|
amount_idx++;
|
|
|
|
|
|
|
|
op = GAPS_OP_SET;
|
|
|
|
|
|
|
|
} else if (strcmp(argv[amount_idx], "plus") == 0) {
|
|
|
|
|
|
|
|
amount_idx++;
|
|
|
|
|
|
|
|
op = GAPS_OP_ADD;
|
|
|
|
|
|
|
|
} else if (strcmp(argv[amount_idx], "minus") == 0) {
|
|
|
|
|
|
|
|
amount_idx++;
|
|
|
|
|
|
|
|
op = GAPS_OP_SUBTRACT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *end;
|
|
|
|
char *end;
|
|
|
|
double val = strtod(argv[amount_idx], &end);
|
|
|
|
int amount = strtol(argv[1], &end, 10);
|
|
|
|
|
|
|
|
if (strlen(end) && strcasecmp(end, "px") != 0) {
|
|
|
|
if (strlen(end) && val == 0.0) { // invalid <amount>
|
|
|
|
|
|
|
|
// guess which variant of the command was attempted
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps", "gaps <amount>");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
"gaps inner|outer <amount>");
|
|
|
|
"Expected 'gaps inner|outer <px>'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
if (amount < 0) {
|
|
|
|
"gaps inner|outer all|workspace|current set|plus|minus <amount>");
|
|
|
|
amount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (amount_idx == 0) { // gaps <amount>
|
|
|
|
if (inner) {
|
|
|
|
config->gaps_inner = val;
|
|
|
|
config->gaps_inner = amount;
|
|
|
|
config->gaps_outer = val;
|
|
|
|
} else {
|
|
|
|
arrange_root();
|
|
|
|
config->gaps_outer = amount;
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Other variants. The middle-length variant (gaps inner|outer <amount>)
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
|
|
// just defaults the scope to "all" and defaults the op to "set".
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double total;
|
|
|
|
static void configure_gaps(struct sway_workspace *ws, void *_data) {
|
|
|
|
switch (op) {
|
|
|
|
struct gaps_data *data = _data;
|
|
|
|
case GAPS_OP_SUBTRACT: {
|
|
|
|
int *prop = data->inner ? &ws->gaps_inner : &ws->gaps_outer;
|
|
|
|
total = (inner ? config->gaps_inner : config->gaps_outer) - val;
|
|
|
|
|
|
|
|
if (total < 0) {
|
|
|
|
switch (data->operation) {
|
|
|
|
total = 0;
|
|
|
|
case GAPS_OP_SET:
|
|
|
|
}
|
|
|
|
*prop = data->amount;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GAPS_OP_ADD:
|
|
|
|
case GAPS_OP_ADD: {
|
|
|
|
*prop += data->amount;
|
|
|
|
total = (inner ? config->gaps_inner : config->gaps_outer) + val;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GAPS_OP_SUBTRACT:
|
|
|
|
case GAPS_OP_SET: {
|
|
|
|
*prop -= data->amount;
|
|
|
|
total = val;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*prop < 0) {
|
|
|
|
|
|
|
|
*prop = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
arrange_workspace(ws);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (scope == GAPS_SCOPE_ALL) {
|
|
|
|
// gaps inner|outer current|all set|plus|minus <px>
|
|
|
|
if (inner) {
|
|
|
|
static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
|
|
|
|
config->gaps_inner = total;
|
|
|
|
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 4);
|
|
|
|
} else {
|
|
|
|
if (error) {
|
|
|
|
config->gaps_outer = total;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrange_root();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
struct gaps_data data;
|
|
|
|
if (scope == GAPS_SCOPE_WORKSPACE) {
|
|
|
|
|
|
|
|
struct sway_workspace *ws = config->handler_context.workspace;
|
|
|
|
if (strcasecmp(argv[0], "inner") == 0) {
|
|
|
|
ws->has_gaps = true;
|
|
|
|
data.inner = true;
|
|
|
|
if (inner) {
|
|
|
|
} else if (strcasecmp(argv[0], "outer") == 0) {
|
|
|
|
ws->gaps_inner = total;
|
|
|
|
data.inner = false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ws->gaps_outer = total;
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
|
|
|
|
"Expected 'gaps inner|outer current|all set|plus|minus <px>'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrange_workspace(ws);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
bool all;
|
|
|
|
struct sway_container *c = config->handler_context.container;
|
|
|
|
if (strcasecmp(argv[1], "current") == 0) {
|
|
|
|
c->has_gaps = true;
|
|
|
|
all = false;
|
|
|
|
if (inner) {
|
|
|
|
} else if (strcasecmp(argv[1], "all") == 0) {
|
|
|
|
c->gaps_inner = total;
|
|
|
|
all = true;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
c->gaps_outer = total;
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
|
|
|
|
"Expected 'gaps inner|outer current|all set|plus|minus <px>'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
arrange_workspace(c->workspace);
|
|
|
|
|
|
|
|
|
|
|
|
if (strcasecmp(argv[2], "set") == 0) {
|
|
|
|
|
|
|
|
data.operation = GAPS_OP_SET;
|
|
|
|
|
|
|
|
} else if (strcasecmp(argv[2], "plus") == 0) {
|
|
|
|
|
|
|
|
data.operation = GAPS_OP_ADD;
|
|
|
|
|
|
|
|
} else if (strcasecmp(argv[2], "minus") == 0) {
|
|
|
|
|
|
|
|
data.operation = GAPS_OP_SUBTRACT;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
|
|
|
|
"Expected 'gaps inner|outer current|all set|plus|minus <px>'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
data.amount = strtol(argv[3], &end, 10);
|
|
|
|
|
|
|
|
if (strlen(end) && strcasecmp(end, "px") != 0) {
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
|
|
|
|
"Expected 'gaps inner|outer current|all set|plus|minus <px>'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (all) {
|
|
|
|
|
|
|
|
root_for_each_workspace(configure_gaps, &data);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
configure_gaps(config->handler_context.workspace, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
|
|
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) {
|
|
|
|
|
|
|
|
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(argv[0], "edge_gaps") == 0) {
|
|
|
|
|
|
|
|
return gaps_edge_gaps(argc, argv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
|
|
|
|
return gaps_set_defaults(argc, argv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 4) {
|
|
|
|
|
|
|
|
if (config->active) {
|
|
|
|
|
|
|
|
return gaps_set_runtime(argc, argv);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
|
|
|
|
"This syntax can only be used when sway is running");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_INVALID, "gaps",
|
|
|
|
|
|
|
|
"Expected 'gaps inner|outer <px>' or "
|
|
|
|
|
|
|
|
"'gaps inner|outer current|all set|plus|minus <px>'");
|
|
|
|
|
|
|
|
}
|
|
|
|