Skip to content

Commit

Permalink
Merge pull request #2010 from skidau/hotkey-input-fixes
Browse files Browse the repository at this point in the history
Hotkey fixes
  • Loading branch information
skidau committed Feb 4, 2015
2 parents 5e64573 + 3709a1c commit 012a4c1
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
20 changes: 14 additions & 6 deletions Source/Core/Core/Core.cpp
Expand Up @@ -361,8 +361,13 @@ void EmuThread()
return;
}

Keyboard::Initialize(s_window_handle);
Pad::Initialize(s_window_handle);
bool init_controllers = false;
if (!g_controller_interface.IsInit())
{
Pad::Initialize(s_window_handle);
Keyboard::Initialize(s_window_handle);
init_controllers = true;
}

// Load and Init Wiimotes - only if we are booting in Wii mode
if (core_parameter.bWii)
Expand Down Expand Up @@ -479,10 +484,13 @@ void EmuThread()
HW::Shutdown();
INFO_LOG(CONSOLE, "%s", StopMessage(false, "HW shutdown").c_str());

Wiimote::Shutdown();

Keyboard::Shutdown();
Pad::Shutdown();
if (init_controllers)
{
Wiimote::Shutdown();
Keyboard::Shutdown();
Pad::Shutdown();
init_controllers = false;
}

g_video_backend->Shutdown();
AudioCommon::ShutdownSoundStream();
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/HW/GCKeyboard.cpp
Expand Up @@ -35,8 +35,9 @@ void Shutdown()
// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd)
{
for (unsigned int i=0; i<4; ++i)
s_config.controllers.push_back(new GCKeyboard(i));
if (s_config.controllers.empty())
for (unsigned int i = 0; i < 4; ++i)
s_config.controllers.push_back(new GCKeyboard(i));

g_controller_interface.Initialize(hwnd);

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/HW/GCPad.cpp
Expand Up @@ -36,8 +36,9 @@ void Shutdown()
void Initialize(void* const hwnd)
{
// add 4 gcpads
for (unsigned int i=0; i<4; ++i)
s_config.controllers.push_back(new GCPad(i));
if (s_config.controllers.empty())
for (unsigned int i = 0; i < 4; ++i)
s_config.controllers.push_back(new GCPad(i));

g_controller_interface.Initialize(hwnd);

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/HW/Wiimote.cpp
Expand Up @@ -40,8 +40,9 @@ void Shutdown()
void Initialize(void* const hwnd, bool wait)
{
// add 4 Wiimotes
for (unsigned int i = WIIMOTE_CHAN_0; i<MAX_BBMOTES; ++i)
s_config.controllers.push_back(new WiimoteEmu::Wiimote(i));
if (s_config.controllers.empty())
for (unsigned int i = WIIMOTE_CHAN_0; i < MAX_BBMOTES; ++i)
s_config.controllers.push_back(new WiimoteEmu::Wiimote(i));

g_controller_interface.Initialize(hwnd);

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/HotkeyManager.cpp
Expand Up @@ -48,7 +48,7 @@ const std::string hotkey_labels[] =
_trans("Change Disc"),
_trans("Refresh List"),

_trans("Play/Pause"),
_trans("Toggle Pause"),
_trans("Stop"),
_trans("Reset"),
_trans("Frame Advance"),
Expand Down Expand Up @@ -205,7 +205,8 @@ bool IsPressed(int Id, bool held)

void Initialize(void* const hwnd)
{
s_config.controllers.push_back(new HotkeyManager());
if (s_config.controllers.empty())
s_config.controllers.push_back(new HotkeyManager());

g_controller_interface.Initialize(hwnd);

Expand Down
22 changes: 19 additions & 3 deletions Source/Core/DolphinWX/Frame.cpp
Expand Up @@ -50,6 +50,9 @@
#include "Core/Movie.h"
#include "Core/State.h"
#include "Core/HW/DVDInterface.h"
#include "Core/HW/GCKeyboard.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/Wiimote.h"

#include "DolphinWX/Frame.h"
#include "DolphinWX/GameListCtrl.h"
Expand Down Expand Up @@ -345,15 +348,21 @@ END_EVENT_TABLE()
// Creation and close, quit functions


bool CFrame::InitHotkeys()
bool CFrame::InitControllers()
{
if (!g_controller_interface.IsInit())
{
#if defined(HAVE_X11) && HAVE_X11
Window win = X11Utils::XWindowFromHandle(GetHandle());
HotkeyManagerEmu::Initialize(reinterpret_cast<void*>(win));
Pad::Initialize(reinterpret_cast<void*>(win));
Keyboard::Initialize(reinterpret_cast<void*>(win));
Wiimote::Initialize(reinterpret_cast<void*>(win));
#else
HotkeyManagerEmu::Initialize(reinterpret_cast<void*>(GetHandle()));
Pad::Initialize(reinterpret_cast<void*>(GetHandle()));
Keyboard::Initialize(reinterpret_cast<void*>(GetHandle()));
Wiimote::Initialize(reinterpret_cast<void*>(GetHandle()));
#endif
return true;
}
Expand Down Expand Up @@ -497,7 +506,7 @@ CFrame::CFrame(wxFrame* parent,
g_pCodeWindow->UpdateButtonStates();

// check if game is running
m_bHotkeysInit = InitHotkeys();
m_bHotkeysInit = InitControllers();

m_poll_hotkey_timer = new wxTimer(this);
Bind(wxEVT_TIMER, &CFrame::PollHotkeys, this);
Expand All @@ -510,7 +519,11 @@ CFrame::~CFrame()

if (m_bHotkeysInit)
{
Wiimote::Shutdown();
Keyboard::Shutdown();
Pad::Shutdown();
HotkeyManagerEmu::Shutdown();
m_bHotkeysInit = false;
}

drives.clear();
Expand Down Expand Up @@ -938,6 +951,9 @@ void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event))

static bool IsHotkey(wxKeyEvent &event, int Id, bool keyUp = false)
{
if (Core::GetState() == Core::CORE_UNINITIALIZED)
return false;

// Input event hotkey
if (event.GetKeyCode() == WXK_NONE)
{
Expand Down Expand Up @@ -1261,7 +1277,7 @@ void CFrame::PollHotkeys(wxTimerEvent& event)
{
if (Core::GetState() == Core::CORE_UNINITIALIZED || Core::GetState() == Core::CORE_PAUSE)
{
InitHotkeys();
m_bHotkeysInit = InitControllers();
g_controller_interface.UpdateInput();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/Frame.h
Expand Up @@ -346,7 +346,7 @@ class CFrame : public CRenderFrame
void PollHotkeys(wxTimerEvent&);
void ParseHotkeys(wxKeyEvent &event);

bool InitHotkeys();
bool InitControllers();

// Event table
DECLARE_EVENT_TABLE();
Expand Down

0 comments on commit 012a4c1

Please sign in to comment.