From bb222fd84d7d0dd6bd75d12ccd2f6adf179c42c0 Mon Sep 17 00:00:00 2001 From: jmsgrogan Date: Mon, 2 Oct 2023 16:27:40 +0100 Subject: [PATCH] Fix wayland build - make x11 build optional. --- infra/cmake/FindWayland.cmake | 18 +++++++---- src/ui/windows/CMakeLists.txt | 23 +++++++++----- .../ui_interfaces/wayland/WaylandBuffer.cpp | 3 +- .../wayland/WaylandInterface.cpp | 11 ++++--- .../ui_interfaces/wayland/WaylandInterface.h | 2 +- .../ui_interfaces/wayland/WaylandKeyboard.cpp | 30 +++++++++++++++--- .../ui_interfaces/wayland/WaylandKeyboard.h | 2 +- .../wayland/WaylandPointerInterface.cpp | 31 ++++++++++++++++--- .../wayland/WaylandSeatInterface.cpp | 3 ++ .../ui_interfaces/wayland/WaylandSurface.cpp | 6 +++- .../ui_interfaces/wayland/WaylandSurface.h | 3 +- test/windows/TestWaylandWindow.cpp | 2 +- 12 files changed, 102 insertions(+), 32 deletions(-) diff --git a/infra/cmake/FindWayland.cmake b/infra/cmake/FindWayland.cmake index b95929d..9edee90 100644 --- a/infra/cmake/FindWayland.cmake +++ b/infra/cmake/FindWayland.cmake @@ -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() \ No newline at end of file + 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() diff --git a/src/ui/windows/CMakeLists.txt b/src/ui/windows/CMakeLists.txt index 695da51..09b72d6 100644 --- a/src/ui/windows/CMakeLists.txt +++ b/src/ui/windows/CMakeLists.txt @@ -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} ) diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandBuffer.cpp b/src/ui/windows/ui_interfaces/wayland/WaylandBuffer.cpp index 513e3f2..beb2606 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandBuffer.cpp +++ b/src/ui/windows/ui_interfaces/wayland/WaylandBuffer.cpp @@ -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; diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandInterface.cpp b/src/ui/windows/ui_interfaces/wayland/WaylandInterface.cpp index 520711e..e5f02b9 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandInterface.cpp +++ b/src/ui/windows/ui_interfaces/wayland/WaylandInterface.cpp @@ -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, bool useHardware) - : AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware), +WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardware) + : AbstractUIInterface(desktopManager, useHardware), mBuffer(std::make_shared()) { mRegistryListener.global = registryHandleGlobalEvent; @@ -108,6 +110,7 @@ void WaylandInterface::setXdgBase(xdg_wm_base* xdg_base) { auto thisClass = static_cast(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) diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandInterface.h b/src/ui/windows/ui_interfaces/wayland/WaylandInterface.h index dfa1159..1fdc82a 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandInterface.h +++ b/src/ui/windows/ui_interfaces/wayland/WaylandInterface.h @@ -18,7 +18,7 @@ class WaylandInterface : public AbstractUIInterface { public: - WaylandInterface(DesktopManager* desktopManager, std::unique_ptr fontsManager, bool useHardware = true); + WaylandInterface(DesktopManager* desktopManager, bool useHardware = true); ~WaylandInterface(); diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.cpp b/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.cpp index 95a6e49..1687027 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.cpp +++ b/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.cpp @@ -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(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(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(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(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(mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0)); // assert(map_shm != MAP_FAILED); diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.h b/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.h index 4fd6ea5..b8dc0bd 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.h +++ b/src/ui/windows/ui_interfaces/wayland/WaylandKeyboard.h @@ -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); diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandPointerInterface.cpp b/src/ui/windows/ui_interfaces/wayland/WaylandPointerInterface.cpp index 6cebe57..9f4e189 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandPointerInterface.cpp +++ b/src/ui/windows/ui_interfaces/wayland/WaylandPointerInterface.cpp @@ -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(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(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(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(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(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) diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandSeatInterface.cpp b/src/ui/windows/ui_interfaces/wayland/WaylandSeatInterface.cpp index a9f9935..68ae3e5 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandSeatInterface.cpp +++ b/src/ui/windows/ui_interfaces/wayland/WaylandSeatInterface.cpp @@ -5,6 +5,7 @@ void WaylandSeatInterface::seatCapabilitiesEvent(void *data, struct wl_seat *wl_seat, uint32_t capabilities) { auto thisClass = static_cast(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; } diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandSurface.cpp b/src/ui/windows/ui_interfaces/wayland/WaylandSurface.cpp index 2a40199..f3fe6a0 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandSurface.cpp +++ b/src/ui/windows/ui_interfaces/wayland/WaylandSurface.cpp @@ -11,7 +11,9 @@ void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_b auto wayland_window = std::make_unique(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 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(); diff --git a/src/ui/windows/ui_interfaces/wayland/WaylandSurface.h b/src/ui/windows/ui_interfaces/wayland/WaylandSurface.h index 762e1e4..275e548 100644 --- a/src/ui/windows/ui_interfaces/wayland/WaylandSurface.h +++ b/src/ui/windows/ui_interfaces/wayland/WaylandSurface.h @@ -38,7 +38,8 @@ public: void onResize(unsigned width, unsigned height) { - + (void) width; + (void) height; } private: diff --git a/test/windows/TestWaylandWindow.cpp b/test/windows/TestWaylandWindow.cpp index 93be811..861b1de 100644 --- a/test/windows/TestWaylandWindow.cpp +++ b/test/windows/TestWaylandWindow.cpp @@ -2,7 +2,7 @@ #include "Window.h" #include "FileLogger.h" - +#include "MainApplication.h" #include "GuiApplication.h" #include "TestFramework.h"