2 Commits

Author SHA1 Message Date
stjet
11af21ee6d fix copy in install script 2025-03-24 00:24:04 +00:00
stjet
fa4627316d v1.0.2: arrow keys, start menu paging support
key press convenience methods, fix logo, docs, add more chars
2025-03-23 21:41:59 +00:00
81 changed files with 277 additions and 85 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "ming-wm"
version = "1.0.1"
version = "1.0.2"
repository = "https://github.com/stjet/ming-wm"
license = "GPL-3.0-or-later"
edition = "2021"

BIN
bmps/ming-wm.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

73
bmps/ming-wm.svg Normal file
View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1"
xml:space="preserve"
inkscape:version="1.4 (e7c3feb100, 2024-10-09)"
sodipodi:docname="ming-wm.svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="4.3046016"
inkscape:cx="449.86742"
inkscape:cy="483.20383"
inkscape:window-width="706"
inkscape:window-height="855"
inkscape:window-x="723"
inkscape:window-y="34"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" /><defs
id="defs1" /><g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"><rect
style="fill:#ffc90e;fill-opacity:1;stroke:none;stroke-width:1.13352"
id="rect1"
width="10.583"
height="10.583"
x="116.72247"
y="121.45529"
inkscape:export-filename="/home/jondough/Downloads/image1.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" /><ellipse
style="fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.53688"
id="path1"
cx="122.01397"
cy="126.7468"
rx="3"
ry="3.1378791" /><text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1.76389px;line-height:1.25;font-family:'Nimbus Roman';-inkscape-font-specification:'Nimbus Roman, ';text-align:start;letter-spacing:0px;writing-mode:lr-tb;direction:ltr;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.25"
x="123.14632"
y="129.68439"
id="text1"><tspan
sodipodi:role="line"
id="tspan1"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:1.76389px;font-family:'Nimbus Roman';-inkscape-font-specification:'Nimbus Roman, ';letter-spacing:0px;fill:#000000;stroke:none;stroke-width:1.25"
x="123.14632"
y="129.68439">wm</tspan></text><text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52778px;line-height:1.25;font-family:'Shippori Mincho';-inkscape-font-specification:'Shippori Mincho';text-align:start;letter-spacing:0px;writing-mode:lr-tb;direction:ltr;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.25"
x="120.23068"
y="128.04678"
id="text2"><tspan
sodipodi:role="line"
id="tspan2"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52778px;font-family:'Shippori Mincho';-inkscape-font-specification:'Shippori Mincho';fill:#000000;stroke-width:1.25"
x="120.23068"
y="128.04678"></tspan></text></g></svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

View File

Before

Width:  |  Height:  |  Size: 582 B

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

BIN
bmps/shippori-mincho/過0.bmp Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 948 KiB

After

Width:  |  Height:  |  Size: 906 KiB

26
docs/system/keys.md Normal file
View File

@@ -0,0 +1,26 @@
Relevant section taken from `src/bin/main.rs`:
```rust
fn key_to_char(key: Key) -> Option<KeyChar> {
match key {
Key::Char('\n') => Some(KeyChar::Press('𐘂')),
Key::Char(c) => Some(KeyChar::Press(c)),
Key::Alt(c) => Some(KeyChar::Alt(c)),
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('𐙥')),
_ => None,
}
}
```
The special keys backspace, enter, escape, and the arrows, are represented by a single Linear A char. For ease, there are [methods](https://docs.rs/ming-wm-lib/latest/ming_wm_lib/messages/struct.KeyPress.html) to check whether a key press is a backspace, enter, etc, without pasting the Linear A into the code.
Although the arrow keys are supported, please try and support the Vim `hjkl` if possible!
The `Press` events are sent as `WindowMessage::KeyPress(KeyPress)`, and the `Ctrl` events are sent as `WindowMessage::CtrlKeyPress(KeyPress)`. Any keys pressed along with the Alt key are not passed to the windows.

View File

@@ -101,8 +101,17 @@ mv target/release/mingMisc_Example /usr/bin/mingMisc_Example #or whatever direct
![The example Hello World window!](/docs/images/window_example.png)
## Now what?
Handle various inputs in `handle_message`, and have it mutate the state. Draw the relevant state in `draw`. Not too hard, eh?
Besides looking at the examples (Koxinga, `src/bin`), read the [ming-wm-lib docs](https://docs.rs/ming-wm-lib)!
Also, `docs/system/keys.md` may be useful.
## Tips
- For windows that are separate binaries, the Elm Architecture obviously cannot be enforced (unless the window is written in Rust and uses the `ming-wm-lib`. However, the design of the IPC and the nature of the window manager being keyboard-driven makes it so using the Elm Architecture is highly recommended.
- Since the window manager currently queries and reads the responses to/from window binaries in the main thread, while the response is being waited for, the window manager is "frozen". Therefore, time-consuming tasks (>1 second) should not be done in the main thread, but rather a separate thread. For example, the ming-wm audio player (`src/bin/audio_player.rs`) does the time-consuming process of reading audio files in a separate thread to not hold up the window manager, and provide quick responses.
- Window panics will be logged to `~/.local/share/ming-wm/logs.txt`.

View File

@@ -2,8 +2,8 @@ Barebones file explorer.
## Navigation
- `j`: Move down
- `k`: Move up
- `j` (or down arrow): Move down
- `k` (or up arrow): Move up
- `i`: See info about current file / directory (press any key to escape info screen)
- `Enter`: Go into directory

View File

@@ -29,8 +29,8 @@ Tab completion is supported for the `<file>` argument.
- `f<char>`
- `F<char>`
- `x`
- `h`, `j`, `k`, `l`
- `<num>h`, `<num>j`, `<num>k`, `<num>l`
- `h` (or left arrow), `j` (or down arrow), `k` (or up arrow), `l` (or right arrow)
- `<num>h`, `<num>j` (or down arrow), `<num>k` (or up arrow), `<num>l`
- `0`, `^`, `$`
### Malvim Specific

View File

@@ -2,9 +2,8 @@ The start menu, which can be opened and closed with the [Alt+s shortcut](../syst
## Navigation
Use the 'j' and 'k' keys to move down and up respectively. Going down past the last option returns the selection to the first option, and vice versa (it loops).
Use the 'j' and 'k' keys to move down and up respectively. The up and down arrow keys can also be used. Going down past the last option returns the selection to the first option, and vice versa (it loops).
Hitting the 'enter' key will either open a subfolder containing window-likes, if a category is selected, or the corresponding window-like, if a window-like is selected. It may also exit a subfolder and return to the category selection if "Back" is selected and 'enter' is hit. There is another special case: hitting 'enter' while the "Logout" option is selected will, as the name implies, logout and return to the lock screen (this does not log out of the Linux user!).
For faster navigation, hitting any lower-case letter (besides 'j' and 'k') will move the selection to the next option that starts with that letter (non-looping). For example, when first opening the start menu, hitting 'e' will move the selection to "Editing". Hitting any upper-case letter will move the selection to any previous option that starts with that letter (also non-looping). For example, when initially opening the start menu, the selected option is "About". After hitting 'j' (moving down), hitting 'A' will return the selection to "About".

View File

@@ -8,8 +8,8 @@ The terminal starts off in INPUT mode, which allows entering commands to run. If
In INPUT mode, commands can be freely typed. There are a few special control sequences:
- `ctrl+p`: Equivalent to the up arrow in most terminals. Brings up the previous command in the command history, and so on.
- `ctrl+n`: Equivalent to the down arrow in most terminals. Either clears the current input if not in a previous command, else brings up the next command in the command history.
- `ctrl+p` (or up arrow): Equivalent to the up arrow in most terminals. Brings up the previous command in the command history, and so on.
- `ctrl+n` (or down arrow): Equivalent to the down arrow in most terminals. Either clears the current input if not in a previous command, else brings up the next command in the command history.
Tab completion is also supported, though only for file/directory paths.

View File

@@ -1,10 +1,11 @@
#!/bin/sh
rm -rf /usr/local/bin/ming_bmps
cp -r ./bmps /usr/local/bin/ming_bmps
rm -rf /usr/local/bin/ming_bmps/nimbus-roman/*.bmp
rm -rf /usr/local/bin/ming_bmps/nimbus-romano/*.bmp
rm -rf /usr/local/bin/ming_bmps/shippori-mincho/*.bmp
rm /usr/local/bin/ming_bmps/*1440x842.bmp
rm -f /usr/local/bin/ming_bmps/nimbus-roman/*.bmp
rm -f /usr/local/bin/ming_bmps/nimbus-romano/*.bmp
rm -f /usr/local/bin/ming_bmps/shippori-mincho/*.bmp
rm -f /usr/local/bin/ming_bmps/*1440x842.bmp
rm -f /usr/local/bin/ming_bmps/*.svg
rm -rf /usr/local/bin/ming_docs
cp -r ./docs /usr/local/bin/ming_docs
rm -rf /usr/local/bin/ming_docs/images

View File

@@ -1,10 +1,11 @@
#!/bin/sh
rm -rf ~/.local/bin/ming_bmps
cp -r ./bmps ~/.local/bin/ming_bmps
rm -rf ~/.local/bin/ming_bmps/nimbus-roman/*.bmp
rm -rf ~/.local/bin/ming_bmps/nimbus-romano/*.bmp
rm -rf ~/.local/bin/ming_bmps/shippori-mincho/*.bmp
rm ~/.local/bin/ming_bmps/*1440x842.bmp
rm -f ~/.local/bin/ming_bmps/nimbus-roman/*.bmp
rm -f ~/.local/bin/ming_bmps/nimbus-romano/*.bmp
rm -f ~/.local/bin/ming_bmps/shippori-mincho/*.bmp
rm -f ~/.local/bin/ming_bmps/*1440x842.bmp
rm -f ~/.local/bin/ming_bmps/*.svg
rm -rf ~/.local/bin/ming_docs
cp -r ./docs ~/.local/bin/ming_docs
rm -rf ~/.local/bin/ming_docs/images

View File

@@ -1,8 +1,9 @@
[package]
name = "ming-wm-lib"
version = "0.1.4"
version = "0.1.5"
repository = "https://github.com/stjet/ming-wm"
description = "library for building windows for ming-wm in rust"
readme = "README.md"
license = "GPL-3.0-or-later"
edition = "2021"

View File

@@ -1 +1,6 @@
Library for building [ming-wm](https://github.com/stjet/ming-wm) windows in Rust.
Documentation [here](https://docs.rs/ming-wm-lib).
The most likely usage of this crate is to implement the [WindowLike trait](https://docs.rs/ming-wm-lib/latest/ming_wm_lib/window_manager_types/trait.WindowLike.html), and then set up [IPC](https://docs.rs/ming-wm-lib/latest/ming_wm_lib/ipc/fn.listen.html) (which automatically handles serialisation).

View File

@@ -31,6 +31,7 @@ pub trait WindowLike {
const LOG: bool = false;
/// Listen and process what the window manager writes to our stdin
pub fn listen(mut window_like: impl WindowLike) {
panic::set_hook(Box::new(|panic_info| {
let (filename, line) = panic_info.location().map(|l| (l.file(), l.line())).unwrap_or(("<unknown>", 0));

View File

@@ -3,6 +3,7 @@ use std::io::Write;
use crate::dirs::data_dir;
/// Writes to `<XDG data directory>/ming-wm/logs.txt`. Use only for debugging!
pub fn log(message: &str) {
let data = data_dir().unwrap().into_os_string().into_string().unwrap();
let _ = create_dir(format!("{}/ming-wm", data));

View File

@@ -4,12 +4,14 @@ use std::vec::Vec;
use crate::framebuffer_types::Dimensions;
use crate::window_manager_types::{ WindowLike, KeyChar };
/// Window manager internal usage
pub enum WindowManagerMessage {
KeyChar(KeyChar),
Touch(usize, usize),
//
}
/// Window manager internal usage
pub type WindowBox = Box<dyn WindowLike>;
/*
@@ -50,10 +52,50 @@ impl WindowMessageResponse {
}
}
//struct because may add more fields later (so struct is better for code backward compatibility)
pub struct KeyPress {
pub key: char,
}
impl KeyPress {
pub fn is_enter(&self) -> bool {
self.key == '𐘂'
}
pub fn is_backspace(&self) -> bool {
self.key == '𐘁'
}
pub fn is_escape(&self) -> bool {
self.key == '𐘃'
}
pub fn is_up_arrow(&self) -> bool {
self.key == '𐙘'
}
pub fn is_down_arrow(&self) -> bool {
self.key == '𐘞'
}
pub fn is_left_arrow(&self) -> bool {
self.key == '𐙣'
}
pub fn is_right_arrow(&self) -> bool {
self.key == '𐙥'
}
pub fn is_arrow(&self) -> bool {
self.is_up_arrow() || self.is_down_arrow() || self.is_left_arrow() || self.is_right_arrow()
}
/// Is not enter, backspace, arrow keys (the Linear A stuff)
pub fn is_regular(&self) -> bool {
!self.is_enter() && !self.is_backspace() && !self.is_escape() && !self.is_arrow()
}
}
#[derive(Clone, Copy, PartialEq)]
pub enum Direction {
Left,
@@ -87,7 +129,7 @@ pub type WindowsVec = Vec<(usize, String)>;
#[non_exhaustive]
pub enum InfoType {
//let taskbar know what the current windows in the workspace are
/// Let taskbar know what the current windows in the workspace are
WindowsInWorkspace(WindowsVec, usize), //Vec<(id, name)>, focused id
//
}
@@ -102,7 +144,8 @@ pub enum WindowMessage {
Unfocus,
FocusClick,
ChangeDimensions(Dimensions),
Touch(usize, usize), //for onscreen keyboard only
/// For onscreen keyboard only
Touch(usize, usize),
//
}

View File

@@ -97,6 +97,7 @@ const THEME_INFOS: [(Themes, ThemeInfo); 5] = [
//
];
/// Window manager internal usage
pub fn get_theme_info(theme: &Themes) -> Option<ThemeInfo> {
for pair in THEME_INFOS {
if &pair.0 == theme {

View File

@@ -62,7 +62,7 @@ impl WindowLike for FileExplorer {
},
WindowMessage::KeyPress(key_press) => {
self.state = State::List;
if key_press.key == '𐘂' { //the enter key
if key_press.is_enter() {
if self.current_dir_contents.len() > 0 {
let selected_entry = &self.current_dir_contents[self.position];
if !selected_entry.is_file {
@@ -74,8 +74,8 @@ impl WindowLike for FileExplorer {
}
}
WindowMessageResponse::DoNothing
} else if key_press.key == 'j' || key_press.key == 'k' {
if key_press.key == 'j' {
} else if key_press.key == 'j' || key_press.is_down_arrow() || key_press.key == 'k' || key_press.is_up_arrow() {
if key_press.key == 'j' || key_press.is_down_arrow() {
//down
if self.position == self.current_dir_contents.len() - 1 {
self.position = 0;
@@ -94,7 +94,7 @@ impl WindowLike for FileExplorer {
let max_height = self.dimensions[1] - HEIGHT;
if self.position > self.top_position {
let current_height = (self.position - self.top_position + 1) * HEIGHT;
if current_height > self.dimensions[1] {
if current_height > max_height {
//somehow this is slightly off sometimes
self.top_position += (current_height - max_height).div_ceil(HEIGHT);
}
@@ -138,7 +138,7 @@ impl WindowLike for FileExplorer {
} else {
name.unwrap()
};
instructions.push(DrawInstructions::Text([5, start_y], vec!["nimbus-roman".to_string(), "shippori-mincho".to_string()], name, if is_selected { theme_info.top_text } else { theme_info.text }, if is_selected { theme_info.top } else { theme_info.background }, None, None));
instructions.push(DrawInstructions::Text([5, start_y + 4], vec!["nimbus-roman".to_string(), "shippori-mincho".to_string()], name, if is_selected { theme_info.top_text } else { theme_info.text }, if is_selected { theme_info.top } else { theme_info.background }, None, None));
start_y += HEIGHT;
i += 1;
}

View File

@@ -9,7 +9,6 @@ use std::env;
use linux::fb::Framebuffer;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::{ clear, cursor };
use termion::event::Key;
use ming_wm_lib::window_manager_types::KeyChar;
@@ -17,7 +16,11 @@ use ming_wm_lib::messages::*;
use ming_wm::framebuffer::{ FramebufferWriter, FramebufferInfo };
use ming_wm::window_manager::WindowManager;
//use Linear A for escape, backspace, enter
const CLEAR_ALL: &'static str = "\x1b[2J";
const HIDE_CURSOR: &'static str = "\x1b[?25l";
const SHOW_CURSOR: &'static str = "\x1b[?25h";
//use Linear A for escape, backspace, enter, arrow keys
//Linear A used only internally in onscreen keyboard: 𐘎 is alt, 𐘧 is switch board, 𐘾 is ctrl
fn key_to_char(key: Key) -> Option<KeyChar> {
match key {
@@ -27,6 +30,10 @@ fn key_to_char(key: Key) -> Option<KeyChar> {
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('𐙥')),
_ => None,
}
}
@@ -68,9 +75,9 @@ fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) {
let mut stdout = stdout().into_raw_mode().unwrap();
write!(stdout, "{}", clear::All).unwrap();
write!(stdout, "{}", CLEAR_ALL).unwrap();
write!(stdout, "{}", cursor::Hide).unwrap();
write!(stdout, "{}", HIDE_CURSOR).unwrap();
stdout.flush().unwrap();
@@ -147,12 +154,12 @@ fn init(framebuffer: Framebuffer, framebuffer_info: FramebufferInfo) {
ThreadMessage::KeyChar(kc) => wm.handle_message(WindowManagerMessage::KeyChar(kc.clone())),
ThreadMessage::Touch(x, y) => wm.handle_message(WindowManagerMessage::Touch(x, y)),
ThreadMessage::Clear => {
write!(stdout, "{}", clear::All).unwrap();
write!(stdout, "{}", CLEAR_ALL).unwrap();
stdout.flush().unwrap();
},
ThreadMessage::Exit => {
if !wm.locked {
write!(stdout, "{}", cursor::Show).unwrap();
write!(stdout, "{}", SHOW_CURSOR).unwrap();
stdout.suspend_raw_mode().unwrap();
exit(0);
}

View File

@@ -94,7 +94,7 @@ impl WindowLike for Malvim {
WindowMessage::KeyPress(key_press) => {
let mut changed = true;
let mut new = false;
if key_press.key == '𐘃' { //escape key
if key_press.is_escape() {
self.mode = Mode::Normal;
self.state = State::None;
changed = false;
@@ -113,7 +113,7 @@ impl WindowLike for Malvim {
let current_file = &mut self.files[self.current_file_index];
let current_length = current_file.content[current_file.line_pos].chars().count();
let line = &current_file.content[current_file.line_pos];
if key_press.key == '𐘂' { //the enter key
if key_press.is_enter() {
let mut line: Vec<char> = line.chars().collect();
let (left, right) = line.split_at_mut(current_file.cursor_pos);
let left = left.into_iter().map(|c| c.to_string()).collect::<Vec<String>>().join("");
@@ -136,7 +136,7 @@ impl WindowLike for Malvim {
current_file.content.insert(current_file.line_pos + 1, " ".repeat(spaces) + &right);
current_file.line_pos += 1;
current_file.cursor_pos = spaces;
} else if key_press.key == '𐘁' { //backspace
} else if key_press.is_backspace() {
if current_length > 0 && current_file.cursor_pos > 0 {
current_file.content[current_file.line_pos] = line.remove(current_file.cursor_pos - 1, 1);
current_file.cursor_pos -= 1;
@@ -150,7 +150,7 @@ impl WindowLike for Malvim {
current_file.cursor_pos = old_previous_line_length;
}
}
} else {
} else if !key_press.is_arrow() { //arrow keys in insert mode is something i cannot support in good conscience
current_file.content[current_file.line_pos] = line.substring(0, current_file.cursor_pos).to_string() + &key_press.key.to_string() + line.substring(current_file.cursor_pos, line.chars().count());
current_file.cursor_pos += 1;
}
@@ -241,11 +241,11 @@ impl WindowLike for Malvim {
current_file.cursor_pos = 0;
}
}
} else if key_press.key == 'h' {
} else if key_press.key == 'h' || key_press.is_left_arrow() {
current_file.cursor_pos = current_file.cursor_pos.checked_sub(self.maybe_num.unwrap_or(1)).unwrap_or(0);
changed = false;
} else if key_press.key == 'j' || key_press.key == 'k' {
if key_press.key == 'j' {
} else if key_press.key == 'j' || key_press.is_down_arrow() || key_press.key == 'k' || key_press.is_up_arrow() {
if key_press.key == 'j' || key_press.is_down_arrow() {
current_file.line_pos += self.maybe_num.unwrap_or(1);
if current_file.line_pos >= current_file.content.len() {
current_file.line_pos = current_file.content.len() - 1;
@@ -256,7 +256,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);
changed = false;
} else if key_press.key == 'l' {
} else if key_press.key == 'l' || key_press.is_right_arrow() {
if current_length > 0 {
current_file.cursor_pos += self.maybe_num.unwrap_or(1);
let line_len = current_file.content[current_file.line_pos].chars().count();
@@ -309,7 +309,7 @@ impl WindowLike for Malvim {
} else if self.mode == Mode::Command {
self.bottom_message = None;
let command = self.command.clone().unwrap_or("".to_string());
if key_press.key == '𐘂' { //the enter key
if key_press.is_enter() {
new = self.process_command();
self.command = None;
self.mode = Mode::Normal;
@@ -330,7 +330,7 @@ impl WindowLike for Malvim {
}
}
}
} else if key_press.key == '𐘁' { //backspace
} else if key_press.is_backspace() {
if command.len() > 0 {
self.command = Some(command[..command.len() - 1].to_string());
}

View File

@@ -54,6 +54,7 @@ impl WindowLike for Minesweeper {
self.random_chars = String::new();
self.state = State::BeforePlaying;
} else {
//since must be u8, the Linear A (enter, backspace, etc) stuff won't do anything
if u8::try_from(key_press.key).is_ok() {
self.random_chars.push(key_press.key);
}

View File

@@ -104,13 +104,13 @@ impl WindowLike for Terminal {
WindowMessage::KeyPress(key_press) => {
match self.mode {
Mode::Input => {
if key_press.key == '𐘁' { //backspace
if key_press.is_backspace() {
if self.current_input.len() > 0 {
self.current_input = self.current_input.remove_last();
} else {
return WindowMessageResponse::DoNothing;
}
} else if key_press.key == '𐘂' { //the enter key
} else if key_press.is_enter() {
self.lines.push("$ ".to_string() + &self.current_input);
self.history.push(self.current_input.clone());
self.history_index = None;
@@ -127,6 +127,10 @@ impl WindowLike for Terminal {
return WindowMessageResponse::DoNothing;
}
}
} else if key_press.is_up_arrow() {
self.prev();
} else if key_press.is_down_arrow() {
self.next();
} else {
self.current_input += &key_press.key.to_string();
}
@@ -175,19 +179,16 @@ impl WindowLike for Terminal {
}
},
Mode::Stdin => {
if key_press.key == '𐘃' {
//esc
if key_press.is_escape() {
self.mode = Mode::Running;
} else if key_press.key == '𐘂' {
//enter
} else if key_press.is_enter() {
let _ = self.pty_in_tx.as_mut().unwrap().send(self.current_stdin_input.clone());
self.mode = Mode::Running;
let pcl_len = self.process_current_line.len();
self.lines.push(strip_ansi_escape_codes(String::from_utf8(self.process_current_line.clone()).unwrap_or("?".repeat(pcl_len))) + &self.current_stdin_input);
self.current_stdin_input = String::new();
self.process_current_line = Vec::new();
} else if key_press.key == '𐘁' {
//backspace
} else if key_press.is_backspace() {
if self.current_stdin_input.len() > 0 {
self.current_stdin_input = self.current_stdin_input.remove_last();
} else {
@@ -210,24 +211,12 @@ impl WindowLike for Terminal {
} else if self.mode == Mode::Input && (key_press.key == 'p' || key_press.key == 'n') {
//only the last command is saved unlike other terminals. good enough for me
if key_press.key == 'p' && self.history.len() > 0 {
if let Some(history_index) = self.history_index {
if history_index > 0 {
self.history_index = Some(history_index - 1);
}
} else {
self.history_index = Some(self.history.len() - 1);
}
self.current_input = self.history[self.history_index.unwrap()].clone();
self.prev();
self.calc_actual_lines();
WindowMessageResponse::JustRedraw
} else if key_press.key == 'n' {
if self.history_index.is_none() || self.history_index.unwrap() == self.history.len() - 1 {
self.history_index = None;
self.current_input = String::new();
} else {
self.history_index = Some(self.history_index.unwrap() + 1);
self.current_input = self.history[self.history_index.unwrap()].clone();
}
self.next();
self.calc_actual_lines();
WindowMessageResponse::JustRedraw
} else {
@@ -300,6 +289,27 @@ impl Terminal {
Default::default()
}
fn prev(&mut self) {
if let Some(history_index) = self.history_index {
if history_index > 0 {
self.history_index = Some(history_index - 1);
}
} else {
self.history_index = Some(self.history.len() - 1);
}
self.current_input = self.history[self.history_index.unwrap()].clone();
}
fn next(&mut self) {
if self.history_index.is_none() || self.history_index.unwrap() == self.history.len() - 1 {
self.history_index = None;
self.current_input = String::new();
} else {
self.history_index = Some(self.history_index.unwrap() + 1);
self.current_input = self.history[self.history_index.unwrap()].clone();
}
}
fn get_max_lines(&self) -> usize {
(self.dimensions[1] - PADDING * 2 - LINE_HEIGHT) / LINE_HEIGHT
}

View File

@@ -28,12 +28,12 @@ impl WindowLike for Help {
} else {
String::new()
};
self.paragraph = Some(Box::new(Paragraph::new("help".to_string(), [2, 22], [self.dimensions[0] - 4, self.dimensions[1] - 24], "Press the 'h' and 'l' keys to read the different help pages".to_string() + &first_content, ())));
self.paragraph = Some(Box::new(Paragraph::new("help".to_string(), [2, 22], [self.dimensions[0] - 4, self.dimensions[1] - 24], "Press the 'h' and 'l' keys (or the left and right arrow keys) to read the different help pages".to_string() + &first_content, ())));
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
if key_press.key == 'h' || key_press.key == 'l' {
if key_press.key == 'h' {
if key_press.key == 'h' || key_press.is_left_arrow() || key_press.key == 'l' || key_press.is_right_arrow() {
if key_press.key == 'h' || key_press.is_left_arrow() {
if self.file_index == 0 {
self.file_index = self.files.len() - 1;
} else {

View File

@@ -24,7 +24,7 @@ impl WindowLike for LockScreen {
WindowMessageResponse::JustRedraw
},
WindowMessage::KeyPress(key_press) => {
if key_press.key == '𐘂' { //the enter key
if key_press.is_enter() {
//check password
let mut hasher = Blake2b512::new();
hasher.update((self.input_password.clone() + "salt?sorrycryptographers").as_bytes());
@@ -34,15 +34,17 @@ impl WindowLike for LockScreen {
self.input_password = String::new();
WindowMessageResponse::JustRedraw
}
} else if key_press.key == '𐘁' { //backspace
} else if key_press.is_backspace() {
let p_len = self.input_password.len();
if p_len != 0 {
self.input_password = self.input_password[..p_len - 1].to_string();
}
WindowMessageResponse::JustRedraw
} else {
} else if key_press.is_regular() {
self.input_password += &key_press.key.to_string();
WindowMessageResponse::JustRedraw
} else {
WindowMessageResponse::DoNothing
}
},
_ => WindowMessageResponse::DoNothing,

View File

@@ -42,10 +42,10 @@ impl WindowLike for StartMenu {
},
WindowMessage::KeyPress(key_press) => {
//up and down
if key_press.key == 'k' || key_press.key == 'j' {
if key_press.key == 'j' || key_press.is_down_arrow() || key_press.key == 'k' || key_press.is_up_arrow() {
let old_focus_index = self.get_focus_index().unwrap();
self.components[old_focus_index].handle_message(WindowMessage::Unfocus);
let current_focus_index = if key_press.key == 'j' {
let current_focus_index = if key_press.key == 'j' || key_press.is_down_arrow() {
if old_focus_index + 1 == self.components.len() {
0
} else {
@@ -61,7 +61,7 @@ impl WindowLike for StartMenu {
self.current_focus = self.components[current_focus_index].name().to_string();
self.components[current_focus_index].handle_message(WindowMessage::Focus);
WindowMessageResponse::JustRedraw
} else if key_press.key == '𐘂' { //the enter key
} else if key_press.is_enter() {
let focus_index = self.get_focus_index();
if let Some(focus_index) = focus_index {
let r = self.components[focus_index].handle_message(WindowMessage::FocusClick);
@@ -108,14 +108,21 @@ impl WindowLike for StartMenu {
DrawInstructions::Rect([self.dimensions[0] - 1, 0], [1, self.dimensions[1]], theme_info.border_right_bottom),
//background
DrawInstructions::Rect([0, 1], [self.dimensions[0] - 1, self.dimensions[1] - 1], theme_info.background),
//mingde logo
DrawInstructions::Bmp([2, 2], exe_dir(Some("ming_bmps/mingde.bmp")).to_string_lossy().to_string(), false),
//ming-wm logo
DrawInstructions::Bmp([2, 2], exe_dir(Some("ming_bmps/ming-wm.bmp")).to_string_lossy().to_string(), true),
//I truly don't know why, it should be - 44 but - 30 seems to work better :shrug:
DrawInstructions::Gradient([2, 42], [40, self.dimensions[1] - 30], [255, 201, 14], [225, 219, 77], 15),
DrawInstructions::Gradient([2, 42], [40, self.dimensions[1] - 30], [255, 201, 14], [225, 219, 100], 15), //[225, 219, 77]
];
let max_per_page = CATEGORIES.len();
let current_focus = self.get_focus_index().unwrap();
let mut index = 0;
for component in &self.components {
//supports multiple pages of window options per category
if (index >= max_per_page && current_focus >= max_per_page) || (index < max_per_page && current_focus < max_per_page) {
instructions.extend(component.draw(theme_info));
}
index += 1;
}
instructions
}
@@ -152,9 +159,13 @@ impl StartMenu {
];
//add window buttons
if let Some(to_add) = self.executable_windows.get(&("ming".to_string() + name)) {
for a in 0..to_add.len() {
let max_per_page = CATEGORIES.len();
//starts at 1 because of back button
for a in 1..=to_add.len() {
let ta = &to_add[a - 1];
//the modulo is for multiple pages for windows per category
self.components.push(Box::new(HighlightButton::new(
to_add[a].1.to_string(), [42, (a + 1) * self.y_each], [self.dimensions[0] - 42 - 1, self.y_each], to_add[a].0.to_string(), StartMenuMessage::WindowClick(to_add[a].1.clone()), StartMenuMessage::ChangeAcknowledge, false
ta.1.to_string(), [42, (a % max_per_page) * self.y_each], [self.dimensions[0] - 42 - 1, self.y_each], ta.0.to_string(), StartMenuMessage::WindowClick(ta.1.clone()), StartMenuMessage::ChangeAcknowledge, false
)));
}
}