Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Fix Alt+Tab menu latch/focus issue on Windows

AuthorDaveJarvis <email>
Date2023-01-26 01:05:19 GMT-0800
Commite7089a78ff65956a1c7010b0e99b96e8ed2de1a2
Parent90f1c30
Delta6 lines added, 12 lines removed, 6-line decrease
src/main/java/com/keenwrite/MainApp.java
import static com.keenwrite.preferences.AppKeys.*;
import static com.keenwrite.util.FontLoader.initFonts;
-import static javafx.scene.input.KeyCode.ALT;
+import static javafx.scene.input.KeyCode.ESCAPE;
import static javafx.scene.input.KeyCode.F11;
import static javafx.scene.input.KeyEvent.KEY_PRESSED;
// After the app loses focus, when the user switches back using Alt+Tab,
- // the menu mnemonic is sometimes engaged, swallowing the first letter that
- // the user types---if it is a menu mnemonic. See MainScene::createScene().
+ // the menu is engaged on Windows. Simulate an ESC keypress to the menu
+ // to disable the menu, giving focus back to the application proper.
//
// JavaFX Bug: https://bugs.openjdk.java.net/browse/JDK-8090647
- stage.focusedProperty().addListener( ( c, lost, show ) -> {
- for( final var menu : mMainScene.getMenuBar().getMenus() ) {
- menu.hide();
- }
-
- for( final var mnemonics : stage.getScene().getMnemonics().values() ) {
- for( final var mnemonic : mnemonics ) {
- mnemonic.getNode().fireEvent( keyUp( ALT ) );
- }
+ stage.focusedProperty().addListener( ( c, lost, found ) -> {
+ if( found ) {
+ mMainScene.getMenuBar().fireEvent( keyDown( ESCAPE, false ) );
}
} );