Merge pull request #304 from fufesou/master
resolution changed, no need to reconnect
This commit is contained in:
commit
5e0bf8f5a9
@ -43,6 +43,36 @@ pub fn new() -> GenericService {
|
|||||||
sp
|
sp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_display_changed(
|
||||||
|
last_n: usize,
|
||||||
|
last_current: usize,
|
||||||
|
last_width: usize,
|
||||||
|
last_hegiht: usize,
|
||||||
|
) -> bool {
|
||||||
|
let displays = match Display::all() {
|
||||||
|
Ok(d) => d,
|
||||||
|
_ => return false,
|
||||||
|
};
|
||||||
|
|
||||||
|
let n = displays.len();
|
||||||
|
if n != last_n {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i, d) in displays.iter().enumerate() {
|
||||||
|
if d.is_primary() {
|
||||||
|
if i != last_current {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
if d.width() != last_width || d.height() != last_hegiht {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
fn run(sp: GenericService) -> ResultType<()> {
|
fn run(sp: GenericService) -> ResultType<()> {
|
||||||
let fps = 30;
|
let fps = 30;
|
||||||
let spf = time::Duration::from_secs_f32(1. / (fps as f32));
|
let spf = time::Duration::from_secs_f32(1. / (fps as f32));
|
||||||
@ -161,6 +191,12 @@ fn run(sp: GenericService) -> ResultType<()> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
if check_display_changed(ndisplay, current, width, height) {
|
||||||
|
log::info!("Displays changed");
|
||||||
|
*SWITCH.lock().unwrap() = true;
|
||||||
|
bail!("SWITCH");
|
||||||
|
}
|
||||||
|
|
||||||
return Err(err.into());
|
return Err(err.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user