diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 83c3e3ae6..41a2a33f6 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -94,7 +94,7 @@ X11::XcursorImage* CursorsImg[(int32)CursorType::MAX]; Dictionary KeyNameMap; Array KeyCodeMap; Delegate LinuxPlatform::xEventRecieved; -const Window* mouseTrackingWindow; +Window* MouseTrackingWindow = nullptr; // Message boxes configuration #define LINUX_DIALOG_MIN_BUTTON_WIDTH 64 @@ -1917,9 +1917,6 @@ bool LinuxPlatform::Init() { if (PlatformBase::Init()) return true; - - mouseTrackingWindow = nullptr; - char fileNameBuffer[1024]; // Init timing @@ -2263,17 +2260,6 @@ bool LinuxPlatform::Init() return false; } -void LinuxPlatform::StartTrackingMouse(const Window* window) -{ - mouseTrackingWindow = window; -} - -void LinuxPlatform::EndTrackingMouse(const Window* window) -{ - if (mouseTrackingWindow == window) - mouseTrackingWindow = nullptr; -} - void LinuxPlatform::BeforeRun() { } @@ -2412,7 +2398,7 @@ void LinuxPlatform::Tick() // Update input context focus X11::XSetICFocus(IC); window = WindowsManager::GetByNativePtr((void*)event.xfocus.window); - if (window && mouseTrackingWindow == nullptr) + if (window && MouseTrackingWindow == nullptr) { window->OnGotFocus(); } @@ -2421,7 +2407,7 @@ void LinuxPlatform::Tick() // Update input context focus X11::XUnsetICFocus(IC); window = WindowsManager::GetByNativePtr((void*)event.xfocus.window); - if (window && mouseTrackingWindow == nullptr) + if (window && MouseTrackingWindow == nullptr) { window->OnLostFocus(); } @@ -2528,22 +2514,22 @@ void LinuxPlatform::Tick() break; case ButtonPress: window = WindowsManager::GetByNativePtr((void*)event.xbutton.window); - if (mouseTrackingWindow) - ((LinuxWindow*)mouseTrackingWindow)->OnButtonPress(&event.xbutton); + if (MouseTrackingWindow) + MouseTrackingWindow->OnButtonPress(&event.xbutton); else if (window) window->OnButtonPress(&event.xbutton); break; case ButtonRelease: window = WindowsManager::GetByNativePtr((void*)event.xbutton.window); - if (mouseTrackingWindow) - ((LinuxWindow*)mouseTrackingWindow)->OnButtonRelease(&event.xbutton); + if (MouseTrackingWindow) + MouseTrackingWindow->OnButtonRelease(&event.xbutton); else if (window) window->OnButtonRelease(&event.xbutton); break; case MotionNotify: window = WindowsManager::GetByNativePtr((void*)event.xmotion.window); - if (mouseTrackingWindow) - ((LinuxWindow*)mouseTrackingWindow)->OnMotionNotify(&event.xmotion); + if (MouseTrackingWindow) + MouseTrackingWindow->OnMotionNotify(&event.xmotion); else if (window) window->OnMotionNotify(&event.xmotion); break; @@ -2552,8 +2538,8 @@ void LinuxPlatform::Tick() break; case LeaveNotify: window = WindowsManager::GetByNativePtr((void*)event.xcrossing.window); - if (mouseTrackingWindow) - ((LinuxWindow*)mouseTrackingWindow)->OnLeaveNotify(&event.xcrossing); + if (MouseTrackingWindow) + MouseTrackingWindow->OnLeaveNotify(&event.xcrossing); if (window) window->OnLeaveNotify(&event.xcrossing); break; diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.h b/Source/Engine/Platform/Linux/LinuxPlatform.h index 00e7743d7..54590adf2 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.h +++ b/Source/Engine/Platform/Linux/LinuxPlatform.h @@ -139,8 +139,6 @@ public: static String GetWorkingDirectory(); static bool SetWorkingDirectory(const String& path); static Window* CreateWindow(const CreateWindowSettings& settings); - static void StartTrackingMouse(const Window* window); - static void EndTrackingMouse(const Window *window); static void GetEnvironmentVariables(Dictionary& result); static bool GetEnvironmentVariable(const String& name, String& value); static bool SetEnvironmentVariable(const String& name, const String& value); diff --git a/Source/Engine/Platform/Linux/LinuxWindow.cpp b/Source/Engine/Platform/Linux/LinuxWindow.cpp index 9168beb29..9004ed84c 100644 --- a/Source/Engine/Platform/Linux/LinuxWindow.cpp +++ b/Source/Engine/Platform/Linux/LinuxWindow.cpp @@ -40,6 +40,7 @@ extern X11::Atom xAtomWmName; extern Dictionary KeyNameMap; extern Array KeyCodeMap; extern X11::Cursor Cursors[(int32)CursorType::MAX]; +extern Window* MouseTrackingWindow; static constexpr uint32 MouseDoubleClickTime = 500; static constexpr uint32 MaxDoubleClickDistanceSquared = 10; @@ -822,12 +823,13 @@ void LinuxWindow::SetTitle(const StringView& title) void LinuxWindow::StartTrackingMouse(bool useMouseScreenOffset) { - LinuxPlatform::StartTrackingMouse(this); + MouseTrackingWindow = this; } void LinuxWindow::EndTrackingMouse() { - LinuxPlatform::EndTrackingMouse(this); + if (MouseTrackingWindow == this) + MouseTrackingWindow = nullptr; } void LinuxWindow::SetCursor(CursorType type)