Fix wayland build - make x11 build optional.

This commit is contained in:
jmsgrogan 2023-10-02 16:27:40 +01:00
parent 7da1d2d539
commit bb222fd84d
12 changed files with 102 additions and 32 deletions

View file

@ -1,12 +1,18 @@
set(WAYLAND_FOUND FALSE)
find_path(_WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h)
find_path(_WAYLAND_EXTENSIONS_INCLUDE_DIR NAMES xdg-shell-client-protocol.h HINTS ENV WAYLAND_EXTENSION_DIR)
find_library(_WAYLAND_CLIENT_LIBRARY NAMES wayland-client libwayland-client)
find_program(_WAYLAND_SCANNER wayland-scanner)
find_file(_WAYLAND_XDG_SHELL_PROTO xdg-shell.xml HINTS /usr/share/wayland-protocols/stable/xdg-shell)
if (_WAYLAND_CLIENT_INCLUDE_DIR AND _WAYLAND_EXTENSIONS_INCLUDE_DIR AND _WAYLAND_CLIENT_LIBRARY)
if (_WAYLAND_CLIENT_INCLUDE_DIR AND _WAYLAND_SCANNER AND _WAYLAND_CLIENT_LIBRARY)
set(WAYLAND_FOUND TRUE)
set(WAYLAND_INCLUDE_DIRS ${_WAYLAND_EXTENSIONS_INCLUDE_DIR})
set(WAYLAND_XDG_SOURCE ${_WAYLAND_EXTENSIONS_INCLUDE_DIR}/xdg-shell-protocol.cpp)
set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARY} wayland-egl)
endif()
set(WAYLAND_LIBRARIES ${_WAYLAND_CLIENT_LIBRARY} wayland-egl)
add_custom_command(OUTPUT xdg-shell-client-procotol.h
xdg-shell-protocol.c
COMMAND ${_WAYLAND_SCANNER} client-header < ${_WAYLAND_XDG_SHELL_PROTO} > xdg-shell-client-protocol.h
COMMAND ${_WAYLAND_SCANNER} private-code < ${_WAYLAND_XDG_SHELL_PROTO} > xdg-shell-protocol.c
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

View file

@ -5,8 +5,9 @@ set (platform_LIBS "")
if(UNIX)
message(STATUS "Checking dependencies for module: window")
#Find_package(X11 QUIET)
if(X11_FOUND)
Find_package(X11 QUIET)
option(NTK_WITH_X11 "Build with X11 support" OFF)
if(X11_FOUND AND ${NTK_WITH_X11})
list(APPEND platform_INCLUDES
ui_interfaces/x11/XcbInterface.cpp
ui_interfaces/x11/XcbEventInterface.cpp
@ -19,7 +20,13 @@ if(UNIX)
ui_interfaces/x11/XcbExtensionInterface.cpp
ui_interfaces/x11/XcbGlWindowInterface.cpp
)
list(APPEND platform_LIBS ${X11_LIBRARIES} ${X11_xcb_LIB} ${X11_X11_xcb_LIB} ${X11_xkbcommon_LIB} ${X11_xkbcommon_X11_LIB} libxcb-image.so)
list(APPEND platform_LIBS
${X11_LIBRARIES}
${X11_xcb_LIB}
${X11_X11_xcb_LIB}
${X11_xkbcommon_LIB}
#${X11_xkbcommon_X11_LIB}
libxcb-image.so)
list(APPEND X11_INCLUDE_DIRS ${X11_xkbcommon_INCLUDE_PATH})
list(APPEND DEFINES "HAS_X11")
else()
@ -37,16 +44,17 @@ if(UNIX)
ui_interfaces/wayland/WaylandKeyboard.cpp
ui_interfaces/wayland/WaylandEglInterface.cpp
ui_interfaces/wayland/WaylandEglWindowInterface.cpp
${WAYLAND_XDG_SOURCE}
${CMAKE_BINARY_DIR}/xdg-shell-protocol.c
)
list(APPEND platform_LIBS OpenGL::EGL)
list(APPEND DEFINES "HAS_WAYLAND")
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL QUIET)
if (OpenGL_FOUND)
list(APPEND platform_LIBS ${WAYLAND_LIBRARIES})
endif()
#if (OpenGL_FOUND)
message(STATUS "ADDING WAYLAND LIBS: " ${WAYLAND_LIBRARIES})
list(APPEND platform_LIBS ${WAYLAND_LIBRARIES} ${X11_xkbcommon_LIB})
#endif()
else()
Message(STATUS "Wayland not found - skipping support")
endif()
@ -98,6 +106,7 @@ target_include_directories(windows PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/wayland
${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/win32
${CMAKE_CURRENT_SOURCE_DIR}/ui_interfaces/win32/directx
${CMAKE_BINARY_DIR}
${WAYLAND_INCLUDE_DIRS}
${X11_INCLUDE_DIRS}
)

View file

@ -44,7 +44,7 @@ void WaylandBuffer::setUpPool(int size, int width, int height, int stride)
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 = 0;
@ -60,6 +60,7 @@ void WaylandBuffer::tearDownPool(int size)
auto wl_buffer_release = [](void *data, struct wl_buffer *wl_buffer)
{
(void)data;
wl_buffer_destroy(wl_buffer);
};
mBufferListener.release = wl_buffer_release;

View file

@ -41,11 +41,13 @@ void WaylandInterface::registryHandleGlobalEvent(void *data, struct wl_registry
void WaylandInterface::registryHandleGlobalRemoveEvent(void *data, struct wl_registry *registry, uint32_t name)
{
(void)data;
(void)registry;
(void)name;
}
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardware)
: AbstractUIInterface(desktopManager, useHardware),
mBuffer(std::make_shared<WaylandBuffer>())
{
mRegistryListener.global = registryHandleGlobalEvent;
@ -108,6 +110,7 @@ void WaylandInterface::setXdgBase(xdg_wm_base* xdg_base)
{
auto thisClass = static_cast<WaylandInterface*>(data);
thisClass->doXdgPong(serial);
(void)xdg_wm_base;
};
mXdgBaseListener.ping = xdg_ping_handler;
xdg_wm_base_add_listener(mXdgBase, &mXdgBaseListener, this);
@ -130,7 +133,7 @@ void WaylandInterface::doXdgPong(uint32_t serial)
void WaylandInterface::addWindow(mt::Window* window)
{
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mFontsManager.get(), mEglInterface.get());
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mDesktopManager->getFontsManager(), mEglInterface.get());
}
void WaylandInterface::showWindow(mt::Window* window)

View file

@ -18,7 +18,7 @@ class WaylandInterface : public AbstractUIInterface
{
public:
WaylandInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = true);
WaylandInterface(DesktopManager* desktopManager, bool useHardware = true);
~WaylandInterface();

View file

@ -13,28 +13,42 @@ void WaylandKeyboard::keyboardKeymapEvent(void *data, struct wl_keyboard *wl_key
void WaylandKeyboard::keyboardEnterEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys)
{
(void)wl_keyboard;
(void)serial;
(void)surface;
auto thisClass = static_cast<WaylandKeyboard*>(data);
thisClass->onEnterEvent(keys);
}
void WaylandKeyboard::keyboardPressedEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state)
{
(void)wl_keyboard;
(void)serial;
(void)time;
auto thisClass = static_cast<WaylandKeyboard*>(data);
thisClass->onPressedEvent(key, state);
}
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface)
{
(void)data;
(void)wl_keyboard;
(void)serial;
(void)surface;
}
static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay)
{
(void)data;
(void)wl_keyboard;
(void)rate;
(void)delay;
}
void WaylandKeyboard::keyboardModifierEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group)
{
(void)wl_keyboard;
(void)serial;
auto thisClass = static_cast<WaylandKeyboard*>(data);
thisClass->onKeyboardModifier(mods_depressed, mods_latched, mods_locked, group);
}
@ -45,8 +59,10 @@ void WaylandKeyboard::onKeyboardModifier(uint32_t mods_depressed, uint32_t mods_
}
void WaylandKeyboard::onEnterEvent(struct wl_array *keys)
{
void* key;
{
(void)keys;
/*
char* key;
wl_array_for_each(key, keys)
{
uint32_t* key_type = static_cast<uint32_t*>(key);
@ -58,15 +74,17 @@ void WaylandKeyboard::onEnterEvent(struct wl_array *keys)
xkb_state_key_get_utf8(mXkbState, *key_type + 8, buf, sizeof(buf));
//fprintf(stderr, "utf8: '%s'\n", buf);
}
*/
}
void WaylandKeyboard::onPressedEvent(uint32_t key, uint32_t state)
{
char buf[128];
(void)state;
uint32_t keycode = key + 8;
xkb_keysym_t sym = xkb_state_key_get_one_sym(mXkbState, keycode);
xkb_keysym_get_name(sym, buf, sizeof(buf));
const char *action = state == WL_KEYBOARD_KEY_STATE_PRESSED ? "press" : "release";
//const char *action = state == WL_KEYBOARD_KEY_STATE_PRESSED ? "press" : "release";
//fprintf(stderr, "key %s: sym: %-12s (%d), ", action, buf, sym);
xkb_state_key_get_utf8(mXkbState, keycode, buf, sizeof(buf));
//fprintf(stderr, "utf8: '%s'\n", buf);
@ -74,6 +92,8 @@ void WaylandKeyboard::onPressedEvent(uint32_t key, uint32_t state)
void WaylandKeyboard::onKeymapEvent(struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size)
{
(void)wl_keyboard;
(void)format;
// assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1);
char* map_shm = static_cast<char*>(mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0));
// assert(map_shm != MAP_FAILED);

View file

@ -13,7 +13,7 @@ public:
~WaylandKeyboard();
std::string getKeyString(KeyCode keyCode) override { return "";};
std::string getKeyString(KeyCode keyCode) override { (void)keyCode; return "";};
private:
static void keyboardKeymapEvent(void *data, struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size);

View file

@ -4,22 +4,34 @@
static void wl_pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
{
(void)data;
(void)wl_pointer;
(void)time;
(void)axis;
(void)value;
}
static void wl_pointer_axis_source(void *data, struct wl_pointer *wl_pointer, uint32_t axis_source)
{
(void)data;
(void)wl_pointer;
(void)axis_source;
}
static void wl_pointer_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis)
{
(void)data;
(void)wl_pointer;
(void)time;
(void)axis;
}
static void wl_pointer_axis_discrete(void *data, struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete)
{
(void)data;
(void)wl_pointer;
(void)axis;
(void)discrete;
}
WaylandPointerInterface::~WaylandPointerInterface()
@ -31,30 +43,36 @@ void WaylandPointerInterface::pointerFrameEvent(void *data, struct wl_pointer *w
{
auto thisClass = static_cast<WaylandPointerInterface*>(data);
thisClass->onPointerFrame();
(void)wl_pointer;
}
void WaylandPointerInterface::pointerEnterEvent(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
{
auto thisClass = static_cast<WaylandPointerInterface*>(data);
thisClass->onPointerEnter(serial, surface, surface_x, surface_y);
(void)wl_pointer;
}
void WaylandPointerInterface::pointerLeaveEvent(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface)
{
auto thisClass = static_cast<WaylandPointerInterface*>(data);
thisClass->onPointerLeave(serial);
(void)wl_pointer;
(void)surface;
}
void WaylandPointerInterface::pointerMotionEvent(void *data, struct wl_pointer *wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
{
auto thisClass = static_cast<WaylandPointerInterface*>(data);
thisClass->onPointerMotion(time, surface_x, surface_y);
(void)wl_pointer;
}
void WaylandPointerInterface::pointerButtonEvent(void *data, struct wl_pointer *wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
{
auto thisClass = static_cast<WaylandPointerInterface*>(data);
thisClass->onPointerButton(serial, time, button, state);
(void)wl_pointer;
}
void WaylandPointerInterface::onPointerFrame()
@ -63,6 +81,8 @@ void WaylandPointerInterface::onPointerFrame()
{
const auto locx = wl_fixed_to_double(mWorkingPointerEvent.surface_x);
const auto locy = wl_fixed_to_double(mWorkingPointerEvent.surface_y);
(void)locx;
(void)locy;
}
else if (mWorkingPointerEvent.event_mask & POINTER_EVENT_LEAVE)
{
@ -75,6 +95,7 @@ void WaylandPointerInterface::onPointerFrame()
else if (mWorkingPointerEvent.event_mask & POINTER_EVENT_BUTTON)
{
const bool released = mWorkingPointerEvent.state == WL_POINTER_BUTTON_STATE_RELEASED;
(void)released;
}
mWorkingPointerEvent = WaylandPointerEvent();
}
@ -86,6 +107,7 @@ void WaylandPointerInterface::onPointerButton(uint32_t serial, uint32_t time, ui
mWorkingPointerEvent.serial = serial;
mWorkingPointerEvent.button = button;
mWorkingPointerEvent.state = state;
}
void WaylandPointerInterface::onPointerEnter(uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
@ -94,6 +116,7 @@ void WaylandPointerInterface::onPointerEnter(uint32_t serial, struct wl_surface
mWorkingPointerEvent.serial = serial;
mWorkingPointerEvent.surface_x = surface_x;
mWorkingPointerEvent.surface_y = surface_y;
(void)surface;
}
void WaylandPointerInterface::onPointerLeave(uint32_t serial)

View file

@ -5,6 +5,7 @@
void WaylandSeatInterface::seatCapabilitiesEvent(void *data, struct wl_seat *wl_seat, uint32_t capabilities)
{
auto thisClass = static_cast<WaylandSeatInterface*>(data);
(void)wl_seat;
thisClass->onSeatCapabilitiesEvent(capabilities);
}
@ -45,4 +46,6 @@ WaylandSeatInterface::WaylandSeatInterface(wl_seat* seat)
void WaylandSeatInterface::seatNameEvent(void *data, struct wl_seat *wl_seat, const char *name)
{
MLOG_INFO("seat name: " << name);
(void)data;
(void)wl_seat;
}

View file

@ -11,7 +11,9 @@ void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_b
auto wayland_window = std::make_unique<WaylandSurface>(window, compositor, xdg_wm_base, buffer, eglInterface);
const auto drawing_mode = eglInterface ? DrawingMode::GRAPH : DrawingMode::RASTER;
window->setPlatformWindow(std::move(wayland_window), fontsManager, drawing_mode);
window->setPlatformWindow(std::move(wayland_window));
(void)fontsManager;
(void)drawing_mode;
}
WaylandSurface::WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
@ -81,6 +83,7 @@ void WaylandSurface::onConfigure(xdg_surface *xdg_surface, uint32_t serial)
void WaylandSurface::beforePaint(mt::Screen* screen)
{
(void)screen;
if (mEglWindowInterface)
{
mEglWindowInterface->initialize(mSurface, mWindow->getWidth(), mWindow->getHeight());
@ -94,6 +97,7 @@ void WaylandSurface::beforePaint(mt::Screen* screen)
void WaylandSurface::afterPaint(mt::Screen* screen)
{
(void)screen;
if (mEglWindowInterface)
{
mEglWindowInterface->afterPaint();

View file

@ -38,7 +38,8 @@ public:
void onResize(unsigned width, unsigned height)
{
(void) width;
(void) height;
}
private:

View file

@ -2,7 +2,7 @@
#include "Window.h"
#include "FileLogger.h"
#include "MainApplication.h"
#include "GuiApplication.h"
#include "TestFramework.h"