mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #425 from jbeich/freebsd
This commit is contained in:
commit
e7367c75aa
56
.travis.yml
56
.travis.yml
@ -1,24 +1,40 @@
|
||||
sudo: false
|
||||
|
||||
services:
|
||||
- docker
|
||||
|
||||
git:
|
||||
submodules: false
|
||||
|
||||
env:
|
||||
- distro: debian
|
||||
- distro: archlinux
|
||||
- distro: fedora
|
||||
- distro: alpine
|
||||
- distro: opensuse
|
||||
_linux_shared: &linux_shared
|
||||
os: linux
|
||||
sudo: false
|
||||
services:
|
||||
- docker
|
||||
before_install:
|
||||
- docker pull alexays/waybar:${distro}
|
||||
- find . -type f \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -r0 clang-format -i
|
||||
script:
|
||||
- echo FROM alexays/waybar:${distro} > Dockerfile
|
||||
- echo ADD . /root >> Dockerfile
|
||||
- docker build -t waybar .
|
||||
- docker run waybar /bin/sh -c "cd /root && meson build -Dman-pages=enabled && ninja -C build"
|
||||
|
||||
before_install:
|
||||
- docker pull alexays/waybar:${distro}
|
||||
- find . -type f \( -name '*.cpp' -o -name '*.h' \) -print0 | xargs -r0 clang-format -i
|
||||
|
||||
script:
|
||||
- echo FROM alexays/waybar:${distro} > Dockerfile
|
||||
- echo ADD . /root >> Dockerfile
|
||||
- docker build -t waybar .
|
||||
- docker run waybar /bin/sh -c "cd /root && meson build -Dman-pages=enabled && ninja -C build"
|
||||
jobs:
|
||||
include:
|
||||
- <<: *linux_shared
|
||||
env: distro=debian
|
||||
- <<: *linux_shared
|
||||
env: distro=archlinux
|
||||
- <<: *linux_shared
|
||||
env: distro=fedora
|
||||
- <<: *linux_shared
|
||||
env: distro=alpine
|
||||
- <<: *linux_shared
|
||||
env: distro=opensuse
|
||||
- os: freebsd
|
||||
language: cpp
|
||||
compiler: clang
|
||||
sudo: required
|
||||
install:
|
||||
- sudo sed -i '' 's/quarterly/latest/' /etc/pkg/FreeBSD.conf
|
||||
- sudo pkg install -y date gtk-layer-shell gtkmm30 jsoncpp libdbusmenu
|
||||
libfmt libmpdclient libudev-devd meson pulseaudio scdoc spdlog
|
||||
script:
|
||||
- meson build -Dman-pages=enabled
|
||||
- ninja -C build
|
||||
|
@ -7,14 +7,18 @@
|
||||
#include "modules/sway/window.hpp"
|
||||
#include "modules/sway/workspaces.hpp"
|
||||
#endif
|
||||
#ifndef NO_FILESYSTEM
|
||||
#if defined(__linux__) && !defined(NO_FILESYSTEM)
|
||||
#include "modules/battery.hpp"
|
||||
#endif
|
||||
#if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD)
|
||||
#include "modules/cpu.hpp"
|
||||
#endif
|
||||
#include "modules/idle_inhibitor.hpp"
|
||||
#if defined(HAVE_MEMORY_LINUX) || defined(HAVE_MEMORY_BSD)
|
||||
#include "modules/memory.hpp"
|
||||
#endif
|
||||
#include "modules/disk.hpp"
|
||||
#if defined(HAVE_DBUSMENU) && !defined(NO_FILESYSTEM)
|
||||
#ifdef HAVE_DBUSMENU
|
||||
#include "modules/sni/tray.hpp"
|
||||
#endif
|
||||
#ifdef HAVE_LIBNL
|
||||
@ -32,7 +36,9 @@
|
||||
#include "bar.hpp"
|
||||
#include "modules/custom.hpp"
|
||||
#include "modules/temperature.hpp"
|
||||
#if defined(__linux__)
|
||||
#include "modules/bluetooth.hpp"
|
||||
#endif
|
||||
|
||||
namespace waybar {
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <unistd.h>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <numeric>
|
||||
@ -20,7 +20,6 @@ class Cpu : public ALabel {
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/stat";
|
||||
uint16_t getCpuLoad();
|
||||
std::tuple<uint16_t, std::string> getCpuUsage();
|
||||
std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
|
||||
|
@ -15,7 +15,6 @@ class Memory : public ALabel {
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/meminfo";
|
||||
void parseMeminfo();
|
||||
|
||||
std::unordered_map<std::string, unsigned long> meminfo_;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <pulse/pulseaudio.h>
|
||||
#include <pulse/volume.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include "ALabel.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
@ -10,11 +10,6 @@
|
||||
#include <json/json.h>
|
||||
#include <libdbusmenu-gtk/dbusmenu-gtk.h>
|
||||
#include <sigc++/trackable.h>
|
||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
||||
#include <experimental/filesystem>
|
||||
#else
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <fmt/format.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <unordered_map>
|
||||
#include "AModule.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <giomm.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <array>
|
||||
|
||||
namespace waybar::util::command {
|
||||
|
||||
|
55
meson.build
55
meson.build
@ -17,11 +17,13 @@ cpp_link_args = []
|
||||
if get_option('libcxx')
|
||||
cpp_args += ['-stdlib=libc++']
|
||||
cpp_link_args += ['-stdlib=libc++', '-lc++abi']
|
||||
endif
|
||||
|
||||
if compiler.has_link_argument('-lc++fs')
|
||||
cpp_link_args += ['-lc++fs']
|
||||
endif
|
||||
else
|
||||
if compiler.has_link_argument('-lc++fs')
|
||||
cpp_link_args += ['-lc++fs']
|
||||
elif compiler.has_link_argument('-lc++experimental')
|
||||
cpp_link_args += ['-lc++experimental']
|
||||
elif compiler.has_link_argument('-lstdc++fs')
|
||||
cpp_link_args += ['-lstdc++fs']
|
||||
endif
|
||||
|
||||
@ -64,8 +66,13 @@ endif
|
||||
add_global_arguments(cpp_args, language : 'cpp')
|
||||
add_global_link_arguments(cpp_link_args, language : 'cpp')
|
||||
|
||||
is_linux = host_machine.system() == 'linux'
|
||||
is_dragonfly = host_machine.system() == 'dragonfly'
|
||||
is_freebsd = host_machine.system() == 'freebsd'
|
||||
is_netbsd = host_machine.system() == 'netbsd'
|
||||
is_openbsd = host_machine.system() == 'openbsd'
|
||||
|
||||
thread_dep = dependency('threads')
|
||||
libinput = dependency('libinput')
|
||||
fmt = dependency('fmt', version : ['>=5.3.0'], fallback : ['fmt', 'fmt_dep'])
|
||||
spdlog = dependency('spdlog', version : ['>=1.3.1'], fallback : ['spdlog', 'spdlog_dep'])
|
||||
wayland_client = dependency('wayland-client')
|
||||
@ -76,6 +83,7 @@ dbusmenu_gtk = dependency('dbusmenu-gtk3-0.4', required: get_option('dbusmenu-gt
|
||||
giounix = dependency('gio-unix-2.0', required: get_option('dbusmenu-gtk'))
|
||||
jsoncpp = dependency('jsoncpp')
|
||||
sigcpp = dependency('sigc++-2.0')
|
||||
libepoll = dependency('epoll-shim', required: false)
|
||||
libnl = dependency('libnl-3.0', required: get_option('libnl'))
|
||||
libnlgen = dependency('libnl-genl-3.0', required: get_option('libnl'))
|
||||
libpulse = dependency('libpulse', required: get_option('pulseaudio'))
|
||||
@ -88,9 +96,12 @@ systemd = dependency('systemd', required: get_option('systemd'))
|
||||
tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ])
|
||||
|
||||
prefix = get_option('prefix')
|
||||
sysconfdir = get_option('sysconfdir')
|
||||
conf_data = configuration_data()
|
||||
conf_data.set('prefix', prefix)
|
||||
|
||||
add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'cpp')
|
||||
|
||||
if systemd.found()
|
||||
user_units_dir = systemd.get_pkgconfig_variable('systemduserunitdir')
|
||||
|
||||
@ -106,21 +117,39 @@ src_files = files(
|
||||
'src/factory.cpp',
|
||||
'src/AModule.cpp',
|
||||
'src/ALabel.cpp',
|
||||
'src/modules/memory.cpp',
|
||||
'src/modules/battery.cpp',
|
||||
'src/modules/bluetooth.cpp',
|
||||
'src/modules/clock.cpp',
|
||||
'src/modules/custom.cpp',
|
||||
'src/modules/cpu.cpp',
|
||||
'src/modules/disk.cpp',
|
||||
'src/modules/idle_inhibitor.cpp',
|
||||
'src/modules/temperature.cpp',
|
||||
'src/main.cpp',
|
||||
'src/bar.cpp',
|
||||
'src/client.cpp',
|
||||
'src/util/rfkill.cpp'
|
||||
)
|
||||
|
||||
if is_linux
|
||||
add_project_arguments('-DHAVE_CPU_LINUX', language: 'cpp')
|
||||
add_project_arguments('-DHAVE_MEMORY_LINUX', language: 'cpp')
|
||||
src_files += files(
|
||||
'src/modules/battery.cpp',
|
||||
'src/modules/bluetooth.cpp',
|
||||
'src/modules/cpu/common.cpp',
|
||||
'src/modules/cpu/linux.cpp',
|
||||
'src/modules/memory/common.cpp',
|
||||
'src/modules/memory/linux.cpp',
|
||||
'src/util/rfkill.cpp'
|
||||
)
|
||||
elif is_dragonfly or is_freebsd or is_netbsd or is_openbsd
|
||||
add_project_arguments('-DHAVE_CPU_BSD', language: 'cpp')
|
||||
add_project_arguments('-DHAVE_MEMORY_BSD', language: 'cpp')
|
||||
src_files += files(
|
||||
'src/modules/cpu/bsd.cpp',
|
||||
'src/modules/cpu/common.cpp',
|
||||
'src/modules/memory/bsd.cpp',
|
||||
'src/modules/memory/common.cpp',
|
||||
)
|
||||
endif
|
||||
|
||||
if true # find_program('sway', required : false).found()
|
||||
add_project_arguments('-DHAVE_SWAY', language: 'cpp')
|
||||
src_files += [
|
||||
@ -151,7 +180,7 @@ if dbusmenu_gtk.found()
|
||||
)
|
||||
endif
|
||||
|
||||
if libudev.found()
|
||||
if libudev.found() and (is_linux or libepoll.found())
|
||||
add_project_arguments('-DHAVE_LIBUDEV', language: 'cpp')
|
||||
src_files += 'src/modules/backlight.cpp'
|
||||
endif
|
||||
@ -178,7 +207,6 @@ executable(
|
||||
spdlog,
|
||||
sigcpp,
|
||||
jsoncpp,
|
||||
libinput,
|
||||
wayland_cursor,
|
||||
gtkmm,
|
||||
dbusmenu_gtk,
|
||||
@ -187,6 +215,7 @@ executable(
|
||||
libnlgen,
|
||||
libpulse,
|
||||
libudev,
|
||||
libepoll,
|
||||
libmpdclient,
|
||||
gtk_layer_shell,
|
||||
tz_dep
|
||||
@ -198,7 +227,7 @@ executable(
|
||||
install_data(
|
||||
'./resources/config',
|
||||
'./resources/style.css',
|
||||
install_dir: join_paths(get_option('out'), 'etc/xdg/waybar')
|
||||
install_dir: sysconfdir + '/xdg/waybar'
|
||||
)
|
||||
|
||||
scdoc = dependency('scdoc', version: '>=1.9.2', native: true, required: get_option('man-pages'))
|
||||
|
@ -6,5 +6,4 @@ option('systemd', type: 'feature', value: 'auto', description: 'Install systemd
|
||||
option('dbusmenu-gtk', type: 'feature', value: 'auto', description: 'Enable support for tray')
|
||||
option('man-pages', type: 'feature', value: 'auto', description: 'Generate and install man pages')
|
||||
option('mpd', type: 'feature', value: 'auto', description: 'Enable support for the Music Player Daemon')
|
||||
option('out', type: 'string', value : '/', description: 'output prefix directory')
|
||||
option('gtk-layer-shell', type: 'feature', value: 'auto', description: 'Use gtk-layer-shell library for popups support')
|
||||
|
@ -161,7 +161,7 @@ std::tuple<const std::string, const std::string> waybar::Client::getConfigs(
|
||||
"$XDG_CONFIG_HOME/waybar/config",
|
||||
"$HOME/.config/waybar/config",
|
||||
"$HOME/waybar/config",
|
||||
"/etc/xdg/waybar/config",
|
||||
SYSCONFDIR "/xdg/waybar/config",
|
||||
"./resources/config",
|
||||
})
|
||||
: config;
|
||||
@ -169,7 +169,7 @@ std::tuple<const std::string, const std::string> waybar::Client::getConfigs(
|
||||
"$XDG_CONFIG_HOME/waybar/style.css",
|
||||
"$HOME/.config/waybar/style.css",
|
||||
"$HOME/waybar/style.css",
|
||||
"/etc/xdg/waybar/style.css",
|
||||
SYSCONFDIR "/xdg/waybar/style.css",
|
||||
"./resources/style.css",
|
||||
})
|
||||
: style;
|
||||
|
@ -7,7 +7,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
||||
auto hash_pos = name.find('#');
|
||||
auto ref = name.substr(0, hash_pos);
|
||||
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
|
||||
#ifndef NO_FILESYSTEM
|
||||
#if defined(__linux__) && !defined(NO_FILESYSTEM)
|
||||
if (ref == "battery") {
|
||||
return new waybar::modules::Battery(id, config_[name]);
|
||||
}
|
||||
@ -26,19 +26,23 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
||||
if (ref == "idle_inhibitor") {
|
||||
return new waybar::modules::IdleInhibitor(id, bar_, config_[name]);
|
||||
}
|
||||
#if defined(HAVE_MEMORY_LINUX) || defined(HAVE_MEMORY_BSD)
|
||||
if (ref == "memory") {
|
||||
return new waybar::modules::Memory(id, config_[name]);
|
||||
}
|
||||
#endif
|
||||
#if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD)
|
||||
if (ref == "cpu") {
|
||||
return new waybar::modules::Cpu(id, config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (ref == "clock") {
|
||||
return new waybar::modules::Clock(id, config_[name]);
|
||||
}
|
||||
if (ref == "disk") {
|
||||
return new waybar::modules::Disk(id, config_[name]);
|
||||
}
|
||||
#if defined(HAVE_DBUSMENU) && !defined(NO_FILESYSTEM)
|
||||
#ifdef HAVE_DBUSMENU
|
||||
if (ref == "tray") {
|
||||
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
|
||||
}
|
||||
@ -66,9 +70,11 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
||||
if (ref == "temperature") {
|
||||
return new waybar::modules::Temperature(id, config_[name]);
|
||||
}
|
||||
#if defined(__linux__)
|
||||
if (ref == "bluetooth") {
|
||||
return new waybar::modules::Bluetooth(id, config_[name]);
|
||||
}
|
||||
#endif
|
||||
if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) {
|
||||
return new waybar::modules::Custom(ref.substr(7), id, config_[name]);
|
||||
}
|
||||
|
97
src/modules/cpu/bsd.cpp
Normal file
97
src/modules/cpu/bsd.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#include "modules/cpu.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <cstdlib> // malloc
|
||||
#include <unistd.h> // sysconf
|
||||
|
||||
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
# include <sys/sched.h>
|
||||
#else
|
||||
# include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
typedef uint64_t cp_time_t;
|
||||
#else
|
||||
typedef long cp_time_t;
|
||||
#endif
|
||||
#if defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
typedef uint64_t pcp_time_t;
|
||||
#else
|
||||
typedef long pcp_time_t;
|
||||
#endif
|
||||
|
||||
std::vector<std::tuple<size_t, size_t>> waybar::modules::Cpu::parseCpuinfo() {
|
||||
cp_time_t sum_cp_time[CPUSTATES];
|
||||
size_t sum_sz = sizeof(sum_cp_time);
|
||||
int ncpu = sysconf(_SC_NPROCESSORS_CONF);
|
||||
size_t sz = CPUSTATES * (ncpu + 1) * sizeof(pcp_time_t);
|
||||
pcp_time_t *cp_time = static_cast<pcp_time_t *>(malloc(sz)), *pcp_time = cp_time;
|
||||
#if defined(__NetBSD__)
|
||||
int mib[] = {
|
||||
CTL_KERN,
|
||||
KERN_CP_TIME,
|
||||
};
|
||||
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), sum_cp_time, &sum_sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl kern.cp_time failed");
|
||||
}
|
||||
for (int state = 0; state < CPUSTATES; state++) {
|
||||
cp_time[state] = sum_cp_time[state];
|
||||
}
|
||||
pcp_time += CPUSTATES;
|
||||
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), pcp_time, &sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl kern.cp_time failed");
|
||||
}
|
||||
#elif defined(__OpenBSD__)
|
||||
{
|
||||
int mib[] = {
|
||||
CTL_KERN,
|
||||
KERN_CPTIME,
|
||||
};
|
||||
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), sum_cp_time, &sum_sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl kern.cp_time failed");
|
||||
}
|
||||
}
|
||||
for (int state = 0; state < CPUSTATES; state++) {
|
||||
cp_time[state] = sum_cp_time[state];
|
||||
}
|
||||
pcp_time = cp_time;
|
||||
sz /= ncpu + 1;
|
||||
{
|
||||
int mib[] = {
|
||||
CTL_KERN,
|
||||
KERN_CPTIME2,
|
||||
0,
|
||||
};
|
||||
for (int cpu = 0; cpu < ncpu; cpu++) {
|
||||
mib[2] = cpu;
|
||||
pcp_time += CPUSTATES;
|
||||
if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), pcp_time, &sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl kern.cp_time2 failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (sysctlbyname("kern.cp_time", sum_cp_time, &sum_sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl kern.cp_time failed");
|
||||
}
|
||||
for (int state = 0; state < CPUSTATES; state++) {
|
||||
cp_time[state] = sum_cp_time[state];
|
||||
}
|
||||
pcp_time += CPUSTATES;
|
||||
if (sysctlbyname("kern.cp_times", pcp_time, &sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl kern.cp_times failed");
|
||||
}
|
||||
#endif
|
||||
std::vector<std::tuple<size_t, size_t>> cpuinfo;
|
||||
for (int cpu = 0; cpu < ncpu + 1; cpu++) {
|
||||
pcp_time_t total = 0, *single_cp_time = &cp_time[cpu * CPUSTATES];
|
||||
for (int state = 0; state < CPUSTATES; state++) {
|
||||
total += single_cp_time[state];
|
||||
}
|
||||
cpuinfo.emplace_back(single_cp_time[CP_IDLE], total);
|
||||
}
|
||||
free(cp_time);
|
||||
return cpuinfo;
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
#include "modules/cpu.hpp"
|
||||
#include <numeric>
|
||||
|
||||
waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "cpu", id, "{usage}%", 10) {
|
||||
@ -23,11 +22,9 @@ auto waybar::modules::Cpu::update() -> void {
|
||||
}
|
||||
|
||||
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
||||
struct sysinfo info = {0};
|
||||
if (sysinfo(&info) == 0) {
|
||||
float f_load = 1.F / (1U << SI_LOAD_SHIFT);
|
||||
uint16_t load = info.loads[0] * f_load * 100 / get_nprocs();
|
||||
return load;
|
||||
double load[1];
|
||||
if (getloadavg(load, 1) != -1) {
|
||||
return load[0] * 100 / sysconf(_SC_NPROCESSORS_ONLN);
|
||||
}
|
||||
throw std::runtime_error("Can't get Cpu load");
|
||||
}
|
||||
@ -56,30 +53,3 @@ std::tuple<uint16_t, std::string> waybar::modules::Cpu::getCpuUsage() {
|
||||
prev_times_ = curr_times;
|
||||
return {usage, tooltip};
|
||||
}
|
||||
|
||||
std::vector<std::tuple<size_t, size_t>> waybar::modules::Cpu::parseCpuinfo() {
|
||||
std::ifstream info(data_dir_);
|
||||
if (!info.is_open()) {
|
||||
throw std::runtime_error("Can't open " + data_dir_);
|
||||
}
|
||||
std::vector<std::tuple<size_t, size_t>> cpuinfo;
|
||||
std::string line;
|
||||
while (getline(info, line)) {
|
||||
if (line.substr(0, 3).compare("cpu") != 0) {
|
||||
break;
|
||||
}
|
||||
std::stringstream sline(line.substr(5));
|
||||
std::vector<size_t> times;
|
||||
for (size_t time = 0; sline >> time; times.push_back(time))
|
||||
;
|
||||
|
||||
size_t idle_time = 0;
|
||||
size_t total_time = 0;
|
||||
if (times.size() >= 4) {
|
||||
idle_time = times[3];
|
||||
total_time = std::accumulate(times.begin(), times.end(), 0);
|
||||
}
|
||||
cpuinfo.emplace_back(idle_time, total_time);
|
||||
}
|
||||
return cpuinfo;
|
||||
}
|
29
src/modules/cpu/linux.cpp
Normal file
29
src/modules/cpu/linux.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include "modules/cpu.hpp"
|
||||
|
||||
std::vector<std::tuple<size_t, size_t>> waybar::modules::Cpu::parseCpuinfo() {
|
||||
const std::string data_dir_ = "/proc/stat";
|
||||
std::ifstream info(data_dir_);
|
||||
if (!info.is_open()) {
|
||||
throw std::runtime_error("Can't open " + data_dir_);
|
||||
}
|
||||
std::vector<std::tuple<size_t, size_t>> cpuinfo;
|
||||
std::string line;
|
||||
while (getline(info, line)) {
|
||||
if (line.substr(0, 3).compare("cpu") != 0) {
|
||||
break;
|
||||
}
|
||||
std::stringstream sline(line.substr(5));
|
||||
std::vector<size_t> times;
|
||||
for (size_t time = 0; sline >> time; times.push_back(time))
|
||||
;
|
||||
|
||||
size_t idle_time = 0;
|
||||
size_t total_time = 0;
|
||||
if (times.size() >= 4) {
|
||||
idle_time = times[3];
|
||||
total_time = std::accumulate(times.begin(), times.end(), 0);
|
||||
}
|
||||
cpuinfo.emplace_back(idle_time, total_time);
|
||||
}
|
||||
return cpuinfo;
|
||||
}
|
@ -44,9 +44,9 @@ auto waybar::modules::Disk::update() -> void {
|
||||
return;
|
||||
}
|
||||
|
||||
auto free = pow_format(stats.f_bavail * stats.f_bsize, "B", true);
|
||||
auto used = pow_format((stats.f_blocks - stats.f_bavail) * stats.f_bsize, "B", true);
|
||||
auto total = pow_format(stats.f_blocks * stats.f_bsize, "B", true);
|
||||
auto free = pow_format(stats.f_bavail * stats.f_frsize, "B", true);
|
||||
auto used = pow_format((stats.f_blocks - stats.f_bavail) * stats.f_frsize, "B", true);
|
||||
auto total = pow_format(stats.f_blocks * stats.f_frsize, "B", true);
|
||||
|
||||
label_.set_markup(fmt::format(format_
|
||||
, stats.f_bavail * 100 / stats.f_blocks
|
||||
|
89
src/modules/memory/bsd.cpp
Normal file
89
src/modules/memory/bsd.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "modules/memory.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <unistd.h> // getpagesize
|
||||
|
||||
#if defined(__DragonFly__)
|
||||
# include <sys/vmmeter.h> // struct vmstats
|
||||
#elif defined(__NetBSD__)
|
||||
# include <uvm/uvm_extern.h> // struct uvmexp_sysctl
|
||||
#elif defined(__OpenBSD__)
|
||||
# include <uvm/uvmexp.h> // struct uvmexp
|
||||
#endif
|
||||
|
||||
static uint64_t get_total_memory() {
|
||||
#if defined(HW_MEMSIZE) || defined(HW_PHYSMEM64)
|
||||
uint64_t physmem;
|
||||
#else
|
||||
u_long physmem;
|
||||
#endif
|
||||
int mib[] = {
|
||||
CTL_HW,
|
||||
#if defined(HW_MEMSIZE)
|
||||
HW_MEMSIZE,
|
||||
#elif defined(HW_PHYSMEM64)
|
||||
HW_PHYSMEM64,
|
||||
#else
|
||||
HW_PHYSMEM,
|
||||
#endif
|
||||
};
|
||||
u_int miblen = sizeof(mib) / sizeof(mib[0]);
|
||||
size_t sz = sizeof(physmem);
|
||||
if (sysctl(mib, miblen, &physmem, &sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl hw.physmem failed");
|
||||
}
|
||||
return physmem;
|
||||
}
|
||||
|
||||
static uint64_t get_free_memory() {
|
||||
#if defined(__DragonFly__)
|
||||
struct vmstats vms;
|
||||
size_t sz = sizeof(vms);
|
||||
if (sysctlbyname("vm.vmstats", &vms, &sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl vm.vmstats failed");
|
||||
}
|
||||
return static_cast<uint64_t>
|
||||
(vms.v_free_count + vms.v_inactive_count + vms.v_cache_count)
|
||||
* getpagesize();
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
u_int v_free_count = 0, v_inactive_count = 0, v_cache_count = 0;
|
||||
size_t sz = sizeof(u_int);
|
||||
sysctlbyname("vm.stats.vm.v_free_count",
|
||||
&v_free_count, &sz, NULL, 0);
|
||||
sysctlbyname("vm.stats.vm.v_inactive_count",
|
||||
&v_inactive_count, &sz, NULL, 0);
|
||||
sysctlbyname("vm.stats.vm.v_cache_count",
|
||||
&v_cache_count, &sz, NULL, 0);
|
||||
return static_cast<uint64_t>
|
||||
(v_free_count + v_inactive_count + v_cache_count)
|
||||
* getpagesize();
|
||||
#elif defined(__NetBSD__) || defined(__OpenBSD__)
|
||||
#ifdef VM_UVMEXP2
|
||||
# undef VM_UVMEXP
|
||||
# define VM_UVMEXP VM_UVMEXP2
|
||||
# define uvmexp uvmexp_sysctl
|
||||
#else
|
||||
# define filepages vnodepages
|
||||
# define execpages vtextpages
|
||||
#endif
|
||||
int mib[] = {
|
||||
CTL_VM,
|
||||
VM_UVMEXP,
|
||||
};
|
||||
u_int miblen = sizeof(mib) / sizeof(mib[0]);
|
||||
struct uvmexp uvmexp;
|
||||
size_t sz = sizeof(uvmexp);
|
||||
if (sysctl(mib, miblen, &uvmexp, &sz, NULL, 0)) {
|
||||
throw std::runtime_error("sysctl vm.uvmexp failed");
|
||||
}
|
||||
return static_cast<uint64_t>
|
||||
(uvmexp.free + uvmexp.inactive + uvmexp.filepages + uvmexp.execpages)
|
||||
* uvmexp.pagesize;
|
||||
#endif
|
||||
}
|
||||
|
||||
void waybar::modules::Memory::parseMeminfo() {
|
||||
meminfo_["MemTotal"] = get_total_memory() / 1024;
|
||||
meminfo_["MemAvailable"] = get_free_memory() / 1024;
|
||||
}
|
@ -45,21 +45,3 @@ auto waybar::modules::Memory::update() -> void {
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
void waybar::modules::Memory::parseMeminfo() {
|
||||
std::ifstream info(data_dir_);
|
||||
if (!info.is_open()) {
|
||||
throw std::runtime_error("Can't open " + data_dir_);
|
||||
}
|
||||
std::string line;
|
||||
while (getline(info, line)) {
|
||||
auto posDelim = line.find(':');
|
||||
if (posDelim == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string name = line.substr(0, posDelim);
|
||||
int64_t value = std::stol(line.substr(posDelim + 1));
|
||||
meminfo_[name] = value;
|
||||
}
|
||||
}
|
20
src/modules/memory/linux.cpp
Normal file
20
src/modules/memory/linux.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "modules/memory.hpp"
|
||||
|
||||
void waybar::modules::Memory::parseMeminfo() {
|
||||
const std::string data_dir_ = "/proc/meminfo";
|
||||
std::ifstream info(data_dir_);
|
||||
if (!info.is_open()) {
|
||||
throw std::runtime_error("Can't open " + data_dir_);
|
||||
}
|
||||
std::string line;
|
||||
while (getline(info, line)) {
|
||||
auto posDelim = line.find(':');
|
||||
if (posDelim == std::string::npos) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string name = line.substr(0, posDelim);
|
||||
int64_t value = std::stol(line.substr(posDelim + 1));
|
||||
meminfo_[name] = value;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#include "modules/sni/item.hpp"
|
||||
#include <glibmm/main.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <fstream>
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<Glib::ustring> : formatter<std::string> {
|
||||
@ -256,11 +257,8 @@ void Item::updateImage() {
|
||||
if (!icon_name.empty()) {
|
||||
try {
|
||||
// Try to find icons specified by path and filename
|
||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
||||
if (std::experimental::filesystem::exists(icon_name)) {
|
||||
#else
|
||||
if (std::filesystem::exists(icon_name)) {
|
||||
#endif
|
||||
std::ifstream temp(icon_name);
|
||||
if (temp.is_open()) {
|
||||
auto pixbuf = Gdk::Pixbuf::create_from_file(icon_name);
|
||||
if (pixbuf->gobj() != nullptr) {
|
||||
// An icon specified by path and filename may be the wrong size for
|
||||
|
Loading…
Reference in New Issue
Block a user