Compare commits
27 Commits
v1.0
...
c2c093595a
| Author | SHA1 | Date | |
|---|---|---|---|
|
c2c093595a
|
|||
| db3e797e36 | |||
| c4ae3e9651 | |||
|
4372c7f7c0
|
|||
| e9550f71f5 | |||
| ff20423a84 | |||
|
6c2e3fca5a
|
|||
|
c6ec65c851
|
|||
|
7a0adc4d82
|
|||
|
016038aca0
|
|||
| 05cf0c1d7e | |||
|
dab90e081e
|
|||
| 07d1921bd3 | |||
|
5e0fe39304
|
|||
|
05593e0959
|
|||
|
37fb09c7c6
|
|||
|
92dc3a983e
|
|||
|
50a445937f
|
|||
|
61daf52906
|
|||
|
49438ecd62
|
|||
|
fbd7aee9d2
|
|||
| 3a9be7c696 | |||
| f8c4381a11 | |||
|
caa448680e
|
|||
|
c352a7cb16
|
|||
| 1cc69bcc61 | |||
| 9171f0771a |
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
name: Bug Report
|
||||||
|
about: Report a crash, visual glitch, or unexpected behavior
|
||||||
|
labels: bug
|
||||||
|
---
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
A clear and concise description of the bug.
|
||||||
|
|
||||||
|
## Steps to Reproduce
|
||||||
|
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
|
||||||
|
## Expected Behavior
|
||||||
|
|
||||||
|
What did you expect to happen?
|
||||||
|
|
||||||
|
## Actual Behavior
|
||||||
|
|
||||||
|
What actually happened? Include any error messages, visual glitches, or crashes.
|
||||||
|
|
||||||
|
## Screenshots / Screen Recordings
|
||||||
|
|
||||||
|
If applicable, add screenshots or recordings to help explain the problem.
|
||||||
|
|
||||||
|
## Environment
|
||||||
|
|
||||||
|
- **Compositor:** (e.g., Hyprland, Sway, River, Niri)
|
||||||
|
- **Compositor version:** (e.g., Hyprland 0.47.0)
|
||||||
|
- **rustlock version:** (`rustlock --version`)
|
||||||
|
- **Display configuration:** (single monitor, multi-monitor, mixed DPI, etc.)
|
||||||
|
- **OS/Distro:** (e.g., Arch Linux, Ubuntu 24.04, Fedora 41)
|
||||||
|
|
||||||
|
## Config / CLI flags
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# The exact command you used to start rustlock
|
||||||
|
# e.g., rustlock --debug --effect-blur 5x2 --theme modern
|
||||||
|
```
|
||||||
|
|
||||||
|
## Logs
|
||||||
|
|
||||||
|
```
|
||||||
|
# Paste any relevant logs here
|
||||||
|
# Run with --debug --log-file to capture verbose logs
|
||||||
|
```
|
||||||
|
|
||||||
|
## Confirmations
|
||||||
|
|
||||||
|
- [ ] I searched existing issues and this is not a duplicate
|
||||||
|
- [ ] I am running the latest version of rustlock
|
||||||
|
- [ ] I have included relevant logs and environment details
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
name: Feature Request
|
||||||
|
about: Suggest an idea for rustlock
|
||||||
|
labels: enhancement
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Pull Request Template
|
||||||
|
|
||||||
|
## Description
|
||||||
|
Please include a summary of the change and which issue is fixed (if relevant).
|
||||||
|
|
||||||
|
## Type of Change
|
||||||
|
- [ ] Bug fix (non-breaking change that fixes an issue)
|
||||||
|
- [ ] New feature (non-breaking change that adds functionality)
|
||||||
|
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
|
||||||
|
- [ ] Documentation update
|
||||||
|
- [ ] Refactoring
|
||||||
|
|
||||||
|
## How Has This Been Tested?
|
||||||
|
Please describe the tests that you ran to verify your changes.
|
||||||
|
|
||||||
|
## Checklist
|
||||||
|
- [ ] My code follows the style guidelines of this project
|
||||||
|
- [ ] I have performed a self-review of my own code
|
||||||
|
- [ ] I have commented my code, particularly in hard-to-understand areas
|
||||||
|
- [ ] I have made corresponding changes to the documentation
|
||||||
|
- [ ] My changes generate no new warnings
|
||||||
|
- [ ] I have added tests that prove my fix is effective or that my feature works
|
||||||
|
- [ ] New and existing unit tests pass locally with my changes
|
||||||
@@ -4,7 +4,7 @@ description: Install system dependencies required for building rustlock
|
|||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- name: Install system dependencies (Ubuntu/Debian)
|
- name: Install system dependencies for Debian based distros
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "cargo"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "monday"
|
||||||
|
time: "09:00"
|
||||||
|
timezone: "UTC"
|
||||||
|
open-pull-requests-limit: 10
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
- "rust"
|
||||||
|
commit-message:
|
||||||
|
prefix: "deps"
|
||||||
|
reviewers:
|
||||||
|
- "JorySeverijnse"
|
||||||
|
versioning-strategy: "increase"
|
||||||
|
groups:
|
||||||
|
rust-dependencies:
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
|
update-types:
|
||||||
|
- "minor"
|
||||||
|
- "patch"
|
||||||
|
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
day: "monday"
|
||||||
|
time: "09:00"
|
||||||
|
timezone: "UTC"
|
||||||
|
labels:
|
||||||
|
- "dependencies"
|
||||||
|
- "github-actions"
|
||||||
|
groups:
|
||||||
|
actions-dependencies:
|
||||||
|
patterns:
|
||||||
|
- "*"
|
||||||
|
update-types:
|
||||||
|
- "minor"
|
||||||
|
- "patch"
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
documentation:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: ['README.md', '*.md', 'docs/**']
|
||||||
|
|
||||||
|
features:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: ['src/input.rs', 'src/lock.rs', 'src/config.rs', 'src/auth.rs', 'src/screenshot.rs', 'src/system.rs']
|
||||||
|
|
||||||
|
rendering:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: ['src/render/**']
|
||||||
|
|
||||||
|
ci:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: ['.github/**', '.github/workflows/**']
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: ['Cargo.toml', 'Cargo.lock']
|
||||||
|
|
||||||
|
refactoring:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: ['src/util.rs', 'src/main.rs']
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
name: Dependabot Automerge
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
if: github.actor == 'dependabot[bot]'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Fetch Dependabot metadata
|
||||||
|
id: metadata
|
||||||
|
uses: dependabot/fetch-metadata@v2
|
||||||
|
with:
|
||||||
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|
||||||
|
- name: Auto-approve minor/patch updates
|
||||||
|
if: |
|
||||||
|
steps.metadata.outputs.update-type == 'version-update:semver-minor' ||
|
||||||
|
steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
|
run: gh pr review --approve "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{ github.event.pull_request.html_url }}
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Enable auto-merge for minor/patch updates
|
||||||
|
if: |
|
||||||
|
steps.metadata.outputs.update-type == 'version-update:semver-minor' ||
|
||||||
|
steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
|
run: gh pr merge --auto --squash "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{ github.event.pull_request.html_url }}
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
name: PR Labeler
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
label:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Label PR based on changed files
|
||||||
|
uses: actions/labeler@v6
|
||||||
|
with:
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
configuration-path: .github/labeler.yml
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
name: Nightly Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main, master]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
nightly-build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set version
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
DATE=$(date -u +%Y%m%d%H%M)
|
||||||
|
SHA=$(git rev-parse --short HEAD)
|
||||||
|
VERSION=$(grep -m1 '^version =' Cargo.toml | cut -d'"' -f2)
|
||||||
|
echo "VERSION=${VERSION}-nightly.$DATE.$SHA" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create nightly release
|
||||||
|
uses: softprops/action-gh-release@v3
|
||||||
|
with:
|
||||||
|
tag_name: nightly-${{ steps.version.outputs.VERSION }}
|
||||||
|
name: Nightly Build ${{ steps.version.outputs.VERSION }}
|
||||||
|
prerelease: true
|
||||||
|
generate_release_notes: true
|
||||||
@@ -14,24 +14,30 @@ jobs:
|
|||||||
quality-checks:
|
quality-checks:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
|
|
||||||
- uses: ./.github/actions/deps
|
- uses: ./.github/actions/deps
|
||||||
|
|
||||||
- name: Install Rust with tools
|
- name: Install Rust with tools
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
components: rustfmt, clippy
|
components: rustfmt, clippy
|
||||||
|
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: cargo fmt -- --check
|
run: cargo fmt -- --check
|
||||||
|
|
||||||
- name: Run clippy
|
- name: Run clippy
|
||||||
run: cargo clippy -- -D warnings
|
run: cargo clippy --all-targets -- -D warnings
|
||||||
|
|
||||||
- name: Run unit tests
|
- name: Run unit tests (default features)
|
||||||
run: cargo test --quiet
|
run: cargo test --quiet
|
||||||
|
|
||||||
|
- name: Run unit tests (all features)
|
||||||
|
run: cargo test --all-features --quiet
|
||||||
|
|
||||||
- name: Check documentation
|
- name: Check documentation
|
||||||
run: cargo doc --no-deps --document-private-items
|
env:
|
||||||
|
RUSTDOCFLAGS: -D warnings
|
||||||
|
run: cargo doc --no-deps --document-private-items
|
||||||
|
|||||||
@@ -5,109 +5,37 @@ on:
|
|||||||
tags:
|
tags:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- variant: "default"
|
|
||||||
args: ""
|
|
||||||
distro: "ubuntu"
|
|
||||||
- variant: "no-networking"
|
|
||||||
args: "--no-default-features"
|
|
||||||
distro: "ubuntu"
|
|
||||||
- variant: "default"
|
|
||||||
args: ""
|
|
||||||
distro: "debian"
|
|
||||||
- variant: "default"
|
|
||||||
args: ""
|
|
||||||
distro: "fedora"
|
|
||||||
- variant: "default"
|
|
||||||
args: ""
|
|
||||||
distro: "arch"
|
|
||||||
container: ${{ matrix.distro == 'ubuntu' && 'ubuntu:latest' || matrix.distro == 'debian' && 'debian:stable-slim' || matrix.distro == 'fedora' && 'fedora:latest' || 'archlinux:latest' }}
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install system dependencies (Ubuntu/Debian)
|
|
||||||
if: matrix.distro == 'ubuntu' || matrix.distro == 'debian'
|
|
||||||
run: |
|
|
||||||
apt-get update
|
|
||||||
apt-get install -y \
|
|
||||||
curl \
|
|
||||||
llvm clang libclang-dev \
|
|
||||||
pkg-config \
|
|
||||||
libglib2.0-dev libcairo2-dev libpango1.0-dev libatk1.0-dev \
|
|
||||||
libgdk-pixbuf-2.0-dev libpam0g-dev libdbus-1-dev \
|
|
||||||
libwayland-dev libxkbcommon-dev
|
|
||||||
|
|
||||||
- name: Install system dependencies (Fedora)
|
|
||||||
if: matrix.distro == 'fedora'
|
|
||||||
run: |
|
|
||||||
dnf install -y \
|
|
||||||
curl \
|
|
||||||
llvm clang clang-devel \
|
|
||||||
pkgconfig \
|
|
||||||
glib2-devel cairo-devel cairo-gobject-devel pango-devel atk-devel \
|
|
||||||
gdk-pixbuf2-devel pam-devel dbus-devel \
|
|
||||||
wayland-devel libxkbcommon-devel
|
|
||||||
|
|
||||||
- name: Install system dependencies (Arch)
|
|
||||||
if: matrix.distro == 'arch'
|
|
||||||
run: |
|
|
||||||
pacman -Sy --noconfirm \
|
|
||||||
base-devel \
|
|
||||||
llvm clang pkgconf \
|
|
||||||
glib2 cairo pango atk gdk-pixbuf2 \
|
|
||||||
pam dbus \
|
|
||||||
wayland libxkbcommon
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Build ${{ matrix.variant }} (${{ matrix.distro }})
|
|
||||||
run: cargo build --release ${{ matrix.args }}
|
|
||||||
|
|
||||||
- name: Upload artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: rustlock-${{ matrix.variant }}-${{ matrix.distro }}
|
|
||||||
path: target/release/rustlock
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [release-build]
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- uses: actions/checkout@v6
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Download all artifacts
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
path: artifacts
|
|
||||||
|
|
||||||
- name: Determine tag
|
- name: Determine tag
|
||||||
id: tag
|
id: tag
|
||||||
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Create Release
|
- name: Create Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v3
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref_name }}
|
tag_name: ${{ github.ref_name }}
|
||||||
name: RustLock v${{ steps.tag.outputs.VERSION }}
|
name: RustLock v${{ steps.tag.outputs.VERSION }}
|
||||||
draft: true
|
draft: true
|
||||||
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
|
prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
|
||||||
files: |
|
generate_release_notes: true
|
||||||
artifacts/rustlock-default-ubuntu/rustlock/rustlock:rustlock-default-ubuntu
|
|
||||||
artifacts/rustlock-no-networking-ubuntu/rustlock/rustlock:rustlock-no-networking-ubuntu
|
publish-crates:
|
||||||
artifacts/rustlock-default-debian/rustlock/rustlock:rustlock-default-debian
|
runs-on: ubuntu-latest
|
||||||
artifacts/rustlock-default-fedora/rustlock/rustlock:rustlock-default-fedora
|
needs: [release]
|
||||||
artifacts/rustlock-default-arch/rustlock/rustlock:rustlock-default-arch
|
if: secrets.CARGO_REGISTRY_TOKEN != ''
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- name: Publish to crates.io
|
||||||
|
env:
|
||||||
|
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||||
|
run: cargo publish
|
||||||
|
|||||||
@@ -19,46 +19,24 @@ jobs:
|
|||||||
security-audit:
|
security-audit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: dtolnay/rust-toolchain@stable
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
- name: Install security tools
|
- name: Install security tools
|
||||||
run: |
|
uses: taiki-e/install-action@v2
|
||||||
cargo install cargo-audit
|
with:
|
||||||
cargo install cargo-deny
|
tool: cargo-audit,cargo-deny,cargo-outdated
|
||||||
|
|
||||||
- name: Run cargo audit
|
- name: Run cargo audit
|
||||||
run: cargo audit
|
run: cargo audit
|
||||||
|
|
||||||
- name: Run cargo deny
|
- name: Run cargo deny
|
||||||
run: cargo deny check
|
run: cargo deny check
|
||||||
|
|
||||||
- name: Generate Software Bill of Materials (SBOM)
|
|
||||||
run: |
|
|
||||||
cargo install cargo-cyclonedx
|
|
||||||
cargo cyclonedx --format json --output bom.json
|
|
||||||
|
|
||||||
- name: Upload SBOM
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: sbom
|
|
||||||
path: bom.json
|
|
||||||
retention-days: 90
|
|
||||||
|
|
||||||
- name: Check for outdated dependencies
|
- name: Check for outdated dependencies
|
||||||
run: |
|
run: cargo outdated --exit-code 1 || echo "Some dependencies are outdated"
|
||||||
cargo install cargo-outdated
|
|
||||||
cargo outdated --exit-code 1 || echo "Some dependencies are outdated"
|
|
||||||
|
|
||||||
- name: Security summary
|
|
||||||
run: |
|
|
||||||
echo "=== Security Scan Complete ==="
|
|
||||||
echo "✅ cargo audit - Vulnerability scanning"
|
|
||||||
echo "✅ cargo deny - Advisory and license checking"
|
|
||||||
echo "✅ SBOM generated - Software Bill of Materials"
|
|
||||||
echo "✅ Outdated dependencies checked"
|
|
||||||
echo ""
|
|
||||||
echo "Next scheduled scan: Weekly (Sunday 00:00 UTC)"
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
name: Stale Issues and PRs
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *' # Daily
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stale:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v9
|
||||||
|
with:
|
||||||
|
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days.'
|
||||||
|
stale-pr-message: 'This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days.'
|
||||||
|
close-issue-message: 'This issue has been automatically closed due to inactivity.'
|
||||||
|
close-pr-message: 'This PR has been automatically closed due to inactivity.'
|
||||||
|
days-before-stale: 30
|
||||||
|
days-before-close: 7
|
||||||
|
stale-issue-label: 'stale'
|
||||||
|
stale-pr-label: 'stale'
|
||||||
|
exempt-issue-labels: 'enhancement,security'
|
||||||
|
exempt-pr-labels: 'security,work-in-progress'
|
||||||
Generated
+608
-902
File diff suppressed because it is too large
Load Diff
+24
-25
@@ -2,6 +2,9 @@
|
|||||||
name = "rustlock"
|
name = "rustlock"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
license = "GPL-3.0-or-later"
|
||||||
|
authors = ["Jory Severijnse"]
|
||||||
|
description = "A high-performance Wayland screen locker"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
smithay-client-toolkit = { version = "0.19", default-features = false, features = ["calloop", "xkbcommon"] }
|
smithay-client-toolkit = { version = "0.19", default-features = false, features = ["calloop", "xkbcommon"] }
|
||||||
@@ -9,42 +12,38 @@ wayland-client = { version = "0.31" }
|
|||||||
wayland-protocols = { version = "0.32", features = ["client"] }
|
wayland-protocols = { version = "0.32", features = ["client"] }
|
||||||
wayland-protocols-wlr = { version = "0.3", features = ["client"] }
|
wayland-protocols-wlr = { version = "0.3", features = ["client"] }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
futures = { version = "0.3", default-features = false, features = ["std"] }
|
|
||||||
cairo-rs = { version = "0.20", default-features = false, features = ["png"] }
|
cairo-rs = { version = "0.20", default-features = false, features = ["png"] }
|
||||||
gdk-pixbuf = { version = "0.20", default-features = false, features = ["v2_40"] }
|
gdk-pixbuf = { version = "0.20", default-features = false, features = ["v2_40"] }
|
||||||
gio = { version = "0.20" }
|
|
||||||
pangocairo = { version = "0.20" }
|
pangocairo = { version = "0.20" }
|
||||||
clap = { version = "4.4", default-features = false, features = ["derive", "std", "help", "usage", "error-context"] }
|
clap = { version = "4.6", default-features = false, features = ["derive", "std", "help", "usage", "error-context"] }
|
||||||
toml = { version = "1.0", default-features = false, features = ["parse", "display", "serde"] }
|
toml = { version = "1.1", default-features = false, features = ["parse", "display", "serde"] }
|
||||||
serde = { version = "1.0", default-features = false, features = ["derive", "std"] }
|
serde = { version = "1.0", default-features = false, features = ["derive", "std"] }
|
||||||
zeroize = "1.7"
|
zeroize = "1.8"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
env_logger = { version = "0.11", default-features = false, features = ["color", "humantime"] }
|
|
||||||
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
|
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
|
||||||
whoami = "1.0"
|
whoami = "1.6"
|
||||||
zbus = { version = "3.15", default-features = false, features = ["tokio"] }
|
zbus = { version = "5.14", default-features = false, features = ["tokio"] }
|
||||||
mpris = "2.0"
|
mpris = "2.0"
|
||||||
upower_dbus = "0.3"
|
tokio = { version = "1.51", default-features = false, features = ["rt", "rt-multi-thread", "macros", "time", "sync"] }
|
||||||
tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi-thread", "macros", "time", "sync"] }
|
rand = { version = "0.10" }
|
||||||
num-traits = { version = "0.2" }
|
reqwest = { version = "0.12", default-features = false, features = ["blocking", "rustls-tls"], optional = true }
|
||||||
rand = { version = "0.8" }
|
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["blocking", "rustls-tls"], optional = true }
|
|
||||||
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
|
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
|
||||||
fastblur = "0.1"
|
fastblur = "0.1"
|
||||||
pam-client = "0.5"
|
pam-client = "0.5"
|
||||||
thiserror = "1.0"
|
calloop = "0.13"
|
||||||
bytemuck = "1.14"
|
xkbcommon = "0.7"
|
||||||
calloop = "0.13"
|
calloop-wayland-source = "0.3"
|
||||||
xkbcommon = "0.7"
|
resvg = { version = "0.42", default-features = false }
|
||||||
calloop-wayland-source = "0.3"
|
usvg = { version = "0.42", default-features = false }
|
||||||
|
tiny-skia = "0.11"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["networking"]
|
default = ["networking"]
|
||||||
networking = ["dep:reqwest", "tokio/net"]
|
networking = ["dep:reqwest", "tokio/net"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = "z" # Optimize for size
|
opt-level = "z"
|
||||||
lto = true # Enable Link Time Optimization
|
lto = true
|
||||||
codegen-units = 1 # Reduce parallel code gen to allow better size optimization
|
codegen-units = 1
|
||||||
panic = "abort" # Remove heavy stack unwinding code
|
panic = "abort"
|
||||||
strip = true # Automatically strip symbols and debug info
|
strip = true
|
||||||
|
|||||||
@@ -1,661 +1,231 @@
|
|||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 3, 19 November 2007
|
Version 3, 29 June 2007
|
||||||
|
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
Preamble
|
||||||
Preamble
|
|
||||||
|
The GNU General Public License is a free, copyleft license for software and other kinds of works.
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works, specifically designed to ensure
|
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
|
||||||
cooperation with the community in the case of network server software.
|
|
||||||
|
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
|
||||||
software for all its users.
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
The precise terms and conditions for copying, distribution and modification follow.
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
|
||||||
you this License which gives you legal permission to copy, distribute
|
TERMS AND CONDITIONS
|
||||||
and/or modify the software.
|
|
||||||
|
0. Definitions.
|
||||||
A secondary benefit of defending all users' freedom is that
|
|
||||||
improvements made in alternate versions of the program, if they
|
“This License” refers to version 3 of the GNU General Public License.
|
||||||
receive widespread use, become available for other developers to
|
|
||||||
incorporate. Many developers of free software are heartened and
|
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
|
||||||
software used on network servers, this result may fail to come about.
|
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
|
||||||
The GNU General Public License permits making a modified version and
|
|
||||||
letting the public access it on a server without ever releasing its
|
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
|
||||||
source code to the public.
|
|
||||||
|
A “covered work” means either the unmodified Program or a work based on the Program.
|
||||||
The GNU Affero General Public License is designed specifically to
|
|
||||||
ensure that, in such cases, the modified source code becomes available
|
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||||
to the community. It requires the operator of a network server to
|
|
||||||
provide the source code of the modified version running there to the
|
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||||
users of that server. Therefore, public use of a modified version, on
|
|
||||||
a publicly accessible server, gives the public access to the source
|
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||||
code of the modified version.
|
|
||||||
|
1. Source Code.
|
||||||
An older license, called the Affero General Public License and
|
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
|
||||||
this license.
|
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||||
modification follow.
|
|
||||||
|
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
The Corresponding Source for a work in source code form is that same work.
|
||||||
0. Definitions.
|
|
||||||
|
2. Basic Permissions.
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
"recipients" may be individuals or organizations.
|
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
4. Conveying Verbatim Copies.
|
||||||
earlier work or a work "based on" the earlier work.
|
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||||
on the Program.
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
To "propagate" a work means to do anything with it that, without
|
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
6. Conveying Non-Source Forms.
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||||
1. Source Code.
|
|
||||||
|
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||||
form of a work.
|
|
||||||
|
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
7. Additional Terms.
|
||||||
(kernel, window system, and so on) of the specific operating system
|
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
|
||||||
Source.
|
|
||||||
|
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
|
||||||
|
|
||||||
2. Basic Permissions.
|
8. Termination.
|
||||||
|
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
You may make, run and propagate covered works that you do not
|
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
of having them make modifications exclusively for you, or provide you
|
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
11. Patents.
|
||||||
|
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
|
||||||
makes it unnecessary.
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
|
||||||
measures.
|
|
||||||
|
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
12. No Surrender of Others' Freedom.
|
||||||
modification of the work as a means of enforcing, against the work's
|
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
13. Use with the GNU Affero General Public License.
|
||||||
|
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
You may convey verbatim copies of the Program's source code as you
|
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
15. Disclaimer of Warranty.
|
||||||
and you may offer support or warranty protection for a fee.
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
16. Limitation of Liability.
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
17. Interpretation of Sections 15 and 16.
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
END OF TERMS AND CONDITIONS
|
||||||
it, and giving a relevant date.
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
License to anyone who comes into possession of a copy. This
|
Copyright (C) <year> <name of author>
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the
|
|
||||||
Program, your modified version must prominently offer all users
|
|
||||||
interacting with it remotely through a computer network (if your version
|
|
||||||
supports such interaction) an opportunity to receive the Corresponding
|
|
||||||
Source of your version by providing access to the Corresponding Source
|
|
||||||
from a network server at no charge, through some standard or customary
|
|
||||||
means of facilitating copying of software. This Corresponding Source
|
|
||||||
shall include the Corresponding Source for any work covered by version 3
|
|
||||||
of the GNU General Public License that is incorporated pursuant to the
|
|
||||||
following paragraph.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the work with which it is combined will remain governed by version
|
|
||||||
3 of the GNU General Public License.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU Affero General Public License from time to time. Such new versions
|
|
||||||
will be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU Affero General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU Affero General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU Affero General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published
|
|
||||||
by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer
|
If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:
|
||||||
network, you should also make sure that it provides a way for users to
|
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
|
||||||
of the code. There are many ways you could offer source, and different
|
|
||||||
solutions will be better for different programs; see section 13 for the
|
|
||||||
specific requirements.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
<program> Copyright (C) <year> <name of author>
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ A high-performance Wayland screen locker written in Rust, inspired by `swaylock-
|
|||||||
- 🔐 **Password Indicator**:
|
- 🔐 **Password Indicator**:
|
||||||
- Circular ring with configurable radius and thickness
|
- Circular ring with configurable radius and thickness
|
||||||
- Dynamic key highlight segments that rotate with each keystroke
|
- Dynamic key highlight segments that rotate with each keystroke
|
||||||
|
- Full password editing with cursor navigation (arrow keys, Home/End)
|
||||||
|
- Visual cursor indicator between dots
|
||||||
- Caps lock indicator
|
- Caps lock indicator
|
||||||
- 🕐 **Information Display**:
|
- 🕐 **Information Display**:
|
||||||
- Centered clock (HH:MM format)
|
- Centered clock (HH:MM format)
|
||||||
@@ -40,8 +42,8 @@ A high-performance Wayland screen locker written in Rust, inspired by `swaylock-
|
|||||||
- PAM-based authentication
|
- PAM-based authentication
|
||||||
- Configurable grace period (any key press within N seconds unlocks without password)
|
- Configurable grace period (any key press within N seconds unlocks without password)
|
||||||
- 🎯 **Customization**:
|
- 🎯 **Customization**:
|
||||||
|
- Multiple ring shapes: circle, square, diamond, hexagon, pill
|
||||||
- Custom icons for WiFi, Bluetooth, Battery
|
- Custom icons for WiFi, Bluetooth, Battery
|
||||||
- Theme presets (dark, light, nord, dracula)
|
|
||||||
- Configuration via config file or CLI
|
- Configuration via config file or CLI
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -63,6 +65,7 @@ rustlock \
|
|||||||
--indicator \
|
--indicator \
|
||||||
--indicator-radius 100 \
|
--indicator-radius 100 \
|
||||||
--indicator-thickness 7 \
|
--indicator-thickness 7 \
|
||||||
|
--ring-shape hexagon \
|
||||||
--effect-blur 7x5 \
|
--effect-blur 7x5 \
|
||||||
--effect-vignette 0.5:0.5 \
|
--effect-vignette 0.5:0.5 \
|
||||||
--ring-color 785412 \
|
--ring-color 785412 \
|
||||||
@@ -70,6 +73,8 @@ rustlock \
|
|||||||
--line-color 00000000 \
|
--line-color 00000000 \
|
||||||
--inside-color 00000088 \
|
--inside-color 00000088 \
|
||||||
--separator-color 00000000 \
|
--separator-color 00000000 \
|
||||||
|
--show-network \
|
||||||
|
--show-battery \
|
||||||
--grace 2 \
|
--grace 2 \
|
||||||
--fade-in 0.2
|
--fade-in 0.2
|
||||||
```
|
```
|
||||||
@@ -81,54 +86,90 @@ When locked, use function keys to control the system:
|
|||||||
- **F2**: Reboot
|
- **F2**: Reboot
|
||||||
- **F3**: Power Off
|
- **F3**: Power Off
|
||||||
|
|
||||||
|
### Password Entry
|
||||||
|
|
||||||
|
Use arrow keys to move the cursor while entering your password:
|
||||||
|
- **Left/Right arrows**: Move cursor one position
|
||||||
|
- **Home**: Move to start
|
||||||
|
- **End**: Move to end
|
||||||
|
- **Delete**: Delete character at cursor
|
||||||
|
- **Ctrl+U**: Clear entire password
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ⚙️ Configuration
|
## ⚙️ Configuration
|
||||||
|
|
||||||
Options can be provided via command line or a configuration file at `~/.config/rustlock/config.toml`. CLI arguments take precedence over config file, which takes precedence over theme defaults.
|
Options can be provided via command line or a configuration file at `~/.config/rustlock/config.toml`. CLI arguments take precedence over config file values.
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Description |
|
| Option | Default | Description |
|
||||||
|--------|-------------|
|
|--------|---------|-------------|
|
||||||
| **General** | |
|
| **General** | | |
|
||||||
| `--screenshots` | Capture desktop background before locking |
|
| `--screenshots` | — | Capture desktop background before locking |
|
||||||
| `--image <PATH>` | Use custom background image instead of screenshot |
|
| `--image <PATH>` | — | Use custom background image instead of screenshot |
|
||||||
| `--clock` | Display centered clock and date |
|
| `--clock` | — | Display centered clock and date |
|
||||||
| `--indicator` | Show password entry ring (default: true) |
|
| `--indicator` | `true` | Show password entry ring |
|
||||||
| `--indicator-radius <N>` | Ring radius in pixels (default: 100) |
|
| `--hide-password` | `false` | Hide password dots (dots are shown by default) |
|
||||||
| `--indicator-thickness <N>` | Ring thickness in pixels (default: 7) |
|
| `--config <PATH>` | — | Path to config file |
|
||||||
| **Effects** | |
|
| `--debug` | — | Enable debug logging |
|
||||||
| `--effect-blur <R>x<P>` | Gaussian blur: radius x passes (e.g., `7x5`) |
|
| **Ring** | | |
|
||||||
| `--effect-pixelate` | Pixelate effect |
|
| `--indicator-radius <N>` | `100` | Ring radius in pixels |
|
||||||
| `--effect-swirl` | Swirl distortion effect |
|
| `--indicator-thickness <N>` | `7` | Ring thickness in pixels |
|
||||||
| `--effect-melting` | Melting distortion effect |
|
| `--ring-shape <SHAPE>` | `circle` | Ring shape: `circle`, `square`, `diamond`, `hexagon`, `pill` |
|
||||||
| `--effect-vignette <B>:<F>` | Vignette: base:factor (e.g., `0.5:0.5`) |
|
| `--max-dots <N>` | `24` | Maximum password dots in the ring |
|
||||||
| **Colors** | |
|
| **Effects** | | |
|
||||||
| `--ring-color <RRGGBB[AA]>` | Outer ring color (hex, optional alpha) |
|
| `--effect-blur <R>x<P>` | — | Gaussian blur: radius x passes (e.g., `7x5`) |
|
||||||
| `--key-hl-color <RRGGBB[AA]>` | Key highlight segment color |
|
| `--effect-vignette <B>:<F>` | — | Vignette: base : factor (e.g., `0.5:0.5`) |
|
||||||
| `--line-color <RRGGBB[AA]>` | Separator line color |
|
| `--effect-pixelate <S>` | — | Pixelate effect with block size in pixels |
|
||||||
| `--inside-color <RRGGBB[AA]>` | Inner circle color |
|
| `--effect-swirl <A>` | — | Swirl distortion with angle |
|
||||||
| `--separator-color <RRGGBB[AA]>` | Ring separator color |
|
| `--effect-melting <F>` | — | Melting distortion with factor |
|
||||||
| **Display Options** | |
|
| **Colors** (hex `RRGGBB[AA]`) | | |
|
||||||
| `--show-media` | Show MPRIS media info (default: true) |
|
| `--ring-color <HEX>` | `#785412` | Outer ring color |
|
||||||
| `--show-battery` | Show battery status (default: true) |
|
| `--line-color <HEX>` | `#00000000` | Separator line color |
|
||||||
| `--show-network` | Show WiFi status (default: true) |
|
| `--inside-color <HEX>` | `#00000088` | Inner circle fill color |
|
||||||
| `--show-bluetooth` | Show Bluetooth status (default: true) |
|
| `--separator-color <HEX>` | `#00000000` | Ring segment separator color |
|
||||||
| `--show-keyboard-layout` | Show keyboard layout indicator (default: true) |
|
| `--key-hl-color <HEX>` | `#4EAC41` | Key highlight segment color |
|
||||||
| `--show-album-art` | Show album art (default: true) |
|
| `--caps-lock-key-hl-color <HEX>` | `#4EAC41` | Key highlight color when caps lock is on |
|
||||||
| **Custom Icons** | |
|
| `--caps-lock-bs-hl-color <HEX>` | `#DB3300` | Backspace highlight color in caps lock |
|
||||||
| `--wifi-icon <PATH>` | Custom WiFi icon (PNG/SVG) |
|
| `--caps-lock-color <HEX>` | `#E5A445` | Caps lock indicator ring color |
|
||||||
| `--bluetooth-icon <PATH>` | Custom Bluetooth icon (PNG/SVG) |
|
| `--caps-lock-text-color <HEX>` | `#E5A445` | Caps lock text color |
|
||||||
| `--battery-icon <PATH>` | Custom battery icon (PNG/SVG) |
|
| `--verifying-color <HEX>` | `#0072FF` | Verifying feedback ring color |
|
||||||
| **Other** | |
|
| `--show-caps-lock-text` | `true` | Show "CAPS" text when caps lock is active |
|
||||||
| `--grace <SECONDS>` | Grace period in seconds (default: 2) |
|
| **Display** | | |
|
||||||
| `--fade-in <SECONDS>` | Fade-in animation duration (default: 0.2) |
|
| `--show-media` | `true` | Show MPRIS media player information |
|
||||||
| `--pam-service <NAME>` | PAM service name (default: "rustlock") |
|
| `--show-battery` | `true` | Show battery status |
|
||||||
| `--config <PATH>` | Path to config file |
|
| `--show-network` | `true` | Show WiFi SSID and signal strength |
|
||||||
| `--theme <NAME>` | Theme preset: dark, light, nord, dracula |
|
| `--show-bluetooth` | `true` | Show Bluetooth status |
|
||||||
| `--debug` | Enable debug logging |
|
| `--show-album-art` | `true` | Show album art for media |
|
||||||
| `--log-file` | Write logs to `~/.rustlock.log` |
|
| `--show-keyboard-layout` | `true` | Show keyboard layout indicator |
|
||||||
|
| **Feedback & Timing** | | |
|
||||||
|
| `--fade-in <SECONDS>` | `0.2` | Fade-in animation duration |
|
||||||
|
| `--grace <SECONDS>` | `0` | Grace period — any key press unlocks within N seconds |
|
||||||
|
| `--auth-timeout <MS>` | `10000` | PAM authentication timeout in milliseconds |
|
||||||
|
| `--wrong-password-duration <MS>` | `500` | Wrong password feedback animation duration |
|
||||||
|
| `--key-highlight-duration <MS>` | `300` | Key highlight feedback duration |
|
||||||
|
| `--cleared-feedback-duration <MS>` | `500` | Cleared password feedback duration |
|
||||||
|
| `--verifying-timeout <MS>` | `5000` | Verifying feedback fallback timeout |
|
||||||
|
| `--feedback-window-duration <MS>` | `1000` | Wrong password feedback input window |
|
||||||
|
| `--key-highlight-window-duration <MS>` | `200` | Key highlight input-side window |
|
||||||
|
| **System** | | |
|
||||||
|
| `--pam-service <NAME>` | `rustlock` | PAM service name |
|
||||||
|
| `--system-poll-interval <S>` | `2` | Polling interval for system status updates |
|
||||||
|
| `--dbus-reconnect-delay <S>` | `5` | Delay before reconnecting DBus on failure |
|
||||||
|
| `--command-timeout <S>` | `5` | Timeout for system commands |
|
||||||
|
| **Custom Icons** (PNG/SVG path) | | |
|
||||||
|
| `--wifi-icon <PATH>` | — | Custom WiFi icon |
|
||||||
|
| `--bluetooth-icon <PATH>` | — | Custom Bluetooth icon |
|
||||||
|
| `--battery-icon <PATH>` | — | Custom battery icon |
|
||||||
|
| `--media-prev-icon <PATH>` | — | Custom previous track icon |
|
||||||
|
| `--media-stop-icon <PATH>` | — | Custom stop icon |
|
||||||
|
| `--media-play-icon <PATH>` | — | Custom play icon |
|
||||||
|
| `--media-pause-icon <PATH>` | — | Custom pause icon |
|
||||||
|
| `--media-next-icon <PATH>` | — | Custom next track icon |
|
||||||
|
| **Logging** | | |
|
||||||
|
| `--log-file` | — | Write verbose logs to `~/.rustlock.log` |
|
||||||
|
| `--log-path <PATH>` | — | Path for log file (enables file logging, overrides `--log-file` default path) |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -167,29 +208,6 @@ The binary will be available at `target/release/rustlock`.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## ✅ Completed
|
|
||||||
|
|
||||||
- [x] PAM-based authentication
|
|
||||||
- [x] Grace period (any key unlocks within N seconds)
|
|
||||||
- [x] Screenshot capture with blur/vignette/pixelate/swirl/melting effects
|
|
||||||
- [x] Configuration file support (`~/.config/rustlock/config.toml`) with schema validation
|
|
||||||
- [x] Debug logging to `~/.rustlock.log`
|
|
||||||
- [x] Clock and date display
|
|
||||||
- [x] Password indicator ring with rotating highlights
|
|
||||||
- [x] Dynamic screen resolution detection
|
|
||||||
- [x] Full multi-monitor support with different resolutions
|
|
||||||
- [x] Theme/profile support with presets (dark, light, nord, dracula)
|
|
||||||
- [x] Wayland protocol stability fixes
|
|
||||||
- [x] Media control integration (MPRIS support with Album Art)
|
|
||||||
- [x] Battery, WiFi, and Bluetooth status indicators
|
|
||||||
- [x] Custom background image support
|
|
||||||
- [x] Custom icons for status indicators
|
|
||||||
- [x] Keyboard layout indicator
|
|
||||||
- [x] Session management (F1-F3 keys)
|
|
||||||
- [x] Caps lock indicator
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 📄 License
|
## 📄 License
|
||||||
|
|
||||||
AGPL v3+
|
GPL v3
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
{ pkgs ? import <nixpkgs> {} }:
|
|
||||||
|
|
||||||
pkgs.rustPlatform.buildRustPackage {
|
|
||||||
pname = "rustlock";
|
|
||||||
version = "0.1.0";
|
|
||||||
src = ./.;
|
|
||||||
cargoLock = { lockFile = ./Cargo.lock; };
|
|
||||||
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
cairo
|
|
||||||
pam
|
|
||||||
gdk-pixbuf
|
|
||||||
librsvg
|
|
||||||
pango
|
|
||||||
libxkbcommon
|
|
||||||
dbus
|
|
||||||
];
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
|
||||||
pkgs.pkg-config
|
|
||||||
pkgs.rustPlatform.bindgenHook
|
|
||||||
pkgs.rustfmt
|
|
||||||
pkgs.clippy
|
|
||||||
];
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,26 @@
|
|||||||
[advisories]
|
[advisories]
|
||||||
vulnerability = "deny"
|
|
||||||
ignore = []
|
ignore = []
|
||||||
|
|
||||||
[bans]
|
[bans]
|
||||||
multiple-versions = "allow"
|
multiple-versions = "allow"
|
||||||
|
|
||||||
|
[licenses]
|
||||||
|
allow = [
|
||||||
|
"MIT",
|
||||||
|
"Apache-2.0",
|
||||||
|
"BSD-2-Clause",
|
||||||
|
"BSD-3-Clause",
|
||||||
|
"ISC",
|
||||||
|
"Zlib",
|
||||||
|
"Unlicense",
|
||||||
|
"0BSD",
|
||||||
|
"Unicode-3.0",
|
||||||
|
"MPL-2.0",
|
||||||
|
"GPL-3.0-or-later",
|
||||||
|
"Apache-2.0 WITH LLVM-exception",
|
||||||
|
"CDLA-Permissive-2.0",
|
||||||
|
]
|
||||||
|
|
||||||
[sources]
|
[sources]
|
||||||
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
|
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
|
||||||
allow-git = []
|
allow-git = []
|
||||||
|
|||||||
Generated
+27
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1774386573,
|
||||||
|
"narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
description = "A high-performance Wayland screen locker written in Rust";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs }: let
|
||||||
|
system = "x86_64-linux";
|
||||||
|
pkgs = import nixpkgs { inherit system; };
|
||||||
|
in {
|
||||||
|
packages.${system}.default = pkgs.rustPlatform.buildRustPackage {
|
||||||
|
pname = "rustlock";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./.;
|
||||||
|
cargoLock = { lockFile = ./Cargo.lock; };
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
cairo
|
||||||
|
pam
|
||||||
|
gdk-pixbuf
|
||||||
|
librsvg
|
||||||
|
pango
|
||||||
|
libxkbcommon
|
||||||
|
dbus
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.rustPlatform.bindgenHook
|
||||||
|
pkgs.rustfmt
|
||||||
|
pkgs.clippy
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "1.94.0"
|
||||||
|
components = ["rustfmt", "clippy"]
|
||||||
+51
-41
@@ -1,5 +1,8 @@
|
|||||||
use std::ffi::{CStr, CString};
|
use std::ffi::{CStr, CString};
|
||||||
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use pam_client::{Context, ErrorCode, Flag};
|
use pam_client::{Context, ErrorCode, Flag};
|
||||||
@@ -7,9 +10,10 @@ use smithay_client_toolkit::reexports::{calloop::channel, calloop::EventLoop};
|
|||||||
use whoami::username;
|
use whoami::username;
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
|
|
||||||
const SERVICE_NAME: &str = "rustlock";
|
type AuthChannels = (
|
||||||
|
channel::Sender<(Zeroizing<String>, u64)>,
|
||||||
pub struct LockConversation {
|
channel::Channel<(bool, u64)>,
|
||||||
|
);pub struct LockConversation {
|
||||||
pub password: Option<Zeroizing<String>>,
|
pub password: Option<Zeroizing<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,59 +40,65 @@ impl pam_client::ConversationHandler for LockConversation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_and_run_auth_loop(
|
pub fn create_and_run_auth_loop(
|
||||||
) -> Option<(channel::Sender<Zeroizing<String>>, channel::Channel<bool>)> {
|
service_name: String,
|
||||||
|
) -> Option<AuthChannels> {
|
||||||
let username = username();
|
let username = username();
|
||||||
|
|
||||||
let conversation = LockConversation { password: None };
|
let (auth_req_send, auth_req_recv) =
|
||||||
match Context::new(SERVICE_NAME, Some(username.as_str()), conversation) {
|
channel::channel::<(Zeroizing<String>, u64)>();
|
||||||
Ok(_) => {
|
let (auth_res_send, auth_res_recv) = channel::channel::<(bool, u64)>();
|
||||||
debug!("Prepared to authenticate user '{}'", username);
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
error!("Failed to initialize PAM context: {:?}", err);
|
|
||||||
error!(
|
|
||||||
"Ensure that the PAM service '{}' is correctly configured.",
|
|
||||||
SERVICE_NAME
|
|
||||||
);
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (auth_req_send, auth_req_recv) = channel::channel::<Zeroizing<String>>();
|
|
||||||
let (auth_res_send, auth_res_recv) = channel::channel::<bool>();
|
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut event_loop: EventLoop<()> = EventLoop::try_new().unwrap();
|
let mut event_loop: EventLoop<()> = EventLoop::try_new().unwrap();
|
||||||
|
|
||||||
|
// Create PAM context once and reuse it for all auth attempts.
|
||||||
|
// Creating a new context each time is expensive because it
|
||||||
|
// re-parses configs and re-loads shared libraries for every attempt.
|
||||||
|
let conversation = LockConversation { password: None };
|
||||||
|
let mut context = match Context::new(service_name.as_str(), Some(username.as_str()), conversation) {
|
||||||
|
Ok(ctx) => {
|
||||||
|
debug!("Prepared to authenticate user '{}'", username);
|
||||||
|
ctx
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!("Failed to initialize PAM context: {:?}", err);
|
||||||
|
error!(
|
||||||
|
"Ensure that the PAM service '{}' is correctly configured.",
|
||||||
|
service_name
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
|
let running_clone = running.clone();
|
||||||
|
|
||||||
event_loop
|
event_loop
|
||||||
.handle()
|
.handle()
|
||||||
.insert_source(auth_req_recv, |evt, _metadata, _state| match evt {
|
.insert_source(auth_req_recv, move |evt, _metadata, _state| match evt {
|
||||||
channel::Event::Msg(password) => {
|
channel::Event::Msg((password, seq)) => {
|
||||||
let conversation = LockConversation {
|
context.conversation_mut().password = Some(password);
|
||||||
password: Some(password),
|
match context.authenticate(Flag::NONE) {
|
||||||
};
|
Ok(()) => {
|
||||||
match Context::new(SERVICE_NAME, Some(username.as_str()), conversation) {
|
let _ = auth_res_send.send((true, seq));
|
||||||
Ok(mut context) => match context.authenticate(Flag::NONE) {
|
}
|
||||||
Ok(()) => {
|
|
||||||
auth_res_send.send(true).unwrap();
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
error!("Pam authenticate failed with {:?}", err);
|
|
||||||
auth_res_send.send(false).unwrap();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Failed to re-initialize PAM context: {:?}", err);
|
error!("Pam authenticate failed with {:?}", err);
|
||||||
auth_res_send.send(false).unwrap();
|
let _ = auth_res_send.send((false, seq));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channel::Event::Closed => {}
|
channel::Event::Closed => {
|
||||||
|
running_clone.store(false, Ordering::SeqCst);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
loop {
|
while running.load(Ordering::SeqCst) {
|
||||||
event_loop.dispatch(None, &mut ()).expect("Failed to run");
|
let _ = event_loop.dispatch(Some(Duration::from_millis(100)), &mut ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("PAM auth thread exiting cleanly");
|
||||||
});
|
});
|
||||||
|
|
||||||
Some((auth_req_send, auth_res_recv))
|
Some((auth_req_send, auth_res_recv))
|
||||||
|
|||||||
+247
-151
@@ -1,18 +1,60 @@
|
|||||||
use crate::util;
|
use crate::util;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
|
||||||
|
pub enum RingShape {
|
||||||
|
#[default]
|
||||||
|
Circle,
|
||||||
|
Square,
|
||||||
|
Diamond,
|
||||||
|
Hexagon,
|
||||||
|
Pill,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for RingShape {
|
||||||
|
type Err = String;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"circle" => Ok(RingShape::Circle),
|
||||||
|
"square" => Ok(RingShape::Square),
|
||||||
|
"diamond" => Ok(RingShape::Diamond),
|
||||||
|
"hexagon" => Ok(RingShape::Hexagon),
|
||||||
|
"pill" => Ok(RingShape::Pill),
|
||||||
|
_ => Err(format!(
|
||||||
|
"Unknown ring shape '{}'. Options: circle, square, diamond, hexagon, pill",
|
||||||
|
s
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for RingShape {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
RingShape::Circle => write!(f, "circle"),
|
||||||
|
RingShape::Square => write!(f, "square"),
|
||||||
|
RingShape::Diamond => write!(f, "diamond"),
|
||||||
|
RingShape::Hexagon => write!(f, "hexagon"),
|
||||||
|
RingShape::Pill => write!(f, "pill"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Parser, Debug, Clone, Serialize, Deserialize)]
|
#[derive(Parser, Debug, Clone, Serialize, Deserialize)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "false", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue)]
|
||||||
pub screenshots: bool,
|
pub screenshots: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "false", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue)]
|
||||||
pub clock: bool,
|
pub clock: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub indicator: bool,
|
pub indicator: bool,
|
||||||
|
|
||||||
#[arg(long, default_value = "100")]
|
#[arg(long, default_value = "100")]
|
||||||
@@ -21,52 +63,112 @@ pub struct Config {
|
|||||||
#[arg(long, default_value = "7")]
|
#[arg(long, default_value = "7")]
|
||||||
pub indicator_thickness: u32,
|
pub indicator_thickness: u32,
|
||||||
|
|
||||||
|
#[arg(long, default_value = "circle", value_parser = clap::value_parser!(RingShape))]
|
||||||
|
#[serde(default)]
|
||||||
|
pub ring_shape: RingShape,
|
||||||
|
|
||||||
#[arg(long, value_parser = util::parse_blur_effect)]
|
#[arg(long, value_parser = util::parse_blur_effect)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_blur_effect",
|
||||||
|
serialize_with = "util::serialize_blur_effect",
|
||||||
|
default
|
||||||
|
)]
|
||||||
pub effect_blur: Option<(u32, u32)>,
|
pub effect_blur: Option<(u32, u32)>,
|
||||||
|
|
||||||
#[arg(long, value_parser = util::parse_vignette_effect)]
|
#[arg(long, value_parser = util::parse_vignette_effect)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_vignette_effect",
|
||||||
|
serialize_with = "util::serialize_vignette_effect",
|
||||||
|
default
|
||||||
|
)]
|
||||||
pub effect_vignette: Option<(f32, f32)>,
|
pub effect_vignette: Option<(f32, f32)>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub effect_pixelate: Option<u32>,
|
pub effect_pixelate: Option<u32>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub effect_swirl: Option<f32>,
|
pub effect_swirl: Option<f32>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub effect_melting: Option<f32>,
|
pub effect_melting: Option<f32>,
|
||||||
|
|
||||||
#[arg(long, default_value = "785412", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "785412", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub ring_color: (f64, f64, f64, f64),
|
pub ring_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "4EAC41", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "4EAC41", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub key_hl_color: (f64, f64, f64, f64),
|
pub key_hl_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "4EAC41", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "4EAC41", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub caps_lock_key_hl_color: (f64, f64, f64, f64),
|
pub caps_lock_key_hl_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "DB3300", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "DB3300", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub caps_lock_bs_hl_color: (f64, f64, f64, f64),
|
pub caps_lock_bs_hl_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "E5A445", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "E5A445", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub caps_lock_color: (f64, f64, f64, f64),
|
pub caps_lock_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "E5A445", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "E5A445", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub caps_lock_text_color: (f64, f64, f64, f64),
|
pub caps_lock_text_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
#[arg(long, default_value = "0072FF", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
|
pub verifying_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub show_caps_lock_text: bool,
|
pub show_caps_lock_text: bool,
|
||||||
|
|
||||||
#[arg(long, default_value = "00000000", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "00000000", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub line_color: (f64, f64, f64, f64),
|
pub line_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "00000088", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "00000088", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub inside_color: (f64, f64, f64, f64),
|
pub inside_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "00000000", value_parser = util::parse_hex_color)]
|
#[arg(long, default_value = "00000000", value_parser = util::parse_hex_color)]
|
||||||
|
#[serde(
|
||||||
|
deserialize_with = "util::deserialize_hex_color",
|
||||||
|
serialize_with = "util::serialize_hex_color"
|
||||||
|
)]
|
||||||
pub separator_color: (f64, f64, f64, f64),
|
pub separator_color: (f64, f64, f64, f64),
|
||||||
|
|
||||||
#[arg(long, default_value = "2")]
|
#[arg(long, default_value = "0")]
|
||||||
pub grace: f32,
|
pub grace: f32,
|
||||||
|
|
||||||
#[arg(long, default_value = "0.2")]
|
#[arg(long, default_value = "0.2")]
|
||||||
@@ -85,51 +187,112 @@ pub struct Config {
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub log_file: bool,
|
pub log_file: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
/// Path for log file (enables file logging, overrides --log-file default path)
|
||||||
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub log_path: Option<PathBuf>,
|
||||||
|
|
||||||
|
/// Timeout (ms) for PAM authentication before showing failure
|
||||||
|
#[arg(long, default_value = "10000")]
|
||||||
|
pub auth_timeout: u64,
|
||||||
|
|
||||||
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub show_media: bool,
|
pub show_media: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub show_battery: bool,
|
pub show_battery: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub show_network: bool,
|
pub show_network: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub show_bluetooth: bool,
|
pub show_bluetooth: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "true", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue, default_value_t = true)]
|
||||||
pub show_album_art: bool,
|
pub show_album_art: bool,
|
||||||
|
|
||||||
#[arg(long, action = clap::ArgAction::Set, num_args = 0..=1, default_value = "false", default_missing_value = "true")]
|
#[arg(long, action = clap::ArgAction::SetTrue)]
|
||||||
|
pub hide_password: bool,
|
||||||
|
|
||||||
|
#[arg(long, action = clap::ArgAction::SetTrue)]
|
||||||
pub show_keyboard_layout: bool,
|
pub show_keyboard_layout: bool,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub image: Option<PathBuf>,
|
pub image: Option<PathBuf>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub wifi_icon: Option<String>,
|
pub wifi_icon: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub bluetooth_icon: Option<String>,
|
pub bluetooth_icon: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub battery_icon: Option<String>,
|
pub battery_icon: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub media_prev_icon: Option<String>,
|
pub media_prev_icon: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub media_stop_icon: Option<String>,
|
pub media_stop_icon: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub media_play_icon: Option<String>,
|
pub media_play_icon: Option<String>,
|
||||||
|
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub media_pause_icon: Option<String>,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
#[serde(default)]
|
||||||
pub media_next_icon: Option<String>,
|
pub media_next_icon: Option<String>,
|
||||||
|
|
||||||
/// Apply a pre-defined theme preset
|
/// Maximum number of password dots in the indicator ring
|
||||||
#[arg(long)]
|
#[arg(long, default_value = "24")]
|
||||||
pub theme: Option<String>,
|
pub max_dots: u32,
|
||||||
|
|
||||||
|
/// Duration (ms) for wrong password feedback animation
|
||||||
|
#[arg(long, default_value = "500")]
|
||||||
|
pub wrong_password_duration: u64,
|
||||||
|
|
||||||
|
/// Duration (ms) for key highlight feedback animation
|
||||||
|
#[arg(long, default_value = "300")]
|
||||||
|
pub key_highlight_duration: u64,
|
||||||
|
|
||||||
|
/// Duration (ms) for cleared password feedback animation
|
||||||
|
#[arg(long, default_value = "500")]
|
||||||
|
pub cleared_feedback_duration: u64,
|
||||||
|
|
||||||
|
/// Duration (ms) for verifying feedback fallback timeout
|
||||||
|
#[arg(long, default_value = "5000")]
|
||||||
|
pub verifying_timeout: u64,
|
||||||
|
|
||||||
|
/// Duration (ms) that wrong password feedback is shown input-side
|
||||||
|
#[arg(long, default_value = "1000")]
|
||||||
|
pub feedback_window_duration: u64,
|
||||||
|
|
||||||
|
/// Duration (ms) for key highlight feedback input-side window
|
||||||
|
#[arg(long, default_value = "200")]
|
||||||
|
pub key_highlight_window_duration: u64,
|
||||||
|
|
||||||
|
/// Polling interval (seconds) for system status updates
|
||||||
|
#[arg(long, default_value = "2")]
|
||||||
|
pub system_poll_interval: u64,
|
||||||
|
|
||||||
|
/// Delay (seconds) before reconnecting DBus on failure
|
||||||
|
#[arg(long, default_value = "5")]
|
||||||
|
pub dbus_reconnect_delay: u64,
|
||||||
|
|
||||||
|
/// Timeout (seconds) for system commands (poweroff, reboot, suspend)
|
||||||
|
#[arg(long, default_value = "5")]
|
||||||
|
pub command_timeout: u64,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -144,7 +307,7 @@ impl Config {
|
|||||||
let is_cli =
|
let is_cli =
|
||||||
|key: &str| matches.value_source(key) == Some(clap::parser::ValueSource::CommandLine);
|
|key: &str| matches.value_source(key) == Some(clap::parser::ValueSource::CommandLine);
|
||||||
|
|
||||||
// 1. Config file layer (overrides defaults and themes)
|
// Config file layer (overrides defaults, CLI args take precedence)
|
||||||
let config_path = config.config.clone().unwrap_or_else(|| {
|
let config_path = config.config.clone().unwrap_or_else(|| {
|
||||||
let mut path = std::path::PathBuf::from(std::env::var("HOME").unwrap_or_default());
|
let mut path = std::path::PathBuf::from(std::env::var("HOME").unwrap_or_default());
|
||||||
path.push(".config/rustlock/config.toml");
|
path.push(".config/rustlock/config.toml");
|
||||||
@@ -153,154 +316,87 @@ impl Config {
|
|||||||
|
|
||||||
if config_path.exists() {
|
if config_path.exists() {
|
||||||
if let Ok(file_content) = std::fs::read_to_string(&config_path) {
|
if let Ok(file_content) = std::fs::read_to_string(&config_path) {
|
||||||
if let Ok(table) = toml::from_str::<toml::Table>(&file_content) {
|
if let Ok(file_table) = toml::from_str::<toml::Table>(&file_content) {
|
||||||
log::debug!("Loaded configuration from {:?}", config_path);
|
log::debug!("Loaded configuration from {:?}", config_path);
|
||||||
|
|
||||||
let merge_bool = |val: &mut bool, key: &str| {
|
// Convert current config to a TOML table to facilitate merging
|
||||||
if !is_cli(key) {
|
if let Ok(mut config_table) = toml::Value::try_from(config.clone()) {
|
||||||
if let Some(toml::Value::Boolean(b)) = table.get(key) {
|
if let Some(config_table) = config_table.as_table_mut() {
|
||||||
*val = *b;
|
for (key, value) in file_table {
|
||||||
|
if !is_cli(&key) {
|
||||||
|
config_table.insert(key, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let merge_u32 = |val: &mut u32, key: &str| {
|
// Convert back to Config struct
|
||||||
if !is_cli(key) {
|
if let Ok(new_config) =
|
||||||
if let Some(toml::Value::Integer(i)) = table.get(key) {
|
toml::Value::Table(config_table.clone()).try_into::<Config>()
|
||||||
*val = *i as u32;
|
{
|
||||||
|
config = new_config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
let merge_f32 = |val: &mut f32, key: &str| {
|
|
||||||
if !is_cli(key) {
|
|
||||||
if let Some(toml::Value::Float(f)) = table.get(key) {
|
|
||||||
*val = *f as f32;
|
|
||||||
} else if let Some(toml::Value::Integer(i)) = table.get(key) {
|
|
||||||
*val = *i as f32;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let merge_string = |val: &mut String, key: &str| {
|
|
||||||
if !is_cli(key) {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get(key) {
|
|
||||||
*val = s.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
merge_bool(&mut config.screenshots, "screenshots");
|
|
||||||
merge_bool(&mut config.clock, "clock");
|
|
||||||
merge_bool(&mut config.indicator, "indicator");
|
|
||||||
merge_u32(&mut config.indicator_radius, "indicator_radius");
|
|
||||||
merge_u32(&mut config.indicator_thickness, "indicator_thickness");
|
|
||||||
merge_f32(&mut config.grace, "grace");
|
|
||||||
merge_f32(&mut config.fade_in, "fade_in");
|
|
||||||
merge_string(&mut config.pam_service, "pam_service");
|
|
||||||
merge_bool(&mut config.show_media, "show_media");
|
|
||||||
merge_bool(&mut config.show_battery, "show_battery");
|
|
||||||
merge_bool(&mut config.show_network, "show_network");
|
|
||||||
merge_bool(&mut config.show_bluetooth, "show_bluetooth");
|
|
||||||
merge_bool(&mut config.show_album_art, "show_album_art");
|
|
||||||
merge_bool(&mut config.show_keyboard_layout, "show_keyboard_layout");
|
|
||||||
|
|
||||||
if !is_cli("image") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("image") {
|
|
||||||
config.image = Some(std::path::PathBuf::from(s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("wifi_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("wifi_icon") {
|
|
||||||
config.wifi_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("bluetooth_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("bluetooth_icon") {
|
|
||||||
config.bluetooth_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("battery_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("battery_icon") {
|
|
||||||
config.battery_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("media_prev_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("media_prev_icon") {
|
|
||||||
config.media_prev_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("media_stop_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("media_stop_icon") {
|
|
||||||
config.media_stop_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("media_play_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("media_play_icon") {
|
|
||||||
config.media_play_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !is_cli("media_next_icon") {
|
|
||||||
if let Some(toml::Value::String(s)) = table.get("media_next_icon") {
|
|
||||||
config.media_next_icon = Some(s.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Theme presets (applied to fields NOT set on CLI or in File)
|
config.auth_timeout = config.auth_timeout.max(100);
|
||||||
if let Some(theme) = &config.theme {
|
config.max_dots = config.max_dots.max(1);
|
||||||
match theme.as_str() {
|
config.fade_in = config.fade_in.max(0.0);
|
||||||
"modern" => {
|
config.grace = config.grace.max(0.0);
|
||||||
if config.effect_blur.is_none() && !is_cli("effect_blur") {
|
|
||||||
config.effect_blur = Some((10, 3));
|
|
||||||
}
|
|
||||||
if config.effect_vignette.is_none() && !is_cli("effect_vignette") {
|
|
||||||
config.effect_vignette = Some((0.5, 0.5));
|
|
||||||
}
|
|
||||||
if !is_cli("indicator_radius") {
|
|
||||||
config.indicator_radius = 120;
|
|
||||||
}
|
|
||||||
if !is_cli("ring_color") {
|
|
||||||
config.ring_color = (0.2, 0.6, 0.8, 1.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"pixel" => {
|
|
||||||
if config.effect_pixelate.is_none() && !is_cli("effect_pixelate") {
|
|
||||||
config.effect_pixelate = Some(10);
|
|
||||||
}
|
|
||||||
if !is_cli("indicator_radius") {
|
|
||||||
config.indicator_radius = 80;
|
|
||||||
}
|
|
||||||
if !is_cli("ring_color") {
|
|
||||||
config.ring_color = (0.8, 0.2, 0.2, 1.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"glass" => {
|
|
||||||
if config.effect_blur.is_none() && !is_cli("effect_blur") {
|
|
||||||
config.effect_blur = Some((20, 5));
|
|
||||||
}
|
|
||||||
if !is_cli("inside_color") {
|
|
||||||
config.inside_color = (1.0, 1.0, 1.0, 0.1);
|
|
||||||
}
|
|
||||||
if !is_cli("ring_color") {
|
|
||||||
config.ring_color = (1.0, 1.0, 1.0, 0.5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
log::warn!("Unknown theme: {}", theme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_max_dots_default() {
|
||||||
|
let config = Config::parse_from(["test"]);
|
||||||
|
assert_eq!(config.max_dots, 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_auth_timeout_default() {
|
||||||
|
let config = Config::parse_from(["test"]);
|
||||||
|
assert_eq!(config.auth_timeout, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_auth_timeout_min_clamp() {
|
||||||
|
let mut config = Config::parse_from(["test", "--auth-timeout", "0"]);
|
||||||
|
config.auth_timeout = config.auth_timeout.max(100);
|
||||||
|
assert_eq!(config.auth_timeout, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_max_dots_min_clamp() {
|
||||||
|
let mut config = Config::parse_from(["test", "--max-dots", "0"]);
|
||||||
|
config.max_dots = config.max_dots.max(1);
|
||||||
|
assert_eq!(config.max_dots, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fade_in_negative_clamp() {
|
||||||
|
let mut config = Config::parse_from(["test", "--fade-in=-1"]);
|
||||||
|
config.fade_in = config.fade_in.max(0.0);
|
||||||
|
assert_eq!(config.fade_in, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_grace_negative_clamp() {
|
||||||
|
let mut config = Config::parse_from(["test", "--grace=-1"]);
|
||||||
|
config.grace = config.grace.max(0.0);
|
||||||
|
assert_eq!(config.grace, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_log_path_default_none() {
|
||||||
|
let config = Config::parse_from(["test"]);
|
||||||
|
assert!(config.log_path.is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+350
-13
@@ -7,16 +7,20 @@ pub struct InputHandler {
|
|||||||
wrong_password_timer: Option<std::time::Instant>,
|
wrong_password_timer: Option<std::time::Instant>,
|
||||||
key_highlight_timer: Option<std::time::Instant>,
|
key_highlight_timer: Option<std::time::Instant>,
|
||||||
caps_lock: bool,
|
caps_lock: bool,
|
||||||
|
config: crate::config::Config,
|
||||||
|
last_failed_attempt: Option<std::time::Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputHandler {
|
impl InputHandler {
|
||||||
pub fn new(_config: crate::config::Config) -> Self {
|
pub fn new(config: crate::config::Config) -> Self {
|
||||||
Self {
|
Self {
|
||||||
password_buffer: Zeroizing::new(String::new()),
|
password_buffer: Zeroizing::new(String::new()),
|
||||||
cursor_position: 0,
|
cursor_position: 0,
|
||||||
wrong_password_timer: None,
|
wrong_password_timer: None,
|
||||||
key_highlight_timer: None,
|
key_highlight_timer: None,
|
||||||
caps_lock: false,
|
caps_lock: false,
|
||||||
|
config,
|
||||||
|
last_failed_attempt: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,16 +31,32 @@ impl InputHandler {
|
|||||||
utf8: Option<String>,
|
utf8: Option<String>,
|
||||||
modifiers: smithay_client_toolkit::seat::keyboard::Modifiers,
|
modifiers: smithay_client_toolkit::seat::keyboard::Modifiers,
|
||||||
) -> InputAction {
|
) -> InputAction {
|
||||||
// Update Caps Lock state
|
if self.is_cooldown() {
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
|
|
||||||
self.caps_lock = modifiers.caps_lock;
|
self.caps_lock = modifiers.caps_lock;
|
||||||
|
|
||||||
|
if modifiers.ctrl && keysym == Keysym::u {
|
||||||
|
if !self.password_buffer.is_empty() {
|
||||||
|
self.password_buffer.clear();
|
||||||
|
self.cursor_position = 0;
|
||||||
|
return InputAction::PasswordCleared;
|
||||||
|
}
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle special keys first using keysym
|
// Handle special keys first using keysym
|
||||||
use smithay_client_toolkit::seat::keyboard::Keysym;
|
use smithay_client_toolkit::seat::keyboard::Keysym;
|
||||||
match keysym {
|
match keysym {
|
||||||
Keysym::BackSpace => {
|
Keysym::BackSpace => {
|
||||||
if !self.password_buffer.is_empty() && self.cursor_position > 0 {
|
if self.password_buffer.is_empty() || self.cursor_position == 0 {
|
||||||
self.cursor_position -= 1;
|
return InputAction::None;
|
||||||
self.password_buffer.remove(self.cursor_position);
|
}
|
||||||
|
self.cursor_position -= 1;
|
||||||
|
self.password_buffer.remove(self.cursor_position);
|
||||||
|
if self.password_buffer.is_empty() {
|
||||||
|
return InputAction::PasswordCleared;
|
||||||
}
|
}
|
||||||
return InputAction::PasswordChanged;
|
return InputAction::PasswordChanged;
|
||||||
}
|
}
|
||||||
@@ -49,6 +69,44 @@ impl InputHandler {
|
|||||||
Keysym::Escape => {
|
Keysym::Escape => {
|
||||||
return InputAction::Cancel;
|
return InputAction::Cancel;
|
||||||
}
|
}
|
||||||
|
Keysym::Left => {
|
||||||
|
if self.cursor_position > 0 {
|
||||||
|
self.cursor_position -= 1;
|
||||||
|
return InputAction::CursorMoved;
|
||||||
|
}
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
|
Keysym::Right => {
|
||||||
|
if self.cursor_position < self.password_buffer.len() {
|
||||||
|
self.cursor_position += 1;
|
||||||
|
return InputAction::CursorMoved;
|
||||||
|
}
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
|
Keysym::Home => {
|
||||||
|
if self.cursor_position > 0 {
|
||||||
|
self.cursor_position = 0;
|
||||||
|
return InputAction::CursorMoved;
|
||||||
|
}
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
|
Keysym::End => {
|
||||||
|
if self.cursor_position < self.password_buffer.len() {
|
||||||
|
self.cursor_position = self.password_buffer.len();
|
||||||
|
return InputAction::CursorMoved;
|
||||||
|
}
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
|
Keysym::Delete => {
|
||||||
|
if self.cursor_position < self.password_buffer.len() {
|
||||||
|
self.password_buffer.remove(self.cursor_position);
|
||||||
|
if self.password_buffer.is_empty() {
|
||||||
|
return InputAction::PasswordCleared;
|
||||||
|
}
|
||||||
|
return InputAction::PasswordChanged;
|
||||||
|
}
|
||||||
|
return InputAction::None;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,20 +124,34 @@ impl InputHandler {
|
|||||||
InputAction::None
|
InputAction::None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current password (for display purposes only - returns masked version)
|
pub fn password_buffer(&self) -> &Zeroizing<String> {
|
||||||
pub fn get_display_password(&self) -> String {
|
&self.password_buffer
|
||||||
self.password_buffer.chars().map(|_| '•').collect()
|
}
|
||||||
|
|
||||||
|
pub fn password_length(&self) -> usize {
|
||||||
|
self.password_buffer.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cursor_position(&self) -> usize {
|
||||||
|
self.cursor_position
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set wrong password feedback timer
|
/// Set wrong password feedback timer
|
||||||
pub fn set_wrong_password_feedback(&mut self) {
|
pub fn set_wrong_password_feedback(&mut self) {
|
||||||
self.wrong_password_timer = Some(std::time::Instant::now());
|
self.wrong_password_timer = Some(std::time::Instant::now());
|
||||||
|
self.last_failed_attempt = Some(std::time::Instant::now());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_cooldown(&self) -> bool {
|
||||||
|
self.last_failed_attempt
|
||||||
|
.map(|t| t.elapsed() < std::time::Duration::from_millis(400))
|
||||||
|
.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if wrong password feedback should be shown
|
/// Check if wrong password feedback should be shown
|
||||||
pub fn should_show_wrong_password(&self) -> bool {
|
pub fn should_show_wrong_password(&self) -> bool {
|
||||||
if let Some(timer) = self.wrong_password_timer {
|
if let Some(timer) = self.wrong_password_timer {
|
||||||
timer.elapsed() < std::time::Duration::from_millis(1000)
|
timer.elapsed() < std::time::Duration::from_millis(self.config.feedback_window_duration)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -93,15 +165,12 @@ impl InputHandler {
|
|||||||
/// Check if key highlight should be shown
|
/// Check if key highlight should be shown
|
||||||
pub fn should_show_key_highlight(&self) -> bool {
|
pub fn should_show_key_highlight(&self) -> bool {
|
||||||
if let Some(timer) = self.key_highlight_timer {
|
if let Some(timer) = self.key_highlight_timer {
|
||||||
timer.elapsed() < std::time::Duration::from_millis(200)
|
timer.elapsed() < std::time::Duration::from_millis(self.config.key_highlight_window_duration)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update timers (should be called periodically)
|
|
||||||
pub fn update(&mut self) {}
|
|
||||||
|
|
||||||
/// Get the current Caps Lock state
|
/// Get the current Caps Lock state
|
||||||
pub fn caps_lock(&self) -> bool {
|
pub fn caps_lock(&self) -> bool {
|
||||||
self.caps_lock
|
self.caps_lock
|
||||||
@@ -113,6 +182,274 @@ impl InputHandler {
|
|||||||
pub enum InputAction {
|
pub enum InputAction {
|
||||||
None,
|
None,
|
||||||
PasswordChanged,
|
PasswordChanged,
|
||||||
|
PasswordCleared,
|
||||||
|
CursorMoved,
|
||||||
SubmitPassword(Zeroizing<String>),
|
SubmitPassword(Zeroizing<String>),
|
||||||
Cancel,
|
Cancel,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::config::Config;
|
||||||
|
use clap::Parser;
|
||||||
|
use smithay_client_toolkit::seat::keyboard::{Keysym, Modifiers};
|
||||||
|
|
||||||
|
fn test_config() -> Config {
|
||||||
|
Config::parse_from(["test"])
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_new_handler_defaults() {
|
||||||
|
let handler = InputHandler::new(test_config());
|
||||||
|
assert_eq!(handler.password_length(), 0);
|
||||||
|
assert_eq!(handler.cursor_position(), 0);
|
||||||
|
assert!(!handler.caps_lock());
|
||||||
|
assert!(!handler.should_show_wrong_password());
|
||||||
|
assert!(!handler.should_show_key_highlight());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_character_input_appends() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
assert!(matches!(action, InputAction::PasswordChanged));
|
||||||
|
assert_eq!(handler.password_length(), 1);
|
||||||
|
assert_eq!(handler.cursor_position(), 1);
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
assert!(matches!(action, InputAction::PasswordChanged));
|
||||||
|
assert_eq!(handler.password_length(), 2);
|
||||||
|
assert_eq!(handler.cursor_position(), 2);
|
||||||
|
|
||||||
|
assert_eq!(&*handler.password_buffer, "ab");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_backspace_removes_last_char() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
assert_eq!(handler.password_length(), 2);
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::BackSpace, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::PasswordChanged));
|
||||||
|
assert_eq!(handler.password_length(), 1);
|
||||||
|
assert_eq!(handler.cursor_position(), 1);
|
||||||
|
assert_eq!(&*handler.password_buffer, "a");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_backspace_on_empty_buffer() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::BackSpace, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::None));
|
||||||
|
assert_eq!(handler.password_length(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_backspace_last_char_clears() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
let action = handler.handle_key_event(Keysym::BackSpace, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::PasswordCleared));
|
||||||
|
assert_eq!(handler.password_length(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ctrl_u_clears_buffer() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers {
|
||||||
|
ctrl: true,
|
||||||
|
..Modifiers::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), Modifiers::default());
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), Modifiers::default());
|
||||||
|
assert_eq!(handler.password_length(), 2);
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::u, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::PasswordCleared));
|
||||||
|
assert_eq!(handler.password_length(), 0);
|
||||||
|
assert_eq!(handler.cursor_position(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_submit_returns_and_clears() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::Return, None, mods);
|
||||||
|
match action {
|
||||||
|
InputAction::SubmitPassword(p) => {
|
||||||
|
assert_eq!(&*p, "ab");
|
||||||
|
}
|
||||||
|
_ => panic!("Expected SubmitPassword, got {:?}", action),
|
||||||
|
}
|
||||||
|
// Buffer should be cleared after submission
|
||||||
|
assert_eq!(handler.password_length(), 0);
|
||||||
|
assert_eq!(handler.cursor_position(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_submit_enter_kp() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::KP_Enter, None, Modifiers::default());
|
||||||
|
assert!(matches!(action, InputAction::SubmitPassword(_)));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_escape_cancels() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::Escape, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::Cancel));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cursor_left_right() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::c, Some("c".to_string()), mods);
|
||||||
|
assert_eq!(handler.cursor_position(), 3);
|
||||||
|
|
||||||
|
// Move left
|
||||||
|
let action = handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::CursorMoved));
|
||||||
|
assert_eq!(handler.cursor_position(), 2);
|
||||||
|
|
||||||
|
// Left again
|
||||||
|
handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
assert_eq!(handler.cursor_position(), 1);
|
||||||
|
|
||||||
|
// Right
|
||||||
|
let action = handler.handle_key_event(Keysym::Right, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::CursorMoved));
|
||||||
|
assert_eq!(handler.cursor_position(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cursor_left_at_start() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::None));
|
||||||
|
assert_eq!(handler.cursor_position(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cursor_right_at_end() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
|
||||||
|
let action = handler.handle_key_event(Keysym::Right, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::None));
|
||||||
|
assert_eq!(handler.cursor_position(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_home_and_end() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::c, Some("c".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
assert_eq!(handler.cursor_position(), 1);
|
||||||
|
|
||||||
|
// Home
|
||||||
|
let action = handler.handle_key_event(Keysym::Home, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::CursorMoved));
|
||||||
|
assert_eq!(handler.cursor_position(), 0);
|
||||||
|
|
||||||
|
// End
|
||||||
|
let action = handler.handle_key_event(Keysym::End, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::CursorMoved));
|
||||||
|
assert_eq!(handler.cursor_position(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_delete_removes_at_cursor() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::c, Some("c".to_string()), mods);
|
||||||
|
// cursor at 3, delete should be a no-op
|
||||||
|
let action = handler.handle_key_event(Keysym::Delete, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::None));
|
||||||
|
assert_eq!(handler.password_length(), 3);
|
||||||
|
|
||||||
|
// move left, delete at cursor position 2 (removes 'c')
|
||||||
|
handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
let action = handler.handle_key_event(Keysym::Delete, None, mods);
|
||||||
|
assert!(matches!(action, InputAction::PasswordChanged));
|
||||||
|
assert_eq!(handler.password_length(), 2);
|
||||||
|
assert_eq!(&*handler.password_buffer, "ab");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_insert_mid_buffer() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
let mods = Modifiers::default();
|
||||||
|
handler.handle_key_event(Keysym::a, Some("a".to_string()), mods);
|
||||||
|
handler.handle_key_event(Keysym::c, Some("c".to_string()), mods);
|
||||||
|
// Move left, insert 'b' between a and c
|
||||||
|
handler.handle_key_event(Keysym::Left, None, mods);
|
||||||
|
handler.handle_key_event(Keysym::b, Some("b".to_string()), mods);
|
||||||
|
assert_eq!(&*handler.password_buffer, "abc");
|
||||||
|
assert_eq!(handler.cursor_position(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_caps_lock_tracking() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
assert!(!handler.caps_lock());
|
||||||
|
|
||||||
|
let caps_mods = Modifiers {
|
||||||
|
caps_lock: true,
|
||||||
|
..Modifiers::default()
|
||||||
|
};
|
||||||
|
handler.handle_key_event(Keysym::a, Some("A".to_string()), caps_mods);
|
||||||
|
assert!(handler.caps_lock());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_wrong_password_timer() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
assert!(!handler.should_show_wrong_password());
|
||||||
|
|
||||||
|
handler.set_wrong_password_feedback();
|
||||||
|
assert!(handler.should_show_wrong_password());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_key_highlight_timer() {
|
||||||
|
let mut handler = InputHandler::new(test_config());
|
||||||
|
assert!(!handler.should_show_key_highlight());
|
||||||
|
|
||||||
|
handler.set_key_highlight();
|
||||||
|
assert!(handler.should_show_key_highlight());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+140
-21
@@ -24,6 +24,13 @@ pub struct LockedSurface {
|
|||||||
wayland_surface: Option<wl_surface::WlSurface>,
|
wayland_surface: Option<wl_surface::WlSurface>,
|
||||||
output: wl_output::WlOutput,
|
output: wl_output::WlOutput,
|
||||||
configured: bool,
|
configured: bool,
|
||||||
|
/// Set whenever rendered state changes (keystroke, status, clock minute,
|
||||||
|
/// animation step). update() renders only when this is set or an animation
|
||||||
|
/// is in flight, so an idle lock screen does no per-frame cairo work.
|
||||||
|
dirty: bool,
|
||||||
|
/// Last clock minute (unix-minute) we rendered, to detect %H:%M rollover.
|
||||||
|
last_minute: i64,
|
||||||
|
ctrl_held: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LockedSurface {
|
impl LockedSurface {
|
||||||
@@ -54,6 +61,9 @@ impl LockedSurface {
|
|||||||
wayland_surface: None,
|
wayland_surface: None,
|
||||||
output,
|
output,
|
||||||
configured: false,
|
configured: false,
|
||||||
|
dirty: true,
|
||||||
|
last_minute: i64::MIN,
|
||||||
|
ctrl_held: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +72,7 @@ impl LockedSurface {
|
|||||||
log::debug!("LockedSurface: Configured, starting animation");
|
log::debug!("LockedSurface: Configured, starting animation");
|
||||||
self.configured = true;
|
self.configured = true;
|
||||||
self.start_time = Instant::now();
|
self.start_time = Instant::now();
|
||||||
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if this surface matches the given Wayland surface
|
/// Check if this surface matches the given Wayland surface
|
||||||
@@ -72,22 +83,50 @@ impl LockedSurface {
|
|||||||
.is_some_and(|ws| ws.id() == surface.id())
|
.is_some_and(|ws| ws.id() == surface.id())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the surface state (called on each frame)
|
/// Update the surface state (called on each frame). Returns `true` if the
|
||||||
pub fn update(&mut self) {
|
/// surface was re-rendered and therefore needs to be committed. An idle
|
||||||
self.input_handler.update();
|
/// surface (no input, no animation, same clock minute) returns `false` and
|
||||||
|
/// does no cairo work, which keeps a locked session near-zero CPU.
|
||||||
|
pub fn update(&mut self) -> bool {
|
||||||
if !self.configured {
|
if !self.configured {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update fade animation
|
// Update fade animation
|
||||||
if self.fade_alpha < 1.0 {
|
if self.fade_alpha < 1.0 {
|
||||||
let elapsed = self.start_time.elapsed();
|
let elapsed = self.start_time.elapsed();
|
||||||
let fade_duration = std::time::Duration::from_secs_f32(self.config.fade_in);
|
let fade_duration = std::time::Duration::from_secs_f32(self.config.fade_in);
|
||||||
let new_alpha = (elapsed.as_secs_f64() / fade_duration.as_secs_f64()).min(1.0);
|
|
||||||
if (new_alpha - self.fade_alpha).abs() > 0.001 {
|
if fade_duration.is_zero() {
|
||||||
self.fade_alpha = new_alpha;
|
self.fade_alpha = 1.0;
|
||||||
self.renderer.set_fade_alpha(self.fade_alpha);
|
self.renderer.set_fade_alpha(1.0);
|
||||||
|
self.dirty = true;
|
||||||
|
} else {
|
||||||
|
// Ease-in-out cubic function
|
||||||
|
let t = (elapsed.as_secs_f64() / fade_duration.as_secs_f64()).clamp(0.0, 1.0);
|
||||||
|
let eased_t = if t < 0.5 {
|
||||||
|
4.0 * t * t * t
|
||||||
|
} else {
|
||||||
|
1.0 - (-2.0 * t + 2.0).powi(3) / 2.0
|
||||||
|
};
|
||||||
|
let new_alpha = eased_t.min(1.0);
|
||||||
|
if t >= 1.0 {
|
||||||
|
// The eased curve only approaches 1.0 asymptotically, and the
|
||||||
|
// 0.001 throttle below suppresses the tiny final steps — which
|
||||||
|
// would leave fade_alpha stuck just under 1.0 forever. Since
|
||||||
|
// `fade_alpha < 1.0` is our "still animating" signal, that would
|
||||||
|
// force a full render every frame. Snap to exactly 1.0 once the
|
||||||
|
// fade duration has elapsed so the animation cleanly completes.
|
||||||
|
if self.fade_alpha != 1.0 {
|
||||||
|
self.fade_alpha = 1.0;
|
||||||
|
self.renderer.set_fade_alpha(1.0);
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
} else if (new_alpha - self.fade_alpha).abs() > 0.001 {
|
||||||
|
self.fade_alpha = new_alpha;
|
||||||
|
self.renderer.set_fade_alpha(self.fade_alpha);
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +134,7 @@ impl LockedSurface {
|
|||||||
if self.input_handler.should_show_wrong_password() && !self.wrong_password_shown {
|
if self.input_handler.should_show_wrong_password() && !self.wrong_password_shown {
|
||||||
self.renderer.show_wrong_password();
|
self.renderer.show_wrong_password();
|
||||||
self.wrong_password_shown = true;
|
self.wrong_password_shown = true;
|
||||||
|
self.dirty = true;
|
||||||
} else if !self.input_handler.should_show_wrong_password() && self.wrong_password_shown {
|
} else if !self.input_handler.should_show_wrong_password() && self.wrong_password_shown {
|
||||||
self.wrong_password_shown = false;
|
self.wrong_password_shown = false;
|
||||||
}
|
}
|
||||||
@@ -103,25 +143,58 @@ impl LockedSurface {
|
|||||||
if self.input_handler.should_show_key_highlight() && !self.key_highlight_shown {
|
if self.input_handler.should_show_key_highlight() && !self.key_highlight_shown {
|
||||||
self.renderer.show_key_highlight();
|
self.renderer.show_key_highlight();
|
||||||
self.key_highlight_shown = true;
|
self.key_highlight_shown = true;
|
||||||
|
self.dirty = true;
|
||||||
} else if !self.input_handler.should_show_key_highlight() && self.key_highlight_shown {
|
} else if !self.input_handler.should_show_key_highlight() && self.key_highlight_shown {
|
||||||
self.key_highlight_shown = false;
|
self.key_highlight_shown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update caps lock state in renderer
|
// Update caps lock state in renderer
|
||||||
self.renderer.caps_lock = self.input_handler.caps_lock();
|
if self.renderer.caps_lock != self.input_handler.caps_lock() {
|
||||||
|
self.renderer.caps_lock = self.input_handler.caps_lock();
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Set background if available and not already applied
|
// Set background if available and not already applied
|
||||||
if !self.background_applied {
|
if !self.background_applied {
|
||||||
if let Some(ref background) = self.background {
|
if let Some(ref background) = self.background {
|
||||||
log::info!("Applying background image to renderer");
|
log::debug!("Applying background image to renderer");
|
||||||
self.renderer.set_background(background.clone());
|
self.renderer.set_background(background.clone());
|
||||||
self.background_applied = true;
|
self.background_applied = true;
|
||||||
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The clock displays %H:%M, so it only needs a redraw once per minute.
|
||||||
|
if self.config.clock {
|
||||||
|
let minute = chrono::Local::now().timestamp().div_euclid(60);
|
||||||
|
if self.last_minute != minute {
|
||||||
|
self.last_minute = minute;
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep emitting frames while an animation is in flight so it can run to
|
||||||
|
// completion even though no new event arrives.
|
||||||
|
let animating = self.fade_alpha < 1.0 || self.renderer.is_animating();
|
||||||
|
|
||||||
|
if !self.dirty && !animating {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.config.hide_password {
|
||||||
|
let length = self.input_handler.password_length();
|
||||||
|
if self.ctrl_held {
|
||||||
|
self.renderer
|
||||||
|
.peek_password(self.input_handler.password_buffer().as_str());
|
||||||
|
} else {
|
||||||
|
self.renderer.set_password_display(length);
|
||||||
|
}
|
||||||
|
}
|
||||||
self.renderer
|
self.renderer
|
||||||
.set_password_display(self.input_handler.get_display_password());
|
.set_cursor_position(self.input_handler.cursor_position());
|
||||||
self.renderer.render();
|
self.renderer.render();
|
||||||
|
self.dirty = false;
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Commit the rendered frame to the Wayland surface
|
/// Commit the rendered frame to the Wayland surface
|
||||||
@@ -154,26 +227,44 @@ impl LockedSurface {
|
|||||||
}
|
}
|
||||||
self.renderer.resize(width, height);
|
self.renderer.resize(width, height);
|
||||||
self.background_applied = false;
|
self.background_applied = false;
|
||||||
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show_wrong_password(&mut self) {
|
pub fn show_wrong_password(&mut self) {
|
||||||
|
self.renderer.clear_verifying();
|
||||||
self.input_handler.set_wrong_password_feedback();
|
self.input_handler.set_wrong_password_feedback();
|
||||||
|
self.wrong_password_shown = false;
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_verifying(&mut self) {
|
||||||
|
self.renderer.show_verifying();
|
||||||
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_key_event(
|
pub fn handle_key_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
event: smithay_client_toolkit::seat::keyboard::KeyEvent,
|
event: KeyEvent,
|
||||||
modifiers: smithay_client_toolkit::seat::keyboard::Modifiers,
|
modifiers: smithay_client_toolkit::seat::keyboard::Modifiers,
|
||||||
) -> Option<InputAction> {
|
) -> Option<InputAction> {
|
||||||
|
self.ctrl_held = modifiers.ctrl;
|
||||||
|
|
||||||
let action = self
|
let action = self
|
||||||
.input_handler
|
.input_handler
|
||||||
.handle_key_event(event.keysym, event.utf8, modifiers);
|
.handle_key_event(event.keysym, event.utf8, modifiers);
|
||||||
|
|
||||||
|
// Any key event may change the password display, cursor or caps state,
|
||||||
|
// so request a redraw on the next update().
|
||||||
|
self.dirty = true;
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
InputAction::PasswordChanged => {
|
InputAction::PasswordChanged => {
|
||||||
self.input_handler.set_key_highlight();
|
self.input_handler.set_key_highlight();
|
||||||
self.key_highlight_shown = false;
|
self.key_highlight_shown = false;
|
||||||
}
|
}
|
||||||
|
InputAction::PasswordCleared => {
|
||||||
|
self.renderer.show_cleared_feedback();
|
||||||
|
}
|
||||||
InputAction::SubmitPassword(_) => {
|
InputAction::SubmitPassword(_) => {
|
||||||
self.input_handler.set_key_highlight();
|
self.input_handler.set_key_highlight();
|
||||||
self.key_highlight_shown = false;
|
self.key_highlight_shown = false;
|
||||||
@@ -195,10 +286,21 @@ impl LockedSurface {
|
|||||||
pub fn set_background(&mut self, surface: ImageSurface) {
|
pub fn set_background(&mut self, surface: ImageSurface) {
|
||||||
self.background = Some(surface);
|
self.background = Some(surface);
|
||||||
self.background_applied = false;
|
self.background_applied = false;
|
||||||
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_system_status(&mut self, status: SystemStatus) {
|
pub fn set_system_status(&mut self, status: SystemStatus) {
|
||||||
self.renderer.system_status = status;
|
if self.renderer.system_status != status {
|
||||||
|
self.renderer.system_status = status;
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_ctrl_held(&mut self, held: bool) {
|
||||||
|
if self.ctrl_held != held {
|
||||||
|
self.ctrl_held = held;
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,12 +327,6 @@ impl LockManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self) {
|
|
||||||
for surface in &mut self.surfaces {
|
|
||||||
surface.update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn surface_count(&self) -> usize {
|
pub fn surface_count(&self) -> usize {
|
||||||
self.surfaces.len()
|
self.surfaces.len()
|
||||||
}
|
}
|
||||||
@@ -256,12 +352,35 @@ impl LockManager {
|
|||||||
let mut action = None;
|
let mut action = None;
|
||||||
for surface in &mut self.surfaces {
|
for surface in &mut self.surfaces {
|
||||||
if let Some(a) = surface.handle_key_event(event.clone(), modifiers) {
|
if let Some(a) = surface.handle_key_event(event.clone(), modifiers) {
|
||||||
action = Some(a);
|
if let crate::input::InputAction::SubmitPassword(p) = &a {
|
||||||
|
if !p.is_empty() {
|
||||||
|
return Some(a);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
action = Some(a);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action
|
action
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_ctrl_held(&mut self, held: bool) {
|
||||||
|
for surface in &mut self.surfaces {
|
||||||
|
surface.set_ctrl_held(held);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remove_surface_by_output(&mut self, output: &wl_output::WlOutput) -> Option<usize> {
|
||||||
|
use wayland_client::Proxy;
|
||||||
|
let output_id = Proxy::id(output);
|
||||||
|
let idx = self
|
||||||
|
.surfaces
|
||||||
|
.iter()
|
||||||
|
.position(|s| Proxy::id(s.output()) == output_id)?;
|
||||||
|
self.surfaces.remove(idx);
|
||||||
|
Some(idx)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_system_status(&mut self, status: SystemStatus) {
|
pub fn set_system_status(&mut self, status: SystemStatus) {
|
||||||
for surface in &mut self.surfaces {
|
for surface in &mut self.surfaces {
|
||||||
surface.set_system_status(status.clone());
|
surface.set_system_status(status.clone());
|
||||||
|
|||||||
+269
-80
@@ -35,6 +35,7 @@ use smithay_client_toolkit::{
|
|||||||
registry_handlers,
|
registry_handlers,
|
||||||
seat::{
|
seat::{
|
||||||
keyboard::{KeyEvent, KeyboardHandler, Modifiers},
|
keyboard::{KeyEvent, KeyboardHandler, Modifiers},
|
||||||
|
pointer::{PointerEvent, PointerEventKind, PointerHandler},
|
||||||
SeatHandler, SeatState,
|
SeatHandler, SeatState,
|
||||||
},
|
},
|
||||||
session_lock::{
|
session_lock::{
|
||||||
@@ -47,21 +48,40 @@ use smithay_client_toolkit::{
|
|||||||
static FILE_LOGGER: std::sync::LazyLock<std::sync::Mutex<Option<std::fs::File>>> =
|
static FILE_LOGGER: std::sync::LazyLock<std::sync::Mutex<Option<std::fs::File>>> =
|
||||||
std::sync::LazyLock::new(|| std::sync::Mutex::new(None));
|
std::sync::LazyLock::new(|| std::sync::Mutex::new(None));
|
||||||
|
|
||||||
fn setup_file_logging(_config: &Config) {
|
fn setup_file_logging(config: &Config) {
|
||||||
let log_path = std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()) + "/.rustlock.log";
|
if let Some(ref path) = config.log_path {
|
||||||
|
match OpenOptions::new()
|
||||||
match OpenOptions::new()
|
.create(true)
|
||||||
.create(true)
|
.write(true)
|
||||||
.write(true)
|
.truncate(true)
|
||||||
.truncate(true)
|
.open(path)
|
||||||
.open(&log_path)
|
{
|
||||||
{
|
Ok(file) => {
|
||||||
Ok(file) => {
|
*FILE_LOGGER.lock().unwrap() = Some(file);
|
||||||
*FILE_LOGGER.lock().unwrap() = Some(file);
|
eprintln!("Logging to: {}", path.display());
|
||||||
eprintln!("Logging to: {}", log_path);
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to open log file {}: {}", path.display(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
} else if config.log_file {
|
||||||
eprintln!("Failed to open log file {}: {}", log_path, e);
|
let default_path = std::path::PathBuf::from(
|
||||||
|
std::env::var("HOME").unwrap_or_else(|_| "/tmp".to_string()),
|
||||||
|
)
|
||||||
|
.join(".rustlock.log");
|
||||||
|
match OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(&default_path)
|
||||||
|
{
|
||||||
|
Ok(file) => {
|
||||||
|
*FILE_LOGGER.lock().unwrap() = Some(file);
|
||||||
|
eprintln!("Logging to: {}", default_path.display());
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("Failed to open log file {}: {}", default_path.display(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,11 +124,14 @@ impl log::Log for DualLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct WaylandLock {
|
struct WaylandLock {
|
||||||
|
conn: Connection,
|
||||||
loop_handle: LoopHandle<'static, Self>,
|
loop_handle: LoopHandle<'static, Self>,
|
||||||
lock_manager: Arc<Mutex<LockManager>>,
|
lock_manager: Arc<Mutex<LockManager>>,
|
||||||
config: Config,
|
config: Config,
|
||||||
ctrlc_exit: Arc<std::sync::atomic::AtomicBool>,
|
ctrlc_exit: Arc<std::sync::atomic::AtomicBool>,
|
||||||
auth_tx: Option<calloop::channel::Sender<Zeroizing<String>>>,
|
auth_tx: Option<calloop::channel::Sender<(Zeroizing<String>, u64)>>,
|
||||||
|
auth_seq: u64,
|
||||||
|
auth_pending_seq: Option<u64>,
|
||||||
compositor_state: CompositorState,
|
compositor_state: CompositorState,
|
||||||
output_state: OutputState,
|
output_state: OutputState,
|
||||||
registry_state: RegistryState,
|
registry_state: RegistryState,
|
||||||
@@ -123,9 +146,9 @@ struct WaylandLock {
|
|||||||
captured_backgrounds: Vec<Option<cairo::ImageSurface>>,
|
captured_backgrounds: Vec<Option<cairo::ImageSurface>>,
|
||||||
pending_screenshots: usize,
|
pending_screenshots: usize,
|
||||||
exit: bool,
|
exit: bool,
|
||||||
unlocking: bool,
|
|
||||||
screenshot_manager: Option<ScreenshotManager>,
|
screenshot_manager: Option<ScreenshotManager>,
|
||||||
grace_until: Option<Instant>,
|
grace_until: Option<Instant>,
|
||||||
|
auth_pending_at: Option<Instant>,
|
||||||
system_manager: Arc<SystemManager>,
|
system_manager: Arc<SystemManager>,
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
current_layout: u32,
|
current_layout: u32,
|
||||||
@@ -133,21 +156,29 @@ struct WaylandLock {
|
|||||||
|
|
||||||
impl WaylandLock {
|
impl WaylandLock {
|
||||||
fn handle_auth_result(&mut self, success: bool) {
|
fn handle_auth_result(&mut self, success: bool) {
|
||||||
// Clear grace period on any auth result
|
// Clear grace period and auth pending on any auth result
|
||||||
self.grace_until = None;
|
self.grace_until = None;
|
||||||
|
self.auth_pending_at = None;
|
||||||
|
self.auth_pending_seq = None;
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
log::info!("✅ Authentication successful - unlocking session");
|
log::info!("✅ Authentication successful - unlocking session");
|
||||||
|
// ext-session-lock-v1 recommends destroying lock surfaces before
|
||||||
|
// issuing unlock_and_destroy. With multiple outputs Hyprland
|
||||||
|
// otherwise treats the unlock as a client crash and shows its
|
||||||
|
// failsafe screen.
|
||||||
|
self.lock_surfaces.clear();
|
||||||
if let Some(session_lock) = &self.session_lock {
|
if let Some(session_lock) = &self.session_lock {
|
||||||
session_lock.unlock();
|
session_lock.unlock();
|
||||||
self.unlocking = true;
|
let _ = self.conn.flush();
|
||||||
log::debug!("Unlock requested - waiting for compositor finished event");
|
self.exit = true;
|
||||||
|
log::info!("Unlock requested - exiting");
|
||||||
} else {
|
} else {
|
||||||
log::error!("No session_lock available to unlock!");
|
log::error!("No session_lock available to unlock!");
|
||||||
self.exit = true;
|
self.exit = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("❌ Authentication failed - wrong password");
|
log::error!("❌ Authentication failed - wrong password");
|
||||||
if let Ok(mut lock_manager) = self.lock_manager.lock() {
|
if let Ok(mut lock_manager) = self.lock_manager.lock() {
|
||||||
for surface in &mut lock_manager.surfaces {
|
for surface in &mut lock_manager.surfaces {
|
||||||
surface.show_wrong_password();
|
surface.show_wrong_password();
|
||||||
@@ -186,17 +217,17 @@ impl WaylandLock {
|
|||||||
}
|
}
|
||||||
Keysym::F1 => {
|
Keysym::F1 => {
|
||||||
self.system_manager
|
self.system_manager
|
||||||
.send_command(system::SystemCommand::Suspend);
|
.send_command(system::BackendCommand::Suspend);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Keysym::F2 => {
|
Keysym::F2 => {
|
||||||
self.system_manager
|
self.system_manager
|
||||||
.send_command(system::SystemCommand::Reboot);
|
.send_command(system::BackendCommand::Reboot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Keysym::F3 => {
|
Keysym::F3 => {
|
||||||
self.system_manager
|
self.system_manager
|
||||||
.send_command(system::SystemCommand::PowerOff);
|
.send_command(system::BackendCommand::PowerOff);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -213,30 +244,44 @@ impl WaylandLock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if event.keysym == Keysym::Return {
|
if event.keysym == Keysym::Return {
|
||||||
|
// Debounce: skip if auth is already pending (user pressed Enter twice)
|
||||||
|
if self.auth_pending_at.is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log::info!("Enter pressed - submitting password");
|
log::info!("Enter pressed - submitting password");
|
||||||
if let Ok(mut lock_manager) = self.lock_manager.lock() {
|
let password: Option<Zeroizing<String>> = self
|
||||||
let mut password = Zeroizing::new(String::new());
|
.lock_manager
|
||||||
let modifiers = self.modifiers;
|
.lock()
|
||||||
for surface in &mut lock_manager.surfaces {
|
.ok()
|
||||||
if let Some(InputAction::SubmitPassword(p)) =
|
.and_then(|mut lm| lm.handle_key_event(event, self.modifiers))
|
||||||
surface.handle_key_event(event.clone(), modifiers)
|
.and_then(|action| {
|
||||||
{
|
if let InputAction::SubmitPassword(p) = action {
|
||||||
password = p;
|
(!p.is_empty()).then_some(p)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(password) = password {
|
||||||
|
self.auth_seq += 1;
|
||||||
|
self.auth_pending_at = Some(Instant::now());
|
||||||
|
self.auth_pending_seq = Some(self.auth_seq);
|
||||||
|
// Show verifying feedback on ALL surfaces BEFORE sending to PAM.
|
||||||
|
if let Ok(mut lock_manager) = self.lock_manager.lock() {
|
||||||
|
for surface in &mut lock_manager.surfaces {
|
||||||
|
surface.show_verifying();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !password.is_empty() {
|
if let Some(tx) = &self.auth_tx {
|
||||||
if let Some(tx) = &self.auth_tx {
|
let _ = tx.send((password, self.auth_seq));
|
||||||
let _ = tx.send(password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let modifiers = self.modifiers;
|
self.lock_manager
|
||||||
let _action = self
|
|
||||||
.lock_manager
|
|
||||||
.lock()
|
.lock()
|
||||||
.map(|mut lm| lm.handle_key_event(event, modifiers))
|
.ok()
|
||||||
.unwrap_or(None);
|
.and_then(|mut lm| lm.handle_key_event(event, self.modifiers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,6 +293,8 @@ impl ProvidesRegistryState for WaylandLock {
|
|||||||
registry_handlers![OutputState, SeatState];
|
registry_handlers![OutputState, SeatState];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WaylandLock {}
|
||||||
|
|
||||||
impl CompositorHandler for WaylandLock {
|
impl CompositorHandler for WaylandLock {
|
||||||
fn scale_factor_changed(
|
fn scale_factor_changed(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -295,9 +342,61 @@ impl OutputHandler for WaylandLock {
|
|||||||
fn output_state(&mut self) -> &mut OutputState {
|
fn output_state(&mut self) -> &mut OutputState {
|
||||||
&mut self.output_state
|
&mut self.output_state
|
||||||
}
|
}
|
||||||
fn new_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {}
|
fn new_output(&mut self, _conn: &Connection, qh: &QueueHandle<Self>, output: WlOutput) {
|
||||||
fn update_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {}
|
// If we are already locked, we must create a lock surface for this newly
|
||||||
fn output_destroyed(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
|
// available output. This happens e.g. when a monitor powers back on after
|
||||||
|
// "niri msg action power-off-monitors" — niri re-advertises the output and
|
||||||
|
// the compositor requires a lock surface on every output or it shows a
|
||||||
|
// compositor-defined fallback (typically a solid red/black screen).
|
||||||
|
if let Some(session_lock) = &self.session_lock {
|
||||||
|
let surface = self.compositor_state.create_surface(qh);
|
||||||
|
let (width, height) = self.get_output_dimensions(&output);
|
||||||
|
let lock_surface = session_lock.create_lock_surface(surface.clone(), &output, qh);
|
||||||
|
self.lock_surfaces.push(lock_surface);
|
||||||
|
if !self.outputs.contains(&output) {
|
||||||
|
self.outputs.push(output.clone());
|
||||||
|
}
|
||||||
|
if let Ok(mut lm) = self.lock_manager.lock() {
|
||||||
|
lm.add_surface(width, height, output);
|
||||||
|
let count = lm.surface_count();
|
||||||
|
if let Some(ls) = lm.get_surface_mut(count - 1) {
|
||||||
|
ls.set_wayland_surface(surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log::info!("Created lock surface for newly available output");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn update_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
|
||||||
|
// Dimension changes while locked are handled by the compositor sending a configure
|
||||||
|
// event on the lock surface, which the SessionLockHandler::configure callback
|
||||||
|
// already processes via locked_surface.resize().
|
||||||
|
}
|
||||||
|
fn output_destroyed(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, output: WlOutput) {
|
||||||
|
// Clean up the lock surface and associated state for this output.
|
||||||
|
// This happens e.g. when a monitor is powered off with its physical power switch.
|
||||||
|
// When the monitor comes back on, new_output() will fire and recreate everything.
|
||||||
|
//
|
||||||
|
// outputs and captured_backgrounds are kept at the same indices, so we remove
|
||||||
|
// from both using the same position.
|
||||||
|
let output_id = Proxy::id(&output);
|
||||||
|
if let Some(idx) = self.outputs.iter().position(|o| Proxy::id(o) == output_id) {
|
||||||
|
self.outputs.remove(idx);
|
||||||
|
if idx < self.captured_backgrounds.len() {
|
||||||
|
self.captured_backgrounds.remove(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// lock_manager.surfaces and lock_surfaces are built in tandem and share indices,
|
||||||
|
// so the index returned from the lock_manager removal applies to lock_surfaces too.
|
||||||
|
if let Ok(mut lm) = self.lock_manager.lock() {
|
||||||
|
if let Some(idx) = lm.remove_surface_by_output(&output) {
|
||||||
|
if idx < self.lock_surfaces.len() {
|
||||||
|
drop(self.lock_surfaces.remove(idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log::info!("Removed lock surface for destroyed output");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +508,9 @@ impl KeyboardHandler for WaylandLock {
|
|||||||
) {
|
) {
|
||||||
self.modifiers = modifiers;
|
self.modifiers = modifiers;
|
||||||
self.current_layout = layout;
|
self.current_layout = layout;
|
||||||
|
if let Ok(mut lock_manager) = self.lock_manager.lock() {
|
||||||
|
lock_manager.set_ctrl_held(modifiers.ctrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,6 +543,9 @@ impl SeatHandler for WaylandLock {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if capability == smithay_client_toolkit::seat::Capability::Pointer {
|
||||||
|
let _ = self.seat_state.get_pointer(qh, &seat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn remove_capability(
|
fn remove_capability(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -488,7 +593,10 @@ impl Dispatch<ZwlrScreencopyFrameV1, CaptureData> for WaylandLock {
|
|||||||
height,
|
height,
|
||||||
stride,
|
stride,
|
||||||
} => {
|
} => {
|
||||||
let format = format.into_result().unwrap();
|
let Ok(format) = format.into_result() else {
|
||||||
|
log::error!("Screencopy: invalid buffer format, skipping capture");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let mut info = data.info.lock().unwrap();
|
let mut info = data.info.lock().unwrap();
|
||||||
*info = Some(screenshot::BufferInfo {
|
*info = Some(screenshot::BufferInfo {
|
||||||
@@ -517,7 +625,11 @@ impl Dispatch<ZwlrScreencopyFrameV1, CaptureData> for WaylandLock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Flags { flags } => {
|
Event::Flags { flags } => {
|
||||||
*data.flags.lock().unwrap() = Some(flags.into_result().unwrap());
|
if let Ok(f) = flags.into_result() {
|
||||||
|
*data.flags.lock().unwrap() = Some(f);
|
||||||
|
} else {
|
||||||
|
log::error!("Screencopy: invalid flags, skipping");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Event::Ready { .. } => {
|
Event::Ready { .. } => {
|
||||||
log::info!("Screencopy: Ready for output {}", data.output_idx);
|
log::info!("Screencopy: Ready for output {}", data.output_idx);
|
||||||
@@ -537,7 +649,9 @@ impl Dispatch<ZwlrScreencopyFrameV1, CaptureData> for WaylandLock {
|
|||||||
};
|
};
|
||||||
if let Ok(surface) = mgr.buffer_to_surface(handle, &mut pool) {
|
if let Ok(surface) = mgr.buffer_to_surface(handle, &mut pool) {
|
||||||
let mut ss = Screenshot::new(surface);
|
let mut ss = Screenshot::new(surface);
|
||||||
let _ = ss.apply_effects(&state.config);
|
if let Err(e) = ss.apply_effects(&state.config) {
|
||||||
|
log::error!("Failed to apply effects to screenshot {}: {e}", data.output_idx);
|
||||||
|
}
|
||||||
if data.output_idx < state.captured_backgrounds.len() {
|
if data.output_idx < state.captured_backgrounds.len() {
|
||||||
state.captured_backgrounds[data.output_idx] = Some(ss.into_inner());
|
state.captured_backgrounds[data.output_idx] = Some(ss.into_inner());
|
||||||
}
|
}
|
||||||
@@ -571,6 +685,43 @@ impl wayland_client::Dispatch<wayland_client::protocol::wl_registry::WlRegistry,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PointerHandler for WaylandLock {
|
||||||
|
fn pointer_frame(
|
||||||
|
&mut self,
|
||||||
|
_conn: &Connection,
|
||||||
|
_qh: &QueueHandle<Self>,
|
||||||
|
_pointer: &wayland_client::protocol::wl_pointer::WlPointer,
|
||||||
|
events: &[PointerEvent],
|
||||||
|
) {
|
||||||
|
for event in events {
|
||||||
|
if let PointerEventKind::Press { button, .. } = event.kind {
|
||||||
|
if button == 0x110 {
|
||||||
|
let (x, y) = event.position;
|
||||||
|
if let Ok(lm) = self.lock_manager.lock() {
|
||||||
|
for surface in &lm.surfaces {
|
||||||
|
if surface.matches_surface(&event.surface) {
|
||||||
|
for (action, rx, ry, rw, rh) in &surface.renderer.media_rects {
|
||||||
|
if x >= *rx && x <= rx + rw && y >= *ry && y <= ry + rh {
|
||||||
|
match *action {
|
||||||
|
"play_pause" => self.system_manager.media_play_pause(),
|
||||||
|
"stop" => self.system_manager.media_stop(),
|
||||||
|
"next" => self.system_manager.media_next(),
|
||||||
|
"prev" => self.system_manager.media_prev(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
smithay_client_toolkit::delegate_pointer!(WaylandLock);
|
||||||
smithay_client_toolkit::delegate_compositor!(WaylandLock);
|
smithay_client_toolkit::delegate_compositor!(WaylandLock);
|
||||||
smithay_client_toolkit::delegate_output!(WaylandLock);
|
smithay_client_toolkit::delegate_output!(WaylandLock);
|
||||||
smithay_client_toolkit::delegate_shm!(WaylandLock);
|
smithay_client_toolkit::delegate_shm!(WaylandLock);
|
||||||
@@ -582,9 +733,15 @@ wayland_client::delegate_noop!(WaylandLock: ignore wayland_client::protocol::wl_
|
|||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let config = Config::load();
|
let config = Config::load();
|
||||||
|
|
||||||
setup_file_logging(&config);
|
setup_file_logging(&config);
|
||||||
static LOGGER: DualLogger = DualLogger;
|
static LOGGER: DualLogger = DualLogger;
|
||||||
log::set_logger(&LOGGER).map(|()| log::set_max_level(log::LevelFilter::Debug))?;
|
let max_level = if config.debug {
|
||||||
|
log::LevelFilter::Debug
|
||||||
|
} else {
|
||||||
|
log::LevelFilter::Info
|
||||||
|
};
|
||||||
|
log::set_logger(&LOGGER).map(|()| log::set_max_level(max_level))?;
|
||||||
|
|
||||||
log::info!("Starting rustlock v{}", env!("CARGO_PKG_VERSION"));
|
log::info!("Starting rustlock v{}", env!("CARGO_PKG_VERSION"));
|
||||||
#[allow(clippy::arc_with_non_send_sync)]
|
#[allow(clippy::arc_with_non_send_sync)]
|
||||||
@@ -598,13 +755,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let shm_state = Shm::bind(&globals, &qh).map_err(|_| "wl_shm not supported")?;
|
let shm_state = Shm::bind(&globals, &qh).map_err(|_| "wl_shm not supported")?;
|
||||||
|
|
||||||
let system_manager = Arc::new(SystemManager::new());
|
let system_manager = Arc::new(SystemManager::new(&config));
|
||||||
|
|
||||||
let (auth_tx_actual, auth_feedback_rx_actual) = match auth::create_and_run_auth_loop() {
|
let (auth_tx_actual, auth_feedback_rx_actual) =
|
||||||
|
match auth::create_and_run_auth_loop(config.pam_service.clone()) {
|
||||||
Some(channels) => channels,
|
Some(channels) => channels,
|
||||||
None => {
|
None => {
|
||||||
log::error!("Failed to initialize authentication. This usually means PAM is not configured correctly.");
|
log::error!("Failed to initialize authentication. This usually means PAM is not configured correctly.");
|
||||||
log::error!("Please ensure you have a PAM service file at /etc/pam.d/rustlock");
|
log::error!("Please ensure you have a PAM service file at /etc/pam.d/{}", config.pam_service);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -617,6 +775,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let pool = SlotPool::new(1, &shm_state)?;
|
let pool = SlotPool::new(1, &shm_state)?;
|
||||||
|
|
||||||
let mut state = WaylandLock {
|
let mut state = WaylandLock {
|
||||||
|
conn: conn.clone(),
|
||||||
loop_handle: event_loop.handle(),
|
loop_handle: event_loop.handle(),
|
||||||
lock_manager: lock_manager.clone(),
|
lock_manager: lock_manager.clone(),
|
||||||
config: config.clone(),
|
config: config.clone(),
|
||||||
@@ -636,9 +795,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
captured_backgrounds: Vec::new(),
|
captured_backgrounds: Vec::new(),
|
||||||
pending_screenshots: 0,
|
pending_screenshots: 0,
|
||||||
exit: false,
|
exit: false,
|
||||||
unlocking: false,
|
|
||||||
screenshot_manager: ScreenshotManager::new(&globals, &qh).ok(),
|
screenshot_manager: ScreenshotManager::new(&globals, &qh).ok(),
|
||||||
grace_until: None,
|
grace_until: None,
|
||||||
|
auth_pending_at: None,
|
||||||
|
auth_seq: 0,
|
||||||
|
auth_pending_seq: None,
|
||||||
system_manager: system_manager.clone(),
|
system_manager: system_manager.clone(),
|
||||||
modifiers: Modifiers::default(),
|
modifiers: Modifiers::default(),
|
||||||
current_layout: 0,
|
current_layout: 0,
|
||||||
@@ -652,31 +813,41 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
if let Ok(img) = image::open(image_path) {
|
if let Ok(img) = image::open(image_path) {
|
||||||
let img = img.to_rgba8();
|
let img = img.to_rgba8();
|
||||||
let (w, h) = img.dimensions();
|
let (w, h) = img.dimensions();
|
||||||
let mut surface =
|
if let Ok(mut surface) =
|
||||||
cairo::ImageSurface::create(cairo::Format::ARgb32, w as i32, h as i32).unwrap();
|
cairo::ImageSurface::create(cairo::Format::ARgb32, w as i32, h as i32)
|
||||||
{
|
{
|
||||||
let mut surface_data = surface.data().unwrap();
|
let image_ok = {
|
||||||
for y in 0..h {
|
if let Ok(mut surface_data) = surface.data() {
|
||||||
for x in 0..w {
|
for y in 0..h {
|
||||||
let pixel = img.get_pixel(x, y);
|
for x in 0..w {
|
||||||
let idx = ((y * w + x) * 4) as usize;
|
let pixel = img.get_pixel(x, y);
|
||||||
surface_data[idx] = pixel[2]; // B
|
let idx = ((y * w + x) * 4) as usize;
|
||||||
surface_data[idx + 1] = pixel[1]; // G
|
surface_data[idx] = pixel[2];
|
||||||
surface_data[idx + 2] = pixel[0]; // R
|
surface_data[idx + 1] = pixel[1];
|
||||||
surface_data[idx + 3] = pixel[3]; // A
|
surface_data[idx + 2] = pixel[0];
|
||||||
|
surface_data[idx + 3] = pixel[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to get background image surface data");
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
if image_ok {
|
||||||
|
let mut ss = Screenshot::new(surface);
|
||||||
|
if let Err(e) = ss.apply_effects(&state.config) {
|
||||||
|
log::error!("Failed to apply effects to custom background image: {e}");
|
||||||
|
}
|
||||||
|
let surface = ss.into_inner();
|
||||||
|
|
||||||
|
let num_outputs = state.output_state.outputs().count();
|
||||||
|
state.captured_backgrounds = vec![Some(surface); num_outputs];
|
||||||
|
state.config.screenshots = false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to create Cairo surface for background image");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ss = Screenshot::new(surface);
|
|
||||||
let _ = ss.apply_effects(&state.config);
|
|
||||||
let surface = ss.into_inner();
|
|
||||||
|
|
||||||
let num_outputs = state.output_state.outputs().count();
|
|
||||||
state.captured_backgrounds = vec![Some(surface); num_outputs];
|
|
||||||
|
|
||||||
// Disable screenshots if image was successfully loaded
|
|
||||||
state.config.screenshots = false;
|
|
||||||
} else {
|
} else {
|
||||||
log::error!(
|
log::error!(
|
||||||
"Failed to load custom background image from {:?}",
|
"Failed to load custom background image from {:?}",
|
||||||
@@ -710,10 +881,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
event_loop
|
event_loop
|
||||||
.handle()
|
.handle()
|
||||||
.insert_source(auth_feedback_rx_actual, |event, _, state| {
|
.insert_source(auth_feedback_rx_actual, |event, _, state| {
|
||||||
if let calloop::channel::Event::Msg(success) = event {
|
if let calloop::channel::Event::Msg((success, seq)) = event {
|
||||||
state.handle_auth_result(success);
|
// Ignore stale auth results from previous requests (e.g. after timeout or retry).
|
||||||
if success {
|
if state.auth_pending_seq == Some(seq) {
|
||||||
state.lock_surfaces.clear();
|
state.handle_auth_result(success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
@@ -727,8 +898,17 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if state.unlocking {
|
// Auth timeout: if PAM thread doesn't respond within config.auth_timeout ms,
|
||||||
return calloop::timer::TimeoutAction::ToDuration(Duration::from_millis(100));
|
// treat as auth failure so the user gets feedback instead of hanging forever.
|
||||||
|
if state.auth_pending_seq.is_some() {
|
||||||
|
if let Some(at) = state.auth_pending_at {
|
||||||
|
if Instant::now().duration_since(at) >= Duration::from_millis(state.config.auth_timeout) {
|
||||||
|
log::warn!("Authentication timed out after {} ms", state.config.auth_timeout);
|
||||||
|
// Clear pending seq so the eventual PAM result is ignored as stale
|
||||||
|
state.auth_pending_seq = None;
|
||||||
|
state.handle_auth_result(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut status = state.system_manager.get_status();
|
let mut status = state.system_manager.get_status();
|
||||||
@@ -736,9 +916,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
if let Ok(mut lm) = state.lock_manager.lock() {
|
if let Ok(mut lm) = state.lock_manager.lock() {
|
||||||
lm.set_system_status(status);
|
lm.set_system_status(status);
|
||||||
lm.update();
|
// Only commit surfaces that actually re-rendered this tick. An idle
|
||||||
|
// lock screen renders nothing and commits nothing.
|
||||||
for surface in &mut lm.surfaces {
|
for surface in &mut lm.surfaces {
|
||||||
let _ = surface.commit(&mut state.pool);
|
if surface.update() {
|
||||||
|
let _ = surface.commit(&mut state.pool);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if state.exit {
|
if state.exit {
|
||||||
@@ -814,6 +997,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
event_loop.dispatch(Duration::from_millis(16), &mut state)?;
|
event_loop.dispatch(Duration::from_millis(16), &mut state)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After unlock_and_destroy the compositor sends keyboard/pointer leave and
|
||||||
|
// delete_id events that must be processed before we disconnect, otherwise
|
||||||
|
// Hyprland treats the disconnect as a client crash and shows its failsafe
|
||||||
|
// screen (only reproducible on multi-output setups).
|
||||||
|
let _ = state.conn.roundtrip();
|
||||||
|
|
||||||
log::info!("Exiting rustlock");
|
log::info!("Exiting rustlock");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
-821
@@ -1,821 +0,0 @@
|
|||||||
use cairo::{Context, Format, ImageSurface};
|
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use crate::config::Config;
|
|
||||||
use crate::system::SystemStatus;
|
|
||||||
|
|
||||||
/// Cairo-based renderer for the lock screen
|
|
||||||
pub struct Renderer {
|
|
||||||
width: i32,
|
|
||||||
height: i32,
|
|
||||||
config: Config,
|
|
||||||
surface: ImageSurface,
|
|
||||||
context: Context,
|
|
||||||
fade_alpha: f64,
|
|
||||||
wrong_password_shown: bool,
|
|
||||||
key_highlight_shown: bool,
|
|
||||||
wrong_password_start: Option<Instant>,
|
|
||||||
key_highlight_start: Option<Instant>,
|
|
||||||
key_highlight_angle: f64,
|
|
||||||
background: Option<ImageSurface>,
|
|
||||||
password_display: String,
|
|
||||||
uptime_cache: String,
|
|
||||||
last_uptime_update: Option<Instant>,
|
|
||||||
pub caps_lock: bool,
|
|
||||||
pub system_status: SystemStatus,
|
|
||||||
media_art_surface: Option<ImageSurface>,
|
|
||||||
last_art_url: Option<String>,
|
|
||||||
wifi_icon_surface: Option<ImageSurface>,
|
|
||||||
bluetooth_icon_surface: Option<ImageSurface>,
|
|
||||||
battery_icon_surface: Option<ImageSurface>,
|
|
||||||
media_prev_icon_surface: Option<ImageSurface>,
|
|
||||||
media_stop_icon_surface: Option<ImageSurface>,
|
|
||||||
media_play_icon_surface: Option<ImageSurface>,
|
|
||||||
media_next_icon_surface: Option<ImageSurface>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Renderer {
|
|
||||||
/// Create a new renderer with the given dimensions and configuration
|
|
||||||
pub fn new(width: i32, height: i32, config: Config) -> Self {
|
|
||||||
log::debug!("Renderer::new({}, {}, ...) called", width, height);
|
|
||||||
let surface = ImageSurface::create(Format::ARgb32, width, height)
|
|
||||||
.expect("Failed to create Cairo surface");
|
|
||||||
let context = Context::new(&surface).expect("Failed to create Cairo context");
|
|
||||||
|
|
||||||
let mut renderer = Self {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
config: config.clone(),
|
|
||||||
surface,
|
|
||||||
context,
|
|
||||||
fade_alpha: 0.0,
|
|
||||||
wrong_password_shown: false,
|
|
||||||
key_highlight_shown: false,
|
|
||||||
wrong_password_start: None,
|
|
||||||
key_highlight_start: None,
|
|
||||||
key_highlight_angle: 0.0,
|
|
||||||
background: None,
|
|
||||||
password_display: String::new(),
|
|
||||||
uptime_cache: String::new(),
|
|
||||||
last_uptime_update: None,
|
|
||||||
caps_lock: false,
|
|
||||||
system_status: SystemStatus::default(),
|
|
||||||
media_art_surface: None,
|
|
||||||
last_art_url: None,
|
|
||||||
wifi_icon_surface: None,
|
|
||||||
bluetooth_icon_surface: None,
|
|
||||||
battery_icon_surface: None,
|
|
||||||
media_prev_icon_surface: None,
|
|
||||||
media_stop_icon_surface: None,
|
|
||||||
media_play_icon_surface: None,
|
|
||||||
media_next_icon_surface: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
renderer.load_icons();
|
|
||||||
renderer
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_icons(&mut self) {
|
|
||||||
if let Some(ref path) = self.config.wifi_icon {
|
|
||||||
self.wifi_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
if let Some(ref path) = self.config.bluetooth_icon {
|
|
||||||
self.bluetooth_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
if let Some(ref path) = self.config.battery_icon {
|
|
||||||
self.battery_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
if let Some(ref path) = self.config.media_prev_icon {
|
|
||||||
self.media_prev_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
if let Some(ref path) = self.config.media_stop_icon {
|
|
||||||
self.media_stop_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
if let Some(ref path) = self.config.media_play_icon {
|
|
||||||
self.media_play_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
if let Some(ref path) = self.config.media_next_icon {
|
|
||||||
self.media_next_icon_surface = self.load_icon(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_icon(&self, identifier: &str) -> Option<ImageSurface> {
|
|
||||||
let path = if identifier.starts_with('/') {
|
|
||||||
std::path::PathBuf::from(identifier)
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(pixbuf) = gdk_pixbuf::Pixbuf::from_file(&path) {
|
|
||||||
let w = pixbuf.width();
|
|
||||||
let h = pixbuf.height();
|
|
||||||
let mut surface = ImageSurface::create(Format::ARgb32, w, h).ok()?;
|
|
||||||
{
|
|
||||||
let mut surface_data = surface.data().ok()?;
|
|
||||||
let pix_data = unsafe { pixbuf.pixels() };
|
|
||||||
let n_channels = pixbuf.n_channels();
|
|
||||||
let rowstride = pixbuf.rowstride() as usize;
|
|
||||||
|
|
||||||
for y in 0..h as usize {
|
|
||||||
for x in 0..w as usize {
|
|
||||||
let pix_idx = y * rowstride + x * n_channels as usize;
|
|
||||||
let surf_idx = (y * w as usize + x) * 4;
|
|
||||||
|
|
||||||
if n_channels == 4 {
|
|
||||||
surface_data[surf_idx] = pix_data[pix_idx + 2];
|
|
||||||
surface_data[surf_idx + 1] = pix_data[pix_idx + 1];
|
|
||||||
surface_data[surf_idx + 2] = pix_data[pix_idx];
|
|
||||||
surface_data[surf_idx + 3] = pix_data[pix_idx + 3];
|
|
||||||
} else if n_channels == 3 {
|
|
||||||
surface_data[surf_idx] = pix_data[pix_idx + 2];
|
|
||||||
surface_data[surf_idx + 1] = pix_data[pix_idx + 1];
|
|
||||||
surface_data[surf_idx + 2] = pix_data[pix_idx];
|
|
||||||
surface_data[surf_idx + 3] = 255;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(surface)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resize the renderer to new dimensions
|
|
||||||
pub fn resize(&mut self, width: i32, height: i32) {
|
|
||||||
log::debug!("Renderer::resize({}, {}) called", width, height);
|
|
||||||
self.width = width;
|
|
||||||
self.height = height;
|
|
||||||
|
|
||||||
self.surface = ImageSurface::create(Format::ARgb32, width, height)
|
|
||||||
.expect("Failed to create Cairo surface");
|
|
||||||
self.context = Context::new(&self.surface).expect("Failed to create Cairo context");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the background image (screenshot)
|
|
||||||
pub fn set_background(&mut self, background: ImageSurface) {
|
|
||||||
self.background = Some(background);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the fade-in alpha value (0.0 to 1.0)
|
|
||||||
pub fn set_fade_alpha(&mut self, alpha: f64) {
|
|
||||||
self.fade_alpha = alpha.clamp(0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show wrong password feedback
|
|
||||||
pub fn show_wrong_password(&mut self) {
|
|
||||||
self.wrong_password_shown = true;
|
|
||||||
self.wrong_password_start = Some(Instant::now());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Show key highlight feedback
|
|
||||||
pub fn show_key_highlight(&mut self) {
|
|
||||||
self.key_highlight_shown = true;
|
|
||||||
self.key_highlight_start = Some(Instant::now());
|
|
||||||
|
|
||||||
// Generate ONE random angle for this highlight
|
|
||||||
use std::time::SystemTime;
|
|
||||||
let seed = SystemTime::now()
|
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_nanos() as u64;
|
|
||||||
let random_val = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
|
|
||||||
self.key_highlight_angle = ((random_val % 360) as f64).to_radians();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the password display string (masked)
|
|
||||||
pub fn set_password_display(&mut self, password: String) {
|
|
||||||
self.password_display = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Render the current frame
|
|
||||||
pub fn render(&mut self) {
|
|
||||||
// Clear the surface
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(0.0, 0.0, 0.0, 1.0);
|
|
||||||
self.context.paint().expect("Failed to clear surface");
|
|
||||||
|
|
||||||
// Draw background
|
|
||||||
if let Some(ref background) = self.background {
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.set_source_surface(background, 0.0, 0.0)
|
|
||||||
.expect("Failed to set source");
|
|
||||||
self.context
|
|
||||||
.paint_with_alpha(self.fade_alpha)
|
|
||||||
.expect("Failed to paint");
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.indicator {
|
|
||||||
self.draw_indicator();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.clock {
|
|
||||||
self.draw_clock();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.show_media {
|
|
||||||
self.draw_media();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.show_network {
|
|
||||||
self.draw_network();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.show_battery {
|
|
||||||
self.draw_status();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.show_bluetooth {
|
|
||||||
self.draw_bluetooth();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.config.show_keyboard_layout {
|
|
||||||
self.draw_keyboard_layout();
|
|
||||||
}
|
|
||||||
|
|
||||||
if !self.password_display.is_empty() {
|
|
||||||
self.draw_password_display();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.caps_lock && self.config.show_caps_lock_text {
|
|
||||||
self.draw_caps_lock_indicator();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.wrong_password_shown {
|
|
||||||
self.draw_wrong_password_feedback();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.key_highlight_shown {
|
|
||||||
self.draw_key_highlight_feedback();
|
|
||||||
}
|
|
||||||
|
|
||||||
self.update_feedback_timers();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get raw pixel data from the surface (ARGB32 format)
|
|
||||||
pub fn get_pixel_data(&self) -> Result<Vec<u8>, cairo::BorrowError> {
|
|
||||||
let stride = self.surface.stride() as usize;
|
|
||||||
let height = self.height as usize;
|
|
||||||
let mut data = vec![0u8; stride * height];
|
|
||||||
self.surface.with_data(|src| {
|
|
||||||
data.copy_from_slice(src);
|
|
||||||
})?;
|
|
||||||
Ok(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn surface_info(&self) -> (i32, i32, i32) {
|
|
||||||
(self.width, self.height, self.surface.stride())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_uptime(&mut self) {
|
|
||||||
let now = Instant::now();
|
|
||||||
if let Some(last) = self.last_uptime_update {
|
|
||||||
if now.duration_since(last).as_secs() < 10 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let uptime_secs = std::fs::read_to_string("/proc/uptime")
|
|
||||||
.ok()
|
|
||||||
.and_then(|s| s.split_whitespace().next()?.parse::<f64>().ok())
|
|
||||||
.unwrap_or(0.0) as u64;
|
|
||||||
self.uptime_cache = format!("up {}h {}m", uptime_secs / 3600, (uptime_secs % 3600) / 60);
|
|
||||||
self.last_uptime_update = Some(now);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_clock(&self) {
|
|
||||||
use chrono::Local;
|
|
||||||
let now = Local::now();
|
|
||||||
let time_str = now.format("%H:%M").to_string();
|
|
||||||
let date_str = now.format("%A, %B %d").to_string();
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let center_y = self.height as f64 / 2.0;
|
|
||||||
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(48.0);
|
|
||||||
let te = self.context.text_extents(&time_str).unwrap();
|
|
||||||
self.context
|
|
||||||
.move_to(center_x - te.width() / 2.0, center_y + te.height() / 4.0);
|
|
||||||
self.context.show_text(&time_str).unwrap();
|
|
||||||
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_font_size(14.0);
|
|
||||||
let de = self.context.text_extents(&date_str).unwrap();
|
|
||||||
self.context.move_to(
|
|
||||||
center_x - de.width() / 2.0,
|
|
||||||
center_y + te.height() / 4.0 + 25.0,
|
|
||||||
);
|
|
||||||
self.context.show_text(&date_str).unwrap();
|
|
||||||
|
|
||||||
self.context.new_path();
|
|
||||||
let ue = self.context.text_extents(&self.uptime_cache).unwrap();
|
|
||||||
self.context.move_to(
|
|
||||||
center_x - ue.width() / 2.0,
|
|
||||||
center_y + te.height() / 4.0 + 43.0,
|
|
||||||
);
|
|
||||||
self.context.show_text(&self.uptime_cache).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_indicator(&self) {
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let center_y = self.height as f64 / 2.0;
|
|
||||||
let radius = self.config.indicator_radius as f64;
|
|
||||||
let thickness = self.config.indicator_thickness as f64;
|
|
||||||
|
|
||||||
self.context.new_path();
|
|
||||||
let (r, g, b, a) = self.config.inside_color;
|
|
||||||
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
|
||||||
self.context.arc(
|
|
||||||
center_x,
|
|
||||||
center_y,
|
|
||||||
radius - thickness / 2.0,
|
|
||||||
0.0,
|
|
||||||
2.0 * std::f64::consts::PI,
|
|
||||||
);
|
|
||||||
self.context.fill().unwrap();
|
|
||||||
|
|
||||||
let (lr, lg, lb, la) = self.config.line_color;
|
|
||||||
if la > 0.0 {
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(lr, lg, lb, la * self.fade_alpha);
|
|
||||||
self.context.set_line_width(1.0);
|
|
||||||
self.context.arc(
|
|
||||||
center_x,
|
|
||||||
center_y,
|
|
||||||
radius - thickness / 2.0,
|
|
||||||
0.0,
|
|
||||||
2.0 * std::f64::consts::PI,
|
|
||||||
);
|
|
||||||
self.context.stroke().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use caps lock color when caps lock is on and indicator is enabled, otherwise ring color
|
|
||||||
let (r, g, b, a) = if self.caps_lock {
|
|
||||||
self.config.caps_lock_color
|
|
||||||
} else {
|
|
||||||
self.config.ring_color
|
|
||||||
};
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
|
||||||
self.context.set_line_width(thickness);
|
|
||||||
self.context
|
|
||||||
.arc(center_x, center_y, radius, 0.0, 2.0 * std::f64::consts::PI);
|
|
||||||
self.context.stroke().unwrap();
|
|
||||||
|
|
||||||
let (r, g, b, a) = self.config.separator_color;
|
|
||||||
if a > 0.0 {
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
|
||||||
self.context.set_line_width(1.0);
|
|
||||||
self.context.move_to(center_x - radius, center_y);
|
|
||||||
self.context.line_to(center_x + radius, center_y);
|
|
||||||
self.context.stroke().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_password_display(&self) {
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let center_y = self.height as f64 / 2.0;
|
|
||||||
let radius = self.config.indicator_radius as f64;
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_font_size(32.0);
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
let te = self.context.text_extents(&self.password_display).unwrap();
|
|
||||||
self.context
|
|
||||||
.move_to(center_x - te.width() / 2.0, center_y + radius / 1.1);
|
|
||||||
self.context.show_text(&self.password_display).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_caps_lock_indicator(&self) {
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let center_y = self.height as f64 / 2.0;
|
|
||||||
let radius = self.config.indicator_radius as f64;
|
|
||||||
self.context.new_path();
|
|
||||||
// Use configurable caps lock text color
|
|
||||||
let (r, g, b, a) = self.config.caps_lock_text_color;
|
|
||||||
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
|
||||||
// Increase font size for bigger letters
|
|
||||||
self.context.set_font_size(24.0);
|
|
||||||
let text = "Caps Lock";
|
|
||||||
let te = self.context.text_extents(text).unwrap();
|
|
||||||
// Position above the ring
|
|
||||||
self.context
|
|
||||||
.move_to(center_x - te.width() / 2.0, center_y - radius - 10.0);
|
|
||||||
self.context.show_text(text).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_wrong_password_feedback(&self) {
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let center_y = self.height as f64 / 2.0;
|
|
||||||
let radius = self.config.indicator_radius as f64;
|
|
||||||
let thickness = self.config.indicator_thickness as f64;
|
|
||||||
let intensity = if let Some(start) = self.wrong_password_start {
|
|
||||||
let elapsed = start.elapsed();
|
|
||||||
let duration = std::time::Duration::from_millis(500);
|
|
||||||
if elapsed < duration {
|
|
||||||
1.0 - (elapsed.as_secs_f64() / duration.as_secs_f64())
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
};
|
|
||||||
|
|
||||||
if intensity > 0.0 {
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 0.0, 0.0, intensity * self.fade_alpha);
|
|
||||||
self.context.set_line_width(thickness + 2.0);
|
|
||||||
self.context
|
|
||||||
.arc(center_x, center_y, radius, 0.0, 2.0 * std::f64::consts::PI);
|
|
||||||
self.context.stroke().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_key_highlight_feedback(&self) {
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let center_y = self.height as f64 / 2.0;
|
|
||||||
let radius = self.config.indicator_radius as f64;
|
|
||||||
let thickness = self.config.indicator_thickness as f64;
|
|
||||||
let intensity = if let Some(start) = self.key_highlight_start {
|
|
||||||
let elapsed = start.elapsed();
|
|
||||||
let duration = std::time::Duration::from_millis(300);
|
|
||||||
if elapsed < duration {
|
|
||||||
1.0 - (elapsed.as_secs_f64() / duration.as_secs_f64())
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
};
|
|
||||||
|
|
||||||
if intensity > 0.0 {
|
|
||||||
let (r, g, b, a) = if self.caps_lock {
|
|
||||||
self.config.caps_lock_key_hl_color
|
|
||||||
} else {
|
|
||||||
self.config.key_hl_color
|
|
||||||
};
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(r, g, b, a * intensity * self.fade_alpha);
|
|
||||||
self.context.set_line_width(thickness + 1.5);
|
|
||||||
|
|
||||||
// Draw ONLY ONE segment that rotates based on password length
|
|
||||||
let global_offset = (self.password_display.len() as f64 * 45.0).to_radians();
|
|
||||||
self.context.new_path();
|
|
||||||
let actual_start = global_offset + self.key_highlight_angle;
|
|
||||||
self.context.arc(
|
|
||||||
center_x,
|
|
||||||
center_y,
|
|
||||||
radius,
|
|
||||||
actual_start,
|
|
||||||
actual_start + (40.0_f64).to_radians(),
|
|
||||||
);
|
|
||||||
self.context.stroke().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_feedback_timers(&mut self) {
|
|
||||||
self.update_uptime();
|
|
||||||
if let Some(start) = self.wrong_password_start {
|
|
||||||
if start.elapsed() > std::time::Duration::from_millis(500) {
|
|
||||||
self.wrong_password_shown = false;
|
|
||||||
self.wrong_password_start = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(start) = self.key_highlight_start {
|
|
||||||
if start.elapsed() > std::time::Duration::from_millis(300) {
|
|
||||||
self.key_highlight_shown = false;
|
|
||||||
self.key_highlight_start = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_media(&mut self) {
|
|
||||||
if let Some(ref title) = self.system_status.media_title {
|
|
||||||
let center_x = self.width as f64 / 2.0;
|
|
||||||
let start_y = self.height as f64 - 120.0;
|
|
||||||
let art_size = 56.0;
|
|
||||||
let spacing = 80.0;
|
|
||||||
|
|
||||||
if self.config.show_album_art && self.system_status.media_art_url != self.last_art_url {
|
|
||||||
self.last_art_url = self.system_status.media_art_url.clone();
|
|
||||||
self.media_art_surface = None;
|
|
||||||
if let Some(ref data) = self.system_status.media_art_data {
|
|
||||||
if let Ok(img) = image::load_from_memory(data) {
|
|
||||||
let img = img.to_rgba8();
|
|
||||||
let (w, h) = img.dimensions();
|
|
||||||
let mut surface =
|
|
||||||
ImageSurface::create(Format::ARgb32, w as i32, h as i32).unwrap();
|
|
||||||
{
|
|
||||||
let mut surface_data = surface.data().unwrap();
|
|
||||||
for y in 0..h {
|
|
||||||
for x in 0..w {
|
|
||||||
let pixel = img.get_pixel(x, y);
|
|
||||||
let idx = ((y * w + x) * 4) as usize;
|
|
||||||
surface_data[idx] = pixel[2];
|
|
||||||
surface_data[idx + 1] = pixel[1];
|
|
||||||
surface_data[idx + 2] = pixel[0];
|
|
||||||
surface_data[idx + 3] = pixel[3];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.media_art_surface = Some(surface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let has_art = self.config.show_album_art && self.media_art_surface.is_some();
|
|
||||||
let text_x = if has_art {
|
|
||||||
center_x - spacing / 2.0
|
|
||||||
} else {
|
|
||||||
center_x
|
|
||||||
};
|
|
||||||
let art_x = center_x - spacing - art_size / 2.0;
|
|
||||||
|
|
||||||
if has_art {
|
|
||||||
if let Some(ref art) = self.media_art_surface {
|
|
||||||
self.context.save().unwrap();
|
|
||||||
let scale = art_size / art.width() as f64;
|
|
||||||
self.context.translate(art_x, start_y);
|
|
||||||
self.context.scale(scale, scale);
|
|
||||||
self.context.set_source_surface(art, 0.0, 0.0).unwrap();
|
|
||||||
self.context.paint_with_alpha(self.fade_alpha).unwrap();
|
|
||||||
self.context.restore().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.9);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
|
|
||||||
let display_text = if let Some(ref artist) = self.system_status.media_artist {
|
|
||||||
format!("{} - {}", artist, title)
|
|
||||||
} else {
|
|
||||||
title.clone()
|
|
||||||
};
|
|
||||||
|
|
||||||
let te = self.context.text_extents(&display_text).unwrap();
|
|
||||||
self.context
|
|
||||||
.move_to(text_x - te.width() / 2.0, start_y + 20.0);
|
|
||||||
self.context.show_text(&display_text).unwrap();
|
|
||||||
|
|
||||||
let status_text = if self.system_status.media_playing {
|
|
||||||
if let Some(ref icon) = self.media_play_icon_surface {
|
|
||||||
// Draw play icon instead of text
|
|
||||||
let play_y = start_y + 40.0;
|
|
||||||
self.draw_icon_at(
|
|
||||||
center_x - icon.width() as f64 / 2.0,
|
|
||||||
play_y - icon.height() as f64 / 2.0,
|
|
||||||
icon,
|
|
||||||
);
|
|
||||||
""
|
|
||||||
} else {
|
|
||||||
"▶ Playing"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
"⏸ Paused"
|
|
||||||
};
|
|
||||||
|
|
||||||
if !status_text.is_empty() {
|
|
||||||
self.context.set_font_size(12.0);
|
|
||||||
let se = self.context.text_extents(status_text).unwrap();
|
|
||||||
self.context
|
|
||||||
.move_to(text_x - se.width() / 2.0, start_y + 40.0);
|
|
||||||
self.context.show_text(status_text).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let controls_y = start_y + 65.0;
|
|
||||||
|
|
||||||
// Draw media control icons
|
|
||||||
let icon_size = 20.0;
|
|
||||||
let icon_spacing = 40.0;
|
|
||||||
let controls_center_x = center_x;
|
|
||||||
|
|
||||||
// Previous icon
|
|
||||||
if let Some(ref icon) = self.media_prev_icon_surface {
|
|
||||||
let ix = controls_center_x - icon_spacing;
|
|
||||||
self.draw_icon_at(ix - icon_size / 2.0, controls_y - icon_size / 2.0, icon);
|
|
||||||
} else {
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.7);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context
|
|
||||||
.move_to(controls_center_x - icon_spacing - 8.0, controls_y);
|
|
||||||
self.context.show_text("⏮").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop icon
|
|
||||||
if let Some(ref icon) = self.media_stop_icon_surface {
|
|
||||||
let ix = controls_center_x;
|
|
||||||
self.draw_icon_at(ix - icon_size / 2.0, controls_y - icon_size / 2.0, icon);
|
|
||||||
} else {
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.7);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context.move_to(controls_center_x - 8.0, controls_y);
|
|
||||||
self.context.show_text("⏹").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Next icon
|
|
||||||
if let Some(ref icon) = self.media_next_icon_surface {
|
|
||||||
let ix = controls_center_x + icon_spacing;
|
|
||||||
self.draw_icon_at(ix - icon_size / 2.0, controls_y - icon_size / 2.0, icon);
|
|
||||||
} else {
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.7);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context
|
|
||||||
.move_to(controls_center_x + icon_spacing - 8.0, controls_y);
|
|
||||||
self.context.show_text("⏭").unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_network(&self) {
|
|
||||||
if !self.config.show_network {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let margin = 20.0;
|
|
||||||
let x = margin;
|
|
||||||
let y = margin + 20.0;
|
|
||||||
|
|
||||||
if let Some(ref ssid) = self.system_status.wifi_ssid {
|
|
||||||
if let Some(ref icon) = self.wifi_icon_surface {
|
|
||||||
self.draw_icon_at(x, y - 15.0, icon);
|
|
||||||
let text_x = x + icon.width() as f64 + 10.0;
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context.move_to(text_x, y);
|
|
||||||
self.context.show_text(ssid).unwrap();
|
|
||||||
} else {
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context.move_to(x, y);
|
|
||||||
self.context.show_text(ssid).unwrap();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let text = "No WiFi";
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.5);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context.move_to(x, y);
|
|
||||||
self.context.show_text(text).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_status(&self) {
|
|
||||||
if let Some(percent) = self.system_status.battery_percent {
|
|
||||||
let margin = 20.0;
|
|
||||||
let icon_width = 30.0;
|
|
||||||
let x = self.width as f64 - margin - icon_width - 50.0;
|
|
||||||
let y = margin + 20.0;
|
|
||||||
|
|
||||||
if let Some(ref icon) = self.battery_icon_surface {
|
|
||||||
self.draw_icon_at(x, y - 15.0, icon);
|
|
||||||
let text_x = x + icon.width() as f64 + 10.0;
|
|
||||||
let battery_text = format!("{:.0}%", percent);
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context.move_to(text_x, y);
|
|
||||||
self.context.show_text(&battery_text).unwrap();
|
|
||||||
} else {
|
|
||||||
self.draw_battery_icon_at(
|
|
||||||
x,
|
|
||||||
y - 12.0,
|
|
||||||
icon_width,
|
|
||||||
15.0,
|
|
||||||
percent,
|
|
||||||
self.system_status.is_charging,
|
|
||||||
);
|
|
||||||
let battery_text = format!("{:.0}%", percent);
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
self.context.move_to(x + icon_width + 10.0, y);
|
|
||||||
self.context.show_text(&battery_text).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_bluetooth(&self) {
|
|
||||||
if !self.config.show_bluetooth {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let margin = 20.0;
|
|
||||||
let x = margin;
|
|
||||||
let y = margin + 50.0;
|
|
||||||
|
|
||||||
if self.system_status.bluetooth_connected {
|
|
||||||
if let Some(ref icon) = self.bluetooth_icon_surface {
|
|
||||||
self.draw_icon_at(x, y - 12.0, icon);
|
|
||||||
let text_x = x + icon.width() as f64 + 10.0;
|
|
||||||
let devices = self.system_status.bluetooth_devices.join(", ");
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(14.0);
|
|
||||||
self.context.move_to(text_x, y);
|
|
||||||
self.context.show_text(&devices).unwrap();
|
|
||||||
} else {
|
|
||||||
let text = format!(
|
|
||||||
"🔵 {} device(s)",
|
|
||||||
self.system_status.bluetooth_devices.len()
|
|
||||||
);
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(14.0);
|
|
||||||
self.context.move_to(x, y);
|
|
||||||
self.context.show_text(&text).unwrap();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let text = "🔴 Bluetooth off";
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.5);
|
|
||||||
self.context.set_font_size(14.0);
|
|
||||||
self.context.move_to(x, y);
|
|
||||||
self.context.show_text(text).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_keyboard_layout(&self) {
|
|
||||||
if self.config.show_keyboard_layout {
|
|
||||||
if let Some(ref layout) = self.system_status.keyboard_layout {
|
|
||||||
let margin = 20.0;
|
|
||||||
let x = margin;
|
|
||||||
let y = margin + 80.0;
|
|
||||||
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
|
||||||
self.context.set_font_size(16.0);
|
|
||||||
let text = format!("Layout: {}", layout);
|
|
||||||
self.context.move_to(x, y);
|
|
||||||
self.context.show_text(&text).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_icon_at(&self, x: f64, y: f64, surface: &ImageSurface) {
|
|
||||||
self.context.save().unwrap();
|
|
||||||
let target_size = 24.0;
|
|
||||||
let scale_x = target_size / surface.width() as f64;
|
|
||||||
let scale_y = target_size / surface.height() as f64;
|
|
||||||
let scale = scale_x.min(scale_y);
|
|
||||||
self.context.translate(x, y);
|
|
||||||
self.context.scale(scale, scale);
|
|
||||||
self.context.set_source_surface(surface, 0.0, 0.0).unwrap();
|
|
||||||
self.context.paint_with_alpha(self.fade_alpha).unwrap();
|
|
||||||
self.context.restore().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw_battery_icon_at(
|
|
||||||
&self,
|
|
||||||
x: f64,
|
|
||||||
y: f64,
|
|
||||||
width: f64,
|
|
||||||
height: f64,
|
|
||||||
percent: f64,
|
|
||||||
charging: bool,
|
|
||||||
) {
|
|
||||||
let alpha = self.fade_alpha;
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 1.0, alpha * 0.5);
|
|
||||||
self.context.set_line_width(2.0);
|
|
||||||
self.context.rectangle(x, y, width, height);
|
|
||||||
self.context.stroke().unwrap();
|
|
||||||
self.context.new_path();
|
|
||||||
self.context
|
|
||||||
.rectangle(x + width, y + height / 4.0, 3.0, height / 2.0);
|
|
||||||
self.context.fill().unwrap();
|
|
||||||
let fill_width = (width - 4.0) * (percent / 100.0);
|
|
||||||
self.context.new_path();
|
|
||||||
if percent < 20.0 {
|
|
||||||
self.context.set_source_rgba(1.0, 0.2, 0.2, alpha);
|
|
||||||
} else {
|
|
||||||
self.context.set_source_rgba(0.2, 1.0, 0.2, alpha * 0.8);
|
|
||||||
}
|
|
||||||
self.context
|
|
||||||
.rectangle(x + 2.0, y + 2.0, fill_width, height - 4.0);
|
|
||||||
self.context.fill().unwrap();
|
|
||||||
if charging {
|
|
||||||
self.context.new_path();
|
|
||||||
self.context.set_source_rgba(1.0, 1.0, 0.0, alpha);
|
|
||||||
let bx = x + width / 2.0;
|
|
||||||
let by = y + height / 2.0;
|
|
||||||
self.context.move_to(bx - 3.0, by + 2.0);
|
|
||||||
self.context.line_to(bx + 1.0, by - 1.0);
|
|
||||||
self.context.line_to(bx - 1.0, by - 1.0);
|
|
||||||
self.context.line_to(bx + 3.0, by - 6.0);
|
|
||||||
self.context.line_to(bx - 1.0, by - 3.0);
|
|
||||||
self.context.line_to(bx + 1.0, by - 3.0);
|
|
||||||
self.context.close_path();
|
|
||||||
self.context.fill().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
use crate::render::ring_shape;
|
||||||
|
use crate::render::Renderer;
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
impl Renderer {
|
||||||
|
pub(crate) fn draw_verifying_feedback(&self) {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
let thickness = self.config.indicator_thickness as f64;
|
||||||
|
let (r, g, b, a) = self.config.verifying_color;
|
||||||
|
|
||||||
|
if a > 0.0 {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(r, g, b, a * self.fade_alpha);
|
||||||
|
self.context.set_line_width(thickness + 2.0);
|
||||||
|
self.context.set_line_join(cairo::LineJoin::Round);
|
||||||
|
ring_shape::build_ring_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius,
|
||||||
|
self.config.ring_shape,
|
||||||
|
);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_wrong_password_feedback(&self) {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
let thickness = self.config.indicator_thickness as f64;
|
||||||
|
let intensity = if let Some(start) = self.wrong_password_start {
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
let duration = std::time::Duration::from_millis(self.config.wrong_password_duration);
|
||||||
|
if elapsed < duration {
|
||||||
|
1.0 - (elapsed.as_secs_f64() / duration.as_secs_f64())
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
if intensity > 0.0 {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(1.0, 0.0, 0.0, intensity * self.fade_alpha);
|
||||||
|
self.context.set_line_width(thickness + 2.0);
|
||||||
|
self.context.set_line_join(cairo::LineJoin::Round);
|
||||||
|
ring_shape::build_ring_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius,
|
||||||
|
self.config.ring_shape,
|
||||||
|
);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_key_highlight_feedback(&self) {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
let thickness = self.config.indicator_thickness as f64;
|
||||||
|
let intensity = if let Some(start) = self.key_highlight_start {
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
let duration = std::time::Duration::from_millis(self.config.key_highlight_duration);
|
||||||
|
if elapsed < duration {
|
||||||
|
1.0 - (elapsed.as_secs_f64() / duration.as_secs_f64())
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
if intensity > 0.0 {
|
||||||
|
let (r, g, b, a) = if self.caps_lock {
|
||||||
|
self.config.caps_lock_key_hl_color
|
||||||
|
} else {
|
||||||
|
self.config.key_hl_color
|
||||||
|
};
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(r, g, b, a * intensity * self.fade_alpha);
|
||||||
|
self.context.set_line_width(thickness + 1.5);
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_line_cap(cairo::LineCap::Round);
|
||||||
|
// Convert angle range to normalized perimeter t (for circle: t = angle / 2π)
|
||||||
|
let max_dots = self.config.max_dots as f64;
|
||||||
|
let t_offset = ring_shape::top_centre_offset(self.config.ring_shape);
|
||||||
|
let global_t = ((self.password_display.len() as f64) / max_dots) + t_offset;
|
||||||
|
let random_t = self.key_highlight_angle / (2.0 * std::f64::consts::PI);
|
||||||
|
let t_start = global_t + random_t;
|
||||||
|
let sector_t = 40.0 / 360.0;
|
||||||
|
let t_end = t_start + sector_t;
|
||||||
|
ring_shape::build_sector_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius,
|
||||||
|
self.config.ring_shape,
|
||||||
|
t_start,
|
||||||
|
t_end,
|
||||||
|
);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_cleared_feedback(&self) {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
let thickness = self.config.indicator_thickness as f64;
|
||||||
|
let intensity = if let Some(start) = self.cleared_feedback_start {
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
let duration = std::time::Duration::from_millis(self.config.cleared_feedback_duration);
|
||||||
|
if elapsed < duration {
|
||||||
|
1.0 - (elapsed.as_secs_f64() / duration.as_secs_f64())
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
|
||||||
|
if intensity > 0.0 {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(1.0, 0.0, 0.0, intensity * self.fade_alpha * 0.5);
|
||||||
|
ring_shape::build_fill_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius - thickness / 2.0,
|
||||||
|
thickness,
|
||||||
|
self.config.ring_shape,
|
||||||
|
);
|
||||||
|
render_try!(self.context.fill());
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(1.0, 0.0, 0.0, intensity * self.fade_alpha);
|
||||||
|
self.context.set_line_width(thickness + 4.0);
|
||||||
|
self.context.set_line_join(cairo::LineJoin::Round);
|
||||||
|
ring_shape::build_ring_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius,
|
||||||
|
self.config.ring_shape,
|
||||||
|
);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_font_size(24.0);
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(1.0, 1.0, 1.0, intensity * self.fade_alpha);
|
||||||
|
let text = "CLEARED";
|
||||||
|
let te = render_try!(self.context.text_extents(text));
|
||||||
|
self.context
|
||||||
|
.move_to(center_x - te.width() / 2.0, center_y - radius - 20.0);
|
||||||
|
render_try!(self.context.show_text(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether any feedback animation is currently in flight and therefore
|
||||||
|
/// requires continued per-frame redraws until it finishes.
|
||||||
|
pub(crate) fn is_animating(&self) -> bool {
|
||||||
|
self.wrong_password_start.is_some()
|
||||||
|
|| self.key_highlight_start.is_some()
|
||||||
|
|| self.cleared_feedback_start.is_some()
|
||||||
|
|| self.verifying_start.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn update_feedback_timers(&mut self) {
|
||||||
|
self.update_uptime();
|
||||||
|
if let Some(start) = self.wrong_password_start {
|
||||||
|
if start.elapsed() > std::time::Duration::from_millis(self.config.wrong_password_duration) {
|
||||||
|
self.wrong_password_shown = false;
|
||||||
|
self.wrong_password_start = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(start) = self.key_highlight_start {
|
||||||
|
if start.elapsed() > std::time::Duration::from_millis(self.config.key_highlight_duration) {
|
||||||
|
self.key_highlight_shown = false;
|
||||||
|
self.key_highlight_start = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(start) = self.cleared_feedback_start {
|
||||||
|
if start.elapsed() > std::time::Duration::from_millis(self.config.cleared_feedback_duration) {
|
||||||
|
self.cleared_feedback_shown = false;
|
||||||
|
self.cleared_feedback_start = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(start) = self.verifying_start {
|
||||||
|
if start.elapsed() > std::time::Duration::from_millis(self.config.auth_timeout) {
|
||||||
|
self.verifying_shown = false;
|
||||||
|
self.verifying_start = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_wrong_password(&mut self) {
|
||||||
|
self.wrong_password_shown = true;
|
||||||
|
self.wrong_password_start = Some(Instant::now());
|
||||||
|
// Clear verifying state — wrong password replaces it
|
||||||
|
self.verifying_shown = false;
|
||||||
|
self.verifying_start = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_key_highlight(&mut self) {
|
||||||
|
self.key_highlight_shown = true;
|
||||||
|
self.key_highlight_start = Some(Instant::now());
|
||||||
|
use std::time::SystemTime;
|
||||||
|
let seed = SystemTime::now()
|
||||||
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_nanos() as u64)
|
||||||
|
.unwrap_or(0);
|
||||||
|
let random_val = seed.wrapping_mul(6364136223846793005).wrapping_add(1);
|
||||||
|
self.key_highlight_angle = ((random_val % 360) as f64).to_radians();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_cleared_feedback(&mut self) {
|
||||||
|
self.cleared_feedback_shown = true;
|
||||||
|
self.cleared_feedback_start = Some(Instant::now());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_verifying(&mut self) {
|
||||||
|
self.verifying_shown = true;
|
||||||
|
self.verifying_start = Some(Instant::now());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_verifying(&mut self) {
|
||||||
|
self.verifying_shown = false;
|
||||||
|
self.verifying_start = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
use crate::render::ring_shape;
|
||||||
|
use crate::render::Renderer;
|
||||||
|
|
||||||
|
impl Renderer {
|
||||||
|
pub(crate) fn draw_indicator(&self) {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
let thickness = self.config.indicator_thickness as f64;
|
||||||
|
let shape = self.config.ring_shape;
|
||||||
|
|
||||||
|
// Filled center
|
||||||
|
self.context.new_path();
|
||||||
|
let (r, g, b, a) = self.config.inside_color;
|
||||||
|
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
||||||
|
ring_shape::build_fill_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius - thickness / 2.0,
|
||||||
|
thickness,
|
||||||
|
shape,
|
||||||
|
);
|
||||||
|
render_try!(self.context.fill());
|
||||||
|
|
||||||
|
// Separator line behind the ring
|
||||||
|
let (lr, lg, lb, la) = self.config.line_color;
|
||||||
|
if la > 0.0 {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(lr, lg, lb, la * self.fade_alpha);
|
||||||
|
self.context.set_line_width(1.0);
|
||||||
|
ring_shape::build_ring_path(
|
||||||
|
&self.context,
|
||||||
|
center_x,
|
||||||
|
center_y,
|
||||||
|
radius - thickness / 2.0,
|
||||||
|
shape,
|
||||||
|
);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Outer ring
|
||||||
|
let (r, g, b, a) = if self.caps_lock {
|
||||||
|
self.config.caps_lock_color
|
||||||
|
} else {
|
||||||
|
self.config.ring_color
|
||||||
|
};
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
||||||
|
self.context.set_line_width(thickness);
|
||||||
|
self.context.set_line_join(cairo::LineJoin::Round);
|
||||||
|
ring_shape::build_ring_path(&self.context, center_x, center_y, radius, shape);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
|
||||||
|
// Separator line through center
|
||||||
|
let (r, g, b, a) = self.config.separator_color;
|
||||||
|
if a > 0.0 {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
||||||
|
self.context.set_line_width(1.0);
|
||||||
|
self.context.move_to(center_x - radius, center_y);
|
||||||
|
self.context.line_to(center_x + radius, center_y);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_password_display(&self) {
|
||||||
|
if self.config.hide_password {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
let thickness = self.config.indicator_thickness as f64;
|
||||||
|
let shape = self.config.ring_shape;
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
|
||||||
|
let count = self.password_display.len();
|
||||||
|
if count == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let max_dots = self.config.max_dots as f64;
|
||||||
|
let dot_radius = radius - thickness - 10.0;
|
||||||
|
let t_offset = ring_shape::top_centre_offset(shape);
|
||||||
|
|
||||||
|
for i in 0..count {
|
||||||
|
let t = (i as f64 / max_dots) + t_offset;
|
||||||
|
let (x, y) = ring_shape::perimeter_point(center_x, center_y, dot_radius, shape, t);
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.arc(x, y, 4.0, 0.0, 2.0 * std::f64::consts::PI);
|
||||||
|
render_try!(self.context.fill());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cursor indicator
|
||||||
|
if self.fade_alpha > 0.0 && self.cursor_position > 0 {
|
||||||
|
let cursor_t = ((self.cursor_position as f64 - 0.5) / max_dots) + t_offset;
|
||||||
|
let (cx, cy) =
|
||||||
|
ring_shape::perimeter_point(center_x, center_y, dot_radius, shape, cursor_t);
|
||||||
|
let dx = cx - center_x;
|
||||||
|
let dy = cy - center_y;
|
||||||
|
let len = (dx * dx + dy * dy).sqrt().max(1.0);
|
||||||
|
let nx = dx / len;
|
||||||
|
let ny = dy / len;
|
||||||
|
|
||||||
|
let x1 = cx - 8.0 * nx;
|
||||||
|
let y1 = cy - 8.0 * ny;
|
||||||
|
let x2 = cx + 8.0 * nx;
|
||||||
|
let y2 = cy + 8.0 * ny;
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(0.0, 0.8, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_line_width(2.0);
|
||||||
|
self.context.move_to(x1, y1);
|
||||||
|
self.context.line_to(x2, y2);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_caps_lock_indicator(&self) {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
let radius = self.config.indicator_radius as f64;
|
||||||
|
self.context.new_path();
|
||||||
|
let (r, g, b, a) = self.config.caps_lock_text_color;
|
||||||
|
self.context.set_source_rgba(r, g, b, a * self.fade_alpha);
|
||||||
|
self.context.set_font_size(24.0);
|
||||||
|
let text = "Caps Lock";
|
||||||
|
let te = render_try!(self.context.text_extents(text));
|
||||||
|
self.context
|
||||||
|
.move_to(center_x - te.width() / 2.0, center_y - radius - 10.0);
|
||||||
|
render_try!(self.context.show_text(text));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
use crate::render::Renderer;
|
||||||
|
use cairo::{Format, ImageSurface};
|
||||||
|
|
||||||
|
impl Renderer {
|
||||||
|
pub(crate) fn draw_media(&mut self) {
|
||||||
|
if let Some(ref title) = self.system_status.media_title {
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let start_y = self.height as f64 - 120.0;
|
||||||
|
let art_size = 56.0;
|
||||||
|
|
||||||
|
if self.config.show_album_art && self.system_status.media_art_url != self.last_art_url {
|
||||||
|
self.last_art_url = self.system_status.media_art_url.clone();
|
||||||
|
self.media_art_surface = None;
|
||||||
|
if let Some(ref data) = self.system_status.media_art_data {
|
||||||
|
if let Ok(img) = image::load_from_memory(data) {
|
||||||
|
let img = img.to_rgba8();
|
||||||
|
let (w, h) = img.dimensions();
|
||||||
|
if let Ok(mut surface) = ImageSurface::create(Format::ARgb32, w as i32, h as i32) {
|
||||||
|
if let Ok(mut surface_data) = surface.data() {
|
||||||
|
for y in 0..h {
|
||||||
|
for x in 0..w {
|
||||||
|
let pixel = img.get_pixel(x, y);
|
||||||
|
let idx = ((y * w + x) * 4) as usize;
|
||||||
|
surface_data[idx] = pixel[2];
|
||||||
|
surface_data[idx + 1] = pixel[1];
|
||||||
|
surface_data[idx + 2] = pixel[0];
|
||||||
|
surface_data[idx + 3] = pixel[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to access album art surface data");
|
||||||
|
}
|
||||||
|
self.media_art_surface = Some(surface);
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to create album art surface");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let has_art = self.config.show_album_art && self.media_art_surface.is_some();
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * 0.9);
|
||||||
|
self.context.set_font_size(16.0);
|
||||||
|
|
||||||
|
let display_text = if let Some(ref artist) = self.system_status.media_artist {
|
||||||
|
format!("{} - {}", artist, title)
|
||||||
|
} else {
|
||||||
|
title.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
let te = render_try!(self.context.text_extents(&display_text));
|
||||||
|
|
||||||
|
// Center art + text as a group with 16px gap between them
|
||||||
|
let art_text_gap = 16.0;
|
||||||
|
let group_width = te.width() + art_size + art_text_gap;
|
||||||
|
let group_start_x = center_x - group_width / 2.0;
|
||||||
|
let art_x = group_start_x;
|
||||||
|
let text_center_x = art_x + art_size + art_text_gap + te.width() / 2.0;
|
||||||
|
|
||||||
|
if has_art {
|
||||||
|
if let Some(ref art) = self.media_art_surface {
|
||||||
|
render_try!(self.context.save());
|
||||||
|
let scale = art_size / art.width() as f64;
|
||||||
|
self.context.translate(art_x, start_y);
|
||||||
|
self.context.scale(scale, scale);
|
||||||
|
render_try!(self.context.set_source_surface(art, 0.0, 0.0));
|
||||||
|
render_try!(self.context.paint_with_alpha(self.fade_alpha));
|
||||||
|
render_try!(self.context.restore());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.context.move_to(text_center_x - te.width() / 2.0, start_y + 20.0);
|
||||||
|
render_try!(self.context.show_text(&display_text));
|
||||||
|
|
||||||
|
// All media buttons on one row, evenly spaced.
|
||||||
|
// Each gets a 24×24 hit area, matching draw_icon_at's target_size.
|
||||||
|
let btn_size = 24.0;
|
||||||
|
let btn_gap = 48.0;
|
||||||
|
let btn_y = start_y + 50.0;
|
||||||
|
|
||||||
|
// Layout: prev | play_pause | next (centered as a group)
|
||||||
|
let total_buttons: f64 =
|
||||||
|
(self.media_prev_icon_surface.is_some() as u32
|
||||||
|
+ 1
|
||||||
|
+ self.media_next_icon_surface.is_some() as u32) as f64;
|
||||||
|
let group_width = (total_buttons - 1.0) * btn_gap + btn_size;
|
||||||
|
let group_start_x = center_x - group_width / 2.0;
|
||||||
|
let mut btn_x = group_start_x;
|
||||||
|
|
||||||
|
if let Some(ref icon) = self.media_prev_icon_surface {
|
||||||
|
self.draw_icon_at(btn_x, btn_y - btn_size / 2.0, icon);
|
||||||
|
self.media_rects.push(("prev", btn_x, btn_y - btn_size / 2.0, btn_size, btn_size));
|
||||||
|
btn_x += btn_gap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Play/pause — always present (at least one of play/pause icon should load)
|
||||||
|
if self.system_status.media_playing {
|
||||||
|
if let Some(ref icon) = self.media_pause_icon_surface {
|
||||||
|
self.draw_icon_at(btn_x, btn_y - btn_size / 2.0, icon);
|
||||||
|
self.media_rects.push(("play_pause", btn_x, btn_y - btn_size / 2.0, btn_size, btn_size));
|
||||||
|
}
|
||||||
|
} else if let Some(ref icon) = self.media_play_icon_surface {
|
||||||
|
self.draw_icon_at(btn_x, btn_y - btn_size / 2.0, icon);
|
||||||
|
self.media_rects.push(("play_pause", btn_x, btn_y - btn_size / 2.0, btn_size, btn_size));
|
||||||
|
}
|
||||||
|
btn_x += btn_gap;
|
||||||
|
|
||||||
|
if let Some(ref icon) = self.media_next_icon_surface {
|
||||||
|
self.draw_icon_at(btn_x, btn_y - btn_size / 2.0, icon);
|
||||||
|
self.media_rects.push(("next", btn_x, btn_y - btn_size / 2.0, btn_size, btn_size));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,252 @@
|
|||||||
|
use cairo::{Context, Format, ImageSurface};
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::system::SystemStatus;
|
||||||
|
|
||||||
|
/// Log cairo errors and return early instead of propagating panics.
|
||||||
|
/// Defined once here and available to all render submodules.
|
||||||
|
macro_rules! render_try {
|
||||||
|
($expr:expr) => {
|
||||||
|
match $expr {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("cairo error: {:?}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
mod feedback;
|
||||||
|
mod indicator;
|
||||||
|
mod media_bar;
|
||||||
|
mod ring_shape;
|
||||||
|
mod status_bar;
|
||||||
|
|
||||||
|
pub struct Renderer {
|
||||||
|
pub(crate) width: i32,
|
||||||
|
pub(crate) height: i32,
|
||||||
|
pub(crate) config: Config,
|
||||||
|
pub(crate) surface: ImageSurface,
|
||||||
|
pub(crate) context: Context,
|
||||||
|
pub(crate) fade_alpha: f64,
|
||||||
|
pub(crate) wrong_password_shown: bool,
|
||||||
|
pub(crate) key_highlight_shown: bool,
|
||||||
|
pub(crate) cleared_feedback_shown: bool,
|
||||||
|
pub(crate) verifying_shown: bool,
|
||||||
|
pub(crate) wrong_password_start: Option<Instant>,
|
||||||
|
pub(crate) key_highlight_start: Option<Instant>,
|
||||||
|
pub(crate) cleared_feedback_start: Option<Instant>,
|
||||||
|
pub(crate) verifying_start: Option<Instant>,
|
||||||
|
pub(crate) key_highlight_angle: f64,
|
||||||
|
pub(crate) background: Option<ImageSurface>,
|
||||||
|
pub(crate) password_display: String,
|
||||||
|
pub(crate) cursor_position: usize,
|
||||||
|
pub(crate) uptime_cache: String,
|
||||||
|
pub(crate) last_uptime_update: Option<Instant>,
|
||||||
|
pub caps_lock: bool,
|
||||||
|
pub system_status: SystemStatus,
|
||||||
|
pub(crate) media_art_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) last_art_url: Option<String>,
|
||||||
|
pub(crate) wifi_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) bluetooth_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) battery_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) media_prev_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) media_stop_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) media_play_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) media_pause_icon_surface: Option<ImageSurface>,
|
||||||
|
pub(crate) media_next_icon_surface: Option<ImageSurface>,
|
||||||
|
pub media_rects: Vec<(&'static str, f64, f64, f64, f64)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Renderer {
|
||||||
|
pub fn new(width: i32, height: i32, config: Config) -> Self {
|
||||||
|
log::debug!("Renderer::new({}, {}, ...) called", width, height);
|
||||||
|
let surface = ImageSurface::create(Format::ARgb32, width, height)
|
||||||
|
.expect("Failed to create Cairo surface");
|
||||||
|
let context = Context::new(&surface).expect("Failed to create Cairo context");
|
||||||
|
|
||||||
|
let mut renderer = Self {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
config: config.clone(),
|
||||||
|
surface,
|
||||||
|
context,
|
||||||
|
fade_alpha: 0.0,
|
||||||
|
wrong_password_shown: false,
|
||||||
|
key_highlight_shown: false,
|
||||||
|
cleared_feedback_shown: false,
|
||||||
|
verifying_shown: false,
|
||||||
|
wrong_password_start: None,
|
||||||
|
key_highlight_start: None,
|
||||||
|
cleared_feedback_start: None,
|
||||||
|
verifying_start: None,
|
||||||
|
key_highlight_angle: 0.0,
|
||||||
|
background: None,
|
||||||
|
password_display: String::new(),
|
||||||
|
cursor_position: 0,
|
||||||
|
uptime_cache: String::new(),
|
||||||
|
last_uptime_update: None,
|
||||||
|
caps_lock: false,
|
||||||
|
system_status: SystemStatus::default(),
|
||||||
|
media_art_surface: None,
|
||||||
|
last_art_url: None,
|
||||||
|
wifi_icon_surface: None,
|
||||||
|
bluetooth_icon_surface: None,
|
||||||
|
battery_icon_surface: None,
|
||||||
|
media_prev_icon_surface: None,
|
||||||
|
media_stop_icon_surface: None,
|
||||||
|
media_play_icon_surface: None,
|
||||||
|
media_pause_icon_surface: None,
|
||||||
|
media_next_icon_surface: None,
|
||||||
|
media_rects: Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
renderer.load_icons();
|
||||||
|
renderer
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resize(&mut self, width: i32, height: i32) {
|
||||||
|
log::debug!("Renderer::resize({}, {}) called", width, height);
|
||||||
|
self.width = width;
|
||||||
|
self.height = height;
|
||||||
|
|
||||||
|
self.surface = ImageSurface::create(Format::ARgb32, width, height)
|
||||||
|
.expect("Failed to create Cairo surface");
|
||||||
|
self.context = Context::new(&self.surface).expect("Failed to create Cairo context");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_background(&mut self, background: ImageSurface) {
|
||||||
|
self.background = Some(background);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_fade_alpha(&mut self, alpha: f64) {
|
||||||
|
self.fade_alpha = alpha.clamp(0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_password_display(&mut self, length: usize) {
|
||||||
|
self.password_display = ".".repeat(length);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn peek_password(&mut self, password: &str) {
|
||||||
|
self.password_display = password.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_cursor_position(&mut self, position: usize) {
|
||||||
|
self.cursor_position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_pixel_data(&self) -> Result<Vec<u8>, cairo::BorrowError> {
|
||||||
|
let stride = self.surface.stride() as usize;
|
||||||
|
let height = self.height as usize;
|
||||||
|
let mut data = vec![0u8; stride * height];
|
||||||
|
self.surface.with_data(|src| {
|
||||||
|
data.copy_from_slice(src);
|
||||||
|
})?;
|
||||||
|
Ok(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn surface_info(&self) -> (i32, i32, i32) {
|
||||||
|
(self.width, self.height, self.surface.stride())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(&mut self) {
|
||||||
|
self.media_rects.clear();
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(0.0, 0.0, 0.0, 1.0);
|
||||||
|
self.context.paint().expect("Failed to clear surface");
|
||||||
|
|
||||||
|
if let Some(ref background) = self.background {
|
||||||
|
self.context.save().expect("Failed to save context");
|
||||||
|
let bg_width = background.width() as f64;
|
||||||
|
let bg_height = background.height() as f64;
|
||||||
|
let scale_x = self.width as f64 / bg_width;
|
||||||
|
let scale_y = self.height as f64 / bg_height;
|
||||||
|
let scale = scale_x.max(scale_y);
|
||||||
|
|
||||||
|
let offset_x = (self.width as f64 - bg_width * scale) / 2.0;
|
||||||
|
let offset_y = (self.height as f64 - bg_height * scale) / 2.0;
|
||||||
|
|
||||||
|
self.context.translate(offset_x, offset_y);
|
||||||
|
self.context.scale(scale, scale);
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_surface(background, 0.0, 0.0)
|
||||||
|
.expect("Failed to set source");
|
||||||
|
self.context
|
||||||
|
.paint_with_alpha(self.fade_alpha)
|
||||||
|
.expect("Failed to paint");
|
||||||
|
self.context.restore().expect("Failed to restore context");
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.indicator {
|
||||||
|
self.draw_indicator();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.clock {
|
||||||
|
self.draw_clock();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.show_media {
|
||||||
|
self.draw_media();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.show_network {
|
||||||
|
self.draw_network();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.show_battery {
|
||||||
|
self.draw_status();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.show_bluetooth {
|
||||||
|
self.draw_bluetooth();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.config.show_keyboard_layout {
|
||||||
|
self.draw_keyboard_layout();
|
||||||
|
}
|
||||||
|
|
||||||
|
if !self.password_display.is_empty() {
|
||||||
|
self.draw_password_display();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.caps_lock && self.config.show_caps_lock_text {
|
||||||
|
self.draw_caps_lock_indicator();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.verifying_shown {
|
||||||
|
self.draw_verifying_feedback();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.wrong_password_shown {
|
||||||
|
self.draw_wrong_password_feedback();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.key_highlight_shown {
|
||||||
|
self.draw_key_highlight_feedback();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.cleared_feedback_shown {
|
||||||
|
self.draw_cleared_feedback();
|
||||||
|
}
|
||||||
|
|
||||||
|
self.update_feedback_timers();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_uptime(&mut self) {
|
||||||
|
let now = Instant::now();
|
||||||
|
if let Some(last) = self.last_uptime_update {
|
||||||
|
if now.duration_since(last).as_secs() < 10 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let uptime_secs = std::fs::read_to_string("/proc/uptime")
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| s.split_whitespace().next()?.parse::<f64>().ok())
|
||||||
|
.unwrap_or(0.0) as u64;
|
||||||
|
self.uptime_cache = format!("up {}h {}m", uptime_secs / 3600, (uptime_secs % 3600) / 60);
|
||||||
|
self.last_uptime_update = Some(now);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
use cairo::Context;
|
||||||
|
|
||||||
|
use crate::config::RingShape;
|
||||||
|
|
||||||
|
/// Number of linear segments used to approximate curved portions of a shape.
|
||||||
|
/// Higher = smoother, lower = faster.
|
||||||
|
const SEGMENTS: usize = 120;
|
||||||
|
|
||||||
|
/// Return the (x, y) point on the shape's perimeter at normalized position `t` ∈ [0, 1].
|
||||||
|
/// `t = 0` is a reference point (rightmost for most shapes); `t` increases clockwise.
|
||||||
|
/// `r` is the shape's characteristic radius (distance from center to side/vertex).
|
||||||
|
pub(crate) fn perimeter_point(
|
||||||
|
cx: f64,
|
||||||
|
cy: f64,
|
||||||
|
r: f64,
|
||||||
|
shape: RingShape,
|
||||||
|
t: f64,
|
||||||
|
) -> (f64, f64) {
|
||||||
|
// Normalize t to [0, 1). Rust's % preserves sign, and the shape-specific
|
||||||
|
// functions use floor/truncation that break on negative values.
|
||||||
|
let t = t - t.floor();
|
||||||
|
|
||||||
|
match shape {
|
||||||
|
RingShape::Circle => {
|
||||||
|
let angle = t * 2.0 * std::f64::consts::PI;
|
||||||
|
(cx + r * angle.cos(), cy + r * angle.sin())
|
||||||
|
}
|
||||||
|
RingShape::Square => square_perimeter_point(cx, cy, r, t),
|
||||||
|
RingShape::Diamond => diamond_perimeter_point(cx, cy, r, t),
|
||||||
|
RingShape::Hexagon => hexagon_perimeter_point(cx, cy, r, t),
|
||||||
|
RingShape::Pill => pill_perimeter_point(cx, cy, r, t),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Right-top-right-bottom-left-bottom-left-top order (clockwise from right).
|
||||||
|
fn square_perimeter_point(cx: f64, cy: f64, r: f64, t: f64) -> (f64, f64) {
|
||||||
|
let t = t % 1.0;
|
||||||
|
let side = (t * 4.0).floor() as u32;
|
||||||
|
let local = t * 4.0 - side as f64;
|
||||||
|
|
||||||
|
match side {
|
||||||
|
0 => {
|
||||||
|
// Right side: top → bottom
|
||||||
|
(cx + r, cy - r + local * 2.0 * r)
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
// Bottom side: right → left
|
||||||
|
(cx + r - local * 2.0 * r, cy + r)
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
// Left side: bottom → top
|
||||||
|
(cx - r, cy + r - local * 2.0 * r)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Top side: left → right
|
||||||
|
(cx - r + local * 2.0 * r, cy - r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Right-bottom-left-top order (clockwise from right).
|
||||||
|
fn diamond_perimeter_point(cx: f64, cy: f64, r: f64, t: f64) -> (f64, f64) {
|
||||||
|
let t = t % 1.0;
|
||||||
|
let side = (t * 4.0).floor() as u32;
|
||||||
|
let local = t * 4.0 - side as f64;
|
||||||
|
|
||||||
|
match side {
|
||||||
|
0 => {
|
||||||
|
// Right to bottom
|
||||||
|
(cx + r - local * r, cy + local * r)
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
// Bottom to left
|
||||||
|
(cx - local * r, cy + r - local * r)
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
// Left to top
|
||||||
|
(cx - r + local * r, cy - local * r)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Top to right
|
||||||
|
(cx + local * r, cy - r + local * r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// 0: right → bottom-right (vertex to vertex)
|
||||||
|
/// 1: bottom edge (right → left)
|
||||||
|
/// 2: bottom-left → left
|
||||||
|
/// 3: left → top-left
|
||||||
|
/// 4: top edge (left → right)
|
||||||
|
/// 5: top-right → right
|
||||||
|
fn hexagon_perimeter_point(cx: f64, cy: f64, r: f64, t: f64) -> (f64, f64) {
|
||||||
|
let t = t % 1.0;
|
||||||
|
let side = (t * 6.0).floor() as u32;
|
||||||
|
let local = t * 6.0 - side as f64;
|
||||||
|
|
||||||
|
// Shared helper for edges between two vertices
|
||||||
|
let vert = |angle_rad: f64| -> (f64, f64) {
|
||||||
|
(cx + r * angle_rad.cos(), cy + r * angle_rad.sin())
|
||||||
|
};
|
||||||
|
|
||||||
|
// Vertices clockwise from right (angle = 0)
|
||||||
|
let v = [
|
||||||
|
vert(0.0), // V0: right
|
||||||
|
vert(std::f64::consts::PI * (1.0 / 3.0)), // V1: bottom-right
|
||||||
|
vert(std::f64::consts::PI * (2.0 / 3.0)), // V2: bottom-left
|
||||||
|
vert(std::f64::consts::PI), // V3: left
|
||||||
|
vert(std::f64::consts::PI * (4.0 / 3.0)), // V4: top-left
|
||||||
|
vert(std::f64::consts::PI * (5.0 / 3.0)), // V5: top-right
|
||||||
|
];
|
||||||
|
|
||||||
|
let (x0, y0) = v[side as usize];
|
||||||
|
let (x1, y1) = v[((side + 1) % 6) as usize];
|
||||||
|
(x0 + local * (x1 - x0), y0 + local * (y1 - y0))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clockwise from top-right corner: right cap (downward) → bottom straight
|
||||||
|
/// (leftward) → left cap (upward) → top straight (rightward).
|
||||||
|
///
|
||||||
|
/// The pill is a stadium / capsule: cap radius = r, straight-section length = 2r,
|
||||||
|
/// total width = 4r, total height = 2r.
|
||||||
|
fn pill_perimeter_point(cx: f64, cy: f64, r: f64, t: f64) -> (f64, f64) {
|
||||||
|
let t = t % 1.0;
|
||||||
|
let total_p = 4.0 + 2.0 * std::f64::consts::PI; // 4r + 2πr, normalised by r
|
||||||
|
let straights = 2.0 / total_p; // each straight segment's t fraction
|
||||||
|
let caps = std::f64::consts::PI / total_p; // each cap's t fraction
|
||||||
|
|
||||||
|
if t < caps {
|
||||||
|
// Right cap: semicircle, top → bottom, centred at (r, 0)
|
||||||
|
let local = t / caps;
|
||||||
|
let angle = -std::f64::consts::PI / 2.0 + local * std::f64::consts::PI;
|
||||||
|
(cx + r + r * angle.cos(), cy + r * angle.sin())
|
||||||
|
} else if t < caps + straights {
|
||||||
|
// Bottom straight: right → left
|
||||||
|
let local = (t - caps) / straights;
|
||||||
|
(cx + r - local * 2.0 * r, cy + r)
|
||||||
|
} else if t < caps + straights + caps {
|
||||||
|
// Left cap: semicircle, bottom → top, centred at (-r, 0)
|
||||||
|
let local = (t - caps - straights) / caps;
|
||||||
|
let angle = std::f64::consts::PI / 2.0 + local * std::f64::consts::PI;
|
||||||
|
(cx - r + r * angle.cos(), cy + r * angle.sin())
|
||||||
|
} else {
|
||||||
|
// Top straight: left → right
|
||||||
|
let local = (t - 2.0 * caps - straights) / straights;
|
||||||
|
(cx - r + local * 2.0 * r, cy - r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build the full closed path of the shape outline (at radius `r`).
|
||||||
|
/// Call `stroke()` after this to draw the ring.
|
||||||
|
pub(crate) fn build_ring_path(ctx: &Context, cx: f64, cy: f64, r: f64, shape: RingShape) {
|
||||||
|
match shape {
|
||||||
|
RingShape::Circle => {
|
||||||
|
ctx.arc(cx, cy, r, 0.0, 2.0 * std::f64::consts::PI);
|
||||||
|
}
|
||||||
|
RingShape::Square | RingShape::Diamond | RingShape::Hexagon | RingShape::Pill => {
|
||||||
|
let (x0, y0) = perimeter_point(cx, cy, r, shape, 0.0);
|
||||||
|
ctx.move_to(x0, y0);
|
||||||
|
// Subdivide perimeter into enough segments for smooth rendering
|
||||||
|
let n = 80;
|
||||||
|
for i in 1..=n {
|
||||||
|
let pt = i as f64 / n as f64;
|
||||||
|
let (x, y) = perimeter_point(cx, cy, r, shape, pt);
|
||||||
|
ctx.line_to(x, y);
|
||||||
|
}
|
||||||
|
ctx.close_path();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build a partial path along the shape perimeter from normalized position
|
||||||
|
/// `t_start` to `t_end`. Call `stroke()` after this to draw a sector.
|
||||||
|
pub(crate) fn build_sector_path(
|
||||||
|
ctx: &Context,
|
||||||
|
cx: f64,
|
||||||
|
cy: f64,
|
||||||
|
r: f64,
|
||||||
|
shape: RingShape,
|
||||||
|
t_start: f64,
|
||||||
|
t_end: f64,
|
||||||
|
) {
|
||||||
|
match shape {
|
||||||
|
RingShape::Circle => {
|
||||||
|
let a_start = t_start * 2.0 * std::f64::consts::PI;
|
||||||
|
let a_end = t_end * 2.0 * std::f64::consts::PI;
|
||||||
|
ctx.arc(cx, cy, r, a_start, a_end);
|
||||||
|
}
|
||||||
|
RingShape::Square | RingShape::Diamond | RingShape::Hexagon | RingShape::Pill => {
|
||||||
|
let (x0, y0) = perimeter_point(cx, cy, r, shape, t_start);
|
||||||
|
ctx.move_to(x0, y0);
|
||||||
|
for i in 1..=SEGMENTS {
|
||||||
|
let t = t_start + (t_end - t_start) * (i as f64 / SEGMENTS as f64);
|
||||||
|
let (x, y) = perimeter_point(cx, cy, r, shape, t);
|
||||||
|
ctx.line_to(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build the filled interior path (inset from outer ring by `thickness / 2`).
|
||||||
|
/// Call `fill()` after this.
|
||||||
|
pub(crate) fn build_fill_path(
|
||||||
|
ctx: &Context,
|
||||||
|
cx: f64,
|
||||||
|
cy: f64,
|
||||||
|
radius: f64,
|
||||||
|
thickness: f64,
|
||||||
|
shape: RingShape,
|
||||||
|
) {
|
||||||
|
let inner_r = (radius - thickness / 2.0).max(0.0);
|
||||||
|
if inner_r <= 0.0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
build_ring_path(ctx, cx, cy, inner_r, shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the normalized `t` offset that places the first password dot at the
|
||||||
|
/// visual top-centre of the shape. May be negative; callers should NOT wrap.
|
||||||
|
pub(crate) fn top_centre_offset(shape: RingShape) -> f64 {
|
||||||
|
match shape {
|
||||||
|
// Circle/Diamond: top at t=0.75 → offset -(1-0.75) = -0.25
|
||||||
|
RingShape::Circle | RingShape::Diamond => -0.25,
|
||||||
|
// Square: top edge centre at t=0.875 → offset -(1-0.875) = -0.125
|
||||||
|
RingShape::Square => -0.125,
|
||||||
|
// Hexagon: top edge centre at t=0.75 → offset -0.25
|
||||||
|
RingShape::Hexagon => -0.25,
|
||||||
|
// Pill: top straight centre at t = 1 - 1/(4+2π) ≈ 0.9027
|
||||||
|
RingShape::Pill => -1.0 / (4.0 + 2.0 * std::f64::consts::PI),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,568 @@
|
|||||||
|
use crate::render::Renderer;
|
||||||
|
use cairo::{Format, ImageSurface};
|
||||||
|
|
||||||
|
impl Renderer {
|
||||||
|
pub(crate) fn load_icons(&mut self) {
|
||||||
|
log::debug!("Attempting to load status icons...");
|
||||||
|
let wifi_names = [
|
||||||
|
"network-wireless-signal-excellent-symbolic",
|
||||||
|
"network-wireless-signal-excellent",
|
||||||
|
"network-wireless-symbolic",
|
||||||
|
"network-wireless",
|
||||||
|
];
|
||||||
|
let wifi_path = self
|
||||||
|
.config
|
||||||
|
.wifi_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &wifi_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if !wifi_path.is_empty() {
|
||||||
|
log::debug!("Resolved WiFi icon path: {}", wifi_path);
|
||||||
|
self.wifi_icon_surface = self.load_icon(&wifi_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let bt_names = [
|
||||||
|
"bluetooth-active-symbolic",
|
||||||
|
"bluetooth-symbolic",
|
||||||
|
"bluetooth-active",
|
||||||
|
"bluetooth",
|
||||||
|
];
|
||||||
|
let bt_path = self
|
||||||
|
.config
|
||||||
|
.bluetooth_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &bt_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if !bt_path.is_empty() {
|
||||||
|
log::debug!("Resolved Bluetooth icon path: {}", bt_path);
|
||||||
|
self.bluetooth_icon_surface = self.load_icon(&bt_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let batt_names = [
|
||||||
|
"battery-level-100-symbolic",
|
||||||
|
"battery-full-symbolic",
|
||||||
|
"battery-full",
|
||||||
|
"battery-level-100",
|
||||||
|
"battery",
|
||||||
|
"battery-symbolic",
|
||||||
|
];
|
||||||
|
let batt_path = self
|
||||||
|
.config
|
||||||
|
.battery_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &batt_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if !batt_path.is_empty() {
|
||||||
|
log::debug!("Resolved Battery icon path: {}", batt_path);
|
||||||
|
self.battery_icon_surface = self.load_icon(&batt_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let prev_names = [
|
||||||
|
"media-skip-backward-symbolic",
|
||||||
|
"media-skip-backward",
|
||||||
|
"media-playlist-repeat-symbolic",
|
||||||
|
];
|
||||||
|
let prev_path = self
|
||||||
|
.config
|
||||||
|
.media_prev_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &prev_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
if !prev_path.is_empty() {
|
||||||
|
self.media_prev_icon_surface = self.load_icon(&prev_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let stop_names = ["media-playback-stop-symbolic", "media-playback-stop"];
|
||||||
|
let stop_path = self
|
||||||
|
.config
|
||||||
|
.media_stop_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &stop_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
if !stop_path.is_empty() {
|
||||||
|
self.media_stop_icon_surface = self.load_icon(&stop_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let play_names = ["media-playback-start-symbolic", "media-playback-start"];
|
||||||
|
let play_path = self
|
||||||
|
.config
|
||||||
|
.media_play_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &play_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
if !play_path.is_empty() {
|
||||||
|
self.media_play_icon_surface = self.load_icon(&play_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let pause_names = ["media-playback-pause-symbolic", "media-playback-pause"];
|
||||||
|
let pause_path = self
|
||||||
|
.config
|
||||||
|
.media_pause_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &pause_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
if !pause_path.is_empty() {
|
||||||
|
self.media_pause_icon_surface = self.load_icon(&pause_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let next_names = ["media-skip-forward-symbolic", "media-skip-forward"];
|
||||||
|
let next_path = self
|
||||||
|
.config
|
||||||
|
.media_next_icon
|
||||||
|
.clone()
|
||||||
|
.or_else(|| {
|
||||||
|
for name in &next_names {
|
||||||
|
if let Some(path) = self.find_system_icon(name) {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
if !next_path.is_empty() {
|
||||||
|
self.media_next_icon_surface = self.load_icon(&next_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn find_system_icon(&self, name: &str) -> Option<String> {
|
||||||
|
let data_dirs = std::env::var("XDG_DATA_DIRS").unwrap_or_default();
|
||||||
|
let mut search_paths = Vec::new();
|
||||||
|
|
||||||
|
for dir in data_dirs.split(':') {
|
||||||
|
let p = std::path::PathBuf::from(dir).join("icons");
|
||||||
|
if p.exists() {
|
||||||
|
search_paths.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let sys_path = std::path::PathBuf::from("/run/current-system/sw/share/icons");
|
||||||
|
if sys_path.exists() {
|
||||||
|
search_paths.push(sys_path);
|
||||||
|
}
|
||||||
|
let usr_path = std::path::PathBuf::from("/usr/share/icons");
|
||||||
|
if usr_path.exists() {
|
||||||
|
search_paths.push(usr_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let themes = [
|
||||||
|
"WhiteSur",
|
||||||
|
"WhiteSur-dark",
|
||||||
|
"WhiteSur-light",
|
||||||
|
"Adwaita",
|
||||||
|
"hicolor",
|
||||||
|
"breeze",
|
||||||
|
"Papirus",
|
||||||
|
];
|
||||||
|
let categories = [
|
||||||
|
"status/symbolic",
|
||||||
|
"actions/symbolic",
|
||||||
|
"devices/symbolic",
|
||||||
|
"status/24",
|
||||||
|
"status/22",
|
||||||
|
"status/16",
|
||||||
|
"status",
|
||||||
|
"actions",
|
||||||
|
"devices",
|
||||||
|
"symbolic/status",
|
||||||
|
"symbolic/actions",
|
||||||
|
"symbolic/devices",
|
||||||
|
"24x24/status",
|
||||||
|
"22x22/status",
|
||||||
|
"16x16/status",
|
||||||
|
"48x48/status",
|
||||||
|
];
|
||||||
|
|
||||||
|
for base in &search_paths {
|
||||||
|
for theme in &themes {
|
||||||
|
for cat in &categories {
|
||||||
|
for ext in [".svg", ".png"] {
|
||||||
|
let icon_path = base.join(theme).join(cat).join(format!("{}{}", name, ext));
|
||||||
|
if icon_path.exists() {
|
||||||
|
return Some(icon_path.to_string_lossy().into_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for base in &search_paths {
|
||||||
|
for theme in &themes {
|
||||||
|
let theme_root = base.join(theme);
|
||||||
|
if !theme_root.exists() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Ok(entries) = std::fs::read_dir(&theme_root) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
if entry.path().is_dir() {
|
||||||
|
for ext in [".svg", ".png"] {
|
||||||
|
let icon_path = entry.path().join(format!("{}{}", name, ext));
|
||||||
|
if icon_path.exists() {
|
||||||
|
return Some(icon_path.to_string_lossy().into_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn load_icon(&self, identifier: &str) -> Option<ImageSurface> {
|
||||||
|
let path = if identifier.starts_with('~') {
|
||||||
|
let home = std::env::var("HOME").unwrap_or_default();
|
||||||
|
std::path::PathBuf::from(identifier.replacen('~', &home, 1))
|
||||||
|
} else {
|
||||||
|
std::path::PathBuf::from(identifier)
|
||||||
|
};
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
if path.extension().and_then(|s| s.to_str()) == Some("svg") {
|
||||||
|
if let Some(surface) = self.load_svg_with_resvg(&path) {
|
||||||
|
return Some(surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match gdk_pixbuf::Pixbuf::from_file(&path) {
|
||||||
|
Ok(pixbuf) => {
|
||||||
|
let w = pixbuf.width();
|
||||||
|
let h = pixbuf.height();
|
||||||
|
let mut surface = ImageSurface::create(Format::ARgb32, w, h).ok()?;
|
||||||
|
{
|
||||||
|
let mut surface_data = surface.data().ok()?;
|
||||||
|
let pix_data = unsafe { pixbuf.pixels() };
|
||||||
|
let n_channels = pixbuf.n_channels();
|
||||||
|
let rowstride = pixbuf.rowstride() as usize;
|
||||||
|
|
||||||
|
for y in 0..h as usize {
|
||||||
|
for x in 0..w as usize {
|
||||||
|
let pix_idx = y * rowstride + x * n_channels as usize;
|
||||||
|
let surf_idx = (y * w as usize + x) * 4;
|
||||||
|
|
||||||
|
if n_channels == 4 {
|
||||||
|
surface_data[surf_idx] = pix_data[pix_idx + 2];
|
||||||
|
surface_data[surf_idx + 1] = pix_data[pix_idx + 1];
|
||||||
|
surface_data[surf_idx + 2] = pix_data[pix_idx];
|
||||||
|
surface_data[surf_idx + 3] = pix_data[pix_idx + 3];
|
||||||
|
} else if n_channels == 3 {
|
||||||
|
surface_data[surf_idx] = pix_data[pix_idx + 2];
|
||||||
|
surface_data[surf_idx + 1] = pix_data[pix_idx + 1];
|
||||||
|
surface_data[surf_idx + 2] = pix_data[pix_idx];
|
||||||
|
surface_data[surf_idx + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(surface)
|
||||||
|
}
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn load_svg_with_resvg(&self, path: &std::path::Path) -> Option<ImageSurface> {
|
||||||
|
use resvg::usvg;
|
||||||
|
let opt = usvg::Options::default();
|
||||||
|
let svg_data = std::fs::read(path).ok()?;
|
||||||
|
let tree = usvg::Tree::from_data(&svg_data, &opt).ok()?;
|
||||||
|
let size = tree.size().to_int_size();
|
||||||
|
let mut pixmap = resvg::tiny_skia::Pixmap::new(size.width(), size.height())?;
|
||||||
|
resvg::render(
|
||||||
|
&tree,
|
||||||
|
resvg::tiny_skia::Transform::default(),
|
||||||
|
&mut pixmap.as_mut(),
|
||||||
|
);
|
||||||
|
let mut surface =
|
||||||
|
ImageSurface::create(Format::ARgb32, size.width() as i32, size.height() as i32).ok()?;
|
||||||
|
{
|
||||||
|
let mut surface_data = surface.data().ok()?;
|
||||||
|
let pix_data = pixmap.data();
|
||||||
|
for i in (0..pix_data.len()).step_by(4) {
|
||||||
|
surface_data[i] = pix_data[i + 2];
|
||||||
|
surface_data[i + 1] = pix_data[i + 1];
|
||||||
|
surface_data[i + 2] = pix_data[i];
|
||||||
|
surface_data[i + 3] = pix_data[i + 3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(surface)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_clock(&self) {
|
||||||
|
use chrono::Local;
|
||||||
|
let now = Local::now();
|
||||||
|
let time_str = now.format("%H:%M").to_string();
|
||||||
|
let date_str = now.format("%A, %B %d").to_string();
|
||||||
|
let center_x = self.width as f64 / 2.0;
|
||||||
|
let center_y = self.height as f64 / 2.0;
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_font_size(48.0);
|
||||||
|
let te = render_try!(self.context.text_extents(&time_str));
|
||||||
|
self.context
|
||||||
|
.move_to(center_x - te.width() / 2.0, center_y + te.height() / 4.0);
|
||||||
|
render_try!(self.context.show_text(&time_str));
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_font_size(14.0);
|
||||||
|
let de = render_try!(self.context.text_extents(&date_str));
|
||||||
|
self.context.move_to(
|
||||||
|
center_x - de.width() / 2.0,
|
||||||
|
center_y + te.height() / 4.0 + 25.0,
|
||||||
|
);
|
||||||
|
render_try!(self.context.show_text(&date_str));
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
let ue = render_try!(self.context.text_extents(&self.uptime_cache));
|
||||||
|
self.context.move_to(
|
||||||
|
center_x - ue.width() / 2.0,
|
||||||
|
center_y + te.height() / 4.0 + 43.0,
|
||||||
|
);
|
||||||
|
render_try!(self.context.show_text(&self.uptime_cache));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_network(&self) {
|
||||||
|
if !self.config.show_network {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let margin = 20.0;
|
||||||
|
let x = margin;
|
||||||
|
let y = margin + 20.0;
|
||||||
|
|
||||||
|
if let Some(ref ssid) = self.system_status.wifi_ssid {
|
||||||
|
if let Some(ref icon) = self.wifi_icon_surface {
|
||||||
|
self.draw_icon_at(x, y - 15.0, icon);
|
||||||
|
let text_x = x + 24.0 + 10.0;
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_font_size(16.0);
|
||||||
|
self.context.move_to(text_x, y);
|
||||||
|
render_try!(self.context.show_text(ssid));
|
||||||
|
} else {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_font_size(16.0);
|
||||||
|
self.context.move_to(x, y);
|
||||||
|
render_try!(self.context.show_text(ssid));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_status(&self) {
|
||||||
|
if let Some(percent) = self.system_status.battery_percent {
|
||||||
|
let margin = 20.0;
|
||||||
|
let icon_width = 30.0;
|
||||||
|
let x = self.width as f64 - margin - icon_width - 50.0;
|
||||||
|
let y = margin + 20.0;
|
||||||
|
|
||||||
|
if let Some(ref icon) = self.battery_icon_surface {
|
||||||
|
self.draw_icon_at(x, y - 15.0, icon);
|
||||||
|
let text_x = x + 24.0 + 10.0;
|
||||||
|
let battery_text = format!("{:.0}%", percent);
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_font_size(16.0);
|
||||||
|
self.context.move_to(text_x, y);
|
||||||
|
render_try!(self.context.show_text(&battery_text));
|
||||||
|
} else {
|
||||||
|
self.draw_battery_icon_at(
|
||||||
|
x,
|
||||||
|
y - 12.0,
|
||||||
|
icon_width,
|
||||||
|
15.0,
|
||||||
|
percent,
|
||||||
|
self.system_status.is_charging,
|
||||||
|
);
|
||||||
|
let battery_text = format!("{:.0}%", percent);
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_font_size(16.0);
|
||||||
|
self.context.move_to(x + icon_width + 10.0, y);
|
||||||
|
render_try!(self.context.show_text(&battery_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_bluetooth(&self) {
|
||||||
|
if !self.config.show_bluetooth {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let margin = 20.0;
|
||||||
|
let x = margin;
|
||||||
|
let y = margin + 50.0;
|
||||||
|
|
||||||
|
let (status_text, is_off) = if self.system_status.bluetooth_connected {
|
||||||
|
(self.system_status.bluetooth_devices.join(", "), false)
|
||||||
|
} else {
|
||||||
|
("Bluetooth off".to_string(), true)
|
||||||
|
};
|
||||||
|
|
||||||
|
let alpha_mult = if is_off { 0.5 } else { 1.0 };
|
||||||
|
|
||||||
|
if let Some(ref icon) = self.bluetooth_icon_surface {
|
||||||
|
self.draw_icon_at_with_alpha(x, y - 12.0, icon, alpha_mult);
|
||||||
|
let text_x = x + 24.0 + 10.0;
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha * alpha_mult);
|
||||||
|
self.context.set_font_size(14.0);
|
||||||
|
self.context.move_to(text_x, y);
|
||||||
|
render_try!(self.context.show_text(&status_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_keyboard_layout(&self) {
|
||||||
|
if self.config.show_keyboard_layout {
|
||||||
|
if let Some(ref layout) = self.system_status.keyboard_layout {
|
||||||
|
let margin = 20.0;
|
||||||
|
let x = margin;
|
||||||
|
let y = margin + 80.0;
|
||||||
|
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, self.fade_alpha);
|
||||||
|
self.context.set_font_size(16.0);
|
||||||
|
let text = format!("Layout: {}", layout);
|
||||||
|
self.context.move_to(x, y);
|
||||||
|
render_try!(self.context.show_text(&text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_icon_at(&self, x: f64, y: f64, surface: &ImageSurface) {
|
||||||
|
self.context.save().unwrap();
|
||||||
|
let target_size = 24.0;
|
||||||
|
let scale =
|
||||||
|
(target_size / surface.width() as f64).min(target_size / surface.height() as f64);
|
||||||
|
self.context.translate(x, y);
|
||||||
|
self.context.scale(scale, scale);
|
||||||
|
if let Err(e) = self.context.set_source_surface(surface, 0.0, 0.0) {
|
||||||
|
log::error!("cairo error: {:?}", e);
|
||||||
|
}
|
||||||
|
if let Err(e) = self.context.paint_with_alpha(self.fade_alpha) {
|
||||||
|
log::error!("cairo error: {:?}", e);
|
||||||
|
}
|
||||||
|
self.context.restore().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_icon_at_with_alpha(
|
||||||
|
&self,
|
||||||
|
x: f64,
|
||||||
|
y: f64,
|
||||||
|
surface: &ImageSurface,
|
||||||
|
alpha: f64,
|
||||||
|
) {
|
||||||
|
self.context.save().unwrap();
|
||||||
|
let target_size = 24.0;
|
||||||
|
let scale =
|
||||||
|
(target_size / surface.width() as f64).min(target_size / surface.height() as f64);
|
||||||
|
self.context.translate(x, y);
|
||||||
|
self.context.scale(scale, scale);
|
||||||
|
if let Err(e) = self.context.set_source_surface(surface, 0.0, 0.0) {
|
||||||
|
log::error!("cairo error: {:?}", e);
|
||||||
|
}
|
||||||
|
if let Err(e) = self.context.paint_with_alpha(self.fade_alpha * alpha) {
|
||||||
|
log::error!("cairo error: {:?}", e);
|
||||||
|
}
|
||||||
|
self.context.restore().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn draw_battery_icon_at(
|
||||||
|
&self,
|
||||||
|
x: f64,
|
||||||
|
y: f64,
|
||||||
|
width: f64,
|
||||||
|
height: f64,
|
||||||
|
percent: f64,
|
||||||
|
charging: bool,
|
||||||
|
) {
|
||||||
|
let alpha = self.fade_alpha;
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 1.0, alpha * 0.5);
|
||||||
|
self.context.set_line_width(2.0);
|
||||||
|
self.context.rectangle(x, y, width, height);
|
||||||
|
render_try!(self.context.stroke());
|
||||||
|
self.context.new_path();
|
||||||
|
self.context
|
||||||
|
.rectangle(x + width, y + height / 4.0, 3.0, height / 2.0);
|
||||||
|
render_try!(self.context.fill());
|
||||||
|
let fill_width = (width - 4.0) * (percent / 100.0);
|
||||||
|
self.context.new_path();
|
||||||
|
if percent < 20.0 {
|
||||||
|
self.context.set_source_rgba(1.0, 0.2, 0.2, alpha);
|
||||||
|
} else {
|
||||||
|
self.context.set_source_rgba(0.2, 1.0, 0.2, alpha * 0.8);
|
||||||
|
}
|
||||||
|
self.context
|
||||||
|
.rectangle(x + 2.0, y + 2.0, fill_width, height - 4.0);
|
||||||
|
render_try!(self.context.fill());
|
||||||
|
if charging {
|
||||||
|
self.context.new_path();
|
||||||
|
self.context.set_source_rgba(1.0, 1.0, 0.0, alpha);
|
||||||
|
let bx = x + width / 2.0;
|
||||||
|
let by = y + height / 2.0;
|
||||||
|
self.context.move_to(bx - 3.0, by + 2.0);
|
||||||
|
self.context.line_to(bx + 1.0, by - 1.0);
|
||||||
|
self.context.line_to(bx - 1.0, by - 1.0);
|
||||||
|
self.context.line_to(bx + 3.0, by - 6.0);
|
||||||
|
self.context.line_to(bx - 1.0, by - 3.0);
|
||||||
|
self.context.line_to(bx + 1.0, by - 3.0);
|
||||||
|
self.context.close_path();
|
||||||
|
render_try!(self.context.fill());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+64
-40
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use cairo::ImageSurface;
|
use cairo::ImageSurface;
|
||||||
use log::debug;
|
use log::warn;
|
||||||
use smithay_client_toolkit::shm::{slot::Buffer, slot::SlotPool};
|
use smithay_client_toolkit::shm::{slot::Buffer, slot::SlotPool};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use wayland_client::globals::GlobalList;
|
use wayland_client::globals::GlobalList;
|
||||||
@@ -39,22 +39,22 @@ impl Screenshot {
|
|||||||
self.apply_blur(radius, times)?;
|
self.apply_blur(radius, times)?;
|
||||||
}
|
}
|
||||||
if let Some((base, factor)) = config.effect_vignette {
|
if let Some((base, factor)) = config.effect_vignette {
|
||||||
self.apply_vignette(base, factor);
|
self.apply_vignette(base, factor)?;
|
||||||
}
|
}
|
||||||
if let Some(pixel_size) = config.effect_pixelate {
|
if let Some(pixel_size) = config.effect_pixelate {
|
||||||
self.apply_pixelate(pixel_size);
|
self.apply_pixelate(pixel_size)?;
|
||||||
}
|
}
|
||||||
if let Some(angle) = config.effect_swirl {
|
if let Some(angle) = config.effect_swirl {
|
||||||
self.apply_swirl(angle);
|
self.apply_swirl(angle)?;
|
||||||
}
|
}
|
||||||
if let Some(factor) = config.effect_melting {
|
if let Some(factor) = config.effect_melting {
|
||||||
self.apply_melting(factor);
|
self.apply_melting(factor)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a swirl effect.
|
/// Apply a swirl effect.
|
||||||
pub fn apply_swirl(&mut self, angle: f32) {
|
pub fn apply_swirl(&mut self, angle: f32) -> Result<()> {
|
||||||
let width = self.surface.width();
|
let width = self.surface.width();
|
||||||
let height = self.surface.height();
|
let height = self.surface.height();
|
||||||
let center_x = width as f32 / 2.0;
|
let center_x = width as f32 / 2.0;
|
||||||
@@ -65,7 +65,7 @@ impl Screenshot {
|
|||||||
let mut data = vec![0u8; stride * height as usize];
|
let mut data = vec![0u8; stride * height as usize];
|
||||||
self.surface
|
self.surface
|
||||||
.with_data(|src| data.copy_from_slice(src))
|
.with_data(|src| data.copy_from_slice(src))
|
||||||
.unwrap();
|
.context("swirl: failed to read surface data")?;
|
||||||
let original = data.clone();
|
let original = data.clone();
|
||||||
|
|
||||||
for y in 0..height {
|
for y in 0..height {
|
||||||
@@ -92,12 +92,13 @@ impl Screenshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut surface_data = self.surface.data().unwrap();
|
let mut surface_data = self.surface.data().context("swirl: failed to write surface data")?;
|
||||||
surface_data.copy_from_slice(&data);
|
surface_data.copy_from_slice(&data);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a melting effect (vertical smear).
|
/// Apply a melting effect (vertical smear).
|
||||||
pub fn apply_melting(&mut self, factor: f32) {
|
pub fn apply_melting(&mut self, factor: f32) -> Result<()> {
|
||||||
let width = self.surface.width();
|
let width = self.surface.width();
|
||||||
let height = self.surface.height();
|
let height = self.surface.height();
|
||||||
|
|
||||||
@@ -105,15 +106,15 @@ impl Screenshot {
|
|||||||
let mut data = vec![0u8; stride * height as usize];
|
let mut data = vec![0u8; stride * height as usize];
|
||||||
self.surface
|
self.surface
|
||||||
.with_data(|src| data.copy_from_slice(src))
|
.with_data(|src| data.copy_from_slice(src))
|
||||||
.unwrap();
|
.context("melting: failed to read surface data")?;
|
||||||
|
|
||||||
use rand::Rng;
|
use rand::RngExt;
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::rng();
|
||||||
|
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
let mut melt_amount = 0.0;
|
let mut melt_amount = 0.0;
|
||||||
for y in 0..height {
|
for y in 0..height {
|
||||||
melt_amount += rng.gen_range(0.0..factor);
|
melt_amount += rng.random_range(0.0..factor);
|
||||||
let src_y = (y as f32 - melt_amount).max(0.0) as i32;
|
let src_y = (y as f32 - melt_amount).max(0.0) as i32;
|
||||||
|
|
||||||
let src_idx = (src_y as usize * stride) + (x as usize * 4);
|
let src_idx = (src_y as usize * stride) + (x as usize * 4);
|
||||||
@@ -130,14 +131,15 @@ impl Screenshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut surface_data = self.surface.data().unwrap();
|
let mut surface_data = self.surface.data().context("melting: failed to write surface data")?;
|
||||||
surface_data.copy_from_slice(&data);
|
surface_data.copy_from_slice(&data);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Pixelate the surface.
|
/// Pixelate the surface.
|
||||||
pub fn apply_pixelate(&mut self, pixel_size: u32) {
|
pub fn apply_pixelate(&mut self, pixel_size: u32) -> Result<()> {
|
||||||
if pixel_size <= 1 {
|
if pixel_size <= 1 {
|
||||||
return;
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let width = self.surface.width();
|
let width = self.surface.width();
|
||||||
@@ -146,7 +148,7 @@ impl Screenshot {
|
|||||||
let mut data = vec![0u8; stride * height as usize];
|
let mut data = vec![0u8; stride * height as usize];
|
||||||
self.surface
|
self.surface
|
||||||
.with_data(|src| data.copy_from_slice(src))
|
.with_data(|src| data.copy_from_slice(src))
|
||||||
.unwrap();
|
.context("pixelate: failed to read surface data")?;
|
||||||
|
|
||||||
for y in (0..height).step_by(pixel_size as usize) {
|
for y in (0..height).step_by(pixel_size as usize) {
|
||||||
for x in (0..width).step_by(pixel_size as usize) {
|
for x in (0..width).step_by(pixel_size as usize) {
|
||||||
@@ -171,9 +173,9 @@ impl Screenshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
let r = (r / count) as u8;
|
let r = r.checked_div(count).unwrap_or(0) as u8;
|
||||||
let g = (g / count) as u8;
|
let g = g.checked_div(count).unwrap_or(0) as u8;
|
||||||
let b = (b / count) as u8;
|
let b = b.checked_div(count).unwrap_or(0) as u8;
|
||||||
|
|
||||||
// Fill the block
|
// Fill the block
|
||||||
for py in 0..pixel_size {
|
for py in 0..pixel_size {
|
||||||
@@ -192,8 +194,9 @@ impl Screenshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut surface_data = self.surface.data().unwrap();
|
let mut surface_data = self.surface.data().context("pixelate: failed to write surface data")?;
|
||||||
surface_data.copy_from_slice(&data);
|
surface_data.copy_from_slice(&data);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a Gaussian blur effect.
|
/// Apply a Gaussian blur effect.
|
||||||
@@ -202,31 +205,42 @@ impl Screenshot {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let width = self.surface.width();
|
let width = self.surface.width() as usize;
|
||||||
let height = self.surface.height();
|
let height = self.surface.height() as usize;
|
||||||
let stride = self.surface.stride() as usize;
|
let stride = self.surface.stride() as usize;
|
||||||
let mut data = vec![0u8; stride * height as usize];
|
let mut data = vec![0u8; stride * height];
|
||||||
|
|
||||||
self.surface
|
self.surface
|
||||||
.with_data(|src| data.copy_from_slice(src))
|
.with_data(|src| data.copy_from_slice(src))
|
||||||
.context("Failed to get surface data")?;
|
.context("blur: failed to read surface data")?;
|
||||||
|
|
||||||
|
// Convert from stride-padded surface data to tight RgbaImage.
|
||||||
|
// Cairo stride may be larger than width*4 for alignment, so copy
|
||||||
|
// row by row to strip the padding.
|
||||||
|
let tight_stride = width * 4;
|
||||||
|
let mut tight = vec![0u8; tight_stride * height];
|
||||||
|
for y in 0..height {
|
||||||
|
let src_off = y * stride;
|
||||||
|
let dst_off = y * tight_stride;
|
||||||
|
tight[dst_off..dst_off + tight_stride]
|
||||||
|
.copy_from_slice(&data[src_off..src_off + tight_stride]);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to image::RgbaImage for processing
|
|
||||||
let mut img: image::ImageBuffer<image::Rgba<u8>, Vec<u8>> =
|
let mut img: image::ImageBuffer<image::Rgba<u8>, Vec<u8>> =
|
||||||
image::ImageBuffer::from_raw(width as u32, height as u32, data)
|
image::ImageBuffer::from_raw(width as u32, height as u32, tight)
|
||||||
.context("Failed to create image buffer")?;
|
.context("blur: failed to create image buffer")?;
|
||||||
|
|
||||||
for _ in 0..times {
|
for _ in 0..times {
|
||||||
let mut rgb_data: Vec<[u8; 3]> =
|
let mut rgb_data: Vec<[u8; 3]> =
|
||||||
Vec::with_capacity((width as usize) * (height as usize));
|
Vec::with_capacity(width * height);
|
||||||
for pixel in img.pixels() {
|
for pixel in img.pixels() {
|
||||||
rgb_data.push([pixel[0], pixel[1], pixel[2]]);
|
rgb_data.push([pixel[0], pixel[1], pixel[2]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fastblur::gaussian_blur(
|
fastblur::gaussian_blur(
|
||||||
&mut rgb_data,
|
&mut rgb_data,
|
||||||
width as usize,
|
width,
|
||||||
height as usize,
|
height,
|
||||||
radius as f32,
|
radius as f32,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -237,15 +251,20 @@ impl Screenshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy back to surface
|
// Copy back from tight buffer into stride-padded surface data
|
||||||
let new_data = img.into_raw();
|
let new_data = img.into_raw();
|
||||||
let mut surface_data = self.surface.data()?;
|
let mut surface_data = self.surface.data()?;
|
||||||
surface_data.copy_from_slice(&new_data);
|
for y in 0..height {
|
||||||
|
let src_off = y * tight_stride;
|
||||||
|
let dst_off = y * stride;
|
||||||
|
surface_data[dst_off..dst_off + tight_stride]
|
||||||
|
.copy_from_slice(&new_data[src_off..src_off + tight_stride]);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply a vignette effect (darken edges).
|
/// Apply a vignette effect (darken edges).
|
||||||
pub fn apply_vignette(&mut self, base: f32, factor: f32) {
|
pub fn apply_vignette(&mut self, base: f32, factor: f32) -> Result<()> {
|
||||||
let width = self.surface.width();
|
let width = self.surface.width();
|
||||||
let height = self.surface.height();
|
let height = self.surface.height();
|
||||||
let center_x = width as f32 / 2.0;
|
let center_x = width as f32 / 2.0;
|
||||||
@@ -256,7 +275,7 @@ impl Screenshot {
|
|||||||
let mut data = vec![0u8; stride * height as usize];
|
let mut data = vec![0u8; stride * height as usize];
|
||||||
self.surface
|
self.surface
|
||||||
.with_data(|src| data.copy_from_slice(src))
|
.with_data(|src| data.copy_from_slice(src))
|
||||||
.unwrap();
|
.context("vignette: failed to read surface data")?;
|
||||||
|
|
||||||
for y in 0..height {
|
for y in 0..height {
|
||||||
for x in 0..width {
|
for x in 0..width {
|
||||||
@@ -265,7 +284,7 @@ impl Screenshot {
|
|||||||
let distance = (dx * dx + dy * dy).sqrt();
|
let distance = (dx * dx + dy * dy).sqrt();
|
||||||
let vignette_factor = base + (1.0 - base) * (distance / max_distance).powf(factor);
|
let vignette_factor = base + (1.0 - base) * (distance / max_distance).powf(factor);
|
||||||
|
|
||||||
let index = ((y * width + x) * 4) as usize;
|
let index = (y as usize * stride) + (x as usize * 4);
|
||||||
for i in 0..3 {
|
for i in 0..3 {
|
||||||
let value = data[index + i] as f32 * vignette_factor;
|
let value = data[index + i] as f32 * vignette_factor;
|
||||||
data[index + i] = value.clamp(0.0, 255.0) as u8;
|
data[index + i] = value.clamp(0.0, 255.0) as u8;
|
||||||
@@ -273,8 +292,9 @@ impl Screenshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut surface_data = self.surface.data().unwrap();
|
let mut surface_data = self.surface.data().context("vignette: failed to write surface data")?;
|
||||||
surface_data.copy_from_slice(&data);
|
surface_data.copy_from_slice(&data);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +332,7 @@ impl ScreenshotManager {
|
|||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
if manager.is_none() {
|
if manager.is_none() {
|
||||||
debug!("zwlr_screencopy_manager_v1 not available");
|
warn!("zwlr_screencopy_manager_v1 not available — backgrounds will not be captured");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self { manager })
|
Ok(Self { manager })
|
||||||
@@ -361,11 +381,15 @@ impl ScreenshotManager {
|
|||||||
|
|
||||||
let raw_data = {
|
let raw_data = {
|
||||||
let mut data = vec![0u8; (info.width * info.height * 4) as usize];
|
let mut data = vec![0u8; (info.width * info.height * 4) as usize];
|
||||||
|
let canvas_end = canvas.len();
|
||||||
for row in 0..height {
|
for row in 0..height {
|
||||||
let src_offset = row * stride;
|
let src_offset = row * stride;
|
||||||
let dst_offset = row * pixel_width;
|
let dst_offset = row * pixel_width;
|
||||||
data[dst_offset..dst_offset + pixel_width]
|
let copy_end = (src_offset + pixel_width).min(canvas_end);
|
||||||
.copy_from_slice(&canvas[src_offset..src_offset + pixel_width]);
|
if copy_end > src_offset {
|
||||||
|
data[dst_offset..dst_offset + pixel_width]
|
||||||
|
.copy_from_slice(&canvas[src_offset..copy_end]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
data
|
data
|
||||||
};
|
};
|
||||||
|
|||||||
+210
-139
@@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default, PartialEq)]
|
||||||
pub struct SystemStatus {
|
pub struct SystemStatus {
|
||||||
pub battery_percent: Option<f64>,
|
pub battery_percent: Option<f64>,
|
||||||
pub is_charging: bool,
|
pub is_charging: bool,
|
||||||
@@ -21,24 +21,31 @@ pub struct SystemStatus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum SystemCommand {
|
pub enum BackendCommand {
|
||||||
PowerOff,
|
PowerOff,
|
||||||
Reboot,
|
Reboot,
|
||||||
Suspend,
|
Suspend,
|
||||||
|
MediaPlayPause,
|
||||||
|
MediaStop,
|
||||||
|
MediaNext,
|
||||||
|
MediaPrev,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SystemManager {
|
pub struct SystemManager {
|
||||||
status: Arc<Mutex<SystemStatus>>,
|
status: Arc<Mutex<SystemStatus>>,
|
||||||
cmd_tx: mpsc::UnboundedSender<SystemCommand>,
|
cmd_tx: mpsc::UnboundedSender<BackendCommand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemManager {
|
impl SystemManager {
|
||||||
pub fn new() -> Self {
|
pub fn new(config: &crate::config::Config) -> Self {
|
||||||
|
let poll_interval = tokio::time::Duration::from_secs(config.system_poll_interval);
|
||||||
|
let reconnect_delay = tokio::time::Duration::from_secs(config.dbus_reconnect_delay);
|
||||||
|
let command_timeout = tokio::time::Duration::from_secs(config.command_timeout);
|
||||||
|
|
||||||
let status = Arc::new(Mutex::new(SystemStatus::default()));
|
let status = Arc::new(Mutex::new(SystemStatus::default()));
|
||||||
let s_clone = status.clone();
|
let s_clone = status.clone();
|
||||||
let (cmd_tx, mut cmd_rx) = mpsc::unbounded_channel::<SystemCommand>();
|
let (cmd_tx, mut cmd_rx) = mpsc::unbounded_channel::<BackendCommand>();
|
||||||
|
|
||||||
// Spawn a thread to update status periodically and handle commands
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
let rt = match tokio::runtime::Runtime::new() {
|
let rt = match tokio::runtime::Runtime::new() {
|
||||||
Ok(rt) => rt,
|
Ok(rt) => rt,
|
||||||
@@ -50,18 +57,19 @@ impl SystemManager {
|
|||||||
|
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
let mut conn: Option<Connection> = None;
|
let mut conn: Option<Connection> = None;
|
||||||
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(2));
|
let mut interval = tokio::time::interval(poll_interval);
|
||||||
let mut last_art_url: Option<String> = None;
|
let mut last_art_url: Option<String> = None;
|
||||||
let mut last_art_data: Option<Arc<Vec<u8>>> = None;
|
let mut last_art_data: Option<Arc<Vec<u8>>> = None;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Try to connect to system DBus if not connected
|
|
||||||
if conn.is_none() {
|
if conn.is_none() {
|
||||||
match Connection::system().await {
|
match Connection::system().await {
|
||||||
Ok(c) => conn = Some(c),
|
Ok(c) => conn = Some(c),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to connect to system DBus: {}", e);
|
error!("Failed to connect to system DBus: {}", e);
|
||||||
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
|
tokio::time::sleep(reconnect_delay).await;
|
||||||
|
interval = tokio::time::interval(poll_interval);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,56 +79,28 @@ impl SystemManager {
|
|||||||
let mut new_status = SystemStatus::default();
|
let mut new_status = SystemStatus::default();
|
||||||
|
|
||||||
if let Some(ref c) = conn {
|
if let Some(ref c) = conn {
|
||||||
// 1. Battery status
|
if let Ok(reply) = c.call_method(
|
||||||
if let Ok(proxy) = upower_dbus::UPowerProxy::new(c).await {
|
Some("org.freedesktop.UPower"),
|
||||||
if let Ok(display_device) = proxy.get_display_device().await {
|
"/org/freedesktop/UPower/devices/DisplayDevice",
|
||||||
new_status.battery_percent = display_device.percentage().await.ok();
|
Some("org.freedesktop.DBus.Properties"),
|
||||||
if let Ok(state) = display_device.state().await {
|
"GetAll",
|
||||||
new_status.is_charging = format!("{:?}", state).contains("Charging");
|
&("org.freedesktop.UPower.Device"),
|
||||||
|
).await {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
if let Ok(props) = reply.body().deserialize::<HashMap<String, zbus::zvariant::OwnedValue>>() {
|
||||||
|
if let Some(v) = props.get("Percentage") {
|
||||||
|
if let Ok(val) = v.downcast_ref::<f64>() {
|
||||||
|
new_status.battery_percent = Some(val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if let Some(v) = props.get("State") {
|
||||||
}
|
if let Ok(state) = v.downcast_ref::<u32>() {
|
||||||
}
|
new_status.is_charging = state == 1;
|
||||||
|
|
||||||
// 2. MPRIS status
|
|
||||||
if let Ok(finder) = PlayerFinder::new() {
|
|
||||||
if let Ok(player) = finder.find_active() {
|
|
||||||
if let Ok(metadata) = player.get_metadata() {
|
|
||||||
new_status.media_title = metadata.title().map(|s| s.to_string());
|
|
||||||
new_status.media_artist = metadata.artists().map(|a| a.join(", "));
|
|
||||||
new_status.media_art_url = metadata.art_url().map(|u| u.to_string());
|
|
||||||
|
|
||||||
if new_status.media_art_url != last_art_url {
|
|
||||||
last_art_url = new_status.media_art_url.clone();
|
|
||||||
last_art_data = None;
|
|
||||||
if let Some(ref url) = last_art_url {
|
|
||||||
if url.starts_with("file://") {
|
|
||||||
let path = url.trim_start_matches("file://");
|
|
||||||
if let Ok(data) = std::fs::read(path) {
|
|
||||||
last_art_data = Some(Arc::new(data));
|
|
||||||
}
|
|
||||||
} else if url.starts_with("http") {
|
|
||||||
#[cfg(feature = "networking")]
|
|
||||||
if let Ok(resp) = reqwest::get(url).await {
|
|
||||||
if let Ok(bytes) = resp.bytes().await {
|
|
||||||
last_art_data = Some(Arc::new(bytes.to_vec()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "networking"))]
|
|
||||||
{
|
|
||||||
log::debug!("Networking disabled, skipping remote album art: {}", url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_status.media_art_data = last_art_data.clone();
|
|
||||||
}
|
}
|
||||||
new_status.media_playing = player.get_playback_status().map(|s| matches!(s, mpris::PlaybackStatus::Playing)).unwrap_or(false);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 3. WiFi status (NetworkManager)
|
|
||||||
if let Some(ref c) = conn {
|
|
||||||
if let Ok(reply) = c.call_method(
|
if let Ok(reply) = c.call_method(
|
||||||
Some("org.freedesktop.NetworkManager"),
|
Some("org.freedesktop.NetworkManager"),
|
||||||
"/org/freedesktop/NetworkManager",
|
"/org/freedesktop/NetworkManager",
|
||||||
@@ -128,54 +108,68 @@ impl SystemManager {
|
|||||||
"GetDevices",
|
"GetDevices",
|
||||||
&(),
|
&(),
|
||||||
).await {
|
).await {
|
||||||
let devices: Vec<zbus::zvariant::OwnedObjectPath> = reply.body().unwrap();
|
if let Ok(devices) = reply.body().deserialize::<Vec<zbus::zvariant::OwnedObjectPath>>() {
|
||||||
for dev_path in devices {
|
for dev_path in devices {
|
||||||
if let Ok(dev_type_reply) = c.call_method(
|
if let Ok(dev_type_reply) = c.call_method(
|
||||||
Some("org.freedesktop.NetworkManager"),
|
Some("org.freedesktop.NetworkManager"),
|
||||||
&dev_path,
|
&dev_path,
|
||||||
Some("org.freedesktop.DBus.Properties"),
|
Some("org.freedesktop.DBus.Properties"),
|
||||||
"Get",
|
"Get",
|
||||||
&("org.freedesktop.NetworkManager.Device", "DeviceType"),
|
&("org.freedesktop.NetworkManager.Device", "DeviceType"),
|
||||||
).await {
|
).await {
|
||||||
let dev_type: u32 = dev_type_reply.body::<zbus::zvariant::Value>().unwrap().downcast().unwrap();
|
if let Ok(val) = dev_type_reply.body().deserialize::<zbus::zvariant::OwnedValue>() {
|
||||||
if dev_type == 2 { // WiFi
|
if let Ok(dev_type) = val.downcast_ref::<u32>() {
|
||||||
if let Ok(active_ap_reply) = c.call_method(
|
if dev_type == 2 {
|
||||||
Some("org.freedesktop.NetworkManager"),
|
if let Ok(active_ap_reply) = c.call_method(
|
||||||
&dev_path,
|
Some("org.freedesktop.NetworkManager"),
|
||||||
Some("org.freedesktop.DBus.Properties"),
|
&dev_path,
|
||||||
"Get",
|
Some("org.freedesktop.DBus.Properties"),
|
||||||
&("org.freedesktop.NetworkManager.Device.Wireless", "ActiveAccessPoint"),
|
"Get",
|
||||||
).await {
|
&("org.freedesktop.NetworkManager.Device.Wireless", "ActiveAccessPoint"),
|
||||||
let ap_path: zbus::zvariant::OwnedObjectPath = active_ap_reply.body::<zbus::zvariant::Value>().unwrap().downcast().unwrap();
|
).await {
|
||||||
if ap_path.as_str() != "/" {
|
if let Ok(ap_val) = active_ap_reply.body().deserialize::<zbus::zvariant::OwnedValue>() {
|
||||||
if let Ok(ssid_reply) = c.call_method(
|
if let Ok(ap_path) = ap_val.downcast_ref::<zbus::zvariant::ObjectPath>() {
|
||||||
Some("org.freedesktop.NetworkManager"),
|
if ap_path.as_str() != "/" {
|
||||||
&ap_path,
|
if let Ok(ssid_reply) = c.call_method(
|
||||||
Some("org.freedesktop.DBus.Properties"),
|
Some("org.freedesktop.NetworkManager"),
|
||||||
"Get",
|
&ap_path,
|
||||||
&("org.freedesktop.NetworkManager.AccessPoint", "Ssid"),
|
Some("org.freedesktop.DBus.Properties"),
|
||||||
).await {
|
"Get",
|
||||||
let ssid_bytes: Vec<u8> = ssid_reply.body::<zbus::zvariant::Value>().unwrap().downcast().unwrap();
|
&("org.freedesktop.NetworkManager.AccessPoint", "Ssid"),
|
||||||
new_status.wifi_ssid = Some(String::from_utf8_lossy(&ssid_bytes).to_string());
|
).await {
|
||||||
}
|
if let Ok(ssid_val) = ssid_reply.body().deserialize::<zbus::zvariant::OwnedValue>() {
|
||||||
if let Ok(strength_reply) = c.call_method(
|
let ssid_bytes: Result<Vec<u8>, _> = ssid_val.try_into();
|
||||||
Some("org.freedesktop.NetworkManager"),
|
if let Ok(ssid_bytes) = ssid_bytes {
|
||||||
&ap_path,
|
new_status.wifi_ssid = Some(String::from_utf8_lossy(&ssid_bytes).to_string());
|
||||||
Some("org.freedesktop.DBus.Properties"),
|
}
|
||||||
"Get",
|
}
|
||||||
&("org.freedesktop.NetworkManager.AccessPoint", "Strength"),
|
}
|
||||||
).await {
|
if let Ok(strength_reply) = c.call_method(
|
||||||
new_status.wifi_strength = Some(strength_reply.body::<zbus::zvariant::Value>().unwrap().downcast().unwrap());
|
Some("org.freedesktop.NetworkManager"),
|
||||||
|
&ap_path,
|
||||||
|
Some("org.freedesktop.DBus.Properties"),
|
||||||
|
"Get",
|
||||||
|
&("org.freedesktop.NetworkManager.AccessPoint", "Strength"),
|
||||||
|
).await {
|
||||||
|
if let Ok(strength_val) = strength_reply.body().deserialize::<zbus::zvariant::OwnedValue>() {
|
||||||
|
if let Ok(strength) = strength_val.downcast_ref::<u8>() {
|
||||||
|
new_status.wifi_strength = Some(strength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Bluetooth status (BlueZ)
|
|
||||||
if let Ok(objects_reply) = c.call_method(
|
if let Ok(objects_reply) = c.call_method(
|
||||||
Some("org.bluez"),
|
Some("org.bluez"),
|
||||||
"/",
|
"/",
|
||||||
@@ -185,15 +179,18 @@ impl SystemManager {
|
|||||||
).await {
|
).await {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
type ManagedObjects = HashMap<zbus::zvariant::OwnedObjectPath, HashMap<String, HashMap<String, zbus::zvariant::OwnedValue>>>;
|
type ManagedObjects = HashMap<zbus::zvariant::OwnedObjectPath, HashMap<String, HashMap<String, zbus::zvariant::OwnedValue>>>;
|
||||||
if let Ok(objects) = objects_reply.body::<ManagedObjects>() {
|
if let Ok(objects) = objects_reply.body().deserialize::<ManagedObjects>() {
|
||||||
for (_path, interfaces) in objects {
|
for (_path, interfaces) in objects {
|
||||||
if let Some(device) = interfaces.get("org.bluez.Device1") {
|
if let Some(device) = interfaces.get("org.bluez.Device1") {
|
||||||
if let Some(connected) = device.get("Connected") {
|
if let Some(connected) = device.get("Connected") {
|
||||||
if connected.downcast_ref::<bool>().copied().unwrap_or(false) {
|
if let Ok(connected) = connected.downcast_ref::<bool>() {
|
||||||
new_status.bluetooth_connected = true;
|
if connected {
|
||||||
if let Some(name) = device.get("Name") {
|
new_status.bluetooth_connected = true;
|
||||||
let name_str: String = name.downcast_ref::<str>().map(|s| s.to_string()).unwrap_or_default();
|
if let Some(name) = device.get("Name") {
|
||||||
new_status.bluetooth_devices.push(name_str);
|
if let Ok(name_str) = name.downcast_ref::<String>() {
|
||||||
|
new_status.bluetooth_devices.push(name_str.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -203,35 +200,114 @@ impl SystemManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mpris_status = tokio::task::spawn_blocking(move || {
|
||||||
|
let mut media_title = None;
|
||||||
|
let mut media_artist = None;
|
||||||
|
let mut media_art_url = None;
|
||||||
|
let mut media_playing = false;
|
||||||
|
if let Ok(finder) = PlayerFinder::new() {
|
||||||
|
if let Ok(player) = finder.find_active() {
|
||||||
|
if let Ok(metadata) = player.get_metadata() {
|
||||||
|
media_title = metadata.title().map(|s| s.to_string());
|
||||||
|
media_artist = metadata.artists().map(|a| a.join(", "));
|
||||||
|
media_art_url = metadata.art_url().map(|u| u.to_string());
|
||||||
|
}
|
||||||
|
media_playing = player.get_playback_status().map(|s| matches!(s, mpris::PlaybackStatus::Playing)).unwrap_or(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(media_title, media_artist, media_art_url, media_playing)
|
||||||
|
}).await.unwrap_or((None, None, None, false));
|
||||||
|
|
||||||
|
new_status.media_title = mpris_status.0;
|
||||||
|
new_status.media_artist = mpris_status.1;
|
||||||
|
new_status.media_art_url = mpris_status.2;
|
||||||
|
new_status.media_playing = mpris_status.3;
|
||||||
|
|
||||||
|
if new_status.media_art_url != last_art_url {
|
||||||
|
last_art_url = new_status.media_art_url.clone();
|
||||||
|
last_art_data = None;
|
||||||
|
if let Some(ref url) = last_art_url {
|
||||||
|
if url.starts_with("file://") {
|
||||||
|
let path = url.trim_start_matches("file://");
|
||||||
|
if let Ok(data) = std::fs::read(path) {
|
||||||
|
last_art_data = Some(Arc::new(data));
|
||||||
|
}
|
||||||
|
} else if url.starts_with("http") {
|
||||||
|
#[cfg(feature = "networking")]
|
||||||
|
if let Ok(resp) = reqwest::get(url).await {
|
||||||
|
if let Ok(bytes) = resp.bytes().await {
|
||||||
|
last_art_data = Some(Arc::new(bytes.to_vec()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "networking"))]
|
||||||
|
{
|
||||||
|
log::debug!("Networking disabled, skipping remote album art: {}", url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new_status.media_art_data = last_art_data.clone();
|
||||||
|
|
||||||
{
|
{
|
||||||
if let Ok(mut s) = s_clone.lock() {
|
if let Ok(mut s) = s_clone.lock() {
|
||||||
*s = new_status;
|
*s = new_status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(command) = cmd_rx.recv() => {
|
Some(cmd) = cmd_rx.recv() => {
|
||||||
if let Some(ref c) = conn {
|
match cmd {
|
||||||
let method = match command {
|
BackendCommand::PowerOff
|
||||||
SystemCommand::PowerOff => "PowerOff",
|
| BackendCommand::Reboot
|
||||||
SystemCommand::Reboot => "Reboot",
|
| BackendCommand::Suspend => {
|
||||||
SystemCommand::Suspend => "Suspend",
|
if let Some(ref c) = conn {
|
||||||
};
|
// Safety: only PowerOff/Reboot/Suspend reach this
|
||||||
|
// branch due to the outer match arm.
|
||||||
debug!("Executing system command: {}", method);
|
let method = match cmd {
|
||||||
// Set a timeout for the DBus call to prevent hanging the background thread
|
BackendCommand::PowerOff => "PowerOff",
|
||||||
let result = tokio::time::timeout(
|
BackendCommand::Reboot => "Reboot",
|
||||||
tokio::time::Duration::from_secs(5),
|
BackendCommand::Suspend => "Suspend",
|
||||||
c.call_method(
|
BackendCommand::MediaPlayPause
|
||||||
Some("org.freedesktop.login1"),
|
| BackendCommand::MediaStop
|
||||||
"/org/freedesktop/login1",
|
| BackendCommand::MediaNext
|
||||||
Some("org.freedesktop.login1.Manager"),
|
| BackendCommand::MediaPrev => {
|
||||||
method,
|
unreachable!("media command in power branch: {:?}", cmd)
|
||||||
&(true),
|
}
|
||||||
)
|
};
|
||||||
).await;
|
debug!("Executing system command: {}", method);
|
||||||
|
let result = tokio::time::timeout(
|
||||||
if result.is_err() {
|
command_timeout,
|
||||||
error!("System command {} timed out", method);
|
c.call_method(
|
||||||
|
Some("org.freedesktop.login1"),
|
||||||
|
"/org/freedesktop/login1",
|
||||||
|
Some("org.freedesktop.login1.Manager"),
|
||||||
|
method,
|
||||||
|
&(true),
|
||||||
|
)
|
||||||
|
).await;
|
||||||
|
if result.is_err() {
|
||||||
|
error!("System command {} timed out", method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BackendCommand::MediaPlayPause
|
||||||
|
| BackendCommand::MediaStop
|
||||||
|
| BackendCommand::MediaNext
|
||||||
|
| BackendCommand::MediaPrev => {
|
||||||
|
let action = cmd;
|
||||||
|
// Fire-and-forget: don't block the polling loop on MPRIS.
|
||||||
|
tokio::task::spawn_blocking(move || {
|
||||||
|
if let Ok(finder) = PlayerFinder::new() {
|
||||||
|
if let Ok(player) = finder.find_active() {
|
||||||
|
match action {
|
||||||
|
BackendCommand::MediaPlayPause => { let _ = player.play_pause(); }
|
||||||
|
BackendCommand::MediaStop => { let _ = player.stop(); }
|
||||||
|
BackendCommand::MediaNext => { let _ = player.next(); }
|
||||||
|
BackendCommand::MediaPrev => { let _ = player.previous(); }
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -244,34 +320,29 @@ impl SystemManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_status(&self) -> SystemStatus {
|
pub fn get_status(&self) -> SystemStatus {
|
||||||
self.status.lock().unwrap().clone()
|
self.status
|
||||||
|
.lock()
|
||||||
|
.map(|s| s.clone())
|
||||||
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_command(&self, cmd: SystemCommand) {
|
pub fn send_command(&self, cmd: BackendCommand) {
|
||||||
let _ = self.cmd_tx.send(cmd);
|
let _ = self.cmd_tx.send(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn media_play_pause(&self) {
|
pub fn media_play_pause(&self) {
|
||||||
if let Ok(finder) = PlayerFinder::new() {
|
let _ = self.cmd_tx.send(BackendCommand::MediaPlayPause);
|
||||||
if let Ok(player) = finder.find_active() {
|
}
|
||||||
let _ = player.play_pause();
|
|
||||||
}
|
pub fn media_stop(&self) {
|
||||||
}
|
let _ = self.cmd_tx.send(BackendCommand::MediaStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn media_next(&self) {
|
pub fn media_next(&self) {
|
||||||
if let Ok(finder) = PlayerFinder::new() {
|
let _ = self.cmd_tx.send(BackendCommand::MediaNext);
|
||||||
if let Ok(player) = finder.find_active() {
|
|
||||||
let _ = player.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn media_prev(&self) {
|
pub fn media_prev(&self) {
|
||||||
if let Ok(finder) = PlayerFinder::new() {
|
let _ = self.cmd_tx.send(BackendCommand::MediaPrev);
|
||||||
if let Ok(player) = finder.find_active() {
|
|
||||||
let _ = player.previous();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+79
@@ -1,3 +1,5 @@
|
|||||||
|
use serde::{Deserialize, Deserializer, Serializer};
|
||||||
|
|
||||||
pub fn parse_hex_color(s: &str) -> Result<(f64, f64, f64, f64), String> {
|
pub fn parse_hex_color(s: &str) -> Result<(f64, f64, f64, f64), String> {
|
||||||
let s = s.trim_start_matches('#');
|
let s = s.trim_start_matches('#');
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
@@ -19,6 +21,34 @@ pub fn parse_hex_color(s: &str) -> Result<(f64, f64, f64, f64), String> {
|
|||||||
Ok((r, g, b, a))
|
Ok((r, g, b, a))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_hex_color<'de, D>(deserializer: D) -> Result<(f64, f64, f64, f64), D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = String::deserialize(deserializer)?;
|
||||||
|
parse_hex_color(&s).map_err(serde::de::Error::custom)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_hex_color<S>(
|
||||||
|
color: &(f64, f64, f64, f64),
|
||||||
|
serializer: S,
|
||||||
|
) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
let (r, g, b, a) = color;
|
||||||
|
let r = (r * 255.0) as u8;
|
||||||
|
let g = (g * 255.0) as u8;
|
||||||
|
let b = (b * 255.0) as u8;
|
||||||
|
let a = (a * 255.0) as u8;
|
||||||
|
|
||||||
|
if a == 255 {
|
||||||
|
serializer.serialize_str(&format!("{:02x}{:02x}{:02x}", r, g, b))
|
||||||
|
} else {
|
||||||
|
serializer.serialize_str(&format!("{:02x}{:02x}{:02x}{:02x}", r, g, b, a))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_blur_effect(s: &str) -> Result<(u32, u32), String> {
|
pub fn parse_blur_effect(s: &str) -> Result<(u32, u32), String> {
|
||||||
let parts: Vec<&str> = s.split('x').collect();
|
let parts: Vec<&str> = s.split('x').collect();
|
||||||
if parts.len() != 2 {
|
if parts.len() != 2 {
|
||||||
@@ -29,6 +59,29 @@ pub fn parse_blur_effect(s: &str) -> Result<(u32, u32), String> {
|
|||||||
Ok((radius, times))
|
Ok((radius, times))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_blur_effect<'de, D>(deserializer: D) -> Result<Option<(u32, u32)>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = Option::<String>::deserialize(deserializer)?;
|
||||||
|
match s {
|
||||||
|
Some(s) => parse_blur_effect(&s)
|
||||||
|
.map(Some)
|
||||||
|
.map_err(serde::de::Error::custom),
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_blur_effect<S>(val: &Option<(u32, u32)>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match val {
|
||||||
|
Some((radius, times)) => serializer.serialize_str(&format!("{}x{}", radius, times)),
|
||||||
|
None => serializer.serialize_none(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_vignette_effect(s: &str) -> Result<(f32, f32), String> {
|
pub fn parse_vignette_effect(s: &str) -> Result<(f32, f32), String> {
|
||||||
let parts: Vec<&str> = s.split(':').collect();
|
let parts: Vec<&str> = s.split(':').collect();
|
||||||
if parts.len() != 2 {
|
if parts.len() != 2 {
|
||||||
@@ -38,3 +91,29 @@ pub fn parse_vignette_effect(s: &str) -> Result<(f32, f32), String> {
|
|||||||
let factor = parts[1].parse().map_err(|_| "Invalid factor")?;
|
let factor = parts[1].parse().map_err(|_| "Invalid factor")?;
|
||||||
Ok((base, factor))
|
Ok((base, factor))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn deserialize_vignette_effect<'de, D>(deserializer: D) -> Result<Option<(f32, f32)>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = Option::<String>::deserialize(deserializer)?;
|
||||||
|
match s {
|
||||||
|
Some(s) => parse_vignette_effect(&s)
|
||||||
|
.map(Some)
|
||||||
|
.map_err(serde::de::Error::custom),
|
||||||
|
None => Ok(None),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_vignette_effect<S>(
|
||||||
|
val: &Option<(f32, f32)>,
|
||||||
|
serializer: S,
|
||||||
|
) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
match val {
|
||||||
|
Some((base, factor)) => serializer.serialize_str(&format!("{}:{}", base, factor)),
|
||||||
|
None => serializer.serialize_none(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user