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)
|
||||
XSelectInput(GLWin.dpy, GLWin.win, ExposureMask | KeyPressMask | ButtonPressMask | KeyReleaseMask | ButtonReleaseMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask |
|
||||
FocusChangeMask );
|
||||
FocusChangeMask | PointerMotionMask );
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
#include "wiimote_hid.h" // Local
|
||||
#include "Encryption.h"
|
||||
|
||||
#if defined(HAVE_X11) && HAVE_X11
|
||||
#include <X11/X.h>
|
||||
#endif
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
|
||||
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. */
|
||||
void GetMousePos(float& x, float& y)
|
||||
{
|
||||
|
@ -217,6 +221,14 @@ void GetMousePos(float& x, float& y)
|
|||
float WinHeight = (float)(Rect.bottom - Rect.top);
|
||||
float XOffset = 0, YOffset = 0;
|
||||
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 */
|
||||
// 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
|
||||
#ifdef _WIN32
|
||||
x = ((float)point.x - XOffset) / PictureWidth;
|
||||
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, "Position X:%1.2f Y:%1.2f", x, y);
|
||||
*/
|
||||
|
||||
#else
|
||||
// TODO fix on linux
|
||||
x = 0.5f;
|
||||
y = 0.5f;
|
||||
#if defined(HAVE_X11) && HAVE_X11
|
||||
x = ((float)MousePos.x - XOffset) / PictureWidth;
|
||||
y = ((float)MousePos.y - YOffset) / PictureHeight;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -696,6 +709,37 @@ void ReadLinuxKeyboard()
|
|||
}
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,15 @@ void TiltToAccelerometer(int &_x, int &_y, int &_z, STiltData &_TiltData);
|
|||
void AdjustAngles(int &Roll, int &Pitch);
|
||||
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
|
||||
//void PitchAccelerometerToDegree(u8 _x, u8 _y, u8 _z, int &_Roll, int &_Pitch, int&, int&);
|
||||
//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)
|
||||
{
|
||||
float G = (float)_G / 100.0;
|
||||
float Neutral, OneG, Accelerometer;
|
||||
float Neutral = 0.0, OneG = 0.0, Accelerometer;
|
||||
|
||||
switch(XYZ)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue