aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorArkadiusz Bokowy <arkadiusz.bokowy@gmail.com>2016-02-11 19:35:10 (GMT)
committerArkadiusz Bokowy <arkadiusz.bokowy@gmail.com>2016-02-28 13:55:36 (GMT)
commit53de872163d61c87fa8128767ebbc218599f3835 (patch)
tree582749e335f9acfcbc29e3aa0887eb4960a32829 /src/FbTk
parent22866c4d30f5b289c429c5ca88d800200db4fc4f (diff)
downloadfluxbox-53de872163d61c87fa8128767ebbc218599f3835.zip
fluxbox-53de872163d61c87fa8128767ebbc218599f3835.tar.bz2
Mixed relative and absolute values for apps
Allow setting relative value for x and y or width and height separately in the apps configuration file. This makes these settings compatible with ones available in the keys file. Previous buggy behavior: If someone has specified, e.g. "[Dimensions] {50% 100}" it was parsed as "{50% 100%}" not as "{50% 100px}" which was inconsistent with the "keys" configuration file. From now on it is possible to write something like this: [app] [Position] (RIGHT) {50% 0} [Dimensions] {300 100%} [end] Signed-off-by: Arkadiusz Bokowy <arkadiusz.bokowy@gmail.com>
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/StringUtil.hh35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh
index 2f7c6fc..bfa3a5c 100644
--- a/src/FbTk/StringUtil.hh
+++ b/src/FbTk/StringUtil.hh
@@ -24,6 +24,12 @@
24 24
25#include <string> 25#include <string>
26 26
27#ifdef HAVE_CSTDLIB
28#include <cstdlib>
29#else
30#include <stdlib.h>
31#endif
32
27namespace FbTk { 33namespace FbTk {
28 34
29namespace StringUtil { 35namespace StringUtil {
@@ -61,12 +67,12 @@ std::string findExtension(const std::string &filename);
61/// @param found - position of found char in alphabet (optional) 67/// @param found - position of found char in alphabet (optional)
62/// @return position of trigger if found 68/// @return position of trigger if found
63/// @return std::string::npos if nothing found 69/// @return std::string::npos if nothing found
64std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in, 70std::string::size_type findCharFromAlphabetAfterTrigger(const std::string& in,
65 char trigger, 71 char trigger,
66 const char alphabet[], size_t len_alphabet, size_t* found); 72 const char alphabet[], size_t len_alphabet, size_t* found);
67 73
68/// @return copy of original with find_string replaced with "replace" 74/// @return copy of original with find_string replaced with "replace"
69std::string replaceString(const std::string &original, 75std::string replaceString(const std::string &original,
70 const char *find_string, 76 const char *find_string,
71 const char *replace); 77 const char *replace);
72 78
@@ -143,6 +149,31 @@ stringtok (Container &container, std::string const &in,
143 } 149 }
144} 150}
145 151
152/// Parse token, which might be in formats as follows: <int>, <int>% or *.
153/// @param relative - parsed relative value (percentage suffix)
154/// @param ignore - this token should be ignored (asterisk)
155/// @return parsed integer value or 0 if not applicable
156template <typename Container>
157static int
158parseSizeToken(Container &container, bool &relative, bool &ignore) {
159
160 if (container.empty())
161 return 0;
162
163 relative = false;
164 ignore = false;
165
166 if (container[0] == '*') {
167 ignore = true;
168 return 0;
169 }
170
171 if (container[container.size() - 1] == '%')
172 relative = true;
173
174 return atoi(container.c_str());
175}
176
146} // end namespace StringUtil 177} // end namespace StringUtil
147 178
148} // end namespace FbTk 179} // end namespace FbTk