aboutsummaryrefslogtreecommitdiffstats
path: root/.config/qtile/config.py
blob: 5fa8e5fa349c3d108ee7a7867eea39bdc7ea1e2c (plain)
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
from libqtile.config import Key, Screen, Group, Drag, Click, Match
from libqtile.command import lazy
from libqtile import layout, bar, widget, hook
from os.path import expanduser
import re
import subprocess

mod = "mod4"
alt = "mod1"

home = expanduser("~")
terminal = "termite"
drun_launcher = "rofi -show drun"
run_launcher = "rofi -show run"
lock = home+"/bin/i3lock"
brightness_up = "xbacklight -inc 10"
brightness_down = "xbacklight -dec 10"

volume_up = home+"/bin/set_volume increase"
volume_down = home+"/bin/set_volume decrease"
volume_toggle = home+"/bin/set_volume toggle"
audio_prev = home+"/bin/notify_mpd prev"
audio_next = home+"/bin/notify_mpd next"
audio_toggle = home+"/bin/notify_mpd toggle"
audio_stop = home+"/bin/notify_mpd stop"

subprocess.call(['feh',
                 '--bg-fill',
                 home+'/ownCloud/photos/desktop/underwater_greenery.JPG'])

colors = {
    "grey": "#555555",
    "red": "#DD1144",
    "blue": "#445588",
    "lgrey": "#b8b6b1",
    "green": "#008080",
}

# kick a window to another screen (handy during presentations)
def move_to_other_screen(qtile, direction=1):
    other_scr_index = (qtile.screens.index(qtile.currentScreen) + direction) % len(qtile.screens)
    othergroup = None
    for group in qtile.cmd_groups().values():
        if group['screen'] == other_scr_index:
            othergroup = group['name']
            break
    if othergroup:
        qtile.moveToGroup(othergroup)

keys = [
    # base commands
    # restart qtile
    Key([mod, "control"], "r", lazy.restart()),
    # close qtile
    Key([mod, "control"], "q", lazy.shutdown()),
    # start run launcher
    Key([mod], "r", lazy.spawn(run_launcher)),
    # start drun launcher
    Key([mod], "p", lazy.spawn(drun_launcher)),
    # lock screen
    Key([mod, "control"], "s", lazy.spawn(lock)),
    # launch terminal
    Key([mod], "Return", lazy.spawn(terminal)),

    # brightness settings
    Key([], "XF86MonBrightnessUp", lazy.spawn(brightness_up)),
    Key([], "XF86MonBrightnessDown", lazy.spawn(brightness_down)),

    # multimedia
    Key([], "XF86AudioRaiseVolume", lazy.spawn(volume_up)),
    Key([], "XF86AudioLowerVolume", lazy.spawn(volume_down)),
    Key([], "XF86AudioMute", lazy.spawn(volume_toggle)),
    Key([], "XF86AudioPrev", lazy.spawn(audio_prev)),
    Key([], "XF86AudioNext", lazy.spawn(audio_next)),
    Key([], "XF86AudioPlay", lazy.spawn(audio_toggle)),
    Key([], "XF86AudioStop", lazy.spawn(audio_stop)),

    # cycle to previous and next group
    Key(["control", alt], "Left", lazy.screen.prev_group(skip_managed=True)),
    Key(["control", alt], "Right", lazy.screen.next_group(skip_managed=True)),
    Key(["control", mod, alt], "Left", lazy.screen.prev_group()),
    Key(["control", mod, alt], "Right", lazy.screen.next_group()),

    # Switch between windows in current stack pane
    Key([mod], "comma", lazy.layout.up()),
    Key([mod], "period", lazy.layout.down()),
    Key([mod], "Tab", lazy.layout.previous()),
    Key([mod, "shift"], "Tab", lazy.layout.next()),

    # toggle between different layouts
    Key([mod], "space", lazy.next_layout()),
    # close window
    Key([mod], "q", lazy.window.kill()),
    # toggle fullscreen
    Key([mod, "control"], "f", lazy.window.toggle_fullscreen()),
    # toggle maximized
    Key([mod], "m", lazy.window.toggle_maximize()),
    # toggle floating
    Key([mod], "f", lazy.window.toggle_floating()),
    Key([mod, alt], "space", lazy.layout.rotate()),   # flip sides

    # Multihead magic
    Key([mod, "control"], "comma", lazy.prev_screen()),
    Key([mod, "control"], "period", lazy.next_screen()),
    Key([mod], "o", lazy.function(move_to_other_screen)),

    # columns layout
    # move selection around in current group
    Key([mod], "j", lazy.layout.down()),
    Key([mod], "k", lazy.layout.up()),
    Key([mod], "h", lazy.layout.left()),
    Key([mod], "l", lazy.layout.right()),
    # move current window around in the current layout
    Key([mod, "shift"], "j", lazy.layout.shuffle_down()),
    Key([mod, "shift"], "k", lazy.layout.shuffle_up()),
    Key([mod, "shift"], "h", lazy.layout.shuffle_left()),
    Key([mod, "shift"], "l", lazy.layout.shuffle_right()),
    # grow current window into some direction
    Key([mod, "control"], "j", lazy.layout.grow_down()),
    Key([mod, "control"], "k", lazy.layout.grow_up()),
    Key([mod, "control"], "h", lazy.layout.grow_left()),
    Key([mod, "control"], "l", lazy.layout.grow_right()),
    # toggle current window to be splitting current group in half
    Key([mod], "s", lazy.layout.toggle_split()),
    Key([mod], "n", lazy.layout.normalize()),
]

matchers = {
    'web': [
        Match(wm_class=[
            "Firefox",
            "chromium",
        ]),
    ],
    'dev': [
        Match(wm_class=[
            "Pycharm",
            "Rubymine",
        ])
    ],
    'games': [
        Match(wm_class=[
            re.compile('Minecraft'),
            re.compile('Minetest'),
            "pyrogenesis",
            "spring",
            "angband",
            "scummvm",
            "widelands",
        ]),
        Match(title=[
            re.compile('ScummVM'),
            re.compile('Widelands'),
            re.compile('Minecraft'),
            re.compile('Minetest'),
            "OpenRA",
            "0 A.D.",
            "Angband",
            "Alien Arena",
        ]),
    ],
    'audio': [
        Match(wm_class=[
            "Ardour",
        ])
    ],
}

workspaces = [
    {"key": "1", "name": "shell"},
    {"key": "2", "name": "web", "matches": matchers["web"]},
    {"key": "3", "name": "dev", "matches": matchers["dev"]},
    {"key": "4", "name": "games", "matches": matchers["games"]},
    {"key": "5", "name": "audio", "matches": matchers["audio"]},
    {"key": "6", "name": "6"},
    {"key": "7", "name": "7"},
    {"key": "8", "name": "8"},
    {"key": "9", "name": "9"},
    {"key": "0", "name": "0"},
]

groups = []
for workspace in workspaces:
    matches = workspace["matches"] if "matches" in workspace else None
    groups.append(Group(workspace["name"], matches=matches))
    keys.append(
        Key([mod], workspace["key"], lazy.group[workspace["name"]].toscreen())
    )
    keys.append(Key(
        [mod, alt], workspace["key"],
        lazy.window.togroup(workspace["name"]),
    ))

layouts = [
    layout.Columns(),
    layout.VerticalTile(),
    layout.Matrix(),
    layout.Max(),
    layout.TreeTab(),
    layout.Zoomy(),
]

widget_defaults = dict(
    font='Monospace',
    fontsize=11,
    padding=3,
)

screens = [
    Screen(
        top=bar.Bar([
            widget.CurrentScreen(),
            widget.Sep(),
            widget.GroupBox(
                highlight_method="block",
                this_current_screen_border=colors["blue"]
            ),
            widget.Sep(),
            widget.Notify(
                foreground_low=colors["red"][1:],
                foreground_urgent=colors["red"][1:]
            ),
            widget.Spacer(),
            widget.CurrentLayout(),
            widget.Sep(),
            widget.HDDGraph(),
            widget.MemoryGraph(),
            widget.CPUGraph(),
            widget.Battery(),
            widget.Sep(),
            widget.Systray(),
            widget.Sep(),
            widget.Clock(
                timezone="Europe/Berlin",
                format="%Y%m%d %a %H:%M:%S"
            ),
        ],
        20
        ),
    ),
    Screen(
        top=bar.Bar([
            widget.CurrentScreen(),
            widget.Sep(),
            widget.GroupBox(
                highlight_method="block",
                this_current_screen_border=colors["blue"]
            ),
            widget.Sep(),
            widget.Notify(
                foreground_low=colors["red"][1:],
                foreground_urgent=colors["red"][1:]
            ),
            widget.Spacer(),
            widget.CurrentLayout(),
            widget.Sep(),
            widget.Clock(
                timezone="Europe/Berlin",
                format="%Y%m%d %a %H:%M:%S"
            ),
        ],
        20
        ),
    ),
]

# 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 = []
follow_mouse_focus = True
bring_front_click = False
cursor_warp = False
floating_layout = layout.Floating()
auto_fullscreen = True
wmname = "LG3D"


def main(qtile):
    qtile.cmd_warning()


@hook.subscribe.screen_change
def restart_on_randr(qtile, ev):
    qtile.cmd_restart()