diff --git a/CMakeLists.txt b/CMakeLists.txt index f0eadd45a..a8d580528 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ option(USE_FRIBIDI "Support for right-to-left languages" ON) option(CHECK_ASSETS "Check if assets are installed in ../stk-assets" ON) option(USE_SYSTEM_ANGELSCRIPT "Use system angelscript instead of built-in angelscript. If you enable this option, make sure to use a compatible version." OFF) option(ENABLE_NETWORK_MULTIPLAYER "Enable network multiplayer. This will replace the online profile GUI in the main menu with the network multiplayer GUI" OFF) +option(ENABLE_WAYLAND_DEVICE "Enable Wayland device for linux build" OFF) CMAKE_DEPENDENT_OPTION(BUILD_RECORDER "Build opengl recorder" ON "NOT SERVER_ONLY;NOT USE_GLES2;NOT APPLE" OFF) @@ -413,7 +414,7 @@ if(NOT SERVER_ONLY) if(NOT USE_GLES2) target_link_libraries(supertuxkart ${OPENGL_gl_LIBRARY} glew graphics_utils) else() - target_link_libraries(supertuxkart EGL GLESv2) + target_link_libraries(supertuxkart GLESv2) endif() endif() @@ -426,7 +427,6 @@ if(UNIX AND NOT APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") target_link_libraries(supertuxkart "-fsanitize=address") endif() - target_link_libraries(supertuxkart wayland-client wayland-egl wayland-cursor EGL xkbcommon) endif() if(BUILD_RECORDER) diff --git a/lib/irrlicht/CMakeLists.txt b/lib/irrlicht/CMakeLists.txt index b42f30b0e..0dbf027cc 100644 --- a/lib/irrlicht/CMakeLists.txt +++ b/lib/irrlicht/CMakeLists.txt @@ -11,6 +11,7 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include/" if (SERVER_ONLY) add_definitions(-DNO_IRR_COMPILE_WITH_OPENGL_) add_definitions(-DNO_IRR_COMPILE_WITH_X11_) + add_definitions(-DNO_IRR_COMPILE_WITH_WAYLAND) else() if(NOT USE_GLES2) find_package(OpenGL REQUIRED) @@ -23,6 +24,10 @@ if (UNIX AND NOT APPLE) include_directories(${X11_INCLUDE_DIR}) endif() +if(ENABLE_WAYLAND_DEVICE) + add_definitions(-D_IRR_COMPILE_WITH_WAYLAND) +endif() + if(APPLE) include_directories("${CMAKE_CURRENT_SOURCE_DIR}/source/Irrlicht/MacOSX" "${CMAKE_CURRENT_SOURCE_DIR}/source/Irrlicht") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64") @@ -552,6 +557,14 @@ endif() add_library(stkirrlicht STATIC ${IRRLICHT_SOURCES}) target_link_libraries(stkirrlicht ${PNG_LIBRARY} ${JPEG_LIBRARY} ${ZLIB_LIBRARY}) +if(USE_GLES2 OR ENABLE_WAYLAND_DEVICE) + target_link_libraries(stkirrlicht EGL) +endif() + +if(ENABLE_WAYLAND_DEVICE) + target_link_libraries(stkirrlicht wayland-client wayland-egl wayland-cursor xkbcommon) +endif() + if(WIN32) target_link_libraries(stkirrlicht imm32) endif() diff --git a/lib/irrlicht/include/IrrCompileConfig.h b/lib/irrlicht/include/IrrCompileConfig.h index e567740b7..c52226721 100644 --- a/lib/irrlicht/include/IrrCompileConfig.h +++ b/lib/irrlicht/include/IrrCompileConfig.h @@ -127,8 +127,16 @@ #endif #define _IRR_POSIX_API_ #define _IRR_COMPILE_WITH_X11_DEVICE_ +//#define _IRR_COMPILE_WITH_WAYLAND #endif +#ifdef NO_IRR_COMPILE_WITH_WAYLAND +#undef _IRR_COMPILE_WITH_WAYLAND +#endif + +#ifdef _IRR_COMPILE_WITH_WAYLAND +#define _IRR_COMPILE_WITH_EGL_ +#endif //! Define _IRR_COMPILE_WITH_JOYSTICK_SUPPORT_ if you want joystick events. #define _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ @@ -211,14 +219,6 @@ define out. */ #undef _IRR_COMPILE_WITH_X11_ #endif -#define _IRR_COMPILE_WITH_WAYLAND - -#ifdef _IRR_COMPILE_WITH_WAYLAND -#define _IRR_COMPILE_WITH_EGL_ -#undef _IRR_COMPILE_WITH_X11_ -#undef _IRR_COMPILE_WITH_X11_DEVICE_ -#endif - //! Define _IRR_OPENGL_USE_EXTPOINTER_ if the OpenGL renderer should use OpenGL extensions via function pointers. /** On some systems there is no support for the dynamic extension of OpenGL via function pointers such that this has to be undef'ed. */ diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp index e1d780bbf..516a205b9 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.cpp @@ -1,7 +1,6 @@ -extern bool GLContextDebugBit; - #include "CIrrDeviceWayland.h" +#ifdef _IRR_COMPILE_WITH_WAYLAND #include #include @@ -615,6 +614,21 @@ const wl_registry_listener WaylandCallbacks::registry_listener = { //const char* wmDeleteWindow = "WM_DELETE_WINDOW"; +bool CIrrDeviceWayland::isWaylandDeviceWorking() +{ + bool is_working = false; + + wl_display* display = wl_display_connect(NULL); + + if (display != NULL) + { + is_working = true; + wl_display_disconnect(display); + } + + return is_working; +} + //! constructor CIrrDeviceWayland::CIrrDeviceWayland(const SIrrlichtCreationParameters& param) : CIrrDeviceStub(param), @@ -1401,3 +1415,5 @@ void CIrrDeviceWayland::initXAtoms() } } // end namespace + +#endif diff --git a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h index 661bca71d..96706303e 100644 --- a/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h +++ b/lib/irrlicht/source/Irrlicht/CIrrDeviceWayland.h @@ -3,6 +3,8 @@ #include "IrrCompileConfig.h" +#ifdef _IRR_COMPILE_WITH_WAYLAND + #include "CIrrDeviceStub.h" #include "IrrlichtDevice.h" #include "IImagePresenter.h" @@ -236,6 +238,7 @@ namespace irr ContextManagerEGL* EglContext; public: + static bool isWaylandDeviceWorking(); void signalEvent(const SEvent&); void addMode(const core::dimension2du &mode) { Modes.push_back(mode); } void setCurrentMode(const core::dimension2du &mode) { CurrentModes = mode; } @@ -322,5 +325,7 @@ private: } // end namespace irr +#endif + #endif // CIRRDEVICEWAYLAND_H diff --git a/lib/irrlicht/source/Irrlicht/COSOperator.cpp b/lib/irrlicht/source/Irrlicht/COSOperator.cpp index 2588ada5f..15439fc76 100644 --- a/lib/irrlicht/source/Irrlicht/COSOperator.cpp +++ b/lib/irrlicht/source/Irrlicht/COSOperator.cpp @@ -22,6 +22,9 @@ #endif #endif +#include + +#include "IrrlichtDevice.h" #if defined(_IRR_COMPILE_WITH_X11_DEVICE_) #include "CIrrDeviceLinux.h" #endif @@ -35,24 +38,16 @@ namespace irr { -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) // constructor linux - COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceLinux* device) -: OperatingSystem(osVersion), IrrDeviceLinux(device) + COSOperator::COSOperator(const core::stringc& osVersion, IrrlichtDevice* device) +: OperatingSystem(osVersion), IrrDevice(device) { } -#endif -#if defined(_IRR_COMPILE_WITH_WAYLAND) -// constructor linux - COSOperator::COSOperator(const core::stringc& osVersion, CIrrDeviceWayland* device) -: OperatingSystem(osVersion), IrrDeviceWayland(device) -{ -} -#endif // constructor -COSOperator::COSOperator(const core::stringc& osVersion) : OperatingSystem(osVersion) +COSOperator::COSOperator(const core::stringc& osVersion) +: OperatingSystem(osVersion), IrrDevice(NULL) { #ifdef _DEBUG setDebugName("COSOperator"); @@ -128,13 +123,29 @@ void COSOperator::copyToClipboard(const c8* text) const #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) OSXCopyToClipboard(text); - -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - if ( IrrDeviceLinux ) - IrrDeviceLinux->copyToClipboard(text); -#elif defined(_IRR_COMPILE_WITH_WAYLAND) - if ( IrrDeviceWayland ) - IrrDeviceWayland->copyToClipboard(text); + +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_WAYLAND) + if (IrrDevice != NULL) + { +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if (IrrDevice->getType() == EIDT_X11) + { + CIrrDeviceLinux* device = dynamic_cast(IrrDevice); + assert(device); + + device->copyToClipboard(text); + } +#endif +#if defined(_IRR_COMPILE_WITH_WAYLAND) + if (IrrDevice->getType() == EIDT_WAYLAND) + { + CIrrDeviceWayland* device = dynamic_cast(IrrDevice); + assert(device); + + device->copyToClipboard(text); + } +#endif + } #else #endif @@ -185,16 +196,32 @@ const c8* COSOperator::getTextFromClipboard() const #elif defined(_IRR_COMPILE_WITH_OSX_DEVICE_) return (OSXCopyFromClipboard()); + + -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) - if ( IrrDeviceLinux ) - return IrrDeviceLinux->getTextFromClipboard(); - return 0; - -#elif defined(_IRR_COMPILE_WITH_WAYLAND) - if ( IrrDeviceWayland ) - return IrrDeviceWayland->getTextFromClipboard(); - return 0; +#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_COMPILE_WITH_WAYLAND) + if (IrrDevice != NULL) + { +#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) + if (IrrDevice->getType() == EIDT_X11) + { + CIrrDeviceLinux* device = dynamic_cast(IrrDevice); + assert(device); + + return device->getTextFromClipboard(); + } +#endif +#if defined(_IRR_COMPILE_WITH_WAYLAND) + if (IrrDevice->getType() == EIDT_WAYLAND) + { + CIrrDeviceWayland* device = dynamic_cast(IrrDevice); + assert(device); + + return device->getTextFromClipboard(); + } +#endif + } + return 0; #else diff --git a/lib/irrlicht/source/Irrlicht/COSOperator.h b/lib/irrlicht/source/Irrlicht/COSOperator.h index c813b804a..de09d6280 100644 --- a/lib/irrlicht/source/Irrlicht/COSOperator.h +++ b/lib/irrlicht/source/Irrlicht/COSOperator.h @@ -10,8 +10,7 @@ namespace irr { -class CIrrDeviceLinux; -class CIrrDeviceWayland; +class IrrlichtDevice; //! The Operating system operator provides operation system specific methods and informations. class COSOperator : public IOSOperator @@ -19,12 +18,7 @@ class COSOperator : public IOSOperator public: // constructor -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) - COSOperator(const core::stringc& osversion, CIrrDeviceLinux* device); -#endif -#if defined(_IRR_COMPILE_WITH_WAYLAND) - COSOperator(const core::stringc& osversion, CIrrDeviceWayland* device); -#endif + COSOperator(const core::stringc& osversion, IrrlichtDevice* device); COSOperator(const core::stringc& osversion); //! returns the current operation system version as string. @@ -59,14 +53,7 @@ public: private: core::stringc OperatingSystem; - -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) - CIrrDeviceLinux * IrrDeviceLinux; -#endif -#if defined(_IRR_COMPILE_WITH_WAYLAND) - CIrrDeviceWayland * IrrDeviceWayland; -#endif - + IrrlichtDevice* IrrDevice; }; diff --git a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp index 4c6210f96..6c5a8ab47 100644 --- a/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp +++ b/lib/irrlicht/source/Irrlicht/COpenGLDriver.cpp @@ -704,6 +704,7 @@ COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params, bool COpenGLDriver::changeRenderContext(const SExposedVideoData& videoData, CIrrDeviceWayland* device) { + //TODO return true; } @@ -722,7 +723,7 @@ bool COpenGLDriver::initDriver(CIrrDeviceWayland* device) return true; } -#endif // _IRR_COMPILE_WITH_X11_DEVICE_ +#endif // _IRR_COMPILE_WITH_WAYLAND diff --git a/lib/irrlicht/source/Irrlicht/Irrlicht.cpp b/lib/irrlicht/source/Irrlicht/Irrlicht.cpp index 775af04ca..4c6a1746e 100644 --- a/lib/irrlicht/source/Irrlicht/Irrlicht.cpp +++ b/lib/irrlicht/source/Irrlicht/Irrlicht.cpp @@ -95,7 +95,12 @@ namespace irr #ifdef _IRR_COMPILE_WITH_WAYLAND if (params.DeviceType == EIDT_WAYLAND || (!dev && params.DeviceType == EIDT_BEST)) - dev = new CIrrDeviceWayland(params); + { + if (CIrrDeviceWayland::isWaylandDeviceWorking()) + { + dev = new CIrrDeviceWayland(params); + } + } #endif #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ diff --git a/src/guiengine/widgets/CGUIEditBox.cpp b/src/guiengine/widgets/CGUIEditBox.cpp index 978ff1d1c..2e74397f3 100644 --- a/src/guiengine/widgets/CGUIEditBox.cpp +++ b/src/guiengine/widgets/CGUIEditBox.cpp @@ -109,8 +109,12 @@ CGUIEditBox::~CGUIEditBox() if (Operator) Operator->drop(); #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ - CIrrDeviceLinux* dl = dynamic_cast(irr_driver->getDevice()); - dl->setIMEEnable(false); + if (irr_driver->getDevice()->getType() == irr::EIDT_X11) + { + CIrrDeviceLinux* dl = dynamic_cast( + irr_driver->getDevice()); + dl->setIMEEnable(false); + } #endif #endif } @@ -243,7 +247,6 @@ bool CGUIEditBox::OnEvent(const SEvent& event) #ifndef SERVER_ONLY if (isEnabled()) { - switch(event.EventType) { case EET_GUI_EVENT: @@ -255,16 +258,24 @@ bool CGUIEditBox::OnEvent(const SEvent& event) setTextMarkers(0,0); } #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ - CIrrDeviceLinux* dl = dynamic_cast(irr_driver->getDevice()); - dl->setIMEEnable(false); + if (irr_driver->getDevice()->getType() == irr::EIDT_X11) + { + CIrrDeviceLinux* dl = dynamic_cast( + irr_driver->getDevice()); + dl->setIMEEnable(false); + } #endif } #ifdef _IRR_COMPILE_WITH_X11_DEVICE_ else if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) { - CIrrDeviceLinux* dl = dynamic_cast(irr_driver->getDevice()); - dl->setIMEEnable(true); - dl->setIMELocation(calculateICPos()); + if (irr_driver->getDevice()->getType() == irr::EIDT_X11) + { + CIrrDeviceLinux* dl = dynamic_cast( + irr_driver->getDevice()); + dl->setIMEEnable(true); + dl->setIMELocation(calculateICPos()); + } } #endif break; @@ -1634,10 +1645,14 @@ void CGUIEditBox::calculateScrollPos() // todo: adjust scrollbar #if defined(_IRR_COMPILE_WITH_X11_DEVICE_) - CIrrDeviceLinux* dl = dynamic_cast(irr_driver->getDevice()); - if (dl) + if (irr_driver->getDevice()->getType() == irr::EIDT_X11) { - dl->setIMELocation(calculateICPos()); + CIrrDeviceLinux* dl = dynamic_cast( + irr_driver->getDevice()); + if (dl) + { + dl->setIMELocation(calculateICPos()); + } } #endif #endif // SERVER_ONLY