diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2023-11-24 19:24:42 +0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-24 19:24:42 +0400 |
commit | 6017326d8293b67eff952ebba2310ea070537f55 (patch) | |
tree | 8b36e70e281ae0683ffaf85634878ce7b9495082 | |
parent | 1152aea66a4bf254973712da03489f781c3e15de (diff) | |
download | alacritty-6017326d8293b67eff952ebba2310ea070537f55.tar.gz alacritty-6017326d8293b67eff952ebba2310ea070537f55.zip |
Fix IME popup positioning
When setting cursor area, the popup will be placed either above or
below not obscuring the supplied region, however we were still
offsetting line with `+1` putting the cursor at the bottom of the line,
and given that area is from the top-left corner, the wrong area
was marked for not being obscured.
It was also discovered that some compositors, like GNOME, position
IME in the bottom right corner of the supplied region, which is wrong,
but it renders IME popup not very useful, since it's far away from
the place it should be, thus try to not obscure just a few characters
near the cursor.
Given that X11 doesn't support area setting, it uses the old logic
with offsetting.
Co-developed-by: lilydjwg <lilydjwg@gmail.com>
Signed-off-by: lilydjwg <lilydjwg@gmail.com>
-rw-r--r-- | alacritty/src/display/window.rs | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/alacritty/src/display/window.rs b/alacritty/src/display/window.rs index 7dc6375e..14df091d 100644 --- a/alacritty/src/display/window.rs +++ b/alacritty/src/display/window.rs @@ -112,6 +112,7 @@ pub struct Window { /// Current window title. title: String, + is_x11: bool, current_mouse_cursor: CursorIcon, mouse_visible: bool, } @@ -188,15 +189,17 @@ impl Window { let scale_factor = window.scale_factor(); log::info!("Window scale factor: {}", scale_factor); + let is_x11 = matches!(window.raw_window_handle(), RawWindowHandle::Xlib(_)); Ok(Self { - current_mouse_cursor, - mouse_visible: true, requested_redraw: false, - window, title: identity.title, + current_mouse_cursor, + mouse_visible: true, has_frame: true, scale_factor, + window, + is_x11, }) } @@ -412,11 +415,17 @@ impl Window { /// 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 + // the text. + let offset = if self.is_x11 { 1 } else { 0 }; let nspot_x = f64::from(size.padding_x() + point.column.0 as f32 * size.cell_width()); - let nspot_y = f64::from(size.padding_y() + (point.line + 1) as f32 * size.cell_height()); + let nspot_y = + f64::from(size.padding_y() + (point.line + offset) as f32 * size.cell_height()); - // Exclude the rest of the line since we edit from left to right. - let width = size.width as f64 - nspot_x; + // NOTE: some compositors don't like excluding too much and try to render popup at the + // bottom right corner of the provided area, so exclude just the full-width char to not + // obscure the cursor and not render popup at the end of the window. + let width = size.cell_width() as f64 * 2.; let height = size.cell_height as f64; self.window.set_ime_cursor_area( |