@@ -141,6 +141,86 @@ impl CGDisplay {
141
141
CGDisplay :: new ( kCGNullDirectDisplayID)
142
142
}
143
143
144
+ /// Return the number of online displays with bounds that include the
145
+ /// specified point.
146
+ pub fn display_count_with_point ( point : CGPoint ) -> Result < u32 , CGError > {
147
+ let mut matching_display_count: u32 = 0 ;
148
+ let result = unsafe {
149
+ CGGetDisplaysWithPoint ( point, 0 , ptr:: null_mut ( ) , & mut matching_display_count)
150
+ } ;
151
+ if result == 0 {
152
+ Ok ( matching_display_count)
153
+ } else {
154
+ Err ( result)
155
+ }
156
+ }
157
+
158
+ /// Return a list of online displays with bounds that include the specified
159
+ /// point.
160
+ pub fn displays_with_point (
161
+ point : CGPoint ,
162
+ max_displays : u32 ,
163
+ ) -> Result < ( Vec < CGDirectDisplayID > , u32 ) , CGError > {
164
+ let count = CGDisplay :: display_count_with_point ( point) ?;
165
+ let count = u32:: max ( u32:: min ( count, max_displays) , 1 ) ;
166
+
167
+ let mut matching_display_count: u32 = 0 ;
168
+ let mut displays: Vec < CGDirectDisplayID > = vec ! [ 0 ; count as usize ] ;
169
+ let result = unsafe {
170
+ CGGetDisplaysWithPoint (
171
+ point,
172
+ max_displays,
173
+ displays. as_mut_ptr ( ) ,
174
+ & mut matching_display_count,
175
+ )
176
+ } ;
177
+
178
+ if result == 0 {
179
+ Ok ( ( displays, matching_display_count) )
180
+ } else {
181
+ Err ( result)
182
+ }
183
+ }
184
+
185
+ /// Return the number of online displays with bounds that intersect the
186
+ /// specified rectangle.
187
+ pub fn display_count_with_rect ( rect : CGRect ) -> Result < u32 , CGError > {
188
+ let mut matching_display_count: u32 = 0 ;
189
+ let result =
190
+ unsafe { CGGetDisplaysWithRect ( rect, 0 , ptr:: null_mut ( ) , & mut matching_display_count) } ;
191
+ if result == 0 {
192
+ Ok ( matching_display_count)
193
+ } else {
194
+ Err ( result)
195
+ }
196
+ }
197
+
198
+ /// Return a list of online displays with bounds that intersect the specified rectangle.
199
+ pub fn displays_with_rect (
200
+ rect : CGRect ,
201
+ max_displays : u32 ,
202
+ ) -> Result < ( Vec < CGDirectDisplayID > , u32 ) , CGError > {
203
+ let count = CGDisplay :: display_count_with_rect ( rect) ?;
204
+ let count = u32:: max ( u32:: min ( count, max_displays) , 1 ) ;
205
+
206
+ let mut matching_display_count: u32 = 0 ;
207
+ let mut displays: Vec < CGDirectDisplayID > = vec ! [ 0 ; count as usize ] ;
208
+ let result = unsafe {
209
+ CGGetDisplaysWithRect (
210
+ rect,
211
+ max_displays,
212
+ displays. as_mut_ptr ( ) ,
213
+ & mut matching_display_count,
214
+ )
215
+ } ;
216
+
217
+ if result == 0 {
218
+ Ok ( ( displays, matching_display_count) )
219
+ } else {
220
+ Err ( result)
221
+ }
222
+ }
223
+
144
224
/// Returns the bounds of a display in the global display coordinate space.
145
225
#[ inline]
146
226
pub fn bounds ( & self ) -> CGRect {
@@ -673,6 +753,12 @@ extern "C" {
673
753
active_displays : * mut CGDirectDisplayID ,
674
754
display_count : * mut u32 ,
675
755
) -> CGError ;
756
+ pub fn CGGetDisplaysWithPoint (
757
+ point : CGPoint ,
758
+ max_displays : u32 ,
759
+ displays : * mut CGDirectDisplayID ,
760
+ matching_display_count : * mut u32 ,
761
+ ) -> CGError ;
676
762
pub fn CGGetDisplaysWithRect (
677
763
rect : CGRect ,
678
764
max_displays : u32 ,
0 commit comments