From d4e3f4cfdd84a97238016361c9b4d6436d8f387f Mon Sep 17 00:00:00 2001 From: wolfwood Date: Mon, 16 Mar 2026 20:55:00 -0500 Subject: [PATCH] Add an option to accept an X11 window id as an argument and draw in it rather than opening a new window. --- src/ProjectMSDLApplication.cpp | 5 +++++ src/SDLRenderingWindow.cpp | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/ProjectMSDLApplication.cpp b/src/ProjectMSDLApplication.cpp index 3d12e58..2ba4399 100644 --- a/src/ProjectMSDLApplication.cpp +++ b/src/ProjectMSDLApplication.cpp @@ -233,6 +233,11 @@ void ProjectMSDLApplication::defineOptions(Poco::Util::OptionSet& options) options.addOption(Option("beatSensitivity", "", "Beat sensitivity. Between 0.0 and 2.0. Default 1.0.", false, "", true) .binding("projectM.beatSensitivity", _commandLineOverrides)); +#ifdef __linux__ + options.addOption(Option("window_id", "wid", "Existing X11 window id to draw in.", + false, "", true) + .binding("window.wid", _commandLineOverrides)); +#endif } int ProjectMSDLApplication::main(POCO_UNUSED const std::vector& args) diff --git a/src/SDLRenderingWindow.cpp b/src/SDLRenderingWindow.cpp index efac35e..201bb44 100644 --- a/src/SDLRenderingWindow.cpp +++ b/src/SDLRenderingWindow.cpp @@ -204,6 +204,10 @@ void SDLRenderingWindow::CreateSDLWindow() int top{_config->getInt("top", 0)}; bool positionOverridden = _config->getBool("overridePosition", false); +#ifdef __linux__ + uint64_t wid{_config->getUInt64("wid", 0)}; +#endif + if (!positionOverridden) { left = SDL_WINDOWPOS_UNDEFINED; @@ -249,8 +253,18 @@ void SDLRenderingWindow::CreateSDLWindow() SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); #endif - _renderingWindow = SDL_CreateWindow("projectM", left, top, width, height, - SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); +#ifdef __linux__ + if (wid) { + SDL_SetHint(SDL_HINT_VIDEO_FOREIGN_WINDOW_OPENGL, "1"); + _renderingWindow = SDL_CreateWindowFrom((void*)wid); + } + else +#endif + { + _renderingWindow = SDL_CreateWindow("projectM", left, top, width, height, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + } + if (!_renderingWindow) { auto errorMessage = "Could not create SDL rendering window. Error: " + std::string(SDL_GetError());