Skip to content

Commit

Permalink
add clear app focus message and command
Browse files Browse the repository at this point in the history
this is like id.clear_focus exepct that it will clear the focus regardless of the id that is clearing the focus
  • Loading branch information
jrmoulton committed Oct 20, 2024
1 parent f1eb90e commit 0388068
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ pub fn focus_window() {
add_update_message(UpdateMessage::FocusWindow);
}

/// Clear the app focus
pub fn clear_app_focus() {
add_update_message(UpdateMessage::ClearAppFocus);
}

/// Set whether ime input is shown
pub fn set_ime_allowed(allowed: bool) {
add_update_message(UpdateMessage::SetImeAllowed { allowed });
Expand Down
4 changes: 3 additions & 1 deletion src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ impl AppState {
}
}

self.prev_focus = self.focus;
if self.focus.is_some() {
self.prev_focus = self.focus;
}
self.focus = None;
}

Expand Down
1 change: 1 addition & 0 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type DeferredUpdateMessages = HashMap<ViewId, Vec<(ViewId, Box<dyn Any>)>>;
pub(crate) enum UpdateMessage {
Focus(ViewId),
ClearFocus(ViewId),
ClearAppFocus,
Active(ViewId),
ClearActive(ViewId),
WindowScale(f64),
Expand Down
7 changes: 7 additions & 0 deletions src/window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,13 @@ impl WindowHandle {
cx.app_state.focus_changed(Some(id), None);
}
}
UpdateMessage::ClearAppFocus => {
let focus = cx.app_state.focus;
cx.app_state.clear_focus();
if let Some(id) = focus {
cx.app_state.focus_changed(Some(id), None);
}
}
UpdateMessage::Active(id) => {
let old = cx.app_state.active;
cx.app_state.active = Some(id);
Expand Down

0 comments on commit 0388068

Please sign in to comment.