Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZWidget Wayland Backend - Window handle fixes #146

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

struct wl_display;
struct wl_surface;
#include <wayland-client-protocol.h>

class WaylandNativeHandle
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,14 @@ void WaylandDisplayBackend::OnMouseLeaveEvent()

void WaylandDisplayBackend::OnMousePressEvent(InputKey button)
{
m_FocusWindow->windowHost->OnWindowMouseDown(m_FocusWindow->m_SurfaceMousePos, button);
if (m_FocusWindow)
m_FocusWindow->windowHost->OnWindowMouseDown(m_FocusWindow->m_SurfaceMousePos, button);
}

void WaylandDisplayBackend::OnMouseReleaseEvent(InputKey button)
{
m_FocusWindow->windowHost->OnWindowMouseUp(m_FocusWindow->m_SurfaceMousePos, button);
if (m_FocusWindow)
m_FocusWindow->windowHost->OnWindowMouseUp(m_FocusWindow->m_SurfaceMousePos, button);
}

void WaylandDisplayBackend::OnMouseMoveEvent(Point surfacePos)
Expand All @@ -380,7 +382,8 @@ void WaylandDisplayBackend::OnMouseMoveEvent(Point surfacePos)

void WaylandDisplayBackend::OnMouseWheelEvent(InputKey button)
{
m_FocusWindow->windowHost->OnWindowMouseWheel(m_FocusWindow->m_SurfaceMousePos, button);
if (m_FocusWindow)
m_FocusWindow->windowHost->OnWindowMouseWheel(m_FocusWindow->m_SurfaceMousePos, button);
}

void WaylandDisplayBackend::SetCursor(StandardCursor cursor)
Expand Down Expand Up @@ -408,7 +411,8 @@ std::unique_ptr<DisplayWindow> WaylandDisplayBackend::Create(DisplayWindowHost*
void WaylandDisplayBackend::OnWindowCreated(WaylandDisplayWindow* window)
{
s_Windows.push_back(window);
m_FocusWindow = window;
if (!window->m_PopupWindow)
m_FocusWindow = window;
}

void WaylandDisplayBackend::OnWindowDestroyed(WaylandDisplayWindow* window)
Expand Down
17 changes: 11 additions & 6 deletions Thirdparty/ZWidget/src/window/wayland/wayland_display_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@


WaylandDisplayWindow::WaylandDisplayWindow(WaylandDisplayBackend* backend, DisplayWindowHost* windowHost, bool popupWindow, WaylandDisplayWindow* owner, RenderAPI renderAPI)
: backend(backend), m_owner(owner), windowHost(windowHost), m_PopupWindow(popupWindow)
: backend(backend), m_owner(owner), windowHost(windowHost), m_PopupWindow(popupWindow), m_renderAPI(renderAPI)
{
m_AppSurface = backend->m_waylandCompositor.create_surface();

m_NativeHandle.display = backend->s_waylandDisplay;
m_NativeHandle.surface = m_AppSurface;

if (backend->m_FractionalScaleManager)
{
m_FractionalScale = backend->m_FractionalScaleManager.get_fractional_scale(m_AppSurface);
Expand Down Expand Up @@ -318,13 +321,15 @@ void WaylandDisplayWindow::OnExitEvent()

void WaylandDisplayWindow::DrawSurface(uint32_t serial)
{
m_AppSurface.attach(m_AppSurfaceBuffer, 0, 0);
m_AppSurface.damage(0, 0, m_WindowSize.width, m_WindowSize.height);

m_FrameCallback = m_AppSurface.frame();
if (m_renderAPI == RenderAPI::Unspecified || m_renderAPI == RenderAPI::Bitmap)
{
m_AppSurface.attach(m_AppSurfaceBuffer, 0, 0);
m_AppSurface.damage(0, 0, m_WindowSize.width, m_WindowSize.height);

m_FrameCallback.on_done() = bind_mem_fn(&WaylandDisplayWindow::DrawSurface, this);
m_FrameCallback = m_AppSurface.frame();

m_FrameCallback.on_done() = bind_mem_fn(&WaylandDisplayWindow::DrawSurface, this);
}
m_AppSurface.commit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <vector>

#include "zwidget/window/window.h"
#include "zwidget/window/waylandnativehandle.h"

#include <sys/mman.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -124,7 +125,7 @@ class WaylandDisplayWindow : public DisplayWindow
Point MapFromGlobal(const Point& pos) const override;
Point MapToGlobal(const Point& pos) const override;

void* GetNativeHandle() override { return (void*)&m_XDGToplevel; }
void* GetNativeHandle() override { return (void*)&m_NativeHandle; }
wayland::surface_t GetWindowSurface() { return m_AppSurface; }

private:
Expand Down Expand Up @@ -152,6 +153,9 @@ class WaylandDisplayWindow : public DisplayWindow

Point m_SurfaceMousePos = Point(0, 0);

WaylandNativeHandle m_NativeHandle;
RenderAPI m_renderAPI;

wayland::data_device_t m_DataDevice;
wayland::data_source_t m_DataSource;

Expand Down
8 changes: 2 additions & 6 deletions bugs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ Engine general:
All they currently do is to sometimes retaliate if attacked, and pick up nearby items.
* Bots literally rotate their entire body (feet off the ground) to look up/down in ways they shouldn't be able to.
* Decals don't clip to BSP correctly, or sometimes do not appear at all.
* Parsing UClasses from Strings (e.g. class'UnrealShare.DispersionPistol') is not implemented,
causing a crash because SE tries to parse them like UObjects.
* Waving water textures at the end of waterfalls render broken. Easily observable in NyLeve's Falls (Unreal) or DM-ArcaneTemple (UT)
* Inventory travelling is quite buggy: Either they travel, but get deselected upon the next level load, or cause a crash.
And not all travel types are implemented.
Expand All @@ -36,12 +34,10 @@ they end up dying because SE thinks that they've fallen from a great height.
* By design, native mods will never work with SE. Thankfully these kind of mods are extremely rare.
* [Linux/ZWidget] Wayland backend is extremely buggy due to Wayland APIs being unpleasant to work with, to name a few things:
- Menus don't properly position themselves.
- Switching menus rapidly sometimes leads to a crash.
- Assigning a wl_surface as a Vulkan surface crashes SurrealEditor, because Vulkan tries to "own" the surface(?) while the app itself also tries the same
causing a protocol error due to explicit sync.
- Sometimes menus remain persistent (due to rapidly switching?), if the user then tries to resize the parent window, it causes a crash.
- Running any ZWidget app (launcher/SurrealEditor) on GNOME will probably lead to not being able to move the window around,
because ZWidget has no custom window decorations (ZWidget uses server side decorations when they're available)
- Currently SurrealEditor crashes immediately due to a queue assertion failure.
- SurrealEngine produces a black screen that is not interactable in any way, while SurrealEditor crashes when trying to open a map

Engine general - Needs testing:
-------------------------------
Expand Down
Loading