更多分享内容可访问我的个人博客
本文记录在 gentoo 上使用 sway 遇到的一些问题和解决方案。
键位设置
查看输入设备。
export SWAYSOCK=$(ls /run/user/*/sway-ipc* | head -n 1)
swaymsg -t get_inputs
查看键位设置。
man 7 xkeyboard-config
案例如下。可以使用设备类型,也可以使用设备名称。
input "type:keyboard" {
xkb_layout us
xkb_options ctrl:swap_lalt_lctl,caps:swapescape
}
input "1:1:AT_Translated_Set_2_keyboard" {
xkb_layout us
}
详见文档。
触控板设置
基本同上。案例如下。
input type:touchpad {
scroll_method two_finger
tap enabled
tap_button_map lrm
}
组件
可以在这里查看一些有用的组件。
输入法
fcitx5 可以在大部分应用上使用,而且也不会出现候选项框错位和无法显示的情况。部分应用,如 utools,依旧无法使用,这一点暂时无解。
安装以下包即可。其中x11-libs/xcb-imdkit
是关键,上面提到的两个问题基本上就是缺失这引起的。另外笔者在全局禁用了X
USE Flag,并启用了wayland
,同时为部分包启用了X
。这可能成为影响因素。
app-i18n/fcitx5
x11-libs/xcb-imdkit
app-i18n/fcitx5-chinese-addons
app-i18n/libime
app-i18n/fcitx5-qt
app-i18n/fcitx5-gtk
然后在~/.zprofile
加入以下内容。注意这是 zsh 启动时加载的文件,如果你使用的不是 zsh, 那么需要自行替换成对应的。另外也可以参考 Arch wiki 中的写法,使用.pam_envrionment
文件。
export GTK_IM_MODULE=fcitx5
export QT_IM_MODULE=fcitx5
export XMODIFIERS="@im=fcitx"
剪贴板
使用gui-apps/wl-clipboard
代替xclip
。但是部分软件,如utools
,无法自动检测剪贴板内容。
waybar 切换与自动隐藏
切换 waybar 可以使用以下脚本。
# toggle_bar.sh
haswaybar=$(ps aux)
haswaybar=$(echo -e $haswaybar | grep "waybar")
if [[ $haswaybar != "" ]]; then
killall waybar
else
waybar &
fi
注意killall waybar
足以,如果用网上的-SIGUSR1 '^waybar$'
的版本则 waybar 进程虽退出,但仍占据原有空间。
可以在 sway 的配置中设置快捷键调用该脚本。注意该脚本的路径不能含有waybar
,建议放在~/.config/sway
目录下。
waybar 的自动隐藏功能目前已经实现,但该版本的 sway 和 waybar 暂无 release,需要自己编译。具体可见antyhrabia 的回答。
waybar 配置
可以在 github 上搜索别人写好的配置。这里推荐一个,是笔者在sora6kq 的配置上自行修改的。其中用到的一些软件需要自行安装或者替换。
~/.config/waybar/config
{
"layer": "bottom",
"position": "bottom", // Waybar position (top|bottom|left|right)
"ipc": true,
"height": 35,
//"width": 1250, // Waybar width
// Choose the order of the modules idle_inhibitor
"modules-left": [
"custom/launcher",
"sway/workspaces",
"sway/mode",
"sway/window"
],
"modules-right": [
"network",
"cpu",
"memory",
"disk",
"temperature",
"battery",
"pulseaudio",
"backlight",
"clock"
],
// Modules configuration
"sway/workspaces": {
"disable-scroll": true,
"all-outputs": true,
"format": "{icon}",
"format-icons": {
"1": "1",
"2": "2",
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"9": "9",
"10": "10"
}
},
"sway/mode": {
"format": "<span style=\"italic\">{}</span>"
},
"sway/window": {
"format": "{}"
},
"clock": {
"tooltip-format": "{:%A %B %d %Y | %H:%M}",
// "format": " {:%a %d %b %I:%M %p}", //12 hour format
"format": " {:%a %d %b %H:%M}", //24 hour format
"format-alt": " {:%d/%m/%Y %H:%M:%S}",
"timezones": ["Asia/Shanghai"],
//"max-length": 200
"interval": 1
},
"cpu": {
"format": " {usage}%",
"on-click": "terminator -e htop"
},
"memory": {
"format": " {}%",
"on-click": "terminator -e htop"
},
"temperature": {
"thermal-zone": 2,
"hwmon-path": "/sys/class/hwmon/hwmon2/temp1_input",
"critical-threshold": 80,
"format-critical": " {temperatureC}°C",
"format": " {temperatureC}°C"
},
"backlight": {
// "device": "acpi_video1",
"format": "{icon} {percent}%",
"format-icons": ["", ""],
"on-scroll-down": "sudo xbacklight -dec 5",
"on-scroll-up": "sudo xbacklight -inc 5"
},
"battery": {
"states": {
// "good": 95,
"warning": 30,
"critical": 15
},
"format": "{icon} {capacity}%",
// "format-good": "", // An empty format will hide the module
// "format-full": "",
"format-icons": ["", "", "", "", ""]
//"format-icons": ["", "", "", "", "", "", "", "", "", ""]
},
"network": {
"interface": "wlp2s0", // (Optional) To force the use of this interface
"format": "⚠ Disabled",
"format-wifi": " {signalStrength}% {essid} ↑ {bandwidthUpBits} ↓ {bandwidthDownBits}",
"format-ethernet": " {ifname}: {ipaddr}/{cidr}",
"format-disconnected": "⚠ Disconnected",
"interval": 1,
"on-click": "terminator -e nethogs"
},
"pulseaudio": {
"scroll-step": 5,
"format": "{icon} {volume}%",
"format-bluetooth": "{icon} {volume}%",
"format-muted": "",
"format-icons": {
"headphones": "",
"handsfree": "",
"headset": "",
"phone": "",
"portable": "",
"car": "",
"default": ["", ""]
},
"on-click": "terminator -e alsamixer"
},
"custom/launcher": {
"format": "",
"on-click": "exec rofi -show drun",
"tooltip": false
},
"disk": {
"interval": 30,
"format": "🖫 {percentage_used}%",
}
}
style.css
* {
color: #a7a2a9;
border: 0;
border-radius: 2px;
padding: 0 0;
font-family: mononoki;
font-size: 16px;
margin-right: 5px;
margin-left: 5px;
padding-bottom: 1px;
}
window#waybar {
background-image: linear-gradient(to right, #ff6600, #0033cc);
}
#workspaces button {
padding: 2px 0px;
border-bottom: 2px;
color: #eceff4;
border-color: #d8dee9;
border-style: solid;
margin-top: 2px;
}
#workspaces button.focused {
border-color: #81a1c1;
}
#mode {
color: #ebcb8b;
}
#clock,
#battery,
#cpu,
#memory,
#idle_inhibitor,
#temperature,
#custom-keyboard-layout,
#backlight,
#network,
#disk,
#pulseaudio,
#mode,
#window,
#custom-launcher {
padding: 0 3px;
border-bottom: 2px;
border-style: solid;
}
/* -----------------------------------------------------------------------------
* Module styles
* -------------------------------------------------------------------------- */
#clock {
color: #f7c548;
}
#backlight {
color: #ae76a6;
}
#battery {
color: #ef946c;
}
#battery.charging {
color: #ef946c;
}
#disk {
color: #809112;
}
@keyframes blink {
to {
color: #4c566a;
background-color: #eceff4;
}
}
#battery.critical:not(.charging) {
background: #bf616a;
color: #eceff4;
animation-name: blink;
animation-duration: 0.5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
}
#cpu {
color: #1dd3b0;
}
#memory {
color: #eb6534;
}
#network.disabled {
color: #bf616a;
}
#network {
color: #2d82b7;
}
#network.disconnected {
color: #ba1f33;
}
#pulseaudio {
color: #99f7ab;
}
#pulseaudio.muted {
color: #c42021;
}
#temperature {
color: #8fbcbb;
}
#temperature.critical {
color: #bf616a;
}
#idle_inhibitor {
color: #ebcb8b;
}
#custom-launcher {
border-style: hidden;
margin-top: 2px;
}
#window {
border-style: hidden;
margin-top: 1px;
}
#mode {
margin-bottom: 3px;
}
#custom-keyboard-layout {
color: #d08770;
}
截图与录像
需要的软件有grim
,slurp
,wf-recorder
。
~/.config/sway/config
bindsym ctrl+Shift+r exec "sh /home/niuiic/.config/sway/record.sh"
# record.sh
isrecoding=$(ps aux)
isrecoding=$(echo -e $isrecoding | grep "wf-recorder")
if [[ $isrecoding != "" ]]; then
killall wf-recorder
else
wf-recorder &
fi
程序启动器
rofi 有一个支持 wayland 的 fork,这应当是最好的选择了。