Skip to content

Commit

Permalink
check view id for ext event
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Aug 13, 2023
1 parent 4cca09c commit 4b3913f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unicode-segmentation = "1.10.0"
leptos_reactive = { version = "0.5.0-alpha" }
glazier = { git = "https://github.com/lapce/glazier", features = [
"serde",
], rev = "b2c780675740c643e0d2e84361c52f077b099429" }
], rev = "db03ea4295daef69cb8d0877f2b2e5734cc116be" }
# glazier = { path = "../glazier", features = ["serde"] }
peniko = { git = "https://github.com/linebender/peniko", rev = "cafdac9a211a0fb2fec5656bd663d1ac770bcc81" }
wgpu = "0.15"
Expand Down
3 changes: 3 additions & 0 deletions src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,9 @@ impl<V: View> WinHandler for AppHandle<V> {
}

fn got_focus(&mut self) {
{
*EXT_EVENT_HANDLER.active.lock() = self.view.id();
}
self.event(Event::WindowGotFocus);
}

Expand Down
15 changes: 14 additions & 1 deletion src/ext_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,38 @@ use parking_lot::Mutex;

use crate::{app_handle::get_current_view, id::Id};

pub static EXT_EVENT_HANDLER: Lazy<ExtEventHandler> = Lazy::new(ExtEventHandler::default);
pub(crate) static EXT_EVENT_HANDLER: Lazy<ExtEventHandler> = Lazy::new(ExtEventHandler::default);

#[derive(Clone)]
pub struct ExtEventHandler {
pub(crate) queue: Arc<Mutex<HashMap<Id, Vec<Trigger>>>>,
pub(crate) handle: Arc<Mutex<HashMap<Id, IdleHandle>>>,
pub(crate) active: Arc<Mutex<Id>>,
}

impl Default for ExtEventHandler {
fn default() -> Self {
Self {
queue: Arc::new(Mutex::new(HashMap::new())),
handle: Arc::new(Mutex::new(HashMap::new())),
active: Arc::new(Mutex::new(Id::next())),
}
}
}

impl ExtEventHandler {
pub fn add_trigger(&self, current_view_id: Id, trigger: Trigger) {
let current_view_id = {
if !EXT_EVENT_HANDLER
.handle
.lock()
.contains_key(&current_view_id)
{
*EXT_EVENT_HANDLER.active.lock()
} else {
current_view_id
}
};
{
let mut queue = EXT_EVENT_HANDLER.queue.lock();
let queue = queue.entry(current_view_id).or_default();
Expand Down

0 comments on commit 4b3913f

Please sign in to comment.