dotfiles/config/qtile/config.py

302 lines
10 KiB
Python
Raw Normal View History

2024-06-15 16:03:26 +00:00
# Copyright (c) 2010 Aldo Cortesi
# Copyright (c) 2010, 2014 dequis
# Copyright (c) 2012 Randall Ma
# Copyright (c) 2012-2014 Tycho Andersen
# Copyright (c) 2012 Craig Barnes
# Copyright (c) 2013 horsik
# Copyright (c) 2013 Tao Sauvage
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import subprocess
from libqtile import bar, extension, hook, layout, qtile, widget
from libqtile.config import Click, Drag, Group, Key, KeyChord, Match, Screen
from libqtile.lazy import lazy
from qtile_extras import widget
from qtile_extras.widget.decorations import BorderDecoration
import colors
mod = "mod4"
myTerm = "alacritty"
myBrowser = "firefox"
keys = [
Key([mod], "Return", lazy.spawn("alacritty -e zsh"), desc="Terminal"),
Key([mod, "shift"], "Return", lazy.spawn("rofi -show drun"), desc='Run Launcher'),
Key([mod], "b", lazy.spawn(myBrowser), desc='Web browser'),
Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"),
Key([mod, "shift"], "c", lazy.window.kill(), desc="Kill focused window"),
Key([mod, "shift"], "r", lazy.reload_config(), desc="Reload the config"),
Key([mod, "shift"], "q", lazy.spawn("qtile cmd-obj -o cmd -f shutdown"), desc="Logout"),
Key([mod], "r", lazy.spawncmd(), desc="Spawn a command using a prompt widget")
]
groups = []
group_names = ["1", "2", "3", "4", "5", "6", "7"]
group_labels = ["DEV", "WWW", "SYS", "DOC", "CHAT", "MUS", "VID"]
group_layouts = ["monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall", "monadtall"]
for i in range(len(group_names)):
groups.append(
Group(
name=group_names[i],
layout=group_layouts[i].lower(),
label=group_labels[i],
))
for i in groups:
keys.extend(
[
Key(
[mod],
i.name,
lazy.group[i.name].toscreen(),
desc="Switch to group {}".format(i.name),
),
Key(
[mod, "shift"],
i.name,
lazy.window.togroup(i.name, switch_group=False),
desc="Move focused window to group {}".format(i.name),
),
]
)
colors = colors.DoomOne
layout_theme = {"border_width": 2,
"margin": 8,
"border_focus": colors[8],
"border_normal": colors[0]
}
layouts = [
layout.MonadTall(**layout_theme),
layout.Max(
border_width = 0,
margin = 0,
),
]
widget_defaults = dict(
font="Ubuntu Bold",
fontsize = 12,
padding = 0,
background=colors[0]
)
extension_defaults = widget_defaults.copy()
def init_widgets_list():
widgets_list = [
widget.Image(
filename = "~/.config/qtile/icons/python.png",
scale = "False",
mouse_callbacks = {'Button1': lambda: qtile.cmd_spawn(myTerm)},
),
widget.Prompt(
font = "Ubuntu Mono",
fontsize=14,
foreground = colors[1]
),
widget.GroupBox(
fontsize = 11,
margin_y = 5,
margin_x = 5,
padding_y = 0,
padding_x = 1,
borderwidth = 3,
active = colors[8],
inactive = colors[1],
rounded = False,
highlight_color = colors[2],
highlight_method = "line",
this_current_screen_border = colors[7],
this_screen_border = colors [4],
other_current_screen_border = colors[7],
other_screen_border = colors[4],
),
widget.TextBox(
text = '|',
font = "Ubuntu Mono",
foreground = colors[1],
padding = 2,
fontsize = 14
),
widget.CurrentLayoutIcon(
foreground = colors[1],
padding = 4,
scale = 0.6
),
widget.CurrentLayout(
foreground = colors[1],
padding = 5
),
widget.TextBox(
text = '|',
font = "Ubuntu Mono",
foreground = colors[1],
padding = 2,
fontsize = 14
),
widget.WindowName(
foreground = colors[6],
max_chars = 40
),
widget.GenPollText(
update_interval = 300,
func = lambda: subprocess.check_output("printf $(uname -r)", shell=True, text=True),
foreground = colors[3],
fmt = '{}',
decorations=[
BorderDecoration(
colour = colors[3],
border_width = [0, 0, 2, 0],
)
],
),
widget.Spacer(length = 8),
widget.CPU(
format = 'Cpu: {load_percent}%',
foreground = colors[4],
decorations=[
BorderDecoration(
colour = colors[4],
border_width = [0, 0, 2, 0],
)
],
),
widget.Spacer(length = 8),
widget.Memory(
foreground = colors[8],
mouse_callbacks = {'Button1': lambda: qtile.cmd_spawn(myTerm + ' -e htop')},
format = '{MemUsed: .0f}{mm}',
fmt = 'Mem: {} used',
decorations=[
BorderDecoration(
colour = colors[8],
border_width = [0, 0, 2, 0],
)
],
),
widget.Spacer(length = 8),
widget.DF(
update_interval = 60,
foreground = colors[5],
mouse_callbacks = {'Button1': lambda: qtile.cmd_spawn(myTerm + ' -e df')},
partition = '/',
format = '{uf}{m} free',
fmt = 'Disk: {}',
visible_on_warn = False,
decorations=[
BorderDecoration(
colour = colors[5],
border_width = [0, 0, 2, 0],
)
],
),
widget.Spacer(length = 8),
widget.KeyboardLayout(
foreground = colors[4],
fmt = 'Kbd: {}',
decorations=[
BorderDecoration(
colour = colors[4],
border_width = [0, 0, 2, 0],
)
],
),
widget.Spacer(length = 8),
widget.Clock(
foreground = colors[8],
format = "%a, %b %d - %H:%M:%S",
decorations=[
BorderDecoration(
colour = colors[8],
border_width = [0, 0, 2, 0],
)
],
),
widget.Spacer(length = 8),
widget.Systray(padding = 3),
widget.Spacer(length = 8),
]
return widgets_list
def init_widgets_screen1():
widgets_screen1 = init_widgets_list()
return widgets_screen1
def init_screens():
return [Screen(top=bar.Bar(widgets=init_widgets_screen1(), size=34))]
if __name__ in ["config", "__main__"]:
screens = init_screens()
widgets_list = init_widgets_list()
def window_to_prev_group(qtile):
if qtile.currentWindow is not None:
i = qtile.groups.index(qtile.currentGroup)
qtile.currentWindow.togroup(qtile.groups[i - 1].name)
def window_to_next_group(qtile):
if qtile.currentWindow is not None:
i = qtile.groups.index(qtile.currentGroup)
qtile.currentWindow.togroup(qtile.groups[i + 1].name)
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
auto_fullscreen = True
focus_on_window_activation = "smart"
reconfigure_screens = True
# If things like steam games want to auto-minimize themselves when losing
# focus, should we respect this or not?
auto_minimize = True
# When using the Wayland backend, this can be used to configure input devices.
wl_input_rules = None
@hook.subscribe.startup_once
def start_once():
home = os.path.expanduser('~')
subprocess.call([home + '/.config/qtile/autostart.sh'])
# XXX: Gasp! We're lying here. In fact, nobody really uses or cares about this
# string besides java UI toolkits; you can see several discussions on the
# mailing lists, GitHub issues, and other WM documentation that suggest setting
# this string if your java app doesn't work correctly. We may as well just lie
# and say that we're a working one by default.
#
# We choose LG3D to maximize irony: it is a 3D non-reparenting WM written in
# java that happens to be on java's whitelist.
wmname = "LG3D"