-
Notifications
You must be signed in to change notification settings - Fork 111
/
config.py
290 lines (252 loc) · 10.5 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# -*- coding: utf-8 -*-
from libqtile.config import Key, Screen, Group, Drag, Click, Match
from libqtile.command import lazy
from libqtile import layout, bar, widget, hook
from libqtile.dgroups import simple_key_binder
from libqtile.log_utils import logger
import platform
import sys
# TODO:
# 2. multi screen switching
# Number of screens on machines I use regularly. I wish there was a good way to
# query this from qtile...
hostname = platform.node()
num_screens = {
'tanders-ubuntu': 2,
'smitten': 2,
'hopstrocity': 1,
'xephyr': 1,
}
sound_card = {
'hopstrocity': 1,
'smitten': 0,
}.get(hostname, 0)
# Global mod key. I have mod3 bound to caps lock, it's great.
mod = "mod3"
# If we're running in debug mode, it's for development. Make sure the
# hotkeys don't clash, only start one window, etc.
if '-d' in sys.argv:
hostname = 'xephyr'
mod = "mod4"
# global font options
widget_defaults = dict(
font = 'Consolas',
fontsize = 18,
padding = 3,
)
inoffensive_green = '339966'
if num_screens[hostname] == 2:
screens = [
Screen(top = bar.Bar([
widget.GroupBox(
urgent_alert_method='text',
this_current_screen_border=inoffensive_green,
disable_drag=True,
**widget_defaults
),
widget.Prompt(**widget_defaults),
widget.Spacer(),
widget.Mpris(name='clementine', stop_pause_text='', **widget_defaults),
widget.IdleRPG(url='http://xethron.lolhosting.net/xml.php?player=pants', **widget_defaults),
widget.Mpris2(
name='spotify',
objname="org.mpris.MediaPlayer2.spotify",
display_metadata=['xesam:title', 'xesam:artist'],
scroll_chars=None,
stop_pause_text='',
**widget_defaults
),
widget.Volume(**widget_defaults),
], 30,),
),
Screen(top = bar.Bar([
widget.GroupBox(
urgent_alert_method='text',
disable_drag=True,
this_current_screen_border=inoffensive_green,
**widget_defaults
),
widget.Clipboard(timeout=None, width=bar.STRETCH, max_width=None),
widget.BitcoinTicker(format="BTC: {avg}", **widget_defaults),
widget.BitcoinTicker(format="LTC: {avg}", source_currency='ltc'),
widget.BitcoinTicker(format="BTC: ฿{avg}", source_currency='ltc', currency='btc', round=False),
widget.Systray(**widget_defaults),
widget.Clock(format='%H:%M MSK', timezone='Europe/Moscow', **widget_defaults),
widget.Clock(format='%Y-%m-%d %a %I:%M %p', **widget_defaults),
], 30,),
),
]
else:
# 1 screen
screens = [Screen(top = bar.Bar([
widget.GroupBox(urgent_alert_method='text', disable_drag=True, **widget_defaults),
widget.Prompt(**widget_defaults),
widget.Clipboard(timeout=None, width=bar.STRETCH, max_width=None),
widget.BitcoinTicker(format="BTC: {avg}", **widget_defaults),
widget.Mpris2(
name='spotify',
objname="org.mpris.MediaPlayer2.spotify",
display_metadata=['xesam:title', 'xesam:artist'],
scroll_chars=None,
stop_pause_text='',
**widget_defaults
),
widget.Mpris(name='clementine', stop_pause_text='', **widget_defaults),
# this pollutes ~/.qtile.log and i don't really use it, so drop it for now
# widget.Volume(cardid=sound_card, **widget_defaults),
# 1 screen means this is a laptop, so let's render the battery
widget.Battery(energy_now_file='charge_now',
energy_full_file='charge_full',
power_now_file='current_now',
**widget_defaults
),
widget.Systray(**widget_defaults),
widget.Clock(format='%Y-%m-%d %a %I:%M %p', **widget_defaults),
],30,),),
]
def app_or_group(group, app):
""" Go to specified group if it exists. Otherwise, run the specified app.
When used in conjunction with dgroups to auto-assign apps to specific
groups, this can be used as a way to go to an app if it is already
running. """
def f(qtile):
try:
qtile.groupMap[group].cmd_toscreen()
except KeyError:
qtile.cmd_spawn(app)
return f
last_playing = 'spotify'
def playpause(qtile):
global last_playing
if qtile.widgetMap['clementine'].is_playing() or last_playing == 'clementine':
qtile.cmd_spawn("clementine --play-pause")
last_playing = 'clementine'
if qtile.widgetMap['spotify'].is_playing or last_playing == 'spotify':
qtile.cmd_spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")
last_playing = 'spotify'
def next_prev(state):
def f(qtile):
if qtile.widgetMap['clementine'].is_playing():
qtile.cmd_spawn("clementine --%s" % state)
if qtile.widgetMap['spotify'].is_playing:
cmd = "Next" if state == "next" else "Previous"
qtile.cmd_spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.%s" % cmd)
return f
keys = [
# Log out; note that this doesn't use mod3: that's intentional in case mod3
# gets hosed (which happens if you unplug and replug your usb keyboard
# sometimes, or on ubuntu upgrades). This way you can still log back out
# and in gracefully.
Key(["shift", "mod1"], "q", lazy.shutdown()),
# I don't ever use floating, but sometimes it is handy to toggle to
# floating for debugging, so I use the "out of band" mnemonic for this as
# well.
Key(["shift", "mod1"], "f", lazy.window.toggle_floating()),
Key([mod], "k", lazy.layout.down()),
Key([mod], "j", lazy.layout.up()),
Key([mod], "h", lazy.layout.previous()),
Key([mod], "l", lazy.layout.next()),
Key([mod, "shift"], "space", lazy.layout.rotate()),
Key([mod, "shift"], "Return",lazy.layout.toggle_split()),
Key(["mod1"], "Tab", lazy.next_layout()),
Key([mod, "mod1"], "h", lazy.to_screen(0)),
Key([mod, "mod1"], "l", lazy.to_screen(1)),
Key([mod], "x", lazy.window.kill()),
Key([mod, "shift"], "l", lazy.layout.swap_left()),
# interact with prompts
Key([mod], "r", lazy.spawncmd()),
Key([mod], "g", lazy.togroup()),
# start specific apps
Key([mod], "n", lazy.function(app_or_group("www", "google-chrome"))),
Key([mod], "m", lazy.function(app_or_group("music", "clementine"))),
Key([mod], "c", lazy.function(app_or_group("io", "pidgin"))),
Key([mod], "Return", lazy.spawn("urxvt")),
# Change the volume if our keyboard has keys
Key(
[], "XF86AudioRaiseVolume",
lazy.spawn("amixer -c %d -q set Master 2dB+" % sound_card)
),
Key(
[], "XF86AudioLowerVolume",
lazy.spawn("amixer -c %d -q set Master 2dB-" % sound_card)
),
Key(
[], "XF86AudioMute",
lazy.spawn("amixer -D pulse set Master toggle")
),
Key(
[], "XF86AudioPlay",
lazy.function(playpause)
),
Key(
[], "XF86AudioNext",
lazy.function(next_prev("next"))
),
Key(
[], "XF86AudioPrev",
lazy.function(next_prev("prev"))
),
# also allow changing volume, tracks the old fashioned way
Key([mod], "equal", lazy.spawn("amixer -c %d -q set Master 2dB+" % sound_card)),
Key([mod], "minus", lazy.spawn("amixer -c %d -q set Master 2dB-" % sound_card)),
Key([mod], "bracketleft", lazy.function(next_prev("prev"))),
Key([mod], "bracketright", lazy.function(next_prev("next"))),
# poor man's middle click
Key([mod], "v", lazy.spawn("xdotool click 2")),
# backlight controls
Key([], "XF86KbdBrightnessUp", lazy.spawn("maclight keyboard up")),
Key([], "XF86KbdBrightnessDown", lazy.spawn("maclight keyboard down")),
Key([], "XF86MonBrightnessUp", lazy.spawn("maclight screen up")),
Key([], "XF86MonBrightnessDown", lazy.spawn("maclight screen down")),
]
host_specific_mouse = {
'hopstrocity': [
Click([mod], "Button1", lazy.spawn("xdotool click 3")),
],
}
mouse = host_specific_mouse.get(hostname, [])
# Next, we specify group names, and use the group name list to generate an appropriate
# set of bindings for group switching.
groups = []
# throwaway groups for random stuff
for i in ['a', 's', 'd', 'f', 'u', 'i', 'o', 'p']:
groups.append(Group(i))
keys.append(
Key([mod], i, lazy.group[i].toscreen())
)
keys.append(
Key([mod, "mod1"], i, lazy.window.togroup(i))
)
# groups with special jobs. I usually navigate to these via my app_or_group
# function.
groups.extend([
Group('music', spawn='clementine', layout='max', persist=False,
matches=[Match(wm_class=['Clementine', 'Viridian'])]),
Group('www', spawn='google-chrome', layout='max', persist=False,
matches=[Match(wm_class=['Firefox', 'google-chrome', 'Google-chrome'])]),
Group('io', layout='pidgin', persist=False, init=False,
matches=[Match(wm_class=['Pidgin'], role=['Buddy List'])]),
Group('java', persist=False, init=False,
matches=[Match(wm_class=['sun-awt-X11-XFramePeer', 'GroupWise'])]),
])
border_args = dict(
border_width=1,
)
layouts = [
layout.Stack(num_stacks=2, **border_args),
layout.Max(),
# a layout just for gimp
layout.Slice(side='left', width=192, name='gimp', role='gimp-toolbox',
fallback=layout.Slice(side='right', width=256, role='gimp-dock',
fallback=layout.Stack(num_stacks=1, **border_args))),
# a layout for pidgin
layout.Slice(side='right', width=256, name='pidgin', role='buddy_list',
fallback=layout.Stack(num_stacks=2, **border_args)),
layout.MonadTall(ratio=0.65, **border_args),
]
no_utility = layout.floating.DEFAULT_FLOAT_WM_TYPES - {'utility'}
floating_layout = layout.Floating(auto_float_types=no_utility)
cursor_warp = True
follow_mouse_focus = True
focus_on_window_activation = "never"
# vim: tabstop=4 shiftwidth=4 expandtab