oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

Added a couple of functions to lua parser for zig.

Commit
a8a8323549b5dc0eb98032e81bbe34c2278b6fa1
Parent
e95e4af
Author
tonybanters <tonybanters@gmail.com>
Date
2026-02-02 08:30:41

Diff

diff --git a/build.zig b/build.zig
index 493ee08..30e883d 100644
--- a/build.zig
+++ b/build.zig
@@ -70,7 +70,7 @@ fn add_xephyr_run(b: *std.Build, exe: *std.Build.Step.Compile, multimon: bool) *
     const run_wm = b.addRunArtifact(exe);
     run_wm.step.dependOn(&setup.step);
     run_wm.setEnvironmentVariable("DISPLAY", ":2");
-    run_wm.addArgs(&.{ "-c", "resources/config.lua" });
+    run_wm.addArgs(&.{ "-c", "resources/test-config.lua" });
 
     return run_wm;
 }
diff --git a/resources/test-config.lua b/resources/test-config.lua
index ecad11d..c52da7f 100644
--- a/resources/test-config.lua
+++ b/resources/test-config.lua
@@ -107,50 +107,50 @@ oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1))
 oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1))
 
 -- View tag (switch workspace)
-oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
-oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
-oxwm.key.bind({ modkey }, "3", oxwm.tag.view(2))
-oxwm.key.bind({ modkey }, "4", oxwm.tag.view(3))
-oxwm.key.bind({ modkey }, "5", oxwm.tag.view(4))
-oxwm.key.bind({ modkey }, "6", oxwm.tag.view(5))
-oxwm.key.bind({ modkey }, "7", oxwm.tag.view(6))
-oxwm.key.bind({ modkey }, "8", oxwm.tag.view(7))
-oxwm.key.bind({ modkey }, "9", oxwm.tag.view(8))
+oxwm.key.bind({ modkey }, "1", oxwm.tag.view(1))
+oxwm.key.bind({ modkey }, "2", oxwm.tag.view(2))
+oxwm.key.bind({ modkey }, "3", oxwm.tag.view(3))
+oxwm.key.bind({ modkey }, "4", oxwm.tag.view(4))
+oxwm.key.bind({ modkey }, "5", oxwm.tag.view(5))
+oxwm.key.bind({ modkey }, "6", oxwm.tag.view(6))
+oxwm.key.bind({ modkey }, "7", oxwm.tag.view(7))
+oxwm.key.bind({ modkey }, "8", oxwm.tag.view(8))
+oxwm.key.bind({ modkey }, "9", oxwm.tag.view(9))
 
 -- Move window to tag
-oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(0))
-oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(1))
-oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(2))
-oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(3))
-oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(4))
-oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(5))
-oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(6))
-oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(7))
-oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(8))
+oxwm.key.bind({ modkey, "Shift" }, "1", oxwm.tag.move_to(1))
+oxwm.key.bind({ modkey, "Shift" }, "2", oxwm.tag.move_to(2))
+oxwm.key.bind({ modkey, "Shift" }, "3", oxwm.tag.move_to(3))
+oxwm.key.bind({ modkey, "Shift" }, "4", oxwm.tag.move_to(4))
+oxwm.key.bind({ modkey, "Shift" }, "5", oxwm.tag.move_to(5))
+oxwm.key.bind({ modkey, "Shift" }, "6", oxwm.tag.move_to(6))
+oxwm.key.bind({ modkey, "Shift" }, "7", oxwm.tag.move_to(7))
+oxwm.key.bind({ modkey, "Shift" }, "8", oxwm.tag.move_to(8))
+oxwm.key.bind({ modkey, "Shift" }, "9", oxwm.tag.move_to(9))
 
 -- Toggle view (view multiple tags at once) - dwm-style multi-tag viewing
 -- Example: Mod+Ctrl+2 while on tag 1 will show BOTH tags 1 and 2
-oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(0))
-oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(1))
-oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(2))
-oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(3))
-oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(4))
-oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(5))
-oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(6))
-oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(7))
-oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(8))
+oxwm.key.bind({ modkey, "Control" }, "1", oxwm.tag.toggleview(1))
+oxwm.key.bind({ modkey, "Control" }, "2", oxwm.tag.toggleview(2))
+oxwm.key.bind({ modkey, "Control" }, "3", oxwm.tag.toggleview(3))
+oxwm.key.bind({ modkey, "Control" }, "4", oxwm.tag.toggleview(4))
+oxwm.key.bind({ modkey, "Control" }, "5", oxwm.tag.toggleview(5))
+oxwm.key.bind({ modkey, "Control" }, "6", oxwm.tag.toggleview(6))
+oxwm.key.bind({ modkey, "Control" }, "7", oxwm.tag.toggleview(7))
+oxwm.key.bind({ modkey, "Control" }, "8", oxwm.tag.toggleview(8))
+oxwm.key.bind({ modkey, "Control" }, "9", oxwm.tag.toggleview(9))
 
 -- Toggle tag (window on multiple tags) - dwm-style sticky windows
 -- Example: Mod+Ctrl+Shift+2 puts focused window on BOTH current tag and tag 2
-oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(0))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(1))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(2))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(3))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(4))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(5))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(6))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(7))
-oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(8))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "1", oxwm.tag.toggletag(1))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "2", oxwm.tag.toggletag(2))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "3", oxwm.tag.toggletag(3))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "4", oxwm.tag.toggletag(4))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "5", oxwm.tag.toggletag(5))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "6", oxwm.tag.toggletag(6))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "7", oxwm.tag.toggletag(7))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "8", oxwm.tag.toggletag(8))
+oxwm.key.bind({ modkey, "Control", "Shift" }, "9", oxwm.tag.toggletag(9))
 
 oxwm.key.bind({ modkey }, "Tab", oxwm.tag.view_next())
 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())
 oxwm.key.bind({ modkey, "Control", "Shift" }, "Tab", oxwm.tag.view_previous_nonempty())
 
 oxwm.bar.set_blocks({
+
     oxwm.bar.block.battery({
-        format = "Bat: {}%",
-        charging = "⚡ Bat: {}%",
-        discharging = "🔋 Bat: {}%",
-        full = "✓ Bat: {}%",
+        fmt_charging = "⚡ Bat: {}%",
+        fmt_discharging = "- Bat: {}%",
+        fmt_full = "✓ Bat: {}%",
         interval = 30,
         color = colors.green,
         underline = true,
@@ -179,20 +179,20 @@ oxwm.bar.set_blocks({
     --     underline = true
     -- }),
     oxwm.bar.block.static({
-        text = " │  ",
+        text = "│",
         format = "",
         interval = 999999999,
         color = colors.lavender,
         underline = false
     }),
     oxwm.bar.block.ram({
-        format = "󰍛 {used}/{total} GB",
+        format = "  {used}/{total} GB",
         interval = 5,
         color = colors.light_blue,
         underline = true
     }),
     oxwm.bar.block.static({
-        text = " │  ",
+        text = "│",
         format = "",
         interval = 999999999,
         color = colors.lavender,
@@ -200,13 +200,13 @@ oxwm.bar.set_blocks({
     }),
     oxwm.bar.block.shell({
         command = "uname -r",
-        format = " {}",
+        format = " {}",
         interval = 999999999,
         color = colors.red,
         underline = true
     }),
     oxwm.bar.block.static({
-        text = " │  ",
+        text = "│",
         format = "",
         interval = 999999999,
         color = colors.lavender,
diff --git a/src/config/config.zig b/src/config/config.zig
index a8986b8..775e1e0 100644
--- a/src/config/config.zig
+++ b/src/config/config.zig
@@ -7,6 +7,7 @@ pub const Action = enum {
     quit,
     reload_config,
     restart,
+    show_keybinds,
     focus_next,
     focus_prev,
     move_next,
@@ -127,6 +128,7 @@ pub const Config = struct {
     layout_tile_symbol: []const u8 = "[]=",
     layout_monocle_symbol: []const u8 = "[M]",
     layout_floating_symbol: []const u8 = "><>",
+    layout_scrolling_symbol: []const u8 = "[S]",
 
     scheme_normal: Color_Scheme = .{ .fg = 0xbbbbbb, .bg = 0x1a1b26, .border = 0x444444 },
     scheme_selected: Color_Scheme = .{ .fg = 0x0db9d7, .bg = 0x1a1b26, .border = 0xad8ee6 },
diff --git a/src/config/lua.zig b/src/config/lua.zig
index 96473f5..6296639 100644
--- a/src/config/lua.zig
+++ b/src/config/lua.zig
@@ -300,6 +300,9 @@ fn register_misc_functions(state: *c.lua_State) void {
     c.lua_pushcfunction(state, lua_set_tags);
     c.lua_setfield(state, -2, "set_tags");
 
+    c.lua_pushcfunction(state, lua_set_layout_symbol);
+    c.lua_setfield(state, -2, "set_layout_symbol");
+
     c.lua_pushcfunction(state, lua_autostart);
     c.lua_setfield(state, -2, "autostart");
 
@@ -315,6 +318,9 @@ fn register_misc_functions(state: *c.lua_State) void {
     c.lua_pushcfunction(state, lua_toggle_gaps);
     c.lua_setfield(state, -2, "toggle_gaps");
 
+    c.lua_pushcfunction(state, lua_show_keybinds);
+    c.lua_setfield(state, -2, "show_keybinds");
+
     c.lua_pushcfunction(state, lua_set_master_factor);
     c.lua_setfield(state, -2, "set_master_factor");
 
@@ -952,6 +958,32 @@ fn lua_auto_tile(state: ?*c.lua_State) callconv(.c) c_int {
     return 0;
 }
 
+fn lua_set_layout_symbol(state: ?*c.lua_State) callconv(.c) c_int {
+    const cfg = config orelse return 0;
+    const s = state orelse return 0;
+    const name = get_string_arg(s, 1) orelse return 0;
+    const symbol = get_string_arg(s, 2) orelse return 0;
+
+    const layout_map = .{
+        .{ "tiling", &cfg.layout_tile_symbol },
+        .{ "tile", &cfg.layout_tile_symbol },
+        .{ "normie", &cfg.layout_floating_symbol },
+        .{ "floating", &cfg.layout_floating_symbol },
+        .{ "float", &cfg.layout_floating_symbol },
+        .{ "monocle", &cfg.layout_monocle_symbol },
+        .{ "scrolling", &cfg.layout_scrolling_symbol },
+        .{ "scroll", &cfg.layout_scrolling_symbol },
+    };
+
+    inline for (layout_map) |entry| {
+        if (std.mem.eql(u8, name, entry[0])) {
+            entry[1].* = symbol;
+            return 0;
+        }
+    }
+    return 0;
+}
+
 fn lua_quit(state: ?*c.lua_State) callconv(.c) c_int {
     const s = state orelse return 0;
     create_action_table(s, "Quit");
@@ -970,6 +1002,12 @@ fn lua_toggle_gaps(state: ?*c.lua_State) callconv(.c) c_int {
     return 1;
 }
 
+fn lua_show_keybinds(state: ?*c.lua_State) callconv(.c) c_int {
+    const s = state orelse return 0;
+    create_action_table(s, "ShowKeybinds");
+    return 1;
+}
+
 fn lua_set_master_factor(state: ?*c.lua_State) callconv(.c) c_int {
     const s = state orelse return 0;
     const delta: i32 = @intCast(c.lua_tointegerx(s, 1, null));
@@ -1063,6 +1101,7 @@ fn parse_action(name: []const u8) ?Action {
         .{ "KillClient", Action.kill_client },
         .{ "Quit", Action.quit },
         .{ "Restart", Action.restart },
+        .{ "ShowKeybinds", Action.show_keybinds },
         .{ "FocusStack", Action.focus_next },
         .{ "MoveStack", Action.move_next },
         .{ "ResizeMaster", Action.resize_master },
diff --git a/src/main.zig b/src/main.zig
index df7e022..21c5fdc 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -735,6 +735,7 @@ fn execute_action(display: *Display, action: config_mod.Action, int_arg: i32, st
         },
         .reload_config => reload_config(display),
         .restart => {},
+        .show_keybinds => {},
         .focus_next => focusstack(display, 1),
         .focus_prev => focusstack(display, -1),
         .move_next => movestack(display, 1),
diff --git a/templates/config.lua b/templates/config.lua
index 1892373..2eb499c 100644
--- a/templates/config.lua
+++ b/templates/config.lua
@@ -25,7 +25,7 @@ local modkey = "Mod4"
 local terminal = "alacritty"
 
 -- Color palette - customize these to match your theme
--- Alternatively you can import other files in here, such as 
+-- Alternatively you can import other files in here, such as
 -- local colors = require("colors.lua") and make colors.lua a file
 -- in the ~/.config/oxwm directory
 local colors = {
@@ -58,7 +58,7 @@ local blocks = {
         underline = true,
     }),
     oxwm.bar.block.static({
-        text = " │  ",
+        text = "│",
         interval = 999999999,
         color = colors.lavender,
         underline = false,
@@ -71,7 +71,7 @@ local blocks = {
         underline = true,
     }),
     oxwm.bar.block.static({
-        text = " │  ",
+        text = "│",
         interval = 999999999,
         color = colors.lavender,
         underline = false,
@@ -84,15 +84,15 @@ local blocks = {
         underline = true,
     }),
     -- Uncomment to add battery status (useful for laptops)
-    -- oxwm.bar.block.battery({
-    --     format = "Bat: {}%",
-    --     charging = "⚡ Bat: {}%",
-    --     discharging = "- Bat: {}%",
-    --     full = "✓ Bat: {}%",
-    --     interval = 30,
-    --     color = colors.green,
-    --     underline = true,
-    -- }),
+    oxwm.bar.block.battery({
+        format = "Bat: {}%",
+        charging = "⚡ Bat: {}%",
+        discharging = "- Bat: {}%",
+        full = "✓ Bat: {}%",
+        interval = 30,
+        color = colors.green,
+        underline = true,
+    }),
 };
 
 -------------------------------------------------------------------------------
@@ -143,11 +143,11 @@ oxwm.gaps.set_outer(5, 5)
 -- - Configure window behavior based on title or class
 
 -- Examples (uncomment to use):
-oxwm.rule.add({ instance = "gimp", floating = true })                             
--- oxwm.rule.add({ class = "Alacritty", tag = 9, focus = true })                             
--- oxwm.rule.add({ class = "firefox", title = "Library", floating = true })  
--- oxwm.rule.add({ class = "firefox", tag = 2 })  
--- oxwm.rule.add({ instance = "mpv", floating = true })                      
+oxwm.rule.add({ instance = "gimp", floating = true })
+-- oxwm.rule.add({ class = "Alacritty", tag = 9, focus = true })
+-- oxwm.rule.add({ class = "firefox", title = "Library", floating = true })
+-- oxwm.rule.add({ class = "firefox", tag = 2 })
+-- oxwm.rule.add({ instance = "mpv", floating = true })
 
 -- To find window properties, use xprop and click on the window
 -- WM_CLASS(STRING) shows both instance and class (instance, class)
@@ -194,7 +194,7 @@ oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal())
 oxwm.key.bind({ modkey }, "D", oxwm.spawn({ "sh", "-c", "dmenu_run -l 10" }))
 -- Copy screenshot to clipboard
 oxwm.key.bind({ modkey }, "S", oxwm.spawn({ "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" }))
-oxwm.key.bind({ modkey }, "Q", oxwm.client.kill()) 
+oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())
 
 -- Keybind overlay - Shows important keybindings on screen
 oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
@@ -306,7 +306,7 @@ oxwm.key.chord({
 -- Commands to run once when OXWM starts
 -- Uncomment and modify these examples, or add your own
 
--- oxwm.autostart("picom")                                  
--- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg") 
+-- oxwm.autostart("picom")
+-- oxwm.autostart("feh --bg-scale ~/wallpaper.jpg")
 -- oxwm.autostart("dunst")
 -- oxwm.autostart("nm-applet")