From d58f1ff5dc2397bf3a24d639061c6445a420d6e9 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 30 Dec 2019 10:32:12 -0800 Subject: [PATCH] Implement focus_change for macos Refs: https://github.com/wez/wezterm/issues/93 --- window/src/os/macos/window.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 343216860..e03f03ba2 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -918,6 +918,18 @@ impl WindowView { } } + extern "C" fn did_become_key(this: &mut Object, _sel: Sel, _id: id) { + if let Some(this) = Self::get_this(this) { + this.inner.borrow_mut().callbacks.focus_change(true); + } + } + + extern "C" fn did_resign_key(this: &mut Object, _sel: Sel, _id: id) { + if let Some(this) = Self::get_this(this) { + this.inner.borrow_mut().callbacks.focus_change(false); + } + } + // Switch the coordinate system to have 0,0 in the top left extern "C" fn is_flipped(_this: &Object, _sel: Sel) -> BOOL { YES @@ -1296,6 +1308,15 @@ impl WindowView { Self::did_resize as extern "C" fn(&mut Object, Sel, id), ); + cls.add_method( + sel!(windowDidBecomeKey:), + Self::did_become_key as extern "C" fn(&mut Object, Sel, id), + ); + cls.add_method( + sel!(windowDidResignKey:), + Self::did_resign_key as extern "C" fn(&mut Object, Sel, id), + ); + cls.add_method( sel!(mouseMoved:), Self::mouse_moved_or_dragged as extern "C" fn(&mut Object, Sel, id),