oxwm github discord tonybtw.com

Example config

A full config.lua, based on the one that ships with Tonarchy. Lua is a real language, so anything repetitive goes in a table and a for loop: the tag keys, the rules, the chords and the autostart list.

Save it as ~/.config/oxwm/config.lua, check it with oxwm --validate and press Mod+Shift+R to load it.

local modkey = "Mod4"
local terminal = "alacritty"

local colors = {
    bg = "#000000",
    fg = "#d4d4d4",
    red = "#f14c4c",
    cyan = "#9cdcfe",
    green = "#6a9955",
    light_blue = "#4ec9b0",
    blue = "#569cd6",
    purple = "#c586c0",
    yellow = "#dcdcaa",
    orange = "#ce9178",
    grey = "#808080",
    sep = "#3c3c3c",
}

oxwm.set_terminal(terminal)
oxwm.set_modkey(modkey)
oxwm.set_tags({ "1", "2", "3", "4", "5", "6", "7", "8", "9" })

oxwm.set_layout("tiling")
oxwm.set_tag_layout(2, "scrolling")
oxwm.set_tag_layout(9, "monocle")
oxwm.set_attach_method("aside")
oxwm.set_floating_position("center")
oxwm.auto_tile(true)
oxwm.tiled_resize_mode(true)

local symbols = {
    tiling = "[T]",
    dwindle = "[D]",
    grid = "[G]",
    monocle = "[M]",
    scrolling = "[S]",
    floating = "[F]",
}

for layout, symbol in pairs(symbols) do
    oxwm.set_layout_symbol(layout, symbol)
end

oxwm.scroll.set_default_width(0.5)
oxwm.scroll.set_width_presets({ 1 / 3, 1 / 2, 2 / 3, 1 })
oxwm.scroll.set_indicator(true)
oxwm.scroll.set_gesture_enabled(true)
oxwm.scroll.set_gesture_fingers(3)

oxwm.tag.set_back_and_forth(true)
oxwm.monitor.warp_cursor(true)
oxwm.monitor.warp_cursor_on_send(true)

oxwm.border.set_width(2)
oxwm.border.set_focused_color(colors.purple)
oxwm.border.set_unfocused_color(colors.grey)

oxwm.gaps.set_smart(true)
oxwm.gaps.set_inner(5, 5)
oxwm.gaps.set_outer(5, 5)

local rules = {
    { instance = "gimp", floating = true },
    { class = "firefox", tag = 3 },
    { class = "discord", tag = 8, monitor = 0 },
    { class = "mpv", floating = true },
    { title = "Picture-in-Picture", floating = true },
    { class = "Alacritty", width = 0.5 },
}

for _, rule in ipairs(rules) do
    oxwm.rule.add(rule)
end

local function sep()
    return oxwm.bar.block.static({
        text = "│",
        interval = 999999999,
        color = colors.sep,
        underline = false,
    })
end

local blocks = {
    oxwm.bar.block.shell({
        format = " {}",
        command = "uname -r",
        interval = 999999999,
        color = colors.red,
        underline = true,
    }),
    sep(),
    oxwm.bar.block.ram({
        format = "󰍛 Ram: {used}/{total} GB",
        interval = 5,
        color = colors.light_blue,
        underline = true,
        click = { command = terminal .. " -e btop", floating = true },
    }),
    sep(),
    oxwm.bar.block.battery({
        format = "Bat: {}%",
        charging = "⚡ Bat: {}%",
        discharging = "- Bat: {}%",
        full = "✓ Bat: {}%",
        interval = 30,
        color = colors.green,
        underline = true,
    }),
    sep(),
    oxwm.bar.block.datetime({
        format = "󰸘 {}",
        date_format = "%a, %b %d - %I:%M %P",
        interval = 1,
        color = colors.cyan,
        underline = true,
    }),
    sep(),
    oxwm.bar.block.systray({}),
}

oxwm.bar.set_font("JetBrainsMono Nerd Font Propo:style=Bold:size=12")
oxwm.bar.set_position("top")
oxwm.bar.set_hide_vacant_tags(false)
oxwm.bar.set_blocks(blocks)
oxwm.bar.set_scheme_normal(colors.fg, colors.bg, "#444444")
oxwm.bar.set_scheme_occupied(colors.blue, colors.bg, colors.cyan)
oxwm.bar.set_scheme_selected(colors.blue, colors.bg, colors.purple)
oxwm.bar.set_scheme_urgent(colors.red, colors.bg, colors.red)

oxwm.key.bind({ modkey }, "Return", oxwm.spawn_terminal())
oxwm.key.bind({ modkey }, "D", oxwm.spawn("rofi -show drun"))
oxwm.key.bind({ modkey }, "S", oxwm.spawn("maim -s | xclip -selection clipboard -t image/png"))
oxwm.key.bind({ modkey }, "Q", oxwm.client.kill())

oxwm.key.bind({ modkey, "Shift" }, "Slash", oxwm.show_keybinds())
oxwm.key.bind({ modkey, "Shift" }, "F", oxwm.client.toggle_fullscreen())
oxwm.key.bind({ modkey, "Shift" }, "Space", oxwm.client.toggle_floating())
oxwm.key.bind({ modkey, "Shift" }, "Q", oxwm.quit())
oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())

oxwm.key.bind({ modkey }, "A", oxwm.toggle_gaps())
oxwm.key.bind({ modkey }, "B", oxwm.toggle_bar())

oxwm.key.bind({ modkey }, "N", oxwm.layout.cycle())
oxwm.key.bind({ modkey }, "C", oxwm.layout.set("tiling"))
oxwm.key.bind({ modkey }, "M", oxwm.layout.set("monocle"))
oxwm.key.bind({ modkey }, "G", oxwm.layout.set("grid"))

oxwm.key.bind({ modkey }, "H", oxwm.set_master_factor(-50))
oxwm.key.bind({ modkey }, "L", oxwm.set_master_factor(50))
oxwm.key.bind({ modkey }, "I", oxwm.inc_num_master(1))
oxwm.key.bind({ modkey }, "P", oxwm.inc_num_master(-1))

oxwm.key.bind({ modkey }, "J", oxwm.client.focus_stack(1))
oxwm.key.bind({ modkey }, "K", oxwm.client.focus_stack(-1))
oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1))
oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1))

oxwm.key.bind({ modkey }, "Left", oxwm.layout.scroll_left())
oxwm.key.bind({ modkey }, "Right", oxwm.layout.scroll_right())
oxwm.key.bind({ modkey }, "R", oxwm.layout.cycle_width(1))
oxwm.key.bind({ modkey, "Shift" }, "M", oxwm.layout.set_width(1))

oxwm.key.bind({ modkey }, "Comma", oxwm.monitor.focus(-1))
oxwm.key.bind({ modkey }, "Period", oxwm.monitor.focus(1))
oxwm.key.bind({ modkey, "Shift" }, "Comma", oxwm.monitor.tag(-1))
oxwm.key.bind({ modkey, "Shift" }, "Period", oxwm.monitor.tag(1))

oxwm.key.bind({ modkey }, "Tab", oxwm.tag.view_next_nonempty())
oxwm.key.bind({ modkey, "Shift" }, "Tab", oxwm.tag.view_previous_nonempty())

for i = 1, 9 do
    local key = tostring(i)
    local tag = i - 1
    oxwm.key.bind({ modkey }, key, oxwm.tag.view(tag))
    oxwm.key.bind({ modkey, "Shift" }, key, oxwm.tag.move_to(tag))
    oxwm.key.bind({ modkey, "Control" }, key, oxwm.tag.toggleview(tag))
    oxwm.key.bind({ modkey, "Control", "Shift" }, key, oxwm.tag.toggletag(tag))
end

oxwm.key.chord({
    { { modkey }, "Space" },
    { {}, "T" },
}, oxwm.spawn_terminal())

local scripts = {
    B = "bookmarks-dmenu.sh",
    F = "repos-dmenu.sh",
    O = "tmux-dmenu.sh",
}

for key, script in pairs(scripts) do
    oxwm.key.chord({
        { { modkey }, "F" },
        { {}, key },
    }, oxwm.spawn("$HOME/repos/dmenu-scripts/" .. script))
end

local autostart = {
    "picom",
    "dunst",
    "nm-applet",
    "xwallpaper --zoom ~/walls/dune.jpg",
}

for _, cmd in ipairs(autostart) do
    oxwm.autostart(cmd)
end

What the loops replace

The tag loop is the one that pays off most. Tag indexes count from 0 and the keys from 1, so i - 1 is the tag for key i. Nine passes bind 36 keys.

The other loops keep data and calls apart. To float another program, add one line to rules. To start another program at login, add one line to autostart.

pairs is fine for symbols and scripts because their order does not matter. Use ipairs on a list when it does: the last matching rule decides whether a window floats, and autostart commands run in the order listed.