@@ -133,15 +133,19 @@ impl VideoModeHandle {
133
133
#[ derive( Clone ) ]
134
134
pub struct MonitorHandle ( CGDirectDisplayID ) ;
135
135
136
+ impl MonitorHandle {
137
+ /// Internal comparisons of [`MonitorHandle`]s are done first requesting a UUID for the handle.
138
+ fn uuid ( & self ) -> ffi:: CfUuid {
139
+ ffi:: CfUuid :: from_display_id ( self . 0 )
140
+ }
141
+ }
142
+
136
143
// `CGDirectDisplayID` changes on video mode change, so we cannot rely on that
137
144
// for comparisons, but we can use `CGDisplayCreateUUIDFromDisplayID` to get an
138
145
// unique identifier that persists even across system reboots
139
146
impl PartialEq for MonitorHandle {
140
147
fn eq ( & self , other : & Self ) -> bool {
141
- unsafe {
142
- ffi:: CGDisplayCreateUUIDFromDisplayID ( self . 0 )
143
- == ffi:: CGDisplayCreateUUIDFromDisplayID ( other. 0 )
144
- }
148
+ self . uuid ( ) == other. uuid ( )
145
149
}
146
150
}
147
151
@@ -155,18 +159,13 @@ impl PartialOrd for MonitorHandle {
155
159
156
160
impl Ord for MonitorHandle {
157
161
fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
158
- unsafe {
159
- ffi:: CGDisplayCreateUUIDFromDisplayID ( self . 0 )
160
- . cmp ( & ffi:: CGDisplayCreateUUIDFromDisplayID ( other. 0 ) )
161
- }
162
+ self . uuid ( ) . cmp ( & other. uuid ( ) )
162
163
}
163
164
}
164
165
165
166
impl std:: hash:: Hash for MonitorHandle {
166
167
fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
167
- unsafe {
168
- ffi:: CGDisplayCreateUUIDFromDisplayID ( self . 0 ) . hash ( state) ;
169
- }
168
+ self . uuid ( ) . hash ( state) ;
170
169
}
171
170
}
172
171
@@ -287,12 +286,10 @@ impl MonitorHandle {
287
286
}
288
287
289
288
pub ( crate ) fn ns_screen ( & self , mtm : MainThreadMarker ) -> Option < Retained < NSScreen > > {
290
- let uuid = unsafe { ffi :: CGDisplayCreateUUIDFromDisplayID ( self . 0 ) } ;
289
+ let uuid = self . uuid ( ) ;
291
290
NSScreen :: screens ( mtm) . into_iter ( ) . find ( |screen| {
292
291
let other_native_id = get_display_id ( screen) ;
293
- let other_uuid = unsafe {
294
- ffi:: CGDisplayCreateUUIDFromDisplayID ( other_native_id as CGDirectDisplayID )
295
- } ;
292
+ let other_uuid = ffi:: CfUuid :: from_display_id ( other_native_id) ;
296
293
uuid == other_uuid
297
294
} )
298
295
}
0 commit comments