_x11 maybe working?

This commit is contained in:
2024-12-28 19:58:08 +02:00
parent 089346b296
commit c9f1a45f40
2 changed files with 57 additions and 4 deletions

View File

@@ -483,7 +483,7 @@ bool SDLInput::HandleEvent(SDLWindow* window, SDL_Event& event)
else
{
const Float2 mousePos = window->ClientToScreen({ event.motion.x, event.motion.y });
LOG(Info, "motion {},{}, mouse: {}, win: {}", event.motion.x, event.motion.y, mousePos, String(window->GetTitle()));
//LOG(Info, "motion {},{}, mouse: {}, win: {}", event.motion.x, event.motion.y, mousePos, String(window->GetTitle()));
Input::Mouse->OnMouseMove(mousePos, window);
}
return true;

View File

@@ -33,6 +33,7 @@
#endif
#elif PLATFORM_LINUX
#include "Engine/Platform/Linux/IncludeX11.h"
#define X11_WINDOW_POSITION_WORKAROUND 1
#endif
#define DefaultDPI 96
@@ -49,6 +50,7 @@ namespace
void* GetNativeWindowPointer(SDL_Window* window);
SDL_HitTestResult OnWindowHitTest(SDL_Window* win, const SDL_Point* area, void* data);
Int2 GetSDLWindowPosition(const SDLWindow* window);
void SetSDLWindowPosition(SDLWindow* window, const int x, const int y);
void GetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition, bool clienttoscreen = true);
class SDLDropFilesData : public IGuiData
@@ -224,6 +226,7 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
}
else if (_settings.Parent != nullptr)
{//(_settings.Type == WindowType::Tooltip || _settings.Type == WindowType::Popup)
#if true//X11_WINDOW_POSITION_WORKAROUND
auto parentPosition = _settings.Parent->ClientToScreen(Float2::Zero);
x -= Math::TruncToInt(parentPosition.X);
y -= Math::TruncToInt(parentPosition.Y);
@@ -248,6 +251,7 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings)
x += 0;
}*/
}
#endif
}
if (SDLPlatform::UsesX11() && _settings.Parent != Engine::MainWindow)
{
@@ -984,7 +988,7 @@ void SDLWindow::SetClientBounds(const Rectangle& clientArea)
SDL_GetWindowPosition(_window, &oldX, &oldY);
SDL_GetWindowSizeInPixels(_window, &oldW, &oldH);
SDL_SetWindowPosition(_window, (int)clientArea.GetLeft(), (int)clientArea.GetTop());
SetSDLWindowPosition(this, (int)clientArea.GetLeft(), (int)clientArea.GetTop());
SDL_SetWindowSize(_window, (int)clientArea.GetWidth(), (int)clientArea.GetHeight());
LOG(Info, "SetClientBounds changed from ({},{} {}x{}) to ({},{} {}x{})", oldX, oldY, oldW, oldH,
@@ -998,6 +1002,7 @@ Int2 GetSDLWindowPosition(const SDLWindow* window)
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
#if X11_WINDOW_POSITION_WORKAROUND
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
{
auto parent = window->GetSettings().Parent;
@@ -1021,11 +1026,59 @@ Int2 GetSDLWindowPosition(const SDLWindow* window)
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//position -= Int2(monitorBounds.GetTopLeft());
}
#endif
}
#endif
return position;
}
void SetSDLWindowPosition(SDLWindow* window, const int x, const int y)
{
#if PLATFORM_LINUX
if (SDLPlatform::UsesX11())
{
#if X11_WINDOW_POSITION_WORKAROUND
if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup)
{
Int2 position(x, y);
auto parent = window->GetSettings().Parent;
while (parent->GetSettings().Parent != nullptr)
{
Int2 rootParentPosition = GetSDLWindowPosition(parent);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
position -= rootParentPosition;
parent = parent->GetSettings().Parent;
}
Int2 rootParentPosition = GetSDLWindowPosition(parent);
//SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y);
position -= rootParentPosition;
auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//position += Int2(monitorBounds.GetTopLeft());
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//position += Int2(monitorBounds.GetTopLeft());
SDL_SetWindowPosition(window->GetSDLWindow(), position.X, position.Y);
SDL_SyncWindow(window->GetSDLWindow());
Int2 newpos;
Int2 newpos2 = GetSDLWindowPosition(window);
SDL_GetWindowPosition(window->GetSDLWindow(), &newpos.X, &newpos.Y);
return;
}
else
{
//auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum);
//position -= Int2(monitorBounds.GetTopLeft());
}
#endif
}
#endif
SDL_SetWindowPosition(window->GetSDLWindow(), x, y);
}
void GetRelativeWindowPosition(const SDLWindow* window, Int2& relativePosition, bool clienttoscreen)
{
// The relative positioning of windows are very inconsistent in different platforms.
@@ -1226,7 +1279,7 @@ void SDLWindow::SetPosition(const Float2& position)
relativePosition += Int2(monitorBounds.GetTopLeft());
}
SDL_SetWindowPosition(_window, relativePosition.X, relativePosition.Y);
SetSDLWindowPosition(this, relativePosition.X, relativePosition.Y);
SDL_SyncWindow(_window);
Int2 newPos;
@@ -1241,7 +1294,7 @@ void SDLWindow::SetPosition(const Float2& position)
void SDLWindow::SetClientPosition(const Float2& position)
{
SDL_SetWindowPosition(_window, static_cast<int>(position.X), static_cast<int>(position.Y));
SetSDLWindowPosition(this, static_cast<int>(position.X), static_cast<int>(position.Y));
}
void SDLWindow::SetIsFullscreen(bool isFullscreen)