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,298 +351,302 @@ 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 { //check if is special key (key releases are guaranteed to be special keys)
if x < 100 && y < 100 { //eg: ctrl, alt, command/windows, shift, or caps lock
//toggle onscreen keyboard if top left keyboard clicked match key_char {
if self.osk.is_some() { KeyChar::Alt(c) => {
self.osk = None; let mut press_response = WindowMessageResponse::DoNothing;
} else { if !self.locked {
let osk = Box::new(OnscreenKeyboard::new()); //keyboard shortcut
let ideal_dimensions = osk.ideal_dimensions(self.dimensions); let shortcuts = HashMap::from([
self.add_window_like(osk, [175, self.dimensions[1] - TASKBAR_HEIGHT - 250], Some(ideal_dimensions)); //alt+e is terminate program (ctrl+c)
} ('s', ShortcutType::StartMenu),
response = WindowMessageResponse::JustRedraw ('[', ShortcutType::FocusPrevWindow),
} else { (']', ShortcutType::FocusNextWindow),
//see if in onscreen keyboard, if so send to it after offsetting coords ('q', ShortcutType::QuitWindow),
if self.osk.is_some() { ('c', ShortcutType::CenterWindow),
let osk = self.osk.as_mut().unwrap(); ('f', ShortcutType::FullscreenWindow),
if point_inside([x, y], osk.top_left, osk.dimensions) { ('w', ShortcutType::HalfWidthWindow),
let osk_resp = osk.window_like.handle_message(WindowMessage::Touch(x - osk.top_left[0], y - osk.top_left[1])); ('C', ShortcutType::ClipboardCopy),
//change to a WindowManagerMessage::KeyChar ('P', ShortcutType::ClipboardPaste(String::new())),
if let WindowMessageResponse::Request(WindowManagerRequest::DoKeyChar(kc)) = osk_resp { //move window a small amount
message = WindowManagerMessage::KeyChar(kc); ('h', ShortcutType::MoveWindow(Direction::Left)),
} ('j', ShortcutType::MoveWindow(Direction::Down)),
} ('k', ShortcutType::MoveWindow(Direction::Up)),
} ('l', ShortcutType::MoveWindow(Direction::Right)),
} //move window to edges
} ('H', ShortcutType::MoveWindowToEdge(Direction::Left)),
if let WindowManagerMessage::KeyChar(key_char) = message { ('J', ShortcutType::MoveWindowToEdge(Direction::Down)),
//check if is special key (key releases are guaranteed to be special keys) ('K', ShortcutType::MoveWindowToEdge(Direction::Up)),
//eg: ctrl, alt, command/windows, shift, or caps lock ('L', ShortcutType::MoveWindowToEdge(Direction::Right)),
match key_char { //
KeyChar::Alt(c) => { //no 10th workspace
if !self.locked { ('1', ShortcutType::SwitchWorkspace(0)),
//keyboard shortcut ('2', ShortcutType::SwitchWorkspace(1)),
let shortcuts = HashMap::from([ ('3', ShortcutType::SwitchWorkspace(2)),
//alt+e is terminate program (ctrl+c) ('4', ShortcutType::SwitchWorkspace(3)),
('s', ShortcutType::StartMenu), ('5', ShortcutType::SwitchWorkspace(4)),
('[', ShortcutType::FocusPrevWindow), ('6', ShortcutType::SwitchWorkspace(5)),
(']', ShortcutType::FocusNextWindow), ('7', ShortcutType::SwitchWorkspace(6)),
('q', ShortcutType::QuitWindow), ('8', ShortcutType::SwitchWorkspace(7)),
('c', ShortcutType::CenterWindow), ('9', ShortcutType::SwitchWorkspace(8)),
('f', ShortcutType::FullscreenWindow), //shfit + num key
('w', ShortcutType::HalfWidthWindow), ('!', ShortcutType::MoveWindowToWorkspace(0)),
('C', ShortcutType::ClipboardCopy), ('@', ShortcutType::MoveWindowToWorkspace(1)),
('P', ShortcutType::ClipboardPaste(String::new())), ('#', ShortcutType::MoveWindowToWorkspace(2)),
//move window a small amount ('$', ShortcutType::MoveWindowToWorkspace(3)),
('h', ShortcutType::MoveWindow(Direction::Left)), ('%', ShortcutType::MoveWindowToWorkspace(4)),
('j', ShortcutType::MoveWindow(Direction::Down)), ('^', ShortcutType::MoveWindowToWorkspace(5)),
('k', ShortcutType::MoveWindow(Direction::Up)), ('&', ShortcutType::MoveWindowToWorkspace(6)),
('l', ShortcutType::MoveWindow(Direction::Right)), ('*', ShortcutType::MoveWindowToWorkspace(7)),
//move window to edges ('(', ShortcutType::MoveWindowToWorkspace(8)),
('H', ShortcutType::MoveWindowToEdge(Direction::Left)), //
('J', ShortcutType::MoveWindowToEdge(Direction::Down)), ]);
('K', ShortcutType::MoveWindowToEdge(Direction::Up)), if let Some(shortcut) = shortcuts.get(&c) {
('L', ShortcutType::MoveWindowToEdge(Direction::Right)), match shortcut {
// &ShortcutType::StartMenu => {
//no 10th workspace //send to taskbar
('1', ShortcutType::SwitchWorkspace(0)), press_response = self.toggle_start_menu(false);
('2', ShortcutType::SwitchWorkspace(1)), if press_response != WindowMessageResponse::Request(WindowManagerRequest::CloseStartMenu) {
('3', ShortcutType::SwitchWorkspace(2)), //only thing that needs to be redrawed is the start menu and taskbar
('4', ShortcutType::SwitchWorkspace(3)), let start_menu_id = self.id_count + 1;
('5', ShortcutType::SwitchWorkspace(4)), let taskbar_id = self.window_infos.iter().find(|w| w.window_like.subtype() == WindowLikeType::Taskbar).unwrap().id;
('6', ShortcutType::SwitchWorkspace(5)), redraw_ids = Some(vec![start_menu_id, taskbar_id]);
('7', ShortcutType::SwitchWorkspace(6)), }
('8', ShortcutType::SwitchWorkspace(7)), },
('9', ShortcutType::SwitchWorkspace(8)), &ShortcutType::MoveWindow(direction) | &ShortcutType::MoveWindowToEdge(direction) => {
//shfit + num key if let Some(focused_index) = self.get_focused_index() {
('!', ShortcutType::MoveWindowToWorkspace(0)), let focused_info = &self.window_infos[focused_index];
('@', ShortcutType::MoveWindowToWorkspace(1)), if focused_info.window_like.subtype() == WindowLikeType::Window && !focused_info.fullscreen {
('#', ShortcutType::MoveWindowToWorkspace(2)), let delta = 15;
('$', ShortcutType::MoveWindowToWorkspace(3)), let window_x = self.window_infos[focused_index].top_left[0];
('%', ShortcutType::MoveWindowToWorkspace(4)), let window_y = self.window_infos[focused_index].top_left[1];
('^', ShortcutType::MoveWindowToWorkspace(5)), let mut changed = true;
('&', ShortcutType::MoveWindowToWorkspace(6)), if direction == Direction::Left {
('*', ShortcutType::MoveWindowToWorkspace(7)), if window_x == 0 {
('(', ShortcutType::MoveWindowToWorkspace(8)), changed = false;
// } else if window_x < delta || shortcut == &ShortcutType::MoveWindowToEdge(direction) {
]); self.window_infos[focused_index].top_left[0] = 0;
if let Some(shortcut) = shortcuts.get(&c) { } else {
match shortcut { self.window_infos[focused_index].top_left[0] -= delta;
&ShortcutType::StartMenu => { }
//send to taskbar } else if direction == Direction::Down {
response = self.toggle_start_menu(false); let max_y = self.dimensions[1] - TASKBAR_HEIGHT - focused_info.dimensions[1];
if response != WindowMessageResponse::Request(WindowManagerRequest::CloseStartMenu) { if window_y == max_y {
//only thing that needs to be redrawed is the start menu and taskbar changed = false;
let start_menu_id = self.id_count + 1; } else if window_y > (max_y - delta) || shortcut == &ShortcutType::MoveWindowToEdge(direction) {
let taskbar_id = self.window_infos.iter().find(|w| w.window_like.subtype() == WindowLikeType::Taskbar).unwrap().id; self.window_infos[focused_index].top_left[1] = max_y;
redraw_ids = Some(vec![start_menu_id, taskbar_id]); } else {
} self.window_infos[focused_index].top_left[1] += delta;
}, }
&ShortcutType::MoveWindow(direction) | &ShortcutType::MoveWindowToEdge(direction) => { } else if direction == Direction::Up {
if let Some(focused_index) = self.get_focused_index() { let min_y = INDICATOR_HEIGHT;
let focused_info = &self.window_infos[focused_index]; if window_y == min_y {
if focused_info.window_like.subtype() == WindowLikeType::Window && !focused_info.fullscreen { changed = false;
let delta = 15; } else if window_y < (min_y + delta) || shortcut == &ShortcutType::MoveWindowToEdge(direction) {
let window_x = self.window_infos[focused_index].top_left[0]; self.window_infos[focused_index].top_left[1] = min_y;
let window_y = self.window_infos[focused_index].top_left[1]; } else {
let mut changed = true; self.window_infos[focused_index].top_left[1] -= delta;
if direction == Direction::Left { }
if window_x == 0 { } else if direction == Direction::Right {
changed = false; let max_x = self.dimensions[0] - focused_info.dimensions[0];
} else if window_x < delta || shortcut == &ShortcutType::MoveWindowToEdge(direction) { if window_x == max_x {
self.window_infos[focused_index].top_left[0] = 0; changed = false;
} else { } else if window_x > (max_x - delta) || shortcut == &ShortcutType::MoveWindowToEdge(direction) {
self.window_infos[focused_index].top_left[0] -= delta; self.window_infos[focused_index].top_left[0] = max_x;
} else {
self.window_infos[focused_index].top_left[0] += delta;
}
} }
} else if direction == Direction::Down { if changed {
let max_y = self.dimensions[1] - TASKBAR_HEIGHT - focused_info.dimensions[1]; press_response = WindowMessageResponse::JustRedraw;
if window_y == max_y { //avoid drawing everything under the moving window, much more efficient
changed = false; use_saved_buffer = true;
} else if window_y > (max_y - delta) || shortcut == &ShortcutType::MoveWindowToEdge(direction) { redraw_ids = Some(vec![self.focused_id]);
self.window_infos[focused_index].top_left[1] = max_y;
} else {
self.window_infos[focused_index].top_left[1] += delta;
} }
} else if direction == Direction::Up {
let min_y = INDICATOR_HEIGHT;
if window_y == min_y {
changed = false;
} else if window_y < (min_y + delta) || shortcut == &ShortcutType::MoveWindowToEdge(direction) {
self.window_infos[focused_index].top_left[1] = min_y;
} else {
self.window_infos[focused_index].top_left[1] -= delta;
}
} else if direction == Direction::Right {
let max_x = self.dimensions[0] - focused_info.dimensions[0];
if window_x == max_x {
changed = false;
} else if window_x > (max_x - delta) || shortcut == &ShortcutType::MoveWindowToEdge(direction) {
self.window_infos[focused_index].top_left[0] = max_x;
} else {
self.window_infos[focused_index].top_left[0] += delta;
}
}
if changed {
response = WindowMessageResponse::JustRedraw;
//avoid drawing everything under the moving window, much more efficient
use_saved_buffer = true;
redraw_ids = Some(vec![self.focused_id]);
} }
} }
} },
}, &ShortcutType::SwitchWorkspace(workspace) => {
&ShortcutType::SwitchWorkspace(workspace) => { if self.current_workspace != workspace {
if self.current_workspace != workspace { //close start menu if open
//close start menu if open self.toggle_start_menu(true);
self.toggle_start_menu(true); self.current_workspace = workspace;
self.current_workspace = workspace; //send to desktop background
//send to desktop background let desktop_background_index = self.window_infos.iter().position(|w| w.window_like.subtype() == WindowLikeType::DesktopBackground).unwrap();
let desktop_background_index = self.window_infos.iter().position(|w| w.window_like.subtype() == WindowLikeType::DesktopBackground).unwrap(); self.window_infos[desktop_background_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::SwitchWorkspace(self.current_workspace)));
self.window_infos[desktop_background_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::SwitchWorkspace(self.current_workspace))); //send to workspace indicator
//send to workspace indicator let indicator_index = self.window_infos.iter().position(|w| w.window_like.subtype() == WindowLikeType::WorkspaceIndicator).unwrap();
let indicator_index = self.window_infos.iter().position(|w| w.window_like.subtype() == WindowLikeType::WorkspaceIndicator).unwrap(); 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(); press_response = WindowMessageResponse::JustRedraw;
response = WindowMessageResponse::JustRedraw; }
} },
}, &ShortcutType::MoveWindowToWorkspace(workspace) => {
&ShortcutType::MoveWindowToWorkspace(workspace) => { if self.current_workspace != workspace {
if self.current_workspace != workspace { if let Some(focused_index) = self.get_focused_index() {
if self.window_infos[focused_index].window_like.subtype() == WindowLikeType::Window {
self.window_infos[focused_index].workspace = Workspace::Workspace(workspace);
self.taskbar_update_windows();
press_response = WindowMessageResponse::JustRedraw;
}
}
}
},
&ShortcutType::FocusPrevWindow | &ShortcutType::FocusNextWindow => {
let current_index = self.get_focused_index().unwrap_or(0);
let mut new_focus_index = current_index;
loop {
if shortcut == &ShortcutType::FocusPrevWindow {
if new_focus_index == 0 {
new_focus_index = self.window_infos.len() - 1;
} else {
new_focus_index -= 1;
}
} else {
new_focus_index += 1;
if new_focus_index == self.window_infos.len() {
new_focus_index = 0;
}
}
if self.window_infos[new_focus_index].window_like.subtype() == WindowLikeType::Window && self.window_infos[new_focus_index].workspace == Workspace::Workspace(self.current_workspace) {
//switch focus to this
self.focused_id = self.window_infos[new_focus_index].id;
//elevate it to the top
self.move_index_to_top(new_focus_index);
self.taskbar_update_windows();
press_response = WindowMessageResponse::JustRedraw;
break;
} else if new_focus_index == current_index {
break; //did a full loop, found no windows
}
}
},
&ShortcutType::QuitWindow => {
if let Some(focused_index) = self.get_focused_index() { if let Some(focused_index) = self.get_focused_index() {
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.remove(focused_index);
self.taskbar_update_windows(); self.taskbar_update_windows();
response = WindowMessageResponse::JustRedraw; press_response = WindowMessageResponse::JustRedraw;
} }
} }
} },
}, &ShortcutType::CenterWindow => {
&ShortcutType::FocusPrevWindow | &ShortcutType::FocusNextWindow => { if let Some(focused_index) = self.get_focused_index() {
let current_index = self.get_focused_index().unwrap_or(0); let window_dimensions = &self.window_infos[focused_index].dimensions;
let mut new_focus_index = current_index; self.window_infos[focused_index].top_left = [self.dimensions[0] / 2 - window_dimensions[0] / 2, self.dimensions[1] / 2 - window_dimensions[1] / 2];
loop { use_saved_buffer = true;
if shortcut == &ShortcutType::FocusPrevWindow { press_response = WindowMessageResponse::JustRedraw;
if new_focus_index == 0 { }
new_focus_index = self.window_infos.len() - 1; },
} else { &ShortcutType::FullscreenWindow => {
new_focus_index -= 1; if let Some(focused_index) = self.get_focused_index() {
} let window_like = &self.window_infos[focused_index].window_like;
} else { if window_like.subtype() == WindowLikeType::Window && window_like.resizable() {
new_focus_index += 1; //toggle fullscreen
if new_focus_index == self.window_infos.len() { self.window_infos[focused_index].fullscreen ^= true;
new_focus_index = 0; //todo: send message to window about resize
let new_dimensions;
if self.window_infos[focused_index].fullscreen {
new_dimensions = [self.dimensions[0], self.dimensions[1] - TASKBAR_HEIGHT - INDICATOR_HEIGHT];
self.window_infos[focused_index].top_left = [0, INDICATOR_HEIGHT];
redraw_ids = Some(vec![self.window_infos[focused_index].id]);
} else {
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]));
press_response = WindowMessageResponse::JustRedraw;
} }
} }
if self.window_infos[new_focus_index].window_like.subtype() == WindowLikeType::Window && self.window_infos[new_focus_index].workspace == Workspace::Workspace(self.current_workspace) { },
//switch focus to this &ShortcutType::HalfWidthWindow => {
self.focused_id = self.window_infos[new_focus_index].id; if let Some(focused_index) = self.get_focused_index() {
//elevate it to the top let window_like = &self.window_infos[focused_index].window_like;
self.move_index_to_top(new_focus_index); if window_like.subtype() == WindowLikeType::Window && window_like.resizable() {
self.taskbar_update_windows(); self.window_infos[focused_index].fullscreen = false;
response = WindowMessageResponse::JustRedraw; //full height, half width
break;
} else if new_focus_index == current_index {
break; //did a full loop, found no windows
}
}
},
&ShortcutType::QuitWindow => {
if let Some(focused_index) = self.get_focused_index() {
if self.window_infos[focused_index].window_like.subtype() == WindowLikeType::Window {
self.window_infos.remove(focused_index);
self.taskbar_update_windows();
response = WindowMessageResponse::JustRedraw;
}
}
},
&ShortcutType::CenterWindow => {
if let Some(focused_index) = self.get_focused_index() {
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];
use_saved_buffer = true;
response = WindowMessageResponse::JustRedraw;
}
},
&ShortcutType::FullscreenWindow => {
if let Some(focused_index) = self.get_focused_index() {
let window_like = &self.window_infos[focused_index].window_like;
if window_like.subtype() == WindowLikeType::Window && window_like.resizable() {
//toggle fullscreen
self.window_infos[focused_index].fullscreen ^= true;
//todo: send message to window about resize
let new_dimensions;
if self.window_infos[focused_index].fullscreen {
new_dimensions = [self.dimensions[0], self.dimensions[1] - TASKBAR_HEIGHT - INDICATOR_HEIGHT];
self.window_infos[focused_index].top_left = [0, INDICATOR_HEIGHT]; self.window_infos[focused_index].top_left = [0, INDICATOR_HEIGHT];
redraw_ids = Some(vec![self.window_infos[focused_index].id]); let new_dimensions = [self.dimensions[0] / 2, self.dimensions[1] - INDICATOR_HEIGHT - TASKBAR_HEIGHT];
} else { self.window_infos[focused_index].dimensions = new_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]));
press_response = WindowMessageResponse::JustRedraw;
} }
self.window_infos[focused_index].window_like.handle_message(WindowMessage::ChangeDimensions([new_dimensions[0], new_dimensions[1] - WINDOW_TOP_HEIGHT]));
response = WindowMessageResponse::JustRedraw;
} }
} },
}, &ShortcutType::ClipboardCopy => {
&ShortcutType::HalfWidthWindow => { 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 && window_like.resizable() { press_response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardCopy));
self.window_infos[focused_index].fullscreen = false; }
//full height, half width
self.window_infos[focused_index].top_left = [0, INDICATOR_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].window_like.handle_message(WindowMessage::ChangeDimensions([new_dimensions[0], new_dimensions[1] - WINDOW_TOP_HEIGHT]));
response = WindowMessageResponse::JustRedraw;
} }
} },
}, &ShortcutType::ClipboardPaste(_) => {
&ShortcutType::ClipboardCopy => { 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 { press_response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardPaste(self.clipboard.clone().unwrap())));
response = self.window_infos[focused_index].window_like.handle_message(WindowMessage::Shortcut(ShortcutType::ClipboardCopy)); }
} }
} },
}, };
&ShortcutType::ClipboardPaste(_) => { }
if let Some(focused_index) = self.get_focused_index() {
let window_like = &self.window_infos[focused_index].window_like;
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
},
KeyChar::Press(c) | KeyChar::Ctrl(c) => {
let mut press_response = WindowMessageResponse::DoNothing;
//send to focused window
if let Some(focused_index) = self.get_focused_index() {
press_response = self.window_infos[focused_index].window_like.handle_message(if key_char == KeyChar::Press(c) {
WindowMessage::KeyPress(KeyPress {
key: c,
})
} else {
WindowMessage::CtrlKeyPress(KeyPress {
key: c,
})
});
//at most, only the focused window needs to be redrawed
redraw_ids = Some(vec![self.window_infos[focused_index].id]);
//requests can result in window openings and closings, etc
if press_response != WindowMessageResponse::JustRedraw {
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
KeyChar::Press(c) | KeyChar::Ctrl(c) => { } else {
//send to focused window //see if in onscreen keyboard, if so send to it after offsetting coords
if let Some(focused_index) = self.get_focused_index() { if self.osk.is_some() {
response = self.window_infos[focused_index].window_like.handle_message(if key_char == KeyChar::Press(c) { let osk = self.osk.as_mut().unwrap();
WindowMessage::KeyPress(KeyPress { if point_inside([x, y], osk.top_left, osk.dimensions) {
key: c, osk.window_like.handle_message(WindowMessage::Touch(x - osk.top_left[0], y - osk.top_left[1]))
})
} else { } else {
WindowMessage::CtrlKeyPress(KeyPress { WindowMessageResponse::DoNothing
key: c,
})
});
//at most, only the focused window needs to be redrawed
redraw_ids = Some(vec![self.window_infos[focused_index].id]);
//requests can result in window openings and closings, etc
if response != WindowMessageResponse::JustRedraw {
redraw_ids = None;
} }
} 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));
},
}; };
} }