mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-27 21:58:16 +01:00
80e8be71a3
When the config gets reloaded, the font height and baseline get reset to 0. If the config does not have a font command in it, the variables will remain at 0 causing a transparent area where the title would be rendered. This makes it so the font height and baseline are recalculated. Additionally, since the font height and baseline may have changed due to the reload, the title and marks textures are rebuilt.
73 lines
1.9 KiB
C
73 lines
1.9 KiB
C
#define _XOPEN_SOURCE 500
|
|
#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) {
|
|
if (con->view) {
|
|
view_update_marks_textures(con->view);
|
|
}
|
|
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));
|
|
}
|
|
|
|
if (!load_main_config(config->current_config_path, true, false)) {
|
|
wlr_log(WLR_ERROR, "Error(s) reloading config");
|
|
list_foreach(bar_ids, free);
|
|
list_free(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_foreach(bar_ids, free);
|
|
list_free(bar_ids);
|
|
|
|
config_update_font_height(true);
|
|
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;
|
|
}
|
|
|
|
if (!load_main_config(config->current_config_path, true, true)) {
|
|
return cmd_results_new(CMD_FAILURE, "reload",
|
|
"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, NULL);
|
|
}
|