From 6d039eb4c3d1a1238b5605b440087123fd9efd76 Mon Sep 17 00:00:00 2001 From: Joshua Megnauth <48846352+joshuamegnauth54@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:12:57 +0000 Subject: [PATCH] fix(wallpaper): duplicate color wallpaper previews The issue arises after the wallpaper settings page is opened after choosing a default color as a background. The chosen color is treated as a custom color on reload which is then duplicated when the default colors are displayed. Solving this issue is as simple as filtering the customs colors list for default colors. I unwrap two `Options` from `partial_cmp` in this fix. Floats don't implement `Eq` due to `NaN`s but they do implement `PartialOrd` and `PartialEq`. Colors shouldn't have `NaN`s at all, so unwrapping here is fine as that invariant should hold unless there is a bug elsewhere. --- Cargo.lock | 26 +++++++++---------- .../src/pages/desktop/wallpaper/widgets.rs | 19 +++++++++++++- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 363f49a..be33ec3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,12 +21,12 @@ checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" [[package]] name = "accesskit" version = "0.12.2" -source = "git+https://github.com/wash2/accesskit.git?branch=winit-0.29#5f9b61c8264000d001499c902562422e13efa7a8" +source = "git+https://github.com/wash2/accesskit.git?branch=winit-0.29#26f729169cd849970af02be62289606c63572d2d" [[package]] name = "accesskit_consumer" version = "0.17.0" -source = "git+https://github.com/wash2/accesskit.git?branch=winit-0.29#5f9b61c8264000d001499c902562422e13efa7a8" +source = "git+https://github.com/wash2/accesskit.git?branch=winit-0.29#26f729169cd849970af02be62289606c63572d2d" dependencies = [ "accesskit", ] @@ -34,7 +34,7 @@ dependencies = [ [[package]] name = "accesskit_unix" version = "0.7.1" -source = "git+https://github.com/wash2/accesskit.git?branch=winit-0.29#5f9b61c8264000d001499c902562422e13efa7a8" +source = "git+https://github.com/wash2/accesskit.git?branch=winit-0.29#26f729169cd849970af02be62289606c63572d2d" dependencies = [ "accesskit", "accesskit_consumer", @@ -1329,7 +1329,7 @@ dependencies = [ [[package]] name = "cosmic-bg-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-bg#2259f5ac81099a8215d5ff69cba1ec0d1fd850d1" +source = "git+https://github.com/pop-os/cosmic-bg#f83d9f4c8e4b47bea3ef16e4894982919fef6b9a" dependencies = [ "colorgrad", "cosmic-config", @@ -1364,7 +1364,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#5c6fa840f4e75ce94075cb1c8d22623077821193" +source = "git+https://github.com/pop-os/libcosmic#41d1f4a7cdafd0bf15d7a8213697932a2dc6e8ba" dependencies = [ "atomicwrites", "calloop 0.14.0", @@ -1387,7 +1387,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#5c6fa840f4e75ce94075cb1c8d22623077821193" +source = "git+https://github.com/pop-os/libcosmic#41d1f4a7cdafd0bf15d7a8213697932a2dc6e8ba" dependencies = [ "quote", "syn 1.0.109", @@ -1723,7 +1723,7 @@ version = "0.19.0" source = "git+https://github.com/gfx-rs/wgpu?rev=20fda69#20fda698341efbdc870b8027d6d49f5bf3f36109" dependencies = [ "bitflags 2.5.0", - "libloading 0.8.3", + "libloading 0.7.4", "winapi", ] @@ -1898,7 +1898,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" dependencies = [ - "libloading 0.8.3", + "libloading 0.7.4", ] [[package]] @@ -2747,7 +2747,7 @@ dependencies = [ "bitflags 2.5.0", "com", "libc", - "libloading 0.8.3", + "libloading 0.7.4", "thiserror", "widestring", "winapi", @@ -2918,7 +2918,7 @@ dependencies = [ [[package]] name = "iced_accessibility" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic#5c6fa840f4e75ce94075cb1c8d22623077821193" +source = "git+https://github.com/pop-os/libcosmic#41d1f4a7cdafd0bf15d7a8213697932a2dc6e8ba" dependencies = [ "accesskit", "accesskit_unix", @@ -2927,7 +2927,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#5c6fa840f4e75ce94075cb1c8d22623077821193" +source = "git+https://github.com/pop-os/libcosmic#41d1f4a7cdafd0bf15d7a8213697932a2dc6e8ba" dependencies = [ "bitflags 2.5.0", "dnd", @@ -2949,7 +2949,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.12.0" -source = "git+https://github.com/pop-os/libcosmic#5c6fa840f4e75ce94075cb1c8d22623077821193" +source = "git+https://github.com/pop-os/libcosmic#41d1f4a7cdafd0bf15d7a8213697932a2dc6e8ba" dependencies = [ "futures", "iced_core", @@ -6911,7 +6911,7 @@ dependencies = [ "js-sys", "khronos-egl", "libc", - "libloading 0.8.3", + "libloading 0.7.4", "log", "metal", "naga", diff --git a/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs b/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs index 09d1f9c..3a621cb 100644 --- a/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs +++ b/cosmic-settings/src/pages/desktop/wallpaper/widgets.rs @@ -11,6 +11,7 @@ use cosmic::widget::{button, container, space}; use cosmic::{iced, Element}; use cosmic_settings_wallpaper as wallpaper; use slotmap::DefaultKey; +use std::sync::OnceLock; const COLOR_WIDTH: u16 = 70; const COLUMN_SPACING: u16 = 12; @@ -93,12 +94,28 @@ pub fn color_select_options( context: &super::Context, selected: Option<&wallpaper::Color>, ) -> Element<'static, Message> { + static SORTED: OnceLock> = OnceLock::new(); + let sorted = &**SORTED.get_or_init(|| { + let mut sorted = wallpaper::DEFAULT_COLORS.to_vec(); + sorted.sort_by(|a, b| a.partial_cmp(b).expect("Neither slices should have NaNs")); + sorted + }); + flex_select_row( context .custom_colors .iter() .rev() - .map(|color| (color, true)) + .filter_map(|color| { + sorted + .binary_search_by(|probe| { + probe + .partial_cmp(color) + .expect("Neither slices should have NaNs") + }) + .is_err() + .then_some((color, true)) + }) .chain(wallpaper::DEFAULT_COLORS.iter().map(|color| (color, false))) .map(|(color, removable)| { color_button(