1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-03 19:53:40 +03:00

gui: explicitly track click-to-focus state

we need to skip processing mouse events while in that state,
until we see the mouse release.

refs: #1310
This commit is contained in:
Wez Furlong 2021-12-12 22:45:46 -07:00
parent 137bdacd3f
commit c33f548db3
2 changed files with 17 additions and 5 deletions

View File

@ -229,6 +229,9 @@ pub struct TermWindow {
tab_bar: TabBarState,
pub right_status: String,
last_ui_item: Option<UIItem>,
/// Tracks whether the current mouse-down event is part of click-focus.
/// If so, we ignore mouse events until released
is_click_to_focus: bool,
last_mouse_coords: (usize, i64),
last_mouse_terminal_coords: (usize, StableRowIndex),
window_drag_position: Option<MouseEvent>,
@ -323,6 +326,7 @@ impl TermWindow {
if self.focused.is_none() {
self.last_mouse_click = None;
self.current_mouse_buttons.clear();
self.is_click_to_focus = false;
}
// Reset the cursor blink phase
@ -652,6 +656,7 @@ impl TermWindow {
ui_items: vec![],
dragging: None,
last_ui_item: None,
is_click_to_focus: false,
};
let tw = Rc::new(RefCell::new(myself));

View File

@ -12,7 +12,6 @@ use std::convert::TryInto;
use std::ops::Sub;
use std::rc::Rc;
use std::sync::Arc;
use std::time::Duration;
use wezterm_term::input::MouseEventKind as TMEK;
use wezterm_term::{LastMouseClick, StableRowIndex};
@ -471,10 +470,18 @@ 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();
if self.focused.is_some() {
// Entering click-to-focus state
if is_click_to_focus {
context.invalidate();
self.is_click_to_focus = true;
return;
}
// Check to see if we can leave click-to-focus state
if self.is_click_to_focus {
if matches!(event.kind, WMEK::Release(_)) {
self.is_click_to_focus = false;
}
return;
}