tony / oxwm

Added a couple of functions to lua parser for zig. Browse files
tonybanters committed 2026-02-02 parent e95e4af commit a8a8323549b5dc0eb98032e81bbe34c2278b6fa1
Showing 6 changed files with 108 additions and 66 deletions. UnifiedSplit
+1 −1 build.zig
@@ -70,7 +70,7 @@ fn add_xephyr_run(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *
70 70 const run_wm = b.addRunArtifact(exe);
71 71 run_wm.step.dependOn(&setup.step);
72 72 run_wm.setEnvironmentVariable("DISPLAY", ":2");
73 - run_wm.addArgs(&.{ "-c", "resources/config.lua" });
73 + run_wm.addArgs(&.{ "-c", "resources/test-config.lua" });
74 74
75 75 return run_wm;
76 76 }
+45 −45 resources/test-config.lua
@@ -107,50 +107,50 @@ oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1))
107 107 oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1))
108 108
109 109 -- View tag (switch workspace)
110 -oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
111 -oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
112 -oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
113 -oxwm.key.bind({ modkey }, "4", oxwm.tag.view(3))
114 -oxwm.key.bind({ modkey }, "5", oxwm.tag.view(4))
115 -oxwm.key.bind({ modkey }, "6", oxwm.tag.view(5))
116 -oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
117 -oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
118 -oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
110 +oxwm.key.bind({ modkey }, "1", oxwm.tag.view(1))
111 +oxwm.key.bind({ modkey }, "2", oxwm.tag.view(2))
112 +oxwm.key.bind({ modkey }, "3", oxwm.tag.view(3))
113 +oxwm.key.bind({ modkey }, "4", oxwm.tag.view(4))
114 +oxwm.key.bind({ modkey }, "5", oxwm.tag.view(5))
115 +oxwm.key.bind({ modkey }, "6", oxwm.tag.view(6))
116 +oxwm.key.bind({ modkey }, "7", oxwm.tag.view(7))
117 +oxwm.key.bind({ modkey }, "8", oxwm.tag.view(8))
118 +oxwm.key.bind({ modkey }, "9", oxwm.tag.view(9))
119 119
120 120 -- Move window to tag
121 -oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
122 -oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
123 -oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
124 -oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(3))
125 -oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(4))
126 -oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(5))
127 -oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
128 -oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
129 -oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
121 +oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(1))
122 +oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(2))
123 +oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(3))
124 +oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(4))
125 +oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(5))
126 +oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(6))
127 +oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(7))
128 +oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(8))
129 +oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(9))
130 130
131 131 -- Toggle view (view multiple tags at once) - dwm-style multi-tag viewing
132 132 -- Example: Mod+Ctrl+2 while on tag 1 will show BOTH tags 1 and 2
133 -oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(0))
134 -oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(1))
135 -oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(2))
136 -oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(3))
137 -oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(4))
138 -oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(5))
139 -oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(6))
140 -oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(7))
141 -oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(8))
133 +oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(1))
134 +oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(2))
135 +oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(3))
136 +oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(4))
137 +oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(5))
138 +oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(6))
139 +oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(7))
140 +oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(8))
141 +oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(9))
142 142
143 143 -- Toggle tag (window on multiple tags) - dwm-style sticky windows
144 144 -- Example: Mod+Ctrl+Shift+2 puts focused window on BOTH current tag and tag 2
145 -oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(0))
146 -oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(1))
147 -oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(2))
148 -oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(3))
149 -oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(4))
150 -oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(5))
151 -oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
152 -oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
153 -oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
145 +oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(1))
146 +oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(2))
147 +oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(3))
148 +oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(4))
149 +oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(5))
150 +oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(6))
151 +oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(7))
152 +oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(8))
153 +oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(9))
154 154
155 155 oxwm.key.bind({ modkey }, "Tab", oxwm.tag.view_next())
156 156 oxwm.key.bind({ modkey, "Shift" }, "Tab", oxwm.tag.view_previous())
@@ -159,11 +159,11 @@ oxwm.key.bind({ modkey, "Control" }, "Tab", oxwm.tag.view_next_nonempty())
159 159 oxwm.key.bind({ modkey, "Control", "Shift" }, "Tab", oxwm.tag.view_previous_nonempty())
160 160
161 161 oxwm.bar.set_blocks({
162 +
162 163 oxwm.bar.block.battery({
163 - format = "Bat: {}%",
164 - charging = "⚡ Bat: {}%",
165 - discharging = "🔋 Bat: {}%",
166 - full = "✓ Bat: {}%",
164 + fmt_charging = "⚡ Bat: {}%",
165 + fmt_discharging = "- Bat: {}%",
166 + fmt_full = "✓ Bat: {}%",
167 167 interval = 30,
168 168 color = colors.green,
169 169 underline = true,
@@ -179,20 +179,20 @@ oxwm.bar.set_blocks({
179 179 -- underline = true
180 180 -- }),
181 181 oxwm.bar.block.static({
182 - text = " │ ",
182 + text = "│",
183 183 format = "",
184 184 interval = 999999999,
185 185 color = colors.lavender,
186 186 underline = false
187 187 }),
188 188 oxwm.bar.block.ram({
189 - format = "󰍛 {used}/{total} GB",
189 + format = " {used}/{total} GB",
190 190 interval = 5,
191 191 color = colors.light_blue,
192 192 underline = true
193 193 }),
194 194 oxwm.bar.block.static({
195 - text = " │ ",
195 + text = "│",
196 196 format = "",
197 197 interval = 999999999,
198 198 color = colors.lavender,
@@ -200,13 +200,13 @@ oxwm.bar.set_blocks({
200 200 }),
201 201 oxwm.bar.block.shell({
202 202 command = "uname -r",
203 - format = " {}",
203 + format = " {}",
204 204 interval = 999999999,
205 205 color = colors.red,
206 206 underline = true
207 207 }),
208 208 oxwm.bar.block.static({
209 - text = " │ ",
209 + text = "│",
210 210 format = "",
211 211 interval = 999999999,
212 212 color = colors.lavender,
+2 −0 src/config/config.zig
@@ -7,6 +7,7 @@ pub const Action = enum {
7 7 quit,
8 8 reload_config,
9 9 restart,
10 + show_keybinds,
10 11 focus_next,
11 12 focus_prev,
12 13 move_next,
@@ -127,6 +128,7 @@ pub const Config = struct {
127 128 layout_tile_symbol: []const u8 = "[]=",
128 129 layout_monocle_symbol: []const u8 = "[M]",
129 130 layout_floating_symbol: []const u8 = "><>",
131 + layout_scrolling_symbol: []const u8 = "[S]",
130 132
131 133 scheme_normal: Color_Scheme = .{ .fg = 0xbbbbbb, .bg = 0x1a1b26, .border = 0x444444 },
132 134 scheme_selected: Color_Scheme = .{ .fg = 0x0db9d7, .bg = 0x1a1b26, .border = 0xad8ee6 },
+39 −0 src/config/lua.zig
@@ -300,6 +300,9 @@ fn register_misc_functions(state: *c.lua_State) void {
300 300 c.lua_pushcfunction(state, lua_set_tags);
301 301 c.lua_setfield(state, -2, "set_tags");
302 302
303 + c.lua_pushcfunction(state, lua_set_layout_symbol);
304 + c.lua_setfield(state, -2, "set_layout_symbol");
305 +
303 306 c.lua_pushcfunction(state, lua_autostart);
304 307 c.lua_setfield(state, -2, "autostart");
305 308
@@ -315,6 +318,9 @@ fn register_misc_functions(state: *c.lua_State) void {
315 318 c.lua_pushcfunction(state, lua_toggle_gaps);
316 319 c.lua_setfield(state, -2, "toggle_gaps");
317 320
321 + c.lua_pushcfunction(state, lua_show_keybinds);
322 + c.lua_setfield(state, -2, "show_keybinds");
323 +
318 324 c.lua_pushcfunction(state, lua_set_master_factor);
319 325 c.lua_setfield(state, -2, "set_master_factor");
320 326
@@ -952,6 +958,32 @@ fn lua_auto_tile(state: ?*c.lua_State) callconv(.c) c_int {
952 958 return 0;
953 959 }
954 960
961 +fn lua_set_layout_symbol(state: ?*c.lua_State) callconv(.c) c_int {
962 + const cfg = config orelse return 0;
963 + const s = state orelse return 0;
964 + const name = get_string_arg(s, 1) orelse return 0;
965 + const symbol = get_string_arg(s, 2) orelse return 0;
966 +
967 + const layout_map = .{
968 + .{ "tiling", &cfg.layout_tile_symbol },
969 + .{ "tile", &cfg.layout_tile_symbol },
970 + .{ "normie", &cfg.layout_floating_symbol },
971 + .{ "floating", &cfg.layout_floating_symbol },
972 + .{ "float", &cfg.layout_floating_symbol },
973 + .{ "monocle", &cfg.layout_monocle_symbol },
974 + .{ "scrolling", &cfg.layout_scrolling_symbol },
975 + .{ "scroll", &cfg.layout_scrolling_symbol },
976 + };
977 +
978 + inline for (layout_map) |entry| {
979 + if (std.mem.eql(u8, name, entry[0])) {
980 + entry[1].* = symbol;
981 + return 0;
982 + }
983 + }
984 + return 0;
985 +}
986 +
955 987 fn lua_quit(state: ?*c.lua_State) callconv(.c) c_int {
956 988 const s = state orelse return 0;
957 989 create_action_table(s, "Quit");
@@ -970,6 +1002,12 @@ fn lua_toggle_gaps(state: ?*c.lua_State) callconv(.c) c_int {
970 1002 return 1;
971 1003 }
972 1004
1005 +fn lua_show_keybinds(state: ?*c.lua_State) callconv(.c) c_int {
1006 + const s = state orelse return 0;
1007 + create_action_table(s, "ShowKeybinds");
1008 + return 1;
1009 +}
1010 +
973 1011 fn lua_set_master_factor(state: ?*c.lua_State) callconv(.c) c_int {
974 1012 const s = state orelse return 0;
975 1013 const delta: i32 = @intCast(c.lua_tointegerx(s, 1, null));
@@ -1063,6 +1101,7 @@ fn parse_action(name: []const u8) ?Action {
1063 1101 .{ "KillClient", Action.kill_client },
1064 1102 .{ "Quit", Action.quit },
1065 1103 .{ "Restart", Action.restart },
1104 + .{ "ShowKeybinds", Action.show_keybinds },
1066 1105 .{ "FocusStack", Action.focus_next },
1067 1106 .{ "MoveStack", Action.move_next },
1068 1107 .{ "ResizeMaster", Action.resize_master },
+1 −0 src/main.zig
@@ -735,6 +735,7 @@ fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, st
735 735 },
736 736 .reload_config => reload_config(display),
737 737 .restart => {},
738 + .show_keybinds => {},
738 739 .focus_next => focusstack(display, 1),
739 740 .focus_prev => focusstack(display, -1),
740 741 .move_next => movestack(display, 1),
+20 −20 templates/config.lua
@@ -25,7 +25,7 @@ local modkey = "Mod4"
25 25 local terminal = "alacritty"
26 26
27 27 -- Color palette - customize these to match your theme
28 --- Alternatively you can import other files in here, such as
28 +-- Alternatively you can import other files in here, such as
29 29 -- local colors = require("colors.lua") and make colors.lua a file
30 30 -- in the ~/.config/oxwm directory
31 31 local colors = {
@@ -58,7 +58,7 @@ local blocks = {
58 58 underline = true,
59 59 }),
60 60 oxwm.bar.block.static({
61 - text = " │ ",
61 + text = "│",
62 62 interval = 999999999,
63 63 color = colors.lavender,
64 64 underline = false,
@@ -71,7 +71,7 @@ local blocks = {
71 71 underline = true,
72 72 }),
73 73 oxwm.bar.block.static({
74 - text = " │ ",
74 + text = "│",
75 75 interval = 999999999,
76 76 color = colors.lavender,
77 77 underline = false,
@@ -84,15 +84,15 @@ local blocks = {
84 84 underline = true,
85 85 }),
86 86 -- Uncomment to add battery status (useful for laptops)
87 - -- oxwm.bar.block.battery({
88 - -- format = "Bat: {}%",
89 - -- charging = "⚡ Bat: {}%",
90 - -- discharging = "- Bat: {}%",
91 - -- full = "✓ Bat: {}%",
92 - -- interval = 30,
93 - -- color = colors.green,
94 - -- underline = true,
95 - -- }),
87 + oxwm.bar.block.battery({
88 + format = "Bat: {}%",
89 + charging = "⚡ Bat: {}%",
90 + discharging = "- Bat: {}%",
91 + full = "✓ Bat: {}%",
92 + interval = 30,
93 + color = colors.green,
94 + underline = true,
95 + }),
96 96 };
97 97
98 98 -------------------------------------------------------------------------------
@@ -143,11 +143,11 @@ oxwm.gaps.set_outer(5, 5)
143 143 -- - Configure window behavior based on title or class
144 144
145 145 -- Examples (uncomment to use):
146 -oxwm.rule.add({ instance = "gimp", floating = true })
147 --- oxwm.rule.add({ class = "Alacritty", tag = 9, focus = true })
148 --- oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
149 --- oxwm.rule.add({ class = "firefox", tag = 2 })
150 --- oxwm.rule.add({ instance = "mpv", floating = true })
146 +oxwm.rule.add({ instance = "gimp", floating = true })
147 +-- oxwm.rule.add({ class = "Alacritty", tag = 9, focus = true })
148 +-- oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
149 +-- oxwm.rule.add({ class = "firefox", tag = 2 })
150 +-- oxwm.rule.add({ instance = "mpv", floating = true })
151 151
152 152 -- To find window properties, use xprop and click on the window
153 153 -- WM_CLASS(STRING) shows both instance and class (instance, class)
@@ -194,7 +194,7 @@ oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal())
194 194 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
195 195 -- Copy screenshot to clipboard
196 196 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
197 -oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
197 +oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
198 198
199 199 -- Keybind overlay - Shows important keybindings on screen
200 200 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
@@ -306,7 +306,7 @@ oxwm.key.chord({
306 306 -- Commands to run once when OXWM starts
307 307 -- Uncomment and modify these examples, or add your own
308 308
309 --- oxwm.autostart("picom")
310 --- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg")
309 +-- oxwm.autostart("picom")
310 +-- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg")
311 311 -- oxwm.autostart("dunst")
312 312 -- oxwm.autostart("nm-applet")