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

Small ZWidget Wayland fixes #145

Merged
merged 3 commits into from
Nov 9, 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
25 changes: 22 additions & 3 deletions Thirdparty/ZWidget/src/window/wayland/wayland_display_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ void WaylandDisplayBackend::ConnectDeviceEvents()

m_KeyboardSerial = serial;

// Find the window to focus on by checking the surface window owns.
for (auto win: s_Windows)
{
if (win->GetWindowSurface() == surfaceEntered)
m_FocusWindow = win;
}

for (auto key: keysVec)
{
// keys parameter represents the keys pressed when entering the surface
Expand Down Expand Up @@ -228,6 +235,13 @@ void WaylandDisplayBackend::ConnectDeviceEvents()
};

m_waylandPointer.on_enter() = [this](uint32_t serial, wayland::surface_t surfaceEntered, double surfaceX, double surfaceY) {
// Find the window to focus on by checking the surface window owns.
for (auto win: s_Windows)
{
if (win->GetWindowSurface() == surfaceEntered)
m_FocusWindow = win;
}

OnMouseEnterEvent(serial);
};

Expand Down Expand Up @@ -341,7 +355,8 @@ void WaylandDisplayBackend::OnMouseEnterEvent(uint32_t serial)

void WaylandDisplayBackend::OnMouseLeaveEvent()
{
m_FocusWindow->windowHost->OnWindowMouseLeave();
if (m_FocusWindow)
m_FocusWindow->windowHost->OnWindowMouseLeave();
}

void WaylandDisplayBackend::OnMousePressEvent(InputKey button)
Expand All @@ -356,8 +371,11 @@ void WaylandDisplayBackend::OnMouseReleaseEvent(InputKey button)

void WaylandDisplayBackend::OnMouseMoveEvent(Point surfacePos)
{
m_FocusWindow->m_SurfaceMousePos = surfacePos / m_FocusWindow->m_ScaleFactor;
m_FocusWindow->windowHost->OnWindowMouseMove(m_FocusWindow->m_SurfaceMousePos);
if (m_FocusWindow)
{
m_FocusWindow->m_SurfaceMousePos = surfacePos / m_FocusWindow->m_ScaleFactor;
m_FocusWindow->windowHost->OnWindowMouseMove(m_FocusWindow->m_SurfaceMousePos);
}
}

void WaylandDisplayBackend::OnMouseWheelEvent(InputKey button)
Expand Down Expand Up @@ -390,6 +408,7 @@ std::unique_ptr<DisplayWindow> WaylandDisplayBackend::Create(DisplayWindowHost*
void WaylandDisplayBackend::OnWindowCreated(WaylandDisplayWindow* window)
{
s_Windows.push_back(window);
m_FocusWindow = window;
}

void WaylandDisplayBackend::OnWindowDestroyed(WaylandDisplayWindow* window)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void WaylandDisplayWindow::Activate()

void WaylandDisplayWindow::ShowCursor(bool enable)
{
ShowCursor(enable);
backend->ShowCursor(enable);
}

void WaylandDisplayWindow::LockCursor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class WaylandDisplayWindow : public DisplayWindow
Point MapToGlobal(const Point& pos) const override;

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

private:
// Event handlers as otherwise linking DisplayWindowHost On...() functions with Wayland events directly crashes the app
Expand Down
Loading