Add KuroWMII layout that manages new windows in a way I like, add some more shortcuts, improve battery icon, automatically open programs on workspaces and remove the GroupRules for them after they spawn so that new instances of that app don't open on that workspace any more.

This commit is contained in:
Kevin Alberts 2017-12-02 09:29:26 +01:00
parent b9224b667d
commit 9a3fdf1b65
5 changed files with 176 additions and 14 deletions

View file

@ -7,8 +7,9 @@ from kuro.utils import general as utils
# Import variables
from kuro.base import BaseTheme
from kuro.utils.general import display_wm_class
from kuro.utils.general import display_wm_class, test_popups
from kuro.utils.kb_backlight import handle_focus_change as kb_handle_focus_change
from kuro.utils import layouts as kuro_layouts
try:
from kuro.config import Config
@ -103,9 +104,17 @@ class Kuro(BaseTheme):
# Super-R to start dmenu_run
Key([self.mod], "r", lazy.spawn(Config.get('app_launcher', "dmenu_run"))),
# Super-B to start webbrowser
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"))),
# Super-Shift-R to start spawncmd
Key([self.mod, "shift"], "r", lazy.spawncmd()),
# Lock shortcut
Key([self.mod], "l", lazy.spawn(Config.get('lock_command', "i3lock"))),
# Backlight keys
Key([], "XF86MonBrightnessUp", lazy.spawn(Config.get('cmd_brightness_up', 'xbacklight -inc 10'))),
@ -120,9 +129,6 @@ class Kuro(BaseTheme):
# Restart QTile
Key([self.mod, "control"], "r", lazy.restart()),
# Redraw the top bar
Key([self.mod, "shift", "control"], "r", lazy.function(self.redraw_bar)),
# Shutdown QTile
Key([self.mod, "control"], "q", lazy.shutdown()),
@ -132,20 +138,39 @@ class Kuro(BaseTheme):
##
# Debug keyboard shortcuts
##
Key([self.mod, "control"], "w", lazy.function(display_wm_class))
Key([self.mod, "control"], "w", lazy.function(display_wm_class)),
# Redraw the top bar
Key([self.mod, "shift", "control"], "r", lazy.function(self.redraw_bar)),
# Spawn a popup, and despawn it after 3 seconds
Key([self.mod, "control"], "p", lazy.function(test_popups)),
]
def init_groups(self):
self.log_debug("Initializing groups")
groups = []
# http://fontawesome.io/cheatsheet
return [Group(i) for i in ""]
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"))
groups.append(Group("", spawn="quasselclient"))
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(""))
return groups
def init_layouts(self):
self.log_debug("Initializing layouts")
return [
layout.Wmii(
kuro_layouts.KuroWmii(
border_focus=Config.get('colour_border_focus', "#ffffff"),
border_focus_stack=Config.get('colour_border_normal', "#777777"),
border_normal=Config.get('colour_border_normal', "#777777"),
@ -261,7 +286,7 @@ class Kuro(BaseTheme):
frequency=2,
),
widget.BatteryIcon(
utils.KuroBatteryIcon(
battery_name=Config.get('battery_name', 'BAT0'),
energy_full_file=Config.get('battery_energy_full_file', 'charge_full'),
energy_now_file=Config.get('battery_energy_now_file', 'charge_now'),
@ -378,6 +403,8 @@ class Kuro(BaseTheme):
self.log_debug("Updating keys")
for i, g in enumerate(self.groups):
if i == 9:
i = -1
# mod1 + number = switch to group
self.keys.append(
Key([self.mod], str(i + 1), lazy.group[g.name].toscreen())
@ -441,3 +468,38 @@ class Kuro(BaseTheme):
def callback_focus_change(self, *args, **kwargs):
kb_handle_focus_change(self)
initial_windows = []
def callback_startup_complete(self, *args, **kwargs):
# Only run on first startup
if not self.qtile.no_spawn:
dg = self.qtile.dgroups
for r in dg.rules:
pid = -1
# noinspection PyProtectedMember
for r2 in r.match._rules:
if r2[0] == "net_wm_pid":
pid = r2[1]
break
if pid != -1:
self.initial_windows.append((pid, r.group))
self.callback_client_new()
def callback_client_new(self, *args, **kwargs):
if len(self.initial_windows) > 0:
init = self.initial_windows.copy()
for pid, gname in init:
for group in self.qtile.groups:
if len(group.windows) > 0:
for window in group.windows:
w_pid = window.window.get_net_wm_pid()
if pid == w_pid:
c = self.qtile.dgroups.rules_map.copy()
for rid, r in c.items():
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(str(self.qtile.dgroups.rules_map))