pub mod start_menu; pub mod taskbar; use crate::apps::AppType; use crate::graphics::color::Color; use crate::graphics::icons::IconType; use crate::graphics::surface::Surface; use crate::graphics::wallpaper::render_wallpaper; use crate::window_manager::compositor::Compositor; use self::start_menu::StartMenuClickResult; use self::taskbar::{handle_taskbar_click, render_taskbar, TaskbarAction}; pub struct Desktop { pub start_menu_open: bool, } impl Desktop { pub fn new() -> Self { Self { start_menu_open: false, } } pub fn handle_click(&mut self, mouse_x: i32, mouse_y: i32, compositor: &mut Compositor, screen_w: usize, screen_h: usize) -> bool { // 1. If start menu is open, handle clicks inside or close it if self.start_menu_open { if let Some(res) = start_menu::handle_start_click(mouse_x, mouse_y, screen_w, screen_h) { match res { StartMenuClickResult::Launch(app) => { self.start_menu_open = false; self.launch_app(app, compositor); return true; } StartMenuClickResult::PowerRestart => { self.start_menu_open = false; // Trigger x86 keyboard controller reset unsafe { x86_64::instructions::port::Port::::new(0x64).write(0xFE); } return true; } StartMenuClickResult::InsideMenu => { return true; } } } else { // Clicked outside start menu self.start_menu_open = false; } } // 2. Taskbar interactions if let Some(action) = handle_taskbar_click(mouse_x, mouse_y, screen_w, screen_h) { match action { TaskbarAction::ToggleStartMenu => { self.start_menu_open = !self.start_menu_open; } TaskbarAction::ToggleShowDesktop => { let any_visible = compositor.windows.iter().any(|w| !w.is_minimized); if any_visible { for w in compositor.windows.iter_mut() { w.is_minimized = true; } } else { for w in compositor.windows.iter_mut() { w.is_minimized = false; } } } TaskbarAction::ClickApp(app) => { let active_id = compositor.windows.last().map(|w| w.id).unwrap_or(0); let mut found = false; for w in compositor.windows.iter_mut() { if w.app_type == app { found = true; if w.id == active_id && !w.is_minimized { // Toggle minimize w.is_minimized = true; } else { w.is_minimized = false; let id = w.id; compositor.bring_to_front(id); } break; } } if !found { self.launch_app(app, compositor); } } } return true; } // 3. Window Manager Click Test (Windows ALWAYS have priority over desktop icons!) let window_handled = compositor.handle_mouse_down(mouse_x, mouse_y, true); if window_handled { return true; } // 4. Desktop Shortcuts Click Test (ONLY if click was on empty desktop!) if mouse_x >= 16 && mouse_x <= 88 { if mouse_y >= 20 && mouse_y < 80 { self.launch_app(AppType::FileManager, compositor); return true; } else if mouse_y >= 90 && mouse_y < 150 { self.launch_app(AppType::SnapStore, compositor); return true; } else if mouse_y >= 160 && mouse_y < 220 { self.launch_app(AppType::Terminal, compositor); return true; } else if mouse_y >= 230 && mouse_y < 290 { self.launch_app(AppType::NetManager, compositor); return true; } else if mouse_y >= 300 && mouse_y < 360 { self.launch_app(AppType::SysInfo, compositor); return true; } else if mouse_y >= 370 && mouse_y < 430 { self.launch_app(AppType::Snake, compositor); return true; } else if mouse_y >= 440 && mouse_y < 500 { self.launch_app(AppType::Editor, compositor); return true; } } false } pub fn launch_app(&self, app: AppType, compositor: &mut Compositor) { match app { AppType::Terminal => { compositor.open_window("AeroShell - Terminal", 130, 40, 520, 360, AppType::Terminal); } AppType::WifiManager => { compositor.open_window("Wi-Fi - Wireless Network Settings", 200, 60, 500, 340, AppType::WifiManager); } AppType::FileManager => { compositor.open_window("File Explorer - System HD", 170, 70, 480, 320, AppType::FileManager); } AppType::NetManager => { compositor.open_window("Network Center (VirtIO)", 210, 100, 480, 280, AppType::NetManager); } AppType::SysInfo => { compositor.open_window("Task Manager - Performance", 250, 70, 460, 320, AppType::SysInfo); } AppType::Calculator => { compositor.open_window("Calculator", 320, 90, 240, 280, AppType::Calculator); } AppType::Editor => { compositor.open_window("Text Editor - welcome.txt", 190, 60, 500, 340, AppType::Editor); } AppType::Settings => { compositor.open_window("System Settings", 220, 80, 460, 300, AppType::Settings); } AppType::Snake => { compositor.open_window("Retro Snake - Arcade", 240, 70, 375, 340, AppType::Snake); } AppType::SnapStore => { compositor.open_window("Snap Store - Software Center", 150, 50, 520, 370, AppType::SnapStore); } } } pub fn render(&self, surface: &mut Surface, compositor: &mut Compositor) { // 1. Desktop Wallpaper render_wallpaper(surface); // 2. Desktop Icons (Left column, authentic Windows 11 style) // Shortcut 1: This PC surface.draw_rounded_rect(20, 20, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::ThisPc, 42, 28, Color::rgb(0, 164, 239)); surface.draw_text_with_shadow("This PC", 28, 56, Color::WHITE, Color::BLACK); // Shortcut 2: Snap Store surface.draw_rounded_rect(20, 90, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::OsLogo, 42, 98, Color::rgb(233, 84, 32)); surface.draw_text_with_shadow("SnapStore", 22, 126, Color::WHITE, Color::BLACK); // Shortcut 3: Terminal surface.draw_rounded_rect(20, 160, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::Terminal, 42, 168, Color::ACCENT_CYAN); surface.draw_text_with_shadow("Terminal", 24, 196, Color::WHITE, Color::BLACK); // Shortcut 4: Network surface.draw_rounded_rect(20, 230, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::Network, 42, 238, Color::rgb(0, 120, 215)); surface.draw_text_with_shadow("Network", 26, 266, Color::WHITE, Color::BLACK); // Shortcut 5: Task Manager surface.draw_rounded_rect(20, 300, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::TaskManager, 42, 308, Color::rgb(16, 124, 65)); surface.draw_text_with_shadow("Activity", 26, 336, Color::WHITE, Color::BLACK); // Shortcut 6: Snake Game surface.draw_rounded_rect(20, 370, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::TaskManager, 42, 378, Color::rgb(177, 70, 194)); surface.draw_text_with_shadow("Snake", 30, 406, Color::WHITE, Color::BLACK); // Shortcut 7: Text Editor surface.draw_rounded_rect(20, 440, 60, 56, 8, Color::rgba(255, 255, 255, 10)); surface.draw_icon_16(IconType::Editor, 42, 448, Color::rgb(0, 153, 188)); surface.draw_text_with_shadow("Notes", 32, 476, Color::WHITE, Color::BLACK); // 3. Render Windows compositor.render(surface); // 4. Render Windows 11 Taskbar at bottom render_taskbar(surface, compositor); // 5. Render Start Menu (if opened) if self.start_menu_open { start_menu::render_start_menu(surface); } } }