インストール - Fcitx
概要
Fcitxは、拡張機能をサポートした入力メソッドフレームワークである。
Fcitxには、3つの入力メソッドエンジン、Pinyin、QuWei、テーブルベースの入力メソッドが内蔵されている。
Fcitxのインストール (パッケージ管理システムからインストール)
RHEL
SUSE
# KKCを使用する場合 sudo zypper install fcitx-kkc fcitx-table-other # SKKを使用する場合 sudo zypper install fcitx-skk fcitx-table-other # Mozcを使用する場合 sudo zypper install fcitx-mozc fcitx-table-other # Anthyを使用する場合 # 2021年からプロジェクトが再開されており、2023年以降からAnthy Unicodeとしてパッケージが配布されている sudo zypper install fcitx-anthy fcitx-table-other
次に、Fcitxの設定ツールをインストールする。
# GNOME sudo zypper install fcitx-configtool fcitx-config-gtk3 # KDE sudo zypper install fcitx-config-kde4 (以前は、kcm-fcitxと呼ばれていた)
※注意
2023年10月現在、パッケージ管理システムからFcitx-Mozcが削除された。
また、Fcitx関連のソフトウェアは、全てfcitxで始まるため、fcitxを検索すると表示される。
Fcitxのインストール (リポジトリを追加してインストール)
SUSEの公式リポジトリからM17Nリポジトリを追加する。
# SLE / openSUSE Leap sudo zypper addrepo 'https://download.opensuse.org/repositories/M17N/$releasever/M17N.repo' M17N
追加したリポジトリを更新する。
sudo zypper refresh
Fcitxをインストールする。
# KKCを使用する場合 sudo zypper install fcitx-kkc fcitx-table-other # SKKを使用する場合 sudo zypper install fcitx-skk fcitx-table-other # Mozcを使用する場合 sudo zypper install fcitx-mozc fcitx-table-other # Anthyを使用する場合 # 2021年からプロジェクトが再開されており、2023年以降からAnthy Unicodeとしてパッケージが配布されている sudo zypper install fcitx-anthy fcitx-table-other
Mozcのインストール (ソースコードからインストール)
ソースコードのダウンロード
SLE 15において、現在、パッケージ管理システムにFcitx-mozcが存在しない。
そのため、FcitxでMozcを使用する場合は、ソースコードからビルドおよびインストールする必要がある。
Mozcのソースコードをダウンロードする。
Mozcをビルドするには、GCC 8以降が必要となる。
git clone --depth 1 https://github.com/fcitx/mozc.git cd mozc git submodule update --init --recursive cd src # または git clone https://github.com/google/mozc.git -b master --single-branch --recursive cd mozc/src
Mozcのビルドに必要な依存関係のライブラリをインストールする。
sudo zypper install git curl unzip bzip2 update-desktop-files pkg-config make ninja gcc10-c++ zlib-devel protobuf-devel \ bazel6 bazel-rules-cc-source bazel-apple-support-source bazel-workspaces \ bazel-rules-java-source bazel-rules-proto-source \ bazel-rules-python-source bazel-rules-swift-source bazel-skylib-source \ qt6-core-devel qt6-gui-devel qt6-widgets-devel \ ibus-devel fcitx-devel # Fcitxをパッケージ管理システムからインストールしている場合
通常のLinux環境でMozcを構築する場合は、以下のファイルを修正する必要がある。
- src/config.bzl
- インストールパス等の指定する。
- src/.bazelrc
- コンパイラのフラグ等を指定する。
- src/WORKSPACE.bazel
- ビルドの依存関係。
インストールディレクトリの設定
必要ならば、srcディレクトリにあるconfig.bzlファイルを編集して、インストールディレクトリを変更する。
vi mozc/src/config.bzl
# mozc/src/config.bzlファイル LINUX_MOZC_BROWSER_COMMAND = "/usr/bin/xdg-open" LINUX_MOZC_ICONS_DIR = "/<Mozcのインストールディクトリ>/share/icons/mozc" LINUX_MOZC_SERVER_DIR = "/<Mozcのインストールディクトリ>/lib/mozc" LINUX_MOZC_DOCUMENT_DIR = LINUX_MOZC_SERVER_DIR + "/documents" IBUS_COMPONENT_DIR = "/<Mozcのインストールディクトリ>/share/ibus/component" IBUS_MOZC_INSTALL_DIR = "/<Mozcのインストールディクトリ>/share/ibus-mozc" IBUS_MOZC_ICON_PATH = IBUS_MOZC_INSTALL_DIR + "/product_icon.png" IBUS_MOZC_PATH = "/<Mozcのインストールディクトリ>/lib/ibus-mozc/ibus-engine-mozc" EMACS_MOZC_CLIENT_DIR = "/<Mozcのインストールディクトリ>/share/emacs/site-lisp/emacs-mozc" EMACS_MOZC_HELPER_DIR = "/<Mozcのインストールディクトリ>/bin"
Bazelの設定ファイルの作成と変更
WORKSPACEの編集
src/WORKSPACE.bazelファイルを編集して、以下に示す設定を追記する。
vi src/WORKSPACE.bazel
- パッケージ管理システムからFcitxをインストールしている場合
# src/WORKSPACE.bazelファイル ## 138行目あたり # Fcitx # pkg_config_repository does not work because pkgconfig --cflags-only-I fcitx returns nothing new_local_repository( name = "fcitx", # This path should be updated per the environment. path = "/usr", # For Debian build_file = "BUILD.fcitx.bazel", )
- ソースコードからFcitxをインストールしている場合
# src/WORKSPACE.bazelファイル ## 138行目あたり # Fcitx new_local_repository( name = "fcitx", path = "/<Fcitxのインストールディレクトリ>", build_file = "BUILD.fcitx.bazel", )
src/BUILD.fcitx.bazelファイルを作成する。
vi src/BUILD.fcitx.bazel
# src/BUILD.fcitx.bazelファイル package( default_visibility = ["//visibility:public"], ) cc_library( name = "fcitx", hdrs = glob([ "include/fcitx/**", "include/fcitx-config/**", "include/fcitx-utils/**", ]), copts = ["-pthread"], includes = [ "include", ], linkopts = [ "-lfcitx-core", "-lfcitx-config", "-lfcitx-utils", ], )
Python 3.6を使用している場合
vi src/base/gen_config_file_stream_data.py
# src/base/gen_config_file_stream_data.pyファイル
# 68行目あたり
## 編集前
output.write('constexpr FileData kFileData[] = {\n')
for path in path_list:
output.write(' {"%s", "' % os.path.basename(path))
with open(path, 'rb') as stream:
while (byte := stream.read(1)):
output.write(r'\x' + byte.hex())
output.write('"},\n')
output.write('};\n')
## 編集後
output.write('constexpr FileData kFileData[] = {\n')
for path in path_list:
output.write(' {"%s", "' % os.path.basename(path))
with open(path, 'rb') as stream:
byte = stream.read(1)
while (byte):
output.write(r'\x' + byte.hex())
byte = stream.read(1)
output.write('"},\n')
output.write('};\n')
Mozcのウインドウレンダリングの変更
vi src/renderer/qt/qt_window_manager.cc
// src/renderer/qt/qt_window_manager.ccファイル
// 35行目あたり
// 編集前
#include "base/logging.h"
#include "protocol/candidates.pb.h"
#include "absl/strings/str_cat.h"
#include "renderer/renderer_style_handler.h"
#include "renderer/window_util.h"
// 編集後
#include "absl/strings/str_cat.h"
#include "base/logging.h"
#include "protocol/candidates.pb.h"
#include "renderer/renderer_style_handler.h"
#include "renderer/window_util.h"
// src/renderer/qt/qt_window_manager.ccファイル
// 344行目あたり
// 追加
struct VirtualRect {
const QScreen* screen;
const Rect rect;
VirtualRect(const QScreen* screen, const Rect rect): screen(screen), rect(rect) {}
};
Rect TranslateToVirtualRectWithScreen(const QScreen *screen, const Rect& native_rect) {
const double device_pixel_ratio = screen->devicePixelRatio();
// screen_left, screen_top have the save value in both virtual and native coordinate
const int screen_left = screen->geometry().x();
const int screen_top = screen->geometry().y();
const int vx = (native_rect.Left() - screen_left) / device_pixel_ratio + screen_left;
const int vy = (native_rect.Top() - screen_top) / device_pixel_ratio + screen_top;
return Rect(vx, vy, native_rect.Width() / device_pixel_ratio, native_rect.Height() / device_pixel_ratio);
}
VirtualRect TranslateToVirtualRect(const Rect& native_rect) {
for (const QScreen *screen: QGuiApplication::screens()) {
Rect rect = TranslateToVirtualRectWithScreen(screen, native_rect);
const QRect screen_rect = screen->geometry();
// Use (top left) to locate a screen
if (screen_rect.contains(rect.Left(), rect.Top())) {
return VirtualRect(screen, rect);
}
}
// fall back to primary screen
const QScreen *screen = QGuiApplication::primaryScreen();
Rect point = TranslateToVirtualRectWithScreen(screen, native_rect);
return VirtualRect(screen, point);
}
// src/renderer/qt/qt_window_manager.ccファイル
// 379行目あたり
// 編集前
Point QtWindowManager::GetWindowPosition(
const commands::RendererCommand &command, const Size &win_size) {
const Rect preedit_rect = GetRect(command.preedit_rectangle());
const Point win_pos = Point(preedit_rect.Left(), preedit_rect.Bottom());
const Rect monitor_rect = GetMonitorRect(win_pos.x, win_pos.y);
const Point offset_to_column1(kColumn0Width, 0);
const Rect adjusted_win_geometry =
WindowUtil::GetWindowRectForMainWindowFromTargetPointAndPreedit(
win_pos, preedit_rect, win_size, offset_to_column1, monitor_rect,
/* vertical */ false); // Only support horizontal window yet.
return adjusted_win_geometry.origin;
}
// 編集後
Point QtWindowManager::GetWindowPosition(
const commands::RendererCommand &command, const Size &win_size) {
const Rect native_preedit_rect = GetRect(command.preedit_rectangle());
const VirtualRect preedit_rect = TranslateToVirtualRect(native_preedit_rect);
const Point win_pos = Point(preedit_rect.rect.Left(), preedit_rect.rect.Bottom());
const Rect monitor_rect = GetRect(preedit_rect.screen->geometry());
const Point offset_to_column1(kColumn0Width, 0);
const Rect adjusted_win_geometry =
WindowUtil::GetWindowRectForMainWindowFromTargetPointAndPreedit(
win_pos, preedit_rect.rect, win_size, offset_to_column1, monitor_rect,
/* vertical */ false); // Only support horizontal window yet.
return adjusted_win_geometry.origin;
}
IBus-Mozcの設定
vi src/unix/ibus/gen_mozc_xml.py
# src/unix/ibus/gen_mozc_xml.pyファイル
# 261行目あたり
# 編集前
}, {
'name': 'mozc-off',
'longname': product_name + ':A_',
'layout': 'default',
'layout_variant': '',
'layout_option': '',
'rank': 99,
'symbol': 'A',
'composition_mode': 'DIRECT',
}]
# 編集後
}, {
'name': 'mozc-off',
'longname': product_name + ':A_',
'layout': 'default',
'layout_variant': '',
'layout_option': '',
'rank': 99,
'symbol': 'A',
'composition_mode': 'DIRECT',
}, {
'name': 'mozc-jp-jp',
'longname': product_name + " - JP layout",
'layout': 'jp',
'layout_variant': '',
'layout_option': '',
'rank': 0,
}, {
'name': 'mozc-us',
'longname': product_name + " - US layout",
'layout': 'us',
'layout_variant': '',
'layout_option': '',
'rank': 0,
}, {
'name': 'mozc-dv',
'longname': product_name + " - US Dvorak layout",
'layout': 'us',
'layout_variant': 'dvorak',
'layout_option': '',
'rank': 0,
}]
Mozcのビルド
Fcitx-Mozc、Mozcサーバ、Mozcツールをビルドおよびインストールする。
# Fcitxをソースコードからインストールしている場合
FCITX_DIR="<Fcitxのインストールディレクトリ>"; \
export PATH="$FCITX_DIR/bin:$PATH"; \
export LD_LIBRARY_PATH="$FCITX_DIR/lib64:$FCITX_DIR/lib:$LD_LIBRARY_PATH"; \
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(pkg-config --variable pc_path pkg-config)"; \
export PKG_CONFIG_PATH="$FCITX_DIR/lib64/pkgconfig:$FCITX_DIR/lib/pkgconfig:$PKG_CONFIG_PATH"
bazel build package --action_env CC=<GCC8以降のパス> --action_env CXX=<G++8以降のパス> \ //unix/fcitx:fcitx-mozc.so \ -c opt --force_pic --config oss_linux \ --jobs $(nproc) \ --strip=never \ --sandbox_debug \ --verbose_failures \ -s # または bazel build --action_env CC=<GCC8以降のパス> --action_env CXX=<G++8以降のパス> \ unix/fcitx5:fcitx5-mozc.so server:mozc_server gui/tool:mozc_tool renderer:gtk_mozc_renderer \ -c opt --copt=-fPIC --config oss_linux \ --jobs $(nproc) \ --verbose_failures
ビルドされたMozcファイル群が、src/bazel-binディレクトリに出力される。
Mozcファイル群を、以下に示すディレクトリに配置する。
ただし、Mozcのインストールディレクトリを変更している場合は、変更した設定に合わせてMozcファイル群を配置する必要がある。
# デフォルトのインストールディレクトリ sudo cp bazel-bin/unix/fcitx/fcitx-mozc.so /usr/lib64/fcitx/ sudo cp bazel-bin/server/mozc_server /usr/lib/mozc/ sudo cp bazel-bin/gui/tool/mozc_tool /usr/lib/mozc/ sudo cp bazel-bin/renderer/mozc_renderer /usr/lib/mozc/ # インストールディレクトリを変更している場合 cp bazel-bin/unix/fcitx/fcitx-mozc.so /<Mozcのインストールディレクトリ>/lib64/fcitx/ cp bazel-bin/server/mozc_server /<Mozcのインストールディレクトリ>/lib/mozc/ cp bazel-bin/gui/tool/mozc_tool /<Mozcのインストールディレクトリ>/lib/mozc/ cp bazel-bin/renderer/mozc_renderer /<Mozcのインストールディレクトリ>/lib/mozc/
※注意
必要であれば、src/scripts/install_fcitx_bazelファイルおよびsrc/scripts/install_server_bazelファイルの内容を参照する。
Mozcの設定ファイルの作成
Mozcのアドオン設定ファイル、および、インプットメソッド設定ファイルを作成する。
vi /<Mozcのインストールディレクトリ>/share/fcitx/addon/fcitx-mozc.conf # または sudo vi /usr/share/fcitx/addon/fcitx-mozc.conf
# /<Mozcのインストールディレクトリ>/share/fcitx/addon/fcitx-mozc.conf
# または
# /usr/share/fcitx/addon/fcitx-mozc.confファイル
[Addon]
Type=SharedLibrary
Name=fcitx-mozc
GeneralName=Mozc
Comment=Mozc support for Fcitx
Library=fcitx-mozc.so
IMRegisterMethod=ConfigFile
LoadLocal=True
Category=InputMethod
Enabled=True
SubConfig=
次に、Fcitx-mozcのインプットメソッド設定ファイルを作成する。
vi /<Mozcのインストールディレクトリ>/share/fcitx/inputmethod/mozc.conf # または sudo vi /usr/share/fcitx/inputmethod/mozc.conf
# /<Mozcのインストールディレクトリ>/share/fcitx/inputmethod/mozc.conf
# または
# /usr/share/fcitx/inputmethod/mozc.confファイル
[InputMethod]
UniqueName=mozc
Name=Mozc
IconName=/usr/share/fcitx/mozc/icon/mozc.png
Priority=1
LangCode=ja
Parent=fcitx-mozc
Fcitxの公式Webサイトにアクセスして、Fcitx-mozcアイコンをダウンロードする。
または、wget
コマンドを実行して、Fcitx-mozcアイコンをダウンロードする。
wget https://download.fcitx-im.org/fcitx-mozc/fcitx-mozc-icon.tar.gz
ダウンロードしたファイルを解凍する。
tar xf fcitx-mozc-icon.tar.gz
Fcitx-mozcアイコンを、/usr/share/fcitx/mozc/iconディレクトリに配置する。
cp fcitx-mozc-icons/* /<Mozcのインストールディレクトリ>/share/fcitx/mozc/icon # または sudo mkdir -p /usr/share/fcitx/mozc/icon sudo cp fcitx-mozc-icons/* /usr/share/fcitx/mozc/icon
拡張機能のインストール
GNOME
https://extensions.gnome.org にアクセスし、検索項目にfcitxと入力・検索して、その拡張機能をインストールする。
KDE
Input Method Panelと呼ばれるプラズモイドを追加できる。
これは、KDE Plasmaアドオンのkimpanelである。
標準でインストールされているので、必要なことは、そのプラズモイドを追加することだけである。
他には、M17Nには、kimtoyと呼ばれるサードパーティ製ソフトウェアが存在する。(Qtで記述されている)
nepomuk等を有効にすることができる。(ただし、KDEの反応が悪くなる)
Fcitxの設定
GNOME (X11)
/etc/sysconfig/languageファイルを、以下のように編集する。
sudo vi /etc/sysconfig/language
# /etc/sysconfig/languageファイル # 変更前 INPUT_METHOD="" # 変更後 INPUT_METHOD="fcitx"
~/.profileファイルに、以下の設定を追記する。
vi ~/.profile
# ~/.profile export XMODIFIERS="@im=fcitx" export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx
PCを再ログインまたは再起動する。
次に、以下のコマンドを実行して、Fcitxの設定ツールを起動する。
fcitx-config-gtk3
Fcitxの設定ツール画面左下にある[+]アイコンを選択して、入力メソッドを追加する。
インプットメソッドの追加画面下部にある[only show current language]チェックボックスのチェックを外して、"Japan"と検索する。
目的のインプットメソッドを選択して、[OK]ボタンを押下する。
これにより、[Ctrl] + [Space]キーを同時押下して、Fcitxのインプットメソッドを呼び出すことができる。
KDE (X11)
~/.profileファイルまたは~/.ximファイルに、以下の設定を追記する。
vi ~/.profile または vi ~/.xim
# ~/.profileファイルまたは~/.ximファイル export INPUT_METHOD="fcitx" export XMODIFIERS="@im=fcitx" export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx
PCを再ログインまたは再起動する。
次に、以下のコマンドを実行して、設定ツールを起動する。
または、システムトレイから起動する。
# GNOME fcitx-config-gtk # KDE fcitx-config-kde
Wayland
最新のFcitxとiBusでは、Xのプロトコルアダプタを介して、基本的なWaylandサポートを備えている。
今後は、Waylandを直接サポートする予定である。
Waylandで入力メソッドを有効にするには、/etc/environmentファイル、または、~/.pam_environmentファイルに以下の内容を追記する。
なお、~/.xprofileファイル、~/.profileファイル、~/.bashrcファイル、~/.xinitrcファイルは設定不要である。
sudo vi /etc/environment または vi ~/.pam_environment
# /etc/environmentファイル または ~/.pam_environmentファイル # Fcitxを使用する場合 LANG=en_US.UTF-8 INPUT_METHOD=fcitx XMODIFIERS=@im=fcitx GTK_IM_MODULE=fcitx QT_IM_MODULE=fcitx DefaultIMModule=fcitx
最後に、PCを再起動する。
KKC
単語登録
KKCにおいて、単語登録する手順を以下に示す。
- Fcitxの場合
- ~/.config/fcitx/kkc/dictionary/segmentファイルを開く。
- Fcitx5の場合
- ~/.local/share/fcitx5/kkc/dictionary/segmentファイルを開く。
- Fcitxの場合
- segmentファイルの最下行に、以下の内容を追記する。
- 1つの読みがなで1つの単語を登録する場合 :
<読みがな> /<登録する単語>;<登録する単語の種類>/
- 1つの読みがなで3つの単語を登録する場合 :
<読みがな> /<登録する単語>;<登録する単語の種類>/<登録する単語>;<登録する単語の種類>/<登録する単語>;<登録する単語の種類>/
- 例えば、"hoge@piyo.com"という単語を"めーる"という読みで登録する時は、以下の手順を行う。
めーる /hoge@piyo.com;メール/
- 1つの読みがなで1つの単語を登録する場合 :
- Fcitx / Fcitx 5において、[Reload Config]または[再起動]を選択する。
- 正常に単語登録されているかどうかを確認する。
- 登録された単語を削除する場合は、該当単語の行を削除して、[Reload Config]または[再起動]を選択する。
その他
Fcitxの再起動
Fcitx関連のソフトウェアのインストール後、設定等を反映させるため、Fcitxを再起動する必要がある。
Fcitxを再起動するには、以下のコマンドを実行する。
fcitx -r
一部の入力メソッドは標準でリストに追加される。(通常、内部に入力メソッドが1つしかないパッケージの場合)
入力メソッドが追加されない場合、設定ツールを使用してそれらをリストに追加して、ニーズに合わせていくつかのオプションを調整することを推奨する。
ibusからfcitxへの切り替え
GNOME以外では、切り替え操作は不要である。
Fcitxを導入して再ログインすると、インプットメソッドがfcitxに自動的に切り替わる。
GNOMEの場合、ibusとの統合を解除する必要があるかもしれない。
もし、自動的に切り替わらない場合は、以下コマンドを実行する。
gsettings set org.gnome.settings-daemon.plugins.keyboard active false
以下のコマンドを実行して、ibusからFcitxへ切り替える。
imsetting-switch fcitx
日本語入力できない場合 1
以下のコマンドを実行する。
sudo mv /usr/share/ibus/component/kimpanel.xml /usr/share/ibus/component/kimpanel_org.xml
日本語入力できない場合 2
Fcitxより先に起動したソフトウェアにおいて、日本語入力できない場合がある。
その時、~/.ximファイルを作成して、以下の内容を記述する。
vi ~/.xim
export XMODIFIERS="@im=fcitx" export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx LANG=ja_JP.UTF-8 fcitx -r
Fcitxのアンインストール
以下のコマンドを実行して、Fcitxをアンインストールする。
# GNOME sudo zypper remove fcitx fcitx-kkc fcitx-skk fcitx-mozc fcitx-anthy fcitx-m17n fcitx-table-other fcitx-config-gtk3 # KDE sudo zypper remove fcitx fcitx-kkc fcitx-skk fcitx-mozc fcitx-anthy fcitx-m17n fcitx-table-other fcitx-config-kde4
再ログインまたはPCを再起動する。