Skip to content

Commit

Permalink
On X11, fix cursor_hittest not reloaded on Resize
Browse files Browse the repository at this point in the history
The cursor hittest was not reloaded on window size changes, only
when `Window::request_inner_size` was called leading to regions
of the window being not clickable.

Also, don't try to apply hittest logic when user never requested a
hittest.

Links: alacritty/alacritty#7220
  • Loading branch information
kchibisov committed Oct 21, 2023
1 parent 7de33bc commit 08edda1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/platform_impl/linux/x11/event_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ impl<T: 'static> EventProcessor<T> {
}

let mut shared_state_lock = window.shared_state_lock();
let hittest = shared_state_lock.cursor_hittest;

// This is a hack to ensure that the DPI adjusted resize is actually applied on all WMs. KWin
// doesn't need this, but Xfwm does. The hack should not be run on other WMs, since tiling
Expand All @@ -501,6 +502,11 @@ impl<T: 'static> EventProcessor<T> {
// Unlock shared state to prevent deadlock in callback below
drop(shared_state_lock);

// Reload hittest.
if hittest.unwrap_or(false) {
let _ = window.set_cursor_hittest(true);
}

if resized {
callback(Event::WindowEvent {
window_id,
Expand Down
11 changes: 6 additions & 5 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub struct SharedState {
pub base_size: Option<Size>,
pub visibility: Visibility,
pub has_focus: bool,
pub cursor_hittest: bool,
// Use `Option` to not apply hittest logic when it was never requested.
pub cursor_hittest: Option<bool>,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -105,7 +106,7 @@ impl SharedState {
resize_increments: None,
base_size: None,
has_focus: false,
cursor_hittest: true,
cursor_hittest: None,
})
}
}
Expand Down Expand Up @@ -1295,8 +1296,8 @@ impl UnownedWindow {
self.xconn
.flush_requests()
.expect("Failed to call XResizeWindow");
// cursor_hittest needs to be reapplied after window resize
if self.shared_state_lock().cursor_hittest {
// cursor_hittest needs to be reapplied after each window resize.
if self.shared_state_lock().cursor_hittest.unwrap_or(false) {
let _ = self.set_cursor_hittest(true);
}
}
Expand Down Expand Up @@ -1627,7 +1628,7 @@ impl UnownedWindow {
.xcb_connection()
.xfixes_set_window_shape_region(self.xwindow, SK::INPUT, 0, 0, region.region())
.map_err(|_e| ExternalError::Ignored)?;
self.shared_state_lock().cursor_hittest = hittest;
self.shared_state_lock().cursor_hittest = Some(hittest);
Ok(())
}

Expand Down

0 comments on commit 08edda1

Please sign in to comment.