Some wayland cleanup
This commit is contained in:
parent
7ce29ce8ae
commit
25b1966c0e
10 changed files with 267 additions and 252 deletions
|
@ -1,39 +1,46 @@
|
|||
#include "WaylandWindowInterface.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
#include "WaylandSurface.h"
|
||||
#include "WaylandBuffer.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
void WaylandWindowInterface::registryHandleGlobalCallback(void *data, struct wl_registry *registry,
|
||||
uint32_t name, const char *interface, uint32_t version)
|
||||
{
|
||||
auto thisClass = static_cast<WaylandWindowInterface*>(data);
|
||||
|
||||
std::stringstream sstrm;
|
||||
sstrm << "interface: " << interface << " version " << version << " name " << name;
|
||||
MLOG_INFO(sstrm.str());
|
||||
|
||||
if (strcmp(interface, wl_compositor_interface.name) == 0)
|
||||
{
|
||||
thisClass->setCompositor(static_cast<wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 4)));
|
||||
}
|
||||
else if (strcmp(interface, wl_shm_interface.name) == 0)
|
||||
{
|
||||
thisClass->setSharedMemory(static_cast<wl_shm*>(wl_registry_bind(registry, name, &wl_shm_interface, 1)));
|
||||
}
|
||||
else if (strcmp(interface, xdg_wm_base_interface.name) == 0)
|
||||
{
|
||||
thisClass->setXdgBase(static_cast<xdg_wm_base*>(wl_registry_bind(registry, name, &xdg_wm_base_interface, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::registryHandleGlobalRemoveCallback(void *data, struct wl_registry *registry, uint32_t name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
WaylandWindowInterface::WaylandWindowInterface()
|
||||
: mBuffer(std::make_shared<WaylandBuffer>())
|
||||
: mBuffer(std::make_shared<WaylandBuffer>())
|
||||
{
|
||||
auto registry_handle_global_func = [](void *data, struct wl_registry *registry,
|
||||
uint32_t name, const char *interface, uint32_t version)
|
||||
{
|
||||
auto thisClass = static_cast<WaylandWindowInterface*>(data);
|
||||
|
||||
printf("interface: '%s', version: %d, name: %d\n", interface, version, name);
|
||||
|
||||
if (strcmp(interface, wl_compositor_interface.name) == 0)
|
||||
{
|
||||
thisClass->setCompositor(static_cast<wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, 4)));
|
||||
}
|
||||
else if (strcmp(interface, wl_shm_interface.name) == 0)
|
||||
{
|
||||
thisClass->setSharedMemory(static_cast<wl_shm*>(wl_registry_bind(registry, name, &wl_shm_interface, 1)));
|
||||
}
|
||||
else if (strcmp(interface, xdg_wm_base_interface.name) == 0)
|
||||
{
|
||||
thisClass->setXdgBase(static_cast<xdg_wm_base*>(wl_registry_bind(registry, name, &xdg_wm_base_interface, 1)));
|
||||
}
|
||||
};
|
||||
|
||||
auto registry_handle_global_remove_func = [](void *data, struct wl_registry *registry,
|
||||
uint32_t name)
|
||||
{
|
||||
// This space deliberately left blank;
|
||||
};
|
||||
|
||||
mRegistryListener.global = registry_handle_global_func;
|
||||
mRegistryListener.global_remove = registry_handle_global_remove_func;
|
||||
mRegistryListener.global = registryHandleGlobalCallback;
|
||||
mRegistryListener.global_remove = registryHandleGlobalRemoveCallback;
|
||||
}
|
||||
|
||||
WaylandWindowInterface::~WaylandWindowInterface()
|
||||
|
@ -41,56 +48,58 @@ WaylandWindowInterface::~WaylandWindowInterface()
|
|||
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::setXdgBase(xdg_wm_base* xdg_base)
|
||||
void WaylandWindowInterface::connect()
|
||||
{
|
||||
mXdgBase = xdg_base;
|
||||
auto xdg_ping_handler = [](void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
|
||||
{
|
||||
auto thisClass = static_cast<WaylandWindowInterface*>(data);
|
||||
thisClass->doXdgPong(serial);
|
||||
};
|
||||
mXdgBaseListener.ping = xdg_ping_handler;
|
||||
xdg_wm_base_add_listener(mXdgBase, &mXdgBaseListener, this);
|
||||
mDisplay = wl_display_connect(nullptr);
|
||||
|
||||
if (!mDisplay)
|
||||
{
|
||||
MLOG_ERROR("Display connect error");
|
||||
return;
|
||||
}
|
||||
|
||||
auto registry = wl_display_get_registry(mDisplay);
|
||||
if (!registry)
|
||||
{
|
||||
MLOG_ERROR("Failed to get registry");
|
||||
return;
|
||||
}
|
||||
|
||||
wl_registry_add_listener(registry, &mRegistryListener, this);
|
||||
wl_display_roundtrip(mDisplay);
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::doXdgPong(uint32_t serial)
|
||||
void WaylandWindowInterface::setXdgBase(xdg_wm_base* xdg_base)
|
||||
{
|
||||
xdg_wm_base_pong(mXdgBase, serial);
|
||||
mXdgBase = xdg_base;
|
||||
auto xdg_ping_handler = [](void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
|
||||
{
|
||||
auto thisClass = static_cast<WaylandWindowInterface*>(data);
|
||||
thisClass->doXdgPong(serial);
|
||||
};
|
||||
mXdgBaseListener.ping = xdg_ping_handler;
|
||||
xdg_wm_base_add_listener(mXdgBase, &mXdgBaseListener, this);
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::setCompositor(wl_compositor* compositor)
|
||||
{
|
||||
mCompositor = compositor;
|
||||
mCompositor = compositor;
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::setSharedMemory(wl_shm* shared_memory)
|
||||
{
|
||||
mBuffer->setSharedMemory(shared_memory);
|
||||
mBuffer->setSharedMemory(shared_memory);
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::connect()
|
||||
void WaylandWindowInterface::doXdgPong(uint32_t serial)
|
||||
{
|
||||
mDisplay = wl_display_connect(nullptr);
|
||||
|
||||
if (!mDisplay)
|
||||
{
|
||||
std::cout << "Display connect error" << std::endl;
|
||||
}
|
||||
|
||||
auto registry = wl_display_get_registry(mDisplay);
|
||||
if (!registry)
|
||||
{
|
||||
std::cout << "Failed to get registry" << std::endl;
|
||||
}
|
||||
|
||||
wl_registry_add_listener(registry, &mRegistryListener, this);
|
||||
wl_display_roundtrip(mDisplay);
|
||||
xdg_wm_base_pong(mXdgBase, serial);
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::addWindow(mt::Window* window)
|
||||
{
|
||||
auto surface = std::make_unique<WaylandSurface>(window);
|
||||
mSurfaces.push_back(std::move(surface));
|
||||
auto surface = std::make_unique<WaylandSurface>(window);
|
||||
mSurfaces.push_back(std::move(surface));
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::mapWindow(mt::Window* window)
|
||||
|
@ -100,15 +109,16 @@ void WaylandWindowInterface::mapWindow(mt::Window* window)
|
|||
|
||||
void WaylandWindowInterface::disconnect()
|
||||
{
|
||||
if (mDisplay)
|
||||
{
|
||||
wl_display_disconnect(mDisplay);
|
||||
}
|
||||
if (mDisplay)
|
||||
{
|
||||
wl_display_disconnect(mDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::run()
|
||||
{
|
||||
while (wl_display_dispatch(mDisplay) != -1) {
|
||||
/* This space deliberately left blank */
|
||||
}
|
||||
while (wl_display_dispatch(mDisplay) != -1)
|
||||
{
|
||||
/* This space deliberately left blank */
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue