debug: added command line param to disable full screen mode on mac os (-Dxmage.fullScreen=false - useless);

This commit is contained in:
Oleg Agafonov 2024-06-23 15:51:40 +04:00
parent 55e8cac66a
commit f78177a540
2 changed files with 21 additions and 19 deletions

View file

@ -88,7 +88,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
private static final Logger LOGGER = Logger.getLogger(MageFrame.class); private static final Logger LOGGER = Logger.getLogger(MageFrame.class);
private static final String LITE_MODE_ARG = "-lite"; private static final String LITE_MODE_ARG = "-lite";
private static final String GRAY_MODE_ARG = "-gray"; private static final String GRAY_MODE_ARG = "-gray";
private static final String FILL_SCREEN_ARG = "-fullscreen"; private static final String FULL_SCREEN_PROP = "xmage.fullScreen"; // -Dxmage.fullScreen=false
private static final String SKIP_DONE_SYMBOLS = "-skipDoneSymbols"; private static final String SKIP_DONE_SYMBOLS = "-skipDoneSymbols";
private static final String USER_ARG = "-user"; private static final String USER_ARG = "-user";
private static final String PASSWORD_ARG = "-pw"; private static final String PASSWORD_ARG = "-pw";
@ -113,7 +113,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
private static boolean liteMode = false; private static boolean liteMode = false;
//TODO: make gray theme, implement theme selector in preferences dialog //TODO: make gray theme, implement theme selector in preferences dialog
private static boolean grayMode = false; private static boolean grayMode = false;
private static boolean fullscreenMode = false; private static boolean macOsFullScreenEnabled = true;
private static boolean skipSmallSymbolGenerationForExisting = false; private static boolean skipSmallSymbolGenerationForExisting = false;
private static String startUser = null; private static String startUser = null;
private static String startPassword = ""; private static String startPassword = "";
@ -203,6 +203,12 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
setWindowTitle(); setWindowTitle();
// mac os only: enable full screen support in java 8 (java 11+ try to use it all the time)
if (MacFullscreenUtil.isMacOSX() && macOsFullScreenEnabled) {
MacFullscreenUtil.enableMacOSFullScreenMode(this);
MacFullscreenUtil.toggleMacOSFullScreenMode(this);
}
EDTExceptionHandler.registerExceptionHandler(); EDTExceptionHandler.registerExceptionHandler();
addWindowListener(new WindowAdapter() { addWindowListener(new WindowAdapter() {
@Override @Override
@ -387,13 +393,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
setWindowTitle(); setWindowTitle();
}); });
if (MacFullscreenUtil.isMacOSX()) {
MacFullscreenUtil.enableMacOSFullScreenMode(this);
if (fullscreenMode) {
MacFullscreenUtil.toggleMacOSFullScreenMode(this);
}
}
} }
private void bootstrapSetsAndFormats() { private void bootstrapSetsAndFormats() {
@ -1423,8 +1422,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
if (arg.startsWith(GRAY_MODE_ARG)) { if (arg.startsWith(GRAY_MODE_ARG)) {
grayMode = true; grayMode = true;
} }
if (arg.startsWith(FILL_SCREEN_ARG)) { if (System.getProperty(FULL_SCREEN_PROP) != null) {
fullscreenMode = true; macOsFullScreenEnabled = Boolean.parseBoolean(System.getProperty(FULL_SCREEN_PROP));
} }
if (arg.startsWith(SKIP_DONE_SYMBOLS)) { if (arg.startsWith(SKIP_DONE_SYMBOLS)) {
skipSmallSymbolGenerationForExisting = true; skipSmallSymbolGenerationForExisting = true;

View file

@ -1,17 +1,22 @@
package mage.client.util; package mage.client.util;
import org.apache.log4j.Logger;
import java.awt.*; import java.awt.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
/** /**
* @author noxx * @author noxx, JayDi85
*/ */
public final class MacFullscreenUtil { public final class MacFullscreenUtil {
public static final String OS_NAME = "os.name"; public static final String OS_NAME = "os.name";
public static final String MAC_OS_X = "Mac OS X"; public static final String MAC_OS_X = "Mac OS X";
private MacFullscreenUtil() {} private static final Logger logger = Logger.getLogger(MacFullscreenUtil.class);
private MacFullscreenUtil() {
}
public static boolean isMacOSX() { public static boolean isMacOSX() {
return System.getProperty(OS_NAME).contains(MAC_OS_X); return System.getProperty(OS_NAME).contains(MAC_OS_X);
@ -26,9 +31,8 @@ public final class MacFullscreenUtil {
Class<?> clazz = Class.forName(className); Class<?> clazz = Class.forName(className);
Method method = clazz.getMethod(methodName, Window.class, boolean.class); Method method = clazz.getMethod(methodName, Window.class, boolean.class);
method.invoke(null, window, true); method.invoke(null, window, true);
} catch (Throwable t) { } catch (Throwable e) {
System.err.println("Full screen mode is not supported"); logger.error("Can't enable full screen support in Mac OS - " + e, e);
t.printStackTrace();
} }
} else { } else {
// Nothing needed. Running with Java 11+ (even when compiled for 1.8) automatically allows for full screen toggling. // Nothing needed. Running with Java 11+ (even when compiled for 1.8) automatically allows for full screen toggling.
@ -49,9 +53,8 @@ public final class MacFullscreenUtil {
Class[] params = new Class[]{Window.class}; Class[] params = new Class[]{Window.class};
method = clazz.getMethod(methodName2, params); method = clazz.getMethod(methodName2, params);
method.invoke(appInstance, window); method.invoke(appInstance, window);
} catch (Throwable t) { } catch (Throwable e) {
System.err.println("Full screen mode is not supported"); logger.error("Can't toggle full screen in Mac OS - " + e, e);
t.printStackTrace();
} }
} else { } else {
// TODO: Need a solution for automatically entering fullscreen under Java 11+ // TODO: Need a solution for automatically entering fullscreen under Java 11+