Skip to content

Instantly share code, notes, and snippets.

@ivon852
Last active June 13, 2025 11:14
Show Gist options
  • Save ivon852/80eb95f3d0ba1c531645d89eb4876ddd to your computer and use it in GitHub Desktop.
Save ivon852/80eb95f3d0ba1c531645d89eb4876ddd to your computer and use it in GitHub Desktop.

Wayland桌面工作階段會帶來許多問題,其中最常見的就是瀏覽器效能下降的問題。因為有些瀏覽器預設跑在XWayland模式,所以看起來會卡卡的。所以要手動啟用Wayland模式。但是有的瀏覽器啟用Wayland模式反而出現了其他問題,下面就要來討論如何解決這些問題。

下列操作適用Ubuntu 24.04 LTS以上版本的系統。

1. 如何確認自己是使用Wayland工作階段

使用echo $XDG_SESSION_TYPE指令即可得知是目前桌面工作階段x11還是wayland

GNOME 42以上版本預設使用Wayland,登入畫面GDM右下角齒輪會有GNOMEGNOME on Xorg的選項。

KDE Plasma 6以上版本預設使用Wayland,登入畫面SDDM左下角有Plasma (Wayland)Plasma (X11)的選項。

如果覺得Wayland問題過多,嘗試切換回X11工作階段。

2. 強制瀏覽器使用純Wayland工作階段

  1. Wayland工作階段,Firefox (v.121以上) 預設會自動使用Wayland,不用再設定MOZ_ENABLE_WAYLAND=1環境變數了。開啟about:config頁面可得知是否正在使用Wayland。

  2. Google Chrome (v.137) 預設仍是使用XWayland,跑在X11模式下,這點可以用xlsclients指令確認。

  3. 編輯Chrome的Desktop Entry,修改Chrome的啟動選項:

vim ~/.local/share/applications/google-chrome.desktop
  1. 加上啟動引數,進入Wayland模式。
Exec=/usr/bin/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform-hint=wayland
  1. 使用以下指令可得知是否正在使用Wayland:
strings `which google-chrome-stable` | grep WAYLAND_DISPLAY
  1. Google Chrome的設定應該也適用其他使用Chromium核心的程式,例如Chromium、Edge、Brave、Vivaldi,還有使用Electron框架的程式,如Visual Studio Code。但是Wayland支援程度要看其使用的Chromium核心版本而定。

3. 解決Fcitx5 Wayland無法輸入中文的問題

確保有安裝fcitx5-gtkfcitx5-qt等套件。

Firefox Wayland應該可以正常使用Fcitx5輸入法,但是Chrome Wayland有時無法喚醒。因為桌面環境合成器實作的輸入法協定有所差異,不同桌面環境有不同作法。

GNOME 48+

  1. 編輯/etc/environment
sudo vim /etc/environment
  1. 針對XWayland程式新增環境變數XMODIFIERS=@im=fcitxQT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
QT_IM_MODULE=fcitx
  1. 編輯Chrome的Desktop Entry,修改Chrome的啟動選項。
vim ~/.local/share/applications/google-chrome.desktop
  1. 加上啟動引數。才能於Google Chrome瀏覽器喚醒Fcitx5輸入法。
Exec=/usr/bin/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime
  1. 推薦安裝GNOME擴充套件Input Method Panel,才能在右上角系統匣顯示Fcitx5圖示。

KDE Plasma 6.3+

  1. Wayland與X11作法不同,不應該設定GTK_IM_MODULEQT_IM_MODULE環境變數,使用env | grep "GTK_IM_MODULE\|QT_IM_MODULE"指令確認。如果有,Ubuntu可以執行im-config指令,點選do not activate any IM from im-config and use desktop default,將其消除。

  2. 編輯/etc/environment

sudo vim /etc/environment
  1. 針對XWayland程式新增環境變數XMODIFIERS=@im=fcitx
XMODIFIERS=@im=fcitx
  1. 開啟KDE Plasma系統設定 → 鍵盤 → 虛擬鍵盤 → 選取Fcitx5,然後重新登入KDE Plasma桌面。

  2. 編輯Chrome的Desktop Entry,修改Chrome的啟動選項。

vim ~/.local/share/applications/google-chrome.desktop
  1. 加上啟動引數。才能於Google Chrome瀏覽器喚醒Fcitx5輸入法。
Exec=/usr/bin/google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

4. 解決Wayland Google Meet共享畫面黑螢幕

  1. 確認有無安裝PipeWire以及XDG Desktop Portal套件,讓瀏覽器能透過XDG Portal存取螢幕。XDG Desktop根據桌面環境不同會有不同的套件,應該是xdg-desktop-portal-gnomexdg-desktop-portal-kde

  2. WebRTC Screen Sharing | Plugin-free網站測試共享畫面。

  3. Firefox與Chrome都跑在Wayland模式下的話,應該能順利分享螢幕。

  4. 若是跑在XWayland模式下的Google Chrome,需要開啟chrome://flags,將WebRTC PipeWire support設為Enabled,重啟。才能在GNOME共享螢幕。至於KDE Plasma 5.27以後有提供XWayland Video Bridge,應該能直接分享螢幕。

參考資料

@y60yu1ii
Copy link

y60yu1ii commented May 4, 2024

目前你這篇是網路上唯一最完整且有用的。
我為了要打開fractional scaling 的時候字不會糊掉, 所以chrome本來就有指定 ozone platform.
但仍然無法打開fcitx 後來才發現要指定gtk version=4

@SakuraPuare
Copy link

thank, very useful for me

@pengchangg
Copy link

thinks~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment