Skip to content

Commit

Permalink
WaylandDisplayBackend: Set m_FocusWindow on the relevant events.
Browse files Browse the repository at this point in the history
  • Loading branch information
LupertEverett authored and dpjudas committed Nov 9, 2024
1 parent 45426b7 commit 4f01846
Showing 1 changed file with 22 additions and 3 deletions.
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

0 comments on commit 4f01846

Please sign in to comment.