From 53db79aa5f5ce2c8ffa2c9f68554ec242542fbd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 27 May 2026 07:31:44 +0200 Subject: [PATCH] api: expose theme_register to plugins Add a single new entry point to the plugin API: struct t_theme *weechat_theme_register (const char *name, struct t_hashtable *overrides); Plugins call this at init time to contribute their per-theme color (or other themable) overrides for a built-in theme like "dark". The overrides hashtable maps full option names ("irc.color.input_nick") to their string values; the caller retains ownership and may free it right after the call. Repeated calls with the same theme name merge into the existing registry entry, so each plugin can declare its own contributions independently of core and of other plugins. Wiring: - struct t_theme forward-declared in weechat-plugin.h alongside the other opaque types. - theme_register function pointer added to t_weechat_plugin. - weechat_theme_register convenience macro added. - plugin.c initializes the pointer to core's theme_register. - WEECHAT_PLUGIN_API_VERSION bumped to 20260526-01. This commit is plumbing only: the underlying theme_register function already has unit-test coverage in tests/unit/core/test-core-theme.cpp (TEST(CoreTheme, Register)), so no new tests are added here. --- src/plugins/plugin.c | 3 +++ src/plugins/weechat-plugin.h | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 91f4a1110..61d92ab88 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -50,6 +50,7 @@ #include "../core/core-log.h" #include "../core/core-network.h" #include "../core/core-string.h" +#include "../core/core-theme.h" #include "../core/core-upgrade-file.h" #include "../core/core-utf8.h" #include "../core/core-util.h" @@ -799,6 +800,8 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->config_set_desc_plugin = &plugin_api_config_set_desc_plugin; new_plugin->config_unset_plugin = &plugin_api_config_unset_plugin; + new_plugin->theme_register = &theme_register; + new_plugin->key_bind = &gui_key_bind_plugin; new_plugin->key_unbind = &gui_key_unbind_plugin; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 7d644a657..0afecab82 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -62,6 +62,7 @@ struct t_hashtable; struct t_hdata; struct t_infolist; struct t_infolist_item; +struct t_theme; struct t_upgrade_file; struct t_weelist; struct t_weelist_item; @@ -76,7 +77,7 @@ struct t_weelist_item; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20260530-01" +#define WEECHAT_PLUGIN_API_VERSION "20260531-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -728,6 +729,10 @@ struct t_weechat_plugin int (*config_unset_plugin) (struct t_weechat_plugin *plugin, const char *option_name); + /* themes */ + struct t_theme *(*theme_register) (const char *name, + struct t_hashtable *overrides); + /* key bindings */ int (*key_bind) (const char *context, struct t_hashtable *keys); int (*key_unbind) (const char *context, const char *key); @@ -1855,6 +1860,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_config_unset_plugin(__option) \ (weechat_plugin->config_unset_plugin)(weechat_plugin, __option) +/* themes */ +#define weechat_theme_register(__name, __overrides) \ + (weechat_plugin->theme_register)(__name, __overrides) + /* key bindings */ #define weechat_key_bind(__context, __keys) \ (weechat_plugin->key_bind)(__context, __keys)