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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
from libqtile.config import (Group, Key, Click, Drag, Screen, Match)
from libqtile.command import lazy
from libqtile import (layout, bar, widget, hook)
import libqtile
import libqtile.widget.launchbar
import subprocess
import os.path
import itertools
import functools
import contextlib
screens_count = str(
subprocess.Popen(
['xrandr'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()[0]
).count(" connected ")
touchpad_id = None
with contextlib.suppress(Exception):
result = subprocess.run(['xinput'], capture_output=True)
stdout = result.stdout.decode('utf-8')
for i in stdout.split('\n'):
if 'TouchPad' in i:
touchpad_id = int(i.split('id=')[1].split('[')[0].strip())
wlan_dev = None
with contextlib.suppress(Exception):
result = subprocess.run(['ip', 'l'], capture_output=True)
stdout = result.stdout.decode('utf-8')
for i in stdout.split('\n'):
if not i or i[0] in (' ', '\t'):
continue
temp_wlan_dev = i.split(':')[1].strip()
if temp_wlan_dev and temp_wlan_dev[0] == 'w':
wlan_dev = temp_wlan_dev
break
mod = 'mod4'
groups = [
Group('1', screen_affinity=0),
Group('2', screen_affinity=0),
Group('3', screen_affinity=0),
Group('4', screen_affinity=0),
Group('a', screen_affinity=1 % screens_count),
Group('s', screen_affinity=1 % screens_count),
Group('d', screen_affinity=1 % screens_count),
Group('f', screen_affinity=1 % screens_count),
# Group('z', screen_affinity=2),
# Group('x', screen_affinity=2),
# Group('c', screen_affinity=2),
# Group('v', screen_affinity=2),
Group('term', layout='max',
matches=[Match(wm_instance_class=['tmux_term'])])
]
bar_background = ['#000000', '#000000', '#333333']
def get_icon_path(name):
return os.path.expanduser('~/.dotfiles/pictures/icons/' + name + '.png')
def create_launch_bar():
return libqtile.widget.launchbar.LaunchBar([
(get_icon_path('chromium'), 'chromium'),
(get_icon_path('falkon'), 'falkon'),
(get_icon_path('qutebrowser'), 'qutebrowser'),
(get_icon_path('dolphin'), 'dolphin'),
(get_icon_path('atom'), 'atom'),
(get_icon_path('claws-mail'), 'claws-mail'),
(get_icon_path('kmix'), 'pavucontrol'),
(get_icon_path('network'), 'connman-gtk'),
(get_icon_path('keepassxc'), 'keepassxc'),
(get_icon_path('clementine'), 'clementine'),
], pading=5)
def create_top_bar(screen_index):
return bar.Bar([
widget.CurrentLayoutIcon(scale=0.7),
widget.CurrentLayout(),
widget.Sep(),
widget.WindowName(),
widget.Prompt(name='prompt' + str(screen_index)),
widget.Sep(),
widget.TextBox('Cpu:'),
widget.CPUGraph(),
widget.Sep(),
widget.TextBox('Memory:'),
widget.MemoryGraph(),
widget.Sep(),
widget.TextBox('Net:'),
widget.NetGraph(),
widget.Sep(),
widget.TextBox('Wlan:'),
widget.Wlan(interface=wlan_dev),
widget.Sep(),
widget.TextBox('Battery:'),
widget.Battery(),
widget.Sep(),
widget.TextBox('Volume:'),
widget.Volume(),
widget.Sep(),
widget.Clock(format='%Y-%m-%d %H:%M:%S')
], 30, background=bar_background)
def create_bottom_bar(screen_index):
return bar.Bar([
widget.GroupBox(disable_drag=True,
fontsize=22,
visible_groups={g.name for g in groups
if g.screen_affinity is None
or g.screen_affinity == screen_index}),
widget.Sep(),
create_launch_bar(),
widget.Sep(),
widget.TaskList(fontsize=20)
] + ([widget.Systray(icon_size=35)] if screen_index == 0 else []), 35,
background=list(reversed(bar_background)))
def create_screen(screen_index):
return Screen(
top=create_top_bar(screen_index),
bottom=create_bottom_bar(screen_index))
screens = [create_screen(i) for i in range(screens_count)]
layouts = [
layout.MonadTall(),
layout.MonadWide(),
layout.Max(),
layout.VerticalTile(),
layout.Zoomy()
]
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())
]
def act_focus_group(group, qtile):
qtile.groups_map[group.name].cmd_toscreen(group.screen_affinity)
qtile.cmd_to_screen(group.screen_affinity)
def act_move_to_group(group, qtile):
qtile.current_window.cmd_togroup(group.name)
def act_F12(qtile):
if qtile.current_group.name != 'term':
for screen in qtile.cmd_screens():
if screen['group'] == 'term':
qtile.cmd_to_screen(screen['index'])
return
qtile.current_screen.cmd_togglegroup('term')
if qtile.current_group.name == 'term' and not qtile.current_group.windows:
subprocess.Popen(['alacritty', '-e', 'tmux', 'new-session', '-A',
'-s', 'default'])
def act_enable_touchpad(qtile):
subprocess.Popen(['xinput', 'enable', str(touchpad_id)])
def act_disable_touchpad(qtile):
subprocess.Popen(['xinput', 'disable', str(touchpad_id)])
def act_left(qtile):
lay = qtile.current_group.layout
scr = qtile.current_screen
scr_next = qtile.screens[(scr.index + 1) % len(qtile.screens)]
change_screen = False
if isinstance(lay, layout.Max):
change_screen = True
elif isinstance(lay, layout.MonadTall):
try:
lay.cmd_left()
except ValueError:
change_screen = True
else:
lay.cmd_previous()
if change_screen:
qtile.cmd_to_screen(scr_next.index)
def act_right(qtile):
lay = qtile.current_group.layout
scr = qtile.current_screen
scr_next = qtile.screens[(scr.index + 1) % len(qtile.screens)]
change_screen = False
if isinstance(lay, layout.Max):
change_screen = True
elif isinstance(lay, layout.MonadTall):
try:
lay.cmd_right()
except ValueError:
change_screen = True
else:
lay.cmd_next()
if change_screen:
qtile.cmd_to_screen(scr_next.index)
def act_up(qtile):
qtile.current_group.layout.cmd_up()
def act_down(qtile):
qtile.current_group.layout.cmd_down()
def act_move_left(qtile):
qtile.current_group.layout.cmd_swap_left()
def act_move_right(qtile):
qtile.current_group.layout.cmd_swap_right()
def act_move_up(qtile):
qtile.current_group.layout.cmd_move_up()
def act_move_down(qtile):
qtile.current_group.layout.cmd_move_down()
def act_spawncmd(qtile):
qtile.cmd_spawncmd(widget='prompt' + str(qtile.current_screen.index))
keys = list(itertools.chain(
[Key([mod, 'shift'], 'q', lazy.window.kill()),
Key([mod], 'w', lazy.next_layout()),
Key([mod, 'shift'], 'e', lazy.shutdown()),
Key([mod, 'shift'], 'r', lazy.restart()),
Key([mod], 'Return', lazy.spawn('urxvt')),
Key([mod], 'space', lazy.function(act_spawncmd)),
Key([mod], 'Tab', lazy.layout.next()),
Key([mod, 'shift'], 'space', lazy.window.toggle_floating()),
Key([mod, 'shift'], 'Return', lazy.window.toggle_fullscreen()),
Key([mod], 'h', lazy.function(act_left)),
Key([mod], 'l', lazy.function(act_right)),
Key([mod], 'j', lazy.function(act_down)),
Key([mod], 'k', lazy.function(act_up)),
Key([mod, 'shift'], "h", lazy.function(act_move_left)),
Key([mod, 'shift'], "l", lazy.function(act_move_right)),
Key([mod, 'shift'], "j", lazy.function(act_move_down)),
Key([mod, 'shift'], "k", lazy.function(act_move_up)),
Key([mod], "m", lazy.layout.grow()),
Key([mod], "n", lazy.layout.shrink()),
Key([mod, 'shift'], "m", lazy.layout.maximize()),
Key([mod, 'shift'], "n", lazy.layout.normalize()),
Key([], 'F12', lazy.function(act_F12)),
# Key([], 'PrintScreen', lazy.spawn('spectacle')),
Key([mod], 't', lazy.function(act_enable_touchpad)),
Key([mod, 'shift'], 't', lazy.function(act_disable_touchpad)),
],
[Key([mod], group.name,
lazy.function(functools.partial(act_focus_group, group)))
for group in groups if group.name != 'term'],
[Key([mod, 'shift'], group.name,
lazy.function(functools.partial(act_move_to_group, group)))
for group in groups if group.name != 'term'],
))
@hook.subscribe.current_screen_change
def hook_current_screen_change():
change_border_focus()
@hook.subscribe.setgroup
def hook_setgroup():
change_border_focus()
def change_border_focus():
qtile = hook.qtile
for i in qtile.screens:
if qtile.current_screen == i:
if isinstance(i.group.layout, layout.MonadTall):
if i.group.layout.border_focus != "#ff0000":
i.group.layout.border_focus = "#ff0000"
i.group.layout_all()
else:
if isinstance(i.group.layout, layout.MonadTall):
if i.group.layout.border_focus != "#000000":
i.group.layout.border_focus = "#000000"
i.group.layout_all()
@hook.subscribe.startup
def hook_startup():
qtile = hook.qtile
screens_set = set()
for g in groups:
if g.screen_affinity is not None and g.screen_affinity not in screens_set:
qtile.groups_map[g.name].cmd_toscreen(g.screen_affinity)
screens_set.add(g.screen_affinity)
with contextlib.suppress(Exception):
subprocess.Popen(['feh', '--bg-scale',
os.path.expanduser('~/.dotfiles/pictures/bg1.jpg'),
os.path.expanduser('~/.dotfiles/pictures/bg2.jpg')])
@hook.subscribe.startup_once
def hook_startup_once():
#with contextlib.suppress(Exception):
# subprocess.Popen(['dropbox'])
#with contextlib.suppress(Exception):
# subprocess.Popen(['megasync'])
with contextlib.suppress(Exception):
subprocess.Popen(['kuiserver5'])
@hook.subscribe.client_new
def float_modal(window):
if 383 in window.window.get_property('_NET_WM_STATE', unpack=int):
window.floating = True
|