summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorBrenno Lemos <brenno@syndel.is>2023-10-22 19:11:03 -0300
committerGitHub <noreply@github.com>2023-10-22 23:11:03 +0100
commitb135bd6cd4c27a9fd94dfa084e75188463c2eb3b (patch)
tree74f04ca3dd010c41f0fd323187bfd916747da151 /src/helpers
parent59f27e7f570170783ac01fb46a0ff90e14de53e6 (diff)
workspacerules: Add new optional "default command" for auto-launching apps on new workspaces (#3559)
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/MiscFunctions.cpp42
-rw-r--r--src/helpers/MiscFunctions.hpp2
-rw-r--r--src/helpers/VarList.hpp10
-rw-r--r--src/helpers/Workspace.hpp6
4 files changed, 56 insertions, 4 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index b3236725..3cce73d2 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -2,6 +2,7 @@
#include "../defines.hpp"
#include <algorithm>
#include "../Compositor.hpp"
+#include <optional>
#include <set>
#include <sys/utsname.h>
#include <iomanip>
@@ -503,6 +504,43 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
return result;
}
+std::optional<std::string> cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {
+
+ std::string cmd = removeBeginEndSpacesTabs(dirtyCmd);
+
+ if (!cmd.empty()) {
+ std::string rules;
+ const std::string workspaceRule = "workspace " + inWorkspaceName;
+
+ if (cmd[0] == '[') {
+ const int closingBracketIdx = cmd.find_last_of(']');
+ auto tmpRules = cmd.substr(1, closingBracketIdx - 1);
+ cmd = cmd.substr(closingBracketIdx + 1);
+
+ auto rulesList = CVarList(tmpRules, 0, ';');
+
+ bool hadWorkspaceRule = false;
+ rulesList.map([&](std::string& rule) {
+ if (rule.find("workspace") == 0) {
+ rule = workspaceRule;
+ hadWorkspaceRule = true;
+ }
+ });
+
+ if (!hadWorkspaceRule)
+ rulesList.append(workspaceRule);
+
+ rules = "[" + rulesList.join(";") + "]";
+ } else {
+ rules = "[" + workspaceRule + "]";
+ }
+
+ return std::optional<std::string>(rules + " " + cmd);
+ }
+
+ return std::nullopt;
+}
+
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2) {
const float DX = std::max({0.0, p1.x - vec.x, vec.x - p2.x});
const float DY = std::max({0.0, p1.y - vec.y, vec.y - p2.y});
@@ -594,8 +632,8 @@ int64_t getPPIDof(int64_t pid) {
return 0;
#else
- std::string dir = "/proc/" + std::to_string(pid) + "/status";
- FILE* infile;
+ std::string dir = "/proc/" + std::to_string(pid) + "/status";
+ FILE* infile;
infile = fopen(dir.c_str(), "r");
if (!infile)
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 429f381f..d489a0cd 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <optional>
#include <string>
#include <wayland-server.h>
#include <wlr/util/box.h>
@@ -20,6 +21,7 @@ std::string removeBeginEndSpacesTabs(std::string);
bool isNumber(const std::string&, bool allowfloat = false);
bool isDirection(const std::string&);
int getWorkspaceIDFromString(const std::string&, std::string&);
+std::optional<std::string> cleanCmdForWorkspace(const std::string&, std::string);
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
void logSystemInfo();
std::string execAndGet(const char*);
diff --git a/src/helpers/VarList.hpp b/src/helpers/VarList.hpp
index 60e9a551..8f33f166 100644
--- a/src/helpers/VarList.hpp
+++ b/src/helpers/VarList.hpp
@@ -1,4 +1,5 @@
#pragma once
+#include <functional>
#include <vector>
#include <string>
#include "../macros.hpp"
@@ -20,6 +21,15 @@ class CVarList {
std::string join(const std::string& joiner, size_t from = 0, size_t to = 0) const;
+ void map(std::function<void(std::string&)> func) {
+ for (auto& s : m_vArgs)
+ func(s);
+ }
+
+ void append(const std::string arg) {
+ m_vArgs.emplace_back(arg);
+ }
+
std::string operator[](const size_t& idx) const {
if (idx >= m_vArgs.size())
return "";
diff --git a/src/helpers/Workspace.hpp b/src/helpers/Workspace.hpp
index cbdbc07a..a0bbb815 100644
--- a/src/helpers/Workspace.hpp
+++ b/src/helpers/Workspace.hpp
@@ -4,8 +4,7 @@
#include <string>
#include "../defines.hpp"
-enum eFullscreenMode : int8_t
-{
+enum eFullscreenMode : int8_t {
FULLSCREEN_INVALID = -1,
FULLSCREEN_FULL = 0,
FULLSCREEN_MAXIMIZED
@@ -53,6 +52,9 @@ class CWorkspace {
// last monitor (used on reconnect)
std::string m_szLastMonitor = "";
+ // Whether the user configured command for on-created-empty has been executed, if any
+ bool m_bOnCreatedEmptyExecuted = false;
+
void startAnim(bool in, bool left, bool instant = false);
void setActive(bool on);