diff --git a/modules/i18n/input-method/fcitx5.nix b/modules/i18n/input-method/fcitx5.nix index f8dacb304..edb2d229c 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 41591aa95..608befd51 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' '';