mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-10 08:51:19 +12:00
Wayland: Use viewporter (#836)
This commit is contained in:
parent
d903b2cf12
commit
4ae5b4f8b8
10 changed files with 647 additions and 21 deletions
|
@ -505,7 +505,7 @@ target_link_libraries(CemuCafe PRIVATE
|
|||
|
||||
if (ENABLE_WAYLAND)
|
||||
# PUBLIC because wayland-client.h is included in VulkanAPI.h
|
||||
target_link_libraries(CemuCafe PUBLIC Wayland::client)
|
||||
target_link_libraries(CemuCafe PUBLIC Wayland::Client)
|
||||
endif()
|
||||
|
||||
if (ENABLE_WXWIDGETS)
|
||||
|
|
|
@ -153,7 +153,7 @@ if(ENABLE_WXWIDGETS AND UNIX AND NOT APPLE)
|
|||
# PUBLIC because gdk/gdkkeysyms.h is included in guiWrapper.h
|
||||
target_link_libraries(CemuGui PUBLIC GTK3::gtk)
|
||||
if (ENABLE_WAYLAND)
|
||||
target_link_libraries(CemuGui PRIVATE Wayland::client)
|
||||
target_link_libraries(CemuGui PRIVATE Wayland::Client CemuWaylandProtocols)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
|
@ -67,9 +67,8 @@ void VulkanCanvas::OnResize(wxSizeEvent& event)
|
|||
#if BOOST_OS_LINUX && HAS_WAYLAND
|
||||
if(m_subsurface)
|
||||
{
|
||||
int32_t x,y;
|
||||
GetScreenPosition(&x,&y);
|
||||
m_subsurface->setPosition(x, y);
|
||||
auto sRect = GetScreenRect();
|
||||
m_subsurface->setSize(sRect.GetX(), sRect.GetY(), sRect.GetWidth(), sRect.GetHeight());
|
||||
}
|
||||
#endif
|
||||
const wxSize size = GetSize();
|
||||
|
|
|
@ -7,16 +7,22 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wx/wx.h>
|
||||
#include "wayland-viewporter-client-protocol.h"
|
||||
|
||||
class wxWlSubsurface
|
||||
{
|
||||
static void registry_add_object(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
|
||||
{
|
||||
auto wlSubsurface = static_cast<wxWlSubsurface*>(data);
|
||||
|
||||
if (!strcmp(interface, wl_subcompositor_interface.name))
|
||||
{
|
||||
auto wlSubsurface = static_cast<wxWlSubsurface*>(data);
|
||||
wlSubsurface->m_subcompositor = static_cast<wl_subcompositor*>(wl_registry_bind(registry, name, &wl_subcompositor_interface, 1));
|
||||
}
|
||||
else if (!strcmp(interface, wp_viewporter_interface.name))
|
||||
{
|
||||
wlSubsurface->m_viewporter = static_cast<wp_viewporter*>(wl_registry_bind(registry, name, &wp_viewporter_interface, 1));
|
||||
}
|
||||
}
|
||||
static void registry_remove_object(void* /*data*/, struct wl_registry* /*registry*/, uint32_t /*name*/) {}
|
||||
|
||||
|
@ -24,8 +30,12 @@ class wxWlSubsurface
|
|||
wl_subcompositor* m_subcompositor;
|
||||
wl_surface* m_surface;
|
||||
wl_subsurface* m_subsurface;
|
||||
wp_viewporter* m_viewporter = NULL;
|
||||
wp_viewport* m_viewport = NULL;
|
||||
int32_t m_xPos = 0;
|
||||
int32_t m_yPos = 0;
|
||||
int32_t m_width = 0;
|
||||
int32_t m_height = 0;
|
||||
|
||||
public:
|
||||
wxWlSubsurface(wxWindow* window)
|
||||
|
@ -41,25 +51,30 @@ public:
|
|||
wl_registry_add_listener(registry, &m_registry_listener, this);
|
||||
wl_display_roundtrip(display);
|
||||
m_surface = wl_compositor_create_surface(compositor);
|
||||
if (m_viewporter)
|
||||
m_viewport = wp_viewporter_get_viewport(m_viewporter, m_surface);
|
||||
wl_region* region = wl_compositor_create_region(compositor);
|
||||
wl_surface_set_input_region(m_surface, region);
|
||||
m_subsurface = wl_subcompositor_get_subsurface(m_subcompositor, m_surface, surface);
|
||||
wl_subsurface_set_desync(m_subsurface);
|
||||
window->GetScreenPosition(&m_xPos, &m_yPos);
|
||||
wl_subsurface_set_position(m_subsurface, m_xPos, m_yPos);
|
||||
wl_surface_commit(m_surface);
|
||||
auto sRect = window->GetScreenRect();
|
||||
setSize(sRect.x, sRect.y, sRect.width, sRect.height);
|
||||
wl_region_destroy(region);
|
||||
}
|
||||
|
||||
wl_surface* getSurface() const { return m_surface; }
|
||||
|
||||
void setPosition(int32_t xPos, int32_t yPos)
|
||||
void setSize(int32_t xPos, int32_t yPos, int32_t width, int32_t height)
|
||||
{
|
||||
if (xPos != m_xPos || m_yPos != yPos)
|
||||
if (xPos != m_xPos || m_yPos != yPos || m_width != width || m_height != height)
|
||||
{
|
||||
m_xPos = xPos;
|
||||
m_yPos = yPos;
|
||||
m_height = height;
|
||||
m_width = width;
|
||||
wl_subsurface_set_position(m_subsurface, m_xPos, m_yPos);
|
||||
if (m_viewport)
|
||||
wp_viewport_set_destination(m_viewport, m_width, m_height);
|
||||
wl_surface_commit(m_surface);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue