diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index 9c7192f8ea..5f60137a42 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -404,6 +404,9 @@ THREAD_RETURN EmuThread(void *pArg) // Load and init GCPadPlugin SPADInitialize PADInitialize; PADInitialize.hWnd = g_pWindowHandle; +#if defined(HAVE_X11) && HAVE_X11 + PADInitialize.pXWindow = g_pXWindow; +#endif PADInitialize.pLog = Callback_PADLog; // This is may be needed to avoid a SDL problem //Plugins.FreeWiimote(); diff --git a/Source/PluginSpecs/pluginspecs_pad.h b/Source/PluginSpecs/pluginspecs_pad.h index fe8031f729..4a0ef29c6a 100644 --- a/Source/PluginSpecs/pluginspecs_pad.h +++ b/Source/PluginSpecs/pluginspecs_pad.h @@ -34,6 +34,9 @@ typedef void (*TLog)(const char* _pMessage); typedef struct { HWND hWnd; +#if defined HAVE_X11 && HAVE_X11 + void *pXWindow; +#endif TLog pLog; } SPADInitialize; diff --git a/Source/PluginSpecs/pluginspecs_wiimote.h b/Source/PluginSpecs/pluginspecs_wiimote.h index ad9e2255cd..f3900afef6 100644 --- a/Source/PluginSpecs/pluginspecs_wiimote.h +++ b/Source/PluginSpecs/pluginspecs_wiimote.h @@ -19,7 +19,7 @@ typedef void (*TWiimoteInput)(int _number, u16 _channelID, const void* _pData, u typedef struct { HWND hWnd; -#ifdef __linux__ +#if defined HAVE_X11 && HAVE_X11 void *pXWindow; #endif u32 ISOId; diff --git a/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp b/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp index d8b654018e..eae0f50b19 100644 --- a/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp +++ b/Source/Plugins/Plugin_GCPad/Src/GCPad.cpp @@ -595,7 +595,18 @@ void UpdatePadState(CONTROLLER_MAPPING_GC &_GCiMapping) Tr = InputCommon::Pad_Convert(Tr); } } - + +#if defined(HAVE_X11) && HAVE_X11 +bool HaveFocus (void) +{ + Window GLWin = *(Window *)g_PADInitialize->pXWindow; + Window FocusWin; + int Revert; + XGetInputFocus(GCdisplay, &FocusWin, &Revert); + return (GLWin != 0 && GLWin == FocusWin); +} +#endif + // Multi System Input Status Check bool IsKey(int Key) { @@ -609,7 +620,7 @@ bool IsKey(int Key) } else if (MapKey < 0x1100) #elif defined HAVE_X11 && HAVE_X11 - if (MapKey < 256 || MapKey > 0xf000) + if (HaveFocus() && (MapKey < 256 || MapKey > 0xf000)) { char keys[32]; KeyCode keyCode; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp index 504e4d0433..92e6727234 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/GLUtil.cpp @@ -360,7 +360,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight /* create a fullscreen window */ GLWin.attr.override_redirect = True; - GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | KeyReleaseMask | ButtonReleaseMask | StructureNotifyMask; + GLWin.attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask; GLWin.win = XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen), 0, 0, dpyWidth, dpyHeight, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, @@ -368,7 +368,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight XWarpPointer(GLWin.dpy, None, GLWin.win, 0, 0, 0, 0, 0, 0); XMapRaised(GLWin.dpy, GLWin.win); XGrabKeyboard(GLWin.dpy, GLWin.win, True, GrabModeAsync, GrabModeAsync, CurrentTime); - XGrabPointer(GLWin.dpy, GLWin.win, True, ButtonPressMask, + XGrabPointer(GLWin.dpy, GLWin.win, True, NULL, GrabModeAsync, GrabModeAsync, GLWin.win, None, CurrentTime); } else { @@ -388,7 +388,7 @@ bool OpenGL_Create(SVideoInitialize &_VideoInitialize, int _iwidth, int _iheight //int Y = (rcdesktop.bottom-rcdesktop.top)/2 - (rc.bottom-rc.top)/2; // create a window in window mode - GLWin.attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | KeyReleaseMask | ButtonReleaseMask | + GLWin.attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | StructureNotifyMask | ResizeRedirectMask; GLWin.win = XCreateWindow(GLWin.dpy, RootWindow(GLWin.dpy, vi->screen), 0, 0, _twidth, _theight, 0, vi->depth, InputOutput, vi->visual, diff --git a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp index 0ee64c46c9..4f8cf340bc 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp @@ -42,12 +42,11 @@ CWII_IPC_HLE_Device_usb_oh1_57e_305::Update() */ -#include "pluginspecs_wiimote.h" - #include #include #include "Common.h" // Common +#include "pluginspecs_wiimote.h" #include "StringUtil.h" // for ArrayToString #include "wiimote_hid.h" // Local diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp index 8792346ad4..81846f8f62 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp @@ -21,8 +21,8 @@ #include #include -#include "pluginspecs_wiimote.h" #include "Common.h" +#include "pluginspecs_wiimote.h" #include "wiimote_hid.h" #include "EmuDefinitions.h" #include "Encryption.h" diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp index 3965edf715..0586cfe285 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp @@ -196,6 +196,17 @@ void LoadRecordedMovements() } } +#if defined(HAVE_X11) && HAVE_X11 +bool HaveFocus (void) +{ + Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow; + Window FocusWin; + int Revert; + XGetInputFocus(WMdisplay, &FocusWin, &Revert); + return (GLWin != 0 && GLWin == FocusWin); +} +#endif + /* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */ void GetMousePos(float& x, float& y) { @@ -216,12 +227,13 @@ void GetMousePos(float& x, float& y) float PictureWidth = WinWidth, PictureHeight = WinHeight; #else #if defined(HAVE_X11) && HAVE_X11 + Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow; float WinWidth = 0, WinHeight = 0; float XOffset = 0, YOffset = 0; int root_x, root_y, win_x, win_y; - Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow; - if (GLWin != 0) + if (HaveFocus()) { + Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow; XWindowAttributes WinAttribs; XGetWindowAttributes (WMdisplay, GLWin, &WinAttribs); WinWidth = (float)WinAttribs.width; diff --git a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h index 1fa17bdbf2..5c37d9ae37 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h +++ b/Source/Plugins/Plugin_Wiimote/Src/EmuMain.h @@ -42,9 +42,12 @@ void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size) ; void Update(int _number); void DoState(PointerWrap &p); -//void ReadLinuxKeyboard(); bool IsKey(int Key); +#if defined(HAVE_X11) && HAVE_X11 +bool HaveFocus (void); +#endif + // Recordings void LoadRecordedMovements(); void GetMousePos(float& x, float& y); diff --git a/Source/Plugins/Plugin_Wiimote/Src/Encryption.cpp b/Source/Plugins/Plugin_Wiimote/Src/Encryption.cpp index 6db639ac91..3ce0a86175 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/Encryption.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/Encryption.cpp @@ -17,8 +17,8 @@ // http://code.google.com/p/dolphin-emu/ -#include "pluginspecs_wiimote.h" #include "Common.h" +#include "pluginspecs_wiimote.h" #include "Encryption.h" diff --git a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp index 0ab25ca254..303748083a 100644 --- a/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp +++ b/Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp @@ -310,7 +310,7 @@ bool IsKey(int Key) } else if (MapKey < 0x1100) #elif defined(HAVE_X11) && HAVE_X11 - if (MapKey < 256 || MapKey >= 0xf000) + if (HaveFocus() && (MapKey < 256 || MapKey >= 0xf000)) { char keys[32]; KeyCode keyCode; @@ -346,23 +346,20 @@ bool IsKey(int Key) } #endif #if defined(HAVE_X11) && HAVE_X11 - if ((Key == EWM_SHAKE) || (Key == EWM_A) || (Key == EWM_B)) + if ((Key == EWM_SHAKE || Key == EWM_A || Key == EWM_B) && HaveFocus()) { Window GLWin = *(Window *)g_WiimoteInitialize.pXWindow; - if (GLWin != 0) + int root_x, root_y, win_x, win_y; + Window rootDummy, childWin; + unsigned int mask; + XQueryPointer(WMdisplay, GLWin, &rootDummy, &childWin, &root_x, &root_y, &win_x, &win_y, &mask); + if (((Key == EWM_A) && (mask & Button1Mask)) + || ((Key == EWM_B) && (mask & Button3Mask)) + || ((Key == EWM_SHAKE) && (mask & Button3Mask))) { - int root_x, root_y, win_x, win_y; - Window rootDummy, childWin; - unsigned int mask; - XQueryPointer(WMdisplay, GLWin, &rootDummy, &childWin, &root_x, &root_y, &win_x, &win_y, &mask); - if (((Key == EWM_A) && (mask & Button1Mask)) - || ((Key == EWM_B) && (mask & Button3Mask)) - || ((Key == EWM_SHAKE) && (mask & Button3Mask))) - { - float x, y; - GetMousePos(x, y); - Ret = !(x < 0 || x > 1 || y < 0 || y > 1); - } + float x, y; + GetMousePos(x, y); + Ret = !(x < 0 || x > 1 || y < 0 || y > 1); } } #endif