This repository has no description
10 kB
251 lines
1import subprocess
2import threading
3import json
4import os
5from typing import Callable
6
7from libqtile import bar, layout, widget, extension, hook
8from libqtile.config import Click, Drag, Group, Key, Match, Screen, ScratchPad, DropDown
9from libqtile.lazy import lazy
10from libqtile.utils import guess_terminal
11from libqtile.command.client import InteractiveCommandClient
12from libqtile.core.manager import Qtile
13from libqtile.backend.wayland import InputConfig
14
15prompt = widget.Prompt()
16state_file = "/home/lass/.local/share/qtile/state"
17
18
19def dmenu(candidates: list[str], callback: Callable) -> None:
20 def thread() -> None:
21 dmenu = subprocess.Popen(["rofi", "-dmenu"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
22 output = dmenu.communicate(input=("\n".join(candidates)).encode())
23 callback(output[0].decode().rstrip())
24 threading.Thread(target=thread).start()
25
26@lazy.function
27def goto_workspace(qtile: Qtile) -> None:
28 def callback(name: str) -> None:
29 c=InteractiveCommandClient()
30 c.group[name].toscreen()
31 dmenu(candidates=qtile.items("group")[1], callback=callback)
32
33@lazy.function
34def moveto_workspace(qtile: Qtile) -> None:
35 def callback(name: str) -> None:
36 c=InteractiveCommandClient()
37 c.window.togroup(name)
38 dmenu(candidates=qtile.items("group")[1], callback=callback)
39
40@lazy.function
41def add_group(qtile: Qtile) -> None:
42 def callback(name: str) -> None:
43 qtile.addgroup(name)
44 prompt.start_input("Add group: ", callback=callback)
45
46@lazy.function
47def del_group(qtile: Qtile) -> None:
48 qtile.delgroup(qtile.current_group.name)
49
50@lazy.function
51def reload_config(qtile: Qtile) -> None:
52 with open(state_file, "w") as f:
53 f.write(json.dumps(qtile.get_groups(), default=tuple))
54 qtile.reload_config()
55
56mod = "mod4"
57terminal = guess_terminal()
58
59if os.path.exists(state_file):
60 with open(state_file, "r") as f:
61 state = json.loads(f.read())
62 groups = [Group(name) for name, _ in state.items()]
63else:
64 groups = [
65 Group("dashboard"),
66 Group("ff"),
67 ]
68
69keys = [
70 # A list of available commands that can be bound to keys can be found
71 # at https://docs.qtile.org/en/latest/manual/config/lazy.html
72 # Switch between windows
73 Key([mod], "Tab", lazy.layout.next(), desc="Move window focus to other window"),
74 Key([mod, "shift"], "Tab", lazy.layout.previous(), desc="Move window focus to other window"),
75
76 Key([mod], "Escape", lazy.screen.toggle_group(), desc="Switch to last active group"),
77 # Move windows between left/right columns or move up/down in current stack.
78 # Moving out of range in Columns layout will create new column.
79 Key([mod, "shift"], "a", add_group, desc="add group"),
80 Key([mod, "shift"], "backspace", del_group, desc="delete group"),
81 Key([mod, "shift"], "h", lazy.layout.shuffle_left(), desc="Move window to the left"),
82 Key([mod, "shift"], "l", lazy.layout.shuffle_right(), desc="Move window to the right"),
83 Key([mod, "shift"], "j", lazy.layout.shuffle_down(), desc="Move window down"),
84 Key([mod, "shift"], "k", lazy.layout.shuffle_up(), desc="Move window up"),
85 # Grow windows. If current window is on the edge of screen and direction
86 # will be to screen edge - window would shrink.
87 Key([mod, "control"], "h", lazy.layout.grow_left(), desc="Grow window to the left"),
88 Key([mod, "control"], "l", lazy.layout.grow_right(), desc="Grow window to the right"),
89 Key([mod, "control"], "j", lazy.layout.grow_down(), desc="Grow window down"),
90 Key([mod, "control"], "k", lazy.layout.grow_up(), desc="Grow window up"),
91 Key([mod], "f", lazy.window.toggle_fullscreen(), desc="Toggle fullscreen",),
92 Key([mod], "n", lazy.layout.normalize(), desc="Reset all window sizes"),
93 Key([mod], "d", lazy.spawn("copyq show")),
94 Key([mod, "shift"], "Return", lazy.spawn(terminal), desc="Launch terminal"),
95 # Toggle between different layouts as defined below
96 Key([mod], "Space", lazy.next_layout(), desc="Toggle between layouts"),
97 Key([mod, "shift"], "c", lazy.window.kill(), desc="Kill focused window"),
98 Key([mod], "F11", lazy.spawn("swaylock --image /var/lib/wallpaper/wallpaper")),
99 Key([mod], "t", lazy.window.toggle_floating(), desc="Toggle floating on the focused window"),
100 Key([mod, "shift"], "r", reload_config, desc="Reload the config"),
101 Key([mod, "control"], "q", lazy.shutdown(), desc="Shutdown Qtile"),
102 Key([mod], "r", lazy.spawncmd(), desc="Spawn a command using a prompt widget"),
103 Key([mod], "F1", lazy.group["scratchpad"].dropdown_toggle("term")),
104 Key([mod], "i", lazy.spawn("screenshot")),
105 Key([mod], "p", lazy.spawn("pass_menu")),
106 Key([mod, "shift"], "p", lazy.spawn("otpmenu")),
107 Key([mod], "v", goto_workspace, desc="Switch to group"),
108 Key([mod, "shift"], "v", moveto_workspace, desc="move window to group"),
109 Key([], "XF86AudioRaiseVolume", lazy.spawn("pactl set-sink-volume @DEFAULT_SINK@ +5%")),
110 Key([], "XF86AudioLowerVolume", lazy.spawn("pactl set-sink-volume @DEFAULT_SINK@ -5%")),
111 Key([], "XF86MonBrightnessUp", lazy.spawn("xbacklight -inc 10")),
112 Key([], "XF86MonBrightnessDown", lazy.spawn("xbacklight -dec 10")),
113
114 Key(["control", "mod1"], "F1", lazy.core.change_vt(1), desc="Switch to VT 1"),
115 Key(["control", "mod1"], "F2", lazy.core.change_vt(2), desc="Switch to VT 2"),
116 Key(["control", "mod1"], "F3", lazy.core.change_vt(3), desc="Switch to VT 3"),
117 Key(["control", "mod1"], "F4", lazy.core.change_vt(4), desc="Switch to VT 4"),
118 Key(["control", "mod1"], "F5", lazy.core.change_vt(5), desc="Switch to VT 5"),
119 Key(["control", "mod1"], "F6", lazy.core.change_vt(6), desc="Switch to VT 6"),
120]
121
122layouts = [
123 layout.Max(),
124 layout.Columns(border_focus_stack=["#d75f5f", "#8f3d3d"], border_width=4),
125 # Try more layouts by unleashing below layouts.
126 # layout.Stack(num_stacks=2),
127 # layout.Bsp(),
128 layout.Matrix(),
129 # layout.MonadTall(),
130 # layout.MonadWide(),
131 # layout.RatioTile(),
132 # layout.Tile(),
133 # layout.TreeTab(),
134 # layout.VerticalTile(),
135 # layout.Zoomy(),
136]
137
138widget_defaults = dict(
139 font="sans",
140 fontsize=12,
141 padding=3,
142)
143extension_defaults = widget_defaults.copy()
144
145screens = [
146 Screen(
147 bottom=bar.Bar(
148 [
149 widget.CurrentLayout(),
150 widget.GenPollUrl(
151 url="http://radio.r:8002/current",
152 parse=lambda r: "/".join(r["filename"].split("/")[-2:]),
153 update_interval=15,
154 ),
155 widget.Spacer(),
156 widget.Wlan(interface="wlp170s0"),
157 widget.HDDBusyGraph(device="nvme0n1", graph_color="#4fbe4f"),
158 widget.MemoryGraph(graph_color="#eed563"),
159 widget.CPUGraph(graph_color="#8575bf"),
160 widget.ThermalZone(zone="/sys/class/thermal/thermal_zone1/temp", background="#440000"),
161 widget.PulseVolume(background="#009900"),
162 widget.Backlight(background="#b18f00", backlight_name="intel_backlight"),
163 widget.Battery(background="#e52383"),
164 widget.Clock(format="%Y-%m-%d %a %H:%M"),
165 # NB Systray is incompatible with Wayland, consider using StatusNotifier instead
166 widget.StatusNotifier(),
167 ],
168 24,
169 # border_width=[2, 0, 2, 0], # Draw top and bottom borders
170 # border_color=["ff00ff", "000000", "ff00ff", "000000"] # Borders are magenta
171 ),
172 top=bar.Bar(
173 [
174 widget.GroupBox(),
175 prompt,
176 widget.WindowName(),
177 widget.Chord(
178 chords_colors={
179 "launch": ("#ff0000", "#ffffff"),
180 },
181 name_transform=lambda name: name.upper(),
182 ),
183 ],
184 24,
185 ),
186 # You can uncomment this variable if you see that on X11 floating resize/moving is laggy
187 # By default we handle these events delayed to already improve performance, however your system might still be struggling
188 # This variable is set to None (no cap) by default, but you can set it to 60 to indicate that you limit it to 60 events per second
189 # x11_drag_polling_rate = 60,
190 ),
191]
192
193# Drag floating layouts.
194mouse = [
195 Drag([mod], "Button1", lazy.window.set_position_floating(), start=lazy.window.get_position()),
196 Drag([mod], "Button3", lazy.window.set_size_floating(), start=lazy.window.get_size()),
197 Click([mod], "Button2", lazy.window.bring_to_front()),
198]
199
200dgroups_key_binder = None
201dgroups_app_rules = [] # type: list
202follow_mouse_focus = True
203bring_front_click = False
204floats_kept_above = True
205cursor_warp = False
206floating_layout = layout.Floating(
207 float_rules=[
208 # Run the utility of `xprop` to see the wm class and name of an X client.
209 *layout.Floating.default_float_rules,
210 Match(wm_class="confirmreset"), # gitk
211 Match(wm_class="makebranch"), # gitk
212 Match(wm_class="maketag"), # gitk
213 Match(wm_class="ssh-askpass"), # ssh-askpass
214 Match(title="branchdialog"), # gitk
215 Match(title="pinentry"), # GPG key password entry
216 ]
217)
218auto_fullscreen = True
219focus_on_window_activation = "smart"
220reconfigure_screens = True
221
222# If things like steam games want to auto-minimize themselves when losing
223# focus, should we respect this or not?
224auto_minimize = True
225
226# When using the Wayland backend, this can be used to configure input devices.
227wl_input_rules = {
228 "type:keyboard": InputConfig(kb_options="ctrl:nocaps", kb_layout="us", kb_variant="altgr-intl"),
229}
230
231@hook.subscribe.startup
232def autostart():
233 subprocess.run(
234 [
235 "systemctl",
236 "--user",
237 "import-environment",
238 "XDG_SESSION_PATH",
239 "WAYLAND_DISPLAY",
240 ]
241 )
242
243# XXX: Gasp! We're lying here. In fact, nobody really uses or cares about this
244# string besides java UI toolkits; you can see several discussions on the
245# mailing lists, GitHub issues, and other WM documentation that suggest setting
246# this string if your java app doesn't work correctly. We may as well just lie
247# and say that we're a working one by default.
248#
249# We choose LG3D to maximize irony: it is a 3D non-reparenting WM written in
250# java that happens to be on java's whitelist.
251wmname = "LG3D"