Browse Source

Merged left and right sides of control, shift and alt keys to make programs behave the same on different keyboards.

David Piuva 2 years ago
parent
commit
a229db625a

+ 18 - 0
Source/DFPSR/History.txt

@@ -5,7 +5,25 @@ There are plans to create an automatic refactoring tool built into the Builder b
 
 Changes since version 0.1.0
 	* simdExtra.h was removed, because such a low depth of abstraction would risk making the code slower from not fitting well with future SIMD extensions.
+		The more features you add to the badly defined extra feature set, the less systems it will work on, until it is just a slower version of specific instruction sets.
 		On missing header when including simdExtra.h:
 			Replace 'simdExtra.h' with 'simd.h' to make it compile.
 			Remove any duplicate includes of simd.h to clean up your code.
 			Remove all code within '#ifdef USE_SIMD_EXTRA' or '#if defined USE_SIMD_EXTRA' to clean up your code.
+	* Left and right sides of control, shift and alt keys were merged.
+		Because MS-Windows allow using control, shift and alt of undefined side.
+			This caused copying and pasting of text to fail when I tested on a different keyboard,
+			  because it was neither left nor right control, just control.
+			Adding a third case would not solve the bug in applications using this library,
+			  because checks for left or right would still fail.
+			Forcing unknown sides to one side would cause new bugs when someone connects different actions to left and right sides.
+			The only resaonable bugfix was to merge left and right sides into the same keys.
+		On missing DsrKey:
+			Replace 'DsrKey_LeftControl' with 'DsrKey_Control'
+			Replace 'DsrKey_RightControl' with 'DsrKey_Control'
+			Replace 'DsrKey_LeftShift' with 'DsrKey_Shift'
+			Replace 'DsrKey_RightShift' with 'DsrKey_Shift'
+			Replace 'DsrKey_LeftAlt' with 'DsrKey_Alt'
+			Replace 'DsrKey_RightAlt' with 'DsrKey_Alt'
+			Merge any uplicated checks for left or right versions to clean up your code.
+			Rethink the design if you relied on distinguishing between left and right control, shift or alt.

+ 6 - 12
Source/DFPSR/gui/InputEvent.cpp

@@ -64,18 +64,12 @@ inline String dsr::getName(DsrKey v) {
 		return U"Return";
 	} else if (v == DsrKey_BackSpace) {
 		return U"BackSpace";
-	} else if (v == DsrKey_LeftShift) {
-		return U"LeftShift";
-	} else if (v == DsrKey_RightShift) {
-		return U"RightShift";
-	} else if (v == DsrKey_LeftControl) {
-		return U"LeftControl";
-	} else if (v == DsrKey_RightControl) {
-		return U"RightControl";
-	} else if (v == DsrKey_LeftAlt) {
-		return U"LeftAlt";
-	} else if (v == DsrKey_RightAlt) {
-		return U"RightAlt";
+	} else if (v == DsrKey_Shift) {
+		return U"Shift";
+	} else if (v == DsrKey_Control) {
+		return U"Control";
+	} else if (v == DsrKey_Alt) {
+		return U"Alt";
 	} else if (v == DsrKey_Delete) {
 		return U"Delete";
 	} else if (v == DsrKey_LeftArrow) {

+ 5 - 2
Source/DFPSR/gui/InputEvent.h

@@ -42,10 +42,13 @@ enum class KeyboardEventType { KeyDown, KeyUp, KeyType };
 //   * DsrKey_0 to DsrKey_9 are guaranteed to be in an increasing serial order (so that "key - DsrKey_0" is the key's number)
 //   * DsrKey_F1 to DsrKey_F12 are guaranteed to be in an increasing serial order (so that "key - (DsrKey_F1 - 1)" is the key's number)
 //   * DsrKey_A to DsrKey_Z are guaranteed to be in an increasing serial order
+// Characters are case insensitive, because DsrKey refers to the physical key.
+//   Use the decoded Unicode value in DsrChar if you want to distinguish between upper and lower case or use special characters.
+// Control, shift and alt combines left and right sides, because sometimes the system does not say if the key is left or right.
 enum DsrKey {
 	DsrKey_LeftArrow, DsrKey_RightArrow, DsrKey_UpArrow, DsrKey_DownArrow, DsrKey_PageUp, DsrKey_PageDown,
-	DsrKey_LeftControl, DsrKey_RightControl, DsrKey_LeftShift, DsrKey_RightShift, DsrKey_LeftAlt, DsrKey_RightAlt,
-	DsrKey_Escape, DsrKey_Pause, DsrKey_Space, DsrKey_Tab, DsrKey_Return, DsrKey_BackSpace, DsrKey_Delete, DsrKey_Insert, DsrKey_Home, DsrKey_End,
+	DsrKey_Control, DsrKey_Shift, DsrKey_Alt, DsrKey_Escape, DsrKey_Pause, DsrKey_Space, DsrKey_Tab,
+	DsrKey_Return, DsrKey_BackSpace, DsrKey_Delete, DsrKey_Insert, DsrKey_Home, DsrKey_End,
 	DsrKey_0, DsrKey_1, DsrKey_2, DsrKey_3, DsrKey_4, DsrKey_5, DsrKey_6, DsrKey_7, DsrKey_8, DsrKey_9,
 	DsrKey_F1, DsrKey_F2, DsrKey_F3, DsrKey_F4, DsrKey_F5, DsrKey_F6, DsrKey_F7, DsrKey_F8, DsrKey_F9, DsrKey_F10, DsrKey_F11, DsrKey_F12,
 	DsrKey_A, DsrKey_B, DsrKey_C, DsrKey_D, DsrKey_E, DsrKey_F, DsrKey_G, DsrKey_H, DsrKey_I, DsrKey_J, DsrKey_K, DsrKey_L, DsrKey_M,

+ 12 - 22
Source/DFPSR/gui/components/TextBox.cpp

@@ -354,12 +354,8 @@ void TextBox::moveBeamVertically(int64_t rowIndexOffset, bool removeSelection) {
 	limitScrolling(true);
 }
 
-static const uint32_t combinationKey_leftShift = 1 << 0;
-static const uint32_t combinationKey_rightShift = 1 << 1;
-static const uint32_t combinationKey_shift = combinationKey_leftShift | combinationKey_rightShift;
-static const uint32_t combinationKey_leftControl = 1 << 2;
-static const uint32_t combinationKey_rightControl = 1 << 3;
-static const uint32_t combinationKey_control = combinationKey_leftControl | combinationKey_rightControl;
+static const uint32_t combinationKey_shift = 1 << 0;
+static const uint32_t combinationKey_control = 1 << 1;
 
 static int64_t getLineStart(const ReadableString &text, int64_t searchStart) {
 	for (int64_t i = searchStart - 1; i >= 0; i--) {
@@ -381,25 +377,19 @@ static int64_t getLineEnd(const ReadableString &text, int64_t searchStart) {
 
 void TextBox::receiveKeyboardEvent(const KeyboardEvent& event) {
 	// Insert and scroll-lock is not supported.
+	// To prevent getting stuck from missing a key event, one can reset by pressing and releasing again.
+	//   So if you press down both control keys and release one of them, it counts both as released.
 	if (event.keyboardEventType == KeyboardEventType::KeyDown) {
-		if (event.dsrKey == DsrKey_LeftShift) {
-			this->combinationKeys |= combinationKey_leftShift;
-		} else if (event.dsrKey == DsrKey_RightShift) {
-			this->combinationKeys |= combinationKey_rightShift;
-		} else if (event.dsrKey == DsrKey_LeftControl) {
-			this->combinationKeys |= combinationKey_leftControl;
-		} else if (event.dsrKey == DsrKey_RightControl) {
-			this->combinationKeys |= combinationKey_rightControl;
+		if (event.dsrKey == DsrKey_Shift) {
+			this->combinationKeys |= combinationKey_shift; // Enable shift
+		} else if (event.dsrKey == DsrKey_Control) {
+			this->combinationKeys |= combinationKey_control; // Enable control
 		}
 	} else if (event.keyboardEventType == KeyboardEventType::KeyUp) {
-		if (event.dsrKey == DsrKey_LeftShift) {
-			this->combinationKeys &= ~combinationKey_leftShift;
-		} else if (event.dsrKey == DsrKey_RightShift) {
-			this->combinationKeys &= ~combinationKey_rightShift;
-		} else if (event.dsrKey == DsrKey_LeftControl) {
-			this->combinationKeys &= ~combinationKey_leftControl;
-		} else if (event.dsrKey == DsrKey_RightControl) {
-			this->combinationKeys &= ~combinationKey_rightControl;
+		if (event.dsrKey == DsrKey_Shift) {
+			this->combinationKeys &= ~combinationKey_shift; // Disable shift
+		} else if (event.dsrKey == DsrKey_Control) {
+			this->combinationKeys &= ~combinationKey_control; // Disable control
 		}
 	} else if (event.keyboardEventType == KeyboardEventType::KeyType) {
 		int64_t textLength = string_length(this->text.value);

+ 6 - 15
Source/windowManagers/Win32Window.cpp

@@ -317,21 +317,12 @@ static dsr::DsrKey getDsrKey(WPARAM keyCode) {
 		result = dsr::DsrKey_Return;
 	} else if (keyCode == VK_BACK) {
 		result = dsr::DsrKey_BackSpace;
-	} else if (keyCode == VK_LSHIFT || keyCode == VK_SHIFT) {
-		// If the keyboard does not tell if the shift is left or right, treat it like a left shift.
-		result = dsr::DsrKey_LeftShift;
-	} else if (keyCode == VK_RSHIFT) {
-		result = dsr::DsrKey_RightShift;
-	} else if (keyCode == VK_LCONTROL || keyCode == VK_CONTROL) {
-		// If the keyboard does not tell if control is left or right, treat it like left control.
-		result = dsr::DsrKey_LeftControl;
-	} else if (keyCode == VK_RCONTROL) {
-		result = dsr::DsrKey_RightControl;
-	} else if (keyCode == VK_LMENU || keyCode == VK_MENU) {
-		// If the keyboard does not tell if alt is left or right, treat it like left alt.
-		result = dsr::DsrKey_LeftAlt;
-	} else if (keyCode == VK_RMENU) {
-		result = dsr::DsrKey_RightAlt;
+	} else if (keyCode == VK_LSHIFT || keyCode == VK_SHIFT || keyCode == VK_RSHIFT) {
+		result = dsr::DsrKey_Shift;
+	} else if (keyCode == VK_LCONTROL || keyCode == VK_CONTROL || keyCode == VK_RCONTROL) {
+		result = dsr::DsrKey_Control;
+	} else if (keyCode == VK_LMENU || keyCode == VK_MENU || keyCode == VK_RMENU) {
+		result = dsr::DsrKey_Alt;
 	} else if (keyCode == VK_DELETE) {
 		result = dsr::DsrKey_Delete;
 	} else if (keyCode == VK_LEFT) {

+ 6 - 12
Source/windowManagers/X11Window.cpp

@@ -466,18 +466,12 @@ static dsr::DsrKey getDsrKey(KeySym keyCode) {
 		result = dsr::DsrKey_Return;
 	} else if (keyCode == XK_BackSpace) {
 		result = dsr::DsrKey_BackSpace;
-	} else if (keyCode == XK_Shift_L) {
-		result = dsr::DsrKey_LeftShift;
-	} else if (keyCode == XK_Shift_R) {
-		result = dsr::DsrKey_RightShift;
-	} else if (keyCode == XK_Control_L) {
-		result = dsr::DsrKey_LeftControl;
-	} else if (keyCode == XK_Control_R) {
-		result = dsr::DsrKey_RightControl;
-	} else if (keyCode == XK_Alt_L) {
-		result = dsr::DsrKey_LeftAlt;
-	} else if (keyCode == XK_Alt_R) {
-		result = dsr::DsrKey_RightAlt;
+	} else if (keyCode == XK_Shift_L || keyCode == XK_Shift_R) {
+		result = dsr::DsrKey_Shift;
+	} else if (keyCode == XK_Control_L || keyCode == XK_Control_R) {
+		result = dsr::DsrKey_Control;
+	} else if (keyCode == XK_Alt_L || keyCode == XK_Alt_R) {
+		result = dsr::DsrKey_Alt;
 	} else if (keyCode == XK_Delete) {
 		result = dsr::DsrKey_Delete;
 	} else if (keyCode == XK_Left) {