remove custom resolution

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-05-18 23:45:38 +08:00
parent c4cefdb54b
commit d339fd178b

View File

@ -29,10 +29,6 @@ const _kKeyLegacyMode = 'legacy';
const _kKeyMapMode = 'map'; const _kKeyMapMode = 'map';
const _kKeyTranslateMode = 'translate'; const _kKeyTranslateMode = 'translate';
const _kResolutionOrigin = 'Origin';
const _kResolutionCustom = 'Custom';
const _kResolutionFitLocal = 'FitLocal';
class MenubarState { class MenubarState {
final kStoreKey = 'remoteMenubarState'; final kStoreKey = 'remoteMenubarState';
late RxBool show; late RxBool show;
@ -1002,10 +998,6 @@ class _ResolutionsMenu extends StatefulWidget {
class _ResolutionsMenuState extends State<_ResolutionsMenu> { class _ResolutionsMenuState extends State<_ResolutionsMenu> {
String _groupValue = ''; String _groupValue = '';
Resolution? _localResolution; Resolution? _localResolution;
late final _customWidth =
TextEditingController(text: display.width.toString());
late final _customHeight =
TextEditingController(text: display.height.toString());
PeerInfo get pi => widget.ffi.ffiModel.pi; PeerInfo get pi => widget.ffi.ffiModel.pi;
FfiModel get ffiModel => widget.ffi.ffiModel; FfiModel get ffiModel => widget.ffi.ffiModel;
@ -1020,8 +1012,9 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isVirtualDisplay = display.isVirtualDisplayResolution; final isVirtualDisplay = display.isVirtualDisplayResolution;
final visible = // final visible =
ffiModel.keyboard && (isVirtualDisplay || resolutions.length > 1); // ffiModel.keyboard && (isVirtualDisplay || resolutions.length > 1);
final visible = ffiModel.keyboard && resolutions.length > 1;
if (!visible) return Offstage(); if (!visible) return Offstage();
_groupValue = '${display.width}x${display.height}'; _groupValue = '${display.width}x${display.height}';
_getLocalResolution(); _getLocalResolution();
@ -1034,12 +1027,22 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
menuChildren: <Widget>[ menuChildren: <Widget>[
_OriginalResolutionMenuButton(showOriginalBtn), _OriginalResolutionMenuButton(showOriginalBtn),
_FitLocalResolutionMenuButton(showFitLocalBtn), _FitLocalResolutionMenuButton(showFitLocalBtn),
_customResolutionMenuButton(isVirtualDisplay), // _customResolutionMenuButton(isVirtualDisplay),
_menuDivider(showOriginalBtn, showFitLocalBtn, isVirtualDisplay),
] + ] +
_supportedResolutionMenuButtons(), _supportedResolutionMenuButtons(),
child: Text(translate("Resolution"))); child: Text(translate("Resolution")));
} }
_menuDivider(
bool showOriginalBtn, bool showFitLocalBtn, bool isVirtualDisplay) {
return Offstage(
// offstage: !(showOriginalBtn || showFitLocalBtn || isVirtualDisplay),
offstage: !(showOriginalBtn || showFitLocalBtn),
child: Divider(),
);
}
_getLocalResolution() { _getLocalResolution() {
_localResolution = null; _localResolution = null;
final String currentDisplay = bind.mainGetCurrentDisplay(); final String currentDisplay = bind.mainGetCurrentDisplay();
@ -1057,53 +1060,38 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
_onChanged(String? value) async { _onChanged(String? value) async {
if (value == null) return; if (value == null) return;
final list = value.split('x');
int? w; if (list.length == 2) {
int? h; final w = int.tryParse(list[0]);
if (value == _kResolutionOrigin) { final h = int.tryParse(list[1]);
w = display.originalWidth; if (w != null && h != null) {
h = display.originalHeight; await _changeResolution(w, h);
} else if (value == _kResolutionFitLocal) {
final resolution = _getBestFitResolution();
if (resolution != null) {
w = resolution.width;
h = resolution.height;
}
} else if (value == _kResolutionCustom) {
w = int.tryParse(_customWidth.value as String);
h = int.tryParse(_customHeight.value as String);
} else {
final list = value.split('x');
if (list.length == 2) {
w = int.tryParse(list[0]);
h = int.tryParse(list[1]);
} }
} }
}
if (w != null && h != null) { _changeResolution(int w, int h) async {
await bind.sessionChangeResolution( await bind.sessionChangeResolution(
id: widget.id, id: widget.id,
width: w, width: w,
height: h, height: h,
); );
Future.delayed(Duration(seconds: 3), () async { Future.delayed(Duration(seconds: 3), () async {
final display = ffiModel.display; final display = ffiModel.display;
if (w == display.width && h == display.height) { if (w == display.width && h == display.height) {
if (await widget.screenAdjustor.isWindowCanBeAdjusted()) { if (await widget.screenAdjustor.isWindowCanBeAdjusted()) {
widget.screenAdjustor.doAdjustWindow(); widget.screenAdjustor.doAdjustWindow();
}
} }
}); }
} });
} }
Widget _OriginalResolutionMenuButton(bool showOriginalBtn) { Widget _OriginalResolutionMenuButton(bool showOriginalBtn) {
return Offstage( return Offstage(
offstage: !showOriginalBtn, offstage: !showOriginalBtn,
child: RdoMenuButton( child: MenuButton(
value: _kResolutionOrigin, onPressed: () =>
groupValue: _groupValue, _changeResolution(display.originalWidth, display.originalHeight),
onChanged: _onChanged,
ffi: widget.ffi, ffi: widget.ffi,
child: Text( child: Text(
'${translate('Original')} ${display.originalWidth}x${display.originalHeight}'), '${translate('Original')} ${display.originalWidth}x${display.originalHeight}'),
@ -1114,10 +1102,13 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
Widget _FitLocalResolutionMenuButton(bool showFitLocalBtn) { Widget _FitLocalResolutionMenuButton(bool showFitLocalBtn) {
return Offstage( return Offstage(
offstage: !showFitLocalBtn, offstage: !showFitLocalBtn,
child: RdoMenuButton( child: MenuButton(
value: _kResolutionFitLocal, onPressed: () {
groupValue: _groupValue, final resolution = _getBestFitResolution();
onChanged: _onChanged, if (resolution != null) {
_changeResolution(resolution.width, resolution.height);
}
},
ffi: widget.ffi, ffi: widget.ffi,
child: Text( child: Text(
'${translate('Fit Local')} ${_localResolution?.width ?? 0}x${_localResolution?.height ?? 0}'), '${translate('Fit Local')} ${_localResolution?.width ?? 0}x${_localResolution?.height ?? 0}'),
@ -1137,50 +1128,61 @@ class _ResolutionsMenuState extends State<_ResolutionsMenu> {
Widget _customResolutionMenuButton(bool showCustomBtn) { Widget _customResolutionMenuButton(bool showCustomBtn) {
return Offstage( return Offstage(
offstage: !showCustomBtn, offstage: !showCustomBtn,
child: RdoMenuButton( child: MenuButton(
value: _kResolutionCustom, onPressed: () => _customResolutionDialog(),
groupValue: _groupValue,
onChanged: _onChanged,
ffi: widget.ffi, ffi: widget.ffi,
child: _customResolutionWidget(), child:
Text('${translate('Custom')} ${display.width}x${display.height}'),
), ),
); );
} }
Widget _customResolutionWidget() { _customResolutionDialog() async {
return Column( OverlayDialogManager dialogManager = widget.ffi.dialogManager;
children: [ dialogManager.dismissAll();
Text(translate('Custom')), dialogManager.show((setState, close, context) {
Container( cancel() {
width: 5, close();
), }
// _resolutionInput(_customWidth),
Container(
width: 3,
),
Text('x'),
Container(
width: 3,
),
// _resolutionInput(_customHeight),
],
);
}
TextField _resolutionInput(TextEditingController controller) { return CustomAlertDialog(
return TextField( title: Row(
decoration: InputDecoration( mainAxisAlignment: MainAxisAlignment.center,
border: InputBorder.none, children: [
isDense: true, Icon(Icons.password_rounded, color: MyTheme.accent),
), Text(translate('Custom width x height')).paddingOnly(left: 10),
keyboardType: TextInputType.number, ],
inputFormatters: <TextInputFormatter>[ ),
FilteringTextInputFormatter.digitsOnly, content: Column(
LengthLimitingTextInputFormatter(4), mainAxisSize: MainAxisSize.min,
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), children: [
], Slider(
controller: controller, value: display.width.toDouble(),
); min: 256,
max: 8192,
divisions: 1,
onChanged: (double value) {},
),
Slider(
value: display.height.toDouble(),
min: 256,
max: 8192,
divisions: 1,
onChanged: (double value) {},
),
],
),
actions: [
dialogButton(
'Cancel',
icon: Icon(Icons.close_rounded),
onPressed: cancel,
isOutline: true,
),
],
onCancel: cancel,
);
});
} }
Resolution? _getBestFitResolution() { Resolution? _getBestFitResolution() {