mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-13 10:18:53 +01:00
Fixed keyboard (win/linux) and input focus (linux) bugs when returning from launching.
This commit is contained in:
parent
65e730bc54
commit
aa797abc61
@ -74,6 +74,29 @@ SDL_Scancode UserInput::GetScancode(KeyCode_E key)
|
||||
}
|
||||
|
||||
|
||||
UserInput::KeyCode_E UserInput::GetKeycode(SDL_Scancode scancode)
|
||||
{
|
||||
KeyCode_E keycode = KeyCodeNull;
|
||||
|
||||
std::map<SDL_Scancode, KeyCode_E>::iterator it = ReverseKeyMap.find(scancode);
|
||||
|
||||
if(it != ReverseKeyMap.end())
|
||||
{
|
||||
keycode = it->second;
|
||||
}
|
||||
|
||||
return keycode;
|
||||
}
|
||||
|
||||
void UserInput::ResetKeyStates()
|
||||
{
|
||||
for(std::map<KeyCode_E, bool>::iterator it = KeyState.begin(); it != KeyState.end(); it++)
|
||||
{
|
||||
it->second = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool UserInput::MapKey(std::string keyDescription, KeyCode_E key)
|
||||
{
|
||||
SDL_Scancode scanCode;
|
||||
@ -96,6 +119,28 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key)
|
||||
}
|
||||
|
||||
KeyMap[key] = scanCode;
|
||||
ReverseKeyMap[scanCode] = key;
|
||||
KeyState[key] = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UserInput::SetKeyState(SDL_Scancode code, bool state)
|
||||
{
|
||||
KeyCode_E key = GetKeycode(code);
|
||||
|
||||
if(key == KeyCodeNull)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
KeyState[key] = state;
|
||||
return true;
|
||||
|
||||
}
|
||||
bool UserInput::GetKeyState(KeyCode_E key)
|
||||
{
|
||||
return KeyState[key];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@ class UserInput
|
||||
public:
|
||||
enum KeyCode_E
|
||||
{
|
||||
KeyCodeNull,
|
||||
KeyCodeUp,
|
||||
KeyCodeDown,
|
||||
KeyCodeLeft,
|
||||
@ -42,11 +43,19 @@ public:
|
||||
virtual ~UserInput();
|
||||
bool Initialize();
|
||||
SDL_Scancode GetScancode(KeyCode_E key);
|
||||
KeyCode_E GetKeycode(SDL_Scancode scancode);
|
||||
bool SetKeyState(SDL_Scancode code, bool state);
|
||||
bool GetKeyState(KeyCode_E key);
|
||||
bool KeyStateChanged();
|
||||
void ResetKeyStates();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
bool MapKey(std::string keyDescription, KeyCode_E key);
|
||||
std::map<KeyCode_E, SDL_Scancode> KeyMap;
|
||||
|
||||
std::map<SDL_Scancode, KeyCode_E> ReverseKeyMap;
|
||||
std::map<KeyCode_E, bool> KeyState;
|
||||
Configuration &Config;
|
||||
const Uint8 *SDLKeys;
|
||||
};
|
||||
|
||||
@ -120,8 +120,10 @@ void RetroFE::LaunchEnter()
|
||||
void RetroFE::LaunchExit()
|
||||
{
|
||||
SDL_RestoreWindow(SDL::GetWindow());
|
||||
SDL_RaiseWindow(SDL::GetWindow());
|
||||
SDL_SetWindowGrab(SDL::GetWindow(), SDL_TRUE);
|
||||
|
||||
Input.ResetKeyStates();
|
||||
Attract.Reset();
|
||||
if(CurrentPage)
|
||||
{
|
||||
CurrentPage->LaunchExit();
|
||||
@ -386,50 +388,50 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
|
||||
SDL_Event e;
|
||||
bool exit = false;
|
||||
RETROFE_STATE state = RETROFE_IDLE;
|
||||
|
||||
if (SDL_PollEvent(&e) == 0) return state;
|
||||
|
||||
if(e.type == SDL_KEYDOWN || e.type == SDL_KEYUP)
|
||||
{
|
||||
const Uint8 *keys = SDL_GetKeyboardState(NULL);
|
||||
SDL_Scancode scancode = SDL_GetScancodeFromKey(e.key.keysym.sym);
|
||||
Input.SetKeyState(scancode, (e.type == SDL_KEYDOWN) ? true : false);
|
||||
|
||||
Attract.Reset();
|
||||
|
||||
if(page->IsHorizontalScroll())
|
||||
if(page->IsHorizontalScroll())
|
||||
{
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeLeft)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodeLeft))
|
||||
{
|
||||
page->SetScrolling(Page::ScrollDirectionBack);
|
||||
}
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeRight)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodeRight))
|
||||
{
|
||||
page->SetScrolling(Page::ScrollDirectionForward);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeUp)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodeUp))
|
||||
{
|
||||
page->SetScrolling(Page::ScrollDirectionBack);
|
||||
}
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeDown)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodeDown))
|
||||
{
|
||||
page->SetScrolling(Page::ScrollDirectionForward);
|
||||
}
|
||||
}
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodePageUp)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodePageUp))
|
||||
{
|
||||
page->PageScroll(Page::ScrollDirectionBack);
|
||||
}
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodePageDown)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodePageDown))
|
||||
{
|
||||
page->PageScroll(Page::ScrollDirectionForward);
|
||||
}
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeAdminMode)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodeAdminMode))
|
||||
{
|
||||
//todo: add admin mode support
|
||||
}
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeSelect)] && page->IsMenuIdle())
|
||||
if (Input.GetKeyState(UserInput::KeyCodeSelect) && page->IsMenuIdle())
|
||||
{
|
||||
NextPageItem = page->GetSelectedItem();
|
||||
|
||||
@ -453,7 +455,7 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
|
||||
}
|
||||
}
|
||||
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeBack)] && page->IsMenuIdle())
|
||||
if (Input.GetKeyState(UserInput::KeyCodeBack) && page->IsMenuIdle())
|
||||
{
|
||||
if(Back(exit) || exit)
|
||||
{
|
||||
@ -461,17 +463,17 @@ RetroFE::RETROFE_STATE RetroFE::ProcessUserInput(Page *page)
|
||||
}
|
||||
}
|
||||
|
||||
if (keys[Input.GetScancode(UserInput::KeyCodeQuit)])
|
||||
if (Input.GetKeyState(UserInput::KeyCodeQuit))
|
||||
{
|
||||
state = RETROFE_QUIT_REQUEST;
|
||||
}
|
||||
|
||||
if(!keys[Input.GetScancode(UserInput::KeyCodeUp)] &&
|
||||
!keys[Input.GetScancode(UserInput::KeyCodeLeft)] &&
|
||||
!keys[Input.GetScancode(UserInput::KeyCodeDown)] &&
|
||||
!keys[Input.GetScancode(UserInput::KeyCodeRight)] &&
|
||||
!keys[Input.GetScancode(UserInput::KeyCodePageUp)] &&
|
||||
!keys[Input.GetScancode(UserInput::KeyCodePageDown)])
|
||||
if(!Input.GetKeyState(UserInput::KeyCodeUp) &&
|
||||
!Input.GetKeyState(UserInput::KeyCodeLeft) &&
|
||||
!Input.GetKeyState(UserInput::KeyCodeDown) &&
|
||||
!Input.GetKeyState(UserInput::KeyCodeRight) &&
|
||||
!Input.GetKeyState(UserInput::KeyCodePageUp) &&
|
||||
!Input.GetKeyState(UserInput::KeyCodePageDown))
|
||||
{
|
||||
page->SetScrolling(Page::ScrollDirectionIdle);
|
||||
}
|
||||
|
||||
@ -135,7 +135,11 @@ bool SDL::Initialize(Configuration &config)
|
||||
|
||||
if (retVal && Fullscreen)
|
||||
{
|
||||
#ifdef WIN32
|
||||
windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
#else
|
||||
windowFlags |= SDL_WINDOW_FULLSCREEN;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(retVal)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user