Some wayland cleanup

This commit is contained in:
James Grogan 2022-11-10 10:48:22 +00:00
parent 7ce29ce8ae
commit 25b1966c0e
10 changed files with 267 additions and 252 deletions

View file

@ -30,6 +30,23 @@ sudo apt-get install libasound2-dev
sudo apt-get install libpng-dev sudo apt-get install libpng-dev
``` ```
#### Window rendering
```bash
sudo apt-get install libwayland-dev wayland-protocols
```
We need to generate suitable xdg shell c code for wayland:
```bash
mkdir $WORK_DIR
cd $WORK_DIR
wayland-scanner private-code < /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml > xdg-shell-protocol.cpp
wayland-scanner client-header < /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml > xdg-shell-client-protocol.h
export WAYLAND_EXTENSION_DIR=$WORK_DIR
```
In `xdg-shell-protocol.cpp` - we need access to `xdg_wm_base_interface` so export it also `extern const struct wl_interface xdg_wm_base_interface;` as per similar interface structs.
# Build from Source # Build from Source

View file

@ -22,34 +22,29 @@ if(UNIX)
message(STATUS "x11 development headers not found - skipping support") message(STATUS "x11 development headers not found - skipping support")
endif() endif()
find_path(WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h) find_path(WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h)
if (NOT ${WAYLAND_CLIENT_INCLUDE_DIR-NOTFOUND}) #if (NOT ${WAYLAND_CLIENT_INCLUDE_DIR-NOTFOUND})
list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR}) list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_CLIENT_INCLUDE_DIR})
find_path(WAYLAND_EXTENSIONS_INCLUDE_DIR NAMES xdg-shell-client-protocol.h find_path(WAYLAND_EXTENSIONS_INCLUDE_DIR NAMES xdg-shell-client-protocol.h HINTS ENV WAYLAND_EXTENSION_DIR)
HINTS ENV WAYLAND_EXTENSION_DIR
)
if(NOT ${WAYLAND_EXTENSIONS_INCLUDE_DIR-NOTFOUND})
find_library(
WAYLAND_CLIENT_LIBRARY
NAMES wayland-client libwayland-client
)
list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_EXTENSIONS_INCLUDE_DIR}) #if(NOT ${WAYLAND_EXTENSIONS_INCLUDE_DIR-NOTFOUND})
find_library(WAYLAND_CLIENT_LIBRARY NAMES wayland-client libwayland-client)
list(APPEND platform_INCLUDES list(APPEND WAYLAND_INCLUDE_DIRS ${WAYLAND_EXTENSIONS_INCLUDE_DIR})
ui_interfaces/wayland/WaylandWindowInterface.cpp list(APPEND platform_INCLUDES
ui_interfaces/wayland/WaylandSurface.cpp ui_interfaces/wayland/WaylandWindowInterface.cpp
ui_interfaces/wayland/WaylandBuffer.cpp ui_interfaces/wayland/WaylandSurface.cpp
${WAYLAND_EXTENSIONS_INCLUDE_DIR}/xdg-shell-protocol.cpp ui_interfaces/wayland/WaylandBuffer.cpp
) ${WAYLAND_EXTENSIONS_INCLUDE_DIR}/xdg-shell-protocol.cpp
set(_HAS_WAYLAND ON) )
else() set(_HAS_WAYLAND ON)
message(STATUS "Wayland Extensions Header not found - not building Wayland support") #else()
endif() #message(STATUS "Wayland Extensions Header not found - not building Wayland support")
else() #endif()
message(STATUS "Wayland Client Header not found - not building Wayland support") #else()
endif() #message(STATUS "Wayland Client Header not found - not building Wayland support")
#endif()
else() else()
list(APPEND platform_INCLUDES list(APPEND platform_INCLUDES
@ -87,6 +82,7 @@ target_include_directories(windows PUBLIC
) )
target_link_libraries(windows PUBLIC ${platform_LIBS} core geometry graphics ui_elements ${WAYLAND_CLIENT_LIBRARY}) target_link_libraries(windows PUBLIC ${platform_LIBS} core geometry graphics ui_elements ${WAYLAND_CLIENT_LIBRARY})
target_compile_options(windows PRIVATE -Wno-attributes) # From xdg shell autogen code
set_property(TARGET windows PROPERTY FOLDER src) set_property(TARGET windows PROPERTY FOLDER src)
set_target_properties( windows PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) set_target_properties( windows PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )

View file

@ -11,10 +11,6 @@
class WindowManager class WindowManager
{ {
private:
std::vector<WindowUPtr> mWindows;
public: public:
WindowManager(); WindowManager();
@ -33,6 +29,8 @@ public:
void OnKeyboardEvent(const KeyboardEvent* event); void OnKeyboardEvent(const KeyboardEvent* event);
private:
std::vector<WindowUPtr> mWindows;
}; };
using WindowManagerUPtr = std::unique_ptr<WindowManager>; using WindowManagerUPtr = std::unique_ptr<WindowManager>;

View file

@ -1,25 +1,21 @@
#include "WaylandBuffer.h" #include "WaylandBuffer.h"
#include "FileLogger.h"
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#include <iostream>
void WaylandBuffer::setSharedMemory(wl_shm* shared_memory)
{
mWlSharedMemory = shared_memory;
}
void WaylandBuffer::initializeSharedBuffer(int size) void WaylandBuffer::initializeSharedBuffer(int size)
{ {
mSharedMemory = std::make_unique<SharedMemory>(); mSharedMemory = std::make_unique<SharedMemory>();
mSharedMemory->allocate("/wl_shm-XXXXXX", size); mSharedMemory->allocate("/wl_shm-XXXXXX", size);
if (!mSharedMemory->isValid()) if (!mSharedMemory->isValid())
{ {
return; return;
} }
mPoolData = static_cast<uint8_t*>(mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, mSharedMemory->getFileDescriptor(), 0));
mPoolData = static_cast<uint8_t*>(mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, mSharedMemory->getFileDescriptor(), 0));
if (mPoolData == MAP_FAILED) if (mPoolData == MAP_FAILED)
{ {
close(mSharedMemory->getFileDescriptor()); close(mSharedMemory->getFileDescriptor());
@ -27,51 +23,56 @@ void WaylandBuffer::initializeSharedBuffer(int size)
} }
} }
void WaylandBuffer::setSharedMemory(wl_shm* shared_memory)
{
mWlSharedMemory = shared_memory;
}
void WaylandBuffer::setUpPool(int size, int width, int height, int stride) void WaylandBuffer::setUpPool(int size, int width, int height, int stride)
{ {
if (!mSharedMemory->isValid()) if (!mSharedMemory->isValid())
{ {
std::cout << "Failed to allocate shared memory" << std::endl; MLOG_ERROR("Failed to allocate shared memory.");
return; return;
} }
if (!mPoolData) if (!mPoolData)
{ {
std::cout << "Failed to mmap pool" << std::endl; MLOG_ERROR("Failed to allocate shared memory.");
return; return;
} }
auto pool = wl_shm_create_pool(mWlSharedMemory, mSharedMemory->getFileDescriptor(), size); auto pool = wl_shm_create_pool(mWlSharedMemory, mSharedMemory->getFileDescriptor(), size);
int index = 0; int index = 0;
// int offset = height * stride * index; // Two buffers, offset to starting point of second // int offset = height * stride * index; // Two buffers, offset to starting point of second
int offset = 0; int offset = 0;
mWorkingBuffer = wl_shm_pool_create_buffer(pool, offset, width, height, stride, WL_SHM_FORMAT_XRGB8888); mWorkingBuffer = wl_shm_pool_create_buffer(pool, offset, width, height, stride, WL_SHM_FORMAT_XRGB8888);
wl_shm_pool_destroy(pool); wl_shm_pool_destroy(pool);
close(mSharedMemory->getFileDescriptor()); close(mSharedMemory->getFileDescriptor());
} }
void WaylandBuffer::tearDownPool(int size) void WaylandBuffer::tearDownPool(int size)
{ {
munmap(mPoolData, size); munmap(mPoolData, size);
auto wl_buffer_release = [](void *data, struct wl_buffer *wl_buffer) auto wl_buffer_release = [](void *data, struct wl_buffer *wl_buffer)
{ {
wl_buffer_destroy(wl_buffer); wl_buffer_destroy(wl_buffer);
}; };
mBufferListener.release = wl_buffer_release; mBufferListener.release = wl_buffer_release;
wl_buffer_add_listener(mWorkingBuffer, &mBufferListener, nullptr); wl_buffer_add_listener(mWorkingBuffer, &mBufferListener, nullptr);
} }
uint8_t* WaylandBuffer::getPoolData() uint8_t* WaylandBuffer::getPoolData()
{ {
return mPoolData; return mPoolData;
} }
wl_buffer* WaylandBuffer::getWorkingBuffer() wl_buffer* WaylandBuffer::getWorkingBuffer()
{ {
return mWorkingBuffer; return mWorkingBuffer;
} }

View file

@ -10,26 +10,24 @@ class WaylandBuffer
{ {
public: public:
WaylandBuffer() = default; WaylandBuffer() = default;
void initializeSharedBuffer(int size);
void setSharedMemory(wl_shm* shared_memory); uint8_t* getPoolData();
wl_buffer* getWorkingBuffer();
void initializeSharedBuffer(int size); void setUpPool(int size, int width, int height, int stride);
void setSharedMemory(wl_shm* shared_memory);
uint8_t* getPoolData(); void tearDownPool(int size);
wl_buffer* getWorkingBuffer();
void setUpPool(int size, int width, int height, int stride);
void tearDownPool(int size);
private: private:
wl_shm* mWlSharedMemory{nullptr}; wl_shm* mWlSharedMemory{nullptr};
std::unique_ptr<SharedMemory> mSharedMemory; std::unique_ptr<SharedMemory> mSharedMemory;
uint8_t* mPoolData{nullptr}; uint8_t* mPoolData{nullptr};
wl_shm_pool* mPool{nullptr}; wl_shm_pool* mPool{nullptr};
wl_buffer* mWorkingBuffer{nullptr}; wl_buffer* mWorkingBuffer{nullptr};
wl_buffer_listener mBufferListener; wl_buffer_listener mBufferListener;
}; };

View file

@ -1,11 +1,7 @@
#include "WaylandSurface.h" #include "WaylandSurface.h"
#include <iostream>
#include <sys/mman.h>
#include <unistd.h>
WaylandSurface::WaylandSurface(mt::Window* window) WaylandSurface::WaylandSurface(mt::Window* window)
: mWindow(window) : mWindow(window)
{ {
} }
@ -17,21 +13,21 @@ WaylandSurface::~WaylandSurface()
void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer) void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer)
{ {
mBuffer = buffer; mBuffer = buffer;
mSurface = wl_compositor_create_surface(compositor); mSurface = wl_compositor_create_surface(compositor);
mXdgSurface = xdg_wm_base_get_xdg_surface(xdg_wm_base, mSurface); mXdgSurface = xdg_wm_base_get_xdg_surface(xdg_wm_base, mSurface);
auto xdg_surface_configure = [](void *data, struct xdg_surface *xdg_surface, uint32_t serial) auto xdg_surface_configure = [](void *data, struct xdg_surface *xdg_surface, uint32_t serial)
{ {
auto thisClass = static_cast<WaylandSurface*>(data); auto thisClass = static_cast<WaylandSurface*>(data);
thisClass->onConfigure(xdg_surface, serial); thisClass->onConfigure(xdg_surface, serial);
}; };
mXdgSurfaceListener.configure = xdg_surface_configure; mXdgSurfaceListener.configure = xdg_surface_configure;
xdg_surface_add_listener(mXdgSurface, &mXdgSurfaceListener, this); xdg_surface_add_listener(mXdgSurface, &mXdgSurfaceListener, this);
mXdgTopLevel = xdg_surface_get_toplevel(mXdgSurface); mXdgTopLevel = xdg_surface_get_toplevel(mXdgSurface);
xdg_toplevel_set_title(mXdgTopLevel, "Example client"); xdg_toplevel_set_title(mXdgTopLevel, "Example client");
wl_surface_commit(mSurface); wl_surface_commit(mSurface);
@ -49,43 +45,43 @@ void WaylandSurface::onConfigure(xdg_surface *xdg_surface, uint32_t serial)
wl_buffer* WaylandSurface::drawFrame() wl_buffer* WaylandSurface::drawFrame()
{ {
const auto width = mWindow->GetWidth(); const auto width = mWindow->GetWidth();
const auto height = mWindow->GetHeight(); const auto height = mWindow->GetHeight();
const int bitDepth = 4; const int bitDepth = 4;
const int stride = width * bitDepth; const int stride = width * bitDepth;
//const int numBuffers = 2; // i.e. front/back //const int numBuffers = 2; // i.e. front/back
const int numBuffers = 1; const int numBuffers = 1;
const int shm_pool_size = height * stride * numBuffers; const int shm_pool_size = height * stride * numBuffers;
mBuffer->initializeSharedBuffer(shm_pool_size); mBuffer->initializeSharedBuffer(shm_pool_size);
mBuffer->setUpPool(shm_pool_size, width, height, stride); mBuffer->setUpPool(shm_pool_size, width, height, stride);
int offset = 0; int offset = 0;
drawCheckerboard(width, height, offset); drawCheckerboard(width, height, offset);
mBuffer->tearDownPool(shm_pool_size); mBuffer->tearDownPool(shm_pool_size);
return mBuffer->getWorkingBuffer(); return mBuffer->getWorkingBuffer();
} }
void WaylandSurface::drawCheckerboard(int width, int height, int offset) void WaylandSurface::drawCheckerboard(int width, int height, int offset)
{ {
uint32_t *pixels = (uint32_t *)&(mBuffer->getPoolData())[offset]; uint32_t *pixels = (uint32_t *)&(mBuffer->getPoolData())[offset];
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
{ {
for (int x = 0; x < width; ++x) for (int x = 0; x < width; ++x)
{ {
if ((x + y / 8 * 8) % 16 < 8) if ((x + y / 8 * 8) % 16 < 8)
{ {
pixels[y * width + x] = 0xFF666666; pixels[y * width + x] = 0xFF666666;
} }
else else
{ {
pixels[y * width + x] = 0xFFEEEEEE; pixels[y * width + x] = 0xFFEEEEEE;
} }
} }
} }
} }

View file

@ -15,30 +15,28 @@ class WaylandSurface
{ {
public: public:
WaylandSurface(mt::Window* window);
WaylandSurface(mt::Window* window); ~WaylandSurface();
~WaylandSurface(); void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer);
void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer); void onConfigure(xdg_surface *xdg_surface, uint32_t serial);
void onConfigure(xdg_surface *xdg_surface, uint32_t serial); wl_buffer* drawFrame();
wl_buffer* drawFrame(); void drawCheckerboard(int width, int height, int offset);
void drawCheckerboard(int width, int height, int offset);
private: private:
mt::Window* mWindow{nullptr};
mt::Window* mWindow{nullptr}; wl_surface* mSurface{nullptr};
xdg_surface* mXdgSurface{nullptr};
xdg_surface_listener mXdgSurfaceListener{nullptr};
wl_surface* mSurface{nullptr}; xdg_toplevel* mXdgTopLevel{nullptr};
xdg_surface* mXdgSurface{nullptr};
xdg_surface_listener mXdgSurfaceListener{nullptr};
xdg_toplevel* mXdgTopLevel{nullptr}; std::shared_ptr<WaylandBuffer> mBuffer;
std::shared_ptr<WaylandBuffer> mBuffer;
}; };
using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>; using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>;

View file

@ -1,39 +1,46 @@
#include "WaylandWindowInterface.h" #include "WaylandWindowInterface.h"
#include "FileLogger.h"
#include "WaylandSurface.h"
#include "WaylandBuffer.h"
#include <cstring> #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() WaylandWindowInterface::WaylandWindowInterface()
: mBuffer(std::make_shared<WaylandBuffer>()) : mBuffer(std::make_shared<WaylandBuffer>())
{ {
auto registry_handle_global_func = [](void *data, struct wl_registry *registry, mRegistryListener.global = registryHandleGlobalCallback;
uint32_t name, const char *interface, uint32_t version) mRegistryListener.global_remove = registryHandleGlobalRemoveCallback;
{
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;
} }
WaylandWindowInterface::~WaylandWindowInterface() WaylandWindowInterface::~WaylandWindowInterface()
@ -41,56 +48,58 @@ WaylandWindowInterface::~WaylandWindowInterface()
} }
void WaylandWindowInterface::setXdgBase(xdg_wm_base* xdg_base) void WaylandWindowInterface::connect()
{ {
mXdgBase = xdg_base; mDisplay = wl_display_connect(nullptr);
auto xdg_ping_handler = [](void *data, struct xdg_wm_base *xdg_wm_base, uint32_t serial)
{ if (!mDisplay)
auto thisClass = static_cast<WaylandWindowInterface*>(data); {
thisClass->doXdgPong(serial); MLOG_ERROR("Display connect error");
}; return;
mXdgBaseListener.ping = xdg_ping_handler; }
xdg_wm_base_add_listener(mXdgBase, &mXdgBaseListener, this);
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) void WaylandWindowInterface::setCompositor(wl_compositor* compositor)
{ {
mCompositor = compositor; mCompositor = compositor;
} }
void WaylandWindowInterface::setSharedMemory(wl_shm* shared_memory) 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); xdg_wm_base_pong(mXdgBase, serial);
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);
} }
void WaylandWindowInterface::addWindow(mt::Window* window) void WaylandWindowInterface::addWindow(mt::Window* window)
{ {
auto surface = std::make_unique<WaylandSurface>(window); auto surface = std::make_unique<WaylandSurface>(window);
mSurfaces.push_back(std::move(surface)); mSurfaces.push_back(std::move(surface));
} }
void WaylandWindowInterface::mapWindow(mt::Window* window) void WaylandWindowInterface::mapWindow(mt::Window* window)
@ -100,15 +109,16 @@ void WaylandWindowInterface::mapWindow(mt::Window* window)
void WaylandWindowInterface::disconnect() void WaylandWindowInterface::disconnect()
{ {
if (mDisplay) if (mDisplay)
{ {
wl_display_disconnect(mDisplay); wl_display_disconnect(mDisplay);
} }
} }
void WaylandWindowInterface::run() void WaylandWindowInterface::run()
{ {
while (wl_display_dispatch(mDisplay) != -1) { while (wl_display_dispatch(mDisplay) != -1)
/* This space deliberately left blank */ {
} /* This space deliberately left blank */
}
} }

View file

@ -1,56 +1,56 @@
#pragma once #pragma once
#include "wayland-client.h"
#include "xdg-shell-client-protocol.h"
#include "Window.h" #include "Window.h"
#include "SharedMemory.h" #include "SharedMemory.h"
#include "WaylandSurface.h" #include "wayland-client.h"
#include "WaylandBuffer.h" #include "xdg-shell-client-protocol.h"
#include <iostream>
#include <vector> #include <vector>
#include <memory> #include <memory>
class WaylandSurface;
class WaylandBuffer;
class WaylandWindowInterface class WaylandWindowInterface
{ {
public: public:
WaylandWindowInterface(); WaylandWindowInterface();
~WaylandWindowInterface(); ~WaylandWindowInterface();
void setXdgBase(xdg_wm_base* xdg_base); void connect();
void doXdgPong(uint32_t serial); void disconnect();
void setCompositor(wl_compositor* compositor); void run();
void setSharedMemory(wl_shm* shared_memory); void addWindow(mt::Window* window);
void connect(); void mapWindow(mt::Window* window);
void disconnect();
void run();
void addWindow(mt::Window* window);
void mapWindow(mt::Window* window);
private: private:
static void registryHandleGlobalCallback(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);
static void registryHandleGlobalRemoveCallback(void *data, struct wl_registry *registry, uint32_t name);
std::vector<std::unique_ptr<WaylandSurface> > mSurfaces; void doXdgPong(uint32_t serial);
wl_display* mDisplay{nullptr}; void setCompositor(wl_compositor* compositor);
wl_compositor* mCompositor{nullptr};
wl_registry_listener mRegistryListener;
xdg_wm_base* mXdgBase{nullptr}; void setSharedMemory(wl_shm* shared_memory);
xdg_wm_base_listener mXdgBaseListener;
std::shared_ptr<WaylandBuffer> mBuffer; void setXdgBase(xdg_wm_base* xdg_base);
wl_display* mDisplay{nullptr};
wl_compositor* mCompositor{nullptr};
wl_registry_listener mRegistryListener;
xdg_wm_base* mXdgBase{nullptr};
xdg_wm_base_listener mXdgBaseListener;
std::vector<std::unique_ptr<WaylandSurface> > mSurfaces;
std::shared_ptr<WaylandBuffer> mBuffer;
}; };

View file

@ -1,23 +1,24 @@
#include "WaylandWindowInterface.h" #include "WaylandWindowInterface.h"
#include "Window.h" #include "Window.h"
#include "FileLogger.h"
int main() int main()
{ {
WaylandWindowInterface window_interface; FileLogger::GetInstance().Open();
window_interface.connect();
auto window = mt::Window::Create(); WaylandWindowInterface window_interface;
window->SetSize(800, 600); window_interface.connect();
window_interface.addWindow(window.get()); auto window = mt::Window::Create();
window->SetSize(800, 600);
window_interface.mapWindow(window.get()); window_interface.addWindow(window.get());
window_interface.run(); window_interface.mapWindow(window.get());
window_interface.disconnect(); window_interface.run();
return 0;
window_interface.disconnect();
return 0;
} }