aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-24 02:59:58 +0100
committerMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-01-24 02:59:58 +0100
commit2707be71994c015b873c4879e8ebb41fb511cbf3 (patch)
treecea24eaba6b570774899390e8b4bdc0ce32a71f5
parentfe35ea633a423bad35589f25fa44b1fe71136ea3 (diff)
use log10 in numlen
-rw-r--r--common/util.c13
-rw-r--r--swaygrab/CMakeLists.txt1
2 files changed, 7 insertions, 7 deletions
diff --git a/common/util.c b/common/util.c
index 243f90a8..25a3e861 100644
--- a/common/util.c
+++ b/common/util.c
@@ -1,3 +1,5 @@
+#include <math.h>
+
#include "util.h"
int wrap(int i, int max) {
@@ -5,13 +7,10 @@ int wrap(int i, int max) {
}
int numlen(int n) {
- if (n >= 1000000) return 7;
- if (n >= 100000) return 6;
- if (n >= 10000) return 5;
- if (n >= 1000) return 4;
- if (n >= 100) return 3;
- if (n >= 10) return 2;
- return 1;
+ if (n == 0) {
+ return n;
+ }
+ return log10(n) + 1;
}
static struct modifier_key {
diff --git a/swaygrab/CMakeLists.txt b/swaygrab/CMakeLists.txt
index 9035ac8b..85ad3907 100644
--- a/swaygrab/CMakeLists.txt
+++ b/swaygrab/CMakeLists.txt
@@ -10,6 +10,7 @@ target_link_libraries(swaygrab
sway-common
${JSONC_LIBRARIES}
rt
+ m
)
install(