From 727283c4de2a33d1d2cca98a7b81fd03b2cdce31 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Tue, 26 Jan 2010 00:11:45 +0000 Subject: [PATCH] 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 --- Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp | 2 +- .../Plugin_Wiimote/Src/EmuDefinitions.h | 4 ++ Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp | 52 +++++++++++++++++-- Source/Plugins/Plugin_Wiimote/Src/EmuMain.h | 9 ++++ .../Plugins/Plugin_Wiimote/Src/FillReport.cpp | 2 +- 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index e16bc49599..a61403ba0d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -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; } diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h index eb6f58f51b..7f17c6996e 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h @@ -30,6 +30,10 @@ #include "wiimote_hid.h" // Local #include "Encryption.h" +#if defined(HAVE_X11) && HAVE_X11 +#include +#endif + extern SWiimoteInitialize g_WiimoteInitialize; namespace WiiMoteEmu diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp index 699468875f..0f4a3480f7 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp @@ -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; } diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h index 32e62029da..e18cdaa05d 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h @@ -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); diff --git a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp index e468a0f6bc..b294ee495f 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp @@ -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) {