diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d0798b..8d09c34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,17 @@ list(TRANSFORM QT_MODULES PREPEND "Qt6::") list(APPEND LINK_LIBS ${QT_MODULES}) if (UNIX AND NOT APPLE) - find_package(PkgConfig REQUIRED) - list(APPEND PKGCONFIG_MODULES "xcb" "xcb-ewmh") - foreach(PKG IN LISTS PKGCONFIG_MODULES) - pkg_check_modules("${PKG}" REQUIRED IMPORTED_TARGET "${PKG}") - endforeach() - list(TRANSFORM PKGCONFIG_MODULES PREPEND "PkgConfig::") - list(APPEND LINK_LIBS ${PKGCONFIG_MODULES}) + find_package(PkgConfig QUIET) + if (PkgConfig_FOUND) + pkg_check_modules(XCB QUIET IMPORTED_TARGET xcb xcb-ewmh) + endif() + if (TARGET PkgConfig::XCB) + list(APPEND LINK_LIBS PkgConfig::XCB) + add_compile_definitions(BLOBDROP_WITH_X11) + message(STATUS "X11 terminal lowering enabled") + else() + message(STATUS "X11 terminal lowering disabled (requires xcb and xcb-ewmh)") + endif() endif() include(FetchContent) diff --git a/Dockerfile b/Dockerfile index 1e9588c..0687ace 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,6 @@ # Run with: podman run -v "$PWD:/output" blobdrop FROM docker.io/vimpostor/appimage-qt6 -RUN apt-get -y install libxcb-ewmh-dev - ADD . /build WORKDIR /build RUN scripts/build-appimage.sh diff --git a/README.md b/README.md index 5392ebf..e91b941 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ cmake --build build cmake --install build ``` +X11 terminal lowering is enabled automatically on Unix (except macOS) when `pkg-config` finds the `xcb` and `xcb-ewmh` development packages. Otherwise, it is omitted; Qt still supports running Blobdrop on X11 without it. + # Usage ```bash diff --git a/doc/man/man1/blobdrop.1 b/doc/man/man1/blobdrop.1 index d7c4577..0026fd3 100644 --- a/doc/man/man1/blobdrop.1 +++ b/doc/man/man1/blobdrop.1 @@ -104,7 +104,7 @@ This frontend starts the drag operation automatically without showing a GUI in b .br Due to limitations in Wayland, this option is only available on X11. This option also works over XWayland, but then the target drop location is required to be running in XWayland too. Native Wayland does not have support for this frontend, because the spec requires an implicit grab for native wl_data_device::start_drag() operations, thus making it impossible to implement this workflow on Wayland. .br -Another feature implemented in immediate mode is that the parent terminal window will be hidden automatically during the drag operation, unless the +When built with the optional xcb and xcb-ewmh dependencies available, another feature implemented in immediate mode is that the parent terminal window will be hidden automatically during the drag operation, unless the .B \-\-persistent option is set. This is useful for usecases where the target application is hidden behind the terminal where blobdrop was started from, which is often the case with floating window managers. This is an additional second usability improvement that is unfortunately also not possible to implement on Wayland due to "security" restrictions. diff --git a/flake.nix b/flake.nix index bac21e7..01c5e2e 100644 --- a/flake.nix +++ b/flake.nix @@ -24,8 +24,6 @@ qt6.qtbase qt6.qtdeclarative qt6.qtsvg - xorg.libxcb - xorg.xcbutilwm ]; cmakeFlags = quartz.lib.cmakeWrapper { inherit pkgs; cmakeFile = ./CMakeLists.txt; }; diff --git a/src/backend.cpp b/src/backend.cpp index 7469b42..89db5d4 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -122,7 +122,7 @@ void Backend::copy_to_clipboard(const std::vector &paths) { } void Backend::hide_terminal() { -#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#ifdef BLOBDROP_WITH_X11 if (Settings::get()->suppress_always_on_bottom || Settings::get()->intercept || !Stdin::get()->is_tty || !xcb.init()) { return; } @@ -135,7 +135,7 @@ void Backend::hide_terminal() { } void Backend::restore_terminal() { -#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#ifdef BLOBDROP_WITH_X11 if (!last_window) { return; } diff --git a/src/backend.hpp b/src/backend.hpp index 40ad82e..2855cc8 100644 --- a/src/backend.hpp +++ b/src/backend.hpp @@ -9,7 +9,7 @@ #include "Util/util.hpp" #include "path.hpp" -#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#ifdef BLOBDROP_WITH_X11 #include "xcb.hpp" #endif @@ -36,7 +36,7 @@ class Backend : public QObject { void drag_finished(); private: QDrag *drag = nullptr; -#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#ifdef BLOBDROP_WITH_X11 Xcb xcb; xcb_window_t last_window = 0; #endif diff --git a/src/xcb.cpp b/src/xcb.cpp index 3eea257..018f6ed 100644 --- a/src/xcb.cpp +++ b/src/xcb.cpp @@ -1,6 +1,6 @@ #include "xcb.hpp" -#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#ifdef BLOBDROP_WITH_X11 #include #include diff --git a/src/xcb.hpp b/src/xcb.hpp index 70dc6eb..f086b0e 100644 --- a/src/xcb.hpp +++ b/src/xcb.hpp @@ -2,7 +2,7 @@ #include -#if !defined(Q_OS_WIN) && !defined(Q_OS_DARWIN) +#ifdef BLOBDROP_WITH_X11 #include #include