git: 6cdddcb8fd5d - main - x11/polybar: Add patches for CPU and memory modules
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 06 Aug 2023 03:05:51 UTC
The branch main has been updated by rigoletto: URL: https://cgit.FreeBSD.org/ports/commit/?id=6cdddcb8fd5df5db70abb86c4abe56664b60c7f9 commit 6cdddcb8fd5df5db70abb86c4abe56664b60c7f9 Author: Joel Bodenmann <jbo@insane.engineer> AuthorDate: 2023-08-06 03:04:55 +0000 Commit: Alexandre C. Guimarães <rigoletto@FreeBSD.org> CommitDate: 2023-08-06 03:04:55 +0000 x11/polybar: Add patches for CPU and memory modules - give it to Joel Bodenmann <jbo@insane.engineer> PR: 272831 --- x11/polybar/Makefile | 4 +- x11/polybar/files/patch-src_modules_cpu.cpp | 66 ++++++++++++++++++++++++++ x11/polybar/files/patch-src_modules_memory.cpp | 49 +++++++++++++++++++ x11/polybar/pkg-message | 4 +- 4 files changed, 119 insertions(+), 4 deletions(-) diff --git a/x11/polybar/Makefile b/x11/polybar/Makefile index c0de6b457108..a3272a58bb56 100644 --- a/x11/polybar/Makefile +++ b/x11/polybar/Makefile @@ -1,10 +1,10 @@ PORTNAME= polybar DISTVERSION= 3.6.3 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= x11 MASTER_SITES= https://github.com/polybar/polybar/releases/download/${DISTVERSION}/ -MAINTAINER= rigoletto@FreeBSD.org +MAINTAINER= jbo@insane.engineer COMMENT= Fast and easy-to-use status bar WWW= https://github.com/polybar/polybar diff --git a/x11/polybar/files/patch-src_modules_cpu.cpp b/x11/polybar/files/patch-src_modules_cpu.cpp new file mode 100644 index 000000000000..7d31e2c08bff --- /dev/null +++ b/x11/polybar/files/patch-src_modules_cpu.cpp @@ -0,0 +1,66 @@ +diff --git src/modules/cpu.cpp src/modules/cpu.cpp +index 527f27fb..179d9221 100644 +--- src/modules/cpu.cpp ++++ src/modules/cpu.cpp +@@ -2,6 +2,11 @@ + + #include <fstream> + #include <istream> ++#ifdef __FreeBSD__ ++ #include <sys/types.h> ++ #include <sys/resource.h> ++ #include <sys/sysctl.h> ++#endif + + #include "drawtypes/label.hpp" + #include "drawtypes/progressbar.hpp" +@@ -128,6 +133,41 @@ namespace modules { + m_cputimes.clear(); + + try { ++#ifdef __FreeBSD__ ++ // Get number of CPUs ++ // ToDo: No need to do this on every invocation. ++ int ncpu = -1; ++ std::size_t sz = sizeof(ncpu); ++ if (sysctlbyname("hw.ncpu", &ncpu, &sz, nullptr, 0) != 0) { ++ m_log.err("Failed to query sysctl 'hw.ncpu' (errno: %s)", strerror(errno)); ++ return false; ++ } ++ if (ncpu < 1) { ++ m_log.err("Failed to determine number of CPUs."); ++ return false; ++ } ++ ++ // Query 'kern.cp_time' ++ long cpu_stat[CPUSTATES]; ++ sz = sizeof(cpu_stat); ++ if (sysctlbyname("kern.cp_time", cpu_stat, &sz, nullptr, 0) != 0) { ++ m_log.err("Failed to query sysctl 'kern.cp_time' (errno: %s)", strerror(errno)); ++ return false; ++ } ++ ++ // Parse ++ static std::size_t field_offset = sizeof(*cpu_stat) + ncpu; ++ for (std::size_t i = 0; i < ncpu; i++) { ++ m_cputimes.emplace_back(new cpu_time); ++ m_cputimes.back()->user = cpu_stat[CP_USER]; ++ m_cputimes.back()->nice = cpu_stat[CP_NICE]; ++ m_cputimes.back()->system = cpu_stat[CP_SYS]; ++ m_cputimes.back()->steal = cpu_stat[CP_INTR]; // Note: This is technically the reported "interrupt" time ++ m_cputimes.back()->idle = cpu_stat[CP_IDLE]; ++ m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system + ++ m_cputimes.back()->idle + m_cputimes.back()->steal; ++ } ++#else + std::ifstream in(PATH_CPU_INFO); + string str; + +@@ -148,6 +188,7 @@ namespace modules { + m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system + + m_cputimes.back()->idle + m_cputimes.back()->steal; + } ++#endif + } catch (const std::ios_base::failure& e) { + m_log.err("Failed to read CPU values (what: %s)", e.what()); + } diff --git a/x11/polybar/files/patch-src_modules_memory.cpp b/x11/polybar/files/patch-src_modules_memory.cpp new file mode 100644 index 000000000000..b0d836e120db --- /dev/null +++ b/x11/polybar/files/patch-src_modules_memory.cpp @@ -0,0 +1,49 @@ +diff --git src/modules/memory.cpp src/modules/memory.cpp +index eb36e5dc..042d85cb 100644 +--- src/modules/memory.cpp ++++ src/modules/memory.cpp +@@ -1,6 +1,10 @@ + #include <fstream> + #include <iomanip> + #include <istream> ++#ifdef __FreeBSD__ ++ #include <sys/types.h> ++ #include <sys/sysctl.h> ++#endif + + #include "drawtypes/label.hpp" + #include "drawtypes/progressbar.hpp" +@@ -63,6 +67,25 @@ namespace modules { + unsigned long long kb_swap_free{0ULL}; + + try { ++#ifdef __FreeBSD__ ++ std::size_t sz; ++ ++ // Total ++ sz = sizeof(kb_total); ++ if (sysctlbyname("hw.physmem", &kb_total, &sz, nullptr, 0) != 0) { ++ m_log.err("Failed to query sysctl 'hw.physmem' (errno: %s)", strerror(errno)); ++ return false; ++ } ++ kb_total /= 1024; ++ ++ // Available ++ sz = sizeof(kb_avail); ++ if (sysctlbyname("hw.usermem", &kb_avail, &sz, nullptr, 0) != 0) { ++ m_log.err("Failed to query sysctl 'hw.usermem' (errno: %s)", strerror(errno)); ++ return false; ++ } ++ kb_avail /= 1024; ++#else + std::ifstream meminfo(PATH_MEMORY_INFO); + std::map<std::string, unsigned long long int> parsed; + +@@ -91,6 +114,7 @@ namespace modules { + // old kernel; give a best-effort approximation of available memory + kb_avail = parsed["MemFree"] + parsed["Buffers"] + parsed["Cached"] + parsed["SReclaimable"] - parsed["Shmem"]; + } ++#endif + } catch (const std::exception& err) { + m_log.err("Failed to read memory values (what: %s)", err.what()); + } diff --git a/x11/polybar/pkg-message b/x11/polybar/pkg-message index ed6bc5b10f26..30a0aa183ced 100644 --- a/x11/polybar/pkg-message +++ b/x11/polybar/pkg-message @@ -6,10 +6,12 @@ not function in FreeBSD. Working modules: - bspwm +- cpu - date - github - i3 - ipc (polybar-msg method does not seem to work) +- memory - menu - mpd - script @@ -19,9 +21,7 @@ Working modules: - xworkspaces (not extensively tested) Broken modules: -- cpu - filesystem -- memory - network (requires wireless_tools) - temperature (requires /sys/class/thermal/* in sysfs) - volume (requires full alsa, not a wrapper)