Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 622b06da3f | |||
| 529a1a54ae | |||
| 473bed479a | |||
| 496a7a4c72 | |||
| 2d1d364270 | |||
| b22172c3a0 |
@@ -0,0 +1,44 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
Format based on [Keep a Changelog](https://keepachangelog.com/).
|
||||
|
||||
## [0.4.0] - 2026-03-28
|
||||
|
||||
### Added
|
||||
|
||||
- Optional background blur via `background_blur` config option (Gaussian blur, `image` crate)
|
||||
|
||||
## [0.1.1] - 2026-03-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- Use absolute paths for all system binaries (`systemctl`, `loginctl`, `niri`, `moonlock`) to prevent PATH hijacking
|
||||
- Implement `POWER_TIMEOUT` (30s) via `try_wait()` polling — previously declared but unused, leaving power actions able to block indefinitely
|
||||
- Prevent panic in `load_background_texture` when GResource path contains non-UTF-8 bytes — now falls back to known wallpaper resource
|
||||
- Fix fallback user UID from `0` (root) to `u32::MAX` as a safe sentinel value
|
||||
- Fix CSS comment incorrectly describing circular buttons as "square card"
|
||||
|
||||
### Changed
|
||||
|
||||
- Compress wallpaper in GResource bundle (`compressed="true"`) to reduce binary size
|
||||
- Merge double `idle_add_local_once` into single idle cycle for faster keyboard focus on launch
|
||||
- Centralize `GRESOURCE_PREFIX` as `pub(crate) const` in `main.rs` (was duplicated in `config.rs`, `users.rs`, and literal strings in `panel.rs`)
|
||||
- Translate README.md and config comments from German to English
|
||||
- Remove stale `journal.md` (one-time development notes, not actively maintained)
|
||||
|
||||
## [0.1.0] - 2026-03-27
|
||||
|
||||
### Added
|
||||
|
||||
- Rust rewrite of the Python power menu (gtk4-rs + gtk4-layer-shell)
|
||||
- 5 power actions: Lock, Logout, Hibernate, Reboot, Shutdown
|
||||
- Inline confirmation for destructive actions (all except Lock)
|
||||
- Multi-monitor wallpaper support via shared `gdk::Texture`
|
||||
- DE/EN localization with automatic locale detection
|
||||
- TOML configuration for custom wallpaper path
|
||||
- GResource bundle for CSS, wallpaper, and default avatar
|
||||
- Async power actions via `glib::spawn_future_local` + `gio::spawn_blocking`
|
||||
- Async avatar loading (file-based avatars decoded off UI thread)
|
||||
- Cached icon loading at startup
|
||||
- 45 unit tests
|
||||
@@ -17,7 +17,7 @@ Lock, Logout, Hibernate, Reboot, Shutdown.
|
||||
## Projektstruktur
|
||||
|
||||
- `src/` — Rust-Quellcode (main.rs, power.rs, i18n.rs, config.rs, users.rs, panel.rs)
|
||||
- `resources/` — GResource-Assets (style.css, wallpaper.jpg, default-avatar.svg)
|
||||
- `resources/` — GResource-Assets (style.css, wallpaper.jpg komprimiert, default-avatar.svg)
|
||||
- `config/` — Beispiel-Konfigurationsdateien
|
||||
|
||||
## Kommandos
|
||||
@@ -35,20 +35,24 @@ LD_PRELOAD=/usr/lib/libgtk4-layer-shell.so ./target/release/moonset
|
||||
|
||||
## Architektur
|
||||
|
||||
- `power.rs` — 5 Power-Action-Wrapper (lock, logout, hibernate, reboot, shutdown)
|
||||
- `main.rs` — Entry Point, GTK App, Layer Shell Setup, Multi-Monitor, zentrale `GRESOURCE_PREFIX`-Konstante
|
||||
- `power.rs` — 5 Power-Action-Wrapper mit absoluten Pfaden und 30s Timeout (lock, logout, hibernate, reboot, shutdown)
|
||||
- `i18n.rs` — Locale-Erkennung und String-Tabellen (DE/EN)
|
||||
- `config.rs` — TOML-Config + Wallpaper-Fallback
|
||||
- `panel.rs` — GTK4 UI (Action-Buttons, Inline-Confirmation, WallpaperWindow)
|
||||
- `main.rs` — Entry Point, GTK App, Layer Shell Setup, Multi-Monitor
|
||||
- `resources/style.css` — Catppuccin Mocha Theme (aus Python-Version übernommen)
|
||||
- `users.rs` — User-Erkennung, Avatar-Loading (AccountsService, ~/.face, GResource-Fallback)
|
||||
- `resources/style.css` — GTK-Theme-Colors für Konsistenz mit dem aktiven Desktop-Theme
|
||||
|
||||
## Design Decisions
|
||||
|
||||
Siehe `DECISIONS.md` für das vollständige Entscheidungsprotokoll.
|
||||
|
||||
Kurzfassung der wichtigsten Entscheidungen:
|
||||
- **OVERLAY statt TOP Layer**: Waybar liegt auf TOP, moonset muss darüber
|
||||
- **Niri-spezifischer Logout** (`niri msg action quit`): Moonarch setzt fest auf Niri
|
||||
- **Einmal-Start per Keybind**: Kein Daemon, GTK `application_id` verhindert Doppelstart
|
||||
- **System-Icons**: Adwaita/Catppuccin liefern alle benötigten symbolischen Icons
|
||||
- **Lock ohne Confirmation**: Lock ist sofort reversibel, braucht kein Confirm
|
||||
- **Icon-Scaling**: 22px Theme-Variante laden, auf 64px skalieren via GdkPixbuf
|
||||
- **GResource-Bundle**: CSS, Wallpaper und Default-Avatar sind in die Binary kompiliert
|
||||
- **Async Power Actions**: `glib::spawn_future_local` + `gio::spawn_blocking` statt raw Threads
|
||||
- **Absolute Pfade für Binaries**: `/usr/bin/systemctl` etc. statt relativer Pfade (Security)
|
||||
- **GResource-Bundle**: CSS, Wallpaper (komprimiert) und Default-Avatar sind in die Binary kompiliert
|
||||
- **Async Power Actions**: `glib::spawn_future_local` + `gio::spawn_blocking` mit 30s Timeout
|
||||
|
||||
Generated
+132
-1
@@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "adler2"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.4"
|
||||
@@ -79,6 +85,18 @@ version = "2.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder-lite"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
|
||||
|
||||
[[package]]
|
||||
name = "cairo-rs"
|
||||
version = "0.22.0"
|
||||
@@ -130,6 +148,15 @@ version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "6.0.0"
|
||||
@@ -196,6 +223,15 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c"
|
||||
dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.6"
|
||||
@@ -206,6 +242,16 @@ dependencies = [
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
@@ -630,6 +676,21 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.25.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"byteorder-lite",
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
@@ -732,9 +793,19 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "moonset"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"env_logger",
|
||||
@@ -744,6 +815,7 @@ dependencies = [
|
||||
"glib-build-tools",
|
||||
"gtk4",
|
||||
"gtk4-layer-shell",
|
||||
"image",
|
||||
"log",
|
||||
"nix",
|
||||
"serde",
|
||||
@@ -751,6 +823,16 @@ dependencies = [
|
||||
"toml 0.8.23",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "moxcms"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
"pxfm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.29.0"
|
||||
@@ -763,6 +845,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
@@ -817,6 +908,19 @@ version = "0.3.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"crc32fast",
|
||||
"fdeflate",
|
||||
"flate2",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.13.1"
|
||||
@@ -860,6 +964,12 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pxfm"
|
||||
version = "0.1.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a041e753da8b807c9255f28de81879c78c876392ff2469cde94799b2896b9d"
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.45"
|
||||
@@ -1004,6 +1114,12 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
@@ -1394,3 +1510,18 @@ name = "zmij"
|
||||
version = "1.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9"
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
|
||||
dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "moonset"
|
||||
version = "0.1.0"
|
||||
version = "0.4.0"
|
||||
edition = "2024"
|
||||
description = "Wayland session power menu with GTK4 and Layer Shell"
|
||||
license = "MIT"
|
||||
@@ -15,6 +15,7 @@ toml = "0.8"
|
||||
dirs = "6"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
nix = { version = "0.29", features = ["user"] }
|
||||
image = { version = "0.25", default-features = false, features = ["jpeg", "png"] }
|
||||
log = "0.4"
|
||||
env_logger = "0.11"
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# Decisions
|
||||
|
||||
Architectural and design decisions for Moonset, in reverse chronological order.
|
||||
|
||||
## 2026-03-28 – Optional background blur via `image` crate
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: Blurred wallpaper as background is a common UX pattern for overlay menus
|
||||
- **Tradeoffs**: Adds `image` crate dependency (~15 transitive crates); CPU-side Gaussian blur at load time adds startup latency proportional to image size and sigma. Acceptable because blur runs once and the texture is shared across monitors.
|
||||
- **How**: `load_background_texture(bg_path, blur_radius)` loads texture, optionally applies `imageops::blur()`, returns `gdk::Texture`. Config option `background_blur: Option<f32>` in TOML.
|
||||
|
||||
## 2026-03-28 – Use absolute paths for system binaries
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: Security audit flagged PATH hijacking risk — relative binary names allow a malicious `$PATH` entry to intercept `systemctl`, `loginctl`, etc.
|
||||
- **Tradeoffs**: Hardcoded paths reduce portability to non-Arch distros where binaries may live elsewhere (e.g. `/sbin/`). Acceptable because Moonarch targets Arch Linux exclusively.
|
||||
- **How**: All five power action wrappers now use `/usr/bin/` prefixed paths.
|
||||
|
||||
## 2026-03-28 – Implement power action timeout via try_wait polling
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: `POWER_TIMEOUT` and `PowerError::Timeout` were declared but never wired up. A hanging `systemctl hibernate` (e.g. blocked NFS mount) would freeze the power menu indefinitely.
|
||||
- **Tradeoffs**: Polling with `try_wait()` + 100ms sleep is slightly less efficient than a dedicated timeout crate, but avoids adding a dependency for a single use case.
|
||||
- **How**: `run_command` now polls `child.try_wait()` against a 30s deadline, kills the child on timeout.
|
||||
|
||||
## 2026-03-28 – Centralize GRESOURCE_PREFIX
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: The string `/dev/moonarch/moonset` was duplicated in `config.rs`, `users.rs`, and as literal strings in `panel.rs` and `main.rs`. Changing the application ID would require edits in 4+ locations.
|
||||
- **Tradeoffs**: Modules now depend on `crate::GRESOURCE_PREFIX` — tighter coupling to main.rs, but acceptable for an internal constant.
|
||||
- **How**: Single `pub(crate) const GRESOURCE_PREFIX` in `main.rs`, referenced everywhere else.
|
||||
|
||||
## 2026-03-28 – Remove journal.md
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: One-time development notes from the Rust rewrite, never updated after initial session. Overlapped with memory system and git history.
|
||||
- **Tradeoffs**: Historical context lost from the file, but the information is preserved in git history and the memory system.
|
||||
- **How**: Deleted. Useful technical learnings migrated to persistent memory.
|
||||
|
||||
## 2026-03-27 – OVERLAY layer instead of TOP
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: Waybar occupies the TOP layer. The power menu must appear above it.
|
||||
- **Tradeoffs**: OVERLAY is the highest layer — nothing can render above moonset while it's open. This is intentional for a session power menu.
|
||||
- **How**: `setup_layer_shell` uses `gtk4_layer_shell::Layer::Overlay` for the panel window.
|
||||
|
||||
## 2026-03-27 – Lock without confirmation
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: Lock is immediately reversible (just unlock). All other actions (logout, hibernate, reboot, shutdown) are destructive or disruptive.
|
||||
- **Tradeoffs**: One less click for the most common action. Risk of accidental lock is negligible since unlocking is trivial.
|
||||
- **How**: `ActionDef.needs_confirm = false` for lock; all others require inline confirmation.
|
||||
|
||||
## 2026-03-27 – Niri-specific logout via `niri msg action quit`
|
||||
|
||||
- **Who**: Hekate, Dom
|
||||
- **Why**: Moonarch is built exclusively for the Niri compositor. Generic Wayland logout mechanisms don't exist — each compositor has its own.
|
||||
- **Tradeoffs**: Hard dependency on Niri. If the compositor changes, `power::logout()` must be updated.
|
||||
- **How**: `Command::new("/usr/bin/niri").args(["msg", "action", "quit"])`.
|
||||
@@ -1,19 +1,19 @@
|
||||
# Moonset
|
||||
|
||||
Wayland Session Power Menu für das Moonarch-Ökosystem.
|
||||
Wayland Session Power Menu for the Moonarch ecosystem.
|
||||
|
||||
Per Keybind aufrufbares Fullscreen-Overlay mit 5 Aktionen:
|
||||
A fullscreen overlay triggered by keybind with 5 actions:
|
||||
**Lock** · **Logout** · **Hibernate** · **Reboot** · **Shutdown**
|
||||
|
||||
## Features
|
||||
|
||||
- Rust + gtk4-rs + gtk4-layer-shell (OVERLAY Layer — über Waybar)
|
||||
- Catppuccin Mocha Theme
|
||||
- Multi-Monitor-Support (Wallpaper auf Sekundärmonitoren)
|
||||
- Inline-Confirmation für destruktive Aktionen
|
||||
- Escape oder Hintergrund-Klick zum Schließen
|
||||
- DE/EN Lokalisierung
|
||||
- Konfigurierbare Wallpaper (TOML)
|
||||
- Rust + gtk4-rs + gtk4-layer-shell (OVERLAY layer — above Waybar)
|
||||
- Catppuccin Mocha theme
|
||||
- Multi-monitor support (wallpaper on secondary monitors)
|
||||
- Inline confirmation for destructive actions
|
||||
- Escape or background click to dismiss
|
||||
- DE/EN localization
|
||||
- Configurable wallpaper (TOML)
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -22,48 +22,48 @@ cargo build --release
|
||||
install -Dm755 target/release/moonset /usr/bin/moonset
|
||||
```
|
||||
|
||||
Oder via PKGBUILD:
|
||||
Or via PKGBUILD:
|
||||
|
||||
```bash
|
||||
cd pkg && makepkg -si
|
||||
```
|
||||
|
||||
## Verwendung
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
# Direkt starten
|
||||
# Launch directly
|
||||
moonset
|
||||
|
||||
# Per Niri-Keybind (in ~/.config/niri/config.kdl)
|
||||
# Via Niri keybind (in ~/.config/niri/config.kdl)
|
||||
# binds {
|
||||
# Mod+Escape { spawn "moonset"; }
|
||||
# }
|
||||
```
|
||||
|
||||
## Konfiguration
|
||||
## Configuration
|
||||
|
||||
Konfigurationsdatei: `~/.config/moonset/moonset.toml` oder `/etc/moonset/moonset.toml`
|
||||
Config file: `~/.config/moonset/moonset.toml` or `/etc/moonset/moonset.toml`
|
||||
|
||||
```toml
|
||||
# Pfad zum Hintergrundbild (optional)
|
||||
# Path to background image (optional)
|
||||
background_path = "/usr/share/moonarch/wallpaper.jpg"
|
||||
```
|
||||
|
||||
Wallpaper-Fallback: Konfiguration → `/usr/share/moonarch/wallpaper.jpg` → eingebettetes Package-Wallpaper
|
||||
Wallpaper fallback: config → `/usr/share/moonarch/wallpaper.jpg` → bundled package wallpaper
|
||||
|
||||
## Entwicklung
|
||||
## Development
|
||||
|
||||
```bash
|
||||
# Tests
|
||||
cargo test
|
||||
|
||||
# Release-Build
|
||||
# Release build
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
## Teil des Moonarch-Ökosystems
|
||||
## Part of the Moonarch ecosystem
|
||||
|
||||
- **moonarch** — Reproduzierbares Arch-Linux-Setup
|
||||
- **moongreet** — greetd Greeter für Wayland
|
||||
- **moonlock** — Wayland Lockscreen
|
||||
- **moonset** — Session Power Menu
|
||||
- **moonarch** — Reproducible Arch Linux setup
|
||||
- **moongreet** — greetd greeter for Wayland
|
||||
- **moonlock** — Wayland lockscreen
|
||||
- **moonset** — Session power menu
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
# Moonset — Wayland Session Power Menu
|
||||
# Konfigurationsdatei: ~/.config/moonset/moonset.toml oder /etc/moonset/moonset.toml
|
||||
# Config file: ~/.config/moonset/moonset.toml or /etc/moonset/moonset.toml
|
||||
|
||||
# Pfad zum Hintergrundbild (optional)
|
||||
# Fallback-Reihenfolge: config → /usr/share/moonarch/wallpaper.jpg → Package-Wallpaper
|
||||
# Path to background image (optional)
|
||||
# Fallback order: config → /usr/share/moonarch/wallpaper.jpg → bundled package wallpaper
|
||||
# background_path = "/usr/share/moonarch/wallpaper.jpg"
|
||||
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
# Hekate — Journal
|
||||
|
||||
## 2026-03-27 — Rust Rewrite
|
||||
|
||||
Rewrite von Python auf Rust (gtk4-rs + gtk4-layer-shell). Motivation: ~800ms Startzeit der Python-Version durch Interpreter-Overhead.
|
||||
|
||||
Alle Module 1:1 portiert:
|
||||
- `power.rs` — Command::new statt subprocess.run, PowerError enum statt Exceptions
|
||||
- `i18n.rs` — Static Strings statt Dataclass, parse_lang_prefix() separat testbar (kein env::set_var nötig)
|
||||
- `config.rs` — serde::Deserialize für TOML, GResource-Pfad als letzter Fallback
|
||||
- `users.rs` — nix-crate für getuid/getpwuid, GResource-Pfad für default-avatar
|
||||
- `panel.rs` — Freie Funktionen statt Klassen, Rc<RefCell> für Confirm-State, glib::spawn_future_local + gio::spawn_blocking für async Power-Actions
|
||||
- `main.rs` — GResource-Registration, LayerShell trait statt Gtk4LayerShell-Modul
|
||||
|
||||
45 Unit-Tests grün. Release-Binary: 3.1 MB.
|
||||
|
||||
Gelernt:
|
||||
- gtk4-rs 0.11 braucht Rust ≥1.92 (system hatte 1.91 → rustup update)
|
||||
- `ContentFit` und `Widget::color()` brauchen Feature-Flags (`v4_8`, `v4_10`)
|
||||
- GTK-Objekte (WeakRef) sind nicht Send → glib::spawn_future_local statt std::thread für UI-Updates
|
||||
- `set_from_paintable` heißt jetzt `set_paintable` in gtk4-rs 0.11
|
||||
- GResource-Bundle kompiliert CSS/Wallpaper/Avatar in die Binary — kein importlib.resources mehr nötig
|
||||
|
||||
## 2026-03-27 — Initiale Python-Version
|
||||
|
||||
Erster Tag. Moonset von Null auf v0.1.0 gebracht. TDD durchgezogen — alle 54 Tests grün, bevor der erste manuelle Start passiert ist. Das Pattern aus moongreet/moonlock hat sich bewährt: power.py, i18n.py, config.py sind fast 1:1 übernommen, nur mit den 5 Aktionen erweitert.
|
||||
|
||||
Layer Shell brauchte `LD_PRELOAD` — selbes Thema wie bei moongreet. GI-Import allein reicht nicht, weil die Linker-Reihenfolge stimmen muss. Erster Start ohne LD_PRELOAD gab die bekannten Warnings, mit LD_PRELOAD lief alles sauber: Overlay auf allen Monitoren, Escape schließt, Buttons da.
|
||||
|
||||
Designentscheidung: Lock ohne Confirmation, alles andere mit Inline-Confirm. Fühlt sich richtig an — Lock ist sofort reversibel, Shutdown nicht.
|
||||
|
||||
v0.2.0 direkt hinterher. Viel gelernt:
|
||||
- `exclusive_zone = -1` ist Pflicht, sonst respektiert man Waybars Zone
|
||||
- Monitor-Detection über `is_primary()` ist unzuverlässig auf Niri — stattdessen kein `set_monitor()` und den Compositor entscheiden lassen
|
||||
- Icon-Theme-Lookup: 22px-Variante laden und per GdkPixbuf auf 64px skalieren, damit die gleichen Icons wie bei moonlock erscheinen
|
||||
- CSS Fade-In Animationen auf Layer Shell Surfaces wirken ruckelig (wenige FPS) — rausgenommen
|
||||
- `loginctl lock-session` braucht einen D-Bus-Listener der schwer aufzusetzen ist — moonlock direkt aufrufen ist einfacher und zuverlässiger
|
||||
- LD_PRELOAD über den Niri-Keybind setzen spart den Reexec und damit ~1s Startzeit
|
||||
@@ -2,7 +2,7 @@
|
||||
<gresources>
|
||||
<gresource prefix="/dev/moonarch/moonset">
|
||||
<file>style.css</file>
|
||||
<file>wallpaper.jpg</file>
|
||||
<file compressed="true">wallpaper.jpg</file>
|
||||
<file>default-avatar.svg</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ window.wallpaper {
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
/* Action button — square card */
|
||||
/* Action button — circular card */
|
||||
.action-button {
|
||||
min-width: 120px;
|
||||
min-height: 120px;
|
||||
|
||||
+31
-2
@@ -6,7 +6,6 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const MOONARCH_WALLPAPER: &str = "/usr/share/moonarch/wallpaper.jpg";
|
||||
const GRESOURCE_PREFIX: &str = "/dev/moonarch/moonset";
|
||||
|
||||
/// Default config search paths: system-wide, then user-specific.
|
||||
fn default_config_paths() -> Vec<PathBuf> {
|
||||
@@ -21,6 +20,7 @@ fn default_config_paths() -> Vec<PathBuf> {
|
||||
#[derive(Debug, Clone, Default, Deserialize)]
|
||||
pub struct Config {
|
||||
pub background_path: Option<String>,
|
||||
pub background_blur: Option<f32>,
|
||||
}
|
||||
|
||||
/// Load config from TOML files. Later paths override earlier ones.
|
||||
@@ -35,6 +35,9 @@ pub fn load_config(config_paths: Option<&[PathBuf]>) -> Config {
|
||||
if parsed.background_path.is_some() {
|
||||
merged.background_path = parsed.background_path;
|
||||
}
|
||||
if parsed.background_blur.is_some() {
|
||||
merged.background_blur = parsed.background_blur;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +68,8 @@ pub fn resolve_background_path_with(config: &Config, moonarch_wallpaper: &Path)
|
||||
}
|
||||
|
||||
// GResource fallback path (loaded from compiled resources at runtime)
|
||||
PathBuf::from(format!("{GRESOURCE_PREFIX}/wallpaper.jpg"))
|
||||
let prefix = crate::GRESOURCE_PREFIX;
|
||||
PathBuf::from(format!("{prefix}/wallpaper.jpg"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -76,6 +80,7 @@ mod tests {
|
||||
fn default_config_has_none_background() {
|
||||
let config = Config::default();
|
||||
assert!(config.background_path.is_none());
|
||||
assert!(config.background_blur.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -95,6 +100,28 @@ mod tests {
|
||||
assert_eq!(config.background_path.as_deref(), Some("/custom/wallpaper.jpg"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_config_reads_background_blur() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let conf = dir.path().join("moonset.toml");
|
||||
fs::write(&conf, "background_blur = 20.0\n").unwrap();
|
||||
let paths = vec![conf];
|
||||
let config = load_config(Some(&paths));
|
||||
assert_eq!(config.background_blur, Some(20.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_config_blur_override() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let conf1 = dir.path().join("first.toml");
|
||||
let conf2 = dir.path().join("second.toml");
|
||||
fs::write(&conf1, "background_blur = 10.0\n").unwrap();
|
||||
fs::write(&conf2, "background_blur = 25.0\n").unwrap();
|
||||
let paths = vec![conf1, conf2];
|
||||
let config = load_config(Some(&paths));
|
||||
assert_eq!(config.background_blur, Some(25.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_config_later_paths_override_earlier() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
@@ -124,6 +151,7 @@ mod tests {
|
||||
fs::write(&wallpaper, "fake").unwrap();
|
||||
let config = Config {
|
||||
background_path: Some(wallpaper.to_str().unwrap().to_string()),
|
||||
..Config::default()
|
||||
};
|
||||
assert_eq!(
|
||||
resolve_background_path_with(&config, Path::new("/nonexistent")),
|
||||
@@ -135,6 +163,7 @@ mod tests {
|
||||
fn resolve_ignores_config_path_when_file_missing() {
|
||||
let config = Config {
|
||||
background_path: Some("/nonexistent/wallpaper.jpg".to_string()),
|
||||
..Config::default()
|
||||
};
|
||||
let result = resolve_background_path_with(&config, Path::new("/nonexistent"));
|
||||
// Falls through to gresource fallback
|
||||
|
||||
+7
-4
@@ -12,9 +12,11 @@ use gtk4::prelude::*;
|
||||
use gtk4::{self as gtk, gio};
|
||||
use gtk4_layer_shell::LayerShell;
|
||||
|
||||
pub(crate) const GRESOURCE_PREFIX: &str = "/dev/moonarch/moonset";
|
||||
|
||||
fn load_css(display: &gdk::Display) {
|
||||
let css_provider = gtk::CssProvider::new();
|
||||
css_provider.load_from_resource("/dev/moonarch/moonset/style.css");
|
||||
css_provider.load_from_resource(&format!("{GRESOURCE_PREFIX}/style.css"));
|
||||
gtk::style_context_add_provider_for_display(
|
||||
display,
|
||||
&css_provider,
|
||||
@@ -51,12 +53,13 @@ fn activate(app: >k::Application) {
|
||||
|
||||
load_css(&display);
|
||||
|
||||
// Resolve wallpaper once, share across all windows
|
||||
// Resolve wallpaper once, decode texture once, share across all windows
|
||||
let config = config::load_config(None);
|
||||
let bg_path = config::resolve_background_path(&config);
|
||||
let texture = panel::load_background_texture(&bg_path, config.background_blur);
|
||||
|
||||
// Panel on focused output (no set_monitor → compositor picks focused)
|
||||
let panel = panel::create_panel_window(&bg_path, app);
|
||||
let panel = panel::create_panel_window(&texture, app);
|
||||
setup_layer_shell(&panel, true, gtk4_layer_shell::Layer::Overlay);
|
||||
panel.present();
|
||||
|
||||
@@ -64,7 +67,7 @@ fn activate(app: >k::Application) {
|
||||
let monitors = display.monitors();
|
||||
for i in 0..monitors.n_items() {
|
||||
if let Some(monitor) = monitors.item(i).and_then(|obj| obj.downcast::<gdk::Monitor>().ok()) {
|
||||
let wallpaper = panel::create_wallpaper_window(&bg_path, app);
|
||||
let wallpaper = panel::create_wallpaper_window(&texture, app);
|
||||
setup_layer_shell(&wallpaper, false, gtk4_layer_shell::Layer::Top);
|
||||
wallpaper.set_monitor(Some(&monitor));
|
||||
wallpaper.present();
|
||||
|
||||
+89
-56
@@ -6,6 +6,7 @@ use gdk_pixbuf::Pixbuf;
|
||||
use glib::clone;
|
||||
use gtk4::prelude::*;
|
||||
use gtk4::{self as gtk, gio};
|
||||
use image::imageops;
|
||||
use std::cell::RefCell;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
@@ -79,14 +80,58 @@ pub fn action_definitions() -> Vec<ActionDef> {
|
||||
]
|
||||
}
|
||||
|
||||
/// Load the wallpaper as a texture once, for sharing across all windows.
|
||||
/// When `blur_radius` is `Some(sigma)` with sigma > 0, a Gaussian blur is applied.
|
||||
pub fn load_background_texture(bg_path: &Path, blur_radius: Option<f32>) -> gdk::Texture {
|
||||
let fallback = format!("{}/wallpaper.jpg", crate::GRESOURCE_PREFIX);
|
||||
|
||||
let texture = if bg_path.starts_with(crate::GRESOURCE_PREFIX) {
|
||||
let resource_path = bg_path.to_str().unwrap_or(&fallback);
|
||||
gdk::Texture::from_resource(resource_path)
|
||||
} else {
|
||||
let file = gio::File::for_path(bg_path);
|
||||
gdk::Texture::from_file(&file).unwrap_or_else(|_| {
|
||||
gdk::Texture::from_resource(&fallback)
|
||||
})
|
||||
};
|
||||
|
||||
match blur_radius {
|
||||
Some(sigma) if sigma > 0.0 => apply_blur(&texture, sigma),
|
||||
_ => texture,
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply Gaussian blur to a texture and return a blurred texture.
|
||||
fn apply_blur(texture: &gdk::Texture, sigma: f32) -> gdk::Texture {
|
||||
let width = texture.width() as u32;
|
||||
let height = texture.height() as u32;
|
||||
let stride = width as usize * 4;
|
||||
let mut pixel_data = vec![0u8; stride * height as usize];
|
||||
texture.download(&mut pixel_data, stride);
|
||||
|
||||
let img = image::RgbaImage::from_raw(width, height, pixel_data)
|
||||
.expect("pixel buffer size matches texture dimensions");
|
||||
let blurred = imageops::blur(&image::DynamicImage::ImageRgba8(img), sigma);
|
||||
|
||||
let bytes = glib::Bytes::from(blurred.as_raw());
|
||||
let mem_texture = gdk::MemoryTexture::new(
|
||||
width as i32,
|
||||
height as i32,
|
||||
gdk::MemoryFormat::B8g8r8a8Premultiplied,
|
||||
&bytes,
|
||||
stride,
|
||||
);
|
||||
mem_texture.upcast()
|
||||
}
|
||||
|
||||
/// Create a wallpaper-only window for secondary monitors.
|
||||
pub fn create_wallpaper_window(bg_path: &Path, app: >k::Application) -> gtk::ApplicationWindow {
|
||||
pub fn create_wallpaper_window(texture: &gdk::Texture, app: >k::Application) -> gtk::ApplicationWindow {
|
||||
let window = gtk::ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.build();
|
||||
window.add_css_class("wallpaper");
|
||||
|
||||
let background = create_background_picture(bg_path);
|
||||
let background = create_background_picture(texture);
|
||||
window.set_child(Some(&background));
|
||||
|
||||
// Fade-in on map
|
||||
@@ -104,7 +149,7 @@ pub fn create_wallpaper_window(bg_path: &Path, app: >k::Application) -> gtk::A
|
||||
}
|
||||
|
||||
/// Create the main panel window with action buttons and confirm flow.
|
||||
pub fn create_panel_window(bg_path: &Path, app: >k::Application) -> gtk::ApplicationWindow {
|
||||
pub fn create_panel_window(texture: &gdk::Texture, app: >k::Application) -> gtk::ApplicationWindow {
|
||||
let window = gtk::ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.build();
|
||||
@@ -115,7 +160,7 @@ pub fn create_panel_window(bg_path: &Path, app: >k::Application) -> gtk::Appli
|
||||
username: "user".to_string(),
|
||||
display_name: "User".to_string(),
|
||||
home: dirs::home_dir().unwrap_or_default(),
|
||||
uid: 0,
|
||||
uid: u32::MAX,
|
||||
});
|
||||
|
||||
// State for confirm box
|
||||
@@ -126,7 +171,7 @@ pub fn create_panel_window(bg_path: &Path, app: >k::Application) -> gtk::Appli
|
||||
window.set_child(Some(&overlay));
|
||||
|
||||
// Background wallpaper
|
||||
let background = create_background_picture(bg_path);
|
||||
let background = create_background_picture(texture);
|
||||
overlay.set_child(Some(&background));
|
||||
|
||||
// Click on background dismisses the menu
|
||||
@@ -157,13 +202,8 @@ pub fn create_panel_window(bg_path: &Path, app: >k::Application) -> gtk::Appli
|
||||
avatar_frame.append(&avatar_image);
|
||||
content_box.append(&avatar_frame);
|
||||
|
||||
// Load avatar
|
||||
let avatar_path = users::get_avatar_path(&user.home, Some(&user.username));
|
||||
if let Some(path) = avatar_path {
|
||||
set_avatar_from_file(&avatar_image, &path);
|
||||
} else {
|
||||
set_default_avatar(&avatar_image, &window);
|
||||
}
|
||||
// Load avatar (file-based avatars load asynchronously)
|
||||
load_avatar_async(&avatar_image, &window, &user);
|
||||
|
||||
// Username label
|
||||
let username_label = gtk::Label::new(Some(&user.display_name));
|
||||
@@ -226,24 +266,18 @@ pub fn create_panel_window(bg_path: &Path, app: >k::Application) -> gtk::Appli
|
||||
let bb = button_box_clone.clone();
|
||||
glib::idle_add_local_once(move || {
|
||||
w.add_css_class("visible");
|
||||
glib::idle_add_local_once(move || {
|
||||
if let Some(first) = bb.first_child() {
|
||||
first.grab_focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
window
|
||||
}
|
||||
|
||||
/// Create a Picture widget for the wallpaper background.
|
||||
fn create_background_picture(bg_path: &Path) -> gtk::Picture {
|
||||
let background = if bg_path.starts_with("/dev/moonarch/moonset") {
|
||||
gtk::Picture::for_resource(bg_path.to_str().unwrap_or(""))
|
||||
} else {
|
||||
gtk::Picture::for_filename(bg_path.to_str().unwrap_or(""))
|
||||
};
|
||||
/// Create a Picture widget for the wallpaper background from a shared texture.
|
||||
fn create_background_picture(texture: &gdk::Texture) -> gtk::Picture {
|
||||
let background = gtk::Picture::for_paintable(texture);
|
||||
background.set_content_fit(gtk::ContentFit::Cover);
|
||||
background.set_hexpand(true);
|
||||
background.set_vexpand(true);
|
||||
@@ -302,34 +336,9 @@ fn create_action_button(
|
||||
button
|
||||
}
|
||||
|
||||
/// Load a symbolic icon at 22px and scale to 64px via GdkPixbuf.
|
||||
/// Load a symbolic icon using native GTK4 rendering at the target size.
|
||||
fn load_scaled_icon(icon_name: &str) -> gtk::Image {
|
||||
let display = gdk::Display::default().unwrap();
|
||||
let theme = gtk::IconTheme::for_display(&display);
|
||||
let icon_paintable = theme.lookup_icon(
|
||||
icon_name,
|
||||
&[],
|
||||
22,
|
||||
1,
|
||||
gtk::TextDirection::None,
|
||||
gtk::IconLookupFlags::FORCE_SYMBOLIC,
|
||||
);
|
||||
|
||||
let icon = gtk::Image::new();
|
||||
if let Some(file) = icon_paintable.file() {
|
||||
if let Some(path) = file.path() {
|
||||
if let Ok(pixbuf) =
|
||||
Pixbuf::from_file_at_scale(path.to_str().unwrap_or(""), 64, 64, true)
|
||||
{
|
||||
let texture = gdk::Texture::for_pixbuf(&pixbuf);
|
||||
icon.set_paintable(Some(&texture));
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: use icon name directly
|
||||
icon.set_icon_name(Some(icon_name));
|
||||
let icon = gtk::Image::from_icon_name(icon_name);
|
||||
icon.set_pixel_size(64);
|
||||
icon
|
||||
}
|
||||
@@ -479,15 +488,39 @@ fn execute_action(
|
||||
));
|
||||
}
|
||||
|
||||
/// Load an image file and set it as the avatar.
|
||||
fn set_avatar_from_file(image: >k::Image, path: &Path) {
|
||||
match Pixbuf::from_file_at_scale(path.to_str().unwrap_or(""), AVATAR_SIZE, AVATAR_SIZE, true) {
|
||||
Ok(pixbuf) => {
|
||||
let texture = gdk::Texture::for_pixbuf(&pixbuf);
|
||||
image.set_paintable(Some(&texture));
|
||||
/// Load the avatar asynchronously. File-based avatars are decoded off the UI thread.
|
||||
fn load_avatar_async(image: >k::Image, window: >k::ApplicationWindow, user: &users::User) {
|
||||
let avatar_path = users::get_avatar_path(&user.home, Some(&user.username));
|
||||
|
||||
match avatar_path {
|
||||
Some(path) => {
|
||||
// File-based avatar: load and scale in background thread
|
||||
glib::spawn_future_local(clone!(
|
||||
#[weak]
|
||||
image,
|
||||
async move {
|
||||
let result = gio::spawn_blocking(move || {
|
||||
Pixbuf::from_file_at_scale(
|
||||
path.to_str().unwrap_or(""),
|
||||
AVATAR_SIZE,
|
||||
AVATAR_SIZE,
|
||||
true,
|
||||
)
|
||||
.ok()
|
||||
.map(|pb| gdk::Texture::for_pixbuf(&pb))
|
||||
})
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(Some(texture)) => image.set_paintable(Some(&texture)),
|
||||
_ => image.set_icon_name(Some("avatar-default-symbolic")),
|
||||
}
|
||||
Err(_) => {
|
||||
image.set_icon_name(Some("avatar-default-symbolic"));
|
||||
}
|
||||
));
|
||||
}
|
||||
None => {
|
||||
// Default SVG avatar: needs widget color, keep synchronous
|
||||
set_default_avatar(image, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+39
-22
@@ -2,16 +2,15 @@
|
||||
// ABOUTME: Wrappers around system commands for the session power menu.
|
||||
|
||||
use std::fmt;
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
use std::io::Read;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
#[allow(dead_code)]
|
||||
const POWER_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PowerError {
|
||||
CommandFailed { action: &'static str, message: String },
|
||||
#[allow(dead_code)]
|
||||
Timeout { action: &'static str },
|
||||
}
|
||||
|
||||
@@ -32,55 +31,73 @@ impl std::error::Error for PowerError {}
|
||||
|
||||
/// Run a command with timeout and return a PowerError on failure.
|
||||
fn run_command(action: &'static str, program: &str, args: &[&str]) -> Result<(), PowerError> {
|
||||
let child = Command::new(program)
|
||||
let mut child = Command::new(program)
|
||||
.args(args)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.map_err(|e| PowerError::CommandFailed {
|
||||
action,
|
||||
message: e.to_string(),
|
||||
})?;
|
||||
|
||||
let output = child
|
||||
.wait_with_output()
|
||||
.map_err(|e| PowerError::CommandFailed {
|
||||
action,
|
||||
message: e.to_string(),
|
||||
})?;
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
let deadline = Instant::now() + POWER_TIMEOUT;
|
||||
loop {
|
||||
match child.try_wait() {
|
||||
Ok(Some(status)) => {
|
||||
if !status.success() {
|
||||
let mut stderr_buf = String::new();
|
||||
if let Some(mut stderr) = child.stderr.take() {
|
||||
let _ = stderr.read_to_string(&mut stderr_buf);
|
||||
}
|
||||
return Err(PowerError::CommandFailed {
|
||||
action,
|
||||
message: format!("exit code {}: {}", output.status, stderr.trim()),
|
||||
message: format!("exit code {}: {}", status, stderr_buf.trim()),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
Ok(None) => {
|
||||
if Instant::now() >= deadline {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
return Err(PowerError::Timeout { action });
|
||||
}
|
||||
std::thread::sleep(Duration::from_millis(100));
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(PowerError::CommandFailed {
|
||||
action,
|
||||
message: e.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lock the current session by launching moonlock.
|
||||
pub fn lock() -> Result<(), PowerError> {
|
||||
run_command("lock", "moonlock", &[])
|
||||
run_command("lock", "/usr/bin/moonlock", &[])
|
||||
}
|
||||
|
||||
/// Quit the Niri compositor (logout).
|
||||
pub fn logout() -> Result<(), PowerError> {
|
||||
run_command("logout", "niri", &["msg", "action", "quit"])
|
||||
run_command("logout", "/usr/bin/niri", &["msg", "action", "quit"])
|
||||
}
|
||||
|
||||
/// Hibernate the system via systemctl.
|
||||
pub fn hibernate() -> Result<(), PowerError> {
|
||||
run_command("hibernate", "systemctl", &["hibernate"])
|
||||
run_command("hibernate", "/usr/bin/systemctl", &["hibernate"])
|
||||
}
|
||||
|
||||
/// Reboot the system via loginctl.
|
||||
pub fn reboot() -> Result<(), PowerError> {
|
||||
run_command("reboot", "loginctl", &["reboot"])
|
||||
run_command("reboot", "/usr/bin/loginctl", &["reboot"])
|
||||
}
|
||||
|
||||
/// Shut down the system via loginctl.
|
||||
pub fn shutdown() -> Result<(), PowerError> {
|
||||
run_command("shutdown", "loginctl", &["poweroff"])
|
||||
run_command("shutdown", "/usr/bin/loginctl", &["poweroff"])
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
+2
-2
@@ -5,7 +5,6 @@ use nix::unistd::{getuid, User as NixUser};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const DEFAULT_ACCOUNTSSERVICE_DIR: &str = "/var/lib/AccountsService/icons";
|
||||
const GRESOURCE_PREFIX: &str = "/dev/moonarch/moonset";
|
||||
|
||||
/// Represents the current user for the power menu.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -74,7 +73,8 @@ pub fn get_avatar_path_with(
|
||||
|
||||
/// Return the GResource path to the default avatar SVG.
|
||||
pub fn get_default_avatar_path() -> String {
|
||||
format!("{GRESOURCE_PREFIX}/default-avatar.svg")
|
||||
let prefix = crate::GRESOURCE_PREFIX;
|
||||
format!("{prefix}/default-avatar.svg")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user