069d37f987
This commit changes how commands decide what container to act on. Commands get the current container though `current_container`, a global defined in sway/commands.c. If a criteria is given before a command, then the following command will be run once for every container the criteria matches with a reference to the matching container in 'current_container'. Commands should use this instead of `get_focused_container()` from now on. This commit also fixes a few (minor) mistakes made in implementing marks such as non-escaped arrows in sway(5) and calling the "mark" command "floating" by accident. It also cleans up `criteria.c` in a few places.
66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
#include "sway/commands.h"
|
|
#include "sway/container.h"
|
|
#include "sway/focus.h"
|
|
|
|
struct cmd_results *cmd_border(int argc, char **argv) {
|
|
struct cmd_results *error = NULL;
|
|
if (!config->active) {
|
|
return cmd_results_new(CMD_FAILURE, "border", "Can only be used when sway is running.");
|
|
}
|
|
if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
|
|
return error;
|
|
}
|
|
|
|
if (argc > 2) {
|
|
return cmd_results_new(CMD_INVALID, "border",
|
|
"Expected 'border <normal|pixel|none|toggle> [<n>]");
|
|
}
|
|
|
|
swayc_t *view = current_container;
|
|
enum swayc_border_types border = view->border_type;
|
|
int thickness = view->border_thickness;
|
|
|
|
if (strcasecmp(argv[0], "none") == 0) {
|
|
border = B_NONE;
|
|
} else if (strcasecmp(argv[0], "normal") == 0) {
|
|
border = B_NORMAL;
|
|
} else if (strcasecmp(argv[0], "pixel") == 0) {
|
|
border = B_PIXEL;
|
|
} else if (strcasecmp(argv[0], "toggle") == 0) {
|
|
switch (border) {
|
|
case B_NONE:
|
|
border = B_PIXEL;
|
|
break;
|
|
case B_NORMAL:
|
|
border = B_NONE;
|
|
break;
|
|
case B_PIXEL:
|
|
border = B_NORMAL;
|
|
break;
|
|
}
|
|
} else {
|
|
return cmd_results_new(CMD_INVALID, "border",
|
|
"Expected 'border <normal|pixel|none|toggle>");
|
|
}
|
|
|
|
if (argc == 2 && (border == B_NORMAL || border == B_PIXEL)) {
|
|
thickness = (int)strtol(argv[1], NULL, 10);
|
|
if (errno == ERANGE || thickness < 0) {
|
|
errno = 0;
|
|
return cmd_results_new(CMD_INVALID, "border", "Number is out of range.");
|
|
}
|
|
}
|
|
|
|
if (view) {
|
|
view->border_type = border;
|
|
view->border_thickness = thickness;
|
|
update_geometry(view);
|
|
}
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
}
|