random lockscreen message, remove rand dep for audio player, add version to about window, add o/O to malvim, add circles to draw, bug fixes, minor byte savings for font .alpha format
This commit is contained in:
stjet
2025-08-18 17:27:16 +00:00
parent 2c4455f623
commit 08c2358bdc
20 changed files with 135 additions and 70 deletions

View File

@@ -2,13 +2,13 @@ use std::vec::Vec;
use std::vec;
use std::io::BufReader;
use std::path::PathBuf;
use std::collections::HashMap;
use std::fs::{ read_to_string, File };
use std::time::{ Duration, SystemTime, UNIX_EPOCH };
use std::thread;
use std::sync::{ Arc, Mutex };
use rodio::{ Decoder, OutputStream, Sink, Source };
use rand::{ SeedableRng, prelude::SliceRandom, rngs::SmallRng };
use id3::TagLike;
use mp4ameta;
use metaflac;
@@ -17,7 +17,7 @@ use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLik
use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest, ShortcutType };
use ming_wm_lib::framebuffer_types::Dimensions;
use ming_wm_lib::themes::ThemeInfo;
use ming_wm_lib::utils::{ concat_paths, get_all_files, path_autocomplete, format_seconds, Substring };
use ming_wm_lib::utils::{ concat_paths, random_u32, get_all_files, path_autocomplete, format_seconds, Substring };
use ming_wm_lib::dirs::home;
use ming_wm_lib::ipc::listen;
@@ -253,8 +253,13 @@ impl AudioPlayer {
} else {
get_all_files(PathBuf::from(new_path))
};
let mut rng = SmallRng::seed_from_u64(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs());
queue.shuffle(&mut rng);
let mut seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().subsec_millis();
let mut q_weights: HashMap<PathBuf, u32> = HashMap::new();
for q in &queue {
seed = random_u32(seed);
q_weights.insert(q.to_path_buf(), seed);
}
queue.sort_by(|a, b| q_weights[a].cmp(&q_weights[b]));
if self.command.starts_with("p ") {
let mut locked_internal = self.internal.lock().unwrap();
(*locked_internal).sink.clear();

View File

@@ -11,7 +11,7 @@ use ming_wm_lib::ipc::listen;
enum DrawAction {
Line(Point, Option<Point>, usize, RGBColor),
Rect(Point, Option<Dimensions>, RGBColor),
//
Circle(Point, Option<usize>, RGBColor),
}
impl DrawAction {
@@ -19,6 +19,7 @@ impl DrawAction {
match self {
DrawAction::Line(_, _, _, _) => "Line",
DrawAction::Rect(_, _, _) => "Rect",
DrawAction::Circle(_, _, _) => "Circle",
}.to_string()
}
}
@@ -49,6 +50,10 @@ impl WindowLike for Draw {
self.dimensions = dimensions;
WindowMessageResponse::JustRedraw
},
WindowMessage::ChangeDimensions(dimensions) => {
self.dimensions = dimensions;
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
if key_press.is_escape() && (self.current_action.is_some() || self.mode != Mode::Move) {
self.current_action = None;
@@ -69,7 +74,10 @@ impl WindowLike for Draw {
"rect" | "r" => {
self.current_action = Some(DrawAction::Rect(self.current_location, None, self.current_color));
},
"colour" | "color" | "c" => {
"circle" | "c" => {
self.current_action = Some(DrawAction::Circle(self.current_location, None, self.current_color));
},
"colour" | "color" | "co" => {
//hex to u8
if let Some(hex_color) = parts.next() {
if hex_color.len() == 6 && hex_color.chars().all(|c| HEX_CHARS.contains(&c)) {
@@ -135,6 +143,10 @@ impl WindowLike for Draw {
];
DrawAction::Rect(tl, Some(d), *r)
},
DrawAction::Circle(p, _, c) => {
let r = ((self.current_location[1] as f64 - p[1] as f64).powi(2) + (self.current_location[0] as f64 - p[0] as f64).powi(2)).sqrt();
DrawAction::Circle(*p, Some(r.round() as usize), *c)
},
});
self.current_action = None;
WindowMessageResponse::JustRedraw
@@ -184,6 +196,7 @@ impl WindowLike for Draw {
instructions.push(match action {
DrawAction::Line(p1, p2, lw, c) => DrawInstructions::Line(*p1, p2.unwrap(), *lw, *c),
DrawAction::Rect(p, d, c) => DrawInstructions::Rect(*p, d.unwrap(), *c),
DrawAction::Circle(p, r, c) => DrawInstructions::Circle(*p, r.unwrap(), *c),
});
}
//draw cursor (crosshair)
@@ -220,6 +233,10 @@ impl WindowLike for Draw {
fn ideal_dimensions(&self, _dimensions: Dimensions) -> Dimensions {
[410, 410]
}
fn resizable(&self) -> bool {
true
}
}
impl Draw {

View File

@@ -9,7 +9,7 @@ use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse, WindowManager
use ming_wm_lib::themes::ThemeInfo;
use ming_wm_lib::framebuffer_types::Dimensions;
use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLikeType };
use ming_wm_lib::utils::{ calc_actual_lines, calc_new_cursor_pos, Substring };
use ming_wm_lib::utils::{ calc_actual_lines, Substring };
use ming_wm_lib::dirs::home;
use ming_wm_lib::utils::{ get_rest_of_split, path_autocomplete };
use ming_wm_lib::ipc::listen;
@@ -103,10 +103,22 @@ impl WindowLike for Malvim {
self.mode = Mode::Command;
self.command = Some(String::new());
changed = false;
} else if (key_press.key == 'i' || key_press.key == 'A') && self.mode == Mode::Normal && self.state == State::None && self.files.len() > 0 {
} else if (key_press.key == 'i' || key_press.key == 'A' || key_press.key == 'o' || key_press.key == 'O') && self.mode == Mode::Normal && self.state == State::None && self.files.len() > 0 {
let current_file = &mut self.files[self.current_file_index];
if key_press.key == 'A' {
let current_file = &mut self.files[self.current_file_index];
current_file.cursor_pos = current_file.content[current_file.line_pos].chars().count();
} else if key_press.key == 'o' || key_press.key == 'O' {
let current_line = &current_file.content[current_file.line_pos];
let spaces = Malvim::calc_spaces(self.autoindent, current_line);
let n = if key_press.key == 'o' {
current_file.line_pos + 1
} else {
current_file.line_pos
};
current_file.content.insert(n, " ".repeat(spaces));
current_file.line_pos = n;
current_file.cursor_pos = spaces;
new = true;
}
self.mode = Mode::Insert;
changed = false;
@@ -120,20 +132,7 @@ impl WindowLike for Malvim {
let left = left.into_iter().map(|c| c.to_string()).collect::<Vec<String>>().join("");
let right = right.into_iter().map(|c| c.to_string()).collect::<Vec<String>>().join("");
current_file.content[current_file.line_pos] = left.to_string();
let spaces = if self.autoindent {
//find out how many spaces the line starts with, copy that to the new line
let mut spaces = 0;
for c in left.chars() {
if c == ' ' {
spaces += 1;
} else {
break;
}
}
spaces
} else {
0
};
let spaces = Malvim::calc_spaces(self.autoindent, &left);
current_file.content.insert(current_file.line_pos + 1, " ".repeat(spaces) + &right);
current_file.line_pos += 1;
current_file.cursor_pos = spaces;
@@ -178,7 +177,7 @@ impl WindowLike for Malvim {
}
}
let new_length = current_file.content[current_file.line_pos].chars().count();
current_file.cursor_pos = calc_new_cursor_pos(current_file.cursor_pos, new_length);
current_file.cursor_pos = Malvim::calc_new_cursor_pos(current_file.cursor_pos, new_length);
} else if key_press.key == 'w' || key_press.key == '$' {
let line = &current_file.content[current_file.line_pos];
let line_len = line.chars().count();
@@ -198,7 +197,7 @@ impl WindowLike for Malvim {
};
current_file.content[current_file.line_pos] = line.remove(current_file.cursor_pos, offset);
let new_length = current_file.content[current_file.line_pos].chars().count();
current_file.cursor_pos = calc_new_cursor_pos(current_file.cursor_pos, new_length);
current_file.cursor_pos = Malvim::calc_new_cursor_pos(current_file.cursor_pos, new_length);
}
}
self.state = State::None;
@@ -209,7 +208,7 @@ impl WindowLike for Malvim {
current_file.line_pos = current_file.content.len() - 1;
}
let new_length = current_file.content[current_file.line_pos].chars().count();
current_file.cursor_pos = calc_new_cursor_pos(current_file.cursor_pos, new_length);
current_file.cursor_pos = Malvim::calc_new_cursor_pos(current_file.cursor_pos, new_length);
}
changed = false;
self.state = State::None;
@@ -265,7 +264,7 @@ impl WindowLike for Malvim {
current_file.line_pos = current_file.line_pos.checked_sub(self.maybe_num.unwrap_or(1)).unwrap_or(0);
}
let new_length = current_file.content[current_file.line_pos].chars().count();
current_file.cursor_pos = calc_new_cursor_pos(current_file.cursor_pos, new_length);
current_file.cursor_pos = Malvim::calc_new_cursor_pos(current_file.cursor_pos, new_length);
changed = false;
} else if key_press.key == 'l' || key_press.is_right_arrow() {
if current_length > 0 {
@@ -298,7 +297,7 @@ impl WindowLike for Malvim {
} else if key_press.key == 'G' {
current_file.line_pos = current_file.content.len() - 1;
let new_length = current_file.content[current_file.line_pos].chars().count();
current_file.cursor_pos = calc_new_cursor_pos(current_file.cursor_pos, new_length);
current_file.cursor_pos = Malvim::calc_new_cursor_pos(current_file.cursor_pos, new_length);
changed = false;
} else if key_press.key == 'f' {
self.state = State::Find;
@@ -424,7 +423,7 @@ impl WindowLike for Malvim {
}
} else if key_press.is_backspace() {
if command.len() > 0 {
self.command = Some(command[..command.len() - 1].to_string());
self.command = Some(command.remove_last());
}
} else {
self.command = Some(command.to_string() + &key_press.key.to_string());
@@ -594,6 +593,34 @@ impl Malvim {
Default::default()
}
fn calc_spaces(autoindent: bool, left: &str) -> usize {
if autoindent {
let mut spaces = 0;
for c in left.chars() {
if c == ' ' {
spaces += 1;
} else {
break;
}
}
spaces
} else {
0
}
}
fn calc_new_cursor_pos(cursor_pos: usize, new_length: usize) -> usize {
if cursor_pos >= new_length {
if new_length == 0 {
0
} else {
new_length - 1
}
} else {
cursor_pos
}
}
fn calc_top_line_pos(&mut self) {
if self.files.len() == 0 {
return;

View File

@@ -7,7 +7,7 @@ use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLik
use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse };
use ming_wm_lib::framebuffer_types::Dimensions;
use ming_wm_lib::themes::ThemeInfo;
use ming_wm_lib::utils::{ u8_to_hex, hex_to_u8, HEX_CHARS };
use ming_wm_lib::utils::{ random_u32, u8_to_hex, hex_to_u8, HEX_CHARS };
use ming_wm_lib::ipc::listen;
//16x16 with 40 mines
@@ -252,11 +252,7 @@ impl Minesweeper {
//https://en.wikipedia.org/wiki/Xorshift
//from 0 to 15
pub fn random(&mut self) -> usize {
let mut x = self.random_seed;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
self.random_seed = x;
self.random_seed = random_u32(self.random_seed);
self.random_seed as usize % 16
}

View File

@@ -72,7 +72,7 @@ fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) {
writer.init(framebuffer_info.clone());
let mut wm: WindowManager = WindowManager::new(writer, framebuffer, dimensions, rotate, grayscale, PASSWORD_HASH);
let mut wm: WindowManager = WindowManager::new(writer, framebuffer, dimensions, rotate, grayscale, env!("CARGO_PKG_VERSION").to_string(), PASSWORD_HASH);
let mut stdout = RawStdout::new(stdout());
stdout.enter_raw_mode().unwrap();
@@ -110,7 +110,6 @@ fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) {
//read touchscreen presses (hopefully)
thread::spawn(move || {
//spawn evtest, parse it for touch coords
if touch {
let mut events = Input::new("/dev/input/by-path/first-touchscreen").unwrap(); //panics in threads don't matter in this case
let mut x: Option<usize> = None;