separate windows out, IPCcargo run --release!
This commit is contained in:
44
src/essential/desktop_background.rs
Normal file
44
src/essential/desktop_background.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use std::vec;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, TASKBAR_HEIGHT, INDICATOR_HEIGHT };
|
||||
use crate::messages::{ WindowMessage, WindowMessageResponse };
|
||||
use crate::framebuffer::Dimensions;
|
||||
use crate::themes::ThemeInfo;
|
||||
|
||||
pub struct DesktopBackground {
|
||||
dimensions: Dimensions,
|
||||
}
|
||||
|
||||
impl WindowLike for DesktopBackground {
|
||||
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
|
||||
match message {
|
||||
WindowMessage::Init(dimensions) => {
|
||||
self.dimensions = dimensions;
|
||||
WindowMessageResponse::JustRerender
|
||||
},
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
}
|
||||
|
||||
//simple
|
||||
fn draw(&self, _theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
|
||||
vec![DrawInstructions::Rect([0, 0], self.dimensions, [0, 128, 128])]
|
||||
}
|
||||
|
||||
//properties
|
||||
fn subtype(&self) -> WindowLikeType {
|
||||
WindowLikeType::DesktopBackground
|
||||
}
|
||||
|
||||
fn ideal_dimensions(&self, dimensions: Dimensions) -> Dimensions {
|
||||
[dimensions[0], dimensions[1] - TASKBAR_HEIGHT - INDICATOR_HEIGHT]
|
||||
}
|
||||
}
|
||||
|
||||
impl DesktopBackground {
|
||||
pub fn new() -> Self {
|
||||
Self { dimensions: [0, 0] }
|
||||
}
|
||||
}
|
||||
|
||||
79
src/essential/lock_screen.rs
Normal file
79
src/essential/lock_screen.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use std::vec;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::framebuffer::Dimensions;
|
||||
use crate::themes::ThemeInfo;
|
||||
use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest };
|
||||
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType };
|
||||
use blake2::{ Blake2b512, Digest };
|
||||
|
||||
const PASSWORD_HASH: [u8; 64] = [220, 88, 183, 188, 240, 27, 107, 181, 58, 191, 198, 170, 114, 38, 7, 148, 6, 179, 75, 128, 231, 171, 172, 220, 85, 38, 36, 113, 116, 146, 70, 197, 163, 179, 158, 192, 130, 53, 247, 48, 47, 209, 95, 96, 179, 211, 4, 122, 254, 127, 21, 165, 139, 199, 151, 226, 216, 176, 123, 41, 194, 221, 58, 69];
|
||||
|
||||
pub struct LockScreen {
|
||||
dimensions: Dimensions,
|
||||
input_password: String,
|
||||
}
|
||||
|
||||
impl WindowLike for LockScreen {
|
||||
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
|
||||
match message {
|
||||
WindowMessage::Init(dimensions) => {
|
||||
self.dimensions = dimensions;
|
||||
WindowMessageResponse::JustRerender
|
||||
},
|
||||
WindowMessage::KeyPress(key_press) => {
|
||||
if key_press.key == '𐘂' { //the enter key
|
||||
//check password
|
||||
let mut hasher = Blake2b512::new();
|
||||
hasher.update(self.input_password.as_bytes());
|
||||
if hasher.finalize() == PASSWORD_HASH.into() {
|
||||
WindowMessageResponse::Request(WindowManagerRequest::Unlock)
|
||||
} else {
|
||||
self.input_password = String::new();
|
||||
WindowMessageResponse::JustRerender
|
||||
}
|
||||
} else if key_press.key == '𐘁' { //backspace
|
||||
let p_len = self.input_password.len();
|
||||
if p_len != 0 {
|
||||
self.input_password = self.input_password[..p_len - 1].to_string();
|
||||
}
|
||||
WindowMessageResponse::JustRerender
|
||||
} else {
|
||||
self.input_password += &key_press.key.to_string();
|
||||
WindowMessageResponse::JustRerender
|
||||
}
|
||||
},
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, _theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
|
||||
vec![
|
||||
DrawInstructions::Rect([0, 0], self.dimensions, [0, 0, 0]),
|
||||
DrawInstructions::Text([4, 4], "times-new-roman".to_string(), "The bulldozer outside the kitchen window was quite a big one.".to_string(), [255, 255, 255], [0, 0, 0], None, None),
|
||||
DrawInstructions::Text([4, 4 + 16], "times-new-roman".to_string(), "\"Yellow,\" he thought, and stomped off back to his bedroom to get dressed.".to_string(), [255, 255, 255], [0, 0, 0], None, None),
|
||||
DrawInstructions::Text([4, 4 + 16 * 2], "times-new-roman".to_string(), "He stared at it.".to_string(), [255, 255, 255], [0, 0, 0], None, None),
|
||||
DrawInstructions::Text([4, 4 + 16 * 3], "times-new-roman".to_string(), "Password: ".to_string(), [255, 255, 255], [0, 0, 0], None, None),
|
||||
DrawInstructions::Text([77, 4 + 16 * 3], "times-new-roman".to_string(), "*".repeat(self.input_password.len()), [255, 255, 255], [0, 0, 0], None, None),
|
||||
]
|
||||
}
|
||||
|
||||
//properties
|
||||
fn subtype(&self) -> WindowLikeType {
|
||||
WindowLikeType::LockScreen
|
||||
}
|
||||
|
||||
fn ideal_dimensions(&self, dimensions: Dimensions) -> Dimensions {
|
||||
dimensions //fullscreen
|
||||
}
|
||||
}
|
||||
|
||||
impl LockScreen {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
dimensions: [0, 0],
|
||||
input_password: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
src/essential/mod.rs
Normal file
5
src/essential/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub mod desktop_background;
|
||||
pub mod taskbar;
|
||||
pub mod lock_screen;
|
||||
pub mod workspace_indicator;
|
||||
|
||||
128
src/essential/taskbar.rs
Normal file
128
src/essential/taskbar.rs
Normal file
@@ -0,0 +1,128 @@
|
||||
use std::vec;
|
||||
use std::vec::Vec;
|
||||
use std::boxed::Box;
|
||||
|
||||
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, TASKBAR_HEIGHT };
|
||||
use crate::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest, ShortcutType, InfoType, WindowsVec };
|
||||
use crate::framebuffer::Dimensions;
|
||||
use crate::themes::ThemeInfo;
|
||||
use crate::components::Component;
|
||||
use crate::components::toggle_button::{ ToggleButton, ToggleButtonAlignment };
|
||||
|
||||
const PADDING: usize = 4;
|
||||
const META_WIDTH: usize = 175; //of the window button
|
||||
|
||||
#[derive(Clone)]
|
||||
enum TaskbarMessage {
|
||||
ShowStartMenu,
|
||||
HideStartMenu,
|
||||
Nothing,
|
||||
//
|
||||
}
|
||||
|
||||
pub struct Taskbar {
|
||||
dimensions: Dimensions,
|
||||
components: Vec<Box<dyn Component<TaskbarMessage> + Send>>,
|
||||
windows_in_workspace: WindowsVec,
|
||||
focused_id: usize,
|
||||
}
|
||||
|
||||
impl WindowLike for Taskbar {
|
||||
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
|
||||
match message {
|
||||
WindowMessage::Init(dimensions) => {
|
||||
self.dimensions = dimensions;
|
||||
self.components = vec![
|
||||
Box::new(ToggleButton::new("start-button".to_string(), [PADDING, PADDING], [44, self.dimensions[1] - (PADDING * 2)], "Start".to_string(), TaskbarMessage::ShowStartMenu, TaskbarMessage::HideStartMenu, false, Some(ToggleButtonAlignment::Left))),
|
||||
];
|
||||
WindowMessageResponse::JustRerender
|
||||
},
|
||||
WindowMessage::Shortcut(shortcut) => {
|
||||
match shortcut {
|
||||
ShortcutType::StartMenu => {
|
||||
let start_index = self.components.iter().position(|c| c.name() == "start-button").unwrap();
|
||||
let start_response = self.components[start_index].handle_message(WindowMessage::FocusClick);
|
||||
self.handle_taskbar_message(start_response)
|
||||
}
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
},
|
||||
WindowMessage::Info(info) => {
|
||||
match info {
|
||||
InfoType::WindowsInWorkspace(windows, focused_id) => {
|
||||
self.windows_in_workspace = windows;
|
||||
self.focused_id = focused_id;
|
||||
WindowMessageResponse::JustRerender
|
||||
}
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
},
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
}
|
||||
|
||||
//simple
|
||||
fn draw(&self, theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
|
||||
let mut instructions = vec![
|
||||
//top thin white border
|
||||
DrawInstructions::Rect([0, 0], [self.dimensions[0], 1], theme_info.border_left_top),
|
||||
//the actual taskbar background
|
||||
DrawInstructions::Rect([0, 1], [self.dimensions[0], self.dimensions[1] - 1], theme_info.background),
|
||||
];
|
||||
for component in &self.components {
|
||||
instructions.extend(component.draw(theme_info));
|
||||
}
|
||||
for wi in 0..self.windows_in_workspace.len() {
|
||||
//if too many windows to fit in taskbar...
|
||||
if wi > (self.dimensions[0] - 200) / META_WIDTH {
|
||||
//
|
||||
break;
|
||||
}
|
||||
let info = &self.windows_in_workspace[wi];
|
||||
let name = &info.1;
|
||||
let mut b = ToggleButton::new(name.to_string() + "-window", [PADDING * 2 + 44 + (META_WIDTH + PADDING) * wi, PADDING], [META_WIDTH, self.dimensions[1] - (PADDING * 2)], name.to_string(), TaskbarMessage::Nothing, TaskbarMessage::Nothing, false, Some(ToggleButtonAlignment::Left));
|
||||
b.inverted = info.0 == self.focused_id;
|
||||
instructions.extend(b.draw(theme_info));
|
||||
}
|
||||
instructions
|
||||
}
|
||||
|
||||
//properties
|
||||
fn subtype(&self) -> WindowLikeType {
|
||||
WindowLikeType::Taskbar
|
||||
}
|
||||
|
||||
fn ideal_dimensions(&self, dimensions: Dimensions) -> Dimensions {
|
||||
[dimensions[0], TASKBAR_HEIGHT]
|
||||
}
|
||||
}
|
||||
|
||||
impl Taskbar {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
dimensions: [0, 0],
|
||||
components: Vec::new(),
|
||||
windows_in_workspace: Vec::new(),
|
||||
focused_id: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_taskbar_message(&mut self, message: Option<TaskbarMessage>) -> WindowMessageResponse {
|
||||
if let Some(message) = message {
|
||||
match message {
|
||||
TaskbarMessage::ShowStartMenu => {
|
||||
WindowMessageResponse::Request(WindowManagerRequest::OpenWindow("StartMenu".to_string()))
|
||||
},
|
||||
TaskbarMessage::HideStartMenu => {
|
||||
WindowMessageResponse::Request(WindowManagerRequest::CloseStartMenu)
|
||||
},
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
} else {
|
||||
//maybe should be JustRerender?
|
||||
WindowMessageResponse::DoNothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
74
src/essential/workspace_indicator.rs
Normal file
74
src/essential/workspace_indicator.rs
Normal file
@@ -0,0 +1,74 @@
|
||||
use std::vec;
|
||||
use std::vec::Vec;
|
||||
|
||||
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, INDICATOR_HEIGHT };
|
||||
use crate::messages::{ WindowMessage, WindowMessageResponse, ShortcutType };
|
||||
use crate::framebuffer::Dimensions;
|
||||
use crate::themes::ThemeInfo;
|
||||
|
||||
const WIDTH: usize = 15;
|
||||
|
||||
pub struct WorkspaceIndicator {
|
||||
dimensions: Dimensions,
|
||||
current_workspace: u8,
|
||||
}
|
||||
|
||||
impl WindowLike for WorkspaceIndicator {
|
||||
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
|
||||
match message {
|
||||
WindowMessage::Init(dimensions) => {
|
||||
self.dimensions = dimensions;
|
||||
WindowMessageResponse::JustRerender
|
||||
},
|
||||
WindowMessage::Shortcut(shortcut) => {
|
||||
match shortcut {
|
||||
ShortcutType::SwitchWorkspace(workspace) => {
|
||||
self.current_workspace = workspace;
|
||||
WindowMessageResponse::JustRerender
|
||||
}
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
},
|
||||
_ => WindowMessageResponse::DoNothing,
|
||||
}
|
||||
}
|
||||
|
||||
//simple
|
||||
fn draw(&self, theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
|
||||
let mut instructions = vec![
|
||||
//background
|
||||
DrawInstructions::Rect([0, 0], [self.dimensions[0], self.dimensions[1] - 1], theme_info.background),
|
||||
//bottom border
|
||||
DrawInstructions::Rect([0, self.dimensions[1] - 1], [self.dimensions[0], 1], theme_info.border_right_bottom),
|
||||
];
|
||||
for w in 0..9 {
|
||||
if w == self.current_workspace as usize {
|
||||
instructions.push(DrawInstructions::Rect([w * WIDTH, 0], [WIDTH, self.dimensions[1]], theme_info.top));
|
||||
instructions.push(DrawInstructions::Text([w * WIDTH + 5, 4], "times-new-roman".to_string(), (w + 1).to_string(), theme_info.top_text, theme_info.top, None, None));
|
||||
} else {
|
||||
instructions.push(DrawInstructions::Text([w * WIDTH + 5, 4], "times-new-roman".to_string(), (w + 1).to_string(), theme_info.text, theme_info.background, None, None));
|
||||
}
|
||||
}
|
||||
instructions
|
||||
}
|
||||
|
||||
//properties
|
||||
fn subtype(&self) -> WindowLikeType {
|
||||
WindowLikeType::WorkspaceIndicator
|
||||
}
|
||||
|
||||
fn ideal_dimensions(&self, dimensions: Dimensions) -> Dimensions {
|
||||
[dimensions[0], INDICATOR_HEIGHT]
|
||||
}
|
||||
}
|
||||
|
||||
impl WorkspaceIndicator {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
dimensions: [0, 0],
|
||||
current_workspace: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user