Files
ming-wm/src/essential/desktop_background.rs
stjet 1a5eba7191 major usability improvements
Terminal now modal, supports line buffering, stdin, because it uses pty (and threading). Also supports paste, again (?). Audio player queueing no longer blocks, supports appending. Now can change window size. Halfscreen window shortcut improved. Eliminate dirs dep, deconstruct audiotags dep, better feature flags. Remove .alpha files because they are built. Use /home/jondough for default dirs if possible. Themes config. Fix for rotated touchscreen. Write more docs
2025-02-28 03:03:09 +00:00

82 lines
2.8 KiB
Rust

use std::vec;
use std::vec::Vec;
use std::fs::File;
use std::io::Read;
use crate::window_manager::{ DrawInstructions, WindowLike, WindowLikeType, TASKBAR_HEIGHT, INDICATOR_HEIGHT };
use crate::messages::{ WindowMessage, WindowMessageResponse, ShortcutType };
use crate::framebuffer::Dimensions;
use crate::themes::ThemeInfo;
use crate::utils::{ hex_to_u8, is_hex };
use crate::dirs::config_dir;
pub struct DesktopBackground {
dimensions: Dimensions,
current_workspace: u8,
}
impl WindowLike for DesktopBackground {
fn handle_message(&mut self, message: WindowMessage) -> WindowMessageResponse {
match message {
WindowMessage::Init(dimensions) => {
self.dimensions = dimensions;
WindowMessageResponse::JustRedraw
},
WindowMessage::Shortcut(shortcut) => {
match shortcut {
ShortcutType::SwitchWorkspace(workspace) => {
self.current_workspace = workspace;
WindowMessageResponse::JustRedraw
},
_ => WindowMessageResponse::DoNothing,
}
},
_ => WindowMessageResponse::DoNothing,
}
}
//simple
fn draw(&self, _theme_info: &ThemeInfo) -> Vec<DrawInstructions> {
if let Ok(mut file) = File::open(format!("{}/ming-wm/desktop-background", config_dir().unwrap().into_os_string().into_string().unwrap())) {
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
let lines: Vec<&str> = contents.split("\n").collect();
if lines.len() > self.current_workspace.into() {
let line = lines[self.current_workspace as usize];
if line.starts_with("#") && line.len() == 7 {
let line_hex = &line[1..];
//if all characters are valid hex
if line_hex.find(|c| !is_hex(c)).is_none() {
let mut chars = line_hex.chars();
let color = [hex_to_u8(chars.next().unwrap(), chars.next().unwrap()), hex_to_u8(chars.next().unwrap(), chars.next().unwrap()), hex_to_u8(chars.next().unwrap(), chars.next().unwrap())];
return vec![DrawInstructions::Rect([0, 0], self.dimensions, color)];
}
} else if line.len() > 1 {
//first character of line is either r or any other character, but is not part of the path
return vec![DrawInstructions::Bmp([0, 0], line[1..].to_string(), line.chars().next().unwrap() == 'r')];
}
}
}
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],
current_workspace: 0,
}
}
}