Files
imajviewer/lib/shortcuts/app_shortcuts.dart
T
Alhan 6e13892ed1
Build & Release / build-linux (push) Has been cancelled
Build & Release / build-windows (push) Has been cancelled
Build & Release / create-release (push) Has been cancelled
fix: Ctrl+R flip also matches the physical R key (v1.6.1)
On some keymaps the R key resolves to a different logical key (observed on a
Turkish remote-desktop setup: the R key arrives as logical T), so the Ctrl+R
shortcut never fired even though the key events reached the app. The shortcut
now matches PhysicalKeyboardKey.keyR as well; a regression test covers the
wrong-layout case.
2026-10-14 03:33:16 +03:00

94 lines
2.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:window_manager/window_manager.dart';
import '../services/image_manager.dart';
import '../services/file_handler.dart';
class AppShortcuts extends StatelessWidget {
final Widget child;
final VoidCallback? onCropSave;
final VoidCallback? onFlipH;
const AppShortcuts({
super.key,
required this.child,
this.onCropSave,
this.onFlipH,
});
@override
Widget build(BuildContext context) {
return Focus(
autofocus: true,
onKeyEvent: (node, event) {
if (event is KeyDownEvent) {
final ctrl = HardwareKeyboard.instance.isControlPressed;
final shift = HardwareKeyboard.instance.isShiftPressed;
// Ctrl+Shift+Q: tüm pencereleri kapat
if (ctrl && shift && event.logicalKey == LogicalKeyboardKey.keyQ) {
if (Platform.isWindows) {
Process.runSync('taskkill', ['/F', '/IM', 'imajviewer.exe']);
} else {
Process.runSync('pkill', ['imajviewer']);
}
return KeyEventResult.handled;
}
// Ctrl+Q: bu pencereyi kapat
if (ctrl && event.logicalKey == LogicalKeyboardKey.keyQ) {
windowManager.close();
return KeyEventResult.handled;
}
// Ctrl+S: görünen alanı kaydet (crop save)
if (ctrl && !shift && event.logicalKey == LogicalKeyboardKey.keyS) {
if (onCropSave != null) {
onCropSave!();
return KeyEventResult.handled;
}
}
// Ctrl+R: yatay aynala / geri al (fiziksel R: bazi klavye haritalarinda
// mantiksal tus T gibi farkli cozuluyor)
if (ctrl &&
(event.logicalKey == LogicalKeyboardKey.keyR ||
event.physicalKey == PhysicalKeyboardKey.keyR)) {
if (onFlipH != null) {
onFlipH!();
return KeyEventResult.handled;
}
}
switch (event.logicalKey) {
case LogicalKeyboardKey.arrowLeft:
ImageManager.instance.previousImage();
return KeyEventResult.handled;
case LogicalKeyboardKey.arrowRight:
ImageManager.instance.nextImage();
return KeyEventResult.handled;
case LogicalKeyboardKey.escape:
windowManager.isFullScreen().then((isFullscreen) {
if (isFullscreen) windowManager.setFullScreen(false);
});
return KeyEventResult.handled;
}
}
return KeyEventResult.ignored;
},
child: CallbackShortcuts(
bindings: {
const SingleActivator(
LogicalKeyboardKey.keyO,
control: true,
): () {
FileHandler.openFileDialog();
},
},
child: child,
),
);
}
}