dotfiles/.config/qtile/config.py

198 lines
6.1 KiB
Python
Raw Normal View History

2015-07-08 16:24:21 +02:00
#
# Copyright (c) 2015 Rodolphe Breard
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
from libqtile.config import Key, Screen, Group, Drag, Click
from libqtile import layout, bar, widget, hook
2015-07-08 16:24:21 +02:00
from libqtile.command import lazy
from glob import glob
import subprocess
import random
import os
class ConfigWrapper:
def __init__(self):
self.mod = 'mod4'
self.term = 'termite'
2015-07-08 16:24:21 +02:00
self.border_focus = '#424242'
self.date_format = '%a %d %B %Y %H:%M'
self.keys = []
self.groups = []
self.layouts = []
2015-07-13 14:04:40 +02:00
def _add_key(self, key, action, *, extra_mod=None, no_mod=False):
mod = []
if not no_mod:
mod.append(self.mod)
2015-07-08 16:24:21 +02:00
if extra_mod:
mod.append(extra_mod)
k = Key(mod, key, action)
self.keys.append(k)
2015-07-18 14:52:27 +02:00
def _add_group(self, name, position, **kwargs):
grp = Group(name, position=position, **kwargs)
2015-07-08 16:24:21 +02:00
self.groups.append(grp)
access_key = str(position + 1)
self._add_key(access_key, lazy.group[name].toscreen())
self._add_key(access_key, lazy.window.togroup(name), extra_mod='shift')
def _has_battery(self):
return len(glob('/sys/class/power_supply/BAT*')) > 0
2015-07-08 16:24:21 +02:00
def set_wallpaper(self):
images = glob(os.path.expanduser('~/pictures/wallpapers/enabled/*'))
if images:
image = random.choice(images)
subprocess.call(['feh', '--bg-fill', image])
def set_keys(self):
self._add_key('j', lazy.layout.up())
self._add_key('k', lazy.layout.down())
self._add_key('Tab', lazy.layout.next())
self._add_key('space', lazy.layout.rotate(), extra_mod='shift')
self._add_key('space', lazy.next_layout())
2016-08-30 21:09:43 +02:00
self._add_key('f', lazy.window.toggle_floating())
2015-07-08 16:24:21 +02:00
self._add_key('Right', lazy.screen.next_group())
self._add_key('Left', lazy.screen.prev_group())
self._add_key('w', lazy.window.kill())
self._add_key('Return', lazy.spawn(self.term))
2015-07-08 17:07:38 +02:00
self._add_key('l', lazy.spawn('xscreensaver-command --lock'))
2015-07-13 14:04:40 +02:00
self._add_key(
'Print',
lazy.spawn("scrot -e 'mv $f ~/pictures/ 2>/dev/null'"),
no_mod=True
)
2015-07-08 16:24:21 +02:00
self._add_key('r', lazy.spawncmd())
self._add_key('r', lazy.restart(), extra_mod='control')
self._add_key('q', lazy.shutdown(), extra_mod='control')
return self.keys
def set_groups(self):
2015-07-18 14:52:27 +02:00
groups = [
('main', {'layout': 'xmonad-tall'}),
('www', {'layout': 'max'}),
('remote', {'layout': 'max'}),
('email', {'layout': 'max'}),
('media', {'layout': 'xmonad-tall'}),
2016-10-30 12:02:05 +01:00
('misc 1', {'layout': 'floating'}),
('misc 2', {'layout': 'floating'}),
2015-07-18 14:52:27 +02:00
]
for i, group in enumerate(groups):
name, opts = group
self._add_group(name, i, **opts)
2015-07-08 16:24:21 +02:00
return self.groups
def set_layouts(self):
self.layouts = [
2015-07-18 14:52:27 +02:00
layout.MonadTall(
border_focus=self.border_focus,
align=1,
name='xmonad-tall'
),
layout.Max(name='max'),
layout.Stack(border_focus=self.border_focus, name='stack'),
layout.Floating(border_focus=self.border_focus, name='floating'),
2015-07-08 16:24:21 +02:00
]
return self.layouts
2015-08-16 17:41:15 +02:00
def graph_params(self, color):
return dict(
width=70,
border_width=1,
line_width=1,
graph_color=color,
border_color=color,
fill_color=color,
)
2015-07-08 16:24:21 +02:00
def set_screens(self):
widgets = [
widget.GroupBox(),
widget.Prompt(),
widget.WindowName(),
widget.Systray(),
widget.Battery(
charge_char='',
discharge_char='',
update_delay=5
),
widget.MemoryGraph(**self.graph_params('#CFCE44')),
widget.CPUGraph(**self.graph_params('#96AECF')),
widget.Clock(format=self.date_format),
]
if not self._has_battery():
widgets = [w for w in widgets if not isinstance(w, widget.Battery)]
2015-07-08 16:24:21 +02:00
screens = [
Screen(
top=bar.Bar(widgets, 30)
2015-07-08 16:24:21 +02:00
),
]
return screens
def set_mouse(self):
mouse = [
Drag(
[self.mod],
'Button1',
lazy.window.set_position_floating(),
start=lazy.window.get_position()
),
Drag(
[self.mod],
'Button3',
lazy.window.set_size_floating(),
start=lazy.window.get_size()
),
Click(
[self.mod],
'Button2',
lazy.window.bring_to_front()
)
]
return mouse
@hook.subscribe.startup
def startup():
2015-07-08 16:24:21 +02:00
cnf = ConfigWrapper()
cnf.set_wallpaper()
if __name__ in ['config', '__main__']:
cnf = ConfigWrapper()
2015-07-08 16:24:21 +02:00
layouts = cnf.set_layouts()
2015-07-18 14:52:27 +02:00
groups = cnf.set_groups()
2015-07-08 16:24:21 +02:00
screens = cnf.set_screens()
mouse = cnf.set_mouse()
keys = cnf.set_keys()
dgroups_key_binder = None
dgroups_app_rules = []
main = None
follow_mouse_focus = True
bring_front_click = False
cursor_warp = False
floating_layout = layout.Floating()
auto_fullscreen = True
wmname = 'LG3D'
widget_defaults = {
2015-11-03 00:43:45 +01:00
'font': 'freesans',
2015-07-08 16:24:21 +02:00
'fontsize': 16,
'padding': 3,
}