summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/enums/input/keyboardfocus.h34
-rw-r--r--src/eventsmanager.cpp15
-rw-r--r--src/game.cpp7
-rw-r--r--src/gui/widgets/tabs/chat/chattab.cpp3
-rw-r--r--src/gui/widgets/tabs/setup_other.cpp7
-rw-r--r--src/input/inputmanager.cpp16
-rw-r--r--src/input/joystick.cpp6
-rw-r--r--src/input/keyboardconfig.cpp37
-rw-r--r--src/input/keyboardconfig.h6
-rw-r--r--src/settings.h6
13 files changed, 130 insertions, 10 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4049b940c..1c10028db 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1164,6 +1164,7 @@ SET(SRCS
input/inputmanager.cpp
input/inputmanager.h
enums/input/inputtype.h
+ enums/input/keyboardfocus.h
enums/input/keyvalue.h
events/inputevent.h
input/joystick.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index c82a336e7..36b43c5ef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -719,6 +719,7 @@ BASE_SRC += client.h \
input/inputmanager.cpp \
input/inputmanager.h \
enums/input/inputtype.h \
+ enums/input/keyboardfocus.h \
enums/input/keyvalue.h \
input/joystick.cpp \
input/joystick.h \
diff --git a/src/defaults.cpp b/src/defaults.cpp
index e3b1f91c6..5df7ab80e 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -414,6 +414,7 @@ void setConfigDefaults(Configuration &cfg)
AddDEF("openglContext", false);
AddDEF("allowMoveByMouse", true);
AddDEF("enableDSA", true);
+ AddDEF("blockAltTab", true);
}
void setConfigDefaults2(Configuration &cfg)
diff --git a/src/enums/input/keyboardfocus.h b/src/enums/input/keyboardfocus.h
new file mode 100644
index 000000000..9b80f7f20
--- /dev/null
+++ b/src/enums/input/keyboardfocus.h
@@ -0,0 +1,34 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2017 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ENUMS_INPUT_KEYBOARDFOCUS_H
+#define ENUMS_INPUT_KEYBOARDFOCUS_H
+
+#include "enums/simpletypes/enumdefines.h"
+
+enumStart(KeyboardFocus)
+{
+ Unfocused = 0,
+ Focused = 1,
+ Focused2 = 2
+}
+enumEnd(KeyboardFocus);
+
+#endif // ENUMS_INPUT_KEYBOARDFOCUS_H
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
index 76fe054fa..143937fe1 100644
--- a/src/eventsmanager.cpp
+++ b/src/eventsmanager.cpp
@@ -513,10 +513,16 @@ void EventsManager::handleSDL2WindowEvent(const SDL_Event &event)
settings.mouseFocused = false;
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
- settings.inputFocused = true;
+ settings.inputFocused = KeyboardFocus::Focused;
break;
+#if SDL_VERSION_ATLEAST(2, 0, 5)
+ case SDL_WINDOWEVENT_TAKE_FOCUS:
+ settings.inputFocused = KeyboardFocus::Focused2;
+ break;
+#endif // SDL_VERSION_ATLEAST(2, 0, 5)
+
case SDL_WINDOWEVENT_FOCUS_LOST:
- settings.inputFocused = false;
+ settings.inputFocused = KeyboardFocus::Unfocused;
break;
case SDL_WINDOWEVENT_MINIMIZED:
WindowManager::setIsMinimized(true);
@@ -624,7 +630,10 @@ void EventsManager::handleActive(const SDL_Event &event)
#endif // DYECMD
if ((event.active.state & SDL_APPINPUTFOCUS) != 0)
- settings.inputFocused = (event.active.gain != 0u);
+ {
+ settings.inputFocused = (event.active.gain != 0u) ?
+ KeyboardFocus::Focused : KeyboardFocus::Unfocused;
+ }
if ((event.active.state & SDL_APPMOUSEFOCUS) != 0)
settings.mouseFocused = (event.active.gain != 0u);
#ifndef DYECMD
diff --git a/src/game.cpp b/src/game.cpp
index 7a66c0b19..ad819230b 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -1002,10 +1002,15 @@ void Game::updateFrameRate(int fpsLimit)
{
if (settings.awayMode)
{
- if (settings.inputFocused || settings.mouseFocused)
+ if (settings.inputFocused != KeyboardFocus::Unfocused ||
+ settings.mouseFocused)
+ {
fpsLimit = config.getIntValue("fpslimit");
+ }
else
+ {
fpsLimit = config.getIntValue("altfpslimit");
+ }
}
else
{
diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp
index ae75f9981..e4f6d751a 100644
--- a/src/gui/widgets/tabs/chat/chattab.cpp
+++ b/src/gui/widgets/tabs/chat/chattab.cpp
@@ -312,7 +312,8 @@ void ChatTab::chatLog(std::string line,
return;
const bool notFocused = WindowManager::getIsMinimized() ||
- (!settings.mouseFocused && !settings.inputFocused);
+ (!settings.mouseFocused &&
+ settings.inputFocused == KeyboardFocus::Unfocused);
if (this != tabArea->getSelectedTab() || notFocused)
{
diff --git a/src/gui/widgets/tabs/setup_other.cpp b/src/gui/widgets/tabs/setup_other.cpp
index 413b93a7f..e608d27e1 100644
--- a/src/gui/widgets/tabs/setup_other.cpp
+++ b/src/gui/widgets/tabs/setup_other.cpp
@@ -332,6 +332,13 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
new SetupItemIntTextField(_("Custom repeat interval"), "",
"repeateInterval2", this, "repeateInterval2Event", 0, 10000);
+#ifdef USE_SDL2
+ // TRANSLATORS: settings option
+ new SetupItemCheckBox(_("Enable alt-tab workaround"), "",
+ "blockAltTab", this, "blockAltTabEvent");
+#endif // USE_SDL2
+
+
// TRANSLATORS: settings group
new SetupItemLabel(_("Windows"), "", this);
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index dbe82d5da..42a4e3b25 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -594,6 +594,14 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
{
case SDL_KEYDOWN:
{
+#ifdef USE_SDL2
+ if (keyboard.ignoreKey(event))
+ {
+ BLOCK_END("InputManager::handleEvent")
+ return true;
+ }
+#endif // USE_SDL2
+
keyboard.refreshActiveKeys();
updateConditionMask();
if (handleAssignKey(event, InputType::KEYBOARD))
@@ -620,6 +628,14 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
}
case SDL_KEYUP:
{
+#ifdef USE_SDL2
+ if (keyboard.ignoreKey(event))
+ {
+ BLOCK_END("InputManager::handleEvent")
+ return true;
+ }
+#endif // USE_SDL2
+
keyboard.refreshActiveKeys();
updateConditionMask();
keyboard.handleDeActicateKey(event);
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 1e53af5b1..10ed33924 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -180,7 +180,8 @@ void Joystick::logic()
mDirection = 0;
- if (mUseInactive || settings.inputFocused)
+ if (mUseInactive ||
+ settings.inputFocused != KeyboardFocus::Unfocused)
{
// X-Axis
int position = SDL_JoystickGetAxis(mJoystick, 0);
@@ -350,7 +351,8 @@ bool Joystick::validate() const
if (mCalibrating || !mEnabled || !mCalibrated)
return false;
- return mUseInactive || settings.inputFocused;
+ return mUseInactive ||
+ settings.inputFocused != KeyboardFocus::Unfocused;
}
void Joystick::handleRepeat(const int time)
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
diff --git a/src/input/keyboardconfig.h b/src/input/keyboardconfig.h
index 1759e4bb9..ef3f056b7 100644
--- a/src/input/keyboardconfig.h
+++ b/src/input/keyboardconfig.h
@@ -129,6 +129,10 @@ class KeyboardConfig final
void resetRepeat(const int key);
+#ifdef USE_SDL2
+ bool ignoreKey(const SDL_Event &restrict event) A_WARN_UNUSED;
+#endif // USE_SDL2
+
private:
bool mEnabled; /**< Flag to respond to key input */
@@ -143,6 +147,8 @@ class KeyboardConfig final
KeyToIdMap mKeyToId;
KeyTimeMap mKeyTimeMap;
+
+ bool mBlockAltTab;
};
extern KeyboardConfig keyboard;
diff --git a/src/settings.h b/src/settings.h
index 308da0202..1a165ad99 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -25,6 +25,8 @@
#include "enums/emotetype.h"
+#include "enums/input/keyboardfocus.h"
+
#include "enums/resources/map/maptype.h"
#include "utils/vector.h"
@@ -82,7 +84,7 @@ class Settings final
emoteType(EmoteType::Player),
persistentIp(true),
limitFps(false),
- inputFocused(true),
+ inputFocused(KeyboardFocus::Focused),
mouseFocused(true),
disableGameModifiers(false),
awayMode(false),
@@ -147,7 +149,7 @@ class Settings final
EmoteTypeT emoteType;
bool persistentIp;
bool limitFps;
- bool inputFocused;
+ KeyboardFocusT inputFocused;
bool mouseFocused;
bool disableGameModifiers;
bool awayMode;