Onboard 虛擬鍵盤 Debian 13 + KDE Plasma 6 + Wayland 完整設定教學(uinput 方案)

前言:從幾乎放棄,到終於能打字

老實說,這篇文章是我在幾乎準備放棄 KDE Plasma Wayland 的虛擬鍵盤時寫下的。

在 Debian 13 + KDE Plasma 6 + Wayland 環境下,官方唯一支援的螢幕鍵盤是 Maliit
但實際使用後,我遇到的是一連串幾乎無解的問題:

  • 鍵盤只出現一次
  • swipe 收起後再也叫不回來
  • 必須重啟 KWin 或整個桌面
  • 與實際平板/二合一裝置使用情境完全不相容

在反覆搜尋解法、翻 GitHub issue、KDE Discuss 討論串的過程中,我一度覺得:
「也許觸控平板選 KDE Wayland 就是死路一條。」

直到我 Google 到一篇 2022 年的 KDE Discuss 討論串

Plasma 6 and Wayland no on-screen keyboard working - Help - KDE Discuss

其中有一位使用者 @INVICTRA 提到:

I managed to get Onboard working on wayland. Kubuntu 25.04

1 Edit the shortcut in the menu. Within the KDE Menu Editor look for the Environment variables field and add “GDK_BACKEND=x11”.

2 Go to Onboard preferences page. Under Keyboard – >Advanced set:

Input Options → Input event source: GTK
Key-stroke Generation → Key-stroke generator: uinput

If you have time please try it. I would like to know if it works for others too.

我拿去問 ChatGPT 5.2,指出:Onboard + X11 backend + uinput,可能是突破口。

於是我開始實驗,補齊權限、kernel、udev 等細節,最後真的在 Debian 13 + KDE Plasma 6 + Wayland 上,
得到一個 穩定、可重複呼叫、不會卡死 的虛擬鍵盤解法。

這篇文章,就是完整整理後的結果。


一、為什麼需要這樣做(背景說明)

  • 2025 年末 KDE Plasma Wayland 官方仍只支援 Maliit
  • Maliit 目前在 KDE Plasma 存在嚴重 bug(收起後無法再叫出)
  • Wayland 設計上禁止 synthetic input(模擬鍵盤/滑鼠)
  • Onboard 可透過 Linux kernel 的 uinput 建立「虛擬鍵盤裝置」
  • uinput 屬於 kernel input device,不受 Wayland 限制

簡單說:

Wayland 不讓你「假裝按鍵」,
但 uinput 讓你「真的插一把虛擬鍵盤」。

在目前 Debian + KDE Plasma Wayland 的條件下,
這幾乎是唯一實際可用的方案。


二、系統需求

  • Debian 13

  • KDE Plasma 6

  • Wayland session

  • 已安裝 XWayland(通常預設已有)

  • 使用者具備 sudo 權限

    • *

三、安裝必要套件

sudo apt update
sudo apt install onboard xwayland

四、啟用 kernel uinput 模組

1. 確認是否已載入

lsmod | grep uinput

若沒有任何輸出,請手動載入:

sudo modprobe uinput

2. 設定開機自動載入

echo uinput | sudo tee /etc/modules-load.d/uinput.conf

五、設定 uinput 權限(關鍵步驟)

1. 建立群組

sudo groupadd -f uinput

2. 將使用者加入群組(以 hln 為例)

sudo usermod -aG uinput hln

注意:這一步完成後,一定要重新登入或重開機。


3. 建立 udev 規則

sudo nano /etc/udev/rules.d/99-uinput.rules

內容如下:

KERNEL=="uinput", MODE="0660", GROUP="uinput"

重新載入規則:

sudo udevadm control --reload
sudo udevadm trigger

4. 重開機後確認

ls -l /dev/uinput

正確結果應類似:

crw-rw---- 1 root uinput /dev/uinput

確認自己在群組內:

groups

必須看到 uinput


六、以 X11 backend 啟動 Onboard(非常重要)

在 Wayland 下,一定要強制使用 X11 backend

GDK_BACKEND=x11 onboard

建議先在 Konsole 中測試,確認鍵盤能正常顯示。


七、Onboard 設定(必做)

開啟 Onboard → Preferences → Keyboard → Advanced

請設定為:

  • Input Options

    • Input event source:GTK
  • Keystroke Generation

    • Key-stroke generator:uinput

如果你之前試過 uinput 但沒有反應,
完成權限設定後一定要重新測試。


八、實際驗證方式

  1. 開啟可輸入文字的程式(Kate / Firefox / Konsole)
  2. 點擊輸入框取得 focus
  3. 使用 Onboard 點擊鍵盤

成功狀態:

  • 文字實際輸入到程式中

  • 可反覆叫出 / 收起

  • 不需重啟 KWin

  • 不會卡死

  • 不受 Maliit bug 影響

    • *

九、建立桌面捷徑(推薦)

nano ~/.local/share/applications/onboard-x11.desktop

內容:

[Desktop Entry]
Name=Onboard (Wayland Safe)
Exec=env GDK_BACKEND=x11 onboard
Type=Application
Icon=onboard
Categories=Utility;Accessibility;

之後可以:

  • 加到 KDE 工作列

  • 加到桌面

  • 當作一鍵呼叫虛擬鍵盤

    • *

十、限制與注意事項

已知限制

  • SDDM 登入畫面無法使用
  • 非 Wayland 原生(透過 XWayland)
  • 提升輸入層權限,適合個人裝置

優點

  • 不會 swipe-down 卡死

  • 支援 Ctrl / Alt / Function keys

  • 可搭配 Fcitx5 新酷音

  • Synergy / KVM 正常

  • 長時間穩定可用

    • *

十一、回復原狀(可逆)

sudo rm /etc/udev/rules.d/99-uinput.rules
sudo gpasswd -d hln uinput
sudo reboot

十二、結論

在 Debian 13 + KDE Plasma Wayland 環境下:

Onboard + uinput 是目前唯一實際可用的虛擬鍵盤方案。

這不是官方完美解法,但 KDE 社群畢竟是做無償,你不能過度給予不符比例的期待。

最重要的是問題解決,我現在可以拿著沒有鍵盤的平板,打注音或英文操作系統了!

Debian Linux 設置 WireGuard L3 路由+NAT 連線

前言

公司目前的 DrayTek 路由器型號 不支援 WireGuard。我改在一台 Debian VM 上自建 WireGuard,帶來幾個好處:

  • 效能不再受限於 DrayTek 硬體:VM 可自行調整資源(CPU/RAM/網卡),加密吞吐量更彈性。
  • 路由規則更好控:只把特定內網(例:192.168.0.0/24192.168.10.0/24)走 VPN,不用額外在客戶端打一堆指令。
  • 維持個人上網體驗:一般上網不走公司出口,避免外部網站看到公司 IP,也不讓自己網速被公司端拖慢。
  • 相容性佳:Windows/macOS/Linux/手機端都容易配置。

目標:外部 Win11 透過 WireGuard 連入公司,能存取 192.168.0.0/24192.168.10.0/24(DrayTek 兩個 VLAN 可互通)。
做法:Layer-3 路由 + NAT;實際出口介面為 ens18


0) 伺服器環境

  • Debian 12
  • KDE Plasma

    設置 GUI 方便同事操作,會影響到網路連線的管理指令。

1) 拓樸與參數

  • WG 伺服器(Debian VM)

    • 介面:ens18
    • LAN IP:192.168.0.70/24
    • Gateway:192.168.0.251(DrayTek)
    • WG 隧道 IP:10.10.0.1/24
  • Win11 用戶端10.10.0.2/32
  • DrayTek:需 Port Forward UDP 51820 → 192.168.0.70:51820;VLAN 0/10 可路由。

1.5) 路由器/連接埠轉發(DrayTek 或你的實際路由器)

你的路由器必須把從網際網路進來的 WireGuard UDP 流量轉發到 Debian WG 伺服器。

以 DrayTek 為例(如果你用別款路由器,請做等效設定):

  • 類型: Port Forward / NAT
  • 協定: UDP
  • 外部連接埠: 51820
  • 內部主機(伺服器): 192.168.0.70
  • 內部連接埠: 51820
  • 備註: WireGuard
  • 若有 WAN 防火牆 規則,請同時允許 UDP/51820

使用其他廠牌/型號?
請做等效的動作:

  1. 建立一條 UDP 51820埠轉發,從 WAN 指向 WG 伺服器的 LAN IP(192.168.0.70)。
  2. 若路由器有獨立的防火牆頁面,新增一條允許 UDP/51820 的入站規則。
  3. 若處於 雙重 NAT(ISP 數據機 + 你的路由器),需在兩層都設定轉發,或把上游設備改成 橋接/DMZ 模式。
  4. 若 ISP 使用 CGNAT (日本常見),通常無法做入站轉發—請改用公共 IP、VPS 中繼,或請能接收入站連線的一端當 WG 伺服器。

可選(純路由、不做 NAT):
若你在 Debian 伺服器上移除 NAT,請在路由器新增靜態路由
目的: 10.10.0.0/24下一跳: 192.168.0.70


2) NetworkManager:建立 ens18(一次完成)

nmcli connection add type ethernet ifname ens18 con-name ens18 \
  ipv4.addresses 192.168.0.70/24 ipv4.gateway 192.168.0.251 \
  ipv4.dns "1.1.1.1 8.8.8.8" ipv4.method manual \
  ipv6.method ignore autoconnect yes

nmcli connection up ens18
# 驗證
ip addr show ens18
ip route get 192.168.0.251   # 應為 dev ens18 src 192.168.0.70

你已刪除 br0;不需要 bridge


3) 伺服器安裝與金鑰

apt update && apt install -y wireguard iptables tcpdump
( umask 077; wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub )
( umask 077; wg genpsk > /etc/wireguard/psk )   # 可選(建議)
chmod 600 /etc/wireguard/server.key /etc/wireguard/psk

4) /etc/wireguard/wg0.conf(NAT 出口 = ens18)

[Interface]
Address    = 10.10.0.1/24
ListenPort = 51820
PrivateKey = <server.key>

# 將 10.10.0.0/24 經 ens18 做 NAT
PostUp   = iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -o ens18 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s 10.10.0.0/24 -o ens18 -j MASQUERADE

# 第一台用戶端
[Peer]
PublicKey    = <client1.pub>
PresharedKey = <psk>                  # 若有
AllowedIPs   = 10.10.0.2/32

5) IP 轉送與 rp_filter

cat >/etc/sysctl.d/99-wg.conf <<'EOF'
net.ipv4.ip_forward=1
# 避免回路徑檢查丟棄 wg0→ens18 的轉送封包
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.wg0.rp_filter=0
net.ipv4.conf.ens18.rp_filter=0
EOF
sysctl --system

6) 防火牆(若有)

iptables -A INPUT -p udp --dport 51820 -j ACCEPT
iptables -A FORWARD -i wg0  -o ens18 -j ACCEPT
iptables -A FORWARD -i ens18 -o wg0  -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

7) 啟動與開機自動

wg-quick up wg0
systemctl enable wg-quick@wg0
wg show

8) Win11 用戶端 client.conf

[Interface]
PrivateKey = <client.key>
Address    = 10.10.0.2/32
DNS        = 192.168.0.251

[Peer]
PublicKey    = <server.pub>
PresharedKey = <psk>                           # 若伺服器啟用 PSK
Endpoint     = <你的公網IP或DDNS>:51820
AllowedIPs   = 10.10.0.1/32, 192.168.0.0/24, 192.168.10.0/24
PersistentKeepalive = 25

若用戶端所在網路也是 192.168.0.0/24,可先改為精確主機 /32(例如只加目標 IP),或暫用 0.0.0.0/0 驗證。


9) 驗證

Win11:

ping 10.10.0.1
ping 192.168.0.70
ping 192.168.0.251
ping 192.168.0.203
ping 192.168.10.20

伺服器(同時):

iptables -t nat -v -n -L POSTROUTING   # 應見 -o ens18 的 MASQUERADE 計數 > 0
wg show                                # 該 peer 的 rx/tx 會跳動
tcpdump -ni wg0 icmp
tcpdump -ni ens18 host 192.168.0.203 and icmp
ip route get 192.168.0.203             # 應為 dev ens18 src 192.168.0.70

10) 常見問題速解

  • 只能 ping 10.10.0.1 / 192.168.0.70 → 檢查:
    ip_forward=1rp_filter=0iptables -t nat 是否有
    -A POSTROUTING -s 10.10.0.0/24 -o ens18 -j MASQUERADE
  • Win11 沒有 192.168.0.0/24 路由AllowedIPs 未包含或本地段衝突。先用 /320.0.0.0/0 驗證。
  • 需要連 VLAN10 → 用戶端 AllowedIPs192.168.10.0/24 即可(DrayTek 會在 VLAN 間路由)。
  • 想改純路由(不 NAT) → 在 DrayTek 加:目的 10.10.0.0/24 → 下一跳 192.168.0.70,並移除 wg0 的 NAT。