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) --- sway/commands/title_format.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 sway/commands/title_format.c (limited to 'sway/commands') diff --git a/sway/commands/title_format.c b/sway/commands/title_format.c new file mode 100644 index 00000000..a2f6e6ff --- /dev/null +++ b/sway/commands/title_format.c @@ -0,0 +1,31 @@ +#define _POSIX_C_SOURCE 200809L +#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" + +struct cmd_results *cmd_title_format(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "title_format", EXPECTED_AT_LEAST, 1))) { + return error; + } + struct sway_container *container = + config->handler_context.current_container; + if (container->type != C_VIEW) { + return cmd_results_new(CMD_INVALID, "title_format", + "Only views can have a title_format"); + } + struct sway_view *view = container->sway_view; + char *format = join_args(argv, argc); + if (view->title_format) { + free(view->title_format); + } + view->title_format = strdup(format); + view_update_title(view, true); + config_find_font_height(true); + arrange_root(); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} -- cgit v1.2.3 From d10a0a8c4156fef6ac64362bf046411f57a3ed5f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 5 May 2018 16:48:10 +1000 Subject: Fix memory leak in title_format command --- sway/commands/title_format.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/commands') diff --git a/sway/commands/title_format.c b/sway/commands/title_format.c index a2f6e6ff..26ddb2f4 100644 --- a/sway/commands/title_format.c +++ b/sway/commands/title_format.c @@ -23,7 +23,7 @@ struct cmd_results *cmd_title_format(int argc, char **argv) { if (view->title_format) { free(view->title_format); } - view->title_format = strdup(format); + view->title_format = format; view_update_title(view, true); config_find_font_height(true); arrange_root(); -- 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 'sway/commands') 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