From 6899001a762b0e089ad7b8ec7637d0a678640b8e Mon Sep 17 00:00:00 2001 From: Flameopathic <64027365+Flameopathic@users.noreply.github.com> Date: Tue, 22 Apr 2025 15:30:45 -0400 Subject: [PATCH] fcitx5: add `themes` and `classicUiConfig` options (#6876) --- modules/i18n/input-method/fcitx5.nix | 76 +++++++++++++++++++ .../input-method/fcitx5-configuration.nix | 17 ++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/modules/i18n/input-method/fcitx5.nix b/modules/i18n/input-method/fcitx5.nix index f8dacb30..edb2d229 100644 --- a/modules/i18n/input-method/fcitx5.nix +++ b/modules/i18n/input-method/fcitx5.nix @@ -37,6 +37,48 @@ in See [Using Fcitx 5 on Wayland](https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland). ''; }; + + classicUiConfig = lib.mkOption { + type = with lib.types; either path lines; + default = ""; + description = '' + Configuration to be written to {file}`$XDG_DATA_HOME/fcitx5/conf/classicui.conf` + ''; + }; + + themes = lib.mkOption { + type = + with lib.types; + lazyAttrsOf (submodule { + options = { + theme = lib.mkOption { + type = with lib.types; nullOr (either lines path); + default = null; + description = '' + The `theme.conf` file of the theme. + + See https://fcitx-im.org/wiki/Fcitx_5_Theme#Background_images + for more information. + ''; + }; + highlightImage = lib.mkOption { + type = with lib.types; nullOr path; + default = null; + description = "Path to the SVG of the highlight."; + }; + panelImage = lib.mkOption { + type = with lib.types; nullOr path; + default = null; + description = "Path to the SVG of the panel."; + }; + }; + }); + example = ""; + description = '' + Themes to be written to {file}`$XDG_DATA_HOME/fcitx5/themes/''${name}` + ''; + default = { }; + }; }; }; @@ -58,6 +100,40 @@ in sessionSearchVariables.QT_PLUGIN_PATH = [ "${fcitx5Package}/${pkgs.qt6.qtbase.qtPluginPrefix}" ]; }; + xdg = + let + mkThemeConfig = name: attrs: { + dataFile = { + "fcitx5/themes/${name}/highlight.svg" = lib.mkIf (attrs.highlightImage != null) { + source = attrs.highlightImage; + }; + "fcitx5/themes/${name}/panel.svg" = lib.mkIf (attrs.panelImage != null) { + source = attrs.panelImage; + }; + "fcitx5/themes/${name}/theme.conf" = lib.mkIf (attrs.theme != null) { + source = + if builtins.isPath attrs.theme || lib.isStorePath attrs.theme then + attrs.theme + else + pkgs.writeText "fcitx5-theme.conf" attrs.theme; + }; + }; + }; + in + lib.mkMerge ( + [ + (lib.mkIf (cfg.classicUiConfig != "") { + dataFile."fcitx5/conf/classicui.conf".source = ( + if builtins.isPath cfg.classicUiConfig || lib.isStorePath cfg.classicUiConfig then + cfg.classicUiConfig + else + pkgs.writeText "fcitx5-classicui.conf" cfg.classicUiConfig + ); + }) + ] + ++ (builtins.attrValues (lib.mapAttrs mkThemeConfig cfg.themes)) + ); + systemd.user.services.fcitx5-daemon = { Unit = { Description = "Fcitx5 input method editor"; diff --git a/tests/modules/i18n/input-method/fcitx5-configuration.nix b/tests/modules/i18n/input-method/fcitx5-configuration.nix index 41591aa9..608befd5 100644 --- a/tests/modules/i18n/input-method/fcitx5-configuration.nix +++ b/tests/modules/i18n/input-method/fcitx5-configuration.nix @@ -8,13 +8,28 @@ lib.mkIf config.test.enableBig { i18n.inputMethod = { enabled = "fcitx5"; - fcitx5.waylandFrontend = true; + fcitx5 = { + waylandFrontend = true; + themes.example = { + theme = '' + [Metadata] + Name=example + Version=0.1 + Author=home-manager + Description=Theme for testing + ScaleWithDPI=True + ''; + }; + classicUiConfig = "Theme=example"; + }; }; _module.args.pkgs = lib.mkForce realPkgs; nmt.script = '' assertFileExists home-files/.config/systemd/user/fcitx5-daemon.service + assertFileExists home-files/.local/share/fcitx5/themes/example/theme.conf + assertFileExists home-files/.local/share/fcitx5/conf/classicui.conf assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'GTK_IM_MODULE' assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'QT_IM_MODULE' '';