From 3df9602ac5bd399c78af19135a81bb4c76a8aab8 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Mon, 30 Dec 2024 03:52:40 +0200 Subject: [PATCH] _refix x11 popu positioning --- .../Editor/GUI/ContextMenu/ContextMenuBase.cs | 2 +- Source/Engine/Platform/SDL/SDLWindow.cpp | 97 ++++++++++--------- Source/Engine/UI/GUI/Tooltip.cs | 4 +- 3 files changed, 53 insertions(+), 50 deletions(-) diff --git a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs index e9e01f4df..f5b05ff2e 100644 --- a/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs +++ b/Source/Editor/GUI/ContextMenu/ContextMenuBase.cs @@ -206,7 +206,7 @@ namespace FlaxEditor.GUI.ContextMenu // Create window var desc = CreateWindowSettings.Default; desc.Position = locationSS; - Editor.Log($"contextmenu loc: {locationSS}, in parentloc: {location}"); + //Editor.Log($"contextmenu loc: {locationSS}, in parentloc: {location}"); desc.StartPosition = WindowStartPosition.Manual; desc.Size = dpiSize; desc.Fullscreen = false; diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp index fdc2b7b57..677ea2798 100644 --- a/Source/Engine/Platform/SDL/SDLWindow.cpp +++ b/Source/Engine/Platform/SDL/SDLWindow.cpp @@ -33,7 +33,7 @@ #endif #elif PLATFORM_LINUX #include "Engine/Platform/Linux/IncludeX11.h" -#define X11_WINDOW_POSITION_WORKAROUND 1 +#define X11_WINDOW_POSITION_WORKAROUND 1 // Popup windows report wrong position? #endif #define DefaultDPI 96 @@ -211,7 +211,7 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings) } } - LOG(Info, "{}x{}, parent: {}", x, y, _settings.Parent != nullptr ? _settings.Parent->GetTitle() : String("null")); + //LOG(Info, "{}x{}, parent: {}", x, y, _settings.Parent != nullptr ? _settings.Parent->GetTitle() : String("null")); // The SDL window position is always relative to the parent window @@ -323,7 +323,7 @@ SDLWindow::SDLWindow(const CreateWindowSettings& settings) Int2 newpos = GetClientPosition(); Int2 newposclient = GetSDLWindowPosition(this); - LOG(Info, "new window at {}, input {}, expected: {}", newposclient, oldpos, oldpos2); + //LOG(Info, "new window at {}, input {}, expected: {}", newposclient, oldpos, oldpos2); //ASSERT(newpos == oldpos || newpos == oldpos2); /*oldpos = newpos; @@ -1020,28 +1020,19 @@ Int2 GetSDLWindowPosition(const SDLWindow* window) if (SDLPlatform::UsesX11()) { #if X11_WINDOW_POSITION_WORKAROUND - if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup) + if (/*window->GetSettings().Type == WindowType::Tooltip ||*/ window->GetSettings().Type == WindowType::Popup) { + auto oldPos = position; auto parent = window->GetSettings().Parent; - while (parent->GetSettings().Parent != nullptr) + while (parent != nullptr) { - Int2 rootParentPosition = GetSDLWindowPosition(parent); - //SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y); + Int2 rootParentPosition; + //rootParentPosition = GetSDLWindowPosition(parent); + SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.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()); - } - else - { - //auto monitorBounds = Platform::GetMonitorBounds(Float2::Minimum); - //position -= Int2(monitorBounds.GetTopLeft()); + } #endif } @@ -1071,41 +1062,19 @@ void SetSDLWindowPosition(SDLWindow* window, const int x, const int y) if (SDLPlatform::UsesX11()) { #if X11_WINDOW_POSITION_WORKAROUND - if (window->GetSettings().Type == WindowType::Tooltip || window->GetSettings().Type == WindowType::Popup) + 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) + while (parent != nullptr) { - Int2 rootParentPosition = GetSDLWindowPosition(parent); - //SDL_GetWindowPosition(window->GetSettings().Parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y); + Int2 rootParentPosition; + SDL_GetWindowPosition(parent->GetSDLWindow(), &rootParentPosition.X, &rootParentPosition.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 } else if (SDLPlatform::UsesWayland()) @@ -1233,23 +1202,57 @@ void SetRelativeWindowPosition(const WindowType windowType, SDLWindow* theParent #if PLATFORM_LINUX if (SDLPlatform::UsesX11()) { + /**/ if (windowType != WindowType::Tooltip && windowType != WindowType::Popup) + { + /*auto parentPosition = theParent->ClientToScreen(Float2::Zero); + xRel -= Math::TruncToInt(parentPosition.X); + yRel -= Math::TruncToInt(parentPosition.Y); + + auto parentType = theParent->GetSettings().Type; + auto parentParent = theParent->GetSettings().Parent; + if (parentParent != nullptr) + { + //if (parentType != WindowType::Popup && parentType != WindowType::Tooltip) + { + auto parentParentType = parentParent->GetSettings().Type; + //if (parentParentType != WindowType::Popup && parentParentType != WindowType::Tooltip) + { + auto parentParentPosition = parentParent->ClientToScreen(Float2::Zero); + xRel -= Math::TruncToInt(parentParentPosition.X); + yRel -= Math::TruncToInt(parentParentPosition.Y); + } + } + }*/ + return; + } SDLWindow* parent = theParent; while (parent != nullptr) { - if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup) + //if (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup) + //if (false) { Int2 parentPosition = GetSDLWindowPosition(parent); + //Int2 parentPosition; + //SDL_GetWindowPosition(parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y); xRel -= parentPosition.X; yRel -= parentPosition.Y; - break; + //break; } //if (parent->GetSettings().Parent == nullptr || (parent->GetSettings().Type != WindowType::Tooltip && parent->GetSettings().Type != WindowType::Popup)) // break; parent = parent->GetSettings().Parent; } + /*if (parent != nullptr) + { + Int2 parentPosition = GetSDLWindowPosition(parent); + //Int2 parentPosition; + //SDL_GetWindowPosition(parent->GetSDLWindow(), &parentPosition.X, &parentPosition.Y); + xRel -= parentPosition.X; + yRel -= parentPosition.Y; + }*/ } else if (SDLPlatform::UsesWayland()) { diff --git a/Source/Engine/UI/GUI/Tooltip.cs b/Source/Engine/UI/GUI/Tooltip.cs index df4f56bdb..7988159b5 100644 --- a/Source/Engine/UI/GUI/Tooltip.cs +++ b/Source/Engine/UI/GUI/Tooltip.cs @@ -88,7 +88,7 @@ namespace FlaxEngine.GUI var desc = CreateWindowSettings.Default; desc.StartPosition = WindowStartPosition.Manual; desc.Position = locationSS; - Editor.Log($"tooltip pos: {Input.MouseScreenPosition}, in parentloc: {location}"); + //Editor.Log($"tooltip pos: {Input.MouseScreenPosition}, in parentloc: {location}"); desc.Size = dpiSize; desc.Fullscreen = false; desc.HasBorder = false; @@ -230,7 +230,7 @@ namespace FlaxEngine.GUI { // Position tooltip when mouse moves WrapPosition(ref mousePos, 10); - Editor.Log($"tooltip newpos: {Input.MouseScreenPosition}, in parentloc: {location}"); + //Editor.Log($"tooltip newpos: {Input.MouseScreenPosition}, in parentloc: {location}"); if (_window) _window.Position = mousePos; }