Added mouse support for linux. It is still rather crude, but it works.
Unfortunately the mouse pointer doesn't match up very well with the IR pointer yet. Also, I had to add the PointerMotionMask to XSelectInput which adds overhead to the already stressed X event loops. Five event loops by my count, really? git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4961 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
dacc0a19a7
commit
727283c4de
|
@ -431,7 +431,7 @@ bool OpenGL_MakeCurrent()
|
||||||
|
|
||||||
// better for pad plugin key input (thc)
|
// better for pad plugin key input (thc)
|
||||||
XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | ButtonPressMask | KeyReleaseMask | ButtonReleaseMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
|
XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | ButtonPressMask | KeyReleaseMask | ButtonReleaseMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
|
||||||
FocusChangeMask );
|
FocusChangeMask | PointerMotionMask );
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@
|
||||||
#include "wiimote_hid.h" // Local
|
#include "wiimote_hid.h" // Local
|
||||||
#include "Encryption.h"
|
#include "Encryption.h"
|
||||||
|
|
||||||
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
|
#include <X11/X.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||||
|
|
||||||
namespace WiiMoteEmu
|
namespace WiiMoteEmu
|
||||||
|
|
|
@ -199,6 +199,10 @@ void LoadRecordedMovements()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
|
MousePosition MousePos;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */
|
/* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */
|
||||||
void GetMousePos(float& x, float& y)
|
void GetMousePos(float& x, float& y)
|
||||||
{
|
{
|
||||||
|
@ -217,6 +221,14 @@ void GetMousePos(float& x, float& y)
|
||||||
float WinHeight = (float)(Rect.bottom - Rect.top);
|
float WinHeight = (float)(Rect.bottom - Rect.top);
|
||||||
float XOffset = 0, YOffset = 0;
|
float XOffset = 0, YOffset = 0;
|
||||||
float PictureWidth = WinWidth, PictureHeight = WinHeight;
|
float PictureWidth = WinWidth, PictureHeight = WinHeight;
|
||||||
|
#else
|
||||||
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
|
float WinWidth = (float)MousePos.WinWidth;
|
||||||
|
float WinHeight = (float)MousePos.WinHeight;
|
||||||
|
float XOffset = 0, YOffset = 0;
|
||||||
|
float PictureWidth = WinWidth, PictureHeight = WinHeight;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Calculate the actual picture size and location */
|
/* Calculate the actual picture size and location */
|
||||||
// Output: PictureWidth, PictureHeight, XOffset, YOffset
|
// Output: PictureWidth, PictureHeight, XOffset, YOffset
|
||||||
|
@ -283,6 +295,7 @@ void GetMousePos(float& x, float& y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the mouse position as a fraction of one, inside the picture, with (0.0, 0.0) being the upper left corner of the picture
|
// Return the mouse position as a fraction of one, inside the picture, with (0.0, 0.0) being the upper left corner of the picture
|
||||||
|
#ifdef _WIN32
|
||||||
x = ((float)point.x - XOffset) / PictureWidth;
|
x = ((float)point.x - XOffset) / PictureWidth;
|
||||||
y = ((float)point.y - YOffset) / PictureHeight;
|
y = ((float)point.y - YOffset) / PictureHeight;
|
||||||
|
|
||||||
|
@ -291,11 +304,11 @@ void GetMousePos(float& x, float& y)
|
||||||
INFO_LOG(WIIMOTE, "GetClientRect: %i %i %i %i", Rect.left, Rect.right, Rect.top, Rect.bottom);
|
INFO_LOG(WIIMOTE, "GetClientRect: %i %i %i %i", Rect.left, Rect.right, Rect.top, Rect.bottom);
|
||||||
INFO_LOG(WIIMOTE, "Position X:%1.2f Y:%1.2f", x, y);
|
INFO_LOG(WIIMOTE, "Position X:%1.2f Y:%1.2f", x, y);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// TODO fix on linux
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
x = 0.5f;
|
x = ((float)MousePos.x - XOffset) / PictureWidth;
|
||||||
y = 0.5f;
|
y = ((float)MousePos.y - YOffset) / PictureHeight;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -696,6 +709,37 @@ void ReadLinuxKeyboard()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ButtonPress:
|
||||||
|
{
|
||||||
|
int button = ((XButtonEvent*)&E)->button;
|
||||||
|
if (button == 1)
|
||||||
|
KeyStatus[EWM_A] = true;
|
||||||
|
else if (button == 3)
|
||||||
|
KeyStatus[EWM_B] = true;
|
||||||
|
else
|
||||||
|
XPutBackEvent(WMdisplay, &E);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ButtonRelease:
|
||||||
|
{
|
||||||
|
int button = ((XButtonEvent*)&E)->button;
|
||||||
|
if (button == 1)
|
||||||
|
KeyStatus[EWM_A] = false;
|
||||||
|
else if (button == 3)
|
||||||
|
KeyStatus[EWM_B] = false;
|
||||||
|
else
|
||||||
|
XPutBackEvent(WMdisplay, &E);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MotionNotify:
|
||||||
|
{
|
||||||
|
MousePos.x = E.xmotion.x;
|
||||||
|
MousePos.y = E.xmotion.y;
|
||||||
|
XWindowAttributes WinAttribs;
|
||||||
|
XGetWindowAttributes (E.xmotion.display, E.xmotion.window, &WinAttribs);
|
||||||
|
MousePos.WinWidth = WinAttribs.width;
|
||||||
|
MousePos.WinHeight = WinAttribs.height;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,15 @@ void TiltToAccelerometer(int &_x, int &_y, int &_z, STiltData &_TiltData);
|
||||||
void AdjustAngles(int &Roll, int &Pitch);
|
void AdjustAngles(int &Roll, int &Pitch);
|
||||||
void RotateIRDot(int &_x, int &_y, STiltData &_TiltData);
|
void RotateIRDot(int &_x, int &_y, STiltData &_TiltData);
|
||||||
|
|
||||||
|
#if defined(HAVE_X11) && HAVE_X11
|
||||||
|
struct MousePosition
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
int WinWidth, WinHeight;
|
||||||
|
};
|
||||||
|
extern MousePosition MousePos;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Accelerometer
|
// Accelerometer
|
||||||
//void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, int&, int&);
|
//void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, int&, int&);
|
||||||
//float AccelerometerToG(float Current, float Neutral, float G);
|
//float AccelerometerToG(float Current, float Neutral, float G);
|
||||||
|
|
|
@ -50,7 +50,7 @@ double g_RecordingCurrentTime[3]; //g_RecordingCurrentTime[0] = 0; g_RecordingCu
|
||||||
int G2Accelerometer(int _G, int XYZ, int Wm)
|
int G2Accelerometer(int _G, int XYZ, int Wm)
|
||||||
{
|
{
|
||||||
float G = (float)_G / 100.0;
|
float G = (float)_G / 100.0;
|
||||||
float Neutral, OneG, Accelerometer;
|
float Neutral = 0.0, OneG = 0.0, Accelerometer;
|
||||||
|
|
||||||
switch(XYZ)
|
switch(XYZ)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue