Hyprland
Hyprland 是一个基于 wlroots包 且使用C++编写的平铺式 Wayland合成器。 Hyprland值得注意的功能包括动态平铺、选项卡窗口、整洁可读的C++代码库,和提供窗口动画的自定义渲染器,窗口圆角,以及透明窗口上的Dual Kawase Blur。一般用法和配置在 Hyprland Wiki 中有详细文档介绍
安装[编辑 | 编辑源代码]
安装以下的其中一个
- hyprland包 - 最新上游版本
- hyprland-gitAUR - 主分支上的最新提交
Hyprland捆绑了自己的wlroots,它紧随着 wlroots-gitAUR 。这提高了稳定性,也避免了与其他基于wlroot 的合成器的依赖冲突
- NVIDIA GPU用户也应该在尝试启动Hyprland之前确保遵守上游的NVIDIA页面Hyprland Wiki。如果不这么做,可能会导致很多错误,包括可能无法登录、窗口闪烁和CPU使用率较高
- Hyprland不支持使用NVIDIA GPU,很多用户成功了,但如果一些东西坏了,那你只能靠你自己了
配置[编辑 | 编辑源代码]
配置是通过一个配置文件,hyprland.conf
完成的,尽管它支持将配置拆分为多个文件并将它们包含到hyprland.conf
中。默认的配置文件在 /usr/share/hyprland/hyprland.conf
,在第一次登录后,为~/.config/hypr/hyprland.conf
。
hyprland.conf
包括配置设备(键盘、鼠标、触控板、显示器)的指令,以及动画、装饰、布局等设置。你可以设置按键绑定、窗口规则以及在重新加载配置时执行命令(一次或者每次)
每次更新文件时,配置都会自动重新加载。你可以使用 hyprctl reload
来重载以获得相同的效果。对于某些设置(尤其是输入设置),你可能需要重启你的Hyprland回话。
设置也可以使用 hyprctl 动态更改设置,但是这些设置不会保存
键盘[编辑 | 编辑源代码]
按键映射[编辑 | 编辑源代码]
Hyprland默认使用 US Qwerty
键盘布局,你可以使用以下配置来配置它
~/.config/hypr/hyprland.conf
# German Colemark layout input { ... kb_layout = de kb_variant = colemark ... }
查看 Hyprland Wiki 以查看所有可用选项
US
布局的键盘则有必要更改按键映射
键入延迟和速率[编辑 | 编辑源代码]
虽然Xorg用户将习惯于在服务器级别定义此设置,在Wayland上,每个合成器都会自行处理:
~/.config/hypr/hyprland.conf
# Repeat rate and delay input { ... repeat_rate = 25 repeat_delay = 600 ... }
键盘亮度[编辑 | 编辑源代码]
在Hyprland中,可以借助 XF86KbdBrightness
来实现键盘亮度的调节功能。
安装 brightnessctl包 并添加以下内容:
~/.config/hypr/hyprland.conf
# Keyboard backlight bind = , xf86KbdBrightnessUp, exec, brightnessctl -d *::kbd_backlight set +33% bind = , xf86KbdBrightnessDown, exec, brightnessctl -d *::kbd_backlight set 33%-
此外,还可以设置更改时弹出通知。
媒体按键[编辑 | 编辑源代码]
在Hyprland上有可能通过使用 XF86Audio
键盘按键和一个外部像 pavucontrol包 或者 pamixer包 和 playerctl 的应用程序使用键盘媒体按键控制媒体(翻译可能不准确,请参照下面英语)
Using keyboard media controls in Hyprland is possible by making use of XF86Audio
keysyms and an external application like pavucontrol包 or pamixer包 and playerctl.
~/.config/hypr/hyprland.conf
# Volume and Media Control bind = , XF86AudioRaiseVolume, exec, pamixer -i 5 bind = , XF86AudioLowerVolume, exec, pamixer -d 5 bind = , XF86AudioMicMute, exec, pamixer --default-source -m bind = , XF86AudioMute, exec, pamixer -t bind = , XF86AudioPlay, exec, playerctl play-pause bind = , XF86AudioPause, exec, playerctl play-pause bind = , XF86AudioNext, exec, playerctl next bind = , XF86AudioPrev, exec, playerctl previous
当有更改时,也可以触发 屏幕通知
触摸板手势[编辑 | 编辑源代码]
作为 Wayland 合成器,Hyprland 完全支持触摸板手势即使它默认是禁用的。使用以下更改来启用它
~/.config/hypr/hyprland.conf
# Enable touchpad gestures gestures { workspace_swipe = true workspace_swipe_fingers = 3 }
查看 上游Wiki 来获取所有可用的选项
显示设置[编辑 | 编辑源代码]
屏幕共享[编辑 | 编辑源代码]
查看 屏幕共享
作为一个基于wlroots的合成器,Hyprland可以利用 xdg-desktop-portal-wlr包 通过 xdg-desktop-portal 在一系列应用程序中启用屏幕录制。
Hyprland 还维护 xdg-desktop-portal-hyprland包 ,一个wlr portal带有添加包括区域共享、窗口共享和图形选择器功能的分支。关于使用该工具在 Hyprland wiki 中有进一步的文档介绍
设置屏幕分辨率[编辑 | 编辑源代码]
Hyprland 将会尝试去自动检测你的屏幕分辨率。不过在某些情况下它将会失败并默认为故障保护,通常是在存在多个屏幕或你有混合笔记本电脑的情况下。如果屏幕下所有的东西都很大,那么你需要设置你默认的显示器和分辨率
首先使用 hyprctl 找到你的默认显示器:
$ hyprctl monitors
Monitor eDP-1 (ID 0): 1920x1080@144.003006 at 0x0 description: Chimei Innolux Corporation 0x153C (eDP-1) ...
然后在配置文件中添加你的显示器:
~/.config/hypr/hyprland.conf
... # Monitor details monitor=eDP-1,1920x1080@144,0x0,1 ...
0x0
是一个用于多屏幕设置和最终设置的位置偏移,1
是屏幕缩放倍数
亮度[编辑 | 编辑源代码]
安装 brightnessctl包 并添加以下内容:
~/.config/hypr/hyprland.conf
# Screen brightness bind = , XF86MonBrightnessUp, exec, brightnessctl s +5% bind = , XF86MonBrightnessDown, exec, brightnessctl s 5%-
此外,还可以设置更改时弹出通知。
使用[编辑 | 编辑源代码]
启动[编辑 | 编辑源代码]
目前推荐从TTY启动Hyprland[编辑 | 编辑源代码]
$ Hyprland
虽然从 显示管理器 中启动不是官方支持得,但是用户们报告成功在 GDM 、 SDDM 和其他的显示管理器中成功启动。hyprland包中包含一个显示管理器条目,且所有Hyprland AUR 包将会自动生成一个条目。
两种方法都提供相同的结果,加上或减去一些环境变量和服务。
自动登录[编辑 | 编辑源代码]
用户可以通过一个 显示管理器 或着在登录时采用 Xinit#Autostart X at login 中描述的方法进行自动登录
hyprctl 和 IPC[编辑 | 编辑源代码]
hyprctl 是一个命令行实用程序,随Hyprland一起安装,用于与显示服务器通信。它允许你向服务器发送命令(相当于配置文件中的命令,但语法略有不同)、设置关键词、发送询问和请求信息。请查看 完整文档
Hyprland also exposes 2 UNIX Sockets for controlling and getting information about Hyprland via code or command-line utilities. These sockets broadcast events on focus change (windows, workspaces, monitors), creation of windows/workspace, and so on.
Both hyprctl and the IPC sockets can be effectively used in scripts to control Hyprland for complex tasks.
exec versus exec-once[编辑 | 编辑源代码]
When starting applications it is important to use the correct type of dispatcher, using exec
incorrectly can result in applications being started multiple times taking up system resources and in the worst cases, causing a race condition that can crash your system.
hyprland.conf
each time a change to the file is saved: do not use exec
for everything.
In most cases you should use exec-once
to launch applications and daemons at boot, as this command will not run again with a reload, only use exec
if you are absolutely sure you want the command to run again on every reload.Setting environment variables[编辑 | 编辑源代码]
It is possible to set environment variables directly in hyprland.conf
through the env keyword, which has a different syntax than the env UNIX command used by shells.
The differences are explained on the upstream Wiki.
Tips and tricks[编辑 | 编辑源代码]
- For all below sections there will usually be more than one way of achieving a similar result, everything provided here is a basic example.
- For a comprehensive list of alternatives refer to List of applications, a Hyprland specific list can be found on the upstream Wiki.
文件管理器[编辑 | 编辑源代码]
在Hyprland环境下,如果需要图形化的文件管理功能,则需要一个兼容Wayland的外部应用程序。以 thunar包 为例,我们只需为其分配一个快捷键,操作如下:
~/.config/hypr/hyprland.conf
... bind = SUPER, E, exec, thunar ...
应用程序启动器[编辑 | 编辑源代码]
在Hyprland环境下,如果需要启动应用程序,则需要一个兼容Wayland的外部应用程序。以 wofi包 软件包为例,我们只需为其分配一个快捷键,操作如下:
~/.config/hypr/hyprland.conf
... bind = SUPER, F, exec, wofi ...
Idle[编辑 | 编辑源代码]
Hyprland requires a wayland-compatible external idle management daemon. The most common setup is swayidle包 and swaylock包. You can lock your screen manually using a bind as follows:
~/.config/hypr/hyprland.conf
... bind = SUPER, L, exec, swaylock -f -c 000000 ...
Automatic screen locking and suspend[编辑 | 编辑源代码]
Create the following script:
~/.config/hypr/scripts/sleep.sh
swayidle -w timeout 300 'swaylock -f -c 000000' \ timeout 600 'systemctl suspend' \ before-sleep 'swaylock -f -c 000000' &
- The script must be executable.
Then call it:
~/.config/hypr/hyprland.conf
... exec-once = ~/.config/hypr/scripts/sleep.sh ...
Turning off the screen using DPMS after a timeout period[编辑 | 编辑源代码]
Hyprland has a built in dispatcher to handle DPMS requests however using it as a direct keybind is not recommended, doing so will result in you not being able to turn the screen back on and will require you to reboot.
Edit the script from above and change it to read:
~/.config/hypr/scripts/sleep.sh
swayidle -w timeout 300 'swaylock -f -c 000000' \ timeout 600 'hyprctl dispatch dpms off' \ resume 'hyprctl dispatch dpms on' \ timeout 900 'systemctl suspend' \ before-sleep 'swaylock -f -c 000000' &
hyprctl dispatch dpms on
command must come directly after the hyprctl dispatch dpms off
command in the script for it to function correctly, as the resume command is linked to the previous timeout used.Stop DPMS while using applications[编辑 | 编辑源代码]
The above setup will result in your monitor powering off while you are doing things like playing a game, watching a video or listening to music where you might not touch the system for longer than the timeout period.
To fix this you can either use Hyprlands built in Window Rules V2 function which has a idleinhibit
rule or you can install one of either idlehack-gitAUR or sway-audio-idle-inhibit-gitAUR. The former uses D-Bus to prevent Swayidle requests whenever Firefox or Chromium are playing audio/video. The latter prevents Swayidle requests whenever any application is playing audio.
For programs that use org.freedesktop.ScreenSaver.inhibit
to pause the screensaver, you can install wscreensaver-bridge-gitAUR to implement it for Hyprland (or any Wayland compositor that support the idle-inhibit
protocol).
状态栏[编辑 | 编辑源代码]
在Hyprland环境下,如果需要状态栏,则需要一个兼容Wayland的外部应用程序。以 waybar包软件包为例,操作如下:
~/.config/hypr/hyprland.conf
... exec-once = waybar -c ~/.config/waybar/waybar.conf ...
Workspace overview[编辑 | 编辑源代码]
waybar包 has a built in, fully customisable module that supports Hyprland workspace switching natively.
See the waybar Wiki [1] for details.
Polkit authentication[编辑 | 编辑源代码]
Polkit authentication requires the use of an external authentication agent. Hyprland recommends using polkit-kde-agent包 but any should work.
Call it as follows:
~/.config/hypr/hyprland.conf
... exec-once = /usr/lib/polkit-kde-authentication-agent-1 ...
桌面壁纸[编辑 | 编辑源代码]
在Hyprland环境下,如果需要管理桌面壁纸,则需要一个兼容Wayland的外部应用程序。以 swwwAUR 软件包为例,操作如下:
~/.config/hypr/hyprland.conf
... exec-once = swww init exec-once = swww img path/to/image ...
Using a script to change wallpaper every X minutes[编辑 | 编辑源代码]
Create the following script and make sure its executable:
~/.config/hypr/scripts/swww-random
#!/bin/bash # This script will randomly go through the files of a directory, setting it # up as the wallpaper at regular intervals # # NOTE: this script uses bash (not POSIX shell) for the RANDOM variable if [[ $# -lt 1 ]] || [[ ! -d $1 ]]; then echo "Usage: $0 <dir containing images>" exit 1 fi # Edit below to control the images transition export SWWW_TRANSITION_FPS=144 export SWWW_TRANSITION_STEP=2 export SWWW_TRANSITION_TYPE=random # This controls (in seconds) when to switch to the next image INTERVAL=300 while true; do find "$1" \ | while read -r img; do echo "$((RANDOM % 1000)):$img" done \ | sort -n | cut -d':' -f2- \ | while read -r img; do swww img "$img" sleep $INTERVAL done done
Next create a new folder to store background images, something like ~/.config/hypr/backgrounds
should work fine, and populate it with any images you want.
Finally call the script:
~/.config/hypr/hyprland.conf
... exec-once = swww init exec-once = ~/.config/hypr/scripts/swww-random ~/.config/hypr/background ...
屏幕通知[编辑 | 编辑源代码]
屏幕上对亮度和音量调整等操作显示通知的功能可以借助外部的通知服务程序来实现。然而,深入探讨这一主题超出了本页面的说明范围。这里我们将会聚焦于安装 mako包 的操作,现在请继续进行 安装。
See Desktop notifications for further instructions and Desktop notifications#Standalone for a list of alternatives.
- All scripts in this section must be executable.
Mako[编辑 | 编辑源代码]
Mako is a lightweight notification daemon, you can read mako(5) for details. Its configuration file is ~/.config/mako/config
, icons used for OSD are stored at ~/.config/mako/icons/
and should be in PNG format.
For the rest of this section all the images used by the scripts are available from this GitHub folder.
Keyboard backlight notifications[编辑 | 编辑源代码]
First create the following script:
~/.config/hypr/scripts/kbbacklight
#!/usr/bin/env bash iDIR="$HOME/.config/mako/icons" # Get brightness get_backlight() { LIGHT="$(cat /sys/class/leds/*::kbd_backlight/brightness)" echo "${LIGHT}" } # Get icons get_icon() { current="$(cat /sys/class/leds/*::kbd_backlight/brightness)" if [[ ("$current" -ge "0") && ("$current" -le "1") ]]; then icon="$iDIR/brightness-20.png" elif [[ ("$current" -ge "1") && ("$current" -le "2") ]]; then icon="$iDIR/brightness-60.png" elif [[ ("$current" -ge "2") && ("$current" -le "3") ]]; then icon="$iDIR/brightness-100.png" fi } # Notify notify_user() { notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Keyboard Brightness : $(brightnessctl -d '*::kbd_backlight' g)" } # Increase brightness inc_backlight() { brightnessctl -d *::kbd_backlight set 33%+ && get_icon && notify_user } # Decrease brightness dec_backlight() { brightnessctl -d *::kbd_backlight set 33%- && get_icon && notify_user } # Zero brightness zero_backlight() { brightnessctl -d *::kbd_backlight s 0% } # Full brightness full_backlight() { brightnessctl -d *::kbd_backlight s 100% } # Execute accordingly if [[ "$1" == "--get" ]]; then brightnessctl -d '*::kbd_backlight' g elif [[ "$1" == "--inc" ]]; then inc_backlight elif [[ "$1" == "--dec" ]]; then dec_backlight elif [[ "$1" == "--zero" ]]; then zero_backlight elif [[ "$1" == "--full" ]]; then full_backlight else get_backlight fi
Then add the following (or edit any existing binds):
~/.config/hypr/hyprland.conf
# Keyboard brightness bind = SUPER, F2, exec, ~/.config/hypr/scripts/kbbacklight --dec bind = SUPER, F3, exec, ~/.config/hypr/scripts/kbbacklight --inc
Media key notifications[编辑 | 编辑源代码]
First create the following script:
~/.config/hypr/scripts/volume
#!/usr/bin/env bash iDIR="$HOME/.config/mako/icons" # Get Volume get_volume() { volume=$(pamixer --get-volume) echo "$volume" } # Get icons get_icon() { current=$(get_volume) if [[ "$current" -eq "0" ]]; then echo "$iDIR/volume-mute.png" elif [[ ("$current" -ge "0") && ("$current" -le "30") ]]; then echo "$iDIR/volume-low.png" elif [[ ("$current" -ge "30") && ("$current" -le "60") ]]; then echo "$iDIR/volume-mid.png" elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then echo "$iDIR/volume-high.png" fi } # Notify notify_user() { notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$(get_icon)" "Volume : $(get_volume) %" } # Increase Volume inc_volume() { pamixer -i 5 && notify_user } # Decrease Volume dec_volume() { pamixer -d 5 && notify_user } # Toggle Mute toggle_mute() { if [ "$(pamixer --get-mute)" == "false" ]; then pamixer -m && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/volume-mute.png" "Volume Switched OFF" elif [ "$(pamixer --get-mute)" == "true" ]; then pamixer -u && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$(get_icon)" "Volume Switched ON" fi } # Toggle Mic toggle_mic() { if [ "$(pamixer --default-source --get-mute)" == "false" ]; then pamixer --default-source -m && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone-mute.png" "Microphone Switched OFF" elif [ "$(pamixer --default-source --get-mute)" == "true" ]; then pamixer -u --default-source u && notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$iDIR/microphone.png" "Microphone Switched ON" fi } # Get icons get_mic_icon() { current=$(pamixer --default-source --get-volume) if [[ "$current" -eq "0" ]]; then echo "$iDIR/microphone.png" elif [[ ("$current" -ge "0") && ("$current" -le "30") ]]; then echo "$iDIR/microphone.png" elif [[ ("$current" -ge "30") && ("$current" -le "60") ]]; then echo "$iDIR/microphone.png" elif [[ ("$current" -ge "60") && ("$current" -le "100") ]]; then echo "$iDIR/microphone.png" fi } # Notify notify_mic_user() { notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$(get_mic_icon)" "Mic-Level : $(pamixer --default-source --get-volume) %" } # Increase MIC Volume inc_mic_volume() { pamixer --default-source -i 5 && notify_mic_user } # Decrease MIC Volume dec_mic_volume() { pamixer --default-source -d 5 && notify_mic_user } # Execute accordingly if [[ "$1" == "--get" ]]; then get_volume elif [[ "$1" == "--inc" ]]; then inc_volume elif [[ "$1" == "--dec" ]]; then dec_volume elif [[ "$1" == "--toggle" ]]; then toggle_mute elif [[ "$1" == "--toggle-mic" ]]; then toggle_mic elif [[ "$1" == "--get-icon" ]]; then get_icon elif [[ "$1" == "--get-mic-icon" ]]; then get_mic_icon elif [[ "$1" == "--mic-inc" ]]; then inc_mic_volume elif [[ "$1" == "--mic-dec" ]]; then dec_mic_volume else get_volume fi
Then add the following (or edit any existing binds):
~/.config/hypr/hyprland.conf
# Volume bind = , XF86AudioRaiseVolume, exec, ~/.config/hypr/scripts/volume --inc bind = , XF86AudioLowerVolume, exec, ~/.config/hypr/scripts/volume --dec bind = , XF86AudioMicMute, exec, ~/.config/hypr/scripts/volume --toggle-mic bind = , XF86AudioMute, exec, ~/.config/hypr/scripts/volume --toggle
Screen backlight notifications[编辑 | 编辑源代码]
First create the following script:
~/.config/hypr/scripts/backlight
!/usr/bin/env bash iDIR="$HOME/.config/mako/icons" # Get brightness get_backlight() { LIGHT=$(printf "%.0f\n" $(brightnessctl g)) echo "${LIGHT}" } # Get icons get_icon() { current="$(get_backlight)" if [[ ("$current" -ge "0") && ("$current" -le "19200") ]]; then icon="$iDIR/brightness-20.png" elif [[ ("$current" -ge "19200") && ("$current" -le "38400") ]]; then icon="$iDIR/brightness-40.png" elif [[ ("$current" -ge "38400") && ("$current" -le "57600") ]]; then icon="$iDIR/brightness-60.png" elif [[ ("$current" -ge "57600") && ("$current" -le "76800") ]]; then icon="$iDIR/brightness-80.png" elif [[ ("$current" -ge "76800") && ("$current" -le "96000") ]]; then icon="$iDIR/brightness-100.png" fi } # Notify notify_user() { notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "Brightness : $(get_backlight)" } # Increase brightness inc_backlight() { brightnessctl s +5% && get_icon && notify_user } # Decrease brightness dec_backlight() { brightnessctl s 5%- && get_icon && notify_user } # Execute accordingly if [[ "$1" == "--get" ]]; then get_backlight elif [[ "$1" == "--inc" ]]; then inc_backlight elif [[ "$1" == "--dec" ]]; then dec_backlight else get_backlight fi
Then add the following (or edit any existing binds):
~/.config/hypr/hyprland.conf
# Screen brightness bind = , XF86MonBrightnessUp, exec, ~/.config/hypr/scripts/backlight --inc bind = , XF86MonBrightnessDown, exec, ~/.config/hypr/scripts/backlight --dec
Keyboard language notifications[编辑 | 编辑源代码]
To run this script, you need a command-line JSON processor gojqAUR.
First create the following script:
~/.config/hypr/scripts/lang
#!/usr/bin/env bash icon="$HOME/.config/mako/icons/language.png" # Get language get_lang() { lang=$(hyprctl devices -j | gojq -r '.keyboards[] | select(.name == "at-translated-set-2-keyboard") | .active_keymap' | cut -c 1-2 | tr 'A-Z' 'a-z') case $lang in en) lang="English language" ;; ru) lang="Русский язык" ;; uk) lang="Українська мова" ;; esac echo $lang } # Notify notify-send -h string:x-canonical-private-synchronous:sys-notify -u low -i "$icon" "$(get_lang)"
Then add the following (or edit any existing binds):
~/.config/hypr/hyprland.conf
device:at-translated-set-2-keyboard { kb_layout = us,ru,ua kb_variant = lang kb_options = grp:win_space_toggle } # Language bind = SUPER, SPACE, exec, ~/.config/hypr/scripts/lang
Power control[编辑 | 编辑源代码]
Hyprland requires a wayland-compatible external application for power control. Using nwg-barAUR as an example, we simply need to bind it as follows:
~/.config/hypr/hyprland.conf
... bind = SUPER, ESCAPE, exec, nwg-bar ...
Clipboard[编辑 | 编辑源代码]
Wayland clipboard behaviour deletes data when closing the application we copied it from. Other desktop environments work around this by using dedicated clipboard managers and on Hyprland there are multiple compatible choices. See the upstream Wiki for more information.
This section will cover cliphist包 as it supports copying images as well as text, start by adding the following:
~/.config/hypr/hyprland.conf
... exec-once = wl-paste --type text --watch cliphist store exec-once = wl-paste --type image --watch cliphist store ...
Then create a bind to call the history in your chosen application launcher:
~/.config/hypr/hyprland.conf
... bind = SUPER, V, exec, cliphist list | wofi --dmenu | cliphist decode | wl-copy ...
Now pressing Super+v
will open up a wofi
window with a clipboard history list.
Troubleshooting[编辑 | 编辑源代码]
xdg-desktop-portal-hyprland is using a lot of CPU[编辑 | 编辑源代码]
This is a known bug [2] that should be resolved in the latest Git build. You can work around it by calling the nuclear script from the Hyprland wiki, as outlined here, in your hyprland.conf
file.