fix resolution restoration (#7572)
* Fix resolution restore. Screen resolution changes may be slow and cause errors in judgment. Remove the consideration of resolution changes caused by other processes. * Keep the design unchange: when all connections end, revert to the resolution when there were no connections. * Resolution menu use `scaledRect` for retina * I can't reproduce the restoration failure of retina with 3rd software, but it maybe the same reason of slow resolution change. Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
57510980ed
commit
de65c8b2cf
@ -1253,7 +1253,7 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
|
||||
FFI get ffi => widget.ffi;
|
||||
PeerInfo get pi => widget.ffi.ffiModel.pi;
|
||||
FfiModel get ffiModel => widget.ffi.ffiModel;
|
||||
Rect? get rect => ffiModel.rect;
|
||||
Rect? get rect => scaledRect();
|
||||
List<Resolution> get resolutions => pi.resolutions;
|
||||
bool get isWayland => bind.mainCurrentIsWayland();
|
||||
|
||||
@ -1263,6 +1263,20 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
|
||||
_getLocalResolutionWayland();
|
||||
}
|
||||
|
||||
Rect? scaledRect() {
|
||||
final scale = pi.scaleOfDisplay(pi.currentDisplay);
|
||||
final rect = ffiModel.rect;
|
||||
if (rect == null) {
|
||||
return null;
|
||||
}
|
||||
return Rect.fromLTWH(
|
||||
rect.left,
|
||||
rect.top,
|
||||
rect.width / scale,
|
||||
rect.height / scale,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isVirtualDisplay = ffiModel.isVirtualDisplayResolution;
|
||||
@ -1296,9 +1310,8 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
|
||||
if (lastGroupValue == _kCustomResolutionValue) {
|
||||
_groupValue = _kCustomResolutionValue;
|
||||
} else {
|
||||
var scale = pi.scaleOfDisplay(pi.currentDisplay);
|
||||
_groupValue =
|
||||
'${(rect?.width ?? 0) ~/ scale}x${(rect?.height ?? 0) ~/ scale}';
|
||||
'${(rect?.width ?? 0).toInt()}x${(rect?.height ?? 0).toInt()}';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,8 @@ pub fn reset_resolutions() {
|
||||
);
|
||||
}
|
||||
}
|
||||
// Can be cleared because reset resolutions is called when there is no client connected.
|
||||
CHANGED_RESOLUTIONS.write().unwrap().clear();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -235,9 +237,13 @@ pub(super) fn get_original_resolution(
|
||||
..Default::default()
|
||||
}
|
||||
} else {
|
||||
let mut changed_resolutions = CHANGED_RESOLUTIONS.write().unwrap();
|
||||
let changed_resolutions = CHANGED_RESOLUTIONS.write().unwrap();
|
||||
let (width, height) = match changed_resolutions.get(display_name) {
|
||||
Some(res) => {
|
||||
res.original
|
||||
/*
|
||||
The resolution change may not happen immediately, `changed` has been updated,
|
||||
but the actual resolution is old, it will be mistaken for a third-party change.
|
||||
if res.changed.0 != w as i32 || res.changed.1 != h as i32 {
|
||||
// If the resolution is changed by third process, remove the record in changed_resolutions.
|
||||
changed_resolutions.remove(display_name);
|
||||
@ -245,6 +251,7 @@ pub(super) fn get_original_resolution(
|
||||
} else {
|
||||
res.original
|
||||
}
|
||||
*/
|
||||
}
|
||||
None => (w as _, h as _),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user