mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' into master
This commit is contained in:
@ -60,14 +60,14 @@ std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_
|
||||
std::string ALabel::getIcon(uint16_t percentage, std::vector<std::string>& alts, uint16_t max) {
|
||||
auto format_icons = config_["format-icons"];
|
||||
if (format_icons.isObject()) {
|
||||
std::string _alt = "default";
|
||||
for (const auto& alt : alts) {
|
||||
if (!alt.empty() && (format_icons[alt].isString() || format_icons[alt].isArray())) {
|
||||
format_icons = format_icons[alt];
|
||||
_alt = alt;
|
||||
break;
|
||||
} else {
|
||||
format_icons = format_icons["default"];
|
||||
}
|
||||
}
|
||||
format_icons = format_icons[_alt];
|
||||
}
|
||||
if (format_icons.isArray()) {
|
||||
auto size = format_icons.size();
|
||||
|
@ -303,10 +303,9 @@ int waybar::Client::main(int argc, char *argv[]) {
|
||||
gtk_app->hold();
|
||||
gtk_app->run();
|
||||
bars.clear();
|
||||
zxdg_output_manager_v1_destroy(xdg_output_manager);
|
||||
zwlr_layer_shell_v1_destroy(layer_shell);
|
||||
zwp_idle_inhibit_manager_v1_destroy(idle_inhibit_manager);
|
||||
wl_registry_destroy(registry);
|
||||
wl_display_disconnect(wl_display);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void waybar::Client::reset() {
|
||||
gtk_app->quit();
|
||||
}
|
||||
|
15
src/main.cpp
15
src/main.cpp
@ -8,6 +8,7 @@
|
||||
|
||||
std::mutex reap_mtx;
|
||||
std::list<pid_t> reap;
|
||||
volatile bool reload;
|
||||
|
||||
void* signalThread(void* args) {
|
||||
int err, signum;
|
||||
@ -70,12 +71,19 @@ void startSignalThread(void) {
|
||||
int main(int argc, char* argv[]) {
|
||||
try {
|
||||
auto client = waybar::Client::inst();
|
||||
|
||||
std::signal(SIGUSR1, [](int /*signal*/) {
|
||||
for (auto& bar : waybar::Client::inst()->bars) {
|
||||
bar->toggle();
|
||||
}
|
||||
});
|
||||
|
||||
std::signal(SIGUSR2, [](int /*signal*/) {
|
||||
spdlog::info("Reloading...");
|
||||
reload = true;
|
||||
waybar::Client::inst()->reset();
|
||||
});
|
||||
|
||||
for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
|
||||
std::signal(sig, [](int sig) {
|
||||
for (auto& bar : waybar::Client::inst()->bars) {
|
||||
@ -85,7 +93,12 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
startSignalThread();
|
||||
|
||||
auto ret = client->main(argc, argv);
|
||||
auto ret = 0;
|
||||
do {
|
||||
reload = false;
|
||||
ret = client->main(argc, argv);
|
||||
} while (reload);
|
||||
|
||||
delete client;
|
||||
return ret;
|
||||
} catch (const std::exception& e) {
|
||||
|
@ -15,8 +15,19 @@ auto waybar::modules::Cpu::update() -> void {
|
||||
if (tooltipEnabled()) {
|
||||
label_.set_tooltip_text(tooltip);
|
||||
}
|
||||
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
||||
getState(cpu_usage);
|
||||
auto format = format_;
|
||||
auto state = getState(cpu_usage);
|
||||
if (!state.empty() && config_["format-" + state].isString()) {
|
||||
format = config_["format-" + state].asString();
|
||||
}
|
||||
|
||||
if (format.empty()) {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
event_box_.show();
|
||||
label_.set_markup(fmt::format(format, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
||||
}
|
||||
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
}
|
||||
|
@ -49,15 +49,27 @@ auto waybar::modules::Disk::update() -> void {
|
||||
auto total = pow_format(stats.f_blocks * stats.f_frsize, "B", true);
|
||||
auto percentage_used = (stats.f_blocks - stats.f_bavail) * 100 / stats.f_blocks;
|
||||
|
||||
label_.set_markup(fmt::format(format_
|
||||
, stats.f_bavail * 100 / stats.f_blocks
|
||||
, fmt::arg("free", free)
|
||||
, fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks)
|
||||
, fmt::arg("used", used)
|
||||
, fmt::arg("percentage_used", percentage_used)
|
||||
, fmt::arg("total", total)
|
||||
, fmt::arg("path", path_)
|
||||
));
|
||||
auto format = format_;
|
||||
auto state = getState(percentage_used);
|
||||
if (!state.empty() && config_["format-" + state].isString()) {
|
||||
format = config_["format-" + state].asString();
|
||||
}
|
||||
|
||||
if (format.empty()) {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
event_box_.show();
|
||||
label_.set_markup(fmt::format(format
|
||||
, stats.f_bavail * 100 / stats.f_blocks
|
||||
, fmt::arg("free", free)
|
||||
, fmt::arg("percentage_free", stats.f_bavail * 100 / stats.f_blocks)
|
||||
, fmt::arg("used", used)
|
||||
, fmt::arg("percentage_used", percentage_used)
|
||||
, fmt::arg("total", total)
|
||||
, fmt::arg("path", path_)
|
||||
));
|
||||
}
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
std::string tooltip_format = "{used} used out of {total} on {path} ({percentage_used}%)";
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
@ -73,8 +85,6 @@ auto waybar::modules::Disk::update() -> void {
|
||||
, fmt::arg("path", path_)
|
||||
));
|
||||
}
|
||||
event_box_.show();
|
||||
getState(percentage_used);
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
}
|
||||
|
@ -28,13 +28,24 @@ auto waybar::modules::Memory::update() -> void {
|
||||
auto used_ram_gigabytes = (memtotal - memfree) / std::pow(1024, 2);
|
||||
auto available_ram_gigabytes = memfree / std::pow(1024, 2);
|
||||
|
||||
getState(used_ram_percentage);
|
||||
label_.set_markup(fmt::format(format_,
|
||||
used_ram_percentage,
|
||||
fmt::arg("total", total_ram_gigabytes),
|
||||
fmt::arg("percentage", used_ram_percentage),
|
||||
fmt::arg("used", used_ram_gigabytes),
|
||||
fmt::arg("avail", available_ram_gigabytes)));
|
||||
auto format = format_;
|
||||
auto state = getState(used_ram_percentage);
|
||||
if (!state.empty() && config_["format-" + state].isString()) {
|
||||
format = config_["format-" + state].asString();
|
||||
}
|
||||
|
||||
if (format.empty()) {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
event_box_.show();
|
||||
label_.set_markup(fmt::format(format,
|
||||
used_ram_percentage,
|
||||
fmt::arg("total", total_ram_gigabytes),
|
||||
fmt::arg("percentage", used_ram_percentage),
|
||||
fmt::arg("used", used_ram_gigabytes),
|
||||
fmt::arg("avail", available_ram_gigabytes)));
|
||||
}
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
auto tooltip_format = config_["tooltip-format"].asString();
|
||||
@ -48,7 +59,6 @@ auto waybar::modules::Memory::update() -> void {
|
||||
label_.set_tooltip_text(fmt::format("{:.{}f}GiB used", used_ram_gigabytes, 1));
|
||||
}
|
||||
}
|
||||
event_box_.show();
|
||||
} else {
|
||||
event_box_.hide();
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "client.hpp"
|
||||
#include "modules/river/tags.hpp"
|
||||
#include "river-status-unstable-v1-client-protocol.h"
|
||||
@ -64,8 +66,20 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
|
||||
|
||||
// Default to 9 tags
|
||||
const uint32_t num_tags = config["num-tags"].isUInt() ? config_["num-tags"].asUInt() : 9;
|
||||
for (uint32_t tag = 1; tag <= num_tags; ++tag) {
|
||||
Gtk::Button &button = buttons_.emplace_back(std::to_string(tag));
|
||||
|
||||
std::vector<std::string> tag_labels(num_tags);
|
||||
for (uint32_t tag = 0; tag < num_tags; ++tag) {
|
||||
tag_labels[tag] = std::to_string(tag+1);
|
||||
}
|
||||
const Json::Value custom_labels = config["tag-labels"];
|
||||
if (custom_labels.isArray() && !custom_labels.empty()) {
|
||||
for (uint32_t tag = 0; tag < std::min(num_tags, custom_labels.size()); ++tag) {
|
||||
tag_labels[tag] = custom_labels[tag].asString();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &tag_label : tag_labels) {
|
||||
Gtk::Button &button = buttons_.emplace_back(tag_label);
|
||||
button.set_relief(Gtk::RELIEF_NONE);
|
||||
box_.pack_start(button, false, false, 0);
|
||||
button.show();
|
||||
|
33
src/modules/simpleclock.cpp
Normal file
33
src/modules/simpleclock.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "modules/simpleclock.hpp"
|
||||
#include <time.h>
|
||||
|
||||
waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "clock", id, "{:%H:%M}", 60) {
|
||||
thread_ = [this] {
|
||||
dp.emit();
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto timeout = std::chrono::floor<std::chrono::seconds>(now + interval_);
|
||||
auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count());
|
||||
thread_.sleep_until(timeout - diff);
|
||||
};
|
||||
}
|
||||
|
||||
auto waybar::modules::Clock::update() -> void {
|
||||
tzset(); // Update timezone information
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto localtime = fmt::localtime(std::chrono::system_clock::to_time_t(now));
|
||||
auto text = fmt::format(format_, localtime);
|
||||
label_.set_markup(text);
|
||||
|
||||
if (tooltipEnabled()) {
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
auto tooltip_format = config_["tooltip-format"].asString();
|
||||
auto tooltip_text = fmt::format(tooltip_format, localtime);
|
||||
label_.set_tooltip_text(tooltip_text);
|
||||
} else {
|
||||
label_.set_tooltip_text(text);
|
||||
}
|
||||
}
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
}
|
@ -40,6 +40,16 @@ auto waybar::modules::Temperature::update() -> void {
|
||||
fmt::arg("temperatureF", temperature_f),
|
||||
fmt::arg("temperatureK", temperature_k),
|
||||
fmt::arg("icon", getIcon(temperature_c, "", max_temp))));
|
||||
if (tooltipEnabled()) {
|
||||
std::string tooltip_format = "{temperatureC}°C";
|
||||
if (config_["tooltip-format"].isString()) {
|
||||
tooltip_format = config_["tooltip-format"].asString();
|
||||
}
|
||||
label_.set_tooltip_text(fmt::format(tooltip_format,
|
||||
fmt::arg("temperatureC", temperature_c),
|
||||
fmt::arg("temperatureF", temperature_f),
|
||||
fmt::arg("temperatureK", temperature_k)));
|
||||
}
|
||||
// Call parent update
|
||||
ALabel::update();
|
||||
}
|
||||
|
@ -367,16 +367,16 @@ void Task::handle_output_leave(struct wl_output *output)
|
||||
void Task::handle_state(struct wl_array *state)
|
||||
{
|
||||
state_ = 0;
|
||||
for (auto* entry = static_cast<uint32_t*>(state->data);
|
||||
entry < static_cast<uint32_t*>(state->data) + state->size;
|
||||
entry++) {
|
||||
if (*entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED)
|
||||
size_t size = state->size / sizeof(uint32_t);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
auto entry = static_cast<uint32_t*>(state->data)[i];
|
||||
if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED)
|
||||
state_ |= MAXIMIZED;
|
||||
if (*entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED)
|
||||
if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED)
|
||||
state_ |= MINIMIZED;
|
||||
if (*entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED)
|
||||
if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED)
|
||||
state_ |= ACTIVE;
|
||||
if (*entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN)
|
||||
if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN)
|
||||
state_ |= FULLSCREEN;
|
||||
}
|
||||
}
|
||||
@ -637,8 +637,20 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
|
||||
Taskbar::~Taskbar()
|
||||
{
|
||||
if (manager_) {
|
||||
zwlr_foreign_toplevel_manager_v1_destroy(manager_);
|
||||
manager_ = nullptr;
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
/*
|
||||
* Send `stop` request and wait for one roundtrip.
|
||||
* This is not quite correct as the protocol encourages us to wait for the .finished event,
|
||||
* but it should work with wlroots foreign toplevel manager implementation.
|
||||
*/
|
||||
zwlr_foreign_toplevel_manager_v1_stop(manager_);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
if (manager_) {
|
||||
spdlog::warn("Foreign toplevel manager destroyed before .finished event");
|
||||
zwlr_foreign_toplevel_manager_v1_destroy(manager_);
|
||||
manager_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user