1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/input/cursor.h"
#include "sway/input/input-manager.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.h"
// A couple of things here:
// - view->border should never be B_CSD when the view is tiled, even when CSD is
// in use (we set using_csd instead and render a sway border).
// - view->saved_border should be the last applied border when switching to CSD.
// - view->using_csd should always reflect whether CSD is applied or not.
static void set_border(struct sway_container *con,
enum sway_container_border new_border) {
if (con->view) {
if (con->view->using_csd && new_border != B_CSD) {
view_set_csd_from_server(con->view, false);
} else if (!con->view->using_csd && new_border == B_CSD) {
view_set_csd_from_server(con->view, true);
con->saved_border = con->pending.border;
}
}
if (new_border != B_CSD || container_is_floating(con)) {
con->pending.border = new_border;
}
if (con->view) {
con->view->using_csd = new_border == B_CSD;
}
}
static void border_toggle(struct sway_container *con) {
if (con->view && con->view->using_csd) {
set_border(con, B_NONE);
return;
}
switch (con->pending.border) {
case B_NONE:
set_border(con, B_PIXEL);
break;
case B_PIXEL:
set_border(con, B_NORMAL);
break;
case B_NORMAL:
if (con->view && con->view->xdg_decoration) {
set_border(con, B_CSD);
} else {
set_border(con, B_NONE);
}
break;
case B_CSD:
// view->using_csd should be true so it would have returned above
sway_assert(false, "Unreachable");
break;
}
}
struct cmd_results *cmd_border(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
return error;
}
struct sway_container *container = config->handler_context.container;
if (!container || !container->view) {
return cmd_results_new(CMD_INVALID, "Only views can have borders");
}
struct sway_view *view = container->view;
if (strcmp(argv[0], "none") == 0) {
set_border(container, B_NONE);
} else if (strcmp(argv[0], "normal") == 0) {
set_border(container, B_NORMAL);
} else if (strcmp(argv[0], "pixel") == 0) {
set_border(container, B_PIXEL);
} else if (strcmp(argv[0], "csd") == 0) {
if (!view->xdg_decoration) {
return cmd_results_new(CMD_INVALID,
"This window doesn't support client side decorations");
}
set_border(container, B_CSD);
} else if (strcmp(argv[0], "toggle") == 0) {
border_toggle(container);
} else {
return cmd_results_new(CMD_INVALID,
"Expected 'border <none|normal|pixel|csd|toggle>' "
"or 'border pixel <px>'");
}
if (argc == 2) {
container->pending.border_thickness = atoi(argv[1]);
}
if (container_is_floating(container)) {
container_set_geometry_from_content(container);
}
arrange_container(container);
return cmd_results_new(CMD_SUCCESS, NULL);
}
|