macos, periodically check if current display is changed
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
f71d4e9e81
commit
b8b3e99602
@ -60,7 +60,7 @@ extern "C" bool MacGetModes(CGDirectDisplayID display, uint32_t *widths, uint32_
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*numModes = CFArrayGetCount(allModes);
|
*numModes = CFArrayGetCount(allModes);
|
||||||
for (int i = 0; i < *numModes && i < max; i++) {
|
for (uint32_t i = 0; i < *numModes && i < max; i++) {
|
||||||
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i);
|
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i);
|
||||||
widths[i] = (uint32_t)CGDisplayModeGetWidth(mode);
|
widths[i] = (uint32_t)CGDisplayModeGetWidth(mode);
|
||||||
heights[i] = (uint32_t)CGDisplayModeGetHeight(mode);
|
heights[i] = (uint32_t)CGDisplayModeGetHeight(mode);
|
||||||
@ -136,7 +136,6 @@ extern "C" bool MacSetMode(CGDirectDisplayID display, uint32_t width, uint32_t h
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
int numModes = CFArrayGetCount(allModes);
|
int numModes = CFArrayGetCount(allModes);
|
||||||
CGDisplayModeRef bestMode = NULL;
|
|
||||||
for (int i = 0; i < numModes; i++) {
|
for (int i = 0; i < numModes; i++) {
|
||||||
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i);
|
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i);
|
||||||
if (width == CGDisplayModeGetWidth(mode) &&
|
if (width == CGDisplayModeGetWidth(mode) &&
|
||||||
|
@ -612,18 +612,18 @@ pub fn resolutions(name: &str) -> Vec<Resolution> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
if YES == MacGetModeNum(display, &mut num) {
|
if YES == MacGetModeNum(display, &mut num) {
|
||||||
let (mut widths, mut heights) = (vec![0; num as _], vec![0; num as _]);
|
let (mut widths, mut heights) = (vec![0; num as _], vec![0; num as _]);
|
||||||
let mut realNum = 0;
|
let mut real_num = 0;
|
||||||
if YES
|
if YES
|
||||||
== MacGetModes(
|
== MacGetModes(
|
||||||
display,
|
display,
|
||||||
widths.as_mut_ptr(),
|
widths.as_mut_ptr(),
|
||||||
heights.as_mut_ptr(),
|
heights.as_mut_ptr(),
|
||||||
num,
|
num,
|
||||||
&mut realNum,
|
&mut real_num,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if realNum <= num {
|
if real_num <= num {
|
||||||
for i in 0..realNum {
|
for i in 0..real_num {
|
||||||
let resolution = Resolution {
|
let resolution = Resolution {
|
||||||
width: widths[i as usize] as _,
|
width: widths[i as usize] as _,
|
||||||
height: heights[i as usize] as _,
|
height: heights[i as usize] as _,
|
||||||
|
@ -577,6 +577,14 @@ fn run(sp: GenericService) -> ResultType<()> {
|
|||||||
if last_check_displays.elapsed().as_millis() > 1000 {
|
if last_check_displays.elapsed().as_millis() > 1000 {
|
||||||
last_check_displays = now;
|
last_check_displays = now;
|
||||||
|
|
||||||
|
// Capturer on macos does not return Err event the solution is changed.
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
if check_display_changed(c.ndisplay, c.current, c.width, c.height) {
|
||||||
|
log::info!("Displays changed");
|
||||||
|
*SWITCH.lock().unwrap() = true;
|
||||||
|
bail!("SWITCH");
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(msg_out) = check_displays_changed() {
|
if let Some(msg_out) = check_displays_changed() {
|
||||||
sp.send(msg_out);
|
sp.send(msg_out);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user