From 7f1d9012e94d3ce59716b103987dd60f11c971ad Mon Sep 17 00:00:00 2001 From: "J. Neugebauer" Date: Mon, 1 Aug 2022 20:50:16 +0200 Subject: [PATCH] Unter macOS auf Cmd+Q reagieren --- .../java/schule/ngb/zm/Zeichenmaschine.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/schule/ngb/zm/Zeichenmaschine.java b/src/main/java/schule/ngb/zm/Zeichenmaschine.java index 69d0cb3..cf5059a 100644 --- a/src/main/java/schule/ngb/zm/Zeichenmaschine.java +++ b/src/main/java/schule/ngb/zm/Zeichenmaschine.java @@ -242,6 +242,11 @@ public class Zeichenmaschine extends Constants { public Zeichenmaschine( int width, int height, String title, boolean run_once ) { LOG.info("Starting " + APP_NAME + " " + APP_VERSION); + // Register Cmd+Q on macOS + if( Constants.MACOS ) { + System.setProperty("apple.eawt.quitStrategy", "CLOSE_ALL_WINDOWS"); + } + // Erstellen der Leinwand canvas = new Zeichenleinwand(width, height); @@ -533,9 +538,7 @@ public class Zeichenmaschine extends Constants { running = false; terminateImediately = true; quitAfterShutdown = true; - if( state != Options.AppState.QUITING ) { - mainThread.interrupt(); - } + mainThread.interrupt(); } else { quit(true); } @@ -570,13 +573,15 @@ public class Zeichenmaschine extends Constants { */ public final void quit( boolean exit ) { state = Options.AppState.QUITING; - frame.setVisible(false); - canvas.dispose(); - frame.dispose(); + TaskRunner.invokeLater(() -> { + frame.setVisible(false); + canvas.dispose(); + frame.dispose(); - if( exit ) { - System.exit(0); - } + if( exit ) { + System.exit(0); + } + }); } /**