Skip to content

Commit bfac8c7

Browse files
committed
Merge branch 're-enable-cursor-icon-support' into 'main'
Re-enable cursor icon support See merge request verso-browser/verso!320
2 parents 06a9654 + c53e6aa commit bfac8c7

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/verso.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,6 @@ impl Verso {
497497
// Handle message in Verso Window
498498
log::trace!("Verso Window is handling Embedder message: {msg:?}");
499499
match msg {
500-
// EmbedderMsg::SetCursor(_, cursor) => {
501-
// // TODO: This should move to compositor
502-
// if let Some(window) = self.windows.get(&compositor.current_window) {
503-
// window.0.set_cursor_icon(cursor);
504-
// }
505-
// }
506500
EmbedderMsg::OnDevtoolsStarted(port, _token) => {
507501
if let Ok(port) = port {
508502
// We use level error by default so this won't show

src/window.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ pub(crate) struct EventListeners {
7272
pub(crate) on_close_requested: bool,
7373
}
7474

75+
#[derive(Debug, Default)]
76+
struct CursorState {
77+
current_cursor: CursorIcon,
78+
cursor_resizing: bool,
79+
}
80+
7581
/// A Verso window is a Winit window containing several web views.
7682
pub struct Window {
7783
/// Access to Winit window
7884
pub(crate) window: WinitWindow,
85+
cursor_state: CursorState,
7986
/// GL surface of the window
8087
pub(crate) surface: Surface<WindowSurface>,
8188
/// The main panel of this window.
@@ -138,6 +145,7 @@ impl Window {
138145
(
139146
Self {
140147
window,
148+
cursor_state: CursorState::default(),
141149
surface,
142150
panel: None,
143151
event_listeners: Default::default(),
@@ -182,6 +190,7 @@ impl Window {
182190

183191
let mut window = Self {
184192
window,
193+
cursor_state: CursorState::default(),
185194
surface,
186195
panel: None,
187196
// webview: None,
@@ -700,6 +709,11 @@ impl Window {
700709
clipboard: Option<&mut Clipboard>,
701710
compositor: &mut IOCompositor,
702711
) -> bool {
712+
if let EmbedderMsg::SetCursor(_, cursor) = message {
713+
self.set_cursor_icon(cursor);
714+
return false;
715+
}
716+
703717
// Handle message in Verso Panel
704718
if let Some(panel) = &self.panel {
705719
if panel.webview.webview_id == webview_id {
@@ -863,7 +877,7 @@ impl Window {
863877
}
864878

865879
/// Set cursor icon of the window.
866-
pub fn set_cursor_icon(&self, cursor: Cursor) {
880+
pub fn set_cursor_icon(&mut self, cursor: Cursor) {
867881
let winit_cursor = match cursor {
868882
Cursor::Default => CursorIcon::Default,
869883
Cursor::Pointer => CursorIcon::Pointer,
@@ -899,9 +913,14 @@ impl Window {
899913
Cursor::AllScroll => CursorIcon::AllScroll,
900914
Cursor::ZoomIn => CursorIcon::ZoomIn,
901915
Cursor::ZoomOut => CursorIcon::ZoomOut,
902-
_ => CursorIcon::Default,
916+
Cursor::None => {
917+
self.window.set_cursor_visible(false);
918+
return;
919+
}
903920
};
921+
self.cursor_state.current_cursor = winit_cursor.clone();
904922
self.window.set_cursor(winit_cursor);
923+
self.window.set_cursor_visible(true);
905924
}
906925

907926
/// This method enables IME and set the IME cursor area of the window.
@@ -1218,9 +1237,9 @@ impl Window {
12181237
}
12191238

12201239
/// Set drag-resize cursor when mouse is hover on the border of the window.
1221-
fn set_drag_resize_cursor(&self, direction: Option<ResizeDirection>) {
1222-
let cursor = match direction {
1223-
Some(direction) => match direction {
1240+
fn set_drag_resize_cursor(&mut self, direction: Option<ResizeDirection>) {
1241+
if let Some(direction) = direction {
1242+
let cursor = match direction {
12241243
ResizeDirection::East => CursorIcon::EResize,
12251244
ResizeDirection::West => CursorIcon::WResize,
12261245
ResizeDirection::South => CursorIcon::SResize,
@@ -1229,11 +1248,13 @@ impl Window {
12291248
ResizeDirection::NorthWest => CursorIcon::NwResize,
12301249
ResizeDirection::SouthEast => CursorIcon::SeResize,
12311250
ResizeDirection::SouthWest => CursorIcon::SwResize,
1232-
},
1233-
None => CursorIcon::Default,
1234-
};
1235-
1236-
self.window.set_cursor(cursor);
1251+
};
1252+
self.cursor_state.cursor_resizing = true;
1253+
self.window.set_cursor(cursor);
1254+
} else if self.cursor_state.cursor_resizing {
1255+
self.cursor_state.cursor_resizing = false;
1256+
self.window.set_cursor(self.cursor_state.current_cursor);
1257+
}
12371258
}
12381259
}
12391260

0 commit comments

Comments
 (0)