diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 7930c51..fb8c4ca 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -871,19 +871,6 @@ void CHyprlock::enqueueForceUpdateTimers() { nullptr, false); } -std::string CHyprlock::spawnSync(const std::string& cmd) { - CProcess proc("/bin/sh", {"-c", cmd}); - if (!proc.runSync()) { - Debug::log(ERR, "Failed to run \"{}\"", cmd); - return ""; - } - - if (!proc.stdErr().empty()) - Debug::log(ERR, "Shell command \"{}\" STDERR:\n{}", cmd, proc.stdErr()); - - return proc.stdOut(); -} - SP CHyprlock::getScreencopy() { return m_sWaylandState.screencopy; } diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index e3cae70..2a28464 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -48,8 +48,6 @@ class CHyprlock { bool acquireSessionLock(); void releaseSessionLock(); - std::string spawnSync(const std::string& cmd); - void onKey(uint32_t key, bool down); void onClick(uint32_t button, bool down, const Vector2D& pos); void onHover(const Vector2D& pos); diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 1a9d3a1..33ac120 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -5,9 +5,11 @@ #include "MiscFunctions.hpp" #include "Log.hpp" #include +#include #include using namespace Hyprutils::String; +using namespace Hyprutils::OS; std::string absolutePath(const std::string& rawpath, const std::string& currentDir) { std::filesystem::path path(rawpath); @@ -137,3 +139,22 @@ int createPoolFile(size_t size, std::string& name) { return FD; } + +std::string spawnSync(const std::string& cmd) { + CProcess proc("/bin/sh", {"-c", cmd}); + if (!proc.runSync()) { + Debug::log(ERR, "Failed to run \"{}\"", cmd); + return ""; + } + + if (!proc.stdErr().empty()) + Debug::log(ERR, "Shell command \"{}\" STDERR:\n{}", cmd, proc.stdErr()); + + return proc.stdOut(); +} + +void spawnAsync(const std::string& cmd) { + CProcess proc("/bin/sh", {"-c", cmd}); + if (!proc.runAsync()) + Debug::log(ERR, "Failed to start \"{}\"", cmd); +} diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index c2fb126..6e7a259 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -7,3 +7,5 @@ std::string absolutePath(const std::string&, const std::string&); int64_t configStringToInt(const std::string& VALUE); int createPoolFile(size_t size, std::string& name); +std::string spawnSync(const std::string& cmd); +void spawnAsync(const std::string& cmd); diff --git a/src/renderer/AsyncResourceGatherer.cpp b/src/renderer/AsyncResourceGatherer.cpp index 45219c5..5355a3f 100644 --- a/src/renderer/AsyncResourceGatherer.cpp +++ b/src/renderer/AsyncResourceGatherer.cpp @@ -218,7 +218,7 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) { const bool ISCMD = rq.props.contains("cmd") ? std::any_cast(rq.props.at("cmd")) : false; static const auto TRIM = g_pConfigManager->getValue("general:text_trim"); - std::string text = ISCMD ? g_pHyprlock->spawnSync(rq.asset) : rq.asset; + std::string text = ISCMD ? spawnSync(rq.asset) : rq.asset; if (*TRIM) { text.erase(0, text.find_first_not_of(" \n\r\t")); diff --git a/src/renderer/widgets/Background.cpp b/src/renderer/widgets/Background.cpp index 67fb016..2971159 100644 --- a/src/renderer/widgets/Background.cpp +++ b/src/renderer/widgets/Background.cpp @@ -240,7 +240,7 @@ void CBackground::onReloadTimerUpdate() { // Path parsing and early returns if (!reloadCommand.empty()) { - path = g_pHyprlock->spawnSync(reloadCommand); + path = spawnSync(reloadCommand); if (path.ends_with('\n')) path.pop_back(); diff --git a/src/renderer/widgets/Image.cpp b/src/renderer/widgets/Image.cpp index b41928f..c777f53 100644 --- a/src/renderer/widgets/Image.cpp +++ b/src/renderer/widgets/Image.cpp @@ -32,7 +32,7 @@ void CImage::onTimerUpdate() { const std::string OLDPATH = path; if (!reloadCommand.empty()) { - path = g_pHyprlock->spawnSync(reloadCommand); + path = spawnSync(reloadCommand); if (path.ends_with('\n')) path.pop_back(); @@ -248,7 +248,7 @@ CBox CImage::getBoundingBoxWl() const { void CImage::onClick(uint32_t button, bool down, const Vector2D& pos) { if (down && !onclickCommand.empty()) - g_pHyprlock->spawnSync(onclickCommand); + spawnAsync(onclickCommand); } void CImage::onHover(const Vector2D& pos) { diff --git a/src/renderer/widgets/Label.cpp b/src/renderer/widgets/Label.cpp index 1a4ac6c..7befb19 100644 --- a/src/renderer/widgets/Label.cpp +++ b/src/renderer/widgets/Label.cpp @@ -3,6 +3,7 @@ #include "../../helpers/Log.hpp" #include "../../core/hyprlock.hpp" #include "../../helpers/Color.hpp" +#include "../../helpers/MiscFunctions.hpp" #include "../../config/ConfigDataValues.hpp" #include #include @@ -186,7 +187,7 @@ CBox CLabel::getBoundingBoxWl() const { void CLabel::onClick(uint32_t button, bool down, const Vector2D& pos) { if (down && !onclickCommand.empty()) - g_pHyprlock->spawnSync(onclickCommand); + spawnAsync(onclickCommand); } void CLabel::onHover(const Vector2D& pos) { diff --git a/src/renderer/widgets/Shape.cpp b/src/renderer/widgets/Shape.cpp index 19c2dc1..cc3e73b 100644 --- a/src/renderer/widgets/Shape.cpp +++ b/src/renderer/widgets/Shape.cpp @@ -2,6 +2,7 @@ #include "../Renderer.hpp" #include "../../config/ConfigDataValues.hpp" #include "../../core/hyprlock.hpp" +#include "../../helpers/MiscFunctions.hpp" #include #include #include @@ -112,7 +113,7 @@ CBox CShape::getBoundingBoxWl() const { void CShape::onClick(uint32_t button, bool down, const Vector2D& pos) { if (down && !onclickCommand.empty()) - g_pHyprlock->spawnSync(onclickCommand); + spawnAsync(onclickCommand); } void CShape::onHover(const Vector2D& pos) {