From f9b6f665c149965e21a6774578bb3d72975e1408 Mon Sep 17 00:00:00 2001 From: Viktar Lukashonak Date: Wed, 6 Mar 2024 18:10:09 +0300 Subject: [PATCH] GTK4: Migration CPU Add documentation for justify option Signed-off-by: Viktar Lukashonak --- include/modules/cpu.hpp | 10 +------ include/modules/cpu_frequency.hpp | 9 ------ include/modules/load.hpp | 9 ------ man/waybar-backlight.5.scd | 6 +++- man/waybar-battery.5.scd | 6 +++- man/waybar-bluetooth.5.scd | 6 +++- man/waybar-cpu.5.scd | 8 +++++- man/waybar-custom.5.scd | 6 +++- man/waybar-disk.5.scd | 6 +++- man/waybar-hyprland-submap.5.scd | 6 +++- man/waybar-idle-inhibitor.5.scd | 6 +++- man/waybar-inhibitor.5.scd | 6 +++- man/waybar-jack.5.scd | 6 +++- man/waybar-memory.5.scd | 6 +++- man/waybar-mpd.5.scd | 6 +++- man/waybar-mpris.5.scd | 7 +++-- man/waybar-network.5.scd | 6 +++- man/waybar-pulseaudio.5.scd | 6 +++- man/waybar-river-layout.5.scd | 6 +++- man/waybar-river-mode.5.scd | 6 +++- man/waybar-river-window.5.scd | 6 +++- man/waybar-sndio.5.scd | 6 +++- man/waybar-sway-mode.5.scd | 6 +++- man/waybar-sway-window.5.scd | 6 +++- man/waybar-temperature.5.scd | 6 +++- man/waybar-wireplumber.5.scd | 6 +++- meson.build | 41 ++++++++++++++++++++++------ src/factory.cpp | 3 +- src/modules/cpu.cpp | 14 +++++++--- src/modules/cpu_frequency/bsd.cpp | 22 +++++++++++---- src/modules/cpu_frequency/common.cpp | 11 +++++--- src/modules/cpu_frequency/linux.cpp | 1 + src/modules/cpu_usage/common.cpp | 8 +++--- src/modules/load.cpp | 10 ++++--- 34 files changed, 197 insertions(+), 82 deletions(-) diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 7f78c165..d8790364 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -1,14 +1,5 @@ #pragma once -#include - -#include -#include -#include -#include -#include -#include - #include "ALabel.hpp" #include "util/sleeper_thread.hpp" @@ -22,6 +13,7 @@ class Cpu : public ALabel { private: std::vector> prev_times_; + std::string prev_state_; util::SleeperThread thread_; }; diff --git a/include/modules/cpu_frequency.hpp b/include/modules/cpu_frequency.hpp index 49ca1b86..fc4ad13f 100644 --- a/include/modules/cpu_frequency.hpp +++ b/include/modules/cpu_frequency.hpp @@ -1,14 +1,5 @@ #pragma once -#include - -#include -#include -#include -#include -#include -#include - #include "ALabel.hpp" #include "util/sleeper_thread.hpp" diff --git a/include/modules/load.hpp b/include/modules/load.hpp index c4c06d26..275108bd 100644 --- a/include/modules/load.hpp +++ b/include/modules/load.hpp @@ -1,14 +1,5 @@ #pragma once -#include - -#include -#include -#include -#include -#include -#include - #include "ALabel.hpp" #include "util/sleeper_thread.hpp" diff --git a/man/waybar-backlight.5.scd b/man/waybar-backlight.5.scd index 7db18a20..b92abd12 100644 --- a/man/waybar-backlight.5.scd +++ b/man/waybar-backlight.5.scd @@ -30,7 +30,11 @@ The *backlight* module displays the current backlight level. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *rotate*: ++ typeof: integer ++ diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 52a6a2d1..e359ea2e 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -61,7 +61,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *rotate*: ++ typeof: integer++ diff --git a/man/waybar-bluetooth.5.scd b/man/waybar-bluetooth.5.scd index 1fdd984b..3808e855 100644 --- a/man/waybar-bluetooth.5.scd +++ b/man/waybar-bluetooth.5.scd @@ -66,7 +66,11 @@ Addressed by *bluetooth* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-cpu.5.scd b/man/waybar-cpu.5.scd index 48479568..30337fe2 100644 --- a/man/waybar-cpu.5.scd +++ b/man/waybar-cpu.5.scd @@ -35,7 +35,11 @@ The *cpu* module displays the current CPU utilization. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *rotate*: ++ typeof: integer ++ @@ -121,3 +125,5 @@ CPU usage per core rendered as icons: # STYLE - *#cpu* +- *#cpu.* + - ** can be defined in the *config*. For more information see *states*. diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 67e4c89c..b968e781 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -72,7 +72,11 @@ Addressed by *custom/* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-disk.5.scd b/man/waybar-disk.5.scd index d466bddf..a279718b 100644 --- a/man/waybar-disk.5.scd +++ b/man/waybar-disk.5.scd @@ -45,7 +45,11 @@ Addressed by *disk* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-hyprland-submap.5.scd b/man/waybar-hyprland-submap.5.scd index 3f8d6280..9f5429b4 100644 --- a/man/waybar-hyprland-submap.5.scd +++ b/man/waybar-hyprland-submap.5.scd @@ -31,7 +31,11 @@ Addressed by *hyprland/submap* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-idle-inhibitor.5.scd b/man/waybar-idle-inhibitor.5.scd index 287def1a..71b3b30c 100644 --- a/man/waybar-idle-inhibitor.5.scd +++ b/man/waybar-idle-inhibitor.5.scd @@ -33,7 +33,11 @@ screensaver, also known as "presentation mode". *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-inhibitor.5.scd b/man/waybar-inhibitor.5.scd index 1233eb7d..47b6ffce 100644 --- a/man/waybar-inhibitor.5.scd +++ b/man/waybar-inhibitor.5.scd @@ -37,7 +37,11 @@ See *systemd-inhibit*(1) for more information. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-jack.5.scd b/man/waybar-jack.5.scd index 3af71b61..87a38354 100644 --- a/man/waybar-jack.5.scd +++ b/man/waybar-jack.5.scd @@ -63,7 +63,11 @@ Addressed by *jack* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-memory.5.scd b/man/waybar-memory.5.scd index 55c74b0b..e0252caf 100644 --- a/man/waybar-memory.5.scd +++ b/man/waybar-memory.5.scd @@ -45,7 +45,11 @@ Addressed by *memory* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-mpd.5.scd b/man/waybar-mpd.5.scd index ffef0fef..fe6ee5a1 100644 --- a/man/waybar-mpd.5.scd +++ b/man/waybar-mpd.5.scd @@ -103,7 +103,11 @@ Addressed by *mpd* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-mpris.5.scd b/man/waybar-mpris.5.scd index 117b816c..186d73c6 100644 --- a/man/waybar-mpris.5.scd +++ b/man/waybar-mpris.5.scd @@ -119,8 +119,11 @@ The *mpris* module displays currently playing media via libplayerctl. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. ++ - If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-network.5.scd b/man/waybar-network.5.scd index 08c86d3d..b5580c52 100644 --- a/man/waybar-network.5.scd +++ b/man/waybar-network.5.scd @@ -70,7 +70,11 @@ Addressed by *network* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-pulseaudio.5.scd b/man/waybar-pulseaudio.5.scd index e04245ee..4bc75258 100644 --- a/man/waybar-pulseaudio.5.scd +++ b/man/waybar-pulseaudio.5.scd @@ -56,7 +56,11 @@ Additionally, you can control the volume by scrolling *up* or *down* while the c *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *scroll-step*: ++ typeof: float ++ diff --git a/man/waybar-river-layout.5.scd b/man/waybar-river-layout.5.scd index f6f682d0..1c09d6f6 100644 --- a/man/waybar-river-layout.5.scd +++ b/man/waybar-river-layout.5.scd @@ -33,7 +33,11 @@ Addressed by *river/layout* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-river-mode.5.scd b/man/waybar-river-mode.5.scd index aea6e205..2d63b5e1 100644 --- a/man/waybar-river-mode.5.scd +++ b/man/waybar-river-mode.5.scd @@ -31,7 +31,11 @@ Addressed by *river/mode* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-river-window.5.scd b/man/waybar-river-window.5.scd index 9c202b2a..dbd9f130 100644 --- a/man/waybar-river-window.5.scd +++ b/man/waybar-river-window.5.scd @@ -31,7 +31,11 @@ Addressed by *river/window* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-sndio.5.scd b/man/waybar-sndio.5.scd index 1bb0484a..197aaba0 100644 --- a/man/waybar-sndio.5.scd +++ b/man/waybar-sndio.5.scd @@ -32,7 +32,11 @@ cursor is over the module, and clicking on the module toggles mute. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *scroll-step*: ++ typeof: int ++ diff --git a/man/waybar-sway-mode.5.scd b/man/waybar-sway-mode.5.scd index 87e70adf..44c8b81a 100644 --- a/man/waybar-sway-mode.5.scd +++ b/man/waybar-sway-mode.5.scd @@ -31,7 +31,11 @@ Addressed by *sway/mode* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-sway-window.5.scd b/man/waybar-sway-window.5.scd index 9b793f32..037e6b55 100644 --- a/man/waybar-sway-window.5.scd +++ b/man/waybar-sway-window.5.scd @@ -31,7 +31,11 @@ Addressed by *sway/window* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-temperature.5.scd b/man/waybar-temperature.5.scd index 1d6e7d2e..ff2168ea 100644 --- a/man/waybar-temperature.5.scd +++ b/man/waybar-temperature.5.scd @@ -71,7 +71,11 @@ Addressed by *temperature* *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *on-click*: ++ typeof: string ++ diff --git a/man/waybar-wireplumber.5.scd b/man/waybar-wireplumber.5.scd index 5424deb6..b08fd90f 100644 --- a/man/waybar-wireplumber.5.scd +++ b/man/waybar-wireplumber.5.scd @@ -47,7 +47,11 @@ The *wireplumber* module displays the current volume reported by WirePlumber. *align*: ++ typeof: float ++ - The alignment of the text, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + The alignment of the label within the module, where 0 is left-aligned and 1 is right-aligned. If the module is rotated, it will follow the flow of the text. + +*justify*: ++ + typeof: string ++ + The alignment of the text within the module's label, allowing options 'left', 'right', or 'center' to define the positioning. *scroll-step*: ++ typeof: float ++ diff --git a/meson.build b/meson.build index 9f72116f..d587204d 100644 --- a/meson.build +++ b/meson.build @@ -128,7 +128,8 @@ src_files = files( 'src/factory.cpp', 'src/util/ustring_clen.cpp', 'src/group.cpp', - 'src/ASlider.cpp' + 'src/ASlider.cpp', + 'src/modules/load.cpp', ) man_files = files( @@ -185,13 +186,37 @@ endif inc_dirs = ['include'] if is_linux - src_files += files('src/modules/battery.cpp') - man_files += files('man/waybar-battery.5.scd') -endif - -if is_freebsd - src_files += files('src/modules/battery.cpp') - man_files += files('man/waybar-battery.5.scd') + add_project_arguments('-DHAVE_CPU_LINUX', language: 'cpp') + src_files += files('src/modules/battery.cpp', + 'src/modules/cpu.cpp', + 'src/modules/cpu_frequency/common.cpp', + 'src/modules/cpu_frequency/linux.cpp', + 'src/modules/cpu_usage/common.cpp', + 'src/modules/cpu_usage/linux.cpp') + man_files += files('man/waybar-battery.5.scd', + 'man/waybar-cpu.5.scd') +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/cffi.cpp', + 'src/modules/cpu.cpp', + 'src/modules/cpu_frequency/bsd.cpp', + 'src/modules/cpu_frequency/common.cpp', + 'src/modules/cpu_usage/bsd.cpp', + 'src/modules/cpu_usage/common.cpp', +# 'src/modules/memory/bsd.cpp', +# 'src/modules/memory/common.cpp', + ) + man_files += files( +# 'man/waybar-cffi.5.scd', + 'man/waybar-cpu.5.scd', +# 'man/waybar-memory.5.scd', + ) + if is_freebsd + src_files += files('src/modules/battery.cpp') + man_files += files('man/waybar-battery.5.scd') + endif endif subdir('protocol') diff --git a/src/factory.cpp b/src/factory.cpp index ac5f5de6..5b32bd4e 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -209,7 +209,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, if (ref == "memory") { return new waybar::modules::Memory(id, config_[name]); } -#endif +#endif*/ #if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD) if (ref == "cpu") { return new waybar::modules::Cpu(id, config_[name]); @@ -226,7 +226,6 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, return new waybar::modules::Load(id, config_[name]); } #endif -*/ if (ref == "clock") { return new waybar::modules::Clock(id, config_[name]); } diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 0703eaf7..fce8e7ba 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -27,7 +27,7 @@ auto waybar::modules::Cpu::update() -> void { auto [cpu_usage, tooltip] = CpuUsage::getCpuUsage(prev_times_); auto [max_frequency, min_frequency, avg_frequency] = CpuFrequency::getCpuFrequency(); if (tooltipEnabled()) { - label_.set_tooltip_text(tooltip); + Gtk::Label::set_tooltip_text(tooltip); } auto format = format_; auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0]; @@ -36,10 +36,16 @@ auto waybar::modules::Cpu::update() -> void { format = config_["format-" + state].asString(); } + if (!prev_state_.empty()) { + Gtk::Label::get_style_context()->remove_class(prev_state_); + } + Gtk::Label::get_style_context()->add_class(state); + prev_state_ = state; + if (format.empty()) { - event_box_.hide(); + Gtk::Label::hide(); } else { - event_box_.show(); + Gtk::Label::show(); auto icons = std::vector{state}; fmt::dynamic_format_arg_store store; store.push_back(fmt::arg("load", load1)); @@ -55,7 +61,7 @@ auto waybar::modules::Cpu::update() -> void { auto icon_format = fmt::format("icon{}", core_i); store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons))); } - label_.set_markup(fmt::vformat(format, store)); + Gtk::Label::set_markup(fmt::vformat(format, store)); } // Call parent update diff --git a/src/modules/cpu_frequency/bsd.cpp b/src/modules/cpu_frequency/bsd.cpp index c837c1fd..743fb288 100644 --- a/src/modules/cpu_frequency/bsd.cpp +++ b/src/modules/cpu_frequency/bsd.cpp @@ -1,15 +1,27 @@ #include - -#include // NAN +#include #include "modules/cpu_frequency.hpp" std::vector waybar::modules::CpuFrequency::parseCpuFrequencies() { - static std::vector frequencies; + std::vector frequencies; + char buffer[256]; + size_t len; + int32_t freq; + uint32_t i = 0; + + while (true) { + len = 4; + snprintf(buffer, 256, "dev.cpu.%u.freq", i); + if (sysctlbyname(buffer, &freq, &len, NULL, 0) == -1 || len <= 0) break; + frequencies.push_back(freq); + ++i; + } + if (frequencies.empty()) { - spdlog::warn( - "cpu/bsd: parseCpuFrequencies is not implemented, expect garbage in {*_frequency}"); + spdlog::warn("cpu/bsd: parseCpuFrequencies failed, not found in sysctl"); frequencies.push_back(NAN); } + return frequencies; } diff --git a/src/modules/cpu_frequency/common.cpp b/src/modules/cpu_frequency/common.cpp index e47364ba..291bfc1a 100644 --- a/src/modules/cpu_frequency/common.cpp +++ b/src/modules/cpu_frequency/common.cpp @@ -1,3 +1,6 @@ +#include +#include + #include "modules/cpu_frequency.hpp" // In the 80000 version of fmt library authors decided to optimize imports @@ -24,7 +27,7 @@ auto waybar::modules::CpuFrequency::update() -> void { auto tooltip = fmt::format("Minimum frequency: {}\nAverage frequency: {}\nMaximum frequency: {}\n", min_frequency, avg_frequency, max_frequency); - label_.set_tooltip_text(tooltip); + Gtk::Label::set_tooltip_text(tooltip); } auto format = format_; auto state = getState(avg_frequency); @@ -33,16 +36,16 @@ auto waybar::modules::CpuFrequency::update() -> void { } if (format.empty()) { - event_box_.hide(); + Gtk::Label::hide(); } else { - event_box_.show(); + Gtk::Label::show(); auto icons = std::vector{state}; fmt::dynamic_format_arg_store store; store.push_back(fmt::arg("icon", getIcon(avg_frequency, icons))); store.push_back(fmt::arg("max_frequency", max_frequency)); store.push_back(fmt::arg("min_frequency", min_frequency)); store.push_back(fmt::arg("avg_frequency", avg_frequency)); - label_.set_markup(fmt::vformat(format, store)); + Gtk::Label::set_markup(fmt::vformat(format, store)); } // Call parent update diff --git a/src/modules/cpu_frequency/linux.cpp b/src/modules/cpu_frequency/linux.cpp index 1f368789..6e18d3ec 100644 --- a/src/modules/cpu_frequency/linux.cpp +++ b/src/modules/cpu_frequency/linux.cpp @@ -1,4 +1,5 @@ #include +#include #include "modules/cpu_frequency.hpp" diff --git a/src/modules/cpu_usage/common.cpp b/src/modules/cpu_usage/common.cpp index 4e36f48e..25aeb67b 100644 --- a/src/modules/cpu_usage/common.cpp +++ b/src/modules/cpu_usage/common.cpp @@ -21,7 +21,7 @@ auto waybar::modules::CpuUsage::update() -> void { // TODO: as creating dynamic fmt::arg arrays is buggy we have to calc both auto [cpu_usage, tooltip] = CpuUsage::getCpuUsage(prev_times_); if (tooltipEnabled()) { - label_.set_tooltip_text(tooltip); + Gtk::Label::set_tooltip_text(tooltip); } auto format = format_; auto total_usage = cpu_usage.empty() ? 0 : cpu_usage[0]; @@ -31,9 +31,9 @@ auto waybar::modules::CpuUsage::update() -> void { } if (format.empty()) { - event_box_.hide(); + Gtk::Label::hide(); } else { - event_box_.show(); + Gtk::Label::show(); auto icons = std::vector{state}; fmt::dynamic_format_arg_store store; store.push_back(fmt::arg("usage", total_usage)); @@ -45,7 +45,7 @@ auto waybar::modules::CpuUsage::update() -> void { auto icon_format = fmt::format("icon{}", core_i); store.push_back(fmt::arg(icon_format.c_str(), getIcon(cpu_usage[i], icons))); } - label_.set_markup(fmt::vformat(format, store)); + Gtk::Label::set_markup(fmt::vformat(format, store)); } // Call parent update diff --git a/src/modules/load.cpp b/src/modules/load.cpp index 69a37b4e..35db01d3 100644 --- a/src/modules/load.cpp +++ b/src/modules/load.cpp @@ -1,3 +1,5 @@ +#include + #include "modules/load.hpp" // In the 80000 version of fmt library authors decided to optimize imports @@ -22,7 +24,7 @@ auto waybar::modules::Load::update() -> void { auto [load1, load5, load15] = Load::getLoad(); if (tooltipEnabled()) { auto tooltip = fmt::format("Load 1: {}\nLoad 5: {}\nLoad 15: {}", load1, load5, load15); - label_.set_tooltip_text(tooltip); + Gtk::Label::set_tooltip_text(tooltip); } auto format = format_; auto state = getState(load1); @@ -31,9 +33,9 @@ auto waybar::modules::Load::update() -> void { } if (format.empty()) { - event_box_.hide(); + Gtk::Label::hide(); } else { - event_box_.show(); + Gtk::Label::show(); auto icons = std::vector{state}; fmt::dynamic_format_arg_store store; store.push_back(fmt::arg("load1", load1)); @@ -42,7 +44,7 @@ auto waybar::modules::Load::update() -> void { store.push_back(fmt::arg("icon1", getIcon(load1, icons))); store.push_back(fmt::arg("icon5", getIcon(load5, icons))); store.push_back(fmt::arg("icon15", getIcon(load15, icons))); - label_.set_markup(fmt::vformat(format, store)); + Gtk::Label::set_markup(fmt::vformat(format, store)); } // Call parent update