x11: support mouse wheel. ascii text keyboard input
This commit is contained in:
parent
0f5a3ab884
commit
c6baa4827b
|
@ -0,0 +1,3 @@
|
|||
#include "keyboard_device.h"
|
||||
|
||||
KeyboardDevice *KeyboardDevice::_instance;
|
|
@ -21,21 +21,37 @@
|
|||
#include "types.h"
|
||||
#include "mapping.h"
|
||||
|
||||
template <typename Keycode>
|
||||
class KeyboardDevice
|
||||
{
|
||||
public:
|
||||
virtual const char* name() = 0;
|
||||
int maple_port() { return _maple_port; }
|
||||
virtual void keyboard_input(Keycode keycode, bool pressed, int modifier_keys = 0);
|
||||
void keyboard_character(char c);
|
||||
std::string get_character_input();
|
||||
virtual ~KeyboardDevice() {}
|
||||
|
||||
static KeyboardDevice *GetInstance() { return _instance; }
|
||||
|
||||
protected:
|
||||
KeyboardDevice(int maple_port) : _maple_port(maple_port), _kb_used(0), _modifier_keys(0) {}
|
||||
virtual u8 convert_keycode(Keycode keycode) = 0;
|
||||
KeyboardDevice(int maple_port) : _maple_port(maple_port) { _instance = this; }
|
||||
|
||||
private:
|
||||
int _maple_port;
|
||||
std::string char_input;
|
||||
static KeyboardDevice *_instance;
|
||||
};
|
||||
|
||||
template <typename Keycode>
|
||||
class KeyboardDeviceTemplate : public KeyboardDevice
|
||||
{
|
||||
public:
|
||||
virtual void keyboard_input(Keycode keycode, bool pressed, int modifier_keys = 0);
|
||||
|
||||
protected:
|
||||
KeyboardDeviceTemplate(int maple_port) : KeyboardDevice(maple_port), _kb_used(0), _modifier_keys(0) {}
|
||||
virtual u8 convert_keycode(Keycode keycode) = 0;
|
||||
|
||||
private:
|
||||
int _modifier_keys;
|
||||
int _kb_used;
|
||||
};
|
||||
|
@ -44,7 +60,7 @@ extern u8 kb_key[6]; // normal keys pressed
|
|||
extern u8 kb_shift; // shift keys pressed (bitmask)
|
||||
|
||||
template <typename Keycode>
|
||||
void KeyboardDevice<Keycode>::keyboard_input(Keycode keycode, bool pressed, int modifier_keys)
|
||||
void KeyboardDeviceTemplate<Keycode>::keyboard_input(Keycode keycode, bool pressed, int modifier_keys)
|
||||
{
|
||||
u8 dc_keycode = convert_keycode(keycode);
|
||||
if (dc_keycode == 0xE1 || dc_keycode == 0xE5) // SHIFT
|
||||
|
@ -94,3 +110,13 @@ void KeyboardDevice<Keycode>::keyboard_input(Keycode keycode, bool pressed, int
|
|||
kb_shift = modifier_keys | _modifier_keys;
|
||||
}
|
||||
}
|
||||
|
||||
inline void KeyboardDevice::keyboard_character(char c) {
|
||||
char_input.push_back(c);
|
||||
}
|
||||
|
||||
inline std::string KeyboardDevice::get_character_input() {
|
||||
std::string input = char_input;
|
||||
char_input.clear();
|
||||
return input;
|
||||
}
|
||||
|
|
|
@ -212,6 +212,14 @@ void input_x11_handle()
|
|||
switch(e.type)
|
||||
{
|
||||
case KeyPress:
|
||||
{
|
||||
char buf[2];
|
||||
KeySym keysym_return;
|
||||
int len = XLookupString(&e.xkey, buf, 1, &keysym_return, NULL);
|
||||
if (len > 0)
|
||||
x11_keyboard->keyboard_character(buf[0]);
|
||||
}
|
||||
/* no break */
|
||||
case KeyRelease:
|
||||
{
|
||||
if (e.type == KeyRelease && XEventsQueued(display, QueuedAfterReading))
|
||||
|
@ -293,12 +301,26 @@ void input_x11_handle()
|
|||
mouse_gamepad->gamepad_btn_input(e.xbutton.button, e.type == ButtonPress);
|
||||
{
|
||||
u32 button_mask = 0;
|
||||
if (e.xbutton.button == Button1) // Left button
|
||||
switch (e.xbutton.button)
|
||||
{
|
||||
case Button1: // Left button
|
||||
button_mask = 1 << 2;
|
||||
else if (e.xbutton.button == Button2) // Middle button
|
||||
break;
|
||||
case Button2: // Middle button
|
||||
button_mask = 1 << 3;
|
||||
else if (e.xbutton.button == Button3) // Right button
|
||||
break;
|
||||
case Button3: // Right button
|
||||
button_mask = 1 << 1;
|
||||
break;
|
||||
case Button4: // Mouse wheel up
|
||||
mo_wheel_delta -= 16;
|
||||
break;
|
||||
case Button5: // Mouse wheel down
|
||||
mo_wheel_delta += 16;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (button_mask)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include "input/gamepad_device.h"
|
||||
#include "x11.h"
|
||||
|
||||
class X11KeyboardDevice : public KeyboardDevice<int>
|
||||
class X11KeyboardDevice : public KeyboardDeviceTemplate<int>
|
||||
{
|
||||
public:
|
||||
X11KeyboardDevice(int maple_port) : KeyboardDevice(maple_port)
|
||||
X11KeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port)
|
||||
{
|
||||
//04-1D Letter keys A-Z (in alphabetic order)
|
||||
kb_map[KEY_A] = 0x04;
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#include "input/keyboard_device.h"
|
||||
#include "sdl.h"
|
||||
|
||||
class SDLKeyboardDevice : public KeyboardDevice<SDL_Keycode>
|
||||
class SDLKeyboardDevice : public KeyboardDeviceTemplate<SDL_Keycode>
|
||||
{
|
||||
public:
|
||||
SDLKeyboardDevice(int maple_port) : KeyboardDevice(maple_port)
|
||||
SDLKeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port)
|
||||
{
|
||||
//04-1D Letter keys A-Z (in alphabetic order)
|
||||
kb_map[SDLK_a] = 0x04;
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
// Used to differentiate between main enter key and num keypad one
|
||||
#define VK_NUMPAD_RETURN 0x0E
|
||||
|
||||
class Win32KeyboardDevice : public KeyboardDevice<u8>
|
||||
class Win32KeyboardDevice : public KeyboardDeviceTemplate<u8>
|
||||
{
|
||||
public:
|
||||
Win32KeyboardDevice(int maple_port) : KeyboardDevice(maple_port)
|
||||
Win32KeyboardDevice(int maple_port) : KeyboardDeviceTemplate(maple_port)
|
||||
{
|
||||
kb_map['A'] = 0x04;
|
||||
kb_map['B'] = 0x05;
|
||||
|
|
Loading…
Reference in New Issue