Arch KDE -> Hyprland
2024-06-20 16:18:44

KDE 上 Wayland 后天天给我 crash, 就直接换 Hyprland 了

1. 安装

  1. 在 Arch KDE(或现有桌面) 下
  2. yay hyprwayland-scanner-git
  3. yay hyprwayland-git
  4. [Optional] 可以在 console 用 hyprland 进桌面, 但是基本什么都干不了, cmd 下的 hyprland 不会接收到我的 Super 按键事件

2. 配置

  1. 先别急着用 sddm 进 hyprland, 在 Arch KDE(或现有桌面)下
  2. 创建或更改 ~/.config/hypr/hyprland.conf, 例子 hyprwm/Hyprland, 可以直接复制覆盖
  3. 确认好基本的设置比如 Super key 是什么, terminal 有没有安装(默认是 kitty) 可能没有安装然后会导致开不了控制台基本就很难受
  4. 然后就可以进去边用边设

2.1 MONITORS

可以给显示器设置摆放位置和刷新率, 比如我放一个 AOC 在左边, 笔记本屏幕在右边

1
2
3
4
5
6
7
8
9
################
### MONITORS ###
################

# See https://wiki.hyprland.org/Configuring/Monitors/
monitor=,preferred,auto,1
# auto put AOC in left
monitor=desc:Chimei Innolux Corporation 0x15E8,1920x1080@60,1920x0,1
monitor=desc:AOC 27B2 0x0000CD6A,1920x1080@75,0x0,1

其中 monitor 的 description 可以在 hyprctl monitors 拿到. 尽量别设负数 position (虽然也能用), 会导致一些程序运行错误, 比如 hyprshot.

2.2 MY PROGRAMS

可以设 terminalkonsole

2.3 Autostart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
exec-once = $terminal
# notification
exec-once = dunst
# copy-paste manager
exec-once = wl-paste --type text --watch cliphist store #Stores only text data
exec-once = wl-paste --type image --watch cliphist store #Stores only image data
# save paste constent after application closed
exec-once = wl-clip-persist --clipboard both

# exec-once = nm-applet &
# KDE auth kit - auth popup
exec-once=/usr/lib/polkit-kde-authentication-agent-1
# status bar and background
exec-once = waybar -c ~/.config/waybar/waybar.conf & hyprpaper #& google-chrome-stable

# fcitx5 config
exec-once=fcitx5-remote -r
exec-once=fcitx5 -d --replace
exec-once=fcitx5-remote -r
  • wl-paste wl-clip-ersist waybar 等需要额外安装, 用 pacman 或 yay
  • wl-paste 可以用来管理复制的内容, 然后用快捷键比如 Super + V 看历史
  • fcitx 解决方法参考 hyprwm/Hyprland/discussions/421

2.4 INPUT

  • kb_options 可以用来设 compose key 比如 kb_options = compose:ralt
  • follow_mouse 用来选鼠标交互方式, 比如鼠标 1=hover(放上去就选中窗口) 或者 2=click(点击选中)
  • scroll_factor 设置滚动速度

2.4 KEYBINDINGSS

大部分都是默认

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# See https://wiki.hyprland.org/Configuring/Keywords/
$mainMod = SUPER # Sets "Windows" key as main modifier

# Example binds, see https://wiki.hyprland.org/Configuring/Binds/ for more
bind = $mainMod, Q, exec, $terminal
bind = $mainMod, C, killactive,
bind = $mainMod, M, exit,
bind = $mainMod, E, exec, $fileManager
bind = $mainMod, F, togglefloating,
bind = $mainMod, R, exec, $menu
# bind = $mainMod, P, pseudo, # dwindle
bind = $mainMod, P, exec, konsole -e " python"
bind = $mainMod, J, togglesplit, # dwindle

# Move focus with mainMod + arrow keys
bind = $mainMod, left, movefocus, l
bind = $mainMod, right, movefocus, r
bind = $mainMod, up, movefocus, u
bind = $mainMod, down, movefocus, d

# Switch workspaces with mainMod + [0-9]
bind = $mainMod, 1, workspace, 1
bind = $mainMod, 2, workspace, 2
bind = $mainMod, 3, workspace, 3
bind = $mainMod, 4, workspace, 4
bind = $mainMod, 5, workspace, 5
bind = $mainMod, 6, workspace, 6
bind = $mainMod, 7, workspace, 7
bind = $mainMod, 8, workspace, 8
bind = $mainMod, 9, workspace, 9
bind = $mainMod, 0, workspace, 10

# Move active window to a workspace with mainMod + SHIFT + [0-9]
bind = $mainMod SHIFT, 1, movetoworkspace, 1
bind = $mainMod SHIFT, 2, movetoworkspace, 2
bind = $mainMod SHIFT, 3, movetoworkspace, 3
bind = $mainMod SHIFT, 4, movetoworkspace, 4
bind = $mainMod SHIFT, 5, movetoworkspace, 5
bind = $mainMod SHIFT, 6, movetoworkspace, 6
bind = $mainMod SHIFT, 7, movetoworkspace, 7
bind = $mainMod SHIFT, 8, movetoworkspace, 8
bind = $mainMod SHIFT, 9, movetoworkspace, 9
bind = $mainMod SHIFT, 0, movetoworkspace, 10

# Example special workspace (scratchpad)
bind = $mainMod, S, togglespecialworkspace, magic
bind = $mainMod SHIFT, S, movetoworkspace, special:magic

bind = $mainMod, V, exec, cliphist list | wofi --dmenu | cliphist decode | wl-copy
# let chrome run in wayland
bind = $mainMod, G, exec, google-chrome-stable --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime

# Scroll through existing workspaces with mainMod + scroll
bind = $mainMod, mouse_down, workspace, e+1
bind = $mainMod, mouse_up, workspace, e-1

# Move/resize windows with mainMod + LMB/RMB and dragging
bindm = $mainMod, mouse:272, movewindow
bindm = $mainMod, mouse:273, resizewindow

# bind=,Print,exec,hyprshot -m region --clipboard-only
bind=,Print, exec, grimblast copy area
bind =, XF86AudioPlay, exec, playerctl play
bind =, XF86AudioPause, exec, playerctl pause
bind =, XF86AudioNext, exec, playerctl next
bind =, XF86AudioPrev, exec, playerctl previous
bind = , XF86AudioRaiseVolume, exec, volumectl -u up
bind = , XF86AudioLowerVolume, exec, volumectl -u down
# if you want to bind backlight control
# use acpi in /etc/acpi/handlers and /etc/acpi/events
# bind = , XF86MonBrightnessUp, exec, lightctl up
# bind = , XF86MonBrightnessDown, exec, lightctl down
bind = $mainMod, L, exec, hyprlock
  • bind bindl bindm 之类的大体上没有显著差别
  • hyprshot grimblast playerctl hyprlock 等要额外安装
  • Arch 没有 lightctl 可以用 acpi 代替, 参考 ejmastnak.com/tutorials/arch/backlight

2.5 Waybar - Status Bar

  1. 创建 ~/.config/waybar/waybar.conf
  2. Alexays/Waybar/wiki/Examples 找模板改, 我改的第三个, 配置如下

waybar.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// -*- mode: json -*-
// from https://github.com/cjbassi/config/blob/master/.config/waybar/config

{
"layer": "top",
"position": "top",

"modules-left": [
"hyprland/workspaces",
"custom/right-arrow-dark"
],
"modules-center": [
"custom/left-arrow-dark",
"clock#1",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"clock#2",
"custom/right-arrow-dark",
"custom/right-arrow-light",
"clock#3",
"custom/right-arrow-dark"
],
"modules-right": [
"custom/left-arrow-dark",
"wireplumber",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"memory",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"cpu",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"battery",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"disk",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"backlight",
"custom/left-arrow-light",
"custom/left-arrow-dark",
"tray"
],

"custom/left-arrow-dark": {
"format": "",
"tooltip": false
},
"custom/left-arrow-light": {
"format": "",
"tooltip": false
},
"custom/right-arrow-dark": {
"format": "",
"tooltip": false
},
"custom/right-arrow-light": {
"format": "",
"tooltip": false
},

"hyprland/workspaces": {
"disable-scroll": true,
"format": "{name}",
"on-click": "activate"
},

"clock#1": {
"format": "{:%a}",
"tooltip": false
},
"clock#2": {
"format": "{:%H:%M}",
"tooltip": false
},
"clock#3": {
"format": "{:%m-%d}",
"tooltip": false
},

"wireplumber": {
"format": "{icon} {volume:2}%",
"format-bluetooth": "{icon} {volume}%",
"format-muted": "MUTE",
"format-icons": {
"headphones": "",
"default": [
"",
""
]
},
"scroll-step": 5,
"on-click": "pamixer -t",
"on-click-right": "pavucontrol"
},
"memory": {
"interval": 5,
"format": "Mem {}%"
},
"cpu": {
"interval": 5,
"format": "CPU {usage:2}%"
},
"battery": {
"states": {
"good": 95,
"warning": 30,
"critical": 15
},
"format": "{icon} {capacity}%",
"format-icons": [
"",
"",
"",
"",
""
]
},
"disk": {
"interval": 5,
"format": "Disk {percentage_used:2}%",
"path": "/"
},
"backlight": {
"format": "\udb80\udcdf {percent}%",
"scroll-step": 5
},
"tray": {
"icon-size": 20
}
}

其中 pavucontrol pamixer 得另外装
style.css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
* {
font-size: 20px;
font-family: monospace;
}

window#waybar {
background: #292b2e;
color: #fdf6e3;
}

#custom-right-arrow-dark,
#custom-left-arrow-dark {
color: #1a1a1a;
}
#custom-right-arrow-light,
#custom-left-arrow-light {
color: #292b2e;
background: #1a1a1a;
}

#workspaces,
#clock.1,
#clock.2,
#clock.3,
#wireplumber,
#memory,
#cpu,
#battery,
#disk,
#backlight,
#tray {
background: #1a1a1a;
}

#workspaces button {
padding: 0 2px;
color: #fdf6e3;
}
#workspaces button.focused {
color: #268bd2;
}
#workspaces button:hover {
box-shadow: inherit;
text-shadow: inherit;
}
#workspaces button:hover {
background: #1a1a1a;
border: #1a1a1a;
padding: 0 3px;
}

#wireplumber {
color: #268bd2;
}
#memory {
color: #2aa198;
}
#cpu {
color: #6c71c4;
}
#battery {
color: #859900;
}
#disk {
color: #b58900;
}

#clock,
#wireplumber,
#memory,
#cpu,
#battery,
#disk,
#backlight{
padding: 0 10px;
}

放在 ~/.config/waybar 下然后 exec-once 里启动

2.6 Hyprlock - screen Locker

  1. 创建 ~/.config/hypr/hyprlock.conf
  2. 复制 wiki.hyprland.org/Hypr-Ecosystem/hyprlock 上 Widgets 下来, 比如
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    background {
    monitor =
    # path = /home/me/someImage.png # only png supported for now
    color = rgba(25, 20, 20, 1.0)

    # all these options are taken from hyprland, see https://wiki.hyprland.org/Configuring/Variables/#blur for explanations
    blur_passes = 0 # 0 disables blurring
    blur_size = 7
    noise = 0.0117
    contrast = 0.8916
    brightness = 0.8172
    vibrancy = 0.1696
    vibrancy_darkness = 0.0
    }
    input-field {
    monitor =
    size = 200, 50
    outline_thickness = 3
    dots_size = 0.33 # Scale of input-field height, 0.2 - 0.8
    dots_spacing = 0.15 # Scale of dots' absolute size, 0.0 - 1.0
    dots_center = false
    dots_rounding = -1 # -1 default circle, -2 follow input-field rounding
    outer_color = rgb(151515)
    inner_color = rgb(200, 200, 200)
    font_color = rgb(10, 10, 10)
    fade_on_empty = true
    fade_timeout = 1000 # Milliseconds before fade_on_empty is triggered.
    placeholder_text = <i>Input Password...</i> # Text rendered in the input box when it's empty.
    hide_input = false
    rounding = -1 # -1 means complete rounding (circle/oval)
    check_color = rgb(204, 136, 34)
    fail_color = rgb(204, 34, 34) # if authentication failed, changes outer_color and fail message color
    fail_text = <i>$FAIL <b>($ATTEMPTS)</b></i> # can be set to empty
    fail_transition = 300 # transition time in ms between normal outer_color and fail_color
    capslock_color = -1
    numlock_color = -1
    bothlock_color = -1 # when both locks are active. -1 means don't change outer color (same for above)
    invert_numlock = false # change color if numlock is off
    swap_font_color = false # see below

    position = 0, -20
    halign = center
    valign = center
    }
    label {
    monitor =
    text = cmd[update:1000] echo "<span foreground='blue'>$(date)</span> "
    text_align = center # center/right or any value for default left. multi-line text alignment inside label container
    color = rgba(200, 200, 200, 1.0)
    font_size = 25
    font_family = Noto Sans
    rotate = 0 # degrees, counter-clockwise

    position = 0, 80
    halign = center
    valign = center
    }

2.7 Electron on wayland

本节为了解决一些 electron 应用不能复制之类的问题

参考:

  1. 如果遇到 chromium / electron 无法复制 -> 可以开 xeyes 看看是不是跑在 X11 下, 要跑在 wayland 上就没问题.
  2. export ELECTRON_OZONE_PLATFORM_HINT=waylandexport QT_QPA_PLATFORM=wayland 让 electron 和 qt 程序跑在 wayland 上
  3. 如果遇到 fcitx5 无法在 chromium / elctron 在 wayland 上输入, 需要加参数 --enable-features=UseOzonePlatform --ozone-platform=wayland --enable-wayland-ime 在启动的时候, 比如 chrome 和 vscode

2.8 Screen sharing

本节为了解决不能分享屏幕或者录屏之类的问题

参考:

  1. 先按照文档1的安装 pipewirewireplumber , 然后按照文档2的安装 xdg-desktop-portal-hyprland(可以卸载 xdg-desktop-portal-wlr 如果有).
  2. 根据文档2把 exec-once=dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP 加进 hyprland.conf
  3. 找地方把文档1里的脚本
    1
    2
    3
    4
    5
    6
    7
    8
    #!/usr/bin/env bash
    sleep 1
    killall -e xdg-desktop-portal-hyprland
    killall -e xdg-desktop-portal-wlr
    killall xdg-desktop-portal
    /usr/lib/xdg-desktop-portal-hyprland &
    sleep 2
    /usr/lib/xdg-desktop-portal &
    写到某个地方并加入到 exec-once
  4. 然后重启, 到这里应该 obs 之类的就能用了, 如果要调试可以看参考中的最后一个 issue

2.9 打开文件 KDE 提示的弹窗

本节为了解决 KDE 提示的弹窗是空白或者他不能根据文件后缀打开

参考: https://www.lorenzobettini.it/2024/05/fixing-the-empty-open-with-in-dolphin-in-hyprland/

  1. 安装 sudo pacman -S archlinux-xdg-menu
  2. env = XDG_MENU_PREFIX,arch- 加到 hyprland.conf

2.10 Jetbrain IDEs in wayland

wayland 上跑 Jetbrain IDEs

参考:

  1. -Dawt.toolkit.name=WLToolkit 加到 help->custom VM options

3. 遇到的未解决的问题

  • Spotify 在另外一个不活跃的工作区可能会不刷新界面, 我就去用 ncspot
  • Jetbrain IDEs 可能在一些操作后, 比如 Ctrl shift L 格式化后失去指针(不会显示正在更改的光标也无法输入), 目测是格式化弹窗用 enter 进行格式化而不是鼠标触发, 我一般用 Super + C 弹出 IDE 的关闭确认弹窗然后取消就可以了
  • 复制不了超过一定大小(60+KB)的屏幕截图 cliphist, 还不知道什么问题 最新的 hyprland 解决了
Prev
2024-06-20 16:18:44