Преглед на файлове

allow specifying outputs with a flag

vaxerski преди 3 години
родител
ревизия
b505db103c

+ 30 - 17
src/WallpaperEngine/Application/CApplicationContext.cpp

@@ -12,22 +12,23 @@
 using namespace WallpaperEngine::Application;
 
 struct option long_options[] = {
-    { "screen-root", required_argument,  nullptr, 'r' },
-    { "bg", required_argument,           nullptr, 'b' },
-    { "window", required_argument,       nullptr, 'w' },
-    { "pkg", required_argument,          nullptr, 'p' },
-    { "dir", required_argument,          nullptr, 'd' },
-    { "silent", no_argument,             nullptr, 's' },
-    { "volume", required_argument,       nullptr, 'v' },
-    { "help", no_argument,               nullptr, 'h' },
-    { "fps", required_argument,          nullptr, 'f' },
-    { "assets-dir", required_argument,   nullptr, 'a' },
-    { "screenshot", required_argument,   nullptr, 'c' },
-    { "list-properties", no_argument,    nullptr, 'l' },
-    { "set-property", required_argument, nullptr, 'o' },
-    { "noautomute", no_argument,         nullptr, 'm' },
-    { "no-fullscreen-pause", no_argument,nullptr, 'n' },
-    { nullptr, 0,                        nullptr, 0 }
+    { "screen-root", required_argument,     nullptr, 'r' },
+    { "wayland-display", required_argument, nullptr, 'i' },
+    { "bg", required_argument,              nullptr, 'b' },
+    { "window", required_argument,          nullptr, 'w' },
+    { "pkg", required_argument,             nullptr, 'p' },
+    { "dir", required_argument,             nullptr, 'd' },
+    { "silent", no_argument,                nullptr, 's' },
+    { "volume", required_argument,          nullptr, 'v' },
+    { "help", no_argument,                  nullptr, 'h' },
+    { "fps", required_argument,             nullptr, 'f' },
+    { "assets-dir", required_argument,      nullptr, 'a' },
+    { "screenshot", required_argument,      nullptr, 'c' },
+    { "list-properties", no_argument,       nullptr, 'l' },
+    { "set-property", required_argument,    nullptr, 'o' },
+    { "noautomute", no_argument,            nullptr, 'm' },
+    { "no-fullscreen-pause", no_argument,   nullptr, 'n' },
+    { nullptr, 0,                           nullptr, 0 }
 };
 
 std::string stringPathFixes (const std::string& s)
@@ -84,7 +85,7 @@ CApplicationContext::CApplicationContext (int argc, char* argv[])
 
     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)
         {
@@ -129,6 +130,18 @@ CApplicationContext::CApplicationContext (int argc, char* argv[])
                 this->settings.general.screenBackgrounds[lastScreen] = "";
                 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':
                 if (this->settings.render.mode == X11_BACKGROUND)
                     sLog.exception ("Cannot run in both background and window mode");

+ 1 - 2
src/WallpaperEngine/Application/CWallpaperApplication.cpp

@@ -263,11 +263,10 @@ namespace WallpaperEngine::Application
     void CWallpaperApplication::show ()
     {
         // 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) {
             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());
-            this->m_context.settings.render.mode = CApplicationContext::WAYLAND_LAYER_SHELL;
         } else {
             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());

+ 14 - 1
src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp

@@ -229,6 +229,19 @@ CWaylandOpenGLDriver::CWaylandOpenGLDriver(const char* windowTitle, CApplication
     if (!waylandContext.compositor || !waylandContext.shm || !waylandContext.layerShell || m_outputs.empty())
         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 PRCURSORTHEME = wl_cursor_theme_load(NULL, XCURSORSIZE, waylandContext.shm);
 
@@ -244,7 +257,7 @@ CWaylandOpenGLDriver::CWaylandOpenGLDriver(const char* windowTitle, CApplication
     initEGL();
     
     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) {
         finishEGL();