Bläddra i källkod

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
Ivan Savenko 1 år sedan
förälder
incheckning
7267e02b8d

+ 1 - 1
client/adventureMap/AdventureMapInterface.cpp

@@ -564,7 +564,7 @@ void AdventureMapInterface::onTileLeftClicked(const int3 &targetPosition)
 			}
 			else
 			{
-				if(GH.isKeyboardCtrlDown()) //normal click behaviour (as no hero selected)
+				if(GH.isKeyboardCmdDown()) //normal click behaviour (as no hero selected)
 				{
 					if(canSelect)
 						LOCPLINT->localState->setSelection(static_cast<const CArmedInstance*>(topBlocking));

+ 5 - 0
client/eventsSDL/InputHandler.cpp

@@ -300,6 +300,11 @@ void InputHandler::fetchEvents()
 	}
 }
 
+bool InputHandler::isKeyboardCmdDown() const
+{
+	return keyboardHandler->isKeyboardCmdDown();
+}
+
 bool InputHandler::isKeyboardCtrlDown() const
 {
 	return keyboardHandler->isKeyboardCtrlDown();

+ 1 - 0
client/eventsSDL/InputHandler.h

@@ -88,6 +88,7 @@ public:
 
 	/// returns true if chosen keyboard key is currently pressed down
 	bool isKeyboardAltDown() const;
+	bool isKeyboardCmdDown() const;
 	bool isKeyboardCtrlDown() const;
 	bool isKeyboardShiftDown() const;
 };

+ 12 - 2
client/eventsSDL/InputSourceKeyboard.cpp

@@ -120,15 +120,25 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
 	GH.events().dispatchShortcutReleased(shortcutsVector);
 }
 
-bool InputSourceKeyboard::isKeyboardCtrlDown() const
+bool InputSourceKeyboard::isKeyboardCmdDown() const
 {
-#ifdef VCMI_MAC
+#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
+{
+#ifdef VCMI_APPLE
+	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
+	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
+#endif
+}
+
 bool InputSourceKeyboard::isKeyboardAltDown() const
 {
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];

+ 1 - 0
client/eventsSDL/InputSourceKeyboard.h

@@ -23,6 +23,7 @@ public:
 	void handleEventKeyUp(const SDL_KeyboardEvent & current);
 
 	bool isKeyboardAltDown() const;
+	bool isKeyboardCmdDown() const;
 	bool isKeyboardCtrlDown() const;
 	bool isKeyboardShiftDown() const;
 };

+ 5 - 0
client/gui/CGuiHandler.cpp

@@ -165,6 +165,11 @@ bool CGuiHandler::isKeyboardCtrlDown() const
 	return inputHandlerInstance->isKeyboardCtrlDown();
 }
 
+bool CGuiHandler::isKeyboardCmdDown() const
+{
+	return inputHandlerInstance->isKeyboardCmdDown();
+}
+
 bool CGuiHandler::isKeyboardAltDown() const
 {
 	return inputHandlerInstance->isKeyboardAltDown();

+ 9 - 1
client/gui/CGuiHandler.h

@@ -62,9 +62,17 @@ public:
 	/// May not match size of window if user has UI scaling different from 100%
 	Point screenDimensions() const;
 
-	/// returns true if chosen keyboard key is currently pressed down
+	/// returns true if Alt is currently pressed down
 	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;
+	/// 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;
 
 	void startTextInput(const Rect & where);

+ 1 - 1
client/widgets/CGarrisonInt.cpp

@@ -485,7 +485,7 @@ bool CGarrisonSlot::handleSplittingShortcuts()
 {
 	const bool isAlt = GH.isKeyboardAltDown();
 	const bool isLShift = GH.isKeyboardShiftDown();
-	const bool isLCtrl = GH.isKeyboardCtrlDown();
+	const bool isLCtrl = GH.isKeyboardCmdDown();
 
 	if(!isAlt && !isLShift && !isLCtrl)
 		return false; // This is only case when return false

+ 1 - 1
client/windows/CWindowWithArtifacts.cpp

@@ -151,7 +151,7 @@ void CWindowWithArtifacts::clickPressedArtPlaceHero(const CArtifactsOfHeroBase &
 						{
 							assert(artSetPtr->getHero()->getSlotByInstance(art) != ArtifactPosition::PRE_FIRST);
 
-							if(GH.isKeyboardCtrlDown())
+							if(GH.isKeyboardCmdDown())
 							{
 								std::shared_ptr<CArtifactsOfHeroMain> anotherHeroEquipmentPointer = nullptr;
 

+ 1 - 1
client/windows/GUIClasses.cpp

@@ -851,7 +851,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2,
 			bool moveEquipped = true;
 			bool moveBackpack = true;
 
-			if(GH.isKeyboardCtrlDown())
+			if(GH.isKeyboardCmdDown())
 				moveBackpack = false;
 			else if(GH.isKeyboardShiftDown())
 				moveEquipped = false;