您尚未登录。

公告

[通告] 本论坛迁移啦~请前往位于 https://forum.archlinuxcn.org/ 的新论坛。所有帖子和参与的用户都已经迁移。

您正在访问的是原 bbs.archlinuxcn.org 的静态存档。本页面的新地址位于 https://forum.archlinuxcn.org/t/topic/13750

#1 2024-11-17 00:45:30

千年草
会员
注册时间: 2023-04-11
帖子: 10

[已解决]wayland下etectron应用(qq, vsc, obsidian等)无法使用中文输入法

能确认的是这几个electron应用运行在wayland而不是xwayland下
尝试过修改环境变量和传递命令行参数“--ozone-platform-hint=auto --enable-wayland-ime”均无效
之前在kde和xwayland下是正常的

求助还有没有其他方法QAQ

最近编辑记录 千年草 (2025-07-13 00:52:28)

离线

#2 2024-11-17 00:53:50

WhiredPlanck
会员
注册时间: 2020-07-26
帖子: 25

Re: [已解决]wayland下etectron应用(qq, vsc, obsidian等)无法使用中文输入法

Steam 不是 Electron 应用,它一直没法使用输入法的。

如果是 QQ 或者 VS Code 话,尝试这个命令行参数:

--enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

离线

#3 2024-11-17 08:33:47

BRS5672023
会员
注册时间: 2020-07-07
帖子: 159

Re: [已解决]wayland下etectron应用(qq, vsc, obsidian等)无法使用中文输入法

WhiredPlanck 说:

Steam 不是 Electron 应用,它一直没法使用输入法的。

如果是 QQ 或者 VS Code 话,尝试这个命令行参数:

--enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

这个是支持 text-input-v1 的桌面才能用的,目前需要等 electron 支持 text-input-v3。。作为对比,目前 chromium 使用 text-input-v3 需要的 flag 是

--enable-wayland-ime
--wayland-text-input-version=3

离线

#4 2025-07-13 00:30:14

千年草
会员
注册时间: 2023-04-11
帖子: 10

Re: [已解决]wayland下etectron应用(qq, vsc, obsidian等)无法使用中文输入法

BRS5672023 说:
WhiredPlanck 说:

Steam 不是 Electron 应用,它一直没法使用输入法的。

如果是 QQ 或者 VS Code 话,尝试这个命令行参数:

--enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

这个是支持 text-input-v1 的桌面才能用的,目前需要等 electron 支持 text-input-v3。。作为对比,目前 chromium 使用 text-input-v3 需要的 flag 是

--enable-wayland-ime
--wayland-text-input-version=3

可以了,目前亲测可用的参数如下:

--enable-platform=wayland --enable-wayland-ime --wayland-text-input-version=3

因为cosmic的wayland的合成器并不支持过时的text-input-v1,只支持v3所以必须要加--wayland-text-input-version=3参数。(飞书客户端在cosmic下还是不能用中文输入法,在kde下可以)
如果是kde的话不加也可以,但是毕竟v1已经过时了还是优先推荐用v3吧。

另外chromium在最近好像也把text-input-v3的支持稳定了,详情可见:https://issues.chromium.org/issues/40113488#comment132
最后附上一个我在用的fish脚本用于软件包更新后批量修改应用的.desktop文件添加命令行参数(大模型生成,注意风险⚠️⚠️⚠️):
我尝试在electron-flags.conf文件下添加这些参数不生效,只好逐个修改.desktop文件,如果有更成熟的方法可以踢我一下。

#!/usr/bin/env fish

#==============================================================================
# Script to add Wayland flags to Electron App .desktop files.
#
# USAGE:
#   ./patch_electron_desktop_files.fish code.desktop obsidian.desktop ...
#
# FEATURES:
#   - Creates backups (.bak) before modifying.
#   - Handles both user and system .desktop files safely.
#   - Avoids duplicate entries if run multiple times.
#   - Updates the desktop database automatically.
#==============================================================================

# --- 请在这里配置您需要添加的参数 ---
set -l flags_to_add "--enable-platform=wayland --enable-wayland-ime --wayland-text-input-version=3"
# ------------------------------------

function print_usage
    set_color bryellow
    echo "Usage: $argv[0] [app1.desktop] [app2.desktop] ..."
    set_color normal
    echo "This script adds Wayland compatibility flags to the Exec= line of specified .desktop files."
    echo ""
    echo "Example:"
    echo "  $argv[0] code.desktop obsidian.desktop"
    echo ""
end 

if not count $argv > /dev/null
    or [ "$argv[1]" = "-h" ]
    or [ "$argv[1]" = "--help" ]
    print_usage
    exit 0
end

set -l user_app_dir "$HOME/.local/share/applications"
set -l system_app_dir "/usr/share/applications"

# 确保用户应用目录存在
mkdir -p $user_app_dir

for desktop_file_name in $argv
    set -l target_path ""

    # 优先查找用户目录,其次是系统目录
    if test -f "$user_app_dir/$desktop_file_name"
        set target_path "$user_app_dir/$desktop_file_name"
        echo -e "🔎 Found user file: (set_color blue)$target_path(set_color normal)"
    else if test -f "$system_app_dir/$desktop_file_name"
        set -l system_path "$system_app_dir/$desktop_file_name"
        set target_path "$user_app_dir/$desktop_file_name"
        echo -e "🔎 Found system file: (set_color cyan)$system_path(set_color normal)"
        echo -e "    └─ Copying to user directory for safe editing..."
        cp "$system_path" "$target_path"
    else
        echo -e "❌ (set_color red)Error: Cannot find '$desktop_file_name' in user or system directories.(set_color normal)"
        continue
    end

    # 检查是否已经包含了参数
    if grep -q "Exec=.*$flags_to_add" "$target_path"
        echo -e "✅ (set_color green)Skipping: Flags already exist in '$desktop_file_name'.(set_color normal)\n"
        continue
    end

    # 创建备份
    cp "$target_path" "$target_path.bak"
    echo "    └─ Backed up to (set_color yellow)$target_path.bak(set_color normal)"

    # 使用 sed 添加参数
    # 这个复杂的sed命令是为了处理 Exec=... %U 或 Exec=... @@...@@ 等情况
    # 它会把参数插入到可执行文件之后,但在 % 或 @@ 占位符之前
    sed -i -E "s|^(Exec=)([^ ]+)(.*)|\1\2 $flags_to_add\3|g" "$target_path"

    echo -e "🚀 (set_color green)Successfully patched '$desktop_file_name'.(set_color normal)\n"
end

# 更新桌面数据库以应用更改
echo "🔄 Updating desktop database for changes to take effect..."
update-desktop-database -q "$user_app_dir"
echo "✅ Done!"

最近编辑记录 千年草 (2025-07-13 00:33:40)

离线

页脚