Weston

出自 Arch Linux 中文维基

Weston 是一個開源的、基於Wayland 顯示伺服器協議的窗口管理器(compositor),專為正確性、可靠性、可預測性和性能而設計。Weston作為Wayland協議的實現,提供了顯示管理器的窗口管理和基本功能 ,包括不限於窗口的創建、移動、縮放、透明度處理、輸入事件分發以及多屏幕支持等功能。

安裝[編輯 | 編輯原始碼]

安裝 weston 軟件包。

使用[編輯 | 編輯原始碼]

要以本機方式(從 TTY)啟動 Weston 或在正在運行的 X 會話中運行 Weston:

$ weston

想了解詳細信息和配置,請參閱 weston(1)

示例應用[編輯 | 編輯原始碼]

在 Weston 中內置了原生wayland演示應用,可以運行這些示例程序。要啟動終端仿真器,請執行以下命令:

$ weston-terminal

可移動的花

$ weston-flower 

顯示圖片

$ weston-image image1.jpg image2.jpg...

快捷鍵[編輯 | 編輯原始碼]

提示:Super (windows按鍵) 可以自定義, 詳細查看 weston.ini
Weston 鍵盤快捷鍵
組合鍵 動作
Ctrl+Alt+Backspace 退出 Weston 合成器
Super+Scroll (或 PageUp/PageDown) 放大/縮小 窗口
Super+Tab 切換窗口
Super+LMB 啟動窗口
Super+MMB 旋轉窗口
Super+RMB 改變窗口大小
Super+Alt+Scroll 改變窗口透明度
Super+k 強制關閉當前活動窗口
Super+Up/Down 切換到 上一個/下一個 工作區
Super+Shift+Up/Down 移動當前活動窗口到其他工作區
Super+Fn 切換到工作區n (例如:F2)
Super+s 截屏
Super+r 錄製屏幕

配置[編輯 | 編輯原始碼]

下面是一個示例配置文件。參見 weston.ini(5) 了解更多信息。

~/.config/weston.ini
[core]
# xwayland support
xwayland=true

[libinput]
enable-tap=true

[shell]
#background-image=/usr/share/backgrounds/gnome/Aqua.jpg
background-type=scale-crop
background-color=0xff000000
#background-color=0xff002244
#panel-color=0x90ff0000
panel-color=0x00ffffff
panel-position=bottom
#clock-format=none
#animation=zoom
#startup-animation=none
close-animation=none
focus-animation=dim-layer
#binding-modifier=ctrl
num-workspaces=6
locking=false
cursor-theme=Adwaita
cursor-size=24

# 平板电脑选项
#lockscreen-icon=/usr/share/icons/gnome/256x256/actions/lock.png
#lockscreen=/usr/share/backgrounds/gnome/Garden.jpg
#homescreen=/usr/share/backgrounds/gnome/Blinds.jpg
#animation=fade

# 用于笔记本电脑显示器
[output]
name=LVDS1
mode=preferred
#mode=1680x1050
#transform=rotate-90

#[output]
#name=VGA1
# 下面使用 modeline 设置模式,您可以使用 cvt 工具获取首选分辨率的模式线
#mode=173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync
#transform=flipped

#[output]
#name=X1
#mode=1024x768
#transform=flipped-rotate-270

# 屏幕键盘输入法
#[input-method]
#path=/usr/lib/weston/weston-keyboard

[keyboard]
keymap_rules=evdev
#keymap_layout=us,de
#keymap_variant=colemak,
#keymap_options=grp:shifts_toggle
#keymap_options=caps:ctrl_modifier,shift:both_capslock_cancel
repeat-rate=30
repeat-delay=300

# keymap_options from /usr/share/X11/xkb/rules/base.lst
#numlock-on=true

[terminal]
font=monospace
font-size=18

[launcher]
icon=/usr/share/weston/icon_flower.png
path=/usr/bin/weston-flower

[launcher]
icon=/usr/share/icons/gnome/32x32/apps/utilities-terminal.png
path=/usr/bin/weston-terminal --shell=/usr/bin/bash

#[launcher]
#icon=/usr/share/icons/gnome/32x32/apps/utilities-terminal.png
#path=/usr/bin/gnome-terminal

[launcher]
icon=/usr/share/icons/hicolor/32x32/apps/firefox.png
path=MOZ_ENABLE_WAYLAND=1 /usr/bin/firefox

#[launcher]
#icon=/usr/share/icons/Adwaita/32x32/apps/multimedia-volume-control.png
#path=/usr/bin/st alsamixer -c0

最少 weston.ini 配置:

~/.config/weston.ini
[core]
xwayland=true

[keyboard]
keymap_layout=us

[launcher]
icon=/usr/share/weston/terminal.png
path=/usr/bin/weston-terminal

顯示器[編輯 | 編輯原始碼]

Weston 的輸出與 xorg.conf 顯示器的輸出略有不同:

$ ls /sys/class/drm
card0
card0-VGA-1
card1
card1-DVI-I-1
card1-HDMI-A-1
card1-VGA-2

card0 是未使用的顯卡(內置視頻適配器)。附加適配器 card1 通過視頻線連接到一個 HDMI 和一個 DVI 顯示器,因此輸出名稱為 HDMI-A-1DVI-I-1

Xwayland[編輯 | 編輯原始碼]

請參閱 Wayland#Xwayland 了解可用軟件包的詳細信息和概述。

設置以下內容以開啟 Xwayland 的使用:

~/.config/weston.ini
[core]
xwayland=true
注意: 如果尚未配置 X,則可能需要配置鍵盤映射: Xorg中的鍵盤配置

高 DPI 顯示器[編輯 | 編輯原始碼]

對於 RetinaHiDPI 的顯示器, 使用:

~/.config/weston.ini
[output]
name=...
scale=2

Weston 字體[編輯 | 編輯原始碼]

Weston 使用默認的無襯線字體作為窗口標題欄、時鐘等。有關如何更改此字體的説明,請參見 字體配置#設置默認和後備字體

Systemd啟動[編輯 | 編輯原始碼]

weston雖沒法作為systemd系統服務啟動,但可通過systemd用户服務進行啟動,我們先創建 weston 的服務和 socket 單元

systemd用户服務啟動[編輯 | 編輯原始碼]

創建用户級weston套節字(socket) 單元,用於監聽圖形應用

提示:若您沒有 /etc/systemd/user/ 目錄的權限,也可在 $HOME/.config/systemd/user 目錄下進行創建,兩者使用效果相同
/etc/systemd/user/weston.socket
[Unit]
Description=Weston, a Wayland compositor
Documentation=man:weston(1) man:weston.ini(5)
Documentation=https://wayland.freedesktop.org/

[Socket]
ListenStream=%t/wayland-0

創建用户級weston服務(service)單元

/etc/systemd/user/weston.service
[Unit]
Description=Weston, a Wayland compositor, as a user service
Documentation=man:weston(1) man:weston.ini(5)
Documentation=https://wayland.freedesktop.org/

# 使用 systemd 套接字激活
Requires=weston.socket
After=weston.socket

# 由于我们是图形会话的一部分,因此请确保我们之前已启动
Before=graphical-session.target

[Service]
Type=notify
TimeoutStartSec=60
WatchdogSec=20
# 日志默认输出到journal
#StandardOutput=journal
StandardError=journal
# 确保已创建最少配置 ~/.config/weston.ini
ExecStart=/usr/bin/weston --modules=systemd-notify.so

[Install]
WantedBy=graphical-session.target

創建完畢後重新加載 systemd --user daemon-reload ,然後在使用 systemd --user start weston.service 啟動weston

以上的使用需要我們提前登錄到系統,並手動運行,若想實現自動啟動請參考下面步驟。

systemd系統會話管理[編輯 | 編輯原始碼]

一些場合下,我們希望在系統引導後自動啟動weston,當然也支持ssh遠程登錄後手動啟動weston,如您不想使用第三方登錄管理器,也可使用systemd服務單元來完成該操作,下面使用sysemd服務來創建用户會話

注意: 訪問/etc/systemd/system/要使用root權限,普通用户無法創建
/etc/systemd/system/weston-autologin.service
[Unit]
Description=Weston graphical session

# 确保我们在允许登录后启动。
After=systemd-user-sessions.service

# 如果需要,可以将其作为图形会话的一部分。
#Before=graphical.target

# 不是不需,但以防万一。
#ConditionPathExists=/dev/tty7

[Service]
Type=simple
Environment=XDG_SESSION_TYPE=wayland
ExecStart=/usr/bin/systemctl --wait --user start weston-session.target

# 要运行会话的用户。需要依据实际用户修改!
User=user
Group=user

# 为 Weston 要求的用户设置完整的用户会话。
PAMName=login

# 需要一个虚拟终端。
TTYPath=/dev/tty7
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes

# 如果不控制 tty,则无法启动。
StandardInput=tty-fail

# 日志输出默认为journal
#StandardOutput=journal
StandardError=journal

# 使用 utmp 记录此用户,让它显示命令 'w' 和 'who'
UtmpIdentifier=tty7
UtmpMode=user

[Install]
WantedBy=graphical.target

請確保 UserGroup 條目是使用有效的用户。同時還需創一個weston-session.target的用户target

/etc/systemd/user/weston-session.target
[Unit]
Description=Weston session

BindsTo=weston-session.target
Before=weston-session.target

通知系統重新加載配置

 $ sudo systemd damon-reload
 $ systemd damon-reload --user

最後確保您的默認target使用的是graphical

 $ sudo systemctl set-default graphical.target
 $ systemctl --user set-default graphical-session.target

提示與技巧[編輯 | 編輯原始碼]

錄像錄製[編輯 | 編輯原始碼]

Weston 具有內置的截屏和視頻錄製功能,可以通過按 Super+r 組合鍵來啟動和停止。截屏視頻保存到 Weston 當前工作目錄中的文件 capture.wcap 中。WCAP 格式是 Weston 特有的無損視頻格式,它只記錄幀數的差異。為了能夠播放錄製的截屏視頻,需要將WCAP文件轉換為媒體播放器可以理解的格式。首先,將捕獲轉換為 YUV 像素格式:

$ wcap-decode --yuv4mpeg2 capture.wcap > capture.y4m

然後,可以使用 FFmpegx264 將 YUV 文件轉碼為其他格式(有關詳細信息,請參閱 x264 -h)。

窗口切換[編輯 | 編輯原始碼]

要切換帶有 Super+Space 而不是 Super+Tab 的窗口,請在 desktop-shell/shell.c 中將 KEY_TAB 更改為 KEY_SPACE,然後重新編譯 weston

觸摸屏幕映射[編輯 | 編輯原始碼]

觸摸顯示映射可以通過使用 udev 規則來實現。就像 WL_SEATID_SEAT 設備環境變量將設備綁定到指定的席位一樣,WL_OUTPUT 變量可用於將設備綁定到相應的輸出。此變量應與顯示器名稱匹配。有關顯示器命名約定的説明,請參見 #顯示器

參考[編輯 | 編輯原始碼]