diff options
Diffstat (limited to 'alacritty/src')
-rw-r--r-- | alacritty/src/config/bindings.rs | 209 | ||||
-rw-r--r-- | alacritty/src/event.rs | 24 | ||||
-rw-r--r-- | alacritty/src/input.rs | 136 | ||||
-rw-r--r-- | alacritty/src/url.rs | 2 |
4 files changed, 165 insertions, 206 deletions
diff --git a/alacritty/src/config/bindings.rs b/alacritty/src/config/bindings.rs index b5680439..dbe5d42e 100644 --- a/alacritty/src/config/bindings.rs +++ b/alacritty/src/config/bindings.rs @@ -210,10 +210,7 @@ impl RelaxedEq for ModifiersState { // Make sure that modifiers in the config are always present, // but ignore surplus modifiers. fn relaxed_eq(&self, other: Self) -> bool { - (!self.logo || other.logo) - && (!self.alt || other.alt) - && (!self.ctrl || other.ctrl) - && (!self.shift || other.shift) + !*self | other == ModifiersState::all() } } @@ -222,7 +219,7 @@ macro_rules! bindings { $ty:ident; $( $key:path - $(,[$($mod:ident: $enabled:expr),*])* + $(,$mods:expr)* $(,+$mode:expr)* $(,~$notmode:expr)* ;$action:expr @@ -232,10 +229,8 @@ macro_rules! bindings { let mut v = Vec::new(); $( - let mut _mods = ModifiersState { - $($($mod: $enabled),*,)* - ..Default::default() - }; + let mut _mods = ModifiersState::empty(); + $(_mods = $mods;)* let mut _mode = TermMode::empty(); $(_mode = $mode;)* let mut _notmode = TermMode::empty(); @@ -266,25 +261,25 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { KeyBinding; Key::Paste; Action::Paste; Key::Copy; Action::Copy; - Key::L, [ctrl: true]; Action::ClearLogNotice; - Key::L, [ctrl: true]; Action::Esc("\x0c".into()); - Key::PageUp, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollPageUp; - Key::PageDown, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollPageDown; - Key::Home, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollToTop; - Key::End, [shift: true], ~TermMode::ALT_SCREEN; Action::ScrollToBottom; + Key::L, ModifiersState::CTRL; Action::ClearLogNotice; + Key::L, ModifiersState::CTRL; Action::Esc("\x0c".into()); + Key::PageUp, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollPageUp; + Key::PageDown, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollPageDown; + Key::Home, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollToTop; + Key::End, ModifiersState::SHIFT, ~TermMode::ALT_SCREEN; Action::ScrollToBottom; Key::Home, +TermMode::APP_CURSOR; Action::Esc("\x1bOH".into()); Key::Home, ~TermMode::APP_CURSOR; Action::Esc("\x1b[H".into()); - Key::Home, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2H".into()); + Key::Home, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2H".into()); Key::End, +TermMode::APP_CURSOR; Action::Esc("\x1bOF".into()); Key::End, ~TermMode::APP_CURSOR; Action::Esc("\x1b[F".into()); - Key::End, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2F".into()); + Key::End, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[1;2F".into()); Key::PageUp; Action::Esc("\x1b[5~".into()); - Key::PageUp, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[5;2~".into()); + Key::PageUp, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[5;2~".into()); Key::PageDown; Action::Esc("\x1b[6~".into()); - Key::PageDown, [shift: true], +TermMode::ALT_SCREEN; Action::Esc("\x1b[6;2~".into()); - Key::Tab, [shift: true]; Action::Esc("\x1b[Z".into()); + Key::PageDown, ModifiersState::SHIFT, +TermMode::ALT_SCREEN; Action::Esc("\x1b[6;2~".into()); + Key::Tab, ModifiersState::SHIFT; Action::Esc("\x1b[Z".into()); Key::Back; Action::Esc("\x7f".into()); - Key::Back, [alt: true]; Action::Esc("\x1b\x7f".into()); + Key::Back, ModifiersState::ALT; Action::Esc("\x1b\x7f".into()); Key::Insert; Action::Esc("\x1b[2~".into()); Key::Delete; Action::Esc("\x1b[3~".into()); Key::Up, +TermMode::APP_CURSOR; Action::Esc("\x1bOA".into()); @@ -330,70 +325,45 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { // ---------+--------------------------- // // from: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-PC-Style-Function-Keys - let modifiers = vec![ - ModifiersState { shift: true, ..ModifiersState::default() }, - ModifiersState { alt: true, ..ModifiersState::default() }, - ModifiersState { shift: true, alt: true, ..ModifiersState::default() }, - ModifiersState { ctrl: true, ..ModifiersState::default() }, - ModifiersState { shift: true, ctrl: true, ..ModifiersState::default() }, - ModifiersState { alt: true, ctrl: true, ..ModifiersState::default() }, - ModifiersState { shift: true, alt: true, ctrl: true, ..ModifiersState::default() }, + let mut modifiers = vec![ + ModifiersState::SHIFT, + ModifiersState::ALT, + ModifiersState::SHIFT | ModifiersState::ALT, + ModifiersState::CTRL, + ModifiersState::SHIFT | ModifiersState::CTRL, + ModifiersState::ALT | ModifiersState::CTRL, + ModifiersState::SHIFT | ModifiersState::ALT | ModifiersState::CTRL, ]; - for (index, mods) in modifiers.iter().enumerate() { + for (index, mods) in modifiers.drain(..).enumerate() { let modifiers_code = index + 2; bindings.extend(bindings!( KeyBinding; - Key::Delete, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[3;{}~", modifiers_code)); - Key::Up, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}A", modifiers_code)); - Key::Down, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}B", modifiers_code)); - Key::Right, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}C", modifiers_code)); - Key::Left, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}D", modifiers_code)); - Key::F1, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}P", modifiers_code)); - Key::F2, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}Q", modifiers_code)); - Key::F3, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}R", modifiers_code)); - Key::F4, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}S", modifiers_code)); - Key::F5, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[15;{}~", modifiers_code)); - Key::F6, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[17;{}~", modifiers_code)); - Key::F7, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[18;{}~", modifiers_code)); - Key::F8, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[19;{}~", modifiers_code)); - Key::F9, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[20;{}~", modifiers_code)); - Key::F10, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[21;{}~", modifiers_code)); - Key::F11, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[23;{}~", modifiers_code)); - Key::F12, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[24;{}~", modifiers_code)); - Key::F13, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[25;{}~", modifiers_code)); - Key::F14, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[26;{}~", modifiers_code)); - Key::F15, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[28;{}~", modifiers_code)); - Key::F16, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[29;{}~", modifiers_code)); - Key::F17, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[31;{}~", modifiers_code)); - Key::F18, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[32;{}~", modifiers_code)); - Key::F19, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[33;{}~", modifiers_code)); - Key::F20, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[34;{}~", modifiers_code)); + Key::Delete, mods; Action::Esc(format!("\x1b[3;{}~", modifiers_code)); + Key::Up, mods; Action::Esc(format!("\x1b[1;{}A", modifiers_code)); + Key::Down, mods; Action::Esc(format!("\x1b[1;{}B", modifiers_code)); + Key::Right, mods; Action::Esc(format!("\x1b[1;{}C", modifiers_code)); + Key::Left, mods; Action::Esc(format!("\x1b[1;{}D", modifiers_code)); + Key::F1, mods; Action::Esc(format!("\x1b[1;{}P", modifiers_code)); + Key::F2, mods; Action::Esc(format!("\x1b[1;{}Q", modifiers_code)); + Key::F3, mods; Action::Esc(format!("\x1b[1;{}R", modifiers_code)); + Key::F4, mods; Action::Esc(format!("\x1b[1;{}S", modifiers_code)); + Key::F5, mods; Action::Esc(format!("\x1b[15;{}~", modifiers_code)); + Key::F6, mods; Action::Esc(format!("\x1b[17;{}~", modifiers_code)); + Key::F7, mods; Action::Esc(format!("\x1b[18;{}~", modifiers_code)); + Key::F8, mods; Action::Esc(format!("\x1b[19;{}~", modifiers_code)); + Key::F9, mods; Action::Esc(format!("\x1b[20;{}~", modifiers_code)); + Key::F10, mods; Action::Esc(format!("\x1b[21;{}~", modifiers_code)); + Key::F11, mods; Action::Esc(format!("\x1b[23;{}~", modifiers_code)); + Key::F12, mods; Action::Esc(format!("\x1b[24;{}~", modifiers_code)); + Key::F13, mods; Action::Esc(format!("\x1b[25;{}~", modifiers_code)); + Key::F14, mods; Action::Esc(format!("\x1b[26;{}~", modifiers_code)); + Key::F15, mods; Action::Esc(format!("\x1b[28;{}~", modifiers_code)); + Key::F16, mods; Action::Esc(format!("\x1b[29;{}~", modifiers_code)); + Key::F17, mods; Action::Esc(format!("\x1b[31;{}~", modifiers_code)); + Key::F18, mods; Action::Esc(format!("\x1b[32;{}~", modifiers_code)); + Key::F19, mods; Action::Esc(format!("\x1b[33;{}~", modifiers_code)); + Key::F20, mods; Action::Esc(format!("\x1b[34;{}~", modifiers_code)); )); // We're adding the following bindings with `Shift` manually above, so skipping them here @@ -401,16 +371,11 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { if modifiers_code != 2 { bindings.extend(bindings!( KeyBinding; - Key::Insert, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[2;{}~", modifiers_code)); - Key::PageUp, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[5;{}~", modifiers_code)); - Key::PageDown, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[6;{}~", modifiers_code)); - Key::End, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}F", modifiers_code)); - Key::Home, [shift: mods.shift, alt: mods.alt, ctrl: mods.ctrl]; - Action::Esc(format!("\x1b[1;{}H", modifiers_code)); + Key::Insert, mods; Action::Esc(format!("\x1b[2;{}~", modifiers_code)); + Key::PageUp, mods; Action::Esc(format!("\x1b[5;{}~", modifiers_code)); + Key::PageDown, mods; Action::Esc(format!("\x1b[6;{}~", modifiers_code)); + Key::End, mods; Action::Esc(format!("\x1b[1;{}F", modifiers_code)); + Key::Home, mods; Action::Esc(format!("\x1b[1;{}H", modifiers_code)); )); } } @@ -424,14 +389,14 @@ pub fn default_key_bindings() -> Vec<KeyBinding> { fn common_keybindings() -> Vec<KeyBinding> { bindings!( KeyBinding; - Key::V, [ctrl: true, shift: true]; Action::Paste; - Key::C, [ctrl: true, shift: true]; Action::Copy; - Key::Insert, [shift: true]; Action::PasteSelection; - Key::Key0, [ctrl: true]; Action::ResetFontSize; - Key::Equals, [ctrl: true]; Action::IncreaseFontSize; - Key::Add, [ctrl: true]; Action::IncreaseFontSize; - Key::Subtract, [ctrl: true]; Action::DecreaseFontSize; - Key::Minus, [ctrl: true]; Action::DecreaseFontSize; + Key::V, ModifiersState::CTRL | ModifiersState::SHIFT; Action::Paste; + Key::C, ModifiersState::CTRL | ModifiersState::SHIFT; Action::Copy; + Key::Insert, ModifiersState::SHIFT; Action::PasteSelection; + Key::Key0, ModifiersState::CTRL; Action::ResetFontSize; + Key::Equals, ModifiersState::CTRL; Action::IncreaseFontSize; + Key::Add, ModifiersState::CTRL; Action::IncreaseFontSize; + Key::Subtract, ModifiersState::CTRL; Action::DecreaseFontSize; + Key::Minus, ModifiersState::CTRL; Action::DecreaseFontSize; ) } @@ -444,7 +409,7 @@ pub fn platform_key_bindings() -> Vec<KeyBinding> { pub fn platform_key_bindings() -> Vec<KeyBinding> { let mut bindings = bindings!( KeyBinding; - Key::Return, [alt: true]; Action::ToggleFullscreen; + Key::Return, ModifiersState::ALT; Action::ToggleFullscreen; ); bindings.extend(common_keybindings()); bindings @@ -454,19 +419,19 @@ pub fn platform_key_bindings() -> Vec<KeyBinding> { pub fn platform_key_bindings() -> Vec<KeyBinding> { bindings!( KeyBinding; - Key::Key0, [logo: true]; Action::ResetFontSize; - Key::Equals, [logo: true]; Action::IncreaseFontSize; - Key::Add, [logo: true]; Action::IncreaseFontSize; - Key::Minus, [logo: true]; Action::DecreaseFontSize; - Key::Insert, [shift: true]; Action::Esc("\x1b[2;2~".into()); - Key::F, [ctrl: true, logo: true]; Action::ToggleFullscreen; - Key::K, [logo: true]; Action::ClearHistory; - Key::K, [logo: true]; Action::Esc("\x0c".into()); - Key::V, [logo: true]; Action::Paste; - Key::C, [logo: true]; Action::Copy; - Key::H, [logo: true]; Action::Hide; - Key::Q, [logo: true]; Action::Quit; - Key::W, [logo: true]; Action::Quit; + Key::Key0, ModifiersState::LOGO; Action::ResetFontSize; + Key::Equals, ModifiersState::LOGO; Action::IncreaseFontSize; + Key::Add, ModifiersState::LOGO; Action::IncreaseFontSize; + Key::Minus, ModifiersState::LOGO; Action::DecreaseFontSize; + Key::Insert, ModifiersState::SHIFT; Action::Esc("\x1b[2;2~".into()); + Key::F, ModifiersState::CTRL | ModifiersState::LOGO; Action::ToggleFullscreen; + Key::K, ModifiersState::LOGO; Action::ClearHistory; + Key::K, ModifiersState::LOGO; Action::Esc("\x0c".into()); + Key::V, ModifiersState::LOGO; Action::Paste; + Key::C, ModifiersState::LOGO; Action::Copy; + Key::H, ModifiersState::LOGO; Action::Hide; + Key::Q, ModifiersState::LOGO; Action::Quit; + Key::W, ModifiersState::LOGO; Action::Quit; ) } @@ -1201,13 +1166,13 @@ impl<'a> de::Deserialize<'a> for ModsWrapper { where E: de::Error, { - let mut res = ModifiersState::default(); + let mut res = ModifiersState::empty(); for modifier in value.split('|') { match modifier.trim().to_lowercase().as_str() { - "command" | "super" => res.logo = true, - "shift" => res.shift = true, - "alt" | "option" => res.alt = true, - "control" => res.ctrl = true, + "command" | "super" => res.insert(ModifiersState::LOGO), + "shift" => res.insert(ModifiersState::SHIFT), + "alt" | "option" => res.insert(ModifiersState::ALT), + "control" => res.insert(ModifiersState::CTRL), "none" => (), _ => error!(target: LOG_TARGET_CONFIG, "Unknown modifier {:?}", modifier), } @@ -1265,9 +1230,9 @@ mod test { #[test] fn mods_binding_requires_strict_match() { let mut superset_mods = MockBinding::default(); - superset_mods.mods = ModifiersState { alt: true, logo: true, ctrl: true, shift: true }; + superset_mods.mods = ModifiersState::all(); let mut subset_mods = MockBinding::default(); - subset_mods.mods = ModifiersState { alt: true, logo: false, ctrl: false, shift: false }; + subset_mods.mods = ModifiersState::ALT; assert!(!superset_mods.triggers_match(&subset_mods)); assert!(!subset_mods.triggers_match(&superset_mods)); @@ -1368,10 +1333,10 @@ mod test { #[test] fn binding_trigger_mods() { let mut binding = MockBinding::default(); - binding.mods = ModifiersState { alt: true, logo: true, ctrl: false, shift: false }; + binding.mods = ModifiersState::ALT | ModifiersState::LOGO; - let superset_mods = ModifiersState { alt: true, logo: true, ctrl: true, shift: true }; - let subset_mods = ModifiersState { alt: false, logo: false, ctrl: false, shift: false }; + let superset_mods = ModifiersState::all(); + let subset_mods = ModifiersState::empty(); let t = binding.trigger; let mode = binding.mode; diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs index 4b1fe892..d03c4390 100644 --- a/alacritty/src/event.rs +++ b/alacritty/src/event.rs @@ -356,7 +356,7 @@ impl<N: Notify + OnResize> Processor<N> { return; }, // Process events - GlutinEvent::EventsCleared => { + GlutinEvent::RedrawEventsCleared => { *control_flow = ControlFlow::Wait; if event_queue.is_empty() { @@ -478,6 +478,7 @@ impl<N: Notify + OnResize> Processor<N> { Event::MouseCursorDirty => processor.reset_mouse_cursor(), Event::Exit => (), }, + GlutinEvent::RedrawRequested(_) => processor.ctx.terminal.dirty = true, GlutinEvent::WindowEvent { event, window_id, .. } => { use glutin::event::WindowEvent::*; match event { @@ -508,24 +509,24 @@ impl<N: Notify + OnResize> Processor<N> { } }, ReceivedCharacter(c) => processor.received_char(c), - MouseInput { state, button, modifiers, .. } => { + MouseInput { state, button, .. } => { if !cfg!(target_os = "macos") || processor.ctx.terminal.is_focused { processor.ctx.window.set_mouse_visible(true); - processor.mouse_input(state, button, modifiers); + processor.mouse_input(state, button); processor.ctx.terminal.dirty = true; } }, - CursorMoved { position: lpos, modifiers, .. } => { + CursorMoved { position: lpos, .. } => { let (x, y) = lpos.to_physical(processor.ctx.size_info.dpr).into(); let x: i32 = limit(x, 0, processor.ctx.size_info.width as i32); let y: i32 = limit(y, 0, processor.ctx.size_info.height as i32); processor.ctx.window.set_mouse_visible(true); - processor.mouse_moved(x as usize, y as usize, modifiers); + processor.mouse_moved(x as usize, y as usize); }, - MouseWheel { delta, phase, modifiers, .. } => { + MouseWheel { delta, phase, .. } => { processor.ctx.window.set_mouse_visible(true); - processor.mouse_wheel_input(delta, phase, modifiers); + processor.mouse_wheel_input(delta, phase); }, Focused(is_focused) => { if window_id == processor.ctx.window.window_id() { @@ -565,7 +566,6 @@ impl<N: Notify + OnResize> Processor<N> { processor.ctx.terminal.dirty = true; processor.ctx.size_info.dpr = dpr; }, - RedrawRequested => processor.ctx.terminal.dirty = true, CursorLeft { .. } => { processor.ctx.mouse.inside_grid = false; @@ -578,6 +578,7 @@ impl<N: Notify + OnResize> Processor<N> { | AxisMotion { .. } | HoveredFileCancelled | Destroyed + | ThemeChanged(_) | HoveredFile(_) | Touch(_) | Moved(_) => (), @@ -585,13 +586,14 @@ impl<N: Notify + OnResize> Processor<N> { }, GlutinEvent::DeviceEvent { event, .. } => { use glutin::event::DeviceEvent::*; - if let ModifiersChanged { modifiers } = event { + if let ModifiersChanged(modifiers) = event { processor.modifiers_input(modifiers); } }, GlutinEvent::Suspended { .. } | GlutinEvent::NewEvents { .. } - | GlutinEvent::EventsCleared + | GlutinEvent::MainEventsCleared + | GlutinEvent::RedrawEventsCleared | GlutinEvent::Resumed | GlutinEvent::LoopDestroyed => (), } @@ -624,7 +626,7 @@ impl<N: Notify + OnResize> Processor<N> { }, GlutinEvent::Suspended { .. } | GlutinEvent::NewEvents { .. } - | GlutinEvent::EventsCleared + | GlutinEvent::MainEventsCleared | GlutinEvent::LoopDestroyed => true, _ => false, } diff --git a/alacritty/src/input.rs b/alacritty/src/input.rs index 2a98dc12..dff46515 100644 --- a/alacritty/src/input.rs +++ b/alacritty/src/input.rs @@ -196,7 +196,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } #[inline] - pub fn mouse_moved(&mut self, x: usize, y: usize, modifiers: ModifiersState) { + pub fn mouse_moved(&mut self, x: usize, y: usize) { let size_info = self.ctx.size_info(); self.ctx.mouse_mut().x = x; @@ -226,13 +226,14 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { self.ctx.mouse_mut().block_url_launcher = true; // Update mouse state and check for URL change - let mouse_state = self.mouse_state(modifiers); + let mouse_state = self.mouse_state(); self.update_url_state(&mouse_state); self.ctx.window_mut().set_mouse_cursor(mouse_state.into()); let last_term_line = self.ctx.terminal().grid().num_lines() - 1; if self.ctx.mouse().left_button_state == ElementState::Pressed - && (modifiers.shift || !self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE)) + && (self.ctx.modifiers().shift() + || !self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE)) { // Treat motion over message bar like motion over the last line let line = min(point.line, last_term_line); @@ -244,13 +245,13 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG) { if self.ctx.mouse().left_button_state == ElementState::Pressed { - self.mouse_report(32, ElementState::Pressed, modifiers); + self.mouse_report(32, ElementState::Pressed); } else if self.ctx.mouse().middle_button_state == ElementState::Pressed { - self.mouse_report(33, ElementState::Pressed, modifiers); + self.mouse_report(33, ElementState::Pressed); } else if self.ctx.mouse().right_button_state == ElementState::Pressed { - self.mouse_report(34, ElementState::Pressed, modifiers); + self.mouse_report(34, ElementState::Pressed); } else if self.ctx.terminal().mode().contains(TermMode::MOUSE_MOTION) { - self.mouse_report(35, ElementState::Pressed, modifiers); + self.mouse_report(35, ElementState::Pressed); } } } @@ -321,16 +322,17 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { self.ctx.write_to_pty(msg.into_bytes()); } - fn mouse_report(&mut self, button: u8, state: ElementState, modifiers: ModifiersState) { + fn mouse_report(&mut self, button: u8, state: ElementState) { // Calculate modifiers value let mut mods = 0; - if modifiers.shift { + let modifiers = self.ctx.modifiers(); + if modifiers.shift() { mods += 4; } - if modifiers.alt { + if modifiers.alt() { mods += 8; } - if modifiers.ctrl { + if modifiers.ctrl() { mods += 16; } @@ -356,7 +358,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } } - fn on_mouse_press(&mut self, button: MouseButton, modifiers: ModifiersState) { + fn on_mouse_press(&mut self, button: MouseButton) { let now = Instant::now(); let elapsed = self.ctx.mouse().last_click_timestamp.elapsed(); self.ctx.mouse_mut().last_click_timestamp = now; @@ -393,13 +395,15 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { // Start new empty selection let side = self.ctx.mouse().cell_side; - if modifiers.ctrl { + if self.ctx.modifiers().ctrl() { self.ctx.block_selection(point, side); } else { self.ctx.simple_selection(point, side); } - if !modifiers.shift && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) { + if !self.ctx.modifiers().shift() + && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) + { let code = match button { MouseButton::Left => 0, MouseButton::Middle => 1, @@ -407,7 +411,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { // Can't properly report more than three buttons. MouseButton::Other(_) => return, }; - self.mouse_report(code, ElementState::Pressed, modifiers); + self.mouse_report(code, ElementState::Pressed); return; } @@ -416,8 +420,10 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { }; } - fn on_mouse_release(&mut self, button: MouseButton, modifiers: ModifiersState) { - if !modifiers.shift && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) { + fn on_mouse_release(&mut self, button: MouseButton) { + if !self.ctx.modifiers().shift() + && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) + { let code = match button { MouseButton::Left => 0, MouseButton::Middle => 1, @@ -425,11 +431,9 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { // Can't properly report more than three buttons. MouseButton::Other(_) => return, }; - self.mouse_report(code, ElementState::Released, modifiers); + self.mouse_report(code, ElementState::Released); return; - } else if let (MouseButton::Left, MouseState::Url(url)) = - (button, self.mouse_state(modifiers)) - { + } else if let (MouseButton::Left, MouseState::Url(url)) = (button, self.mouse_state()) { self.launch_url(url); } @@ -455,16 +459,11 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } } - pub fn mouse_wheel_input( - &mut self, - delta: MouseScrollDelta, - phase: TouchPhase, - modifiers: ModifiersState, - ) { + pub fn mouse_wheel_input(&mut self, delta: MouseScrollDelta, phase: TouchPhase) { match delta { MouseScrollDelta::LineDelta(_columns, lines) => { let new_scroll_px = lines * self.ctx.size_info().cell_height; - self.scroll_terminal(modifiers, new_scroll_px as i32); + self.scroll_terminal(new_scroll_px as i32); }, MouseScrollDelta::PixelDelta(lpos) => { match phase { @@ -473,7 +472,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { self.ctx.mouse_mut().scroll_px = 0; }, TouchPhase::Moved => { - self.scroll_terminal(modifiers, lpos.y as i32); + self.scroll_terminal(lpos.y as i32); }, _ => (), } @@ -481,7 +480,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } } - fn scroll_terminal(&mut self, modifiers: ModifiersState, new_scroll_px: i32) { + fn scroll_terminal(&mut self, new_scroll_px: i32) { let height = self.ctx.size_info().cell_height as i32; if self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) { @@ -491,14 +490,14 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { let lines = (self.ctx.mouse().scroll_px / height).abs(); for _ in 0..lines { - self.mouse_report(code, ElementState::Pressed, modifiers); + self.mouse_report(code, ElementState::Pressed); } } else if self .ctx .terminal() .mode() .contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL) - && !modifiers.shift + && !self.ctx.modifiers().shift() { let multiplier = i32::from( self.ctx @@ -540,12 +539,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } } - pub fn mouse_input( - &mut self, - state: ElementState, - button: MouseButton, - modifiers: ModifiersState, - ) { + pub fn mouse_input(&mut self, state: ElementState, button: MouseButton) { match button { MouseButton::Left => self.ctx.mouse_mut().left_button_state = state, MouseButton::Middle => self.ctx.mouse_mut().middle_button_state = state, @@ -580,10 +574,10 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } else { match state { ElementState::Pressed => { - self.process_mouse_bindings(modifiers, button); - self.on_mouse_press(button, modifiers); + self.process_mouse_bindings(button); + self.on_mouse_press(button); }, - ElementState::Released => self.on_mouse_release(button, modifiers), + ElementState::Released => self.on_mouse_release(button), } } @@ -592,9 +586,6 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { /// Process key input. pub fn key_input(&mut self, input: KeyboardInput) { - // TODO: Implement `ModifiersChanged` event on all platforms: rust-windowing/winit#1151 - self.modifiers_input(input.modifiers); - match input.state { ElementState::Pressed => { *self.ctx.received_count() = 0; @@ -609,7 +600,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { *self.ctx.modifiers() = modifiers; // Update mouse state and check for URL change - let mouse_state = self.mouse_state(modifiers); + let mouse_state = self.mouse_state(); self.update_url_state(&mouse_state); self.ctx.window_mut().set_mouse_cursor(mouse_state.into()); } @@ -632,7 +623,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { if self.ctx.config().alt_send_esc() && *self.ctx.received_count() == 0 - && self.ctx.modifiers().alt + && self.ctx.modifiers().alt() && utf8_len == 1 { bytes.insert(0, b'\x1b'); @@ -647,8 +638,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { /// Reset mouse cursor based on modifier and terminal state. #[inline] pub fn reset_mouse_cursor(&mut self) { - let mods = *self.ctx.modifiers(); - let mouse_state = self.mouse_state(mods); + let mouse_state = self.mouse_state(); self.ctx.window_mut().set_mouse_cursor(mouse_state.into()); } @@ -660,6 +650,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { let mut suppress_chars = None; for i in 0..self.ctx.config().ui_config.key_bindings.len() { + let mods = *self.ctx.modifiers(); let binding = &self.ctx.config().ui_config.key_bindings[i]; let key = match (binding.trigger, input.virtual_keycode) { @@ -668,7 +659,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { _ => continue, }; - if binding.is_triggered_by(*self.ctx.terminal().mode(), input.modifiers, &key, false) { + if binding.is_triggered_by(*self.ctx.terminal().mode(), mods, &key, false) { // Binding was triggered; run the action let binding = binding.clone(); binding.execute(&mut self.ctx, false); @@ -686,14 +677,15 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { /// /// The provided mode, mods, and key must match what is allowed by a binding /// for its action to be executed. - fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) { + fn process_mouse_bindings(&mut self, button: MouseButton) { for i in 0..self.ctx.config().ui_config.mouse_bindings.len() { + let mods = *self.ctx.modifiers(); let binding = &self.ctx.config().ui_config.mouse_bindings[i]; if binding.is_triggered_by(*self.ctx.terminal().mode(), mods, &button, true) { // binding was triggered; run the action let mouse_mode_active = - !mods.shift && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE); + !mods.shift() && self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE); let binding = binding.clone(); binding.execute(&mut self.ctx, mouse_mode_active); @@ -735,7 +727,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } /// Location of the mouse cursor. - fn mouse_state(&mut self, mods: ModifiersState) -> MouseState { + fn mouse_state(&mut self) -> MouseState { // Check message bar before URL to ignore URLs in the message bar if self.message_close_at_cursor() { return MouseState::MessageBarButton; @@ -744,6 +736,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { } // Check for URL at mouse cursor + let mods = *self.ctx.modifiers(); let selection = !self.ctx.terminal().selection().as_ref().map(Selection::is_empty).unwrap_or(true); let mouse_mode = self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE); @@ -756,7 +749,7 @@ impl<'a, T: EventListener, A: ActionContext<T>> Processor<'a, T, A> { // Check mouse mode if location is not special if self.ctx.terminal().mode().intersects(TermMode::MOUSE_MODE) - && !self.ctx.modifiers().shift + && !self.ctx.modifiers().shift() { MouseState::Mouse } else { @@ -982,13 +975,12 @@ mod tests { event: WindowEvent::MouseInput { state, button, - modifiers, .. }, .. } = $input { - processor.mouse_input(state, button, modifiers); + processor.mouse_input(state, button); }; assert!(match processor.ctx.mouse.click_state { @@ -1005,7 +997,7 @@ mod tests { binding: $binding:expr, triggers: $triggers:expr, mode: $mode:expr, - mods: $mods:expr + mods: $mods:expr, } => { #[test] fn $name() { @@ -1088,65 +1080,65 @@ mod tests { test_process_binding! { name: process_binding_nomode_shiftmod_require_shift, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::SHIFT, action: Action::from("\x1b[1;2D"), mode: TermMode::NONE, notmode: TermMode::NONE }, triggers: true, mode: TermMode::NONE, - mods: ModifiersState { shift: true, ctrl: false, alt: false, logo: false } + mods: ModifiersState::SHIFT, } test_process_binding! { name: process_binding_nomode_nomod_require_shift, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::SHIFT, action: Action::from("\x1b[1;2D"), mode: TermMode::NONE, notmode: TermMode::NONE }, triggers: false, mode: TermMode::NONE, - mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } + mods: ModifiersState::empty(), } test_process_binding! { name: process_binding_nomode_controlmod, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::CTRL, action: Action::from("\x1b[1;5D"), mode: TermMode::NONE, notmode: TermMode::NONE }, triggers: true, mode: TermMode::NONE, - mods: ModifiersState { ctrl: true, shift: false, alt: false, logo: false } + mods: ModifiersState::CTRL, } test_process_binding! { name: process_binding_nomode_nomod_require_not_appcursor, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1b[D"), mode: TermMode::NONE, notmode: TermMode::APP_CURSOR }, triggers: true, mode: TermMode::NONE, - mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } + mods: ModifiersState::empty(), } test_process_binding! { name: process_binding_appcursormode_nomod_require_appcursor, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1bOD"), mode: TermMode::APP_CURSOR, notmode: TermMode::NONE }, triggers: true, mode: TermMode::APP_CURSOR, - mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } + mods: ModifiersState::empty(), } test_process_binding! { name: process_binding_nomode_nomod_require_appcursor, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1bOD"), mode: TermMode::APP_CURSOR, notmode: TermMode::NONE }, triggers: false, mode: TermMode::NONE, - mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } + mods: ModifiersState::empty(), } test_process_binding! { name: process_binding_appcursormode_appkeypadmode_nomod_require_appcursor, - 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 }, + binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1bOD"), mode: TermMode::APP_CURSOR, notmode: TermMode::NONE }, triggers: true, mode: TermMode::APP_CURSOR | TermMode::APP_KEYPAD, - mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } + mods: ModifiersState::empty(), } test_process_binding! { name: process_binding_fail_with_extra_mods, - binding: Binding { trigger: KEY, mods: ModifiersState { shift: false, ctrl: false, alt: false, logo: true }, action: Action::from("arst"), mode: TermMode::NONE, notmode: TermMode::NONE }, + binding: Binding { trigger: KEY, mods: ModifiersState::LOGO, action: Action::from("arst"), mode: TermMode::NONE, notmode: TermMode::NONE }, triggers: false, mode: TermMode::NONE, - mods: ModifiersState { shift: false, ctrl: false, alt: true, logo: true } + mods: ModifiersState::ALT | ModifiersState::LOGO, } } diff --git a/alacritty/src/url.rs b/alacritty/src/url.rs index 09f66886..e510aa2b 100644 --- a/alacritty/src/url.rs +++ b/alacritty/src/url.rs @@ -154,7 +154,7 @@ impl Urls { ) -> Option<Url> { // Make sure all prerequisites for highlighting are met if selection - || (mouse_mode && !mods.shift) + || (mouse_mode && !mods.shift()) || !mouse.inside_grid || config.ui_config.mouse.url.launcher.is_none() || !config.ui_config.mouse.url.mods().relaxed_eq(mods) |