Hyprland是一个基于Wayland的窗口管理器,本文档基于Archlinux,简单介绍了Hyprland的常用软件与配置。
安装
序号 | 软件 | 功能 |
---|---|---|
01 | hyprland | Wayland混成器 |
02 | waybar | 状态栏 |
03 | otf-font-awesome | Waybar图标字体 |
04 | wqy-zenhei | Waybar时钟组件日历中文字体 |
05 | wofi | 启动菜单 |
06 | mako | 通知守护进程 |
07 | hyprpaper | 桌面壁纸 |
08 | hyprlock | 锁屏 |
09 | nwg-bar | 电源控制 |
10 | cliphist | 剪贴板 |
11 | hyprshot | 截图 |
sudo pacman -S hyprland waybar otf-font-awesome wqy-zenhei wofi mako hyprpaper hyprlock nwg-bar cliphist
yay -S hyprshot
Hyprland
初始化Hyprland配置目录与文件:
mkdir -p ~/.config/hypr/
cp /usr/share/hypr/hyprland.conf ~/.config/hypr
编辑Hyprland配置:
#替换Hyprland配置
sed -i \
-e 's/monitor=,preferred,auto,auto/monitor=,preferred,auto,auto,mirror,HDMI-A-1/' \
-e 's/gaps_in = 5/gaps_in = 4/' \
-e 's/gaps_out = 20/gaps_out = 0/' \
-e 's/border_size = 2/border_size = 0/' \
-e '/$mainMod, Q/d' \
-e '/$mainMod, C/d' \
-e '/$mainMod, E/d' \
-e '/$mainMod, V/d' \
-e '/$mainMod, R/d' \
~/.config/hypr/hyprland.conf
#新增Hyprland配置
cat >> ~/.config/hypr/hyprland.conf << \EOF
exec-once = waybar # 状态栏
exec-once = hyprpaper # 桌面壁纸
exec-once = nm-applet & # 网络管理器托盘
exec-once = fcitx5 # 输入法
exec-once = wl-paste --type text --watch cliphist store # 剪贴板(文本)
exec-once = wl-paste --type image --watch cliphist store # 剪贴板(图片)
exec-once = xfce4-terminal & microsoft-edge-stable & code & thunderbird & dingtalk # 日常应用
$mainMod = SUPER
bind = $mainMod, Q, killactive, # 关闭窗口
bind = $mainMod, F, togglefloating,
bind = $mainMod, RETURN, exec, xfce4-terminal # 终端模拟器
bind = $mainMod, E, exec, thunar # 文件管理器
bind = $mainMod, SPACE, exec, wofi --show drun --no-actions --allow-image --hide-scrol --width 400 # 启动菜单
bind = $mainMod, L, exec, hyprlock # 锁屏
bind = $mainMod, ESCAPE, exec, nwg-bar # 电源控制
bind = $mainMod, V, exec, cliphist list | wofi --dmenu | cliphist decode | wl-copy # 剪贴板
bind = $mainMod SHIFT, A , exec, hyprshot -m region # 截图
bind = ALT, Tab, exec, ${HOME}/.config/hypr/switch_windows.sh # 切换窗口
# 定义工作区属性
workspace = 1, defaultName:Terminal
workspace = 2, defaultName:Web
workspace = 3, defaultName:Code
workspace = 4, defaultName:Chat
workspace = 5, defaultName:Mail
workspace = 6, defaultName:Cloud
# 在指定工作区打开应用
windowrule = workspace 1, class:^(xfce4-terminal)$
windowrule = workspace 2, class:^(Microsoft-edge)$
windowrule = workspace 2, class:^(microsoft-edge)$
windowrule = workspace 2, class:^(Google-chrome)$
windowrule = workspace 2, class:^(google-chrome)$
windowrule = workspace 2, class:^(Chromium)$
windowrule = workspace 2, class:^(chromium)$
windowrule = workspace 2, class:^(firefox)$
windowrule = workspace 3, class:^(Code)$
windowrule = workspace 3, class:^(code)$
windowrule = workspace 3, class:^(jetbrains-idea-ce)$
windowrule = workspace 4, class:^(com.alibabainc.dingtalk)$
windowrule = workspace 4, class:^(wechat)$
windowrule = workspace 5, class:^(thunderbird)$
windowrule = workspace 6, class:^(VirtualBox Manager)$
windowrule = workspace 6, class:^(VirtualBox Machine)$
EOF
编辑切换窗口脚本(参见hypyland实现alt + tab切换到任意工作区的窗口):
cat > ~/.config/hypr/switch_windows.sh << \EOF
#!/usr/bin/env bash
NAME=`hyprctl clients -j | jq -r '.[] | select(.title != "") | .title' | wofi -dmenu`
WINDOW=`hyprctl clients -j | jq -r ".[] | select(.title == \"${NAME}\") | .address"`
hyprctl dispatch focuswindow address:${WINDOW}
EOF
chmod +x ~/.config/hypr/switch_windows.sh
状态栏Waybar
初始化Waybar配置目录:
mkdir -p ~/.config/waybar/
编辑Waybar配置:
cat > ~/.config/waybar/config.jsonc << EOF
{
"layer": "top",
"modules-left": [
"hyprland/window"
],
"modules-center": [
"hyprland/workspaces"
],
"modules-right": [
"tray",
"battery",
"pulseaudio",
"clock"
],
"hyprland/window": {
"icon": true,
"max-length": 50
},
"hyprland/workspaces": {
"all-outputs": true,
"move-to-monitor": true,
"format": "{id} {icon} ",
"format-icons": {
"Terminal": "",
"Web": "",
"Code": "",
"Chat": "",
"Mail": "",
"Cloud": "",
"default": "",
"empty": ""
}
},
"tray": {
"icon-size": 20,
"spacing": 8
},
"battery": {
"format": "{capacity}% {icon}",
"format-icons": [
"",
"",
"",
"",
""
]
},
"pulseaudio": {
"format": "{volume}% {icon}",
"format-bluetooth": "{volume}% {icon}",
"format-muted": "",
"format-icons": {
"headphone": "",
"default": [
"",
""
]
},
"scroll-step": 1,
"on-click": "pavucontrol",
"ignored-sinks": [
"Easy Effects Sink"
]
},
"clock": {
"timezone": "Asia/Chongqing",
"format-alt": "{:%Y-%m-%d}",
"tooltip-format": "\n<span size='9pt' font='WenQuanYi Zen Hei Mono'>{calendar}</span>",
"calendar": {
"weeks-pos": "right",
"format": {
"months": "<span color='#ffead3'><b>{}</b></span>",
"days": "<span color='#ecc6d9'><b>{}</b></span>",
"weeks": "<span color='#99ffdd'><b>W{}</b></span>",
"weekdays": "<span color='#ffcc66'><b>{}</b></span>",
"today": "<span color='#ff6699'><b><u>{}</u></b></span>"
}
}
}
}
EOF
初始化Waybar样式文件:
cp /etc/xdg/waybar/style.css ~/.config/waybar/
编辑Waybar样式:
cat >> ~/.config/waybar/style.css << EOF
* {
font-family: 'Noto Sans CJK SC', 'Font Awesome 6 Free';
font-size: 13px;
}
#workspaces button.active {
background-color: #64727D;
box-shadow: inset 0 -3px #ffffff;
}
#tray {
margin: 0 0 4 0 ;
border-radius: 4;
background-color: rgba(0, 0, 0, 0);
}
#battery {
margin: 0 0 4 0 ;
border-radius: 4;
background-color: rgba(0, 0, 0, 0);
color: #ffffff;
}
#battery:hover {
background-color: rgba(0, 0, 0, 0.4);
}
#battery.charging, #battery.plugged {
background-color: rgba(38,166,91,0.4);
color: #ffffff;
}
#pulseaudio {
margin: 0 0 4 0 ;
border-radius: 4;
background-color: rgba(0, 0, 0, 0);
color: #ffffff;
}
#pulseaudio:hover {
background-color: rgba(0, 0, 0, 0.4);
}
#pulseaudio.muted {
background-color: rgb(60,60,60);
color: #666666;
}
#clock {
margin: 0 0 4 0 ;
border-radius: 4;
background-color: rgba(0, 0, 0, 0);
}
#clock:hover {
background-color: rgba(0, 0, 0, 0.4);
}
/*
#pulseaudio:hover
#clock
#battery
#battery.charging, #battery.plugged
#pulseaudio
#pulseaudio.muted
#tray
*/
EOF
启动菜单Wofi
初始化Wofi配置目录:
mkdir -p ~/.config/wofi/
编辑Wofi样式:
cat > ~/.config/wofi/style.css << EOF
/**
window
└── outer-box
├── input
└── scroll
└── inner-box
└── text
*/
window {
background-color: rgba(0, 0, 0, 0);
}
#outer-box {
background-color: rgba(0, 0, 0, 1);
border-radius: 20px;
}
#input {
margin: 20px;
padding: 10px;
}
#scroll {
margin: 0 20px;
}
#inner-box {
}
#text {
margin: 10px;
}
EOF
通知守护进程Mako
初始化Mako配置目录:
mkdir -p ~/.config/mako/
编辑Mako配置:
cat > ~/.config/mako/config << EOF
sort=-time
layer=overlay
background-color=#2e34407f
width=400
height=600
border-size=1
border-color=#99c0d0
border-radius=8
icons=1
max-icon-size=64
default-timeout=5000
ignore-timeout=0
font="Noto Sans CJK SC" 10
margin=8
padding=8
[urgency=low]
border-color=#cccccc
[urgency=normal]
border-color=#99c0d0
[urgency=critical]
border-color=#bf616a
EOF
验证配置:
notify-send Hello
桌面壁纸Hyprpaper
编辑Hyprpaper配置:
cat > ~/.config/hypr/hyprpaper.conf << EOF
preload = /usr/share/hypr/wall0.png
wallpaper = , /usr/share/hypr/wall0.png
EOF
锁屏Hyprlock
编辑Hyprlock配置:
cat > ~/.config/hypr/hyprlock.conf << \EOF
general {
hide_cursor = true
}
background {
path = /usr/share/hypr/wall1.png
color = rgba(25, 20, 20, 1.0)
}
input-field {
size = 300, 50
font_color = rgb(10, 10, 10)
placeholder_text = 请输入密码
fail_text = 密码验证失败
}
label {
text = $TIME
font_size = 65
position = 0, 100
}
EOF
电源控制nwg-bar
初始化Nwg-bar配置目录:
mkdir -p ~/.config/nwg-bar/
编辑Nwg-bar配置:
cat > ~/.config/nwg-bar/bar.json << EOF
[
{
"label": "Lock",
"exec": "hyprlock",
"icon": "/usr/share/nwg-bar/images/system-lock-screen.svg"
},
{
"label": "Logout",
"exec": "hyprctl dispatch exit",
"icon": "/usr/share/nwg-bar/images/system-log-out.svg"
},
{
"label": "Reboot",
"exec": "systemctl reboot",
"icon": "/usr/share/nwg-bar/images/system-reboot.svg"
},
{
"label": "Shutdown",
"exec": "systemctl -i poweroff",
"icon": "/usr/share/nwg-bar/images/system-shutdown.svg"
}
]
EOF
其它
(1)配置部分软件以原生Wayland启动
# Chrome
echo "--ozone-platform-hint=auto" > ~/.config/google-chrome-flags.conf
# Chromium
echo "--ozone-platform-hint=auto" > ~/.config/chromium-flags.conf
# Edge
echo "--ozone-platform-hint=auto --enable-wayland-ime" > ~/.config/microsoft-edge-stable-flags.conf
# VSCode
echo "--ozone-platform-hint=auto --enable-wayland-ime" > ~/.config/code-flags.conf
# Typora
echo "--ozone-platform-hint=auto --enable-wayland-ime" > ~/.config/typora-flags.conf
参考链接