From 8110bb2773b6c841029a51eca7971f42a36f480c Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Tue, 2 Apr 2024 00:58:00 +0200 Subject: 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. --- legacy-cpp/src/platform/linux_platform.h | 105 +++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 legacy-cpp/src/platform/linux_platform.h (limited to 'legacy-cpp/src/platform/linux_platform.h') diff --git a/legacy-cpp/src/platform/linux_platform.h b/legacy-cpp/src/platform/linux_platform.h new file mode 100644 index 0000000..1237c85 --- /dev/null +++ b/legacy-cpp/src/platform/linux_platform.h @@ -0,0 +1,105 @@ +#ifndef SRDWM_LINUX_PLATFORM_H +#define SRDWM_LINUX_PLATFORM_H + +#include "platform.h" +#include +#include + +// Forward declarations for X11 +#ifdef __linux__ +struct _XDisplay; +typedef struct _XDisplay Display; +typedef unsigned long SRDWindow; +typedef unsigned long Atom; + +// Forward declarations for Wayland +struct wl_display; +struct wl_registry; +struct wl_compositor; +struct wl_shell; +struct wl_seat; +struct wl_keyboard; +struct wl_pointer; +#endif + +class LinuxPlatform : public Platform { +public: + enum class Backend { + Auto, + X11, + Wayland + }; + + explicit LinuxPlatform(Backend backend = Backend::Auto); + ~LinuxPlatform() override; + + // Platform interface implementation + bool initialize() override; + void shutdown() override; + + bool poll_events(std::vector& events) override; + void process_event(const Event& event) override; + + std::unique_ptr create_window(const std::string& title, int x, int y, int width, int height) override; + void destroy_window(SRDWindow* window) override; + void set_window_position(SRDWindow* window, int x, int y) override; + void set_window_size(SRDWindow* window, int width, int height) override; + void set_window_title(SRDWindow* window, const std::string& title) override; + void focus_window(SRDWindow* window) override; + void minimize_window(SRDWindow* window) override; + void maximize_window(SRDWindow* window) override; + void close_window(SRDWindow* window) override; + + std::vector get_monitors() override; + Monitor get_primary_monitor() override; + + void grab_keyboard() override; + void ungrab_keyboard() override; + void grab_pointer() override; + void ungrab_pointer() override; + + std::string get_platform_name() const override; + bool is_wayland() const override; + bool is_x11() const override; + bool is_windows() const override; + bool is_macos() const override; + +private: + Backend backend_; + bool initialized_; + + // X11 specific members + Display* x11_display_; + SRDWindow x11_root_; + Atom x11_wm_delete_window_; + Atom x11_wm_protocols_; + + // Wayland specific members + wl_display* wayland_display_; + wl_registry* wayland_registry_; + wl_compositor* wayland_compositor_; + wl_shell* wayland_shell_; + wl_seat* wayland_seat_; + wl_keyboard* wayland_keyboard_; + wl_pointer* wayland_pointer_; + + // Common members + std::vector monitors_; + + // Private methods + bool initialize_x11(); + bool initialize_wayland(); + void shutdown_x11(); + void shutdown_wayland(); + + bool detect_backend(); + void setup_x11_atoms(); + void setup_wayland_registry(); + + // Event processing + void process_x11_event(XEvent& event, std::vector& events); + void process_wayland_event(wl_display* display, std::vector& events); +}; + +#endif // SRDWM_LINUX_PLATFORM_H + -- cgit v1.2.3