tony / oxwm

Branch: 842e22a
Switch branches/tags
master
tonybanters Added lua parser. 842e22a 2025-11-08
309 lines · 12.1 KB Raw Blame History
1 -- OXWM Configuration File (Lua)
2 -- Edit this file and reload with Mod+Shift+R (no compilation needed!)
3
4 ---@class LayoutSymbol
5 ---@field name string The internal layout name (e.g., "tiling", "normie")
6 ---@field symbol string The display symbol for the layout (e.g., "[T]", "[F]")
7
8 ---@class KeyBinding
9 ---@field modifiers string[] List of modifiers: "Mod", "Mod1"-"Mod5", "Shift", "Control"
10 ---@field key string The key name (e.g., "Return", "Q", "1", "Space")
11 ---@field action string Action to perform (see below for list)
12 ---@field arg? string|number|string[] Optional argument for the action
13
14 ---@class KeyChord
15 ---@field keys {modifiers: string[], key: string}[] Sequence of keys to press
16 ---@field action string Action to perform when chord completes
17 ---@field arg? string|number|string[] Optional argument for the action
18
19 ---@class StatusBlock
20 ---@field format string Display format with {} placeholders
21 ---@field command string Command type: "Ram", "DateTime", "Shell", "Static", "Battery"
22 ---@field command_arg? string Argument for command (shell command, date format, etc.)
23 ---@field interval_secs number Update interval in seconds
24 ---@field color number Color as hex number (e.g., 0xff0000 for red)
25 ---@field underline boolean Whether to show underline
26 ---@field battery_formats? {charging: string, discharging: string, full: string} Battery format strings
27
28 ---@class ColorScheme
29 ---@field foreground number Foreground color (hex)
30 ---@field background number Background color (hex)
31 ---@field underline number Underline color (hex)
32
33 ---@class Config
34 ---@field border_width number Width of window borders in pixels
35 ---@field border_focused number Color for focused window border (hex)
36 ---@field border_unfocused number Color for unfocused window border (hex)
37 ---@field font string Font specification (e.g., "monospace:style=Bold:size=10")
38 ---@field gaps_enabled boolean Whether gaps are enabled
39 ---@field gap_inner_horizontal number Inner horizontal gap size
40 ---@field gap_inner_vertical number Inner vertical gap size
41 ---@field gap_outer_horizontal number Outer horizontal gap size
42 ---@field gap_outer_vertical number Outer vertical gap size
43 ---@field modkey string Main modifier key (e.g., "Mod4" for Super)
44 ---@field terminal string Terminal emulator command
45 ---@field tags string[] List of workspace tag names
46 ---@field layout_symbols LayoutSymbol[] Custom layout symbols
47 ---@field keybindings (KeyBinding|KeyChord)[] List of keybindings
48 ---@field status_blocks StatusBlock[] Status bar configuration blocks
49 ---@field scheme_normal ColorScheme Color scheme for normal tags
50 ---@field scheme_occupied ColorScheme Color scheme for occupied tags
51 ---@field scheme_selected ColorScheme Color scheme for selected tag
52 ---@field autostart string[] Commands to run on startup
53
54 -- Available Actions:
55 -- "Spawn" - Launch a program (arg: string or string[])
56 -- "KillClient" - Close focused window
57 -- "FocusStack" - Focus next/prev in stack (arg: 1 or -1)
58 -- "FocusDirection" - Focus by direction (arg: 0=up, 1=down, 2=left, 3=right)
59 -- "SwapDirection" - Swap window by direction (arg: 0=up, 1=down, 2=left, 3=right)
60 -- "Quit" - Exit window manager
61 -- "Restart" - Restart and reload config
62 -- "Recompile" - Recompile and restart
63 -- "ViewTag" - Switch to tag (arg: tag index)
64 -- "MoveToTag" - Move window to tag (arg: tag index)
65 -- "ToggleGaps" - Toggle gaps on/off
66 -- "ToggleFullScreen" - Toggle fullscreen mode
67 -- "ToggleFloating" - Toggle floating mode
68 -- "ChangeLayout" - Switch to specific layout (arg: layout name)
69 -- "CycleLayout" - Cycle through layouts
70 -- "FocusMonitor" - Focus monitor (arg: 1 or -1)
71 -- "SmartMoveWin" - Smart window movement
72 -- "ExchangeClient" - Exchange window positions
73
74 -- Available Modifiers:
75 -- "Mod" - Replaced with configured modkey
76 -- "Mod1" - Alt key
77 -- "Mod4" - Super/Windows key
78 -- "Shift" - Shift key
79 -- "Control" - Control key
80 -- "Mod2", "Mod3", "Mod5" - Additional modifiers
81
82 -- Define variables for easy customization
83 local terminal = "st"
84 local modkey = "Mod4"
85 local secondary_modkey = "Mod1"
86
87 -- Color palette (Tokyo Night theme)
88 local colors = {
89 blue = 0x6dade3,
90 grey = 0xbbbbbb,
91 green = 0x9ece6a,
92 red = 0xf7768e,
93 cyan = 0x0db9d7,
94 purple = 0xad8ee6,
95 lavender = 0xa9b1d6,
96 bg = 0x1a1b26,
97 fg = 0xbbbbbb,
98 light_blue = 0x7aa2f7,
99 }
100
101 -- Main configuration table
102 ---@type Config
103 config = {
104 -- Appearance
105 border_width = 2,
106 border_focused = colors.blue,
107 border_unfocused = colors.grey,
108 font = "monospace:style=Bold:size=10",
109
110 -- Window gaps
111 gaps_enabled = true,
112 gap_inner_horizontal = 5,
113 gap_inner_vertical = 5,
114 gap_outer_horizontal = 5,
115 gap_outer_vertical = 5,
116
117 -- Basics
118 modkey = modkey,
119 terminal = terminal,
120
121 -- Workspace tags
122 tags = {"1", "2", "3", "4", "5", "6", "7", "8", "9"},
123
124 -- Layout symbol overrides
125 layout_symbols = {
126 {name = "tiling", symbol = "[T]"},
127 {name = "normie", symbol = "[F]"},
128 },
129
130 -- Keybindings
131 --
132 -- Format:
133 -- Single key: {modifiers = {...}, key = "X", action = "...", arg = ...}
134 -- Keychord: {keys = {{modifiers = {...}, key = "X"}, {modifiers = {...}, key = "Y"}}, action = "...", arg = ...}
135 --
136 -- Available modifiers: "Mod", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5", "Shift", "Control"
137 -- "Mod" will be replaced with the configured modkey
138 --
139 -- Available actions:
140 -- "Spawn", "KillClient", "FocusStack", "FocusDirection", "SwapDirection",
141 -- "Quit", "Restart", "Recompile", "ViewTag", "ToggleGaps", "ToggleFullScreen",
142 -- "ToggleFloating", "ChangeLayout", "CycleLayout", "MoveToTag", "FocusMonitor",
143 -- "SmartMoveWin", "ExchangeClient"
144 --
145 -- arg can be: string, number, array of strings, or omitted (nil)
146 --
147 -- You can cancel any in-progress keychord by pressing Escape.
148 keybindings = {
149 -- Basic window management
150 {modifiers = {"Mod"}, key = "Return", action = "Spawn", arg = terminal},
151 {modifiers = {"Mod"}, key = "D", action = "Spawn", arg = {"sh", "-c", "dmenu_run -l 10"}},
152 {modifiers = {"Mod"}, key = "S", action = "Spawn", arg = {"sh", "-c", "maim -s | xclip -selection clipboard -t image/png"}},
153 {modifiers = {"Mod"}, key = "Q", action = "KillClient"},
154 {modifiers = {"Mod", "Shift"}, key = "F", action = "ToggleFullScreen"},
155 {modifiers = {"Mod", "Shift"}, key = "Space", action = "ToggleFloating"},
156
157 -- Layout management
158 {modifiers = {"Mod"}, key = "F", action = "ChangeLayout", arg = "normie"},
159 {modifiers = {"Mod"}, key = "C", action = "ChangeLayout", arg = "tiling"},
160 {modifiers = {secondary_modkey}, key = "N", action = "CycleLayout"},
161 {modifiers = {"Mod"}, key = "A", action = "ToggleGaps"},
162
163 -- WM control
164 {modifiers = {"Mod", "Shift"}, key = "Q", action = "Quit"},
165 {modifiers = {"Mod", "Shift"}, key = "R", action = "Restart"},
166
167 -- Focus movement (vim-style hjkl)
168 {modifiers = {"Mod"}, key = "H", action = "FocusDirection", arg = 2}, -- left
169 {modifiers = {"Mod"}, key = "J", action = "FocusDirection", arg = 1}, -- down
170 {modifiers = {"Mod"}, key = "K", action = "FocusDirection", arg = 0}, -- up
171 {modifiers = {"Mod"}, key = "L", action = "FocusDirection", arg = 3}, -- right
172
173 -- Window swapping (vim-style hjkl)
174 {modifiers = {"Mod", "Shift"}, key = "H", action = "SwapDirection", arg = 2}, -- left
175 {modifiers = {"Mod", "Shift"}, key = "J", action = "SwapDirection", arg = 1}, -- down
176 {modifiers = {"Mod", "Shift"}, key = "K", action = "SwapDirection", arg = 0}, -- up
177 {modifiers = {"Mod", "Shift"}, key = "L", action = "SwapDirection", arg = 3}, -- right
178
179 -- Monitor focus
180 {modifiers = {"Mod"}, key = "Comma", action = "FocusMonitor", arg = -1},
181 {modifiers = {"Mod"}, key = "Period", action = "FocusMonitor", arg = 1},
182
183 -- View tags
184 {modifiers = {"Mod"}, key = "1", action = "ViewTag", arg = 0},
185 {modifiers = {"Mod"}, key = "2", action = "ViewTag", arg = 1},
186 {modifiers = {"Mod"}, key = "3", action = "ViewTag", arg = 2},
187 {modifiers = {"Mod"}, key = "4", action = "ViewTag", arg = 3},
188 {modifiers = {"Mod"}, key = "5", action = "ViewTag", arg = 4},
189 {modifiers = {"Mod"}, key = "6", action = "ViewTag", arg = 5},
190 {modifiers = {"Mod"}, key = "7", action = "ViewTag", arg = 6},
191 {modifiers = {"Mod"}, key = "8", action = "ViewTag", arg = 7},
192 {modifiers = {"Mod"}, key = "9", action = "ViewTag", arg = 8},
193
194 -- Move window to tag
195 {modifiers = {"Mod", "Shift"}, key = "1", action = "MoveToTag", arg = 0},
196 {modifiers = {"Mod", "Shift"}, key = "2", action = "MoveToTag", arg = 1},
197 {modifiers = {"Mod", "Shift"}, key = "3", action = "MoveToTag", arg = 2},
198 {modifiers = {"Mod", "Shift"}, key = "4", action = "MoveToTag", arg = 3},
199 {modifiers = {"Mod", "Shift"}, key = "5", action = "MoveToTag", arg = 4},
200 {modifiers = {"Mod", "Shift"}, key = "6", action = "MoveToTag", arg = 5},
201 {modifiers = {"Mod", "Shift"}, key = "7", action = "MoveToTag", arg = 6},
202 {modifiers = {"Mod", "Shift"}, key = "8", action = "MoveToTag", arg = 7},
203 {modifiers = {"Mod", "Shift"}, key = "9", action = "MoveToTag", arg = 8},
204
205 -- Example keychord: Mod+Space, then T to spawn terminal
206 {
207 keys = {
208 {modifiers = {"Mod4"}, key = "Space"},
209 {modifiers = {}, key = "T"}
210 },
211 action = "Spawn",
212 arg = terminal
213 },
214 },
215
216 -- Status bar blocks
217 --
218 -- Available commands:
219 -- "Ram" - Shows RAM usage (no command_arg needed)
220 -- "DateTime" - Shows date/time with strftime format in command_arg
221 -- "Shell" - Runs shell command from command_arg
222 -- "Static" - Static text from command_arg
223 -- "Battery" - Shows battery status (requires battery_formats table)
224 --
225 -- Battery formats example:
226 -- battery_formats = {
227 -- charging = "⚡ {}%",
228 -- discharging = "🔋 {}%",
229 -- full = "✓ {}%"
230 -- }
231 status_blocks = {
232 {
233 format = "Ram: {used}/{total} GB",
234 command = "Ram",
235 interval_secs = 5,
236 color = colors.light_blue,
237 underline = true
238 },
239 {
240 format = " │ ",
241 command = "Static",
242 interval_secs = 999999999, -- Very large number for static blocks (never update)
243 color = colors.lavender,
244 underline = false
245 },
246 {
247 format = "Kernel: {}",
248 command = "Shell",
249 command_arg = "uname -r",
250 interval_secs = 999999999,
251 color = colors.red,
252 underline = true
253 },
254 {
255 format = " │ ",
256 command = "Static",
257 interval_secs = 999999999,
258 color = colors.lavender,
259 underline = false
260 },
261 {
262 format = "{}",
263 command = "DateTime",
264 command_arg = "%a, %b %d - %-I:%M %P",
265 interval_secs = 1,
266 color = colors.cyan,
267 underline = true
268 },
269 },
270
271 -- Color schemes for bar
272 scheme_normal = {
273 foreground = colors.fg,
274 background = colors.bg,
275 underline = 0x444444
276 },
277 scheme_occupied = {
278 foreground = colors.cyan,
279 background = colors.bg,
280 underline = colors.cyan
281 },
282 scheme_selected = {
283 foreground = colors.cyan,
284 background = colors.bg,
285 underline = colors.purple
286 },
287
288 -- Autostart commands
289 -- These are executed when the window manager starts
290 -- Add your startup applications here
291 autostart = {
292 -- Uncomment and add your autostart commands:
293 -- "picom -b",
294 -- "nitrogen --restore &",
295 -- "dunst &",
296 },
297 }
298
299 -- You can also add helper functions for more complex configs:
300 --
301 -- Example: Generate keybindings programmatically
302 -- for i = 1, 9 do
303 -- table.insert(config.keybindings, {
304 -- modifiers = {"Mod"},
305 -- key = tostring(i),
306 -- action = "ViewTag",
307 -- arg = i - 1
308 -- })
309 -- end