diff --git a/src/us/deathmarine/luyten/Keymap.java b/src/us/deathmarine/luyten/Keymap.java new file mode 100644 index 0000000000000000000000000000000000000000..c84f26ba1aeee7b006d14f98fba11785e8b9fbf6 --- /dev/null +++ b/src/us/deathmarine/luyten/Keymap.java @@ -0,0 +1,14 @@ +package us.deathmarine.luyten; + +import java.awt.event.InputEvent; + +public final class Keymap { + /** + * Ctrl+click defaults to "context menu" in macOS, so META+click is used there. + * + * @return META_DOWN_MASK for macOS, CTRL_DOWN_MASK otherwise + */ + public static int ctrlDownModifier() { + return SystemInfo.IS_MAC ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK; + } +} diff --git a/src/us/deathmarine/luyten/LuytenOsx.java b/src/us/deathmarine/luyten/LuytenOsx.java index c848b3b15c654f40c396a7ed873ad36ec1a6c9e1..46670ae1ff60ab9a3b0b71fa11a398479f220736 100644 --- a/src/us/deathmarine/luyten/LuytenOsx.java +++ b/src/us/deathmarine/luyten/LuytenOsx.java @@ -10,9 +10,6 @@ import com.apple.eawt.ApplicationEvent; */ public class LuytenOsx extends Luyten { public static void main(String[] args) { - // Set a flag that says we are running in OS X - System.setProperty("us.deathmarine.luyten.Luyten.running_in_osx", "true"); - // Add an adapter as the handler to a new instance of the application // class @SuppressWarnings("deprecation") diff --git a/src/us/deathmarine/luyten/MainMenuBar.java b/src/us/deathmarine/luyten/MainMenuBar.java index 8aef20351657d4ad7fd58965bb2c061d13961039..0faed432e669bdd61ef7076a04c188441a6cb9ae 100644 --- a/src/us/deathmarine/luyten/MainMenuBar.java +++ b/src/us/deathmarine/luyten/MainMenuBar.java @@ -249,7 +249,7 @@ public class MainMenuBar extends JMenuBar { // Only add the exit command for non-OS X. OS X handles its close // automatically - if (!("true".equals(System.getProperty("us.deathmarine.luyten.Luyten.running_in_osx")))) { + if (!Boolean.getBoolean("apple.laf.useScreenMenuBar")) { menuItem = new JMenuItem("Exit"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)); menuItem.addActionListener(new ActionListener() { diff --git a/src/us/deathmarine/luyten/Model.java b/src/us/deathmarine/luyten/Model.java index 83f14a86e398a3b28b4c15f2bb200aae2d3d0e01..777ecd390dae9564041390cd88fdd09712085924 100644 --- a/src/us/deathmarine/luyten/Model.java +++ b/src/us/deathmarine/luyten/Model.java @@ -153,7 +153,7 @@ public class Model extends JSplitPane { } }); - KeyStroke sfuncF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_DOWN_MASK, false); + KeyStroke sfuncF4 = KeyStroke.getKeyStroke(KeyEvent.VK_F4, Keymap.ctrlDownModifier(), false); mainWindow.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sfuncF4, "CloseTab"); mainWindow.getRootPane().getActionMap().put("CloseTab", new AbstractAction() { diff --git a/src/us/deathmarine/luyten/OpenFile.java b/src/us/deathmarine/luyten/OpenFile.java index 4e45782097d6b03818fb0013f80b3c54c790a873..57607e619946db5380c8e8219a0c73c20805305d 100644 --- a/src/us/deathmarine/luyten/OpenFile.java +++ b/src/us/deathmarine/luyten/OpenFile.java @@ -188,7 +188,7 @@ public class OpenFile implements SyntaxConstants { } textArea.setHyperlinksEnabled(true); - textArea.setLinkScanningMask(InputEvent.CTRL_DOWN_MASK); + textArea.setLinkScanningMask(Keymap.ctrlDownModifier()); textArea.setLinkGenerator(new LinkGenerator() { @Override @@ -228,7 +228,7 @@ public class OpenFile implements SyntaxConstants { @Override public void mouseWheelMoved(MouseWheelEvent e) { - if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) { + if ((e.getModifiersEx() & Keymap.ctrlDownModifier()) != 0) { Font font = textArea.getFont(); int size = font.getSize(); if (e.getWheelRotation() > 0) { @@ -398,7 +398,7 @@ public class OpenFile implements SyntaxConstants { public synchronized void mouseMoved(MouseEvent e) { String linkText = null; boolean isLinkLabel = false; - boolean isCtrlDown = (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0; + boolean isCtrlDown = (e.getModifiersEx() & Keymap.ctrlDownModifier()) != 0; if (isCtrlDown) { linkText = createLinkLabel(e); isLinkLabel = linkText != null; diff --git a/src/us/deathmarine/luyten/SystemInfo.java b/src/us/deathmarine/luyten/SystemInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..77722ef381fada42260748676b4fa60250981b23 --- /dev/null +++ b/src/us/deathmarine/luyten/SystemInfo.java @@ -0,0 +1,10 @@ +package us.deathmarine.luyten; + +import java.util.Locale; + +public class SystemInfo { + private static final String OS_NAME = System.getProperty("os.name"); + private static final String OS_NAME_LOWER = OS_NAME.toLowerCase(Locale.US); + + public static boolean IS_MAC = OS_NAME_LOWER.startsWith("mac"); +}