aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-05-11 18:44:56 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-05-11 18:44:56 -0400
commit3db7fc2bb2c35d545b2a0a72f5554af833bd447f (patch)
tree1da6e43dca62aa55501a10598acd33dcc2d7142e
parentMerge pull request #1956 from ggreer/move-focus (diff)
downloadsway-3db7fc2bb2c35d545b2a0a72f5554af833bd447f.tar.gz
sway-3db7fc2bb2c35d545b2a0a72f5554af833bd447f.tar.zst
sway-3db7fc2bb2c35d545b2a0a72f5554af833bd447f.zip
Implement hide_edge_borders
-rw-r--r--sway/commands.c1
-rw-r--r--sway/commands/hide_edge_borders.c37
-rw-r--r--sway/desktop/output.c254
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/view.c56
5 files changed, 226 insertions, 123 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 2e1cdc2c..37ead367 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -108,6 +108,7 @@ static struct cmd_handler handlers[] = {
108 { "font", cmd_font }, 108 { "font", cmd_font },
109 { "for_window", cmd_for_window }, 109 { "for_window", cmd_for_window },
110 { "fullscreen", cmd_fullscreen }, 110 { "fullscreen", cmd_fullscreen },
111 { "hide_edge_borders", cmd_hide_edge_borders },
111 { "include", cmd_include }, 112 { "include", cmd_include },
112 { "input", cmd_input }, 113 { "input", cmd_input },
113 { "mode", cmd_mode }, 114 { "mode", cmd_mode },
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c
new file mode 100644
index 00000000..7d70055b
--- /dev/null
+++ b/sway/commands/hide_edge_borders.c
@@ -0,0 +1,37 @@
1#include "sway/commands.h"
2#include "sway/config.h"
3#include "sway/tree/container.h"
4#include "sway/tree/view.h"
5
6static void _configure_view(struct sway_container *con, void *data) {
7 if (con->type == C_VIEW) {
8 view_autoconfigure(con->sway_view);
9 }
10}
11
12struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) {
13 struct cmd_results *error = NULL;
14 if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) {
15 return error;
16 }
17
18 if (strcmp(argv[0], "none") == 0) {
19 config->hide_edge_borders = E_NONE;
20 } else if (strcmp(argv[0], "vertical") == 0) {
21 config->hide_edge_borders = E_VERTICAL;
22 } else if (strcmp(argv[0], "horizontal") == 0) {
23 config->hide_edge_borders = E_HORIZONTAL;
24 } else if (strcmp(argv[0], "both") == 0) {
25 config->hide_edge_borders = E_BOTH;
26 } else if (strcmp(argv[0], "smart") == 0) {
27 config->hide_edge_borders = E_SMART;
28 } else {
29 return cmd_results_new(CMD_INVALID, "hide_edge_borders",
30 "Expected 'hide_edge_borders "
31 "<none|vertical|horizontal|both|smart>'");
32 }
33
34 container_for_each_descendant_dfs(&root_container, _configure_view, NULL);
35
36 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
37}
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index a25139b4..c3bff03d 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -14,6 +14,7 @@
14#include <wlr/types/wlr_wl_shell.h> 14#include <wlr/types/wlr_wl_shell.h>
15#include <wlr/util/region.h> 15#include <wlr/util/region.h>
16#include "log.h" 16#include "log.h"
17#include "sway/config.h"
17#include "sway/input/input-manager.h" 18#include "sway/input/input-manager.h"
18#include "sway/input/seat.h" 19#include "sway/input/seat.h"
19#include "sway/layers.h" 20#include "sway/layers.h"
@@ -321,82 +322,96 @@ static void render_container_simple_border_normal(struct sway_output *output,
321 struct wlr_box box; 322 struct wlr_box box;
322 float color[4]; 323 float color[4];
323 324
324 // Child border - left edge 325 struct sway_container *workspace = container_parent(con, C_WORKSPACE);
325 memcpy(&color, colors->child_border, sizeof(float) * 4); 326 int other_views = workspace->children->length - 1;
326 color[3] *= con->alpha;
327 box.x = con->x;
328 box.y = con->y + 1;
329 box.width = con->sway_view->border_thickness;
330 box.height = con->height - 1;
331 render_rect(output->wlr_output, output_damage, &box, color);
332
333 // Child border - right edge
334 if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) {
335 memcpy(&color, colors->indicator, sizeof(float) * 4);
336 } else {
337 memcpy(&color, colors->child_border, sizeof(float) * 4);
338 }
339 color[3] *= con->alpha;
340 box.x = con->x + con->width - con->sway_view->border_thickness;
341 box.y = con->y + 1;
342 box.width = con->sway_view->border_thickness;
343 box.height = con->height - 1;
344 render_rect(output->wlr_output, output_damage, &box, color);
345 327
346 // Child border - bottom edge 328 if (config->hide_edge_borders != E_VERTICAL
347 if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { 329 && config->hide_edge_borders != E_BOTH
348 memcpy(&color, colors->indicator, sizeof(float) * 4); 330 && (config->hide_edge_borders != E_SMART || other_views)) {
349 } else { 331 // Child border - left edge
350 memcpy(&color, colors->child_border, sizeof(float) * 4); 332 memcpy(&color, colors->child_border, sizeof(float) * 4);
351 } 333 color[3] *= con->alpha;
352 color[3] *= con->alpha; 334 box.x = con->x;
353 box.x = con->x; 335 box.y = con->y + 1;
354 box.y = con->y + con->height - con->sway_view->border_thickness; 336 box.width = con->sway_view->border_thickness;
355 box.width = con->width; 337 box.height = con->height - 1;
356 box.height = con->sway_view->border_thickness; 338 render_rect(output->wlr_output, output_damage, &box, color);
357 render_rect(output->wlr_output, output_damage, &box, color); 339
358 340 // Child border - right edge
359 // Single pixel bar above title 341 if (con->parent->children->length == 1
360 memcpy(&color, colors->border, sizeof(float) * 4); 342 && con->parent->layout == L_HORIZ) {
361 color[3] *= con->alpha; 343 memcpy(&color, colors->indicator, sizeof(float) * 4);
362 box.x = con->x; 344 } else {
363 box.y = con->y; 345 memcpy(&color, colors->child_border, sizeof(float) * 4);
364 box.width = con->width; 346 }
365 box.height = 1; 347 color[3] *= con->alpha;
366 render_rect(output->wlr_output, output_damage, &box, color); 348 box.x = con->x + con->width - con->sway_view->border_thickness;
367 349 box.y = con->y + 1;
368 // Single pixel bar below title 350 box.width = con->sway_view->border_thickness;
369 box.x = con->x + con->sway_view->border_thickness; 351 box.height = con->height - 1;
370 box.y = con->sway_view->y - 1; 352 render_rect(output->wlr_output, output_damage, &box, color);
371 box.width = con->width - con->sway_view->border_thickness * 2; 353 }
372 box.height = 1; 354
373 render_rect(output->wlr_output, output_damage, &box, color); 355 if (config->hide_edge_borders != E_HORIZONTAL
374 356 && config->hide_edge_borders != E_BOTH
375 // Title background 357 && (config->hide_edge_borders != E_SMART || other_views)) {
376 memcpy(&color, colors->background, sizeof(float) * 4); 358 // Child border - bottom edge
377 color[3] *= con->alpha; 359 if (con->parent->children->length == 1
378 box.x = con->x + con->sway_view->border_thickness; 360 && con->parent->layout == L_VERT) {
379 box.y = con->y + 1; 361 memcpy(&color, colors->indicator, sizeof(float) * 4);
380 box.width = con->width - con->sway_view->border_thickness * 2; 362 } else {
381 box.height = con->sway_view->y - con->y - 2; 363 memcpy(&color, colors->child_border, sizeof(float) * 4);
382 render_rect(output->wlr_output, output_damage, &box, color); 364 }
383 365 color[3] *= con->alpha;
384 // Title text 366 box.x = con->x;
385 if (title_texture) { 367 box.y = con->y + con->height - con->sway_view->border_thickness;
386 float output_scale = output->wlr_output->scale; 368 box.width = con->width;
387 struct wlr_box texture_box = { 369 box.height = con->sway_view->border_thickness;
388 .x = box.x * output_scale, 370 render_rect(output->wlr_output, output_damage, &box, color);
389 .y = box.y * output_scale, 371
390 }; 372 // Single pixel bar above title
391 wlr_texture_get_size(title_texture, 373 memcpy(&color, colors->border, sizeof(float) * 4);
392 &texture_box.width, &texture_box.height); 374 color[3] *= con->alpha;
393 375 box.x = con->x;
394 float matrix[9]; 376 box.y = con->y;
395 wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, 377 box.width = con->width;
396 0.0, output->wlr_output->transform_matrix); 378 box.height = 1;
397 379 render_rect(output->wlr_output, output_damage, &box, color);
398 render_texture(output->wlr_output, output_damage, title_texture, 380
399 &texture_box, matrix, 1.0); 381 // Single pixel bar below title
382 box.x = con->x + con->sway_view->border_thickness;
383 box.y = con->sway_view->y - 1;
384 box.width = con->width - con->sway_view->border_thickness * 2;
385 box.height = 1;
386 render_rect(output->wlr_output, output_damage, &box, color);
387
388 // Title background
389 memcpy(&color, colors->background, sizeof(float) * 4);
390 color[3] *= con->alpha;
391 box.x = con->x + con->sway_view->border_thickness;
392 box.y = con->y + 1;
393 box.width = con->width - con->sway_view->border_thickness * 2;
394 box.height = con->sway_view->y - con->y - 2;
395 render_rect(output->wlr_output, output_damage, &box, color);
396
397 // Title text
398 if (title_texture) {
399 float output_scale = output->wlr_output->scale;
400 struct wlr_box texture_box = {
401 .x = box.x * output_scale,
402 .y = box.y * output_scale,
403 };
404 wlr_texture_get_size(title_texture,
405 &texture_box.width, &texture_box.height);
406
407 float matrix[9];
408 wlr_matrix_project_box(matrix, &texture_box,
409 WL_OUTPUT_TRANSFORM_NORMAL,
410 0.0, output->wlr_output->transform_matrix);
411
412 render_texture(output->wlr_output, output_damage, title_texture,
413 &texture_box, matrix, 1.0);
414 }
400 } 415 }
401} 416}
402 417
@@ -409,47 +424,60 @@ static void render_container_simple_border_pixel(struct sway_output *output,
409 struct wlr_box box; 424 struct wlr_box box;
410 float color[4]; 425 float color[4];
411 426
412 // Child border - left edge 427 struct sway_container *workspace = container_parent(con, C_WORKSPACE);
413 memcpy(&color, colors->child_border, sizeof(float) * 4); 428 int other_views = workspace->children->length - 1;
414 color[3] *= con->alpha; 429
415 box.x = con->x; 430 if (config->hide_edge_borders != E_VERTICAL
416 box.y = con->y; 431 && config->hide_edge_borders != E_BOTH
417 box.width = con->sway_view->border_thickness; 432 && (config->hide_edge_borders != E_SMART || other_views)) {
418 box.height = con->height; 433 // Child border - left edge
419 render_rect(output->wlr_output, output_damage, &box, color);
420
421 // Child border - right edge
422 if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) {
423 memcpy(&color, colors->indicator, sizeof(float) * 4);
424 } else {
425 memcpy(&color, colors->child_border, sizeof(float) * 4);
426 }
427 color[3] *= con->alpha;
428 box.x = con->x + con->width - con->sway_view->border_thickness;
429 box.y = con->y;
430 box.width = con->sway_view->border_thickness;
431 box.height = con->height;
432 render_rect(output->wlr_output, output_damage, &box, color);
433
434 // Child border - top edge
435 box.x = con->x;
436 box.y = con->y;
437 box.width = con->width;
438 box.height = con->sway_view->border_thickness;
439 render_rect(output->wlr_output, output_damage, &box, color);
440
441 // Child border - bottom edge
442 if (con->parent->children->length == 1 && con->parent->layout == L_VERT) {
443 memcpy(&color, colors->indicator, sizeof(float) * 4);
444 } else {
445 memcpy(&color, colors->child_border, sizeof(float) * 4); 434 memcpy(&color, colors->child_border, sizeof(float) * 4);
435 color[3] *= con->alpha;
436 box.x = con->x;
437 box.y = con->y;
438 box.width = con->sway_view->border_thickness;
439 box.height = con->height;
440 render_rect(output->wlr_output, output_damage, &box, color);
441
442 // Child border - right edge
443 if (con->parent->children->length == 1
444 && con->parent->layout == L_HORIZ) {
445 memcpy(&color, colors->indicator, sizeof(float) * 4);
446 } else {
447 memcpy(&color, colors->child_border, sizeof(float) * 4);
448 }
449 color[3] *= con->alpha;
450 box.x = con->x + con->width - con->sway_view->border_thickness;
451 box.y = con->y;
452 box.width = con->sway_view->border_thickness;
453 box.height = con->height;
454 render_rect(output->wlr_output, output_damage, &box, color);
455 }
456
457 if (config->hide_edge_borders != E_HORIZONTAL
458 && config->hide_edge_borders != E_BOTH
459 && (config->hide_edge_borders != E_SMART || other_views)) {
460 // Child border - top edge
461 box.x = con->x;
462 box.y = con->y;
463 box.width = con->width;
464 box.height = con->sway_view->border_thickness;
465 render_rect(output->wlr_output, output_damage, &box, color);
466
467 // Child border - bottom edge
468 if (con->parent->children->length == 1
469 && con->parent->layout == L_VERT) {
470 memcpy(&color, colors->indicator, sizeof(float) * 4);
471 } else {
472 memcpy(&color, colors->child_border, sizeof(float) * 4);
473 }
474 color[3] *= con->alpha;
475 box.x = con->x;
476 box.y = con->y + con->height - con->sway_view->border_thickness;
477 box.width = con->width;
478 box.height = con->sway_view->border_thickness;
479 render_rect(output->wlr_output, output_damage, &box, color);
446 } 480 }
447 color[3] *= con->alpha;
448 box.x = con->x;
449 box.y = con->y + con->height - con->sway_view->border_thickness;
450 box.width = con->width;
451 box.height = con->sway_view->border_thickness;
452 render_rect(output->wlr_output, output_damage, &box, color);
453} 481}
454 482
455static void render_container(struct sway_output *output, 483static void render_container(struct sway_output *output,
diff --git a/sway/meson.build b/sway/meson.build
index f70a8e44..acf4a3e4 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -41,6 +41,7 @@ sway_sources = files(
41 'commands/font.c', 41 'commands/font.c',
42 'commands/for_window.c', 42 'commands/for_window.c',
43 'commands/fullscreen.c', 43 'commands/fullscreen.c',
44 'commands/hide_edge_borders.c',
44 'commands/kill.c', 45 'commands/kill.c',
45 'commands/opacity.c', 46 'commands/opacity.c',
46 'commands/include.c', 47 'commands/include.c',
diff --git a/sway/tree/view.c b/sway/tree/view.c
index afd7eade..c2496f0d 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -100,6 +100,9 @@ void view_autoconfigure(struct sway_view *view) {
100 return; 100 return;
101 } 101 }
102 102
103 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
104 int other_views = ws->children->length - 1;
105
103 double x, y, width, height; 106 double x, y, width, height;
104 x = y = width = height = 0; 107 x = y = width = height = 0;
105 switch (view->border) { 108 switch (view->border) {
@@ -110,18 +113,51 @@ void view_autoconfigure(struct sway_view *view) {
110 height = view->swayc->height; 113 height = view->swayc->height;
111 break; 114 break;
112 case B_PIXEL: 115 case B_PIXEL:
113 x = view->swayc->x + view->border_thickness; 116 if (view->swayc->layout > L_VERT
114 y = view->swayc->y + view->border_thickness; 117 || config->hide_edge_borders == E_NONE
115 width = view->swayc->width - view->border_thickness * 2; 118 || config->hide_edge_borders == E_HORIZONTAL
116 height = view->swayc->height - view->border_thickness * 2; 119 || (config->hide_edge_borders == E_SMART && other_views)) {
120 x = view->swayc->x + view->border_thickness;
121 width = view->swayc->width - view->border_thickness * 2;
122 } else {
123 x = view->swayc->x;
124 width = view->swayc->width;
125 }
126 if (view->swayc->layout > L_VERT
127 || config->hide_edge_borders == E_NONE
128 || config->hide_edge_borders == E_VERTICAL
129 || (config->hide_edge_borders == E_SMART && other_views)) {
130 y = view->swayc->y + view->border_thickness;
131 height = view->swayc->height - view->border_thickness * 2;
132 } else {
133 y = view->swayc->y;
134 height = view->swayc->height;
135 }
117 break; 136 break;
118 case B_NORMAL: 137 case B_NORMAL:
119 // Height is: border + title height + border + view height + border 138 if (view->swayc->layout > L_VERT
120 x = view->swayc->x + view->border_thickness; 139 || config->hide_edge_borders == E_NONE
121 y = view->swayc->y + config->font_height + view->border_thickness * 2; 140 || config->hide_edge_borders == E_HORIZONTAL
122 width = view->swayc->width - view->border_thickness * 2; 141 || (config->hide_edge_borders == E_SMART && other_views)) {
123 height = view->swayc->height - config->font_height 142 x = view->swayc->x + view->border_thickness;
124 - view->border_thickness * 3; 143 width = view->swayc->width - view->border_thickness * 2;
144 } else {
145 x = view->swayc->x;
146 width = view->swayc->width;
147 }
148 if (view->swayc->layout > L_VERT
149 || config->hide_edge_borders == E_NONE
150 || config->hide_edge_borders == E_VERTICAL
151 || (config->hide_edge_borders == E_SMART && other_views)) {
152 // Height is: border + title height + border + view height + border
153 y = view->swayc->y + config->font_height
154 + view->border_thickness * 2;
155 height = view->swayc->height - config->font_height
156 - view->border_thickness * 3;
157 } else {
158 y = view->swayc->y;
159 height = view->swayc->height;
160 }
125 break; 161 break;
126 } 162 }
127 163