Revert "different approach"

This reverts commit a5489d67e6.
This commit is contained in:
stjet
2025-02-09 18:23:16 +00:00
parent a5489d67e6
commit 972d4fc425

View File

@@ -351,38 +351,13 @@ impl WindowManager {
pub fn handle_message(&mut self, message: WindowManagerMessage) { pub fn handle_message(&mut self, message: WindowManagerMessage) {
let mut use_saved_buffer = false; let mut use_saved_buffer = false;
let mut redraw_ids = None; let mut redraw_ids = None;
let mut response: WindowMessageResponse = WindowMessageResponse::DoNothing; let response: WindowMessageResponse = match message {
let mut message = message; WindowManagerMessage::KeyChar(key_char) => {
if let WindowManagerMessage::Touch(x, y) = message {
if x < 100 && y < 100 {
//toggle onscreen keyboard if top left keyboard clicked
if self.osk.is_some() {
self.osk = None;
} else {
let osk = Box::new(OnscreenKeyboard::new());
let ideal_dimensions = osk.ideal_dimensions(self.dimensions);
self.add_window_like(osk, [175, self.dimensions[1] - TASKBAR_HEIGHT - 250], Some(ideal_dimensions));
}
response = WindowMessageResponse::JustRedraw
} else {
//see if in onscreen keyboard, if so send to it after offsetting coords
if self.osk.is_some() {
let osk = self.osk.as_mut().unwrap();
if point_inside([x, y], osk.top_left, osk.dimensions) {
let osk_resp = osk.window_like.handle_message(WindowMessage::Touch(x - osk.top_left[0], y - osk.top_left[1]));
//change to a WindowManagerMessage::KeyChar
if let WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(kc)) = osk_resp {
message = WindowManagerMessage::KeyChar(kc);
}
}
}
}
}
if let WindowManagerMessage::KeyChar(key_char) = message {
//check if is special key (key releases are guaranteed to be special keys) //check if is special key (key releases are guaranteed to be special keys)
//eg: ctrl, alt, command/windows, shift, or caps lock //eg: ctrl, alt, command/windows, shift, or caps lock
match key_char { match key_char {
KeyChar::Alt(c) => { KeyChar::Alt(c) => {
let mut press_response = WindowMessageResponse::DoNothing;
if !self.locked { if !self.locked {
//keyboard shortcut //keyboard shortcut
let shortcuts = HashMap::from([ let shortcuts = HashMap::from([
@@ -433,8 +408,8 @@ impl WindowManager {
match shortcut { match shortcut {
&ShortcutType::StartMenu => { &ShortcutType::StartMenu => {
//send to taskbar //send to taskbar
response = self.toggle_start_menu(false); press_response = self.toggle_start_menu(false);
if response != WindowMessageResponse::Request(WindowManagerRequest::CloseStartMenu) { if press_response != WindowMessageResponse::Request(WindowManagerRequest::CloseStartMenu) {
//only thing that needs to be redrawed is the start menu and taskbar //only thing that needs to be redrawed is the start menu and taskbar
let start_menu_id = self.id_count + 1; let start_menu_id = self.id_count + 1;
let taskbar_id = self.window_infos.iter().find(|w| w.window_like.subtype() == WindowLikeType::Taskbar).unwrap().id; let taskbar_id = self.window_infos.iter().find(|w| w.window_like.subtype() == WindowLikeType::Taskbar).unwrap().id;
@@ -486,7 +461,7 @@ impl WindowManager {
} }
} }
if changed { if changed {
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
//avoid drawing everything under the moving window, much more efficient //avoid drawing everything under the moving window, much more efficient
use_saved_buffer = true; use_saved_buffer = true;
redraw_ids = Some(vec![self.focused_id]); redraw_ids = Some(vec![self.focused_id]);
@@ -507,7 +482,7 @@ impl WindowManager {
self.focused_id = self.window_infos[indicator_index].id; self.focused_id = self.window_infos[indicator_index].id;
self.window_infos[indicator_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::SwitchWorkspace(self.current_workspace))); self.window_infos[indicator_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::SwitchWorkspace(self.current_workspace)));
self.taskbar_update_windows(); self.taskbar_update_windows();
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
}, },
&ShortcutType::MoveWindowToWorkspace(workspace) => { &ShortcutType::MoveWindowToWorkspace(workspace) => {
@@ -516,7 +491,7 @@ impl WindowManager {
if self.window_infos[focused_index].window_like.subtype() == WindowLikeType::Window { if self.window_infos[focused_index].window_like.subtype() == WindowLikeType::Window {
self.window_infos[focused_index].workspace = Workspace::Workspace(workspace); self.window_infos[focused_index].workspace = Workspace::Workspace(workspace);
self.taskbar_update_windows(); self.taskbar_update_windows();
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
} }
} }
@@ -543,7 +518,7 @@ impl WindowManager {
//elevate it to the top //elevate it to the top
self.move_index_to_top(new_focus_index); self.move_index_to_top(new_focus_index);
self.taskbar_update_windows(); self.taskbar_update_windows();
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
break; break;
} else if new_focus_index == current_index { } else if new_focus_index == current_index {
break; //did a full loop, found no windows break; //did a full loop, found no windows
@@ -555,7 +530,7 @@ impl WindowManager {
if self.window_infos[focused_index].window_like.subtype() == WindowLikeType::Window { if self.window_infos[focused_index].window_like.subtype() == WindowLikeType::Window {
self.window_infos.remove(focused_index); self.window_infos.remove(focused_index);
self.taskbar_update_windows(); self.taskbar_update_windows();
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
} }
}, },
@@ -564,7 +539,7 @@ impl WindowManager {
let window_dimensions = &self.window_infos[focused_index].dimensions; let window_dimensions = &self.window_infos[focused_index].dimensions;
self.window_infos[focused_index].top_left = [self.dimensions[0] / 2 - window_dimensions[0] / 2, self.dimensions[1] / 2 - window_dimensions[1] / 2]; self.window_infos[focused_index].top_left = [self.dimensions[0] / 2 - window_dimensions[0] / 2, self.dimensions[1] / 2 - window_dimensions[1] / 2];
use_saved_buffer = true; use_saved_buffer = true;
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
}, },
&ShortcutType::FullscreenWindow => { &ShortcutType::FullscreenWindow => {
@@ -583,7 +558,7 @@ impl WindowManager {
new_dimensions = self.window_infos[focused_index].dimensions; new_dimensions = self.window_infos[focused_index].dimensions;
} }
self.window_infos[focused_index].window_like.handle_message(WindowMessage::ChangeDimensions([new_dimensions[0], new_dimensions[1] - WINDOW_TOP_HEIGHT])); self.window_infos[focused_index].window_like.handle_message(WindowMessage::ChangeDimensions([new_dimensions[0], new_dimensions[1] - WINDOW_TOP_HEIGHT]));
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
} }
}, },
@@ -597,7 +572,7 @@ impl WindowManager {
let new_dimensions = [self.dimensions[0] / 2, self.dimensions[1] - INDICATOR_HEIGHT - TASKBAR_HEIGHT]; let new_dimensions = [self.dimensions[0] / 2, self.dimensions[1] - INDICATOR_HEIGHT - TASKBAR_HEIGHT];
self.window_infos[focused_index].dimensions = new_dimensions; self.window_infos[focused_index].dimensions = new_dimensions;
self.window_infos[focused_index].window_like.handle_message(WindowMessage::ChangeDimensions([new_dimensions[0], new_dimensions[1] - WINDOW_TOP_HEIGHT])); self.window_infos[focused_index].window_like.handle_message(WindowMessage::ChangeDimensions([new_dimensions[0], new_dimensions[1] - WINDOW_TOP_HEIGHT]));
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
} }
}, },
@@ -605,7 +580,7 @@ impl WindowManager {
if let Some(focused_index) = self.get_focused_index() { if let Some(focused_index) = self.get_focused_index() {
let window_like = &self.window_infos[focused_index].window_like; let window_like = &self.window_infos[focused_index].window_like;
if window_like.subtype() == WindowLikeType::Window { if window_like.subtype() == WindowLikeType::Window {
response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardCopy)); press_response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardCopy));
} }
} }
}, },
@@ -613,18 +588,20 @@ impl WindowManager {
if let Some(focused_index) = self.get_focused_index() { if let Some(focused_index) = self.get_focused_index() {
let window_like = &self.window_infos[focused_index].window_like; let window_like = &self.window_infos[focused_index].window_like;
if window_like.subtype() == WindowLikeType::Window && self.clipboard.is_some() { if window_like.subtype() == WindowLikeType::Window && self.clipboard.is_some() {
response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardPaste(self.clipboard.clone().unwrap()))); press_response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardPaste(self.clipboard.clone().unwrap())));
} }
} }
}, },
}; };
} }
} }
press_response
}, },
KeyChar::Press(c) | KeyChar::Ctrl(c) => { KeyChar::Press(c) | KeyChar::Ctrl(c) => {
let mut press_response = WindowMessageResponse::DoNothing;
//send to focused window //send to focused window
if let Some(focused_index) = self.get_focused_index() { if let Some(focused_index) = self.get_focused_index() {
response = self.window_infos[focused_index].window_like.handle_message(if key_char == KeyChar::Press(c) { press_response = self.window_infos[focused_index].window_like.handle_message(if key_char == KeyChar::Press(c) {
WindowMessage::KeyPress(KeyPress { WindowMessage::KeyPress(KeyPress {
key: c, key: c,
}) })
@@ -636,13 +613,40 @@ impl WindowManager {
//at most, only the focused window needs to be redrawed //at most, only the focused window needs to be redrawed
redraw_ids = Some(vec![self.window_infos[focused_index].id]); redraw_ids = Some(vec![self.window_infos[focused_index].id]);
//requests can result in window openings and closings, etc //requests can result in window openings and closings, etc
if response != WindowMessageResponse::JustRedraw { if press_response != WindowMessageResponse::JustRedraw {
redraw_ids = None; redraw_ids = None;
} }
} }
press_response
}, },
} }
},
WindowManagerMessage::Touch(x, y) => {
if x < 100 && y < 100 {
//toggle onscreen keyboard if top left keyboard clicked
if self.osk.is_some() {
self.osk = None;
} else {
let osk = Box::new(OnscreenKeyboard::new());
let ideal_dimensions = osk.ideal_dimensions(self.dimensions);
self.add_window_like(osk, [175, self.dimensions[1] - TASKBAR_HEIGHT - 250], Some(ideal_dimensions));
} }
WindowMessageResponse::JustRedraw
} else {
//see if in onscreen keyboard, if so send to it after offsetting coords
if self.osk.is_some() {
let osk = self.osk.as_mut().unwrap();
if point_inside([x, y], osk.top_left, osk.dimensions) {
osk.window_like.handle_message(WindowMessage::Touch(x - osk.top_left[0], y - osk.top_left[1]))
} else {
WindowMessageResponse::DoNothing
}
} else {
WindowMessageResponse::DoNothing
}
}
}
};
if response != WindowMessageResponse::DoNothing { if response != WindowMessageResponse::DoNothing {
match response { match response {
WindowMessageResponse::Request(request) => self.handle_request(request), WindowMessageResponse::Request(request) => self.handle_request(request),
@@ -711,7 +715,9 @@ impl WindowManager {
WindowManagerRequest::ClipboardCopy(content) => { WindowManagerRequest::ClipboardCopy(content) => {
self.clipboard = Some(content); self.clipboard = Some(content);
}, },
WindowManagerRequest::DoKeyChar(_) => {}, WindowManagerRequest::DoKeyChar(kc) => {
self.handle_message(WindowManagerMessage::KeyChar(kc));
},
}; };
} }