mirror of
https://github.com/wez/wezterm.git
synced 2024-12-24 05:42:03 +03:00
add swallow_mouse_click_on_window_focus option
Separates out window vs pane click-to-focus behavior more distinctly, and fixes up the behavior when swallow_mouse_click_on_window_focus=false. refs: #1540
This commit is contained in:
parent
5f1b0cff18
commit
7fc7201ae5
@ -571,6 +571,9 @@ pub struct Config {
|
||||
#[serde(default)]
|
||||
pub swallow_mouse_click_on_pane_focus: bool,
|
||||
|
||||
#[serde(default = "default_swallow_mouse_click_on_window_focus")]
|
||||
pub swallow_mouse_click_on_window_focus: bool,
|
||||
|
||||
#[serde(default)]
|
||||
pub pane_focus_follows_mouse: bool,
|
||||
|
||||
@ -1058,6 +1061,10 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
fn default_swallow_mouse_click_on_window_focus() -> bool {
|
||||
cfg!(target_os = "macos")
|
||||
}
|
||||
|
||||
fn default_mux_output_parser_buffer_size() -> usize {
|
||||
128 * 1024
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
# `swallow_mouse_click_on_window_focus`
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
When set to `true`, clicking on a wezterm window will focus it.
|
||||
|
||||
When set to `false`,clickong on a wezterm window will focus it and then pass
|
||||
through the click to the pane where the
|
||||
[swallow_mouse_click_on_pane_focus](swallow_mouse_click_on_pane_focus.md)
|
||||
option will further modify mouse event processing.
|
||||
|
||||
The default is `true` on macOS but `false` on other systems.
|
||||
|
@ -308,7 +308,7 @@ pub struct TermWindow {
|
||||
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,
|
||||
is_click_to_focus_window: bool,
|
||||
last_mouse_coords: (usize, i64),
|
||||
window_drag_position: Option<MouseEvent>,
|
||||
current_mouse_event: Option<MouseEvent>,
|
||||
@ -405,7 +405,11 @@ impl TermWindow {
|
||||
if self.focused.is_none() {
|
||||
self.last_mouse_click = None;
|
||||
self.current_mouse_buttons.clear();
|
||||
self.is_click_to_focus = false;
|
||||
self.is_click_to_focus_window = false;
|
||||
|
||||
for state in self.pane_state.borrow_mut().values_mut() {
|
||||
state.mouse_terminal_coords.take();
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the cursor blink phase
|
||||
@ -753,7 +757,7 @@ impl TermWindow {
|
||||
ui_items: vec![],
|
||||
dragging: None,
|
||||
last_ui_item: None,
|
||||
is_click_to_focus: false,
|
||||
is_click_to_focus_window: false,
|
||||
};
|
||||
|
||||
let tw = Rc::new(RefCell::new(myself));
|
||||
|
@ -465,7 +465,7 @@ impl super::TermWindow {
|
||||
event: MouseEvent,
|
||||
context: &dyn WindowOps,
|
||||
) {
|
||||
let mut is_click_to_focus = false;
|
||||
let mut is_click_to_focus_pane = false;
|
||||
|
||||
let mut x = position.column;
|
||||
let mut y = position.row;
|
||||
@ -485,7 +485,7 @@ impl super::TermWindow {
|
||||
.map(|tab| tab.set_active_idx(pos.index));
|
||||
|
||||
pane = Rc::clone(&pos.pane);
|
||||
is_click_to_focus = true;
|
||||
is_click_to_focus_pane = true;
|
||||
}
|
||||
WMEK::Move => {
|
||||
if self.config.pane_focus_follows_mouse {
|
||||
@ -513,29 +513,32 @@ impl super::TermWindow {
|
||||
}
|
||||
|
||||
let is_focused = if let Some(focused) = self.focused.as_ref() {
|
||||
focused.elapsed() > Duration::from_millis(200)
|
||||
!self.config.swallow_mouse_click_on_window_focus
|
||||
|| (focused.elapsed() > Duration::from_millis(200))
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
if self.focused.is_some() && !is_focused {
|
||||
if matches!(&event.kind, WMEK::Press(_)) {
|
||||
if matches!(&event.kind, WMEK::Press(_))
|
||||
&& self.config.swallow_mouse_click_on_window_focus
|
||||
{
|
||||
// Entering click to focus state
|
||||
self.is_click_to_focus = true;
|
||||
self.is_click_to_focus_window = true;
|
||||
context.invalidate();
|
||||
log::trace!("enter click to focus");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if self.is_click_to_focus && matches!(&event.kind, WMEK::Release(_)) {
|
||||
if self.is_click_to_focus_window && matches!(&event.kind, WMEK::Release(_)) {
|
||||
// Exiting click to focus state
|
||||
self.is_click_to_focus = false;
|
||||
self.is_click_to_focus_window = false;
|
||||
context.invalidate();
|
||||
log::trace!("exit click to focus");
|
||||
return;
|
||||
}
|
||||
|
||||
let allow_action = if self.is_click_to_focus || !is_focused {
|
||||
let allow_action = if self.is_click_to_focus_window || !is_focused {
|
||||
matches!(&event.kind, WMEK::VertWheel(_) | WMEK::HorzWheel(_))
|
||||
} else {
|
||||
true
|
||||
@ -731,7 +734,9 @@ impl super::TermWindow {
|
||||
modifiers: window_mods_to_termwiz_mods(event.modifiers),
|
||||
};
|
||||
|
||||
if allow_action && !(self.config.swallow_mouse_click_on_pane_focus && is_click_to_focus) {
|
||||
if allow_action
|
||||
&& !(self.config.swallow_mouse_click_on_pane_focus && is_click_to_focus_pane)
|
||||
{
|
||||
pane.mouse_event(mouse_event).ok();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user