mirror of
https://github.com/wez/wezterm.git
synced 2024-09-20 03:09:06 +03:00
Ignore mouse clicks that coincide with window focusing
Now that we can track focus changes, we can eliminate an annoyance: clicking in the window to focus it would cause a click event to be passed to the terminal and clear the selection. This commit will swallow button events that occur within 200ms of the focus being gained by the window.
This commit is contained in:
parent
8485e5db0c
commit
699d092a6b
@ -102,7 +102,8 @@ impl PrevCursorPos {
|
||||
|
||||
pub struct TermWindow {
|
||||
window: Option<Window>,
|
||||
focused: bool,
|
||||
/// When we most recently received keyboard focus
|
||||
focused: Option<Instant>,
|
||||
fonts: Rc<FontConfiguration>,
|
||||
/// Window dimensions and dpi
|
||||
dimensions: Dimensions,
|
||||
@ -189,7 +190,7 @@ impl WindowCallbacks for TermWindow {
|
||||
|
||||
fn focus_change(&mut self, focused: bool) {
|
||||
log::trace!("Setting focus to {:?}", focused);
|
||||
self.focused = focused;
|
||||
self.focused = if focused { Some(Instant::now()) } else { None };
|
||||
// Reset the cursor blink phase
|
||||
self.prev_cursor.bump();
|
||||
|
||||
@ -219,6 +220,15 @@ impl WindowCallbacks for TermWindow {
|
||||
return;
|
||||
}
|
||||
}
|
||||
WMEK::Press(_) => {
|
||||
if let Some(focused) = self.focused.as_ref() {
|
||||
let now = Instant::now();
|
||||
if now - *focused <= Duration::from_millis(200) {
|
||||
log::trace!("discard mouse click because it focused the window");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
WMEK::Move => {
|
||||
if let Some(from_top) = self.scroll_drag_start.as_ref() {
|
||||
// Dragging the scroll bar
|
||||
@ -633,7 +643,7 @@ impl TermWindow {
|
||||
dimensions.pixel_height,
|
||||
Box::new(Self {
|
||||
window: None,
|
||||
focused: false,
|
||||
focused: None,
|
||||
mux_window_id,
|
||||
fonts: Rc::clone(fontconfig),
|
||||
render_metrics,
|
||||
@ -2135,7 +2145,8 @@ impl TermWindow {
|
||||
let shape = config.default_cursor_style.effective_shape(cursor.shape);
|
||||
// Work out the blinking shape if its a blinking cursor and it hasn't been disabled
|
||||
// and the window is focused.
|
||||
let blinking = shape.is_blinking() && config.cursor_blink_rate != 0 && self.focused;
|
||||
let blinking =
|
||||
shape.is_blinking() && config.cursor_blink_rate != 0 && self.focused.is_some();
|
||||
if blinking {
|
||||
// Divide the time since we last moved by the blink rate.
|
||||
// If the result is even then the cursor is "on", else it
|
||||
@ -2157,7 +2168,7 @@ impl TermWindow {
|
||||
CursorShape::Hidden
|
||||
};
|
||||
|
||||
let (fg_color, bg_color) = match (selected, self.focused, cursor_shape) {
|
||||
let (fg_color, bg_color) = match (selected, self.focused.is_some(), cursor_shape) {
|
||||
// Selected text overrides colors
|
||||
(true, _, CursorShape::Hidden) => (
|
||||
rgbcolor_to_window_color(palette.selection_fg),
|
||||
|
Loading…
Reference in New Issue
Block a user