Skip to content

Commit

Permalink
wayland: add cursor_shape_v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed Oct 2, 2023
1 parent 74ef59a commit 16d0ba3
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ appendlist = "1.4"
ash = { version = "0.37.1", optional = true }
bitflags = "2.2.1"
calloop = "0.12.2"
cursor-icon = "1.0.0"
cgmath = "0.18.0"
downcast-rs = "1.2.0"
drm-fourcc = "^2.2.0"
Expand Down
5 changes: 3 additions & 2 deletions anvil/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<T: Texture> Default for PointerElement<T> {
fn default() -> Self {
Self {
texture: Default::default(),
status: CursorImageStatus::Default,
status: CursorImageStatus::default_named(),
}
}
}
Expand Down Expand Up @@ -84,7 +84,8 @@ where
{
match &self.status {
CursorImageStatus::Hidden => vec![],
CursorImageStatus::Default => {
// Always render `Default` for a named shape.
CursorImageStatus::Named(_) => {
if let Some(texture) = self.texture.as_ref() {
vec![
PointerRenderElement::<R>::from(TextureRenderElement::from_texture_buffer(
Expand Down
2 changes: 1 addition & 1 deletion anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
let seat_name = backend_data.seat_name();
let mut seat = seat_state.new_wl_seat(&dh, seat_name.clone());

let cursor_status = Arc::new(Mutex::new(CursorImageStatus::Default));
let cursor_status = Arc::new(Mutex::new(CursorImageStatus::default_named()));
let pointer = seat.add_pointer();
seat.add_keyboard(XkbConfig::default(), 200, 25)
.expect("Failed to initialize the keyboard");
Expand Down
2 changes: 1 addition & 1 deletion anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ fn render_surface<'a, 'b>(
reset = !surface.alive();
}
if reset {
*cursor_status = CursorImageStatus::Default;
*cursor_status = CursorImageStatus::default_named();
}

pointer_element.set_status(cursor_status.clone());
Expand Down
2 changes: 1 addition & 1 deletion anvil/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ pub fn run_winit() {
reset = !surface.alive();
}
if reset {
*cursor_guard = CursorImageStatus::Default;
*cursor_guard = CursorImageStatus::default_named();
}
let cursor_visible = !matches!(*cursor_guard, CursorImageStatus::Surface(_));

Expand Down
2 changes: 1 addition & 1 deletion anvil/src/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ pub fn run_x11() {
reset = !surface.alive();
}
if reset {
*cursor_guard = CursorImageStatus::Default;
*cursor_guard = CursorImageStatus::default_named();
}
let cursor_visible = !matches!(*cursor_guard, CursorImageStatus::Surface(_));

Expand Down
15 changes: 12 additions & 3 deletions src/input/pointer/cursor_image.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(feature = "wayland_frontend")]
use wayland_server::protocol::wl_surface::WlSurface;

pub use cursor_icon::CursorIcon;

use crate::utils::{Logical, Point};
use std::sync::Mutex;

Expand Down Expand Up @@ -31,11 +33,18 @@ pub type CursorImageSurfaceData = Mutex<CursorImageAttributes>;
pub enum CursorImageStatus {
/// The cursor should be hidden
Hidden,
/// The compositor should draw its cursor
Default,

/// The compositor should draw the given named
/// cursor.
Named(CursorIcon),
// TODO bitmap, dmabuf cursor? Or let the compositor handle everything through "Default"
/// The cursor should be drawn using this surface as an image
#[cfg(feature = "wayland_frontend")]
Surface(WlSurface),
}

impl CursorImageStatus {
/// Get default `Named` cursor.
pub fn default_named() -> Self {
Self::Named(CursorIcon::Default)
}
}
3 changes: 2 additions & 1 deletion src/input/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
};

mod cursor_image;
pub use cursor_icon::CursorIcon;
pub use cursor_image::{CursorImageAttributes, CursorImageStatus, CursorImageSurfaceData};

mod grab;
Expand Down Expand Up @@ -740,7 +741,7 @@ impl<D: SeatHandler + 'static> PointerInternal<D> {
focused.leave(seat, data, event.serial, event.time);
}
self.focus = None;
data.cursor_image(seat, CursorImageStatus::Default);
data.cursor_image(seat, CursorImageStatus::default_named());
}

// do we enter one ?
Expand Down
Loading

0 comments on commit 16d0ba3

Please sign in to comment.