cloud storage client
git clone https://git.lucas.co/cce-cloud.git
Remove color picker mode from clear-cloud
src/main.rs | 809 ++----------------------------------------------------------
1 file changed, 21 insertions(+), 788 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index b911d19..983e473 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -402,624 +402,7 @@ fn spawn_command(cmd: &str) {
}
}
-fn gradient_quad_vertices(x: f32, y: f32, w: f32, h: f32, sw: f32, sh: f32, c0: [f32; 4], c1: [f32; 4]) -> [Vertex; 6] {
- let x0 = (x / sw) * 2.0 - 1.0;
- let y0 = 1.0 - (y / sh) * 2.0;
- let x1 = ((x + w) / sw) * 2.0 - 1.0;
- let y1 = 1.0 - ((y + h) / sh) * 2.0;
- [
- Vertex { position: [x0, y0], color: c0, clip_circle: [0.0; 3] },
- Vertex { position: [x1, y0], color: c1, clip_circle: [0.0; 3] },
- Vertex { position: [x0, y1], color: c0, clip_circle: [0.0; 3] },
- Vertex { position: [x1, y0], color: c1, clip_circle: [0.0; 3] },
- Vertex { position: [x1, y1], color: c1, clip_circle: [0.0; 3] },
- Vertex { position: [x0, y1], color: c0, clip_circle: [0.0; 3] },
- ]
-}
-
-fn parse_hex(hex: &str) -> Option<(f32, f32, f32)> {
- let s = hex.trim_start_matches('#');
- if s.len() == 6 {
- u32::from_str_radix(s, 16).ok().map(|v| {
- let r = ((v >> 16) & 0xFF) as f32 / 255.0;
- let g = ((v >> 8) & 0xFF) as f32 / 255.0;
- let b = (v & 0xFF) as f32 / 255.0;
- (r, g, b)
- })
- } else {
- None
- }
-}
-
-fn rgb_to_hsl(r: f32, g: f32, b: f32) -> (f32, f32, f32) {
- let max = r.max(g.max(b));
- let min = r.min(g.min(b));
- let mut h = 0.0;
- let mut s = 0.0;
- let l = (max + min) / 2.0;
-
- if max != min {
- let d = max - min;
- s = if l > 0.5 { d / (2.0 - max - min) } else { d / (max + min) };
- if max == r {
- h = (g - b) / d + (if g < b { 6.0 } else { 0.0 });
- } else if max == g {
- h = (b - r) / d + 2.0;
- } else if max == b {
- h = (r - g) / d + 4.0;
- }
- h /= 6.0;
- }
-
- (h, s, l)
-}
-
-fn hsl_to_rgb(h: f32, s: f32, l: f32) -> (f32, f32, f32) {
- if s == 0.0 {
- return (l, l, l);
- }
-
- let q = if l < 0.5 { l * (1.0 + s) } else { l + s - l * s };
- let p = 2.0 * l - q;
-
- let r = hue_to_rgb(p, q, h + 1.0 / 3.0);
- let g = hue_to_rgb(p, q, h);
- let b = hue_to_rgb(p, q, h - 1.0 / 3.0);
-
- (r, g, b)
-}
-
-fn hue_to_rgb(p: f32, q: f32, mut t: f32) -> f32 {
- if t < 0.0 { t += 1.0; }
- if t > 1.0 { t -= 1.0; }
- if t < 1.0 / 6.0 { return p + (q - p) * 6.0 * t; }
- if t < 1.0 / 2.0 { return q; }
- if t < 2.0 / 3.0 { return p + (q - p) * (2.0 / 3.0 - t) * 6.0; }
- p
-}
-
-const HEADER_H: f32 = 36.0;
-const SLIDER_ROW_H: f32 = 36.0;
-const SLIDER_START_Y: f32 = 48.0;
-const SLIDER_LABEL_X: f32 = 12.0;
-const SLIDER_TRACK_X: f32 = 32.0;
-const SLIDER_TRACK_W: f32 = 280.0;
-const SLIDER_TRACK_H: f32 = 20.0;
-const SLIDER_VALUE_X: f32 = 320.0;
-const PREVIEW_X: f32 = 12.0;
-const PREVIEW_Y: f32 = 276.0;
-const PREVIEW_W: f32 = 160.0;
-const PREVIEW_H: f32 = 72.0;
-const BUTTON_Y: f32 = 360.0;
-const BUTTON_H: f32 = 24.0;
-const BUTTON_W: f32 = 100.0;
-const BUTTON_GAP: f32 = 12.0;
-const WIN_W: f32 = 380.0;
-const WIN_H: f32 = 428.0;
-
-#[derive(Debug, Clone, Copy, PartialEq)]
-pub enum DragTarget { Red, Green, Blue, Hue, Saturation, Lightness }
-
-#[derive(Debug, Clone, Copy, PartialEq)]
-pub enum ColorAction { Apply, Cancel }
-
-struct RectWidget {
- x: f32, y: f32, w: f32, h: f32,
- color: [f32; 4],
-}
-
-struct GradientRectWidget {
- x: f32, y: f32, w: f32, h: f32,
- c0: [f32; 4],
- c1: [f32; 4],
-}
-
-struct HitButton {
- x: f32, y: f32, w: f32, h: f32,
- action: ColorAction,
-}
-
-struct ColorPickerWidget {
- _x: f32, _y: f32, _w: f32, _h: f32,
- pub red: f32,
- pub green: f32,
- pub blue: f32,
- pub hue: f32,
- pub saturation: f32,
- pub lightness: f32,
- pub dragging: Option<DragTarget>,
- pub action_requested: Option<ColorAction>,
- cursor_x: f32,
- cursor_y: f32,
- scale_factor: f32,
-
- rects: Vec<RectWidget>,
- gradient_rects: Vec<GradientRectWidget>,
- pub labels: Vec<TextLabel>,
- action_buttons: Vec<HitButton>,
- pub needs_rebuild: bool,
-}
-
-impl ColorPickerWidget {
- fn new(red: f32, green: f32, blue: f32) -> Self {
- let (hue, saturation, lightness) = rgb_to_hsl(red, green, blue);
- Self {
- _x: 0.0, _y: 0.0, _w: 0.0, _h: 0.0,
- red, green, blue,
- hue, saturation, lightness,
- dragging: None,
- action_requested: None,
- cursor_x: 0.0, cursor_y: 0.0,
- scale_factor: 2.0,
- rects: Vec::new(),
- gradient_rects: Vec::new(),
- labels: Vec::new(),
- action_buttons: Vec::new(),
- needs_rebuild: true,
- }
- }
-
- fn hex(&self) -> String {
- format!("#{:02X}{:02X}{:02X}",
- (self.red * 255.0) as u8,
- (self.green * 255.0) as u8,
- (self.blue * 255.0) as u8)
- }
-
- fn rebuild_layout(&mut self, scale: f32) {
- self.scale_factor = scale;
- let s = scale;
- let sw = WIN_W * s;
- let sh = WIN_H * s;
-
- let mut rects = Vec::new();
- let mut gradient_rects = Vec::new();
- let mut labels = Vec::new();
- let mut action_buttons = Vec::new();
-
- rects.push(RectWidget {
- x: 0.0, y: 0.0, w: sw, h: HEADER_H * s,
- color: cce_ui::color::HEADER_BG,
- });
-
- labels.push(TextLabel {
- text: "Clear Color Interface".to_string(),
- x: 12.0 * s,
- y: 10.0 * s,
- font_size: 14.0 * s,
- color: [0xcc, 0xcc, 0xd4],
- });
-
- rects.push(RectWidget {
- x: 0.0, y: HEADER_H * s, w: sw, h: sh - HEADER_H * s,
- color: cce_ui::color::CONTENT_BG,
- });
-
- let channels = [self.red, self.green, self.blue, self.hue, self.saturation, self.lightness];
- let chan_labels = ['R', 'G', 'B', 'H', 'S', 'L'];
-
- let red = self.red;
- let green = self.green;
- let blue = self.blue;
- let hue = self.hue;
- let saturation = self.saturation;
- let lightness = self.lightness;
-
- let get_color_at = |i: usize, t: f32| -> [f32; 4] {
- match i {
- 0 => [t, green, blue, 1.0],
- 1 => [red, t, blue, 1.0],
- 2 => [red, green, t, 1.0],
- 3 => {
- let (r, g, b) = hsl_to_rgb(t, saturation, lightness);
- [r, g, b, 1.0]
- }
- 4 => {
- let (r, g, b) = hsl_to_rgb(hue, t, lightness);
- [r, g, b, 1.0]
- }
- _ => {
- let (r, g, b) = hsl_to_rgb(hue, saturation, t);
- [r, g, b, 1.0]
- }
- }
- };
-
- for i in 0..6 {
- let row_y = (SLIDER_START_Y + i as f32 * SLIDER_ROW_H) * s;
- let track_y = row_y + ((SLIDER_ROW_H - SLIDER_TRACK_H) / 2.0) * s;
-
- rects.push(RectWidget {
- x: (SLIDER_TRACK_X - 1.0) * s,
- y: track_y - 1.0 * s,
- w: (SLIDER_TRACK_W + 2.0) * s,
- h: (SLIDER_TRACK_H + 2.0) * s,
- color: [0.08, 0.08, 0.10, 1.0],
- });
-
- let n_segments = if i == 3 { 30 } else { 10 };
- for j in 0..n_segments {
- let t0 = j as f32 / n_segments as f32;
- let t1 = (j + 1) as f32 / n_segments as f32;
- let c0 = get_color_at(i, t0);
- let c1 = get_color_at(i, t1);
- gradient_rects.push(GradientRectWidget {
- x: (SLIDER_TRACK_X + t0 * SLIDER_TRACK_W) * s,
- y: track_y,
- w: ((t1 - t0) * SLIDER_TRACK_W) * s,
- h: SLIDER_TRACK_H * s,
- c0,
- c1,
- });
- }
-
- let indicator_w = 4.0;
- let indicator_h = SLIDER_TRACK_H + 4.0;
- let indicator_x = SLIDER_TRACK_X + channels[i] * SLIDER_TRACK_W - indicator_w / 2.0;
- let indicator_y = (SLIDER_START_Y + i as f32 * SLIDER_ROW_H) + ((SLIDER_ROW_H - indicator_h) / 2.0);
-
- rects.push(RectWidget {
- x: (indicator_x - 1.0) * s,
- y: (indicator_y - 1.0) * s,
- w: (indicator_w + 2.0) * s,
- h: (indicator_h + 2.0) * s,
- color: [0.05, 0.05, 0.05, 0.95],
- });
-
- rects.push(RectWidget {
- x: indicator_x * s,
- y: indicator_y * s,
- w: indicator_w * s,
- h: indicator_h * s,
- color: [1.0, 1.0, 1.0, 1.0],
- });
-
- labels.push(TextLabel {
- text: chan_labels[i].to_string(),
- x: SLIDER_LABEL_X * s,
- y: row_y + 4.0 * s,
- font_size: 12.0 * s,
- color: [0xaa, 0xaa, 0xbb],
- });
-
- let val = if i < 3 {
- format!("{}", (channels[i] * 255.0) as u8)
- } else if i == 3 {
- format!("{}°", (channels[i] * 360.0).round() as u16)
- } else {
- format!("{}%", (channels[i] * 100.0).round() as u8)
- };
-
- labels.push(TextLabel {
- text: val,
- x: SLIDER_VALUE_X * s,
- y: row_y + 4.0 * s,
- font_size: 11.0 * s,
- color: [0xcc, 0xcc, 0xdd],
- });
- }
-
- rects.push(RectWidget {
- x: PREVIEW_X * s, y: PREVIEW_Y * s,
- w: PREVIEW_W * s, h: PREVIEW_H * s,
- color: [self.red, self.green, self.blue, 1.0],
- });
-
- let hex = self.hex();
- labels.push(TextLabel {
- text: hex,
- x: (PREVIEW_X + PREVIEW_W + 16.0) * s,
- y: (PREVIEW_Y + 26.0) * s,
- font_size: 16.0 * s,
- color: [0xe0, 0xe0, 0xe8],
- });
-
- let apply_x = PREVIEW_X;
- let cancel_x = PREVIEW_X + BUTTON_W + BUTTON_GAP;
- let btn_y = BUTTON_Y;
- let btn_bg = [0.20, 0.40, 0.65, 1.0];
- let cancel_bg = [0.40, 0.20, 0.20, 1.0];
-
- rects.push(RectWidget {
- x: apply_x * s, y: btn_y * s,
- w: BUTTON_W * s, h: BUTTON_H * s,
- color: btn_bg,
- });
- labels.push(TextLabel {
- text: "Apply".to_string(),
- x: (apply_x + 28.0) * s,
- y: (btn_y + 8.0) * s,
- font_size: 12.0 * s,
- color: [0xee, 0xee, 0xf0],
- });
- action_buttons.push(HitButton {
- x: apply_x * s, y: btn_y * s,
- w: BUTTON_W * s, h: BUTTON_H * s,
- action: ColorAction::Apply,
- });
-
- rects.push(RectWidget {
- x: cancel_x * s, y: btn_y * s,
- w: BUTTON_W * s, h: BUTTON_H * s,
- color: cancel_bg,
- });
- labels.push(TextLabel {
- text: "Cancel".to_string(),
- x: (cancel_x + 22.0) * s,
- y: (btn_y + 8.0) * s,
- font_size: 12.0 * s,
- color: [0xee, 0xee, 0xf0],
- });
- action_buttons.push(HitButton {
- x: cancel_x * s, y: btn_y * s,
- w: BUTTON_W * s, h: BUTTON_H * s,
- action: ColorAction::Cancel,
- });
-
- self.rects = rects;
- self.gradient_rects = gradient_rects;
- self.labels = labels;
- self.action_buttons = action_buttons;
- self.needs_rebuild = false;
- }
-
- fn slider_physical_rect(i: usize, s: f32) -> (f32, f32, f32, f32) {
- let row_y = (SLIDER_START_Y + i as f32 * SLIDER_ROW_H) * s;
- let track_y = row_y + ((SLIDER_ROW_H - SLIDER_TRACK_H) / 2.0) * s;
- (SLIDER_TRACK_X * s, track_y, SLIDER_TRACK_W * s, SLIDER_TRACK_H * s)
- }
-
- fn collect_vertices(&self, sw: f32, sh: f32) -> Vec<Vertex> {
- let mut verts = Vec::new();
- for r in &self.rects {
- verts.extend(quad_vertices(r.x, r.y, r.w, r.h, sw, sh, r.color));
- }
- for g in &self.gradient_rects {
- verts.extend(gradient_quad_vertices(g.x, g.y, g.w, g.h, sw, sh, g.c0, g.c1));
- }
- verts
- }
-
- fn handle_cursor_moved(&mut self, cx: f32, cy: f32) {
- self.cursor_x = cx;
- self.cursor_y = cy;
- if let Some(drag) = self.dragging {
- let i = match drag {
- DragTarget::Red => 0,
- DragTarget::Green => 1,
- DragTarget::Blue => 2,
- DragTarget::Hue => 3,
- DragTarget::Saturation => 4,
- DragTarget::Lightness => 5,
- };
- let s = self.scale_factor;
- let (tx, _, tw, _) = Self::slider_physical_rect(i, s);
- let new_val = ((self.cursor_x - tx) / tw).clamp(0.0, 1.0);
- let old = match i {
- 0 => self.red,
- 1 => self.green,
- 2 => self.blue,
- 3 => self.hue,
- 4 => self.saturation,
- _ => self.lightness,
- };
- if (new_val - old).abs() > 0.002 {
- match i {
- 0 => {
- self.red = new_val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- }
- 1 => {
- self.green = new_val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- }
- 2 => {
- self.blue = new_val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- }
- 3 => {
- self.hue = new_val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- }
- 4 => {
- self.saturation = new_val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- }
- _ => {
- self.lightness = new_val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- }
- }
- self.needs_rebuild = true;
- }
- }
- }
- fn handle_mouse_input(&mut self, state: cce_ui::widget::ElementState) {
- match state {
- cce_ui::widget::ElementState::Pressed => {
- let s = self.scale_factor;
- let (px, py) = (self.cursor_x, self.cursor_y);
- for i in 0..6 {
- let (tx, ty, tw, th) = Self::slider_physical_rect(i, s);
- if px >= tx && px <= tx + tw && py >= ty && py <= ty + th {
- let val = ((px - tx) / tw).clamp(0.0, 1.0);
- match i {
- 0 => {
- self.red = val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- self.dragging = Some(DragTarget::Red);
- }
- 1 => {
- self.green = val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- self.dragging = Some(DragTarget::Green);
- }
- 2 => {
- self.blue = val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- self.dragging = Some(DragTarget::Blue);
- }
- 3 => {
- self.hue = val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- self.dragging = Some(DragTarget::Hue);
- }
- 4 => {
- self.saturation = val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- self.dragging = Some(DragTarget::Saturation);
- }
- _ => {
- self.lightness = val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- self.dragging = Some(DragTarget::Lightness);
- }
- }
- self.needs_rebuild = true;
- return;
- }
- }
- for btn in &self.action_buttons {
- if px >= btn.x && px <= btn.x + btn.w && py >= btn.y && py <= btn.y + btn.h {
- self.action_requested = Some(btn.action);
- self.needs_rebuild = true;
- return;
- }
- }
- }
- cce_ui::widget::ElementState::Released => {
- if self.dragging.is_some() {
- self.dragging = None;
- }
- }
- }
- }
-
- fn handle_scroll(&mut self, scroll_amount_y: f32) {
- let s = self.scale_factor;
- let (px, py) = (self.cursor_x, self.cursor_y);
- let scroll_amount = scroll_amount_y;
- if scroll_amount.abs() > 0.0001 {
- for i in 0..6 {
- let (tx, ty, tw, th) = Self::slider_physical_rect(i, s);
- if px >= tx && px <= tx + tw && py >= ty - 4.0 * s && py <= ty + th + 4.0 * s {
- let step = 0.02;
- let old_val = match i {
- 0 => self.red,
- 1 => self.green,
- 2 => self.blue,
- 3 => self.hue,
- 4 => self.saturation,
- _ => self.lightness,
- };
- let new_val = (old_val + scroll_amount * step).clamp(0.0, 1.0);
- if (new_val - old_val).abs() > 0.0001 {
- match i {
- 0 => {
- self.red = new_val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- }
- 1 => {
- self.green = new_val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- }
- 2 => {
- self.blue = new_val;
- let (h, sat, l) = rgb_to_hsl(self.red, self.green, self.blue);
- self.saturation = sat;
- self.lightness = l;
- if sat > 0.001 && l > 0.001 && l < 0.999 {
- self.hue = h;
- }
- }
- 3 => {
- self.hue = new_val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- }
- 4 => {
- self.saturation = new_val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- }
- _ => {
- self.lightness = new_val;
- let (r, g, b) = hsl_to_rgb(self.hue, self.saturation, self.lightness);
- self.red = r;
- self.green = g;
- self.blue = b;
- }
- }
- self.needs_rebuild = true;
- }
- }
- }
- }
- }
-}
pub struct FuzzelWidget {
@@ -1249,7 +632,6 @@ enum LauncherMode {
Dmenu,
Path,
Apps,
- Color,
Json,
}
@@ -1301,7 +683,6 @@ struct State {
vertex_count: u32,
fuzzel: FuzzelWidget,
- color_picker: Option<ColorPickerWidget>,
json_layout: Option<JsonLayoutWidget>,
font_system: FontSystem,
swash_cache: SwashCache,
@@ -1338,7 +719,6 @@ impl State {
prompt: String,
stdin_sender: calloop::channel::Sender<()>,
mode: LauncherMode,
- initial_hex: Option<String>,
x_pos: Option<i32>,
y_pos: Option<i32>,
align_right: bool,
@@ -1347,9 +727,7 @@ impl State {
json_layout_config: Option<JsonLayoutConfig>,
) -> Self {
cce_ui::scale::set_scale_factor(scale as f32);
- let (width, height) = if mode == LauncherMode::Color {
- (WIN_W as u32, WIN_H as u32)
- } else if mode == LauncherMode::Json {
+ let (width, height) = if mode == LauncherMode::Json {
if let Some(ref config) = json_layout_config {
let w = config.width.unwrap_or(300);
let h = config.height.unwrap_or_else(|| {
@@ -1404,11 +782,7 @@ impl State {
let wl_surface = compositor_state.create_surface(qh);
wl_surface.set_buffer_scale(scale as i32);
- let app_id = if mode == LauncherMode::Color {
- "clear-color-interface".to_string()
- } else {
- "cce-cloud".to_string()
- };
+ let app_id = "cce-cloud".to_string();
let window = layer_shell_state.create_layer_surface(
qh,
wl_surface.clone(),
@@ -1589,18 +963,6 @@ impl State {
}
}
- let color_picker = if mode == LauncherMode::Color {
- let (r, g, b) = initial_hex
- .as_ref()
- .and_then(|h| parse_hex(h))
- .unwrap_or((0.5, 0.5, 0.5));
- let mut cp = ColorPickerWidget::new(r, g, b);
- cp.rebuild_layout(scale as f32);
- Some(cp)
- } else {
- None
- };
-
let json_layout = if mode == LauncherMode::Json {
if let Some(ref config) = json_layout_config {
let mut jl = JsonLayoutWidget::new(config);
@@ -1626,7 +988,6 @@ impl State {
vertex_buffer,
vertex_count: 0,
fuzzel,
- color_picker,
json_layout,
font_system,
swash_cache,
@@ -1686,7 +1047,7 @@ impl State {
}
fn update_desired_size(&mut self) {
- if self.mode == LauncherMode::Color || self.mode == LauncherMode::Json {
+ if self.mode == LauncherMode::Json {
return;
}
let num_items = self.fuzzel.filtered_items.len();
@@ -1743,11 +1104,7 @@ impl State {
fn apply_layout(&mut self) {
let (w, h) = (self.width, self.height);
- if self.mode == LauncherMode::Color {
- if let Some(cp) = &mut self.color_picker {
- cp.rebuild_layout(self.scale as f32);
- }
- } else if self.mode == LauncherMode::Json {
+ if self.mode == LauncherMode::Json {
if let Some(jl) = &mut self.json_layout {
cce_ui::scale::set_scale_factor(self.scale as f32);
jl.set_rect(0.0, 0.0, w, h);
@@ -1760,17 +1117,7 @@ impl State {
fn collect_vertices(&self) -> Vec<Vertex> {
let sw = self.width;
let sh = self.height;
- if self.mode == LauncherMode::Color {
- if let Some(cp) = &self.color_picker {
- let pw = self.physical_width as f32;
- let ph = self.physical_height as f32;
- let mut verts = quad_vertices(0.0, 0.0, pw, ph, pw, ph, [0.05, 0.05, 0.08, self.opacity]).to_vec();
- verts.extend(cp.collect_vertices(pw, ph));
- verts
- } else {
- Vec::new()
- }
- } else if self.mode == LauncherMode::Json {
+ if self.mode == LauncherMode::Json {
if let Some(jl) = &self.json_layout {
let mut verts = quad_vertices(0.0, 0.0, sw, sh, sw, sh, [0.05, 0.05, 0.08, self.opacity]).to_vec();
verts.extend(widget_vertices(jl, sw, sh));
@@ -1822,7 +1169,6 @@ impl State {
physical_height,
scale,
ref fuzzel,
- ref color_picker,
ref json_layout,
ref mode,
..
@@ -1837,15 +1183,8 @@ impl State {
let mut widget_buffers: Vec<Buffer> = Vec::new();
let mut widget_labels: Vec<TextLabel> = Vec::new();
- let is_color_mode = *mode == LauncherMode::Color;
let is_json_mode = *mode == LauncherMode::Json;
- if is_color_mode {
- if let Some(cp) = color_picker {
- for label in &cp.labels {
- widget_labels.push(label.clone());
- }
- }
- } else if is_json_mode {
+ if is_json_mode {
if let Some(jl) = json_layout {
for label in jl.text_labels() {
widget_labels.push(label);
@@ -1862,9 +1201,9 @@ impl State {
}
for (buf, label) in widget_buffers.iter().zip(widget_labels.iter()) {
- let left = if is_color_mode { label.x.round() } else { (label.x * scale_f32).round() };
- let top = if is_color_mode { label.y.round() } else { (label.y * scale_f32).round() };
- let scale = if is_color_mode { 1.0 } else { scale_f32 };
+ let left = (label.x * scale_f32).round();
+ let top = (label.y * scale_f32).round();
+ let scale = scale_f32;
let default_color = if self.fade_factor < 1.0 {
let alpha = (self.fade_factor * 255.0) as u8;
glyphon::Color::rgba(label.color[0], label.color[1], label.color[2], alpha)
@@ -1901,13 +1240,7 @@ impl State {
self.config.width = width;
self.config.height = height;
self.surface.configure(&self.device, &self.config);
- if self.mode == LauncherMode::Color {
- if let Some(cp) = &mut self.color_picker {
- cp.rebuild_layout(self.scale as f32);
- }
- } else {
- self.apply_layout();
- }
+ self.apply_layout();
self.upload_vertices();
}
}
@@ -2164,20 +1497,7 @@ impl PointerHandler for AppState {
PointerEventKind::Motion { .. } => {
st.cursor_x = cx;
st.cursor_y = cy;
- if st.mode == LauncherMode::Color {
- let mut needs_rebuild = false;
- if let Some(cp) = &mut st.color_picker {
- cp.handle_cursor_moved(cx, cy);
- if cp.needs_rebuild {
- cp.rebuild_layout(st.scale as f32);
- needs_rebuild = true;
- }
- }
- if needs_rebuild {
- st.upload_vertices();
- self.redraw = true;
- }
- } else if st.mode == LauncherMode::Json {
+ if st.mode == LauncherMode::Json {
let mut changed = false;
if let Some(jl) = &mut st.json_layout {
if jl.on_cursor_moved(event.position.0 as f32, event.position.1 as f32, &mut st.ui_context) {
@@ -2194,37 +1514,7 @@ impl PointerHandler for AppState {
if *button == 272 {
st.cursor_x = cx;
st.cursor_y = cy;
- if st.mode == LauncherMode::Color {
- let mut needs_rebuild = false;
- let mut action_requested = None;
- let mut hex = String::new();
- if let Some(cp) = &mut st.color_picker {
- cp.handle_mouse_input(cce_ui::widget::ElementState::Pressed);
- if cp.needs_rebuild {
- cp.rebuild_layout(st.scale as f32);
- needs_rebuild = true;
- }
- if let Some(action) = cp.action_requested {
- action_requested = Some(action);
- hex = cp.hex();
- }
- }
- if needs_rebuild {
- st.upload_vertices();
- self.redraw = true;
- }
- if let Some(action) = action_requested {
- match action {
- ColorAction::Apply => {
- println!("{}", hex);
- should_close = true;
- }
- ColorAction::Cancel => {
- should_close = true;
- }
- }
- }
- } else if st.mode == LauncherMode::Json {
+ if st.mode == LauncherMode::Json {
let mut changed = false;
if let Some(jl) = &mut st.json_layout {
if jl.mouse_input(
@@ -2265,7 +1555,6 @@ impl PointerHandler for AppState {
spawn_command(item);
}
LauncherMode::Dmenu => {}
- LauncherMode::Color => {}
LauncherMode::Json => {}
}
should_close = true;
@@ -2279,20 +1568,7 @@ impl PointerHandler for AppState {
}
PointerEventKind::Release { button, .. } => {
if *button == 272 {
- if st.mode == LauncherMode::Color {
- let mut needs_rebuild = false;
- if let Some(cp) = &mut st.color_picker {
- cp.handle_mouse_input(cce_ui::widget::ElementState::Released);
- if cp.needs_rebuild {
- cp.rebuild_layout(st.scale as f32);
- needs_rebuild = true;
- }
- }
- if needs_rebuild {
- st.upload_vertices();
- self.redraw = true;
- }
- } else if st.mode == LauncherMode::Json {
+ if st.mode == LauncherMode::Json {
let mut changed = false;
let mut clicked_btn_id = None;
if let Some(jl) = &mut st.json_layout {
@@ -2350,29 +1626,13 @@ impl PointerHandler for AppState {
}
}
PointerEventKind::Axis { horizontal, vertical, .. } => {
- if st.mode == LauncherMode::Color {
- let mut needs_rebuild = false;
- if let Some(cp) = &mut st.color_picker {
- let v_scroll = vertical.absolute as f32;
- cp.handle_scroll(-v_scroll / 10.0);
- if cp.needs_rebuild {
- cp.rebuild_layout(st.scale as f32);
- needs_rebuild = true;
- }
- }
- if needs_rebuild {
- st.upload_vertices();
- self.redraw = true;
- }
- } else {
- let h_scroll = horizontal.absolute as f32;
- let v_scroll = vertical.absolute as f32;
- let delta = cce_ui::widget::MouseScrollDelta::LineDelta(-h_scroll / 10.0, -v_scroll / 10.0);
- if st.fuzzel.scroll_box.mouse_wheel(&delta, st.cursor_x, st.cursor_y, &mut st.ui_context) {
- st.fuzzel.update_scroll();
- st.upload_vertices();
- self.redraw = true;
- }
+ let h_scroll = horizontal.absolute as f32;
+ let v_scroll = vertical.absolute as f32;
+ let delta = cce_ui::widget::MouseScrollDelta::LineDelta(-h_scroll / 10.0, -v_scroll / 10.0);
+ if st.fuzzel.scroll_box.mouse_wheel(&delta, st.cursor_x, st.cursor_y, &mut st.ui_context) {
+ st.fuzzel.update_scroll();
+ st.upload_vertices();
+ self.redraw = true;
}
}
_ => {}
@@ -2535,22 +1795,7 @@ impl AppState {
let mut should_close = false;
if let Some(st) = &mut self.state {
let mut handled = true;
- if st.mode == LauncherMode::Color {
- match &logical_key {
- Key::Named(NamedKey::Escape) => {
- should_close = true;
- }
- Key::Named(NamedKey::Enter) => {
- if let Some(cp) = &st.color_picker {
- println!("{}", cp.hex());
- }
- should_close = true;
- }
- _ => {
- handled = false;
- }
- }
- } else if st.mode == LauncherMode::Json {
+ if st.mode == LauncherMode::Json {
let mut widget_handled = false;
let key_event = cce_ui::widget::KeyEvent {
state,
@@ -2596,7 +1841,6 @@ impl AppState {
spawn_command(item);
}
LauncherMode::Dmenu => {}
- LauncherMode::Color => {}
LauncherMode::Json => {}
}
should_close = true;
@@ -2659,7 +1903,6 @@ fn main() {
} else {
LauncherMode::Path
};
- let mut initial_hex: Option<String> = None;
let mut x_pos: Option<i32> = None;
let mut y_pos: Option<i32> = None;
let mut select_item: Option<String> = None;
@@ -2708,7 +1951,6 @@ fn main() {
"apps" | "app" => mode = LauncherMode::Apps,
"path" => mode = LauncherMode::Path,
"dmenu" => mode = LauncherMode::Dmenu,
- "color" => mode = LauncherMode::Color,
_ => eprintln!("Unknown mode: {}", m),
}
i += 2;
@@ -2724,14 +1966,6 @@ fn main() {
} else if arg == "--dmenu" {
mode = LauncherMode::Dmenu;
i += 1;
- } else if arg == "--color" {
- mode = LauncherMode::Color;
- if i + 1 < args.len() && !args[i + 1].starts_with('-') {
- initial_hex = Some(args[i + 1].clone());
- i += 2;
- } else {
- i += 1;
- }
} else if arg == "--json" || arg == "--layout" {
mode = LauncherMode::Json;
i += 1;
@@ -2814,7 +2048,6 @@ fn main() {
prompt,
stdin_sender,
mode,
- initial_hex,
x_pos,
y_pos,
align_right,