From 2fc143e6dda3fa573fab17b440380e68fa9af69d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 26 Jun 2021 15:24:17 -0700 Subject: [PATCH] click to focus window now focuses the pane under the mouse cursor refs: https://github.com/wez/wezterm/issues/881 --- docs/changelog.md | 1 + wezterm-gui/src/termwindow/mouseevent.rs | 15 ++++++++------- window/src/os/macos/window.rs | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 80df560ec..eed1d353e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -46,6 +46,7 @@ As features stabilize some brief notes about them will accumulate here. * Improved: `wezterm ls-fonts --list-system` shows all available fonts, `wezterm ls-fonts --text "hello"` explains which fonts are used for each glyph in the supplied text * Fixed: mouse cursor is now Arrow rather than I-beam when the application in the terminal has enabled mouse reporting [#859](https://github.com/wez/wezterm/issues/859) * Improved: DEC Special Graphics mode conformance and complete coverage of the graphics character set. Thanks to [Autumn Lamonte](https://gitlab.com/klamonte)! [#891](https://github.com/wez/wezterm/pull/891) +* Fixed: click to focus now focuses the pane under the mouse cursor [#881](https://github.com/wez/wezterm/issues/881) ### 20210502-154244-3f7122cb diff --git a/wezterm-gui/src/termwindow/mouseevent.rs b/wezterm-gui/src/termwindow/mouseevent.rs index 04ff367e3..849f77275 100644 --- a/wezterm-gui/src/termwindow/mouseevent.rs +++ b/wezterm-gui/src/termwindow/mouseevent.rs @@ -95,13 +95,6 @@ impl super::TermWindow { } WMEK::Press(ref press) => { - if let Some(focused) = self.focused.as_ref() { - if focused.elapsed() <= Duration::from_millis(200) { - log::trace!("discard mouse click because it focused the window"); - return; - } - } - // Perform click counting let button = mouse_press_to_tmb(press); @@ -385,6 +378,14 @@ impl super::TermWindow { break; } } + if let Some(focused) = self.focused.as_ref() { + if focused.elapsed() <= Duration::from_millis(200) { + if is_click_to_focus { + context.invalidate(); + } + return; + } + } let dims = pane.get_dimensions(); let stable_row = self diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 02b15f6e7..7a20eb339 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -1483,6 +1483,10 @@ impl WindowView { } } + extern "C" fn accepts_first_mouse(_this: &mut Object, _sel: Sel, _nsevent: id) -> BOOL { + YES + } + extern "C" fn accepts_first_responder(_this: &mut Object, _sel: Sel) -> BOOL { YES } @@ -2118,6 +2122,11 @@ impl WindowView { Self::accepts_first_responder as extern "C" fn(&mut Object, Sel) -> BOOL, ); + cls.add_method( + sel!(acceptsFirstMouse:), + Self::accepts_first_mouse as extern "C" fn(&mut Object, Sel, id) -> BOOL, + ); + // NSTextInputClient cls.add_method(