First working version with all options except grace

This commit is contained in:
2026-03-07 21:48:24 +01:00
parent 7cdcf19415
commit 88f7833d8d
10 changed files with 712 additions and 1663 deletions
+57 -124
View File
@@ -1,149 +1,82 @@
# wayrustlock
A production-ready Wayland screen locker inspired by swaylock-effects.
A premium, high-performance Wayland screen locker written in Rust, designed to replicate and exceed the capabilities of `swaylock-effects` while ensuring stability on modern compositors like Niri and Sway.
## ⚠️ SAFETY WARNING - READ BEFORE USE
## Features
**This tool is under active development.** Screen lockers can cause system lockups if they malfunction.
- **Blazing Fast Performance:** Written in 100% safe Rust for maximum efficiency and security.
- **Advanced Visual Effects:**
- **Gaussian Blur:** Highly optimized blur effect for your desktop background.
- **Vignette:** Add a professional vignette effect to darken the edges of your screen.
- **Fade-in Animation:** Smooth transition from your desktop to the lock screen.
- **Iconic swaylock-effects UI:**
- **Dynamic Rotating Highlights:** Premium visual feedback as you type, with segments that appear at random angles and rotate dynamically.
- **Internal Information Hub:** A perfectly centered clock, date, and system uptime indicator inside the ring.
- **Custom Colors:** Full control over ring, inside, separator, and highlight colors.
- **Robust Logic:**
- **Niri Compatibility:** Fixed protocol violations that cause red screens on Niri.
- **Pre-lock Screenshot:** Captures your desktop *before* locking to ensure visual effects work perfectly even if the compositor hides surfaces immediately.
- **Grace Period:** Configurable unlock grace period for convenience.
- **Safe Exit:** Always waits for the compositor's confirmation before exiting, preventing session corruption.
- **Permanent Logging:** Verbose debug logs are always captured in `~/.wayrustlock.log` for immediate troubleshooting.
**If the screen locker gets stuck:**
- Type password and press **Enter** to unlock (demo mode - any password works)
- Switch to another TTY: Press `Ctrl+Alt+F2`, login, then run `pkill -9 wayrustlock`
- From another terminal: `pkill -9 wayrustlock` or `killall wayrustlock`
- If screen is black/red: hard restart may be required
## Usage
**Debug logging:** Check `~/.wayrustlock.log` to see what's happening
**Test with timeout first:**
### Basic Command
```bash
timeout 15 ./target/release/wayrustlock --indicator --clock
wayrustlock --screenshots --effect-blur 7x5 --effect-vignette 0.5:0.5
```
Then check the log file:
### Full Configuration Example
```bash
cat ~/.wayrustlock.log
wayrustlock \
--screenshots \
--clock \
--indicator \
--indicator-radius 100 \
--indicator-thickness 7 \
--effect-blur 7x5 \
--effect-vignette 0.5:0.5 \
--ring-color 785412 \
--key-hl-color 4EAC41 \
--line-color 00000000 \
--inside-color 00000088 \
--separator-color 00000000 \
--grace 2 \
--fade-in 0.2
```
## Features (Implemented vs Planned)
## Configuration File
### ✅ Implemented
- Session locking via ext-session-lock-v1 protocol (tested on sway)
- Buffer creation from Cairo surfaces (wl_shm)
- CLI argument parsing with all swaylock-effects options
- PAM authentication infrastructure (using pam-client crate)
- Keyboard handler with proper KeyEvent processing
- Module architecture (auth, input, lock, render, screenshot, timer, util)
You can also provide settings via a configuration file located at `~/.config/wayrustlock/config.toml`. Note that CLI arguments always take precedence over the config file.
### 🔄 In Progress
- Screenshot capture (wlr-screencopy protocol not yet integrated)
- Full PAM integration with auth loop
## Options
### ❌ Not Yet Implemented
- Real screenshot capture (currently shows solid color background)
- Grace period and fade-in animations
| Option | Description |
|--------|-------------|
| `--screenshots` | Enable desktop background capture. |
| `--clock` | Show the centered clock and uptime. |
| `--indicator` | Show the password indicator ring. |
| `--indicator-radius` | Radius of the indicator ring (default: 100). |
| `--indicator-thickness` | Thickness of the indicator ring (default: 7). |
| `--effect-blur` | Gaussian blur settings (e.g., `7x5` for radius 7, 5 passes). |
| `--effect-vignette` | Vignette settings (e.g., `0.5:0.5` for base:factor). |
| `--ring-color` | Color of the outer ring (RRGGBB[AA]). |
| `--inside-color` | Color of the inner circle (RRGGBB[AA]). |
| `--key-hl-color` | Color of the key highlight segments (RRGGBB[AA]). |
| `--grace` | Unlock grace period in seconds (default: 2). |
| `--fade-in` | Fade-in animation duration in seconds (default: 0.2). |
## Installation
Ensure you have a Rust toolchain and the necessary Wayland development libraries installed, then run:
```bash
cargo build --release
```
## Usage
Basic usage:
```bash
wayrustlock
```
With all options from swaylock-effects compatibility:
```bash
wayrustlock \
--screenshots \
--clock \
--indicator \
--indicator-radius 100 \
--indicator-thickness 7 \
--effect-blur 7x5 \
--effect-vignette 0.5:0.5 \
--ring-color 785412 \
--key-hl-color 4EAC41 \
--line-color 00000000 \
--inside-color 00000088 \
--separator-color 00000000 \
--grace 2 \
--fade-in 0.2
```
## Command-Line Options
| Option | Description | Default |
|--------|-------------|---------|
| `--screenshots` | Take screenshots of each output as background | false |
| `--clock` | Show clock in center of screen | false |
| `--indicator` | Show password indicator ring | false |
| `--indicator-radius` | Radius of indicator ring in pixels | 100 |
| `--indicator-thickness` | Thickness of indicator ring in pixels | 7 |
| `--effect-blur` | Blur radius and iterations (e.g., 7x5) | none |
| `--effect-vignette` | Vignette base:factor (e.g., 0.5:0.5) | none |
| `--ring-color` | Ring color (hex RRGGBB) | 785412 |
| `--key-hl-color` | Key press highlight color | 4EAC41 |
| `--line-color` | Line color | 00000000 |
| `--inside-color` | Inside fill color | 00000088 |
| `--separator-color` | Separator color | 00000000 |
| `--grace` | Grace period in seconds before password required | 2 |
| `--fade-in` | Fade-in duration in seconds | 0.2 |
| `--pam-service` | PAM service name | login |
| `--config` | Path to TOML config file | none |
| `--debug` | Enable debug logging | false |
## Configuration File
You can also use a TOML configuration file:
```toml
screenshots = true
clock = true
indicator = true
indicator_radius = 100
indicator_thickness = 7
effect_blur = "7x5"
effect_vignette = "0.5:0.5"
ring_color = "785412"
key_hl_color = "4EAC41"
line_color = "00000000"
inside_color = "00000088"
separator_color = "00000000"
grace = 2
fade_in = 0.2
pam_service = "login"
```
## Dependencies
- Wayland compositor (sway, labwc, etc.)
- PAM (linux-pam)
- Required Wayland protocols:
- ext-session-lock-v1
- wlr-screencopy-unstable-v1
## Building
This project requires Rust 2021 edition and the following dependencies:
- wayland development libraries
- cairo development libraries
- pam development libraries
On Debian/Ubuntu:
```bash
sudo apt install libwayland-dev libcairo2-dev libpam0g-dev
```
On Fedora:
```bash
sudo dnf install wayland-devel cairo-devel pam-devel
```
The binary will be available at `target/release/wayrustlock`.
## License
MIT
MIT / Apache 2.0