Download kernel/src/desktop/taskbar.rs from Jaswanth-2008/AeroOS: direct link, hf CLI and curl.
- Browser
- Download file 8.26 kB
-
https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/desktop/taskbar.rs
- Command line
-
hf download hf://Jaswanth-2008/AeroOS/kernel/src/desktop/taskbar.rs
-
curl -L -o taskbar.rs https://huggingface.co/Jaswanth-2008/AeroOS/resolve/main/kernel/src/desktop/taskbar.rs
8.26 kB
| extern crate alloc; | |
| use alloc::format; | |
| use crate::apps::AppType; | |
| use crate::graphics::color::Color; | |
| use crate::graphics::icons::IconType; | |
| use crate::graphics::surface::Surface; | |
| use crate::net::stack; | |
| use crate::window_manager::compositor::Compositor; | |
| pub const TASKBAR_HEIGHT: usize = 44; | |
| pub struct TaskbarPin { | |
| pub app_type: AppType, | |
| pub icon: IconType, | |
| pub name: &'static str, | |
| } | |
| pub static TASKBAR_PINS: [TaskbarPin; 9] = [ | |
| TaskbarPin { app_type: AppType::Terminal, icon: IconType::Terminal, name: "Terminal" }, | |
| TaskbarPin { app_type: AppType::WifiManager, icon: IconType::Network, name: "Wi-Fi" }, | |
| TaskbarPin { app_type: AppType::FileManager, icon: IconType::FileManager, name: "Files" }, | |
| TaskbarPin { app_type: AppType::SnapStore, icon: IconType::OsLogo, name: "Store" }, | |
| TaskbarPin { app_type: AppType::NetManager, icon: IconType::Network, name: "Network" }, | |
| TaskbarPin { app_type: AppType::SysInfo, icon: IconType::TaskManager, name: "TaskMgr" }, | |
| TaskbarPin { app_type: AppType::Editor, icon: IconType::Editor, name: "Editor" }, | |
| TaskbarPin { app_type: AppType::Calculator, icon: IconType::Calculator, name: "Calc" }, | |
| TaskbarPin { app_type: AppType::Settings, icon: IconType::Settings, name: "Settings" }, | |
| ]; | |
| pub enum TaskbarAction { | |
| ToggleStartMenu, | |
| ToggleShowDesktop, | |
| ClickApp(AppType), | |
| } | |
| pub fn handle_taskbar_click(mouse_x: i32, mouse_y: i32, screen_w: usize, screen_h: usize) -> Option<TaskbarAction> { | |
| let taskbar_y = (screen_h - TASKBAR_HEIGHT) as i32; | |
| if mouse_y < taskbar_y || mouse_y >= screen_h as i32 { | |
| return None; | |
| } | |
| // 1. Far right: Show Desktop peek strip (last 6 pixels) | |
| if mouse_x >= (screen_w as i32 - 8) { | |
| return Some(TaskbarAction::ToggleShowDesktop); | |
| } | |
| // 2. System Tray Wi-Fi & Network Click (click tray icon to open Wi-Fi settings) | |
| if mouse_x >= (screen_w as i32 - 110) && mouse_x < (screen_w as i32 - 8) { | |
| return Some(TaskbarAction::ClickApp(AppType::WifiManager)); | |
| } | |
| // 2. Centered cluster layout | |
| // Cluster: Start (42px) + Gap (4px) + Search (70px) + Gap (6px) + 8 Pins (42px each with 4px gap) | |
| let start_w = 42; | |
| let search_w = 70; | |
| let pin_w = 42; | |
| let pin_gap = 4; | |
| let total_pins_w = (TASKBAR_PINS.len() * pin_w) + ((TASKBAR_PINS.len() - 1) * pin_gap); | |
| let cluster_w = start_w + 4 + search_w + 6 + total_pins_w; | |
| let cluster_x = ((screen_w as i32) - (cluster_w as i32)) / 2; | |
| // Start Button | |
| if mouse_x >= cluster_x && mouse_x < cluster_x + start_w as i32 { | |
| return Some(TaskbarAction::ToggleStartMenu); | |
| } | |
| // Search Pill | |
| let search_x = cluster_x + start_w as i32 + 4; | |
| if mouse_x >= search_x && mouse_x < search_x + search_w as i32 { | |
| return Some(TaskbarAction::ToggleStartMenu); | |
| } | |
| // App Pins | |
| let pins_start_x = search_x + search_w as i32 + 6; | |
| for (i, pin) in TASKBAR_PINS.iter().enumerate() { | |
| let px = pins_start_x + (i as i32 * (pin_w as i32 + pin_gap as i32)); | |
| if mouse_x >= px && mouse_x < px + pin_w as i32 { | |
| return Some(TaskbarAction::ClickApp(pin.app_type)); | |
| } | |
| } | |
| None | |
| } | |
| pub fn render_taskbar(surface: &mut Surface, compositor: &Compositor) { | |
| let w = surface.width; | |
| let h = surface.height; | |
| let taskbar_y = (h - TASKBAR_HEIGHT) as i32; | |
| // 1. Windows 11 Acrylic Taskbar Background | |
| surface.draw_rect(0, taskbar_y, w, TASKBAR_HEIGHT, Color::rgba(24, 28, 38, 245)); | |
| // Subtle 1px top border highlight | |
| surface.draw_rect(0, taskbar_y, w, 1, Color::rgba(255, 255, 255, 25)); | |
| // 2. Left side: OS Badge / Widgets | |
| surface.draw_rounded_rect(10, taskbar_y + 6, 88, 32, 6, Color::rgba(255, 255, 255, 8)); | |
| surface.draw_icon_16(IconType::OsLogo, 16, taskbar_y + 14, Color::ACCENT_CYAN); | |
| surface.draw_text("AeroOS", 36, taskbar_y + 14, Color::WHITE); | |
| // 3. Center section: Start Button + Search + App Pins | |
| let start_w = 42; | |
| let search_w = 70; | |
| let pin_w = 42; | |
| let pin_gap = 4; | |
| let total_pins_w = (TASKBAR_PINS.len() * pin_w) + ((TASKBAR_PINS.len() - 1) * pin_gap); | |
| let cluster_w = start_w + 4 + search_w + 6 + total_pins_w; | |
| let cluster_x = ((w as i32) - (cluster_w as i32)) / 2; | |
| // A. Start Button (Windows 11 4-pane blue logo) | |
| surface.draw_rounded_rect(cluster_x, taskbar_y + 4, start_w, 36, 6, Color::rgba(255, 255, 255, 12)); | |
| surface.draw_icon_16(IconType::Win11Logo, cluster_x + 13, taskbar_y + 14, Color::rgb(0, 164, 239)); | |
| // B. Search Pill | |
| let search_x = cluster_x + start_w as i32 + 4; | |
| surface.draw_rounded_rect(search_x, taskbar_y + 4, search_w, 36, 6, Color::rgba(255, 255, 255, 10)); | |
| surface.draw_text("Search", search_x + 14, taskbar_y + 14, Color::rgb(180, 190, 205)); | |
| // C. Pinned & Running Apps | |
| let pins_start_x = search_x + search_w as i32 + 6; | |
| let active_id = compositor.windows.last().map(|win| win.id).unwrap_or(0); | |
| for (i, pin) in TASKBAR_PINS.iter().enumerate() { | |
| let px = pins_start_x + (i as i32 * (pin_w as i32 + pin_gap as i32)); | |
| // Check if app is open | |
| let running_win = compositor.windows.iter().find(|win| win.app_type == pin.app_type); | |
| let is_running = running_win.is_some(); | |
| let is_focused = running_win.map(|w| w.id == active_id && !w.is_minimized).unwrap_or(false); | |
| // Background highlight if running or focused | |
| let bg_color = if is_focused { | |
| Color::rgba(255, 255, 255, 28) | |
| } else if is_running { | |
| Color::rgba(255, 255, 255, 14) | |
| } else { | |
| Color::rgba(0, 0, 0, 0) | |
| }; | |
| if bg_color.a > 0 { | |
| surface.draw_rounded_rect(px, taskbar_y + 4, pin_w, 36, 6, bg_color); | |
| } | |
| // App Icon | |
| let icon_color = match pin.app_type { | |
| AppType::Terminal => Color::ACCENT_CYAN, | |
| AppType::WifiManager => Color::rgb(0, 198, 255), | |
| AppType::FileManager => Color::rgb(255, 185, 0), | |
| AppType::SnapStore => Color::rgb(233, 84, 32), | |
| AppType::NetManager => Color::rgb(0, 120, 215), | |
| AppType::SysInfo => Color::rgb(16, 124, 65), | |
| AppType::Editor => Color::rgb(0, 153, 188), | |
| AppType::Calculator => Color::rgb(142, 142, 147), | |
| AppType::Settings => Color::rgb(200, 200, 200), | |
| AppType::Snake => Color::rgb(177, 70, 194), | |
| }; | |
| surface.draw_icon_16(pin.icon, px + 13, taskbar_y + 14, icon_color); | |
| // Windows 11 Running Pill Indicator underneath | |
| if is_focused { | |
| // Bright active pill (16px x 3px) | |
| surface.draw_rounded_rect(px + 13, taskbar_y + 39, 16, 3, 1, Color::rgb(0, 150, 255)); | |
| } else if is_running { | |
| // Subtle running dot/pill (6px x 3px) | |
| surface.draw_rounded_rect(px + 18, taskbar_y + 39, 6, 3, 1, Color::rgba(255, 255, 255, 120)); | |
| } | |
| } | |
| // 4. Right side: System Tray | |
| let mut right_x = w as i32 - 12; | |
| // Show Desktop peek strip | |
| surface.draw_rect(w as i32 - 4, taskbar_y + 8, 2, 28, Color::rgba(255, 255, 255, 40)); | |
| right_x -= 10; | |
| // Clock and Date (Synchronized with Hardware CMOS RTC) | |
| let dt = crate::drivers::rtc::get_datetime(); | |
| let time_str = dt.format_time_24(); | |
| let date_str = dt.format_date(); | |
| right_x -= 54; | |
| surface.draw_text(&time_str, right_x, taskbar_y + 10, Color::WHITE); | |
| surface.draw_text(&date_str, right_x, taskbar_y + 24, Color::TEXT_MUTED); | |
| // Audio Volume Icon | |
| right_x -= 24; | |
| surface.draw_icon_16(IconType::Volume, right_x, taskbar_y + 14, Color::WHITE); | |
| // Laptop ACPI Battery Level & Icon | |
| let hw = crate::drivers::laptop::get_hardware(); | |
| right_x -= 30; | |
| let bat_str = format!("{}%", hw.battery_percent); | |
| surface.draw_text(&bat_str, right_x, taskbar_y + 14, Color::WHITE); | |
| right_x -= 20; | |
| surface.draw_icon_16(IconType::Battery, right_x, taskbar_y + 14, Color::rgb(16, 185, 129)); | |
| // Network Icon (Green if connected) | |
| let (_, _, _, active) = stack::get_status_info(); | |
| right_x -= 24; | |
| let net_color = if active { Color::rgb(16, 124, 65) } else { Color::rgb(232, 17, 35) }; | |
| surface.draw_icon_16(IconType::Network, right_x, taskbar_y + 14, net_color); | |
| } | |