srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorsrdusr <[email protected]>2024-04-02 00:58:00 +0200
committersrdusr <[email protected]>2024-04-02 00:58:00 +0200
commit8110bb2773b6c841029a51eca7971f42a36f480c (patch)
treeb3b364a6c0231fe408229e94dc9e25ce4562ad02 /config
parentd1f856edc516047575cf46f12fad2b59006363c8 (diff)
downloadsrdwm-8110bb2773b6c841029a51eca7971f42a36f480c.tar.gz
srdwm-8110bb2773b6c841029a51eca7971f42a36f480c.zip
Rewrite srdwm in Rust: working X11 and Wayland backends, Lua config
The C++ prototype (moved to legacy-cpp/) was mostly a design skeleton: X11 and Windows backends were partially real, Wayland created the wlroots object graph but never wired a single event listener, macOS was stub except monitor enumeration, and the Lua engine's srd.bind() stored a key-combo string but never the actual closure. See docs/PRIOR_ART.md for the full audit. This replaces it with a Cargo workspace: - srdwm-core: platform-independent window/workspace/monitor state, a real master-stack tiling layout, and SmartPlacement grid/cascade/ snap-to-edge placement - fixing several bugs in the C++ version (hardcoded 2-column grid, cascade that never cascaded, snap-to-edge that always returned a fixed rect). 35 unit tests. - srdwm-config: the srd Lua API via mlua, implementing the surface docs/DEFAULTS.md always documented but the C++ engine never actually built (srd.window.close()/focus(direction), srd.workspace.next(), real keybinding closures, require("srd") support). 10 unit tests. - srdwm-x11: a real reparenting WM with a drawn title bar (buttons, drag, resize), verified live under Xephyr - frame placement and client offset match srdwm-core's computed geometry exactly, and the decoration renders correctly on screen. - srdwm-wayland: a from-scratch smithay compositor (the C++ version had nothing working to port from) - runs via the winit backend, tracks xdg-shell toplevels through the same WindowManager and hit-testing code X11 uses, verified to start/render/run without crashing. Decorations are solid-color (no text yet); see docs/IMPLEMENTATION_STATUS.md for exact scope. - srdwm-windows / srdwm-macos: structured, cfg-gated designs informed by komorebi/glazewm and yabai/AeroSpace respectively (see docs/PRIOR_ART.md), honestly marked as unbuilt/unverified since this sandbox has no Windows or macOS target.
Diffstat (limited to 'config')
-rw-r--r--config/srd/cross_platform_test.lua240
-rw-r--r--config/srd/keybindings.lua215
-rw-r--r--config/srd/layouts.lua18
-rw-r--r--config/srd/monitors.lua6
-rw-r--r--config/srd/rules.lua6
-rw-r--r--config/srd/startup.lua5
-rw-r--r--config/srd/test_decorations.lua127
-rw-r--r--config/srd/themes.lua27
8 files changed, 97 insertions, 547 deletions
diff --git a/config/srd/cross_platform_test.lua b/config/srd/cross_platform_test.lua
deleted file mode 100644
index 86d93f6..0000000
--- a/config/srd/cross_platform_test.lua
+++ /dev/null
@@ -1,240 +0,0 @@
-- Cross-Platform Test Configuration
-- This file demonstrates all the cross-platform functionality of SRDWM
-
-print("Loading cross-platform test configuration...")
-
-- Platform detection and configuration
-local platform = srd.get_platform()
-print("Detected platform: " .. platform)
-
-- Platform-specific settings
-if platform == "wayland" then
- print("Configuring for Wayland/XWayland...")
- srd.set("general.decorations_enabled", true)
- srd.set("general.border_width", 2)
- srd.set("general.border_color", "#2e3440")
-
- - Wayland-specific keybindings
- srd.bind("Mod4+w", function()
- - Toggle server-side decorations
- local window = srd.window.focused()
- if window then
- local current = srd.window.get_decorations(window.id)
- srd.window.set_decorations(window.id, not current)
- print("Wayland: Toggled server-side decorations")
- end
- end)
-
-elseif platform == "x11" then
- print("Configuring for X11...")
- srd.set("general.decorations_enabled", true)
- srd.set("general.border_width", 3)
- srd.set("general.border_color", "#2e3440")
-
- - X11-specific keybindings
- srd.bind("Mod4+x", function()
- - Toggle frame windows
- local window = srd.window.focused()
- if window then
- local current = srd.window.get_decorations(window.id)
- srd.window.set_decorations(window.id, not current)
- print("X11: Toggled frame windows")
- end
- end)
-
-elseif platform == "windows" then
- print("Configuring for Windows...")
- srd.set("general.decorations_enabled", true)
- srd.set("general.border_width", 2)
- srd.set("general.border_color", "#2e3440")
-
- - Windows-specific keybindings
- srd.bind("Mod4+d", function()
- - Toggle DWM border colors
- local window = srd.window.focused()
- if window then
- srd.window.set_border_color(window.id, 255, 0, 0) - Red border
- print("Windows: Set DWM border color")
- end
- end)
-
-elseif platform == "macos" then
- print("Configuring for macOS...")
- srd.set("general.decorations_enabled", false) - Limited decoration support
- srd.set("general.border_width", 1)
- srd.set("general.border_color", "#2e3440")
-
- - macOS-specific keybindings
- srd.bind("Mod4+m", function()
- - Toggle overlay windows (macOS limitation)
- local window = srd.window.focused()
- if window then
- print("macOS: Overlay window toggle requested")
- end
- end)
-end
-
-- Universal cross-platform keybindings
-srd.bind("Mod4+1", function()
- srd.layout.set("tiling")
- print("Switched to tiling layout")
-end)
-
-srd.bind("Mod4+2", function()
- srd.layout.set("dynamic")
- print("Switched to dynamic layout (smart placement)")
-end)
-
-srd.bind("Mod4+3", function()
- srd.layout.set("floating")
- print("Switched to floating layout")
-end)
-
-- Window state controls (cross-platform)
-srd.bind("Mod4+f", function()
- local window = srd.window.focused()
- if window then
- srd.window.toggle_floating(window.id)
- local floating = srd.window.is_floating(window.id)
- print("Window floating state: " .. tostring(floating))
- end
-end)
-
-srd.bind("Mod4+t", function()
- local window = srd.window.focused()
- if window then
- srd.window.set_floating(window.id, false)
- print("Set window to tiling mode")
- end
-end)
-
-srd.bind("Mod4+l", function()
- local window = srd.window.focused()
- if window then
- srd.window.set_floating(window.id, true)
- print("Set window to floating mode")
- end
-end)
-
-- Decoration controls (cross-platform)
-srd.bind("Mod4+b", function()
- local window = srd.window.focused()
- if window then
- srd.window.set_border_color(window.id, 0, 255, 0) - Green border
- print("Set green border")
- end
-end)
-
-srd.bind("Mod4+n", function()
- local window = srd.window.focused()
- if window then
- srd.window.set_border_color(window.id, 0, 0, 255) - Blue border
- print("Set blue border")
- end
-end)
-
-srd.bind("Mod4+r", function()
- local window = srd.window.focused()
- if window then
- srd.window.set_border_color(window.id, 255, 0, 0) - Red border
- print("Set red border")
- end
-end)
-
-srd.bind("Mod4+0", function()
- local window = srd.window.focused()
- if window then
- - Reset to default colors
- srd.window.set_border_color(window.id, 46, 52, 64) - Default color
- srd.window.set_border_width(window.id, 2)
- print("Reset to default decoration")
- end
-end)
-
-- Smart placement test
-srd.bind("Mod4+s", function()
- print("Smart placement test:")
- print("- Grid placement: Windows 11-style window arrangement")
- print("- Cascade placement: Overlapping window management")
- print("- Snap-to-edge: Edge snapping functionality")
- print("- Overlap detection: Prevents window overlap")
-end)
-
-- Platform-specific feature tests
-function test_platform_features()
- print("Testing platform-specific features...")
-
- if platform == "wayland" then
- print("Wayland features:")
- print("- zxdg-decoration protocol support")
- print("- XWayland integration")
- print("- Layer shell support")
- print("- Server-side decorations")
-
- elseif platform == "x11" then
- print("X11 features:")
- print("- Frame window reparenting")
- print("- Custom titlebar drawing")
- print("- Border customization")
- print("- Event handling")
-
- elseif platform == "windows" then
- print("Windows features:")
- print("- DWM border color API")
- print("- Native decoration toggling")
- print("- Global keyboard/mouse hooks")
- print("- Window class management")
-
- elseif platform == "macos" then
- print("macOS features:")
- print("- Accessibility APIs")
- print("- Event tap system")
- print("- Core Graphics integration")
- print("- Limited decoration support")
- end
-end
-
-- Test function for decoration system
-function test_decoration_system()
- print("Testing decoration system...")
-
- - Test decoration toggling
- srd.window.set_decorations("test_window", true)
- local has_decorations = srd.window.get_decorations("test_window")
- print("Decoration test: " .. tostring(has_decorations))
-
- - Test border color
- srd.window.set_border_color("test_window", 128, 128, 128)
- print("Border color test: RGB(128, 128, 128)")
-
- - Test border width
- srd.window.set_border_width("test_window", 5)
- print("Border width test: 5px")
-end
-
-- Test function for window state system
-function test_window_state_system()
- print("Testing window state system...")
-
- - Test floating state
- srd.window.set_floating("test_window", true)
- local is_floating = srd.window.is_floating("test_window")
- print("Floating state test: " .. tostring(is_floating))
-
- - Test toggle
- srd.window.toggle_floating("test_window")
- is_floating = srd.window.is_floating("test_window")
- print("Toggle test: " .. tostring(is_floating))
-end
-
-- Run tests
-test_platform_features()
-test_decoration_system()
-test_window_state_system()
-
-print("Cross-platform test configuration loaded successfully!")
-print("Use Mod4+1/2/3 to switch layouts")
-print("Use Mod4+f to toggle floating")
-print("Use Mod4+b/n/r to change border colors")
-print("Use Mod4+0 to reset decorations")
-print("Use Mod4+s for smart placement info")
diff --git a/config/srd/keybindings.lua b/config/srd/keybindings.lua
index e2585b2..5c05b84 100644
--- a/config/srd/keybindings.lua
+++ b/config/srd/keybindings.lua
@@ -1,185 +1,58 @@
- SRDWM Key Bindings Configuration
-- Define all keyboard shortcuts and their actions
+- Every function called here is part of the real `srd` API implemented in
+- crates/config/src/lib.rs - see docs/DEFAULTS.md for the full reference.
local srd = require("srd")
- Layout switching
-srd.bind("Mod4+1", function()
+srd.bind("Mod4+1", function()
srd.layout.set("tiling")
srd.notify("Layout: Tiling", "info")
end)
-srd.bind("Mod4+2", function()
+srd.bind("Mod4+2", function()
srd.layout.set("dynamic")
srd.notify("Layout: Dynamic", "info")
end)
-srd.bind("Mod4+3", function()
+srd.bind("Mod4+3", function()
srd.layout.set("floating")
srd.notify("Layout: Floating", "info")
end)
-- Window management
-srd.bind("Mod4+q", function()
- local window = srd.window.focused()
- if window then
- window:close()
- end
-end)
-
-srd.bind("Mod4+m", function()
- local window = srd.window.focused()
- if window then
- window:minimize()
- end
-end)
-
-srd.bind("Mod4+f", function()
- local window = srd.window.focused()
- if window then
- window:maximize()
- end
-end)
-
-- Window movement (vim-style)
-srd.bind("Mod4+h", function()
- srd.window.focus("left")
-end)
-
-srd.bind("Mod4+j", function()
- srd.window.focus("down")
-end)
-
-srd.bind("Mod4+k", function()
- srd.window.focus("up")
-end)
-
-srd.bind("Mod4+l", function()
- srd.window.focus("right")
-end)
+- Window management (act on the focused window)
+srd.bind("Mod4+q", function() srd.window.close() end)
+srd.bind("Mod4+m", function() srd.window.minimize() end)
+srd.bind("Mod4+f", function() srd.window.maximize() end)
+srd.bind("Mod4+Shift+space", function() srd.window.toggle_floating() end)
-- Window resizing
-srd.bind("Mod4+Shift+h", function()
- local window = srd.window.focused()
- if window then
- local x, y, w, h = window:get_geometry()
- window:set_geometry(x - 10, y, w + 10, h)
- end
-end)
-
-srd.bind("Mod4+Shift+j", function()
- local window = srd.window.focused()
- if window then
- local x, y, w, h = window:get_geometry()
- window:set_geometry(x, y, w, h + 10)
- end
-end)
-
-srd.bind("Mod4+Shift+k", function()
- local window = srd.window.focused()
- if window then
- local x, y, w, h = window:get_geometry()
- window:set_geometry(x, y - 10, w, h + 10)
- end
-end)
-
-srd.bind("Mod4+Shift+l", function()
- local window = srd.window.focused()
- if window then
- local x, y, w, h = window:get_geometry()
- window:set_geometry(x, y, w + 10, h)
- end
-end)
+- Window navigation (vim-style directional focus)
+srd.bind("Mod4+h", function() srd.window.focus("left") end)
+srd.bind("Mod4+j", function() srd.window.focus("down") end)
+srd.bind("Mod4+k", function() srd.window.focus("up") end)
+srd.bind("Mod4+l", function() srd.window.focus("right") end)
- Workspace management
-srd.bind("Mod4+Tab", function()
- srd.workspace.next()
-end)
+srd.bind("Mod4+Tab", function() srd.workspace.next() end)
+srd.bind("Mod4+Shift+Tab", function() srd.workspace.prev() end)
-srd.bind("Mod4+Shift+Tab", function()
- srd.workspace.prev()
-end)
-
-- Workspace switching with number keys
-for i = 1, 10 do
- srd.bind("Mod4+" .. i, function()
- srd.workspace.switch(i)
- end)
-
- srd.bind("Mod4+Shift+" .. i, function()
- local window = srd.window.focused()
- if window then
- srd.workspace.move_window(window, i)
- end
- end)
+- Workspace switching with number keys (0 doubles as "workspace 10")
+for i = 0, 9 do
+ srd.bind("Mod4+" .. i, function() srd.workspace.switch(i) end)
+ srd.bind("Mod4+Shift+" .. i, function() srd.workspace.move_window(i) end)
end
-- Monitor switching
-srd.bind("Mod4+Left", function()
- srd.monitor.focus("left")
-end)
-
-srd.bind("Mod4+Right", function()
- srd.monitor.focus("right")
-end)
-
-- Window state toggles
-srd.bind("Mod4+Shift+space", function()
- local window = srd.window.focused()
- if window then
- if window:is_floating() then
- window:set_tiling()
- else
- window:set_floating()
- end
- end
-end)
-
-srd.bind("Mod4+Shift+f", function()
- local window = srd.window.focused()
- if window then
- if window:is_fullscreen() then
- window:unset_fullscreen()
- else
- window:set_fullscreen()
- end
- end
-end)
-
- Quick actions
-srd.bind("Mod4+d", function()
- srd.spawn("rofi -show drun")
-end)
-
-srd.bind("Mod4+Return", function()
- srd.spawn("alacritty")
-end)
-
-srd.bind("Mod4+r", function()
- srd.spawn("rofi -show run")
-end)
-
-srd.bind("Mod4+w", function()
- srd.spawn("firefox")
-end)
+srd.bind("Mod4+d", function() srd.spawn("rofi -show drun") end)
+srd.bind("Mod4+Return", function() srd.spawn("alacritty") end)
+srd.bind("Mod4+r", function() srd.spawn("rofi -show run") end)
-- System actions
-srd.bind("Mod4+Shift+q", function()
- srd.quit()
-end)
+- System
+srd.bind("Mod4+Shift+q", function() srd.quit() end)
-srd.bind("Mod4+Shift+r", function()
- srd.reload_config()
-end)
-
-srd.bind("Mod4+Shift+l", function()
- srd.spawn("i3lock")
-end)
-
-- Custom functions
-function toggle_gaps()
- local current_gap = srd.get("general.window_gap")
- if current_gap > 0 then
+- Custom function example: toggle window gaps at runtime
+local function toggle_gaps()
+ if srd.get("general.window_gap") > 0 then
srd.set("general.window_gap", 0)
srd.notify("Gaps: Off", "info")
else
@@ -187,31 +60,13 @@ function toggle_gaps()
srd.notify("Gaps: On", "info")
end
end
-
srd.bind("Mod4+g", toggle_gaps)
-- Volume control
-srd.bind("XF86AudioRaiseVolume", function()
- srd.spawn("pactl set-sink-volume @DEFAULT_SINK@ +5%")
-end)
-
-srd.bind("XF86AudioLowerVolume", function()
- srd.spawn("pactl set-sink-volume @DEFAULT_SINK@ -5%")
-end)
+- Media keys
+srd.bind("XF86AudioRaiseVolume", function() srd.spawn("pactl set-sink-volume @DEFAULT_SINK@ +5%") end)
+srd.bind("XF86AudioLowerVolume", function() srd.spawn("pactl set-sink-volume @DEFAULT_SINK@ -5%") end)
+srd.bind("XF86AudioMute", function() srd.spawn("pactl set-sink-mute @DEFAULT_SINK@ toggle") end)
+srd.bind("XF86MonBrightnessUp", function() srd.spawn("brightnessctl set +5%") end)
+srd.bind("XF86MonBrightnessDown", function() srd.spawn("brightnessctl set 5%-") end)
-srd.bind("XF86AudioMute", function()
- srd.spawn("pactl set-sink-mute @DEFAULT_SINK@ toggle")
-end)
-
-- Brightness control
-srd.bind("XF86MonBrightnessUp", function()
- srd.spawn("brightnessctl set +5%")
-end)
-
-srd.bind("XF86MonBrightnessDown", function()
- srd.spawn("brightnessctl set 5%-")
-end)
-
-- Print key bindings loaded
print("Key bindings configuration loaded")
-
diff --git a/config/srd/layouts.lua b/config/srd/layouts.lua
new file mode 100644
index 0000000..3a070c2
--- /dev/null
+++ b/config/srd/layouts.lua
@@ -0,0 +1,18 @@
+- Layout tuning. Keys and defaults match docs/DEFAULTS.md.
+local srd = require("srd")
+
+srd.layout.configure("tiling", {
+ master_ratio = 0.6,
+ gaps = { inner = 8, outer = 16 },
+})
+
+srd.layout.configure("dynamic", {
+ snap_threshold = 50,
+ cascade_offset = 30,
+ gaps = { inner = 8, outer = 16 },
+})
+
+srd.layout.configure("floating", {
+ default_position = "center",
+ gaps = { inner = 0, outer = 16 },
+})
diff --git a/config/srd/monitors.lua b/config/srd/monitors.lua
new file mode 100644
index 0000000..5810a42
--- /dev/null
+++ b/config/srd/monitors.lua
@@ -0,0 +1,6 @@
+- Per-monitor defaults (docs/DEFAULTS.md monitor.* keys).
+local srd = require("srd")
+
+srd.set("monitor.primary_layout", "dynamic")
+srd.set("monitor.secondary_layout", "tiling")
+srd.set("monitor.auto_detect", true)
diff --git a/config/srd/rules.lua b/config/srd/rules.lua
new file mode 100644
index 0000000..576333a
--- /dev/null
+++ b/config/srd/rules.lua
@@ -0,0 +1,6 @@
+- Window rules (match-by-title/class -> action).
+--
+- A dedicated `srd.rule(...)` API is not implemented yet - see
+- docs/IMPLEMENTATION_STATUS.md. For now, achieve the same effect from
+- srd.bind()'d keys or by reacting to srd.window.focused() in your own
+- functions. This file is intentionally a no-op placeholder.
diff --git a/config/srd/startup.lua b/config/srd/startup.lua
new file mode 100644
index 0000000..52c0985
--- /dev/null
+++ b/config/srd/startup.lua
@@ -0,0 +1,5 @@
+- Autostart. Uncomment/add whatever you want srdwm to launch on login.
+local srd = require("srd")
+
+- srd.spawn("nm-applet")
+- srd.spawn("picom")
diff --git a/config/srd/test_decorations.lua b/config/srd/test_decorations.lua
deleted file mode 100644
index 2b49d0a..0000000
--- a/config/srd/test_decorations.lua
+++ /dev/null
@@ -1,127 +0,0 @@
-- Test configuration for decoration and window state controls
-- This file demonstrates the cross-platform decoration and tiling/floating functionality
-
-print("Loading decoration and window state test configuration...")
-
-- Global decoration settings
-srd.set("general.decorations_enabled", true)
-srd.set("general.border_width", 3)
-srd.set("general.border_color", "#2e3440")
-
-- Keybindings for decoration and window state controls
-srd.bind("Mod4+d", function()
- - Toggle decorations for focused window
- local window = srd.window.focused()
- if window then
- local current = srd.window.get_decorations(window.id)
- srd.window.set_decorations(window.id, not current)
- print("Toggled decorations for window " .. window.id)
- end
-end)
-
-srd.bind("Mod4+b", function()
- - Toggle border color for focused window
- local window = srd.window.focused()
- if window then
- srd.window.set_border_color(window.id, 255, 0, 0) - Red border
- print("Set red border for window " .. window.id)
- end
-end)
-
-srd.bind("Mod4+n", function()
- - Toggle border color back to normal
- local window = srd.window.focused()
- if window then
- srd.window.set_border_color(window.id, 46, 52, 64) - Default color
- print("Reset border color for window " .. window.id)
- end
-end)
-
-srd.bind("Mod4+w", function()
- - Toggle border width
- local window = srd.window.focused()
- if window then
- srd.window.set_border_width(window.id, 8) - Thick border
- print("Set thick border for window " .. window.id)
- end
-end)
-
-srd.bind("Mod4+s", function()
- - Reset border width
- local window = srd.window.focused()
- if window then
- srd.window.set_border_width(window.id, 3) - Normal border
- print("Reset border width for window " .. window.id)
- end
-end)
-
-- Window state controls
-srd.bind("Mod4+f", function()
- - Toggle floating state for focused window
- local window = srd.window.focused()
- if window then
- srd.window.toggle_floating(window.id)
- local floating = srd.window.is_floating(window.id)
- print("Window " .. window.id .. " floating: " .. tostring(floating))
- end
-end)
-
-srd.bind("Mod4+t", function()
- - Set window to tiling mode
- local window = srd.window.focused()
- if window then
- srd.window.set_floating(window.id, false)
- print("Set window " .. window.id .. " to tiling mode")
- end
-end)
-
-srd.bind("Mod4+l", function()
- - Set window to floating mode
- local window = srd.window.focused()
- if window then
- srd.window.set_floating(window.id, true)
- print("Set window " .. window.id .. " to floating mode")
- end
-end)
-
-- Layout switching with decoration awareness
-srd.bind("Mod4+1", function()
- srd.layout.set("tiling")
- print("Switched to tiling layout")
-end)
-
-srd.bind("Mod4+2", function()
- srd.layout.set("dynamic")
- print("Switched to dynamic layout")
-end)
-
-srd.bind("Mod4+3", function()
- srd.layout.set("floating")
- print("Switched to floating layout")
-end)
-
-- Test function to apply decorations to all windows
-function apply_test_decorations()
- print("Applying test decorations to all windows...")
-
- - This would iterate through all windows in a real implementation
- - For now, we'll just demonstrate the API
-
- - Example: Apply red border to window with ID "1"
- srd.window.set_border_color("1", 255, 0, 0)
- srd.window.set_border_width("1", 5)
-
- - Example: Apply blue border to window with ID "2"
- srd.window.set_border_color("2", 0, 0, 255)
- srd.window.set_border_width("2", 3)
-
- - Example: Disable decorations for window with ID "3"
- srd.window.set_decorations("3", false)
-
- print("Test decorations applied")
-end
-
-- Call the test function
-apply_test_decorations()
-
-print("Decoration and window state test configuration loaded successfully!")
diff --git a/config/srd/themes.lua b/config/srd/themes.lua
new file mode 100644
index 0000000..4233b46
--- /dev/null
+++ b/config/srd/themes.lua
@@ -0,0 +1,27 @@
+- Nord-inspired theme (matches the built-in defaults; edit freely).
+local srd = require("srd")
+
+srd.theme.set_colors({
+ background = "#2e3440",
+ foreground = "#eceff4",
+ primary = "#88c0d0",
+ secondary = "#81a1c1",
+ accent = "#5e81ac",
+ error = "#bf616a",
+ warning = "#ebcb8b",
+ success = "#a3be8c",
+})
+
+srd.theme.set_decorations({
+ border = {
+ width = 2,
+ active_color = "#88c0d0",
+ inactive_color = "#4c566a",
+ },
+ title_bar = {
+ height = 30,
+ show = true,
+ background = "#2e3440",
+ foreground = "#eceff4",
+ },
+})