mirror of
https://github.com/vcmi/vcmi.git
synced 2025-09-16 09:26:28 +02:00
Better handling of Ctrl / Cmd modifier keys on Apple systems:
- Test only for Cmd modifier key when processing mouse clicks - Test both Ctrl and Cmd modifier key when processing keyboard input - This logic is now used for all Apple systems - macOS and iOS
This commit is contained in:
@@ -564,7 +564,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &targetPosition)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(GH.isKeyboardCtrlDown()) //normal click behaviour (as no hero selected)
|
if(GH.isKeyboardCmdDown()) //normal click behaviour (as no hero selected)
|
||||||
{
|
{
|
||||||
if(canSelect)
|
if(canSelect)
|
||||||
LOCPLINT->localState->setSelection(static_cast<const CArmedInstance*>(topBlocking));
|
LOCPLINT->localState->setSelection(static_cast<const CArmedInstance*>(topBlocking));
|
||||||
|
@@ -300,6 +300,11 @@ void InputHandler::fetchEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InputHandler::isKeyboardCmdDown() const
|
||||||
|
{
|
||||||
|
return keyboardHandler->isKeyboardCmdDown();
|
||||||
|
}
|
||||||
|
|
||||||
bool InputHandler::isKeyboardCtrlDown() const
|
bool InputHandler::isKeyboardCtrlDown() const
|
||||||
{
|
{
|
||||||
return keyboardHandler->isKeyboardCtrlDown();
|
return keyboardHandler->isKeyboardCtrlDown();
|
||||||
|
@@ -88,6 +88,7 @@ public:
|
|||||||
|
|
||||||
/// returns true if chosen keyboard key is currently pressed down
|
/// returns true if chosen keyboard key is currently pressed down
|
||||||
bool isKeyboardAltDown() const;
|
bool isKeyboardAltDown() const;
|
||||||
|
bool isKeyboardCmdDown() const;
|
||||||
bool isKeyboardCtrlDown() const;
|
bool isKeyboardCtrlDown() const;
|
||||||
bool isKeyboardShiftDown() const;
|
bool isKeyboardShiftDown() const;
|
||||||
};
|
};
|
||||||
|
@@ -120,10 +120,20 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
|
|||||||
GH.events().dispatchShortcutReleased(shortcutsVector);
|
GH.events().dispatchShortcutReleased(shortcutsVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool InputSourceKeyboard::isKeyboardCmdDown() const
|
||||||
|
{
|
||||||
|
#ifdef VCMI_APPLE
|
||||||
|
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI];
|
||||||
|
#else
|
||||||
|
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
bool InputSourceKeyboard::isKeyboardCtrlDown() const
|
bool InputSourceKeyboard::isKeyboardCtrlDown() const
|
||||||
{
|
{
|
||||||
#ifdef VCMI_MAC
|
#ifdef VCMI_APPLE
|
||||||
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI];
|
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL] ||
|
||||||
|
SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI];
|
||||||
#else
|
#else
|
||||||
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
|
return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
|
||||||
#endif
|
#endif
|
||||||
|
@@ -23,6 +23,7 @@ public:
|
|||||||
void handleEventKeyUp(const SDL_KeyboardEvent & current);
|
void handleEventKeyUp(const SDL_KeyboardEvent & current);
|
||||||
|
|
||||||
bool isKeyboardAltDown() const;
|
bool isKeyboardAltDown() const;
|
||||||
|
bool isKeyboardCmdDown() const;
|
||||||
bool isKeyboardCtrlDown() const;
|
bool isKeyboardCtrlDown() const;
|
||||||
bool isKeyboardShiftDown() const;
|
bool isKeyboardShiftDown() const;
|
||||||
};
|
};
|
||||||
|
@@ -165,6 +165,11 @@ bool CGuiHandler::isKeyboardCtrlDown() const
|
|||||||
return inputHandlerInstance->isKeyboardCtrlDown();
|
return inputHandlerInstance->isKeyboardCtrlDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CGuiHandler::isKeyboardCmdDown() const
|
||||||
|
{
|
||||||
|
return inputHandlerInstance->isKeyboardCmdDown();
|
||||||
|
}
|
||||||
|
|
||||||
bool CGuiHandler::isKeyboardAltDown() const
|
bool CGuiHandler::isKeyboardAltDown() const
|
||||||
{
|
{
|
||||||
return inputHandlerInstance->isKeyboardAltDown();
|
return inputHandlerInstance->isKeyboardAltDown();
|
||||||
|
@@ -62,9 +62,17 @@ public:
|
|||||||
/// May not match size of window if user has UI scaling different from 100%
|
/// May not match size of window if user has UI scaling different from 100%
|
||||||
Point screenDimensions() const;
|
Point screenDimensions() const;
|
||||||
|
|
||||||
/// returns true if chosen keyboard key is currently pressed down
|
/// returns true if Alt is currently pressed down
|
||||||
bool isKeyboardAltDown() const;
|
bool isKeyboardAltDown() const;
|
||||||
|
/// returns true if Ctrl is currently pressed down
|
||||||
|
/// on Apple system, this also tests for Cmd key
|
||||||
|
/// For use with keyboard-based events
|
||||||
bool isKeyboardCtrlDown() const;
|
bool isKeyboardCtrlDown() const;
|
||||||
|
/// on Apple systems, returns true if Cmd key is pressed
|
||||||
|
/// on other systems, returns true if Ctrl is pressed
|
||||||
|
/// /// For use with mouse-based events
|
||||||
|
bool isKeyboardCmdDown() const;
|
||||||
|
/// returns true if Shift is currently pressed down
|
||||||
bool isKeyboardShiftDown() const;
|
bool isKeyboardShiftDown() const;
|
||||||
|
|
||||||
void startTextInput(const Rect & where);
|
void startTextInput(const Rect & where);
|
||||||
|
@@ -485,7 +485,7 @@ bool CGarrisonSlot::handleSplittingShortcuts()
|
|||||||
{
|
{
|
||||||
const bool isAlt = GH.isKeyboardAltDown();
|
const bool isAlt = GH.isKeyboardAltDown();
|
||||||
const bool isLShift = GH.isKeyboardShiftDown();
|
const bool isLShift = GH.isKeyboardShiftDown();
|
||||||
const bool isLCtrl = GH.isKeyboardCtrlDown();
|
const bool isLCtrl = GH.isKeyboardCmdDown();
|
||||||
|
|
||||||
if(!isAlt && !isLShift && !isLCtrl)
|
if(!isAlt && !isLShift && !isLCtrl)
|
||||||
return false; // This is only case when return false
|
return false; // This is only case when return false
|
||||||
|
@@ -151,7 +151,7 @@ void CWindowWithArtifacts::clickPressedArtPlaceHero(const CArtifactsOfHeroBase &
|
|||||||
{
|
{
|
||||||
assert(artSetPtr->getHero()->getSlotByInstance(art) != ArtifactPosition::PRE_FIRST);
|
assert(artSetPtr->getHero()->getSlotByInstance(art) != ArtifactPosition::PRE_FIRST);
|
||||||
|
|
||||||
if(GH.isKeyboardCtrlDown())
|
if(GH.isKeyboardCmdDown())
|
||||||
{
|
{
|
||||||
std::shared_ptr<CArtifactsOfHeroMain> anotherHeroEquipmentPointer = nullptr;
|
std::shared_ptr<CArtifactsOfHeroMain> anotherHeroEquipmentPointer = nullptr;
|
||||||
|
|
||||||
|
@@ -851,7 +851,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
|
|||||||
bool moveEquipped = true;
|
bool moveEquipped = true;
|
||||||
bool moveBackpack = true;
|
bool moveBackpack = true;
|
||||||
|
|
||||||
if(GH.isKeyboardCtrlDown())
|
if(GH.isKeyboardCmdDown())
|
||||||
moveBackpack = false;
|
moveBackpack = false;
|
||||||
else if(GH.isKeyboardShiftDown())
|
else if(GH.isKeyboardShiftDown())
|
||||||
moveEquipped = false;
|
moveEquipped = false;
|
||||||
|
Reference in New Issue
Block a user