mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' of https://github.com/Alexays/Waybar into pr/anakael/add-name-to-taskbar
This commit is contained in:
@ -26,9 +26,11 @@ auto waybar::modules::Cpu::update() -> void {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
event_box_.show();
|
||||
auto icons = std::vector<std::string>{state};
|
||||
label_.set_markup(fmt::format(format,
|
||||
fmt::arg("load", cpu_load),
|
||||
fmt::arg("usage", cpu_usage),
|
||||
fmt::arg("icon", getIcon(cpu_usage, icons)),
|
||||
fmt::arg("max_frequency", max_frequency),
|
||||
fmt::arg("min_frequency", min_frequency),
|
||||
fmt::arg("avg_frequency", avg_frequency)));
|
||||
|
@ -38,8 +38,10 @@ auto waybar::modules::Memory::update() -> void {
|
||||
event_box_.hide();
|
||||
} else {
|
||||
event_box_.show();
|
||||
auto icons = std::vector<std::string>{state};
|
||||
label_.set_markup(fmt::format(format,
|
||||
used_ram_percentage,
|
||||
fmt::arg("icon", getIcon(used_ram_percentage, icons)),
|
||||
fmt::arg("total", total_ram_gigabytes),
|
||||
fmt::arg("percentage", used_ram_percentage),
|
||||
fmt::arg("used", used_ram_gigabytes),
|
||||
|
@ -22,14 +22,24 @@ static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_
|
||||
static_cast<Tags *>(data)->handle_view_tags(tags);
|
||||
}
|
||||
|
||||
static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
uint32_t tags) {
|
||||
static_cast<Tags *>(data)->handle_urgent_tags(tags);
|
||||
}
|
||||
|
||||
static const zriver_output_status_v1_listener output_status_listener_impl{
|
||||
.focused_tags = listen_focused_tags,
|
||||
.view_tags = listen_view_tags,
|
||||
.urgent_tags = listen_urgent_tags,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) {
|
||||
version = std::min<uint32_t>(version, 2);
|
||||
if (version < ZRIVER_OUTPUT_STATUS_V1_URGENT_TAGS_SINCE_VERSION) {
|
||||
spdlog::warn("river server does not support urgent tags");
|
||||
}
|
||||
static_cast<Tags *>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1 *>(
|
||||
wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version));
|
||||
}
|
||||
@ -64,8 +74,9 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
|
||||
}
|
||||
event_box_.add(box_);
|
||||
|
||||
// Default to 9 tags
|
||||
const uint32_t num_tags = config["num-tags"].isUInt() ? config_["num-tags"].asUInt() : 9;
|
||||
// Default to 9 tags, cap at 32
|
||||
const uint32_t num_tags =
|
||||
config["num-tags"].isUInt() ? std::min<uint32_t>(32, config_["num-tags"].asUInt()) : 9;
|
||||
|
||||
std::vector<std::string> tag_labels(num_tags);
|
||||
for (uint32_t tag = 0; tag < num_tags; ++tag) {
|
||||
@ -129,4 +140,16 @@ void Tags::handle_view_tags(struct wl_array *view_tags) {
|
||||
}
|
||||
}
|
||||
|
||||
void Tags::handle_urgent_tags(uint32_t tags) {
|
||||
uint32_t i = 0;
|
||||
for (auto &button : buttons_) {
|
||||
if ((1 << i) & tags) {
|
||||
button.get_style_context()->add_class("urgent");
|
||||
} else {
|
||||
button.get_style_context()->remove_class("urgent");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace waybar::modules::river */
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
namespace waybar::modules::SNI {
|
||||
|
||||
Host::Host(const std::size_t id, const Json::Value& config,
|
||||
Host::Host(const std::size_t id, const Json::Value& config, const Bar& bar,
|
||||
const std::function<void(std::unique_ptr<Item>&)>& on_add,
|
||||
const std::function<void(std::unique_ptr<Item>&)>& on_remove)
|
||||
: bus_name_("org.kde.StatusNotifierHost-" + std::to_string(getpid()) + "-" +
|
||||
@ -13,6 +13,7 @@ Host::Host(const std::size_t id, const Json::Value& config,
|
||||
bus_name_id_(Gio::DBus::own_name(Gio::DBus::BusType::BUS_TYPE_SESSION, bus_name_,
|
||||
sigc::mem_fun(*this, &Host::busAcquired))),
|
||||
config_(config),
|
||||
bar_(bar),
|
||||
on_add_(on_add),
|
||||
on_remove_(on_remove) {}
|
||||
|
||||
@ -136,7 +137,7 @@ void Host::addRegisteredItem(std::string service) {
|
||||
return bus_name == item->bus_name && object_path == item->object_path;
|
||||
});
|
||||
if (it == items_.end()) {
|
||||
items_.emplace_back(new Item(bus_name, object_path, config_));
|
||||
items_.emplace_back(new Item(bus_name, object_path, config_, bar_));
|
||||
on_add_(items_.back());
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace waybar::modules::SNI {
|
||||
static const Glib::ustring SNI_INTERFACE_NAME = sn_item_interface_info()->name;
|
||||
static const unsigned UPDATE_DEBOUNCE_TIME = 10;
|
||||
|
||||
Item::Item(const std::string& bn, const std::string& op, const Json::Value& config)
|
||||
Item::Item(const std::string& bn, const std::string& op, const Json::Value& config, const Bar& bar)
|
||||
: bus_name(bn),
|
||||
object_path(op),
|
||||
icon_size(16),
|
||||
@ -54,6 +54,9 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
|
||||
if (config["show-passive-items"].isBool()) {
|
||||
show_passive_ = config["show-passive-items"].asBool();
|
||||
}
|
||||
|
||||
auto &window = const_cast<Bar &>(bar).window;
|
||||
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Item::onConfigure));
|
||||
event_box.add(image);
|
||||
event_box.add_events(Gdk::BUTTON_PRESS_MASK | Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||
event_box.signal_button_press_event().connect(sigc::mem_fun(*this, &Item::handleClick));
|
||||
@ -73,6 +76,10 @@ Item::Item(const std::string& bn, const std::string& op, const Json::Value& conf
|
||||
interface);
|
||||
}
|
||||
|
||||
void Item::onConfigure(GdkEventConfigure* ev) {
|
||||
this->updateImage();
|
||||
}
|
||||
|
||||
void Item::proxyReady(Glib::RefPtr<Gio::AsyncResult>& result) {
|
||||
try {
|
||||
this->proxy_ = Gio::DBus::Proxy::create_for_bus_finish(result);
|
||||
|
@ -7,7 +7,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: AModule(config, "tray", id),
|
||||
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
||||
watcher_(SNI::Watcher::getInstance()),
|
||||
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
||||
spdlog::warn(
|
||||
"For a functional tray you must have libappindicator-* installed and export "
|
||||
|
@ -20,6 +20,12 @@ const std::string Language::XKB_ACTIVE_LAYOUT_NAME_KEY = "xkb_active_layout_name
|
||||
Language::Language(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "language", id, "{}", 0, true) {
|
||||
is_variant_displayed = format_.find("{variant}") != std::string::npos;
|
||||
if (format_.find("{}") != std::string::npos || format_.find("{short}") != std::string::npos) {
|
||||
displayed_short_flag |= static_cast<std::byte>(DispayedShortFlag::ShortName);
|
||||
}
|
||||
if (format_.find("{shortDescription}") != std::string::npos) {
|
||||
displayed_short_flag |= static_cast<std::byte>(DispayedShortFlag::ShortDescription);
|
||||
}
|
||||
if (config.isMember("tooltip-format")) {
|
||||
tooltip_format_ = config["tooltip-format"].asString();
|
||||
}
|
||||
@ -88,8 +94,10 @@ void Language::onEvent(const struct Ipc::ipc_response& res) {
|
||||
}
|
||||
|
||||
auto Language::update() -> void {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto display_layout = trim(fmt::format(format_,
|
||||
fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description),
|
||||
fmt::arg("long", layout_.full_name),
|
||||
fmt::arg("variant", layout_.variant)));
|
||||
label_.set_markup(display_layout);
|
||||
@ -97,10 +105,10 @@ auto Language::update() -> void {
|
||||
if (tooltip_format_ != "") {
|
||||
auto tooltip_display_layout = trim(fmt::format(tooltip_format_,
|
||||
fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description),
|
||||
fmt::arg("long", layout_.full_name),
|
||||
fmt::arg("variant", layout_.variant)));
|
||||
label_.set_tooltip_markup(tooltip_display_layout);
|
||||
|
||||
} else {
|
||||
label_.set_tooltip_markup(display_layout);
|
||||
}
|
||||
@ -118,8 +126,9 @@ auto Language::set_current_layout(std::string current_layout) -> void {
|
||||
|
||||
auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) -> void {
|
||||
std::map<std::string, std::vector<Layout*>> found_by_short_names;
|
||||
auto layout = xkb_context_.next_layout();
|
||||
for (; layout != nullptr; layout = xkb_context_.next_layout()) {
|
||||
XKBContext xkb_context;
|
||||
auto layout = xkb_context.next_layout();
|
||||
for (; layout != nullptr; layout = xkb_context.next_layout()) {
|
||||
if (std::find(used_layouts.begin(), used_layouts.end(), layout->full_name) ==
|
||||
used_layouts.end()) {
|
||||
continue;
|
||||
@ -145,7 +154,6 @@ auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) ->
|
||||
for (const auto& used_layout_name : used_layouts) {
|
||||
auto used_layout = &layouts_map_.find(used_layout_name)->second;
|
||||
auto layouts_with_same_name_list = found_by_short_names[used_layout->short_name];
|
||||
spdlog::info("SIZE: " + std::to_string(layouts_with_same_name_list.size()));
|
||||
if (layouts_with_same_name_list.size() < 2) {
|
||||
continue;
|
||||
}
|
||||
@ -153,9 +161,15 @@ auto Language::init_layouts_map(const std::vector<std::string>& used_layouts) ->
|
||||
if (short_name_to_number_map.count(used_layout->short_name) == 0) {
|
||||
short_name_to_number_map[used_layout->short_name] = 1;
|
||||
}
|
||||
|
||||
used_layout->short_name =
|
||||
used_layout->short_name + std::to_string(short_name_to_number_map[used_layout->short_name]++);
|
||||
|
||||
if (displayed_short_flag != static_cast<std::byte>(0)) {
|
||||
int& number = short_name_to_number_map[used_layout->short_name];
|
||||
used_layout->short_name =
|
||||
used_layout->short_name + std::to_string(number);
|
||||
used_layout->short_description =
|
||||
used_layout->short_description + std::to_string(number);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,10 +194,22 @@ auto Language::XKBContext::next_layout() -> Layout* {
|
||||
auto name = std::string(rxkb_layout_get_name(xkb_layout_));
|
||||
auto variant_ = rxkb_layout_get_variant(xkb_layout_);
|
||||
std::string variant = variant_ == nullptr ? "" : std::string(variant_);
|
||||
|
||||
layout_ = new Layout{description, name, variant};
|
||||
auto short_description_ = rxkb_layout_get_brief(xkb_layout_);
|
||||
std::string short_description;
|
||||
if (short_description_ != nullptr) {
|
||||
short_description = std::string(short_description_);
|
||||
base_layouts_by_name_.emplace(name, xkb_layout_);
|
||||
} else {
|
||||
auto base_layout = base_layouts_by_name_[name];
|
||||
short_description = base_layout == nullptr ? "" : std::string(rxkb_layout_get_brief(base_layout));
|
||||
}
|
||||
delete layout_;
|
||||
layout_ = new Layout{description, name, variant, short_description};
|
||||
return layout_;
|
||||
}
|
||||
|
||||
Language::XKBContext::~XKBContext() { rxkb_context_unref(context_); }
|
||||
Language::XKBContext::~XKBContext() {
|
||||
rxkb_context_unref(context_);
|
||||
delete layout_;
|
||||
}
|
||||
} // namespace waybar::modules::sway
|
||||
|
Reference in New Issue
Block a user