summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Florent de Lamotte <florent.lamotte@gmail.com>2018-11-17 20:06:48 +0100
committerLibravatar Florent de Lamotte <florent.lamotte@gmail.com>2018-11-22 10:30:04 +0100
commit7555c7efdce66c7de7a5320879c501e901a5aab7 (patch)
treed9acff5cb9d0a5e420067602aca11f79fc1aabb7
parentMerge pull request #3158 from emersion/get-outputs-focused (diff)
downloadsway-7555c7efdce66c7de7a5320879c501e901a5aab7.tar.gz
sway-7555c7efdce66c7de7a5320879c501e901a5aab7.tar.zst
sway-7555c7efdce66c7de7a5320879c501e901a5aab7.zip
Adding commands for configuring titlebar borders and padding
-rw-r--r--include/sway/commands.h2
-rw-r--r--include/sway/config.h3
-rw-r--r--include/sway/tree/container.h6
-rw-r--r--sway/commands.c2
-rw-r--r--sway/commands/titlebar_border_thickness.c30
-rw-r--r--sway/commands/titlebar_padding.c42
-rw-r--r--sway/config.c4
-rw-r--r--sway/desktop/render.c71
-rw-r--r--sway/meson.build2
-rw-r--r--sway/sway.5.scd10
-rw-r--r--sway/tree/container.c2
11 files changed, 133 insertions, 41 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index b0339313..e6036e51 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -173,6 +173,8 @@ sway_cmd cmd_swaynag_command;
173sway_cmd cmd_swap; 173sway_cmd cmd_swap;
174sway_cmd cmd_tiling_drag; 174sway_cmd cmd_tiling_drag;
175sway_cmd cmd_title_format; 175sway_cmd cmd_title_format;
176sway_cmd cmd_titlebar_border_thickness;
177sway_cmd cmd_titlebar_padding;
176sway_cmd cmd_unmark; 178sway_cmd cmd_unmark;
177sway_cmd cmd_urgent; 179sway_cmd cmd_urgent;
178sway_cmd cmd_workspace; 180sway_cmd cmd_workspace;
diff --git a/include/sway/config.h b/include/sway/config.h
index 4927b8e0..a6920835 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -391,6 +391,9 @@ struct sway_config {
391 size_t font_height; 391 size_t font_height;
392 size_t font_baseline; 392 size_t font_baseline;
393 bool pango_markup; 393 bool pango_markup;
394 int titlebar_border_thickness;
395 int titlebar_h_padding;
396 int titlebar_v_padding;
394 size_t urgent_timeout; 397 size_t urgent_timeout;
395 enum sway_fowa focus_on_window_activation; 398 enum sway_fowa focus_on_window_activation;
396 enum sway_popup_during_fullscreen popup_during_fullscreen; 399 enum sway_popup_during_fullscreen popup_during_fullscreen;
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index f907aad2..1d0a0ad1 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -10,12 +10,6 @@
10struct sway_view; 10struct sway_view;
11struct sway_seat; 11struct sway_seat;
12 12
13#define TITLEBAR_BORDER_THICKNESS 1
14
15// Padding includes titlebar border
16#define TITLEBAR_H_PADDING 3
17#define TITLEBAR_V_PADDING 4
18
19enum sway_container_layout { 13enum sway_container_layout {
20 L_NONE, 14 L_NONE,
21 L_HORIZ, 15 L_HORIZ,
diff --git a/sway/commands.c b/sway/commands.c
index 4b86c2fa..d35658d5 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -103,6 +103,8 @@ static struct cmd_handler handlers[] = {
103 { "smart_borders", cmd_smart_borders }, 103 { "smart_borders", cmd_smart_borders },
104 { "smart_gaps", cmd_smart_gaps }, 104 { "smart_gaps", cmd_smart_gaps },
105 { "tiling_drag", cmd_tiling_drag }, 105 { "tiling_drag", cmd_tiling_drag },
106 { "titlebar_border_thickness", cmd_titlebar_border_thickness },
107 { "titlebar_padding", cmd_titlebar_padding },
106 { "workspace", cmd_workspace }, 108 { "workspace", cmd_workspace },
107 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, 109 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth },
108}; 110};
diff --git a/sway/commands/titlebar_border_thickness.c b/sway/commands/titlebar_border_thickness.c
new file mode 100644
index 00000000..c1e9bb52
--- /dev/null
+++ b/sway/commands/titlebar_border_thickness.c
@@ -0,0 +1,30 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/output.h"
5#include "sway/tree/arrange.h"
6#include "log.h"
7
8struct cmd_results *cmd_titlebar_border_thickness(int argc, char **argv) {
9 struct cmd_results *error = NULL;
10 if ((error = checkarg(argc, "titlebar_border_thickness", EXPECTED_EQUAL_TO, 1))) {
11 return error;
12 }
13
14 char *inv;
15 int value = strtol(argv[0], &inv, 10);
16 if (*inv != '\0' || value < 0 || value > config->titlebar_v_padding) {
17 return cmd_results_new(CMD_FAILURE, "titlebar_border_thickness",
18 "Invalid size specified");
19 }
20
21 config->titlebar_border_thickness = value;
22
23 for (int i = 0; i < root->outputs->length; ++i) {
24 struct sway_output *output = root->outputs->items[i];
25 arrange_workspace(output_get_active_workspace(output));
26 output_damage_whole(output);
27 }
28
29 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
30}
diff --git a/sway/commands/titlebar_padding.c b/sway/commands/titlebar_padding.c
new file mode 100644
index 00000000..a642e945
--- /dev/null
+++ b/sway/commands/titlebar_padding.c
@@ -0,0 +1,42 @@
1#include <string.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/output.h"
5#include "sway/tree/arrange.h"
6#include "log.h"
7
8struct cmd_results *cmd_titlebar_padding(int argc, char **argv) {
9 struct cmd_results *error = NULL;
10 if ((error = checkarg(argc, "titlebar_padding", EXPECTED_AT_LEAST, 1))) {
11 return error;
12 }
13
14 char *inv;
15 int h_value = strtol(argv[0], &inv, 10);
16 if (*inv != '\0' || h_value < 0 || h_value < config->titlebar_border_thickness) {
17 return cmd_results_new(CMD_FAILURE, "titlebar_padding",
18 "Invalid size specified");
19 }
20
21 int v_value;
22 if (argc == 1) {
23 v_value = h_value;
24 } else {
25 v_value = strtol(argv[1], &inv, 10);
26 if (*inv != '\0' || v_value < 0 || v_value < config->titlebar_border_thickness) {
27 return cmd_results_new(CMD_FAILURE, "titlebar_padding",
28 "Invalid size specified");
29 }
30 }
31
32 config->titlebar_v_padding = v_value;
33 config->titlebar_h_padding = h_value;
34
35 for (int i = 0; i < root->outputs->length; ++i) {
36 struct sway_output *output = root->outputs->items[i];
37 arrange_workspace(output_get_active_workspace(output));
38 output_damage_whole(output);
39 }
40
41 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
42}
diff --git a/sway/config.c b/sway/config.c
index c1320acf..59edc6d8 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -213,6 +213,10 @@ static void config_defaults(struct sway_config *config) {
213 config->urgent_timeout = 500; 213 config->urgent_timeout = 500;
214 config->popup_during_fullscreen = POPUP_SMART; 214 config->popup_during_fullscreen = POPUP_SMART;
215 215
216 config->titlebar_border_thickness = 1;
217 config->titlebar_h_padding = 5;
218 config->titlebar_v_padding = 4;
219
216 // floating view 220 // floating view
217 config->floating_maximum_width = 0; 221 config->floating_maximum_width = 0;
218 config->floating_maximum_height = 0; 222 config->floating_maximum_height = 0;
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index 8d4a701b..51cb8980 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -368,6 +368,9 @@ static void render_titlebar(struct sway_output *output,
368 children->items[children->length - 1] == con; 368 children->items[children->length - 1] == con;
369 double output_x = output->wlr_output->lx; 369 double output_x = output->wlr_output->lx;
370 double output_y = output->wlr_output->ly; 370 double output_y = output->wlr_output->ly;
371 int titlebar_border_thickness = config->titlebar_border_thickness;
372 int titlebar_h_padding = config->titlebar_h_padding;
373 int titlebar_v_padding = config->titlebar_v_padding;
371 374
372 // Single pixel bar above title 375 // Single pixel bar above title
373 memcpy(&color, colors->border, sizeof(float) * 4); 376 memcpy(&color, colors->border, sizeof(float) * 4);
@@ -375,7 +378,7 @@ static void render_titlebar(struct sway_output *output,
375 box.x = x; 378 box.x = x;
376 box.y = y; 379 box.y = y;
377 box.width = width; 380 box.width = width;
378 box.height = TITLEBAR_BORDER_THICKNESS; 381 box.height = titlebar_border_thickness;
379 scale_box(&box, output_scale); 382 scale_box(&box, output_scale);
380 render_rect(output->wlr_output, output_damage, &box, color); 383 render_rect(output->wlr_output, output_damage, &box, color);
381 384
@@ -391,36 +394,36 @@ static void render_titlebar(struct sway_output *output,
391 } 394 }
392 } 395 }
393 box.x = x + left_offset; 396 box.x = x + left_offset;
394 box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; 397 box.y = y + container_titlebar_height() - titlebar_border_thickness;
395 box.width = width - left_offset - right_offset; 398 box.width = width - left_offset - right_offset;
396 box.height = TITLEBAR_BORDER_THICKNESS; 399 box.height = titlebar_border_thickness;
397 scale_box(&box, output_scale); 400 scale_box(&box, output_scale);
398 render_rect(output->wlr_output, output_damage, &box, color); 401 render_rect(output->wlr_output, output_damage, &box, color);
399 402
400 if (layout == L_TABBED) { 403 if (layout == L_TABBED) {
401 // Single pixel left edge 404 // Single pixel left edge
402 box.x = x; 405 box.x = x;
403 box.y = y + TITLEBAR_BORDER_THICKNESS; 406 box.y = y + titlebar_border_thickness;
404 box.width = TITLEBAR_BORDER_THICKNESS; 407 box.width = titlebar_border_thickness;
405 box.height = 408 box.height =
406 container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2; 409 container_titlebar_height() - titlebar_border_thickness * 2;
407 scale_box(&box, output_scale); 410 scale_box(&box, output_scale);
408 render_rect(output->wlr_output, output_damage, &box, color); 411 render_rect(output->wlr_output, output_damage, &box, color);
409 412
410 // Single pixel right edge 413 // Single pixel right edge
411 box.x = x + width - TITLEBAR_BORDER_THICKNESS; 414 box.x = x + width - titlebar_border_thickness;
412 box.y = y + TITLEBAR_BORDER_THICKNESS; 415 box.y = y + titlebar_border_thickness;
413 box.width = TITLEBAR_BORDER_THICKNESS; 416 box.width = titlebar_border_thickness;
414 box.height = 417 box.height =
415 container_titlebar_height() - TITLEBAR_BORDER_THICKNESS * 2; 418 container_titlebar_height() - titlebar_border_thickness * 2;
416 scale_box(&box, output_scale); 419 scale_box(&box, output_scale);
417 render_rect(output->wlr_output, output_damage, &box, color); 420 render_rect(output->wlr_output, output_damage, &box, color);
418 } 421 }
419 422
420 size_t inner_width = width - TITLEBAR_H_PADDING * 2; 423 size_t inner_width = width - titlebar_h_padding * 2;
421 int bg_y = y + TITLEBAR_BORDER_THICKNESS; 424 int bg_y = y + titlebar_border_thickness;
422 int ob_bg_height = scale_length( 425 int ob_bg_height = scale_length(
423 (TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS) * 2 + 426 (titlebar_v_padding - titlebar_border_thickness) * 2 +
424 config->font_height, bg_y, output_scale); 427 config->font_height, bg_y, output_scale);
425 428
426 // Marks 429 // Marks
@@ -438,7 +441,7 @@ static void render_titlebar(struct sway_output *output,
438 int ob_padding_below = ceil(ob_padding_total / 2.0); 441 int ob_padding_below = ceil(ob_padding_total / 2.0);
439 442
440 // Render texture 443 // Render texture
441 texture_box.x = round((x - output_x + width - TITLEBAR_H_PADDING) 444 texture_box.x = round((x - output_x + width - titlebar_h_padding)
442 * output_scale) - texture_box.width; 445 * output_scale) - texture_box.width;
443 texture_box.y = round((bg_y - output_y) * output_scale) + 446 texture_box.y = round((bg_y - output_y) * output_scale) +
444 ob_padding_above; 447 ob_padding_above;
@@ -458,7 +461,7 @@ static void render_titlebar(struct sway_output *output,
458 memcpy(&color, colors->background, sizeof(float) * 4); 461 memcpy(&color, colors->background, sizeof(float) * 4);
459 premultiply_alpha(color, con->alpha); 462 premultiply_alpha(color, con->alpha);
460 box.x = texture_box.x + round(output_x * output_scale); 463 box.x = texture_box.x + round(output_x * output_scale);
461 box.y = round((y + TITLEBAR_BORDER_THICKNESS) * output_scale); 464 box.y = round((y + titlebar_border_thickness) * output_scale);
462 box.width = texture_box.width; 465 box.width = texture_box.width;
463 box.height = ob_padding_above; 466 box.height = ob_padding_above;
464 render_rect(output->wlr_output, output_damage, &box, color); 467 render_rect(output->wlr_output, output_damage, &box, color);
@@ -480,14 +483,14 @@ static void render_titlebar(struct sway_output *output,
480 // The title texture might be shorter than the config->font_height, 483 // The title texture might be shorter than the config->font_height,
481 // in which case we need to pad it above and below. 484 // in which case we need to pad it above and below.
482 int ob_padding_above = round((config->font_baseline - 485 int ob_padding_above = round((config->font_baseline -
483 con->title_baseline + TITLEBAR_V_PADDING - 486 con->title_baseline + titlebar_v_padding -
484 TITLEBAR_BORDER_THICKNESS) * output_scale); 487 titlebar_border_thickness) * output_scale);
485 int ob_padding_below = ob_bg_height - ob_padding_above - 488 int ob_padding_below = ob_bg_height - ob_padding_above -
486 texture_box.height; 489 texture_box.height;
487 490
488 // Render texture 491 // Render texture
489 texture_box.x = 492 texture_box.x =
490 round((x - output_x + TITLEBAR_H_PADDING) * output_scale); 493 round((x - output_x + titlebar_h_padding) * output_scale);
491 texture_box.y = 494 texture_box.y =
492 round((bg_y - output_y) * output_scale) + ob_padding_above; 495 round((bg_y - output_y) * output_scale) + ob_padding_above;
493 496
@@ -496,7 +499,7 @@ static void render_titlebar(struct sway_output *output,
496 WL_OUTPUT_TRANSFORM_NORMAL, 499 WL_OUTPUT_TRANSFORM_NORMAL,
497 0.0, output->wlr_output->transform_matrix); 500 0.0, output->wlr_output->transform_matrix);
498 501
499 int inner_x = x - output_x + TITLEBAR_H_PADDING; 502 int inner_x = x - output_x + titlebar_h_padding;
500 int ob_inner_width = scale_length(inner_width, inner_x, output_scale); 503 int ob_inner_width = scale_length(inner_width, inner_x, output_scale);
501 if (ob_inner_width - marks_ob_width < texture_box.width) { 504 if (ob_inner_width - marks_ob_width < texture_box.width) {
502 texture_box.width = ob_inner_width - marks_ob_width; 505 texture_box.width = ob_inner_width - marks_ob_width;
@@ -508,7 +511,7 @@ static void render_titlebar(struct sway_output *output,
508 memcpy(&color, colors->background, sizeof(float) * 4); 511 memcpy(&color, colors->background, sizeof(float) * 4);
509 premultiply_alpha(color, con->alpha); 512 premultiply_alpha(color, con->alpha);
510 box.x = texture_box.x + round(output_x * output_scale); 513 box.x = texture_box.x + round(output_x * output_scale);
511 box.y = round((y + TITLEBAR_BORDER_THICKNESS) * output_scale); 514 box.y = round((y + titlebar_border_thickness) * output_scale);
512 box.width = texture_box.width; 515 box.width = texture_box.width;
513 box.height = ob_padding_above; 516 box.height = ob_padding_above;
514 render_rect(output->wlr_output, output_damage, &box, color); 517 render_rect(output->wlr_output, output_damage, &box, color);
@@ -523,28 +526,28 @@ static void render_titlebar(struct sway_output *output,
523 box.width = 526 box.width =
524 round(inner_width * output_scale) - title_ob_width - marks_ob_width; 527 round(inner_width * output_scale) - title_ob_width - marks_ob_width;
525 if (box.width > 0) { 528 if (box.width > 0) {
526 box.x = round((x + TITLEBAR_H_PADDING) * output_scale) + title_ob_width; 529 box.x = round((x + titlebar_h_padding) * output_scale) + title_ob_width;
527 box.y = round(bg_y * output_scale); 530 box.y = round(bg_y * output_scale);
528 box.height = ob_bg_height; 531 box.height = ob_bg_height;
529 render_rect(output->wlr_output, output_damage, &box, color); 532 render_rect(output->wlr_output, output_damage, &box, color);
530 } 533 }
531 534
532 // Padding left of title 535 // Padding left of title
533 left_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; 536 left_offset = (layout == L_TABBED) * titlebar_border_thickness;
534 box.x = x + left_offset; 537 box.x = x + left_offset;
535 box.y = y + TITLEBAR_BORDER_THICKNESS; 538 box.y = y + titlebar_border_thickness;
536 box.width = TITLEBAR_H_PADDING - left_offset; 539 box.width = titlebar_h_padding - left_offset;
537 box.height = (TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS) * 2 + 540 box.height = (titlebar_v_padding - titlebar_border_thickness) * 2 +
538 config->font_height; 541 config->font_height;
539 scale_box(&box, output_scale); 542 scale_box(&box, output_scale);
540 render_rect(output->wlr_output, output_damage, &box, color); 543 render_rect(output->wlr_output, output_damage, &box, color);
541 544
542 // Padding right of marks 545 // Padding right of marks
543 right_offset = (layout == L_TABBED) * TITLEBAR_BORDER_THICKNESS; 546 right_offset = (layout == L_TABBED) * titlebar_border_thickness;
544 box.x = x + width - TITLEBAR_H_PADDING; 547 box.x = x + width - titlebar_h_padding;
545 box.y = y + TITLEBAR_BORDER_THICKNESS; 548 box.y = y + titlebar_border_thickness;
546 box.width = TITLEBAR_H_PADDING - right_offset; 549 box.width = titlebar_h_padding - right_offset;
547 box.height = (TITLEBAR_V_PADDING - TITLEBAR_BORDER_THICKNESS) * 2 + 550 box.height = (titlebar_v_padding - titlebar_border_thickness) * 2 +
548 config->font_height; 551 config->font_height;
549 scale_box(&box, output_scale); 552 scale_box(&box, output_scale);
550 render_rect(output->wlr_output, output_damage, &box, color); 553 render_rect(output->wlr_output, output_damage, &box, color);
@@ -552,17 +555,17 @@ static void render_titlebar(struct sway_output *output,
552 if (connects_sides) { 555 if (connects_sides) {
553 // Left pixel in line with bottom bar 556 // Left pixel in line with bottom bar
554 box.x = x; 557 box.x = x;
555 box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; 558 box.y = y + container_titlebar_height() - titlebar_border_thickness;
556 box.width = state->border_thickness * state->border_left; 559 box.width = state->border_thickness * state->border_left;
557 box.height = TITLEBAR_BORDER_THICKNESS; 560 box.height = titlebar_border_thickness;
558 scale_box(&box, output_scale); 561 scale_box(&box, output_scale);
559 render_rect(output->wlr_output, output_damage, &box, color); 562 render_rect(output->wlr_output, output_damage, &box, color);
560 563
561 // Right pixel in line with bottom bar 564 // Right pixel in line with bottom bar
562 box.x = x + width - state->border_thickness * state->border_right; 565 box.x = x + width - state->border_thickness * state->border_right;
563 box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; 566 box.y = y + container_titlebar_height() - titlebar_border_thickness;
564 box.width = state->border_thickness * state->border_right; 567 box.width = state->border_thickness * state->border_right;
565 box.height = TITLEBAR_BORDER_THICKNESS; 568 box.height = titlebar_border_thickness;
566 scale_box(&box, output_scale); 569 scale_box(&box, output_scale);
567 render_rect(output->wlr_output, output_damage, &box, color); 570 render_rect(output->wlr_output, output_damage, &box, color);
568 } 571 }
diff --git a/sway/meson.build b/sway/meson.build
index 14822dbd..c8c95a96 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -89,6 +89,8 @@ sway_sources = files(
89 'commands/swap.c', 89 'commands/swap.c',
90 'commands/tiling_drag.c', 90 'commands/tiling_drag.c',
91 'commands/title_format.c', 91 'commands/title_format.c',
92 'commands/titlebar_border_thickness.c',
93 'commands/titlebar_padding.c',
92 'commands/unmark.c', 94 'commands/unmark.c',
93 'commands/urgent.c', 95 'commands/urgent.c',
94 'commands/workspace.c', 96 'commands/workspace.c',
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 1a11015f..6ccb1acf 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -436,6 +436,16 @@ The default colors are:
436*font* <font> 436*font* <font>
437 Sets font for use in title bars in Pango format. 437 Sets font for use in title bars in Pango format.
438 438
439*titlebar\_border\_thickness* <thickness>
440 Thickness of the titlebar border in pixels
441
442*titlebar\_padding* <horizontal> [<vertical>]
443 Padding of the text in the titlebar. _horizontal_ value affects horizontal
444 padding of the text while _vertical_ value affects vertical padding (space
445 above and below text). Padding includes titlebar borders so their value
446 should be greater than titlebar\_border\_thickness. If _vertical_ value is
447 not specified it is set to the _horizontal_ value.
448
439*for\_window* <criteria> <command> 449*for\_window* <criteria> <command>
440 Whenever a window that matches _criteria_ appears, run list of commands. 450 Whenever a window that matches _criteria_ appears, run list of commands.
441 See *CRITERIA* for more details. 451 See *CRITERIA* for more details.
diff --git a/sway/tree/container.c b/sway/tree/container.c
index cf6f5b54..91e8dd7f 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -594,7 +594,7 @@ void container_update_representation(struct sway_container *con) {
594} 594}
595 595
596size_t container_titlebar_height(void) { 596size_t container_titlebar_height(void) {
597 return config->font_height + TITLEBAR_V_PADDING * 2; 597 return config->font_height + config->titlebar_v_padding * 2;
598} 598}
599 599
600void container_init_floating(struct sway_container *con) { 600void container_init_floating(struct sway_container *con) {