@@ -16,7 +16,7 @@ use std::marker::PhantomData;
1616use std:: pin:: Pin ;
1717use std:: rc:: Rc ;
1818use url:: Url ;
19- use glib:: Properties ;
19+ use glib:: { clone , Properties } ;
2020
2121use crate :: common;
2222use crate :: common:: { glibctx, HistoryItem , LossyTextRead , PageElement , RequestCtx } ;
@@ -42,6 +42,7 @@ pub mod imp {
4242 pub ( crate ) clamp : adw:: Clamp ,
4343 pub ( crate ) left_click_ctrl : RefCell < Option < gtk:: GestureClick > > ,
4444 pub ( crate ) right_click_ctrl : RefCell < Option < gtk:: GestureClick > > ,
45+ pub ( crate ) motion_ctrl : RefCell < Option < gtk:: EventControllerMotion > > ,
4546 pub ( crate ) req_handle : RefCell < Option < RemoteHandle < ( ) > > > ,
4647 #[ property( get = Self :: history_status, builder( HistoryStatus :: static_type( ) ) ) ]
4748 pub ( crate ) history_status : PhantomData < HistoryStatus > ,
@@ -81,6 +82,8 @@ pub mod imp {
8182 . replace ( Some ( gtk:: GestureClick :: builder ( ) . button ( 1 ) . build ( ) ) ) ;
8283 self . right_click_ctrl
8384 . replace ( Some ( gtk:: GestureClick :: builder ( ) . button ( 3 ) . build ( ) ) ) ;
85+ self . motion_ctrl
86+ . replace ( Some ( gtk:: EventControllerMotion :: new ( ) ) ) ;
8487 self . gemini_client
8588 . replace ( gemini:: ClientBuilder :: new ( ) . redirect ( true ) . build ( ) ) ;
8689 }
@@ -151,6 +154,7 @@ impl Tab {
151154 . build ( ) ;
152155 text_view. add_controller ( imp. left_click_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
153156 text_view. add_controller ( imp. right_click_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
157+ text_view. add_controller ( imp. motion_ctrl . borrow ( ) . as_ref ( ) . unwrap ( ) ) ;
154158
155159 imp. scroll_win . set_child ( Some ( & text_view) ) ;
156160 imp. draw_ctx . replace ( Some ( DrawCtx :: new ( text_view, config) ) ) ;
@@ -214,6 +218,22 @@ impl Tab {
214218 text_view. set_extra_menu ( Some ( & menu) ) ;
215219 Ok ( ( ) )
216220 }
221+ fn handle_motion ( & self , x : f64 , y : f64 ) -> Result < ( ) > {
222+ let imp = self . imp ( ) ;
223+ let draw_ctx = imp. draw_ctx . borrow ( ) ;
224+ let draw_ctx = draw_ctx. as_ref ( ) . unwrap ( ) ;
225+ let link = Self :: extract_linkhandler ( draw_ctx, x, y) ;
226+ match link {
227+ Ok ( _) => {
228+ draw_ctx. text_view . set_cursor_from_name ( Some ( "pointer" ) ) ;
229+ }
230+ Err ( _) => {
231+ draw_ctx. text_view . set_cursor_from_name ( Some ( "text" ) ) ;
232+ }
233+ }
234+
235+ Ok ( ( ) )
236+ }
217237 pub fn spawn_open_url ( & self , url : Url ) {
218238 let i = self . add_to_history ( HistoryItem {
219239 url : url. clone ( ) ,
@@ -373,16 +393,25 @@ impl Tab {
373393 } ;
374394 } ) ;
375395
376- let this = self . clone ( ) ;
396+
377397 imp. right_click_ctrl
378398 . borrow ( )
379399 . as_ref ( )
380400 . unwrap ( )
381- . connect_pressed ( move |_ctrl, _n_press, x, y| {
401+ . connect_pressed ( clone ! ( @weak self as this => @ default -panic , move |_ctrl, _n_press, x, y| {
382402 if let Err ( e) = this. handle_right_click( x, y) {
383403 info!( "{}" , e) ;
384404 } ;
385- } ) ;
405+ } ) ) ;
406+
407+
408+ imp. motion_ctrl
409+ . borrow ( )
410+ . as_ref ( )
411+ . unwrap ( )
412+ . connect_motion ( clone ! ( @weak self as this => @default -panic, move |_ctrl, x, y| {
413+ let _ = this. handle_motion( x, y) ;
414+ } ) ) ;
386415 }
387416 fn extract_linkhandler ( draw_ctx : & DrawCtx , x : f64 , y : f64 ) -> Result < String > {
388417 info ! ( "Extracting linkhandler from clicked text" ) ;
@@ -393,13 +422,11 @@ impl Tab {
393422 . iter_at_location ( x as i32 , y as i32 )
394423 . context ( "Can't get text iter where clicked" ) ?;
395424
396- for tag in iter. tags ( ) {
397- if let Some ( link) = DrawCtx :: linkhandler ( & tag) {
398- return Ok ( link. clone ( ) ) ;
399- }
400- }
401-
402- Err ( anyhow:: Error :: msg ( "Clicked text doesn't have a link tag" ) )
425+ iter. tags ( )
426+ . iter ( )
427+ . find_map ( DrawCtx :: linkhandler)
428+ . cloned ( )
429+ . ok_or ( anyhow:: Error :: msg ( "Clicked text doesn't have a link tag" ) )
403430 }
404431 async fn open_file_url ( & self , req : & mut RequestCtx ) -> Result < ( ) > {
405432 let path = req
0 commit comments