core: run onclick commands asnychronously
Some checks failed
Build / nix (push) Has been cancelled

This commit is contained in:
Maximilian Seidler 2025-04-28 09:58:09 +02:00
parent d28d2d8ae7
commit 59f6cb5ac3
9 changed files with 31 additions and 21 deletions

View file

@ -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<CCZwlrScreencopyManagerV1> CHyprlock::getScreencopy() {
return m_sWaylandState.screencopy;
}

View file

@ -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);

View file

@ -5,9 +5,11 @@
#include "MiscFunctions.hpp"
#include "Log.hpp"
#include <hyprutils/string/String.hpp>
#include <hyprutils/os/Process.hpp>
#include <unistd.h>
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);
}

View file

@ -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);

View file

@ -218,7 +218,7 @@ void CAsyncResourceGatherer::renderText(const SPreloadRequest& rq) {
const bool ISCMD = rq.props.contains("cmd") ? std::any_cast<bool>(rq.props.at("cmd")) : false;
static const auto TRIM = g_pConfigManager->getValue<Hyprlang::INT>("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"));

View file

@ -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();

View file

@ -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) {

View file

@ -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 <hyprlang.hpp>
#include <stdexcept>
@ -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) {

View file

@ -2,6 +2,7 @@
#include "../Renderer.hpp"
#include "../../config/ConfigDataValues.hpp"
#include "../../core/hyprlock.hpp"
#include "../../helpers/MiscFunctions.hpp"
#include <cmath>
#include <hyprlang.hpp>
#include <sys/types.h>
@ -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) {