Clear clippy 1.97 lints across bread-theme, bread-utils, bread-polkit
Toolchain drift (clippy 0.1.97): pre-existing on main, all mechanical and behaviour-preserving. - bread-theme/gtk.rs: `type AppCssBuilder` alias for the repeated `Rc<dyn Fn(&Palette) -> String>` (type_complexity ×4). - bread-theme/lib.rs: `sort_by_key(|..| Reverse(len))` (unnecessary_sort_by). - bread-theme/output.rs: `io::Error::other`; struct-init in a test. - bread-utils/singleton.rs: explicit `.truncate(false)` on the lock file open — we only clear it after winning the lock (suspicious_open_options). - bread-polkit/identity.rs: elide `pick_user` lifetimes.
This commit is contained in:
parent
6d9912af56
commit
a86c31291b
5 changed files with 24 additions and 15 deletions
|
|
@ -10,6 +10,10 @@ use std::rc::Rc;
|
|||
|
||||
use crate::Palette;
|
||||
|
||||
/// Per-widget app-CSS builder: given the resolved palette for the widget's
|
||||
/// monitor, produce the app stylesheet to layer on top of the theme CSS.
|
||||
type AppCssBuilder = Rc<dyn Fn(&Palette) -> String>;
|
||||
|
||||
/// Above APPLICATION (600) so we beat [`apply_shared`], below USER (800)
|
||||
/// so `apply_user_css` still wins.
|
||||
const BIND_PRIORITY: u32 = gtk4::STYLE_PROVIDER_PRIORITY_USER - 10;
|
||||
|
|
@ -162,7 +166,7 @@ struct WidgetBind {
|
|||
output: String,
|
||||
theme: CssProvider,
|
||||
app: Option<CssProvider>,
|
||||
app_build: Option<Rc<dyn Fn(&Palette) -> String>>,
|
||||
app_build: Option<AppCssBuilder>,
|
||||
/// Keep the directory monitor + child model alive for this widget.
|
||||
_watch: Option<gio::ListModel>,
|
||||
}
|
||||
|
|
@ -284,7 +288,7 @@ fn watch_root_children(widget: >k4::Widget) -> gio::ListModel {
|
|||
fn bind_window_inner(
|
||||
widget: >k4::Widget,
|
||||
output: &str,
|
||||
app_build: Option<Rc<dyn Fn(&Palette) -> String>>,
|
||||
app_build: Option<AppCssBuilder>,
|
||||
) {
|
||||
let key = widget_key(widget);
|
||||
let palette = crate::load_palette_for(output);
|
||||
|
|
@ -387,7 +391,7 @@ where
|
|||
bind_window_inner(widget.as_ref(), output, Some(Rc::new(build)));
|
||||
}
|
||||
|
||||
fn attach_enter_monitor(widget: >k4::Widget, build: Option<Rc<dyn Fn(&Palette) -> String>>) {
|
||||
fn attach_enter_monitor(widget: >k4::Widget, build: Option<AppCssBuilder>) {
|
||||
let Some(native) = widget.native() else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -408,7 +412,7 @@ fn attach_enter_monitor(widget: >k4::Widget, build: Option<Rc<dyn Fn(&Palette)
|
|||
});
|
||||
}
|
||||
|
||||
fn bind_auto(native: >k4::Native, build: Option<Rc<dyn Fn(&Palette) -> String>>) {
|
||||
fn bind_auto(native: >k4::Native, build: Option<AppCssBuilder>) {
|
||||
let widget = native.upcast_ref::<gtk4::Widget>().clone();
|
||||
|
||||
let apply = {
|
||||
|
|
|
|||
|
|
@ -330,7 +330,8 @@ pub fn stylesheet_resolved(p: &Palette) -> String {
|
|||
/// named colors cannot leak the wrong monitor's accent.
|
||||
pub(crate) fn resolve_color_names(css: &str, p: &Palette) -> String {
|
||||
let mut pairs: Vec<(&str, String)> = color_pairs(p).into_iter().collect();
|
||||
pairs.sort_by(|a, b| b.0.len().cmp(&a.0.len()));
|
||||
// Longest name first, so `@on-bg` is replaced before `@bg` can match its tail.
|
||||
pairs.sort_by_key(|(name, _)| std::cmp::Reverse(name.len()));
|
||||
let mut out = css.to_string();
|
||||
for (name, value) in pairs {
|
||||
out = out.replace(&format!("@{name}"), &value);
|
||||
|
|
@ -544,8 +545,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn stylesheet_resolved_inlines_color4_and_drops_named_refs_in_rules() {
|
||||
let mut p = Palette::default();
|
||||
p.color4 = "#7aa2f7".into();
|
||||
let p = Palette {
|
||||
color4: "#7aa2f7".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let css = stylesheet_resolved(&p);
|
||||
assert!(css.contains("#7aa2f7"), "color4 must appear as hex: {css}");
|
||||
// Rule bodies must not keep named colors — GTK display-global
|
||||
|
|
|
|||
|
|
@ -185,10 +185,7 @@ pub fn palette_from_image(path: &Path) -> std::io::Result<Palette> {
|
|||
Ok(s) => s,
|
||||
};
|
||||
if !status.success() {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
format!("wal failed with {status}"),
|
||||
));
|
||||
return Err(std::io::Error::other(format!("wal failed with {status}")));
|
||||
}
|
||||
|
||||
let json_path = [
|
||||
|
|
@ -299,9 +296,11 @@ mod tests {
|
|||
#[test]
|
||||
fn write_output_palette_roundtrips_color4() {
|
||||
with_runtime_dir(|_| {
|
||||
let mut p = Palette::default();
|
||||
p.color4 = "#7aa2f7".into();
|
||||
p.background = "#ffffff".into();
|
||||
let p = Palette {
|
||||
color4: "#7aa2f7".into(),
|
||||
background: "#ffffff".into(),
|
||||
..Default::default()
|
||||
};
|
||||
write_output_palette("HDMI-A-1", &p).unwrap();
|
||||
let loaded = load_palette_for("HDMI-A-1");
|
||||
assert_eq!(loaded.color4, "#7aa2f7");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue