From 1f4eb6db3eeae98980d64eacde62a81e431845b9 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Wed, 25 May 2016 16:52:54 +0300 Subject: [PATCH] IDEA-144702 Unable to use Windows as a modifier key in keymap (registry key keymap.windows.as.meta=true by default) --- .../src/com/intellij/ide/IdeEventQueue.java | 36 +++++++++++++++++++ .../util/resources/misc/registry.properties | 1 + 2 files changed, 37 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index aa75d5ffc1b7..1fce159d8d2b 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -138,6 +138,7 @@ public class IdeEventQueue extends EventQueue { private boolean myKeyboardBusy; private boolean myDispatchingFocusEvent; + private boolean myWinMetaPressed; private int myInputMethodLock; @@ -370,6 +371,9 @@ public class IdeEventQueue extends EventQueue { e = fixNonEnglishKeyboardLayouts(e); e = mapEvent(e); + if (Registry.is("keymap.windows.as.meta")) { + e = mapMetaState(e); + } boolean wasInputEvent = myIsInInputEvent; myIsInInputEvent = e instanceof InputEvent || e instanceof InputMethodEvent || e instanceof WindowEvent || e instanceof ActionEvent; @@ -530,6 +534,38 @@ public class IdeEventQueue extends EventQueue { return e; } + private AWTEvent mapMetaState(AWTEvent e) { + if (myWinMetaPressed) { + Application app = ApplicationManager.getApplication(); + if (app == null || !app.isActive()) { + myWinMetaPressed = false; + return e; + } + } + + if (e instanceof KeyEvent) { + KeyEvent ke = (KeyEvent)e; + if (ke.getKeyCode() == KeyEvent.VK_WINDOWS) { + if (ke.getID() == KeyEvent.KEY_PRESSED) myWinMetaPressed = true; + if (ke.getID() == KeyEvent.KEY_RELEASED) myWinMetaPressed = false; + return new KeyEvent(ke.getComponent(), ke.getID(), ke.getWhen(), ke.getModifiers(), KeyEvent.VK_META, ke.getKeyChar(), + ke.getKeyLocation()); + } + if (myWinMetaPressed) { + return new KeyEvent(ke.getComponent(), ke.getID(), ke.getWhen(), ke.getModifiers() | InputEvent.META_MASK, ke.getKeyCode(), + ke.getKeyChar(), ke.getKeyLocation()); + } + } + + if (myWinMetaPressed && e instanceof MouseEvent && ((MouseEvent)e).getButton() != 0) { + MouseEvent me = (MouseEvent)e; + return new MouseEvent(me.getComponent(), me.getID(), me.getWhen(), me.getModifiers() | InputEvent.META_MASK, me.getX(), me.getY(), + me.getClickCount(), me.isPopupTrigger(), me.getButton()); + } + + return e; + } + public void _dispatchEvent(@NotNull AWTEvent e, boolean typeAheadFlushing) { if (e.getID() == MouseEvent.MOUSE_DRAGGED) { DnDManagerImpl dndManager = (DnDManagerImpl)DnDManager.getInstance(); diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 3ee1f67a4f1c..5fa42afbeba4 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -280,6 +280,7 @@ find.search.in.project.files=true structureView.coalesceTime=500 keymap.show.alias.actions=false +keymap.windows.as.meta=true frameworks.download.libraries.server.url=http://pluginsrepo-test:8080 caches.indexerThreadsCount=-1 navBar.updateMergeTime=100