Merge pull request #4179 from magcius/xinput2-default
Remove the old Xlib backend
This commit is contained in:
commit
18030ebfb4
|
@ -541,12 +541,7 @@ if(USE_X11)
|
|||
add_definitions(-DHAVE_XRANDR=0)
|
||||
endif(XRANDR_FOUND)
|
||||
|
||||
pkg_check_modules(XINPUT2 xi>=1.5.0)
|
||||
if(XINPUT2_FOUND)
|
||||
add_definitions(-DHAVE_X11_XINPUT2=1)
|
||||
else()
|
||||
add_definitions(-DHAVE_X11_XINPUT2=0)
|
||||
endif(XINPUT2_FOUND)
|
||||
pkg_check_modules(XINPUT2 REQUIRED xi>=1.5.0)
|
||||
endif()
|
||||
if(ENCODE_FRAMEDUMPS)
|
||||
check_libav()
|
||||
|
|
|
@ -4,12 +4,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// These imports need to be in this order for mbed to be included correctly.
|
||||
// clang-format off
|
||||
|
||||
#include <mbedtls/platform.h>
|
||||
#include <mbedtls/ctr_drbg.h>
|
||||
#include <mbedtls/entropy.h>
|
||||
#include <mbedtls/net.h>
|
||||
#include <mbedtls/ssl.h>
|
||||
#include <string>
|
||||
|
||||
// clang-format on
|
||||
|
||||
#include "Core/IPC_HLE/WII_IPC_HLE_Device.h"
|
||||
|
||||
#define NET_SSL_MAXINSTANCES 4
|
||||
|
|
|
@ -24,11 +24,7 @@ elseif(APPLE)
|
|||
set(LIBS ${LIBS} ${COREFOUNDATION_LIBRARY} ${CARBON_LIBRARY} ${COCOA_LIBRARY})
|
||||
elseif(X11_FOUND)
|
||||
set(SRCS ${SRCS}
|
||||
ControllerInterface/Xlib/Xlib.cpp)
|
||||
if(XINPUT2_FOUND)
|
||||
set(SRCS ${SRCS}
|
||||
ControllerInterface/Xlib/XInput2.cpp)
|
||||
endif()
|
||||
ControllerInterface/Xlib/XInput2.cpp)
|
||||
set(LIBS ${LIBS} ${X11_LIBRARIES} ${XINPUT2_LIBRARIES})
|
||||
elseif(ANDROID)
|
||||
add_definitions(-DCIFACE_USE_ANDROID)
|
||||
|
|
|
@ -14,11 +14,8 @@
|
|||
#include "InputCommon/ControllerInterface/DInput/DInput.h"
|
||||
#endif
|
||||
#ifdef CIFACE_USE_XLIB
|
||||
#include "InputCommon/ControllerInterface/Xlib/Xlib.h"
|
||||
#ifdef CIFACE_USE_X11_XINPUT2
|
||||
#include "InputCommon/ControllerInterface/Xlib/XInput2.h"
|
||||
#endif
|
||||
#endif
|
||||
#ifdef CIFACE_USE_OSX
|
||||
#include "InputCommon/ControllerInterface/OSX/OSX.h"
|
||||
#endif
|
||||
|
@ -63,11 +60,8 @@ void ControllerInterface::Initialize(void* const hwnd)
|
|||
ciface::XInput::Init();
|
||||
#endif
|
||||
#ifdef CIFACE_USE_XLIB
|
||||
ciface::Xlib::Init(hwnd);
|
||||
#ifdef CIFACE_USE_X11_XINPUT2
|
||||
ciface::XInput2::Init(hwnd);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef CIFACE_USE_OSX
|
||||
ciface::OSX::Init(hwnd);
|
||||
#endif
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
#endif
|
||||
#if defined(HAVE_X11) && HAVE_X11
|
||||
#define CIFACE_USE_XLIB
|
||||
#if defined(HAVE_X11_XINPUT2) && HAVE_X11_XINPUT2
|
||||
#define CIFACE_USE_X11_XINPUT2
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
#define CIFACE_USE_OSX
|
||||
|
|
|
@ -216,12 +216,10 @@ void KeyboardMouse::UpdateInput()
|
|||
{
|
||||
XFlush(m_display);
|
||||
|
||||
// Get the absolute position of the mouse pointer
|
||||
UpdateCursor();
|
||||
|
||||
// for the axis controls
|
||||
float delta_x = 0.0f, delta_y = 0.0f;
|
||||
double delta_delta;
|
||||
bool mouse_moved = false;
|
||||
|
||||
// Iterate through the event queue - update the axis controls, mouse
|
||||
// button controls, and keyboard controls.
|
||||
|
@ -256,6 +254,8 @@ void KeyboardMouse::UpdateInput()
|
|||
m_state.keyboard[dev_event->detail / 8] &= ~(1 << (dev_event->detail % 8));
|
||||
break;
|
||||
case XI_RawMotion:
|
||||
mouse_moved = true;
|
||||
|
||||
// always safe because there is always at least one byte in
|
||||
// raw_event->valuators.mask, and if a bit is set in the mask,
|
||||
// then the value in raw_values is also available.
|
||||
|
@ -286,6 +286,10 @@ void KeyboardMouse::UpdateInput()
|
|||
m_state.axis.y *= MOUSE_AXIS_SMOOTHING;
|
||||
m_state.axis.y += delta_y;
|
||||
m_state.axis.y /= MOUSE_AXIS_SMOOTHING + 1.0f;
|
||||
|
||||
// Get the absolute position of the mouse pointer
|
||||
if (mouse_moved)
|
||||
UpdateCursor();
|
||||
}
|
||||
|
||||
std::string KeyboardMouse::GetName() const
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
// Copyright 2010 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <X11/XKBlib.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "InputCommon/ControllerInterface/Xlib/Xlib.h"
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace Xlib
|
||||
{
|
||||
void Init(void* const hwnd)
|
||||
{
|
||||
g_controller_interface.AddDevice(std::make_shared<KeyboardMouse>((Window)hwnd));
|
||||
}
|
||||
|
||||
KeyboardMouse::KeyboardMouse(Window window) : m_window(window)
|
||||
{
|
||||
memset(&m_state, 0, sizeof(m_state));
|
||||
|
||||
m_display = XOpenDisplay(nullptr);
|
||||
|
||||
int min_keycode, max_keycode;
|
||||
XDisplayKeycodes(m_display, &min_keycode, &max_keycode);
|
||||
|
||||
// Keyboard Keys
|
||||
for (int i = min_keycode; i <= max_keycode; ++i)
|
||||
{
|
||||
Key* temp_key = new Key(m_display, i, m_state.keyboard);
|
||||
if (temp_key->m_keyname.length())
|
||||
AddInput(temp_key);
|
||||
else
|
||||
delete temp_key;
|
||||
}
|
||||
|
||||
// Mouse Buttons
|
||||
AddInput(new Button(Button1Mask, m_state.buttons));
|
||||
AddInput(new Button(Button2Mask, m_state.buttons));
|
||||
AddInput(new Button(Button3Mask, m_state.buttons));
|
||||
AddInput(new Button(Button4Mask, m_state.buttons));
|
||||
AddInput(new Button(Button5Mask, m_state.buttons));
|
||||
|
||||
// Mouse Cursor, X-/+ and Y-/+
|
||||
for (int i = 0; i != 4; ++i)
|
||||
AddInput(new Cursor(!!(i & 2), !!(i & 1), (&m_state.cursor.x)[!!(i & 2)]));
|
||||
}
|
||||
|
||||
KeyboardMouse::~KeyboardMouse()
|
||||
{
|
||||
XCloseDisplay(m_display);
|
||||
}
|
||||
|
||||
void KeyboardMouse::UpdateInput()
|
||||
{
|
||||
XQueryKeymap(m_display, m_state.keyboard);
|
||||
|
||||
int root_x, root_y, win_x, win_y;
|
||||
Window root, child;
|
||||
XQueryPointer(m_display, m_window, &root, &child, &root_x, &root_y, &win_x, &win_y,
|
||||
&m_state.buttons);
|
||||
|
||||
// update mouse cursor
|
||||
XWindowAttributes win_attribs;
|
||||
XGetWindowAttributes(m_display, m_window, &win_attribs);
|
||||
|
||||
// the mouse position as a range from -1 to 1
|
||||
m_state.cursor.x = (float)win_x / (float)win_attribs.width * 2 - 1;
|
||||
m_state.cursor.y = (float)win_y / (float)win_attribs.height * 2 - 1;
|
||||
}
|
||||
|
||||
std::string KeyboardMouse::GetName() const
|
||||
{
|
||||
return "Keyboard Mouse";
|
||||
}
|
||||
|
||||
std::string KeyboardMouse::GetSource() const
|
||||
{
|
||||
return "Xlib";
|
||||
}
|
||||
|
||||
KeyboardMouse::Key::Key(Display* const display, KeyCode keycode, const char* keyboard)
|
||||
: m_display(display), m_keyboard(keyboard), m_keycode(keycode)
|
||||
{
|
||||
int i = 0;
|
||||
KeySym keysym = 0;
|
||||
do
|
||||
{
|
||||
keysym = XkbKeycodeToKeysym(m_display, keycode, i, 0);
|
||||
i++;
|
||||
} while (keysym == NoSymbol && i < 8);
|
||||
|
||||
// Convert to upper case for the keyname
|
||||
if (keysym >= 97 && keysym <= 122)
|
||||
keysym -= 32;
|
||||
|
||||
// 0x0110ffff is the top of the unicode character range according
|
||||
// to keysymdef.h although it is probably more than we need.
|
||||
if (keysym == NoSymbol || keysym > 0x0110ffff || XKeysymToString(keysym) == nullptr)
|
||||
m_keyname = std::string();
|
||||
else
|
||||
m_keyname = std::string(XKeysymToString(keysym));
|
||||
}
|
||||
|
||||
ControlState KeyboardMouse::Key::GetState() const
|
||||
{
|
||||
return (m_keyboard[m_keycode / 8] & (1 << (m_keycode % 8))) != 0;
|
||||
}
|
||||
|
||||
ControlState KeyboardMouse::Button::GetState() const
|
||||
{
|
||||
return ((m_buttons & m_index) != 0);
|
||||
}
|
||||
|
||||
ControlState KeyboardMouse::Cursor::GetState() const
|
||||
{
|
||||
return std::max(0.0f, m_cursor / (m_positive ? 1.0f : -1.0f));
|
||||
}
|
||||
|
||||
std::string KeyboardMouse::Key::GetName() const
|
||||
{
|
||||
return m_keyname;
|
||||
}
|
||||
|
||||
std::string KeyboardMouse::Cursor::GetName() const
|
||||
{
|
||||
static char tmpstr[] = "Cursor ..";
|
||||
tmpstr[7] = (char)('X' + m_index);
|
||||
tmpstr[8] = (m_positive ? '+' : '-');
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
std::string KeyboardMouse::Button::GetName() const
|
||||
{
|
||||
char button = '0';
|
||||
switch (m_index)
|
||||
{
|
||||
case Button1Mask:
|
||||
button = '1';
|
||||
break;
|
||||
case Button2Mask:
|
||||
button = '2';
|
||||
break;
|
||||
case Button3Mask:
|
||||
button = '3';
|
||||
break;
|
||||
case Button4Mask:
|
||||
button = '4';
|
||||
break;
|
||||
case Button5Mask:
|
||||
button = '5';
|
||||
break;
|
||||
}
|
||||
|
||||
static char tmpstr[] = "Click .";
|
||||
tmpstr[6] = button;
|
||||
return tmpstr;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
// Copyright 2010 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
namespace Xlib
|
||||
{
|
||||
void Init(void* const hwnd);
|
||||
|
||||
class KeyboardMouse : public Core::Device
|
||||
{
|
||||
private:
|
||||
struct State
|
||||
{
|
||||
char keyboard[32];
|
||||
unsigned int buttons;
|
||||
struct
|
||||
{
|
||||
float x, y;
|
||||
} cursor;
|
||||
};
|
||||
|
||||
class Key : public Input
|
||||
{
|
||||
friend class KeyboardMouse;
|
||||
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
Key(Display* display, KeyCode keycode, const char* keyboard);
|
||||
ControlState GetState() const override;
|
||||
|
||||
private:
|
||||
std::string m_keyname;
|
||||
Display* const m_display;
|
||||
const char* const m_keyboard;
|
||||
const KeyCode m_keycode;
|
||||
};
|
||||
|
||||
class Button : public Input
|
||||
{
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
Button(unsigned int index, unsigned int& buttons) : m_buttons(buttons), m_index(index) {}
|
||||
ControlState GetState() const override;
|
||||
|
||||
private:
|
||||
const unsigned int& m_buttons;
|
||||
const unsigned int m_index;
|
||||
};
|
||||
|
||||
class Cursor : public Input
|
||||
{
|
||||
public:
|
||||
std::string GetName() const override;
|
||||
bool IsDetectable() override { return false; }
|
||||
Cursor(u8 index, bool positive, const float& cursor)
|
||||
: m_cursor(cursor), m_index(index), m_positive(positive)
|
||||
{
|
||||
}
|
||||
ControlState GetState() const override;
|
||||
|
||||
private:
|
||||
const float& m_cursor;
|
||||
const u8 m_index;
|
||||
const bool m_positive;
|
||||
};
|
||||
|
||||
public:
|
||||
void UpdateInput() override;
|
||||
|
||||
KeyboardMouse(Window window);
|
||||
~KeyboardMouse();
|
||||
|
||||
std::string GetName() const override;
|
||||
std::string GetSource() const override;
|
||||
|
||||
private:
|
||||
Window m_window;
|
||||
Display* m_display;
|
||||
State m_state;
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue