Files
.dotfiles/qtile/.config/qtile/config.py
T
2020-12-12 04:32:34 +01:00

452 lines
14 KiB
Python

import os
import subprocess
import psutil
from libqtile import layout, bar, widget
from libqtile.config import Key, Drag, Click, Group, Screen
from libqtile.command import lazy
#region defines
term = 'termite'
focus_color = '#bd93f9'
border_width = 2
mod = 'mod4'
#region colors
light_foreground_color = ['#f8f8f2','#f8f8f2']
dark_foreground_color = ['#282a36','#282a36']
background_color0 = ['#000000','#000000']
background_color8 = ['#4d4d4d','#4d4d4d']
base_color = ['#101010','#101010']
# red
red_color = ['#df253f','#df253f']
light_red_color = ['#ff5555','#ff5555']
# green
green_color = ['#53a93f','#53a93f']
light_green_color = ['#50fa7b','#50fa7b']
#orange
orange_color = ['#f57900','#f57900']
# yellow
yellow_color = ['#f1fa8c','#f1fa8c']
#blue
blue_color = ['#7197e7','#7197e7']
# purple
purple_color = ['#bd93f9','#bd93f9']
# magenta
magenta_color = ['#ff79c6','#ff79c6']
# cyan
cyan_color = ['#8be9fd','#8be9fd']
#endregion
#endregion
#region Keys
keys = [
#moving focus aroung
Key([mod], "h", lazy.layout.left()),
Key([mod], "l", lazy.layout.right()),
Key([mod], "j", lazy.layout.down()),
Key([mod], "k", lazy.layout.up()),
Key([mod,"mod1"], "k", lazy.to_screen(0)),
Key([mod,"mod1"], "j", lazy.to_screen(1)),
Key([mod,"mod1"], "l", lazy.to_screen(1)),
Key([mod,"mod1"], "h", lazy.to_screen(2)),
# moving windows around
Key([mod, "shift"], "h", lazy.layout.swap_left()),
Key([mod, "shift"], "l", lazy.layout.swap_right()),
Key([mod, "shift"], "j", lazy.layout.shuffle_down()),
Key([mod, "shift"], "k", lazy.layout.shuffle_up()),
# resize windows
Key([mod], "plus", lazy.layout.grow()),
Key([mod], "minus", lazy.layout.shrink()),
Key([mod], "n", lazy.layout.normalize()),
Key([mod], "o", lazy.layout.maximize()),
Key([mod], "space", lazy.window.toggle_fullscreen()),
# app hotkeys
Key([mod],"t", lazy.spawn(term), desc="Launch terminal"),
Key([mod],"f", lazy.spawn("firefox"),desc="Launch firefox"),
Key([mod],"e", lazy.spawn("pcmanfm"),desc="Launch pcmanfm"),
Key([mod],"c", lazy.spawn("code"),desc="Launch visual studio code"),
# Toggle between different layouts as defined below
Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"),
Key([mod], "BackSpace", lazy.window.kill(), desc="Kill focused window"),
# qtile hotkeys
Key([mod, "control"], "r", lazy.restart(), desc="Restart qtile"),
Key([mod, "control"], "q", lazy.shutdown(), desc="Shutdown qtile"),
Key([mod], "r", lazy.spawncmd(),desc="Spawn a command using a prompt widget"),
# Media hotkeys
Key([], 'XF86AudioRaiseVolume', lazy.spawn('pulseaudio-ctl up 1')),
Key([], 'XF86AudioLowerVolume', lazy.spawn('pulseaudio-ctl down 1')),
Key([], 'XF86AudioMute', lazy.spawn('pulseaudio-ctl mute')),
]
# 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())
]
#endregion
#region Groups
group_names = [("WWW", {'layout': 'monadtall'}),
("DEV", {'layout': 'monadtall'}),
("SYS", {'layout': 'monadtall'}),
("DOC", {'layout': 'monadtall'}),
("VBOX", {'layout': 'monadtall'}),
("CHAT", {'layout': 'monadtall'}),
("MUS", {'layout': 'monadtall'}),
("VID", {'layout': 'monadtall'}),
("GFX", {'layout': 'floating'})]
groups = [Group(name, **kwargs) for name, kwargs in group_names]
for i, (name, kwargs) in enumerate(group_names, 1):
keys.extend([
Key(["mod1","control"], str(i), lazy.group[name].toscreen(),
desc="Switch to group {}".format(name)),
Key(['mod1','control', "shift"], str(i), lazy.window.togroup(name),
desc="move focused window to group {}".format(name)),
])
#endregion
#region Layouts
layouts = [
layout.MonadTall(
align=1,
border_focus = focus_color,
border_width = border_width,
new_at_current = True,
),
layout.Floating(
border_focus = focus_color,
border_width = border_width,
),
layout.Max(),
layout.MonadWide(
border_focus = focus_color,
border_width = border_width,
new_at_current = True,
),
]
floating_layout = layout.Floating(
border_focus = focus_color,
border_width = border_width,
float_rules=[
# Run the utility of `xprop` to see the wm class and name of an X client.
{'wmclass': 'confirm'},
{'wmclass': 'dialog'},
{'wmclass': 'download'},
{'wmclass': 'error'},
{'wmclass': 'file_progress'},
{'wmclass': 'notification'},
{'wmclass': 'splash'},
{'wmclass': 'toolbar'},
{'wmclass': 'confirmreset'}, # gitk
{'wmclass': 'makebranch'}, # gitk
{'wmclass': 'maketag'}, # gitk
{'wname': 'branchdialog'}, # gitk
{'wname': 'pinentry'}, # GPG key password entry
{'wmclass': 'ssh-askpass'}, # ssh-askpass
])
#endregion
#region Custom_Widgets
class MemoryC(widget.base.ThreadedPollText):
orientations = widget.base.ORIENTATION_HORIZONTAL
defaults = [
("format", "{MemUsed}GB/{MemTotal}GB", "Formatting for field names."),
("update_interval", 1.0, "Update interval for the Memory"),
]
def __init__(self, **config):
super().__init__(**config)
self.add_defaults(MemoryC.defaults)
def tick(self):
self.update(self.poll())
return self.update_interval
def poll(self):
mem = psutil.virtual_memory()
swap = psutil.swap_memory()
val = {}
val["MemUsed"] = mem.used // 1024 // 1024 // 102.4 / 10
val["MemTotal"] = mem.total // 1024 // 1024 // 102.4 / 10
val["MemPercent"] = mem.percent
val["MemFree"] = mem.free // 1024 // 1024 // 102.4 / 10
val["Buffers"] = mem.buffers // 1024 // 1024 // 102.4 / 10
val["Active"] = mem.active // 1024 // 1024 // 102.4 / 10
val["Inactive"] = mem.inactive // 1024 // 1024 // 102.4 / 10
val["Shmem"] = mem.shared // 1024 // 1024 // 102.4 / 10
val["SwapTotal"] = swap.total // 1024 // 1024 // 102.4 / 10
val["Swapfree"] = swap.free // 1024 // 1024 // 102.4 / 10
val["SwapUsed"] = swap.used // 1024 // 1024 // 102.4 / 10
val["SwapPercent"] = swap.percent
return self.format.format(**val)
#endregion
#region widgets
#region Powerline
def powerline_arrow(direction, color1, color2,size):
if direction == "r":
return [
widget.TextBox(
text=u"\ue0b0",
foreground=color1,
background=color2,
fontsize=size,
borderwidth=0,
padding=0
),
widget.Sep(padding=5, linewidth=0, background=color2),
]
else:
return [
widget.TextBox(
text=u"\ue0b2",
foreground=color2,
background=color1,
fontsize=size,
borderwidth=0,
padding=0
),
]
#endregion
#region Volume_widget
def vloume_widget(prev_color,color,size,fontsize):
return[
*powerline_arrow('l',prev_color,color,size),
widget.Volume(
foreground=dark_foreground_color,
background=color,
emoji=True,
fontsize=fontsize,
),
widget.Volume(
foreground=dark_foreground_color,
background=color,
fontsize=fontsize,
padding=0
),
widget.TextBox(" ",background=color),
]
#endregion
#region Pacman_widget
def pacman_widget(prev_color,color,size,fontsize):
return[
*powerline_arrow('l',prev_color,color,main_bar_height),
widget.Image(
filename='~/.config/qtile/icons/pacman.png',
margin=5,
background=color,
),
widget.CheckUpdates(
colour_have_updates=dark_foreground_color,
background=color,
fontsize=fontsize,
display_format="{updates}",
mouse_callbacks = {'Button1': lambda qtile: qtile.cmd_spawn(term + ' -e "sudo pacman -Syu"')},
),
]
#endregion
#region System_widgets
def System_widgets(prev_color,last_color,size,fontsize):
return [
*powerline_arrow('l',prev_color,red_color,size),
widget.Image(
filename='~/.config/qtile/icons/temp.png',
margin=5,
background=red_color,
),
widget.ThermalSensor(
foreground=dark_foreground_color,
background=red_color,
fontsize=fontsize,
tag_sensor='Tctl',
),
*powerline_arrow('l',red_color,green_color,size),
widget.Image(
filename='~/.config/qtile/icons/cpu.png',
margin=5,
background=green_color,
),
widget.CPU(
foreground=dark_foreground_color,
background=green_color,
fontsize=fontsize,
format='{load_percent}% @ {freq_current}GHz',
mouse_callbacks = {'Button1': lambda qtile: qtile.cmd_spawn(term + ' -e htop')},
),
*powerline_arrow('l',green_color,orange_color,size),
widget.Image(
filename='~/.config/qtile/icons/ram.png',
background=orange_color,
margin=-10
),
MemoryC(
foreground=dark_foreground_color,
background=orange_color,
fontsize=fontsize,
format=" {MemUsed}GB({MemPercent}%) | {SwapUsed}GB({SwapPercent}%)",
mouse_callbacks = {'Button1': lambda qtile: qtile.cmd_spawn(term + ' -e htop')},
),
*powerline_arrow('l',orange_color,last_color,size),
widget.Image(
filename='~/.config/qtile/icons/network.png',
background=blue_color,
margin=5
),
widget.Net(
background=last_color,
foreground=dark_foreground_color,
fontsize=fontsize,
fmt='{:.9}',
format='{down}',
),
widget.Net(
background=last_color,
foreground=dark_foreground_color,
fontsize=fontsize,
fmt='{:.9}',
format='{up}',
),
]
#endregion
#region End_widgets
def end_widgets(prev_color,size,fontsize):
return [
*powerline_arrow('l',prev_color,magenta_color,size),
widget.Image(
filename='~/.config/qtile/icons/calendar.png',
margin=5,
background=magenta_color,
),
widget.Clock(
foreground=dark_foreground_color,
background=magenta_color,
fontsize=fontsize,
format='%Y-%m-%d'
),
*powerline_arrow('l',magenta_color,base_color,size),
widget.Clock(
font='dseg7 classic bold',
fontsize=16,
format='%H:%M'
),
]
#endregion
#endregion
#region Bars and Widgets
widget_defaults = dict(
background=base_color,
font='Ubuntu Mono',
fontsize=15,
padding=3,
)
extension_defaults = widget_defaults.copy()
main_bar_fontsize=22
main_bar_height=28
secondary_bar_height=24
secondary_bar_fontsize=18
main_bar = bar.Bar([
widget.CurrentLayoutIcon(),
widget.GroupBox(
fontsize=main_bar_fontsize,
urgent_border=red_color,
urgent_text=red_color,
this_current_screen_border=purple_color,
this_screen_border=purple_color,
),
widget.Image(
filename='~/.config/qtile/icons/archlinux-logo-small.png',
margin=5,
background=blue_color
),
*powerline_arrow('r',blue_color,base_color,main_bar_height),
widget.Prompt(fontsize=main_bar_fontsize),
widget.WindowName(fontsize=16),
widget.Systray(fontsize=main_bar_fontsize),
*vloume_widget(base_color,blue_color,main_bar_height,main_bar_fontsize),
*System_widgets(blue_color,blue_color,main_bar_height,main_bar_fontsize),
*pacman_widget(blue_color,red_color,main_bar_height,main_bar_fontsize),
*end_widgets(red_color,main_bar_height,main_bar_fontsize),
],main_bar_height)
#left bar
left_bar = bar.Bar([
widget.CurrentLayoutIcon(),
widget.GroupBox(
urgent_border=red_color,
urgent_text=red_color,
this_current_screen_border=purple_color,
this_screen_border=purple_color,
),
widget.WindowName(),
*vloume_widget(base_color,blue_color,secondary_bar_height,secondary_bar_fontsize),
*end_widgets(blue_color,secondary_bar_height,secondary_bar_fontsize)
],secondary_bar_height)
top_bar = bar.Bar([
widget.CurrentLayoutIcon(),
widget.GroupBox(
urgent_border=red_color,
urgent_text=red_color,
this_current_screen_border=purple_color,
this_screen_border=purple_color,
),
widget.WindowName(),
*vloume_widget(base_color,blue_color,secondary_bar_height,secondary_bar_fontsize),
*end_widgets(blue_color,secondary_bar_height,secondary_bar_fontsize)
],secondary_bar_height)
#endregion
#region Screens
screens = [
Screen(bottom=top_bar),
Screen(top=main_bar),
Screen(top=left_bar),
]
#endregion
#region miscelanious
dgroups_key_binder = None
dgroups_app_rules = [] # type: List
main = None # WARNING: this is deprecated and will be removed soon
follow_mouse_focus = True
bring_front_click = True
cursor_warp = False
auto_fullscreen = True
focus_on_window_activation = "smart"
# 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"
#endregion