1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

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.
This commit is contained in:
Sébastien Helleu
2026-05-27 07:31:44 +02:00
parent b994a645e3
commit 53db79aa5f
2 changed files with 13 additions and 1 deletions
+3
View File
@@ -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;
+10 -1
View File
@@ -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)