Quince: a Material You video player on mpv
libmpv render API into an egui/glow texture, floating controls with a wavy seek bar and morphing play button, track/speed/chapter menus, playlist and adjust sheets, settings, open link, previews, smoke-test harness. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/tests/media
|
||||
3771
Cargo.lock
generated
Normal file
31
Cargo.toml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
[package]
|
||||
name = "quince"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
description = "A Material You video player for Linux, built on mpv"
|
||||
license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
eframe = { version = "0.37", default-features = false, features = ["glow", "wayland", "x11", "clipboard", "default_fonts", "system_fonts"] }
|
||||
egui_glow = "0.37"
|
||||
glow = "0.17"
|
||||
libmpv2 = "6"
|
||||
libmpv2-sys = "4"
|
||||
raw-window-handle = "0.6"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
image = { version = "0.25", default-features = false, features = ["jpeg", "png"] }
|
||||
dirs = "6"
|
||||
zbus = { version = "5", default-features = false, features = ["blocking-api", "async-io"] }
|
||||
rfd = { version = "0.17", default-features = false, features = ["xdg-portal", "pollster"] }
|
||||
urlencoding = "2"
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
lto = "thin"
|
||||
codegen-units = 4
|
||||
strip = true
|
||||
|
||||
[patch.crates-io]
|
||||
# winit 0.30 cannot receive file drops on Wayland; this copy (from Mulberry) adds wl_data_device support
|
||||
winit = { path = "vendor/winit" }
|
||||
35
README.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Quince
|
||||
|
||||
A Material You video player for Linux, built on [mpv](https://mpv.io). Everything mpv plays, Quince plays: local files,
|
||||
folders, playlists and links (through yt-dlp). The controls float over the video and hide while you watch.
|
||||
|
||||
- Wavy seek bar that moves while playing and lies flat when paused, with chapter marks, the buffered part and a frame
|
||||
preview on hover (ffmpeg).
|
||||
- Play button that turns from a circle into a cookie while playing.
|
||||
- Sound, subtitle and video track menus; second subtitles; loading external subtitles and sound tracks.
|
||||
- Speed, A-B loop, repeat, frame stepping, screenshots, chapters, playlist with drag to reorder and shuffle.
|
||||
- Adjust sheet: aspect ratio, zoom, rotate, mirror, fill, brightness, contrast, saturation, gamma, hue, deinterlace,
|
||||
hardware decoding, audio delay, loudness levelling, stereo downmix, output device, subtitle delay, size and position.
|
||||
- Carries on where you left off (mpv's watch-later), recent files, drag and drop, keeps the screen awake while playing.
|
||||
- Your `~/.config/mpv` (mpv.conf, input.conf, scripts) is used, and keys Quince doesn't use go to mpv, so the console
|
||||
(`` ` ``), statistics (`i`), mpv-mpris and your own bindings work.
|
||||
- Colours from the desktop (Caelestia, KDE), your own colour or the video playing; light, dark and AMOLED; four styles,
|
||||
three contrast levels and four motion levels.
|
||||
|
||||
## Build
|
||||
|
||||
Needs Rust, libmpv (mpv 0.38 or newer) and, for previews, ffmpeg.
|
||||
|
||||
```
|
||||
cargo build --release
|
||||
./target/release/quince video.mkv
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
`cargo test` runs the unit tests. `tools/smoke.sh script.txt outdir [files]` runs the app hidden in a nested niri on Xvfb
|
||||
and plays a script of pointer, key and screenshot steps (see `src/script.rs`).
|
||||
|
||||
## Licence
|
||||
|
||||
MIT. Rubik is under the SIL Open Font License (`assets/Rubik-OFL.txt`); Material Symbols under the Apache License 2.0.
|
||||
93
assets/Rubik-OFL.txt
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
Copyright 2015 The Rubik Project Authors (https://github.com/googlefonts/rubik)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
https://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
BIN
assets/Rubik.ttf
Normal file
BIN
assets/icons/128x128/quince.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
assets/icons/16x16/quince.png
Normal file
|
After Width: | Height: | Size: 412 B |
BIN
assets/icons/256x256/quince.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
assets/icons/32x32/quince.png
Normal file
|
After Width: | Height: | Size: 626 B |
BIN
assets/icons/48x48/quince.png
Normal file
|
After Width: | Height: | Size: 863 B |
BIN
assets/icons/64x64/quince.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
12
assets/quince.desktop
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Quince
|
||||
GenericName=Video player
|
||||
Comment=Watch videos and listen to music with mpv
|
||||
Exec=quince %U
|
||||
Icon=quince
|
||||
Terminal=false
|
||||
Categories=AudioVideo;Video;Player;
|
||||
MimeType=video/mp4;video/x-matroska;video/webm;video/x-msvideo;video/quicktime;video/mpeg;video/ogg;video/x-flv;video/3gpp;video/mp2t;audio/mpeg;audio/flac;audio/ogg;audio/x-wav;audio/mp4;application/x-mpegurl;
|
||||
Keywords=mpv;video;movie;film;player;
|
||||
StartupWMClass=quince
|
||||
4
assets/quince.svg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
|
||||
<path d="M203.3,128.0 L203.4,130.0 L203.5,132.0 L203.8,134.0 L204.1,136.0 L204.6,138.1 L205.1,140.2 L205.7,142.4 L206.3,144.6 L207.0,147.0 L207.7,149.3 L208.4,151.8 L209.1,154.3 L209.7,156.9 L210.3,159.6 L210.8,162.3 L211.3,165.1 L211.6,167.9 L211.8,170.7 L211.9,173.6 L211.9,176.4 L211.6,179.3 L211.2,182.1 L210.7,184.8 L209.9,187.5 L209.0,190.1 L207.9,192.7 L206.5,195.1 L205.1,197.4 L203.4,199.5 L201.5,201.5 L199.5,203.4 L197.4,205.1 L195.1,206.5 L192.7,207.9 L190.1,209.0 L187.5,209.9 L184.8,210.7 L182.1,211.2 L179.3,211.6 L176.4,211.9 L173.6,211.9 L170.7,211.8 L167.9,211.6 L165.1,211.3 L162.3,210.8 L159.6,210.3 L156.9,209.7 L154.3,209.1 L151.8,208.4 L149.3,207.7 L147.0,207.0 L144.6,206.3 L142.4,205.7 L140.2,205.1 L138.1,204.6 L136.0,204.1 L134.0,203.8 L132.0,203.5 L130.0,203.4 L128.0,203.3 L126.0,203.4 L124.0,203.5 L122.0,203.8 L120.0,204.1 L117.9,204.6 L115.8,205.1 L113.6,205.7 L111.4,206.3 L109.0,207.0 L106.7,207.7 L104.2,208.4 L101.7,209.1 L99.1,209.7 L96.4,210.3 L93.7,210.8 L90.9,211.3 L88.1,211.6 L85.3,211.8 L82.4,211.9 L79.6,211.9 L76.7,211.6 L73.9,211.2 L71.2,210.7 L68.5,209.9 L65.9,209.0 L63.3,207.9 L60.9,206.5 L58.6,205.1 L56.5,203.4 L54.5,201.5 L52.6,199.5 L50.9,197.4 L49.5,195.1 L48.1,192.7 L47.0,190.1 L46.1,187.5 L45.3,184.8 L44.8,182.1 L44.4,179.3 L44.1,176.4 L44.1,173.6 L44.2,170.7 L44.4,167.9 L44.7,165.1 L45.2,162.3 L45.7,159.6 L46.3,156.9 L46.9,154.3 L47.6,151.8 L48.3,149.3 L49.0,147.0 L49.7,144.6 L50.3,142.4 L50.9,140.2 L51.4,138.1 L51.9,136.0 L52.2,134.0 L52.5,132.0 L52.6,130.0 L52.7,128.0 L52.6,126.0 L52.5,124.0 L52.2,122.0 L51.9,120.0 L51.4,117.9 L50.9,115.8 L50.3,113.6 L49.7,111.4 L49.0,109.0 L48.3,106.7 L47.6,104.2 L46.9,101.7 L46.3,99.1 L45.7,96.4 L45.2,93.7 L44.7,90.9 L44.4,88.1 L44.2,85.3 L44.1,82.4 L44.1,79.6 L44.4,76.7 L44.8,73.9 L45.3,71.2 L46.1,68.5 L47.0,65.9 L48.1,63.3 L49.5,60.9 L50.9,58.6 L52.6,56.5 L54.5,54.5 L56.5,52.6 L58.6,50.9 L60.9,49.5 L63.3,48.1 L65.9,47.0 L68.5,46.1 L71.2,45.3 L73.9,44.8 L76.7,44.4 L79.6,44.1 L82.4,44.1 L85.3,44.2 L88.1,44.4 L90.9,44.7 L93.7,45.2 L96.4,45.7 L99.1,46.3 L101.7,46.9 L104.2,47.6 L106.7,48.3 L109.0,49.0 L111.4,49.7 L113.6,50.3 L115.8,50.9 L117.9,51.4 L120.0,51.9 L122.0,52.2 L124.0,52.5 L126.0,52.6 L128.0,52.7 L130.0,52.6 L132.0,52.5 L134.0,52.2 L136.0,51.9 L138.1,51.4 L140.2,50.9 L142.4,50.3 L144.6,49.7 L147.0,49.0 L149.3,48.3 L151.8,47.6 L154.3,46.9 L156.9,46.3 L159.6,45.7 L162.3,45.2 L165.1,44.7 L167.9,44.4 L170.7,44.2 L173.6,44.1 L176.4,44.1 L179.3,44.4 L182.1,44.8 L184.8,45.3 L187.5,46.1 L190.1,47.0 L192.7,48.1 L195.1,49.5 L197.4,50.9 L199.5,52.6 L201.5,54.5 L203.4,56.5 L205.1,58.6 L206.5,60.9 L207.9,63.3 L209.0,65.9 L209.9,68.5 L210.7,71.2 L211.2,73.9 L211.6,76.7 L211.9,79.6 L211.9,82.4 L211.8,85.3 L211.6,88.1 L211.3,90.9 L210.8,93.7 L210.3,96.4 L209.7,99.1 L209.1,101.7 L208.4,104.2 L207.7,106.7 L207.0,109.0 L206.3,111.4 L205.7,113.6 L205.1,115.8 L204.6,117.9 L204.1,120.0 L203.8,122.0 L203.5,124.0 L203.4,126.0 Z" fill="#94bb3b"/>
|
||||
<path d="M111.7,95.6 L171.6,128.0 L111.7,160.4 Z" fill="#2b390b" stroke="#2b390b" stroke-width="14" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.1 KiB |
BIN
assets/symbols-fill.ttf
Normal file
BIN
assets/symbols.ttf
Normal file
18
docs/DESIGN.md
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# Design notes
|
||||
|
||||
Built with the /material skill (kit modules in `src/tokens.rs`, `motion.rs`, `theme.rs`, `widgets.rs`, `wave.rs`,
|
||||
`shape.rs`).
|
||||
|
||||
- Signature moments: the wavy seek bar (waves while playing, flat when paused or when Wave is off) and the play button,
|
||||
a circle that becomes a 9-lobe cookie while the triangle folds into pause bars. Everything else is quiet surfaces.
|
||||
- Video fills the window; chrome floats on `container` surfaces (radius 28, one shadow): title pill and button pill at
|
||||
the top, the dock at the bottom (max 1040 wide, 116 high), side sheets 360 wide from the right that push the dock.
|
||||
- Controls hide after `hide_after` seconds of no pointer movement while playing; they stay while paused, while a menu,
|
||||
sheet or dialog is open, while the pointer is over them, and while seeking.
|
||||
- mpv: `vo=libmpv`, render API into our FBO (`src/mpv.rs`), properties observed and drained each frame, commands sent
|
||||
async. The user's mpv config is loaded (option), `osc=no`, `osd-bar=no`; our own OSD pill replaces the bar.
|
||||
- Keys: Quince's shortcuts first; others go to mpv as `keypress` (input.conf, console, stats). When mpv's console is
|
||||
open every key goes to it.
|
||||
- App icon: leaf-green clover with a dark play mark (OKLCH hue 125, the quince's own green-yellow). Our icons already
|
||||
sit at hues 5, 53, 100, 150, 207, 255 and 295, so no hue is 40 degrees from all of them; 125 is 25 from the nearest
|
||||
(Audiphi's mustard and Damson's green) and differs from both in lightness and shape.
|
||||
20
docs/STATUS.md
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Status
|
||||
|
||||
Version 0.1.0, first build (2026-11-26).
|
||||
|
||||
## Works (checked in hidden smoke runs, software GL)
|
||||
- Empty screen with recent files; opening files from the command line; playlist of several files.
|
||||
- Video through libmpv's render API into a GL texture drawn by egui; controls over it (top bar, dock), auto-hide.
|
||||
- Wavy seek bar with hover preview thumbnails; play button morph; volume slider; speed pill.
|
||||
- Context menu with submenus; subtitle, sound, speed and chapter menus from the dock.
|
||||
- Playlist and Adjust sheets; Settings dialog (Appearance, Playback, Languages, mpv, Keyboard, About); Open link dialog.
|
||||
- Light and dark themes; idle: no frames about a second after pausing.
|
||||
|
||||
## Not checked yet
|
||||
- Real GPU (only llvmpipe so far), hardware decoding on real hardware, Wayland drag and drop from a file manager.
|
||||
- File dialogs (portal), screensaver inhibit, colours from the video, keys passed to mpv's console.
|
||||
- Window at the minimum size (480x360), fullscreen, menus near the window edges.
|
||||
|
||||
## Missing
|
||||
- A `--gallery` page of every control in every state (the /material skill asks for one).
|
||||
- Packaging (AppImage / tar.gz) and a release.
|
||||
1011
src/app.rs
Normal file
211
src/config.rs
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
//! Settings and recent files, stored as JSON with words for choices (`~/.config/quince/settings.json`).
|
||||
|
||||
use crate::motion::Motion;
|
||||
use crate::theme::{Appearance, Contrast, Scheme};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ColourFrom {
|
||||
#[default]
|
||||
Desktop,
|
||||
Own,
|
||||
/// The film playing.
|
||||
Video,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Settings {
|
||||
pub colour_from: ColourFrom,
|
||||
pub own_colour: String,
|
||||
pub scheme: String,
|
||||
pub appearance: String,
|
||||
pub contrast: String,
|
||||
pub motion: String,
|
||||
/// Seconds before the controls hide while playing.
|
||||
pub hide_after: f32,
|
||||
pub wave: bool,
|
||||
pub resume: bool,
|
||||
pub hwdec: bool,
|
||||
pub use_mpv_conf: bool,
|
||||
pub pass_keys: bool,
|
||||
pub ytdl_quality: String,
|
||||
pub alang: String,
|
||||
pub slang: String,
|
||||
pub screenshot_dir: String,
|
||||
pub volume: f64,
|
||||
pub seek_small: f64,
|
||||
pub seek_large: f64,
|
||||
pub thumbnails: bool,
|
||||
pub remaining_time: bool,
|
||||
pub click_pauses: bool,
|
||||
pub recent: Vec<Recent>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Recent {
|
||||
pub path: String,
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub position: f64,
|
||||
#[serde(default)]
|
||||
pub duration: f64,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
fn default() -> Settings {
|
||||
let shots = dirs::picture_dir().unwrap_or_else(|| dirs::home_dir().unwrap_or_default()).join("Screenshots");
|
||||
Settings {
|
||||
colour_from: ColourFrom::Desktop,
|
||||
own_colour: "#c9a227".into(),
|
||||
scheme: "tonal".into(),
|
||||
appearance: "auto".into(),
|
||||
contrast: "standard".into(),
|
||||
motion: String::new(),
|
||||
hide_after: 2.5,
|
||||
wave: true,
|
||||
resume: true,
|
||||
hwdec: true,
|
||||
use_mpv_conf: true,
|
||||
pass_keys: true,
|
||||
ytdl_quality: "best".into(),
|
||||
alang: String::new(),
|
||||
slang: String::new(),
|
||||
screenshot_dir: shots.to_string_lossy().into_owned(),
|
||||
volume: 100.0,
|
||||
seek_small: 5.0,
|
||||
seek_large: 30.0,
|
||||
thumbnails: true,
|
||||
remaining_time: false,
|
||||
click_pauses: true,
|
||||
recent: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dir() -> PathBuf {
|
||||
dirs::config_dir().unwrap_or_else(std::env::temp_dir).join("quince")
|
||||
}
|
||||
|
||||
fn file() -> PathBuf {
|
||||
if let Some(p) = std::env::var_os("QUINCE_CONFIG") {
|
||||
return PathBuf::from(p);
|
||||
}
|
||||
dir().join("settings.json")
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn load() -> Settings {
|
||||
std::fs::read(file()).ok().and_then(|b| serde_json::from_slice(&b).ok()).unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
let f = file();
|
||||
if let Some(d) = f.parent() {
|
||||
let _ = std::fs::create_dir_all(d);
|
||||
}
|
||||
if let Ok(s) = serde_json::to_vec_pretty(self) {
|
||||
let tmp = f.with_extension("tmp");
|
||||
if std::fs::write(&tmp, s).is_ok() {
|
||||
let _ = std::fs::rename(tmp, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scheme(&self) -> Scheme {
|
||||
match self.scheme.as_str() {
|
||||
"vibrant" => Scheme::Vibrant,
|
||||
"expressive" => Scheme::Expressive,
|
||||
"mono" => Scheme::Mono,
|
||||
_ => Scheme::Tonal,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn appearance(&self) -> Appearance {
|
||||
match self.appearance.as_str() {
|
||||
"light" => Appearance::Light,
|
||||
"dark" => Appearance::Dark,
|
||||
"amoled" => Appearance::Amoled,
|
||||
_ => Appearance::Auto,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contrast(&self) -> Contrast {
|
||||
match self.contrast.as_str() {
|
||||
"medium" => Contrast::Medium,
|
||||
"high" => Contrast::High,
|
||||
_ => Contrast::Standard,
|
||||
}
|
||||
}
|
||||
|
||||
/// Unset means: Reduced when the desktop asks for less motion, else Normal.
|
||||
pub fn motion(&self) -> Motion {
|
||||
match self.motion.as_str() {
|
||||
"off" => Motion::Off,
|
||||
"reduced" => Motion::Reduced,
|
||||
"normal" => Motion::Normal,
|
||||
"lively" => Motion::Expressive,
|
||||
_ => {
|
||||
if desktop_wants_less_motion() {
|
||||
Motion::Reduced
|
||||
} else {
|
||||
Motion::Normal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ytdl_format(&self) -> String {
|
||||
match self.ytdl_quality.as_str() {
|
||||
"2160" | "1440" | "1080" | "720" | "480" => {
|
||||
format!("bestvideo[height<=?{0}]+bestaudio/best[height<=?{0}]", self.ytdl_quality)
|
||||
}
|
||||
"audio" => "bestaudio/best".into(),
|
||||
_ => String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Puts a file at the top of the recent list, keeping 20.
|
||||
pub fn remember(&mut self, path: &str, title: &str, position: f64, duration: f64) {
|
||||
if path.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.recent.retain(|r| r.path != path);
|
||||
self.recent.insert(0, Recent { path: path.into(), title: title.into(), position, duration });
|
||||
self.recent.truncate(20);
|
||||
}
|
||||
}
|
||||
|
||||
pub const SCHEMES: [&str; 4] = ["tonal", "vibrant", "expressive", "mono"];
|
||||
pub const APPEARANCES: [&str; 4] = ["auto", "light", "dark", "amoled"];
|
||||
pub const CONTRASTS: [&str; 3] = ["standard", "medium", "high"];
|
||||
pub const MOTIONS: [&str; 4] = ["off", "reduced", "normal", "lively"];
|
||||
pub const QUALITIES: [(&str, &str); 6] =
|
||||
[("best", "Best"), ("2160", "4K"), ("1080", "1080p"), ("720", "720p"), ("480", "480p"), ("audio", "Sound only")];
|
||||
|
||||
fn desktop_wants_less_motion() -> bool {
|
||||
static ASKED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ASKED.get_or_init(ask_desktop_motion)
|
||||
}
|
||||
|
||||
fn ask_desktop_motion() -> bool {
|
||||
let kde = dirs::config_dir().unwrap_or_default().join("kdeglobals");
|
||||
if let Ok(t) = std::fs::read_to_string(kde) {
|
||||
for l in t.lines() {
|
||||
if let Some(v) = l.trim().strip_prefix("AnimationDurationFactor=") {
|
||||
return v.trim().parse::<f32>().map(|f| f == 0.0).unwrap_or(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// GNOME only; elsewhere gsettings may wait on a bus that isn't there
|
||||
if !std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default().to_lowercase().contains("gnome") {
|
||||
return false;
|
||||
}
|
||||
std::process::Command::new("timeout")
|
||||
.args(["1", "gsettings", "get", "org.gnome.desktop.interface", "enable-animations"])
|
||||
.output()
|
||||
.map(|o| String::from_utf8_lossy(&o.stdout).trim() == "false")
|
||||
.unwrap_or(false)
|
||||
}
|
||||