mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
fix(battery): use path for the / operator
This commit is contained in:
parent
84728f6fab
commit
80e9ea746b
@ -7,11 +7,13 @@
|
|||||||
#include "modules/sway/window.hpp"
|
#include "modules/sway/window.hpp"
|
||||||
#include "modules/sway/workspaces.hpp"
|
#include "modules/sway/workspaces.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
#include "modules/battery.hpp"
|
#include "modules/battery.hpp"
|
||||||
|
#endif
|
||||||
#include "modules/cpu.hpp"
|
#include "modules/cpu.hpp"
|
||||||
#include "modules/idle_inhibitor.hpp"
|
#include "modules/idle_inhibitor.hpp"
|
||||||
#include "modules/memory.hpp"
|
#include "modules/memory.hpp"
|
||||||
#ifdef HAVE_DBUSMENU
|
#if defined(HAVE_DBUSMENU) && !defined(NO_FILESYSTEM)
|
||||||
#include "modules/sni/tray.hpp"
|
#include "modules/sni/tray.hpp"
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBNL
|
#ifdef HAVE_LIBNL
|
||||||
|
@ -4,11 +4,6 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
|
||||||
#include <experimental/filesystem>
|
|
||||||
#else
|
|
||||||
#include <filesystem>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ project(
|
|||||||
cpp_args = []
|
cpp_args = []
|
||||||
cpp_link_args = []
|
cpp_link_args = []
|
||||||
|
|
||||||
if false # libc++
|
if get_option('libcxx')
|
||||||
cpp_args += ['-stdlib=libc++']
|
cpp_args += ['-stdlib=libc++']
|
||||||
cpp_link_args += ['-stdlib=libc++', '-lc++abi']
|
cpp_link_args += ['-stdlib=libc++', '-lc++abi']
|
||||||
|
|
||||||
@ -34,7 +34,12 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if not compiler.has_header('filesystem')
|
if not compiler.has_header('filesystem')
|
||||||
|
if compiler.has_header('experimental/filesystem')
|
||||||
add_project_arguments('-DFILESYSTEM_EXPERIMENTAL', language: 'cpp')
|
add_project_arguments('-DFILESYSTEM_EXPERIMENTAL', language: 'cpp')
|
||||||
|
else
|
||||||
|
add_project_arguments('-DNO_FILESYSTEM', language: 'cpp')
|
||||||
|
warning('No filesystem header found, some modules may not work')
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
add_global_arguments(cpp_args, language : 'cpp')
|
add_global_arguments(cpp_args, language : 'cpp')
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
option('libcxx', type : 'boolean', value : false, description : 'Build with Clang\'s libc++ instead of libstdc++ on Linux.')
|
||||||
option('libnl', type: 'feature', value: 'auto', description: 'Enable libnl support for network related features')
|
option('libnl', type: 'feature', value: 'auto', description: 'Enable libnl support for network related features')
|
||||||
option('libudev', type: 'feature', value: 'auto', description: 'Enable libudev support for udev related features')
|
option('libudev', type: 'feature', value: 'auto', description: 'Enable libudev support for udev related features')
|
||||||
option('pulseaudio', type: 'feature', value: 'auto', description: 'Enable support for pulseaudio')
|
option('pulseaudio', type: 'feature', value: 'auto', description: 'Enable support for pulseaudio')
|
||||||
|
@ -7,9 +7,11 @@ waybar::IModule* waybar::Factory::makeModule(const std::string& name) const {
|
|||||||
auto hash_pos = name.find('#');
|
auto hash_pos = name.find('#');
|
||||||
auto ref = name.substr(0, hash_pos);
|
auto ref = name.substr(0, hash_pos);
|
||||||
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
|
auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : "";
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
if (ref == "battery") {
|
if (ref == "battery") {
|
||||||
return new waybar::modules::Battery(id, config_[name]);
|
return new waybar::modules::Battery(id, config_[name]);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
if (ref == "sway/mode") {
|
if (ref == "sway/mode") {
|
||||||
return new waybar::modules::sway::Mode(id, config_[name]);
|
return new waybar::modules::sway::Mode(id, config_[name]);
|
||||||
@ -33,7 +35,7 @@ waybar::IModule* waybar::Factory::makeModule(const std::string& name) const {
|
|||||||
if (ref == "clock") {
|
if (ref == "clock") {
|
||||||
return new waybar::modules::Clock(id, config_[name]);
|
return new waybar::modules::Clock(id, config_[name]);
|
||||||
}
|
}
|
||||||
#ifdef HAVE_DBUSMENU
|
#if defined(HAVE_DBUSMENU) && !defined(NO_FILESYSTEM)
|
||||||
if (ref == "tray") {
|
if (ref == "tray") {
|
||||||
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
|
return new waybar::modules::SNI::Tray(id, bar_, config_[name]);
|
||||||
}
|
}
|
||||||
|
@ -47,21 +47,21 @@ void waybar::modules::Battery::worker() {
|
|||||||
|
|
||||||
void waybar::modules::Battery::getBatteries() {
|
void waybar::modules::Battery::getBatteries() {
|
||||||
try {
|
try {
|
||||||
for (auto const& node : fs::directory_iterator(data_dir_)) {
|
for (auto& node : fs::directory_iterator(data_dir_)) {
|
||||||
if (!fs::is_directory(node)) {
|
if (!fs::is_directory(node)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto dir_name = node.path().filename();
|
auto dir_name = node.path().filename();
|
||||||
auto bat_defined = config_["bat"].isString();
|
auto bat_defined = config_["bat"].isString();
|
||||||
if (((bat_defined && dir_name == config_["bat"].asString()) || !bat_defined) &&
|
if (((bat_defined && dir_name == config_["bat"].asString()) || !bat_defined) &&
|
||||||
fs::exists(node / "capacity") && fs::exists(node / "uevent") &&
|
fs::exists(node.path() / "capacity") && fs::exists(node.path() / "uevent") &&
|
||||||
fs::exists(node / "status")) {
|
fs::exists(node.path() / "status")) {
|
||||||
batteries_.push_back(node);
|
batteries_.push_back(node.path());
|
||||||
}
|
}
|
||||||
auto adap_defined = config_["adapter"].isString();
|
auto adap_defined = config_["adapter"].isString();
|
||||||
if (((adap_defined && dir_name == config_["adapter"].asString()) || !adap_defined) &&
|
if (((adap_defined && dir_name == config_["adapter"].asString()) || !adap_defined) &&
|
||||||
fs::exists(node / "online")) {
|
fs::exists(node.path() / "online")) {
|
||||||
adapter_ = node;
|
adapter_ = node.path();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (fs::filesystem_error& e) {
|
} catch (fs::filesystem_error& e) {
|
||||||
|
@ -8,11 +8,8 @@ waybar::modules::Temperature::Temperature(const std::string& id, const Json::Val
|
|||||||
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
|
auto zone = config_["thermal-zone"].isInt() ? config_["thermal-zone"].asInt() : 0;
|
||||||
file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone);
|
file_path_ = fmt::format("/sys/class/thermal/thermal_zone{}/temp", zone);
|
||||||
}
|
}
|
||||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
std::ifstream temp(file_path_);
|
||||||
if (!std::experimental::filesystem::exists(file_path_)) {
|
if (!temp.is_open()) {
|
||||||
#else
|
|
||||||
if (!std::filesystem::exists(file_path_)) {
|
|
||||||
#endif
|
|
||||||
throw std::runtime_error("Can't open " + file_path_);
|
throw std::runtime_error("Can't open " + file_path_);
|
||||||
}
|
}
|
||||||
label_.set_name("temperature");
|
label_.set_name("temperature");
|
||||||
|
Loading…
Reference in New Issue
Block a user