Cleamnup code for #2020 and use internal pointer for current tracking window

This commit is contained in:
Wojtek Figat
2023-12-16 12:39:10 +01:00
parent 141bec0259
commit c0ef2a1f58
3 changed files with 15 additions and 29 deletions

View File

@@ -94,7 +94,7 @@ X11::XcursorImage* CursorsImg[(int32)CursorType::MAX];
Dictionary<StringAnsi, X11::KeyCode> KeyNameMap;
Array<KeyboardKeys> KeyCodeMap;
Delegate<void*> 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;

View File

@@ -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<String, String, HeapAllocation>& result);
static bool GetEnvironmentVariable(const String& name, String& value);
static bool SetEnvironmentVariable(const String& name, const String& value);

View File

@@ -40,6 +40,7 @@ extern X11::Atom xAtomWmName;
extern Dictionary<StringAnsi, X11::KeyCode> KeyNameMap;
extern Array<KeyboardKeys> 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)