Last active
August 29, 2015 14:15
-
-
Save onjin/32e658dd856358c6d62c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import subprocess | |
from time import sleep | |
from threading import Thread | |
import logging | |
from logging.handlers import RotatingFileHandler | |
from libqtile.config import Key, Screen, Group, Drag, Click, Match | |
from libqtile.command import lazy | |
from libqtile import layout, bar, widget, hook | |
# logging {{{ | |
logger = logging.getLogger() | |
logger.setLevel(logging.WARN) | |
handler = RotatingFileHandler( | |
os.path.join(os.getenv('HOME'), '.qtilelog'), maxBytes=10240000, | |
backupCount=7 | |
) | |
handler.setLevel(logging.WARN) | |
logger.addHandler(handler) | |
# logging }}} | |
# functions {{{ | |
def is_running(process): | |
s = subprocess.Popen(["ps", "axw"], stdout=subprocess.PIPE) | |
for x in s.stdout: | |
if re.search(process, x): | |
return True | |
return False | |
def run_once(process): | |
if not is_running(process): | |
return subprocess.Popen(process.split()) | |
def move_window_to_screen(screen): | |
def cmd(qtile): | |
w = qtile.currentWindow | |
qtile.toScreen(screen) | |
if w is not None: | |
w.togroup(qtile.screens[screen].group.name) | |
return cmd | |
def focus_screen(screen): | |
def cmd(qtile): | |
qtile.toScreen(screen) | |
return cmd | |
# functions }}} | |
mod = "mod4" | |
keys = [ | |
# Switch between windows in current stack pane | |
Key([mod], "j", lazy.layout.up()), | |
Key([mod], "k", lazy.layout.down()), | |
Key([mod], "Tab", lazy.layout.down()), | |
Key([mod, 'shift'], "Tab", lazy.layout.up()), | |
# Move windows up or down in current stack | |
Key([mod, "control"], "j", lazy.layout.shuffle_up()), | |
Key([mod, "control"], "k", lazy.layout.shuffle_down()), | |
# Toggle between split and unsplit sides of stack. | |
# Split = all windows displayed | |
# Unsplit = 1 window displayed, like Max layout, but still with | |
# multiple stack panes | |
Key([mod, "shift"], "s", lazy.layout.toggle_split()), | |
# terminals | |
Key([mod], "Return", lazy.spawn("gnome-terminal --role terminal")), | |
Key([mod, 'shift'], "Return", lazy.spawn("gnome-terminal --role shell")), | |
# Toggle between different layouts as defined below | |
Key([mod], "space", lazy.nextlayout()), | |
Key([mod, 'shift'], "space", lazy.prevlayout()), | |
Key([mod], "9", lazy.screen.prevgroup(skip_managed=True)), | |
Key([mod], "0", lazy.screen.nextgroup(skip_managed=True)), | |
Key([mod, 'shift'], "c", lazy.window.kill()), | |
Key([mod, "control"], "r", lazy.restart()), | |
Key([mod, "control"], "q", lazy.shutdown()), | |
Key([mod], "r", lazy.spawncmd()), | |
# layout swap | |
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()), | |
# screen change | |
Key([mod], "1", lazy.function(focus_screen(1))), | |
Key([mod], "2", lazy.function(focus_screen(0))), | |
# Key([mod, 'shift'], "1", lazy.function(move_window_to_screen(1))), | |
# Key([mod, 'shift'], "2", lazy.function(move_window_to_screen(0))), | |
] | |
# matched wm_classes for all groups | |
common_wm_classes = ['nagstamon', 'Nagstamon'] | |
def merged_wm_class(wm_classes=None): | |
if not wm_classes: | |
return common_wm_classes | |
return wm_classes + common_wm_classes | |
groups_conf = [ | |
{ | |
'_name': 'term', | |
'_accesskey': 'a', | |
'init': True, | |
'persist': True, | |
'exclusive': True, | |
'matches': [Match(role=['terminal'], wm_class=merged_wm_class())], | |
'layout': 'monadtall', | |
}, | |
{ | |
'_name': 'www', | |
'_accesskey': 's', | |
'init': False, | |
'persist': False, | |
'exclusive': True, | |
'matches': [Match(wm_class=merged_wm_class(['firefox-onjin']))], | |
'layout': 'max', | |
}, | |
{ | |
'_name': 'edit', | |
'_accesskey': 'd', | |
'init': False, | |
'persist': False, | |
'exclusive': True, | |
'matches': [Match(wm_class=merged_wm_class([ | |
'gvim', 'Gvim', 'gedit', 'Gedit' | |
]))], | |
'layout': 'max', | |
}, | |
{ | |
'_name': 'ingre', | |
'_accesskey': 'f', | |
'init': False, | |
'persist': False, | |
'exclusive': True, | |
'matches': [Match(wm_class=merged_wm_class(['firefox-ingre']))], | |
'layout': 'max', | |
}, | |
{ | |
'_name': 'hon', | |
'_accesskey': 'u', | |
'init': False, | |
'persist': False, | |
'exclusive': True, | |
'matches': [Match(wm_class=merged_wm_class([ | |
"hon-x86_64", "Heroes of Newerth", "hon_updater", | |
"Heroes of Newerth - Updater", | |
]))], | |
'layout': 'max', | |
}, | |
{ | |
'_name': 'read', | |
'_accesskey': 'i', | |
'init': False, | |
'persist': False, | |
'exclusive': False, | |
'matches': [Match(wm_class=merged_wm_class([ | |
"acroread", "Acroread" | |
]))], | |
'layout': 'max', | |
}, | |
{ | |
'_name': 'shell', | |
'_accesskey': 'o', | |
'init': True, | |
'persist': True, | |
'exclusive': True, | |
'matches': [Match(role=['shell'], wm_class=merged_wm_class())], | |
'layout': 'treetab', | |
}, | |
{ | |
'_name': 'mail', | |
'_accesskey': 'p', | |
'init': False, | |
'persist': False, | |
'exclusive': True, | |
'matches': [Match(wm_class=merged_wm_class([ | |
'Thunderbird', 'thunderbird' | |
]))], | |
'layout': 'max', | |
}, | |
{ | |
'_name': 'mud', | |
'_accesskey': 'm', | |
'init': False, | |
'persist': False, | |
'exclusive': True, | |
'matches': [Match(wm_class=merged_wm_class([ | |
"kildclient", "Kildclient" | |
]))], | |
'layout': 'max', | |
}, | |
] | |
groups = [] | |
for position, conf in enumerate(groups_conf, 1): | |
accesskey = conf['_accesskey'] | |
del conf['_accesskey'] | |
name = conf['_name'] | |
del conf['_name'] | |
conf['position'] = position | |
name = "%s.%s" % (name, accesskey) | |
groups.append(Group(name, **conf)) | |
keys.append( | |
Key([mod], str(accesskey), lazy.group[name].toscreen()) | |
) | |
# mod1 + shift + letter of group = switch to & move focused window to group | |
keys.append( | |
Key([mod, "shift"], str(accesskey), lazy.window.togroup(name)) | |
) | |
widget_defaults = dict( | |
font='Arial', | |
fontsize=14, | |
padding=3, | |
) | |
layouts = [ | |
layout.MonadTall(), | |
layout.TreeTab( | |
active_bg='ff0000', | |
active_fg='ffffff', | |
inactive_bg='222222', | |
inactive_fg='999999', | |
), | |
layout.Max(), | |
layout.Floating() | |
] | |
screens = [ | |
Screen( | |
top=bar.Bar( | |
[ | |
widget.GroupBox(), | |
widget.Prompt(), | |
widget.WindowName(), | |
widget.Systray(icon_size=14), | |
widget.Volume(update_interval=0.2, emoji=True), | |
widget.Clock(format='%Y-%m-%d %a %H:%M %p'), | |
widget.Sep(), | |
widget.CurrentLayout(), | |
], | |
30, | |
), | |
), | |
Screen( | |
top=bar.Bar( | |
[ | |
widget.GroupBox(), | |
widget.Prompt(), | |
widget.WindowName(), | |
widget.Clock(format='%Y-%m-%d %a %H:%M %p'), | |
widget.Sep(), | |
widget.CurrentLayout(), | |
], | |
30, | |
), | |
), | |
] | |
# 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()) | |
] | |
dgroups_key_binder = None | |
dgroups_app_rules = [] | |
main = None | |
follow_mouse_focus = False | |
bring_front_click = False | |
cursor_warp = False | |
floating_layout = layout.Floating() | |
auto_fullscreen = True | |
# 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" | |
float_windows = set([ | |
"nagstamon", "x11-ssh-askpass", "nitrogen" | |
]) | |
def should_be_floating(w): | |
wm_class = w.get_wm_class() | |
if isinstance(wm_class, tuple): | |
for cls in wm_class: | |
if cls.lower() in float_windows: | |
return True | |
else: | |
if wm_class.lower() in float_windows: | |
return True | |
return w.get_wm_type() == 'dialog' or bool(w.get_wm_transient_for()) | |
def _client_info(c): | |
return "name: %s, wm_class: %s, wm_type: %s, wm_transient_for: %s" % ( | |
c.name, c.window.get_wm_class(), c.window.get_wm_type(), | |
c.window.get_wm_transient_for() | |
) | |
@hook.subscribe.changegroup | |
def changegroup(group): | |
logging.warn( | |
'HOOK: subscribe.changegroup' | |
) | |
@hook.subscribe.setgroup | |
def setgroup(): | |
logging.warn( | |
'HOOK: subscribe.setgroup' | |
) | |
@hook.subscribe.current_screen_change | |
def current_screen_change(): | |
logging.warn( | |
'HOOK: subscribe.current_screen_change' | |
) | |
@hook.subscribe.client_new | |
def client_new(client): | |
logging.warn( | |
'HOOK: subscribe.client_new CLIENT:%s' % _client_info(client) | |
) | |
if should_be_floating(client.window): | |
logging.warn('CLIENT/%s - set floating' % client.name) | |
client.floating = True | |
@hook.subscribe.startup | |
def startup(): | |
def blocking(): | |
sleep(1) | |
run_once('unclutter -idle 5') | |
run_once('dropbox start') | |
run_once('gnome-settings-daemon') | |
run_once('nm-applet') | |
run_once('/usr/bin/nitrogen --restore') | |
run_once('python /home/onjin/bin/tidybattery') | |
Thread(target=blocking).start() | |
logging.warn('started') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment