summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2022-07-18 23:19:12 +0200
committerGitHub <noreply@github.com>2022-07-18 23:19:12 +0200
commitf35d513bf55d5232936f017aa2697a6b4d64f6e6 (patch)
tree9dfaf54fc3507207cf97130f0ee16b25b9fb9b64 /src/helpers/MiscFunctions.cpp
parent10a83853ac1785d4dabcef3920ebc5a74fc7707f (diff)
parentf2c0e6ef02ebc639c525a24fcf532b989d2340bb (diff)
Merge pull request #391 from dgerblick/focuswindow-options
focuswindow options + other hyprctl bugs I found when testing
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 126600f3..8f8ee0f9 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -3,6 +3,7 @@
#include <algorithm>
#include "../Compositor.hpp"
#include <sys/utsname.h>
+#include <iomanip>
static const float transforms[][9] = {{
1.0f, 0.0f, 0.0f,
@@ -113,6 +114,29 @@ std::string getFormat(const char *fmt, ...) {
return output;
}
+std::string escapeJSONStrings(const std::string& str) {
+ std::ostringstream oss;
+ for (auto &c : str) {
+ switch (c) {
+ case '"': oss << "\\\""; break;
+ case '\\': oss << "\\\\"; break;
+ case '\b': oss << "\\b"; break;
+ case '\f': oss << "\\f"; break;
+ case '\n': oss << "\\n"; break;
+ case '\r': oss << "\\r"; break;
+ case '\t': oss << "\\t"; break;
+ default:
+ if ('\x00' <= c && c <= '\x1f') {
+ oss << "\\u"
+ << std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(c);
+ } else {
+ oss << c;
+ }
+ }
+ }
+ return oss.str();
+}
+
void scaleBox(wlr_box* box, float scale) {
box->width = std::round(box->width * scale);
box->height = std::round(box->height * scale);