fix, change_display_resolution, add comments

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-10-18 09:59:02 +08:00
parent a32e740242
commit c1b865d00e
4 changed files with 38 additions and 24 deletions

View File

@ -430,14 +430,12 @@ class FfiModel with ChangeNotifier {
Map<String, dynamic> evt, SessionID sessionId, String peerId) { Map<String, dynamic> evt, SessionID sessionId, String peerId) {
final curDisplay = int.parse(evt['display']); final curDisplay = int.parse(evt['display']);
// The message should be handled by the another UI session.
if (isChooseDisplayToOpenInNewWindow(_pi, sessionId)) {
if (curDisplay != _pi.currentDisplay) {
return;
}
}
if (_pi.currentDisplay != kAllDisplayValue) { if (_pi.currentDisplay != kAllDisplayValue) {
if (bind.peerGetDefaultSessionsCount(id: peerId) > 1) {
if (curDisplay != _pi.currentDisplay) {
return;
}
}
_pi.currentDisplay = curDisplay; _pi.currentDisplay = curDisplay;
} }
@ -825,6 +823,7 @@ class FfiModel with ChangeNotifier {
} }
_pi.displays = newDisplays; _pi.displays = newDisplays;
_pi.displaysCount.value = _pi.displays.length; _pi.displaysCount.value = _pi.displays.length;
if (_pi.currentDisplay == kAllDisplayValue) { if (_pi.currentDisplay == kAllDisplayValue) {
updateCurDisplay(sessionId); updateCurDisplay(sessionId);
// to-do: What if the displays are changed? // to-do: What if the displays are changed?

View File

@ -59,7 +59,10 @@ impl SyncDisplaysInfo {
} }
} }
// This function is really useful, though a duplicate check if display changed.
// Because the video server will send the supported resolutions of the {idx} display to the subscribers.
pub(super) fn check_display_changed( pub(super) fn check_display_changed(
ndisplay: usize,
idx: usize, idx: usize,
(x, y, w, h): (i32, i32, usize, usize), (x, y, w, h): (i32, i32, usize, usize),
) -> Option<DisplayInfo> { ) -> Option<DisplayInfo> {
@ -72,7 +75,14 @@ pub(super) fn check_display_changed(
} }
let lock = SYNC_DISPLAYS.lock().unwrap(); let lock = SYNC_DISPLAYS.lock().unwrap();
// If plugging out a monitor && lock.displays.get(idx) is None.
// 1. The client version < 1.2.4. The client side has to reconnect.
// 2. The client version > 1.2.4, The client side can handle the case becuase sync peer info message will be sent.
// But it is acceptable to for the user to reconnect manually, becuase the monitor is unplugged.
let d = lock.displays.get(idx)?; let d = lock.displays.get(idx)?;
if ndisplay != lock.displays.len() {
return Some(d.clone());
}
if !(d.x == x && d.y == y && d.width == w as i32 && d.height == h as i32) { if !(d.x == x && d.y == y && d.width == w as i32 && d.height == h as i32) {
Some(d.clone()) Some(d.clone())
} else { } else {
@ -144,6 +154,8 @@ fn displays_to_msg(displays: Vec<DisplayInfo>) -> Message {
..Default::default() ..Default::default()
}; };
pi.displays = displays.clone(); pi.displays = displays.clone();
// current_display should not be used in server.
// It is set to 0 for compatibility with old clients.
pi.current_display = 0; pi.current_display = 0;
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_peer_info(pi); msg_out.set_peer_info(pi);

View File

@ -297,6 +297,7 @@ pub(super) struct CapturerInfo {
pub origin: (i32, i32), pub origin: (i32, i32),
pub width: usize, pub width: usize,
pub height: usize, pub height: usize,
pub ndisplay: usize,
pub current: usize, pub current: usize,
pub privacy_mode_id: i32, pub privacy_mode_id: i32,
pub _capturer_privacy_mode_id: i32, pub _capturer_privacy_mode_id: i32,
@ -388,6 +389,7 @@ fn get_capturer(
origin, origin,
width, width,
height, height,
ndisplay,
current, current,
privacy_mode_id, privacy_mode_id,
_capturer_privacy_mode_id: capturer_privacy_mode_id, _capturer_privacy_mode_id: capturer_privacy_mode_id,
@ -503,9 +505,11 @@ fn run(vs: VideoService) -> ResultType<()> {
let now = time::Instant::now(); let now = time::Instant::now();
if last_check_displays.elapsed().as_millis() > 1000 { if last_check_displays.elapsed().as_millis() > 1000 {
last_check_displays = now; last_check_displays = now;
if let Some(display) = if let Some(display) = check_display_changed(
check_display_changed(c.current, (c.origin.0, c.origin.1, c.width, c.height)) c.ndisplay,
{ c.current,
(c.origin.0, c.origin.1, c.width, c.height),
) {
log::info!("Display {} changed", display); log::info!("Display {} changed", display);
broadcast_display_changed(display_idx, &sp, &c.name, display); broadcast_display_changed(display_idx, &sp, &c.name, display);
bail!("SWITCH"); bail!("SWITCH");
@ -586,6 +590,16 @@ fn run(vs: VideoService) -> ResultType<()> {
} }
} }
Err(err) => { Err(err) => {
if let Some(display) = check_display_changed(
c.ndisplay,
c.current,
(c.origin.0, c.origin.1, c.width, c.height),
) {
log::info!("Display {} changed", display);
broadcast_display_changed(display_idx, &sp, &c.name, display);
bail!("SWITCH");
}
#[cfg(windows)] #[cfg(windows)]
if !c.is_gdi() { if !c.is_gdi() {
c.set_gdi(); c.set_gdi();
@ -850,20 +864,6 @@ fn broadcast_display_changed(
} }
} }
fn get_display_info_simple_meta(display_idx: usize) -> Option<(String, (i32, i32), usize, usize)> {
let displays = display_service::try_get_displays().ok()?;
if let Some(display) = displays.get(display_idx) {
Some((
display.name(),
display.origin(),
display.width(),
display.height(),
))
} else {
None
}
}
fn make_display_changed_msg( fn make_display_changed_msg(
display_idx: usize, display_idx: usize,
name: &str, name: &str,

View File

@ -84,6 +84,7 @@ impl TraitCapturer for CapturerPtr {
struct CapDisplayInfo { struct CapDisplayInfo {
rects: Vec<((i32, i32), usize, usize)>, rects: Vec<((i32, i32), usize, usize)>,
displays: Vec<DisplayInfo>, displays: Vec<DisplayInfo>,
num: usize,
primary: usize, primary: usize,
current: usize, current: usize,
capturer: CapturerPtr, capturer: CapturerPtr,
@ -194,6 +195,7 @@ pub(super) async fn check_init() -> ResultType<()> {
let cap_display_info = Box::into_raw(Box::new(CapDisplayInfo { let cap_display_info = Box::into_raw(Box::new(CapDisplayInfo {
rects, rects,
displays, displays,
num,
primary, primary,
current, current,
capturer, capturer,
@ -275,6 +277,7 @@ pub(super) fn get_capturer() -> ResultType<super::video_service::CapturerInfo> {
origin: rect.0, origin: rect.0,
width: rect.1, width: rect.1,
height: rect.2, height: rect.2,
ndisplay: cap_display_info.num,
current: cap_display_info.current, current: cap_display_info.current,
privacy_mode_id: 0, privacy_mode_id: 0,
_capturer_privacy_mode_id: 0, _capturer_privacy_mode_id: 0,