Skip to content

Commit

Permalink
feat: conditionally enable wayland and x11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Almamu committed May 11, 2024
1 parent a14ded1 commit 953ef01
Show file tree
Hide file tree
Showing 26 changed files with 191 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v3

- name: Install dependencies
run: sudo apt-get update && sudo apt-get -y install libxrandr-dev libfreeimage-dev libxinerama-dev libxcursor-dev libxi-dev libgl-dev libglew-dev freeglut3-dev libsdl2-dev liblz4-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libxxf86vm-dev libglm-dev libglfw3-dev libmpv-dev mpv libmpv1 libpulse-dev libpulse0 wayland-scanner++ wayland-protocols libwayland-dev libwayland-egl-backend-dev
run: sudo apt-get update && sudo apt-get -y install libfreeimage-dev libgl-dev libglew-dev freeglut3-dev libsdl2-dev liblz4-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libglm-dev libglfw3-dev libmpv-dev mpv libmpv1 libpulse-dev libpulse0 wayland-scanner++ wayland-protocols libwayland-dev libwayland-egl-backend-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
Expand Down
66 changes: 43 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
add_compile_definitions(ERRORONLY=${ERRORONLY})
add_compile_definitions(DATADIR="${DATADIR}")

find_package(X11 REQUIRED)
find_package(Xrandr REQUIRED)
find_package(X11)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLUT REQUIRED)
Expand Down Expand Up @@ -90,7 +89,6 @@ add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper)

include_directories(
${MPV_INCLUDE_DIR}
${X11_INCLUDE_DIR}
${XRANDR_INCLUDE_DIR}
${GLEW_INCLUDE_DIR}
${LZ4_INCLUDE_DIR}
Expand Down Expand Up @@ -155,6 +153,28 @@ if(WAYLAND_SUPPORT_FOUND)
"wlr-layer-shell-unstable-v1-protocol.c")
endif()

if(X11_FOUND)
if(NOT X11_Xrandr_FOUND)
message(WARNING "X11 support disabled. Xrandr package is missing")
endif()
if(NOT X11_xf86vmode_FOUND)
message(WARNING "X11 support disabled. Xxf86vm package is missing")
endif()

set(X11_SUPPORT_FOUND TRUE)
endif()

if(X11_SUPPORT_FOUND)
include_directories(${X11_INCLUDE_DIR})
add_compile_definitions(ENABLE_X11)

set(X11_SOURCES
"src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp"
"src/WallpaperEngine/Render/Drivers/Output/CX11Output.h"
"src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.cpp"
"src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h")
endif()

add_executable(
linux-wallpaperengine
main.cpp
Expand Down Expand Up @@ -241,21 +261,17 @@ add_executable(

src/WallpaperEngine/Render/Drivers/Detectors/CFullScreenDetector.cpp
src/WallpaperEngine/Render/Drivers/Detectors/CFullScreenDetector.h
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.cpp
src/WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h

src/WallpaperEngine/Render/Drivers/Output/COutput.cpp
src/WallpaperEngine/Render/Drivers/Output/COutput.h
src/WallpaperEngine/Render/Drivers/Output/CX11Output.cpp
src/WallpaperEngine/Render/Drivers/Output/CX11Output.h
src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.cpp
src/WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h
src/WallpaperEngine/Render/Drivers/Output/CGLFWOutputViewport.cpp
src/WallpaperEngine/Render/Drivers/Output/CGLFWOutputViewport.h
src/WallpaperEngine/Render/Drivers/Output/COutputViewport.cpp
src/WallpaperEngine/Render/Drivers/Output/COutputViewport.h
src/WallpaperEngine/Render/Drivers/Output/CX11OutputViewport.cpp
src/WallpaperEngine/Render/Drivers/Output/CX11OutputViewport.h
src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h
src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp
src/WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h
src/WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.cpp
src/WallpaperEngine/Render/Drivers/CVideoDriver.h
src/WallpaperEngine/Render/Drivers/CVideoDriver.cpp
src/WallpaperEngine/Render/CRenderContext.h
Expand Down Expand Up @@ -295,8 +311,8 @@ add_executable(
src/WallpaperEngine/Render/Objects/Effects/CMaterial.h
src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp

src/WallpaperEngine/WebBrowsesr/CWebBrowserContext.cpp
src/WallpaperEngine/WebBrowsesr/CWebBrowserContext.h
src/WallpaperEngine/WebBrowser/CWebBrowserContext.cpp
src/WallpaperEngine/WebBrowser/CWebBrowserContext.h

src/WallpaperEngine/FileSystem/FileSystem.cpp
src/WallpaperEngine/FileSystem/FileSystem.h
Expand Down Expand Up @@ -397,6 +413,7 @@ add_executable(
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h

${WAYLAND_SOURCES}
${X11_SOURCES}
)

COPY_FILES(linux-wallpaperengine "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${TARGET_OUTPUT_DIRECTORY}")
Expand All @@ -408,10 +425,7 @@ add_dependencies(linux-wallpaperengine libcef_dll_wrapper)
# Need to remove libvulkan, otherwise will get error on linking:
# /usr/bin/ld: /usr/lib/libmpv.so: undefined reference to `vkCreateXlibSurfaceKHR'
file(REMOVE "${CEF_BINARY_DIR_DEBUG}/libvulkan.so.1" "${CEF_BINARY_DIR_RELEASE}/libvulkan.so.1")
target_link_libraries (linux-wallpaperengine PUBLIC
${X11_LIBRARIES}
${Xrandr_LIBRARIES}
${X11_Xxf86vm_LIB}
target_link_libraries (linux-wallpaperengine PUBLIC
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${GLUT_LIBRARIES}
Expand All @@ -435,17 +449,23 @@ if (WAYLAND_SUPPORT_FOUND)
${OPENGL_egl_LIBRARY})
endif()

file(CREATE_LINK linux-wallpaperengine wallengine SYMBOLIC)
if(X11_SUPPORT_FOUND)
target_link_libraries (linux-wallpaperengine PUBLIC
${X11_LIBRARIES} ${X11_Xrandr_LIB})


set(CMAKE_REQUIRED_LIBRARIES ${X11_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${X11_LIBRARIES})

# make sure some of the X11 functions we'll use are available
check_function_exists(XSetIOErrorExitHandler HAVE_XSETIOERROREXITHANDLER)
# make sure some of the X11 functions we'll use are available
check_function_exists(XSetIOErrorExitHandler HAVE_XSETIOERROREXITHANDLER)

if(HAVE_XSETIOERROREXITHANDLER)
add_compile_definitions(HAVE_XSETIOERROREXITHANDLER=1)
if(HAVE_XSETIOERROREXITHANDLER)
add_compile_definitions(HAVE_XSETIOERROREXITHANDLER=1)
endif()
endif()

file(CREATE_LINK linux-wallpaperengine wallengine SYMBOLIC)

# set some install parameters if not in debug mode
install(TARGETS linux-wallpaperengine)
install(DIRECTORY share/ DESTINATION share/${PROJECT_NAME})
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "WallpaperEngine/Application/CApplicationContext.h"
#include "WallpaperEngine/Application/CWallpaperApplication.h"
#include "WallpaperEngine/Core/Wallpapers/CWeb.h"
#include "WallpaperEngine/WebBrowsesr/CWebBrowserContext.h"
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"
#include "common.h"

WallpaperEngine::Application::CWallpaperApplication* appPointer;
Expand Down
84 changes: 66 additions & 18 deletions src/WallpaperEngine/Application/CWallpaperApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "WallpaperEngine/Input/Drivers/CWaylandMouseInput.h"
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
#include "WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h"

#define FULLSCREEN_CHECK_WAIT_TIME 250

float g_Time;
float g_TimeLast;
Expand Down Expand Up @@ -255,26 +258,67 @@ void CWallpaperApplication::takeScreenshot (const Render::CRenderContext& contex
}

void CWallpaperApplication::show () {
const char* XDG_SESSION_TYPE = getenv ("XDG_SESSION_TYPE");

if (!XDG_SESSION_TYPE) {
sLog.exception("Cannot read environment variable XDG_SESSION_TYPE, window server detection failed. Please ensure proper values are set");
}


#ifdef ENABLE_WAYLAND
const bool WAYLAND_DISPLAY = getenv ("WAYLAND_DISPLAY");
bool isWayland = strncmp("wayland", XDG_SESSION_TYPE, strlen("wayland")) == 0;
#endif // ENABLE_WAYLAND
#ifdef ENABLE_X11
bool isX11 = strncmp("x11", XDG_SESSION_TYPE, strlen("x11")) == 0;
#endif // ENABLE_X11

// setup the right video driver based on the environment and the startup mode requested
if (WAYLAND_DISPLAY && this->m_context.settings.render.mode == CApplicationContext::DESKTOP_BACKGROUND) {
const auto waylandDriver = new WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver (this->m_context, *this);
inputContext = new WallpaperEngine::Input::CInputContext (
new WallpaperEngine::Input::Drivers::CWaylandMouseInput (waylandDriver));

videoDriver = waylandDriver;
} else
#endif
{
const auto x11Driver =
new WallpaperEngine::Render::Drivers::CX11OpenGLDriver ("wallpaperengine", this->m_context, *this);
// no wayland detected, try the old X11 method
inputContext = new WallpaperEngine::Input::CInputContext (
new WallpaperEngine::Input::Drivers::CGLFWMouseInput (x11Driver));
if (this->m_context.settings.render.mode == CApplicationContext::DESKTOP_BACKGROUND) {
#ifdef ENABLE_WAYLAND
if (isWayland) {
videoDriver = new WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver (this->m_context, *this);
inputContext = new WallpaperEngine::Input::CInputContext (
new WallpaperEngine::Input::Drivers::CWaylandMouseInput (reinterpret_cast<WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver*>(videoDriver)));
this->fullScreenDetector = new WallpaperEngine::Render::Drivers::Detectors::CWaylandFullScreenDetector(this->m_context);
}
#endif // ENABLE_WAYLAND
#ifdef ENABLE_X11
#ifdef ENABLE_WAYLAND
else
#endif // ENABLE_WAYLAND
if (isX11)
{
videoDriver = new WallpaperEngine::Render::Drivers::CGLFWOpenGLDriver ("wallpaperengine", this->m_context, *this);
inputContext = new WallpaperEngine::Input::CInputContext (
new WallpaperEngine::Input::Drivers::CGLFWMouseInput (reinterpret_cast <Render::Drivers::CGLFWOpenGLDriver*>(videoDriver)));
this->fullScreenDetector = new WallpaperEngine::Render::Drivers::Detectors::CX11FullScreenDetector (this->m_context, *reinterpret_cast <Render::Drivers::CGLFWOpenGLDriver*>(videoDriver));
}
#endif // ENABLE_X11
else {
sLog.exception("Cannot run in background mode, window server could not be detected. XDG_SESSION_TYPE must be wayland or x11");
}
} else {
videoDriver = new WallpaperEngine::Render::Drivers::CGLFWOpenGLDriver ("wallpaperengine", this->m_context, *this);

#ifdef ENABLE_WAYLAND
if (isWayland) {
this->fullScreenDetector = new WallpaperEngine::Render::Drivers::Detectors::CWaylandFullScreenDetector(this->m_context);
}
#endif // ENABLE_WAYLAND
#ifdef ENABLE_X11
#ifdef ENABLE_WAYLAND
else
#endif // ENABLE_WAYLAND
if(isX11)
{
this->fullScreenDetector = new WallpaperEngine::Render::Drivers::Detectors::CX11FullScreenDetector (this->m_context, *reinterpret_cast <Render::Drivers::CGLFWOpenGLDriver*>(videoDriver));
}
#endif // ENABLE_X11
else {
this->fullScreenDetector = new WallpaperEngine::Render::Drivers::Detectors::CFullScreenDetector (this->m_context);
}

videoDriver = x11Driver;
inputContext = new WallpaperEngine::Input::CInputContext (
new WallpaperEngine::Input::Drivers::CGLFWMouseInput (reinterpret_cast <Render::Drivers::CGLFWOpenGLDriver*>(videoDriver)));
}

if (this->m_context.settings.audio.audioprocessing) {
Expand All @@ -285,7 +329,7 @@ void CWallpaperApplication::show () {

// audio playing detector
WallpaperEngine::Audio::Drivers::Detectors::CPulseAudioPlayingDetector audioDetector (
this->m_context, videoDriver->getFullscreenDetector ());
this->m_context, *this->fullScreenDetector);
// initialize sdl audio driver
audioDriver =
new WallpaperEngine::Audio::Drivers::CSDLAudioDriver (this->m_context, audioDetector, *this->audioRecorder);
Expand Down Expand Up @@ -345,6 +389,10 @@ void CWallpaperApplication::show () {
}

void CWallpaperApplication::update (Render::Drivers::Output::COutputViewport* viewport) {
// check for fullscreen windows and wait until there's none fullscreen
while (this->fullScreenDetector->anythingFullscreen () && this->m_context.state.general.keepRunning)
usleep (FULLSCREEN_CHECK_WAIT_TIME);

// render the scene
context->render (viewport);
}
Expand Down
16 changes: 11 additions & 5 deletions src/WallpaperEngine/Application/CWallpaperApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,31 @@

#include "WallpaperEngine/Render/CRenderContext.h"
#include "WallpaperEngine/Render/CWallpaper.h"
#include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
#include "WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h"
#include "WallpaperEngine/Render/Drivers/Detectors/CFullScreenDetector.h"
#ifdef ENABLE_WAYLAND
#include "WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h"
#endif

#ifdef ENABLE_X11
#include "WallpaperEngine/Render/Drivers/Detectors/CX11FullScreenDetector.h"
#endif
#ifdef ENABLE_WAYLAND
#include "WallpaperEngine/Render/Drivers/Detectors/CWaylandFullScreenDetector.h"
#endif

#include "WallpaperEngine/Render/Drivers/Output/CGLFWWindowOutput.h"
#ifdef ENABLE_X11
#include "WallpaperEngine/Render/Drivers/Output/CX11Output.h"
#endif
#ifdef ENABLE_WAYLAND
#include "WallpaperEngine/Render/Drivers/Output/CWaylandOutput.h"
#endif

#include "WallpaperEngine/Audio/Drivers/CSDLAudioDriver.h"

#include "WallpaperEngine/Input/CInputContext.h"
#include "WallpaperEngine/WebBrowsesr/CWebBrowserContext.h"
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"

namespace WallpaperEngine::Application {
/**
Expand Down Expand Up @@ -117,12 +122,13 @@ class CWallpaperApplication {
/** Maps screens to backgrounds */
std::map<std::string, Core::CProject*> m_backgrounds;

WallpaperEngine::Audio::CAudioContext* audioContext;
WallpaperEngine::Audio::Drivers::CSDLAudioDriver* audioDriver;
WallpaperEngine::Audio::Drivers::Recorders::CPlaybackRecorder* audioRecorder;
WallpaperEngine::Render::Drivers::CVideoDriver* videoDriver;
WallpaperEngine::Input::CInputContext* inputContext;
WallpaperEngine::Audio::Drivers::CSDLAudioDriver* audioDriver;
WallpaperEngine::Render::CRenderContext* context;
WallpaperEngine::Audio::CAudioContext* audioContext;
WallpaperEngine::Render::Drivers::CVideoDriver* videoDriver;
WallpaperEngine::Render::Drivers::Detectors::CFullScreenDetector* fullScreenDetector;
WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext;
};
} // namespace WallpaperEngine::Application
4 changes: 2 additions & 2 deletions src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "CGLFWMouseInput.h"
#include <glm/common.hpp>

#include "WallpaperEngine/Render/Drivers/CX11OpenGLDriver.h"
#include "WallpaperEngine/Render/Drivers/CGLFWOpenGLDriver.h"

using namespace WallpaperEngine::Input::Drivers;

CGLFWMouseInput::CGLFWMouseInput (Render::Drivers::CX11OpenGLDriver* driver) :
CGLFWMouseInput::CGLFWMouseInput (Render::Drivers::CGLFWOpenGLDriver* driver) :
m_reportedPosition (),
m_mousePosition (),
m_driver (driver) {}
Expand Down
6 changes: 3 additions & 3 deletions src/WallpaperEngine/Input/Drivers/CGLFWMouseInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <glm/vec2.hpp>

namespace WallpaperEngine::Render::Drivers {
class CX11OpenGLDriver;
class CGLFWOpenGLDriver;
}

namespace WallpaperEngine::Input::Drivers {
Expand All @@ -14,7 +14,7 @@ namespace WallpaperEngine::Input::Drivers {
*/
class CGLFWMouseInput final : public CMouseInput {
public:
explicit CGLFWMouseInput (Render::Drivers::CX11OpenGLDriver* driver);
explicit CGLFWMouseInput (Render::Drivers::CGLFWOpenGLDriver* driver);

/**
* Takes current mouse position and updates it
Expand All @@ -27,7 +27,7 @@ class CGLFWMouseInput final : public CMouseInput {
[[nodiscard]] glm::dvec2 position () const override;

private:
Render::Drivers::CX11OpenGLDriver* m_driver;
Render::Drivers::CGLFWOpenGLDriver* m_driver;

/**
* The current mouse position
Expand Down
2 changes: 1 addition & 1 deletion src/WallpaperEngine/Render/CWallpaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "WallpaperEngine/Render/CRenderContext.h"
#include "WallpaperEngine/Render/Helpers/CContextAware.h"

#include "WallpaperEngine/WebBrowsesr/CWebBrowserContext.h"
#include "WallpaperEngine/WebBrowser/CWebBrowserContext.h"

#include "CWallpaperState.h"

Expand Down
Loading

0 comments on commit 953ef01

Please sign in to comment.