Move in-game keybinding handling to a central location

Instead of handling it separately in every backend.
This commit is contained in:
Jasper St. Pierre 2013-07-21 17:54:43 -04:00
parent e742b32c65
commit 52482115e1
6 changed files with 66 additions and 209 deletions

View File

@ -143,7 +143,6 @@ enum HOST_COMM
WM_USER_STOP = 10,
WM_USER_CREATE,
WM_USER_SETCURSOR,
WM_USER_KEYDOWN,
};
// Used for notification on emulation state

View File

@ -30,6 +30,9 @@
#include "State.h"
#include "VolumeHandler.h"
#include "Movie.h"
#include "RenderBase.h"
#include "VideoConfig.h"
#include "VertexShaderManager.h"
#include "VideoBackendBase.h"
@ -873,28 +876,72 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
ConnectWiimote(WiimoteId, connect);
}
// Send the OSD hotkeys to the video backend
if (event.GetKeyCode() >= '3' && event.GetKeyCode() <= '7' && event.GetModifiers() == wxMOD_NONE)
if (g_Config.bOSDHotKey && event.GetModifiers() == wxMOD_NONE)
{
#ifdef _WIN32
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
#elif defined(HAVE_X11) && HAVE_X11
X11Utils::SendKeyEvent(X11Utils::XDisplayFromHandle(GetHandle()), event.GetKeyCode());
#endif
switch (event.GetKeyCode())
{
case '3':
OSDChoice = 1;
// Toggle native resolution
g_Config.iEFBScale = g_Config.iEFBScale + 1;
if (g_Config.iEFBScale > 7) g_Config.iEFBScale = 0;
break;
case '4':
OSDChoice = 2;
// Toggle aspect ratio
g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
break;
case '5':
OSDChoice = 3;
// Toggle EFB copy
if (!g_Config.bEFBCopyEnable || g_Config.bCopyEFBToTexture)
{
g_Config.bEFBCopyEnable ^= true;
g_Config.bCopyEFBToTexture = false;
}
else
{
g_Config.bCopyEFBToTexture = !g_Config.bCopyEFBToTexture;
}
break;
case '6':
OSDChoice = 4;
g_Config.bDisableFog = !g_Config.bDisableFog;
break;
default:
break;
}
}
// Send the freelook hotkeys to the video backend
if ((event.GetKeyCode() == ')' || event.GetKeyCode() == '(' ||
event.GetKeyCode() == '0' || event.GetKeyCode() == '9' ||
event.GetKeyCode() == 'W' || event.GetKeyCode() == 'S' ||
event.GetKeyCode() == 'A' || event.GetKeyCode() == 'D' ||
event.GetKeyCode() == 'R')
&& event.GetModifiers() == wxMOD_SHIFT)
if (g_Config.bFreeLook && event.GetModifiers() == wxMOD_SHIFT)
{
#ifdef _WIN32
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
#elif defined(HAVE_X11) && HAVE_X11
X11Utils::SendKeyEvent(X11Utils::XDisplayFromHandle(GetHandle()), event.GetKeyCode());
#endif
static float debugSpeed = 1.0f;
switch (event.GetKeyCode())
{
case '9':
debugSpeed /= 2.0f;
break;
case '0':
debugSpeed *= 2.0f;
break;
case 'W':
VertexShaderManager::TranslateView(0.0f, debugSpeed);
break;
case 'S':
VertexShaderManager::TranslateView(0.0f, -debugSpeed);
break;
case 'A':
VertexShaderManager::TranslateView(debugSpeed, 0.0f);
break;
case 'D':
VertexShaderManager::TranslateView(-debugSpeed, 0.0f);
break;
case 'R':
VertexShaderManager::ResetView();
break;
default:
break;
}
}
}
else

View File

@ -16,7 +16,6 @@
// http://code.google.com/p/dolphin-emu/
#include "Host.h"
#include "RenderBase.h"
#include "VideoConfig.h"
#include "../GLInterface.h"
#include "VertexShaderManager.h"
@ -174,82 +173,10 @@ void cX11Window::XEventThread()
while (GLWin.win)
{
XEvent event;
KeySym key;
for (int num_events = XPending(GLWin.evdpy); num_events > 0; num_events--)
{
XNextEvent(GLWin.evdpy, &event);
switch(event.type) {
case KeyPress:
key = XLookupKeysym((XKeyEvent*)&event, 0);
if (g_Config.bOSDHotKey)
{
switch (key)
{
case XK_3:
OSDChoice = 1;
// Toggle native resolution
g_Config.iEFBScale = g_Config.iEFBScale + 1;
if (g_Config.iEFBScale > 7) g_Config.iEFBScale = 0;
break;
case XK_4:
OSDChoice = 2;
// Toggle aspect ratio
g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
break;
case XK_5:
OSDChoice = 3;
// Toggle EFB copy
if (!g_Config.bEFBCopyEnable || g_Config.bCopyEFBToTexture)
{
g_Config.bEFBCopyEnable ^= true;
g_Config.bCopyEFBToTexture = false;
}
else
{
g_Config.bCopyEFBToTexture = !g_Config.bCopyEFBToTexture;
}
break;
case XK_6:
OSDChoice = 4;
g_Config.bDisableFog = !g_Config.bDisableFog;
break;
default:
break;
}
}
if (g_Config.bFreeLook)
{
static float debugSpeed = 1.0f;
switch (key)
{
case XK_parenleft:
debugSpeed /= 2.0f;
break;
case XK_parenright:
debugSpeed *= 2.0f;
break;
case XK_w:
VertexShaderManager::TranslateView(0.0f, debugSpeed);
break;
case XK_s:
VertexShaderManager::TranslateView(0.0f, -debugSpeed);
break;
case XK_a:
VertexShaderManager::TranslateView(debugSpeed, 0.0f);
break;
case XK_d:
VertexShaderManager::TranslateView(-debugSpeed, 0.0f);
break;
case XK_r:
VertexShaderManager::ResetView();
break;
}
}
break;
case ButtonPress:
if (g_Config.bFreeLook)
{

View File

@ -32,22 +32,6 @@ extern char **environ;
namespace X11Utils
{
void SendKeyEvent(Display *dpy, int key)
{
XEvent event;
Window win = (Window)Core::GetWindowHandle();
// Init X event structure for key press event
event.xkey.type = KeyPress;
// WARNING: This works for ASCII keys. If in the future other keys are needed
// convert with InputCommon::wxCharCodeWXToX from X11InputBase.cpp.
event.xkey.keycode = XKeysymToKeycode(dpy, key);
// Send the event
if (!XSendEvent(dpy, win, False, False, &event))
ERROR_LOG(VIDEO, "Failed to send key press event to the emulator window.");
}
void SendButtonEvent(Display *dpy, int button, int x, int y, bool pressed)
{
XEvent event;

View File

@ -43,7 +43,6 @@
namespace X11Utils
{
void SendKeyEvent(Display *dpy, int key);
void SendButtonEvent(Display *dpy, int button, int x, int y, bool pressed);
void SendMotionEvent(Display *dpy, int x, int y);
void EWMH_Fullscreen(Display *dpy, int action);

View File

@ -8,7 +8,6 @@
#include "EmuWindow.h"
#include "Fifo.h"
#include "VertexShaderManager.h"
#include "RenderBase.h"
#include "VideoBackendBase.h"
#include "Core.h"
#include "Host.h"
@ -42,28 +41,8 @@ HWND GetParentWnd()
return m_hParent;
}
// ---------------------------------------------------------------------
// KeyDown events
// -------------
void OnKeyDown(WPARAM wParam)
{
switch (LOWORD( wParam ))
{
case '3': // OSD keys
case '4':
case '5':
case '6':
case '7':
if (g_Config.bOSDHotKey)
OSDMenu(wParam);
break;
}
}
// ---------------------------------------------------------------------
void FreeLookInput( UINT iMsg, WPARAM wParam )
{
static float debugSpeed = 1.0f;
static bool mouseLookEnabled = false;
static bool mouseMoveEnabled = false;
static float lastMouse[2];
@ -71,34 +50,6 @@ void FreeLookInput( UINT iMsg, WPARAM wParam )
switch(iMsg)
{
case WM_USER_KEYDOWN:
case WM_KEYDOWN:
switch (LOWORD(wParam))
{
case '9':
debugSpeed /= 2.0f;
break;
case '0':
debugSpeed *= 2.0f;
break;
case 'W':
VertexShaderManager::TranslateView(0.0f, debugSpeed);
break;
case 'S':
VertexShaderManager::TranslateView(0.0f, -debugSpeed);
break;
case 'A':
VertexShaderManager::TranslateView(debugSpeed, 0.0f);
break;
case 'D':
VertexShaderManager::TranslateView(-debugSpeed, 0.0f);
break;
case 'R':
VertexShaderManager::ResetView();
break;
}
break;
case WM_MOUSEMOVE:
if (mouseLookEnabled)
{
@ -190,11 +141,6 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
break;
case WM_USER:
if (wParam == WM_USER_KEYDOWN)
{
OnKeyDown(lParam);
FreeLookInput((u32)wParam, lParam);
}
break;
// Called when a screensaver wants to show up while this window is active
@ -224,51 +170,6 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
return 0;
}
// ---------------------------------------------------------------------
// OSD Menu
// -------------
// Let's begin with 3 since 1 and 2 are default Wii keys
// -------------
void OSDMenu(WPARAM wParam)
{
switch( LOWORD( wParam ))
{
case '3':
OSDChoice = 1;
// Toggle native resolution
g_Config.iEFBScale = g_Config.iEFBScale + 1;
if (g_Config.iEFBScale > SCALE_4X) g_Config.iEFBScale = SCALE_AUTO;
break;
case '4':
OSDChoice = 2;
// Toggle aspect ratio
g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
break;
case '5':
OSDChoice = 3;
// Toggle EFB copy
if (!g_Config.bEFBCopyEnable)
{
g_Config.bEFBCopyEnable = true;
g_Config.bCopyEFBToTexture = false;
}
else if (!g_Config.bCopyEFBToTexture)
{
g_Config.bCopyEFBToTexture = true;
}
else
{
g_Config.bEFBCopyEnable = false;
g_Config.bCopyEFBToTexture = false;
}
break;
case '6':
OSDChoice = 4;
g_Config.bDisableFog = !g_Config.bDisableFog;
break;
}
}
HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const TCHAR *title)
{
wndClass.cbSize = sizeof( wndClass );