Created
July 6, 2015 18:59
-
-
Save rsbowman/090517b84ff12e6bb2ba to your computer and use it in GitHub Desktop.
QTile Config
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# | |
import re, subprocess | |
from libqtile.config import Key, Click, Drag, Screen, Group, Match, Rule | |
from libqtile.command import lazy | |
from libqtile import layout, bar, widget, hook | |
from libqtile.dgroups import simple_key_binder | |
from libqtile import hook | |
def get_n_screens(): | |
n_screens = subprocess.check_output( | |
"xrandr -q | grep ' connected' | wc -l", | |
shell=True) | |
try: | |
n_screens = int(n_screens) | |
except ValueError: | |
n_screens = 1 | |
return n_screens | |
def get_mouse_loc(loc_re=re.compile("x:(\d+)\s+y:(\d+)")): | |
output = subprocess.check_output("xdotool getmouselocation") | |
m = loc_re.match(output) | |
if m: | |
return map(int, m.groups()) | |
else: | |
return 0, 0 | |
n_screens = get_n_screens() | |
mod = 'mod4' | |
keys = [ | |
# Movement | |
Key([mod], "h", lazy.layout.left()), | |
Key([mod], "l", lazy.layout.right()), | |
Key([mod], "j", lazy.layout.down()), | |
Key([mod], "k", lazy.layout.up()), | |
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()), | |
# size | |
Key([mod], "period", lazy.layout.grow()), | |
Key([mod], "comma", lazy.layout.shrink()), | |
Key([mod], "n", lazy.layout.normalize()), | |
Key([mod, "shift"], "q", lazy.window.kill()), | |
Key([mod, "shift"], "r", lazy.restart()), | |
Key([mod, "shift"], "space", lazy.window.toggle_floating()), | |
#Key([mod, "shirt"], "comma", lazy.function(move_to_other_screen)), | |
Key([mod], "Return", lazy.spawn("gnome-terminal")), | |
Key([mod, "shift"], "e", lazy.shutdown()), | |
Key([mod], "d", lazy.spawncmd()) | |
] | |
# This allows you to drag windows around with the mouse if you want. | |
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()) | |
] | |
layouts = [layout.MonadTall(follow_max=True)] | |
if False: | |
def log(msg, path="/home/rsbowman/qtile-my.log"): | |
with open(path, "a") as f: | |
f.write(msg + "\n") | |
else: | |
def log(msg): | |
pass | |
class GroupChanger(object): | |
def __init__(self, groups, n_screens): | |
self.groups = groups | |
self.n_screens = n_screens | |
self.groups_to_screens = {} | |
for g in self.groups: | |
self.groups_to_screens[g.name] = 0 | |
def _find_group(self, qtile, group_name): | |
for g in qtile.groups: | |
if g.name == group_name: | |
# log("returning g: {}".format(g.info())) | |
return g | |
def group_to_screen(self, group_name): | |
def callback(qtile): | |
log("GTS: screen map {}".format(self.groups_to_screens)) | |
group = self._find_group(qtile, group_name) | |
log("gts: getting group_screen") | |
group_screen = self.groups_to_screens[group.name] | |
log("gts: group '{}' on screen {}".format( | |
group.name, group_screen)) | |
log("gts: group.screen {}".format(group.screen)) | |
#if not group.screen or group.screen.index != group_screen: | |
log("gts: group_cmd_toscreen {}".format(group_screen)) | |
group.cmd_toscreen(group_screen) | |
log("gts: lazy.toscreen {}".format(group_screen)) | |
if qtile.currentScreen != group.screen: | |
subprocess.call("swarp {} {}".format( | |
100 if group_screen == 0 else 2000, 100), shell=True) | |
log("Done!") | |
return callback | |
def _find_group_for_screen(self, qtile, screen_idx): | |
log("_find_group_for_screen {}".format(screen_idx)) | |
for g in qtile.groups: | |
log("_fgfs: g.screen {}".format(g.screen)) | |
if g.screen and g.screen.index == screen_idx: | |
log("_fgfs: returning {}".format(g.name)) | |
return g | |
def change_screen(self, src_screen_idx): | |
def callback(qtile): | |
log("cs: enter") | |
group = self._find_group_for_screen(qtile, src_screen_idx) | |
log("cs: ssidx {}, nscreens {}".format(src_screen_idx, | |
self.n_screens)) | |
dest_idx = min(1 - src_screen_idx, self.n_screens - 1) | |
self.groups_to_screens[group.name] = dest_idx | |
log("cs: cmd_toscreen {}".format(dest_idx)) | |
group.cmd_toscreen(dest_idx) | |
log("cs: lazy.toscreen {}".format(dest_idx)) | |
lazy.toscreen(dest_idx) | |
return callback | |
groups = [Group(n) for n in "1234567890"] | |
group_changer = GroupChanger(groups, n_screens) | |
for i, group in enumerate(groups): | |
name = group.name | |
keys.append(Key([mod], name, | |
lazy.function(group_changer.group_to_screen(name)))) | |
keys.append(Key([mod, "shift"], name, | |
lazy.window.togroup(name))) | |
#group_changer.group_change_screen(name)))) | |
## for old times sake: | |
keys.append(Key([mod, "control"], name, lazy.group[name].toscreen())) | |
keys.append(Key([mod, "shift", "control"], name, lazy.window.togroup(name))) | |
keys.append(Key([mod, "shift"], "comma", | |
lazy.function(group_changer.change_screen(1)))) | |
keys.append(Key([mod, "shift"], "period", | |
lazy.function(group_changer.change_screen(0)))) | |
gloss_theme = { | |
"bg_dark": ["#505050", | |
"#303030", | |
"#202020", | |
"#101010", | |
"#202020", | |
"#303030", | |
"#505050"], | |
"bg_light": ["#707070", | |
"#505050", | |
"#505050", | |
"#505050", | |
"#505050", | |
"#707070"], | |
"font_color": ["#ffffff", "#ffffff", "#cacaca", "#707070"], | |
# groupbox | |
"gb_selected": ["#707070", | |
"#505050", | |
"#404040", | |
"#303030", | |
"#404040", | |
"#505050", | |
"#707070"], | |
"gb_urgent": ["#ff0000", | |
"#820202", | |
"#820202", | |
"#820202", | |
"#820202", | |
"#ff0000" | |
] | |
} | |
theme = gloss_theme | |
widget_defaults = dict(font="Meslo LG L Regular for Powerline", | |
fontsize=14) | |
def style_bar(*widgets): | |
all_widgets = [] | |
for w_list in widgets: | |
widget_defaults = {} | |
for w in w_list: | |
w.add_defaults(widget_defaults) | |
all_widgets.append( | |
widget.TextBox(text=u"◥", fontsize=44, padding=-1, | |
font="Arial", foreground=theme["bg_dark"])) | |
all_widgets.extend(w_list) | |
all_widgets.append( | |
widget.TextBox(text=u"◣", fontsize=44, padding=-1, | |
font="Arial", foreground=theme["bg_dark"])) | |
return all_widgets | |
def setup_screens(n_screens): | |
bar_height = 26 | |
top_bar = bar.Bar([ | |
widget.Prompt(**widget_defaults), | |
widget.WindowName(background=theme["bg_dark"], **widget_defaults), | |
widget.TextBox(text=u"◣", fontsize=44, padding=-1, | |
font="Arial", foreground=theme["bg_dark"]) | |
], bar_height, opacity=0.9) | |
aux_top_bar = bar.Bar([ | |
widget.WindowName(background=theme["bg_dark"], **widget_defaults), | |
widget.TextBox(text=u"◣", fontsize=44, padding=-1, | |
font="Arial", foreground=theme["bg_dark"]) | |
], bar_height, opacity=0.9) | |
main_bar = bar.Bar([ | |
widget.GroupBox(**widget_defaults), | |
widget.TextBox("Cpu", **widget_defaults), | |
widget.CPUGraph(core=0, graph_color='#18BAEB', fill_color='#1667EB.3', | |
**widget_defaults), | |
widget.CPUGraph(core=1, graph_color='#18BAEB', fill_color='#1667EB.3', | |
**widget_defaults), | |
widget.TextBox("Mem", **widget_defaults), | |
widget.MemoryGraph(graph_color='#00FE81', fill_color='#00B25B.3', | |
**widget_defaults), | |
widget.TextBox("Swap", **widget_defaults), | |
widget.SwapGraph(graph_color='#00FE81', fill_color='#00B25B.3', | |
**widget_defaults), | |
widget.TextBox("Net", **widget_defaults), | |
widget.NetGraph(graph_color='#18BAEB', fill_color='#1667EB.3', | |
**widget_defaults), | |
widget.Spacer(), | |
widget.Battery(**widget_defaults), | |
widget.Systray(**widget_defaults), | |
widget.Clock(format='%Y-%m-%d %a %I:%M %p', | |
**widget_defaults), | |
], bar_height) | |
aux_bar = bar.Bar([ | |
widget.TextBox("Aux bar", **widget_defaults) | |
], bar_height) | |
## XXX: This needs to be changed: | |
if n_screens == 2: | |
subprocess.call("xrandr --output VGA1 --mode 1680x1050", shell=True) | |
subprocess.call("xrandr --output LVDS1 --mode 1280x800", shell=True) | |
subprocess.call("xrandr --output VGA1 --right-of LVDS1", shell=True) | |
screens = [Screen(bottom=aux_bar, top=aux_top_bar), | |
Screen(bottom=main_bar, top=top_bar)] | |
else: | |
subprocess.call("xrandr --output LVDS1 --mode 1280x800", shell=True) | |
screens = [Screen(bottom=main_bar, top=top_bar)] | |
return screens | |
screens = setup_screens(get_n_screens()) | |
@hook.subscribe.screen_change | |
def restart_on_randr(qtile, ev): | |
screens = setup_screens(get_n_screens()) | |
lazy.restart() | |
## call("setup_screens") | |
wmname = "LG3D" | |
follow_mouse_focus = True | |
bring_front_click = True | |
floating_layout = layout.Floating() | |
auto_fullscreen = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment