Get GCPadNew keyboard working in linux. Also some code cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5320 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2010-04-10 20:44:56 +00:00
parent d00f5b20a1
commit a5edf59787
7 changed files with 128 additions and 93 deletions

View File

@ -805,38 +805,39 @@ void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event))
void CFrame::OnKeyDown(wxKeyEvent& event) void CFrame::OnKeyDown(wxKeyEvent& event)
{ {
// Toggle fullscreen if(Core::GetState() != Core::CORE_UNINITIALIZED)
if (event.GetKeyCode() == WXK_RETURN && event.GetModifiers() == wxMOD_ALT)
{ {
DoFullscreen(!IsFullScreen()); // Toggle fullscreen
if (event.GetKeyCode() == WXK_RETURN && event.GetModifiers() == wxMOD_ALT)
{
DoFullscreen(!IsFullScreen());
// We do that to avoid the event to be double processed (which would cause the window to be stuck in fullscreen) // We do that to avoid the event to be double processed (which would cause the window to be stuck in fullscreen)
event.StopPropagation(); event.StopPropagation();
} }
else if(event.GetKeyCode() == WXK_ESCAPE) else if(event.GetKeyCode() == WXK_ESCAPE)
{ {
main_frame->DoPause(); main_frame->DoPause();
} }
// event.Skip() allows the event to propagate to the gamelist for example // event.Skip() allows the event to propagate to the gamelist for example
else if (! (Core::GetState() == Core::CORE_RUN && bRenderToMain && event.GetEventObject() == this)) else if (! (Core::GetState() == Core::CORE_RUN && bRenderToMain && event.GetEventObject() == this))
event.Skip(); event.Skip();
#ifdef _WIN32 #ifdef _WIN32
if(event.GetKeyCode() == 'M', '3', '4', '5', '6', '7') // Send this to the video plugin WndProc if(event.GetKeyCode() == 'M', '3', '4', '5', '6', '7') // Send this to the video plugin WndProc
{ {
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode()); PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
} }
#elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_GTK2) && HAVE_GTK2 && defined(wxGTK) #elif defined(HAVE_X11) && HAVE_X11 && defined(HAVE_GTK2) && HAVE_GTK2 && defined(wxGTK)
if (event.GetKeyCode() >= '3' && event.GetKeyCode() <= '7') // Send this to the video plugin if (event.GetKeyCode() >= '3' && event.GetKeyCode() <= '7') // Send this to the video plugin
{ {
X11_SendKeyEvent(event.GetKeyCode()); X11_SendKeyEvent(event.GetKeyCode());
} }
#endif #endif
// Send the keyboard status to the Input plugin
// Send the keyboard status to the Input plugin CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 1); // 1 = Down
if(Core::GetState() != Core::CORE_UNINITIALIZED) }
CPluginManager::GetInstance().GetPad(0)->PAD_Input(event.GetKeyCode(), 1); // 1 = Down
} }
void CFrame::OnKeyUp(wxKeyEvent& event) void CFrame::OnKeyUp(wxKeyEvent& event)

View File

@ -2,8 +2,8 @@
#include "ConfigDiag.h" #include "ConfigDiag.h"
PadSettingCheckBox::PadSettingCheckBox( wxWindow* const parent, ControlState& _value, const char* const label ) PadSettingCheckBox::PadSettingCheckBox( wxWindow* const parent, ControlState& _value, const char* const label )
: wxCheckBox( parent, -1, wxString::FromAscii( label ), wxDefaultPosition ) : PadSetting(_value)
, PadSetting(_value) , wxCheckBox( parent, -1, wxString::FromAscii( label ), wxDefaultPosition )
{ {
UpdateGUI(); UpdateGUI();
} }
@ -20,8 +20,8 @@ void PadSettingCheckBox::UpdateValue()
} }
PadSettingChoice::PadSettingChoice( wxWindow* const parent, ControlState& _value, int min, int max ) PadSettingChoice::PadSettingChoice( wxWindow* const parent, ControlState& _value, int min, int max )
: wxChoice( parent, -1, wxDefaultPosition, wxSize( 48, -1 ) ) : PadSetting(_value)
, PadSetting(_value) , wxChoice( parent, -1, wxDefaultPosition, wxSize( 48, -1 ) )
{ {
Append( wxT("0") ); Append( wxT("0") );
for ( ; min<=max; ++min ) for ( ; min<=max; ++min )
@ -362,17 +362,19 @@ void ControlDialog::SelectControl( wxCommandEvent& event )
// final_label = "||"; // final_label = "||";
else else
{ {
final_label = wxT('|'); final_label = wxT('|');
for ( unsigned int i=0; i<sels.size(); ++i ) for ( unsigned int i=0; i<sels.size(); ++i )
final_label += names[ sels[i] ] + wxT('|'); final_label += names[ sels[i] ] + wxT('|');
} }
if (!final_label.CompareTo(wxT("|")))
final_label.Empty();
control_chooser->textctrl->SetLabel( final_label ); control_chooser->textctrl->SetLabel( final_label );
// kinda dumb // kinda dumb
wxCommandEvent nullevent; wxCommandEvent nullevent;
((GamepadPage*)m_parent)->SetControl( nullevent ); ((GamepadPage*)m_parent)->SetControl( nullevent );
} }
ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink ) ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::ControlReference* const ref, wxWindow* const eventsink )
@ -422,7 +424,7 @@ ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::Con
txtbox_szr->Add( textctrl, 1, wxEXPAND, 0 ); txtbox_szr->Add( textctrl, 1, wxEXPAND, 0 );
wxBoxSizer* mode_szr; wxBoxSizer* mode_szr = NULL;
if ( control_reference->is_input ) if ( control_reference->is_input )
{ {
mode_cbox = new wxChoice( parent, -1 ); mode_cbox = new wxChoice( parent, -1 );

View File

@ -238,7 +238,7 @@ ControlState ControllerInterface::InputReference::State( const ControlState igno
if ( NULL == device ) if ( NULL == device )
return 0; return 0;
ControlState state; ControlState state = 0;
// this mode thing will be turned into a switch statement // this mode thing will be turned into a switch statement
switch ( mode ) switch ( mode )
{ {
@ -360,11 +360,7 @@ void ControllerInterface::DeviceQualifier::FromDevice(const ControllerInterface:
// //
bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface::Device* const dev) const bool ControllerInterface::DeviceQualifier::operator==(const ControllerInterface::Device* const dev) const
{ {
if ( dev->GetName() == name ) return (dev->GetName() == name) && (dev->GetId() == cid) && (dev->GetSource() == source);
if ( dev->GetId() == cid )
if ( dev->GetSource() == source )
return true;
return false;
} }
// //

View File

@ -6,6 +6,7 @@
#include <sstream> #include <sstream>
#include <map> #include <map>
#include <algorithm> #include <algorithm>
#include "Common.h"
// enable disable sources // enable disable sources
#ifdef _WIN32 #ifdef _WIN32

View File

@ -1,7 +1,3 @@
#include "../ControllerInterface.h"
#ifdef CIFACE_USE_XLIB
#include "Xlib.h" #include "Xlib.h"
namespace ciface namespace ciface
@ -9,48 +5,48 @@ namespace ciface
namespace Xlib namespace Xlib
{ {
void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd)
void Init( std::vector<ControllerInterface::Device*>& devices, void* const hwnd )
{ {
// mouse will be added to this, Keyboard class will be turned into KeyboardMouse // mouse will be added to this, Keyboard class will be turned into KeyboardMouse
// single device for combined keyboard/mouse, this will allow combinations like shift+click more easily // single device for combined keyboard/mouse, this will allow combinations like shift+click more easily
devices.push_back( new Keyboard( (Display*)hwnd ) ); devices.push_back(new Keyboard((Display*)hwnd));
} }
Keyboard::Keyboard( Display* const display ) : m_display(display) Keyboard::Keyboard(Display* display) : m_display(display)
{ {
memset(&m_state, 0, sizeof(m_state));
memset( &m_state, 0, sizeof(m_state) ); int min_keycode, max_keycode;
XDisplayKeycodes(m_display, &min_keycode, &max_keycode);
// this is probably dumb
for ( KeySym i = 0; i < 1024; ++i ) for (int i = min_keycode; i <= max_keycode; ++i)
{ {
if ( XKeysymToString( m_keysym ) ) // if it isnt NULL Key *temp_key = new Key(m_display, i);
inputs.push_back( new Key( i ) ); if (temp_key->m_keyname.length())
inputs.push_back(temp_key);
else
delete temp_key;
} }
} }
Keyboard::~Keyboard() Keyboard::~Keyboard()
{ {
// might not need this func
} }
ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input ) ControlState Keyboard::GetInputState(const ControllerInterface::Device::Input* const input)
{ {
return ((Input*)input)->GetState( &m_state ); return ((Input*)input)->GetState(&m_state);
} }
void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ) void Keyboard::SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state)
{ {
} }
bool Keyboard::UpdateInput() bool Keyboard::UpdateInput()
{ {
XQueryKeymap( m_display, m_state.keyboard ); XQueryKeymap(m_display, m_state.keyboard);
// mouse stuff in here too // mouse stuff in here too
@ -80,19 +76,33 @@ int Keyboard::GetId() const
} }
ControlState Keyboard::Key::GetState( const State* const state ) Keyboard::Key::Key(Display* const display, KeyCode keycode)
: m_display(display), m_keycode(keycode)
{ {
key_code = XKeysymToKeycode(m_display, m_keysym ); int i = 0;
return (state->keyboard[key_code/8] & (1 << (key_code%8))); // need >0 ? KeySym keysym = 0;
do
{
keysym = XKeycodeToKeysym(m_display, keycode, i);
i++;
}
while (keysym == NoSymbol && i < 8);
if (keysym == NoSymbol)
m_keyname = std::string();
else
m_keyname = std::string(XKeysymToString(keysym));
}
ControlState Keyboard::Key::GetState(const State* const state)
{
return state->keyboard[m_keycode/8] & (1 << (m_keycode%8));
} }
std::string Keyboard::Key::GetName() const std::string Keyboard::Key::GetName() const
{ {
return XKeysymToString( m_keysym ); return m_keyname;
} }
} }
} }
#endif

View File

@ -7,17 +7,17 @@
namespace ciface namespace ciface
{ {
namespace XInput namespace Xlib
{ {
void Init( std::vector<ControllerInterface::Device*>& devices, void* const hwnd ); void Init(std::vector<ControllerInterface::Device*>& devices, void* const hwnd);
class Keyboard : public ControllerInterface::Device class Keyboard : public ControllerInterface::Device
{ {
friend class ControllerInterface; friend class ControllerInterface;
friend class ControllerInterface::ControlReference; friend class ControllerInterface::ControlReference;
protected: protected:
struct State struct State
{ {
@ -25,42 +25,48 @@ protected:
// mouse crap will go here // mouse crap will go here
}; };
class Input : public ControllerInterface::Input class Input : public ControllerInterface::Device::Input
{ {
friend class Keyboard; friend class Keyboard;
protected:
ControlState GetState( const State* const state ) = 0; protected:
} virtual ControlState GetState(const State* const state) = 0;
};
class Key : public Input class Key : public Input
{ {
friend class Keyboard; friend class Keyboard;
public:
public:
std::string GetName() const; std::string GetName() const;
protected:
Key( KeySym keysym ) : m_keysym(keysym) {} protected:
ControlState GetState( const State* const state ); Key(Display* const display, KeyCode keycode);
private: ControlState GetState(const State* const state);
const KeySym m_keysym
private:
Display* const m_display;
const KeyCode m_keycode;
std::string m_keyname;
}; };
bool UpdateInput(); bool UpdateInput();
bool UpdateOutput(); bool UpdateOutput();
ControlState Keyboard::GetInputState( const ControllerInterface::Device::Input* const input ); ControlState GetInputState(const ControllerInterface::Device::Input* const input);
void Keyboard::SetOutputState( const ControllerInterface::Device::Output* const output, const ControlState state ); void SetOutputState(const ControllerInterface::Device::Output* const output, const ControlState state);
public: public:
Keyboard( Display* const display ); Keyboard(Display* display);
~Keyboard(); ~Keyboard();
std::string GetName() const; std::string GetName() const;
std::string GetSource() const; std::string GetSource() const;
int GetId() const; int GetId() const;
private: private:
Display* const m_display; Display* m_display;
State m_state; State m_state;
}; };

View File

@ -56,12 +56,14 @@ bool IsFocus()
#elif defined HAVE_X11 && HAVE_X11 #elif defined HAVE_X11 && HAVE_X11
Display* GCdisplay = (Display*)g_PADInitialize->hWnd; Display* GCdisplay = (Display*)g_PADInitialize->hWnd;
Window GLWin = *(Window *)g_PADInitialize->pXWindow; Window GLWin = *(Window *)g_PADInitialize->pXWindow;
bool bFocus = False;
#if defined(HAVE_GTK2) && HAVE_GTK2 && defined(wxGTK)
bFocus = (wxPanel *)g_PADInitialize->pPanel == wxWindow::FindFocus();
#endif
Window FocusWin; Window FocusWin;
int Revert; int Revert;
XGetInputFocus(GCdisplay, &FocusWin, &Revert); XGetInputFocus(GCdisplay, &FocusWin, &Revert);
XWindowAttributes WinAttribs; return (GLWin == FocusWin || bFocus);
XGetWindowAttributes (GCdisplay, GLWin, &WinAttribs);
return (GLWin != 0 && (GLWin == FocusWin || WinAttribs.override_redirect));
#else #else
return true; return true;
#endif #endif
@ -181,8 +183,10 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// if we want background input or have focus // if we want background input or have focus
if ( g_plugin.controllers[_numPAD]->options[0].settings[0]->value || IsFocus() ) if ( g_plugin.controllers[_numPAD]->options[0].settings[0]->value || IsFocus() )
{
// get input // get input
((GCPad*)g_plugin.controllers[ _numPAD ])->GetInput( _pPADStatus ); ((GCPad*)g_plugin.controllers[ _numPAD ])->GetInput( _pPADStatus );
}
else else
{ {
// center sticks // center sticks
@ -256,10 +260,20 @@ void GetDllInfo(PLUGIN_INFO* _pPluginInfo)
void DllConfig(HWND _hParent) void DllConfig(HWND _hParent)
{ {
bool was_init = false; bool was_init = false;
#if defined(HAVE_X11) && HAVE_X11
Display *dpy = NULL;
#endif
if ( g_plugin.controller_interface.IsInit() ) // hack for showing dialog when game isnt running if ( g_plugin.controller_interface.IsInit() ) // hack for showing dialog when game isnt running
was_init = true; was_init = true;
else else
InitPlugin( _hParent ); {
#if defined(HAVE_X11) && HAVE_X11
dpy = XOpenDisplay(0);
InitPlugin(dpy);
#else
InitPlugin(_hParent);
#endif
}
// copied from GCPad // copied from GCPad
#if defined(HAVE_WX) && HAVE_WX #if defined(HAVE_WX) && HAVE_WX
@ -286,8 +300,13 @@ void DllConfig(HWND _hParent)
#endif #endif
// / // /
if ( false == was_init ) // hack for showing dialog when game isnt running if ( !was_init ) // hack for showing dialog when game isnt running
{
#if defined(HAVE_X11) && HAVE_X11
XCloseDisplay(dpy);
#endif
g_plugin.controller_interface.DeInit(); g_plugin.controller_interface.DeInit();
}
} }
// ___________________________________________________________________________ // ___________________________________________________________________________