Qtile
来自 项目网站
- Qtile 是一个功能齐全、可 hack 的平铺窗口管理器,使用 Python 编写。Qtile 简单、小巧且可扩展。它可以轻松编写自定义布局、小部件和内置命令。它完全使用 Python 编写和配置,这意味着您可以利用该语言的全部功能和灵活性来使其满足您的需求。
安装
安装 以下软件包之一
为了以 Wayland 合成器运行 Qtile,您需要安装 python-pywlroots。
启动
Xorg
要以 X11 窗口管理器运行 Qtile,请使用 xinit 运行 qtile start
。
Wayland
通过运行 qtile start -b wayland
以 Wayland 合成器启动 Qtile。
有关 Qtile Wayland 开发进度的状态,请参阅 https://github.com/qtile/qtile/discussions/2409。
配置
正如 Configuration Lookup (或 备用文档 中的 Configuration Lookup Order)中所述,Qtile 在 ~/.config/qtile/config.py
提供了一个默认配置文件,在没有用户自定义配置文件的情况下将使用该文件。
默认配置包括快捷键 Super+Enter
以打开新终端(从 硬编码列表 中选择),以及 Super+Ctrl+q
以退出 Qtile。
最新的默认配置文件可以从 git 仓库 libqtile/resources/default_config.py 下载。
更多完整的配置文件示例可以在 qtile-examples 仓库中找到。
配置完全使用 Python 完成:要快速入门该语言,您可以阅读 本教程。
在重启 Qtile 之前,您可以使用以下命令测试配置文件的语法错误
$ python -m py_compile ~/.config/qtile/config.py
如果命令没有输出,则您的脚本是正确的。
或者,命令
$ qtile check
将执行语法检查,然后进行额外的类型检查。
工作区组
在 Qtile 中,工作区(或视图)称为工作区组。它们可以如下定义
from libqtile.config import Group, Match ... groups = [ Group("term"), Group("irc"), Group("web", matches=[Match(title=["Firefox"])]), ] ...
工作区组规则
以下示例展示了如何根据标题和 wm_class 等属性自动将应用程序移动到工作区。如果您在 X 上运行,您可能需要使用 xprop 来获取这些属性。
from libqtile.config import Group, Match ... def is_text_editor(window): result = "neovim" in (window.name or "").lower() return result def is_terminal(window): result = "kitty" in (window.name or "").lower() and not is_text_editor(window) return result ... groups = [ Group(name=str(idx), **group) for idx, group in enumerate( [ { "label": "term", # restrict layouts since tiling is handled by kitty "layouts": [layout.Max()], "matches": [ Match(func=is_terminal), ], }, { "label": "browser", "matches": [ Match(role="browser"), ], }, { "label": "music", "matches": [ Match(title="YouTube Music"), ], }, {"label": "text editor", "matches": [Match(func=is_text_editor)]}, {"label": "other"}, ], start=1, ) ] ...
快捷键
您可以使用 Key 类配置快捷键。这是一个使用快捷键 Alt+Shift+q
退出窗口管理器的示例。
from libqtile.config import Key from libqtile.command import lazy ... keys = [ Key( ["mod1", "shift"], "q", lazy.shutdown()) ] ...
您可以使用 Xmodmap 命令找出哪个 modX
对应哪个键。
声音
您可以通过将用户添加到 audio 组并使用 alsamixer
命令行界面来添加快捷键以轻松控制音量和状态,alsamixer 可以通过 alsa-utils 软件包安装。
keys= [ ... # Sound Key([], "XF86AudioMute", lazy.spawn("amixer -q set Master toggle")), Key([], "XF86AudioLowerVolume", lazy.spawn("amixer -c 0 sset Master 1- unmute")), Key([], "XF86AudioRaiseVolume", lazy.spawn("amixer -c 0 sset Master 1+ unmute")) ]
语言
您可以使用 setxkbmap 等工具添加快捷键以轻松切换不同语言的键盘布局
keys= [ ... # Language Key([mod], "F1", lazy.spawn("setxkbmap us"), desc= "Change to US layout"), Key([mod],"F2", lazy.spawn("setxkbmap gr"), desc= "Change to Greek layout"), ]
屏幕
为您拥有的每个显示器创建一个 Screen 类。Qtile 的状态栏在 Screen 类中配置,如下例所示
from libqtile.config import Screen from libqtile import bar, widget import os.path ... screens = [ Screen( wallpaper=os.path.join(os.path.expanduser("~"), "Photos/Wallpapers/arch_fill.png"), wallpaper_mode="fill", bottom=bar.Bar([ # add a bar to the bottom of the screen widget.GroupBox(), # display the current Group widget.WindowName() # display the name of the window that currently has focus ], 30)) ] ...
状态栏和小部件
您可以在 官方文档 (或 备用文档)中找到所有内置小部件的列表。
如果您想向状态栏添加小部件,只需像上面的示例中那样添加它(对于 WindowName
小部件)。例如,如果我们想添加电池通知,我们可以使用 Battery
小部件
from libqtile.config import Screen from libqtile import bar, widget ... screens = [ Screen(top=bar.Bar([ widget.GroupBox(), # display the current Group widget.Battery() # display the battery state ], 30)) ] ...
使用 Polybar 作为主状态栏
要使用 Polybar 而不是默认状态栏,您需要删除 screen 类的内容
from libqtile.config import Screen from libqtile import bar, widget ... screens = [ Screen() ] ...
要使用 Qtile 重启 Polybar,请将 Polybar 的启动脚本与 spawn
命令添加到 #快捷键 类中的重启 Key,例如
... keys = [ Key([mod, "control"], "r", lazy.reload_config(), lazy.spawn("~/.config/polybar/launch.sh")), ] ...
启动
您可以使用 hooks 启动应用程序,特别是 startup
hook。有关可用 hooks 的列表,请参阅 文档 (或 备用文档)。
这是一个应用程序仅启动一次的示例
import os import subprocess from libqtile import hook @hook.subscribe.startup_once def autostart(): script = os.path.expanduser("~/.config/qtile/autostart.sh") subprocess.run([script])
调试
Qtile 将其日志写入 ~/.local/share/qtile/qtile.log
xinit
在不同的虚拟屏幕上启动 Qtile 可以帮助诊断问题
$ echo "exec qtile start" > /tmp/.start_qtile; xinit /tmp/.start_qtile -- :2
Xephyr
Qtile 提供了一个 Xephyr 开发脚本,可以通过替换轻松修改该脚本以实例化系统安装的软件包
env DISPLAY=${XDISPLAY} QTILE_XEPHYR=1 ${PYTHON} "${HERE}"/../bin/qtile start -l ${LOG_LEVEL} $@ &
替换为
env DISPLAY=${XDISPLAY} QTILE_XEPHYR=1 qtile start -l ${LOG_LEVEL} $@ &
参见
- Qtile 网站
- 官方文档
- 官方文档的备用来源,可在 "docs.qtile.org" 宕机时使用,如 issue 4295 中所示
- Qtile 示例
- qtile-extras 为 qtile 提供了额外的功能,包括小部件装饰、附加小部件、窗口边框装饰等。