ASSISTANT
The error occurs because the `registry_global_handler` and `registry_global_remove_handler` functions are member functions of the `waylandDisplay` class, and as such, they need to be accessed through an instance of the class.
To resolve this error, you can modify the `displayInit` function to use the member functions of the `waylandDisplay` class instance. Here's how you can update the `displayInit` function:
waylandDisplay.h:
```cpp
#ifndef WAYLAND_DISPLAY_H
#define WAYLAND_DISPLAY_H
#include <wayland-client-protocol.h>
#include <wayland-egl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#define CLUSTER_WIDTH 800
#define CLUSTER_HEIGHT 600
class waylandDisplay
{
public:
static waylandDisplay& getInstance();
bool displayInit();
void registry_global_remove_handler(void *data, struct wl_registry *registry, uint32_t name);
void registry_global_handler(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);
private:
waylandDisplay();
waylandDisplay(const waylandDisplay&) = delete;
waylandDisplay& operator=(const waylandDisplay&) = delete;
EGLDisplay egldisplay;
EGLConfig config;
EGLSurface eglsurface;
EGLContext eglcontext;
struct wl_compositor *compositor;
struct wl_subcompositor *subcompositor;
struct wl_shm *shm;
struct wl_shell *shell;
struct wl_surface *parent_surface;
struct wl_surface *child_surface;
struct wl_display *display;
EGLNativeDisplayType eglNativeDisplayType;
EGLNativeWindowType native_window;
EGLint majorVersion;
EGLint minorVersion;
EGLBoolean eRetStatus;
EGLint contextAttribs[3];
EGLint attribList[13];
};
#endif
```
waylandDisplay.cpp:
```cpp
#include "waylandDisplay.h"
#include <iostream>
waylandDisplay& waylandDisplay::getInstance()
{
static waylandDisplay instance;
return instance;
}
waylandDisplay::waylandDisplay()
{
egldisplay = nullptr;
config = nullptr;
eglsurface = nullptr;
eglcontext = nullptr;
compositor = nullptr;
subcompositor = nullptr;
shm = nullptr;
shell = nullptr;
parent_surface = nullptr;
child_surface = nullptr;
display = nullptr;
eglNativeDisplayType = nullptr;
native_window = nullptr;
majorVersion = 0;
minorVersion = 0;
eRetStatus = EGL_FALSE;
contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION;
contextAttribs[1] = 3;
contextAttribs[2] = EGL_NONE;
attribList[0] = EGL_RED_SIZE;
attribList[1] = 5;
attribList[2] = EGL_GREEN_SIZE;
attribList[3] = 6;
attribList[4] = EGL_BLUE_SIZE;
attribList[5] = 5;
attribList[6] = EGL_ALPHA_SIZE;
attribList[7] = (ES_WINDOW_RGB & ES_WINDOW_ALPHA) ? 8 : EGL_DONT_CARE;
attribList[8] = EGL_DEPTH_SIZE;
attribList[9] = (ES_WINDOW_RGB & ES_WINDOW_DEPTH) ? 8 : EGL_DONT_CARE;
attribList[10] = EGL_STENCIL_SIZE;
attribList[11] = (ES_WINDOW_RGB & ES_WINDOW_STENCIL) ? 8 : EGL_DONT_CARE;
attribList[12] = EGL_NONE;
}
bool waylandDisplay::displayInit()
{
int width = 1;
int height = 1;
int stride = width * 4;
int size = stride * height;
const wl_registry_listener registry_listener = {
.global = [](void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
waylandDisplay::getInstance().registry_global_handler(data, registry, name, interface, version);
},
.global_remove = [](void *data, struct wl_registry *registry, uint32_t name) {
waylandDisplay::getInstance().registry_global_remove_handler(data, registry, name);
}};
struct wl_subsurface *subsurface;
display = wl_display_connect(NULL);
struct wl_registry *registry = wl_display_get_registry(display);
wl_registry_add_listener(registry, ®istry_listener, NULL);
// wait for the "initial" set of globals to appear
wl_display_roundtrip(display);
child_surface = wl_compositor_create_surface(compositor);
parent_surface = wl_compositor_create_surface(compositor);
subsurface = wl_subcompositor_get_subsurface(subcompositor, child_surface, parent_surface);
struct wl_shell_surface *shell_surface = wl_shell_get_shell_surface(shell, parent_surface);
wl_shell_surface_set_toplevel(shell_surface);
int fd = syscall(SYS_memfd_create, "buffer", 0);
ftruncate(fd, size);
unsigned char *data = static_cast<unsigned char *>(mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0));
struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size);
struct wl_buffer *buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, WL_SHM_FORMAT_XRGB8888);
wl_surface_attach(parent_surface, buffer, 0, 0);
wl_subsurface_set_desync(subsurface);
wl_subsurface_set_position(subsurface, 0, 200);
egldisplay = eglGetDisplay(static_cast<EGLNativeDisplayType>(display));
if (egldisplay == EGL_NO_DISPLAY)
{
std::cout << "Error while eglGetDisplay" << std::endl;
}
eRetStatus = eglInitialize(egldisplay, &majorVersion, &minorVersion);
if (eRetStatus != EGL_TRUE)
{
std::cout << "Error while eglInitialize" << std::endl;
}
eRetStatus = eglChooseConfig(egldisplay, attribList, &config, 1, &numConfigs);
if (eRetStatus != EGL_TRUE)
{
std::cout << "Error while eglChooseConfig" << std::endl;
}
// native_window = EGL_DEFAULT_WINDOW;
native_window = wl_egl_window_create(child_surface, CLUSTER_WIDTH, CLUSTER_HEIGHT);
eglsurface = eglCreateWindowSurface(egldisplay, config,
native_window, NULL);
if (eglsurface == EGL_NO_SURFACE)
{
std::cout << "Error while eglCreateWindowSurface" << std::endl;
}
eglcontext = eglCreateContext(egldisplay, config,
EGL_NO_CONTEXT, contextAttribs);
if (eglcontext == EGL_NO_CONTEXT)
{
std::cout << "Error while eglCreateContext" << std::endl;
}
eRetStatus = eglMakeCurrent(egldisplay, eglsurface,
eglsurface, eglcontext);
if (eRetStatus == EGL_TRUE)
{
return true;
}
else
{
return false;
}
}
void waylandDisplay::registry_global_remove_handler(void *data, struct wl_registry *registry, uint32_t name)
{
// Implementation of registry_global_remove_handler function
}
void waylandDisplay::registry_global_handler(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
{
// Implementation of registry_global_handler function
if (strcmp(interface, "wl_compositor") == 0)
{
compositor = (wl_compositor *)wl_registry_bind(registry, name, &wl_compositor_interface, 3);
}
else if (strcmp(interface, "wl_subcompositor") == 0)
{
subcompositor = (wl_subcompositor *)wl_registry_bind(registry, name, &wl_subcompositor_interface, 1);
}
else if (strcmp(interface, "wl_shm") == 0)
{
shm = (wl_shm *)wl_registry_bind(registry, name, &wl_shm_interface, 1);
}
else if (strcmp(interface, "wl_shell") == 0)
{
shell = (wl_shell *)wl_registry_bind(registry, name, &wl_shell_interface, 1);
}
}
```
In the `displayInit` function, the `registry_global_handler` and `registry_global_remove_handler` functions are called using the `waylandDisplay::getInstance()` to access the singleton instance of the `waylandDisplay` class. This way, the member functions of the class can be correctly utilized within the listener context.