View | Details | Raw Unified | Return to bug 272831
Collapse All | Expand All

(-)b/x11/polybar/Makefile (-1 / +1 lines)
Lines 1-6 Link Here
1
PORTNAME=	polybar
1
PORTNAME=	polybar
2
DISTVERSION=	3.6.3
2
DISTVERSION=	3.6.3
3
PORTREVISION=	1
3
PORTREVISION=	2
4
CATEGORIES=	x11
4
CATEGORIES=	x11
5
MASTER_SITES=	https://github.com/polybar/polybar/releases/download/${DISTVERSION}/
5
MASTER_SITES=	https://github.com/polybar/polybar/releases/download/${DISTVERSION}/
6
6
(-)b/x11/polybar/files/patch-src_modules_cpu.cpp (+66 lines)
Added Link Here
1
diff --git src/modules/cpu.cpp src/modules/cpu.cpp
2
index 527f27fb..179d9221 100644
3
--- src/modules/cpu.cpp
4
+++ src/modules/cpu.cpp
5
@@ -2,6 +2,11 @@
6
 
7
 #include <fstream>
8
 #include <istream>
9
+#ifdef __FreeBSD__
10
+  #include <sys/types.h>
11
+  #include <sys/resource.h>
12
+  #include <sys/sysctl.h>
13
+#endif
14
 
15
 #include "drawtypes/label.hpp"
16
 #include "drawtypes/progressbar.hpp"
17
@@ -128,6 +133,41 @@ namespace modules {
18
     m_cputimes.clear();
19
 
20
     try {
21
+#ifdef __FreeBSD__
22
+      // Get number of CPUs
23
+      // ToDo: No need to do this on every invocation.
24
+      int ncpu = -1;
25
+      std::size_t sz = sizeof(ncpu);
26
+      if (sysctlbyname("hw.ncpu", &ncpu, &sz, nullptr, 0) != 0) {
27
+        m_log.err("Failed to query sysctl 'hw.ncpu' (errno: %s)", strerror(errno));
28
+        return false;
29
+      }
30
+      if (ncpu < 1) {
31
+        m_log.err("Failed to determine number of CPUs.");
32
+        return false;
33
+      }
34
+
35
+      // Query 'kern.cp_time'
36
+      long cpu_stat[CPUSTATES];
37
+      sz = sizeof(cpu_stat);
38
+      if (sysctlbyname("kern.cp_time", cpu_stat, &sz, nullptr, 0) != 0) {
39
+        m_log.err("Failed to query sysctl 'kern.cp_time' (errno: %s)", strerror(errno));
40
+        return false;
41
+      }
42
+
43
+      // Parse
44
+      static std::size_t field_offset = sizeof(*cpu_stat) + ncpu;
45
+      for (std::size_t i = 0; i < ncpu; i++) {
46
+        m_cputimes.emplace_back(new cpu_time);
47
+        m_cputimes.back()->user = cpu_stat[CP_USER];
48
+        m_cputimes.back()->nice = cpu_stat[CP_NICE];
49
+        m_cputimes.back()->system = cpu_stat[CP_SYS];
50
+        m_cputimes.back()->steal = cpu_stat[CP_INTR];   // Note: This is technically the reported "interrupt" time
51
+        m_cputimes.back()->idle = cpu_stat[CP_IDLE];
52
+        m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system +
53
+                                   m_cputimes.back()->idle + m_cputimes.back()->steal;
54
+      }
55
+#else
56
       std::ifstream in(PATH_CPU_INFO);
57
       string str;
58
 
59
@@ -148,6 +188,7 @@ namespace modules {
60
         m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system +
61
                                    m_cputimes.back()->idle + m_cputimes.back()->steal;
62
       }
63
+#endif
64
     } catch (const std::ios_base::failure& e) {
65
       m_log.err("Failed to read CPU values (what: %s)", e.what());
66
     }
(-)b/x11/polybar/files/patch-src_modules_memory.cpp (+49 lines)
Added Link Here
1
diff --git src/modules/memory.cpp src/modules/memory.cpp
2
index eb36e5dc..042d85cb 100644
3
--- src/modules/memory.cpp
4
+++ src/modules/memory.cpp
5
@@ -1,6 +1,10 @@
6
 #include <fstream>
7
 #include <iomanip>
8
 #include <istream>
9
+#ifdef __FreeBSD__
10
+  #include <sys/types.h>
11
+  #include <sys/sysctl.h>
12
+#endif
13
 
14
 #include "drawtypes/label.hpp"
15
 #include "drawtypes/progressbar.hpp"
16
@@ -63,6 +67,25 @@ namespace modules {
17
     unsigned long long kb_swap_free{0ULL};
18
 
19
     try {
20
+#ifdef __FreeBSD__
21
+      std::size_t sz;
22
+
23
+      // Total
24
+      sz = sizeof(kb_total);
25
+      if (sysctlbyname("hw.physmem", &kb_total, &sz, nullptr, 0) != 0) {
26
+        m_log.err("Failed to query sysctl 'hw.physmem' (errno: %s)", strerror(errno));
27
+        return false;
28
+      }
29
+      kb_total /= 1024;
30
+
31
+      // Available
32
+      sz = sizeof(kb_avail);
33
+      if (sysctlbyname("hw.usermem", &kb_avail, &sz, nullptr, 0) != 0) {
34
+        m_log.err("Failed to query sysctl 'hw.usermem' (errno: %s)", strerror(errno));
35
+        return false;
36
+      }
37
+      kb_avail /= 1024;
38
+#else
39
       std::ifstream meminfo(PATH_MEMORY_INFO);
40
       std::map<std::string, unsigned long long int> parsed;
41
 
42
@@ -91,6 +114,7 @@ namespace modules {
43
         // old kernel; give a best-effort approximation of available memory
44
         kb_avail = parsed["MemFree"] + parsed["Buffers"] + parsed["Cached"] + parsed["SReclaimable"] - parsed["Shmem"];
45
       }
46
+#endif
47
     } catch (const std::exception& err) {
48
       m_log.err("Failed to read memory values (what: %s)", err.what());
49
     }
(-)b/x11/polybar/pkg-message (-3 / +2 lines)
Lines 6-15 not function in FreeBSD. Link Here
6
6
7
Working modules:
7
Working modules:
8
- bspwm
8
- bspwm
9
- cpu
9
- date
10
- date
10
- github
11
- github
11
- i3
12
- i3
12
- ipc (polybar-msg method does not seem to work)
13
- ipc (polybar-msg method does not seem to work)
14
- memory
13
- menu
15
- menu
14
- mpd
16
- mpd
15
- script
17
- script
Lines 19-27 Working modules: Link Here
19
- xworkspaces (not extensively tested)
21
- xworkspaces (not extensively tested)
20
22
21
Broken modules:
23
Broken modules:
22
- cpu
23
- filesystem
24
- filesystem
24
- memory
25
- network (requires wireless_tools)
25
- network (requires wireless_tools)
26
- temperature (requires /sys/class/thermal/* in sysfs)
26
- temperature (requires /sys/class/thermal/* in sysfs)
27
- volume (requires full alsa, not a wrapper)
27
- volume (requires full alsa, not a wrapper)
28
- 

Return to bug 272831