feat: initial low-level foundation for Gastinel Desktop (offline Rust + Vulkan)
Cette révision appartient à :
révision
a6d090fedd
32 fichiers modifiés
+2385
Aucun fichier ne correspond à votre recherche
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "gastinel-shell"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
gastinel-core = { path = "../gastinel-core" }
|
||||
@@ -0,0 +1,163 @@
|
||||
//! Spotlight-style fast application search and command launcher.
|
||||
//!
|
||||
//! Instant popup, fuzzy matching, and keyboard navigation.
|
||||
|
||||
use gastinel_core::geom::{Rect, Size};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppEntry {
|
||||
pub name: String,
|
||||
pub exec: String,
|
||||
pub comment: String,
|
||||
}
|
||||
|
||||
pub struct Launcher {
|
||||
pub visible: bool,
|
||||
pub bounds: Rect,
|
||||
pub query: String,
|
||||
pub entries: Vec<AppEntry>,
|
||||
pub filtered_indices: Vec<usize>,
|
||||
pub selected_index: usize,
|
||||
}
|
||||
|
||||
impl Launcher {
|
||||
pub const WIDTH: u32 = 640;
|
||||
pub const HEIGHT: u32 = 420;
|
||||
|
||||
pub fn new(screen_size: Size) -> Self {
|
||||
let x = (screen_size.width.saturating_sub(Self::WIDTH) / 2) as i32;
|
||||
let y = (screen_size.height.saturating_sub(Self::HEIGHT) / 3) as i32; // slightly above center
|
||||
|
||||
Self {
|
||||
visible: false,
|
||||
bounds: Rect::new(x, y, Self::WIDTH, Self::HEIGHT),
|
||||
query: String::with_capacity(64),
|
||||
entries: Vec::new(),
|
||||
filtered_indices: Vec::with_capacity(32),
|
||||
selected_index: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recalculate_position(&mut self, screen_size: Size) {
|
||||
self.bounds.x = (screen_size.width.saturating_sub(Self::WIDTH) / 2) as i32;
|
||||
self.bounds.y = (screen_size.height.saturating_sub(Self::HEIGHT) / 3) as i32;
|
||||
}
|
||||
|
||||
pub fn toggle(&mut self) {
|
||||
self.visible = !self.visible;
|
||||
if self.visible {
|
||||
self.query.clear();
|
||||
self.refilter();
|
||||
self.selected_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn open(&mut self) {
|
||||
self.visible = true;
|
||||
self.query.clear();
|
||||
self.refilter();
|
||||
self.selected_index = 0;
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
self.visible = false;
|
||||
self.query.clear();
|
||||
}
|
||||
|
||||
pub fn add_app(&mut self, name: &str, exec: &str, comment: &str) {
|
||||
self.entries.push(AppEntry {
|
||||
name: name.to_string(),
|
||||
exec: exec.to_string(),
|
||||
comment: comment.to_string(),
|
||||
});
|
||||
self.refilter();
|
||||
}
|
||||
|
||||
pub fn insert_char(&mut self, c: char) {
|
||||
self.query.push(c);
|
||||
self.refilter();
|
||||
self.selected_index = 0;
|
||||
}
|
||||
|
||||
pub fn backspace(&mut self) {
|
||||
self.query.pop();
|
||||
self.refilter();
|
||||
self.selected_index = 0;
|
||||
}
|
||||
|
||||
pub fn select_next(&mut self) {
|
||||
if !self.filtered_indices.is_empty() {
|
||||
self.selected_index = (self.selected_index + 1) % self.filtered_indices.len();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_prev(&mut self) {
|
||||
if !self.filtered_indices.is_empty() {
|
||||
if self.selected_index == 0 {
|
||||
self.selected_index = self.filtered_indices.len() - 1;
|
||||
} else {
|
||||
self.selected_index -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selected_entry(&self) -> Option<&AppEntry> {
|
||||
let idx = *self.filtered_indices.get(self.selected_index)?;
|
||||
self.entries.get(idx)
|
||||
}
|
||||
|
||||
/// Fast, zero-allocation fuzzy matching
|
||||
fn refilter(&mut self) {
|
||||
self.filtered_indices.clear();
|
||||
|
||||
if self.query.is_empty() {
|
||||
for i in 0..self.entries.len() {
|
||||
self.filtered_indices.push(i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let query_lower = self.query.to_lowercase();
|
||||
|
||||
for (i, entry) in self.entries.iter().enumerate() {
|
||||
let name_lower = entry.name.to_lowercase();
|
||||
if fuzzy_match(&name_lower, &query_lower) {
|
||||
self.filtered_indices.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Simple sub-sequence fuzzy search: returns true if all query chars appear in sequence
|
||||
fn fuzzy_match(target: &str, query: &str) -> bool {
|
||||
let mut target_chars = target.chars();
|
||||
for qc in query.chars() {
|
||||
match target_chars.find(|&tc| tc == qc) {
|
||||
Some(_) => continue,
|
||||
None => return false,
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_launcher_filter() {
|
||||
let mut launcher = Launcher::new(Size::new(1920, 1080));
|
||||
launcher.add_app("Firefox", "firefox", "Web Browser");
|
||||
launcher.add_app("Alacritty", "alacritty", "Terminal Emulator");
|
||||
launcher.add_app("Foot", "foot", "Lightweight Wayland Terminal");
|
||||
|
||||
launcher.open();
|
||||
assert_eq!(launcher.filtered_indices.len(), 3);
|
||||
|
||||
launcher.insert_char('f');
|
||||
launcher.insert_char('i');
|
||||
launcher.insert_char('r');
|
||||
assert_eq!(launcher.filtered_indices.len(), 1);
|
||||
assert_eq!(launcher.selected_entry().unwrap().name, "Firefox");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
//! Embedded Desktop Shell: TopBar, Spotlight Launcher, Workspaces, and Window Management.
|
||||
|
||||
pub mod launcher;
|
||||
pub mod topbar;
|
||||
pub mod workspace;
|
||||
|
||||
pub use launcher::{AppEntry, Launcher};
|
||||
pub use topbar::TopBar;
|
||||
pub use workspace::{Window, WorkspaceManager};
|
||||
@@ -0,0 +1,69 @@
|
||||
//! Embedded TopBar / Status bar for Gastinel Desktop.
|
||||
|
||||
use gastinel_core::geom::{Point, Rect};
|
||||
|
||||
pub struct TopBar {
|
||||
pub bounds: Rect,
|
||||
pub height: u32,
|
||||
pub active_workspace: u32,
|
||||
pub workspace_count: u32,
|
||||
pub current_time_str: String,
|
||||
pub ram_used_mb: u64,
|
||||
pub ram_total_mb: u64,
|
||||
}
|
||||
|
||||
impl TopBar {
|
||||
pub const DEFAULT_HEIGHT: u32 = 32;
|
||||
|
||||
pub fn new(screen_width: u32) -> Self {
|
||||
Self {
|
||||
bounds: Rect::new(0, 0, screen_width, Self::DEFAULT_HEIGHT),
|
||||
height: Self::DEFAULT_HEIGHT,
|
||||
active_workspace: 1,
|
||||
workspace_count: 5,
|
||||
current_time_str: String::from("00:00"),
|
||||
ram_used_mb: 0,
|
||||
ram_total_mb: 8192,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resize(&mut self, screen_width: u32) {
|
||||
self.bounds.width = screen_width;
|
||||
}
|
||||
|
||||
pub fn update_time(&mut self, time_str: &str) {
|
||||
self.current_time_str.clear();
|
||||
self.current_time_str.push_str(time_str);
|
||||
}
|
||||
|
||||
pub fn update_memory(&mut self, used_mb: u64, total_mb: u64) {
|
||||
self.ram_used_mb = used_mb;
|
||||
self.ram_total_mb = total_mb;
|
||||
}
|
||||
|
||||
pub fn set_active_workspace(&mut self, ws: u32) {
|
||||
self.active_workspace = ws;
|
||||
}
|
||||
|
||||
/// Hit-test: checks if a point clicks on a workspace button (returns Some(workspace_id))
|
||||
pub fn hit_test_workspace(&self, p: Point) -> Option<u32> {
|
||||
if !self.bounds.contains(p) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Workspace buttons on the left
|
||||
let start_x = 10;
|
||||
let btn_width = 30;
|
||||
let spacing = 6;
|
||||
|
||||
for i in 1..=self.workspace_count {
|
||||
let x = start_x + ((i - 1) as i32) * (btn_width + spacing);
|
||||
let rect = Rect::new(x, 4, btn_width as u32, self.height - 8);
|
||||
if rect.contains(p) {
|
||||
return Some(i);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
//! Workspaces and Window Management for Gastinel Desktop.
|
||||
|
||||
use gastinel_core::geom::Rect;
|
||||
use gastinel_core::mem::{Handle, Pool};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Window {
|
||||
pub title: String,
|
||||
pub geometry: Rect,
|
||||
pub workspace_id: u32,
|
||||
pub is_focused: bool,
|
||||
pub is_minimized: bool,
|
||||
pub is_fullscreen: bool,
|
||||
}
|
||||
|
||||
pub struct WorkspaceManager {
|
||||
pub active_workspace: u32,
|
||||
pub workspace_count: u32,
|
||||
pub windows: Pool<Window>,
|
||||
pub focused_window: Option<Handle<Window>>,
|
||||
}
|
||||
|
||||
impl WorkspaceManager {
|
||||
pub fn new(workspace_count: u32) -> Self {
|
||||
Self {
|
||||
active_workspace: 1,
|
||||
workspace_count,
|
||||
windows: Pool::with_capacity(32),
|
||||
focused_window: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_window(&mut self, title: &str, geometry: Rect) -> Handle<Window> {
|
||||
let win = Window {
|
||||
title: title.to_string(),
|
||||
geometry,
|
||||
workspace_id: self.active_workspace,
|
||||
is_focused: true,
|
||||
is_minimized: false,
|
||||
is_fullscreen: false,
|
||||
};
|
||||
|
||||
let handle = self.windows.insert(win);
|
||||
self.set_focus(Some(handle));
|
||||
handle
|
||||
}
|
||||
|
||||
pub fn destroy_window(&mut self, handle: Handle<Window>) -> Option<Window> {
|
||||
if self.focused_window == Some(handle) {
|
||||
self.focused_window = None;
|
||||
}
|
||||
self.windows.remove(handle)
|
||||
}
|
||||
|
||||
pub fn set_focus(&mut self, handle: Option<Handle<Window>>) {
|
||||
if let Some(prev) = self.focused_window {
|
||||
if let Some(win) = self.windows.get_mut(prev) {
|
||||
win.is_focused = false;
|
||||
}
|
||||
}
|
||||
|
||||
self.focused_window = handle;
|
||||
|
||||
if let Some(curr) = handle {
|
||||
if let Some(win) = self.windows.get_mut(curr) {
|
||||
win.is_focused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn switch_workspace(&mut self, ws: u32) {
|
||||
if ws >= 1 && ws <= self.workspace_count {
|
||||
self.active_workspace = ws;
|
||||
|
||||
// Pick a focused window in this workspace if any
|
||||
let new_focus = self
|
||||
.windows
|
||||
.iter()
|
||||
.find(|(_, win)| win.workspace_id == ws && !win.is_minimized)
|
||||
.map(|(h, _)| h);
|
||||
|
||||
self.set_focus(new_focus);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_window_to_workspace(&mut self, handle: Handle<Window>, ws: u32) {
|
||||
if let Some(win) = self.windows.get_mut(handle) {
|
||||
win.workspace_id = ws;
|
||||
if self.active_workspace != ws && self.focused_window == Some(handle) {
|
||||
self.focused_window = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterates over all visible windows on the active workspace.
|
||||
pub fn visible_windows(&self) -> impl Iterator<Item = (Handle<Window>, &Window)> {
|
||||
let active = self.active_workspace;
|
||||
self.windows
|
||||
.iter()
|
||||
.filter(move |(_, win)| win.workspace_id == active && !win.is_minimized)
|
||||
}
|
||||
}
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur