Skip to content

Commit

Permalink
feat: Implement set_cursor_hittest for X11
Browse files Browse the repository at this point in the history
  • Loading branch information
lunixbochs authored Oct 14, 2023
1 parent 61581eb commit bbeacc4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Legend:
|Cursor locking ||✔️ ||✔️ |**N/A**|**N/A**|✔️ ||
|Cursor confining |✔️ ||✔️ |✔️ |**N/A**|**N/A**|||
|Cursor icon |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|✔️ |**N/A** |
|Cursor hittest |✔️ |✔️ | |✔️ |**N/A**|**N/A**|||
|Cursor hittest |✔️ |✔️ |✔️ |✔️ |**N/A**|**N/A**|||
|Touch events |✔️ ||✔️ |✔️ |✔️ |✔️ |✔️ |**N/A** |
|Touch pressure |✔️ |||||✔️ |✔️ |**N/A** |
|Multitouch |✔️ ||✔️ |✔️ |✔️ |✔️ ||**N/A** |
Expand Down
34 changes: 30 additions & 4 deletions src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ use x11rb::{
connection::Connection,
properties::{WmHints, WmHintsState, WmSizeHints, WmSizeHintsSpecification},
protocol::{
randr, xinput,
xproto::{self, ConnectionExt as _},
randr,
shape::SK,
xfixes::{ConnectionExt, RegionWrapper},
xinput,
xproto::{self, ConnectionExt as _, Rectangle},
},
};

Expand Down Expand Up @@ -62,6 +65,7 @@ pub struct SharedState {
pub base_size: Option<Size>,
pub visibility: Visibility,
pub has_focus: bool,
pub cursor_hittest: bool,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -102,6 +106,7 @@ impl SharedState {
resize_increments: None,
base_size: None,
has_focus: false,
cursor_hittest: true,
})
}
}
Expand Down Expand Up @@ -1286,6 +1291,10 @@ 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 {
let _ = self.set_cursor_hittest(true);
}
}

#[inline]
Expand Down Expand Up @@ -1595,8 +1604,25 @@ impl UnownedWindow {
}

#[inline]
pub fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), ExternalError> {
Err(ExternalError::NotSupported(NotSupportedError::new()))
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> {
let mut rectangles: Vec<Rectangle> = Vec::new();
if hittest {
let size = self.inner_size();
rectangles.push(Rectangle {
x: 0,
y: 0,
width: size.width as u16,
height: size.height as u16,
})
}
let region = RegionWrapper::create_region(self.xconn.xcb_connection(), &rectangles)
.map_err(|_e| ExternalError::Ignored)?;
self.xconn
.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;
Ok(())
}

/// Moves the window while it is being dragged.
Expand Down
2 changes: 1 addition & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ impl Window {
///
/// ## Platform-specific
///
/// - **iOS / Android / Web / X11 / Orbital:** Always returns an [`ExternalError::NotSupported`].
/// - **iOS / Android / Web / Orbital:** Always returns an [`ExternalError::NotSupported`].
#[inline]
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> {
self.window
Expand Down

0 comments on commit bbeacc4

Please sign in to comment.