_window dragging X11 fixed
Some checks are pending
Build Android / Game (Android, Release ARM64) (push) Waiting to run
Build iOS / Game (iOS, Release ARM64) (push) Waiting to run
Build Linux / Editor (Linux, Development x64) (push) Waiting to run
Build Linux / Game (Linux, Release x64) (push) Waiting to run
Build macOS / Editor (Mac, Development ARM64) (push) Waiting to run
Build macOS / Game (Mac, Release ARM64) (push) Waiting to run
Build Windows / Editor (Windows, Development x64) (push) Waiting to run
Build Windows / Game (Windows, Release x64) (push) Waiting to run
Cooker / Cook (Mac) (push) Waiting to run
Tests / Tests (Linux) (push) Waiting to run
Tests / Tests (Windows) (push) Waiting to run

This commit is contained in:
2025-01-20 22:31:13 +02:00
parent e45075f7d8
commit 3dd9612ae4
7 changed files with 97 additions and 57 deletions

View File

@@ -30,6 +30,11 @@
#define DefaultDPI 96
Window* draggedWindow = nullptr;
#if PLATFORM_WINDOWS
extern Float2 draggedWindowStartPosition;
extern Float2 draggedWindowMousePosition;
#endif
uint32 SDLPlatform::DraggedWindowId = 0;
namespace
@@ -47,7 +52,7 @@ bool SDLPlatform::Init()
SDL_SetHintWithPriority(SDL_HINT_VIDEO_DRIVER, "wayland", SDL_HINT_OVERRIDE);
else
SDL_SetHintWithPriority(SDL_HINT_VIDEO_DRIVER, "wayland", SDL_HINT_OVERRIDE);
//SDL_SetHintWithPriority(SDL_HINT_VIDEO_DRIVER, "x11", SDL_HINT_OVERRIDE);
SDL_SetHintWithPriority(SDL_HINT_VIDEO_DRIVER, "x11", SDL_HINT_OVERRIDE);
#endif
#if PLATFORM_LINUX
@@ -144,10 +149,6 @@ bool SDLPlatform::CheckWindowDragging(Window* window, WindowHitCodes hit)
return handled;
}
extern Window* draggedWindow;
extern Float2 draggedWindowStartPosition;
extern Float2 draggedWindowMousePosition;
void SDLPlatform::Tick()
{
SDLInput::Update();
@@ -209,6 +210,7 @@ void SDLPlatform::Tick()
}
#endif
#if PLATFORM_WINDOWS
auto watch = [](void* userdata, SDL_Event* event) -> bool
{
Window* draggedWindow = *(Window**)userdata;
@@ -264,6 +266,7 @@ void SDLPlatform::Tick()
};
SDL_AddEventWatch(watch, &draggedWindow);
#endif
SDL_PumpEvents();
SDL_Event events[32];
@@ -279,22 +282,35 @@ void SDLPlatform::Tick()
SDLPlatform::HandleEvent(events[i]);
}
#if PLATFORM_WINDOWS
SDL_RemoveEventWatch(watch, &draggedWindow);
#endif
// Handle Windows and X11 window dragging release
if (draggedWindow != nullptr)
{
// We are no longer dragging since event loop is no longer blocked
SDL_Event event{ 0 };
event.button.type = SDL_EVENT_MOUSE_BUTTON_UP;
event.button.down = false;
event.button.timestamp = SDL_GetTicksNS();
event.button.windowID = SDL_GetWindowID(draggedWindow->GetSDLWindow());
event.button.button = SDL_BUTTON_LEFT;
event.button.clicks = 1;
event.button.x = 0;//static_cast<float>(static_cast<LONG>(WINDOWS_GET_X_LPARAM(msg->lParam)));
event.button.y = 0;//static_cast<float>(static_cast<LONG>(WINDOWS_GET_Y_LPARAM(msg->lParam)));
Float2 mousePosition;
auto buttons = SDL_GetGlobalMouseState(&mousePosition.X, &mousePosition.Y);
bool buttonReleased = (buttons & SDL_BUTTON_MASK(SDL_BUTTON_LEFT)) == 0;
if (buttonReleased || UsesWindows())
{
// Send simulated mouse up event
SDL_Event buttonUpEvent { 0 };
buttonUpEvent.motion.type = SDL_EVENT_MOUSE_BUTTON_UP;
buttonUpEvent.button.down = false;
buttonUpEvent.motion.windowID = SDL_GetWindowID(draggedWindow->GetSDLWindow());
buttonUpEvent.motion.timestamp = SDL_GetTicksNS();
buttonUpEvent.motion.state = SDL_BUTTON_LEFT;
buttonUpEvent.button.clicks = 1;
buttonUpEvent.motion.x = mousePosition.X;
buttonUpEvent.motion.y = mousePosition.Y;
draggedWindow->HandleEvent(buttonUpEvent);
//SDL_PushEvent(&buttonUpEvent);
SDL_PushEvent(&event);
draggedWindow = nullptr;
SDL_SetWindowAlwaysOnTop(draggedWindow->GetSDLWindow(), false);
draggedWindow->BringToFront();
draggedWindow = nullptr;
}
}
}
@@ -350,18 +366,16 @@ void SDLPlatform::OpenUrl(const StringView& url)
Float2 SDLPlatform::GetMousePosition()
{
Float2 pos;
#if PLATFORM_LINUX
if (UsesWayland())
{
// Wayland doesn't support reporting global mouse position.
// Use the last known reported position we got from window events.
// Wayland doesn't support reporting global mouse position,
// use the last known reported position we got from received window events.
pos = Input::GetMouseScreenPosition();
}
//else
// SDL_GetGlobalMouseState(&pos.X, &pos.Y);
#else
pos = Input::GetMouseScreenPosition();
#endif
else if (UsesX11())
SDL_GetGlobalMouseState(&pos.X, &pos.Y);
else
pos = Input::GetMouseScreenPosition();
return pos;
}
@@ -410,25 +424,6 @@ Window* SDLPlatform::CreateWindow(const CreateWindowSettings& settings)
return New<SDLWindow>(settings);
}
#if !PLATFORM_LINUX
bool SDLPlatform::UsesWayland()
{
return false;
}
bool SDLPlatform::UsesXWayland()
{
return false;
}
bool SDLPlatform::UsesX11()
{
return false;
}
#endif
#if PLATFORM_LINUX
DialogResult MessageBox::Show(Window* parent, const StringView& text, const StringView& caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{