Merge pull request #142 from vlsi/mac_meta_key

use META (cmd) key instead of CTRL for macOS
This commit is contained in:
Deathmarine 2019-04-15 08:58:06 -04:00 committed by GitHub
commit f1ccf991d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -10,9 +10,6 @@ import com.apple.eawt.ApplicationEvent;
*/ */
public class LuytenOsx extends Luyten { public class LuytenOsx extends Luyten {
public static void main(String[] args) { 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 // Add an adapter as the handler to a new instance of the application
// class // class
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

View File

@ -249,7 +249,7 @@ public class MainMenuBar extends JMenuBar {
// Only add the exit command for non-OS X. OS X handles its close // Only add the exit command for non-OS X. OS X handles its close
// automatically // automatically
if (!("true".equals(System.getProperty("us.deathmarine.luyten.Luyten.running_in_osx")))) { if (!Boolean.getBoolean("apple.laf.useScreenMenuBar")) {
menuItem = new JMenuItem("Exit"); menuItem = new JMenuItem("Exit");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK)); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
menuItem.addActionListener(new ActionListener() { menuItem.addActionListener(new ActionListener() {

View File

@ -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().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sfuncF4, "CloseTab");
mainWindow.getRootPane().getActionMap().put("CloseTab", new AbstractAction() { mainWindow.getRootPane().getActionMap().put("CloseTab", new AbstractAction() {

View File

@ -193,7 +193,7 @@ public class OpenFile implements SyntaxConstants {
} }
textArea.setHyperlinksEnabled(true); textArea.setHyperlinksEnabled(true);
textArea.setLinkScanningMask(InputEvent.CTRL_DOWN_MASK); textArea.setLinkScanningMask(Keymap.ctrlDownModifier());
textArea.setLinkGenerator(new LinkGenerator() { textArea.setLinkGenerator(new LinkGenerator() {
@Override @Override
@ -240,7 +240,7 @@ public class OpenFile implements SyntaxConstants {
return; return;
} }
if ((e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0) { if ((e.getModifiersEx() & Keymap.ctrlDownModifier()) != 0) {
Font font = textArea.getFont(); Font font = textArea.getFont();
int size = font.getSize(); int size = font.getSize();
if (e.getWheelRotation() > 0) { if (e.getWheelRotation() > 0) {
@ -410,7 +410,7 @@ public class OpenFile implements SyntaxConstants {
public synchronized void mouseMoved(MouseEvent e) { public synchronized void mouseMoved(MouseEvent e) {
String linkText = null; String linkText = null;
boolean isLinkLabel = false; boolean isLinkLabel = false;
boolean isCtrlDown = (e.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) != 0; boolean isCtrlDown = (e.getModifiersEx() & Keymap.ctrlDownModifier()) != 0;
if (isCtrlDown) { if (isCtrlDown) {
linkText = createLinkLabel(e); linkText = createLinkLabel(e);
isLinkLabel = linkText != null; isLinkLabel = linkText != null;

View File

@ -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");
}