1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 13:26:38 +02:00
Files
weechat/src/core/core-theme-builtin.c
T
Sébastien Helleu 6f979f2e95 core: track per-contributor overrides in theme registry
Refactor the theme registry to store one sub-table per contributor
instead of a single merged hashtable. Each registered theme now holds
a linked list of t_theme_contribution entries:

  struct t_theme_contribution {
      struct t_weechat_plugin *plugin;  /* NULL = core */
      const void *script;               /* NULL for non-script */
      struct t_hashtable *overrides;
      ...
  };

Identity of a contributor is the (plugin, script) pair:

  - (NULL, NULL)     -> core (theme_builtin_init)
  - (plugin, NULL)   -> plugin-level contribution
  - (plugin, script) -> individual script (filled in by next commit)

theme_register is now (plugin, script, name, overrides). It searches
the existing contributions for a matching (plugin, script) and merges
the new overrides into it; otherwise it appends a fresh contribution.
The public macro weechat_theme_register(name, overrides) still takes
two args - it now expands to pass weechat_plugin and NULL for script.

theme_apply iterates contributions in list order, calling
config_file_option_set for each entry; later contributions naturally
win for duplicate keys.

Two new internal helpers prepare for the lifecycle work in the next
two commits:

  - theme_unregister_plugin (plugin): drops every contribution owned
    by that plugin (with script == NULL).
  - theme_unregister_script (plugin, script): drops every contribution
    owned by that script.

Neither is called yet; the auto-purge wiring lands in commits 24
(plugin_unloaded signal) and 25 (script API + script-unload hook).

Other touched code:

  - core-theme-builtin.c switches to theme_register (NULL, NULL, ...).
  - core-command.c /theme info uses theme_overrides_count helper
    instead of reaching into theme->overrides (which no longer
    exists).
  - WEECHAT_PLUGIN_API_VERSION bumped to 20260527-01 (function-pointer
    signature change).

Two new tests cover the new semantics:

  - UnregisterByOwner: registers four contributions from distinct
    (plugin, script) pairs, then prunes by plugin and by script,
    asserting per-contribution removal.
  - RegisterMergesPerContributor: two successive register calls from
    the same (plugin, script) merge into a single contribution with
    later keys overriding earlier ones.

Existing tests are updated to use the new theme_register signature,
theme_overrides_count, and theme_get_override (replacing direct
access to theme->overrides->items_count and hashtable_get on
theme->overrides). No plugin or script call sites change - the
public weechat_theme_register macro keeps the same shape.
2026-06-03 22:26:13 +02:00

130 lines
4.6 KiB
C

/*
* SPDX-FileCopyrightText: 2026 Sébastien Helleu <flashcode@flashtux.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
*/
/* Built-in theme registrations (core contribution only). */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stddef.h>
#include "weechat.h"
#include "core-hashtable.h"
#include "core-theme.h"
#include "../plugins/weechat-plugin.h"
/*
* Core overrides for the "light" theme: option values tuned for a
* light-background terminal. Order is by full option name to keep diffs
* stable; the list ends with a NULL sentinel.
*/
struct t_theme_builtin_entry
{
const char *option;
const char *value;
};
struct t_theme_builtin_entry theme_builtin_light_core[] =
{
{ "weechat.bar.status.color_bg", "254" },
{ "weechat.bar.status.color_bg_inactive", "default" },
{ "weechat.bar.title.color_bg", "254" },
{ "weechat.bar.title.color_bg_inactive", "default" },
{ "weechat.color.bar_more", "magenta" },
{ "weechat.color.chat_buffer", "default" },
{ "weechat.color.chat_channel", "default" },
{ "weechat.color.chat_nick", "cyan" },
{ "weechat.color.chat_nick_colors",
"red,green,brown,blue,magenta,cyan,lightred,lightblue,lightmagenta,"
"20,28,52,57,58,61,63,88,94,128,166,202" },
{ "weechat.color.chat_nick_self", "default" },
{ "weechat.color.chat_prefix_action", "default" },
{ "weechat.color.chat_prefix_error", "94" },
{ "weechat.color.chat_prefix_join", "green" },
{ "weechat.color.chat_prefix_more", "magenta" },
{ "weechat.color.chat_prefix_quit", "red" },
{ "weechat.color.chat_prefix_suffix", "251" },
{ "weechat.color.chat_server", "94" },
{ "weechat.color.chat_text_found_bg", "magenta" },
{ "weechat.color.chat_time_delimiters", "94" },
{ "weechat.color.eval_syntax_colors",
"green,red,blue,magenta,94,cyan" },
{ "weechat.color.input_actions", "28" },
{ "weechat.color.item_away", "brown" },
{ "weechat.color.separator", "251" },
{ "weechat.color.status_count_msg", "94" },
{ "weechat.color.status_data_highlight", "93" },
{ "weechat.color.status_data_msg", "94" },
{ "weechat.color.status_data_private", "green" },
{ "weechat.color.status_more", "94" },
{ "weechat.color.status_mouse", "green" },
{ "weechat.color.status_name", "default" },
{ "weechat.color.status_name_insecure", "202" },
{ "weechat.color.status_name_tls", "default" },
{ "weechat.color.status_number", "28" },
{ NULL, NULL },
};
/*
* Builds a hashtable of overrides from a NULL-terminated table and
* registers it under the given theme name.
*/
void
theme_builtin_register_entries (const char *name,
const struct t_theme_builtin_entry *entries)
{
struct t_hashtable *overrides;
int i;
if (!name || !entries)
return;
overrides = hashtable_new (32,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_STRING,
NULL, NULL);
if (!overrides)
return;
for (i = 0; entries[i].option; i++)
hashtable_set (overrides, entries[i].option, entries[i].value);
theme_register (NULL, NULL, name, overrides);
hashtable_free (overrides);
}
/*
* Registers all built-in themes contributed by core. Called once from
* theme_init; plugins/scripts add their own contributions later via
* weechat_theme_register.
*/
void
theme_builtin_init (void)
{
theme_builtin_register_entries ("light", theme_builtin_light_core);
}