@@ -72,10 +72,17 @@ pub(crate) struct EventListeners {
72
72
pub ( crate ) on_close_requested : bool ,
73
73
}
74
74
75
+ #[ derive( Debug , Default ) ]
76
+ struct CursorState {
77
+ current_cursor : CursorIcon ,
78
+ cursor_resizing : bool ,
79
+ }
80
+
75
81
/// A Verso window is a Winit window containing several web views.
76
82
pub struct Window {
77
83
/// Access to Winit window
78
84
pub ( crate ) window : WinitWindow ,
85
+ cursor_state : CursorState ,
79
86
/// GL surface of the window
80
87
pub ( crate ) surface : Surface < WindowSurface > ,
81
88
/// The main panel of this window.
@@ -138,6 +145,7 @@ impl Window {
138
145
(
139
146
Self {
140
147
window,
148
+ cursor_state : CursorState :: default ( ) ,
141
149
surface,
142
150
panel : None ,
143
151
event_listeners : Default :: default ( ) ,
@@ -182,6 +190,7 @@ impl Window {
182
190
183
191
let mut window = Self {
184
192
window,
193
+ cursor_state : CursorState :: default ( ) ,
185
194
surface,
186
195
panel : None ,
187
196
// webview: None,
@@ -700,6 +709,11 @@ impl Window {
700
709
clipboard : Option < & mut Clipboard > ,
701
710
compositor : & mut IOCompositor ,
702
711
) -> bool {
712
+ if let EmbedderMsg :: SetCursor ( _, cursor) = message {
713
+ self . set_cursor_icon ( cursor) ;
714
+ return false ;
715
+ }
716
+
703
717
// Handle message in Verso Panel
704
718
if let Some ( panel) = & self . panel {
705
719
if panel. webview . webview_id == webview_id {
@@ -863,7 +877,7 @@ impl Window {
863
877
}
864
878
865
879
/// 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 ) {
867
881
let winit_cursor = match cursor {
868
882
Cursor :: Default => CursorIcon :: Default ,
869
883
Cursor :: Pointer => CursorIcon :: Pointer ,
@@ -899,9 +913,14 @@ impl Window {
899
913
Cursor :: AllScroll => CursorIcon :: AllScroll ,
900
914
Cursor :: ZoomIn => CursorIcon :: ZoomIn ,
901
915
Cursor :: ZoomOut => CursorIcon :: ZoomOut ,
902
- _ => CursorIcon :: Default ,
916
+ Cursor :: None => {
917
+ self . window . set_cursor_visible ( false ) ;
918
+ return ;
919
+ }
903
920
} ;
921
+ self . cursor_state . current_cursor = winit_cursor. clone ( ) ;
904
922
self . window . set_cursor ( winit_cursor) ;
923
+ self . window . set_cursor_visible ( true ) ;
905
924
}
906
925
907
926
/// This method enables IME and set the IME cursor area of the window.
@@ -1218,9 +1237,9 @@ impl Window {
1218
1237
}
1219
1238
1220
1239
/// 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 {
1224
1243
ResizeDirection :: East => CursorIcon :: EResize ,
1225
1244
ResizeDirection :: West => CursorIcon :: WResize ,
1226
1245
ResizeDirection :: South => CursorIcon :: SResize ,
@@ -1229,11 +1248,13 @@ impl Window {
1229
1248
ResizeDirection :: NorthWest => CursorIcon :: NwResize ,
1230
1249
ResizeDirection :: SouthEast => CursorIcon :: SeResize ,
1231
1250
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
+ }
1237
1258
}
1238
1259
}
1239
1260
0 commit comments