@@ -10,7 +10,7 @@ use smithay::{
1010 input:: { pointer:: MotionEvent , Seat } ,
1111 output:: Output ,
1212 reexports:: wayland_server:: Resource ,
13- utils:: { IsAlive , Serial , SERIAL_COUNTER } ,
13+ utils:: { IsAlive , Point , Serial , SERIAL_COUNTER } ,
1414 wayland:: {
1515 seat:: WaylandFocus ,
1616 selection:: { data_device:: set_data_device_focus, primary_selection:: set_primary_focus} ,
@@ -231,29 +231,30 @@ fn update_focus_state(
231231 if target. is_some ( ) {
232232 //need to borrow mutably for surface under
233233 let mut shell = state. common . shell . write ( ) . unwrap ( ) ;
234- // get the top left corner of the target element
234+ // get geometry of the target element
235235 let geometry = shell. focused_geometry ( target. unwrap ( ) ) ;
236- //to avoid the nested mutable borrow of state
237- if geometry. is_some ( ) {
238- let top_left = geometry. unwrap ( ) . loc . to_f64 ( ) ;
236+ if let Some ( geometry) = geometry {
237+ // get the center of the target element
238+ let window_center = Point :: from ( ( geometry. size . w / 2 , geometry. size . h / 2 ) ) ;
239+ let new_pos = ( geometry. loc + window_center) . to_f64 ( ) ;
239240
240241 // create a pointer target from the target element
241242 let output = shell
242243 . outputs ( )
243- . find ( |output| output. geometry ( ) . to_f64 ( ) . contains ( top_left ) )
244+ . find ( |output| output. geometry ( ) . to_f64 ( ) . contains ( new_pos ) )
244245 . cloned ( )
245246 . unwrap_or ( seat. active_output ( ) ) ;
246247
247248 let focus = shell
248- . surface_under ( top_left , & output)
249+ . surface_under ( new_pos , & output)
249250 . map ( |( focus, loc) | ( focus, loc. as_logical ( ) ) ) ;
250251 //drop here to avoid multiple mutable borrows
251252 mem:: drop ( shell) ;
252253 seat. get_pointer ( ) . unwrap ( ) . motion (
253254 state,
254255 focus,
255256 & MotionEvent {
256- location : top_left . as_logical ( ) ,
257+ location : new_pos . as_logical ( ) ,
257258 serial : SERIAL_COUNTER . next_serial ( ) ,
258259 time : 0 ,
259260 } ,
0 commit comments