ArchWsl 运行图形界面步伐

[复制链接]
发表于 前天 12:11 | 显示全部楼层 |阅读模式
最新的WSL2已经支持图形界面(wslg)了,这里教各人运行GUI应用(桌面环境同理,但是我发起各人不要安装桌面环境,没有桌面环境也可以单独运行GUI应用)
更新WSL

   发起更新到最新版本,早期的WSL2不支持wslg,如果你是wsl1,请先升级wsl2
  1. # 更新wsl版本
  2. wsl --update
  3. # 停止正在运行的实例,不停的话不会生效
  4. wsl --shutdown
复制代码
安装ArchWSL

   安装好了的请直接跳过此步调
  下载
Releases · yuk7/ArchWSL · GitHub
安装请看如下官方阐明
怎样安装 | ArchWSL official documentation
运行GUI应用

原文如下
利用 WSL 运行 Linux GUI 应用 | Microsoft Learn
文中以ubuntu为例的,着实其他linux也是一样,直接安装GUI应用就可以了
本文以firefox为例,原文中是gimp、vlc
  1. # 安装
  2. sudo pacman -S firefox firefox-i18n-zh-cn
  3. # 启动
  4. firefox
复制代码
 如果此时出现以下错误
  1. [2950] Wayland Proxy [0x7f1ae414d350] Error: CheckWaylandDisplay(): Failed to connect to Wayland display '/run/user/0//wayland-0' error: No such file or directory
  2. Error: Failed to open Wayland display, fallback to X11. WAYLAND_DISPLAY='wayland-0' DISPLAY=':0'
  3. [GFX1-]: glxtest: Could not connect to wayland display, WAYLAND_DISPLAY=(null)
复制代码
如下图


不要慌,链接wslg的接口套接字到x11
  1. sudo rm -r /tmp/.X11-unix
  2. ln -s /mnt/wslg/.X11-unix /tmp/.X11-unix
复制代码
再实验firefox下令就会弹出窗口了。
发起再创建一个设置文件/etc/tmpfiles.d/wslg.conf写入以下内容,如许重启就不会再出现上面的标题了
  1. #  This file is part of the debianisation of systemd.
  2. #
  3. #  systemd is free software; you can redistribute it and/or modify it
  4. #  under the terms of the GNU General Public License as published by
  5. #  the Free Software Foundation; either version 2 of the License, or
  6. #  (at your option) any later version.
  7. # See tmpfiles.d(5) for details
  8. # Type Path           Mode UID  GID  Age Argument
  9. L+     /tmp/.X11-unix -    -    -    -   /mnt/wslg/.X11-unix
复制代码
这里的办理方案是通过反面的链接找到的,如果有其他标题,发起翻阅。
标题清除

Diagnosing "cannot open display" type issues with WSLg · microsoft/wslg Wiki · GitHub
中文乱码

这种方式打开GUI步伐,如果须要展示中文,就会展示成小方块,须要按以下步调设置中笔墨体
  1. # 修改字体配置
  2. sudo sed -i 's/#zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen
  3. sudo locale-gen
  4. # 安装中文字体
  5. sudo pacman -S noto-fonts-cjk noto-fonts-emoji
  6. # 重启wsl生效
  7. wsl --shutdown
  8. wsl
复制代码
中文输入法

安装fcitx5, 具体设置可参考
  1. # 安装
  2. sudo pacman -S fcitx5-im fcitx5-chinese-addons fcitx5-material-color
  3. # 启动
  4. fcitx5 &
复制代码
设置环境变量,写入~/.bashrc
  1. export LANG=zh_CN.UTF-8
  2. export LC_CTYPE="zh_CN.UTF-8"
  3. # 一般只需要这三行就可以了
  4. export QT_IM_MODULE=fcitx
  5. export GTK_IM_MODULE=fcitx
  6. export XMODIFIERS=@im=fcitx
  7. export DefaultIMModule=fcitx
  8. export SDL_IM_MODULE=fcitx
  9. export GLFW_IM_MODULE=ibus
  10. export XIM=fcitx
  11. export XIM_PROGRAM=fcitx
复制代码
设置fcitx5,运行下令
  1. fcitx5-configtool
复制代码
如果运行出现这个错误:无法通过DBus毗连到Fcitx,Fcitx是否正在运行?

这是应该是wsl在开启systemctl的一个bug,没有自动创建dbus的用户历程。可以通过systemctl status --user验证,会报错:“Failed to connect to bus: No such a file or dirctory”,手动启动dbus可以办理这个标题,但是须要每次都答应dbus-damon,github issues有办理方法
  1. sudo loginctl enable-linger $USER
复制代码
 原文:microsoft/WSL#10205 (comment)
其他标题可以运行fcitx5下令,看一下日志日志,大概实验下诊断下令fcitx5-diagnose
如果由于wayland的缘故起因导致毗连不上,可以禁用wayland
方法一:能打开fcitx5设置窗口(fcitx5-configtool)

方法二:不能打开fcitx5设置窗口(fcitx5-configtool)
  1. # 在配置文件 /home/$USER/.config/fcitx5/config 后面追加 以下内容
  2. [Behavior/DisabledAddons]
  3. 0=wayland
复制代码
方法三:直接删除wayland附加组件
  1. rm /usr/share/fcitx5/addon/wayland*
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表