diff --git a/.gitmodules b/.gitmodules index 2949641..b5355d3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -25,3 +25,6 @@ [submodule "fcitx5-rime-data/rime-stroke"] path = fcitx5-rime-data/rime-stroke url = https://github.com/rime/rime-stroke +[submodule "fcitx5-skk"] + path = fcitx5-skk + url = https://github.com/fcitx/fcitx5-skk diff --git a/README.md b/README.md index 1affc4b..46bbdce 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ Build plugins for [fcitx5-macos](https://github.com/fcitx-contrib/fcitx5-macos). ### Chinese * [chinese-addons](https://github.com/fcitx/fcitx5-chinese-addons): LGPL-2.1-or-later +### Japanese +* [skk](https://github.com/fcitx/fcitx5-skk): GPL-3.0-or-later + ### English * [hallelujah](https://github.com/fcitx-contrib/fcitx5-hallelujah): GPL-3.0-only diff --git a/all.sh b/all.sh index 852c162..52c5426 100755 --- a/all.sh +++ b/all.sh @@ -3,6 +3,7 @@ set -e all_plugins=( + skk lua hallelujah chinese-addons # Optional dependency: lua diff --git a/fcitx5-skk b/fcitx5-skk new file mode 160000 index 0000000..9b34b5f --- /dev/null +++ b/fcitx5-skk @@ -0,0 +1 @@ +Subproject commit 9b34b5fdb9e5a9fedfaf46d6ba6dba05479e552a diff --git a/patches/skk.patch b/patches/skk.patch new file mode 100644 index 0000000..d238cad --- /dev/null +++ b/patches/skk.patch @@ -0,0 +1,57 @@ +diff --git a/src/skk.cpp b/src/skk.cpp +index 2606461..1b37bcd 100644 +--- a/src/skk.cpp ++++ b/src/skk.cpp +@@ -294,6 +294,8 @@ SkkEngine::SkkEngine(Instance *instance) + newState->applyConfig(); + return newState; + }) { ++ std::string datadir = std::string(getenv("HOME")) + "/Library/fcitx5/share/libskk"; ++ setenv("LIBSKK_DATA_PATH", datadir.c_str(), 1); + skk_init(); + + modeAction_ = std::make_unique(this); +@@ -501,30 +502,36 @@ void SkkEngine::loadDictionary() { + continue; + } + if (mode == 1) { +- if (stringutils::endsWith(path, ".cdb")) { ++ constexpr char xdgDataDir[] = "$XDG_DATA_DIR/"; ++ std::string realpath = path; ++ if (stringutils::startsWith(path, xdgDataDir)) { ++ realpath = StandardPath::global().locate( ++ StandardPath::Type::Data, ++ path.substr(sizeof(xdgDataDir) - 1)); ++ } ++ if (stringutils::endsWith(realpath, ".cdb")) { + SkkCdbDict *dict = +- skk_cdb_dict_new(path.data(), encoding.data(), nullptr); ++ skk_cdb_dict_new(realpath.data(), encoding.data(), nullptr); + if (dict) { +- SKK_DEBUG() << "Adding cdb dict: " << path; ++ SKK_DEBUG() << "Adding cdb dict: " << realpath; + dictionaries_.emplace_back(SKK_DICT(dict)); + } + } else { + SkkFileDict *dict = skk_file_dict_new( +- path.data(), encoding.data(), nullptr); ++ realpath.data(), encoding.data(), nullptr); + if (dict) { +- SKK_DEBUG() << "Adding file dict: " << path; ++ SKK_DEBUG() << "Adding file dict: " << realpath; + dictionaries_.emplace_back(SKK_DICT(dict)); + } + } + } else { + constexpr char configDir[] = "$FCITX_CONFIG_DIR/"; +- constexpr auto len = sizeof(configDir) - 1; + std::string realpath = path; + if (stringutils::startsWith(path, configDir)) { + realpath = stringutils::joinPath( + StandardPath::global().userDirectory( + StandardPath::Type::PkgData), +- path.substr(len)); ++ path.substr(sizeof(configDir) - 1)); + } + SkkUserDict *userdict = skk_user_dict_new( + realpath.data(), encoding.data(), nullptr); diff --git a/scripts/skk.sh b/scripts/skk.sh new file mode 100755 index 0000000..d0e4b99 --- /dev/null +++ b/scripts/skk.sh @@ -0,0 +1,39 @@ +set -e + +. ./common.sh skk $1 + +# Use PkgConfig::LibSKK +sed -i '' 's/find_package(LibSKK REQUIRED)/pkg_check_modules(LibSKK REQUIRED IMPORTED_TARGET "libskk" REQUIRED)/' CMakeLists.txt +sed -i '' 's/LibSKK::LibSKK/PkgConfig::LibSKK/' src/CMakeLists.txt + +# Patch to load data files from ~/Library/fcitx5 +git checkout src/skk.cpp +git apply ../patches/skk.patch + +# Build fcitx5-skk +install_deps libxkbcommon pcre2 glib libgee libskk json-glib +f5m_configure -DENABLE_QT=OFF +f5m_build +f5m_install + +# Install libskk data files to ~/Library/fcitx5/share/libskk +rm -rf $DESTDIR$INSTALL_PREFIX/share/libskk +mkdir -p $DESTDIR$INSTALL_PREFIX/share/libskk +mv /tmp/fcitx5/share/libskk/rules $DESTDIR$INSTALL_PREFIX/share/libskk + +# Install the default dict to ~/Library/fcitx5/share/skk-dict +dict_dir=$DESTDIR$INSTALL_PREFIX/share/skk-dict +mkdir -p $dict_dir +cd $dict_dir +wget -nc https://skk-dev.github.io/dict/SKK-JISYO.L.gz +gunzip -f SKK-JISYO.L.gz +mv SKK-JISYO.L $dict_dir/SKK-JISYO.L +cd - + +# Write the new dictionary list +cat > $DESTDIR$INSTALL_PREFIX/share/fcitx5/skk/dictionary_list <