Pi66

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

← back to log

remove clone methods

author: pixel2175
date: 2025-06-10 01:26
hash: 8b4523189cf480f9cb191f1e63708e4abfb77546

Diffstat:

M

src/get_colors.rs
27 +++++++++++++++++-------------

M

src/wallpaper.rs
7 +++-----
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
diff --git a/src/get_colors.rs b/src/get_colors.rs
index c54b2b9..9d6a5ae 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -32,7 +32,7 @@ fn to_gray(r: u8, g: u8, b: u8, v: u8) -> (u8, u8, u8) {
     (gray, gray, gray)
 }

-fn kmeans_colors(len: u8, native_rgba: RgbaImage) -> Vec<(u8, u8, u8)> {
+fn kmeans_colors(len: u8, native_rgba: &RgbaImage) -> Vec<(u8, u8, u8)> {
     let pixels_kmeans: Vec<Lab> = native_rgba
         .pixels()
         .filter(|p| p.0[3] > 0) // Filter out transparent pixels
@@ -68,7 +68,7 @@ fn kmeans_colors(len: u8, native_rgba: RgbaImage) -> Vec<(u8, u8, u8)> {
         .collect::<Vec<(u8, u8, u8)>>()
 }

-fn color_thief_colors(len: u8, native_rgba: RgbaImage) -> Vec<(u8, u8, u8)> {
+fn color_thief_colors(len: u8, native_rgba: &RgbaImage) -> Vec<(u8, u8, u8)> {
     let palette_extract = palette_extract::get_palette_with_options(
         &native_rgba,
         palette_extract::PixelEncoding::Rgba,
@@ -83,7 +83,7 @@ fn color_thief_colors(len: u8, native_rgba: RgbaImage) -> Vec<(u8, u8, u8)> {
         .collect::<Vec<(u8, u8, u8)>>()
 }

-fn palette_extract_colors(len: u8, native_rgba: RgbaImage, send: bool) -> Vec<(u8, u8, u8)> {
+fn palette_extract_colors(len: u8, native_rgba: &RgbaImage, send: bool) -> Vec<(u8, u8, u8)> {
     let palette_thief = color_thief::get_palette(&native_rgba, ColorFormat::Rgba, 5, len)
         .unwrap_or_else(|_| {
             warning("Backend", "palette thief can't extract the palette", send);
@@ -96,7 +96,12 @@ fn palette_extract_colors(len: u8, native_rgba: RgbaImage, send: bool) -> Vec<(u
         .collect::<Vec<(u8, u8, u8)>>()
 }

-fn extract_colors(len: u8, backend: &str, native_rgba: RgbaImage, send: bool) -> Vec<(u8, u8, u8)> {
+fn extract_colors(
+    len: u8,
+    backend: &str,
+    native_rgba: &RgbaImage,
+    send: bool,
+) -> Vec<(u8, u8, u8)> {
     match backend {
         "backends" => {
             println!(
@@ -116,12 +121,10 @@ fn extract_colors(len: u8, backend: &str, native_rgba: RgbaImage, send: bool) ->
         "palette_extract" => palette_extract_colors(10, native_rgba, send),
         "all" => {
             let mut collected: Vec<(u8, u8, u8)> = Vec::new();
-            kmeans_colors(len, native_rgba.clone())
-                .iter()
-                .for_each(|c| {
-                    collected.push(*c);
-                });
-            color_thief_colors(len / 3_u8, native_rgba.clone())
+            kmeans_colors(len, native_rgba).iter().for_each(|c| {
+                collected.push(*c);
+            });
+            color_thief_colors(len / 3_u8, native_rgba)
                 .iter()
                 .for_each(|c| {
                     collected.push(*c);
@@ -169,11 +172,11 @@ pub fn get_colors(

     let native_rgba = image.to_rgba8();
     let alpha = &native_rgba.get_pixel(0, 0)[3];
-    let mut collect_rgb: Vec<(u8, u8, u8)> = extract_colors(30, backend, native_rgba.clone(), send);
+    let mut collect_rgb: Vec<(u8, u8, u8)> = extract_colors(30, backend, &native_rgba, send);

     collect_rgb = remove_duplicates(collect_rgb);
     while collect_rgb.len() <= 21 {
-        collect_rgb.push(extract_colors(1, backend, native_rgba.clone(), send)[0]);
+        collect_rgb.push(extract_colors(1, backend, &native_rgba, send)[0]);
     }

     collect_rgb.sort_by(|a, b| {
diff --git a/src/wallpaper.rs b/src/wallpaper.rs
index 12c3fd2..f0002c9 100644
--- a/src/wallpaper.rs
+++ b/src/wallpaper.rs
@@ -116,9 +116,8 @@ fn set_wm_wallpaper(img: &str, send: bool) {
     }
 }

-fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
-    let d = desktop.to_lowercase();
-    let abs_path = get_absolute_path(&d).unwrap_or_else(|| {
+fn set_desktop_wallpaper(d: &str, img: &str, send: bool) {
+    let abs_path = get_absolute_path(img).unwrap_or_else(|| {
         warning("Wallpaper", "failed to get absolute path", send);
         img.to_string()
     });
@@ -380,7 +379,7 @@ pub fn change_wallpaper(img: &str, send: bool) {
                     send,
                 );
             }
-            set_desktop_wallpaper(&d, img, send);
+            set_desktop_wallpaper(&d.to_lowercase(), img, send);
         }
         None => {
             if send {