Skip to content

Commit f94fa25

Browse files
authored
Added ffi bindings for CGDisplayRegisterReconfigurationCallback and related types/funcs (#687)
1 parent 31a92cd commit f94fa25

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

core-graphics/src/display.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#![allow(non_upper_case_globals)]
1111

12+
use bitflags::bitflags;
1213
use libc;
1314
use std::ops::Deref;
1415
use std::ptr;
@@ -110,6 +111,41 @@ pub enum CGConfigureOption {
110111
ConfigurePermanently = 2,
111112
}
112113

114+
/// A client-supplied callback function that’s invoked whenever the configuration of a local display is changed.
115+
pub type CGDisplayReconfigurationCallBack =
116+
unsafe extern "C" fn(display: CGDirectDisplayID, flags: u32, user_info: *const libc::c_void);
117+
118+
bitflags! {
119+
/// The configuration parameters that are passed to a display reconfiguration callback function.
120+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
121+
pub struct CGDisplayChangeSummaryFlags: u32 {
122+
/// The display configuration is about to change.
123+
const kCGDisplayBeginConfigurationFlag = 1;
124+
/// The location of the upper-left corner of the display in the global display coordinate space has changed.
125+
const kCGDisplayMovedFlag = 1 << 1;
126+
/// The display is now the main display.
127+
const kCGDisplaySetMainFlag = 1 << 2;
128+
/// The display mode has changed.
129+
const kCGDisplaySetModeFlag = 1 << 3;
130+
/// The display has been added to the active display list.
131+
const kCGDisplayAddFlag = 1 << 4;
132+
/// The display has been removed from the active display list.
133+
const kCGDisplayRemoveFlag = 1 << 5;
134+
/// The display has been enabled.
135+
const kCGDisplayEnabledFlag = 1 << 8;
136+
/// The display has been disabled.
137+
const kCGDisplayDisabledFlag = 1 << 9;
138+
/// The display is now mirroring another display.
139+
const kCGDisplayMirrorFlag = 1 << 10;
140+
/// The display is no longer mirroring another display.
141+
const kCGDisplayUnMirrorFlag = 1 << 11;
142+
/// The shape of the desktop (the union of display areas) has changed.
143+
const kCGDisplayDesktopShapeChangedFlag = 1 << 12;
144+
145+
const _ = !0;
146+
}
147+
}
148+
113149
#[derive(Copy, Clone, Debug)]
114150
pub struct CGDisplay {
115151
pub id: CGDirectDisplayID,
@@ -724,6 +760,14 @@ extern "C" {
724760
y: i32,
725761
) -> CGError;
726762
pub fn CGRestorePermanentDisplayConfiguration();
763+
pub fn CGDisplayRegisterReconfigurationCallback(
764+
callback: CGDisplayReconfigurationCallBack,
765+
user_info: *const libc::c_void,
766+
) -> CGError;
767+
pub fn CGDisplayRemoveReconfigurationCallback(
768+
callback: CGDisplayReconfigurationCallBack,
769+
user_info: *const libc::c_void,
770+
) -> CGError;
727771

728772
pub fn CGDisplayCopyDisplayMode(display: CGDirectDisplayID) -> crate::sys::CGDisplayModeRef;
729773
pub fn CGDisplayModeGetHeight(mode: crate::sys::CGDisplayModeRef) -> libc::size_t;

0 commit comments

Comments
 (0)