server: sigusr1/2: update conf object with the "new" theme

When sending SIGUSR1/SIGUSR2 to a server process, all currently
running client instances change their theme. But before this patch,
all future instances used the original theme. With this patch, the
server owned config object is updated with the selected theme, thus
making new instances use the same theme as well.
This commit is contained in:
Daniel Eklöf 2025-07-30 12:23:39 +02:00
parent 7636f264a8
commit 6eedc88d70
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 49 additions and 16 deletions

36
main.c
View file

@ -45,23 +45,28 @@ fdm_sigint(struct fdm *fdm, int signo, void *data)
return true;
}
struct sigusr_context {
struct terminal *term;
struct server *server;
};
static bool
fdm_sigusr(struct fdm *fdm, int signo, void *data)
{
struct wayland *wayl = data;
xassert(signo == SIGUSR1 || signo == SIGUSR2);
if (signo == SIGUSR1) {
tll_foreach(wayl->terms, it) {
struct terminal *term = it->item;
term_theme_switch_to_1(term);
}
struct sigusr_context *ctx = data;
if (ctx->server != NULL) {
if (signo == SIGUSR1)
server_global_theme_switch_to_1(ctx->server);
else
server_global_theme_switch_to_2(ctx->server);
} else {
tll_foreach(wayl->terms, it) {
struct terminal *term = it->item;
term_theme_switch_to_2(term);
}
if (signo == SIGUSR1)
term_theme_switch_to_1(ctx->term);
else
term_theme_switch_to_2(ctx->term);
}
return true;
@ -630,8 +635,13 @@ main(int argc, char *const *argv)
goto out;
}
if (!fdm_signal_add(fdm, SIGUSR1, &fdm_sigusr, wayl) ||
!fdm_signal_add(fdm, SIGUSR2, &fdm_sigusr, wayl))
struct sigusr_context sigusr_context = {
.term = term,
.server = server,
};
if (!fdm_signal_add(fdm, SIGUSR1, &fdm_sigusr, &sigusr_context) ||
!fdm_signal_add(fdm, SIGUSR2, &fdm_sigusr, &sigusr_context))
{
goto out;
}

View file

@ -30,7 +30,7 @@ struct client;
struct terminal_instance;
struct server {
const struct config *conf;
struct config *conf;
struct fdm *fdm;
struct reaper *reaper;
struct wayland *wayl;
@ -505,7 +505,7 @@ prepare_socket(int fd)
}
struct server *
server_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
server_init(struct config *conf, struct fdm *fdm, struct reaper *reaper,
struct wayland *wayl)
{
int fd;
@ -617,3 +617,23 @@ server_destroy(struct server *server)
unlink(server->sock_path);
free(server);
}
void
server_global_theme_switch_to_1(struct server *server)
{
server->conf->initial_color_theme = COLOR_THEME1;
tll_foreach(server->clients, it)
term_theme_switch_to_1(it->item->instance->terminal);
tll_foreach(server->terminals, it)
term_theme_switch_to_1(it->item->terminal);
}
void
server_global_theme_switch_to_2(struct server *server)
{
server->conf->initial_color_theme = COLOR_THEME2;
tll_foreach(server->clients, it)
term_theme_switch_to_2(it->item->instance->terminal);
tll_foreach(server->terminals, it)
term_theme_switch_to_2(it->item->terminal);
}

View file

@ -6,6 +6,9 @@
#include "wayland.h"
struct server;
struct server *server_init(const struct config *conf, struct fdm *fdm,
struct server *server_init(struct config *conf, struct fdm *fdm,
struct reaper *reaper, struct wayland *wayl);
void server_destroy(struct server *server);
void server_global_theme_switch_to_1(struct server *server);
void server_global_theme_switch_to_2(struct server *server);