Migration to lua.
Browse files
+1 −1 Cargo.toml
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | [package] |
| 2 | 2 | name = "oxwm" |
| 3 | -version = "0.5.0" | |
| 3 | +version = "0.6.0" | |
| 4 | 4 | edition = "2024" |
| 5 | 5 | |
| 6 | 6 | [lib] |
+1 −1 default.nix
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | }: |
| 9 | 9 | rustPlatform.buildRustPackage (finalAttrs: { |
| 10 | 10 | pname = "oxwm"; |
| 11 | - version = "0.4.0"; | |
| 11 | + version = "0.6.0"; | |
| 12 | 12 | |
| 13 | 13 | src = ./.; |
| 14 | 14 |
+17 −6 readme.org
| @@ -79,7 +79,7 @@ Add this to your =configuration.nix=: | ||
| 79 | 79 | *** Initialize your config |
| 80 | 80 | After rebuilding your system with =sudo nixos-rebuild switch=, log in via your display manager. |
| 81 | 81 | |
| 82 | -On first launch, your initial config file will be automatically created and placed in =~/.config/oxwm/config.ron=. Edit it and reload with =Mod+Shift+R=. | |
| 82 | +On first launch, your initial config file will be automatically created and placed in =~/.config/oxwm/config.lua=. Edit it and reload with =Mod+Shift+R=. | |
| 83 | 83 | |
| 84 | 84 | *** Advanced: Using a specific oxwm version |
| 85 | 85 | If you want to pin or customize the oxwm package: |
| @@ -154,22 +154,33 @@ startx | ||
| 154 | 154 | If using a display manager (LightDM, GDM, SDDM), OXWM should appear in the session list after installation. |
| 155 | 155 | |
| 156 | 156 | * Configuration |
| 157 | -OXWM was inspired by dwm, but ditched the suckless philosophy. This philosophy quite literally discourages users from using the software for the sake of 'elitism'. I find that quite nonsensical, so I went ahead and created this project to be user friendly. The configuration is done by editing =~/.config/oxwm/config.ron= and the binary can be reloaded with a hotkey (Super+Shift+R by default). | |
| 157 | +OXWM was inspired by dwm, but ditched the suckless philosophy. This philosophy quite literally discourages users from using the software for the sake of 'elitism'. I find that quite nonsensical, so I went ahead and created this project to be user friendly. The configuration is done by editing =~/.config/oxwm/config.lua= and the binary can be reloaded with a hotkey (Super+Shift+R by default). | |
| 158 | 158 | |
| 159 | -Edit =~/.config/oxwm/config.ron= to customize: | |
| 159 | +Edit =~/.config/oxwm/config.lua= to customize: | |
| 160 | 160 | - Keybindings |
| 161 | 161 | - Colors and appearance |
| 162 | 162 | - Status bar blocks |
| 163 | 163 | - Gaps and borders |
| 164 | 164 | - Terminal and applications |
| 165 | 165 | |
| 166 | -After making changes, reload OXWM with =Mod+Shift+R= | |
| 166 | +After making changes, reload OXWM with =Mod+Shift+R= | |
| 167 | + | |
| 168 | +** Migrating from RON | |
| 169 | +If you have an old RON config (=config.ron=), use the migration tool to automatically convert it: | |
| 170 | + | |
| 171 | +#+begin_src sh | |
| 172 | +oxwm --migrate | |
| 173 | +# Or specify a path: | |
| 174 | +oxwm --migrate ~/.config/oxwm/config.ron | |
| 175 | +#+end_src | |
| 176 | + | |
| 177 | +This will convert your =config.ron= to =config.lua=, preserving all your settings. Your old config will remain intact for backup. | |
| 167 | 178 | |
| 168 | 179 | * Contributing |
| 169 | 180 | When contributing to OXWM: |
| 170 | 181 | |
| 171 | -1. Never commit your personal =~/.config/oxwm/config.ron= | |
| 172 | -2. Only modify =templates/config.ron= if adding new configuration options | |
| 182 | +1. Never commit your personal =~/.config/oxwm/config.lua= | |
| 183 | +2. Only modify =templates/config.lua= if adding new configuration options | |
| 173 | 184 | 3. Test your changes with =just test= using Xephyr/Xwayland |
| 174 | 185 | 4. Document any new features or keybindings |
| 175 | 186 |
+87 −168 resources/test-config.lua
| @@ -1,111 +1,31 @@ | ||
| 1 | --- OXWM Test Configuration File (Lua) | |
| 2 | --- This config uses Mod1 (Alt) as the modkey for testing in Xephyr | |
| 1 | +-- OXWM Configuration File (Lua) | |
| 2 | +-- Migrated from config.ron | |
| 3 | +-- Edit this file and reload with Mod+Shift+R (no compilation needed!) | |
| 3 | 4 | |
| 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 | 5 | local terminal = "st" |
| 84 | -local modkey = "Mod1" -- Alt key for Xephyr testing | |
| 85 | -local secondary_modkey = "Control" | |
| 6 | +local modkey = "Mod4" | |
| 86 | 7 | |
| 87 | --- Color palette (Tokyo Night theme) | |
| 8 | +-- Color palette | |
| 88 | 9 | 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, | |
| 10 | + lavender = "#a9b1d6", | |
| 11 | + light_blue = "#7aa2f7", | |
| 12 | + grey = "#bbbbbb", | |
| 13 | + purple = "#ad8ee6", | |
| 14 | + cyan = "#0db9d7", | |
| 15 | + bg = "#1a1b26", | |
| 16 | + green = "#9ece6a", | |
| 17 | + red = "#f7768e", | |
| 18 | + fg = "#bbbbbb", | |
| 19 | + blue = "#6dade3", | |
| 99 | 20 | } |
| 100 | 21 | |
| 101 | 22 | -- Main configuration table |
| 102 | ----@type Config | |
| 103 | -config = { | |
| 23 | +return { | |
| 104 | 24 | -- Appearance |
| 105 | 25 | border_width = 2, |
| 106 | 26 | border_focused = colors.blue, |
| 107 | 27 | border_unfocused = colors.grey, |
| 108 | - font = "monospace:style=Bold:size=10", | |
| 28 | + font = "JetBrainsMono Nerd Font:style=Bold:size=12", | |
| 109 | 29 | |
| 110 | 30 | -- Window gaps |
| 111 | 31 | gaps_enabled = true, |
| @@ -115,92 +35,91 @@ config = { | ||
| 115 | 35 | gap_outer_vertical = 5, |
| 116 | 36 | |
| 117 | 37 | -- Basics |
| 118 | - modkey = modkey, | |
| 119 | - terminal = terminal, | |
| 38 | + modkey = "Mod1", | |
| 39 | + terminal = "st", | |
| 120 | 40 | |
| 121 | 41 | -- Workspace tags |
| 122 | - tags = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}, | |
| 42 | + tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, | |
| 123 | 43 | |
| 124 | 44 | -- Layout symbol overrides |
| 125 | 45 | layout_symbols = { |
| 126 | - {name = "tiling", symbol = "[T]"}, | |
| 127 | - {name = "normie", symbol = "[F]"}, | |
| 46 | + { name = "tiling", symbol = "[T]" }, | |
| 47 | + { name = "normie", symbol = "[F]" }, | |
| 128 | 48 | }, |
| 129 | 49 | |
| 130 | 50 | -- Keybindings |
| 131 | - -- Using Mod1 (Alt) for Xephyr testing so it doesn't conflict with host WM | |
| 132 | 51 | keybindings = { |
| 133 | - -- Basic window management | |
| 134 | - {modifiers = {"Mod"}, key = "Return", action = "Spawn", arg = terminal}, | |
| 135 | - {modifiers = {"Mod"}, key = "D", action = "Spawn", arg = {"sh", "-c", "dmenu_run -l 10"}}, | |
| 136 | - {modifiers = {"Mod"}, key = "S", action = "Spawn", arg = {"sh", "-c", "maim -s | xclip -selection clipboard -t image/png"}}, | |
| 137 | - {modifiers = {"Mod"}, key = "Q", action = "KillClient"}, | |
| 138 | - {modifiers = {"Mod", "Shift"}, key = "F", action = "ToggleFullScreen"}, | |
| 139 | - {modifiers = {"Mod", "Shift"}, key = "Space", action = "ToggleFloating"}, | |
| 140 | - | |
| 141 | - -- Layout management | |
| 142 | - {modifiers = {"Mod"}, key = "F", action = "ChangeLayout", arg = "normie"}, | |
| 143 | - {modifiers = {"Mod"}, key = "C", action = "ChangeLayout", arg = "tiling"}, | |
| 144 | - {modifiers = {secondary_modkey}, key = "N", action = "CycleLayout"}, | |
| 145 | - {modifiers = {"Mod"}, key = "A", action = "ToggleGaps"}, | |
| 146 | - | |
| 147 | - -- WM control | |
| 148 | - {modifiers = {"Mod", "Shift"}, key = "Q", action = "Quit"}, | |
| 149 | - {modifiers = {"Mod", "Shift"}, key = "R", action = "Restart"}, | |
| 150 | - | |
| 151 | - -- Focus movement (vim-style hjkl) | |
| 152 | - {modifiers = {"Mod"}, key = "H", action = "FocusDirection", arg = 2}, -- left | |
| 153 | - {modifiers = {"Mod"}, key = "J", action = "FocusDirection", arg = 1}, -- down | |
| 154 | - {modifiers = {"Mod"}, key = "K", action = "FocusDirection", arg = 0}, -- up | |
| 155 | - {modifiers = {"Mod"}, key = "L", action = "FocusDirection", arg = 3}, -- right | |
| 156 | - | |
| 157 | - -- Window swapping (vim-style hjkl) | |
| 158 | - {modifiers = {"Mod", "Shift"}, key = "H", action = "SwapDirection", arg = 2}, -- left | |
| 159 | - {modifiers = {"Mod", "Shift"}, key = "J", action = "SwapDirection", arg = 1}, -- down | |
| 160 | - {modifiers = {"Mod", "Shift"}, key = "K", action = "SwapDirection", arg = 0}, -- up | |
| 161 | - {modifiers = {"Mod", "Shift"}, key = "L", action = "SwapDirection", arg = 3}, -- right | |
| 162 | - | |
| 163 | - -- Monitor focus | |
| 164 | - {modifiers = {"Mod"}, key = "Comma", action = "FocusMonitor", arg = -1}, | |
| 165 | - {modifiers = {"Mod"}, key = "Period", action = "FocusMonitor", arg = 1}, | |
| 166 | - | |
| 167 | - -- View tags | |
| 168 | - {modifiers = {"Mod"}, key = "1", action = "ViewTag", arg = 0}, | |
| 169 | - {modifiers = {"Mod"}, key = "2", action = "ViewTag", arg = 1}, | |
| 170 | - {modifiers = {"Mod"}, key = "3", action = "ViewTag", arg = 2}, | |
| 171 | - {modifiers = {"Mod"}, key = "4", action = "ViewTag", arg = 3}, | |
| 172 | - {modifiers = {"Mod"}, key = "5", action = "ViewTag", arg = 4}, | |
| 173 | - {modifiers = {"Mod"}, key = "6", action = "ViewTag", arg = 5}, | |
| 174 | - {modifiers = {"Mod"}, key = "7", action = "ViewTag", arg = 6}, | |
| 175 | - {modifiers = {"Mod"}, key = "8", action = "ViewTag", arg = 7}, | |
| 176 | - {modifiers = {"Mod"}, key = "9", action = "ViewTag", arg = 8}, | |
| 177 | - | |
| 178 | - -- Move window to tag | |
| 179 | - {modifiers = {"Mod", "Shift"}, key = "1", action = "MoveToTag", arg = 0}, | |
| 180 | - {modifiers = {"Mod", "Shift"}, key = "2", action = "MoveToTag", arg = 1}, | |
| 181 | - {modifiers = {"Mod", "Shift"}, key = "3", action = "MoveToTag", arg = 2}, | |
| 182 | - {modifiers = {"Mod", "Shift"}, key = "4", action = "MoveToTag", arg = 3}, | |
| 183 | - {modifiers = {"Mod", "Shift"}, key = "5", action = "MoveToTag", arg = 4}, | |
| 184 | - {modifiers = {"Mod", "Shift"}, key = "6", action = "MoveToTag", arg = 5}, | |
| 185 | - {modifiers = {"Mod", "Shift"}, key = "7", action = "MoveToTag", arg = 6}, | |
| 186 | - {modifiers = {"Mod", "Shift"}, key = "8", action = "MoveToTag", arg = 7}, | |
| 187 | - {modifiers = {"Mod", "Shift"}, key = "9", action = "MoveToTag", arg = 8}, | |
| 188 | - | |
| 189 | - -- Example keychord: Alt+Space, then T to spawn terminal | |
| 190 | 52 | { |
| 191 | 53 | keys = { |
| 192 | - {modifiers = {"Mod1"}, key = "Space"}, | |
| 193 | - {modifiers = {}, key = "T"} | |
| 54 | + { modifiers = { "Mod1" }, key = "Space" }, | |
| 55 | + { modifiers = { }, key = "T" }, | |
| 194 | 56 | }, |
| 195 | 57 | action = "Spawn", |
| 196 | - arg = terminal | |
| 58 | + arg = "st" | |
| 197 | 59 | }, |
| 60 | + { modifiers = { "Mod1" }, key = "Return", action = "Spawn", arg = "st" }, | |
| 61 | + { modifiers = { "Mod1" }, key = "D", action = "Spawn", arg = { "sh", "-c", "dmenu_run -l 10" } }, | |
| 62 | + { modifiers = { "Mod1" }, key = "S", action = "Spawn", arg = { "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" } }, | |
| 63 | + { modifiers = { "Mod1" }, key = "Q", action = "KillClient" }, | |
| 64 | + { modifiers = { "Mod1", "Shift" }, key = "F", action = "ToggleFullScreen" }, | |
| 65 | + { modifiers = { "Mod1", "Shift" }, key = "Space", action = "ToggleFloating" }, | |
| 66 | + { modifiers = { "Mod1" }, key = "F", action = "ChangeLayout", arg = "normie" }, | |
| 67 | + { modifiers = { "Mod1" }, key = "C", action = "ChangeLayout", arg = "tiling" }, | |
| 68 | + { modifiers = { "Mod1" }, key = "N", action = "CycleLayout" }, | |
| 69 | + { modifiers = { "Mod1" }, key = "A", action = "ToggleGaps" }, | |
| 70 | + { modifiers = { "Mod1", "Shift" }, key = "Q", action = "Quit" }, | |
| 71 | + { modifiers = { "Mod1", "Shift" }, key = "R", action = "Restart" }, | |
| 72 | + { modifiers = { "Mod1" }, key = "H", action = "FocusDirection", arg = 2 }, | |
| 73 | + { modifiers = { "Mod1" }, key = "J", action = "FocusDirection", arg = 1 }, | |
| 74 | + { modifiers = { "Mod1" }, key = "K", action = "FocusDirection", arg = 0 }, | |
| 75 | + { modifiers = { "Mod1" }, key = "L", action = "FocusDirection", arg = 3 }, | |
| 76 | + { modifiers = { "Mod1", "Shift" }, key = "H", action = "SwapDirection", arg = 2 }, | |
| 77 | + { modifiers = { "Mod1", "Shift" }, key = "J", action = "SwapDirection", arg = 1 }, | |
| 78 | + { modifiers = { "Mod1", "Shift" }, key = "K", action = "SwapDirection", arg = 0 }, | |
| 79 | + { modifiers = { "Mod1", "Shift" }, key = "L", action = "SwapDirection", arg = 3 }, | |
| 80 | + { modifiers = { "Mod1" }, key = "1", action = "ViewTag", arg = 0 }, | |
| 81 | + { modifiers = { "Mod1" }, key = "2", action = "ViewTag", arg = 1 }, | |
| 82 | + { modifiers = { "Mod1" }, key = "3", action = "ViewTag", arg = 2 }, | |
| 83 | + { modifiers = { "Mod1" }, key = "4", action = "ViewTag", arg = 3 }, | |
| 84 | + { modifiers = { "Mod1" }, key = "5", action = "ViewTag", arg = 4 }, | |
| 85 | + { modifiers = { "Mod1" }, key = "6", action = "ViewTag", arg = 5 }, | |
| 86 | + { modifiers = { "Mod1" }, key = "7", action = "ViewTag", arg = 6 }, | |
| 87 | + { modifiers = { "Mod1" }, key = "8", action = "ViewTag", arg = 7 }, | |
| 88 | + { modifiers = { "Mod1" }, key = "9", action = "ViewTag", arg = 8 }, | |
| 89 | + { modifiers = { "Mod1", "Shift" }, key = "1", action = "MoveToTag", arg = 0 }, | |
| 90 | + { modifiers = { "Mod1", "Shift" }, key = "2", action = "MoveToTag", arg = 1 }, | |
| 91 | + { modifiers = { "Mod1", "Shift" }, key = "3", action = "MoveToTag", arg = 2 }, | |
| 92 | + { modifiers = { "Mod1", "Shift" }, key = "4", action = "MoveToTag", arg = 3 }, | |
| 93 | + { modifiers = { "Mod1", "Shift" }, key = "5", action = "MoveToTag", arg = 4 }, | |
| 94 | + { modifiers = { "Mod1", "Shift" }, key = "6", action = "MoveToTag", arg = 5 }, | |
| 95 | + { modifiers = { "Mod1", "Shift" }, key = "7", action = "MoveToTag", arg = 6 }, | |
| 96 | + { modifiers = { "Mod1", "Shift" }, key = "8", action = "MoveToTag", arg = 7 }, | |
| 97 | + { modifiers = { "Mod1", "Shift" }, key = "9", action = "MoveToTag", arg = 8 }, | |
| 198 | 98 | }, |
| 199 | 99 | |
| 200 | 100 | -- Status bar blocks |
| 201 | 101 | status_blocks = { |
| 202 | 102 | { |
| 203 | - format = "Ram: {used}/{total} GB", | |
| 103 | + format = "", | |
| 104 | + command = "Battery", | |
| 105 | + battery_formats = { | |
| 106 | + charging = " Bat: {}%", | |
| 107 | + discharging = " Bat:{}%", | |
| 108 | + full = " Bat: {}%" | |
| 109 | + }, | |
| 110 | + interval_secs = 30, | |
| 111 | + color = colors.green, | |
| 112 | + underline = true | |
| 113 | + }, | |
| 114 | + { | |
| 115 | + format = " │ ", | |
| 116 | + command = "Static", | |
| 117 | + interval_secs = 999999999, | |
| 118 | + color = colors.lavender, | |
| 119 | + underline = false | |
| 120 | + }, | |
| 121 | + { | |
| 122 | + format = " {used}/{total} GB", | |
| 204 | 123 | command = "Ram", |
| 205 | 124 | interval_secs = 5, |
| 206 | 125 | color = colors.light_blue, |
| @@ -209,12 +128,12 @@ config = { | ||
| 209 | 128 | { |
| 210 | 129 | format = " │ ", |
| 211 | 130 | command = "Static", |
| 212 | - interval_secs = 999999999, -- Very large number for static blocks | |
| 131 | + interval_secs = 999999999, | |
| 213 | 132 | color = colors.lavender, |
| 214 | 133 | underline = false |
| 215 | 134 | }, |
| 216 | 135 | { |
| 217 | - format = "Kernel: {}", | |
| 136 | + format = " {}", | |
| 218 | 137 | command = "Shell", |
| 219 | 138 | command_arg = "uname -r", |
| 220 | 139 | interval_secs = 999999999, |
| @@ -229,7 +148,7 @@ config = { | ||
| 229 | 148 | underline = false |
| 230 | 149 | }, |
| 231 | 150 | { |
| 232 | - format = "{}", | |
| 151 | + format = " {}", | |
| 233 | 152 | command = "DateTime", |
| 234 | 153 | command_arg = "%a, %b %d - %-I:%M %P", |
| 235 | 154 | interval_secs = 1, |
| @@ -242,7 +161,7 @@ config = { | ||
| 242 | 161 | scheme_normal = { |
| 243 | 162 | foreground = colors.fg, |
| 244 | 163 | background = colors.bg, |
| 245 | - underline = 0x444444 | |
| 164 | + underline = "#444444" | |
| 246 | 165 | }, |
| 247 | 166 | scheme_occupied = { |
| 248 | 167 | foreground = colors.cyan, |
+46 −0 src/bin/main.rs
| @@ -19,6 +19,11 @@ fn main() -> Result<()> { | ||
| 19 | 19 | init_config()?; |
| 20 | 20 | return Ok(()); |
| 21 | 21 | } |
| 22 | + Some("--migrate") => { | |
| 23 | + let path = args.get(2).map(PathBuf::from); | |
| 24 | + migrate_config(path)?; | |
| 25 | + return Ok(()); | |
| 26 | + } | |
| 22 | 27 | Some("--config") => { |
| 23 | 28 | if let Some(path) = args.get(2) { |
| 24 | 29 | custom_config_path = Some(PathBuf::from(path)); |
| @@ -106,12 +111,50 @@ fn get_config_path() -> PathBuf { | ||
| 106 | 111 | .join("oxwm") |
| 107 | 112 | } |
| 108 | 113 | |
| 114 | +fn migrate_config(custom_path: Option<PathBuf>) -> Result<()> { | |
| 115 | + let ron_path = if let Some(path) = custom_path { | |
| 116 | + path | |
| 117 | + } else { | |
| 118 | + // Default to ~/.config/oxwm/config.ron | |
| 119 | + get_config_path().join("config.ron") | |
| 120 | + }; | |
| 121 | + | |
| 122 | + if !ron_path.exists() { | |
| 123 | + eprintln!("Error: RON config file not found at {:?}", ron_path); | |
| 124 | + eprintln!("Please specify a path: oxwm --migrate <path/to/config.ron>"); | |
| 125 | + std::process::exit(1); | |
| 126 | + } | |
| 127 | + | |
| 128 | + println!("Migrating RON config to Lua..."); | |
| 129 | + println!(" Reading: {:?}", ron_path); | |
| 130 | + | |
| 131 | + let ron_content = std::fs::read_to_string(&ron_path) | |
| 132 | + .with_context(|| format!("Failed to read RON config from {:?}", ron_path))?; | |
| 133 | + | |
| 134 | + let lua_content = oxwm::config::migrate::ron_to_lua(&ron_content) | |
| 135 | + .map_err(|e| anyhow::anyhow!("Migration failed: {}", e))?; | |
| 136 | + | |
| 137 | + // Determine output path (same directory, .lua extension) | |
| 138 | + let lua_path = ron_path.with_extension("lua"); | |
| 139 | + | |
| 140 | + std::fs::write(&lua_path, lua_content) | |
| 141 | + .with_context(|| format!("Failed to write Lua config to {:?}", lua_path))?; | |
| 142 | + | |
| 143 | + println!("✓ Migration complete!"); | |
| 144 | + println!(" Output: {:?}", lua_path); | |
| 145 | + println!("\nYour old config.ron is still intact."); | |
| 146 | + println!("Review the new config.lua and then you can delete config.ron if everything looks good."); | |
| 147 | + | |
| 148 | + Ok(()) | |
| 149 | +} | |
| 150 | + | |
| 109 | 151 | fn print_help() { |
| 110 | 152 | println!("OXWM - A dynamic window manager written in Rust\n"); |
| 111 | 153 | println!("USAGE:"); |
| 112 | 154 | println!(" oxwm [OPTIONS]\n"); |
| 113 | 155 | println!("OPTIONS:"); |
| 114 | 156 | println!(" --init Create default config in ~/.config/oxwm/config.lua"); |
| 157 | + println!(" --migrate [PATH] Convert RON config to Lua (default: ~/.config/oxwm/config.ron)"); | |
| 115 | 158 | println!(" --config <PATH> Use custom config file (.lua or .ron)"); |
| 116 | 159 | println!(" --version Print version information"); |
| 117 | 160 | println!(" --help Print this help message\n"); |
| @@ -119,6 +162,9 @@ fn print_help() { | ||
| 119 | 162 | println!(" Location: ~/.config/oxwm/config.lua (or config.ron for legacy)"); |
| 120 | 163 | println!(" Edit the config file and use Mod+Shift+R to reload"); |
| 121 | 164 | println!(" No compilation needed - instant hot-reload!\n"); |
| 165 | + println!("MIGRATION:"); | |
| 166 | + println!(" To migrate from RON to Lua: oxwm --migrate"); | |
| 167 | + println!(" Or specify a custom path: oxwm --migrate /path/to/config.ron\n"); | |
| 122 | 168 | println!("FIRST RUN:"); |
| 123 | 169 | println!(" Run 'oxwm --init' to create a config file"); |
| 124 | 170 | println!(" Or just start oxwm and it will create one automatically\n"); |
+3 −12 src/config/lua.rs
| @@ -10,18 +10,9 @@ use x11rb::protocol::xproto::KeyButMask; | ||
| 10 | 10 | pub fn parse_lua_config(input: &str) -> Result<crate::Config, ConfigError> { |
| 11 | 11 | let lua = Lua::new(); |
| 12 | 12 | |
| 13 | - // Execute the config file | |
| 14 | - lua.load(input) | |
| 15 | - .exec() | |
| 13 | + let config: Table = lua.load(input) | |
| 14 | + .eval() | |
| 16 | 15 | .map_err(|e| ConfigError::LuaError(format!("Failed to execute Lua config: {}", e)))?; |
| 17 | - | |
| 18 | - // Get the config table from global scope | |
| 19 | - let globals = lua.globals(); | |
| 20 | - let config: Table = globals | |
| 21 | - .get("config") | |
| 22 | - .map_err(|e| ConfigError::LuaError(format!("Config table not found: {}", e)))?; | |
| 23 | - | |
| 24 | - // Parse each config section | |
| 25 | 16 | let border_width: u32 = get_table_field(&config, "border_width")?; |
| 26 | 17 | let border_focused: u32 = parse_color(&config, "border_focused")?; |
| 27 | 18 | let border_unfocused: u32 = parse_color(&config, "border_unfocused")?; |
| @@ -527,7 +518,7 @@ mod tests { | ||
| 527 | 518 | #[test] |
| 528 | 519 | fn test_parse_minimal_lua_config() { |
| 529 | 520 | let config_str = r#" |
| 530 | -config = { | |
| 521 | +return { | |
| 531 | 522 | border_width = 2, |
| 532 | 523 | border_focused = 0x6dade3, |
| 533 | 524 | border_unfocused = 0xbbbbbb, |
+552 −0 src/config/migrate.rs new file mode 100644 Large diff collapsed, click to expand
| @@ -0,0 +1,552 @@ | ||
| 1 | +use std::collections::HashMap; | |
| 2 | + | |
| 3 | +pub fn ron_to_lua(ron_content: &str) -> Result<String, String> { | |
| 4 | + let mut lua_output = String::new(); | |
| 5 | + let defines = extract_defines(ron_content); | |
| 6 | + | |
| 7 | + lua_output.push_str("-- OXWM Configuration File (Lua)\n"); | |
| 8 | + lua_output.push_str("-- Migrated from config.ron\n"); | |
| 9 | + lua_output.push_str("-- Edit this file and reload with Mod+Shift+R (no compilation needed!)\n\n"); | |
| 10 | + | |
| 11 | + let terminal = resolve_value(&defines.get("$terminal").cloned().unwrap_or_else(|| "\"st\"".to_string()), &defines); | |
| 12 | + let modkey = resolve_value(&defines.get("$modkey").cloned().unwrap_or_else(|| "Mod4".to_string()), &defines); | |
| 13 | + let secondary_modkey = defines.get("$secondary_modkey").map(|v| resolve_value(v, &defines)); | |
| 14 | + | |
| 15 | + lua_output.push_str(&format!("local terminal = {}\n", terminal)); | |
| 16 | + lua_output.push_str(&format!("local modkey = \"{}\"\n", modkey.trim_matches('"'))); | |
| 17 | + if let Some(sec_mod) = secondary_modkey { | |
| 18 | + lua_output.push_str(&format!("local secondary_modkey = \"{}\"\n", sec_mod.trim_matches('"'))); | |
| 19 | + } | |
| 20 | + lua_output.push_str("\n"); | |
| 21 | + | |
| 22 | + lua_output.push_str("-- Color palette\n"); | |
| 23 | + lua_output.push_str("local colors = {\n"); | |
| 24 | + for (key, value) in &defines { | |
| 25 | + if key.starts_with("$color_") { | |
| 26 | + let color_name = &key[7..]; | |
| 27 | + let color_value = if value.starts_with("0x") { | |
| 28 | + format!("\"#{}\"", &value[2..]) | |
| 29 | + } else { | |
| 30 | + value.clone() | |
| 31 | + }; | |
| 32 | + lua_output.push_str(&format!(" {} = {},\n", color_name, color_value)); | |
| 33 | + } | |
| 34 | + } | |
| 35 | + lua_output.push_str("}\n\n"); | |
| 36 | + | |
| 37 | + lua_output.push_str("-- Main configuration table\n"); | |
| 38 | + lua_output.push_str("return {\n"); | |
| 39 | + | |
| 40 | + if let Some(config_start) = ron_content.find('(') { | |
| 41 | + let config_content = &ron_content[config_start + 1..]; | |
| 42 | + | |
| 43 | + lua_output.push_str(" -- Appearance\n"); | |
| 44 | + if let Some(val) = extract_field(config_content, "border_width") { | |
| 45 | + lua_output.push_str(&format!(" border_width = {},\n", val)); | |
| 46 | + } | |
| 47 | + if let Some(val) = extract_field(config_content, "border_focused") { | |
| 48 | + lua_output.push_str(&format!(" border_focused = {},\n", resolve_color_value(&val, &defines))); | |
| 49 | + } | |
| 50 | + if let Some(val) = extract_field(config_content, "border_unfocused") { | |
| 51 | + lua_output.push_str(&format!(" border_unfocused = {},\n", resolve_color_value(&val, &defines))); | |
| 52 | + } | |
| 53 | + if let Some(val) = extract_field(config_content, "font") { | |
| 54 | + lua_output.push_str(&format!(" font = {},\n", val)); | |
| 55 | + } | |
| 56 | + | |
| 57 | + lua_output.push_str("\n -- Window gaps\n"); | |
| 58 | + if let Some(val) = extract_field(config_content, "gaps_enabled") { | |
| 59 | + lua_output.push_str(&format!(" gaps_enabled = {},\n", val)); | |
| 60 | + } | |
| 61 | + if let Some(val) = extract_field(config_content, "gap_inner_horizontal") { | |
| 62 | + lua_output.push_str(&format!(" gap_inner_horizontal = {},\n", val)); | |
| 63 | + } | |
| 64 | + if let Some(val) = extract_field(config_content, "gap_inner_vertical") { | |
| 65 | + lua_output.push_str(&format!(" gap_inner_vertical = {},\n", val)); | |
| 66 | + } | |
| 67 | + if let Some(val) = extract_field(config_content, "gap_outer_horizontal") { | |
| 68 | + lua_output.push_str(&format!(" gap_outer_horizontal = {},\n", val)); | |
| 69 | + } | |
| 70 | + if let Some(val) = extract_field(config_content, "gap_outer_vertical") { | |
| 71 | + lua_output.push_str(&format!(" gap_outer_vertical = {},\n", val)); | |
| 72 | + } | |
| 73 | + | |
| 74 | + lua_output.push_str("\n -- Basics\n"); | |
| 75 | + if let Some(val) = extract_field(config_content, "modkey") { | |
| 76 | + let resolved = resolve_value(&val, &defines).trim_matches('"').to_string(); | |
| 77 | + if resolved == "modkey" { | |
| 78 | + lua_output.push_str(" modkey = modkey,\n"); | |
| 79 | + } else { | |
| 80 | + lua_output.push_str(&format!(" modkey = \"{}\",\n", resolved)); | |
| 81 | + } | |
| 82 | + } | |
| 83 | + if let Some(val) = extract_field(config_content, "terminal") { | |
| 84 | + let resolved = resolve_value(&val, &defines); | |
| 85 | + if resolved == "terminal" { | |
| 86 | + lua_output.push_str(" terminal = terminal,\n"); | |
| 87 | + } else { | |
| 88 | + lua_output.push_str(&format!(" terminal = {},\n", resolved)); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + lua_output.push_str("\n -- Workspace tags\n"); | |
| 93 | + if let Some(val) = extract_field(config_content, "tags") { | |
| 94 | + lua_output.push_str(&format!(" tags = {},\n", convert_array_to_lua(&val))); | |
| 95 | + } | |
| 96 | + | |
| 97 | + lua_output.push_str("\n -- Layout symbol overrides\n"); | |
| 98 | + if let Some(val) = extract_field(config_content, "layout_symbols") { | |
| 99 | + lua_output.push_str(" layout_symbols = "); | |
| 100 | + lua_output.push_str(&convert_layout_symbols(&val)); | |
| 101 | + lua_output.push_str(",\n"); | |
| 102 | + } | |
| 103 | + | |
| 104 | + lua_output.push_str("\n -- Keybindings\n"); | |
| 105 | + if let Some(val) = extract_field(config_content, "keybindings") { | |
| 106 | + lua_output.push_str(" keybindings = "); | |
| 107 | + lua_output.push_str(&convert_keybindings(&val, &defines)); | |
| 108 | + lua_output.push_str(",\n"); | |
| 109 | + } | |
| 110 | + | |
| 111 | + lua_output.push_str("\n -- Status bar blocks\n"); | |
| 112 | + if let Some(val) = extract_field(config_content, "status_blocks") { | |
| 113 | + lua_output.push_str(" status_blocks = "); | |
| 114 | + lua_output.push_str(&convert_status_blocks(&val, &defines)); | |
| 115 | + lua_output.push_str(",\n"); | |
| 116 | + } | |
| 117 | + | |
| 118 | + lua_output.push_str("\n -- Color schemes for bar\n"); | |
| 119 | + if let Some(val) = extract_field(config_content, "scheme_normal") { | |
| 120 | + lua_output.push_str(" scheme_normal = "); | |
| 121 | + lua_output.push_str(&convert_color_scheme(&val, &defines)); | |
| 122 | + lua_output.push_str(",\n"); | |
| 123 | + } | |
| 124 | + if let Some(val) = extract_field(config_content, "scheme_occupied") { | |
| 125 | + lua_output.push_str(" scheme_occupied = "); | |
| 126 | + lua_output.push_str(&convert_color_scheme(&val, &defines)); | |
| 127 | + lua_output.push_str(",\n"); | |
| 128 | + } | |
| 129 | + if let Some(val) = extract_field(config_content, "scheme_selected") { | |
| 130 | + lua_output.push_str(" scheme_selected = "); | |
| 131 | + lua_output.push_str(&convert_color_scheme(&val, &defines)); | |
| 132 | + lua_output.push_str(",\n"); | |
| 133 | + } | |
| 134 | + | |
| 135 | + lua_output.push_str("\n -- Autostart commands\n"); | |
| 136 | + if let Some(val) = extract_field(config_content, "autostart") { | |
| 137 | + let converted = convert_array_to_lua(&val); | |
| 138 | + lua_output.push_str(" autostart = "); | |
| 139 | + lua_output.push_str(&converted); | |
| 140 | + lua_output.push_str(",\n"); | |
| 141 | + } else { | |
| 142 | + lua_output.push_str(" autostart = {},\n"); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + lua_output.push_str("}\n"); | |
| 147 | + | |
| 148 | + Ok(lua_output) | |
| 149 | +} | |
| 150 | + | |
| 151 | +fn extract_defines(content: &str) -> HashMap<String, String> { | |
| 152 | + let mut defines = HashMap::new(); | |
| 153 | + for line in content.lines() { | |
| 154 | + let trimmed = line.trim(); | |
| 155 | + if trimmed.starts_with("#DEFINE") { | |
| 156 | + if let Some(rest) = trimmed.strip_prefix("#DEFINE") { | |
| 157 | + if let Some(eq_pos) = rest.find('=') { | |
| 158 | + let var_name = rest[..eq_pos].trim().to_string(); | |
| 159 | + let value = rest[eq_pos + 1..].trim().trim_end_matches(',').to_string(); | |
| 160 | + defines.insert(var_name, value); | |
| 161 | + } | |
| 162 | + } | |
| 163 | + } | |
| 164 | + } | |
| 165 | + defines | |
| 166 | +} | |
| 167 | + | |
| 168 | +fn resolve_value(value: &str, defines: &HashMap<String, String>) -> String { | |
| 169 | + if let Some(resolved) = defines.get(value) { | |
| 170 | + resolved.clone() | |
| 171 | + } else { | |
| 172 | + value.to_string() | |
| 173 | + } | |
| 174 | +} | |
| 175 | + | |
| 176 | +fn resolve_color_value(value: &str, defines: &HashMap<String, String>) -> String { | |
| 177 | + let resolved = resolve_value(value, defines); | |
| 178 | + if resolved.starts_with("$color_") { | |
| 179 | + format!("colors.{}", &resolved[7..]) | |
| 180 | + } else if value.starts_with("$color_") { | |
| 181 | + format!("colors.{}", &value[7..]) | |
| 182 | + } else if resolved.starts_with("0x") { | |
| 183 | + format!("\"#{}\"", &resolved[2..]) | |
| 184 | + } else { | |
| 185 | + resolved | |
| 186 | + } | |
| 187 | +} | |
| 188 | + | |
| 189 | +fn extract_field(content: &str, field_name: &str) -> Option<String> { | |
| 190 | + let pattern = format!("{}:", field_name); | |
| 191 | + let cleaned_content = remove_comments(content); | |
| 192 | + | |
| 193 | + if let Some(start) = cleaned_content.find(&pattern) { | |
| 194 | + let after_colon = &cleaned_content[start + pattern.len()..]; | |
| 195 | + let value_start = after_colon.trim_start(); | |
| 196 | + | |
| 197 | + if value_start.starts_with('[') { | |
| 198 | + extract_bracketed(value_start, '[', ']') | |
| 199 | + } else if value_start.starts_with('(') { | |
| 200 | + extract_bracketed(value_start, '(', ')') | |
| 201 | + } else if value_start.starts_with('"') { | |
| 202 | + if let Some(end) = value_start[1..].find('"') { | |
| 203 | + Some(value_start[..end + 2].to_string()) | |
| 204 | + } else { | |
| 205 | + None | |
| 206 | + } | |
| 207 | + } else { | |
| 208 | + let end = value_start | |
| 209 | + .find(|c: char| c == ',' || c == '\n' || c == ')') | |
| 210 | + .unwrap_or(value_start.len()); | |
| 211 | + Some(value_start[..end].trim().to_string()) | |
| 212 | + } | |
| 213 | + } else { | |
| 214 | + None | |
| 215 | + } | |
| 216 | +} | |
| 217 | + | |
| 218 | +fn extract_bracketed(s: &str, open: char, close: char) -> Option<String> { | |
| 219 | + if !s.starts_with(open) { | |
| 220 | + return None; | |
| 221 | + } | |
| 222 | + let mut depth = 0; | |
| 223 | + let mut end = 0; | |
| 224 | + for (i, c) in s.char_indices() { | |
| 225 | + if c == open { | |
| 226 | + depth += 1; | |
| 227 | + } else if c == close { | |
| 228 | + depth -= 1; | |
| 229 | + if depth == 0 { | |
| 230 | + end = i + 1; | |
| 231 | + break; | |
| 232 | + } | |
| 233 | + } | |
| 234 | + } | |
| 235 | + if end > 0 { | |
| 236 | + Some(s[..end].to_string()) | |
| 237 | + } else { | |
| 238 | + None | |
| 239 | + } | |
| 240 | +} | |
| 241 | + | |
| 242 | +fn convert_array_to_lua(ron_array: &str) -> String { | |
| 243 | + let inner = ron_array.trim_start_matches('[').trim_end_matches(']'); | |
| 244 | + let items: Vec<&str> = inner.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()).collect(); | |
| 245 | + format!("{{ {} }}", items.join(", ")) | |
| 246 | +} | |
| 247 | + | |
| 248 | +fn convert_layout_symbols(ron_array: &str) -> String { | |
| 249 | + let mut result = String::from("{\n"); | |
| 250 | + let inner = ron_array.trim_start_matches('[').trim_end_matches(']'); | |
| 251 | + | |
| 252 | + let items = extract_all_bracketed(inner, '(', ')'); | |
| 253 | + for item in items { | |
| 254 | + let item_inner = item.trim_start_matches('(').trim_end_matches(')'); | |
| 255 | + if let (Some(name), Some(symbol)) = (extract_quoted_value(item_inner, "name"), extract_quoted_value(item_inner, "symbol")) { | |
| 256 | + result.push_str(&format!(" {{ name = \"{}\", symbol = \"{}\" }},\n", name, symbol)); | |
| 257 | + } | |
| 258 | + } | |
| 259 | + | |
| 260 | + result.push_str(" }"); | |
| 261 | + result | |
| 262 | +} | |
| 263 | + | |
| 264 | +fn convert_keybindings(ron_array: &str, defines: &HashMap<String, String>) -> String { | |
| 265 | + let mut result = String::from("{\n"); | |
| 266 | + let inner = ron_array.trim_start_matches('[').trim_end_matches(']'); | |
| 267 | + | |
| 268 | + let items = extract_all_bracketed(inner, '(', ')'); | |
| 269 | + for item in items { | |
| 270 | + let binding = convert_keybinding(&item, defines); | |
| 271 | + result.push_str(&binding); | |
| 272 | + result.push_str(",\n"); | |
| 273 | + } | |
| 274 | + | |
| 275 | + result.push_str(" }"); | |
| 276 | + result | |
| 277 | +} | |
| 278 | + | |
| 279 | +fn convert_keybinding(ron_binding: &str, defines: &HashMap<String, String>) -> String { | |
| 280 | + let inner = ron_binding.trim_start_matches('(').trim_end_matches(')'); | |
| 281 | + | |
| 282 | + if inner.contains("keys:") { | |
| 283 | + convert_keychord(inner, defines) | |
| 284 | + } else { | |
| 285 | + convert_single_key(inner, defines) | |
| 286 | + } | |
| 287 | +} | |
| 288 | + | |
| 289 | +fn convert_keychord(inner: &str, defines: &HashMap<String, String>) -> String { | |
| 290 | + let mut result = String::from(" {\n keys = {\n"); | |
| 291 | + | |
| 292 | + if let Some(keys_str) = extract_field(inner, "keys") { | |
| 293 | + let keys = extract_all_bracketed(&keys_str, '(', ')'); | |
| 294 | + for key in keys { | |
| 295 | + let key_inner = key.trim_start_matches('(').trim_end_matches(')'); | |
| 296 | + let mods = extract_modifiers(key_inner, defines); | |
| 297 | + let key_name = extract_key(key_inner); | |
| 298 | + result.push_str(&format!(" {{ modifiers = {{ {} }}, key = \"{}\" }},\n", mods, key_name)); | |
| 299 | + } | |
| 300 | + } | |
| 301 | + | |
| 302 | + result.push_str(" },\n"); | |
| 303 | + | |
| 304 | + if let Some(action) = extract_identifier(inner, "action") { | |
| 305 | + result.push_str(&format!(" action = \"{}\",\n", action)); | |
| 306 | + } | |
| 307 | + | |
| 308 | + if let Some(arg) = extract_arg(inner, defines) { | |
| 309 | + result.push_str(&format!(" arg = {}\n", arg)); | |
| 310 | + } | |
| 311 | + | |
| 312 | + result.push_str(" }"); | |
| 313 | + result | |
| 314 | +} | |
| 315 | + | |
| 316 | +fn convert_single_key(inner: &str, defines: &HashMap<String, String>) -> String { | |
| 317 | + let mods = extract_modifiers(inner, defines); | |
| 318 | + let key = extract_key(inner); | |
| 319 | + let action = extract_identifier(inner, "action").unwrap_or_default(); | |
| 320 | + | |
| 321 | + let mut result = format!(" {{ modifiers = {{ {} }}, key = \"{}\", action = \"{}\"", mods, key, action); | |
| 322 | + | |
| 323 | + if let Some(arg) = extract_arg(inner, defines) { | |
| 324 | + result.push_str(&format!(", arg = {}", arg)); | |
| 325 | + } | |
| 326 | + | |
| 327 | + result.push_str(" }"); | |
| 328 | + result | |
| 329 | +} | |
| 330 | + | |
| 331 | +fn extract_modifiers(content: &str, defines: &HashMap<String, String>) -> String { | |
| 332 | + if let Some(mods_str) = extract_field(content, "modifiers") { | |
| 333 | + let inner = mods_str.trim_start_matches('[').trim_end_matches(']').trim(); | |
| 334 | + if inner.is_empty() { | |
| 335 | + return String::new(); | |
| 336 | + } | |
| 337 | + let mods: Vec<String> = inner | |
| 338 | + .split(',') | |
| 339 | + .map(|s| { | |
| 340 | + let trimmed = s.trim(); | |
| 341 | + if !trimmed.is_empty() { | |
| 342 | + let resolved = resolve_value(trimmed, defines); | |
| 343 | + format!("\"{}\"", resolved) | |
| 344 | + } else { | |
| 345 | + String::new() | |
| 346 | + } | |
| 347 | + }) | |
| 348 | + .filter(|s| !s.is_empty()) | |
| 349 | + .collect(); | |
| 350 | + mods.join(", ") | |
| 351 | + } else { | |
| 352 | + String::new() | |
| 353 | + } | |
| 354 | +} | |
| 355 | + | |
| 356 | +fn extract_key(content: &str) -> String { | |
| 357 | + if let Some(key_str) = extract_identifier(content, "key") { | |
| 358 | + if key_str.starts_with("Key") && key_str.len() == 4 { | |
| 359 | + if let Some(digit) = key_str.chars().nth(3) { | |
| 360 | + if digit.is_ascii_digit() { | |
| 361 | + return digit.to_string(); | |
| 362 | + } | |
| 363 | + } | |
| 364 | + } | |
| 365 | + key_str | |
| 366 | + } else { | |
| 367 | + String::from("Return") | |
| 368 | + } | |
| 369 | +} | |
| 370 | + | |
| 371 | +fn extract_identifier(content: &str, field_name: &str) -> Option<String> { | |
| 372 | + let pattern = format!("{}:", field_name); | |
| 373 | + if let Some(start) = content.find(&pattern) { | |
| 374 | + let after_colon = &content[start + pattern.len()..]; | |
| 375 | + let value_start = after_colon.trim_start(); | |
| 376 | + let end = value_start | |
| 377 | + .find(|c: char| c == ',' || c == ')' || c == '\n') | |
| 378 | + .unwrap_or(value_start.len()); | |
| 379 | + Some(value_start[..end].trim().to_string()) | |
| 380 | + } else { | |
| 381 | + None | |
| 382 | + } | |
| 383 | +} | |
| 384 | + | |
| 385 | +fn extract_arg(content: &str, defines: &HashMap<String, String>) -> Option<String> { | |
| 386 | + if let Some(arg_str) = extract_field(content, "arg") { | |
| 387 | + let resolved = resolve_value(&arg_str, defines); | |
| 388 | + if resolved.starts_with('[') { | |
| 389 | + Some(convert_array_to_lua(&resolved)) | |
| 390 | + } else if resolved.starts_with('"') || resolved.parse::<i32>().is_ok() || resolved.starts_with("0x") { | |
| 391 | + Some(resolved) | |
| 392 | + } else { | |
| 393 | + Some(format!("\"{}\"", resolved)) | |
| 394 | + } | |
| 395 | + } else { | |
| 396 | + None | |
| 397 | + } | |
| 398 | +} | |
| 399 | + | |
| 400 | +fn convert_status_blocks(ron_array: &str, defines: &HashMap<String, String>) -> String { | |
| 401 | + let mut result = String::from("{\n"); | |
| 402 | + let inner = ron_array.trim_start_matches('[').trim_end_matches(']'); | |
| 403 | + | |
| 404 | + let items = extract_all_bracketed(inner, '(', ')'); | |
| 405 | + for item in items { | |
| 406 | + let block = convert_status_block(&item, defines); | |
| 407 | + if !block.trim().ends_with("{\n }") { | |
| 408 | + result.push_str(&block); | |
| 409 | + result.push_str(",\n"); | |
| 410 | + } | |
| 411 | + } | |
| 412 | + | |
| 413 | + result.push_str(" }"); | |
| 414 | + result | |
| 415 | +} | |
| 416 | + | |
| 417 | +fn convert_status_block(ron_block: &str, defines: &HashMap<String, String>) -> String { | |
| 418 | + let mut result = String::from(" {\n"); | |
| 419 | + let inner = ron_block.trim_start_matches('(').trim_end_matches(')'); | |
| 420 | + | |
| 421 | + if let Some(format) = extract_field(inner, "format") { | |
| 422 | + result.push_str(&format!(" format = {},\n", format)); | |
| 423 | + } | |
| 424 | + if let Some(command) = extract_field(inner, "command") { | |
| 425 | + result.push_str(&format!(" command = {},\n", command)); | |
| 426 | + } | |
| 427 | + if let Some(command_arg) = extract_field(inner, "command_arg") { | |
| 428 | + result.push_str(&format!(" command_arg = {},\n", command_arg)); | |
| 429 | + } | |
| 430 | + if inner.contains("battery_formats:") { | |
| 431 | + if let Some(battery_str) = extract_field(inner, "battery_formats") { | |
| 432 | + result.push_str(" battery_formats = {\n"); | |
| 433 | + let battery_inner = battery_str.trim_start_matches('(').trim_end_matches(')'); | |
| 434 | + if let Some(charging) = extract_quoted_value(battery_inner, "charging") { | |
| 435 | + result.push_str(&format!(" charging = \"{}\",\n", charging)); | |
| 436 | + } | |
| 437 | + if let Some(discharging) = extract_quoted_value(battery_inner, "discharging") { | |
| 438 | + result.push_str(&format!(" discharging = \"{}\",\n", discharging)); | |
| 439 | + } | |
| 440 | + if let Some(full) = extract_quoted_value(battery_inner, "full") { | |
| 441 | + result.push_str(&format!(" full = \"{}\"\n", full)); | |
| 442 | + } | |
| 443 | + result.push_str(" },\n"); | |
| 444 | + } | |
| 445 | + } | |
| 446 | + if let Some(interval) = extract_field(inner, "interval_secs") { | |
| 447 | + let interval_val = if interval.len() > 10 { | |
| 448 | + "999999999".to_string() | |
| 449 | + } else { | |
| 450 | + interval | |
| 451 | + }; | |
| 452 | + result.push_str(&format!(" interval_secs = {},\n", interval_val)); | |
| 453 | + } | |
| 454 | + if let Some(color) = extract_field(inner, "color") { | |
| 455 | + let resolved = resolve_color_value(&color, defines); | |
| 456 | + result.push_str(&format!(" color = {},\n", resolved)); | |
| 457 | + } | |
| 458 | + if let Some(underline) = extract_field(inner, "underline") { | |
| 459 | + result.push_str(&format!(" underline = {}\n", underline)); | |
| 460 | + } | |
| 461 | + | |
| 462 | + result.push_str(" }"); | |
| 463 | + result | |
| 464 | +} | |
| 465 | + | |
| 466 | +fn convert_color_scheme(ron_scheme: &str, defines: &HashMap<String, String>) -> String { | |
| 467 | + let mut result = String::from("{\n"); | |
| 468 | + let inner = ron_scheme.trim_start_matches('(').trim_end_matches(')'); | |
| 469 | + | |
| 470 | + if let Some(fg) = extract_field(inner, "foreground") { | |
| 471 | + let resolved = resolve_color_value(&fg, defines); | |
| 472 | + result.push_str(&format!(" foreground = {},\n", resolved)); | |
| 473 | + } | |
| 474 | + if let Some(bg) = extract_field(inner, "background") { | |
| 475 | + let resolved = resolve_color_value(&bg, defines); | |
| 476 | + result.push_str(&format!(" background = {},\n", resolved)); | |
| 477 | + } | |
| 478 | + if let Some(ul) = extract_field(inner, "underline") { | |
| 479 | + let resolved = resolve_color_value(&ul, defines); | |
| 480 | + result.push_str(&format!(" underline = {}\n", resolved)); | |
| 481 | + } | |
| 482 | + | |
| 483 | + result.push_str(" }"); | |
| 484 | + result | |
| 485 | +} | |
| 486 | + | |
| 487 | +fn extract_all_bracketed(s: &str, open: char, close: char) -> Vec<String> { | |
| 488 | + let mut results = Vec::new(); | |
| 489 | + let mut depth = 0; | |
| 490 | + let mut start = None; | |
| 491 | + | |
| 492 | + let cleaned = remove_comments(s); | |
| 493 | + | |
| 494 | + for (i, c) in cleaned.char_indices() { | |
| 495 | + if c == open { | |
| 496 | + if depth == 0 { | |
| 497 | + start = Some(i); | |
| 498 | + } | |
| 499 | + depth += 1; | |
| 500 | + } else if c == close { | |
| 501 | + depth -= 1; | |
| 502 | + if depth == 0 { | |
| 503 | + if let Some(start_idx) = start { | |
| 504 | + results.push(cleaned[start_idx..=i].to_string()); | |
| 505 | + start = None; | |
| 506 | + } | |
| 507 | + } | |
| 508 | + } | |
| 509 | + } | |
| 510 | + | |
| 511 | + results | |
| 512 | +} | |
| 513 | + | |
| 514 | +fn remove_comments(s: &str) -> String { | |
| 515 | + let mut result = String::new(); | |
| 516 | + for line in s.lines() { | |
| 517 | + let mut in_string = false; | |
| 518 | + let mut comment_start = None; | |
| 519 | + | |
| 520 | + for (i, c) in line.char_indices() { | |
| 521 | + if c == '"' && (i == 0 || line.chars().nth(i - 1) != Some('\\')) { | |
| 522 | + in_string = !in_string; | |
| 523 | + } | |
| 524 | + if !in_string && i + 1 < line.len() && &line[i..i + 2] == "//" { | |
| 525 | + comment_start = Some(i); | |
| 526 | + break; | |
| 527 | + } | |
| 528 | + } | |
| 529 | + | |
| 530 | + if let Some(pos) = comment_start { | |
| 531 | + result.push_str(&line[..pos]); | |
| 532 | + } else { | |
| 533 | + result.push_str(line); | |
| 534 | + } | |
| 535 | + result.push('\n'); | |
| 536 | + } | |
| 537 | + result | |
| 538 | +} | |
| 539 | + | |
| 540 | +fn extract_quoted_value(content: &str, field_name: &str) -> Option<String> { | |
| 541 | + let pattern = format!("{}:", field_name); | |
| 542 | + if let Some(start) = content.find(&pattern) { | |
| 543 | + let after_colon = &content[start + pattern.len()..]; | |
| 544 | + let trimmed = after_colon.trim_start(); | |
| 545 | + if trimmed.starts_with('"') { | |
| 546 | + if let Some(end) = trimmed[1..].find('"') { | |
| 547 | + return Some(trimmed[1..end + 1].to_string()); | |
| 548 | + } | |
| 549 | + } | |
| 550 | + } | |
| 551 | + None | |
| 552 | +} |
+1 −0 src/config/mod.rs
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | mod lua; |
| 2 | +pub mod migrate; | |
| 2 | 3 | |
| 3 | 4 | use crate::bar::{BlockCommand, BlockConfig}; |
| 4 | 5 | use crate::errors::ConfigError; |
+64 −210 templates/config.lua
| @@ -1,106 +1,27 @@ | ||
| 1 | 1 | -- OXWM Configuration File (Lua) |
| 2 | +-- Migrated from config.ron | |
| 2 | 3 | -- Edit this file and reload with Mod+Shift+R (no compilation needed!) |
| 3 | 4 | |
| 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 | 5 | local terminal = "st" |
| 84 | 6 | local modkey = "Mod4" |
| 85 | 7 | local secondary_modkey = "Mod1" |
| 86 | 8 | |
| 87 | --- Color palette (Tokyo Night theme) | |
| 9 | +-- Color palette | |
| 88 | 10 | 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, | |
| 11 | + fg = "#bbbbbb", | |
| 12 | + red = "#f7768e", | |
| 13 | + bg = "#1a1b26", | |
| 14 | + cyan = "#0db9d7", | |
| 15 | + green = "#9ece6a", | |
| 16 | + lavender = "#a9b1d6", | |
| 17 | + light_blue = "#7aa2f7", | |
| 18 | + grey = "#bbbbbb", | |
| 19 | + blue = "#6dade3", | |
| 20 | + purple = "#ad8ee6", | |
| 99 | 21 | } |
| 100 | 22 | |
| 101 | 23 | -- Main configuration table |
| 102 | ----@type Config | |
| 103 | -config = { | |
| 24 | +return { | |
| 104 | 25 | -- Appearance |
| 105 | 26 | border_width = 2, |
| 106 | 27 | border_focused = colors.blue, |
| @@ -115,119 +36,71 @@ config = { | ||
| 115 | 36 | gap_outer_vertical = 5, |
| 116 | 37 | |
| 117 | 38 | -- Basics |
| 118 | - modkey = modkey, | |
| 119 | - terminal = terminal, | |
| 39 | + modkey = "Mod4", | |
| 40 | + terminal = "st", | |
| 120 | 41 | |
| 121 | 42 | -- Workspace tags |
| 122 | - tags = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}, | |
| 43 | + tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, | |
| 123 | 44 | |
| 124 | 45 | -- Layout symbol overrides |
| 125 | 46 | layout_symbols = { |
| 126 | - {name = "tiling", symbol = "[T]"}, | |
| 127 | - {name = "normie", symbol = "[F]"}, | |
| 47 | + { name = "tiling", symbol = "[T]" }, | |
| 48 | + { name = "normie", symbol = "[F]" }, | |
| 128 | 49 | }, |
| 129 | 50 | |
| 130 | 51 | -- 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 | 52 | 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 | |
| 53 | + { modifiers = { "Mod4" }, key = "Return", action = "Spawn", arg = "st" }, | |
| 54 | + { modifiers = { "Mod4" }, key = "D", action = "Spawn", arg = { "sh", "-c", "dmenu_run -l 10" } }, | |
| 55 | + { modifiers = { "Mod4" }, key = "S", action = "Spawn", arg = { "sh", "-c", "maim -s | xclip -selection clipboard -t image/png" } }, | |
| 56 | + { modifiers = { "Mod4" }, key = "Q", action = "KillClient" }, | |
| 57 | + { modifiers = { "Mod4", "Shift" }, key = "F", action = "ToggleFullScreen" }, | |
| 58 | + { modifiers = { "Mod4", "Shift" }, key = "Space", action = "ToggleFloating" }, | |
| 59 | + { modifiers = { "Mod4" }, key = "F", action = "ChangeLayout", arg = "normie" }, | |
| 60 | + { modifiers = { "Mod4" }, key = "C", action = "ChangeLayout", arg = "tiling" }, | |
| 61 | + { modifiers = { "Mod1" }, key = "N", action = "CycleLayout" }, | |
| 62 | + { modifiers = { "Mod4" }, key = "A", action = "ToggleGaps" }, | |
| 63 | + { modifiers = { "Mod4", "Shift" }, key = "Q", action = "Quit" }, | |
| 64 | + { modifiers = { "Mod4", "Shift" }, key = "R", action = "Restart" }, | |
| 65 | + { modifiers = { "Mod4" }, key = "H", action = "FocusDirection", arg = 2 }, | |
| 66 | + { modifiers = { "Mod4" }, key = "J", action = "FocusDirection", arg = 1 }, | |
| 67 | + { modifiers = { "Mod4" }, key = "K", action = "FocusDirection", arg = 0 }, | |
| 68 | + { modifiers = { "Mod4" }, key = "L", action = "FocusDirection", arg = 3 }, | |
| 69 | + { modifiers = { "Mod4" }, key = "Comma", action = "FocusMonitor", arg = -1 }, | |
| 70 | + { modifiers = { "Mod4" }, key = "Period", action = "FocusMonitor", arg = 1 }, | |
| 71 | + { modifiers = { "Mod4" }, key = "1", action = "ViewTag", arg = 0 }, | |
| 72 | + { modifiers = { "Mod4" }, key = "2", action = "ViewTag", arg = 1 }, | |
| 73 | + { modifiers = { "Mod4" }, key = "3", action = "ViewTag", arg = 2 }, | |
| 74 | + { modifiers = { "Mod4" }, key = "4", action = "ViewTag", arg = 3 }, | |
| 75 | + { modifiers = { "Mod4" }, key = "5", action = "ViewTag", arg = 4 }, | |
| 76 | + { modifiers = { "Mod4" }, key = "6", action = "ViewTag", arg = 5 }, | |
| 77 | + { modifiers = { "Mod4" }, key = "7", action = "ViewTag", arg = 6 }, | |
| 78 | + { modifiers = { "Mod4" }, key = "8", action = "ViewTag", arg = 7 }, | |
| 79 | + { modifiers = { "Mod4" }, key = "9", action = "ViewTag", arg = 8 }, | |
| 80 | + { modifiers = { "Mod4", "Shift" }, key = "1", action = "MoveToTag", arg = 0 }, | |
| 81 | + { modifiers = { "Mod4", "Shift" }, key = "2", action = "MoveToTag", arg = 1 }, | |
| 82 | + { modifiers = { "Mod4", "Shift" }, key = "3", action = "MoveToTag", arg = 2 }, | |
| 83 | + { modifiers = { "Mod4", "Shift" }, key = "4", action = "MoveToTag", arg = 3 }, | |
| 84 | + { modifiers = { "Mod4", "Shift" }, key = "5", action = "MoveToTag", arg = 4 }, | |
| 85 | + { modifiers = { "Mod4", "Shift" }, key = "6", action = "MoveToTag", arg = 5 }, | |
| 86 | + { modifiers = { "Mod4", "Shift" }, key = "7", action = "MoveToTag", arg = 6 }, | |
| 87 | + { modifiers = { "Mod4", "Shift" }, key = "8", action = "MoveToTag", arg = 7 }, | |
| 88 | + { modifiers = { "Mod4", "Shift" }, key = "9", action = "MoveToTag", arg = 8 }, | |
| 89 | + { modifiers = { "Mod4", "Shift" }, key = "H", action = "SwapDirection", arg = 2 }, | |
| 90 | + { modifiers = { "Mod4", "Shift" }, key = "J", action = "SwapDirection", arg = 1 }, | |
| 91 | + { modifiers = { "Mod4", "Shift" }, key = "K", action = "SwapDirection", arg = 0 }, | |
| 92 | + { modifiers = { "Mod4", "Shift" }, key = "L", action = "SwapDirection", arg = 3 }, | |
| 206 | 93 | { |
| 207 | 94 | keys = { |
| 208 | - {modifiers = {"Mod4"}, key = "Space"}, | |
| 209 | - {modifiers = {}, key = "T"} | |
| 95 | + { modifiers = { "Mod4" }, key = "Space" }, | |
| 96 | + { modifiers = { }, key = "T" }, | |
| 210 | 97 | }, |
| 211 | 98 | action = "Spawn", |
| 212 | - arg = terminal | |
| 99 | + arg = "st" | |
| 213 | 100 | }, |
| 214 | 101 | }, |
| 215 | 102 | |
| 216 | 103 | -- 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 | 104 | status_blocks = { |
| 232 | 105 | { |
| 233 | 106 | format = "Ram: {used}/{total} GB", |
| @@ -239,7 +112,7 @@ config = { | ||
| 239 | 112 | { |
| 240 | 113 | format = " │ ", |
| 241 | 114 | command = "Static", |
| 242 | - interval_secs = 999999999, -- Very large number for static blocks (never update) | |
| 115 | + interval_secs = 999999999, | |
| 243 | 116 | color = colors.lavender, |
| 244 | 117 | underline = false |
| 245 | 118 | }, |
| @@ -272,7 +145,7 @@ config = { | ||
| 272 | 145 | scheme_normal = { |
| 273 | 146 | foreground = colors.fg, |
| 274 | 147 | background = colors.bg, |
| 275 | - underline = 0x444444 | |
| 148 | + underline = "#444444" | |
| 276 | 149 | }, |
| 277 | 150 | scheme_occupied = { |
| 278 | 151 | foreground = colors.cyan, |
| @@ -286,24 +159,5 @@ config = { | ||
| 286 | 159 | }, |
| 287 | 160 | |
| 288 | 161 | -- 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 | - }, | |
| 162 | + autostart = { }, | |
| 297 | 163 | } |
| 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 |