Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/native/linux_wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,10 @@ where

let mut event_handler = (f.take().unwrap())();

// track cursor visibility and icon separately, so that we can show/hide cursor without resetting icon
let mut cursor_icon = crate::CursorIcon::Default;
let mut cursor_visible = true;

while !crate::native_display().try_lock().unwrap().quit_ordered {
while let Ok(request) = rx.try_recv() {
match request {
Expand All @@ -1213,19 +1217,20 @@ where
}
Request::ScheduleUpdate => display.update_requested = true,
Request::SetMouseCursor(icon) => {
cursor_icon = icon;
display
.pointer_context
.set_cursor(&mut display.client, Some(icon));
.set_cursor(&mut display.client, cursor_visible.then_some(cursor_icon));
}
Request::SetCursorGrab(grab) => {
let payload = &mut display as *mut _ as _;
display.pointer_context.set_grab(payload, grab);
}
Request::ShowMouse(show) => {
display.pointer_context.set_cursor(
&mut display.client,
show.then_some(crate::CursorIcon::Default),
);
cursor_visible = show;
display
.pointer_context
.set_cursor(&mut display.client, cursor_visible.then_some(cursor_icon));
}
// TODO: implement the other events
_ => (),
Expand Down
24 changes: 12 additions & 12 deletions src/native/linux_x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct X11Display {
repeated_keycodes: [bool; 256],
empty_cursor: libx11::Cursor,
cursor_cache: HashMap<CursorIcon, libx11::Cursor>,
cursor_icon: CursorIcon,
cursor_visible: bool,
update_requested: bool,
drag_n_drop: drag_n_drop::X11DnD,
}
Expand Down Expand Up @@ -329,16 +331,6 @@ impl X11Display {
(self.libx11.XMoveWindow)(self.display, window, new_x, new_y);
}

fn show_mouse(&mut self, shown: bool) {
unsafe {
if shown {
self.set_cursor(self.window, Some(CursorIcon::Default));
} else {
self.set_cursor(self.window, None);
}
}
}

pub unsafe fn set_cursor_grab(&mut self, window: Window, grab: bool) {
(self.libx11.XUngrabPointer)(self.display, 0);

Expand Down Expand Up @@ -407,8 +399,14 @@ impl X11Display {
self.update_requested = true;
}
SetCursorGrab(grab) => self.set_cursor_grab(self.window, grab),
ShowMouse(show) => self.show_mouse(show),
SetMouseCursor(icon) => self.set_cursor(self.window, Some(icon)),
ShowMouse(show) => {
self.cursor_visible = show;
self.set_cursor(self.window, self.cursor_visible.then_some(self.cursor_icon));
}
SetMouseCursor(icon) => {
self.cursor_icon = icon;
self.set_cursor(self.window, self.cursor_visible.then_some(self.cursor_icon));
}
SetWindowSize {
new_width,
new_height,
Expand Down Expand Up @@ -680,6 +678,8 @@ where
cursor_cache: HashMap::new(),
update_requested: true,
drag_n_drop: Default::default(),
cursor_icon: CursorIcon::Default,
cursor_visible: true,
};

display
Expand Down
Loading