qtile: adjust default config with light and dark themes

This commit is contained in:
Łukasz Pankowski 2021-10-06 07:57:33 +02:00
parent dda7f6aa40
commit 5c93edc211
5 changed files with 149 additions and 35 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
bspwm/.config/bspwm/themes/theme.sh
shell/.config/zsh/plugins/zsh-autosuggestions
shell/.config/zsh/plugins/zsh-syntax-highlighting
qtile/.config/qtile/theme.txt
*~
__pycache__

View File

@ -6,7 +6,7 @@ fi
xrandr --auto
xrandr --output HDMI1 --right-of DP1
xsetroot -solid '#224242'
xsetroot -solid '#94a3b8'
xrdb -merge ~/.Xresources
setxkbmap pl -option ctrl:nocaps
xmodmap ~/.xmodmaprc
@ -21,9 +21,12 @@ fi
# run emacs daemon if not running
emacsclient --eval nil -a '' &
xsettingsd &
exec qtile start
if which bspwm > /dev/null; then
sxhkd &
xsettingsd &
xsetroot -cursor_name left_ptr
exec bspwm
fi

View File

@ -0,0 +1,26 @@
colors = {
"indigo": {
50: "#eef2ff",
100: "#e0e7ff",
200: "#c7d2fe",
300: "#a5b4fc",
400: "#818cf8",
500: "#6366f1",
600: "#4f46e5",
700: "#4338ca",
800: "#3730a3",
900: "#312e81",
},
"blue-gray": {
50: "#f8fafc",
100: "#f1f5f9",
200: "#e2e8f0",
300: "#cbd5e1",
400: "#94a3b8",
500: "#64748b",
600: "#475569",
700: "#334155",
800: "#1e293b",
900: "#0f172a",
}
}

View File

@ -5,6 +5,7 @@
# Copyright (c) 2012 Craig Barnes
# Copyright (c) 2013 horsik
# Copyright (c) 2013 Tao Sauvage
# Copyright (c) 2021 Łukasz Pankowski (adapted default config to my needs)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ -26,22 +27,26 @@
from typing import List # noqa: F401
from libqtile import bar, layout, widget
from libqtile.config import Click, Drag, Group, Key, Match, Screen
from libqtile import bar, layout, qtile, widget
from libqtile.config import Click, Drag, Group, Key, KeyChord, Match, Screen
from libqtile.lazy import lazy
from libqtile.utils import guess_terminal
from themes import theme, init_theme, toggle_theme
mod = "mod4"
terminal = guess_terminal()
init_theme(qtile)
keys = [
# Switch between windows
Key([mod], "h", lazy.layout.left(), desc="Move focus to left"),
Key([mod], "l", lazy.layout.right(), desc="Move focus to right"),
Key([mod], "j", lazy.layout.down(), desc="Move focus down"),
Key([mod], "k", lazy.layout.up(), desc="Move focus up"),
Key([mod], "space", lazy.layout.next(),
desc="Move window focus to other window"),
# Key([mod], "space", lazy.layout.next(),
# desc="Move window focus to other window"),
# Move windows between left/right columns or move up/down in current stack.
# Moving out of range in Columns layout will create new column.
@ -73,16 +78,28 @@ keys = [
Key([mod], "Return", lazy.spawn(terminal), desc="Launch terminal"),
# Toggle between different layouts as defined below
Key([mod], "Tab", lazy.next_layout(), desc="Toggle between layouts"),
Key([mod], "m", lazy.next_layout(), desc="Toggle between layouts"),
Key([mod], "w", lazy.window.kill(), desc="Kill focused window"),
Key([mod], "Tab", lazy.screen.toggle_group(), desc="Toggle between groups"),
Key([mod], "e", lazy.spawn("emacsclient -n -c")),
Key([mod], "s", lazy.window.toggle_floating()),
KeyChord([mod], "semicolon", [
Key([], "h", lazy.spawn("systemctl hibernate")),
Key([], "l", lazy.spawn("slock")),
Key([], "s", lazy.spawn("systemctl suspend")),
]),
Key([mod, "shift"], "F6", lazy.function(toggle_theme), lazy.restart()),
Key([mod, "control"], "r", lazy.restart(), desc="Restart Qtile"),
Key([mod, "control"], "q", lazy.shutdown(), desc="Shutdown Qtile"),
Key([mod], "r", lazy.spawncmd(),
Key([mod], "space", lazy.spawncmd(),
desc="Spawn a command using a prompt widget"),
]
groups = [Group(i) for i in "123456789"]
groups = [Group(i) for i in "1234567890"]
for i in groups:
keys.extend([
@ -91,16 +108,19 @@ for i in groups:
desc="Switch to group {}".format(i.name)),
# mod1 + shift + letter of group = switch to & move focused window to group
Key([mod, "shift"], i.name, lazy.window.togroup(i.name, switch_group=True),
desc="Switch to & move focused window to group {}".format(i.name)),
# Key([mod, "shift"], i.name, lazy.window.togroup(i.name, switch_group=True),
# desc="Switch to & move focused window to group {}".format(i.name)),
# Or, use below if you prefer not to switch to that group.
# # mod1 + shift + letter of group = move focused window to group
# Key([mod, "shift"], i.name, lazy.window.togroup(i.name),
# desc="move focused window to group {}".format(i.name)),
Key([mod, "shift"], i.name, lazy.window.togroup(i.name),
desc="move focused window to group {}".format(i.name)),
])
layouts = [
layout.Columns(border_focus_stack=['#d75f5f', '#8f3d3d'], border_width=4),
layout.Columns(border_focus_stack=['#d75f5f', '#8f3d3d'],
border_focus=theme["border_focus"],
border_normal=theme["border_normal"],
border_width=4, margin=2),
layout.Max(),
# Try more layouts by unleashing below layouts.
# layout.Stack(num_stacks=2),
@ -116,19 +136,31 @@ layouts = [
]
widget_defaults = dict(
font='sans',
fontsize=12,
font="Iosevka Slab Light",
fontsize=28,
padding=3,
foreground = theme["widget_foreground"],
)
extension_defaults = widget_defaults.copy()
screens = [
Screen(
bottom=bar.Bar(
top=bar.Bar(
[
widget.CurrentLayout(),
widget.GroupBox(),
widget.Prompt(),
widget.Spacer(10),
widget.CurrentLayout(120, foreground=theme["inactive"]),
widget.Spacer(10),
widget.GroupBox(
borderwidth=2,
margin_x=1,
padding_x=7,
active=widget_defaults["foreground"],
inactive=theme["inactive"],
highlight_method="block",
this_current_screen_border=theme["this_current_screen_border"]),
widget.Spacer(10),
widget.Prompt(cursor_color=theme["widget_foreground"]),
widget.Spacer(10),
widget.WindowName(),
widget.Chord(
chords_colors={
@ -136,13 +168,12 @@ screens = [
},
name_transform=lambda name: name.upper(),
),
widget.TextBox("default config", name="default"),
widget.TextBox("Press <M-r> to spawn", foreground="#d75f5f"),
widget.Systray(),
widget.Clock(format='%Y-%m-%d %a %I:%M %p'),
widget.QuickExit(),
widget.Clock(format=f"<span foreground=\"{theme['inactive']}\">%Y-%m-%d %a</span> %H:%M"),
widget.Spacer(10),
],
24,
42,
background=theme["bar_background"],
),
),
]
@ -161,7 +192,8 @@ dgroups_app_rules = [] # type: List
follow_mouse_focus = True
bring_front_click = False
cursor_warp = False
floating_layout = layout.Floating(float_rules=[
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
@ -170,7 +202,11 @@ floating_layout = layout.Floating(float_rules=[
Match(wm_class='ssh-askpass'), # ssh-askpass
Match(title='branchdialog'), # gitk
Match(title='pinentry'), # GPG key password entry
])
],
border_focus=theme["border_focus"],
border_normal=theme["border_normal"],
border_width=4)
auto_fullscreen = True
focus_on_window_activation = "smart"
reconfigure_screens = True

View File

@ -0,0 +1,48 @@
import os
from colors import colors
theme_file = os.path.join(os.path.dirname(__file__), "theme.txt")
def write_theme(name):
with open(theme_file, "w") as f:
f.write(name)
def read_theme(file_name):
try:
with open(file_name) as f:
return f.read().strip()
except FileNotFoundError:
return "dark"
is_dark = read_theme(theme_file) == "dark"
def light_dark(light, dark):
return dark if is_dark else light
def toggle_theme(qtile):
write_theme(light_dark("dark", "light"))
theme = dict(
background=light_dark(colors["blue-gray"][200], colors["blue-gray"][700]),
bar_background=light_dark([colors["blue-gray"][200], colors["blue-gray"][300]],
[colors["blue-gray"][600], colors["blue-gray"][900]]),
widget_foreground=light_dark(colors["blue-gray"][600], colors["blue-gray"][400]),
inactive=light_dark(colors["blue-gray"][400], colors["blue-gray"][500]),
this_current_screen_border=light_dark([colors["blue-gray"][200], colors["blue-gray"][50]],
[colors["blue-gray"][900], colors["blue-gray"][800]]),
border_focus=light_dark(colors["indigo"][400], colors["blue-gray"][500]),
border_normal=light_dark(colors["indigo"][900], colors["blue-gray"][900]),
alacritty_theme=light_dark("lupan-material-light", "lupan-dark-gray"),
emacs_theme=light_dark("lupan-material-light", "lupan-dark-gray"),
gtk_theme=light_dark("Materia-light", "Materia-dark"),
)
def init_theme(qtile):
qtile.cmd_spawn(["xsetroot", "-solid", theme["background"]])
qtile.cmd_spawn(["sed", "-i", f"s/^colors: [*].*/colors: *{theme['alacritty_theme']}/",
os.path.expanduser("~/.config/alacritty/alacritty.yml")])
qtile.cmd_spawn(["emacsclient", "--eval", f"(my-select-theme '{theme['emacs_theme']})"])
qtile.cmd_spawn(["sed", "-i", "-E", f"s#(Net/ThemeName) .*#\\1 \"{theme['gtk_theme']}\"#",
os.path.expanduser("~/.config/xsettingsd/xsettingsd.conf")])
qtile.cmd_spawn(["pkill", "-HUP", "-x", "xsettingsd"])