📅  最后修改于: 2023-12-03 15:04:44.388000             🧑  作者: Mango
Qtile 是一个快速、轻量级、动态窗口管理器,基于 Python 构建。它是完全可配置的,并且包含具有优美和易于使用的界面的库。 这使得 Qtile 成为一种理想的窗口管理器,不仅适用于高级用户,而且适用于新手。
from libqtile import layout
from libqtile.config impory Key, Group, Screen
from libqtile.command import lazy
mod = 'mod4'
keys = [
# 切换窗口
Key([mod], 'h', lazy.layout.left()),
Key([mod], 'j', lazy.layout.down()),
Key([mod], 'k', lazy.layout.up()),
Key([mod], 'l', lazy.layout.right()),
# 改变窗口大小
Key([mod, 'shift'], 'h', lazy.layout.grow()),
Key([mod, 'shift'], 'j', lazy.layout.foryard()),
Key([mod, 'shift'], 'k', lazy.layout.back()),
Key([mod, 'shift'], 'l', lazy.layout.shrink()),
# 切换到不同的组
Key([mod], 'Left', lazy.screen.prev_group()),
Key([mod], 'Right', lazy.screen.next_group()),
# 关闭窗口
Key([mod], 'w', lazy.window.kill()),
# 重新启动 Qtile
Key([mod, 'control'], 'r', lazy.restart()),
]
group_names = [
('WEB', {'layout': 'top'}),
('SSH', {'layout': 'top'}),
('TERM'),
('MUSIC', {'layout': 'top'}),
('CHAT'),
]
groups = [Group(name, **kwargs) for name, kwargs in group_names]
for i, (name, kwargs) in enumerate(group_names, 1):
keys += [
Key([mod], str(i), lazy.group[name].toscreen()),
Key([mod, 'shift'], str(i), lazy.window.togroup(name)),
]
layout_theme = {
'border_focus': '#606060',
'border_width': 2,
'margin': 5,
}
layouts = [
layout.Max(**layout_theme),
layout.Tile(**layout_theme),
]
widget_defaults = dict(
font='sans',
fontsize=12,
)
screens = [
Screen(top=bar.Bar([
widget.GroupBox(),
widget.Prompt(),
widget.WindowName(),
widget.Clock(format='%Y-%m-%d %a %I:%M %p'),
widget.Systray(),
widget.CurrentLayout(),
widget.Sep(),
], 24),),
Screen(),
]
# 配置文件主体
def get_config():
return dict(
mod=mod,
keys=keys,
mouse=(),
groups=groups,
layouts=layouts,
widget_defaults=widget_defaults,
screens=screens,
auto_fullscreen=True,
cursor_warp=True,
)
if __name__ == '__main__':
from libqtile.command import go_to_group
from libqtile.command import lazy
qtile = None
@hook.subscribe.startup_once
def startup_once():
try:
qtile.cmd_spawn('feh --bg-max ~/images/wallpapers/01.jpg')
except:
pass
@hook.subscribe.client_new
def assign_app_group(client):
d = {}
d[None] = lazy.window.togroup('TERM')
d['Chromium'] = lazy.window.togroup('WEB')
d['Emacs'] = lazy.window.togroup('TERM')
d['Termial'] = lazy.window.togroup('TERM')
d['Filezilla'] = lazy.window.togroup('SSH')
d['spotify'] = lazy.window.togroup('MUSIC')
group = matching.first(dic, client.cmdline)
if group is not None:
client.togroup(group)
qtile = None
setup(get_config(), qtile)
Qtile 具有灵活性和可定制性,这使得它成为一个不错的窗口管理器。 它的轻量级和速度意味着它适用于几乎任何硬件,而且适用于所有操作系统。因此,不妨一试。