From ac7aeb0dcb49232e131d40f00b527f61430c3921 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 11 Sep 2023 23:29:56 +0100 Subject: [PATCH] internal: add a notification on missing qt-wayland packages fixes #91 --- hyprland-share-picker/main.cpp | 3 +++ src/helpers/MiscFunctions.cpp | 9 +++++++++ src/helpers/MiscFunctions.hpp | 3 ++- src/shared/ScreencopyShared.cpp | 21 +++++++++++++++++---- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/hyprland-share-picker/main.cpp b/hyprland-share-picker/main.cpp index 9deeaca..d102165 100644 --- a/hyprland-share-picker/main.cpp +++ b/hyprland-share-picker/main.cpp @@ -114,6 +114,7 @@ int main(int argc, char* argv[]) { ID = ID.substr(ID.find_last_of('(') + 1); ID = ID.substr(0, ID.find_last_of(')')); + std::cout << "[SELECTION]"; std::cout << (ALLOWTOKENBUTTON->isChecked() ? "r" : ""); std::cout << "/"; @@ -141,6 +142,7 @@ int main(int argc, char* argv[]) { mainPickerPtr->windowIDs[button] = window.id; QObject::connect(button, &QPushButton::clicked, [=]() { + std::cout << "[SELECTION]"; std::cout << (ALLOWTOKENBUTTON->isChecked() ? "r" : ""); std::cout << "/"; @@ -199,6 +201,7 @@ int main(int argc, char* argv[]) { REGION = REGION.substr(REGION.find_first_of(' ') + 1); const auto H = std::stoi(REGION); + std::cout << "[SELECTION]"; std::cout << (ALLOWTOKENBUTTON->isChecked() ? "r" : ""); std::cout << "/"; diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 956a663..da05ee6 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -3,6 +3,8 @@ #include "../helpers/Log.hpp" std::string execAndGet(const char* cmd) { + Debug::log(LOG, "execAndGet: {}", cmd); + std::array buffer; std::string result; const std::unique_ptr pipe(popen(cmd, "r"), pclose); @@ -14,4 +16,11 @@ std::string execAndGet(const char* cmd) { result += buffer.data(); } return result; +} + +void addHyprlandNotification(const std::string& icon, float timeMs, const std::string& color, const std::string& message) { + const std::string CMD = std::format("hyprctl notify {} {} {} \"{}\"", icon, timeMs, color, message); + Debug::log(LOG, "addHyprlandNotification: {}", CMD); + if (fork() == 0) + execl("/bin/sh", "/bin/sh", "-c", CMD.c_str(), nullptr); } \ No newline at end of file diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index ccefb68..fcb7cae 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -1,4 +1,5 @@ #pragma once #include -std::string execAndGet(const char* cmd); \ No newline at end of file +std::string execAndGet(const char* cmd); +void addHyprlandNotification(const std::string& icon, float timeMs, const std::string& color, const std::string& message); \ No newline at end of file diff --git a/src/shared/ScreencopyShared.cpp b/src/shared/ScreencopyShared.cpp index cc22875..bcecdf3 100644 --- a/src/shared/ScreencopyShared.cpp +++ b/src/shared/ScreencopyShared.cpp @@ -42,15 +42,28 @@ SSelectionData promptForScreencopySelection() { const char* HYPRLAND_INSTANCE_SIGNATURE = getenv("HYPRLAND_INSTANCE_SIGNATURE"); std::string cmd = - std::format("WAYLAND_DISPLAY={} QT_QPA_PLATFORM=\"wayland\" XCURSOR_SIZE={} HYPRLAND_INSTANCE_SIGNATURE={} XDPH_WINDOW_SHARING_LIST=\"{}\" hyprland-share-picker", + std::format("WAYLAND_DISPLAY={} QT_QPA_PLATFORM=\"wayland\" XCURSOR_SIZE={} HYPRLAND_INSTANCE_SIGNATURE={} XDPH_WINDOW_SHARING_LIST=\"{}\" hyprland-share-picker 2>&1", WAYLAND_DISPLAY ? WAYLAND_DISPLAY : "", XCURSOR_SIZE ? XCURSOR_SIZE : "24", HYPRLAND_INSTANCE_SIGNATURE ? HYPRLAND_INSTANCE_SIGNATURE : "0", buildWindowList()); const auto RETVAL = execAndGet(cmd.c_str()); - Debug::log(LOG, "[sc] Selection: {}", RETVAL); + if (!RETVAL.contains("[SELECTION]")) { + // failed - const auto FLAGS = RETVAL.substr(0, RETVAL.find_first_of('/')); - const auto SEL = RETVAL.substr(RETVAL.find_first_of('/') + 1); + if (RETVAL.contains("qt.qpa.plugin: Could not find the Qt platform plugin")) { + // prompt the user to install qt5-wayland and qt6-wayland + addHyprlandNotification("3", 7000, "0", "[xdph] Could not open the picker: qt5-wayland or qt6-wayland doesn't seem to be installed."); + } + + return data; + } + + const auto SELECTION = RETVAL.substr(RETVAL.find("[SELECTION]") + 11); + + Debug::log(LOG, "[sc] Selection: {}", SELECTION); + + const auto FLAGS = SELECTION.substr(0, SELECTION.find_first_of('/')); + const auto SEL = SELECTION.substr(SELECTION.find_first_of('/') + 1); for (auto& flag : FLAGS) { if (flag == 'r') {