From 228c478e8d11dd14972b237574146fd0d2d6b96c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 5 May 2018 12:36:50 +1000 Subject: Implement title_format This implements the title_format command, with a new placeholder %shell which gets substituted with the view type (xwayland, xdg_shell_v6 or wl_shell). Example config: for_window [title=".*"] title_format %title (class=%class instance=%instance shell=%shell) --- include/sway/commands.h | 1 + include/sway/tree/container.h | 6 +++--- include/sway/tree/view.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/sway/commands.h b/include/sway/commands.h index 0732a90a..d39ac56c 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -144,6 +144,7 @@ sway_cmd cmd_splitt; sway_cmd cmd_splitv; sway_cmd cmd_sticky; sway_cmd cmd_swaybg_command; +sway_cmd cmd_title_format; sway_cmd cmd_unmark; sway_cmd cmd_workspace; sway_cmd cmd_ws_auto_back_and_forth; diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index b07af72c..61ab7ca1 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -63,7 +63,8 @@ struct sway_container { */ size_t id; - char *name; + char *name; // The view's title (unformatted) + char *formatted_title; // The title displayed in the title bar enum sway_container_type type; enum sway_container_layout layout; @@ -204,7 +205,6 @@ void container_update_title_textures(struct sway_container *container); */ void container_calculate_title_height(struct sway_container *container); -void container_update_title(struct sway_container *container, - const char *new_title); +void container_notify_child_title_changed(struct sway_container *container); #endif diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 21127ab1..9d4256f7 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -48,6 +48,7 @@ struct sway_view { bool is_fullscreen; + char *title_format; enum sway_container_border border; int border_thickness; @@ -164,6 +165,8 @@ const char *view_get_class(struct sway_view *view); const char *view_get_instance(struct sway_view *view); +const char *view_get_type(struct sway_view *view); + void view_configure(struct sway_view *view, double ox, double oy, int width, int height); @@ -207,4 +210,11 @@ void view_child_init(struct sway_view_child *child, void view_child_destroy(struct sway_view_child *child); +/** + * Re-read the view's title property and update any relevant title bars. + * The force argument makes it recreate the title bars even if the title hasn't + * changed. + */ +void view_update_title(struct sway_view *view, bool force); + #endif -- cgit v1.2.3 From 5d6d24e71aabc026c99ac736c788fa8103658c42 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 5 May 2018 18:25:31 +1000 Subject: Move code for re-arranging after font height change into a common place --- include/sway/config.h | 5 ++++- sway/commands/font.c | 6 +----- sway/commands/title_format.c | 4 +--- sway/config.c | 9 ++++++++- sway/tree/view.c | 7 +------ 5 files changed, 15 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/sway/config.h b/include/sway/config.h index db942c3f..fa40ef4e 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -465,8 +465,11 @@ void free_bar_config(struct bar_config *bar); * Updates the value of config->font_height based on the max title height * reported by each container. If recalculate is true, the containers will * recalculate their heights before reporting. + * + * If the height has changed, all containers will be rearranged to take on the + * new size. */ -void config_find_font_height(bool recalculate); +void config_update_font_height(bool recalculate); /* Global config singleton. */ extern struct sway_config *config; diff --git a/sway/commands/font.c b/sway/commands/font.c index 38ad8880..8e0b51e3 100644 --- a/sway/commands/font.c +++ b/sway/commands/font.c @@ -2,7 +2,6 @@ #include #include "sway/commands.h" #include "sway/config.h" -#include "sway/tree/arrange.h" #include "log.h" #include "stringop.h" @@ -14,9 +13,6 @@ struct cmd_results *cmd_font(int argc, char **argv) { char *font = join_args(argv, argc); free(config->font); config->font = strdup(font); - config_find_font_height(true); - if (!config->reading) { - arrange_root(); - } + config_update_font_height(true); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/title_format.c b/sway/commands/title_format.c index 26ddb2f4..3d1c578c 100644 --- a/sway/commands/title_format.c +++ b/sway/commands/title_format.c @@ -2,7 +2,6 @@ #include #include "sway/commands.h" #include "sway/config.h" -#include "sway/tree/arrange.h" #include "sway/tree/view.h" #include "log.h" #include "stringop.h" @@ -25,7 +24,6 @@ struct cmd_results *cmd_title_format(int argc, char **argv) { } view->title_format = format; view_update_title(view, true); - config_find_font_height(true); - arrange_root(); + config_update_font_height(true); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/config.c b/sway/config.c index 2e5eab2b..a14f4ec6 100644 --- a/sway/config.c +++ b/sway/config.c @@ -24,6 +24,7 @@ #include "sway/input/seat.h" #include "sway/commands.h" #include "sway/config.h" +#include "sway/tree/arrange.h" #include "sway/tree/layout.h" #include "cairo.h" #include "pango.h" @@ -741,8 +742,14 @@ static void find_font_height_iterator(struct sway_container *container, } } -void config_find_font_height(bool recalculate) { +void config_update_font_height(bool recalculate) { + size_t prev_max_height = config->font_height; config->font_height = 0; + container_for_each_descendant_dfs(&root_container, find_font_height_iterator, &recalculate); + + if (config->font_height != prev_max_height) { + arrange_root(); + } } diff --git a/sway/tree/view.c b/sway/tree/view.c index 386144f6..851348d8 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -601,10 +601,5 @@ void view_update_title(struct sway_view *view, bool force) { container_calculate_title_height(view->swayc); container_update_title_textures(view->swayc); container_notify_child_title_changed(view->swayc->parent); - - size_t prev_max_height = config->font_height; - config_find_font_height(false); - if (config->font_height != prev_max_height) { - arrange_root(); - } + config_update_font_height(false); } -- cgit v1.2.3