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
|
|
@ -37,7 +37,7 @@ pub fn users_from_uids(uids: &[u32], passwd: &str) -> Vec<UnixUser> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prefer the process's own uid when it is in `users`, otherwise the first.
|
/// Prefer the process's own uid when it is in `users`, otherwise the first.
|
||||||
pub fn pick_user<'a>(users: &'a [UnixUser], current_uid: Option<u32>) -> Option<&'a UnixUser> {
|
pub fn pick_user(users: &[UnixUser], current_uid: Option<u32>) -> Option<&UnixUser> {
|
||||||
if let Some(uid) = current_uid {
|
if let Some(uid) = current_uid {
|
||||||
if let Some(user) = users.iter().find(|u| u.uid == uid) {
|
if let Some(user) = users.iter().find(|u| u.uid == uid) {
|
||||||
return Some(user);
|
return Some(user);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,10 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use crate::Palette;
|
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)
|
/// Above APPLICATION (600) so we beat [`apply_shared`], below USER (800)
|
||||||
/// so `apply_user_css` still wins.
|
/// so `apply_user_css` still wins.
|
||||||
const BIND_PRIORITY: u32 = gtk4::STYLE_PROVIDER_PRIORITY_USER - 10;
|
const BIND_PRIORITY: u32 = gtk4::STYLE_PROVIDER_PRIORITY_USER - 10;
|
||||||
|
|
@ -162,7 +166,7 @@ struct WidgetBind {
|
||||||
output: String,
|
output: String,
|
||||||
theme: CssProvider,
|
theme: CssProvider,
|
||||||
app: Option<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.
|
/// Keep the directory monitor + child model alive for this widget.
|
||||||
_watch: Option<gio::ListModel>,
|
_watch: Option<gio::ListModel>,
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +288,7 @@ fn watch_root_children(widget: >k4::Widget) -> gio::ListModel {
|
||||||
fn bind_window_inner(
|
fn bind_window_inner(
|
||||||
widget: >k4::Widget,
|
widget: >k4::Widget,
|
||||||
output: &str,
|
output: &str,
|
||||||
app_build: Option<Rc<dyn Fn(&Palette) -> String>>,
|
app_build: Option<AppCssBuilder>,
|
||||||
) {
|
) {
|
||||||
let key = widget_key(widget);
|
let key = widget_key(widget);
|
||||||
let palette = crate::load_palette_for(output);
|
let palette = crate::load_palette_for(output);
|
||||||
|
|
@ -387,7 +391,7 @@ where
|
||||||
bind_window_inner(widget.as_ref(), output, Some(Rc::new(build)));
|
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 {
|
let Some(native) = widget.native() else {
|
||||||
return;
|
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 widget = native.upcast_ref::<gtk4::Widget>().clone();
|
||||||
|
|
||||||
let apply = {
|
let apply = {
|
||||||
|
|
|
||||||
|
|
@ -330,7 +330,8 @@ pub fn stylesheet_resolved(p: &Palette) -> String {
|
||||||
/// named colors cannot leak the wrong monitor's accent.
|
/// named colors cannot leak the wrong monitor's accent.
|
||||||
pub(crate) fn resolve_color_names(css: &str, p: &Palette) -> String {
|
pub(crate) fn resolve_color_names(css: &str, p: &Palette) -> String {
|
||||||
let mut pairs: Vec<(&str, String)> = color_pairs(p).into_iter().collect();
|
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();
|
let mut out = css.to_string();
|
||||||
for (name, value) in pairs {
|
for (name, value) in pairs {
|
||||||
out = out.replace(&format!("@{name}"), &value);
|
out = out.replace(&format!("@{name}"), &value);
|
||||||
|
|
@ -544,8 +545,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stylesheet_resolved_inlines_color4_and_drops_named_refs_in_rules() {
|
fn stylesheet_resolved_inlines_color4_and_drops_named_refs_in_rules() {
|
||||||
let mut p = Palette::default();
|
let p = Palette {
|
||||||
p.color4 = "#7aa2f7".into();
|
color4: "#7aa2f7".into(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
let css = stylesheet_resolved(&p);
|
let css = stylesheet_resolved(&p);
|
||||||
assert!(css.contains("#7aa2f7"), "color4 must appear as hex: {css}");
|
assert!(css.contains("#7aa2f7"), "color4 must appear as hex: {css}");
|
||||||
// Rule bodies must not keep named colors — GTK display-global
|
// 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,
|
Ok(s) => s,
|
||||||
};
|
};
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
return Err(std::io::Error::new(
|
return Err(std::io::Error::other(format!("wal failed with {status}")));
|
||||||
std::io::ErrorKind::Other,
|
|
||||||
format!("wal failed with {status}"),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let json_path = [
|
let json_path = [
|
||||||
|
|
@ -299,9 +296,11 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn write_output_palette_roundtrips_color4() {
|
fn write_output_palette_roundtrips_color4() {
|
||||||
with_runtime_dir(|_| {
|
with_runtime_dir(|_| {
|
||||||
let mut p = Palette::default();
|
let p = Palette {
|
||||||
p.color4 = "#7aa2f7".into();
|
color4: "#7aa2f7".into(),
|
||||||
p.background = "#ffffff".into();
|
background: "#ffffff".into(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
write_output_palette("HDMI-A-1", &p).unwrap();
|
write_output_palette("HDMI-A-1", &p).unwrap();
|
||||||
let loaded = load_palette_for("HDMI-A-1");
|
let loaded = load_palette_for("HDMI-A-1");
|
||||||
assert_eq!(loaded.color4, "#7aa2f7");
|
assert_eq!(loaded.color4, "#7aa2f7");
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,9 @@ pub fn try_acquire(app: &str) -> std::io::Result<Acquire> {
|
||||||
.read(true)
|
.read(true)
|
||||||
.write(true)
|
.write(true)
|
||||||
.create(true)
|
.create(true)
|
||||||
|
// Never truncate on open: an existing lock file may be held by a live
|
||||||
|
// instance. We only clear it (`set_len(0)`) *after* winning the lock.
|
||||||
|
.truncate(false)
|
||||||
.open(&path)?;
|
.open(&path)?;
|
||||||
|
|
||||||
match file.try_lock() {
|
match file.try_lock() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue