From 3d8e4f8b0e786caab4d8fda99b7758d9e8ca33c9 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 16 Jul 2019 23:45:42 -0700 Subject: [PATCH] fix issue where focusing the window would clear the clipboard This was particularly noticable on windows. --- src/frontend/glium/window.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/frontend/glium/window.rs b/src/frontend/glium/window.rs index 831fae164..cd553ca73 100644 --- a/src/frontend/glium/window.rs +++ b/src/frontend/glium/window.rs @@ -16,6 +16,7 @@ use glium::glutin::{self, ElementState, MouseCursor}; use log::{debug, error}; use std::rc::Rc; use std::sync::Arc; +use std::time::{Duration, Instant}; use term; use term::KeyCode; use term::KeyModifiers; @@ -83,6 +84,7 @@ pub struct GliumTerminalWindow { allow_received_character: bool, mux_window_id: WindowId, have_pending_resize_check: bool, + focus_instant: Instant, } impl TerminalWindow for GliumTerminalWindow { @@ -257,6 +259,7 @@ impl GliumTerminalWindow { allow_received_character: false, mux_window_id, have_pending_resize_check: false, + focus_instant: Instant::now(), }) } @@ -670,6 +673,14 @@ impl GliumTerminalWindow { self.host.with_window(|win| win.check_for_resize()); } } + Event::WindowEvent { + event: WindowEvent::Focused(focus), + .. + } => { + if focus { + self.focus_instant = Instant::now(); + } + } Event::WindowEvent { event: WindowEvent::Moved(position), .. @@ -723,7 +734,14 @@ impl GliumTerminalWindow { }, .. } => { - self.mouse_click(state, button, modifiers)?; + // When focusing the window, allow a brief grace period and ignore + // clicks within that interval. If we don't do this, the click will + // clear the current selection which is super annoying if you just + // copied some text in another app, and then clicked on the terminal + // to paste it. + if Instant::now() - self.focus_instant > Duration::from_millis(200) { + self.mouse_click(state, button, modifiers)?; + } } Event::WindowEvent { event: