wallswitch 0.60.8

randomly selects wallpapers for multiple monitors
Documentation
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};

const RESET: &str = "\x1b[0m";
const BOLD: &str = "\x1b[1m";
const DIM: &str = "\x1b[2m";
const BLACK: &str = "\x1b[30m";
const RED: &str = "\x1b[31m";
const GREEN: &str = "\x1b[32m";
const YELLOW: &str = "\x1b[33m";
const BLUE: &str = "\x1b[34m";
const MAGENTA: &str = "\x1b[35m";
const CYAN: &str = "\x1b[36m";
const WHITE: &str = "\x1b[37m";

pub const CURSOR_TO_START: &str = "\r";
pub const ERASE_LINE_TO_END: &str = "\x1b[K";

pub trait Colors {
    fn bold(&self) -> String;
    fn dimmed(&self) -> String;
    fn black(&self) -> String;
    fn red(&self) -> String;
    fn green(&self) -> String;
    fn yellow(&self) -> String;
    fn blue(&self) -> String;
    fn magenta(&self) -> String;
    fn cyan(&self) -> String;
    fn white(&self) -> String;
    fn to_line_start(&self) -> String;
}

impl<T> Colors for T
where
    T: Display,
{
    fn bold(&self) -> String {
        format!("{BOLD}{self}{RESET}")
    }
    fn dimmed(&self) -> String {
        format!("{DIM}{self}{RESET}")
    }
    fn black(&self) -> String {
        format!("{BLACK}{self}{RESET}")
    }
    fn red(&self) -> String {
        format!("{RED}{self}{RESET}")
    }
    fn green(&self) -> String {
        format!("{GREEN}{self}{RESET}")
    }
    fn yellow(&self) -> String {
        format!("{YELLOW}{self}{RESET}")
    }
    fn blue(&self) -> String {
        format!("{BLUE}{self}{RESET}")
    }
    fn magenta(&self) -> String {
        format!("{MAGENTA}{self}{RESET}")
    }
    fn cyan(&self) -> String {
        format!("{CYAN}{self}{RESET}")
    }
    fn white(&self) -> String {
        format!("{WHITE}{self}{RESET}")
    }
    fn to_line_start(&self) -> String {
        format!("{CURSOR_TO_START}{self}{ERASE_LINE_TO_END}")
    }
}

// ==============================================================================
// GRAPHICS AND IMAGE RENDERING COLOR MODELS
// ==============================================================================

/// Zero-cost, stack-allocated raw float-based RGB color vector.
/// Designed for high-performance pixel-level shader computations.
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
pub struct ColorRGB {
    /// Red channel value in the range [0.0, 1.0].
    pub red: f32,
    /// Green channel value in the range [0.0, 1.0].
    pub green: f32,
    /// Blue channel value in the range [0.0, 1.0].
    pub blue: f32,
}

impl ColorRGB {
    /// Creates a new ColorRGB vector.
    #[inline(always)]
    pub fn new(red: f32, green: f32, blue: f32) -> Self {
        Self { red, green, blue }
    }

    /// Creates a `ColorRGB` by reading 3 bytes from a slice, normalizing values to the range `[0.0, 1.0]`.
    ///
    /// # Arguments
    ///
    /// * `slice` - A slice containing at least 3 bytes representing Red, Green, and Blue channels respectively.
    ///
    /// # Panics
    ///
    /// This method will panic if the slice has fewer than 3 elements.
    #[inline(always)]
    pub fn from_slice(slice: &[u8]) -> Self {
        Self {
            red: slice[0] as f32 / 255.0,
            green: slice[1] as f32 / 255.0,
            blue: slice[2] as f32 / 255.0,
        }
    }

    /// Converts the internal normalized float channels back to the byte range `[0..255]`
    /// and writes them to a mutable 3-byte slice.
    ///
    /// # Arguments
    ///
    /// * `slice` - A mutable slice with at least 3 elements to write the Red, Green, and Blue bytes to.
    ///
    /// # Panics
    ///
    /// This method will panic if the slice has fewer than 3 elements.
    #[inline(always)]
    pub fn write_to_slice(&self, slice: &mut [u8]) {
        slice[0] = (self.red * 255.0).clamp(0.0, 255.0) as u8;
        slice[1] = (self.green * 255.0).clamp(0.0, 255.0) as u8;
        slice[2] = (self.blue * 255.0).clamp(0.0, 255.0) as u8;
    }

    /// Performs linearly interpolated (LERP) blending with another ColorRGB.
    #[inline(always)]
    pub fn lerp(&self, other: &Self, t: f32) -> Self {
        let t_clamp = t.clamp(0.0, 1.0);
        Self {
            red: self.red * t_clamp + other.red * (1.0 - t_clamp),
            green: self.green * t_clamp + other.green * (1.0 - t_clamp),
            blue: self.blue * t_clamp + other.blue * (1.0 - t_clamp),
        }
    }

    /// Shifts RGB channels cyclically to produce a highly compatible secondary color.
    #[inline(always)]
    pub fn rotated(&self) -> Self {
        Self {
            red: self.green,
            green: self.blue,
            blue: self.red,
        }
    }

    /// Converts the struct's color channels into a raw float array [red, green, blue].
    #[inline(always)]
    pub const fn to_array(&self) -> [f32; 3] {
        [self.red, self.green, self.blue]
    }

    /// Returns the complementary (inverse) color of the current vector.
    #[inline(always)]
    pub fn complementary(&self) -> Self {
        Self {
            red: 1.0 - self.red,
            green: 1.0 - self.green,
            blue: 1.0 - self.blue,
        }
    }

    /// Returns the maximum component value among the Red, Green, and Blue channels.
    #[inline(always)]
    pub fn max_component(&self) -> f32 {
        self.red.max(self.green).max(self.blue)
    }

    /// Normalizes (saturates) the color components by dividing each channel by the maximum channel value,
    /// boosting visual intensity to its absolute physical peak (maximum component becomes exactly 1.0).
    #[inline(always)]
    pub fn saturate_components(&self) -> Self {
        let max = self.max_component();
        if max > 0.0 {
            Self {
                red: self.red / max,
                green: self.green / max,
                blue: self.blue / max,
            }
        } else {
            *self
        }
    }

    /// Scales all color channels by a single floating-point factor (e.g. brightness or lighting).
    #[inline(always)]
    pub fn scale(&self, factor: f32) -> Self {
        Self {
            red: self.red * factor,
            green: self.green * factor,
            blue: self.blue * factor,
        }
    }

    /// Clamps all color channels to the standard physical range [0.0, 1.0].
    #[inline(always)]
    pub fn clamp_bounds(&self) -> Self {
        Self {
            red: self.red.clamp(0.0, 1.0),
            green: self.green.clamp(0.0, 1.0),
            blue: self.blue.clamp(0.0, 1.0),
        }
    }

    /// Computes the component-wise square of the color components.
    #[inline(always)]
    pub fn squared(&self) -> Self {
        Self {
            red: self.red * self.red,
            green: self.green * self.green,
            blue: self.blue * self.blue,
        }
    }

    /// Computes the component-wise square root of the color components.
    #[inline(always)]
    pub fn sqrt(&self) -> Self {
        Self {
            red: self.red.sqrt(),
            green: self.green.sqrt(),
            blue: self.blue.sqrt(),
        }
    }
}

/// Represents a named neon color palette with float-based RGB channels.
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub struct NeonColor {
    /// The raw mathematical RGB channels.
    pub color_rgb: ColorRGB,
    /// Descriptive name of the color palette.
    pub name: &'static str,
}

impl NeonColor {
    /// Delegate: Shifts RGB channels cyclically.
    #[inline(always)]
    pub fn rotated(&self) -> ColorRGB {
        self.color_rgb.rotated()
    }

    /// Delegate: Linearly interpolates (LERP) blending with another NeonColor.
    #[inline(always)]
    pub fn lerp(&self, other: &Self, t: f32) -> ColorRGB {
        self.color_rgb.lerp(&other.color_rgb, t)
    }

    /// Delegate: Converts the struct's color channels into a raw float array [red, green, blue].
    #[inline(always)]
    pub const fn to_array(&self) -> [f32; 3] {
        self.color_rgb.to_array()
    }
}

impl fmt::Display for NeonColor {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "RGB [{:.2}, {:.2}, {:.2}] {}",
            self.color_rgb.red, self.color_rgb.green, self.color_rgb.blue, self.name
        )
    }
}

pub const NEON_PALETTES: [NeonColor; 20] = [
    NeonColor {
        color_rgb: ColorRGB {
            red: 1.0,
            green: 0.05,
            blue: 0.55,
        },
        name: "Neon Rose - Punchy Pink",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.0,
            green: 0.95,
            blue: 0.85,
        },
        name: "Vivid Turquoise - Electric Teal",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.95,
            green: 0.45,
            blue: 0.0,
        },
        name: "Tangerine Dream - Electric Orange",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.4,
            green: 0.9,
            blue: 0.0,
        },
        name: "Radioactive Lime - Acid Green",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.9,
            green: 0.9,
            blue: 0.0,
        },
        name: "Laser Lemon - Bright Yellow",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.05,
            green: 0.8,
            blue: 1.0,
        },
        name: "Blue Bolt - Intense Sky Cyan",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.85,
            green: 0.15,
            blue: 1.0,
        },
        name: "Radiant Orchid - Electric Violet",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 1.0,
            green: 0.35,
            blue: 0.1,
        },
        name: "Fiery Coral - Sunset Flame",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.1,
            green: 0.95,
            blue: 0.4,
        },
        name: "Mint Spark - Spring Neon Green",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 1.0,
            green: 0.0,
            blue: 0.35,
        },
        name: "Cherry Flare - Electric Ruby",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.75,
            green: 0.95,
            blue: 0.0,
        },
        name: "Vibrant Chartreuse - Pear Glow",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.0,
            green: 1.0,
            blue: 0.7,
        },
        name: "Aqua Glow - Supercharged seafoam",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 1.0,
            green: 0.55,
            blue: 0.4,
        },
        name: "Warm Apricot - Peach Spark",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.9,
            green: 0.2,
            blue: 0.9,
        },
        name: "Cyberpunk Fuchsia - Hot Magenta",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.35,
            green: 1.0,
            blue: 0.5,
        },
        name: "Bright Emerald - Neon Clover",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 1.0,
            green: 0.85,
            blue: 0.0,
        },
        name: "Solar Flare - Amber Gold",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.55,
            green: 0.35,
            blue: 1.0,
        },
        name: "Electric Amethyst - Bright Violet",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 1.0,
            green: 0.25,
            blue: 0.5,
        },
        name: "Flamingo Neon - Warm Pink",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.2,
            green: 0.9,
            blue: 0.9,
        },
        name: "Glacier Cyan - Ice Blue Glow",
    },
    NeonColor {
        color_rgb: ColorRGB {
            red: 0.85,
            green: 1.0,
            blue: 0.2,
        },
        name: "Radioactive Melon - Lemon Lime Flare",
    },
];