Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
fcitx5-skk (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf authored Jan 8, 2024
1 parent b6b3f85 commit ebcd3dc
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

all_plugins=(
skk
lua
hallelujah
chinese-addons # Optional dependency: lua
Expand Down
1 change: 1 addition & 0 deletions fcitx5-skk
Submodule fcitx5-skk added at 9b34b5
57 changes: 57 additions & 0 deletions patches/skk.patch
Original file line number Diff line number Diff line change
@@ -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<SkkModeAction>(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);
39 changes: 39 additions & 0 deletions scripts/skk.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
type=file,file=\$FCITX_CONFIG_DIR/skk/user.dict,mode=readwrite
type=file,file=\$XDG_DATA_DIR/skk-dict/SKK-JISYO.L,mode=readonly
EOF

f5m_make_tarball

0 comments on commit ebcd3dc

Please sign in to comment.