Compare commits
21 Commits
side-pills
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 303764732b | |||
| 184da49c2f | |||
| e963c944e8 | |||
| c24671e981 | |||
| 90130add06 | |||
| 1b8fc66130 | |||
| f79662bd5b | |||
| e0d8a5479c | |||
| 344d318959 | |||
| 801eab9ab4 | |||
| c0fff44bcf | |||
| f55314f511 | |||
| 3de3709871 | |||
| 0457830aba | |||
| 689b53be0f | |||
| f8c17025ce | |||
| aadf765d87 | |||
| 756f38be4e | |||
| 7cb2368b23 | |||
| 8cbd211da0 | |||
| e2ef1a9d52 |
@@ -113,7 +113,7 @@ Whether the open card takes the song cover's colours instead (`appearance.colors
|
||||
|
||||
## Side pills
|
||||
|
||||
Two small one-icon pills sit left of the island and two right of it, on every monitor; they move outward while the island opens. A click morphs a pill into its card. Only one card is open across the shell: opening the island closes a card, and opening a card closes the island. Esc, the cross or a click elsewhere closes it.
|
||||
Two small one-icon pills sit left of the island and two right of it, on every monitor, each in its own colour (`pills.colors.*`; Home's follows the sky). A click grows a pill into a big card in the middle of the top of the screen; meanwhile the row becomes a carousel: the other pills and the island's pill line up two left and two right of the card in their usual order (around Home: AI and System left, the island and the bell right), and clicking one switches straight to its card (the island's pill closes the card, then opens the island). A closing card shrinks back into its own pill's place. Only one card is open across the shell. Esc, the cross or a click elsewhere closes it.
|
||||
|
||||
- **AI** (sparkle): a chat with an Ollama model on your own servers, `gemma4:e4b` at `http://localhost:11434` by default. `pills.ai.servers` takes several, comma-separated, in order: the model chip in the header lists every server's models (each once, with its server when there are several) and switches at once, and a question goes to the first server that has the chosen model. Answers stream in through curl. When Ollama doesn't answer, the shell starts the OpenRC service with `doas rc-service ollama start` (`pills.ai.start_service`). Stop ends an answer and New chat starts over. Nothing goes to a cloud service, only to the servers listed.
|
||||
- **System** (pulse): CPU, the integrated GPU's clock, the external GPU's load (with its video memory and the programs on it, formerly in the control centre), memory, swap, network and disk read/write as graphs over the last minute, plus the hottest sensors with icons, in cool/warm/hot colours (`pills.monitor.warm|hot`). Everything is read from `/proc` and `/sys`, so there is no process list. Processes opens `ghostty --class=amane.monitor -e btm` on the special workspace `monitor`; a second press shows or hides it.
|
||||
@@ -124,6 +124,16 @@ Two small one-icon pills sit left of the island and two right of it, on every mo
|
||||
|
||||
Left out on purpose: phone stats (iOS shares nothing Linux can read without extra daemons).
|
||||
|
||||
## Lock screen
|
||||
|
||||
`amane ipc call lock` locks the session (ext-session-lock; bind it to a key or an idle daemon yourself). Every monitor shows the wallpaper blurred and darkened, the date with Munich's weather now, a big clock, Hyprland's splash message, what plays with its cover, how far it is and previous/play/next (they work while locked), chips for the next calendar event, the new notifications and the battery, and at the bottom `~/.face`, your name and the password field. The monitors share one field. Enter checks the password with PAM as `login` does; a wrong one lights the field's rim and says so. Each part can be switched off and every size is a setting (`lock.look.*`, `lock.show.*`, the Lock screen page).
|
||||
|
||||
The picture is `lock.look.wallpaper`, or else the wallpaper the colours came from: `matugen/amane.colors` writes its path into the theme file (`wallpaper=`), so it's there after the next wallpaper change. Without either, the colours' gradient. Amane reads PNG and JPEG only.
|
||||
|
||||
It redraws for the music's progress, the clock and typing, so it's cheap to draw: the backdrop (the gradient, and the veil over the picture, darker toward the corners, `lock.look.vignette`) is one shader, `src/lock.wgsl`, and every icon goes into one canvas. Measured in a preview on one 1080p monitor: 0.8 ms per frame to submit and present (2.4 ms before), the GPU's render engine half as busy.
|
||||
|
||||
Killing the shell does not unlock: Hyprland keeps the session locked and shows its own error screen. Keep a second TTY logged in when trying changes to the lock screen.
|
||||
|
||||
## Settings
|
||||
|
||||
Every setting lives in `~/.config/amane/config.toml`: sizes, timings, text sizes, colours, poll intervals, equalizer presets and bands, the hotspot profile, the extra Sound output. The shell writes the file with every setting and its explanation the first time it starts (moving `cover_colors`, `transition_ms`, `hotspot` and `extra_output` over from an old `shell.conf`, which it no longer reads). Saving the file applies it at once; a line left out takes its default, and a line the shell can't use is listed at the top of the config window. The font and the cava bar count take effect on restart.
|
||||
@@ -132,7 +142,9 @@ The config window edits the same file: Settings at the foot of the control centr
|
||||
|
||||
### Glass
|
||||
|
||||
`appearance.surface.design` picks what the island, the pills, the tray menu, the control centre and its popups are made of: `solid` (the wallpaper's gradient with an accent glow), `frosted` (a thin tint, a hairline white rim, a sheen along the top, a soft shadow) or `liquid` (clear glass, denser toward the bottom right, a light-catching edge, the accent's glow). Each design's opacity, rim and light are settings of their own (`appearance.solid|frosted|liquid.*`); the look itself is `src/surface.rs`, drawn by one shader (`src/surface.wgsl`: the shadow, the fill and the sheen or lit edge in one pass; the rim stays a border). On see-through glass a face fades with `.opacity()` instead of a veil, a GPU layer only while it fades.
|
||||
`appearance.surface.design` picks what the island, the pills, the tray menu, the control centre and its popups are made of: `solid` (the wallpaper's gradient with an accent glow), `frosted` (a thin tint, a hairline white rim, a sheen along the top, a soft shadow), `liquid` (clear glass, denser toward the bottom right, a light-catching edge, the accent's glow) or `glass` (after Apple's Liquid Glass: a thin tint and an edge like the rim of a lens, brightest where the light falls in at the top left, a glint where it leaves at the bottom right, a thin specular line and a faint warm and cool fringe). Each design's opacity, rim and light are settings of their own (`appearance.solid|frosted|liquid|glass.*`); the look itself is `src/surface.rs`, drawn by one shader (`src/surface.wgsl`: the shadow, the fill and the sheen or lit edge in one pass; the rim stays a border). `glass` has its own, `src/glass.wgsl`, drawn twice: the shadow and tint under the content, the lit edge over it, so a photo on a card lies behind the glass. Unlike Apple's, it doesn't bend the desktop at the rim: a shell's shader never sees what's behind its window, Hyprland's blur is all it has. On see-through glass a face fades with `.opacity()` instead of a veil, a GPU layer only while it fades.
|
||||
|
||||
Screenshots of each design, from when they were made: `docs/design/` (`base-solid-card.png`, `base-glass-0.5-card.png` for solid below 1, `frosted-0.62-card.png`, `liquid-0.4-card.png`, and a board for each glass design: the card three times side by side, with the pills below).
|
||||
|
||||
### Performance
|
||||
|
||||
@@ -140,7 +152,7 @@ Amane draws rectangles, borders, letters and pictures as cheap quads, and gradie
|
||||
|
||||
`tools/perf.sh PID [SECONDS]` (on the desktop) prints a process's CPU (and its children's), GPU per engine (DRM fdinfo) and memory.
|
||||
|
||||
Amane can only blur what the shell draws, so the frosting comes from Hyprland: a layer rule for the shell's windows (the namespace match is a full match). `ignore_alpha` leaves pixels at or below that opacity unblurred, which keeps the clear margin around the pills sharp; keep it below the design's thinnest part, or that part shows the desktop unblurred (liquid at its default 0.4 is 0.22 in its top left corner).
|
||||
Amane can only blur what the shell draws, so the frosting comes from Hyprland: a layer rule for the shell's windows (the namespace match is a full match). `ignore_alpha` leaves pixels at or below that opacity unblurred, which keeps the clear margin around the pills sharp; keep it below the design's thinnest part, or that part shows the desktop unblurred (liquid at its default 0.4 is 0.22 in its top left corner; glass is its `opacity` all over, 0.32 by default).
|
||||
|
||||
```lua
|
||||
hl.layer_rule({
|
||||
@@ -183,8 +195,9 @@ src/png.rs a stdlib png writer, for tray icons sent as pixels
|
||||
src/system.rs what the control centre shows: iwd, wired cards, openvpn, power, the external GPU
|
||||
src/glyph.rs every drawn icon, as a Canvas or as shapes for a shared one
|
||||
src/theme.rs the shell's colours: the matugen theme file, the cross-fade; watches config.toml
|
||||
src/surface.rs what the island, pills, menus and popups are made of: the solid, frosted and liquid designs as values for surface.wgsl
|
||||
src/*.wgsl shaders: surface (every surface), ring (the candles), curve (the equalizer's line)
|
||||
src/lock.rs the lock screen (amane's App::lock), `lock` IPC
|
||||
src/surface.rs what the island, pills, menus and popups are made of: the solid, frosted and liquid designs as values for surface.wgsl, glass for glass.wgsl
|
||||
src/*.wgsl shaders: surface (every surface), glass (the glass design), ring (the candles), curve (the equalizer's line), lock (the lock screen's backdrop)
|
||||
src/config.rs every setting, declared once (typed accessors + the window's list), config.toml read and written
|
||||
src/hypr.rs Hyprland's options for the config window: hyprctl descriptions/getoption, hl.config, amane.lua
|
||||
src/settings.rs the config window, `config` IPC
|
||||
@@ -202,6 +215,7 @@ On the desktop that runs the shell:
|
||||
- PipeWire with `pipewire-pulse`: `pactl`, `pw-record`, `pw-cli`, `pipewire` (filter-chain module)
|
||||
- `cava`, `curl`
|
||||
- the Fira Code font
|
||||
- PAM (`/etc/pam.d/login`), for the lock screen's password
|
||||
- for the control centre: `iwd`, openrc `openvpn.<name>` services, `pciutils` (`lspci`), `wl-clipboard` (`wl-copy`, for copying a saved password or an address), `iproute2` (`ip`, for the Ethernet details), optionally `bluez` (with `bluetoothctl`), and a doas rule without a password for `rc-service`, `sh` and `cat` (see [Control centre](#control-centre))
|
||||
|
||||
## Install and run
|
||||
@@ -233,6 +247,7 @@ amane ipc call config set island.pill.width 260 # any setting by its con
|
||||
amane ipc call config set hyprland.decoration.blur.size 3
|
||||
amane ipc call config reset island.pill.width
|
||||
amane ipc call config status # open=<bool> page=<id> errors=<n> search=<words>
|
||||
amane ipc call lock # lock the session
|
||||
```
|
||||
|
||||
Example Hyprland keybind:
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 348 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 175 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 328 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 880 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 381 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
@@ -10,3 +10,5 @@ outline={{colors.outline_variant.default.hex}}
|
||||
surface={{colors.surface_container.default.hex}}
|
||||
surface_high={{colors.surface_container_high.default.hex}}
|
||||
surface_low={{colors.surface_container_lowest.default.hex}}
|
||||
# the picture the colours came from, for the lock screen
|
||||
wallpaper={{image}}
|
||||
|
||||
+157
-32
@@ -1,7 +1,10 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{LazyLock, Mutex, PoisonError, RwLock};
|
||||
use std::thread::LocalKey;
|
||||
|
||||
use amane::Color;
|
||||
|
||||
@@ -181,7 +184,11 @@ macro_rules! settings {
|
||||
$(
|
||||
#[allow(dead_code)]
|
||||
pub fn $name() -> $ty {
|
||||
super::super::get(concat!(stringify!($module), ".", stringify!($group), ".", stringify!($name)), || $default)
|
||||
std::thread_local! {
|
||||
static SLOT: std::cell::RefCell<(u64, Option<$ty>)> = const { std::cell::RefCell::new((0, None)) };
|
||||
}
|
||||
|
||||
super::super::cached(&SLOT, concat!(stringify!($module), ".", stringify!($group), ".", stringify!($name)), || $default)
|
||||
}
|
||||
)*
|
||||
} )*
|
||||
@@ -225,7 +232,7 @@ settings! {
|
||||
hover_ms: u64 = 220, 0..=2000; "How long hover highlights take to fade in and out"
|
||||
}
|
||||
surface {
|
||||
design: String ["solid", "frosted", "liquid"] = String::from("solid"); "What the island, the pills, the menus, the control centre and its popups are made of: solid (the wallpaper's gradient with an accent glow), frosted (a thin tint, a hairline rim and a sheen) or liquid (clear glass with a light-catching edge). See-through ones need Hyprland's blur behind the shell: README, Glass"
|
||||
design: String ["solid", "frosted", "liquid", "glass"] = String::from("solid"); "What the island, the pills, the menus, the control centre and its popups are made of: solid (the wallpaper's gradient with an accent glow), frosted (a thin tint, a hairline rim and a sheen), liquid (clear glass with a light-catching edge) or glass (after Apple's Liquid Glass: a thin tint with a lens-like rim). See-through ones need Hyprland's blur behind the shell: README, Glass"
|
||||
}
|
||||
solid {
|
||||
opacity: f32 = 1.0, 0.05..=1.0; "How opaque the solid design is; below 1 the desktop shows through"
|
||||
@@ -245,6 +252,14 @@ settings! {
|
||||
light: f32 = 0.235, 0.0..=1.0; "Opacity of the light caught at the top left edge"
|
||||
glow: f32 = 0.22, 0.0..=1.0; "Strength of the accent glow around each surface"
|
||||
}
|
||||
glass {
|
||||
opacity: f32 = 0.32, 0.05..=1.0; "How strongly the glass is tinted in its middle. Keep it above the ignore_alpha of Hyprland's layer rule, or the desktop behind isn't blurred (README, Glass)"
|
||||
edge: f32 = 16.0, 1..=60; "Width of the band along the rim that catches the light like the edge of a lens, in pixels"
|
||||
light: f32 = 0.55, 0.0..=1.0; "Strength of the light caught where it falls in (top left) and where it leaves (bottom right)"
|
||||
rim: f32 = 0.5, 0.0..=1.0; "Strength of the thin bright line on the rim"
|
||||
dispersion: f32 = 0.3, 0.0..=1.0; "Strength of the warm and cool fringe along the rim, as glass splits light"
|
||||
shadow: f32 = 0.18, 0.0..=1.0; "Strength of the soft shadow under each surface"
|
||||
}
|
||||
fallback {
|
||||
accent: Color = Color::rgb(247, 168, 200); "Accent, used until matugen writes ~/.config/amane/theme from the wallpaper"
|
||||
on_accent: Color = Color::rgb(40, 18, 32); "Text and icons on the accent colour, without a theme file"
|
||||
@@ -504,25 +519,38 @@ settings! {
|
||||
layout {
|
||||
gap: f32 = 10.0, 0..=200; "Space between the island's pill and the small pills beside it"
|
||||
spacing: f32 = 8.0, 0..=100; "Space between the small pills on one side"
|
||||
icon: f32 = 16.0, 6..=40; "Size of the small pills' icons"
|
||||
icon: f32 = 18.0, 6..=40; "Size of the small pills' icons"
|
||||
open_ms: u64 = 420, 0..=5000; "How long a small pill takes to open into its card, and to close"
|
||||
radius: f32 = 22.0, 0..=60; "Corner radius of the opened cards"
|
||||
pad: f32 = 18.0, 0..=60; "Padding inside the opened cards"
|
||||
reveal_at: f32 = 0.2, 0..=1; "How much of a closing card's growth is left when the pills beside it start to show again behind it (0 = only once it's closed)"
|
||||
radius: f32 = 28.0, 0..=60; "Corner radius of the opened cards"
|
||||
pad: f32 = 24.0, 0..=60; "Padding inside the opened cards"
|
||||
}
|
||||
colors {
|
||||
ai: Color = Color::rgb(160, 128, 255); "The AI pill's own colour, mixed into its pill and card"
|
||||
monitor: Color = Color::rgb(64, 208, 190); "The system monitor pill's own colour"
|
||||
notifications: Color = Color::rgb(255, 128, 104); "The notification pill's own colour"
|
||||
home_clear_day: Color = Color::rgb(255, 190, 92); "The home pill's colour under a clear or partly cloudy day sky"
|
||||
home_clear_night: Color = Color::rgb(104, 118, 230); "The home pill's colour on a clear night"
|
||||
home_cloudy: Color = Color::rgb(150, 170, 200); "The home pill's colour under clouds (and before the weather is known)"
|
||||
home_fog: Color = Color::rgb(176, 176, 190); "The home pill's colour in fog"
|
||||
home_rain: Color = Color::rgb(84, 156, 244); "The home pill's colour in rain"
|
||||
home_snow: Color = Color::rgb(206, 232, 255); "The home pill's colour in snow"
|
||||
home_storm: Color = Color::rgb(160, 104, 230); "The home pill's colour in a storm"
|
||||
pill_mix: f32 = 0.55, 0..=1; "How much of its own colour a small pill takes (0 = the wallpaper's only)"
|
||||
card_mix: f32 = 0.28, 0..=1; "How much of its pill's colour an open card takes"
|
||||
}
|
||||
ai {
|
||||
width: f32 = 440.0, 280..=1200; "Width of the AI card"
|
||||
height: f32 = 520.0, 200..=1200; "Height of the AI card"
|
||||
width: f32 = 760.0, 280..=1400; "Width of the AI card"
|
||||
height: f32 = 680.0, 200..=1200; "Height of the AI card"
|
||||
servers: String = String::from("http://localhost:11434"); "The Ollama servers the AI card talks to, comma-separated, in order: the model list shows all their models, a question goes to the first that has the chosen one"
|
||||
model: String = String::from("gemma4:e4b"); "The Ollama model to chat with, with its tag (ollama list shows them)"
|
||||
start_service: bool = true; "Start the local ollama service (doas rc-service ollama start) when it isn't answering"
|
||||
system: String = String::from("You are a helpful assistant inside a Linux desktop shell. Answer briefly and plainly."); "What the model is told before every chat"
|
||||
}
|
||||
monitor {
|
||||
width: f32 = 420.0, 280..=1200; "Width of the system monitor card"
|
||||
width: f32 = 620.0, 280..=1400; "Width of the system monitor card"
|
||||
interval_ms: u64 = 1000, 200..=10000; "How often the system monitor reads the system"
|
||||
history: usize = 60, 10..=600; "How many readings the graphs show"
|
||||
graph_height: f32 = 34.0, 10..=200; "Height of each graph"
|
||||
graph_height: f32 = 46.0, 10..=200; "Height of each graph"
|
||||
temperatures: usize = 6, 0..=20; "How many temperature sensors to show, always in the same order: CPU, iGPU, eGPU, NVMe, memory, board, then the rest"
|
||||
warm: f32 = 65.0, 20..=120; "From this temperature (°C) a sensor shows in the warm colour"
|
||||
hot: f32 = 85.0, 20..=130; "From this temperature (°C) a sensor shows in the hot colour"
|
||||
@@ -535,7 +563,7 @@ settings! {
|
||||
workspace: String = String::from("processes"); "The special workspace the process list opens on"
|
||||
}
|
||||
home {
|
||||
width: f32 = 820.0, 300..=1600; "Width of the home card. It opens rightwards from beside the island, so on a 1920 px wide monitor about 820 fits"
|
||||
width: f32 = 880.0, 300..=1600; "Width of the home card. It opens in the middle with the AI, system and island pills on its left, which on a 1920 px wide monitor leaves room for about 900 beside the workspace pill"
|
||||
clock_size: f32 = 64.0, 20..=200; "Size of the big clock"
|
||||
clock_font: String = String::new(); "The big clock's font family, any installed one (fc-list : family lists them); empty takes the shell's font"
|
||||
clock_weight: u64 = 700, 100..=900; "The big clock's weight, 100 (thin) to 900 (black); a font without that weight shows its nearest one"
|
||||
@@ -596,15 +624,52 @@ settings! {
|
||||
blocked: String = String::new(); "Apps whose notifications are dropped at once, comma-separated (Block app on a notification adds it)"
|
||||
}
|
||||
history {
|
||||
width: f32 = 420.0, 280..=1200; "Width of the notification card"
|
||||
height: f32 = 560.0, 200..=1400; "Height of the notification card"
|
||||
width: f32 = 620.0, 280..=1400; "Width of the notification card"
|
||||
height: f32 = 700.0, 200..=1400; "Height of the notification card"
|
||||
}
|
||||
}
|
||||
|
||||
lock {
|
||||
look {
|
||||
wallpaper: String = String::new(); "The picture behind the lock screen, PNG or JPEG; empty takes the wallpaper the shell's colours come from (the wallpaper line matugen writes into the theme file), else the colours' gradient"
|
||||
blur: u64 = 6, 0..=40; "How blurred the picture is, in pixels of its small copy; 0 shows it sharp"
|
||||
copy_width: u64 = 320, 64..=1920; "Width of the small copy of the picture that's blurred and stretched over the screen; smaller is softer"
|
||||
dim: f32 = 0.3, 0..=1; "How much the picture is darkened, so the words over it stay readable"
|
||||
vignette: f32 = 0.35, 0..=1; "How much darker the screen's corners are than its middle"
|
||||
top: f32 = 90.0, 0..=600; "Space above the date"
|
||||
bottom: f32 = 70.0, 0..=600; "Space below the password field"
|
||||
gap: f32 = 16.0, 0..=80; "Space between the lock screen's parts"
|
||||
date_size: f32 = 22.0, 10..=80; "Size of the date and the weather beside it"
|
||||
clock_size: f32 = 150.0, 40..=400; "Size of the clock"
|
||||
clock_font: String = String::new(); "The clock's font family, any installed one (fc-list : family lists them); empty takes the shell's font"
|
||||
clock_weight: u64 = 600, 100..=900; "The clock's weight, 100 (thin) to 900 (black)"
|
||||
card_width: f32 = 440.0, 240..=1200; "Width of the music card"
|
||||
card_height: f32 = 100.0, 60..=300; "Height of the music card"
|
||||
cover: f32 = 68.0, 24..=200; "Size of the cover on the music card"
|
||||
chip_height: f32 = 34.0, 20..=80; "Height of the chips under the music: the next event, the new notifications, the battery"
|
||||
avatar_size: f32 = 96.0, 24..=300; "Size of the avatar; pills.home.avatar is the picture"
|
||||
field_width: f32 = 300.0, 160..=800; "Width of the password field"
|
||||
field_height: f32 = 46.0, 28..=100; "Height of the password field"
|
||||
wrong_color: Color = Color::rgb(255, 105, 97); "Colour of the note after a wrong password"
|
||||
}
|
||||
show {
|
||||
weather: bool = true; "The weather now beside the date, for the home pill's place"
|
||||
splash: bool = true; "Hyprland's splash message under the clock"
|
||||
music: bool = true; "What plays, with its cover"
|
||||
controls: bool = true; "Previous, play/pause and next on the music card; they work while locked"
|
||||
event: bool = true; "The next event of the home pill's calendar"
|
||||
notifications: bool = true; "How many notifications came in that you haven't seen yet"
|
||||
battery: bool = true; "The battery's charge"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// what config.toml set, by path; a missing or bad setting takes its default
|
||||
// what config.toml set, by path; a missing or bad setting takes its default. written only through change()
|
||||
static VALUES: LazyLock<RwLock<HashMap<String, Value>>> = LazyLock::new(Default::default);
|
||||
|
||||
// how many times VALUES changed; an accessor's cached answer from an older count is read again
|
||||
static GENERATION: AtomicU64 = AtomicU64::new(1);
|
||||
|
||||
// what was wrong in the file when it was last read, for the config window
|
||||
static ERRORS: Mutex<Vec<String>> = Mutex::new(Vec::new());
|
||||
|
||||
@@ -619,11 +684,43 @@ fn written() -> std::sync::MutexGuard<'static, String> {
|
||||
WRITTEN.lock().unwrap_or_else(PoisonError::into_inner)
|
||||
}
|
||||
|
||||
// ponytail: a lock and a hash lookup per call, a few hundred a frame; a snapshot struct if a profile ever shows it
|
||||
fn get<T: Setting>(path: &str, default: impl FnOnce() -> T) -> T {
|
||||
VALUES.read().unwrap_or_else(PoisonError::into_inner).get(path).and_then(T::read).unwrap_or_else(default)
|
||||
}
|
||||
|
||||
// an accessor's last answer on this thread, with the GENERATION it was read at
|
||||
type Slot<T> = LocalKey<RefCell<(u64, Option<T>)>>;
|
||||
|
||||
/*
|
||||
* what every accessor (settings!) returns: its last answer while VALUES hasn't changed
|
||||
* since, else a fresh get(). a few hundred reads a frame with a card open, each a lock,
|
||||
* a hash of the path and a conversion (a colour parsed from its text) at 160 to 570 ns
|
||||
* unoptimised; a cached one is an atomic load and a copy, 13 ns. per thread, so it takes
|
||||
* no lock. a read racing a change may return the old value once, as get() could
|
||||
*/
|
||||
fn cached<T: Setting + Clone>(slot: &'static Slot<T>, path: &str, default: impl FnOnce() -> T) -> T {
|
||||
let now = GENERATION.load(Ordering::Acquire);
|
||||
|
||||
if let Some(value) = slot.with_borrow(|(seen, value)| value.clone().filter(|_| *seen == now)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
let value = get(path, default);
|
||||
|
||||
slot.set((now, Some(value.clone())));
|
||||
|
||||
value
|
||||
}
|
||||
|
||||
// every change to VALUES: made, then counted (the write lock is gone by then), so the accessors read again
|
||||
fn change<R>(edit: impl FnOnce(&mut HashMap<String, Value>) -> R) -> R {
|
||||
let done = edit(&mut VALUES.write().unwrap_or_else(PoisonError::into_inner));
|
||||
|
||||
GENERATION.fetch_add(1, Ordering::Release);
|
||||
|
||||
done
|
||||
}
|
||||
|
||||
pub fn file() -> PathBuf {
|
||||
theme::config_file("config.toml")
|
||||
}
|
||||
@@ -670,23 +767,24 @@ pub fn reread() -> bool {
|
||||
// shell.conf's four settings, moved to their places in config.toml
|
||||
fn migrate() {
|
||||
let old = fs::read_to_string(theme::config_file("shell.conf")).unwrap_or_default();
|
||||
let mut values = VALUES.write().unwrap_or_else(PoisonError::into_inner);
|
||||
|
||||
for (key, text) in parse::settings(&old) {
|
||||
let path = match key.as_str() {
|
||||
"cover_colors" => "appearance.colors.cover_colors",
|
||||
"transition_ms" => "appearance.colors.transition_ms",
|
||||
"hotspot" => "control.services.hotspot",
|
||||
"extra_output" => "control.services.extra_output",
|
||||
_ => continue,
|
||||
};
|
||||
change(|values| {
|
||||
for (key, text) in parse::settings(&old) {
|
||||
let path = match key.as_str() {
|
||||
"cover_colors" => "appearance.colors.cover_colors",
|
||||
"transition_ms" => "appearance.colors.transition_ms",
|
||||
"hotspot" => "control.services.hotspot",
|
||||
"extra_output" => "control.services.extra_output",
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
if let Some(option) = option(path)
|
||||
&& let Ok(value) = from_text(option, &text)
|
||||
{
|
||||
values.insert(path.to_string(), value);
|
||||
if let Some(option) = option(path)
|
||||
&& let Ok(value) = from_text(option, &text)
|
||||
{
|
||||
values.insert(path.to_string(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// the file's text, read anew: what it sets replaces everything set before
|
||||
@@ -703,7 +801,7 @@ pub fn apply_text(text: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
*VALUES.write().unwrap_or_else(PoisonError::into_inner) = values;
|
||||
change(|old| *old = values);
|
||||
*ERRORS.lock().unwrap_or_else(PoisonError::into_inner) = errors;
|
||||
|
||||
hypr::sync_soon();
|
||||
@@ -803,7 +901,7 @@ pub fn set(path: &str, value: Value) -> Result<(), String> {
|
||||
|
||||
let mut written = written();
|
||||
|
||||
VALUES.write().unwrap_or_else(PoisonError::into_inner).insert(path.to_string(), value);
|
||||
change(|values| values.insert(path.to_string(), value));
|
||||
|
||||
save(&mut written)
|
||||
}
|
||||
@@ -812,7 +910,7 @@ pub fn set(path: &str, value: Value) -> Result<(), String> {
|
||||
pub fn reset(path: &str) -> Result<(), String> {
|
||||
let mut written = written();
|
||||
|
||||
VALUES.write().unwrap_or_else(PoisonError::into_inner).remove(path);
|
||||
change(|values| values.remove(path));
|
||||
|
||||
save(&mut written)
|
||||
}
|
||||
@@ -968,6 +1066,7 @@ pub fn title(id: &str) -> String {
|
||||
match id {
|
||||
"control" => String::from("Control centre"),
|
||||
"pills" => String::from("Side pills"),
|
||||
"lock" => String::from("Lock screen"),
|
||||
"bar" => String::from("Bar hiding"),
|
||||
"input-capture" => String::from("Input capture"),
|
||||
"opengl" => String::from("OpenGL"),
|
||||
@@ -991,3 +1090,29 @@ pub fn label(name: &str) -> String {
|
||||
|
||||
title(name)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
// the cached accessors follow every change, on this thread and on others
|
||||
#[test]
|
||||
fn accessors_follow_changes() {
|
||||
let (width, family, accent) = (island::pill::width(), appearance::font::family(), appearance::fallback::accent());
|
||||
|
||||
change(|values| {
|
||||
values.insert("island.pill.width".into(), Value::Float(321.0));
|
||||
values.insert("appearance.font.family".into(), Value::Text("Iosevka".into()));
|
||||
values.insert("appearance.fallback.accent".into(), Value::Text("#102030".into()));
|
||||
});
|
||||
|
||||
assert_eq!(island::pill::width(), 321.0);
|
||||
assert_eq!(appearance::font::family(), "Iosevka");
|
||||
assert_eq!(appearance::fallback::accent(), Color::rgb(16, 32, 48));
|
||||
assert_eq!(std::thread::spawn(island::pill::width).join().unwrap(), 321.0);
|
||||
|
||||
change(|values| values.clear());
|
||||
|
||||
assert_eq!((island::pill::width(), appearance::font::family(), appearance::fallback::accent()), (width, family, accent));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-3
@@ -820,14 +820,19 @@ fn compact(items: Vec<Box<dyn Widget>>, width: f32) -> Rectangle {
|
||||
}
|
||||
|
||||
// as wide as battery() draws: the bolt, the body and its nub, the percentage
|
||||
fn battery_width(charge: &Charge) -> f32 {
|
||||
pub fn battery_width(charge: &Charge) -> f32 {
|
||||
let bolt = if charge.status == "Charging" { 11.0 + 5.0 } else { 0.0 };
|
||||
|
||||
bolt + 24.0 + 1.0 + 1.8 + 5.0 + label_width(&format!("{}%", charge.percent), 11.0, 0.0)
|
||||
}
|
||||
|
||||
// a battery drawn from rectangles, filled to its charge, with a bolt while it charges
|
||||
fn battery(charge: &Charge) -> Row {
|
||||
pub fn battery(charge: &Charge) -> Row {
|
||||
battery_with(charge, true)
|
||||
}
|
||||
|
||||
// `bolt` false leaves the bolt's place (11 px, first) empty, for a caller drawing its icons into one canvas
|
||||
pub fn battery_with(charge: &Charge, bolt: bool) -> Row {
|
||||
let theme = theme::now();
|
||||
|
||||
let low = charge.percent <= 15 && charge.status == "Discharging";
|
||||
@@ -849,7 +854,11 @@ fn battery(charge: &Charge) -> Row {
|
||||
let mut parts: Vec<Box<dyn Widget>> = Vec::new();
|
||||
|
||||
if charge.status == "Charging" {
|
||||
parts.push(Box::new(icon(Glyph::Bolt, 11.0, theme.accent)));
|
||||
if bolt {
|
||||
parts.push(Box::new(icon(Glyph::Bolt, 11.0, theme.accent)));
|
||||
} else {
|
||||
parts.push(Box::new(Rectangle::new().width(11.0).height(11.0)));
|
||||
}
|
||||
}
|
||||
|
||||
parts.push(Box::new(Row::new(children![body, nub]).gap(1.0).align(Center)));
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ fn socket(name: &str) -> Option<PathBuf> {
|
||||
}
|
||||
|
||||
// a question to hyprland, as `hyprctl <request>` would ask it; empty if it can't be asked
|
||||
fn hyprctl(request: &str) -> String {
|
||||
pub fn hyprctl(request: &str) -> String {
|
||||
let Some(mut stream) = socket(".socket.sock").and_then(|path| UnixStream::connect(path).ok()) else {
|
||||
return String::new();
|
||||
};
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
// glass after Apple's Liquid Glass, as far as a surface that can't see what's behind it
|
||||
// gets: a thin, lightly tinted middle over Hyprland's blur, and an edge drawn like the rim
|
||||
// of a lens: a band that brightens toward the rim where the light falls in (top left) and
|
||||
// where it leaves again (bottom right), a thin specular line on the rim itself, and a faint
|
||||
// warm and cool fringe. surface.rs fills the values:
|
||||
// 0: shape width, height, corner radius, margin (room around the shape for the shadow)
|
||||
// 1: shadow colour, its alpha already scaled by the shadow's strength
|
||||
// 2: shadow deviation, its x and y offset, lift (0 to 1, hovered or raised)
|
||||
// 3: width of the edge band in pixels, light, rim and fringe strengths (0 to 1)
|
||||
// 4-6: the tint, top left to bottom right, plain colours with the middle's opacity as alpha
|
||||
// 7.x: the layer: 1 the shadow and the tint, under the content; 2 the lit edge and the rim,
|
||||
// over it (a photo on the card then lies behind the glass); 0 both
|
||||
|
||||
fn erf7(x: f32) -> f32 {
|
||||
let y = clamp(x * 1.1283791671, -100.0, 100.0);
|
||||
let yy = y * y;
|
||||
let z = y + (0.24295 + (0.03395 + 0.0104 * yy) * yy) * (y * yy);
|
||||
|
||||
return z / sqrt(1.0 + z * z);
|
||||
}
|
||||
|
||||
// vello's blurred rounded rectangle at p, from its centre, as in surface.wgsl
|
||||
fn shadow(p: vec2<f32>, w: f32, h: f32, radius: f32, deviation: f32) -> f32 {
|
||||
let s = max(deviation, 1e-5);
|
||||
let inv = 1.0 / s;
|
||||
let min_edge = min(w, h);
|
||||
let radius_max = 0.5 * min_edge;
|
||||
let r0 = min(length(vec2<f32>(radius, s * 1.15)), radius_max);
|
||||
let r1 = min(length(vec2<f32>(radius, s * 2.0)), radius_max);
|
||||
let exponent = 2.0 * r1 / r0;
|
||||
|
||||
let delta = 1.25 * s * (exp(-pow(0.5 * inv * w, 2.0)) - exp(-pow(0.5 * inv * h, 2.0)));
|
||||
let width = w + min(delta, 0.0);
|
||||
let height = h - max(delta, 0.0);
|
||||
|
||||
let scale = 0.5 * erf7(inv * 0.5 * (max(width, height) - 0.5 * radius));
|
||||
|
||||
let y0 = abs(p.y) - (height * 0.5 - r1);
|
||||
let x0 = abs(p.x) - (width * 0.5 - r1);
|
||||
let d_pos = pow(pow(max(x0, 0.0), exponent) + pow(max(y0, 0.0), exponent), 1.0 / exponent);
|
||||
let d = d_pos + min(max(x0, y0), 0.0) - r1;
|
||||
|
||||
return scale * (erf7(inv * (min_edge + d)) - erf7(inv * d));
|
||||
}
|
||||
|
||||
// signed distance to a rounded rectangle centred on 0, negative inside
|
||||
fn rounded(p: vec2<f32>, half: vec2<f32>, radius: f32) -> f32 {
|
||||
let r = min(radius, min(half.x, half.y));
|
||||
let q = abs(p) - half + vec2<f32>(r);
|
||||
|
||||
return length(max(q, vec2<f32>(0.0))) + min(max(q.x, q.y), 0.0) - r;
|
||||
}
|
||||
|
||||
// the way out of the shape at p: across a side, or out from a corner's centre
|
||||
fn outward(p: vec2<f32>, half: vec2<f32>, radius: f32) -> vec2<f32> {
|
||||
let r = min(radius, min(half.x, half.y));
|
||||
let q = abs(p) - half + vec2<f32>(r);
|
||||
let side = select(vec2<f32>(-1.0), vec2<f32>(1.0), p >= vec2<f32>(0.0));
|
||||
|
||||
if q.x > 0.0 && q.y > 0.0 {
|
||||
return normalize(q) * side;
|
||||
}
|
||||
|
||||
return select(vec2<f32>(0.0, side.y), vec2<f32>(side.x, 0.0), q.x > q.y);
|
||||
}
|
||||
|
||||
// premultiplied colours, one over the other
|
||||
fn over(top: vec4<f32>, under: vec4<f32>) -> vec4<f32> {
|
||||
return top + under * (1.0 - top.a);
|
||||
}
|
||||
|
||||
// amane blends a plain colour over the window
|
||||
fn plain(color: vec4<f32>) -> vec4<f32> {
|
||||
if color.a <= 0.0 {
|
||||
return vec4<f32>(0.0);
|
||||
}
|
||||
|
||||
return vec4<f32>(color.rgb / color.a, color.a);
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn main(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
||||
let shape = values[0];
|
||||
let extent = shape.xy;
|
||||
let centre = extent / 2.0;
|
||||
let lift = values[2].w;
|
||||
let edge = max(values[3].x, 1.0);
|
||||
let light = values[3].y * (1.0 + 0.35 * lift);
|
||||
let rim = values[3].z * (1.0 + 0.35 * lift);
|
||||
let fringe = values[3].w;
|
||||
|
||||
let layer = u32(values[7].x);
|
||||
|
||||
let p = uv * size - vec2<f32>(shape.w);
|
||||
let pixel = max(fwidth(p.x), 1e-4);
|
||||
let from_centre = p - centre;
|
||||
|
||||
let shade = select(shadow(from_centre - values[2].yz, extent.x, extent.y, shape.z, values[2].x) * values[1].a, 0.0, layer == 2u);
|
||||
let under = vec4<f32>(values[1].rgb * shade, shade);
|
||||
|
||||
let d = rounded(from_centre, centre, shape.z);
|
||||
let inside = clamp(0.5 - d / pixel, 0.0, 1.0);
|
||||
|
||||
if inside <= 0.0 {
|
||||
return plain(under);
|
||||
}
|
||||
|
||||
// the tint, a gradient over the shape from its top left to its bottom right
|
||||
let t = clamp(dot(p / max(extent, vec2<f32>(1.0)), vec2<f32>(0.5)), 0.0, 1.0);
|
||||
let tint = select(mix(values[5], values[6], (t - 0.5) * 2.0), mix(values[4], values[5], t * 2.0), t < 0.5);
|
||||
|
||||
var glass = select(vec4<f32>(tint.rgb * tint.a, tint.a), vec4<f32>(0.0), layer == 2u);
|
||||
|
||||
if layer == 1u {
|
||||
return plain(over(glass * inside, under));
|
||||
}
|
||||
|
||||
// the lens: 1 on the rim, 0 deeper in than `edge`, steepest at the rim like a bevel
|
||||
let band = pow(1.0 - smoothstep(0.0, edge, max(-d, 0.0)), 2.0);
|
||||
|
||||
// which way this part of the rim faces: toward the light (top left) is 1, away is -1
|
||||
let facing = dot(outward(from_centre, centre, shape.z), vec2<f32>(-0.7071, -0.7071));
|
||||
|
||||
// a faint warm fringe toward the light and a cool one away from it
|
||||
let hue = mix(vec3<f32>(0.75, 0.85, 1.0), vec3<f32>(1.0, 0.9, 0.78), facing * 0.5 + 0.5);
|
||||
let tone = mix(vec3<f32>(1.0), hue, fringe);
|
||||
|
||||
// brightest where the light comes in, a weaker glint where it goes out, a little all round
|
||||
let caught = clamp(light * band * (0.9 * max(facing, 0.0) + 0.45 * max(-facing, 0.0) + 0.12), 0.0, 1.0);
|
||||
|
||||
glass = over(vec4<f32>(tone * caught, caught), glass);
|
||||
|
||||
// the specular line on the rim itself, about 1.5 px wide
|
||||
let line = clamp(clamp((d + 1.5) / pixel, 0.0, 1.0) * rim * (0.35 + 0.65 * abs(facing)), 0.0, 1.0);
|
||||
|
||||
glass = over(vec4<f32>(tone * line, line), glass);
|
||||
|
||||
return plain(over(glass * inside, under));
|
||||
}
|
||||
+61
-3
@@ -71,6 +71,17 @@ impl Service for Clock {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clock {
|
||||
// local seconds since 1970, 0 until the first tick
|
||||
pub fn now(&self) -> i64 {
|
||||
self.now
|
||||
}
|
||||
|
||||
pub fn avatar(&self) -> Option<&str> {
|
||||
self.avatar.as_deref()
|
||||
}
|
||||
}
|
||||
|
||||
fn now_unix() -> i64 {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).map_or(0, |since| since.as_secs() as i64)
|
||||
}
|
||||
@@ -92,7 +103,7 @@ fn home_dir() -> PathBuf {
|
||||
}
|
||||
|
||||
// a path from the settings, ~/ meaning the home folder
|
||||
fn expanded(path: &str) -> PathBuf {
|
||||
pub fn expanded(path: &str) -> PathBuf {
|
||||
match path.strip_prefix("~/") {
|
||||
Some(rest) => home_dir().join(rest),
|
||||
None => PathBuf::from(path),
|
||||
@@ -349,7 +360,11 @@ fn sync_settings() -> (String, String, String, bool) {
|
||||
(agenda_settings::account(), agenda_settings::server(), agenda_settings::contacts_server(), agenda_settings::birthdays())
|
||||
}
|
||||
|
||||
// whether the card has a form to type into: then it keeps the keyboard and stays open
|
||||
// the sky now and whether it's day, once the weather is known (the home pill takes its colour from it)
|
||||
pub fn sky() -> Option<(parse::Sky, bool)> {
|
||||
Forecast::read().weather.as_ref().map(|weather| (parse::sky(weather.code), weather.is_day))
|
||||
}
|
||||
|
||||
// the event form closes without saving
|
||||
fn cancel() {
|
||||
Agenda::write().form = None;
|
||||
@@ -366,6 +381,7 @@ pub fn escape() -> bool {
|
||||
open
|
||||
}
|
||||
|
||||
// whether the card has a form to type into: then it keeps the keyboard and stays open
|
||||
pub fn typing() -> bool {
|
||||
Agenda::read().form.is_some()
|
||||
}
|
||||
@@ -1044,6 +1060,48 @@ fn month_name(month: u32) -> &'static str {
|
||||
MONTHS[(month as usize + 11) % 12]
|
||||
}
|
||||
|
||||
// "Tuesday, 20 October" for local seconds `now`
|
||||
pub fn date_words(now: i64) -> String {
|
||||
let days = now.div_euclid(86_400);
|
||||
let (_, month, day) = parse::civil_from_days(days);
|
||||
|
||||
format!("{}, {day} {}", weekday_name(days), month_name(month))
|
||||
}
|
||||
|
||||
// the weather now as its icon and "14° Munich", once it's known
|
||||
pub fn weather_now() -> Option<(Glyph, String)> {
|
||||
let forecast = Forecast::read();
|
||||
let weather = forecast.weather.as_ref()?;
|
||||
|
||||
Some((sky_glyph(weather.code, weather.is_day), format!("{:.0}° {}", weather.temperature, settings::city())))
|
||||
}
|
||||
|
||||
// the soonest event that hasn't ended at local seconds `now`: when ("Tomorrow 09:30"), its title and its calendar's colour
|
||||
pub fn next_event(now: i64) -> Option<(String, String, Option<Color>)> {
|
||||
let agenda = Agenda::read();
|
||||
let entry = agenda.events.iter().filter(|entry| entry.end > now).min_by_key(|entry| entry.start)?;
|
||||
|
||||
let today = now.div_euclid(86_400);
|
||||
let day = entry.start.div_euclid(86_400).max(today);
|
||||
|
||||
let (_, month, number) = parse::civil_from_days(day);
|
||||
|
||||
let named = match day - today {
|
||||
0 => String::from("Today"),
|
||||
1 => String::from("Tomorrow"),
|
||||
2..=6 => String::from(weekday_name(day)),
|
||||
_ => format!("{number} {}", month_name(month)),
|
||||
};
|
||||
|
||||
let when = match (entry.all_day, entry.start <= now) {
|
||||
(true, _) => named,
|
||||
(false, true) => format!("Now until {}", hhmm(entry.end)),
|
||||
(false, false) => format!("{named} {}", hhmm(entry.start)),
|
||||
};
|
||||
|
||||
Some((when, entry.summary.clone(), entry.color))
|
||||
}
|
||||
|
||||
fn sky_glyph(code: u32, day: bool) -> Glyph {
|
||||
match parse::sky(code) {
|
||||
Sky::Clear if day => Glyph::Sun,
|
||||
@@ -1088,7 +1146,7 @@ pub fn height() -> f32 {
|
||||
2.0 * layout::pad() + settings::avatar_size() + gap + middle_h() + gap + 1.0 + gap + calendar_h()
|
||||
}
|
||||
|
||||
fn name() -> String {
|
||||
pub fn name() -> String {
|
||||
let user = env::var("USER").unwrap_or_default();
|
||||
let mut letters = user.chars();
|
||||
|
||||
|
||||
+101
-16
@@ -225,8 +225,12 @@ pub fn view(monitor: &Monitor) -> LayerWindow {
|
||||
.space(Zone::Ignore)
|
||||
.namespace("magic-island");
|
||||
|
||||
// out of sight: empty and click-through (never hidden, see below), and nothing else read, so a playing player doesn't redraw it
|
||||
if slide <= -edge::hide_h() {
|
||||
/*
|
||||
* out of sight: empty and click-through (never hidden, see below), and nothing else
|
||||
* read, so a playing player doesn't redraw it. also while a side pill's card is open in
|
||||
* the middle: the pods' window draws this pill in the row beside it meanwhile
|
||||
*/
|
||||
if slide <= -edge::hide_h() || crate::pods::holds_island(here) {
|
||||
return window.click_through().child(Rectangle::new().width(0.0).height(0.0));
|
||||
}
|
||||
|
||||
@@ -297,9 +301,9 @@ pub fn view(monitor: &Monitor) -> LayerWindow {
|
||||
|
||||
veiled(card(&scene), width, height, radius, reveal, &colors)
|
||||
}
|
||||
Some(player) if pill > 0.0 => veiled(compact(player, playing(player, &island), &art.path, levels), width, height, radius, pill, &colors),
|
||||
Some(player) if pill > 0.0 => veiled(compact(player, playing(player, &island), &art.path, levels, c::pill::width()), width, height, radius, pill, &colors),
|
||||
None if reveal > 0.0 => veiled(crate::last::card(), width, height, radius, reveal, &colors),
|
||||
None if pill > 0.0 => veiled(idle(), width, height, radius, pill, &colors),
|
||||
None if pill > 0.0 => veiled(idle_face(c::pill::width()), width, height, radius, pill, &colors),
|
||||
// mid-grow: the empty shape alone, the cheapest frames of the animation
|
||||
_ => Rectangle::new().width(0.0).height(0.0),
|
||||
};
|
||||
@@ -356,8 +360,74 @@ pub fn view(monitor: &Monitor) -> LayerWindow {
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* the island's pill as the side pills' carousel draws it while one of their cards is
|
||||
* open in the middle (the island's own window leaves it to them meanwhile, see
|
||||
* pods::holds_island). `small` shrinks it from the pill (0) to its least (1): the song's
|
||||
* cover, or its live bars when there's no cover, or a note with nothing playing. the
|
||||
* pill's face fades out over the first half, the small one in over the second
|
||||
*/
|
||||
pub fn pill_face(monitor: &str, small: f32) -> Rectangle {
|
||||
let media = Media::read();
|
||||
let island = Island::read();
|
||||
let colors = theme::now().surfaces();
|
||||
let art = Art::read();
|
||||
let h = c::pill::height();
|
||||
|
||||
let player = shown(&media, island.selected.as_deref());
|
||||
let small_w = small_width_for(player.is_some(), &art.path);
|
||||
let width = mix(c::pill::width(), small_w, small);
|
||||
|
||||
let live = player.is_some() && focused_monitor().as_deref().is_none_or(|name| name == monitor);
|
||||
let spectrum = live.then(Spectrum::read);
|
||||
let levels: &[f32] = spectrum.as_deref().map_or(&[], |spectrum| spectrum.levels.as_slice());
|
||||
|
||||
if !levels.is_empty() {
|
||||
amane::request_frame();
|
||||
}
|
||||
|
||||
/*
|
||||
* the pill's face fades out, then the small one in: they swap halfway, or with nothing
|
||||
* playing as soon as the shape gets too narrow for the words, so these never vanish while seen
|
||||
*/
|
||||
let turn = if player.is_some() { 0.5 } else { ((c::pill::width() - idle_room()) / (c::pill::width() - small_w).max(1.0)).clamp(0.05, 0.5) };
|
||||
|
||||
let face = if small < turn {
|
||||
let big = match player {
|
||||
Some(player) => compact(player, playing(player, &island), &art.path, levels, width),
|
||||
None => idle_face(width),
|
||||
};
|
||||
|
||||
veiled(big, width, h, h / 2.0, 1.0 - small / turn, &colors)
|
||||
} else {
|
||||
let little: Box<dyn Widget> = match player {
|
||||
Some(_) if !art.path.is_empty() => Box::new(cover(&art.path, h - 10.0, 1.5, false)),
|
||||
Some(player) => Box::new(pill_levels(playing(player, &island), levels)),
|
||||
None => Box::new(icon(Glyph::Note, IDLE_NOTE, theme::now().accent)),
|
||||
};
|
||||
|
||||
veiled(Rectangle::new().width(width).height(h).align_child(Center, Center).child(Stack::new(vec![little])), width, h, h / 2.0, (small - turn) / (1.0 - turn), &colors)
|
||||
};
|
||||
|
||||
surface::shell(width, h, h / 2.0, &colors, 0.0, face)
|
||||
}
|
||||
|
||||
// the island's pill at its least in the carousel: as wide as tall with a cover or nothing playing, else room for its bars
|
||||
pub fn small_width() -> f32 {
|
||||
let media = Media::read();
|
||||
let island = Island::read();
|
||||
|
||||
small_width_for(shown(&media, island.selected.as_deref()).is_some(), &Art::read().path)
|
||||
}
|
||||
|
||||
fn small_width_for(playing_something: bool, art: &str) -> f32 {
|
||||
let h = c::pill::height();
|
||||
|
||||
if !playing_something || !art.is_empty() { h } else { (c::pill::bars_width() + 24.0).max(h) }
|
||||
}
|
||||
|
||||
// a click on the island of `monitor`: closes an open dropdown, else opens the card there
|
||||
fn tap(monitor: &str) {
|
||||
pub fn tap(monitor: &str) {
|
||||
let mut island = Island::write();
|
||||
|
||||
if island.menu.take().is_none() {
|
||||
@@ -587,21 +657,36 @@ pub fn faded(color: Color, alpha: u8) -> Color {
|
||||
Color::rgba(color.red(), color.green(), color.blue(), alpha)
|
||||
}
|
||||
|
||||
// the pill while no player is open: a music note and "Nothing playing"; the words only
|
||||
// where they fit with half the pill's height to spare at each end, else the note alone, so it never nears the rim
|
||||
fn idle() -> Rectangle {
|
||||
let (width, h, note) = (c::pill::width(), c::pill::height(), 15.0);
|
||||
let words = Text::new("Nothing playing").size(text::body()).color(theme::now().dim);
|
||||
let fits = matches!(words.width(), amane::Size::Fixed(words_w) if note + 8.0 + words_w + h <= width);
|
||||
/*
|
||||
* a note and "Nothing playing", centred. the words only where they fit with half the
|
||||
* pill's height to spare at each end, else the note alone: an elided text takes the whole
|
||||
* width, which put the note against the rim, and a pill narrower than the words did too
|
||||
*/
|
||||
fn idle_face(width: f32) -> Rectangle {
|
||||
let note = icon(Glyph::Note, IDLE_NOTE, theme::now().accent);
|
||||
let row = if idle_room() <= width { Row::new(children![note, idle_words()]) } else { Row::new(children![note]) };
|
||||
|
||||
let row = if fits { Row::new(children![icon(Glyph::Note, note, theme::now().accent), words]) } else { Row::new(children![icon(Glyph::Note, note, theme::now().accent)]) };
|
||||
Rectangle::new().width(width).height(h).align_child(Center, Center).child(row.gap(8.0).align(Center))
|
||||
Rectangle::new().width(width).height(c::pill::height()).align_child(Center, Center).child(row.gap(8.0).align(Center))
|
||||
}
|
||||
|
||||
// the pill: cover, title, the player's live levels
|
||||
fn compact(player: &MediaPlayer, playing: bool, art: &str, levels: &[f32]) -> Rectangle {
|
||||
const IDLE_NOTE: f32 = 15.0;
|
||||
|
||||
fn idle_words() -> Text {
|
||||
Text::new("Nothing playing").size(text::body()).color(theme::now().dim)
|
||||
}
|
||||
|
||||
// the width the note and the words need, with half the pill's height to spare at each end
|
||||
fn idle_room() -> f32 {
|
||||
match idle_words().width() {
|
||||
amane::Size::Fixed(words) => IDLE_NOTE + 8.0 + words + c::pill::height(),
|
||||
amane::Size::Parent => f32::MAX,
|
||||
}
|
||||
}
|
||||
|
||||
// the pill, `width` wide: cover, title, the player's live levels
|
||||
fn compact(player: &MediaPlayer, playing: bool, art: &str, levels: &[f32], width: f32) -> Rectangle {
|
||||
Rectangle::new()
|
||||
.width(c::pill::width())
|
||||
.width(width)
|
||||
.height(c::pill::height())
|
||||
.padding(Padding { top: 0.0, right: 12.0, bottom: 0.0, left: 6.0 })
|
||||
.child(
|
||||
|
||||
+488
@@ -0,0 +1,488 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use amane::{Canvas, Center, Color, Column, Full, Image, LayerWindow, Lock, Media, MediaPlayer, Monitor, Pointer, Rectangle, Row, Service, Shape, SpaceBetween, Stack, Start, Text, TextInput, Weight, Widget, children, window_size};
|
||||
|
||||
use crate::art::Art;
|
||||
use crate::config::appearance::{font, overlays, text};
|
||||
use crate::config::lock::{look, show};
|
||||
use crate::config::pills::layout;
|
||||
use crate::glyph::{Glyph, glyph_shapes};
|
||||
use crate::home::{self, Clock};
|
||||
use crate::island::{self, CLEAR, Island, faded};
|
||||
use crate::system::Power;
|
||||
use crate::{control, edge, notices, parse, surface, theme};
|
||||
|
||||
/*
|
||||
* the lock screen, amane's App::lock (ext-session-lock; pam checks the password the way the
|
||||
* `login` service does): the wallpaper blurred under a veil; the date with the weather now,
|
||||
* a big clock and hyprland's splash; the music with its controls, then chips for the next
|
||||
* event, the new notifications and the battery; at the bottom the avatar, the name and the
|
||||
* password. every monitor shows it, all sharing the one password field.
|
||||
* `amane ipc call lock` locks. killing the shell doesn't unlock: hyprland keeps the session
|
||||
* locked (README, Lock screen)
|
||||
*
|
||||
* it redraws for the music's progress, the clock and the password, so it's drawn cheaply:
|
||||
* the backdrop is one shader (lock.wgsl) instead of a gradient vello paints over the whole
|
||||
* screen on every frame, the glass is surface.rs's shader, and every icon goes into one
|
||||
* canvas over it all, as each canvas is a vello pass of its own. so that where each icon
|
||||
* lands is known, every part has a fixed size
|
||||
*/
|
||||
|
||||
// what the lock screen looks up once per lock, before it shows
|
||||
#[derive(Default)]
|
||||
pub struct Shown {
|
||||
splash: String,
|
||||
picture: Option<String>,
|
||||
}
|
||||
|
||||
impl Service for Shown {
|
||||
fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
// set by command() only
|
||||
fn listen() {}
|
||||
}
|
||||
|
||||
// the password field's name; every monitor's lock screen shows the same one
|
||||
const FIELD: &str = "lock-password";
|
||||
|
||||
static SHADER: LazyLock<PathBuf> = LazyLock::new(|| surface::shader_file("lock.wgsl", include_str!("lock.wgsl")));
|
||||
|
||||
// the icons of one frame, drawn together into one canvas over the screen
|
||||
type Icons = Vec<Box<dyn Shape>>;
|
||||
|
||||
// a chip's parts, how wide they are, and the icon the canvas draws at their start
|
||||
type Chip = (Vec<Box<dyn Widget>>, f32, Option<(Glyph, f32, Color)>);
|
||||
|
||||
// `amane ipc call lock`: the splash and the picture are looked up first, so the screen shows them from its first frame
|
||||
pub fn command(words: &[String]) -> String {
|
||||
if !words.is_empty() {
|
||||
return String::from("usage: lock");
|
||||
}
|
||||
|
||||
let splash = edge::hyprctl("splash").trim().to_string();
|
||||
|
||||
*Shown::write() = Shown { splash, picture: picture() };
|
||||
|
||||
Lock::start();
|
||||
|
||||
String::from("locked")
|
||||
}
|
||||
|
||||
// the picture: the setting's, else the wallpaper matugen named in the theme file; only a file that's there
|
||||
fn picture() -> Option<String> {
|
||||
let set = look::wallpaper();
|
||||
|
||||
let wanted = if set.trim().is_empty() {
|
||||
let theme = fs::read_to_string(theme::config_file("theme")).unwrap_or_default();
|
||||
|
||||
parse::settings(&theme).into_iter().find(|(key, _)| key == "wallpaper").map(|(_, value)| value)?
|
||||
} else {
|
||||
set
|
||||
};
|
||||
|
||||
let path = home::expanded(wanted.trim());
|
||||
|
||||
path.is_file().then(|| path.to_string_lossy().into_owned())
|
||||
}
|
||||
|
||||
pub fn view(_: &Monitor) -> LayerWindow {
|
||||
theme::begin();
|
||||
|
||||
// a lock screen always covers its whole monitor, whatever size it asks for
|
||||
let window = LayerWindow::new().width(1.0).height(1.0);
|
||||
let (width, height) = window_size();
|
||||
|
||||
// the compositor hasn't said the size yet
|
||||
if width <= 0.0 || height <= 0.0 {
|
||||
return window.child(Rectangle::new().width(0.0).height(0.0));
|
||||
}
|
||||
|
||||
window.child(screen(width, height))
|
||||
}
|
||||
|
||||
// about how wide words are at `size`, as the chips size themselves
|
||||
fn words_width(words: &str, size: f32) -> f32 {
|
||||
words.chars().count() as f32 * size * font::letter_width()
|
||||
}
|
||||
|
||||
// words in a box `width` wide, from its left, elided past it
|
||||
fn words(words: &str, size: f32, color: Color, bold: bool, width: f32) -> Rectangle {
|
||||
let text = Text::new(words).size(size).color(color).elide();
|
||||
let text = if bold { text.weight(Weight::Bold) } else { text };
|
||||
|
||||
Rectangle::new().width(width).height(size * 1.4).align_child(Start, Center).child(text)
|
||||
}
|
||||
|
||||
// empty room `width` wide, where an icon of the canvas goes or just space
|
||||
fn room(width: f32) -> Rectangle {
|
||||
Rectangle::new().width(width).height(1.0)
|
||||
}
|
||||
|
||||
// `glyph` centred on (x, y)
|
||||
fn place(icons: &mut Icons, glyph: Glyph, size: f32, color: Color, (x, y): (f32, f32)) {
|
||||
icons.extend(glyph_shapes(glyph, size, color, 0.0, (x - size / 2.0, y - size / 2.0)));
|
||||
}
|
||||
|
||||
fn screen(width: f32, height: f32) -> Stack {
|
||||
let clock = Clock::read();
|
||||
let shown = Shown::read();
|
||||
let gap = look::gap();
|
||||
|
||||
let mut icons: Icons = Vec::new();
|
||||
|
||||
// the top part downward from look::top, the bottom part upward from look::bottom
|
||||
let upper_y = look::top() + gap;
|
||||
let (upper, upper_h) = upper(&clock, &shown, width, upper_y, &mut icons);
|
||||
let middle = middle(clock.now(), width, upper_y + upper_h + gap, &mut icons);
|
||||
|
||||
let lower_y = height - look::bottom() - lower_height();
|
||||
let lower = lower(&clock, width, lower_y, &mut icons);
|
||||
|
||||
let top = Column::new(children![Rectangle::new().width(1.0).height(look::top()), upper, middle]).gap(gap).align(Center);
|
||||
let bottom = Column::new(children![lower, Rectangle::new().width(1.0).height(look::bottom())]).align(Center);
|
||||
|
||||
let content = Column::new(children![top, bottom]).width(width).height(height).justify(SpaceBetween).align(Center);
|
||||
|
||||
let mut layers = backdrop(width, height, shown.picture.as_deref());
|
||||
|
||||
layers.push(Box::new(content));
|
||||
|
||||
if !icons.is_empty() {
|
||||
layers.push(Box::new(Canvas::new().width(width).height(height).shapes(icons)));
|
||||
}
|
||||
|
||||
Stack::new(layers).width(width).height(height)
|
||||
}
|
||||
|
||||
// the wallpaper colours' gradient, the picture blurred over it, and a veil over that darker at the edges: lock.wgsl
|
||||
fn backdrop(width: f32, height: f32, picture: Option<&str>) -> Vec<Box<dyn Widget>> {
|
||||
let [high, middle, low] = theme::now().surfaces();
|
||||
|
||||
let shade = |layer: f32| {
|
||||
let values = vec![[width, height, 160.0, layer], surface::plain(high), surface::plain(middle), surface::plain(low), [look::dim(), look::vignette(), 0.0, 0.0]];
|
||||
|
||||
Box::new(Rectangle::new().width(width).height(height).shader(SHADER.as_path()).shader_values(values)) as Box<dyn Widget>
|
||||
};
|
||||
|
||||
let Some(path) = picture else {
|
||||
return vec![shade(0.0)];
|
||||
};
|
||||
|
||||
let blur = look::blur() as u32;
|
||||
|
||||
// blurred: a small copy, blurred once when decoded and stretched over the screen, costs nothing per frame
|
||||
let image = if blur == 0 {
|
||||
Image::cover(path).thumbnail(width.ceil() as u32, height.ceil() as u32)
|
||||
} else {
|
||||
let copy = look::copy_width() as u32;
|
||||
|
||||
Image::cover(path).thumbnail(copy, (copy as f32 * height / width).ceil() as u32).blurred(blur)
|
||||
};
|
||||
|
||||
// the gradient shows while the picture decodes
|
||||
vec![shade(1.0), Box::new(Rectangle::new().width(width).height(height).fill(image)), shade(2.0)]
|
||||
}
|
||||
|
||||
// the date with the weather now, the clock, hyprland's splash, from `y` down; and how tall
|
||||
fn upper(clock: &Clock, shown: &Shown, width: f32, y: f32, icons: &mut Icons) -> (Rectangle, f32) {
|
||||
let theme = theme::now();
|
||||
let size = look::date_size();
|
||||
let now = clock.now();
|
||||
let inner = look::gap() * 0.4;
|
||||
|
||||
// the date, and the weather's icon and words after it
|
||||
let date = if now > 0 { home::date_words(now) } else { String::new() };
|
||||
let date_w = words_width(&date, size);
|
||||
let date_h = size * 1.4;
|
||||
|
||||
let mut row: Vec<Box<dyn Widget>> = vec![Box::new(words(&date, size, theme.text, true, date_w))];
|
||||
let mut row_w = date_w;
|
||||
|
||||
if show::weather()
|
||||
&& let Some((glyph, said)) = home::weather_now()
|
||||
{
|
||||
let (space, icon, after) = (size * 0.6, size * 1.15, size * 0.3);
|
||||
let said_w = words_width(&said, size);
|
||||
let total = date_w + space + icon + after + said_w;
|
||||
|
||||
place(icons, glyph, icon, theme.text, ((width - total) / 2.0 + date_w + space + icon / 2.0, y + date_h / 2.0));
|
||||
|
||||
row.extend(children![room(space), room(icon), room(after), words(&said, size, theme.text, false, said_w)]);
|
||||
row_w = total;
|
||||
}
|
||||
|
||||
let seconds = now.rem_euclid(86_400);
|
||||
let time = if now > 0 { format!("{:02}:{:02}", seconds / 3_600, seconds % 3_600 / 60) } else { String::new() };
|
||||
|
||||
let digits = Text::new(time).size(look::clock_size()).weight(look::clock_weight().min(1000) as u16).color(theme.text).tight();
|
||||
let family = look::clock_font();
|
||||
let digits = if family.trim().is_empty() { digits } else { digits.font(family.trim()) };
|
||||
let clock_h = digits.height_in(width);
|
||||
|
||||
let mut parts: Vec<Box<dyn Widget>> = vec![
|
||||
Box::new(Rectangle::new().width(row_w).height(date_h).child(Row::new(row).align(Center))),
|
||||
Box::new(Rectangle::new().width(width).height(clock_h).align_child(Center, Center).child(digits)),
|
||||
];
|
||||
|
||||
let mut height = date_h + inner + clock_h;
|
||||
|
||||
if show::splash() && !shown.splash.is_empty() {
|
||||
let size = size * 0.7;
|
||||
let said = format!("“{}”", shown.splash);
|
||||
let said_w = (words_width(&said, size) + size).min(width * 0.7);
|
||||
|
||||
parts.push(Box::new(words(&said, size, theme.dim, false, said_w)));
|
||||
height += inner + size * 1.4;
|
||||
}
|
||||
|
||||
(Rectangle::new().width(width).height(height).align_child(Center, Start).child(Column::new(parts).gap(inner).align(Center)), height)
|
||||
}
|
||||
|
||||
// the music, then the chips, from `y` down
|
||||
fn middle(now: i64, width: f32, y: f32, icons: &mut Icons) -> Column {
|
||||
let gap = look::gap() * 0.75;
|
||||
let mut parts: Vec<Box<dyn Widget>> = Vec::new();
|
||||
let mut y = y;
|
||||
|
||||
if show::music()
|
||||
&& let Some(card) = music(width, y, icons)
|
||||
{
|
||||
parts.push(Box::new(card));
|
||||
y += look::card_height() + gap;
|
||||
}
|
||||
|
||||
if let Some(chips) = chips(now, width, y, icons) {
|
||||
parts.push(Box::new(chips));
|
||||
}
|
||||
|
||||
Column::new(parts).gap(gap).align(Center)
|
||||
}
|
||||
|
||||
// the shown player's song at `y`: its cover, title, artist and how far it is, and its buttons
|
||||
fn music(width: f32, y: f32, icons: &mut Icons) -> Option<Rectangle> {
|
||||
let media = Media::read();
|
||||
let island = Island::read();
|
||||
let art = Art::read();
|
||||
let theme = theme::now();
|
||||
|
||||
let player = island::shown(&media, island.selected.as_deref())?;
|
||||
|
||||
let (card_w, card_h) = (look::card_width(), look::card_height());
|
||||
let gap = look::gap() * 0.75;
|
||||
let cover = look::cover().min(card_h - 8.0);
|
||||
let pad = (card_h - cover) / 2.0;
|
||||
|
||||
// where the card's row starts, and the height every part of it is centred on
|
||||
let left = (width - card_w) / 2.0 + pad;
|
||||
let middle = y + card_h / 2.0;
|
||||
|
||||
let picture = Rectangle::new().width(cover).height(cover).radius(cover * 0.18);
|
||||
|
||||
let picture = if art.path.is_empty() {
|
||||
place(icons, Glyph::Note, cover * 0.45, theme.accent, (left + cover / 2.0, middle));
|
||||
|
||||
picture.fill(theme.accent_soft)
|
||||
} else {
|
||||
let pixels = (cover * 2.0).ceil() as u32;
|
||||
|
||||
picture.fill(Image::cover(art.path.clone()).thumbnail(pixels, pixels))
|
||||
};
|
||||
|
||||
let (small, big) = (text::title() * 1.9, text::title() * 1.9 * 1.25);
|
||||
let buttons_w = if show::controls() { 2.0 * small + big + 8.0 + gap } else { 0.0 };
|
||||
let words_w = (card_w - 2.0 * pad - cover - gap - buttons_w).max(0.0);
|
||||
|
||||
let title = if player.title().is_empty() { player.identity() } else { player.title() };
|
||||
|
||||
let length = player.length().as_secs_f32();
|
||||
let done = if length > 0.0 { (player.position().as_secs_f32() / length).clamp(0.0, 1.0) } else { 0.0 };
|
||||
|
||||
let track = Rectangle::new().width(words_w).height(4.0).radius(Full).fill(overlays::track()).align_child(Start, Center).child(Rectangle::new().width((words_w * done).max(4.0)).height(4.0).radius(Full).fill(theme.text));
|
||||
|
||||
let said = Column::new(children![words(title, text::title(), theme.text, true, words_w), words(player.artist(), text::body(), theme.dim, false, words_w), track]).gap(6.0);
|
||||
|
||||
let mut items: Vec<Box<dyn Widget>> = vec![Box::new(picture), Box::new(said)];
|
||||
|
||||
if show::controls() {
|
||||
items.push(Box::new(controls(player, (left + cover + gap + words_w + gap, middle), small, big, icons)));
|
||||
}
|
||||
|
||||
let content = Rectangle::new().width(card_w).height(card_h).padding(pad).align_child(Start, Center).child(Row::new(items).gap(gap).align(Center));
|
||||
|
||||
Some(surface::shell(card_w, card_h, layout::radius().min(card_h / 2.0), &theme.surfaces(), 0.0, content))
|
||||
}
|
||||
|
||||
// previous, play or pause, next, from (x, the middle's y), their icons into the canvas
|
||||
fn controls(player: &MediaPlayer, (x, y): (f32, f32), small: f32, big: f32, icons: &mut Icons) -> Row {
|
||||
let theme = theme::now();
|
||||
|
||||
let middle = if player.playing() { Glyph::Pause } else { Glyph::Play };
|
||||
|
||||
for (glyph, size, centre) in [(Glyph::Previous, small, x + small / 2.0), (middle, big, x + small + 4.0 + big / 2.0), (Glyph::Next, small, x + small + 4.0 + big + 4.0 + small / 2.0)] {
|
||||
place(icons, glyph, size * 0.42, theme.text, (centre, y));
|
||||
}
|
||||
|
||||
let button = |size: f32, fill: Color, pressed: Box<dyn Fn()>| Rectangle::new().width(size).height(size).radius(Full).fill(fill).cursor(Pointer).on_click(move |_| pressed());
|
||||
|
||||
let (previous, toggle, next) = (player.clone(), player.clone(), player.clone());
|
||||
|
||||
Row::new(children![
|
||||
button(small, CLEAR, Box::new(move || previous.previous())),
|
||||
button(big, overlays::chip(), Box::new(move || toggle.play_pause())),
|
||||
button(small, CLEAR, Box::new(move || next.next())),
|
||||
])
|
||||
.gap(4.0)
|
||||
.align(Center)
|
||||
}
|
||||
|
||||
// a glass chip around `parts`, which are `inner` wide
|
||||
fn chip(parts: Vec<Box<dyn Widget>>, inner: f32) -> Rectangle {
|
||||
let height = look::chip_height();
|
||||
let width = inner + height;
|
||||
|
||||
let content = Rectangle::new().width(width).height(height).align_child(Center, Center).child(Row::new(parts).gap(8.0).align(Center));
|
||||
|
||||
surface::shell(width, height, height / 2.0, &theme::now().surfaces(), 0.0, content)
|
||||
}
|
||||
|
||||
// the next event, the new notifications, the battery at `y`: each its own chip, when there is one
|
||||
fn chips(now: i64, width: f32, y: f32, icons: &mut Icons) -> Option<Row> {
|
||||
let theme = theme::now();
|
||||
let (size, height) = (text::body(), look::chip_height());
|
||||
let icon = size * 1.3;
|
||||
let spacing = look::gap() * 0.6;
|
||||
|
||||
// each chip's parts and inner width, and an icon at the start of its parts
|
||||
let mut wanted: Vec<Chip> = Vec::new();
|
||||
|
||||
if show::event()
|
||||
&& let Some((when, what, color)) = home::next_event(now)
|
||||
{
|
||||
let said = format!("{when} · {what}");
|
||||
let said_w = words_width(&said, size).min(look::card_width() * 0.8);
|
||||
let dot = Rectangle::new().width(9.0).height(9.0).radius(Full).fill(color.unwrap_or(theme.accent));
|
||||
|
||||
wanted.push((children![dot, words(&said, size, theme.text, false, said_w)], 9.0 + 8.0 + said_w, None));
|
||||
}
|
||||
|
||||
let unread = notices::unread();
|
||||
|
||||
if show::notifications() && unread > 0 {
|
||||
let said = if unread == 1 { String::from("1 new notification") } else { format!("{unread} new notifications") };
|
||||
let said_w = words_width(&said, size).min(look::card_width());
|
||||
|
||||
wanted.push((children![room(icon), words(&said, size, theme.text, false, said_w)], icon + 8.0 + said_w, Some((Glyph::Bell, icon, theme.text))));
|
||||
}
|
||||
|
||||
if show::battery()
|
||||
&& let Some(charge) = &Power::read().battery
|
||||
{
|
||||
let bolt = (charge.status == "Charging").then_some((Glyph::Bolt, 11.0, theme.accent));
|
||||
|
||||
wanted.push((children![control::battery_with(charge, false)], control::battery_width(charge), bolt));
|
||||
}
|
||||
|
||||
if wanted.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let total: f32 = wanted.iter().map(|(_, inner, _)| inner + height).sum::<f32>() + spacing * (wanted.len() - 1) as f32;
|
||||
let mut x = (width - total) / 2.0;
|
||||
|
||||
let mut row: Vec<Box<dyn Widget>> = Vec::new();
|
||||
|
||||
for (parts, inner, icon) in wanted {
|
||||
// a chip's parts start half its height in
|
||||
if let Some((glyph, size, color)) = icon {
|
||||
place(icons, glyph, size, color, (x + height / 2.0 + size / 2.0, y + height / 2.0));
|
||||
}
|
||||
|
||||
row.push(Box::new(chip(parts, inner)));
|
||||
x += inner + height + spacing;
|
||||
}
|
||||
|
||||
Some(Row::new(row).gap(spacing).align(Center))
|
||||
}
|
||||
|
||||
fn name_height() -> f32 {
|
||||
text::title() * 1.4
|
||||
}
|
||||
|
||||
fn note_height() -> f32 {
|
||||
text::body() * 1.6
|
||||
}
|
||||
|
||||
// how tall the avatar, the name, the password and the note are together
|
||||
fn lower_height() -> f32 {
|
||||
let gap = look::gap() * 0.6;
|
||||
|
||||
look::avatar_size() + gap + name_height() + gap + look::field_height() + gap + note_height()
|
||||
}
|
||||
|
||||
// the avatar, the name, the password and what became of the last one, from `y` down
|
||||
fn lower(clock: &Clock, width: f32, y: f32, icons: &mut Icons) -> Column {
|
||||
let theme = theme::now();
|
||||
let lock = Lock::read();
|
||||
let gap = look::gap() * 0.6;
|
||||
let size = look::avatar_size();
|
||||
|
||||
let avatar = Rectangle::new().width(size).height(size).radius(Full).border(2.0, faded(theme.text, 90));
|
||||
|
||||
let avatar = match clock.avatar() {
|
||||
Some(path) => {
|
||||
let pixels = (size * 2.0).ceil() as u32;
|
||||
|
||||
avatar.fill(Image::cover(path).thumbnail(pixels, pixels))
|
||||
}
|
||||
None => {
|
||||
place(icons, Glyph::Person, size * 0.54, theme.accent, (width / 2.0, y + size / 2.0));
|
||||
|
||||
avatar.fill(faded(theme.accent, 60))
|
||||
}
|
||||
};
|
||||
|
||||
let name = Rectangle::new().width(width).height(name_height()).align_child(Center, Center).child(Text::new(home::name()).size(text::title()).weight(Weight::Bold).color(theme.text));
|
||||
|
||||
let (field_w, field_h) = (look::field_width(), look::field_height());
|
||||
let letters = text::popup();
|
||||
let icon = letters * 1.1;
|
||||
let start = field_h * 0.45;
|
||||
|
||||
let field_y = y + size + gap + name_height() + gap;
|
||||
|
||||
place(icons, Glyph::Lock, icon, theme.dim, ((width - field_w) / 2.0 + start + icon / 2.0, field_y + field_h / 2.0));
|
||||
|
||||
let input = TextInput::new(FIELD).password().focused().placeholder("Enter password").size(letters).color(theme.text).on_submit(submit);
|
||||
|
||||
// the lock icon's room, then the input 10 px after it
|
||||
let inside = Row::new(children![room(start), room(icon), room(10.0), Rectangle::new().width(field_w - 2.0 * start - icon - 10.0).height(field_h).align_child(Start, Center).child(input)]).align(Center);
|
||||
|
||||
// a wrong password lights the field's rim
|
||||
let lift = if lock.failed() { 1.0 } else { 0.0 };
|
||||
let field = surface::shell(field_w, field_h, field_h / 2.0, &theme.surfaces(), lift, Rectangle::new().width(field_w).height(field_h).align_child(Start, Center).child(inside));
|
||||
|
||||
let (note, color) = if lock.checking() {
|
||||
("Checking…", theme.dim)
|
||||
} else if lock.failed() {
|
||||
("Wrong password, try again", look::wrong_color())
|
||||
} else {
|
||||
("", theme.dim)
|
||||
};
|
||||
|
||||
let note = Rectangle::new().width(field_w).height(note_height()).align_child(Center, Center).child(Text::new(note).size(text::body()).color(color));
|
||||
|
||||
Column::new(children![avatar, name, field, note]).gap(gap).align(Center)
|
||||
}
|
||||
|
||||
// Enter: the field empties at once, pam gets the password on its own thread
|
||||
fn submit(password: String) {
|
||||
TextInput::set_text(FIELD, "");
|
||||
|
||||
if !password.is_empty() {
|
||||
Lock::unlock(&password);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// the lock screen's backdrop in one pass: the wallpaper colours' gradient, and over the picture
|
||||
// a veil that darkens it, more toward the edges. drawn as amane's gradient it was a vello pass
|
||||
// over the whole screen on every frame (vello keeps no gradient between frames). lock.rs fills
|
||||
// the values:
|
||||
// 0: width, height, the gradient's angle in degrees (0 runs bottom to top, 90 left to right), layer
|
||||
// 1-3: the gradient's colours at 0, 0.55 and 1, plain
|
||||
// 4: the veil's darkness and the vignette's strength, 0 to 1
|
||||
// layer 1 is the gradient (under the picture), 2 the veil (over it), 0 both (no picture)
|
||||
|
||||
@fragment
|
||||
fn main(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
|
||||
let extent = values[0].xy;
|
||||
let angle = radians(values[0].z);
|
||||
let layer = u32(values[0].w);
|
||||
|
||||
// where this pixel lies along the gradient, 0 at its start corner and 1 at its end
|
||||
let direction = vec2<f32>(sin(angle), -cos(angle));
|
||||
let reach = abs(direction.x) * extent.x + abs(direction.y) * extent.y;
|
||||
let t = clamp(dot((uv - 0.5) * extent, direction) / max(reach, 1.0) + 0.5, 0.0, 1.0);
|
||||
|
||||
let gradient = select(mix(values[2], values[3], (t - 0.55) / 0.45), mix(values[1], values[2], t / 0.55), t < 0.55);
|
||||
|
||||
// the veil, darker toward the corners: 0 in the middle, 1 in a corner
|
||||
let corner = length((uv - 0.5) * 2.0) / 1.4142;
|
||||
let dark = clamp(values[4].x + (1.0 - values[4].x) * values[4].y * smoothstep(0.3, 1.0, corner), 0.0, 1.0);
|
||||
|
||||
if layer == 1u {
|
||||
return vec4<f32>(gradient.rgb, 1.0);
|
||||
}
|
||||
|
||||
if layer == 2u {
|
||||
return vec4<f32>(0.0, 0.0, 0.0, dark);
|
||||
}
|
||||
|
||||
return vec4<f32>(gradient.rgb * (1.0 - dark), 1.0);
|
||||
}
|
||||
+6
-3
@@ -8,6 +8,7 @@ mod home;
|
||||
mod hypr;
|
||||
mod island;
|
||||
mod last;
|
||||
mod lock;
|
||||
mod map;
|
||||
mod notices;
|
||||
mod parse;
|
||||
@@ -44,12 +45,14 @@ fn main() {
|
||||
.ipc("tray", tray::command)
|
||||
.ipc("config", settings::command)
|
||||
.ipc("pods", pods::command)
|
||||
.ipc("lock", lock::command)
|
||||
.lock(lock::view)
|
||||
.window_per_monitor(edge::spacer)
|
||||
.window_per_monitor(edge::view)
|
||||
.window_per_monitor(island::view)
|
||||
// the small pills beside the island, and their cards
|
||||
.window_per_monitor(pods::left)
|
||||
.window_per_monitor(pods::right)
|
||||
// the small pills beside the island, and their cards in the middle
|
||||
.window_per_monitor(pods::row_view)
|
||||
.window_per_monitor(pods::card_view)
|
||||
.window_per_monitor(workspaces::view)
|
||||
.window_per_monitor(control::view)
|
||||
.window_per_monitor(control::menu_view)
|
||||
|
||||
+386
-119
@@ -8,20 +8,27 @@ use amane::{
|
||||
};
|
||||
|
||||
use crate::config::appearance::{motion, overlays, text};
|
||||
use crate::config::island::{card as island_card, pill as island_pill};
|
||||
use crate::config::island::pill as island_pill;
|
||||
use crate::config::notifications::history;
|
||||
use crate::config::pills::{self as settings, layout};
|
||||
use crate::config::pills::{self as settings, colors as hues, layout};
|
||||
use crate::edge::{self, Edge};
|
||||
use crate::glyph::{Glyph, icon};
|
||||
use crate::island::{self, CLEAR, mix, phases, veiled};
|
||||
use crate::parse::Sky;
|
||||
use crate::{ai, home, notices, stats, surface, theme};
|
||||
|
||||
/*
|
||||
* four small one-icon pills beside the island, each opening into a card the way the
|
||||
* island does: left of it the AI chat and the system monitor, right of it home and
|
||||
* notifications. one window per side and monitor (magic-pods-left|right) placed beside
|
||||
* the island's pill; while the island opens they move out of its way. one card at a
|
||||
* time across the shell: opening one collapses the island and the other way round
|
||||
* four small one-icon pills beside the island, each opening into a big card in the
|
||||
* middle of the top of the screen. while a card is open the row becomes a carousel:
|
||||
* every other pill and the island's pill line up left and right of the card in their
|
||||
* usual order ([AI][System] island [Home][Bell]), and clicking one switches to its card.
|
||||
* a closing card shrinks back into its own pill's place.
|
||||
*
|
||||
* one window per monitor (magic-pods), as wide as the monitor and anchored to its left
|
||||
* edge, so it never moves: only its height changes, at the top edge. while a card is
|
||||
* open it also draws the island's pill (island::pill_face), which the island's own
|
||||
* window leaves out meanwhile (holds_island); the two overlap for a moment at each
|
||||
* hand-over, at the same place, so the pill never blinks
|
||||
*/
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum Pod {
|
||||
@@ -31,15 +38,18 @@ pub enum Pod {
|
||||
Notifications,
|
||||
}
|
||||
|
||||
// left of the island, outermost first; right of it, innermost first
|
||||
const LEFT: [Pod; 2] = [Pod::Ai, Pod::Monitor];
|
||||
const RIGHT: [Pod; 2] = [Pod::Home, Pod::Notifications];
|
||||
// the row, left to right
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Item {
|
||||
Pod(Pod),
|
||||
Island,
|
||||
}
|
||||
|
||||
const ROW: [Item; 5] = [Item::Pod(Pod::Ai), Item::Pod(Pod::Monitor), Item::Island, Item::Pod(Pod::Home), Item::Pod(Pod::Notifications)];
|
||||
|
||||
const PODS: [Pod; 4] = [Pod::Ai, Pod::Monitor, Pod::Home, Pod::Notifications];
|
||||
|
||||
impl Pod {
|
||||
fn left(self) -> bool {
|
||||
matches!(self, Self::Ai | Self::Monitor)
|
||||
}
|
||||
|
||||
fn glyph(self) -> Glyph {
|
||||
match self {
|
||||
Self::Ai => Glyph::Sparkle,
|
||||
@@ -59,6 +69,24 @@ impl Pod {
|
||||
}
|
||||
}
|
||||
|
||||
// its own colour; home's follows the sky
|
||||
fn hue(self) -> Color {
|
||||
match self {
|
||||
Self::Ai => hues::ai(),
|
||||
Self::Monitor => hues::monitor(),
|
||||
Self::Notifications => hues::notifications(),
|
||||
Self::Home => match home::sky() {
|
||||
Some((Sky::Clear | Sky::PartlyCloudy, true)) => hues::home_clear_day(),
|
||||
Some((Sky::Clear | Sky::PartlyCloudy, false)) => hues::home_clear_night(),
|
||||
Some((Sky::Cloudy, _)) | None => hues::home_cloudy(),
|
||||
Some((Sky::Fog, _)) => hues::home_fog(),
|
||||
Some((Sky::Rain, _)) => hues::home_rain(),
|
||||
Some((Sky::Snow, _)) => hues::home_snow(),
|
||||
Some((Sky::Storm, _)) => hues::home_storm(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// whether its card takes typing: then it has the keyboard and stays open when the pointer leaves
|
||||
fn types(self) -> bool {
|
||||
self == Self::Ai || (self == Self::Home && home::typing())
|
||||
@@ -74,16 +102,25 @@ impl Pod {
|
||||
}
|
||||
|
||||
fn from_word(word: &str) -> Option<Self> {
|
||||
[Self::Ai, Self::Monitor, Self::Home, Self::Notifications].into_iter().find(|pod| pod.word() == word)
|
||||
PODS.into_iter().find(|pod| pod.word() == word)
|
||||
}
|
||||
}
|
||||
|
||||
// the wallpaper's surfaces with some of a colour mixed in, keeping their see-through
|
||||
fn tinted(colors: &[Color; 3], hue: Color, amount: f32) -> [Color; 3] {
|
||||
colors.map(|color| Color::blend(color, Color::rgba(hue.red(), hue.green(), hue.blue(), color.alpha()), amount))
|
||||
}
|
||||
|
||||
pub struct Pods {
|
||||
// the card open or closing, and the monitor it's on; `shown` whether it's opening or open
|
||||
card: Option<(Pod, String)>,
|
||||
shown: bool,
|
||||
timeline: Animation,
|
||||
|
||||
// a switch from one open card straight to another: the one before, and the switch's progress
|
||||
previous: Option<Pod>,
|
||||
switch: Animation,
|
||||
|
||||
hover: HashMap<Pod, Animation>,
|
||||
|
||||
// the pointer over the card, and a count every arrival and departure bumps, so a late close does nothing
|
||||
@@ -93,7 +130,7 @@ pub struct Pods {
|
||||
|
||||
impl Service for Pods {
|
||||
fn new() -> Self {
|
||||
Self { card: None, shown: false, timeline: timeline(), hover: HashMap::new(), inside: false, moves: 0 }
|
||||
Self { card: None, shown: false, timeline: timeline(), previous: None, switch: switching(1.0), hover: HashMap::new(), inside: false, moves: 0 }
|
||||
}
|
||||
|
||||
// changes only through input
|
||||
@@ -104,15 +141,34 @@ fn timeline() -> Animation {
|
||||
Animation::new(0.0).duration(Duration::from_millis(layout::open_ms())).easing(Easing::Linear)
|
||||
}
|
||||
|
||||
fn switching(from: f32) -> Animation {
|
||||
Animation::new(from).duration(Duration::from_millis(layout::open_ms())).easing(Easing::InOut)
|
||||
}
|
||||
|
||||
pub fn open(pod: Pod, monitor: &str) {
|
||||
island::collapse();
|
||||
|
||||
let mut pods = Pods::write();
|
||||
|
||||
// another card, or this one on another monitor: it grows from its own pill
|
||||
if pods.card.as_ref().is_none_or(|(open, on)| *open != pod || on != monitor) {
|
||||
pods.card = Some((pod, monitor.to_string()));
|
||||
pods.timeline = timeline();
|
||||
let open_here = pods.shown && pods.timeline.value() > 0.5;
|
||||
let current = pods.card.as_ref().filter(|(_, on)| on == monitor).map(|(open, _)| *open);
|
||||
|
||||
match current {
|
||||
Some(open) if open == pod => {}
|
||||
// another card while one is open here: the open one turns into it
|
||||
Some(open) if open_here => {
|
||||
pods.previous = Some(open);
|
||||
pods.switch = switching(0.0);
|
||||
pods.switch.to(1.0);
|
||||
pods.card = Some((pod, monitor.to_string()));
|
||||
}
|
||||
// another card, or one on another monitor: it grows from its own pill
|
||||
_ => {
|
||||
pods.card = Some((pod, monitor.to_string()));
|
||||
pods.timeline = timeline();
|
||||
pods.previous = None;
|
||||
pods.switch = switching(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
pods.shown = true;
|
||||
@@ -152,6 +208,20 @@ pub fn open_card() -> Option<Pod> {
|
||||
pods.card.as_ref().filter(|_| pods.shown).map(|(pod, _)| *pod)
|
||||
}
|
||||
|
||||
/*
|
||||
* whether this window draws the island's pill on `monitor` now: a little past the start
|
||||
* of opening and until a little before the end of closing. this window draws it from
|
||||
* the first frame to the last, so the two overlap at each hand-over, at the same place
|
||||
*/
|
||||
pub fn holds_island(monitor: &str) -> bool {
|
||||
let pods = Pods::read();
|
||||
|
||||
pods.card.as_ref().is_some_and(|(_, on)| on == monitor) && pods.timeline.value() > HAND_OVER
|
||||
}
|
||||
|
||||
// a share of the open timeline (420 ms by default: 0.08 is about two frames)
|
||||
const HAND_OVER: f32 = 0.08;
|
||||
|
||||
fn hovering(pod: Pod) -> impl Fn(bool) + 'static {
|
||||
move |inside| {
|
||||
edge::over_bar(inside);
|
||||
@@ -195,138 +265,334 @@ fn over_card(inside: bool) {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn left(monitor: &Monitor) -> LayerWindow {
|
||||
side(monitor, true)
|
||||
// the island's pill in the carousel: the card closes back into place, then the island opens
|
||||
fn island_tapped(monitor: String) {
|
||||
close();
|
||||
|
||||
thread::spawn(move || {
|
||||
thread::sleep(Duration::from_millis(layout::open_ms()));
|
||||
|
||||
island::tap(&monitor);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn right(monitor: &Monitor) -> LayerWindow {
|
||||
side(monitor, false)
|
||||
// an item's width in the carousel
|
||||
fn item_width(item: Item) -> f32 {
|
||||
match item {
|
||||
Item::Pod(_) => island_pill::height(),
|
||||
// beside an open card the island's pill shrinks to its cover or its bars
|
||||
Item::Island => island::small_width(),
|
||||
}
|
||||
}
|
||||
|
||||
fn side(monitor: &Monitor, left: bool) -> LayerWindow {
|
||||
// an item's left edge in the row with nothing open, around the island as wide as it is now
|
||||
fn closed_x(item: Item, middle: f32, island_w: f32) -> f32 {
|
||||
let (h, spacing, gap) = (island_pill::height(), layout::spacing(), layout::gap());
|
||||
|
||||
match item {
|
||||
Item::Island => middle - island_pill::width() / 2.0,
|
||||
Item::Pod(Pod::Monitor) => middle - island_w / 2.0 - gap - h,
|
||||
Item::Pod(Pod::Ai) => middle - island_w / 2.0 - gap - 2.0 * h - spacing,
|
||||
Item::Pod(Pod::Home) => middle + island_w / 2.0 + gap,
|
||||
Item::Pod(Pod::Notifications) => middle + island_w / 2.0 + gap + h + spacing,
|
||||
}
|
||||
}
|
||||
|
||||
fn index(item: Item) -> usize {
|
||||
ROW.iter().position(|other| *other == item).unwrap_or(0)
|
||||
}
|
||||
|
||||
/*
|
||||
* the two items on each side of `open`'s card: the other four in the row's order, the
|
||||
* first two on its left and the last two on its right, so the left-most stays left-most
|
||||
* (around Home: AI and System on its left, the island and the bell on its right; around
|
||||
* AI: System and the island on its left, Home and the bell on its right)
|
||||
*/
|
||||
fn beside(open: Pod) -> ([Item; 2], [Item; 2]) {
|
||||
let others: Vec<Item> = ROW.into_iter().filter(|item| *item != Item::Pod(open)).collect();
|
||||
|
||||
([others[0], others[1]], [others[2], others[3]])
|
||||
}
|
||||
|
||||
// an item's left edge in the carousel around `open`'s card, `card_w` wide, in the middle, and its side of the card (-1, 0 for the card's own, 1)
|
||||
fn carousel(item: Item, open: Pod, card_w: f32, middle: f32) -> (f32, i8) {
|
||||
// the card's own pill, while it fades into the card or out of it, sits in the card's middle
|
||||
if item == Item::Pod(open) {
|
||||
return (middle - item_width(item) / 2.0, 0);
|
||||
}
|
||||
|
||||
let (spacing, gap) = (layout::spacing(), layout::gap());
|
||||
let (left, right) = beside(open);
|
||||
|
||||
match left.iter().position(|other| *other == item) {
|
||||
// leftwards from the card, past the one between
|
||||
Some(k) => {
|
||||
let between: f32 = left[k + 1..].iter().map(|other| item_width(*other) + spacing).sum();
|
||||
|
||||
(middle - card_w / 2.0 - gap - between - item_width(item), -1)
|
||||
}
|
||||
None => {
|
||||
let k = right.iter().position(|other| *other == item).unwrap_or(0);
|
||||
let between: f32 = right[..k].iter().map(|other| item_width(*other) + spacing).sum();
|
||||
|
||||
(middle + card_w / 2.0 + gap + between, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* an item's side of the middle in the closed row, where every card opens: AI and System
|
||||
* left, the island in it (0, so it slides out to whichever side it goes), Home and the
|
||||
* bell right. no item changes sides on opening, so none crosses the card
|
||||
*/
|
||||
fn closed_side(item: Item) -> i8 {
|
||||
(index(item) as i8 - index(Item::Island) as i8).signum()
|
||||
}
|
||||
|
||||
/*
|
||||
* from one place to another by `k`, with how much it shows: sliding when it stays on its
|
||||
* side of the card; changing sides it fades out where it is over the first half and in at
|
||||
* its new place over the second, so it never crosses the card
|
||||
*/
|
||||
fn travel(from: (f32, i8), to: (f32, i8), k: f32) -> (f32, f32) {
|
||||
if from.1 == to.1 || from.1 == 0 || to.1 == 0 {
|
||||
(mix(from.0, to.0, k), 1.0)
|
||||
} else if k < 0.5 {
|
||||
(from.0, 1.0 - 2.0 * k)
|
||||
} else {
|
||||
(to.0, 2.0 * k - 1.0)
|
||||
}
|
||||
}
|
||||
|
||||
// what both windows need to know about this monitor's card this frame
|
||||
struct Scene {
|
||||
// the pod and its timeline, while it's at all open here
|
||||
card: Option<(Pod, f32)>,
|
||||
grow: f32,
|
||||
pill_shown: f32,
|
||||
reveal: f32,
|
||||
switch: f32,
|
||||
previous: Option<Pod>,
|
||||
middle: f32,
|
||||
island_w: f32,
|
||||
// the row's move into the carousel: it starts only after the hand-over (see holds_island), so the island's pill never shows twice
|
||||
row_grow: f32,
|
||||
}
|
||||
|
||||
fn scene(state: &Pods, monitor: &Monitor) -> Scene {
|
||||
let here = monitor.name.as_str();
|
||||
let card = state.card.as_ref().filter(|(_, on)| on == here).map(|(pod, _)| (*pod, state.timeline.value())).filter(|(_, t)| *t > 0.0);
|
||||
let (grow, pill_shown, reveal) = card.map_or((0.0, 1.0, 0.0), |(_, t)| phases(t));
|
||||
|
||||
// read only here: a running animation redraws every window that reads it
|
||||
let switch = if card.is_some() { state.switch.value() } else { 1.0 };
|
||||
let previous = state.previous.filter(|_| switch < 1.0 && card.is_some());
|
||||
|
||||
let row_grow = card.map_or(0.0, |(_, t)| phases(((t - 2.0 * HAND_OVER) / (1.0 - 2.0 * HAND_OVER)).max(0.0)).0);
|
||||
|
||||
Scene { card, grow, pill_shown, reveal, switch, previous, middle: monitor.width as f32 / 2.0, island_w: island::width_on(here), row_grow }
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
// an item's left edge on the monitor and how much it shows: between the closed row and the carousel by `row_grow`, between two carousels by `switch`
|
||||
fn place(&self, item: Item) -> (f32, f32) {
|
||||
let closed = closed_x(item, self.middle, self.island_w);
|
||||
|
||||
let Some((open, _)) = self.card else { return (closed, 1.0) };
|
||||
|
||||
let now = carousel(item, open, open.size().0, self.middle);
|
||||
|
||||
let (open_x, open_shown, open_side) = match self.previous {
|
||||
Some(before) => {
|
||||
let from = carousel(item, before, before.size().0, self.middle);
|
||||
let (x, shown) = travel(from, now, self.switch);
|
||||
|
||||
(x, shown, if self.switch < 0.5 { from.1 } else { now.1 })
|
||||
}
|
||||
None => (now.0, 1.0, now.1),
|
||||
};
|
||||
|
||||
let (x, shown) = travel((closed, closed_side(item)), (open_x, open_side), self.row_grow);
|
||||
|
||||
(x, shown * open_shown)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* the row of pills: as wide as the monitor and as tall as a pill, never changing. amane
|
||||
* repaints a whole window every frame and hyprland then recomposites (and re-blurs)
|
||||
* everything under it, so a window as tall as the cards ran the animations at 15 fps;
|
||||
* the cards have their own window (card_view)
|
||||
*/
|
||||
pub fn row_view(monitor: &Monitor) -> LayerWindow {
|
||||
theme::begin();
|
||||
|
||||
let here = monitor.name.as_str();
|
||||
let pods = if left { LEFT } else { RIGHT };
|
||||
let colors = theme::now().surfaces();
|
||||
|
||||
let wallpaper = theme::now().surfaces();
|
||||
let state = Pods::read();
|
||||
let scene = scene(&state, monitor);
|
||||
let (h, top, shadow) = (island_pill::height(), island_pill::top_gap(), island_pill::shadow());
|
||||
|
||||
// this side's card on this monitor, while it's at all open
|
||||
let card = state.card.as_ref().filter(|(pod, on)| pod.left() == left && on == here).map(|(pod, _)| (*pod, state.timeline.value())).filter(|(_, t)| *t > 0.0);
|
||||
|
||||
// with the bar on a fullscreen monitor, unless its card is open; out of the island's way while it opens
|
||||
let slide = if card.is_some() { 0.0 } else { edge::hidden_by(Edge::read().shown(here), 0.0, edge::hide_h()) };
|
||||
let shift = (island::width_on(here) - island_pill::width()) / 2.0;
|
||||
|
||||
let (h, top, shadow, spacing) = (island_pill::height(), island_pill::top_gap(), island_pill::shadow(), layout::spacing());
|
||||
let count = pods.len() as f32;
|
||||
let group_w = count * h + (count - 1.0) * spacing;
|
||||
|
||||
let (card_w, card_h) = card.map_or((0.0, 0.0), |(pod, _)| pod.size());
|
||||
|
||||
/*
|
||||
* room for the pills to move away from the open island, or for this side's widest
|
||||
* card. the width never follows the open card: a narrower window would move with
|
||||
* its margin, and Hyprland applies size and position on different frames, so the
|
||||
* pills jumped when a card closed
|
||||
*/
|
||||
let room = (island_card::width() - island_pill::width()) / 2.0;
|
||||
let widest = pods.iter().map(|pod| pod.size().0).fold(0.0, f32::max);
|
||||
let inner_w = (group_w + room).max(widest);
|
||||
let window_h = top + h.max(card_h) + shadow;
|
||||
|
||||
// the group's edge nearest the island, in the window, and where the window starts on the monitor
|
||||
let near = if left { shadow + inner_w } else { shadow };
|
||||
let middle = monitor.width as f32 / 2.0;
|
||||
let beside = island_pill::width() / 2.0 + layout::gap();
|
||||
let start = if left { middle - beside - near } else { middle + beside - near };
|
||||
// with the bar on a fullscreen monitor, unless a card is open
|
||||
let slide = if scene.card.is_some() { 0.0 } else { edge::hidden_by(Edge::read().shown(here), 0.0, edge::hide_h()) };
|
||||
|
||||
let window = LayerWindow::new()
|
||||
.width(inner_w + 2.0 * shadow)
|
||||
.height(window_h)
|
||||
.width(monitor.width as f32)
|
||||
.height(top + h + shadow)
|
||||
.anchor_vertical(Vertical::Top)
|
||||
.anchor_horizontal(Horizontal::Left)
|
||||
.margin(Margin { top: 0, right: 0, bottom: 0, left: start.round() as i32 })
|
||||
.margin(Margin { top: 0, right: 0, bottom: 0, left: 0 })
|
||||
.layer(Layer::Overlay)
|
||||
.space(Zone::Ignore)
|
||||
.namespace(if left { "magic-pods-left" } else { "magic-pods-right" });
|
||||
.namespace("magic-pods");
|
||||
|
||||
// empty and click-through rather than hidden: see the island's view for why
|
||||
if slide <= -edge::hide_h() {
|
||||
return window.click_through().child(Rectangle::new().width(0.0).height(0.0));
|
||||
}
|
||||
|
||||
// a pill's left edge in the window; `k` counts from the island outwards
|
||||
let pill_x = |pod: Pod| {
|
||||
let at = pods.iter().position(|other| *other == pod).unwrap_or(0) as f32;
|
||||
let k = if left { count - 1.0 - at } else { at };
|
||||
|
||||
if left { near - shift - (k + 1.0) * h - k * spacing } else { near + shift + k * (h + spacing) }
|
||||
};
|
||||
|
||||
let (grow, pill_shown, reveal) = card.map_or((0.0, 1.0, 0.0), |(_, t)| phases(t));
|
||||
|
||||
/*
|
||||
* the pills beside an open card are gone; a closing card shrinks back into its own
|
||||
* pill's place, and they come back behind it only over the last `reveal_at` of its
|
||||
* shrinking, so they don't pop up around a big card
|
||||
*/
|
||||
let reveal_at = layout::reveal_at();
|
||||
let others = if grow <= 0.0 {
|
||||
1.0
|
||||
} else if reveal_at <= 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
let k = (1.0 - grow / reveal_at).clamp(0.0, 1.0);
|
||||
|
||||
k * k * (3.0 - 2.0 * k)
|
||||
};
|
||||
let (card, previous, switch) = (scene.card, scene.previous, scene.switch);
|
||||
|
||||
let mut layers: Vec<Box<dyn Widget>> = Vec::new();
|
||||
let mut regions: Vec<InputArea> = Vec::new();
|
||||
|
||||
for pod in pods {
|
||||
// the open one is the card, drawn last, over the others
|
||||
if card.is_some_and(|(open, _)| open == pod) || others <= 0.0 {
|
||||
for item in ROW {
|
||||
let (x, seen) = scene.place(item);
|
||||
|
||||
if seen <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let x = pill_x(pod);
|
||||
let lit = state.hover.get(&pod).map_or(0.0, Animation::value);
|
||||
let pill = pill(pod, lit, &colors, here);
|
||||
let pill = if others < 1.0 { pill.opacity(others) } else { pill };
|
||||
match item {
|
||||
Item::Island => {
|
||||
// the island's own window draws its pill while nothing is open here
|
||||
if card.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
regions.push(InputArea { x: x as i32, y: (top + slide) as i32, width: h.ceil() as i32, height: h.ceil() as i32 });
|
||||
layers.push(Box::new(pill.translate(x, top + slide)));
|
||||
// it shrinks to its cover (or its bars) as it moves aside
|
||||
let small = scene.row_grow;
|
||||
let width = mix(island_pill::width(), island::small_width(), small);
|
||||
let on = here.to_string();
|
||||
let pill = island::pill_face(here, small).cursor(Pointer).on_hover(edge::over_bar).on_click(move |_| island_tapped(on.clone()));
|
||||
let pill = if seen < 1.0 { pill.opacity(seen) } else { pill };
|
||||
|
||||
regions.push(InputArea { x: x as i32, y: top as i32, width: width.ceil() as i32, height: h.ceil() as i32 });
|
||||
layers.push(Box::new(pill.translate(x, top)));
|
||||
}
|
||||
Item::Pod(pod) => {
|
||||
// the open one is the card, drawn last. in a switch, the one switched to slides into
|
||||
// the card and fades over the first half; the one switched away from fades back in as a pill
|
||||
let shown = match previous {
|
||||
Some(_) if card.is_some_and(|(open, _)| open == pod) => 1.0 - 2.0 * switch,
|
||||
// its card is in the card window, which starts drawing at HAND_OVER; the pill stays a little longer under it
|
||||
_ if card.is_some_and(|(open, t)| open == pod && t > 2.0 * HAND_OVER) => continue,
|
||||
Some(before) if before == pod => switch,
|
||||
_ => 1.0,
|
||||
} * seen;
|
||||
|
||||
if shown <= 0.0 {
|
||||
continue;
|
||||
}
|
||||
|
||||
let lit = state.hover.get(&pod).map_or(0.0, Animation::value);
|
||||
let pill = pill(pod, lit, &wallpaper, here);
|
||||
let pill = if shown < 1.0 { pill.opacity(shown) } else { pill };
|
||||
|
||||
regions.push(InputArea { x: x as i32, y: (top + slide) as i32, width: h.ceil() as i32, height: h.ceil() as i32 });
|
||||
layers.push(Box::new(pill.translate(x, top + slide)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let typing = card.is_some_and(|(pod, _)| pod.types() && state.shown);
|
||||
window.input_region(regions).child(Rectangle::new().width(Parent).height(Parent).child(Stack::new(layers).width(Parent).height(Parent)))
|
||||
}
|
||||
|
||||
if let Some((pod, _)) = card {
|
||||
// from the pill to the card, its edge nearest the island staying put
|
||||
let from_x = pill_x(pod);
|
||||
let to_x = if left { near - shift - card_w } else { near + shift };
|
||||
/*
|
||||
* the open card, in the middle: a window as big as the biggest card while one is open
|
||||
* here, and an empty pixel otherwise. it changes size only while it shows nothing (the
|
||||
* card starts and ends as its pill, which the row window draws under it meanwhile), so
|
||||
* hyprland's squashed first frame at a new size is never seen
|
||||
*/
|
||||
pub fn card_view(monitor: &Monitor) -> LayerWindow {
|
||||
theme::begin();
|
||||
|
||||
let width = mix(h, card_w, grow);
|
||||
let height = mix(h, card_h, grow);
|
||||
let wallpaper = theme::now().surfaces();
|
||||
let state = Pods::read();
|
||||
let scene = scene(&state, monitor);
|
||||
let (h, top, shadow) = (island_pill::height(), island_pill::top_gap(), island_pill::shadow());
|
||||
|
||||
let window = |width: f32, height: f32| LayerWindow::new().width(width).height(height).anchor_vertical(Vertical::Top).layer(Layer::Overlay).space(Zone::Ignore).namespace("magic-pods-card");
|
||||
|
||||
let Some((pod, t)) = scene.card else {
|
||||
return window(1.0, 1.0).click_through().child(Rectangle::new().width(0.0).height(0.0));
|
||||
};
|
||||
|
||||
let widest = PODS.iter().map(|pod| pod.size().0).fold(h, f32::max);
|
||||
let tallest = [settings::ai::height(), stats::tallest(), home::height(), history::height()].into_iter().fold(h, f32::max);
|
||||
let window_w = (widest + 2.0 * shadow).round();
|
||||
|
||||
// centred by hyprland: its left edge on the monitor
|
||||
let left = ((monitor.width as f32 - window_w) / 2.0).floor();
|
||||
let window = window(window_w, top + tallest + shadow);
|
||||
|
||||
// the first frames at the new size show at the old place, so they stay empty (the row draws the pill meanwhile)
|
||||
if t <= HAND_OVER {
|
||||
return window.click_through().child(Rectangle::new().width(0.0).height(0.0));
|
||||
}
|
||||
|
||||
let (grow, pill_shown, reveal, switch, previous, middle) = (scene.grow, scene.pill_shown, scene.reveal, scene.switch, scene.previous, scene.middle);
|
||||
|
||||
let mut layers: Vec<Box<dyn Widget>> = Vec::new();
|
||||
let mut regions: Vec<InputArea> = Vec::new();
|
||||
|
||||
let typing = pod.types() && state.shown;
|
||||
|
||||
{
|
||||
let (card_w, card_h) = pod.size();
|
||||
|
||||
// a switch morphs the card from the one before: its size, its colour, and its face crossing over
|
||||
let (full_w, full_h, hue) = match previous {
|
||||
Some(before) => {
|
||||
let (before_w, before_h) = before.size();
|
||||
|
||||
(mix(before_w, card_w, switch), mix(before_h, card_h, switch), Color::blend(before.hue(), pod.hue(), switch))
|
||||
}
|
||||
None => (card_w, card_h, pod.hue()),
|
||||
};
|
||||
|
||||
// from its pill's place in the closed row to the middle, and back into that place; in the window
|
||||
let from_x = closed_x(Item::Pod(pod), middle, scene.island_w) - left;
|
||||
let to_x = middle - full_w / 2.0 - left;
|
||||
|
||||
let width = mix(h, full_w, grow);
|
||||
let height = mix(h, full_h, grow);
|
||||
let x = mix(from_x, to_x, grow);
|
||||
let radius = mix(h / 2.0, layout::radius(), grow);
|
||||
let lit = state.hover.get(&pod).map_or(0.0, Animation::value);
|
||||
let colors = tinted(&wallpaper, hue, mix(hues::pill_mix(), hues::card_mix(), grow));
|
||||
|
||||
let face: Rectangle = if reveal > 0.0 {
|
||||
veiled(content(pod, card_w, card_h), width, height, radius, reveal, &colors)
|
||||
} else {
|
||||
// the pill's icon fading as the shape grows
|
||||
let tint = Color::blend(CLEAR, theme::now().text, pill_shown);
|
||||
let face: Rectangle = match previous {
|
||||
// the card before fades out over the first half of the switch, this one in over the second
|
||||
Some(before) if switch < 0.5 => {
|
||||
let (before_w, before_h) = before.size();
|
||||
|
||||
Rectangle::new().width(h).height(h).align_child(Center, Center).child(icon(pod.glyph(), layout::icon(), tint))
|
||||
veiled(content(before, before_w, before_h), width, height, radius, 1.0 - 2.0 * switch, &colors)
|
||||
}
|
||||
Some(_) => veiled(content(pod, card_w, card_h), width, height, radius, 2.0 * switch - 1.0, &colors),
|
||||
None if reveal > 0.0 => veiled(content(pod, card_w, card_h), width, height, radius, reveal, &colors),
|
||||
None => {
|
||||
// the pill's icon fading as the shape grows
|
||||
let tint = Color::blend(CLEAR, pod.hue(), pill_shown);
|
||||
|
||||
Rectangle::new().width(h).height(h).align_child(Center, Center).child(icon(pod.glyph(), layout::icon(), tint))
|
||||
}
|
||||
};
|
||||
|
||||
let face = Rectangle::new().width(width).height(height).align_child(Start, Start).child(face);
|
||||
let shape = surface::shell(width, height, radius, &colors, lit * pill_shown, face).on_hover(over_card).translate(x, top + slide);
|
||||
let face = Rectangle::new().width(width).height(height).align_child(Center, Start).child(face);
|
||||
let shape = surface::shell(width, height, radius, &colors, lit * pill_shown, face).on_hover(over_card).translate(x, top);
|
||||
|
||||
regions.push(InputArea { x: x as i32, y: (top + slide) as i32, width: width.ceil() as i32, height: height.ceil() as i32 });
|
||||
regions.push(InputArea { x: x as i32, y: top as i32, width: width.ceil() as i32, height: height.ceil() as i32 });
|
||||
layers.push(Box::new(shape));
|
||||
}
|
||||
|
||||
@@ -346,12 +612,14 @@ fn side(monitor: &Monitor, left: bool) -> LayerWindow {
|
||||
window.child(Rectangle::new().width(Parent).height(Parent).child(Stack::new(layers).width(Parent).height(Parent)))
|
||||
}
|
||||
|
||||
// a small pill: the surface with one icon; the bell carries the unread count
|
||||
fn pill(pod: Pod, lit: f32, colors: &[Color; 3], monitor: &str) -> Rectangle {
|
||||
// a small pill in its own colour: the surface with one icon; the bell carries the unread count
|
||||
fn pill(pod: Pod, lit: f32, wallpaper: &[Color; 3], monitor: &str) -> Rectangle {
|
||||
let h = island_pill::height();
|
||||
let theme = theme::now();
|
||||
let hue = pod.hue();
|
||||
let colors = tinted(wallpaper, hue, hues::pill_mix());
|
||||
|
||||
let glyph = icon(pod.glyph(), layout::icon() * (1.0 + 0.08 * lit), Color::blend(theme.dim, theme.text, 0.6 + 0.4 * lit));
|
||||
let glyph = icon(pod.glyph(), layout::icon() * (1.0 + 0.08 * lit), Color::blend(hue, theme.text, 0.25 + 0.5 * lit));
|
||||
let mut inside: Vec<Box<dyn Widget>> = vec![Box::new(Rectangle::new().width(h).height(h).align_child(Center, Center).child(glyph))];
|
||||
|
||||
let unread = if pod == Pod::Notifications { notices::unread() } else { 0 };
|
||||
@@ -365,7 +633,7 @@ fn pill(pod: Pod, lit: f32, colors: &[Color; 3], monitor: &str) -> Rectangle {
|
||||
.width(badge)
|
||||
.height(badge)
|
||||
.radius(Full)
|
||||
.fill(theme.accent)
|
||||
.fill(hue)
|
||||
.align_child(Center, Center)
|
||||
.translate(h - badge - 3.0, 3.0)
|
||||
.child(Text::new(words).size(text::tiny() - 1.0).weight(Weight::Bold).color(theme.on_accent)),
|
||||
@@ -375,7 +643,7 @@ fn pill(pod: Pod, lit: f32, colors: &[Color; 3], monitor: &str) -> Rectangle {
|
||||
let content = Rectangle::new().width(h).height(h).child(Stack::new(inside).width(h).height(h));
|
||||
let on = monitor.to_string();
|
||||
|
||||
surface::shell(h, h, h / 2.0, colors, lit, content).cursor(Pointer).on_hover(hovering(pod)).on_click(move |_| toggle(pod, &on))
|
||||
surface::shell(h, h, h / 2.0, &colors, lit, content).cursor(Pointer).on_hover(hovering(pod)).on_click(move |_| toggle(pod, &on))
|
||||
}
|
||||
|
||||
fn content(pod: Pod, width: f32, height: f32) -> Rectangle {
|
||||
@@ -494,9 +762,9 @@ pub fn command(arguments: &[String]) -> String {
|
||||
let card = pods.card.as_ref().filter(|_| pods.shown).map_or("none", |(pod, _)| pod.word());
|
||||
let on = pods.card.as_ref().map_or("", |(_, on)| on.as_str());
|
||||
|
||||
format!("card={card} monitor={on} timeline={:.2} unread={}", pods.timeline.value(), notices::unread())
|
||||
format!("card={card} monitor={on} timeline={:.2} switch={:.2} unread={}", pods.timeline.value(), pods.switch.value(), notices::unread())
|
||||
}
|
||||
_ => String::from("usage: pods open|toggle <ai|monitor|home|notifications> [monitor] | close | ask <question> | notices list|dismiss <id>|clear | status"),
|
||||
_ => String::from("usage: pods open|toggle <ai|monitor|home|notifications> [monitor] | close | ask <question> | processes | notices list|dismiss <id>|clear | status"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,4 +772,3 @@ pub fn command(arguments: &[String]) -> String {
|
||||
pub fn rule(width: f32) -> Rectangle {
|
||||
Rectangle::new().width(width).height(1.0).fill(overlays::track())
|
||||
}
|
||||
|
||||
|
||||
@@ -293,6 +293,14 @@ pub fn height() -> f32 {
|
||||
2.0 * layout::pad() + pods::header_height() + graphs + egpu + 1.0 + label_height() + temp_rows() as f32 * temp_row_height() + (parts - 1.0) * 10.0
|
||||
}
|
||||
|
||||
// the card's height at its tallest: an external gpu with its whole list of programs
|
||||
pub fn tallest() -> f32 {
|
||||
let graphs = 7.0 * (label_height() + settings::graph_height()) + 6.0 * 10.0;
|
||||
let egpu = (1 + settings::programs()) as f32 * program_row_height();
|
||||
|
||||
2.0 * layout::pad() + pods::header_height() + graphs + egpu + 1.0 + label_height() + temp_rows() as f32 * temp_row_height() + 5.0 * 10.0
|
||||
}
|
||||
|
||||
// bytes a second in words
|
||||
fn rate(bytes: f32) -> String {
|
||||
match bytes {
|
||||
|
||||
+48
-1
@@ -3,7 +3,7 @@ use std::sync::LazyLock;
|
||||
|
||||
use amane::{Blend, Color, Rectangle, Stack, children};
|
||||
|
||||
use crate::config::appearance::{frosted, liquid, solid, surface};
|
||||
use crate::config::appearance::{frosted, glass, liquid, solid, surface};
|
||||
use crate::island::faded;
|
||||
use crate::theme;
|
||||
|
||||
@@ -22,6 +22,10 @@ use crate::theme;
|
||||
* the rim stays a border, which amane draws as a quad
|
||||
*/
|
||||
pub fn shell(width: f32, height: f32, radius: f32, colors: &[Color; 3], lift: f32, content: Rectangle) -> Rectangle {
|
||||
if surface::design() == "glass" {
|
||||
return glass_shell(width, height, radius, colors, lift, content);
|
||||
}
|
||||
|
||||
let theme = theme::now();
|
||||
|
||||
let look = match surface::design().as_str() {
|
||||
@@ -89,6 +93,49 @@ pub fn clear() -> bool {
|
||||
}
|
||||
|
||||
static SHADER: LazyLock<PathBuf> = LazyLock::new(|| shader_file("surface.wgsl", include_str!("surface.wgsl")));
|
||||
static GLASS: LazyLock<PathBuf> = LazyLock::new(|| shader_file("glass.wgsl", include_str!("glass.wgsl")));
|
||||
|
||||
/*
|
||||
* after Apple's Liquid Glass: glass.wgsl draws the shadow and the thin tint in the
|
||||
* wallpaper's colours under the content, and the lens-like edge with its rim over it, so a
|
||||
* photo on a card lies behind the glass; there's no border. the frosting behind is
|
||||
* Hyprland's blur; the desktop isn't bent at the rim the way Apple's glass bends it, since
|
||||
* a shell's shader can't see what's behind its window
|
||||
*/
|
||||
fn glass_shell(width: f32, height: f32, radius: f32, colors: &[Color; 3], lift: f32, content: Rectangle) -> Rectangle {
|
||||
let (blur, drop): (f32, f32) = (22.0, 6.0);
|
||||
let margin = (1.25 * blur + drop).ceil();
|
||||
|
||||
let mut shadow = plain(Color::BLACK);
|
||||
|
||||
shadow[3] = (glass::shadow() + 0.1 * lift).clamp(0.0, 1.0);
|
||||
|
||||
let tint = |color: Color| {
|
||||
let mut tint = plain(color);
|
||||
|
||||
tint[3] = glass::opacity().clamp(0.0, 1.0);
|
||||
|
||||
tint
|
||||
};
|
||||
|
||||
// the under layer covers the shadow's room around the shape too, the edge only the shape
|
||||
let layer = |which: f32, margin: f32| {
|
||||
let values = vec![
|
||||
[width, height, radius, margin],
|
||||
shadow,
|
||||
[blur / 2.0, 0.0, drop, lift],
|
||||
[glass::edge(), glass::light(), glass::rim(), glass::dispersion()],
|
||||
tint(colors[0]),
|
||||
tint(colors[1]),
|
||||
tint(colors[2]),
|
||||
[which, 0.0, 0.0, 0.0],
|
||||
];
|
||||
|
||||
Rectangle::new().width(width + 2.0 * margin).height(height + 2.0 * margin).translate(-margin, -margin).shader(GLASS.as_path()).shader_values(values)
|
||||
};
|
||||
|
||||
Rectangle::new().width(width).height(height).child(Stack::new(children![layer(1.0, margin), content, layer(2.0, 0.0)]).width(width).height(height))
|
||||
}
|
||||
|
||||
// a shader's source is part of the shell; amane wants a file, so it goes beside cava's config
|
||||
pub fn shader_file(name: &str, source: &str) -> PathBuf {
|
||||
|
||||
Reference in New Issue
Block a user