summaryrefslogtreecommitdiff
path: root/src/input/keyboardconfig.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-09-09 22:54:01 +0300
committerAndrei Karas <akaras@inbox.ru>2017-09-09 22:56:17 +0300
commit481ea0b776bbab92b500540f59c5a191c6e93cba (patch)
tree5b73e15b5ab16d67095852d83ba764d83c36cbb8 /src/input/keyboardconfig.cpp
parentc108b00ddc98e99182bf1a0f83602772f4931122 (diff)
downloadplus-481ea0b776bbab92b500540f59c5a191c6e93cba.tar.gz
plus-481ea0b776bbab92b500540f59c5a191c6e93cba.tar.bz2
plus-481ea0b776bbab92b500540f59c5a191c6e93cba.tar.xz
plus-481ea0b776bbab92b500540f59c5a191c6e93cba.zip
Add workaround for fix alt-tab issue in SDL2.
Also add option to enable/disable this workaround.
Diffstat (limited to 'src/input/keyboardconfig.cpp')
-rw-r--r--src/input/keyboardconfig.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/input/keyboardconfig.cpp b/src/input/keyboardconfig.cpp
index 1ce317db7..e90d126a5 100644
--- a/src/input/keyboardconfig.cpp
+++ b/src/input/keyboardconfig.cpp
@@ -23,6 +23,9 @@
#include "input/keyboardconfig.h"
#include "configuration.h"
+#ifdef USE_SDL2
+#include "settings.h"
+#endif // USE_SDL2
#include "input/inputmanager.h"
@@ -42,7 +45,8 @@ KeyboardConfig::KeyboardConfig() :
mRepeatTime(0),
mKeyToAction(),
mKeyToId(),
- mKeyTimeMap()
+ mKeyTimeMap(),
+ mBlockAltTab(true)
{
}
@@ -52,6 +56,7 @@ void KeyboardConfig::init()
delete [] mActiveKeys2;
mActiveKeys2 = new uint8_t[500];
mRepeatTime = config.getIntValue("repeateInterval2") / 10;
+ mBlockAltTab = config.getBoolValue("blockAltTab");
}
void KeyboardConfig::deinit()
@@ -270,3 +275,33 @@ void KeyboardConfig::resetRepeat(const int key)
if (it != mKeyTimeMap.end())
(*it).second = tick_time;
}
+
+#ifdef USE_SDL2
+
+bool KeyboardConfig::ignoreKey(const SDL_Event &restrict event)
+{
+ if (!mBlockAltTab ||
+ mActiveKeys == nullptr)
+ {
+ return false;
+ }
+ const int key = event.key.keysym.scancode;
+ if (key == SDL_SCANCODE_TAB)
+ {
+#if SDL_VERSION_ATLEAST(2, 0, 5)
+ // SDL_WINDOWEVENT_TAKE_FOCUS not triggered after focus restored
+ if (settings.inputFocused != KeyboardFocus::Focused2)
+ return true;
+#endif // SDL_VERSION_ATLEAST(2, 0, 5)
+
+ if (mActiveKeys[SDL_SCANCODE_LALT] != 0)
+ return true;
+ }
+ else if (key == SDL_SCANCODE_LALT)
+ {
+ if (mActiveKeys[SDL_SCANCODE_TAB] != 0)
+ return true;
+ }
+ return false;
+}
+#endif // USE_SDL2