windows, custom resolution

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2023-05-19 20:48:47 +08:00
parent 5f10d1aae6
commit df2de0fd61
7 changed files with 218 additions and 94 deletions

View File

@@ -997,7 +997,6 @@ class _ResolutionsMenu extends StatefulWidget {
const double _kCustonResolutionEditingWidth = 42;
const _kCustomResolutionValue = 'custom';
String? _lastResolutionGroupValue;
class _ResolutionsMenuState extends State<_ResolutionsMenu> {
String _groupValue = '';
@@ -1043,7 +1042,9 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
}
_setGroupValue() {
if (_lastResolutionGroupValue == _kCustomResolutionValue) {
final lastGroupValue =
stateGlobal.getLastResolutionGroupValue(widget.id, pi.currentDisplay);
if (lastGroupValue == _kCustomResolutionValue) {
_groupValue = _kCustomResolutionValue;
} else {
_groupValue = '${display.width}x${display.height}';
@@ -1053,8 +1054,7 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
_menuDivider(
bool showOriginalBtn, bool showFitLocalBtn, bool isVirtualDisplay) {
return Offstage(
// offstage: !(showOriginalBtn || showFitLocalBtn || isVirtualDisplay),
offstage: !(showOriginalBtn || showFitLocalBtn),
offstage: !(showOriginalBtn || showFitLocalBtn || isVirtualDisplay),
child: Divider(),
);
}
@@ -1075,7 +1075,8 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
}
_onChanged(String? value) async {
_lastResolutionGroupValue = value;
stateGlobal.setLastResolutionGroupValue(
widget.id, pi.currentDisplay, value);
if (value == null) return;
int? w;
@@ -1092,7 +1093,7 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
}
if (w != null && h != null) {
if (w != display.width && h != display.height) {
if (w != display.width || h != display.height) {
await _changeResolution(w, h);
}
}
@@ -1145,24 +1146,27 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
}
Widget _customResolutionMenuButton(isVirtualDisplay) {
return RdoMenuButton(
value: _kCustomResolutionValue,
groupValue: _groupValue,
onChanged: _onChanged,
ffi: widget.ffi,
child: Row(
children: [
Text('${translate('resolution_custom_tip')} '),
SizedBox(
width: _kCustonResolutionEditingWidth,
child: _resolutionInput(_customWidth),
),
Text(' x '),
SizedBox(
width: _kCustonResolutionEditingWidth,
child: _resolutionInput(_customHeight),
),
],
return Offstage(
offstage: !isVirtualDisplay,
child: RdoMenuButton(
value: _kCustomResolutionValue,
groupValue: _groupValue,
onChanged: _onChanged,
ffi: widget.ffi,
child: Row(
children: [
Text('${translate('resolution_custom_tip')} '),
SizedBox(
width: _kCustonResolutionEditingWidth,
child: _resolutionInput(_customWidth),
),
Text(' x '),
SizedBox(
width: _kCustonResolutionEditingWidth,
child: _resolutionInput(_customHeight),
),
],
),
),
);
}

View File

@@ -503,6 +503,9 @@ class FfiModel with ChangeNotifier {
}
}
}
stateGlobal.resetLastResolutionGroupValues(peerId);
notifyListeners();
}

View File

@@ -12,12 +12,14 @@ class StateGlobal {
bool _maximize = false;
bool grabKeyboard = false;
final RxBool _showTabBar = true.obs;
final RxBool _showResizeEdge = true.obs;
final RxDouble _resizeEdgeSize = RxDouble(kWindowEdgeSize);
final RxDouble _windowBorderWidth = RxDouble(kWindowBorderWidth);
final RxBool showRemoteMenuBar = false.obs;
final RxInt displaysCount = 0.obs;
// Use for desktop -> remote toolbar -> resolution
final Map<String, Map<int, String?>> _lastResolutionGroupValues = {};
int get windowId => _windowId;
bool get fullscreen => _fullscreen;
bool get maximize => _maximize;
@@ -26,6 +28,22 @@ class StateGlobal {
RxDouble get resizeEdgeSize => _resizeEdgeSize;
RxDouble get windowBorderWidth => _windowBorderWidth;
resetLastResolutionGroupValues(String peerId) {
_lastResolutionGroupValues[peerId] = {};
}
setLastResolutionGroupValue(
String peerId, int currentDisplay, String? value) {
if (!_lastResolutionGroupValues.containsKey(peerId)) {
_lastResolutionGroupValues[peerId] = {};
}
_lastResolutionGroupValues[peerId]![currentDisplay] = value;
}
String? getLastResolutionGroupValue(String peerId, int currentDisplay) {
return _lastResolutionGroupValues[peerId]?[currentDisplay];
}
setWindowId(int id) => _windowId = id;
setMaximize(bool v) {
if (_maximize != v && !_fullscreen) {
@@ -33,12 +51,12 @@ class StateGlobal {
_resizeEdgeSize.value = _maximize ? kMaximizeEdgeSize : kWindowEdgeSize;
}
}
setFullscreen(bool v) {
if (_fullscreen != v) {
_fullscreen = v;
_showTabBar.value = !_fullscreen;
_resizeEdgeSize.value =
fullscreen
_resizeEdgeSize.value = fullscreen
? kFullScreenEdgeSize
: _maximize
? kMaximizeEdgeSize