mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-11-04 01:32:42 +01:00 
			
		
		
		
	Merge branch 'master' into master
This commit is contained in:
		@@ -161,7 +161,7 @@ const std::tuple<uint8_t, float, std::string, float> waybar::modules::Battery::g
 | 
			
		||||
      uint32_t    energy_now;
 | 
			
		||||
      uint32_t    energy_full_design;
 | 
			
		||||
      std::string _status;
 | 
			
		||||
      std::ifstream(bat / "status") >> _status;
 | 
			
		||||
      std::getline(std::ifstream(bat / "status"), _status);
 | 
			
		||||
 | 
			
		||||
      // Some battery will report current and charge in μA/μAh.
 | 
			
		||||
      // Scale these by the voltage to get μW/μWh.
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,24 @@
 | 
			
		||||
#include "modules/clock.hpp"
 | 
			
		||||
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
#if FMT_VERSION < 60000
 | 
			
		||||
#include <fmt/time.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <fmt/chrono.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <ctime>
 | 
			
		||||
#include <sstream>
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
 | 
			
		||||
#include "util/ustring_clen.hpp"
 | 
			
		||||
#include "util/waybar_time.hpp"
 | 
			
		||||
#ifdef HAVE_LANGINFO_1STDAY
 | 
			
		||||
#include <langinfo.h>
 | 
			
		||||
#include <locale.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
using waybar::modules::waybar_time;
 | 
			
		||||
using waybar::waybar_time;
 | 
			
		||||
 | 
			
		||||
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
 | 
			
		||||
    : ALabel(config, "clock", id, "{:%H:%M}", 60, false, false, true),
 | 
			
		||||
@@ -92,7 +99,7 @@ auto waybar::modules::Clock::update() -> void {
 | 
			
		||||
    // As date dep is not fully compatible, prefer fmt
 | 
			
		||||
    tzset();
 | 
			
		||||
    auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
 | 
			
		||||
    text = fmt::format(format_, localtime);
 | 
			
		||||
    text = fmt::format(locale_, format_, localtime);
 | 
			
		||||
  } else {
 | 
			
		||||
    text = fmt::format(format_, wtime);
 | 
			
		||||
  }
 | 
			
		||||
@@ -227,14 +234,3 @@ auto waybar::modules::Clock::first_day_of_week() -> date::weekday {
 | 
			
		||||
#endif
 | 
			
		||||
  return date::Sunday;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <>
 | 
			
		||||
struct fmt::formatter<waybar_time> : fmt::formatter<std::tm> {
 | 
			
		||||
  template <typename FormatContext>
 | 
			
		||||
  auto format(const waybar_time& t, FormatContext& ctx) {
 | 
			
		||||
#if FMT_VERSION >= 80000
 | 
			
		||||
  auto& tm_format = specs;
 | 
			
		||||
#endif
 | 
			
		||||
    return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(tm_format), t.ztime));
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,15 @@ auto waybar::modules::Memory::update() -> void {
 | 
			
		||||
  parseMeminfo();
 | 
			
		||||
 | 
			
		||||
  unsigned long memtotal = meminfo_["MemTotal"];
 | 
			
		||||
  unsigned long swaptotal = 0;
 | 
			
		||||
  if (meminfo_.count("SwapTotal")) {
 | 
			
		||||
    swaptotal = meminfo_["SwapTotal"];
 | 
			
		||||
  }
 | 
			
		||||
  unsigned long memfree;
 | 
			
		||||
  unsigned long swapfree = 0;
 | 
			
		||||
  if (meminfo_.count("SwapFree")) {
 | 
			
		||||
    swapfree = meminfo_["SwapFree"];
 | 
			
		||||
  }
 | 
			
		||||
  if (meminfo_.count("MemAvailable")) {
 | 
			
		||||
    // New kernels (3.4+) have an accurate available memory field.
 | 
			
		||||
    memfree = meminfo_["MemAvailable"] + meminfo_["zfs_size"];
 | 
			
		||||
@@ -24,9 +32,16 @@ auto waybar::modules::Memory::update() -> void {
 | 
			
		||||
 | 
			
		||||
  if (memtotal > 0 && memfree >= 0) {
 | 
			
		||||
    auto total_ram_gigabytes = memtotal / std::pow(1024, 2);
 | 
			
		||||
    auto total_swap_gigabytes = swaptotal / std::pow(1024, 2);
 | 
			
		||||
    int  used_ram_percentage = 100 * (memtotal - memfree) / memtotal;
 | 
			
		||||
    int  used_swap_percentage = 0;
 | 
			
		||||
    if (swaptotal && swapfree) {
 | 
			
		||||
      used_swap_percentage = 100 * (swaptotal - swapfree) / swaptotal;
 | 
			
		||||
    }
 | 
			
		||||
    auto used_ram_gigabytes = (memtotal - memfree) / std::pow(1024, 2);
 | 
			
		||||
    auto used_swap_gigabytes = (swaptotal - swapfree) / std::pow(1024, 2);
 | 
			
		||||
    auto available_ram_gigabytes = memfree / std::pow(1024, 2);
 | 
			
		||||
    auto available_swap_gigabytes = swapfree / std::pow(1024, 2);
 | 
			
		||||
 | 
			
		||||
    auto format = format_;
 | 
			
		||||
    auto state = getState(used_ram_percentage);
 | 
			
		||||
@@ -43,9 +58,13 @@ auto waybar::modules::Memory::update() -> void {
 | 
			
		||||
                                    used_ram_percentage,
 | 
			
		||||
                                    fmt::arg("icon", getIcon(used_ram_percentage, icons)),
 | 
			
		||||
                                    fmt::arg("total", total_ram_gigabytes),
 | 
			
		||||
                                    fmt::arg("swapTotal", total_swap_gigabytes),
 | 
			
		||||
                                    fmt::arg("percentage", used_ram_percentage),
 | 
			
		||||
                                    fmt::arg("swapPercentage", used_swap_percentage),
 | 
			
		||||
                                    fmt::arg("used", used_ram_gigabytes),
 | 
			
		||||
                                    fmt::arg("avail", available_ram_gigabytes)));
 | 
			
		||||
                                    fmt::arg("swapUsed", used_swap_gigabytes),
 | 
			
		||||
                                    fmt::arg("avail", available_ram_gigabytes),
 | 
			
		||||
                                    fmt::arg("swapAvail", available_swap_gigabytes)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (tooltipEnabled()) {
 | 
			
		||||
@@ -54,9 +73,13 @@ auto waybar::modules::Memory::update() -> void {
 | 
			
		||||
        label_.set_tooltip_text(fmt::format(tooltip_format,
 | 
			
		||||
                                            used_ram_percentage,
 | 
			
		||||
                                            fmt::arg("total", total_ram_gigabytes),
 | 
			
		||||
                                            fmt::arg("swapTotal", total_swap_gigabytes),
 | 
			
		||||
                                            fmt::arg("percentage", used_ram_percentage),
 | 
			
		||||
                                            fmt::arg("swapPercentage", used_swap_percentage),
 | 
			
		||||
                                            fmt::arg("used", used_ram_gigabytes),
 | 
			
		||||
                                            fmt::arg("avail", available_ram_gigabytes)));
 | 
			
		||||
                                            fmt::arg("swapUsed", used_swap_gigabytes),
 | 
			
		||||
                                            fmt::arg("avail", available_ram_gigabytes),
 | 
			
		||||
                                            fmt::arg("swapAvail", available_swap_gigabytes)));
 | 
			
		||||
      } else {
 | 
			
		||||
        label_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1));
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user