Fix tabbing

This commit is contained in:
Nate Symer 2018-05-26 13:37:08 -04:00
parent 81a456d68d
commit 02599f6402
5 changed files with 149 additions and 150 deletions

View file

@ -84,9 +84,9 @@ struct sway_container {
double width, height;
double saved_width, saved_height;
bool has_gaps;
double gaps_inner;
double gaps_outer;
bool has_gaps;
double gaps_inner;
double gaps_outer;
list_t *children;

View file

@ -6,128 +6,128 @@
#include "stringop.h"
int read_double(char *str, double *out) {
char *end;
double v = strtod(str, &end);
if (v == -HUGE_VAL || v == HUGE_VAL || strlen(end) > 0) {
*out = 0.0;
return 1;
}
*out = v;
return 0;
char *end;
double v = strtod(str, &end);
if (v == -HUGE_VAL || v == HUGE_VAL || strlen(end) > 0) {
*out = 0.0;
return 1;
}
*out = v;
return 0;
}
struct cmd_results *cmd_gaps(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) {
return error;
}
if (strcmp(argv[0], "edge_gaps") == 0) {
if (strcmp(argv[1], "on") == 0) {
config->edge_gaps = true;
arrange_root();
} else if (strcmp(argv[1], "off") == 0) {
config->edge_gaps = false;
arrange_root();
} else if (strcmp(argv[1], "toggle") == 0) {
if (config->active) {
config->edge_gaps = !(config->edge_gaps);
arrange_root();
} else {
return cmd_results_new(CMD_INVALID, "gaps", "Cannot toggle gaps while not running.");
}
} else {
return cmd_results_new(CMD_INVALID, "gaps", "");
}
} else {
int amount_idx = 0;
char op = '=';
char scope = 'a';
bool inner = true;
if (strcmp(argv[amount_idx], "inner") == 0) {
amount_idx++;
inner = true;
} else if (strcmp(argv[amount_idx], "outer") == 0) {
amount_idx++;
inner = false;
}
if (amount_idx > 0) {
if (strcmp(argv[0], "all") == 0) {
amount_idx++;
scope = 'a';
} else if (strcmp(argv[0], "workspace") == 0) {
amount_idx++;
scope = 'w';
} else if (strcmp(argv[0], "current") == 0) {
amount_idx++;
scope = 'c';
}
if (strcmp(argv[amount_idx], "set") == 0) {
amount_idx++;
op = '=';
} else if (strcmp(argv[amount_idx], "plus") == 0) {
amount_idx++;
op = '+';
} else if (strcmp(argv[amount_idx], "minus") == 0) {
amount_idx++;
op = '-';
}
}
double val;
if (read_double(argv[amount_idx], &val) == 0) {
if (amount_idx == 0) {
config->gaps_inner = val;
config->gaps_outer = val;
arrange_root();
} else {
double total = val;
if (op == '-') {
total = (inner ? config->gaps_inner : config->gaps_outer) - val;
if (total < 0) {
total = 0;
}
} else if (op == '+') {
total = (inner ? config->gaps_inner : config->gaps_inner) + val;
}
if (scope == 'a') {
if (inner) {
config->gaps_inner = total;
} else {
config->gaps_outer = total;
}
arrange_root();
} else if (scope == 'w') {
struct sway_container *workspace =
config->handler_context.current_container;
if (workspace->type != C_WORKSPACE) {
workspace = container_parent(workspace, C_WORKSPACE);
}
workspace->has_gaps = true;
if (inner) {
workspace->gaps_inner = total;
} else {
workspace->gaps_outer = total;
}
arrange_workspace(workspace);
} else if (scope == 'c') {
struct sway_container *container =
config->handler_context.current_container;
container->has_gaps = true;
if (inner) {
container->gaps_inner = total;
} else {
container->gaps_outer = total;
}
arrange_workspace(container_parent(container, C_WORKSPACE));
}
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) {
return error;
}
}
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
if (strcmp(argv[0], "edge_gaps") == 0) {
if (strcmp(argv[1], "on") == 0) {
config->edge_gaps = true;
arrange_root();
} else if (strcmp(argv[1], "off") == 0) {
config->edge_gaps = false;
arrange_root();
} else if (strcmp(argv[1], "toggle") == 0) {
if (config->active) {
config->edge_gaps = !(config->edge_gaps);
arrange_root();
} else {
return cmd_results_new(CMD_INVALID, "gaps", "Cannot toggle gaps while not running.");
}
} else {
return cmd_results_new(CMD_INVALID, "gaps", "");
}
} else {
int amount_idx = 0;
char op = '=';
char scope = 'a';
bool inner = true;
if (strcmp(argv[amount_idx], "inner") == 0) {
amount_idx++;
inner = true;
} else if (strcmp(argv[amount_idx], "outer") == 0) {
amount_idx++;
inner = false;
}
if (amount_idx > 0) {
if (strcmp(argv[0], "all") == 0) {
amount_idx++;
scope = 'a';
} else if (strcmp(argv[0], "workspace") == 0) {
amount_idx++;
scope = 'w';
} else if (strcmp(argv[0], "current") == 0) {
amount_idx++;
scope = 'c';
}
if (strcmp(argv[amount_idx], "set") == 0) {
amount_idx++;
op = '=';
} else if (strcmp(argv[amount_idx], "plus") == 0) {
amount_idx++;
op = '+';
} else if (strcmp(argv[amount_idx], "minus") == 0) {
amount_idx++;
op = '-';
}
}
double val;
if (read_double(argv[amount_idx], &val) == 0) {
if (amount_idx == 0) {
config->gaps_inner = val;
config->gaps_outer = val;
arrange_root();
} else {
double total = val;
if (op == '-') {
total = (inner ? config->gaps_inner : config->gaps_outer) - val;
if (total < 0) {
total = 0;
}
} else if (op == '+') {
total = (inner ? config->gaps_inner : config->gaps_inner) + val;
}
if (scope == 'a') {
if (inner) {
config->gaps_inner = total;
} else {
config->gaps_outer = total;
}
arrange_root();
} else if (scope == 'w') {
struct sway_container *workspace =
config->handler_context.current_container;
if (workspace->type != C_WORKSPACE) {
workspace = container_parent(workspace, C_WORKSPACE);
}
workspace->has_gaps = true;
if (inner) {
workspace->gaps_inner = total;
} else {
workspace->gaps_outer = total;
}
arrange_workspace(workspace);
} else if (scope == 'c') {
struct sway_container *container =
config->handler_context.current_container;
container->has_gaps = true;
if (inner) {
container->gaps_inner = total;
} else {
container->gaps_outer = total;
}
arrange_workspace(container_parent(container, C_WORKSPACE));
}
}
}
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -8,21 +8,20 @@
#include "stringop.h"
struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1))) {
return error;
}
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1))) {
return error;
}
if (strcmp(argv[0], "on") == 0) {
config->smart_gaps = true;
arrange_root();
} else if (strcmp(argv[0], "off") == 0) {
config->smart_gaps = false;
arrange_root();
} else {
return cmd_results_new(CMD_INVALID, "smart_gaps",
if (strcmp(argv[0], "on") == 0) {
config->smart_gaps = true;
arrange_root();
} else if (strcmp(argv[0], "off") == 0) {
config->smart_gaps = false;
arrange_root();
} else {
return cmd_results_new(CMD_INVALID, "smart_gaps",
"Expected 'smart_gaps <on|off>' ");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -193,8 +193,8 @@ static void config_defaults(struct sway_config *config) {
config->edge_gaps = true;
config->smart_gaps = false;
config->gaps_inner = 20;//0;
config->gaps_outer = 20;//0;
config->gaps_inner = 0;
config->gaps_outer = 0;
if (!(config->active_bar_modifiers = create_list())) goto cleanup;

View file

@ -71,17 +71,17 @@ void arrange_workspace(struct sway_container *workspace) {
struct wlr_box *area = &output->sway_output->usable_area;
wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
area->width, area->height, area->x, area->y);
if (config->edge_gaps || (config->smart_gaps && workspace->children->length > 1)) {
double gaps = workspace->has_gaps ? workspace->gaps_outer : config->gaps_outer;
workspace->width = area->width - (2 * gaps);
workspace->height = area->height - (2 * gaps);
workspace->x = area->x + gaps;
workspace->y = area->y + gaps;
} else {
workspace->width = area->width;
workspace->height = area->height;
workspace->x = area->x;
workspace->y = area->y;
if (config->edge_gaps || (config->smart_gaps && workspace->children->length > 1)) {
double gaps = workspace->has_gaps ? workspace->gaps_outer : config->gaps_outer;
workspace->width = area->width - (2 * gaps);
workspace->height = area->height - (2 * gaps);
workspace->x = area->x + gaps;
workspace->y = area->y + gaps;
} else {
workspace->width = area->width;
workspace->height = area->height;
workspace->x = area->x;
workspace->y = area->y;
}
wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f",
workspace->name, workspace->x, workspace->y);