Skip to content

如何在 WSL2 中使用 fcitx5 mcbopomofo

Weizhong Yang a.k.a zonble edited this page May 27, 2022 · 7 revisions

在 Windows 上,我們可以使用 WSL 建立 Linux 環境,我們也可以在 WSL 中使用 fcitx5-mcbopomofo。由於 fcitx5-mcbopomofo 是在 fcitx5 下的輸入法,fcitx5 是一套在 GUI 環境下的輸入法框架,而微軟是在 WSL2 以上,才能夠執行具有 GUI 的 Linux 應用程式,以下說明所基於的環境,是在 Windows 11 上,透過 WSL2 使用 Ubuntu 22.04。

wsl-screenshot

安裝 WSL2

  • 請先用系統管理員權限打開一個命令提示視窗,然後輸入 dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart,啟用 WSL 功能。
  • 請先參考 微軟的官方說明,尤其是當中「從 WSL 1 升級至 WSL 2 的版本」這一段。在命令提示視窗中,輸入 wsl --set-version 2 指令,您也可能需要額外安裝的套件。
  • 接著,打開 Microsoft Store,安裝 Ubuntu 22.04 LTS
  • 在第一次啟動之後,先更新一次系統。請輸入 sudo apt updatesudo apt upgrade

安裝 fcitx5 與必要工具

接下來請使用 apt 指令安裝 fcitx5 輸入法框架,以及各種需要的工具

sudo apt install fonts-noto-cjk fonts-noto-color-emoji # 安裝字體
sudo apt install clang # 安裝開發工具
sudo apt install cmake extra-cmake-modules gettext libfmt-dev # 安裝開發工具
sudo apt install -y fcitx5 libfcitx5core-dev libfcitx5config-dev libfcitx5utils-dev # 安裝 fcitx5

然後,我們可以用 im-config 指令,要求系統將輸入法切換成 fcitx5。

解決 fcitx5 無法啟動的問題

目前(2022 年 5 月),如果在 WSL2/Ubuntu 的命令提示字元下,馬上輸入 fcitx5 指令,會發現無法正確啟動 fcitx5;原因是,在 WSL2 下,還無法正確使用 fcitx5 的 wayland 支援,所以,我們可以先透過 fcitx5 --disable=wayland 指令,先把 fcitx5 跑起來,接著,透過 fcitx5-config-qt 指令,叫出設定工具,關閉 wayland 支援。

關閉 wayland 支援的方式是,在 fcitx5 設定工具的第三個分頁 "Addons" 中,在搜尋框當中,輸入 wayland 關鍵字,然後勾選畫面左下角的 "Show advanced options",就可以看到在 wayland 選項前有一個 checkbox,我們便可以用這個 checkbox 選擇不要啟用 wayland 支援。

wsl-fcitx5-settings

當我們重新直接輸入 fcitx5 命令,就可以在各種應用程式中打字了。

安裝 fctix5-mcbopomofo

接下來的安裝流程,就和在 Linux 上相同,請參考專案首頁上的說明。