Skip to content

Commit

Permalink
GUI: In Unix map Windows key as D-
Browse files Browse the repository at this point in the history
Neovim now supports the D- modifer, which we already use in Mac OS X
for the Command key. This commit enables a similar behaviour for the
Windows key. Qt represents the Windows key as being the Meta key.

* Internally in input.cpp the key is named Cmd just like on Mac OS.
* Took the chance to remove the Key_Meta mapping since it was not being
  used.
* Added unit test to check if modifier keys are not being handled as
  regular keys.
  • Loading branch information
equalsraf committed Jul 14, 2016
1 parent 5fef216 commit e257faf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/gui/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ InputConv::InputConv() {
QString InputConv::modPrefix(Qt::KeyboardModifiers mod)
{
QString modprefix;
#ifdef Q_OS_MAC
#if defined(Q_OS_MAC) || defined(Q_OS_UNIX)
if ( mod & CmdModifier ) {
modprefix += "D-"; // like MacVim does
}
Expand Down
9 changes: 6 additions & 3 deletions src/gui/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ class InputConv {
const Qt::KeyboardModifiers MetaModifier = Qt::AltModifier;
const Qt::Key Key_Control = Qt::Key_Meta;
const Qt::Key Key_Cmd = Qt::Key_Control;
const Qt::Key Key_Meta = Qt::Key_Alt;
#else
const Qt::KeyboardModifiers ControlModifier = Qt::ControlModifier;
# ifdef Q_OS_UNIX
const Qt::KeyboardModifiers CmdModifier = Qt::MetaModifier;
const Qt::Key Key_Cmd = Qt::Key_Meta;;
# else
const Qt::KeyboardModifiers CmdModifier = (Qt::KeyboardModifiers)0;
const Qt::Key Key_Cmd = (Qt::Key)0;
# endif
const Qt::KeyboardModifiers MetaModifier = Qt::MetaModifier;
const Qt::Key Key_Control = Qt::Key_Control;
const Qt::Key Key_Cmd = (Qt::Key)0;
const Qt::Key Key_Meta = Qt::Key_Meta;
#endif
const Qt::KeyboardModifiers ShiftModifier = Qt::ShiftModifier;
const Qt::KeyboardModifiers AltModifier = Qt::AltModifier;
Expand Down
20 changes: 17 additions & 3 deletions test/tst_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,29 @@ class TestInput: public QObject
Q_OBJECT
private slots:
void specialKeys();
void modifiersAreNotKeys();
private:
NeovimQt::InputConv input;
};

void TestInput::modifiersAreNotKeys()
{
QCOMPARE(input.convertKey("", Qt::Key_Meta, Qt::MetaModifier),
QString());
QCOMPARE(input.convertKey("", Qt::Key_Control, Qt::ControlModifier),
QString());
QCOMPARE(input.convertKey("", Qt::Key_Alt, Qt::AltModifier),
QString());
}

void TestInput::specialKeys()
{
foreach(int k, input.specialKeys.keys()) {
QCOMPARE(input.convertKey("", k, Qt::NoModifier),
QString("<%1>").arg(input.specialKeys.value(k)));

#ifdef Q_OS_MAC
// On Mac Control is actually the Cmd key, which we
// don't support yet
// On Mac Control is actually the Cmd key
QCOMPARE(input.convertKey("", k, Qt::ControlModifier),
QString("<D-%1>").arg(input.specialKeys.value(k)));
#else
Expand All @@ -30,10 +40,14 @@ void TestInput::specialKeys()
QCOMPARE(input.convertKey("", k, Qt::AltModifier),
QString("<A-%1>").arg(input.specialKeys.value(k)));

#ifdef Q_OS_MAC
#if defined(Q_OS_MAC)
QCOMPARE(input.convertKey("", k, Qt::MetaModifier),
// On Mac Meta is actually the Control key
QString("<C-%1>").arg(input.specialKeys.value(k)));
#elif defined(Q_OS_UNIX)
QCOMPARE(input.convertKey("", k, Qt::MetaModifier),
// On UNIX Meta is the Windows key, treated as D-
QString("<D-%1>").arg(input.specialKeys.value(k)));
#else
QCOMPARE(input.convertKey("", k, Qt::MetaModifier),
// Meta is not handled right now
Expand Down

0 comments on commit e257faf

Please sign in to comment.