diff --git a/Cargo.toml b/Cargo.toml index 889c445..abd30d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ members = [ "wm", "wm/linux" ] [build-dependencies] bmp-rust = "0.5.0" -blake2 = { version = "0.10.6", default-features = false } +bitcoin_hashes = { version = "0.16.0", default-features = false } [dependencies] ming-wm-lib = { path = "ming-wm-lib" } diff --git a/bmps/ming1440x842.bmp b/bmps/ming1440x842.bmp deleted file mode 100644 index 1b4d34f..0000000 Binary files a/bmps/ming1440x842.bmp and /dev/null differ diff --git a/bmps/nimbus-romono/C0.bmp b/bmps/nimbus-romono/C0.bmp index ada45ba..50a5926 100644 Binary files a/bmps/nimbus-romono/C0.bmp and b/bmps/nimbus-romono/C0.bmp differ diff --git a/bmps/nimbus-romono/D0.bmp b/bmps/nimbus-romono/D0.bmp index c4f25c6..7077712 100644 Binary files a/bmps/nimbus-romono/D0.bmp and b/bmps/nimbus-romono/D0.bmp differ diff --git a/build.rs b/build.rs index 9f598a4..825ba13 100644 --- a/build.rs +++ b/build.rs @@ -4,7 +4,7 @@ use std::env; use std::path::Path; use std::process::Command; -use blake2::{ Blake2b512, Digest }; +use bitcoin_hashes::Sha512; use bmp_rust::bmp::BMP; fn font_chars_to_alphas(dir: &str) { @@ -47,12 +47,11 @@ fn font_chars_to_alphas(dir: &str) { fn main() { //hash + "salt" password and add to build - let password = read_to_string("password.env").unwrap_or("password".to_string()).replace("\n", "") + "salt?sorrycryptographers"; - let mut hasher = Blake2b512::new(); - hasher.update(password.as_bytes()); + let password = read_to_string("password.env").unwrap_or("password".to_string()).replace("\n", "") + "salt?sorrycryptographers!1!"; + let hash = Sha512::hash(password.as_bytes()).to_byte_array(); let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("password.rs"); - write(&dest_path, format!("pub const PASSWORD_HASH: [u8; 64] = {:?};", hasher.finalize())).unwrap(); + write(&dest_path, format!("pub const PASSWORD_HASH: [u8; 64] = {:?};", hash)).unwrap(); //process bmps for entry in read_dir("./bmps").unwrap() { let path = entry.unwrap().path(); diff --git a/src/bin/audio_player.rs b/src/bin/audio_player.rs index e560293..5c3101a 100644 --- a/src/bin/audio_player.rs +++ b/src/bin/audio_player.rs @@ -109,8 +109,10 @@ impl WindowLike for AudioPlayer { } else { return WindowMessageResponse::DoNothing; } - } else { + } else if key_press.is_regular() { self.command += &key_press.key.to_string(); + } else { + return WindowMessageResponse::DoNothing } WindowMessageResponse::JustRedraw }, diff --git a/src/bin/terminal.rs b/src/bin/terminal.rs index c87f249..912e8bc 100644 --- a/src/bin/terminal.rs +++ b/src/bin/terminal.rs @@ -150,6 +150,9 @@ impl WindowLike for Terminal { } else if char::from(ci) == '\r' { //for now, ignore // + } else if char::from(ci) == '\t' { + //for now, ignore + // } else { self.process_current_line.push(ci); } diff --git a/src/bin/wm.rs b/src/bin/wm.rs index b639d13..4327cdc 100644 --- a/src/bin/wm.rs +++ b/src/bin/wm.rs @@ -6,12 +6,9 @@ use std::io::{ stdin, stdout, BufReader, BufRead, Write }; use std::process::exit; use std::env; -//termion is an external dep, will be removed eventually -use wm::termion::input::TermRead; -use wm::termion::event::Key; - use wm::linux::fb::Framebuffer; use wm::linux::raw::RawStdout; +use wm::linux::keys::{ RawStdin, Key }; use wm::framebuffer::{ FramebufferWriter, FramebufferInfo }; use wm::window_manager::WindowManager; @@ -34,10 +31,10 @@ fn key_to_char(key: Key) -> Option { Key::Ctrl(c) => Some(KeyChar::Ctrl(c)), Key::Backspace => Some(KeyChar::Press('𐘁')), Key::Esc => Some(KeyChar::Press('𐘃')), - Key::Up => Some(KeyChar::Press('𐙘')), - Key::Down => Some(KeyChar::Press('𐘞')), - Key::Left => Some(KeyChar::Press('𐙣')), - Key::Right => Some(KeyChar::Press('𐙥')), + Key::ArrowUp => Some(KeyChar::Press('𐙘')), + Key::ArrowDown => Some(KeyChar::Press('𐘞')), + Key::ArrowLeft => Some(KeyChar::Press('𐙣')), + Key::ArrowRight => Some(KeyChar::Press('𐙥')), _ => None, } } @@ -94,9 +91,9 @@ fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) { //read key presses thread::spawn(move || { - let stdin = stdin().lock(); - for c in stdin.keys() { - if let Some(kc) = key_to_char(c.unwrap()) { + let stdin = RawStdin::new(stdin()); + for c in stdin { + if let Some(kc) = key_to_char(c) { //do not allow exit when locked unless debugging //if kc == KeyChar::Alt('E') { if kc == KeyChar::Alt('E') { diff --git a/wm/Cargo.toml b/wm/Cargo.toml index 8f99de7..97a13d9 100644 --- a/wm/Cargo.toml +++ b/wm/Cargo.toml @@ -8,7 +8,5 @@ edition = "2021" [dependencies] ming-wm-lib = { path = "../ming-wm-lib" } linux = { path = "linux" } -blake2 = { version = "0.10.6", default-features = false } -termion = { version = "4.0.3" } +bitcoin_hashes = { version = "0.16.0", default-features = false } bmp-rust = "0.5.0" - diff --git a/wm/linux/src/keys.rs b/wm/linux/src/keys.rs index ab0c014..5e8fc59 100644 --- a/wm/linux/src/keys.rs +++ b/wm/linux/src/keys.rs @@ -1 +1,89 @@ -// \ No newline at end of file +use std::io::{ Read, Stdin }; +use std::sync::mpsc::{ channel, Receiver }; +use std::thread; + +//includes a section on reading keys +//https://viewsourcecode.org/snaptoken/kilo/02.enteringRawMode.html + +const ALPHABET: [char; 26] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; + +pub enum Key { + Char(char), + Alt(char), + Ctrl(char), + Backspace, + Esc, + ArrowUp, + ArrowDown, + ArrowLeft, + ArrowRight, + Other(u8), //we don't get about anything else, lmao +} + +pub struct RawStdin { + //bytes: Peekable>>, + receiver: Receiver, +} + +impl RawStdin { + pub fn new(stdin: Stdin) -> Self { + let (sender, receiver) = channel(); + thread::spawn(move || { + let bytes = stdin.lock().bytes(); + for b in bytes { + sender.send(b.unwrap()).unwrap(); + } + }); + RawStdin { + //bytes: stdin.lock().bytes().peekable(), + receiver, + } + } +} + +impl Iterator for RawStdin { + type Item = Key; + + fn next(&mut self) -> Option { + let first = self.receiver.recv().unwrap(); + Some(match first { + 1..=26 => { + //ctrl + if first == 9 { + Key::Char('\t') + } else if first == 13 { + //ctrl+m and enter give the same thing + Key::Char('\n') + } else { + Key::Ctrl(ALPHABET[first as usize - 1]) + } + }, + 27 => { + //escape sequence + //not handling escape sequences that are 3+ bytes is probably going to come back to bite us + let n = self.receiver.try_recv(); + if let Ok(b'[') = n { + let n = self.receiver.recv().unwrap(); + match n { + b'A' => Key::ArrowUp, + b'B' => Key::ArrowDown, + b'C' => Key::ArrowRight, + b'D' => Key::ArrowLeft, + _ => Key::Other(n), + } + } else if n.is_ok() { + //Alt+ sends Esc+ + Key::Alt(char::from(n.unwrap())) + } else { + Key::Esc + } + }, + 127 => { + Key::Backspace + }, + _ => { + Key::Char(char::from(first)) + }, + }) + } +} diff --git a/wm/linux/src/lib.rs b/wm/linux/src/lib.rs index 138fb7b..83eaee7 100644 --- a/wm/linux/src/lib.rs +++ b/wm/linux/src/lib.rs @@ -1,2 +1,3 @@ pub mod fb; pub mod raw; +pub mod keys; diff --git a/wm/src/essential/lock_screen.rs b/wm/src/essential/lock_screen.rs index a508a87..97b8b66 100644 --- a/wm/src/essential/lock_screen.rs +++ b/wm/src/essential/lock_screen.rs @@ -5,7 +5,7 @@ use ming_wm_lib::framebuffer_types::Dimensions; use ming_wm_lib::themes::ThemeInfo; use ming_wm_lib::messages::{ WindowMessage, WindowMessageResponse, WindowManagerRequest }; use ming_wm_lib::window_manager_types::{ DrawInstructions, WindowLike, WindowLikeType }; -use blake2::{ Blake2b512, Digest }; +use bitcoin_hashes::Sha512; //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]; @@ -25,9 +25,7 @@ impl WindowLike for LockScreen { WindowMessage::KeyPress(key_press) => { if key_press.is_enter() { //check password - let mut hasher = Blake2b512::new(); - hasher.update((self.input_password.clone() + "salt?sorrycryptographers").as_bytes()); - if hasher.finalize() == self.password_hash.into() { + if Sha512::hash((self.input_password.clone() + "salt?sorrycryptographers!1!").as_bytes()).to_byte_array() == self.password_hash { WindowMessageResponse::Request(WindowManagerRequest::Unlock) } else { self.input_password = String::new(); diff --git a/wm/src/lib.rs b/wm/src/lib.rs index 4b3edaa..e927891 100644 --- a/wm/src/lib.rs +++ b/wm/src/lib.rs @@ -1,5 +1,4 @@ pub use linux; -pub use termion; pub mod framebuffer; pub mod window_manager;