Multiple changes including random wallpaper, theme colors and switching to yay instead of yaourt
This commit is contained in:
parent
b78b817a33
commit
5b7475e50f
7 changed files with 609 additions and 46 deletions
257
kuro/theme.py
257
kuro/theme.py
|
@ -1,3 +1,7 @@
|
|||
import json
|
||||
import os
|
||||
import random
|
||||
|
||||
from libqtile.config import Key, Screen, Group, Drag, Click
|
||||
from libqtile.command import lazy
|
||||
from libqtile import layout, bar, widget
|
||||
|
@ -39,6 +43,12 @@ class Kuro(BaseTheme):
|
|||
# Top bars
|
||||
topbars = []
|
||||
|
||||
# Current wallpaper path
|
||||
current_wallpaper = None
|
||||
|
||||
# Whether or not to perform keyboard backlight updates
|
||||
do_keyboard_updates = True
|
||||
|
||||
# Window manager name
|
||||
wmname = "QTile"
|
||||
|
||||
|
@ -60,6 +70,12 @@ class Kuro(BaseTheme):
|
|||
def initialize(self):
|
||||
self.log_debug("Initializing Kuro Theme...")
|
||||
|
||||
# Update color scheme
|
||||
self.initialize_colorscheme()
|
||||
|
||||
# Set settings
|
||||
self.do_keyboard_updates = Config.get("do_keyboard_updates", True)
|
||||
|
||||
super(Kuro, self).initialize()
|
||||
|
||||
self.update()
|
||||
|
@ -108,7 +124,7 @@ class Kuro(BaseTheme):
|
|||
Key([self.mod], "b", lazy.spawn(Config.get('web_browser', "xterm links"))),
|
||||
|
||||
# Super-F to start file manager
|
||||
# Key([self.mod], "f", lazy.spawn(Config.get('file_manager', "thunar"))),
|
||||
# Key([self.mod], "f", lazy.spawn(Config.get('file_m4anager', "thunar"))),
|
||||
|
||||
# Super-Shift-R to start spawncmd
|
||||
Key([self.mod, "shift"], "r", lazy.spawncmd()),
|
||||
|
@ -132,13 +148,20 @@ class Kuro(BaseTheme):
|
|||
# Shutdown QTile
|
||||
Key([self.mod, "control"], "q", lazy.shutdown()),
|
||||
|
||||
# Update wallpaper
|
||||
Key([self.mod, "control"], "w", lazy.function(self.update_wallpaper)),
|
||||
|
||||
# Reload colorscheme
|
||||
Key([self.mod, "control"], "t", lazy.function(self.update_colorscheme)),
|
||||
|
||||
# Reorganize screens
|
||||
Key([self.mod, "control"], "s", lazy.function(self.update_screens)),
|
||||
|
||||
|
||||
##
|
||||
# Debug keyboard shortcuts
|
||||
##
|
||||
Key([self.mod, "control"], "w", lazy.function(display_wm_class)),
|
||||
Key([self.mod, "control"], "c", lazy.function(display_wm_class)),
|
||||
|
||||
# Redraw the top bar
|
||||
Key([self.mod, "shift", "control"], "r", lazy.function(self.redraw_bar)),
|
||||
|
@ -153,7 +176,7 @@ class Kuro(BaseTheme):
|
|||
groups = []
|
||||
|
||||
# http://fontawesome.io/cheatsheet
|
||||
groups.append(Group("", spawn=Config.get('web_browser', "xterm links")))
|
||||
groups.append(Group("", spawn=Config.get('web_browser', "xterm links")))
|
||||
groups.append(Group("", spawn=Config.get('app_terminal', "xterm")))
|
||||
groups.append(Group(""))
|
||||
groups.append(Group("", spawn="franz4-bin"))
|
||||
|
@ -161,7 +184,7 @@ class Kuro(BaseTheme):
|
|||
groups.append(Group("", spawn=Config.get('file_manager', "thunar")))
|
||||
groups.append(Group("", spawn="thunderbird"))
|
||||
groups.append(Group(""))
|
||||
groups.append(Group("", spawn="qupzilla https://music.kurocon.nl/"))
|
||||
groups.append(Group(""))
|
||||
groups.append(Group(""))
|
||||
|
||||
return groups
|
||||
|
@ -233,7 +256,23 @@ class Kuro(BaseTheme):
|
|||
urgent_alert_method=Config.get('tasklist_urgent_alert_method', 'border'),
|
||||
urgent_border=Config.get('tasklist_urgent_border', '#ff0000'),
|
||||
margin=Config.get('margin_groupbox', 0)
|
||||
),
|
||||
)
|
||||
])
|
||||
|
||||
if Config.get('show_audio_visualizer', False):
|
||||
widgets.append(utils.AudioVisualizerWidget(
|
||||
graph_color=Config.get('visualizer_graph_color', "#ffffff"),
|
||||
fill_color=Config.get('visualizer_fill_color', "#ffffff.3"),
|
||||
border_color=Config.get('visualizer_border_color', "#000000"),
|
||||
border_width=Config.get('visualizer_graph_width', 0),
|
||||
line_width=Config.get('visualizer_line_width', 1),
|
||||
frequency=0.05
|
||||
))
|
||||
|
||||
widgets.extend([
|
||||
utils.MediaWidget(),
|
||||
|
||||
utils.SeparatorWidget(),
|
||||
|
||||
utils.ThermalSensorWidget(
|
||||
font=Config.get('font_topbar', 'Arial'),
|
||||
|
@ -342,9 +381,9 @@ class Kuro(BaseTheme):
|
|||
widgets.append(widget.Systray(**self.widget_defaults))
|
||||
|
||||
widgets.extend([
|
||||
widget.CurrentLayoutIcon(),
|
||||
utils.KuroCurrentLayoutIcon(custom_icon_paths=Config.get('custom_layout_icon_paths', [])),
|
||||
widget.Clock(format="%a %d %b, %H:%M", **self.widget_defaults),
|
||||
utils.CheckUpdatesYaourt(
|
||||
utils.CheckUpdatesYay(
|
||||
colour_no_updates=Config.get('updates_colour_none', '#ffffff'),
|
||||
colour_have_updates=Config.get('updates_colour_available', '#ff0000'),
|
||||
display_format=Config.get('updates_display_format', 'Updates: {updates}'),
|
||||
|
@ -442,16 +481,67 @@ class Kuro(BaseTheme):
|
|||
# Util functions
|
||||
@staticmethod
|
||||
def redraw_bar(qtile):
|
||||
for b in qtile.topbars:
|
||||
b.draw()
|
||||
for s in qtile.screens:
|
||||
s.top.draw()
|
||||
|
||||
@staticmethod
|
||||
def update_screens(qtile):
|
||||
out = utils.call_process(["xrandr", "--current"])
|
||||
laptop_screen = None
|
||||
screens = []
|
||||
for x in out.split("\n"):
|
||||
if " connected " in x:
|
||||
if Config.get("laptop_screen", None) is not None and Config.get("laptop_screen", None) in x:
|
||||
laptop_screen = x
|
||||
else:
|
||||
screens.append(x)
|
||||
|
||||
# Only configure two screens. Open arandr if more screens are present.
|
||||
if laptop_screen is not None and len(screens) == 1:
|
||||
laptop = laptop_screen.split()[0]
|
||||
other = screens[0].split()[0]
|
||||
utils.call_process(["xrandr", "--output", laptop, "--below", other])
|
||||
qtile.cmd_restart()
|
||||
elif laptop_screen is not None and len(screens) > 1:
|
||||
utils.execute("arandr")
|
||||
|
||||
# QTile base callbacks
|
||||
def callback_startup_once(self, *args, **kwargs):
|
||||
pass
|
||||
#Kuro.update_screens(self.qtile)
|
||||
|
||||
def callback_startup(self):
|
||||
utils.execute("sleep 3")
|
||||
|
||||
self.log_info("Restoring wallpaper...")
|
||||
utils.execute_once("nitrogen --restore")
|
||||
#
|
||||
# self.log_info("Restoring previous wallpaper...")
|
||||
# utils.execute_once("nitrogen --restore")
|
||||
self.update_wallpaper(self.qtile)
|
||||
|
||||
if self.current_wallpaper:
|
||||
utils.execute_once(["wal", "-n", "-i", "{}".format(self.current_wallpaper)])
|
||||
else:
|
||||
|
||||
wallpaper = None
|
||||
if os.path.isfile("/home/kevin/.cache/wal/colors.json"):
|
||||
with open("/home/kevin/.cache/wal/colors.json", 'r') as f:
|
||||
try:
|
||||
wallpaper = json.load(f)['wallpaper']
|
||||
except KeyError:
|
||||
wallpaper = None
|
||||
if wallpaper:
|
||||
Kuro.set_wallpaper(self.qtile, wallpaper)
|
||||
else:
|
||||
utils.execute_once("nitrogen --restore")
|
||||
|
||||
self.log_info("Starting compositor...")
|
||||
utils.execute_once("compton -b")
|
||||
|
||||
# Update color scheme
|
||||
self.initialize_colorscheme()
|
||||
|
||||
# Update color scheme
|
||||
Kuro.update_colorscheme(self.qtile)
|
||||
|
||||
# display = os.environ['DISPLAY']
|
||||
#
|
||||
# if not display:
|
||||
|
@ -467,7 +557,8 @@ class Kuro(BaseTheme):
|
|||
# return True
|
||||
|
||||
def callback_focus_change(self, *args, **kwargs):
|
||||
kb_handle_focus_change(self)
|
||||
if self.do_keyboard_updates:
|
||||
kb_handle_focus_change(self)
|
||||
|
||||
initial_windows = []
|
||||
|
||||
|
@ -487,6 +578,9 @@ class Kuro(BaseTheme):
|
|||
|
||||
self.callback_client_new()
|
||||
|
||||
# Update color scheme
|
||||
Kuro.update_colorscheme(self.qtile)
|
||||
|
||||
def callback_client_new(self, *args, **kwargs):
|
||||
if len(self.initial_windows) > 0:
|
||||
init = self.initial_windows.copy()
|
||||
|
@ -501,5 +595,140 @@ class Kuro(BaseTheme):
|
|||
if r.matches(window):
|
||||
self.qtile.dgroups.remove_rule(rid)
|
||||
self.initial_windows.remove((pid, gname))
|
||||
self.log_info("Removed group rule for PID {}, window {}".format(pid, window.name))
|
||||
self.log_info("Removed group rule for PID {}, window {}".format(pid,
|
||||
window.name))
|
||||
self.log_info(str(self.qtile.dgroups.rules_map))
|
||||
|
||||
@staticmethod
|
||||
def update_wallpaper(qtile):
|
||||
wallpapers = []
|
||||
wallpaper_dir = Config.get("desktop_bg_folder", "")
|
||||
try:
|
||||
wallpapers = os.listdir(wallpaper_dir)
|
||||
except os.error:
|
||||
pass
|
||||
|
||||
if wallpapers:
|
||||
qtile.theme_instance.current_wallpaper = os.path.join(wallpaper_dir, random.choice(wallpapers))
|
||||
Kuro.set_wallpaper(qtile, qtile.theme_instance.current_wallpaper)
|
||||
else:
|
||||
utils.execute_once("nitrogen --restore")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def set_wallpaper(qtile, filename):
|
||||
utils.execute_once("wal-nitrogen {}".format(filename))
|
||||
qtile.theme_instance.current_wallpaper = filename
|
||||
Kuro.update_colorscheme(qtile)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def update_mediaclients(*args, **kwargs):
|
||||
return str(str(args) + " " + str(kwargs))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def initialize_colorscheme():
|
||||
colors = None
|
||||
if os.path.isfile("/home/kevin/.cache/wal/colors.json"):
|
||||
with open("/home/kevin/.cache/wal/colors.json", 'r') as f:
|
||||
try:
|
||||
colors = json.load(f)['colors']
|
||||
except KeyError:
|
||||
colors = None
|
||||
|
||||
if colors:
|
||||
# Update Config
|
||||
Config.foreground = colors['color15']
|
||||
Config.background = colors['color0']
|
||||
Config.highlight = colors['color3']
|
||||
Config.inactive_light = colors['color4']
|
||||
Config.inactive_dark = colors['color5']
|
||||
|
||||
@staticmethod
|
||||
def update_colorscheme(qtile):
|
||||
"""
|
||||
:type qtile: libqtile.manager.Qtile
|
||||
"""
|
||||
if qtile.theme_instance.current_wallpaper:
|
||||
utils.execute(["wal", "-n", "-i", "{}".format(qtile.theme_instance.current_wallpaper)])
|
||||
|
||||
colors = None
|
||||
if os.path.isfile("/home/kevin/.cache/wal/colors.json"):
|
||||
with open("/home/kevin/.cache/wal/colors.json", 'r') as f:
|
||||
try:
|
||||
colors = json.load(f)['colors']
|
||||
except KeyError:
|
||||
colors = None
|
||||
|
||||
if colors:
|
||||
# Update Config
|
||||
Config.foreground = colors['color15']
|
||||
Config.background = colors['color0']
|
||||
Config.highlight = colors['color3']
|
||||
Config.inactive_light = colors['color4']
|
||||
Config.inactive_dark = colors['color5']
|
||||
|
||||
# Update border colors in layouts
|
||||
for group in qtile.groups:
|
||||
for layout in group.layouts:
|
||||
if isinstance(layout, kuro_layouts.KuroWmii):
|
||||
layout.border_focus = colors['color15']
|
||||
layout.border_focus_stack = colors['color1']
|
||||
layout.border_normal = colors['color1']
|
||||
layout.border_normal_stack = colors['color1']
|
||||
|
||||
for screen in qtile.screens:
|
||||
bar = screen.top
|
||||
bar.background = colors['color1']
|
||||
bar.drawer.clear(bar.background)
|
||||
for w in bar.widgets:
|
||||
if hasattr(w, '_update_drawer'):
|
||||
try:
|
||||
w._update_drawer()
|
||||
except Exception as e:
|
||||
logger.error("Error while updating drawer: {}".format(e))
|
||||
|
||||
if hasattr(w, 'foreground'):
|
||||
w.foreground = colors['color15']
|
||||
|
||||
if hasattr(w, 'foreground_normal'):
|
||||
w.foreground_normal = colors['color15']
|
||||
|
||||
if hasattr(w, 'foreground_alert'):
|
||||
w.foreground_alert = colors['color3']
|
||||
|
||||
if hasattr(w, 'border'):
|
||||
w.border = colors['color15']
|
||||
|
||||
if hasattr(w, 'active'):
|
||||
w.active = colors['color15']
|
||||
|
||||
if hasattr(w, 'highlight_color'):
|
||||
w.highlight_color = colors['color3']
|
||||
|
||||
if hasattr(w, 'inactive'):
|
||||
w.inactive = colors['color8']
|
||||
|
||||
if hasattr(w, 'this_current_screen_border'):
|
||||
w.this_current_screen_border = colors['color15']
|
||||
|
||||
if hasattr(w, 'this_screen_border'):
|
||||
w.this_screen_border = colors['color15']
|
||||
|
||||
if hasattr(w, 'other_current_screen_border'):
|
||||
w.other_current_screen_border = colors['color8']
|
||||
|
||||
if hasattr(w, 'other_screen_border'):
|
||||
w.other_screen_border = colors['color8']
|
||||
|
||||
if isinstance(w, utils.AudioVisualizerWidget):
|
||||
w.graph_color = colors['color15']
|
||||
w.fill_color = colors['color8']
|
||||
|
||||
bar.draw()
|
||||
|
||||
utils.notify(
|
||||
"Updated colorscheme!",
|
||||
"active: {}, inactive: {}".format(colors['color15'], colors['color1'])
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue