swayfx/sway/commands/reload.c
Hugo Osvaldo Barrera c16b2a26ed Avoid unecessary font metric calculations
Prior to 62d90a8e, titlebar's font height (and other related values)
would change any time any titlebar's content changed, so these values
were recalculated each time any titlebar's content changed (or a new
titlebar was created).

However, since the above was merge, these values no longer change so
often and we only need to recalculate them when the configured font
changes (and stop calling `config_update_font_height` each time
titlebars are rendered).

This commit removes all the unecessary calls to this function and avoids
all those unecessary calculations. Whenever the font strays from the
default value, the `font` command is called, and it calls
`config_update_font_height`, which is enough to keep the value always up
to date.

I've also added a default value to the `font_baseline` config, since
otherwise that's zero for setups that don't explicitly specify a font.
2021-09-20 09:25:47 +02:00

77 lines
2 KiB
C

#define _POSIX_C_SOURCE 200809L
#include <string.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/ipc-server.h"
#include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/view.h"
#include "list.h"
#include "log.h"
static void rebuild_textures_iterator(struct sway_container *con, void *data) {
container_update_marks_textures(con);
container_update_title_textures(con);
}
static void do_reload(void *data) {
// store bar ids to check against new bars for barconfig_update events
list_t *bar_ids = create_list();
for (int i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = config->bars->items[i];
list_add(bar_ids, strdup(bar->id));
}
const char *path = NULL;
if (config->user_config_path) {
path = config->current_config_path;
}
if (!load_main_config(path, true, false)) {
sway_log(SWAY_ERROR, "Error(s) reloading config");
list_free_items_and_destroy(bar_ids);
return;
}
ipc_event_workspace(NULL, NULL, "reload");
load_swaybars();
for (int i = 0; i < config->bars->length; ++i) {
struct bar_config *bar = config->bars->items[i];
for (int j = 0; j < bar_ids->length; ++j) {
if (strcmp(bar->id, bar_ids->items[j]) == 0) {
ipc_event_barconfig_update(bar);
break;
}
}
}
list_free_items_and_destroy(bar_ids);
root_for_each_container(rebuild_textures_iterator, NULL);
arrange_root();
}
struct cmd_results *cmd_reload(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) {
return error;
}
const char *path = NULL;
if (config->user_config_path) {
path = config->current_config_path;
}
if (!load_main_config(path, true, true)) {
return cmd_results_new(CMD_FAILURE, "Error(s) reloading config.");
}
// The reload command frees a lot of stuff, so to avoid use-after-frees
// we schedule the reload to happen using an idle event.
wl_event_loop_add_idle(server.wl_event_loop, do_reload, NULL);
return cmd_results_new(CMD_SUCCESS, NULL);
}