Files
dots/.config/qtile/config.py
2021-12-06 10:04:12 +02:00

212 lines
5.3 KiB
Python

import os
import subprocess
from typing import List # noqa: F401
from libqtile import bar, layout, widget
from libqtile.config import Click, Drag, Group, Match, Screen
from libqtile.lazy import lazy
from libqtile.config import EzKey
from libqtile import hook
#
# variables
#
mod = "mod4"
terminal = "kitty"
launcher = "dmenu_run"
file_manager = "thunar"
browser = "firefox"
calculator = "dcalc"
music_player = f"{terminal} -e ncmpcpp"
feed_reader = f"{terminal} -e newsboat"
screen_locker = "i3lock -c 000000"
scripts = os.path.expanduser('~/.config/qtile/scripts')
#
# keybinds
#
keys = [
# basics
EzKey("M-w", lazy.window.kill()),
EzKey("M-t", lazy.restart()),
EzKey("M-q", lazy.spawn(os.path.join(scripts, "exitmenu"))),
# focus
EzKey("M-h", lazy.layout.left()),
EzKey("M-j", lazy.layout.down()),
EzKey("M-k", lazy.layout.up()),
EzKey("M-l", lazy.layout.right()),
# shift
EzKey("M-S-h", lazy.layout.shuffle_left()),
EzKey("M-S-j", lazy.layout.shuffle_down()),
EzKey("M-S-k", lazy.layout.shuffle_up()),
EzKey("M-S-l", lazy.layout.shuffle_right()),
# resize
EzKey("M-C-h", lazy.layout.grow_left()),
EzKey("M-C-j", lazy.layout.grow_down()),
EzKey("M-C-k", lazy.layout.grow_up()),
EzKey("M-C-l", lazy.layout.grow_right()),
# cycle
EzKey("M-n", lazy.group.next_window()),
# window attributes
EzKey("M-C-q", lazy.window.toggle_floating()),
EzKey("M-C-w", lazy.window.toggle_fullscreen()),
# cycle layouts
EzKey("M-<Tab>", lazy.next_layout()),
# toggles
EzKey("M-S-w", lazy.spawn(os.path.join(scripts, "togglemaster"))),
# # media
# EzKey("XF86AudioMute", lazy.spawn("pulsemixer --toggle-mute")),
# EzKey("XF86AudioLowerVolume", lazy.spawn("pulsemixer --change-volume -5")),
# EzKey("XF86AudioRaiseVolume", lazy.spawn("pulsemixer --change-volume +5")),
# EzKey("XF86MonBrightnessDown", lazy.spawn("light -U 5")),
# EzKey("XF86MonBrightnessUp", lazy.spawn("light -A 5")),
# app launchers
EzKey("M-<Return>", lazy.spawn(terminal)),
EzKey("M-<space>", lazy.spawn(launcher)),
EzKey("M-<grave>", lazy.spawn("flameshot gui")),
EzKey("M-1", lazy.spawn(file_manager)),
EzKey("M-2", lazy.spawn(browser)),
EzKey("M-3", lazy.spawn(calculator)),
EzKey("M-4", lazy.spawn(music_player)),
EzKey("M-5", lazy.spawn(feed_reader)),
EzKey("M-6", lazy.spawn("virt-manager")),
EzKey("M-0", lazy.spawn(screen_locker)),
]
#
# groups
#
groups = [Group(i) for i in "asdfgzxcvb"]
for i in groups:
keys.extend([
EzKey(f"M-{i.name}", lazy.group[i.name].toscreen()),
EzKey(f"M-S-{i.name}", lazy.window.togroup(i.name)),
])
#
# theme
#
# load wal colors
colors = []
walpath = os.path.expanduser('~/.cache/wal/colors')
with open(walpath, 'r') as file:
for _ in range(8):
colors.append(file.readline().strip())
colors.append('#ffffff')
lazy.reload()
layout_theme = {
"border_width": 2,
"margin": 6,
"border_on_single": True,
"border_focus": colors[8],
"border_normal": colors[0],
}
#
# layouts
#
layouts = [
layout.Columns(**layout_theme),
layout.Bsp(**layout_theme, fair=False),
layout.Max(**layout_theme),
]
#
# bar
#
widget_defaults = dict(
font='mononoki',
fontsize=15,
padding=6,
)
extension_defaults = widget_defaults.copy()
group_box_settings = dict(
disable_drag=True,
highlight_method="block",
borderwidth=0,
# group is focused
this_current_screen_border=colors[2],
other_current_screen_border=colors[2],
block_highlight_text_color="ffffff",
active="ffffff",
# tag containts an urgent window
urgent_border=colors[6],
# tag is viewed on a non-focused monitor
this_screen_border=colors[1],
other_screen_border=colors[1],
# tag is empty
inactive="817f7f",
)
screens = []
for _ in range(2):
screens.append(
Screen(top=bar.Bar(
[
widget.GroupBox(**group_box_settings),
widget.Sep(),
widget.WindowName(),
widget.Spacer(),
widget.PulseVolume(),
widget.Sep(),
widget.Clock(format='%a %b %d %H:%M'),
],
29,
background='#0e0e0e',
margin=[6, 6, 6, 6],
), ), )
# Drag floating layouts.
mouse = [
Drag([mod],
"Button1",
lazy.window.set_position_floating(),
start=lazy.window.get_position()),
Drag([mod],
"Button3",
lazy.window.set_size_floating(),
start=lazy.window.get_size()),
Click([mod], "Button2", lazy.window.bring_to_front())
]
dgroups_key_binder = None
dgroups_app_rules = [] # type: List
follow_mouse_focus = True
bring_front_click = False
cursor_warp = False
floating_layout = layout.Floating(float_rules=[
# Run the utility of `xprop` to see the wm class and name of an X client.
*layout.Floating.default_float_rules,
Match(wm_class='confirmreset'), # gitk
Match(wm_class='makebranch'), # gitk
Match(wm_class='maketag'), # gitk
Match(wm_class='ssh-askpass'), # ssh-askpass
Match(title='branchdialog'), # gitk
Match(title='pinentry'), # GPG key password entry
])
# autostart script
@hook.subscribe.startup_complete
def autostart():
autostart = os.path.expanduser('~/.config/qtile/autostart.sh')
subprocess.call([autostart])