flutter_desktop: fix resize scale && Pin peer menu bar

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-09-13 06:59:06 -07:00
parent ae570acd03
commit a075385a11
25 changed files with 146 additions and 116 deletions

View File

@@ -330,18 +330,6 @@ class _DesktopHomePageState extends State<DesktopHomePage>
onHover: (value) => refreshHover.value = value,
),
const _PasswordPopupMenu(),
// FutureBuilder<Widget>(
// future: buildPasswordPopupMenu(context),
// builder: (context, snapshot) {
// if (snapshot.hasError) {
// print("${snapshot.error}");
// }
// if (snapshot.hasData) {
// return snapshot.data!;
// } else {
// return Offstage();
// }
// })
],
),
],
@@ -353,92 +341,6 @@ class _DesktopHomePageState extends State<DesktopHomePage>
);
}
Future<Widget> buildPasswordPopupMenu(BuildContext context) async {
var position;
RxBool editHover = false.obs;
return InkWell(
onTapDown: (detail) {
final x = detail.globalPosition.dx;
final y = detail.globalPosition.dy;
position = RelativeRect.fromLTRB(x, y, x, y);
},
onTap: () async {
var method = (String text, String value) => PopupMenuItem(
child: Row(
children: [
Offstage(
offstage: gFFI.serverModel.verificationMethod != value,
child: Icon(Icons.check)),
Text(
text,
),
],
),
onTap: () => gFFI.serverModel.setVerificationMethod(value),
);
final temporary_enabled =
gFFI.serverModel.verificationMethod != kUsePermanentPassword;
var menu = <PopupMenuEntry>[
method(translate("Use temporary password"), kUseTemporaryPassword),
method(translate("Use permanent password"), kUsePermanentPassword),
method(translate("Use both passwords"), kUseBothPasswords),
PopupMenuDivider(),
PopupMenuItem(
child: Text(translate("Set permanent password")),
value: 'set-permanent-password',
enabled: gFFI.serverModel.verificationMethod !=
kUseTemporaryPassword),
PopupMenuItem(
child: PopupMenuButton(
padding: EdgeInsets.zero,
child: Text(
translate("Set temporary password length"),
),
itemBuilder: (context) => ["6", "8", "10"]
.map((e) => PopupMenuItem(
child: Row(
children: [
Offstage(
offstage: gFFI.serverModel
.temporaryPasswordLength !=
e,
child: Icon(Icons.check)),
Text(
e,
),
],
),
onTap: () {
if (gFFI.serverModel.temporaryPasswordLength !=
e) {
() async {
await gFFI.serverModel
.setTemporaryPasswordLength(e);
await bind.mainUpdateTemporaryPassword();
}();
}
},
))
.toList(),
enabled: temporary_enabled,
),
enabled: temporary_enabled),
];
final v =
await showMenu(context: context, position: position, items: menu);
if (v == "set-permanent-password") {
setPasswordDialog();
}
},
onHover: (value) => editHover.value = value,
child: Obx(() => Icon(Icons.edit,
size: 22,
color: editHover.value
? MyTheme.color(context).text
: Color(0xFFDDDDDD))
.marginOnly(bottom: 2)));
}
buildTip(BuildContext context) {
return Padding(
padding:
@@ -469,7 +371,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
@override
void onTrayMenuItemClick(MenuItem menuItem) {
print("click ${menuItem.key}");
print('click ${menuItem.key}');
switch (menuItem.key) {
case "quit":
exit(0);

View File

@@ -50,6 +50,8 @@ class _RemotePageState extends State<RemotePage>
var _isPhysicalMouse = false;
var _imageFocused = false;
final _onEnterOrLeaveImage = <Function(bool)>[];
late FFI _ffi;
void _updateTabBarHeight() {
@@ -421,11 +423,17 @@ class _RemotePageState extends State<RemotePage>
_physicalFocusNode.requestFocus();
}
_cursorOverImage.value = true;
for (var f in _onEnterOrLeaveImage) {
f(true);
}
_ffi.enterOrLeave(true);
}
void leaveView(PointerExitEvent evt) {
_cursorOverImage.value = false;
for (var f in _onEnterOrLeaveImage) {
f(false);
}
_ffi.enterOrLeave(false);
}
@@ -469,6 +477,7 @@ class _RemotePageState extends State<RemotePage>
paints.add(RemoteMenubar(
id: widget.id,
ffi: _ffi,
onEnterOrLeaveImage: _onEnterOrLeaveImage,
));
return Stack(
children: paints,
@@ -597,8 +606,8 @@ class ImagePaint extends StatelessWidget {
return FlutterCustomMemoryImageCursor(
pixbuf: cacheLinux.data,
key: key,
hotx: 0.0,
hoty: 0.0,
hotx: cacheLinux.hotx,
hoty: cacheLinux.hoty,
imageWidth: (cacheLinux.width * scale).toInt(),
imageHeight: (cacheLinux.height * scale).toInt(),
);

View File

@@ -25,11 +25,13 @@ class _MenubarTheme {
class RemoteMenubar extends StatefulWidget {
final String id;
final FFI ffi;
final List<Function(bool)> onEnterOrLeaveImage;
const RemoteMenubar({
Key? key,
required this.id,
required this.ffi,
required this.onEnterOrLeaveImage,
}) : super(key: key);
@override
@@ -39,12 +41,38 @@ class RemoteMenubar extends StatefulWidget {
class _RemoteMenubarState extends State<RemoteMenubar> {
final RxBool _show = false.obs;
final Rx<Color> _hideColor = Colors.white12.obs;
final _rxHideReplay = rxdart.ReplaySubject<int>();
final _pinMenubar = false.obs;
bool _isCursorOverImage = false;
bool get isFullscreen => Get.find<RxBool>(tag: 'fullscreen').isTrue;
void setFullscreen(bool v) {
void _setFullscreen(bool v) {
Get.find<RxBool>(tag: 'fullscreen').value = v;
}
@override
void initState() {
super.initState();
widget.onEnterOrLeaveImage.add((enter) {
if (enter) {
_rxHideReplay.add(0);
_isCursorOverImage = true;
} else {
_isCursorOverImage = false;
}
});
_rxHideReplay
.throttleTime(const Duration(milliseconds: 5000),
trailing: true, leading: false)
.listen((int v) {
if (_pinMenubar.isFalse && _show.isTrue && _isCursorOverImage) {
_show.value = false;
}
});
}
@override
Widget build(BuildContext context) {
return Align(
@@ -76,6 +104,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
Widget _buildMenubar(BuildContext context) {
final List<Widget> menubarItems = [];
if (!isWebDesktop) {
menubarItems.add(_buildPinMenubar(context));
menubarItems.add(_buildFullscreen(context));
if (widget.ffi.ffiModel.isPeerAndroid) {
menubarItems.add(IconButton(
@@ -111,11 +140,24 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
]));
}
Widget _buildPinMenubar(BuildContext context) {
return IconButton(
tooltip: translate('Pin menubar'),
onPressed: () {
_pinMenubar.value = !_pinMenubar.value;
},
icon: Obx(() => Icon(
Icons.push_pin,
color: _pinMenubar.isTrue ? _MenubarTheme.commonColor : Colors.grey,
)),
);
}
Widget _buildFullscreen(BuildContext context) {
return IconButton(
tooltip: translate(isFullscreen ? 'Exit Fullscreen' : 'Fullscreen'),
onPressed: () {
setFullscreen(!isFullscreen);
_setFullscreen(!isFullscreen);
},
icon: Obx(() => isFullscreen
? const Icon(
@@ -250,7 +292,6 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
),
tooltip: translate('Display Settings'),
position: mod_menu.PopupMenuPosition.under,
onSelected: (String item) {},
itemBuilder: (BuildContext context) => _getDisplayMenu()
.map((entry) => entry.build(
context,
@@ -273,7 +314,6 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
),
tooltip: translate('Keyboard Settings'),
position: mod_menu.PopupMenuPosition.under,
onSelected: (String item) {},
itemBuilder: (BuildContext context) => _getKeyboardMenu()
.map((entry) => entry.build(
context,