commit
bb51122f3d
|
@ -116,7 +116,9 @@ void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *);
|
||||||
|
|
||||||
// Mappings
|
// Mappings
|
||||||
void set_view_visibility(swayc_t *view, void *data);
|
void set_view_visibility(swayc_t *view, void *data);
|
||||||
void reset_gaps(swayc_t *view, void *data);
|
// Set or add to gaps
|
||||||
|
void set_gaps(swayc_t *view, void *amount);
|
||||||
|
void add_gaps(swayc_t *view, void *amount);
|
||||||
|
|
||||||
void update_visibility(swayc_t *container);
|
void update_visibility(swayc_t *container);
|
||||||
|
|
||||||
|
|
14
sway.5.txt
14
sway.5.txt
|
@ -64,11 +64,19 @@ Commands
|
||||||
Toggles fullscreen status for the focused view.
|
Toggles fullscreen status for the focused view.
|
||||||
|
|
||||||
**gaps** <amount>::
|
**gaps** <amount>::
|
||||||
Adds _amount_ pixels between each view, and around each output.
|
Sets _amount_ pixels as the gap between each view, and around each
|
||||||
|
workspace.
|
||||||
|
|
||||||
**gaps** <inner|outer> <amount>::
|
**gaps** <inner|outer> <amount>::
|
||||||
Adds _amount_ pixels as an _inner_ or _outer_ gap, where the former affects
|
Sets _amount_ pixels as the _inner_ or _outer_ gap, where the former affects
|
||||||
spacing between views and the latter affects the space around each output.
|
spacing between views and the latter affects the space around each
|
||||||
|
workspace.
|
||||||
|
|
||||||
|
**gaps** <inner|outer> <all|workspace|current> <set|plus|minus> <amount>::
|
||||||
|
Changes the gaps for the _inner_ or _outer_ gap. _all_ changes the gaps for
|
||||||
|
all views or workspace, _workspace_ changes gaps for all views in current
|
||||||
|
workspace, or current workspace, and _current_ changes gaps for the current
|
||||||
|
view or workspace.
|
||||||
|
|
||||||
**kill**::
|
**kill**::
|
||||||
Closes the currently focused view.
|
Closes the currently focused view.
|
||||||
|
|
131
sway/commands.c
131
sway/commands.c
|
@ -517,9 +517,10 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
|
||||||
if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
|
if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const char *amount_str = argv[0];
|
||||||
if (argc == 1) {
|
// gaps amount
|
||||||
int amount = (int)strtol(argv[0], NULL, 10);
|
if (argc >= 1 && isdigit(*amount_str)) {
|
||||||
|
int amount = (int)strtol(amount_str, NULL, 10);
|
||||||
if (errno == ERANGE || amount == 0) {
|
if (errno == ERANGE || amount == 0) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return false;
|
return false;
|
||||||
|
@ -530,23 +531,127 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
|
||||||
if (config->gaps_outer == 0) {
|
if (config->gaps_outer == 0) {
|
||||||
config->gaps_outer = amount;
|
config->gaps_outer = amount;
|
||||||
}
|
}
|
||||||
} else if (argc == 2) {
|
return true;
|
||||||
int amount = (int)strtol(argv[1], NULL, 10);
|
}
|
||||||
|
// gaps inner|outer n
|
||||||
|
else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) {
|
||||||
|
int amount = (int)strtol(amount_str, NULL, 10);
|
||||||
if (errno == ERANGE || amount == 0) {
|
if (errno == ERANGE || amount == 0) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcasecmp(argv[0], "inner") == 0) {
|
const char *target_str = argv[0];
|
||||||
|
if (strcasecmp(target_str, "inner") == 0) {
|
||||||
config->gaps_inner = amount;
|
config->gaps_inner = amount;
|
||||||
} else if (strcasecmp(argv[0], "outer") == 0) {
|
} else if (strcasecmp(target_str, "outer") == 0) {
|
||||||
config->gaps_outer = amount;
|
config->gaps_outer = amount;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// gaps inner|outer current|all set|plus|minus n
|
||||||
|
if (argc < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// gaps inner|outer ...
|
||||||
|
const char *inout_str = argv[0];
|
||||||
|
enum {INNER, OUTER} inout;
|
||||||
|
if (strcasecmp(inout_str, "inner") == 0) {
|
||||||
|
inout = INNER;
|
||||||
|
} else if (strcasecmp(inout_str, "outer") == 0) {
|
||||||
|
inout = OUTER;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// gaps ... current|all ...
|
||||||
|
const char *target_str = argv[1];
|
||||||
|
enum {CURRENT, WORKSPACE, ALL} target;
|
||||||
|
if (strcasecmp(target_str, "current") == 0) {
|
||||||
|
target = CURRENT;
|
||||||
|
} else if (strcasecmp(target_str, "all") == 0) {
|
||||||
|
target = ALL;
|
||||||
|
} else if (strcasecmp(target_str, "workspace") == 0) {
|
||||||
|
if (inout == OUTER) {
|
||||||
|
target = CURRENT;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
// Set gap for views in workspace
|
||||||
|
target = WORKSPACE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
arrange_windows(&root_container, -1, -1);
|
|
||||||
|
// gaps ... n
|
||||||
|
amount_str = argv[3];
|
||||||
|
int amount = (int)strtol(amount_str, NULL, 10);
|
||||||
|
if (errno == ERANGE || amount == 0) {
|
||||||
|
errno = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// gaps ... set|plus|minus ...
|
||||||
|
const char *method_str = argv[2];
|
||||||
|
enum {SET, ADD} method;
|
||||||
|
if (strcasecmp(method_str, "set") == 0) {
|
||||||
|
method = SET;
|
||||||
|
} else if (strcasecmp(method_str, "plus") == 0) {
|
||||||
|
method = ADD;
|
||||||
|
} else if (strcasecmp(method_str, "minus") == 0) {
|
||||||
|
method = ADD;
|
||||||
|
amount *= -1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target == CURRENT) {
|
||||||
|
swayc_t *cont;
|
||||||
|
if (inout == OUTER) {
|
||||||
|
if ((cont = swayc_active_workspace()) == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((cont = get_focused_view(&root_container))->type != C_VIEW) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cont->gaps = swayc_gap(cont);
|
||||||
|
if (method == SET) {
|
||||||
|
cont->gaps = amount;
|
||||||
|
} else if ((cont->gaps += amount) < 0) {
|
||||||
|
cont->gaps = 0;
|
||||||
|
}
|
||||||
|
arrange_windows(cont->parent, -1, -1);
|
||||||
|
} else if (inout == OUTER) {
|
||||||
|
//resize all workspace.
|
||||||
|
int i,j;
|
||||||
|
for (i = 0; i < root_container.children->length; ++i) {
|
||||||
|
swayc_t *op = root_container.children->items[i];
|
||||||
|
for (j = 0; j < op->children->length; ++j) {
|
||||||
|
swayc_t *ws = op->children->items[j];
|
||||||
|
if (method == SET) {
|
||||||
|
ws->gaps = amount;
|
||||||
|
} else if ((ws->gaps += amount) < 0) {
|
||||||
|
ws->gaps = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
arrange_windows(&root_container, -1, -1);
|
||||||
|
} else {
|
||||||
|
// Resize gaps for all views in workspace
|
||||||
|
swayc_t *top;
|
||||||
|
if (target == WORKSPACE) {
|
||||||
|
if ((top = swayc_active_workspace()) == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
top = &root_container;
|
||||||
|
}
|
||||||
|
int top_gap = top->gaps;
|
||||||
|
container_map(top, method == SET ? set_gaps : add_gaps, &amount);
|
||||||
|
top->gaps = top_gap;
|
||||||
|
arrange_windows(top, -1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,10 +1080,10 @@ bool handle_command(struct sway_config *config, char *exec) {
|
||||||
char **argv = split_directive(exec + strlen(handler->command), &argc);
|
char **argv = split_directive(exec + strlen(handler->command), &argc);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
// Perform var subs on all parts of the command
|
// Perform var subs on all parts of the command
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
argv[i] = do_var_replacement(config, argv[i]);
|
argv[i] = do_var_replacement(config, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
exec_success = handler->handle(config, argc, argv);
|
exec_success = handler->handle(config, argc, argv);
|
||||||
for (i = 0; i < argc; ++i) {
|
for (i = 0; i < argc; ++i) {
|
||||||
|
|
|
@ -246,7 +246,6 @@ _continue:
|
||||||
|
|
||||||
if (is_active) {
|
if (is_active) {
|
||||||
temp_config->reloading = false;
|
temp_config->reloading = false;
|
||||||
container_map(&root_container, reset_gaps, NULL);
|
|
||||||
arrange_windows(&root_container, -1, -1);
|
arrange_windows(&root_container, -1, -1);
|
||||||
}
|
}
|
||||||
config = temp_config;
|
config = temp_config;
|
||||||
|
|
|
@ -653,15 +653,24 @@ void update_visibility(swayc_t *container) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset_gaps(swayc_t *view, void *data) {
|
void set_gaps(swayc_t *view, void *_data) {
|
||||||
(void) data;
|
int *data = _data;
|
||||||
if (!ASSERT_NONNULL(view)) {
|
if (!ASSERT_NONNULL(view)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (view->type == C_WORKSPACE) {
|
if (view->type == C_WORKSPACE || view->type == C_VIEW) {
|
||||||
view->gaps = -1;
|
view->gaps = *data;
|
||||||
}
|
}
|
||||||
if (view->type == C_VIEW) {
|
}
|
||||||
view->gaps = -1;
|
|
||||||
|
void add_gaps(swayc_t *view, void *_data) {
|
||||||
|
int *data = _data;
|
||||||
|
if (!ASSERT_NONNULL(view)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (view->type == C_WORKSPACE || view->type == C_VIEW) {
|
||||||
|
if ((view->gaps += *data) < 0) {
|
||||||
|
view->gaps = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,8 +159,9 @@ static void container_log(const swayc_t *c) {
|
||||||
c->layout == L_STACKED ? "Stacked|":
|
c->layout == L_STACKED ? "Stacked|":
|
||||||
c->layout == L_FLOATING ? "Floating|":
|
c->layout == L_FLOATING ? "Floating|":
|
||||||
"Unknown|");
|
"Unknown|");
|
||||||
fprintf(stderr, "w:%f|h:%f|", c->width, c->height);
|
fprintf(stderr, "w:%.f|h:%.f|", c->width, c->height);
|
||||||
fprintf(stderr, "x:%f|y:%f|", c->x, c->y);
|
fprintf(stderr, "x:%.f|y:%.f|", c->x, c->y);
|
||||||
|
fprintf(stderr, "g:%d|",c->gaps);
|
||||||
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
fprintf(stderr, "vis:%c|", c->visible?'t':'f');
|
||||||
fprintf(stderr, "name:%.16s|", c->name);
|
fprintf(stderr, "name:%.16s|", c->name);
|
||||||
fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
|
fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
|
||||||
|
|
Loading…
Reference in a new issue