summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorJef <54236+ElJeffe@users.noreply.github.com>2022-11-13 20:33:13 +0100
committerGitHub <noreply@github.com>2022-11-13 19:33:13 +0000
commit549fdf63f6f72fadf4e1f67f42fc2a99d625b42e (patch)
treedb06da03842266c024ea8e6d6604630cdd79d8e4 /src/helpers/MiscFunctions.cpp
parent1a14841a75b2c387b9f67b7f7c40e0b5d3e1f86b (diff)
Add bordercolor windowrule (#992)
* Add bordercolor windowrule * remove spaces form bordercolor rule + typo Co-authored-by: Jef Steelant <jef.steelant_ext@softathome.com>
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index bf20f390..706bb31e 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -450,3 +450,39 @@ int64_t getPPIDof(int64_t pid) {
}
#endif
}
+
+int64_t configStringToInt(const std::string& VALUE) {
+ if (VALUE.find("0x") == 0) {
+ // Values with 0x are hex
+ const auto VALUEWITHOUTHEX = VALUE.substr(2);
+ return stol(VALUEWITHOUTHEX, nullptr, 16);
+ } else if (VALUE.find("rgba(") == 0 && VALUE.find(")") == VALUE.length() - 1) {
+ const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6);
+
+ if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 8) {
+ Debug::log(WARN, "invalid length %i for rgba", VALUEWITHOUTFUNC.length());
+ throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes)");
+ }
+
+ const auto RGBA = std::stol(VALUEWITHOUTFUNC, nullptr, 16);
+
+ // now we need to RGBA -> ARGB. The config holds ARGB only.
+ return (RGBA >> 8) + 0x1000000 * (RGBA & 0xFF);
+ } else if (VALUE.find("rgb(") == 0 && VALUE.find(")") == VALUE.length() - 1) {
+ const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5);
+
+ if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 6) {
+ Debug::log(WARN, "invalid length %i for rgb", VALUEWITHOUTFUNC.length());
+ throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)");
+ }
+
+ const auto RGB = std::stol(VALUEWITHOUTFUNC, nullptr, 16);
+
+ return RGB + 0xFF000000; // 0xFF for opaque
+ } else if (VALUE.find("true") == 0 || VALUE.find("on") == 0 || VALUE.find("yes") == 0) {
+ return 1;
+ } else if (VALUE.find("false") == 0 || VALUE.find("off") == 0 || VALUE.find("no") == 0) {
+ return 0;
+ }
+ return stol(VALUE);
+} \ No newline at end of file