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

@ -1,7 +1,3 @@
#include "../ControllerInterface.h"
#ifdef CIFACE_USE_XLIB
#include "Xlib.h"
namespace ciface
@ -9,48 +5,48 @@ namespace ciface
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
// 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) );
// this is probably dumb
for ( KeySym i = 0; i < 1024; ++i )
int min_keycode, max_keycode;
XDisplayKeycodes(m_display, &min_keycode, &max_keycode);
for (int i = min_keycode; i <= max_keycode; ++i)
{
if ( XKeysymToString( m_keysym ) ) // if it isnt NULL
inputs.push_back( new Key( i ) );
Key *temp_key = new Key(m_display, i);
if (temp_key->m_keyname.length())
inputs.push_back(temp_key);
else
delete temp_key;
}
}
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()
{
XQueryKeymap( m_display, m_state.keyboard );
XQueryKeymap(m_display, m_state.keyboard);
// 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 );
return (state->keyboard[key_code/8] & (1 << (key_code%8))); // need >0 ?
int i = 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
{
return XKeysymToString( m_keysym );
return m_keyname;
}
}
}
#endif

View File

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