mirror of
https://github.com/alacritty/alacritty.git
synced 2026-11-20 21:23:23 +03:00
Ignore touch gestures for enabling IME
Previously whenever the user would use touch gestures to make selections or scroll the terminal, IME would automatically be enabled due to the focus change and reduce the terminal height. This isn't ideal when the goal is just scanning through the terminal history without making any input. This patch keeps track of pointer and touch focus and only enables IME when either the pointer is within the window or a tap touch sequence was performed to give the window 'touch focus'. The initial touch tap sequence used to enable IME is still forwarded to the terminal as a simulated click event, since otherwise touch devices without virtual keyboard would be forced into a confusing additional tap to make it work. This means that virtual keyboard users will not be able to open the virtual keyboard without creating a click event, which should still be preferable to the status quo.
This commit is contained in:
1 parent
52deae45bc
commit
1399545f48
6 files changed
+60
-24
No files matched your search
@@ -17,6 +17,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
|
||||
### Changed
|
||||
|
||||
- Don't highlight hints on hover when the mouse cursor is hidden
|
||||
- Require explicit tap to enable IME with touch input
|
||||
|
||||
### Fixed
|
||||
|
||||
|
||||
@@ -119,6 +119,9 @@ pub struct Window {
|
||||
|
||||
is_x11: bool,
|
||||
current_mouse_cursor: CursorIcon,
|
||||
text_input_active: bool,
|
||||
pointer_focused: bool,
|
||||
touch_focused: bool,
|
||||
mouse_visible: bool,
|
||||
}
|
||||
|
||||
@@ -202,15 +205,18 @@ impl Window {
|
||||
let is_x11 = matches!(window.window_handle().unwrap().as_raw(), RawWindowHandle::Xlib(_));
|
||||
|
||||
Ok(Self {
|
||||
current_mouse_cursor,
|
||||
scale_factor,
|
||||
is_x11,
|
||||
window,
|
||||
hold: options.terminal_options.hold,
|
||||
requested_redraw: false,
|
||||
text_input_active: true,
|
||||
title: identity.title,
|
||||
current_mouse_cursor,
|
||||
mouse_visible: true,
|
||||
has_frame: true,
|
||||
scale_factor,
|
||||
window,
|
||||
is_x11,
|
||||
pointer_focused: Default::default(),
|
||||
touch_focused: Default::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -433,13 +439,41 @@ impl Window {
|
||||
self.window.set_simple_fullscreen(simple_fullscreen);
|
||||
}
|
||||
|
||||
pub fn set_ime_allowed(&self, allowed: bool) {
|
||||
// Skip runtime IME manipulation on X11 since it breaks some IMEs.
|
||||
if !self.is_x11 {
|
||||
self.window.set_ime_allowed(allowed);
|
||||
/// Set whether plain-text input is currently possible.
|
||||
pub fn set_text_input_active(&mut self, active: bool) {
|
||||
if self.text_input_active != active {
|
||||
self.text_input_active = active;
|
||||
self.update_ime_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
/// Set whether the pointer is currently within the window.
|
||||
pub fn set_pointer_focus(&mut self, focused: bool) {
|
||||
if self.touch_focused != focused {
|
||||
self.touch_focused = focused;
|
||||
self.update_ime_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
/// Set whether a touch action has focused the window.
|
||||
pub fn set_touch_focus(&mut self, focused: bool) {
|
||||
if self.touch_focused != focused {
|
||||
self.touch_focused = focused;
|
||||
self.update_ime_allowed();
|
||||
}
|
||||
}
|
||||
|
||||
/// Update whether IME should be offered.
|
||||
fn update_ime_allowed(&mut self) {
|
||||
// Skip runtime IME manipulation on X11 since it breaks some IMEs.
|
||||
if self.is_x11 {
|
||||
return;
|
||||
}
|
||||
|
||||
let allowed = self.text_input_active && (self.touch_focused || self.pointer_focused);
|
||||
self.window.set_ime_allowed(allowed);
|
||||
}
|
||||
|
||||
/// Adjust the IME editor position according to the new location of the cursor.
|
||||
pub fn update_ime_position(&self, point: Point<usize>, size: &SizeInfo) {
|
||||
// NOTE: X11 doesn't support cursor area, so we need to offset manually to not obscure
|
||||
|
||||
+12
-14
@@ -214,7 +214,6 @@ impl Processor {
|
||||
| WindowEvent::DoubleTapGesture { .. }
|
||||
| WindowEvent::TouchpadPressure { .. }
|
||||
| WindowEvent::RotationGesture { .. }
|
||||
| WindowEvent::CursorEntered { .. }
|
||||
| WindowEvent::PinchGesture { .. }
|
||||
| WindowEvent::AxisMotion { .. }
|
||||
| WindowEvent::PanGesture { .. }
|
||||
@@ -969,7 +968,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
|
||||
}
|
||||
|
||||
// Enable IME so we can input into the search bar with it if we were in Vi mode.
|
||||
self.window().set_ime_allowed(true);
|
||||
self.window().set_text_input_active(true);
|
||||
|
||||
self.display.damage_tracker.frame().mark_fully_damaged();
|
||||
self.display.pending_update.dirty = true;
|
||||
@@ -1424,7 +1423,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
|
||||
}
|
||||
|
||||
// We don't want IME in Vi mode.
|
||||
self.window().set_ime_allowed(was_in_vi_mode);
|
||||
self.window().set_text_input_active(was_in_vi_mode);
|
||||
|
||||
self.terminal.toggle_vi_mode();
|
||||
|
||||
@@ -1466,7 +1465,7 @@ impl<'a, N: Notify + 'a, T: EventListener> input::ActionContext<T> for ActionCon
|
||||
|
||||
self.inline_search_state.char_pending = false;
|
||||
self.inline_search_state.character = Some(c);
|
||||
self.window().set_ime_allowed(false);
|
||||
self.window().set_text_input_active(false);
|
||||
|
||||
// Immediately move to the captured character.
|
||||
self.inline_search_next();
|
||||
@@ -1602,7 +1601,7 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
|
||||
/// Cleanup the search state.
|
||||
fn exit_search(&mut self) {
|
||||
let vi_mode = self.terminal.mode().contains(TermMode::VI);
|
||||
self.window().set_ime_allowed(!vi_mode);
|
||||
self.window().set_text_input_active(!vi_mode);
|
||||
|
||||
self.display.damage_tracker.frame().mark_fully_damaged();
|
||||
self.display.pending_update.dirty = true;
|
||||
@@ -1702,8 +1701,9 @@ impl<'a, N: Notify + 'a, T: EventListener> ActionContext<'a, N, T> {
|
||||
}
|
||||
|
||||
/// Identified purpose of the touch input.
|
||||
#[derive(Debug)]
|
||||
#[derive(Default, Debug)]
|
||||
pub enum TouchPurpose {
|
||||
#[default]
|
||||
None,
|
||||
Select(TouchEvent),
|
||||
Scroll(TouchEvent),
|
||||
@@ -1713,12 +1713,6 @@ pub enum TouchPurpose {
|
||||
Invalid(HashSet<u64, RandomState>),
|
||||
}
|
||||
|
||||
impl Default for TouchPurpose {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
/// Touch zooming state.
|
||||
#[derive(Debug)]
|
||||
pub struct TouchZoom {
|
||||
@@ -1990,9 +1984,12 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
|
||||
*self.ctx.dirty = true;
|
||||
}
|
||||
|
||||
// Reset the urgency hint when gaining focus.
|
||||
if is_focused {
|
||||
// Reset the urgency hint when gaining focus.
|
||||
self.ctx.window().set_urgent(false);
|
||||
} else {
|
||||
// Clear touch focus when window loses focus.
|
||||
self.ctx.window().set_touch_focus(false);
|
||||
}
|
||||
|
||||
self.ctx.update_cursor_blinking();
|
||||
@@ -2005,7 +2002,9 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
|
||||
let path: String = path.to_string_lossy().into();
|
||||
self.ctx.paste(&(path + " "), true);
|
||||
},
|
||||
WindowEvent::CursorEntered { .. } => self.ctx.window().set_pointer_focus(true),
|
||||
WindowEvent::CursorLeft { .. } => {
|
||||
self.ctx.window().set_pointer_focus(false);
|
||||
self.ctx.mouse.inside_text_area = false;
|
||||
|
||||
if self.ctx.display().highlighted_hint.is_some() {
|
||||
@@ -2043,7 +2042,6 @@ impl input::Processor<EventProxy, ActionContext<'_, Notifier, EventProxy>> {
|
||||
| WindowEvent::DoubleTapGesture { .. }
|
||||
| WindowEvent::TouchpadPressure { .. }
|
||||
| WindowEvent::RotationGesture { .. }
|
||||
| WindowEvent::CursorEntered { .. }
|
||||
| WindowEvent::PinchGesture { .. }
|
||||
| WindowEvent::AxisMotion { .. }
|
||||
| WindowEvent::PanGesture { .. }
|
||||
|
||||
@@ -29,7 +29,7 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
|
||||
|
||||
if key.state == ElementState::Released {
|
||||
if self.ctx.inline_search_state().char_pending {
|
||||
self.ctx.window().set_ime_allowed(true);
|
||||
self.ctx.window().set_text_input_active(true);
|
||||
}
|
||||
self.key_release(key, mode, mods);
|
||||
return;
|
||||
|
||||
@@ -933,6 +933,9 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
|
||||
self.mouse_moved(start_location);
|
||||
self.mouse_input(ElementState::Pressed, MouseButton::Left);
|
||||
self.mouse_input(ElementState::Released, MouseButton::Left);
|
||||
|
||||
// Set touch focus, enabling IME.
|
||||
self.ctx.window().set_touch_focus(true);
|
||||
},
|
||||
// Transition zoom to pending state once a finger was released.
|
||||
TouchPurpose::Zoom(zoom) => {
|
||||
|
||||
@@ -895,7 +895,7 @@ impl Canvas {
|
||||
*offset += 1.;
|
||||
}
|
||||
|
||||
let radius_i = (short_side + stroke_size + 1) / 2;
|
||||
let radius_i = (short_side + stroke_size).div_ceil(2);
|
||||
for y in 0..radius_i {
|
||||
for x in 0..radius_i {
|
||||
let y = y as f32;
|
||||
|
||||
Reference in new issue
Block a user