Merge pull request #3374 from fufesou/fix/macos_change_resolution

fix/macos change resolution
This commit is contained in:
RustDesk 2023-02-25 22:56:27 +08:00 committed by GitHub
commit 117b306dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 38 deletions

View File

@ -156,7 +156,7 @@ class FfiModel with ChangeNotifier {
} else if (name == 'clipboard') {
Clipboard.setData(ClipboardData(text: evt['content']));
} else if (name == 'permission') {
parent.target?.ffiModel.updatePermission(evt, peerId);
updatePermission(evt, peerId);
} else if (name == 'chat_client_mode') {
parent.target?.chatModel
.receive(ChatModel.clientModeID, evt['text'] ?? '');
@ -241,36 +241,33 @@ class FfiModel with ChangeNotifier {
}
}
handleSwitchDisplay(Map<String, dynamic> evt, String peerId) {
final oldOrientation = _display.width > _display.height;
var old = _pi.currentDisplay;
_pi.currentDisplay = int.parse(evt['display']);
_display.x = double.parse(evt['x']);
_display.y = double.parse(evt['y']);
_display.width = int.parse(evt['width']);
_display.height = int.parse(evt['height']);
_display.cursorEmbedded = int.parse(evt['cursor_embedded']) == 1;
if (old != _pi.currentDisplay) {
parent.target?.cursorModel.updateDisplayOrigin(_display.x, _display.y);
_updateCurDisplay(String peerId, Display newDisplay) {
if (newDisplay != _display) {
if (newDisplay.x != _display.x || newDisplay.y != _display.y) {
parent.target?.cursorModel
.updateDisplayOrigin(newDisplay.x, newDisplay.y);
}
_display = newDisplay;
_updateSessionWidthHeight(peerId);
}
}
_updateSessionWidthHeight(peerId, display.width, display.height);
handleSwitchDisplay(Map<String, dynamic> evt, String peerId) {
_pi.currentDisplay = int.parse(evt['display']);
var newDisplay = Display();
newDisplay.x = double.parse(evt['x']);
newDisplay.y = double.parse(evt['y']);
newDisplay.width = int.parse(evt['width']);
newDisplay.height = int.parse(evt['height']);
newDisplay.cursorEmbedded = int.parse(evt['cursor_embedded']) == 1;
_updateCurDisplay(peerId, newDisplay);
try {
CurrentDisplayState.find(peerId).value = _pi.currentDisplay;
} catch (e) {
//
}
// remote is mobile, and orientation changed
if ((_display.width > _display.height) != oldOrientation) {
gFFI.canvasModel.updateViewStyle();
}
if (_pi.platform == kPeerPlatformLinux ||
_pi.platform == kPeerPlatformWindows ||
_pi.platform == kPeerPlatformMacOS) {
parent.target?.canvasModel.updateViewStyle();
}
parent.target?.recordingModel.onSwitchDisplay();
handleResolutions(peerId, evt["resolutions"]);
notifyListeners();
@ -372,7 +369,8 @@ class FfiModel with ChangeNotifier {
});
}
_updateSessionWidthHeight(String id, int width, int height) {
_updateSessionWidthHeight(String id) {
parent.target?.canvasModel.updateViewStyle();
bind.sessionSetSize(id: id, width: display.width, height: display.height);
}
@ -429,7 +427,7 @@ class FfiModel with ChangeNotifier {
stateGlobal.displaysCount.value = _pi.displays.length;
if (_pi.currentDisplay < _pi.displays.length) {
_display = _pi.displays[_pi.currentDisplay];
_updateSessionWidthHeight(peerId, display.width, display.height);
_updateSessionWidthHeight(peerId);
}
if (displays.isNotEmpty) {
parent.target?.dialogManager.showLoading(
@ -488,7 +486,7 @@ class FfiModel with ChangeNotifier {
_pi.displays = newDisplays;
stateGlobal.displaysCount.value = _pi.displays.length;
if (_pi.currentDisplay >= 0 && _pi.currentDisplay < _pi.displays.length) {
_display = _pi.displays[_pi.currentDisplay];
_updateCurDisplay(peerId, _pi.displays[_pi.currentDisplay]);
}
}
notifyListeners();
@ -797,12 +795,18 @@ class CanvasModel with ChangeNotifier {
final dh = getDisplayHeight() * _scale;
var dxOffset = 0;
var dyOffset = 0;
if (dw > size.width) {
dxOffset = (x - dw * (x / size.width) - _x).toInt();
}
if (dh > size.height) {
dyOffset = (y - dh * (y / size.height) - _y).toInt();
try {
if (dw > size.width) {
dxOffset = (x - dw * (x / size.width) - _x).toInt();
}
if (dh > size.height) {
dyOffset = (y - dh * (y / size.height) - _y).toInt();
}
} catch (e) {
// Unhandled Exception: Unsupported operation: Infinity or NaN toInt
return;
}
_x += dxOffset;
_y += dyOffset;
if (dxOffset != 0 || dyOffset != 0) {
@ -1579,6 +1583,19 @@ class Display {
? kDesktopDefaultDisplayHeight
: kMobileDefaultDisplayHeight;
}
@override
bool operator ==(Object other) =>
other is Display &&
other.runtimeType == runtimeType &&
_innerEqual(other);
bool _innerEqual(Display other) =>
other.x == x &&
other.y == y &&
other.width == width &&
other.height == height &&
other.cursorEmbedded == cursorEmbedded;
}
class Resolution {

View File

@ -60,7 +60,7 @@ extern "C" bool MacGetModes(CGDirectDisplayID display, uint32_t *widths, uint32_
return false;
}
*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);
widths[i] = (uint32_t)CGDisplayModeGetWidth(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;
}
int numModes = CFArrayGetCount(allModes);
CGDisplayModeRef bestMode = NULL;
for (int i = 0; i < numModes; i++) {
CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i);
if (width == CGDisplayModeGetWidth(mode) &&

View File

@ -612,18 +612,18 @@ pub fn resolutions(name: &str) -> Vec<Resolution> {
unsafe {
if YES == MacGetModeNum(display, &mut num) {
let (mut widths, mut heights) = (vec![0; num as _], vec![0; num as _]);
let mut realNum = 0;
let mut real_num = 0;
if YES
== MacGetModes(
display,
widths.as_mut_ptr(),
heights.as_mut_ptr(),
num,
&mut realNum,
&mut real_num,
)
{
if realNum <= num {
for i in 0..realNum {
if real_num <= num {
for i in 0..real_num {
let resolution = Resolution {
width: widths[i as usize] as _,
height: heights[i as usize] as _,

View File

@ -577,6 +577,14 @@ fn run(sp: GenericService) -> ResultType<()> {
if last_check_displays.elapsed().as_millis() > 1000 {
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() {
sp.send(msg_out);
}

View File

@ -9,7 +9,7 @@ use sciter::Value;
use hbb_common::{
allow_err,
config::{self, LocalConfig, PeerConfig},
config::{LocalConfig, PeerConfig},
log,
};