2016-06-30 03:56:12 +00:00
|
|
|
// Copyright 2016 Joe Wilm, The Alacritty Project Contributors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
2016-06-23 16:48:31 +00:00
|
|
|
//! Handle input from glutin
|
|
|
|
//!
|
|
|
|
//! Certain key combinations should send some escape sequence back to the pty.
|
|
|
|
//! In order to figure that out, state about which modifier keys are pressed
|
|
|
|
//! needs to be tracked. Additionally, we need a bit of a state machine to
|
|
|
|
//! determine what to do when a non-modifier key is pressed.
|
2017-02-02 06:13:08 +00:00
|
|
|
use std::borrow::Cow;
|
2019-10-05 00:29:26 +00:00
|
|
|
use std::marker::PhantomData;
|
2017-01-02 02:28:49 +00:00
|
|
|
use std::mem;
|
2019-03-30 16:48:36 +00:00
|
|
|
use std::time::Instant;
|
2017-01-02 02:28:49 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
use glutin::event::{
|
|
|
|
ElementState, KeyboardInput, ModifiersState, MouseButton, MouseScrollDelta, TouchPhase,
|
|
|
|
VirtualKeyCode,
|
2019-03-19 19:14:17 +00:00
|
|
|
};
|
2019-10-05 00:29:26 +00:00
|
|
|
use glutin::window::CursorIcon;
|
|
|
|
use log::{debug, trace, warn};
|
|
|
|
|
|
|
|
use alacritty_terminal::ansi::{ClearMode, Handler};
|
|
|
|
use alacritty_terminal::clipboard::ClipboardType;
|
|
|
|
use alacritty_terminal::event::EventListener;
|
|
|
|
use alacritty_terminal::grid::Scroll;
|
|
|
|
use alacritty_terminal::index::{Column, Line, Point, Side};
|
|
|
|
use alacritty_terminal::message_bar::{self, Message};
|
|
|
|
use alacritty_terminal::term::mode::TermMode;
|
|
|
|
use alacritty_terminal::term::{SizeInfo, Term};
|
|
|
|
use alacritty_terminal::url::Url;
|
|
|
|
use alacritty_terminal::util::start_daemon;
|
|
|
|
|
|
|
|
use crate::config::{Action, Binding, Config, Key, RelaxedEq};
|
2019-03-24 17:37:30 +00:00
|
|
|
use crate::event::{ClickState, Mouse};
|
2019-10-05 00:29:26 +00:00
|
|
|
use crate::window::Window;
|
2018-07-21 17:17:41 +00:00
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
/// Font size change interval
|
|
|
|
pub const FONT_SIZE_STEP: f32 = 0.5;
|
|
|
|
|
2016-06-23 16:48:31 +00:00
|
|
|
/// Processes input from glutin.
|
|
|
|
///
|
|
|
|
/// An escape sequence may be emitted in case specific keys or key combinations
|
|
|
|
/// are activated.
|
2019-11-03 19:02:26 +00:00
|
|
|
pub struct Processor<T: EventListener, A: ActionContext<T>> {
|
2017-02-02 06:13:08 +00:00
|
|
|
pub ctx: A,
|
2019-10-05 00:29:26 +00:00
|
|
|
_phantom: PhantomData<T>,
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
pub trait ActionContext<T: EventListener> {
|
2018-12-10 17:53:56 +00:00
|
|
|
fn write_to_pty<B: Into<Cow<'static, [u8]>>>(&mut self, _: B);
|
2017-02-02 06:13:08 +00:00
|
|
|
fn size_info(&self) -> SizeInfo;
|
2019-04-28 20:21:39 +00:00
|
|
|
fn copy_selection(&mut self, _: ClipboardType);
|
2017-02-02 06:13:08 +00:00
|
|
|
fn clear_selection(&mut self);
|
2017-06-16 04:43:28 +00:00
|
|
|
fn update_selection(&mut self, point: Point, side: Side);
|
|
|
|
fn simple_selection(&mut self, point: Point, side: Side);
|
2019-06-20 15:56:09 +00:00
|
|
|
fn block_selection(&mut self, point: Point, side: Side);
|
2017-06-16 04:43:28 +00:00
|
|
|
fn semantic_selection(&mut self, point: Point);
|
|
|
|
fn line_selection(&mut self, point: Point);
|
2018-10-22 19:39:26 +00:00
|
|
|
fn selection_is_empty(&self) -> bool;
|
2017-02-02 06:13:08 +00:00
|
|
|
fn mouse_mut(&mut self) -> &mut Mouse;
|
2018-09-27 12:12:49 +00:00
|
|
|
fn mouse(&self) -> &Mouse;
|
2017-01-15 01:53:48 +00:00
|
|
|
fn mouse_coords(&self) -> Option<Point>;
|
2017-07-20 17:50:50 +00:00
|
|
|
fn received_count(&mut self) -> &mut usize;
|
|
|
|
fn suppress_chars(&mut self) -> &mut bool;
|
2019-08-24 23:18:51 +00:00
|
|
|
fn modifiers(&mut self) -> &mut Modifiers;
|
2018-03-11 12:01:06 +00:00
|
|
|
fn scroll(&mut self, scroll: Scroll);
|
2019-10-05 00:29:26 +00:00
|
|
|
fn window(&self) -> &Window;
|
|
|
|
fn window_mut(&mut self) -> &mut Window;
|
|
|
|
fn terminal(&self) -> &Term<T>;
|
|
|
|
fn terminal_mut(&mut self) -> &mut Term<T>;
|
2019-01-05 20:47:12 +00:00
|
|
|
fn spawn_new_instance(&mut self);
|
2019-10-05 00:29:26 +00:00
|
|
|
fn change_font_size(&mut self, delta: f32);
|
|
|
|
fn reset_font_size(&mut self);
|
|
|
|
fn pop_message(&mut self);
|
|
|
|
fn message(&self) -> Option<&Message>;
|
2019-11-03 19:02:26 +00:00
|
|
|
fn config(&self) -> &Config;
|
2016-07-02 15:32:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 23:18:51 +00:00
|
|
|
#[derive(Debug, Default, Copy, Clone)]
|
|
|
|
pub struct Modifiers {
|
|
|
|
mods: ModifiersState,
|
|
|
|
lshift: bool,
|
|
|
|
rshift: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Modifiers {
|
|
|
|
pub fn update(&mut self, input: KeyboardInput) {
|
|
|
|
match input.virtual_keycode {
|
|
|
|
Some(VirtualKeyCode::LShift) => self.lshift = input.state == ElementState::Pressed,
|
|
|
|
Some(VirtualKeyCode::RShift) => self.rshift = input.state == ElementState::Pressed,
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
self.mods = input.modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn shift(self) -> bool {
|
|
|
|
self.lshift || self.rshift
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn ctrl(self) -> bool {
|
|
|
|
self.mods.ctrl
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn logo(self) -> bool {
|
|
|
|
self.mods.logo
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn alt(self) -> bool {
|
|
|
|
self.mods.alt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-26 16:09:20 +00:00
|
|
|
impl From<&mut Modifiers> for ModifiersState {
|
|
|
|
fn from(mods: &mut Modifiers) -> ModifiersState {
|
2019-08-24 23:18:51 +00:00
|
|
|
ModifiersState { shift: mods.shift(), ..mods.mods }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
trait Execute<T: EventListener> {
|
|
|
|
fn execute<A: ActionContext<T>>(&self, ctx: &mut A, mouse_mode: bool);
|
2016-12-27 00:00:27 +00:00
|
|
|
}
|
2016-11-15 17:38:50 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl<T, U: EventListener> Execute<U> for Binding<T> {
|
2016-12-27 00:00:27 +00:00
|
|
|
/// Execute the action associate with this binding
|
2016-11-15 17:38:50 +00:00
|
|
|
#[inline]
|
2019-10-05 00:29:26 +00:00
|
|
|
fn execute<A: ActionContext<U>>(&self, ctx: &mut A, mouse_mode: bool) {
|
2018-11-01 19:35:37 +00:00
|
|
|
self.action.execute(ctx, mouse_mode)
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl<T: EventListener> Execute<T> for Action {
|
2016-11-15 17:38:50 +00:00
|
|
|
#[inline]
|
2019-10-05 00:29:26 +00:00
|
|
|
fn execute<A: ActionContext<T>>(&self, ctx: &mut A, mouse_mode: bool) {
|
2016-11-15 17:38:50 +00:00
|
|
|
match *self {
|
2016-12-26 23:33:27 +00:00
|
|
|
Action::Esc(ref s) => {
|
2019-10-29 16:56:48 +00:00
|
|
|
ctx.clear_selection();
|
2018-03-23 00:01:55 +00:00
|
|
|
ctx.scroll(Scroll::Bottom);
|
2017-02-02 06:13:08 +00:00
|
|
|
ctx.write_to_pty(s.clone().into_bytes())
|
2016-12-26 23:33:27 +00:00
|
|
|
},
|
2016-12-25 23:54:01 +00:00
|
|
|
Action::Copy => {
|
2019-06-09 11:46:31 +00:00
|
|
|
ctx.copy_selection(ClipboardType::Clipboard);
|
2016-12-25 23:54:01 +00:00
|
|
|
},
|
2017-01-20 05:55:38 +00:00
|
|
|
Action::Paste => {
|
2019-06-09 11:46:31 +00:00
|
|
|
let text = ctx.terminal_mut().clipboard().load(ClipboardType::Clipboard);
|
2019-10-05 00:29:26 +00:00
|
|
|
paste(ctx, &text);
|
2017-01-20 05:55:38 +00:00
|
|
|
},
|
2016-12-26 23:33:27 +00:00
|
|
|
Action::PasteSelection => {
|
2018-03-31 12:16:05 +00:00
|
|
|
// Only paste if mouse events are not captured by an application
|
2018-11-01 19:35:37 +00:00
|
|
|
if !mouse_mode {
|
2019-06-09 11:46:31 +00:00
|
|
|
let text = ctx.terminal_mut().clipboard().load(ClipboardType::Selection);
|
2019-10-05 00:29:26 +00:00
|
|
|
paste(ctx, &text);
|
2018-03-31 12:16:05 +00:00
|
|
|
}
|
2016-11-15 17:38:50 +00:00
|
|
|
},
|
2017-05-25 16:19:00 +00:00
|
|
|
Action::Command(ref program, ref args) => {
|
2019-01-07 00:06:57 +00:00
|
|
|
trace!("Running command {} with args {:?}", program, args);
|
2018-10-16 17:02:52 +00:00
|
|
|
|
2018-12-06 21:38:34 +00:00
|
|
|
match start_daemon(program, args) {
|
2019-04-30 13:30:46 +00:00
|
|
|
Ok(_) => debug!("Spawned new proc"),
|
|
|
|
Err(err) => warn!("Couldn't run command {}", err),
|
2017-05-25 16:19:00 +00:00
|
|
|
}
|
|
|
|
},
|
2019-10-05 00:29:26 +00:00
|
|
|
Action::ToggleFullscreen => ctx.window_mut().toggle_fullscreen(),
|
2019-04-23 19:05:47 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2019-10-05 00:29:26 +00:00
|
|
|
Action::ToggleSimpleFullscreen => ctx.window_mut().toggle_simple_fullscreen(),
|
|
|
|
Action::Hide => ctx.window().set_visible(false),
|
|
|
|
Action::Quit => ctx.terminal_mut().exit(),
|
|
|
|
Action::IncreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP),
|
|
|
|
Action::DecreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP * -1.),
|
|
|
|
Action::ResetFontSize => ctx.reset_font_size(),
|
|
|
|
Action::ScrollPageUp => ctx.scroll(Scroll::PageUp),
|
|
|
|
Action::ScrollPageDown => ctx.scroll(Scroll::PageDown),
|
|
|
|
Action::ScrollLineUp => ctx.scroll(Scroll::Lines(1)),
|
|
|
|
Action::ScrollLineDown => ctx.scroll(Scroll::Lines(-1)),
|
|
|
|
Action::ScrollToTop => ctx.scroll(Scroll::Top),
|
|
|
|
Action::ScrollToBottom => ctx.scroll(Scroll::Bottom),
|
|
|
|
Action::ClearHistory => ctx.terminal_mut().clear_screen(ClearMode::Saved),
|
|
|
|
Action::ClearLogNotice => ctx.pop_message(),
|
|
|
|
Action::SpawnNewInstance => ctx.spawn_new_instance(),
|
2019-09-28 00:37:22 +00:00
|
|
|
Action::ReceiveChar | Action::None => (),
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-01 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn paste<T: EventListener, A: ActionContext<T>>(ctx: &mut A, contents: &str) {
|
|
|
|
if ctx.terminal().mode().contains(TermMode::BRACKETED_PASTE) {
|
|
|
|
ctx.write_to_pty(&b"\x1b[200~"[..]);
|
|
|
|
ctx.write_to_pty(contents.replace("\x1b", "").into_bytes());
|
|
|
|
ctx.write_to_pty(&b"\x1b[201~"[..]);
|
|
|
|
} else {
|
|
|
|
// In non-bracketed (ie: normal) mode, terminal applications cannot distinguish
|
|
|
|
// pasted data from keystrokes.
|
|
|
|
// In theory, we should construct the keystrokes needed to produce the data we are
|
|
|
|
// pasting... since that's neither practical nor sensible (and probably an impossible
|
|
|
|
// task to solve in a general way), we'll just replace line breaks (windows and unix
|
|
|
|
// style) with a single carriage return (\r, which is what the Enter key produces).
|
|
|
|
ctx.write_to_pty(contents.replace("\r\n", "\r").replace("\n", "\r").into_bytes());
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-24 23:18:51 +00:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
|
|
pub enum MouseState {
|
2019-07-28 17:04:26 +00:00
|
|
|
Url(Url),
|
|
|
|
MessageBar,
|
|
|
|
MessageBarButton,
|
2019-08-24 23:18:51 +00:00
|
|
|
Mouse,
|
|
|
|
Text,
|
2019-07-28 17:04:26 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl From<MouseState> for CursorIcon {
|
|
|
|
fn from(mouse_state: MouseState) -> CursorIcon {
|
|
|
|
match mouse_state {
|
|
|
|
MouseState::Url(_) | MouseState::MessageBarButton => CursorIcon::Hand,
|
|
|
|
MouseState::Text => CursorIcon::Text,
|
|
|
|
_ => CursorIcon::Default,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
|
|
|
|
pub fn new(ctx: A) -> Self {
|
|
|
|
Self { ctx, _phantom: Default::default() }
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2019-08-26 16:09:20 +00:00
|
|
|
fn mouse_state(&mut self, point: Point, mods: ModifiersState) -> MouseState {
|
2019-08-03 13:19:33 +00:00
|
|
|
let mouse_mode =
|
|
|
|
TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG | TermMode::MOUSE_REPORT_CLICK;
|
|
|
|
|
2019-08-01 15:37:01 +00:00
|
|
|
// Check message bar before URL to ignore URLs in the message bar
|
2019-07-28 17:04:26 +00:00
|
|
|
if let Some(message) = self.message_at_point(Some(point)) {
|
|
|
|
if self.message_close_at_point(point, message) {
|
2019-08-24 23:18:51 +00:00
|
|
|
return MouseState::MessageBarButton;
|
2019-07-28 17:04:26 +00:00
|
|
|
} else {
|
2019-08-24 23:18:51 +00:00
|
|
|
return MouseState::MessageBar;
|
2019-07-28 17:04:26 +00:00
|
|
|
}
|
2019-08-03 13:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for URL at point with required modifiers held
|
2019-11-03 19:02:26 +00:00
|
|
|
if self.ctx.config().ui_config.mouse.url.mods().relaxed_eq(mods)
|
2019-08-26 16:09:20 +00:00
|
|
|
&& (!self.ctx.terminal().mode().intersects(mouse_mode) || mods.shift)
|
2019-11-03 19:02:26 +00:00
|
|
|
&& self.ctx.config().ui_config.mouse.url.launcher.is_some()
|
2019-09-09 20:39:39 +00:00
|
|
|
&& self.ctx.selection_is_empty()
|
|
|
|
&& self.ctx.mouse().left_button_state != ElementState::Pressed
|
2019-08-01 15:37:01 +00:00
|
|
|
{
|
2019-08-04 16:01:08 +00:00
|
|
|
let buffer_point = self.ctx.terminal().visible_to_buffer(point);
|
2019-08-03 13:19:33 +00:00
|
|
|
if let Some(url) =
|
|
|
|
self.ctx.terminal().urls().drain(..).find(|url| url.contains(buffer_point))
|
|
|
|
{
|
2019-08-24 23:18:51 +00:00
|
|
|
return MouseState::Url(url);
|
2019-08-03 13:19:33 +00:00
|
|
|
}
|
2019-07-28 17:04:26 +00:00
|
|
|
}
|
2019-08-03 13:19:33 +00:00
|
|
|
|
2019-08-24 23:18:51 +00:00
|
|
|
if self.ctx.terminal().mode().intersects(mouse_mode) && !self.ctx.modifiers().shift() {
|
|
|
|
MouseState::Mouse
|
|
|
|
} else {
|
|
|
|
MouseState::Text
|
|
|
|
}
|
2019-07-28 17:04:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 04:25:37 +00:00
|
|
|
#[inline]
|
2018-03-13 18:00:14 +00:00
|
|
|
pub fn mouse_moved(&mut self, x: usize, y: usize, modifiers: ModifiersState) {
|
2017-02-02 06:13:08 +00:00
|
|
|
self.ctx.mouse_mut().x = x;
|
|
|
|
self.ctx.mouse_mut().y = y;
|
2016-12-12 06:02:03 +00:00
|
|
|
|
2017-02-02 06:13:08 +00:00
|
|
|
let size_info = self.ctx.size_info();
|
2018-03-13 18:00:14 +00:00
|
|
|
let point = size_info.pixels_to_coords(x, y);
|
|
|
|
|
2018-10-22 19:39:26 +00:00
|
|
|
let cell_side = self.get_mouse_side();
|
|
|
|
let prev_side = mem::replace(&mut self.ctx.mouse_mut().cell_side, cell_side);
|
2018-03-13 18:00:14 +00:00
|
|
|
let prev_line = mem::replace(&mut self.ctx.mouse_mut().line, point.line);
|
|
|
|
let prev_col = mem::replace(&mut self.ctx.mouse_mut().column, point.col);
|
|
|
|
|
|
|
|
let motion_mode = TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG;
|
|
|
|
let report_mode = TermMode::MOUSE_REPORT_CLICK | motion_mode;
|
|
|
|
|
2019-04-28 22:36:02 +00:00
|
|
|
let cell_changed =
|
|
|
|
prev_line != self.ctx.mouse().line || prev_col != self.ctx.mouse().column;
|
2019-07-08 18:13:55 +00:00
|
|
|
|
|
|
|
// If the mouse hasn't changed cells, do nothing
|
2019-07-10 18:27:43 +00:00
|
|
|
if !cell_changed && prev_side == cell_side {
|
2019-07-08 18:13:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-22 19:39:26 +00:00
|
|
|
|
2019-04-28 22:36:02 +00:00
|
|
|
// Don't launch URLs if mouse has moved
|
|
|
|
self.ctx.mouse_mut().block_url_launcher = true;
|
|
|
|
|
2019-08-26 16:09:20 +00:00
|
|
|
let mouse_state = self.mouse_state(point, modifiers);
|
2019-08-24 23:18:51 +00:00
|
|
|
self.update_mouse_cursor(mouse_state);
|
|
|
|
match mouse_state {
|
|
|
|
MouseState::Url(url) => {
|
2019-08-03 13:19:33 +00:00
|
|
|
let url_bounds = url.linear_bounds(self.ctx.terminal());
|
|
|
|
self.ctx.terminal_mut().set_url_highlight(url_bounds);
|
2019-07-28 17:04:26 +00:00
|
|
|
},
|
2019-08-24 23:18:51 +00:00
|
|
|
MouseState::MessageBar | MouseState::MessageBarButton => {
|
2019-07-28 17:04:26 +00:00
|
|
|
self.ctx.terminal_mut().reset_url_highlight();
|
|
|
|
return;
|
|
|
|
},
|
2019-08-24 23:18:51 +00:00
|
|
|
_ => self.ctx.terminal_mut().reset_url_highlight(),
|
2019-04-28 22:36:02 +00:00
|
|
|
}
|
2019-03-19 19:14:17 +00:00
|
|
|
|
2018-11-01 19:35:37 +00:00
|
|
|
if self.ctx.mouse().left_button_state == ElementState::Pressed
|
2019-02-07 22:36:45 +00:00
|
|
|
&& (modifiers.shift || !self.ctx.terminal().mode().intersects(report_mode))
|
2018-03-13 18:00:14 +00:00
|
|
|
{
|
2019-03-30 16:48:36 +00:00
|
|
|
self.ctx.update_selection(Point { line: point.line, col: point.col }, cell_side);
|
2019-02-07 22:36:45 +00:00
|
|
|
} else if self.ctx.terminal().mode().intersects(motion_mode)
|
2019-03-04 16:20:15 +00:00
|
|
|
&& size_info.contains_point(x, y, false)
|
2019-04-28 22:36:02 +00:00
|
|
|
&& cell_changed
|
2018-03-13 18:00:14 +00:00
|
|
|
{
|
2018-09-27 12:12:49 +00:00
|
|
|
if self.ctx.mouse().left_button_state == ElementState::Pressed {
|
2018-03-13 18:00:14 +00:00
|
|
|
self.mouse_report(32, ElementState::Pressed, modifiers);
|
2018-09-27 12:12:49 +00:00
|
|
|
} else if self.ctx.mouse().middle_button_state == ElementState::Pressed {
|
2018-03-13 18:00:14 +00:00
|
|
|
self.mouse_report(33, ElementState::Pressed, modifiers);
|
2018-09-27 12:12:49 +00:00
|
|
|
} else if self.ctx.mouse().right_button_state == ElementState::Pressed {
|
2018-03-13 18:00:14 +00:00
|
|
|
self.mouse_report(34, ElementState::Pressed, modifiers);
|
2019-02-07 22:36:45 +00:00
|
|
|
} else if self.ctx.terminal().mode().contains(TermMode::MOUSE_MOTION) {
|
2018-03-13 18:00:14 +00:00
|
|
|
self.mouse_report(35, ElementState::Pressed, modifiers);
|
2016-12-22 18:43:06 +00:00
|
|
|
}
|
2016-12-12 06:02:03 +00:00
|
|
|
}
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 19:39:26 +00:00
|
|
|
fn get_mouse_side(&self) -> Side {
|
|
|
|
let size_info = self.ctx.size_info();
|
|
|
|
let x = self.ctx.mouse().x;
|
|
|
|
|
|
|
|
let cell_x = x.saturating_sub(size_info.padding_x as usize) % size_info.cell_width as usize;
|
|
|
|
let half_cell_width = (size_info.cell_width / 2.0) as usize;
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
let additional_padding =
|
|
|
|
(size_info.width - size_info.padding_x * 2.) % size_info.cell_width;
|
2018-10-22 19:39:26 +00:00
|
|
|
let end_of_grid = size_info.width - size_info.padding_x - additional_padding;
|
|
|
|
|
|
|
|
if cell_x > half_cell_width
|
|
|
|
// Edge case when mouse leaves the window
|
|
|
|
|| x as f32 >= end_of_grid
|
|
|
|
{
|
|
|
|
Side::Right
|
|
|
|
} else {
|
|
|
|
Side::Left
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-02 02:28:49 +00:00
|
|
|
pub fn normal_mouse_report(&mut self, button: u8) {
|
2018-09-27 12:12:49 +00:00
|
|
|
let (line, column) = (self.ctx.mouse().line, self.ctx.mouse().column);
|
2016-12-22 18:43:06 +00:00
|
|
|
|
|
|
|
if line < Line(223) && column < Column(223) {
|
|
|
|
let msg = vec![
|
2017-09-28 00:29:44 +00:00
|
|
|
b'\x1b',
|
|
|
|
b'[',
|
|
|
|
b'M',
|
2016-12-22 18:43:06 +00:00
|
|
|
32 + button,
|
|
|
|
32 + 1 + column.0 as u8,
|
|
|
|
32 + 1 + line.0 as u8,
|
|
|
|
];
|
|
|
|
|
2017-02-02 06:13:08 +00:00
|
|
|
self.ctx.write_to_pty(msg);
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 19:39:33 +00:00
|
|
|
pub fn sgr_mouse_report(&mut self, button: u8, state: ElementState) {
|
2018-09-27 12:12:49 +00:00
|
|
|
let (line, column) = (self.ctx.mouse().line, self.ctx.mouse().column);
|
2018-01-06 19:39:33 +00:00
|
|
|
let c = match state {
|
|
|
|
ElementState::Pressed => 'M',
|
|
|
|
ElementState::Released => 'm',
|
|
|
|
};
|
2017-01-02 02:28:49 +00:00
|
|
|
|
|
|
|
let msg = format!("\x1b[<{};{};{}{}", button, column + 1, line + 1, c);
|
2017-02-02 06:13:08 +00:00
|
|
|
self.ctx.write_to_pty(msg.into_bytes());
|
2017-01-02 02:28:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 21:50:04 +00:00
|
|
|
pub fn mouse_report(&mut self, button: u8, state: ElementState, modifiers: ModifiersState) {
|
|
|
|
// Calculate modifiers value
|
|
|
|
let mut mods = 0;
|
|
|
|
if modifiers.shift {
|
|
|
|
mods += 4;
|
|
|
|
}
|
2018-03-09 23:40:53 +00:00
|
|
|
if modifiers.alt {
|
2018-03-08 21:50:04 +00:00
|
|
|
mods += 8;
|
|
|
|
}
|
|
|
|
if modifiers.ctrl {
|
|
|
|
mods += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report mouse events
|
2019-02-07 22:36:45 +00:00
|
|
|
if self.ctx.terminal().mode().contains(TermMode::SGR_MOUSE) {
|
2018-03-08 21:50:04 +00:00
|
|
|
self.sgr_mouse_report(button + mods, state);
|
2018-01-26 22:37:48 +00:00
|
|
|
} else if let ElementState::Released = state {
|
2018-03-08 21:50:04 +00:00
|
|
|
self.normal_mouse_report(3 + mods);
|
2017-01-02 02:28:49 +00:00
|
|
|
} else {
|
2018-03-08 21:50:04 +00:00
|
|
|
self.normal_mouse_report(button + mods);
|
2017-01-02 02:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 20:13:14 +00:00
|
|
|
pub fn on_mouse_double_click(&mut self, button: MouseButton, point: Option<Point>) {
|
|
|
|
if let (Some(point), true) = (point, button == MouseButton::Left) {
|
2017-01-15 01:53:48 +00:00
|
|
|
self.ctx.semantic_selection(point);
|
2016-12-22 18:43:06 +00:00
|
|
|
}
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
2016-12-22 18:43:06 +00:00
|
|
|
|
2019-02-21 20:13:14 +00:00
|
|
|
pub fn on_mouse_triple_click(&mut self, button: MouseButton, point: Option<Point>) {
|
|
|
|
if let (Some(point), true) = (point, button == MouseButton::Left) {
|
2017-01-15 01:53:48 +00:00
|
|
|
self.ctx.line_selection(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
pub fn on_mouse_press(
|
|
|
|
&mut self,
|
|
|
|
button: MouseButton,
|
|
|
|
modifiers: ModifiersState,
|
2019-02-21 20:13:14 +00:00
|
|
|
point: Option<Point>,
|
2019-02-07 22:36:45 +00:00
|
|
|
) {
|
2017-01-15 01:53:48 +00:00
|
|
|
let now = Instant::now();
|
2018-09-27 12:12:49 +00:00
|
|
|
let elapsed = self.ctx.mouse().last_click_timestamp.elapsed();
|
2017-01-15 01:53:48 +00:00
|
|
|
self.ctx.mouse_mut().last_click_timestamp = now;
|
|
|
|
|
2019-01-08 07:37:58 +00:00
|
|
|
let button_changed = self.ctx.mouse().last_button != button;
|
|
|
|
|
2018-09-27 12:12:49 +00:00
|
|
|
self.ctx.mouse_mut().click_state = match self.ctx.mouse().click_state {
|
2019-01-08 07:37:58 +00:00
|
|
|
ClickState::Click
|
2019-10-05 00:29:26 +00:00
|
|
|
if !button_changed
|
2019-11-03 19:02:26 +00:00
|
|
|
&& elapsed < self.ctx.config().ui_config.mouse.double_click.threshold =>
|
2019-01-08 07:37:58 +00:00
|
|
|
{
|
2018-10-22 19:39:26 +00:00
|
|
|
self.ctx.mouse_mut().block_url_launcher = true;
|
2019-02-07 22:36:45 +00:00
|
|
|
self.on_mouse_double_click(button, point);
|
2017-01-15 01:53:48 +00:00
|
|
|
ClickState::DoubleClick
|
2019-03-30 16:48:36 +00:00
|
|
|
}
|
2019-01-08 07:37:58 +00:00
|
|
|
ClickState::DoubleClick
|
2019-10-05 00:29:26 +00:00
|
|
|
if !button_changed
|
2019-11-03 19:02:26 +00:00
|
|
|
&& elapsed < self.ctx.config().ui_config.mouse.triple_click.threshold =>
|
2019-01-08 07:37:58 +00:00
|
|
|
{
|
2018-10-22 19:39:26 +00:00
|
|
|
self.ctx.mouse_mut().block_url_launcher = true;
|
2019-02-07 22:36:45 +00:00
|
|
|
self.on_mouse_triple_click(button, point);
|
2017-01-15 01:53:48 +00:00
|
|
|
ClickState::TripleClick
|
2019-03-30 16:48:36 +00:00
|
|
|
}
|
2017-01-15 01:53:48 +00:00
|
|
|
_ => {
|
2018-10-22 19:39:26 +00:00
|
|
|
// Don't launch URLs if this click cleared the selection
|
|
|
|
self.ctx.mouse_mut().block_url_launcher = !self.ctx.selection_is_empty();
|
|
|
|
|
2018-01-02 16:03:47 +00:00
|
|
|
self.ctx.clear_selection();
|
2018-09-27 12:12:49 +00:00
|
|
|
|
|
|
|
// Start new empty selection
|
2019-02-07 22:36:45 +00:00
|
|
|
let side = self.ctx.mouse().cell_side;
|
2019-02-21 20:13:14 +00:00
|
|
|
if let Some(point) = point {
|
2019-06-20 15:56:09 +00:00
|
|
|
if modifiers.ctrl {
|
|
|
|
self.ctx.block_selection(point, side);
|
|
|
|
} else {
|
|
|
|
self.ctx.simple_selection(point, side);
|
|
|
|
}
|
2019-02-21 20:13:14 +00:00
|
|
|
}
|
2019-02-07 22:36:45 +00:00
|
|
|
|
|
|
|
let report_modes =
|
|
|
|
TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
|
|
|
|
if !modifiers.shift && self.ctx.terminal().mode().intersects(report_modes) {
|
|
|
|
let code = match button {
|
|
|
|
MouseButton::Left => 0,
|
|
|
|
MouseButton::Middle => 1,
|
|
|
|
MouseButton::Right => 2,
|
2018-01-26 21:28:43 +00:00
|
|
|
// Can't properly report more than three buttons.
|
2019-02-07 22:36:45 +00:00
|
|
|
MouseButton::Other(_) => return,
|
2018-01-26 21:28:43 +00:00
|
|
|
};
|
2019-02-07 22:36:45 +00:00
|
|
|
self.mouse_report(code, ElementState::Pressed, modifiers);
|
2017-01-15 01:53:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClickState::Click
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
pub fn on_mouse_release(
|
|
|
|
&mut self,
|
|
|
|
button: MouseButton,
|
|
|
|
modifiers: ModifiersState,
|
2019-02-21 20:13:14 +00:00
|
|
|
point: Option<Point>,
|
2019-02-07 22:36:45 +00:00
|
|
|
) {
|
|
|
|
let report_modes =
|
|
|
|
TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
|
|
|
|
if !modifiers.shift && self.ctx.terminal().mode().intersects(report_modes) {
|
|
|
|
let code = match button {
|
|
|
|
MouseButton::Left => 0,
|
|
|
|
MouseButton::Middle => 1,
|
|
|
|
MouseButton::Right => 2,
|
2018-01-26 21:28:43 +00:00
|
|
|
// Can't properly report more than three buttons.
|
2019-02-07 22:36:45 +00:00
|
|
|
MouseButton::Other(_) => return,
|
2018-01-26 21:28:43 +00:00
|
|
|
};
|
2019-02-07 22:36:45 +00:00
|
|
|
self.mouse_report(code, ElementState::Released, modifiers);
|
2016-12-22 18:43:06 +00:00
|
|
|
return;
|
2019-02-21 20:13:14 +00:00
|
|
|
} else if let (Some(point), true) = (point, button == MouseButton::Left) {
|
2019-09-09 20:39:39 +00:00
|
|
|
let mouse_state = self.mouse_state(point, modifiers);
|
|
|
|
self.update_mouse_cursor(mouse_state);
|
|
|
|
if let MouseState::Url(url) = mouse_state {
|
|
|
|
let url_bounds = url.linear_bounds(self.ctx.terminal());
|
|
|
|
self.ctx.terminal_mut().set_url_highlight(url_bounds);
|
|
|
|
self.launch_url(url);
|
|
|
|
}
|
2016-12-22 18:43:06 +00:00
|
|
|
}
|
2016-12-30 01:39:30 +00:00
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
self.copy_selection();
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Spawn URL launcher when clicking on URLs.
|
2019-09-09 20:39:39 +00:00
|
|
|
fn launch_url(&self, url: Url) {
|
|
|
|
if self.ctx.mouse().block_url_launcher {
|
|
|
|
return;
|
2018-10-22 19:39:26 +00:00
|
|
|
}
|
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
if let Some(ref launcher) = self.ctx.config().ui_config.mouse.url.launcher {
|
2019-09-09 20:39:39 +00:00
|
|
|
let mut args = launcher.args().to_vec();
|
|
|
|
args.push(self.ctx.terminal().url_to_string(url));
|
2018-10-22 19:39:26 +00:00
|
|
|
|
2019-09-09 20:39:39 +00:00
|
|
|
match start_daemon(launcher.program(), &args) {
|
|
|
|
Ok(_) => debug!("Launched {} with args {:?}", launcher.program(), args),
|
|
|
|
Err(_) => warn!("Unable to launch {} with args {:?}", launcher.program(), args),
|
|
|
|
}
|
2018-10-22 19:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
pub fn on_mouse_wheel(
|
|
|
|
&mut self,
|
|
|
|
delta: MouseScrollDelta,
|
|
|
|
phase: TouchPhase,
|
|
|
|
modifiers: ModifiersState,
|
|
|
|
) {
|
2016-11-25 03:50:34 +00:00
|
|
|
match delta {
|
2016-12-12 04:00:00 +00:00
|
|
|
MouseScrollDelta::LineDelta(_columns, lines) => {
|
2019-01-27 21:06:27 +00:00
|
|
|
let new_scroll_px = lines * self.ctx.size_info().cell_height;
|
|
|
|
self.scroll_terminal(modifiers, new_scroll_px as i32);
|
2016-11-25 03:50:34 +00:00
|
|
|
},
|
2018-11-10 16:08:48 +00:00
|
|
|
MouseScrollDelta::PixelDelta(lpos) => {
|
2016-11-25 03:50:34 +00:00
|
|
|
match phase {
|
|
|
|
TouchPhase::Started => {
|
|
|
|
// Reset offset to zero
|
2017-02-02 06:13:08 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px = 0;
|
2016-11-25 03:50:34 +00:00
|
|
|
},
|
|
|
|
TouchPhase::Moved => {
|
2019-01-27 21:06:27 +00:00
|
|
|
self.scroll_terminal(modifiers, lpos.y as i32);
|
2016-11-25 03:50:34 +00:00
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2016-11-25 03:50:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-27 21:06:27 +00:00
|
|
|
fn scroll_terminal(&mut self, modifiers: ModifiersState, new_scroll_px: i32) {
|
|
|
|
let mouse_modes =
|
|
|
|
TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
|
2019-10-15 19:13:58 +00:00
|
|
|
let alt_scroll_modes = TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL;
|
2019-01-27 21:06:27 +00:00
|
|
|
let height = self.ctx.size_info().cell_height as i32;
|
2018-03-09 22:02:45 +00:00
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
if self.ctx.terminal().mode().intersects(mouse_modes) {
|
2019-01-27 21:06:27 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px += new_scroll_px;
|
|
|
|
|
|
|
|
let code = if new_scroll_px > 0 { 64 } else { 65 };
|
|
|
|
let lines = (self.ctx.mouse().scroll_px / height).abs();
|
|
|
|
|
|
|
|
for _ in 0..lines {
|
|
|
|
self.mouse_report(code, ElementState::Pressed, modifiers);
|
|
|
|
}
|
2019-10-15 19:13:58 +00:00
|
|
|
} else if self.ctx.terminal().mode().contains(alt_scroll_modes) && !modifiers.shift {
|
|
|
|
let multiplier = i32::from(
|
2019-11-03 19:02:26 +00:00
|
|
|
self.ctx
|
|
|
|
.config()
|
2019-10-15 19:13:58 +00:00
|
|
|
.scrolling
|
|
|
|
.faux_multiplier()
|
2019-11-03 19:02:26 +00:00
|
|
|
.unwrap_or_else(|| self.ctx.config().scrolling.multiplier()),
|
2019-10-15 19:13:58 +00:00
|
|
|
);
|
|
|
|
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
|
2019-01-27 21:06:27 +00:00
|
|
|
|
|
|
|
let cmd = if new_scroll_px > 0 { b'A' } else { b'B' };
|
|
|
|
let lines = (self.ctx.mouse().scroll_px / height).abs();
|
|
|
|
|
|
|
|
let mut content = Vec::with_capacity(lines as usize * 3);
|
|
|
|
for _ in 0..lines {
|
2018-03-09 10:17:47 +00:00
|
|
|
content.push(0x1b);
|
|
|
|
content.push(b'O');
|
|
|
|
content.push(cmd);
|
|
|
|
}
|
|
|
|
self.ctx.write_to_pty(content);
|
2018-02-16 02:35:49 +00:00
|
|
|
} else {
|
2019-11-03 19:02:26 +00:00
|
|
|
let multiplier = i32::from(self.ctx.config().scrolling.multiplier());
|
2019-01-27 21:06:27 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
|
|
|
|
|
|
|
|
let lines = self.ctx.mouse().scroll_px / height;
|
|
|
|
|
|
|
|
self.ctx.scroll(Scroll::Lines(lines as isize));
|
2017-12-25 21:15:41 +00:00
|
|
|
}
|
2019-01-27 21:06:27 +00:00
|
|
|
|
|
|
|
self.ctx.mouse_mut().scroll_px %= height;
|
2017-12-25 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 16:51:49 +00:00
|
|
|
pub fn on_focus_change(&mut self, is_focused: bool) {
|
2019-02-07 22:36:45 +00:00
|
|
|
if self.ctx.terminal().mode().contains(TermMode::FOCUS_IN_OUT) {
|
2019-03-30 16:48:36 +00:00
|
|
|
let chr = if is_focused { "I" } else { "O" };
|
2017-05-29 16:51:49 +00:00
|
|
|
|
|
|
|
let msg = format!("\x1b[{}", chr);
|
|
|
|
self.ctx.write_to_pty(msg.into_bytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
pub fn mouse_input(
|
|
|
|
&mut self,
|
|
|
|
state: ElementState,
|
|
|
|
button: MouseButton,
|
2019-03-30 16:48:36 +00:00
|
|
|
modifiers: ModifiersState,
|
2019-02-07 22:36:45 +00:00
|
|
|
) {
|
2019-01-03 01:56:28 +00:00
|
|
|
match button {
|
|
|
|
MouseButton::Left => self.ctx.mouse_mut().left_button_state = state,
|
|
|
|
MouseButton::Middle => self.ctx.mouse_mut().middle_button_state = state,
|
|
|
|
MouseButton::Right => self.ctx.mouse_mut().right_button_state = state,
|
|
|
|
_ => (),
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 20:13:14 +00:00
|
|
|
let point = self.ctx.mouse_coords();
|
2019-02-07 22:36:45 +00:00
|
|
|
|
|
|
|
// Skip normal mouse events if the message bar has been clicked
|
2019-02-21 20:13:14 +00:00
|
|
|
if let Some(message) = self.message_at_point(point) {
|
|
|
|
// Message should never be `Some` if point is `None`
|
|
|
|
debug_assert!(point.is_some());
|
2019-08-26 16:09:20 +00:00
|
|
|
self.on_message_bar_click(state, point.unwrap(), message, modifiers);
|
2019-02-07 22:36:45 +00:00
|
|
|
} else {
|
|
|
|
match state {
|
|
|
|
ElementState::Pressed => {
|
|
|
|
self.process_mouse_bindings(modifiers, button);
|
|
|
|
self.on_mouse_press(button, modifiers, point);
|
|
|
|
},
|
|
|
|
ElementState::Released => self.on_mouse_release(button, modifiers, point),
|
|
|
|
}
|
2016-09-27 05:22:28 +00:00
|
|
|
}
|
2019-01-08 07:37:58 +00:00
|
|
|
|
|
|
|
self.ctx.mouse_mut().last_button = button;
|
2016-09-27 05:22:28 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Process key input.
|
2018-10-16 18:46:26 +00:00
|
|
|
pub fn process_key(&mut self, input: KeyboardInput) {
|
2019-08-24 23:18:51 +00:00
|
|
|
self.ctx.modifiers().update(input);
|
|
|
|
|
|
|
|
// Update mouse cursor for temporarily disabling mouse mode
|
|
|
|
if input.virtual_keycode == Some(VirtualKeyCode::LShift)
|
|
|
|
|| input.virtual_keycode == Some(VirtualKeyCode::RShift)
|
|
|
|
{
|
|
|
|
if let Some(point) = self.ctx.mouse_coords() {
|
2019-08-26 16:09:20 +00:00
|
|
|
let mods = self.ctx.modifiers().into();
|
|
|
|
let mouse_state = self.mouse_state(point, mods);
|
2019-08-24 23:18:51 +00:00
|
|
|
self.update_mouse_cursor(mouse_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 18:46:26 +00:00
|
|
|
match input.state {
|
|
|
|
ElementState::Pressed => {
|
2017-07-20 17:50:50 +00:00
|
|
|
*self.ctx.received_count() = 0;
|
2019-09-28 00:37:22 +00:00
|
|
|
self.process_key_bindings(input);
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2018-10-16 18:46:26 +00:00
|
|
|
ElementState::Released => *self.ctx.suppress_chars() = false,
|
2017-07-20 17:50:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Process a received character.
|
2017-07-20 17:50:50 +00:00
|
|
|
pub fn received_char(&mut self, c: char) {
|
2019-02-16 20:23:23 +00:00
|
|
|
if *self.ctx.suppress_chars() {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-07 06:04:51 +00:00
|
|
|
|
2019-02-16 20:23:23 +00:00
|
|
|
self.ctx.scroll(Scroll::Bottom);
|
|
|
|
self.ctx.clear_selection();
|
2018-12-20 00:33:42 +00:00
|
|
|
|
2019-02-16 20:23:23 +00:00
|
|
|
let utf8_len = c.len_utf8();
|
|
|
|
let mut bytes = Vec::with_capacity(utf8_len);
|
|
|
|
unsafe {
|
|
|
|
bytes.set_len(utf8_len);
|
|
|
|
c.encode_utf8(&mut bytes[..]);
|
|
|
|
}
|
2017-07-20 17:50:50 +00:00
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
if self.ctx.config().alt_send_esc()
|
2019-02-16 20:23:23 +00:00
|
|
|
&& *self.ctx.received_count() == 0
|
2019-08-24 23:18:51 +00:00
|
|
|
&& self.ctx.modifiers().alt()
|
2019-02-16 20:23:23 +00:00
|
|
|
&& utf8_len == 1
|
|
|
|
{
|
|
|
|
bytes.insert(0, b'\x1b');
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
2019-02-16 20:23:23 +00:00
|
|
|
|
|
|
|
self.ctx.write_to_pty(bytes);
|
|
|
|
|
|
|
|
*self.ctx.received_count() += 1;
|
2019-10-05 00:29:26 +00:00
|
|
|
self.ctx.terminal_mut().dirty = false;
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Attempt to find a binding and execute its action.
|
2016-11-15 17:38:50 +00:00
|
|
|
///
|
|
|
|
/// The provided mode, mods, and key must match what is allowed by a binding
|
|
|
|
/// for its action to be executed.
|
2019-09-28 00:37:22 +00:00
|
|
|
fn process_key_bindings(&mut self, input: KeyboardInput) {
|
2019-10-05 00:29:26 +00:00
|
|
|
let mut suppress_chars = None;
|
2019-09-28 00:37:22 +00:00
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
for i in 0..self.ctx.config().ui_config.key_bindings.len() {
|
|
|
|
let binding = &self.ctx.config().ui_config.key_bindings[i];
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
let key = match (binding.trigger, input.virtual_keycode) {
|
|
|
|
(Key::Scancode(_), _) => Key::Scancode(input.scancode),
|
|
|
|
(_, Some(key)) => Key::from_glutin_input(key),
|
|
|
|
_ => continue,
|
|
|
|
};
|
|
|
|
|
|
|
|
if binding.is_triggered_by(*self.ctx.terminal().mode(), input.modifiers, &key, false) {
|
2019-09-28 00:37:22 +00:00
|
|
|
// Binding was triggered; run the action
|
2019-11-03 19:02:26 +00:00
|
|
|
let binding = binding.clone();
|
2018-11-01 19:35:37 +00:00
|
|
|
binding.execute(&mut self.ctx, false);
|
2016-11-15 17:38:50 +00:00
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
// Don't suppress when there has been a `ReceiveChar` action
|
2019-10-05 00:29:26 +00:00
|
|
|
*suppress_chars.get_or_insert(true) &= binding.action != Action::ReceiveChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't suppress char if no bindings were triggered
|
|
|
|
*self.ctx.suppress_chars() = suppress_chars.unwrap_or(false);
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Attempt to find a binding and execute its action.
|
2016-11-15 17:38:50 +00:00
|
|
|
///
|
|
|
|
/// The provided mode, mods, and key must match what is allowed by a binding
|
|
|
|
/// for its action to be executed.
|
2019-09-28 00:37:22 +00:00
|
|
|
fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) {
|
2019-11-03 19:02:26 +00:00
|
|
|
for i in 0..self.ctx.config().ui_config.mouse_bindings.len() {
|
|
|
|
let binding = &self.ctx.config().ui_config.mouse_bindings[i];
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
if binding.is_triggered_by(*self.ctx.terminal().mode(), mods, &button, true) {
|
2016-11-15 17:38:50 +00:00
|
|
|
// binding was triggered; run the action
|
2019-03-30 16:48:36 +00:00
|
|
|
let mouse_mode = !mods.shift
|
|
|
|
&& self.ctx.terminal().mode().intersects(
|
|
|
|
TermMode::MOUSE_REPORT_CLICK
|
|
|
|
| TermMode::MOUSE_DRAG
|
|
|
|
| TermMode::MOUSE_MOTION,
|
|
|
|
);
|
2019-11-03 19:02:26 +00:00
|
|
|
|
|
|
|
let binding = binding.clone();
|
2018-11-01 19:35:37 +00:00
|
|
|
binding.execute(&mut self.ctx, mouse_mode);
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
2019-02-07 22:36:45 +00:00
|
|
|
|
2019-02-21 20:13:14 +00:00
|
|
|
/// Return the message bar's message if there is some at the specified point
|
|
|
|
fn message_at_point(&mut self, point: Option<Point>) -> Option<Message> {
|
2019-10-05 00:29:26 +00:00
|
|
|
let size = &self.ctx.size_info();
|
|
|
|
if let (Some(point), Some(message)) = (point, self.ctx.message()) {
|
|
|
|
if point.line.0 >= size.lines().saturating_sub(message.text(size).len()) {
|
|
|
|
return Some(message.to_owned());
|
2019-02-21 20:13:14 +00:00
|
|
|
}
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
2019-02-21 20:13:14 +00:00
|
|
|
|
|
|
|
None
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 18:13:55 +00:00
|
|
|
/// Whether the point is over the message bar's close button
|
|
|
|
fn message_close_at_point(&self, point: Point, message: Message) -> bool {
|
|
|
|
let size = self.ctx.size_info();
|
|
|
|
point.col + message_bar::CLOSE_BUTTON_TEXT.len() >= size.cols()
|
|
|
|
&& point.line == size.lines() - message.text(&size).len()
|
|
|
|
}
|
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
/// Handle clicks on the message bar.
|
2019-08-26 16:09:20 +00:00
|
|
|
fn on_message_bar_click(
|
|
|
|
&mut self,
|
|
|
|
button_state: ElementState,
|
|
|
|
point: Point,
|
|
|
|
message: Message,
|
|
|
|
mods: ModifiersState,
|
|
|
|
) {
|
2019-02-07 22:36:45 +00:00
|
|
|
match button_state {
|
|
|
|
ElementState::Released => self.copy_selection(),
|
|
|
|
ElementState::Pressed => {
|
2019-07-08 18:13:55 +00:00
|
|
|
if self.message_close_at_point(point, message) {
|
2019-08-26 16:09:20 +00:00
|
|
|
let mouse_state = self.mouse_state(point, mods);
|
2019-08-24 23:18:51 +00:00
|
|
|
self.update_mouse_cursor(mouse_state);
|
2019-10-05 00:29:26 +00:00
|
|
|
self.ctx.pop_message();
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self.ctx.clear_selection();
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Copy text selection.
|
|
|
|
fn copy_selection(&mut self) {
|
2019-11-03 19:02:26 +00:00
|
|
|
if self.ctx.config().selection.save_to_clipboard {
|
2019-06-09 11:46:31 +00:00
|
|
|
self.ctx.copy_selection(ClipboardType::Clipboard);
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
2019-06-09 11:46:31 +00:00
|
|
|
self.ctx.copy_selection(ClipboardType::Selection);
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
2019-08-24 23:18:51 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn update_mouse_cursor(&mut self, mouse_state: MouseState) {
|
2019-10-05 00:29:26 +00:00
|
|
|
self.ctx.window_mut().set_mouse_cursor(mouse_state.into());
|
|
|
|
}
|
2019-08-24 23:18:51 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn reset_mouse_cursor(&mut self) {
|
|
|
|
if let Some(point) = self.ctx.mouse_coords() {
|
|
|
|
let mods = self.ctx.modifiers().into();
|
|
|
|
let mouse_state = self.mouse_state(point, mods);
|
|
|
|
self.update_mouse_cursor(mouse_state);
|
|
|
|
}
|
2019-08-24 23:18:51 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2017-01-15 01:53:48 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
use std::time::Duration;
|
2016-06-23 16:48:31 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
use glutin::event::{
|
|
|
|
ElementState, Event, ModifiersState, MouseButton, VirtualKeyCode, WindowEvent,
|
|
|
|
};
|
|
|
|
|
|
|
|
use alacritty_terminal::clipboard::{Clipboard, ClipboardType};
|
|
|
|
use alacritty_terminal::event::{Event as TerminalEvent, EventListener};
|
|
|
|
use alacritty_terminal::grid::Scroll;
|
|
|
|
use alacritty_terminal::index::{Point, Side};
|
|
|
|
use alacritty_terminal::message_bar::{Message, MessageBuffer};
|
|
|
|
use alacritty_terminal::selection::Selection;
|
|
|
|
use alacritty_terminal::term::{SizeInfo, Term, TermMode};
|
2016-09-27 15:27:39 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
use crate::config::{ClickHandler, Config};
|
|
|
|
use crate::event::{ClickState, Mouse};
|
|
|
|
use crate::window::Window;
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2019-08-24 23:18:51 +00:00
|
|
|
use super::{Action, Binding, Modifiers, Processor};
|
2016-06-23 16:48:31 +00:00
|
|
|
|
2016-11-15 17:38:50 +00:00
|
|
|
const KEY: VirtualKeyCode = VirtualKeyCode::Key0;
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
struct MockEventProxy;
|
2019-07-15 21:32:48 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl EventListener for MockEventProxy {
|
|
|
|
fn send_event(&self, _event: TerminalEvent) {}
|
2019-07-15 21:32:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum MultiClick {
|
|
|
|
DoubleClick,
|
|
|
|
TripleClick,
|
|
|
|
None,
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
struct ActionContext<'a, T> {
|
|
|
|
pub terminal: &'a mut Term<T>,
|
2017-06-17 17:29:59 +00:00
|
|
|
pub selection: &'a mut Option<Selection>,
|
2017-01-15 01:53:48 +00:00
|
|
|
pub size_info: &'a SizeInfo,
|
|
|
|
pub mouse: &'a mut Mouse,
|
2019-10-05 00:29:26 +00:00
|
|
|
pub message_buffer: &'a mut MessageBuffer,
|
2017-01-15 01:53:48 +00:00
|
|
|
pub last_action: MultiClick,
|
2017-07-20 17:50:50 +00:00
|
|
|
pub received_count: usize,
|
|
|
|
pub suppress_chars: bool,
|
2019-08-24 23:18:51 +00:00
|
|
|
pub modifiers: Modifiers,
|
2019-11-03 19:02:26 +00:00
|
|
|
config: &'a Config,
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl<'a, T: EventListener> super::ActionContext<T> for ActionContext<'a, T> {
|
2019-01-05 20:47:12 +00:00
|
|
|
fn write_to_pty<B: Into<Cow<'static, [u8]>>>(&mut self, _val: B) {}
|
2019-03-30 16:48:36 +00:00
|
|
|
|
2019-01-05 20:47:12 +00:00
|
|
|
fn update_selection(&mut self, _point: Point, _side: Side) {}
|
2019-03-30 16:48:36 +00:00
|
|
|
|
2019-01-05 20:47:12 +00:00
|
|
|
fn simple_selection(&mut self, _point: Point, _side: Side) {}
|
2019-03-30 16:48:36 +00:00
|
|
|
|
2019-06-20 15:56:09 +00:00
|
|
|
fn block_selection(&mut self, _point: Point, _side: Side) {}
|
|
|
|
|
2019-04-28 20:21:39 +00:00
|
|
|
fn copy_selection(&mut self, _: ClipboardType) {}
|
2019-03-30 16:48:36 +00:00
|
|
|
|
2019-01-05 20:47:12 +00:00
|
|
|
fn clear_selection(&mut self) {}
|
2019-03-30 16:48:36 +00:00
|
|
|
|
2019-01-05 20:47:12 +00:00
|
|
|
fn spawn_new_instance(&mut self) {}
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn change_font_size(&mut self, _delta: f32) {}
|
2019-04-23 19:05:47 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn reset_font_size(&mut self) {}
|
2019-04-23 19:05:47 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn terminal(&self) -> &Term<T> {
|
2019-02-07 22:36:45 +00:00
|
|
|
&self.terminal
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn terminal_mut(&mut self) -> &mut Term<T> {
|
2019-02-07 22:36:45 +00:00
|
|
|
&mut self.terminal
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn size_info(&self) -> SizeInfo {
|
|
|
|
*self.size_info
|
|
|
|
}
|
|
|
|
|
|
|
|
fn semantic_selection(&mut self, _point: Point) {
|
|
|
|
// set something that we can check for here
|
|
|
|
self.last_action = MultiClick::DoubleClick;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn line_selection(&mut self, _point: Point) {
|
|
|
|
self.last_action = MultiClick::TripleClick;
|
|
|
|
}
|
|
|
|
|
2018-10-22 19:39:26 +00:00
|
|
|
fn selection_is_empty(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2018-03-25 19:09:18 +00:00
|
|
|
fn scroll(&mut self, scroll: Scroll) {
|
|
|
|
self.terminal.scroll_display(scroll);
|
|
|
|
}
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
fn mouse_coords(&self) -> Option<Point> {
|
2019-10-05 00:29:26 +00:00
|
|
|
let x = self.mouse.x as usize;
|
|
|
|
let y = self.mouse.y as usize;
|
|
|
|
|
|
|
|
if self.size_info.contains_point(x, y, true) {
|
|
|
|
Some(self.size_info.pixels_to_coords(x, y))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn mouse_mut(&mut self) -> &mut Mouse {
|
|
|
|
self.mouse
|
|
|
|
}
|
2018-09-27 12:12:49 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn mouse(&self) -> &Mouse {
|
|
|
|
self.mouse
|
|
|
|
}
|
|
|
|
|
2017-07-20 17:50:50 +00:00
|
|
|
fn received_count(&mut self) -> &mut usize {
|
|
|
|
&mut self.received_count
|
|
|
|
}
|
2019-01-05 20:47:12 +00:00
|
|
|
|
2017-07-20 17:50:50 +00:00
|
|
|
fn suppress_chars(&mut self) -> &mut bool {
|
|
|
|
&mut self.suppress_chars
|
|
|
|
}
|
2019-01-05 20:47:12 +00:00
|
|
|
|
2019-08-24 23:18:51 +00:00
|
|
|
fn modifiers(&mut self) -> &mut Modifiers {
|
|
|
|
&mut self.modifiers
|
2017-07-20 17:50:50 +00:00
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
|
|
|
|
fn window(&self) -> &Window {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn window_mut(&mut self) -> &mut Window {
|
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pop_message(&mut self) {
|
|
|
|
self.message_buffer.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn message(&self) -> Option<&Message> {
|
|
|
|
self.message_buffer.message()
|
|
|
|
}
|
2019-11-03 19:02:26 +00:00
|
|
|
|
|
|
|
fn config(&self) -> &Config {
|
|
|
|
self.config
|
|
|
|
}
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! test_clickstate {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
initial_state: $initial_state:expr,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: $initial_button:expr,
|
2017-01-15 01:53:48 +00:00
|
|
|
input: $input:expr,
|
|
|
|
end_state: $end_state:pat,
|
|
|
|
last_action: $last_action:expr
|
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2019-10-05 00:29:26 +00:00
|
|
|
let mut cfg = Config::default();
|
|
|
|
cfg.ui_config.mouse = crate::config::Mouse {
|
|
|
|
double_click: ClickHandler {
|
|
|
|
threshold: Duration::from_millis(1000),
|
|
|
|
},
|
|
|
|
triple_click: ClickHandler {
|
|
|
|
threshold: Duration::from_millis(1000),
|
|
|
|
},
|
|
|
|
hide_when_typing: false,
|
|
|
|
url: Default::default(),
|
|
|
|
};
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
let size = SizeInfo {
|
|
|
|
width: 21.0,
|
|
|
|
height: 51.0,
|
|
|
|
cell_width: 3.0,
|
|
|
|
cell_height: 3.0,
|
2017-05-06 15:45:23 +00:00
|
|
|
padding_x: 0.0,
|
|
|
|
padding_y: 0.0,
|
2018-11-10 16:08:48 +00:00
|
|
|
dpr: 1.0,
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
let mut terminal = Term::new(&cfg, &size, Clipboard::new_nop(), MockEventProxy);
|
2017-01-15 01:53:48 +00:00
|
|
|
|
|
|
|
let mut mouse = Mouse::default();
|
|
|
|
mouse.click_state = $initial_state;
|
2019-01-08 07:37:58 +00:00
|
|
|
mouse.last_button = $initial_button;
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2017-06-17 17:29:59 +00:00
|
|
|
let mut selection = None;
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
let mut message_buffer = MessageBuffer::new();
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
let context = ActionContext {
|
|
|
|
terminal: &mut terminal,
|
2017-06-17 17:29:59 +00:00
|
|
|
selection: &mut selection,
|
2017-01-15 01:53:48 +00:00
|
|
|
mouse: &mut mouse,
|
|
|
|
size_info: &size,
|
|
|
|
last_action: MultiClick::None,
|
2017-07-20 17:50:50 +00:00
|
|
|
received_count: 0,
|
|
|
|
suppress_chars: false,
|
2019-10-05 00:29:26 +00:00
|
|
|
modifiers: Modifiers::default(),
|
|
|
|
message_buffer: &mut message_buffer,
|
2019-11-03 19:02:26 +00:00
|
|
|
config: &cfg,
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
|
|
|
|
2019-11-03 19:02:26 +00:00
|
|
|
let mut processor = Processor::new(context);
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2017-12-28 20:36:30 +00:00
|
|
|
if let Event::WindowEvent { event: WindowEvent::MouseInput { state, button, modifiers, .. }, .. } = $input {
|
2018-01-03 16:52:49 +00:00
|
|
|
processor.mouse_input(state, button, modifiers);
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
|
|
|
|
2018-12-10 17:53:56 +00:00
|
|
|
assert!(match processor.ctx.mouse.click_state {
|
2017-01-15 01:53:48 +00:00
|
|
|
$end_state => processor.ctx.last_action == $last_action,
|
|
|
|
_ => false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:48:31 +00:00
|
|
|
macro_rules! test_process_binding {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
binding: $binding:expr,
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: $triggers:expr,
|
2016-06-23 16:48:31 +00:00
|
|
|
mode: $mode:expr,
|
|
|
|
mods: $mods:expr
|
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2016-12-27 00:00:27 +00:00
|
|
|
if $triggers {
|
2018-11-01 19:35:37 +00:00
|
|
|
assert!($binding.is_triggered_by($mode, $mods, &KEY, false));
|
2016-12-27 00:00:27 +00:00
|
|
|
} else {
|
2018-11-01 19:35:37 +00:00
|
|
|
assert!(!$binding.is_triggered_by($mode, $mods, &KEY, false));
|
2016-12-27 00:00:27 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
test_clickstate! {
|
|
|
|
name: single_click,
|
|
|
|
initial_state: ClickState::None,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: MouseButton::Other(0),
|
2019-10-05 00:29:26 +00:00
|
|
|
input: Event::<TerminalEvent>::WindowEvent {
|
2017-07-20 17:50:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Left,
|
|
|
|
device_id: unsafe { ::std::mem::transmute_copy(&0) },
|
2017-12-29 23:49:20 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
|
|
|
window_id: unsafe { ::std::mem::transmute_copy(&0) },
|
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
end_state: ClickState::Click,
|
|
|
|
last_action: MultiClick::None
|
|
|
|
}
|
|
|
|
|
|
|
|
test_clickstate! {
|
|
|
|
name: double_click,
|
|
|
|
initial_state: ClickState::Click,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: MouseButton::Left,
|
2019-10-05 00:29:26 +00:00
|
|
|
input: Event::<TerminalEvent>::WindowEvent {
|
2017-07-20 17:50:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Left,
|
|
|
|
device_id: unsafe { ::std::mem::transmute_copy(&0) },
|
2017-12-29 23:49:20 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
|
|
|
window_id: unsafe { ::std::mem::transmute_copy(&0) },
|
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
end_state: ClickState::DoubleClick,
|
|
|
|
last_action: MultiClick::DoubleClick
|
|
|
|
}
|
|
|
|
|
|
|
|
test_clickstate! {
|
|
|
|
name: triple_click,
|
|
|
|
initial_state: ClickState::DoubleClick,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: MouseButton::Left,
|
2019-10-05 00:29:26 +00:00
|
|
|
input: Event::<TerminalEvent>::WindowEvent {
|
2017-07-20 17:50:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Left,
|
|
|
|
device_id: unsafe { ::std::mem::transmute_copy(&0) },
|
2017-12-29 23:49:20 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
|
|
|
window_id: unsafe { ::std::mem::transmute_copy(&0) },
|
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
end_state: ClickState::TripleClick,
|
|
|
|
last_action: MultiClick::TripleClick
|
|
|
|
}
|
|
|
|
|
2019-01-08 07:37:58 +00:00
|
|
|
test_clickstate! {
|
|
|
|
name: multi_click_separate_buttons,
|
|
|
|
initial_state: ClickState::DoubleClick,
|
|
|
|
initial_button: MouseButton::Left,
|
2019-10-05 00:29:26 +00:00
|
|
|
input: Event::<TerminalEvent>::WindowEvent {
|
2019-01-08 07:37:58 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Right,
|
|
|
|
device_id: unsafe { ::std::mem::transmute_copy(&0) },
|
|
|
|
modifiers: ModifiersState::default(),
|
|
|
|
},
|
|
|
|
window_id: unsafe { ::std::mem::transmute_copy(&0) },
|
|
|
|
},
|
|
|
|
end_state: ClickState::Click,
|
|
|
|
last_action: MultiClick::None
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:48:31 +00:00
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_shiftmod_require_shift,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: true, ctrl: false, alt: false, logo: false }, action: Action::from("\x1b[1;2D"), mode: TermMode::NONE, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::NONE,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: true, ctrl: false, alt: false, logo: false }
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_nomod_require_shift,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: true, ctrl: false, alt: false, logo: false }, action: Action::from("\x1b[1;2D"), mode: TermMode::NONE, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: false,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::NONE,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_controlmod,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { ctrl: true, shift: false, alt: false, logo: false }, action: Action::from("\x1b[1;5D"), mode: TermMode::NONE, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::NONE,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { ctrl: true, shift: false, alt: false, logo: false }
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_nomod_require_not_appcursor,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }, action: Action::from("\x1b[D"), mode: TermMode::NONE, notmode: TermMode::APP_CURSOR },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::NONE,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_appcursormode_nomod_require_appcursor,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }, action: Action::from("\x1bOD"), mode: TermMode::APP_CURSOR, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::APP_CURSOR,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_nomod_require_appcursor,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }, action: Action::from("\x1bOD"), mode: TermMode::APP_CURSOR, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: false,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::NONE,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
2016-07-30 01:27:45 +00:00
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_appcursormode_appkeypadmode_nomod_require_appcursor,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }, action: Action::from("\x1bOD"), mode: TermMode::APP_CURSOR, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::APP_CURSOR | TermMode::APP_KEYPAD,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false }
|
2016-07-30 01:27:45 +00:00
|
|
|
}
|
2016-09-27 15:27:39 +00:00
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_fail_with_extra_mods,
|
2018-03-08 21:50:04 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: true }, action: Action::from("arst"), mode: TermMode::NONE, notmode: TermMode::NONE },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: false,
|
2018-03-08 21:50:04 +00:00
|
|
|
mode: TermMode::NONE,
|
2017-07-20 17:50:50 +00:00
|
|
|
mods: ModifiersState { shift: false, ctrl: false, alt: true, logo: true }
|
2016-09-27 15:27:39 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|