diff options
-rw-r--r-- | .clang-format | 13 | ||||
-rw-r--r-- | include/sway/config.h | 3 | ||||
-rw-r--r-- | include/sway/output.h | 1 | ||||
-rw-r--r-- | sway/commands/hide_edge_borders.c | 2 | ||||
-rw-r--r-- | sway/handlers.c | 4 | ||||
-rw-r--r-- | sway/layout.c | 7 | ||||
-rw-r--r-- | sway/main.c | 29 | ||||
-rw-r--r-- | sway/output.c | 76 |
8 files changed, 127 insertions, 8 deletions
diff --git a/.clang-format b/.clang-format index 83d50545..5818da3c 100644 --- a/.clang-format +++ b/.clang-format | |||
@@ -1,7 +1,16 @@ | |||
1 | BasedOnStyle: LLVM | 1 | BasedOnStyle: LLVM |
2 | IndentWidth: 8 | 2 | IndentWidth: 4 |
3 | TabWidth: 4 | ||
3 | UseTab: Always | 4 | UseTab: Always |
4 | BreakBeforeBraces: Attach | 5 | BreakBeforeBraces: Attach |
5 | AllowShortIfStatementsOnASingleLine: false | 6 | AllowShortIfStatementsOnASingleLine: false |
6 | IndentCaseLabels: false | 7 | IndentCaseLabels: false |
7 | ColumnLimit: 0 | 8 | SortIncludes: false |
9 | ColumnLimit: 80 | ||
10 | AlignAfterOpenBracket: DontAlign | ||
11 | BinPackParameters: false | ||
12 | BinPackArguments: false | ||
13 | ContinuationIndentWidth: 8 | ||
14 | AllowAllParametersOfDeclarationOnNextLine: false | ||
15 | AllowShortLoopsOnASingleLine: true | ||
16 | ReflowComments: false | ||
diff --git a/include/sway/config.h b/include/sway/config.h index 4a14cd36..febde63d 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -178,7 +178,8 @@ enum edge_border_types { | |||
178 | E_NONE, /**< Don't hide edge borders */ | 178 | E_NONE, /**< Don't hide edge borders */ |
179 | E_VERTICAL, /**< hide vertical edge borders */ | 179 | E_VERTICAL, /**< hide vertical edge borders */ |
180 | E_HORIZONTAL, /**< hide horizontal edge borders */ | 180 | E_HORIZONTAL, /**< hide horizontal edge borders */ |
181 | E_BOTH /**< hide vertical and horizontal edge borders */ | 181 | E_BOTH, /**< hide vertical and horizontal edge borders */ |
182 | E_SMART /**< hide both if precisely one window is present in workspace */ | ||
182 | }; | 183 | }; |
183 | 184 | ||
184 | enum command_context { | 185 | enum command_context { |
diff --git a/include/sway/output.h b/include/sway/output.h index e8afd5ed..e1bdd3f0 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -7,6 +7,7 @@ | |||
7 | // Position is absolute coordinates on the edge where the adjacent output | 7 | // Position is absolute coordinates on the edge where the adjacent output |
8 | // should be searched for. | 8 | // should be searched for. |
9 | swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); | 9 | swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos); |
10 | swayc_t *swayc_opposite_output(enum movement_direction dir, const struct wlc_point *abs_pos); | ||
10 | swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest); | 11 | swayc_t *swayc_adjacent_output(swayc_t *output, enum movement_direction dir, const struct wlc_point *abs_pos, bool pick_closest); |
11 | 12 | ||
12 | // Place absolute coordinates for given container into given wlc_point. | 13 | // Place absolute coordinates for given container into given wlc_point. |
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c index 0be940c1..cb4f052d 100644 --- a/sway/commands/hide_edge_borders.c +++ b/sway/commands/hide_edge_borders.c | |||
@@ -15,6 +15,8 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | |||
15 | config->hide_edge_borders = E_HORIZONTAL; | 15 | config->hide_edge_borders = E_HORIZONTAL; |
16 | } else if (strcasecmp(argv[0], "both") == 0) { | 16 | } else if (strcasecmp(argv[0], "both") == 0) { |
17 | config->hide_edge_borders = E_BOTH; | 17 | config->hide_edge_borders = E_BOTH; |
18 | } else if (strcasecmp(argv[0], "smart") == 0) { | ||
19 | config->hide_edge_borders = E_SMART; | ||
18 | } else { | 20 | } else { |
19 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", | 21 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", |
20 | "Expected 'hide_edge_borders <none|vertical|horizontal|both>'"); | 22 | "Expected 'hide_edge_borders <none|vertical|horizontal|both>'"); |
diff --git a/sway/handlers.c b/sway/handlers.c index 3abe2fca..ad6c1c19 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -807,6 +807,10 @@ static bool swayc_border_check(swayc_t *c, const void *_origin) { | |||
807 | const struct wlc_point *origin = _origin; | 807 | const struct wlc_point *origin = _origin; |
808 | const struct wlc_geometry title_bar = c->title_bar_geometry; | 808 | const struct wlc_geometry title_bar = c->title_bar_geometry; |
809 | 809 | ||
810 | if (c->border_type != B_NORMAL) { | ||
811 | return false; | ||
812 | } | ||
813 | |||
810 | if (origin->x >= title_bar.origin.x && origin->y >= title_bar.origin.y | 814 | if (origin->x >= title_bar.origin.x && origin->y >= title_bar.origin.y |
811 | && origin->x < title_bar.origin.x + (int32_t)title_bar.size.w | 815 | && origin->x < title_bar.origin.x + (int32_t)title_bar.size.w |
812 | && origin->y < title_bar.origin.y + (int32_t)title_bar.size.h) { | 816 | && origin->y < title_bar.origin.y + (int32_t)title_bar.size.h) { |
diff --git a/sway/layout.c b/sway/layout.c index fdd2fe6b..4b30f729 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -717,6 +717,13 @@ void update_geometry(swayc_t *container) { | |||
717 | border_bottom = 0; | 717 | border_bottom = 0; |
718 | } | 718 | } |
719 | } | 719 | } |
720 | |||
721 | if (config->hide_edge_borders == E_SMART && workspace->children->length == 1) { | ||
722 | border_top = 0; | ||
723 | border_bottom = 0; | ||
724 | border_left = 0; | ||
725 | border_right = 0; | ||
726 | } | ||
720 | } | 727 | } |
721 | 728 | ||
722 | int title_bar_height = config->font_height + 4; //borders + padding | 729 | int title_bar_height = config->font_height + 4; //borders + padding |
diff --git a/sway/main.c b/sway/main.c index e8a02e7a..7bf71b53 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -10,6 +10,9 @@ | |||
10 | #include <unistd.h> | 10 | #include <unistd.h> |
11 | #include <getopt.h> | 11 | #include <getopt.h> |
12 | #include <sys/capability.h> | 12 | #include <sys/capability.h> |
13 | #ifdef __linux__ | ||
14 | #include <sys/prctl.h> | ||
15 | #endif | ||
13 | #include "sway/extensions.h" | 16 | #include "sway/extensions.h" |
14 | #include "sway/layout.h" | 17 | #include "sway/layout.h" |
15 | #include "sway/config.h" | 18 | #include "sway/config.h" |
@@ -289,6 +292,18 @@ int main(int argc, char **argv) { | |||
289 | return 0; | 292 | return 0; |
290 | } | 293 | } |
291 | 294 | ||
295 | #ifdef __linux__ | ||
296 | bool suid = false; | ||
297 | if (getuid() != geteuid() || getgid() != getegid()) { | ||
298 | // Retain capabilities after setuid() | ||
299 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { | ||
300 | sway_log(L_ERROR, "Cannot keep caps after setuid()"); | ||
301 | exit(EXIT_FAILURE); | ||
302 | } | ||
303 | suid = true; | ||
304 | } | ||
305 | #endif | ||
306 | |||
292 | // we need to setup logging before wlc_init in case it fails. | 307 | // we need to setup logging before wlc_init in case it fails. |
293 | if (debug) { | 308 | if (debug) { |
294 | init_log(L_DEBUG); | 309 | init_log(L_DEBUG); |
@@ -311,6 +326,20 @@ int main(int argc, char **argv) { | |||
311 | } | 326 | } |
312 | register_extensions(); | 327 | register_extensions(); |
313 | 328 | ||
329 | #ifdef __linux__ | ||
330 | if (suid) { | ||
331 | // Drop every cap except CAP_SYS_PTRACE | ||
332 | cap_t caps = cap_init(); | ||
333 | cap_value_t keep = CAP_SYS_PTRACE; | ||
334 | sway_log(L_INFO, "Dropping extra capabilities"); | ||
335 | if (cap_set_flag(caps, CAP_PERMITTED, 1, &keep, CAP_SET) || | ||
336 | cap_set_flag(caps, CAP_EFFECTIVE, 1, &keep, CAP_SET) || | ||
337 | cap_set_proc(caps)) { | ||
338 | sway_log(L_ERROR, "Failed to drop extra capabilities"); | ||
339 | exit(EXIT_FAILURE); | ||
340 | } | ||
341 | } | ||
342 | #endif | ||
314 | // handle SIGTERM signals | 343 | // handle SIGTERM signals |
315 | signal(SIGTERM, sig_handler); | 344 | signal(SIGTERM, sig_handler); |
316 | 345 | ||
diff --git a/sway/output.c b/sway/output.c index b337b143..c0f29c5a 100644 --- a/sway/output.c +++ b/sway/output.c | |||
@@ -13,14 +13,29 @@ void output_get_scaled_size(wlc_handle handle, struct wlc_size *size) { | |||
13 | } | 13 | } |
14 | 14 | ||
15 | swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { | 15 | swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { |
16 | swayc_t *output = NULL; | ||
17 | // If there is no output directly next to the current one, use | ||
18 | // swayc_opposite_output to wrap. | ||
16 | if (strcasecmp(name, "left") == 0) { | 19 | if (strcasecmp(name, "left") == 0) { |
17 | return swayc_adjacent_output(NULL, MOVE_LEFT, abs_pos, true); | 20 | output = swayc_adjacent_output(NULL, MOVE_LEFT, abs_pos, true); |
21 | if (!output) { | ||
22 | output = swayc_opposite_output(MOVE_RIGHT, abs_pos); | ||
23 | } | ||
18 | } else if (strcasecmp(name, "right") == 0) { | 24 | } else if (strcasecmp(name, "right") == 0) { |
19 | return swayc_adjacent_output(NULL, MOVE_RIGHT, abs_pos, true); | 25 | output = swayc_adjacent_output(NULL, MOVE_RIGHT, abs_pos, true); |
26 | if (!output) { | ||
27 | output = swayc_opposite_output(MOVE_LEFT, abs_pos); | ||
28 | } | ||
20 | } else if (strcasecmp(name, "up") == 0) { | 29 | } else if (strcasecmp(name, "up") == 0) { |
21 | return swayc_adjacent_output(NULL, MOVE_UP, abs_pos, true); | 30 | output = swayc_adjacent_output(NULL, MOVE_UP, abs_pos, true); |
31 | if (!output) { | ||
32 | output = swayc_opposite_output(MOVE_DOWN, abs_pos); | ||
33 | } | ||
22 | } else if (strcasecmp(name, "down") == 0) { | 34 | } else if (strcasecmp(name, "down") == 0) { |
23 | return swayc_adjacent_output(NULL, MOVE_DOWN, abs_pos, true); | 35 | output = swayc_adjacent_output(NULL, MOVE_DOWN, abs_pos, true); |
36 | if (!output) { | ||
37 | output = swayc_opposite_output(MOVE_UP, abs_pos); | ||
38 | } | ||
24 | } else { | 39 | } else { |
25 | for(int i = 0; i < root_container.children->length; ++i) { | 40 | for(int i = 0; i < root_container.children->length; ++i) { |
26 | swayc_t *c = root_container.children->items[i]; | 41 | swayc_t *c = root_container.children->items[i]; |
@@ -29,7 +44,58 @@ swayc_t *output_by_name(const char* name, const struct wlc_point *abs_pos) { | |||
29 | } | 44 | } |
30 | } | 45 | } |
31 | } | 46 | } |
32 | return NULL; | 47 | return output; |
48 | } | ||
49 | |||
50 | swayc_t *swayc_opposite_output(enum movement_direction dir, | ||
51 | const struct wlc_point *abs_pos) { | ||
52 | |||
53 | // Search through all the outputs and pick the output whose edge covers the | ||
54 | // given position, and is at leftmost/rightmost/upmost/downmost side of the | ||
55 | // screen (decided by the direction given). | ||
56 | swayc_t *opposite = NULL; | ||
57 | char *dir_text = NULL; | ||
58 | switch(dir) { | ||
59 | case MOVE_LEFT: | ||
60 | case MOVE_RIGHT: ; | ||
61 | for (int i = 0; i < root_container.children->length; ++i) { | ||
62 | swayc_t *c = root_container.children->items[i]; | ||
63 | if (abs_pos->y >= c->y && abs_pos->y <= c->y + c->height) { | ||
64 | if (!opposite) { | ||
65 | opposite = c; | ||
66 | } else if ((dir == MOVE_LEFT && c->x < opposite->x) | ||
67 | || (dir == MOVE_RIGHT && c->x > opposite->x)) { | ||
68 | opposite = c; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | dir_text = dir == MOVE_LEFT ? "leftmost" : "rightmost"; | ||
73 | break; | ||
74 | case MOVE_UP: | ||
75 | case MOVE_DOWN: ; | ||
76 | for (int i = 0; i < root_container.children->length; ++i) { | ||
77 | swayc_t *c = root_container.children->items[i]; | ||
78 | if (abs_pos->x >= c->x && abs_pos->x <= c->x + c->width) { | ||
79 | if (!opposite) { | ||
80 | opposite = c; | ||
81 | } else if ((dir == MOVE_UP && c->y < opposite->y) | ||
82 | || (dir == MOVE_DOWN && c->y > opposite->y)) { | ||
83 | opposite = c; | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | dir_text = dir == MOVE_UP ? "upmost" : "downmost"; | ||
88 | break; | ||
89 | default: | ||
90 | sway_abort("Function called with invalid argument."); | ||
91 | break; | ||
92 | } | ||
93 | if (opposite) { | ||
94 | sway_log(L_DEBUG, "%s (%.0fx%.0f+%.0f+%.0f) is %s from y-position %i", | ||
95 | opposite->name, opposite->width, opposite->height, opposite->x, opposite->y, | ||
96 | dir_text, abs_pos->y); | ||
97 | } | ||
98 | return opposite; | ||
33 | } | 99 | } |
34 | 100 | ||
35 | // Position is where on the edge (as absolute position) the adjacent output should be searched for. | 101 | // Position is where on the edge (as absolute position) the adjacent output should be searched for. |