allow specifying outputs with a flag

This commit is contained in:
vaxerski 2023-04-19 21:02:44 +01:00
parent 5b1ea68164
commit b505db103c
3 changed files with 45 additions and 20 deletions

View File

@ -13,6 +13,7 @@ using namespace WallpaperEngine::Application;
struct option long_options[] = { struct option long_options[] = {
{ "screen-root", required_argument, nullptr, 'r' }, { "screen-root", required_argument, nullptr, 'r' },
{ "wayland-display", required_argument, nullptr, 'i' },
{ "bg", required_argument, nullptr, 'b' }, { "bg", required_argument, nullptr, 'b' },
{ "window", required_argument, nullptr, 'w' }, { "window", required_argument, nullptr, 'w' },
{ "pkg", required_argument, nullptr, 'p' }, { "pkg", required_argument, nullptr, 'p' },
@ -84,7 +85,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv[])
std::string lastScreen; std::string lastScreen;
while ((c = getopt_long (argc, argv, "b:r:p:d:shf:a:w:mn", long_options, nullptr)) != -1) while ((c = getopt_long (argc, argv, "b:ri:p:d:shf:a:w:mn", long_options, nullptr)) != -1)
{ {
switch (c) switch (c)
{ {
@ -129,6 +130,18 @@ CApplicationContext::CApplicationContext (int argc, char* argv[])
this->settings.general.screenBackgrounds[lastScreen] = ""; this->settings.general.screenBackgrounds[lastScreen] = "";
break; break;
case 'i':
if (this->settings.general.screenBackgrounds.find (optarg) != this->settings.general.screenBackgrounds.end ())
sLog.exception ("Cannot specify the same screen more than once: ", optarg);
if (this->settings.render.mode == EXPLICIT_WINDOW)
sLog.exception ("Cannot run in both background and window mode");
this->settings.render.mode = WAYLAND_LAYER_SHELL;
lastScreen = optarg;
this->settings.general.screenBackgrounds[lastScreen] = "";
break;
case 'w': case 'w':
if (this->settings.render.mode == X11_BACKGROUND) if (this->settings.render.mode == X11_BACKGROUND)
sLog.exception ("Cannot run in both background and window mode"); sLog.exception ("Cannot run in both background and window mode");

View File

@ -263,11 +263,10 @@ namespace WallpaperEngine::Application
void CWallpaperApplication::show () void CWallpaperApplication::show ()
{ {
// initialize OpenGL driver // initialize OpenGL driver
const bool WAYLAND = getenv("WAYLAND_DISPLAY"); const bool WAYLAND = getenv("WAYLAND_DISPLAY") && this->m_context.settings.render.mode == CApplicationContext::WAYLAND_LAYER_SHELL;
if (WAYLAND) { if (WAYLAND) {
videoDriver = std::make_unique<WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver>("wallpaperengine", this->m_context, this); videoDriver = std::make_unique<WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver>("wallpaperengine", this->m_context, this);
inputContext = std::make_unique<WallpaperEngine::Input::CInputContext>(*(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver*)videoDriver.get()); inputContext = std::make_unique<WallpaperEngine::Input::CInputContext>(*(WallpaperEngine::Render::Drivers::CWaylandOpenGLDriver*)videoDriver.get());
this->m_context.settings.render.mode = CApplicationContext::WAYLAND_LAYER_SHELL;
} else { } else {
videoDriver = std::make_unique<WallpaperEngine::Render::Drivers::CX11OpenGLDriver>("wallpaperengine", this->m_context); videoDriver = std::make_unique<WallpaperEngine::Render::Drivers::CX11OpenGLDriver>("wallpaperengine", this->m_context);
inputContext = std::make_unique<WallpaperEngine::Input::CInputContext>(*(WallpaperEngine::Render::Drivers::CX11OpenGLDriver*)videoDriver.get()); inputContext = std::make_unique<WallpaperEngine::Input::CInputContext>(*(WallpaperEngine::Render::Drivers::CX11OpenGLDriver*)videoDriver.get());

View File

@ -229,6 +229,19 @@ CWaylandOpenGLDriver::CWaylandOpenGLDriver(const char* windowTitle, CApplication
if (!waylandContext.compositor || !waylandContext.shm || !waylandContext.layerShell || m_outputs.empty()) if (!waylandContext.compositor || !waylandContext.shm || !waylandContext.layerShell || m_outputs.empty())
sLog.exception("Failed to bind to required interfaces"); sLog.exception("Failed to bind to required interfaces");
SWaylandOutput* outputToUse = nullptr;
for (auto& o : m_outputs) {
if (std::find_if(context.settings.general.screenBackgrounds.begin(), context.settings.general.screenBackgrounds.end(), [&] (const auto& e) { return e.first == o->name; }) != context.settings.general.screenBackgrounds.end()) {
outputToUse = o.get();
break;
}
}
if (!outputToUse) {
sLog.debug("Failed to find any output, using first");
outputToUse = m_outputs[0].get();
}
const auto XCURSORSIZE = getenv("XCURSOR_SIZE") ? std::stoi(getenv("XCURSOR_SIZE")) : 24; const auto XCURSORSIZE = getenv("XCURSOR_SIZE") ? std::stoi(getenv("XCURSOR_SIZE")) : 24;
const auto PRCURSORTHEME = wl_cursor_theme_load(NULL, XCURSORSIZE, waylandContext.shm); const auto PRCURSORTHEME = wl_cursor_theme_load(NULL, XCURSORSIZE, waylandContext.shm);
@ -244,7 +257,7 @@ CWaylandOpenGLDriver::CWaylandOpenGLDriver(const char* windowTitle, CApplication
initEGL(); initEGL();
waylandContext.layerSurface.surface = wl_compositor_create_surface(waylandContext.compositor); waylandContext.layerSurface.surface = wl_compositor_create_surface(waylandContext.compositor);
waylandContext.layerSurface.layerSurface = zwlr_layer_shell_v1_get_layer_surface(waylandContext.layerShell, waylandContext.layerSurface.surface, m_outputs[0]->output, ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "linux-wallpaperengine"); waylandContext.layerSurface.layerSurface = zwlr_layer_shell_v1_get_layer_surface(waylandContext.layerShell, waylandContext.layerSurface.surface, outputToUse->output, ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "linux-wallpaperengine");
if (!waylandContext.layerSurface.layerSurface) { if (!waylandContext.layerSurface.layerSurface) {
finishEGL(); finishEGL();