1
1
use std:: path:: PathBuf ;
2
2
3
3
use objc2:: { msg_send_id, rc:: Retained , ClassType } ;
4
- use objc2_app_kit:: { NSEvent , NSSharingServicePicker , NSView , NSWindow } ;
4
+ use objc2_app_kit:: { NSSharingServicePicker , NSView , NSWindow } ;
5
5
use objc2_foundation:: {
6
6
MainThreadMarker , NSArray , NSPoint , NSRect , NSRectEdge , NSSize , NSString , NSURL ,
7
7
} ;
8
- use tauri:: { Runtime , WebviewWindow } ;
8
+ use tauri:: { PhysicalPosition , Runtime , WebviewWindow } ;
9
9
10
10
pub enum PreferredEdge {
11
11
TopLeft ,
@@ -26,14 +26,19 @@ impl PreferredEdge {
26
26
}
27
27
28
28
pub trait SharePicker < R : Runtime > {
29
- fn share ( & self , items : Vec < PathBuf > , offset : Option < ( f64 , f64 ) > , preferred_edge : PreferredEdge ) ;
29
+ fn share (
30
+ & self ,
31
+ items : Vec < PathBuf > ,
32
+ position : PhysicalPosition < f64 > ,
33
+ preferred_edge : PreferredEdge ,
34
+ ) ;
30
35
}
31
36
32
37
impl < R : Runtime > SharePicker < R > for WebviewWindow < R > {
33
38
fn share (
34
39
& self ,
35
40
items : Vec < PathBuf > ,
36
- offset : Option < ( f64 , f64 ) > ,
41
+ position : PhysicalPosition < f64 > ,
37
42
preferred_edge : PreferredEdge ,
38
43
) {
39
44
let items = items
@@ -58,29 +63,23 @@ impl<R: Runtime> SharePicker<R> for WebviewWindow<R> {
58
63
59
64
let content_view = window. contentView ( ) . unwrap ( ) ;
60
65
61
- let mouse_location_in_screen = unsafe { NSEvent :: mouseLocation ( ) } ;
66
+ let scale_factor = self . scale_factor ( ) . unwrap ( ) ;
67
+
68
+ let position = PhysicalPosition {
69
+ x : position. x ,
70
+ y : window. frame ( ) . size . height - position. y ,
71
+ } ;
62
72
63
- let mouse_location_in_window = window . convertPointFromScreen ( mouse_location_in_screen ) ;
73
+ let point_in_window = NSPoint :: new ( position . x , position . y ) ;
64
74
65
- let mouse_location_in_content_view =
66
- content_view. convertPoint_fromView ( mouse_location_in_window, None ) ;
75
+ let point_in_content_view = content_view. convertPoint_fromView ( point_in_window, None ) ;
67
76
68
77
let mtm = MainThreadMarker :: new ( ) . unwrap ( ) ;
69
78
70
79
let view = unsafe { NSView :: new ( mtm) } ;
71
80
72
81
unsafe {
73
- view. setFrame ( NSRect :: new (
74
- if let Some ( ( x, y) ) = offset {
75
- NSPoint :: new (
76
- mouse_location_in_content_view. x + x,
77
- mouse_location_in_content_view. y + y,
78
- )
79
- } else {
80
- mouse_location_in_content_view
81
- } ,
82
- NSSize :: new ( 1.0 , 1.0 ) ,
83
- ) ) ;
82
+ view. setFrame ( NSRect :: new ( point_in_content_view, NSSize :: new ( 1.0 , 1.0 ) ) ) ;
84
83
85
84
content_view. addSubview ( & view) ;
86
85
}
0 commit comments