refactor: destroy threads first
This commit is contained in:
parent
b05d4cd413
commit
fcf2d18a01
|
@ -56,6 +56,6 @@ class Backlight : public ALabel {
|
||||||
std::mutex udev_thread_mutex_;
|
std::mutex udev_thread_mutex_;
|
||||||
std::vector<BacklightDev> devices_;
|
std::vector<BacklightDev> devices_;
|
||||||
// thread must destruct before shared data
|
// thread must destruct before shared data
|
||||||
waybar::util::SleeperThread udev_thread_;
|
util::SleeperThread udev_thread_;
|
||||||
};
|
};
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -31,19 +31,20 @@ class Battery : public ALabel {
|
||||||
private:
|
private:
|
||||||
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
|
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
|
||||||
|
|
||||||
void getBatteries();
|
void getBatteries();
|
||||||
void worker();
|
void worker();
|
||||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||||
const std::tuple<uint8_t, float, std::string> getInfos() const;
|
const std::tuple<uint8_t, float, std::string> getInfos() const;
|
||||||
const std::string formatTimeRemaining(float hoursRemaining);
|
const std::string formatTimeRemaining(float hoursRemaining);
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
|
||||||
util::SleeperThread thread_timer_;
|
|
||||||
std::vector<fs::path> batteries_;
|
std::vector<fs::path> batteries_;
|
||||||
fs::path adapter_;
|
fs::path adapter_;
|
||||||
int fd_;
|
int fd_;
|
||||||
std::vector<int> wds_;
|
std::vector<int> wds_;
|
||||||
std::string old_status_;
|
std::string old_status_;
|
||||||
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
|
util::SleeperThread thread_timer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Clock : public ALabel {
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
waybar::util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
#include <fstream>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <fstream>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
|
@ -26,7 +26,8 @@ class Cpu : public ALabel {
|
||||||
std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
|
std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
|
||||||
|
|
||||||
std::vector<std::tuple<size_t, size_t>> prev_times_;
|
std::vector<std::tuple<size_t, size_t>> prev_times_;
|
||||||
waybar::util::SleeperThread thread_;
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -25,17 +25,18 @@ class Custom : public ALabel {
|
||||||
bool handleScroll(GdkEventScroll* e);
|
bool handleScroll(GdkEventScroll* e);
|
||||||
bool handleToggle(GdkEventButton* const& e);
|
bool handleToggle(GdkEventButton* const& e);
|
||||||
|
|
||||||
const std::string name_;
|
const std::string name_;
|
||||||
std::string text_;
|
std::string text_;
|
||||||
std::string alt_;
|
std::string alt_;
|
||||||
std::string tooltip_;
|
std::string tooltip_;
|
||||||
std::vector<std::string> class_;
|
std::vector<std::string> class_;
|
||||||
int percentage_;
|
int percentage_;
|
||||||
waybar::util::SleeperThread thread_;
|
FILE* fp_;
|
||||||
waybar::util::command::res output_;
|
int pid_;
|
||||||
waybar::util::JsonParser parser_;
|
util::command::res output_;
|
||||||
FILE* fp_;
|
util::JsonParser parser_;
|
||||||
int pid_;
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -15,10 +15,12 @@ class Memory : public ALabel {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static inline const std::string data_dir_ = "/proc/meminfo";
|
static inline const std::string data_dir_ = "/proc/meminfo";
|
||||||
unsigned long memtotal_;
|
|
||||||
unsigned long memfree_;
|
|
||||||
void parseMeminfo();
|
void parseMeminfo();
|
||||||
waybar::util::SleeperThread thread_;
|
|
||||||
|
unsigned long memtotal_;
|
||||||
|
unsigned long memfree_;
|
||||||
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -46,17 +46,15 @@ class Network : public ALabel {
|
||||||
void clearIface();
|
void clearIface();
|
||||||
bool wildcardMatch(const std::string& pattern, const std::string& text) const;
|
bool wildcardMatch(const std::string& pattern, const std::string& text) const;
|
||||||
|
|
||||||
waybar::util::SleeperThread thread_;
|
int ifid_;
|
||||||
waybar::util::SleeperThread thread_timer_;
|
sa_family_t family_;
|
||||||
int ifid_;
|
struct sockaddr_nl nladdr_ = {0};
|
||||||
sa_family_t family_;
|
struct nl_sock* sock_ = nullptr;
|
||||||
struct sockaddr_nl nladdr_ = {0};
|
struct nl_sock* ev_sock_ = nullptr;
|
||||||
struct nl_sock* sock_ = nullptr;
|
int efd_;
|
||||||
struct nl_sock* ev_sock_ = nullptr;
|
int ev_fd_;
|
||||||
int efd_;
|
int nl80211_id_;
|
||||||
int ev_fd_;
|
std::mutex mutex_;
|
||||||
int nl80211_id_;
|
|
||||||
std::mutex mutex_;
|
|
||||||
|
|
||||||
unsigned long long bandwidth_down_total_;
|
unsigned long long bandwidth_down_total_;
|
||||||
unsigned long long bandwidth_up_total_;
|
unsigned long long bandwidth_up_total_;
|
||||||
|
@ -70,6 +68,9 @@ class Network : public ALabel {
|
||||||
int32_t signal_strength_dbm_;
|
int32_t signal_strength_dbm_;
|
||||||
uint8_t signal_strength_;
|
uint8_t signal_strength_;
|
||||||
uint32_t frequency_;
|
uint32_t frequency_;
|
||||||
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
|
util::SleeperThread thread_timer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
|
@ -20,10 +20,11 @@ class Mode : public ALabel, public sigc::trackable {
|
||||||
void onEvent(const struct Ipc::ipc_response&);
|
void onEvent(const struct Ipc::ipc_response&);
|
||||||
void worker();
|
void worker();
|
||||||
|
|
||||||
waybar::util::SleeperThread thread_;
|
std::string mode_;
|
||||||
Ipc ipc_;
|
|
||||||
std::string mode_;
|
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
|
Ipc ipc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
|
|
@ -24,14 +24,15 @@ class Window : public ALabel, public sigc::trackable {
|
||||||
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes);
|
std::tuple<std::size_t, int, std::string, std::string> getFocusedNode(const Json::Value& nodes);
|
||||||
void getTree();
|
void getTree();
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
waybar::util::SleeperThread thread_;
|
std::mutex mutex_;
|
||||||
Ipc ipc_;
|
std::string window_;
|
||||||
std::mutex mutex_;
|
int windowId_;
|
||||||
std::string window_;
|
std::string app_id_;
|
||||||
int windowId_;
|
util::JsonParser parser_;
|
||||||
std::string app_id_;
|
|
||||||
util::JsonParser parser_;
|
util::SleeperThread thread_;
|
||||||
|
Ipc ipc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
|
|
@ -36,13 +36,14 @@ class Workspaces : public IModule, public sigc::trackable {
|
||||||
const Json::Value& config_;
|
const Json::Value& config_;
|
||||||
std::vector<Json::Value> workspaces_;
|
std::vector<Json::Value> workspaces_;
|
||||||
std::vector<std::string> workspaces_order_;
|
std::vector<std::string> workspaces_order_;
|
||||||
waybar::util::SleeperThread thread_;
|
|
||||||
Ipc ipc_;
|
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
bool scrolling_;
|
bool scrolling_;
|
||||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||||
|
|
||||||
|
util::SleeperThread thread_;
|
||||||
|
Ipc ipc_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
|
|
@ -17,8 +17,8 @@ class Temperature : public ALabel {
|
||||||
std::tuple<uint16_t, uint16_t> getTemperature();
|
std::tuple<uint16_t, uint16_t> getTemperature();
|
||||||
bool isCritical(uint16_t);
|
bool isCritical(uint16_t);
|
||||||
|
|
||||||
std::string file_path_;
|
std::string file_path_;
|
||||||
waybar::util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|
|
@ -25,14 +25,14 @@ void waybar::modules::Custom::delayWorker() {
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
bool can_update = true;
|
bool can_update = true;
|
||||||
if (config_["exec-if"].isString()) {
|
if (config_["exec-if"].isString()) {
|
||||||
auto res = waybar::util::command::exec(config_["exec-if"].asString());
|
auto res = util::command::exec(config_["exec-if"].asString());
|
||||||
if (res.exit_code != 0) {
|
if (res.exit_code != 0) {
|
||||||
can_update = false;
|
can_update = false;
|
||||||
event_box_.hide();
|
event_box_.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (can_update) {
|
if (can_update) {
|
||||||
output_ = waybar::util::command::exec(config_["exec"].asString());
|
output_ = util::command::exec(config_["exec"].asString());
|
||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
thread_.sleep_for(interval_);
|
thread_.sleep_for(interval_);
|
||||||
|
|
Loading…
Reference in New Issue