chore: upgrade to clang-format@21
This commit is contained in:
@ -13,7 +13,7 @@
|
||||
#include "util/backend_common.hpp"
|
||||
#include "util/backlight_backend.hpp"
|
||||
|
||||
waybar::modules::Backlight::Backlight(const std::string &id, const Json::Value &config)
|
||||
waybar::modules::Backlight::Backlight(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "backlight", id, "{percent}%", 2),
|
||||
preferred_device_(config["device"].isString() ? config["device"].asString() : ""),
|
||||
backend(interval_, [this] { dp.emit(); }) {
|
||||
@ -79,7 +79,7 @@ auto waybar::modules::Backlight::update() -> void {
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
bool waybar::modules::Backlight::handleScroll(GdkEventScroll *e) {
|
||||
bool waybar::modules::Backlight::handleScroll(GdkEventScroll* e) {
|
||||
// Check if the user has set a custom command for scrolling
|
||||
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||
return AModule::handleScroll(e);
|
||||
|
||||
@ -33,7 +33,7 @@ std::vector<std::tuple<size_t, size_t>> waybar::modules::CpuUsage::parseCpuinfo(
|
||||
size_t sum_sz = sizeof(sum_cp_time);
|
||||
int ncpu = sysconf(_SC_NPROCESSORS_CONF);
|
||||
size_t sz = CPUSTATES * (ncpu + 1) * sizeof(pcp_time_t);
|
||||
pcp_time_t *cp_time = static_cast<pcp_time_t *>(malloc(sz)), *pcp_time = cp_time;
|
||||
pcp_time_t *cp_time = static_cast<pcp_time_t*>(malloc(sz)), *pcp_time = cp_time;
|
||||
waybar::util::ScopeGuard cp_time_deleter([cp_time]() {
|
||||
if (cp_time) {
|
||||
free(cp_time);
|
||||
|
||||
@ -21,39 +21,39 @@ wl_array tags, layouts;
|
||||
|
||||
static uint num_tags = 0;
|
||||
|
||||
static void toggle_visibility(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) {
|
||||
static void toggle_visibility(void* data, zdwl_ipc_output_v2* zdwl_output_v2) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void active(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t active) {
|
||||
static void active(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t active) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void set_tag(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t tag, uint32_t state,
|
||||
static void set_tag(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t tag, uint32_t state,
|
||||
uint32_t clients, uint32_t focused) {
|
||||
static_cast<Tags *>(data)->handle_view_tags(tag, state, clients, focused);
|
||||
static_cast<Tags*>(data)->handle_view_tags(tag, state, clients, focused);
|
||||
|
||||
num_tags = (state & ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE) ? num_tags | (1 << tag)
|
||||
: num_tags & ~(1 << tag);
|
||||
}
|
||||
|
||||
static void set_layout_symbol(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *layout) {
|
||||
static void set_layout_symbol(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* layout) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void title(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *title) {
|
||||
static void title(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* title) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void dwl_frame(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) {
|
||||
static void dwl_frame(void* data, zdwl_ipc_output_v2* zdwl_output_v2) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void set_layout(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t layout) {
|
||||
static void set_layout(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t layout) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void appid(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *appid) {
|
||||
static void appid(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* appid) {
|
||||
// Intentionally empty
|
||||
};
|
||||
|
||||
@ -68,35 +68,35 @@ static const zdwl_ipc_output_v2_listener output_status_listener_impl{
|
||||
.frame = dwl_frame,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
static void handle_global(void* data, struct wl_registry* registry, uint32_t name,
|
||||
const char* interface, uint32_t version) {
|
||||
if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) {
|
||||
static_cast<Tags *>(data)->status_manager_ = static_cast<struct zdwl_ipc_manager_v2 *>(
|
||||
(zdwl_ipc_manager_v2 *)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1));
|
||||
static_cast<Tags*>(data)->status_manager_ = static_cast<struct zdwl_ipc_manager_v2*>(
|
||||
(zdwl_ipc_manager_v2*)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1));
|
||||
}
|
||||
if (std::strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
version = std::min<uint32_t>(version, 1);
|
||||
static_cast<Tags *>(data)->seat_ = static_cast<struct wl_seat *>(
|
||||
wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
static_cast<Tags*>(data)->seat_ =
|
||||
static_cast<struct wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
/* Ignore event */
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
|
||||
Tags::Tags(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
||||
: waybar::AModule(config, "tags", id, false, false),
|
||||
status_manager_{nullptr},
|
||||
seat_{nullptr},
|
||||
bar_(bar),
|
||||
box_{bar.orientation, 0},
|
||||
output_status_{nullptr} {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
@ -133,8 +133,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
|
||||
}
|
||||
|
||||
uint32_t i = 1;
|
||||
for (const auto &tag_label : tag_labels) {
|
||||
Gtk::Button &button = buttons_.emplace_back(tag_label);
|
||||
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);
|
||||
if (!config_["disable-click"].asBool()) {
|
||||
@ -147,7 +147,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
|
||||
i <<= 1;
|
||||
}
|
||||
|
||||
struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
struct wl_output* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
output_status_ = zdwl_ipc_manager_v2_get_output(status_manager_, output);
|
||||
zdwl_ipc_output_v2_add_listener(output_status_, &output_status_listener_impl, this);
|
||||
|
||||
@ -170,7 +170,7 @@ void Tags::handle_primary_clicked(uint32_t tag) {
|
||||
zdwl_ipc_output_v2_set_tags(output_status_, tag, 1);
|
||||
}
|
||||
|
||||
bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) {
|
||||
bool Tags::handle_button_press(GdkEventButton* event_button, uint32_t tag) {
|
||||
if (event_button->type == GDK_BUTTON_PRESS && event_button->button == 3) {
|
||||
if (!output_status_) return true;
|
||||
zdwl_ipc_output_v2_set_tags(output_status_, num_tags ^ tag, 0);
|
||||
@ -180,7 +180,7 @@ bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) {
|
||||
|
||||
void Tags::handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused) {
|
||||
// First clear all occupied state
|
||||
auto &button = buttons_[tag];
|
||||
auto& button = buttons_[tag];
|
||||
if (clients) {
|
||||
button.get_style_context()->add_class("occupied");
|
||||
} else {
|
||||
|
||||
@ -14,37 +14,37 @@
|
||||
|
||||
namespace waybar::modules::dwl {
|
||||
|
||||
static void toggle_visibility(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) {
|
||||
static void toggle_visibility(void* data, zdwl_ipc_output_v2* zdwl_output_v2) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void active(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t active) {
|
||||
static void active(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t active) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void set_tag(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t tag, uint32_t state,
|
||||
static void set_tag(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t tag, uint32_t state,
|
||||
uint32_t clients, uint32_t focused) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void set_layout_symbol(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *layout) {
|
||||
static_cast<Window *>(data)->handle_layout_symbol(layout);
|
||||
static void set_layout_symbol(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* layout) {
|
||||
static_cast<Window*>(data)->handle_layout_symbol(layout);
|
||||
}
|
||||
|
||||
static void title(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *title) {
|
||||
static_cast<Window *>(data)->handle_title(title);
|
||||
static void title(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* title) {
|
||||
static_cast<Window*>(data)->handle_title(title);
|
||||
}
|
||||
|
||||
static void dwl_frame(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) {
|
||||
static_cast<Window *>(data)->handle_frame();
|
||||
static void dwl_frame(void* data, zdwl_ipc_output_v2* zdwl_output_v2) {
|
||||
static_cast<Window*>(data)->handle_frame();
|
||||
}
|
||||
|
||||
static void set_layout(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t layout) {
|
||||
static_cast<Window *>(data)->handle_layout(layout);
|
||||
static void set_layout(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t layout) {
|
||||
static_cast<Window*>(data)->handle_layout(layout);
|
||||
}
|
||||
|
||||
static void appid(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *appid) {
|
||||
static_cast<Window *>(data)->handle_appid(appid);
|
||||
static void appid(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* appid) {
|
||||
static_cast<Window*>(data)->handle_appid(appid);
|
||||
};
|
||||
|
||||
static const zdwl_ipc_output_v2_listener output_status_listener_impl{
|
||||
@ -58,25 +58,25 @@ static const zdwl_ipc_output_v2_listener output_status_listener_impl{
|
||||
.frame = dwl_frame,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
static void handle_global(void* data, struct wl_registry* registry, uint32_t name,
|
||||
const char* interface, uint32_t version) {
|
||||
if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) {
|
||||
static_cast<Window *>(data)->status_manager_ = static_cast<struct zdwl_ipc_manager_v2 *>(
|
||||
(zdwl_ipc_manager_v2 *)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1));
|
||||
static_cast<Window*>(data)->status_manager_ = static_cast<struct zdwl_ipc_manager_v2*>(
|
||||
(zdwl_ipc_manager_v2*)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
/* Ignore event */
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Window::Window(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: AAppIconLabel(config, "window", id, "{}", 0, true), bar_(bar) {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
@ -86,7 +86,7 @@ Window::Window(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
return;
|
||||
}
|
||||
|
||||
struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
struct wl_output* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
output_status_ = zdwl_ipc_manager_v2_get_output(status_manager_, output);
|
||||
zdwl_ipc_output_v2_add_listener(output_status_, &output_status_listener_impl, this);
|
||||
zdwl_ipc_manager_v2_destroy(status_manager_);
|
||||
@ -98,11 +98,11 @@ Window::~Window() {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::handle_title(const char *title) { title_ = Glib::Markup::escape_text(title); }
|
||||
void Window::handle_title(const char* title) { title_ = Glib::Markup::escape_text(title); }
|
||||
|
||||
void Window::handle_appid(const char *appid) { appid_ = Glib::Markup::escape_text(appid); }
|
||||
void Window::handle_appid(const char* appid) { appid_ = Glib::Markup::escape_text(appid); }
|
||||
|
||||
void Window::handle_layout_symbol(const char *layout_symbol) {
|
||||
void Window::handle_layout_symbol(const char* layout_symbol) {
|
||||
layout_symbol_ = Glib::Markup::escape_text(layout_symbol);
|
||||
}
|
||||
|
||||
|
||||
@ -20,8 +20,8 @@ uint32_t WorkspaceManager::group_global_id = 0;
|
||||
uint32_t WorkspaceManager::workspace_global_id = 0;
|
||||
std::map<std::string, std::string> Workspace::icon_map_;
|
||||
|
||||
WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar,
|
||||
const Json::Value &config)
|
||||
WorkspaceManager::WorkspaceManager(const std::string& id, const waybar::Bar& bar,
|
||||
const Json::Value& config)
|
||||
: waybar::AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) {
|
||||
add_registry_listener(this);
|
||||
|
||||
@ -70,7 +70,7 @@ WorkspaceManager::~WorkspaceManager() {
|
||||
groups_.clear();
|
||||
|
||||
if (ext_manager_ != nullptr) {
|
||||
auto *display = Client::inst()->wl_display;
|
||||
auto* display = Client::inst()->wl_display;
|
||||
// Send `stop` request and wait for one roundtrip.
|
||||
ext_workspace_manager_v1_stop(ext_manager_);
|
||||
wl_display_roundtrip(display);
|
||||
@ -84,7 +84,7 @@ WorkspaceManager::~WorkspaceManager() {
|
||||
spdlog::debug("[ext/workspaces]: Workspace manager destroyed");
|
||||
}
|
||||
|
||||
void WorkspaceManager::register_manager(wl_registry *registry, uint32_t name, uint32_t version) {
|
||||
void WorkspaceManager::register_manager(wl_registry* registry, uint32_t name, uint32_t version) {
|
||||
if (ext_manager_ != nullptr) {
|
||||
spdlog::warn("[ext/workspaces]: Register workspace manager again although already registered!");
|
||||
return;
|
||||
@ -99,7 +99,7 @@ void WorkspaceManager::register_manager(wl_registry *registry, uint32_t name, ui
|
||||
|
||||
void WorkspaceManager::remove_workspace_group(uint32_t id) {
|
||||
const auto it =
|
||||
std::find_if(groups_.begin(), groups_.end(), [id](const auto &g) { return g->id() == id; });
|
||||
std::find_if(groups_.begin(), groups_.end(), [id](const auto& g) { return g->id() == id; });
|
||||
|
||||
if (it == groups_.end()) {
|
||||
spdlog::warn("[ext/workspaces]: Can't find workspace group with id {}", id);
|
||||
@ -111,7 +111,7 @@ void WorkspaceManager::remove_workspace_group(uint32_t id) {
|
||||
|
||||
void WorkspaceManager::remove_workspace(uint32_t id) {
|
||||
const auto it = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||
[id](const auto &w) { return w->id() == id; });
|
||||
[id](const auto& w) { return w->id() == id; });
|
||||
|
||||
if (it == workspaces_.end()) {
|
||||
spdlog::warn("[ext/workspaces]: Can't find workspace with id {}", id);
|
||||
@ -121,13 +121,13 @@ void WorkspaceManager::remove_workspace(uint32_t id) {
|
||||
workspaces_.erase(it);
|
||||
}
|
||||
|
||||
void WorkspaceManager::handle_workspace_group(ext_workspace_group_handle_v1 *handle) {
|
||||
void WorkspaceManager::handle_workspace_group(ext_workspace_group_handle_v1* handle) {
|
||||
const auto new_id = ++group_global_id;
|
||||
groups_.push_back(std::make_unique<WorkspaceGroup>(*this, handle, new_id));
|
||||
spdlog::debug("[ext/workspaces]: Workspace group {} created", new_id);
|
||||
}
|
||||
|
||||
void WorkspaceManager::handle_workspace(ext_workspace_handle_v1 *handle) {
|
||||
void WorkspaceManager::handle_workspace(ext_workspace_handle_v1* handle) {
|
||||
const auto new_id = ++workspace_global_id;
|
||||
const auto new_name = std::to_string(++workspace_name);
|
||||
workspaces_.push_back(std::make_unique<Workspace>(config_, *this, handle, new_id, new_name));
|
||||
@ -158,7 +158,7 @@ void WorkspaceManager::update() {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
bool WorkspaceManager::has_button(const Gtk::Button *button) {
|
||||
bool WorkspaceManager::has_button(const Gtk::Button* button) {
|
||||
const auto buttons = box_.get_children();
|
||||
return std::find(buttons.begin(), buttons.end(), button) != buttons.end();
|
||||
}
|
||||
@ -166,20 +166,20 @@ bool WorkspaceManager::has_button(const Gtk::Button *button) {
|
||||
void WorkspaceManager::sort_workspaces() {
|
||||
// determine if workspace ID's and names can be sort numerically or literally
|
||||
|
||||
auto is_numeric = [](const std::string &s) {
|
||||
auto is_numeric = [](const std::string& s) {
|
||||
return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
|
||||
};
|
||||
|
||||
auto sort_by_workspace_id_numerically =
|
||||
std::all_of(workspaces_.begin(), workspaces_.end(),
|
||||
[&](const auto &w) { return is_numeric(w->workspace_id()); });
|
||||
[&](const auto& w) { return is_numeric(w->workspace_id()); });
|
||||
|
||||
auto sort_by_name_numerically = std::all_of(workspaces_.begin(), workspaces_.end(),
|
||||
[&](const auto &w) { return is_numeric(w->name()); });
|
||||
[&](const auto& w) { return is_numeric(w->name()); });
|
||||
|
||||
// sort based on configuration setting with sort-by-id as fallback
|
||||
|
||||
std::sort(workspaces_.begin(), workspaces_.end(), [&](const auto &w1, const auto &w2) {
|
||||
std::sort(workspaces_.begin(), workspaces_.end(), [&](const auto& w1, const auto& w2) {
|
||||
if (sort_by_id_ || (!sort_by_name_ && !sort_by_coordinates_)) {
|
||||
if (w1->workspace_id() == w2->workspace_id()) {
|
||||
return w1->id() < w2->id();
|
||||
@ -218,7 +218,7 @@ void WorkspaceManager::sort_workspaces() {
|
||||
}
|
||||
|
||||
void WorkspaceManager::clear_buttons() {
|
||||
for (const auto &workspace : workspaces_) {
|
||||
for (const auto& workspace : workspaces_) {
|
||||
if (has_button(&workspace->button())) {
|
||||
box_.remove(workspace->button());
|
||||
}
|
||||
@ -226,13 +226,13 @@ void WorkspaceManager::clear_buttons() {
|
||||
}
|
||||
|
||||
void WorkspaceManager::update_buttons() {
|
||||
const auto *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
const auto* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
|
||||
// go through all workspace
|
||||
|
||||
for (const auto &workspace : workspaces_) {
|
||||
for (const auto& workspace : workspaces_) {
|
||||
const bool workspace_on_any_group_for_output =
|
||||
std::any_of(groups_.begin(), groups_.end(), [&](const auto &group) {
|
||||
std::any_of(groups_.begin(), groups_.end(), [&](const auto& group) {
|
||||
const bool group_on_output = group->has_output(output) || all_outputs_;
|
||||
const bool workspace_on_group = group->has_workspace(workspace->handle());
|
||||
return group_on_output && workspace_on_group;
|
||||
@ -259,7 +259,7 @@ void WorkspaceManager::update_buttons() {
|
||||
|
||||
// WorkspaceGroup
|
||||
|
||||
WorkspaceGroup::WorkspaceGroup(WorkspaceManager &manager, ext_workspace_group_handle_v1 *handle,
|
||||
WorkspaceGroup::WorkspaceGroup(WorkspaceManager& manager, ext_workspace_group_handle_v1* handle,
|
||||
uint32_t id)
|
||||
: workspaces_manager_(manager), ext_handle_(handle), id_(id) {
|
||||
add_workspace_group_listener(ext_handle_, this);
|
||||
@ -272,11 +272,11 @@ WorkspaceGroup::~WorkspaceGroup() {
|
||||
spdlog::debug("[ext/workspaces]: Workspace group {} destroyed", id_);
|
||||
}
|
||||
|
||||
bool WorkspaceGroup::has_output(const wl_output *output) {
|
||||
bool WorkspaceGroup::has_output(const wl_output* output) {
|
||||
return std::find(outputs_.begin(), outputs_.end(), output) != outputs_.end();
|
||||
}
|
||||
|
||||
bool WorkspaceGroup::has_workspace(const ext_workspace_handle_v1 *workspace) {
|
||||
bool WorkspaceGroup::has_workspace(const ext_workspace_handle_v1* workspace) {
|
||||
return std::find(workspaces_.begin(), workspaces_.end(), workspace) != workspaces_.end();
|
||||
}
|
||||
|
||||
@ -288,20 +288,20 @@ void WorkspaceGroup::handle_capabilities(uint32_t capabilities) {
|
||||
}
|
||||
}
|
||||
|
||||
void WorkspaceGroup::handle_output_enter(wl_output *output) { outputs_.push_back(output); }
|
||||
void WorkspaceGroup::handle_output_enter(wl_output* output) { outputs_.push_back(output); }
|
||||
|
||||
void WorkspaceGroup::handle_output_leave(wl_output *output) {
|
||||
void WorkspaceGroup::handle_output_leave(wl_output* output) {
|
||||
const auto it = std::find(outputs_.begin(), outputs_.end(), output);
|
||||
if (it != outputs_.end()) {
|
||||
outputs_.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void WorkspaceGroup::handle_workspace_enter(ext_workspace_handle_v1 *handle) {
|
||||
void WorkspaceGroup::handle_workspace_enter(ext_workspace_handle_v1* handle) {
|
||||
workspaces_.push_back(handle);
|
||||
}
|
||||
|
||||
void WorkspaceGroup::handle_workspace_leave(ext_workspace_handle_v1 *handle) {
|
||||
void WorkspaceGroup::handle_workspace_leave(ext_workspace_handle_v1* handle) {
|
||||
const auto it = std::find(workspaces_.begin(), workspaces_.end(), handle);
|
||||
if (it != workspaces_.end()) {
|
||||
workspaces_.erase(it);
|
||||
@ -315,30 +315,30 @@ void WorkspaceGroup::handle_removed() {
|
||||
|
||||
// Workspace
|
||||
|
||||
Workspace::Workspace(const Json::Value &config, WorkspaceManager &manager,
|
||||
ext_workspace_handle_v1 *handle, uint32_t id, const std::string &name)
|
||||
Workspace::Workspace(const Json::Value& config, WorkspaceManager& manager,
|
||||
ext_workspace_handle_v1* handle, uint32_t id, const std::string& name)
|
||||
: workspace_manager_(manager), ext_handle_(handle), id_(id), workspace_id_(name), name_(name) {
|
||||
add_workspace_listener(ext_handle_, this);
|
||||
|
||||
// parse configuration
|
||||
|
||||
const auto &config_active_only = config["active-only"];
|
||||
const auto& config_active_only = config["active-only"];
|
||||
if (config_active_only.isBool()) {
|
||||
active_only_ = config_active_only.asBool();
|
||||
}
|
||||
|
||||
const auto &config_ignore_hidden = config["ignore-hidden"];
|
||||
const auto& config_ignore_hidden = config["ignore-hidden"];
|
||||
if (config_ignore_hidden.isBool()) {
|
||||
ignore_hidden_ = config_ignore_hidden.asBool();
|
||||
}
|
||||
|
||||
const auto &config_format = config["format"];
|
||||
const auto& config_format = config["format"];
|
||||
format_ = config_format.isString() ? config_format.asString() : "{name}";
|
||||
with_icon_ = format_.find("{icon}") != std::string::npos;
|
||||
|
||||
if (with_icon_ && icon_map_.empty()) {
|
||||
const auto &format_icons = config["format-icons"];
|
||||
for (auto &n : format_icons.getMemberNames()) {
|
||||
const auto& format_icons = config["format-icons"];
|
||||
for (auto& n : format_icons.getMemberNames()) {
|
||||
icon_map_.emplace(n, format_icons[n].asString());
|
||||
}
|
||||
}
|
||||
@ -413,19 +413,19 @@ void Workspace::update() {
|
||||
fmt::arg("icon", with_icon_ ? icon() : "")));
|
||||
}
|
||||
|
||||
void Workspace::handle_id(const std::string &id) {
|
||||
void Workspace::handle_id(const std::string& id) {
|
||||
spdlog::debug("[ext/workspaces]: ID for workspace {}: {}", id_, id);
|
||||
workspace_id_ = id;
|
||||
workspace_manager_.set_needs_sorting();
|
||||
}
|
||||
|
||||
void Workspace::handle_name(const std::string &name) {
|
||||
void Workspace::handle_name(const std::string& name) {
|
||||
spdlog::debug("[ext/workspaces]: Name for workspace {}: {}", id_, name);
|
||||
name_ = name;
|
||||
workspace_manager_.set_needs_sorting();
|
||||
}
|
||||
|
||||
void Workspace::handle_coordinates(const std::vector<uint32_t> &coordinates) {
|
||||
void Workspace::handle_coordinates(const std::vector<uint32_t>& coordinates) {
|
||||
coordinates_ = coordinates;
|
||||
workspace_manager_.set_needs_sorting();
|
||||
}
|
||||
@ -453,7 +453,7 @@ void Workspace::handle_removed() {
|
||||
workspace_manager_.remove_workspace(id_);
|
||||
}
|
||||
|
||||
bool Workspace::handle_clicked(const GdkEventButton *button) const {
|
||||
bool Workspace::handle_clicked(const GdkEventButton* button) const {
|
||||
std::string action;
|
||||
if (button->button == GDK_BUTTON_PRIMARY) {
|
||||
action = on_click_action_;
|
||||
|
||||
@ -9,44 +9,44 @@
|
||||
|
||||
namespace waybar::modules::ext {
|
||||
|
||||
static void handle_global(void *data, wl_registry *registry, uint32_t name, const char *interface,
|
||||
static void handle_global(void* data, wl_registry* registry, uint32_t name, const char* interface,
|
||||
uint32_t version) {
|
||||
if (std::strcmp(interface, ext_workspace_manager_v1_interface.name) == 0) {
|
||||
static_cast<WorkspaceManager *>(data)->register_manager(registry, name, version);
|
||||
static_cast<WorkspaceManager*>(data)->register_manager(registry, name, version);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, wl_registry* registry, uint32_t name) {
|
||||
/* Nothing to do here */
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
void add_registry_listener(void *data) {
|
||||
wl_display *display = Client::inst()->wl_display;
|
||||
wl_registry *registry = wl_display_get_registry(display);
|
||||
void add_registry_listener(void* data) {
|
||||
wl_display* display = Client::inst()->wl_display;
|
||||
wl_registry* registry = wl_display_get_registry(display);
|
||||
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, data);
|
||||
wl_display_roundtrip(display);
|
||||
}
|
||||
|
||||
static void workspace_manager_handle_workspace_group(
|
||||
void *data, ext_workspace_manager_v1 *_, ext_workspace_group_handle_v1 *workspace_group) {
|
||||
static_cast<WorkspaceManager *>(data)->handle_workspace_group(workspace_group);
|
||||
void* data, ext_workspace_manager_v1* _, ext_workspace_group_handle_v1* workspace_group) {
|
||||
static_cast<WorkspaceManager*>(data)->handle_workspace_group(workspace_group);
|
||||
}
|
||||
|
||||
static void workspace_manager_handle_workspace(void *data, ext_workspace_manager_v1 *_,
|
||||
ext_workspace_handle_v1 *workspace) {
|
||||
static_cast<WorkspaceManager *>(data)->handle_workspace(workspace);
|
||||
static void workspace_manager_handle_workspace(void* data, ext_workspace_manager_v1* _,
|
||||
ext_workspace_handle_v1* workspace) {
|
||||
static_cast<WorkspaceManager*>(data)->handle_workspace(workspace);
|
||||
}
|
||||
|
||||
static void workspace_manager_handle_done(void *data, ext_workspace_manager_v1 *_) {
|
||||
static_cast<WorkspaceManager *>(data)->handle_done();
|
||||
static void workspace_manager_handle_done(void* data, ext_workspace_manager_v1* _) {
|
||||
static_cast<WorkspaceManager*>(data)->handle_done();
|
||||
}
|
||||
|
||||
static void workspace_manager_handle_finished(void *data, ext_workspace_manager_v1 *_) {
|
||||
static_cast<WorkspaceManager *>(data)->handle_finished();
|
||||
static void workspace_manager_handle_finished(void* data, ext_workspace_manager_v1* _) {
|
||||
static_cast<WorkspaceManager*>(data)->handle_finished();
|
||||
}
|
||||
|
||||
static const ext_workspace_manager_v1_listener workspace_manager_impl = {
|
||||
@ -56,9 +56,9 @@ static const ext_workspace_manager_v1_listener workspace_manager_impl = {
|
||||
.finished = workspace_manager_handle_finished,
|
||||
};
|
||||
|
||||
ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name,
|
||||
uint32_t version, void *data) {
|
||||
auto *workspace_manager = static_cast<ext_workspace_manager_v1 *>(
|
||||
ext_workspace_manager_v1* workspace_manager_bind(wl_registry* registry, uint32_t name,
|
||||
uint32_t version, void* data) {
|
||||
auto* workspace_manager = static_cast<ext_workspace_manager_v1*>(
|
||||
wl_registry_bind(registry, name, &ext_workspace_manager_v1_interface, version));
|
||||
|
||||
if (workspace_manager)
|
||||
@ -69,33 +69,33 @@ ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t
|
||||
return workspace_manager;
|
||||
}
|
||||
|
||||
static void workspace_group_handle_capabilities(void *data, ext_workspace_group_handle_v1 *_,
|
||||
static void workspace_group_handle_capabilities(void* data, ext_workspace_group_handle_v1* _,
|
||||
uint32_t capabilities) {
|
||||
static_cast<WorkspaceGroup *>(data)->handle_capabilities(capabilities);
|
||||
static_cast<WorkspaceGroup*>(data)->handle_capabilities(capabilities);
|
||||
}
|
||||
|
||||
static void workspace_group_handle_output_enter(void *data, ext_workspace_group_handle_v1 *_,
|
||||
wl_output *output) {
|
||||
static_cast<WorkspaceGroup *>(data)->handle_output_enter(output);
|
||||
static void workspace_group_handle_output_enter(void* data, ext_workspace_group_handle_v1* _,
|
||||
wl_output* output) {
|
||||
static_cast<WorkspaceGroup*>(data)->handle_output_enter(output);
|
||||
}
|
||||
|
||||
static void workspace_group_handle_output_leave(void *data, ext_workspace_group_handle_v1 *_,
|
||||
wl_output *output) {
|
||||
static_cast<WorkspaceGroup *>(data)->handle_output_leave(output);
|
||||
static void workspace_group_handle_output_leave(void* data, ext_workspace_group_handle_v1* _,
|
||||
wl_output* output) {
|
||||
static_cast<WorkspaceGroup*>(data)->handle_output_leave(output);
|
||||
}
|
||||
|
||||
static void workspace_group_handle_workspace_enter(void *data, ext_workspace_group_handle_v1 *_,
|
||||
ext_workspace_handle_v1 *workspace) {
|
||||
static_cast<WorkspaceGroup *>(data)->handle_workspace_enter(workspace);
|
||||
static void workspace_group_handle_workspace_enter(void* data, ext_workspace_group_handle_v1* _,
|
||||
ext_workspace_handle_v1* workspace) {
|
||||
static_cast<WorkspaceGroup*>(data)->handle_workspace_enter(workspace);
|
||||
}
|
||||
|
||||
static void workspace_group_handle_workspace_leave(void *data, ext_workspace_group_handle_v1 *_,
|
||||
ext_workspace_handle_v1 *workspace) {
|
||||
static_cast<WorkspaceGroup *>(data)->handle_workspace_leave(workspace);
|
||||
static void workspace_group_handle_workspace_leave(void* data, ext_workspace_group_handle_v1* _,
|
||||
ext_workspace_handle_v1* workspace) {
|
||||
static_cast<WorkspaceGroup*>(data)->handle_workspace_leave(workspace);
|
||||
}
|
||||
|
||||
static void workspace_group_handle_removed(void *data, ext_workspace_group_handle_v1 *_) {
|
||||
static_cast<WorkspaceGroup *>(data)->handle_removed();
|
||||
static void workspace_group_handle_removed(void* data, ext_workspace_group_handle_v1* _) {
|
||||
static_cast<WorkspaceGroup*>(data)->handle_removed();
|
||||
}
|
||||
|
||||
static const ext_workspace_group_handle_v1_listener workspace_group_impl = {
|
||||
@ -106,43 +106,43 @@ static const ext_workspace_group_handle_v1_listener workspace_group_impl = {
|
||||
.workspace_leave = workspace_group_handle_workspace_leave,
|
||||
.removed = workspace_group_handle_removed};
|
||||
|
||||
void add_workspace_group_listener(ext_workspace_group_handle_v1 *workspace_group_handle,
|
||||
void *data) {
|
||||
void add_workspace_group_listener(ext_workspace_group_handle_v1* workspace_group_handle,
|
||||
void* data) {
|
||||
ext_workspace_group_handle_v1_add_listener(workspace_group_handle, &workspace_group_impl, data);
|
||||
}
|
||||
|
||||
void workspace_handle_name(void *data, struct ext_workspace_handle_v1 *_, const char *name) {
|
||||
static_cast<Workspace *>(data)->handle_name(name);
|
||||
void workspace_handle_name(void* data, struct ext_workspace_handle_v1* _, const char* name) {
|
||||
static_cast<Workspace*>(data)->handle_name(name);
|
||||
}
|
||||
|
||||
void workspace_handle_id(void *data, struct ext_workspace_handle_v1 *_, const char *id) {
|
||||
static_cast<Workspace *>(data)->handle_id(id);
|
||||
void workspace_handle_id(void* data, struct ext_workspace_handle_v1* _, const char* id) {
|
||||
static_cast<Workspace*>(data)->handle_id(id);
|
||||
}
|
||||
|
||||
void workspace_handle_coordinates(void *data, struct ext_workspace_handle_v1 *_,
|
||||
struct wl_array *coordinates) {
|
||||
void workspace_handle_coordinates(void* data, struct ext_workspace_handle_v1* _,
|
||||
struct wl_array* coordinates) {
|
||||
std::vector<uint32_t> coords_vec;
|
||||
auto coords = static_cast<uint32_t *>(coordinates->data);
|
||||
auto coords = static_cast<uint32_t*>(coordinates->data);
|
||||
for (size_t i = 0; i < coordinates->size / sizeof(uint32_t); ++i) {
|
||||
coords_vec.push_back(coords[i]);
|
||||
}
|
||||
|
||||
static_cast<Workspace *>(data)->handle_coordinates(coords_vec);
|
||||
static_cast<Workspace*>(data)->handle_coordinates(coords_vec);
|
||||
}
|
||||
|
||||
void workspace_handle_state(void *data, struct ext_workspace_handle_v1 *workspace_handle,
|
||||
void workspace_handle_state(void* data, struct ext_workspace_handle_v1* workspace_handle,
|
||||
uint32_t state) {
|
||||
static_cast<Workspace *>(data)->handle_state(state);
|
||||
static_cast<Workspace*>(data)->handle_state(state);
|
||||
}
|
||||
|
||||
static void workspace_handle_capabilities(void *data,
|
||||
struct ext_workspace_handle_v1 *workspace_handle,
|
||||
static void workspace_handle_capabilities(void* data,
|
||||
struct ext_workspace_handle_v1* workspace_handle,
|
||||
uint32_t capabilities) {
|
||||
static_cast<Workspace *>(data)->handle_capabilities(capabilities);
|
||||
static_cast<Workspace*>(data)->handle_capabilities(capabilities);
|
||||
}
|
||||
|
||||
void workspace_handle_removed(void *data, struct ext_workspace_handle_v1 *workspace_handle) {
|
||||
static_cast<Workspace *>(data)->handle_removed();
|
||||
void workspace_handle_removed(void* data, struct ext_workspace_handle_v1* workspace_handle) {
|
||||
static_cast<Workspace*>(data)->handle_removed();
|
||||
}
|
||||
|
||||
static const ext_workspace_handle_v1_listener workspace_impl = {
|
||||
@ -153,7 +153,7 @@ static const ext_workspace_handle_v1_listener workspace_impl = {
|
||||
.capabilities = workspace_handle_capabilities,
|
||||
.removed = workspace_handle_removed};
|
||||
|
||||
void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data) {
|
||||
void add_workspace_listener(ext_workspace_handle_v1* workspace_handle, void* data) {
|
||||
ext_workspace_handle_v1_add_listener(workspace_handle, &workspace_impl, data);
|
||||
}
|
||||
} // namespace waybar::modules::ext
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
WindowCreationPayload::WindowCreationPayload(Json::Value const &client_data)
|
||||
WindowCreationPayload::WindowCreationPayload(Json::Value const& client_data)
|
||||
: m_window(std::make_pair(client_data["class"].asString(), client_data["title"].asString())),
|
||||
m_windowAddress(client_data["address"].asString()),
|
||||
m_workspaceName(client_data["workspace"]["name"].asString()) {
|
||||
@ -73,7 +73,7 @@ void WindowCreationPayload::clearWorkspaceName() {
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowCreationPayload::isEmpty(Workspaces &workspace_manager) {
|
||||
bool WindowCreationPayload::isEmpty(Workspaces& workspace_manager) {
|
||||
if (std::holds_alternative<Repr>(m_window)) {
|
||||
return std::get<Repr>(m_window).empty();
|
||||
}
|
||||
@ -89,16 +89,16 @@ bool WindowCreationPayload::isEmpty(Workspaces &workspace_manager) {
|
||||
|
||||
int WindowCreationPayload::incrementTimeSpentUncreated() { return m_timeSpentUncreated++; }
|
||||
|
||||
void WindowCreationPayload::moveToWorkspace(std::string &new_workspace_name) {
|
||||
void WindowCreationPayload::moveToWorkspace(std::string& new_workspace_name) {
|
||||
m_workspaceName = new_workspace_name;
|
||||
}
|
||||
|
||||
WindowRepr WindowCreationPayload::repr(Workspaces &workspace_manager) {
|
||||
WindowRepr WindowCreationPayload::repr(Workspaces& workspace_manager) {
|
||||
if (std::holds_alternative<Repr>(m_window)) {
|
||||
return std::get<Repr>(m_window);
|
||||
}
|
||||
if (std::holds_alternative<ClassAndTitle>(m_window)) {
|
||||
auto const &[window_class, window_title] = std::get<ClassAndTitle>(m_window);
|
||||
auto const& [window_class, window_title] = std::get<ClassAndTitle>(m_window);
|
||||
return {m_windowAddress, window_class, window_title,
|
||||
workspace_manager.getRewrite(window_class, window_title), m_isActive};
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager,
|
||||
const Json::Value &clients_data)
|
||||
Workspace::Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager,
|
||||
const Json::Value& clients_data)
|
||||
: m_workspaceManager(workspace_manager),
|
||||
m_id(workspace_data["id"].asInt()),
|
||||
m_name(workspace_data["name"].asString()),
|
||||
@ -45,8 +45,8 @@ Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_ma
|
||||
initializeWindowMap(clients_data);
|
||||
}
|
||||
|
||||
void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext> &context, bool condition,
|
||||
const std::string &class_name) {
|
||||
void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext>& context, bool condition,
|
||||
const std::string& class_name) {
|
||||
if (condition) {
|
||||
context->add_class(class_name);
|
||||
} else {
|
||||
@ -54,9 +54,9 @@ void addOrRemoveClass(const Glib::RefPtr<Gtk::StyleContext> &context, bool condi
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const &addr) {
|
||||
std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const& addr) {
|
||||
auto it = std::ranges::find_if(m_windowMap,
|
||||
[&addr](const auto &window) { return window.address == addr; });
|
||||
[&addr](const auto& window) { return window.address == addr; });
|
||||
// If the vector contains the address, remove it and return the window representation
|
||||
if (it != m_windowMap.end()) {
|
||||
WindowRepr windowRepr = *it;
|
||||
@ -66,7 +66,7 @@ std::optional<WindowRepr> Workspace::closeWindow(WindowAddress const &addr) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool Workspace::handleClicked(GdkEventButton *bt) const {
|
||||
bool Workspace::handleClicked(GdkEventButton* bt) const {
|
||||
if (bt->type == GDK_BUTTON_PRESS) {
|
||||
try {
|
||||
if (id() > 0) { // normal
|
||||
@ -87,14 +87,14 @@ bool Workspace::handleClicked(GdkEventButton *bt) const {
|
||||
m_ipc.getSocket1Reply("dispatch togglespecialworkspace");
|
||||
}
|
||||
return true;
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Failed to dispatch workspace: {}", e.what());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Workspace::initializeWindowMap(const Json::Value &clients_data) {
|
||||
void Workspace::initializeWindowMap(const Json::Value& clients_data) {
|
||||
m_windowMap.clear();
|
||||
for (auto client : clients_data) {
|
||||
if (client["workspace"]["id"].asInt() == id()) {
|
||||
@ -103,10 +103,10 @@ void Workspace::initializeWindowMap(const Json::Value &clients_data) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspace::setActiveWindow(WindowAddress const &addr) {
|
||||
void Workspace::setActiveWindow(WindowAddress const& addr) {
|
||||
std::optional<long> activeIdx;
|
||||
for (size_t i = 0; i < m_windowMap.size(); ++i) {
|
||||
auto &window = m_windowMap[i];
|
||||
auto& window = m_windowMap[i];
|
||||
bool isActive = (window.address == addr);
|
||||
window.setActive(isActive);
|
||||
if (isActive) {
|
||||
@ -133,7 +133,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) {
|
||||
if (!repr.empty() || m_workspaceManager.enableTaskbar()) {
|
||||
auto addr = create_window_payload.getAddress();
|
||||
auto it = std::ranges::find_if(
|
||||
m_windowMap, [&addr](const auto &window) { return window.address == addr; });
|
||||
m_windowMap, [&addr](const auto& window) { return window.address == addr; });
|
||||
// If the vector contains the address, update the window representation, otherwise insert it
|
||||
if (it != m_windowMap.end()) {
|
||||
*it = repr;
|
||||
@ -144,7 +144,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) {
|
||||
}
|
||||
};
|
||||
|
||||
bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payload) {
|
||||
bool Workspace::onWindowOpened(WindowCreationPayload const& create_window_payload) {
|
||||
if (create_window_payload.getWorkspaceName() == name()) {
|
||||
insertWindow(create_window_payload);
|
||||
return true;
|
||||
@ -152,7 +152,7 @@ bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payloa
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map) {
|
||||
std::string& Workspace::selectIcon(std::map<std::string, std::string>& icons_map) {
|
||||
spdlog::trace("Selecting icon for workspace {}", name());
|
||||
if (isUrgent()) {
|
||||
auto urgentIconIt = icons_map.find("urgent");
|
||||
@ -209,7 +209,7 @@ std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Workspace::update(const std::string &workspace_icon) {
|
||||
void Workspace::update(const std::string& workspace_icon) {
|
||||
if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) {
|
||||
m_button.hide();
|
||||
return;
|
||||
@ -248,7 +248,7 @@ void Workspace::update(const std::string &workspace_icon) {
|
||||
|
||||
bool isNotFirst = false;
|
||||
|
||||
for (const auto &window_repr : m_windowMap) {
|
||||
for (const auto& window_repr : m_windowMap) {
|
||||
if (isNotFirst) {
|
||||
windows.append(windowSeparator);
|
||||
}
|
||||
@ -276,10 +276,10 @@ bool Workspace::isEmpty() const {
|
||||
// If there are windows but they are all ignored, consider the workspace empty
|
||||
return std::all_of(
|
||||
m_windowMap.begin(), m_windowMap.end(),
|
||||
[this, &ignore_list](const auto &window_repr) { return shouldSkipWindow(window_repr); });
|
||||
[this, &ignore_list](const auto& window_repr) { return shouldSkipWindow(window_repr); });
|
||||
}
|
||||
|
||||
void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
void Workspace::updateTaskbar(const std::string& workspace_icon) {
|
||||
for (auto child : m_content.get_children()) {
|
||||
if (child != &m_labelBefore) {
|
||||
m_content.remove(*child);
|
||||
@ -287,7 +287,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
}
|
||||
|
||||
bool isFirst = true;
|
||||
auto processWindow = [&](const WindowRepr &window_repr) {
|
||||
auto processWindow = [&](const WindowRepr& window_repr) {
|
||||
if (shouldSkipWindow(window_repr)) {
|
||||
return; // skip
|
||||
}
|
||||
@ -343,7 +343,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
processWindow(*it);
|
||||
}
|
||||
} else {
|
||||
for (const auto &window_repr : m_windowMap) {
|
||||
for (const auto& window_repr : m_windowMap) {
|
||||
processWindow(window_repr);
|
||||
}
|
||||
}
|
||||
@ -358,7 +358,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress const &addr) const {
|
||||
bool Workspace::handleClick(const GdkEventButton* event_button, WindowAddress const& addr) const {
|
||||
if (event_button->type == GDK_BUTTON_PRESS) {
|
||||
std::string command = std::regex_replace(m_workspaceManager.onClickWindow(),
|
||||
std::regex("\\{address\\}"), "0x" + addr);
|
||||
@ -372,9 +372,9 @@ bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress co
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Workspace::shouldSkipWindow(const WindowRepr &window_repr) const {
|
||||
bool Workspace::shouldSkipWindow(const WindowRepr& window_repr) const {
|
||||
auto ignore_list = m_workspaceManager.getIgnoredWindows();
|
||||
auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto &ignoreItem) {
|
||||
auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto& ignoreItem) {
|
||||
return std::regex_match(window_repr.window_class, ignoreItem) ||
|
||||
std::regex_match(window_repr.window_title, ignoreItem);
|
||||
});
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
namespace waybar::modules::hyprland {
|
||||
|
||||
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: AModule(config, "workspaces", id, false, false),
|
||||
m_bar(bar),
|
||||
m_box(bar.orientation, 0),
|
||||
@ -46,8 +46,8 @@ void Workspaces::init() {
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name,
|
||||
std::string const &monitor) {
|
||||
Json::Value Workspaces::createMonitorWorkspaceData(std::string const& name,
|
||||
std::string const& monitor) {
|
||||
spdlog::trace("Creating persistent workspace: {} on monitor {}", name, monitor);
|
||||
Json::Value workspaceData;
|
||||
|
||||
@ -62,14 +62,14 @@ Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name,
|
||||
return workspaceData;
|
||||
}
|
||||
|
||||
void Workspaces::createWorkspace(Json::Value const &workspace_data,
|
||||
Json::Value const &clients_data) {
|
||||
void Workspaces::createWorkspace(Json::Value const& workspace_data,
|
||||
Json::Value const& clients_data) {
|
||||
auto workspaceName = workspace_data["name"].asString();
|
||||
auto workspaceId = workspace_data["id"].asInt();
|
||||
spdlog::debug("Creating workspace {}", workspaceName);
|
||||
|
||||
// avoid recreating existing workspaces
|
||||
auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace> const &w) {
|
||||
auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace> const& w) {
|
||||
if (workspaceId > 0) {
|
||||
return w->id() == workspaceId;
|
||||
}
|
||||
@ -81,7 +81,7 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data,
|
||||
// don't recreate workspace, but update persistency if necessary
|
||||
const auto keys = workspace_data.getMemberNames();
|
||||
|
||||
const auto *k = "persistent-rule";
|
||||
const auto* k = "persistent-rule";
|
||||
if (std::ranges::find(keys, k) != keys.end()) {
|
||||
spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName,
|
||||
workspace_data[k].asBool() ? "true" : "false");
|
||||
@ -100,14 +100,14 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data,
|
||||
|
||||
// create new workspace
|
||||
m_workspaces.emplace_back(std::make_unique<Workspace>(workspace_data, *this, clients_data));
|
||||
Gtk::Button &newWorkspaceButton = m_workspaces.back()->button();
|
||||
Gtk::Button& newWorkspaceButton = m_workspaces.back()->button();
|
||||
m_box.pack_start(newWorkspaceButton, false, false);
|
||||
sortWorkspaces();
|
||||
newWorkspaceButton.show_all();
|
||||
}
|
||||
|
||||
void Workspaces::createWorkspacesToCreate() {
|
||||
for (const auto &[workspaceData, clientsData] : m_workspacesToCreate) {
|
||||
for (const auto& [workspaceData, clientsData] : m_workspacesToCreate) {
|
||||
createWorkspace(workspaceData, clientsData);
|
||||
}
|
||||
if (!m_workspacesToCreate.empty()) {
|
||||
@ -139,9 +139,9 @@ void Workspaces::doUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::extendOrphans(int workspaceId, Json::Value const &clientsJson) {
|
||||
void Workspaces::extendOrphans(int workspaceId, Json::Value const& clientsJson) {
|
||||
spdlog::trace("Extending orphans with workspace {}", workspaceId);
|
||||
for (const auto &client : clientsJson) {
|
||||
for (const auto& client : clientsJson) {
|
||||
if (client["workspace"]["id"].asInt() == workspaceId) {
|
||||
registerOrphanWindow({client});
|
||||
}
|
||||
@ -163,7 +163,7 @@ std::string Workspaces::getRewrite(std::string window_class, std::string window_
|
||||
std::vector<int> Workspaces::getVisibleWorkspaces() {
|
||||
std::vector<int> visibleWorkspaces;
|
||||
auto monitors = IPC::inst().getSocket1JsonReply("monitors");
|
||||
for (const auto &monitor : monitors) {
|
||||
for (const auto& monitor : monitors) {
|
||||
auto ws = monitor["activeWorkspace"];
|
||||
if (ws.isObject() && ws["id"].isInt()) {
|
||||
visibleWorkspaces.push_back(ws["id"].asInt());
|
||||
@ -181,7 +181,7 @@ void Workspaces::initializeWorkspaces() {
|
||||
spdlog::debug("Initializing workspaces");
|
||||
|
||||
// if the workspace rules changed since last initialization, make sure we reset everything:
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
m_workspacesToRemove.push_back(std::to_string(workspace->id()));
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ void Workspaces::initializeWorkspaces() {
|
||||
loadPersistentWorkspacesFromWorkspaceRules(clientsJson);
|
||||
}
|
||||
|
||||
bool isDoubleSpecial(std::string const &workspace_name) {
|
||||
bool isDoubleSpecial(std::string const& workspace_name) {
|
||||
// Hyprland's IPC sometimes reports the creation of workspaces strangely named
|
||||
// `special:special:<some_name>`. This function checks for that and is used
|
||||
// to avoid creating (and then removing) such workspaces.
|
||||
@ -217,8 +217,8 @@ bool isDoubleSpecial(std::string const &workspace_name) {
|
||||
return workspace_name.find("special:special:") != std::string::npos;
|
||||
}
|
||||
|
||||
bool Workspaces::isWorkspaceIgnored(std::string const &name) {
|
||||
for (auto &rule : m_ignoreWorkspaces) {
|
||||
bool Workspaces::isWorkspaceIgnored(std::string const& name) {
|
||||
for (auto& rule : m_ignoreWorkspaces) {
|
||||
if (std::regex_match(name, rule)) {
|
||||
return true;
|
||||
break;
|
||||
@ -228,19 +228,19 @@ bool Workspaces::isWorkspaceIgnored(std::string const &name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJson) {
|
||||
void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson) {
|
||||
spdlog::info("Loading persistent workspaces from Waybar config");
|
||||
const std::vector<std::string> keys = m_persistentWorkspaceConfig.getMemberNames();
|
||||
std::vector<std::string> persistentWorkspacesToCreate;
|
||||
|
||||
const std::string currentMonitor = m_bar.output->name;
|
||||
const bool monitorInConfig = std::ranges::find(keys, currentMonitor) != keys.end();
|
||||
for (const std::string &key : keys) {
|
||||
for (const std::string& key : keys) {
|
||||
// only add if either:
|
||||
// 1. key is the current monitor name
|
||||
// 2. key is "*" and this monitor is not already defined in the config
|
||||
bool canCreate = key == currentMonitor || (key == "*" && !monitorInConfig);
|
||||
const Json::Value &value = m_persistentWorkspaceConfig[key];
|
||||
const Json::Value& value = m_persistentWorkspaceConfig[key];
|
||||
spdlog::trace("Parsing persistent workspace config: {} => {}", key, value.toStyledString());
|
||||
|
||||
if (value.isInt()) {
|
||||
@ -255,13 +255,13 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs
|
||||
} else if (value.isArray() && !value.empty()) {
|
||||
// value is an array => create defined workspaces for this monitor
|
||||
if (canCreate) {
|
||||
for (const Json::Value &workspace : value) {
|
||||
for (const Json::Value& workspace : value) {
|
||||
spdlog::debug("Creating workspace {} on monitor {}", workspace, currentMonitor);
|
||||
persistentWorkspacesToCreate.emplace_back(workspace.asString());
|
||||
}
|
||||
} else {
|
||||
// key is the workspace and value is array of monitors to create on
|
||||
for (const Json::Value &monitor : value) {
|
||||
for (const Json::Value& monitor : value) {
|
||||
if (monitor.isString() && monitor.asString() == currentMonitor) {
|
||||
persistentWorkspacesToCreate.emplace_back(currentMonitor);
|
||||
break;
|
||||
@ -274,18 +274,18 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const &workspace : persistentWorkspacesToCreate) {
|
||||
for (auto const& workspace : persistentWorkspacesToCreate) {
|
||||
auto workspaceData = createMonitorWorkspaceData(workspace, m_bar.output->name);
|
||||
workspaceData["persistent-config"] = true;
|
||||
m_workspacesToCreate.emplace_back(workspaceData, clientsJson);
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &clientsJson) {
|
||||
void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson) {
|
||||
spdlog::info("Loading persistent workspaces from Hyprland workspace rules");
|
||||
|
||||
auto const workspaceRules = m_ipc.getSocket1JsonReply("workspacerules");
|
||||
for (Json::Value const &rule : workspaceRules) {
|
||||
for (Json::Value const& rule : workspaceRules) {
|
||||
if (!rule["workspaceString"].isString()) {
|
||||
spdlog::warn("Workspace rules: invalid workspaceString, skipping: {}", rule);
|
||||
continue;
|
||||
@ -305,7 +305,7 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &c
|
||||
if (workspace.starts_with("name:")) {
|
||||
workspace = workspace.substr(5);
|
||||
}
|
||||
auto const &monitor = rule["monitor"].asString();
|
||||
auto const& monitor = rule["monitor"].asString();
|
||||
// create this workspace persistently if:
|
||||
// 1. the allOutputs config option is enabled
|
||||
// 2. the rule's monitor is the current monitor
|
||||
@ -322,7 +322,7 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &c
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onEvent(const std::string &ev) {
|
||||
void Workspaces::onEvent(const std::string& ev) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>'));
|
||||
std::string payload = ev.substr(eventName.size() + 2);
|
||||
@ -360,7 +360,7 @@ void Workspaces::onEvent(const std::string &ev) {
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
void Workspaces::onWorkspaceActivated(std::string const &payload) {
|
||||
void Workspaces::onWorkspaceActivated(std::string const& payload) {
|
||||
const auto [workspaceIdStr, workspaceName] = splitDoublePayload(payload);
|
||||
const auto workspaceId = parseWorkspaceId(workspaceIdStr);
|
||||
if (workspaceId.has_value()) {
|
||||
@ -368,19 +368,19 @@ void Workspaces::onWorkspaceActivated(std::string const &payload) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onSpecialWorkspaceActivated(std::string const &payload) {
|
||||
void Workspaces::onSpecialWorkspaceActivated(std::string const& payload) {
|
||||
std::string name(begin(payload), begin(payload) + payload.find_first_of(','));
|
||||
m_activeSpecialWorkspaceName = (!name.starts_with("special:") ? name : name.substr(8));
|
||||
}
|
||||
|
||||
void Workspaces::onWorkspaceDestroyed(std::string const &payload) {
|
||||
void Workspaces::onWorkspaceDestroyed(std::string const& payload) {
|
||||
const auto [workspaceId, workspaceName] = splitDoublePayload(payload);
|
||||
if (!isDoubleSpecial(workspaceName)) {
|
||||
m_workspacesToRemove.push_back(workspaceId);
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onWorkspaceCreated(std::string const &payload, Json::Value const &clientsData) {
|
||||
void Workspaces::onWorkspaceCreated(std::string const& payload, Json::Value const& clientsData) {
|
||||
spdlog::debug("Workspace created: {}", payload);
|
||||
|
||||
const auto [workspaceIdStr, _] = splitDoublePayload(payload);
|
||||
@ -407,7 +407,7 @@ void Workspaces::onWorkspaceCreated(std::string const &payload, Json::Value cons
|
||||
if ((allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) &&
|
||||
(showSpecial() || !workspaceName.starts_with("special")) &&
|
||||
!isDoubleSpecial(workspaceName)) {
|
||||
for (Json::Value const &rule : workspaceRules) {
|
||||
for (Json::Value const& rule : workspaceRules) {
|
||||
auto ruleWorkspaceName = rule.isMember("defaultName")
|
||||
? rule["defaultName"].asString()
|
||||
: rule["workspaceString"].asString();
|
||||
@ -426,7 +426,7 @@ void Workspaces::onWorkspaceCreated(std::string const &payload, Json::Value cons
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onWorkspaceMoved(std::string const &payload) {
|
||||
void Workspaces::onWorkspaceMoved(std::string const& payload) {
|
||||
spdlog::debug("Workspace moved: {}", payload);
|
||||
|
||||
// Update active workspace
|
||||
@ -447,7 +447,7 @@ void Workspaces::onWorkspaceMoved(std::string const &payload) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onWorkspaceRenamed(std::string const &payload) {
|
||||
void Workspaces::onWorkspaceRenamed(std::string const& payload) {
|
||||
spdlog::debug("Workspace renamed: {}", payload);
|
||||
const auto [workspaceIdStr, newName] = splitDoublePayload(payload);
|
||||
|
||||
@ -456,7 +456,7 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
if (workspace->id() == *workspaceId) {
|
||||
workspace->setName(newName);
|
||||
break;
|
||||
@ -465,7 +465,7 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) {
|
||||
sortWorkspaces();
|
||||
}
|
||||
|
||||
void Workspaces::onMonitorFocused(std::string const &payload) {
|
||||
void Workspaces::onMonitorFocused(std::string const& payload) {
|
||||
spdlog::trace("Monitor focused: {}", payload);
|
||||
|
||||
const auto [monitorName, workspaceIdStr] = splitDoublePayload(payload);
|
||||
@ -477,7 +477,7 @@ void Workspaces::onMonitorFocused(std::string const &payload) {
|
||||
|
||||
m_activeWorkspaceId = *workspaceId;
|
||||
|
||||
for (Json::Value &monitor : m_ipc.getSocket1JsonReply("monitors")) {
|
||||
for (Json::Value& monitor : m_ipc.getSocket1JsonReply("monitors")) {
|
||||
if (monitor["name"].asString() == monitorName) {
|
||||
const auto name = monitor["specialWorkspace"]["name"].asString();
|
||||
m_activeSpecialWorkspaceName = !name.starts_with("special:") ? name : name.substr(8);
|
||||
@ -485,7 +485,7 @@ void Workspaces::onMonitorFocused(std::string const &payload) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onWindowOpened(std::string const &payload) {
|
||||
void Workspaces::onWindowOpened(std::string const& payload) {
|
||||
spdlog::trace("Window opened: {}", payload);
|
||||
updateWindowCount();
|
||||
size_t lastCommaIdx = 0;
|
||||
@ -506,18 +506,18 @@ void Workspaces::onWindowOpened(std::string const &payload) {
|
||||
m_windowsToCreate.emplace_back(workspaceName, windowAddress, windowClass, windowTitle, isActive);
|
||||
}
|
||||
|
||||
void Workspaces::onWindowClosed(std::string const &addr) {
|
||||
void Workspaces::onWindowClosed(std::string const& addr) {
|
||||
spdlog::trace("Window closed: {}", addr);
|
||||
updateWindowCount();
|
||||
m_orphanWindowMap.erase(addr);
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
if (workspace->closeWindow(addr)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onWindowMoved(std::string const &payload) {
|
||||
void Workspaces::onWindowMoved(std::string const& payload) {
|
||||
spdlog::trace("Window moved: {}", payload);
|
||||
updateWindowCount();
|
||||
auto [windowAddress, _, workspaceName] = splitTriplePayload(payload);
|
||||
@ -526,7 +526,7 @@ void Workspaces::onWindowMoved(std::string const &payload) {
|
||||
|
||||
// If the window was still queued to be created, just change its destination
|
||||
// and exit
|
||||
for (auto &window : m_windowsToCreate) {
|
||||
for (auto& window : m_windowsToCreate) {
|
||||
if (window.getAddress() == windowAddress) {
|
||||
window.moveToWorkspace(workspaceName);
|
||||
return;
|
||||
@ -534,7 +534,7 @@ void Workspaces::onWindowMoved(std::string const &payload) {
|
||||
}
|
||||
|
||||
// Take the window's representation from the old workspace...
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
if (auto windowAddr = workspace->closeWindow(windowAddress); windowAddr != std::nullopt) {
|
||||
windowRepr = windowAddr.value();
|
||||
break;
|
||||
@ -553,7 +553,7 @@ void Workspaces::onWindowMoved(std::string const &payload) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
void Workspaces::onWindowTitleEvent(std::string const& payload) {
|
||||
spdlog::trace("Window title changed: {}", payload);
|
||||
std::optional<std::function<void(WindowCreationPayload)>> inserter;
|
||||
|
||||
@ -563,7 +563,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
if (m_orphanWindowMap.contains(windowAddress)) {
|
||||
inserter = [this](WindowCreationPayload wcp) { this->registerOrphanWindow(std::move(wcp)); };
|
||||
} else {
|
||||
auto windowWorkspace = std::ranges::find_if(m_workspaces, [windowAddress](auto &workspace) {
|
||||
auto windowWorkspace = std::ranges::find_if(m_workspaces, [windowAddress](auto& workspace) {
|
||||
return workspace->containsWindow(windowAddress);
|
||||
});
|
||||
|
||||
@ -575,7 +575,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
};
|
||||
} else {
|
||||
auto queuedWindow =
|
||||
std::ranges::find_if(m_windowsToCreate, [&windowAddress](auto &windowPayload) {
|
||||
std::ranges::find_if(m_windowsToCreate, [&windowAddress](auto& windowPayload) {
|
||||
return windowPayload.getAddress() == windowAddress;
|
||||
});
|
||||
|
||||
@ -590,7 +590,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
Json::Value clientsData = m_ipc.getSocket1JsonReply("clients");
|
||||
std::string jsonWindowAddress = fmt::format("0x{}", windowAddress);
|
||||
|
||||
auto client = std::ranges::find_if(clientsData, [jsonWindowAddress](auto &client) {
|
||||
auto client = std::ranges::find_if(clientsData, [jsonWindowAddress](auto& client) {
|
||||
return client["address"].asString() == jsonWindowAddress;
|
||||
});
|
||||
|
||||
@ -600,17 +600,17 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onActiveWindowChanged(WindowAddress const &activeWindowAddress) {
|
||||
void Workspaces::onActiveWindowChanged(WindowAddress const& activeWindowAddress) {
|
||||
spdlog::trace("Active window changed: {}", activeWindowAddress);
|
||||
m_currentActiveWindowAddress = activeWindowAddress;
|
||||
|
||||
for (auto &[address, window] : m_orphanWindowMap) {
|
||||
for (auto& [address, window] : m_orphanWindowMap) {
|
||||
window.setActive(address == activeWindowAddress);
|
||||
}
|
||||
for (auto const &workspace : m_workspaces) {
|
||||
for (auto const& workspace : m_workspaces) {
|
||||
workspace->setActiveWindow(activeWindowAddress);
|
||||
}
|
||||
for (auto &window : m_windowsToCreate) {
|
||||
for (auto& window : m_windowsToCreate) {
|
||||
window.setActive(window.getAddress() == activeWindowAddress);
|
||||
}
|
||||
}
|
||||
@ -620,8 +620,8 @@ void Workspaces::onConfigReloaded() {
|
||||
init();
|
||||
}
|
||||
|
||||
auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||
const auto &configFormat = config["format"];
|
||||
auto Workspaces::parseConfig(const Json::Value& config) -> void {
|
||||
const auto& configFormat = config["format"];
|
||||
m_formatBefore = configFormat.isString() ? configFormat.asString() : "{name}";
|
||||
m_withIcon = m_formatBefore.find("{icon}") != std::string::npos;
|
||||
auto withWindows = m_formatBefore.find("{windows}") != std::string::npos;
|
||||
@ -653,28 +653,28 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto Workspaces::populateIconsMap(const Json::Value &formatIcons) -> void {
|
||||
for (const auto &name : formatIcons.getMemberNames()) {
|
||||
auto Workspaces::populateIconsMap(const Json::Value& formatIcons) -> void {
|
||||
for (const auto& name : formatIcons.getMemberNames()) {
|
||||
m_iconsMap.emplace(name, formatIcons[name].asString());
|
||||
}
|
||||
m_iconsMap.emplace("", "");
|
||||
}
|
||||
|
||||
auto Workspaces::populateBoolConfig(const Json::Value &config, const std::string &key, bool &member)
|
||||
auto Workspaces::populateBoolConfig(const Json::Value& config, const std::string& key, bool& member)
|
||||
-> void {
|
||||
const auto &configValue = config[key];
|
||||
const auto& configValue = config[key];
|
||||
if (configValue.isBool()) {
|
||||
member = configValue.asBool();
|
||||
}
|
||||
}
|
||||
|
||||
auto Workspaces::populateSortByConfig(const Json::Value &config) -> void {
|
||||
const auto &configSortBy = config["sort-by"];
|
||||
auto Workspaces::populateSortByConfig(const Json::Value& config) -> void {
|
||||
const auto& configSortBy = config["sort-by"];
|
||||
if (configSortBy.isString()) {
|
||||
auto sortByStr = configSortBy.asString();
|
||||
try {
|
||||
m_sortBy = m_enumParser.parseStringToEnum(sortByStr, m_sortMap);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
} catch (const std::invalid_argument& e) {
|
||||
m_sortBy = SortMethod::DEFAULT;
|
||||
spdlog::warn(
|
||||
"Invalid string representation for sort-by. Falling back to default sort method.");
|
||||
@ -682,16 +682,16 @@ auto Workspaces::populateSortByConfig(const Json::Value &config) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> void {
|
||||
auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value& config) -> void {
|
||||
auto ignoreWorkspaces = config["ignore-workspaces"];
|
||||
if (ignoreWorkspaces.isArray()) {
|
||||
for (const auto &workspaceRegex : ignoreWorkspaces) {
|
||||
for (const auto& workspaceRegex : ignoreWorkspaces) {
|
||||
if (workspaceRegex.isString()) {
|
||||
std::string ruleString = workspaceRegex.asString();
|
||||
try {
|
||||
const std::regex rule{ruleString, std::regex_constants::icase};
|
||||
m_ignoreWorkspaces.emplace_back(rule);
|
||||
} catch (const std::regex_error &e) {
|
||||
} catch (const std::regex_error& e) {
|
||||
spdlog::error("Invalid rule {}: {}", ruleString, e.what());
|
||||
}
|
||||
} else {
|
||||
@ -701,30 +701,30 @@ auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> vo
|
||||
}
|
||||
}
|
||||
|
||||
auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value &config) -> void {
|
||||
const auto &formatWindowSeparator = config["format-window-separator"];
|
||||
auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value& config) -> void {
|
||||
const auto& formatWindowSeparator = config["format-window-separator"];
|
||||
m_formatWindowSeparator =
|
||||
formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " ";
|
||||
}
|
||||
|
||||
auto Workspaces::populateWindowRewriteConfig(const Json::Value &config) -> void {
|
||||
const auto &windowRewrite = config["window-rewrite"];
|
||||
auto Workspaces::populateWindowRewriteConfig(const Json::Value& config) -> void {
|
||||
const auto& windowRewrite = config["window-rewrite"];
|
||||
if (!windowRewrite.isObject()) {
|
||||
spdlog::debug("window-rewrite is not defined or is not an object, using default rules.");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &windowRewriteDefaultConfig = config["window-rewrite-default"];
|
||||
const auto& windowRewriteDefaultConfig = config["window-rewrite-default"];
|
||||
std::string windowRewriteDefault =
|
||||
windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
|
||||
|
||||
m_windowRewriteRules = util::RegexCollection(
|
||||
windowRewrite, windowRewriteDefault,
|
||||
[this](std::string &window_rule) { return windowRewritePriorityFunction(window_rule); });
|
||||
[this](std::string& window_rule) { return windowRewritePriorityFunction(window_rule); });
|
||||
}
|
||||
|
||||
auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> void {
|
||||
const auto &workspaceTaskbar = config["workspace-taskbar"];
|
||||
auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value& config) -> void {
|
||||
const auto& workspaceTaskbar = config["workspace-taskbar"];
|
||||
if (!workspaceTaskbar.isObject()) {
|
||||
spdlog::debug("workspace-taskbar is not defined or is not an object, using default rules.");
|
||||
return;
|
||||
@ -751,7 +751,7 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
||||
|
||||
auto iconTheme = workspaceTaskbar["icon-theme"];
|
||||
if (iconTheme.isArray()) {
|
||||
for (auto &c : iconTheme) {
|
||||
for (auto& c : iconTheme) {
|
||||
m_iconLoader.add_custom_icon_theme(c.asString());
|
||||
}
|
||||
} else if (iconTheme.isString()) {
|
||||
@ -771,11 +771,11 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
||||
}
|
||||
|
||||
if (workspaceTaskbar["ignore-list"].isArray()) {
|
||||
for (auto &windowRegex : workspaceTaskbar["ignore-list"]) {
|
||||
for (auto& windowRegex : workspaceTaskbar["ignore-list"]) {
|
||||
std::string ruleString = windowRegex.asString();
|
||||
try {
|
||||
m_ignoreWindows.emplace_back(ruleString, std::regex_constants::icase);
|
||||
} catch (const std::regex_error &e) {
|
||||
} catch (const std::regex_error& e) {
|
||||
spdlog::error("Invalid rule {}: {}", ruleString, e.what());
|
||||
}
|
||||
}
|
||||
@ -786,7 +786,7 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo
|
||||
try {
|
||||
m_activeWindowPosition =
|
||||
m_activeWindowEnumParser.parseStringToEnum(posStr, m_activeWindowPositionMap);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
} catch (const std::invalid_argument& e) {
|
||||
spdlog::warn(
|
||||
"Invalid string representation for active-window-position. Falling back to 'none'.");
|
||||
m_activeWindowPosition = ActiveWindowPosition::NONE;
|
||||
@ -829,13 +829,13 @@ auto Workspaces::registerIpc() -> void {
|
||||
}
|
||||
|
||||
void Workspaces::removeWorkspacesToRemove() {
|
||||
for (const auto &workspaceString : m_workspacesToRemove) {
|
||||
for (const auto& workspaceString : m_workspacesToRemove) {
|
||||
removeWorkspace(workspaceString);
|
||||
}
|
||||
m_workspacesToRemove.clear();
|
||||
}
|
||||
|
||||
void Workspaces::removeWorkspace(std::string const &workspaceString) {
|
||||
void Workspaces::removeWorkspace(std::string const& workspaceString) {
|
||||
spdlog::debug("Removing workspace {}", workspaceString);
|
||||
|
||||
// If this succeeds, we have a workspace ID.
|
||||
@ -853,7 +853,7 @@ void Workspaces::removeWorkspace(std::string const &workspaceString) {
|
||||
name = workspaceString;
|
||||
}
|
||||
|
||||
const auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace> &x) {
|
||||
const auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr<Workspace>& x) {
|
||||
if (workspaceId.has_value()) {
|
||||
return *workspaceId == x->id();
|
||||
}
|
||||
@ -879,7 +879,7 @@ void Workspaces::setCurrentMonitorId() {
|
||||
// get monitor ID from name (used by persistent workspaces)
|
||||
m_monitorId = 0;
|
||||
auto monitors = m_ipc.getSocket1JsonReply("monitors");
|
||||
auto currentMonitor = std::ranges::find_if(monitors, [this](const Json::Value &m) {
|
||||
auto currentMonitor = std::ranges::find_if(monitors, [this](const Json::Value& m) {
|
||||
return m["name"].asString() == m_bar.output->name;
|
||||
});
|
||||
if (currentMonitor == monitors.end()) {
|
||||
@ -895,7 +895,7 @@ void Workspaces::sortSpecialCentered() {
|
||||
std::vector<std::unique_ptr<Workspace>> hiddenWorkspaces;
|
||||
std::vector<std::unique_ptr<Workspace>> normalWorkspaces;
|
||||
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
if (workspace->isSpecial()) {
|
||||
specialWorkspaces.push_back(std::move(workspace));
|
||||
} else {
|
||||
@ -926,7 +926,7 @@ void Workspaces::sortSpecialCentered() {
|
||||
|
||||
void Workspaces::sortWorkspaces() {
|
||||
std::ranges::sort( //
|
||||
m_workspaces, [&](std::unique_ptr<Workspace> &a, std::unique_ptr<Workspace> &b) {
|
||||
m_workspaces, [&](std::unique_ptr<Workspace>& a, std::unique_ptr<Workspace>& b) {
|
||||
// Helper comparisons
|
||||
auto isIdLess = a->id() < b->id();
|
||||
auto isNameLess = a->name() < b->name();
|
||||
@ -939,7 +939,7 @@ void Workspaces::sortWorkspaces() {
|
||||
case SortMethod::NUMBER:
|
||||
try {
|
||||
return std::stoi(a->name()) < std::stoi(b->name());
|
||||
} catch (const std::invalid_argument &) {
|
||||
} catch (const std::invalid_argument&) {
|
||||
// Handle the exception if necessary.
|
||||
break;
|
||||
}
|
||||
@ -991,7 +991,7 @@ void Workspaces::sortWorkspaces() {
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::setUrgentWorkspace(std::string const &windowaddress) {
|
||||
void Workspaces::setUrgentWorkspace(std::string const& windowaddress) {
|
||||
const Json::Value clientsJson = m_ipc.getSocket1JsonReply("clients");
|
||||
int workspaceId = -1;
|
||||
|
||||
@ -1002,7 +1002,7 @@ void Workspaces::setUrgentWorkspace(std::string const &windowaddress) {
|
||||
}
|
||||
}
|
||||
|
||||
auto workspace = std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr<Workspace> &x) {
|
||||
auto workspace = std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr<Workspace>& x) {
|
||||
return x->id() == workspaceId;
|
||||
});
|
||||
if (workspace != m_workspaces.end()) {
|
||||
@ -1017,8 +1017,8 @@ auto Workspaces::update() -> void {
|
||||
|
||||
void Workspaces::updateWindowCount() {
|
||||
const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces");
|
||||
for (auto const &workspace : m_workspaces) {
|
||||
auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) {
|
||||
for (auto const& workspace : m_workspaces) {
|
||||
auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const& x) {
|
||||
return x["name"].asString() == workspace->name() ||
|
||||
(workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name());
|
||||
});
|
||||
@ -1026,7 +1026,7 @@ void Workspaces::updateWindowCount() {
|
||||
if (workspaceJson != workspacesJson.end()) {
|
||||
try {
|
||||
count = (*workspaceJson)["windows"].asUInt();
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Failed to update window count: {}", e.what());
|
||||
}
|
||||
}
|
||||
@ -1037,9 +1037,9 @@ void Workspaces::updateWindowCount() {
|
||||
bool Workspaces::updateWindowsToCreate() {
|
||||
bool anyWindowCreated = false;
|
||||
std::vector<WindowCreationPayload> notCreated;
|
||||
for (auto &windowPayload : m_windowsToCreate) {
|
||||
for (auto& windowPayload : m_windowsToCreate) {
|
||||
bool created = false;
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
if (workspace->onWindowOpened(windowPayload)) {
|
||||
created = true;
|
||||
anyWindowCreated = true;
|
||||
@ -1068,7 +1068,7 @@ void Workspaces::updateWorkspaceStates() {
|
||||
std::string currentWorkspaceName =
|
||||
currentWorkspace.isMember("name") ? currentWorkspace["name"].asString() : "";
|
||||
|
||||
for (auto &workspace : m_workspaces) {
|
||||
for (auto& workspace : m_workspaces) {
|
||||
bool isActiveByName =
|
||||
!currentWorkspaceName.empty() && workspace->name() == currentWorkspaceName;
|
||||
|
||||
@ -1080,11 +1080,11 @@ void Workspaces::updateWorkspaceStates() {
|
||||
}
|
||||
workspace->setVisible(std::ranges::find(visibleWorkspaces, workspace->id()) !=
|
||||
visibleWorkspaces.end());
|
||||
std::string &workspaceIcon = m_iconsMap[""];
|
||||
std::string& workspaceIcon = m_iconsMap[""];
|
||||
if (m_withIcon) {
|
||||
workspaceIcon = workspace->selectIcon(m_iconsMap);
|
||||
}
|
||||
auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto &w) {
|
||||
auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto& w) {
|
||||
auto wNameRaw = w["name"].asString();
|
||||
auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw;
|
||||
return wName == workspace->name();
|
||||
@ -1096,7 +1096,7 @@ void Workspaces::updateWorkspaceStates() {
|
||||
}
|
||||
}
|
||||
|
||||
int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
|
||||
int Workspaces::windowRewritePriorityFunction(std::string const& window_rule) {
|
||||
// Rules that match against title are prioritized
|
||||
// Rules that don't specify if they're matching against either title or class are deprioritized
|
||||
bool const hasTitle = window_rule.find("title") != std::string::npos;
|
||||
@ -1117,21 +1117,21 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
std::string Workspaces::makePayload(Args const &...args) {
|
||||
std::string Workspaces::makePayload(Args const&... args) {
|
||||
std::ostringstream result;
|
||||
bool first = true;
|
||||
((result << (first ? "" : ",") << args, first = false), ...);
|
||||
return result.str();
|
||||
}
|
||||
|
||||
std::pair<std::string, std::string> Workspaces::splitDoublePayload(std::string const &payload) {
|
||||
std::pair<std::string, std::string> Workspaces::splitDoublePayload(std::string const& payload) {
|
||||
const std::string part1 = payload.substr(0, payload.find(','));
|
||||
const std::string part2 = payload.substr(part1.size() + 1);
|
||||
return {part1, part2};
|
||||
}
|
||||
|
||||
std::tuple<std::string, std::string, std::string> Workspaces::splitTriplePayload(
|
||||
std::string const &payload) {
|
||||
std::string const& payload) {
|
||||
const size_t firstComma = payload.find(',');
|
||||
const size_t secondComma = payload.find(',', firstComma + 1);
|
||||
|
||||
@ -1142,10 +1142,10 @@ std::tuple<std::string, std::string, std::string> Workspaces::splitTriplePayload
|
||||
return {part1, part2, part3};
|
||||
}
|
||||
|
||||
std::optional<int> Workspaces::parseWorkspaceId(std::string const &workspaceIdStr) {
|
||||
std::optional<int> Workspaces::parseWorkspaceId(std::string const& workspaceIdStr) {
|
||||
try {
|
||||
return workspaceIdStr == "special" ? -99 : std::stoi(workspaceIdStr);
|
||||
} catch (std::exception const &e) {
|
||||
} catch (std::exception const& e) {
|
||||
spdlog::debug("Workspace \"{}\" is not bound to an id: {}", workspaceIdStr, e.what());
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
JACK::JACK(const std::string &id, const Json::Value &config)
|
||||
JACK::JACK(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "jack", id, "{load}%", 1) {
|
||||
running_ = false;
|
||||
client_ = NULL;
|
||||
@ -113,14 +113,14 @@ void JACK::shutdown() {
|
||||
|
||||
} // namespace waybar::modules
|
||||
|
||||
int bufSizeCallback(jack_nframes_t size, void *obj) {
|
||||
return static_cast<waybar::modules::JACK *>(obj)->bufSize(size);
|
||||
int bufSizeCallback(jack_nframes_t size, void* obj) {
|
||||
return static_cast<waybar::modules::JACK*>(obj)->bufSize(size);
|
||||
}
|
||||
|
||||
int sampleRateCallback(jack_nframes_t rate, void *obj) {
|
||||
return static_cast<waybar::modules::JACK *>(obj)->sampleRate(rate);
|
||||
int sampleRateCallback(jack_nframes_t rate, void* obj) {
|
||||
return static_cast<waybar::modules::JACK*>(obj)->sampleRate(rate);
|
||||
}
|
||||
|
||||
int xrunCallback(void *obj) { return static_cast<waybar::modules::JACK *>(obj)->xrun(); }
|
||||
int xrunCallback(void* obj) { return static_cast<waybar::modules::JACK*>(obj)->xrun(); }
|
||||
|
||||
void shutdownCallback(void *obj) { return static_cast<waybar::modules::JACK *>(obj)->shutdown(); }
|
||||
void shutdownCallback(void* obj) { return static_cast<waybar::modules::JACK*>(obj)->shutdown(); }
|
||||
|
||||
@ -21,10 +21,10 @@
|
||||
|
||||
namespace {
|
||||
using namespace waybar::util;
|
||||
constexpr const char *DEFAULT_FORMAT = "{ifname}";
|
||||
constexpr const char* DEFAULT_FORMAT = "{ifname}";
|
||||
} // namespace
|
||||
|
||||
constexpr const char *NETDEV_FILE =
|
||||
constexpr const char* NETDEV_FILE =
|
||||
"/proc/net/dev"; // std::ifstream does not take std::string_view as param
|
||||
std::optional<std::pair<unsigned long long, unsigned long long>>
|
||||
waybar::modules::Network::readBandwidthUsage() {
|
||||
@ -82,7 +82,7 @@ waybar::modules::Network::readBandwidthUsage() {
|
||||
return {{receivedBytes, transmittedBytes}};
|
||||
}
|
||||
|
||||
waybar::modules::Network::Network(const std::string &id, const Json::Value &config)
|
||||
waybar::modules::Network::Network(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "network", id, DEFAULT_FORMAT, 60) {
|
||||
// Start with some "text" in the module's label_. update() will then
|
||||
// update it. Since the text should be different, update() will be able
|
||||
@ -216,7 +216,7 @@ void waybar::modules::Network::worker() {
|
||||
thread_timer_.sleep_for(interval_);
|
||||
};
|
||||
#ifdef WANT_RFKILL
|
||||
rfkill_.on_update.connect([this](auto &) {
|
||||
rfkill_.on_update.connect([this](auto&) {
|
||||
/* If we are here, it's likely that the network thread already holds the mutex and will be
|
||||
* holding it for a next few seconds.
|
||||
* Let's delegate the update to the timer thread instead of blocking the main thread.
|
||||
@ -397,7 +397,7 @@ auto waybar::modules::Network::update() -> void {
|
||||
}
|
||||
|
||||
// https://gist.github.com/rressi/92af77630faf055934c723ce93ae2495
|
||||
static bool wildcardMatch(const std::string &pattern, const std::string &text) {
|
||||
static bool wildcardMatch(const std::string& pattern, const std::string& text) {
|
||||
auto P = int(pattern.size());
|
||||
auto T = int(text.size());
|
||||
|
||||
@ -435,9 +435,9 @@ static bool wildcardMatch(const std::string &pattern, const std::string &text) {
|
||||
return p == P;
|
||||
}
|
||||
|
||||
bool waybar::modules::Network::matchInterface(const std::string &ifname,
|
||||
const std::vector<std::string> &altnames,
|
||||
std::string &matched) const {
|
||||
bool waybar::modules::Network::matchInterface(const std::string& ifname,
|
||||
const std::vector<std::string>& altnames,
|
||||
std::string& matched) const {
|
||||
if (!config_["interface"].isString()) {
|
||||
return false;
|
||||
}
|
||||
@ -448,7 +448,7 @@ bool waybar::modules::Network::matchInterface(const std::string &ifname,
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const auto &altname : altnames) {
|
||||
for (const auto& altname : altnames) {
|
||||
if (config_ifname == altname || wildcardMatch(config_ifname, altname)) {
|
||||
matched = altname;
|
||||
return true;
|
||||
@ -478,8 +478,8 @@ void waybar::modules::Network::clearIface() {
|
||||
frequency_ = 0.0;
|
||||
}
|
||||
|
||||
int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
auto net = static_cast<waybar::modules::Network *>(data);
|
||||
int waybar::modules::Network::handleEvents(struct nl_msg* msg, void* data) {
|
||||
auto net = static_cast<waybar::modules::Network*>(data);
|
||||
std::lock_guard<std::mutex> lock(net->mutex_);
|
||||
auto nh = nlmsg_hdr(msg);
|
||||
bool is_del_event = false;
|
||||
@ -488,8 +488,8 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
case RTM_DELLINK:
|
||||
is_del_event = true;
|
||||
case RTM_NEWLINK: {
|
||||
struct ifinfomsg *ifi = static_cast<struct ifinfomsg *>(NLMSG_DATA(nh));
|
||||
struct nlattr *attrs[IFLA_MAX + 1];
|
||||
struct ifinfomsg* ifi = static_cast<struct ifinfomsg*>(NLMSG_DATA(nh));
|
||||
struct nlattr* attrs[IFLA_MAX + 1];
|
||||
std::string ifname;
|
||||
std::vector<std::string> altnames;
|
||||
std::optional<bool> carrier;
|
||||
@ -517,7 +517,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
}
|
||||
|
||||
if (attrs[IFLA_IFNAME] != nullptr) {
|
||||
const char *ifname_ptr = nla_get_string(attrs[IFLA_IFNAME]);
|
||||
const char* ifname_ptr = nla_get_string(attrs[IFLA_IFNAME]);
|
||||
size_t ifname_len = nla_len(attrs[IFLA_IFNAME]) - 1; // minus \0
|
||||
ifname = std::string(ifname_ptr, ifname_len);
|
||||
}
|
||||
@ -527,12 +527,12 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
}
|
||||
|
||||
if (attrs[IFLA_PROP_LIST] != nullptr) {
|
||||
struct nlattr *prop;
|
||||
struct nlattr* prop;
|
||||
int rem;
|
||||
|
||||
nla_for_each_nested(prop, attrs[IFLA_PROP_LIST], rem) {
|
||||
if (nla_type(prop) == IFLA_ALT_IFNAME) {
|
||||
const char *altname_ptr = nla_get_string(prop);
|
||||
const char* altname_ptr = nla_get_string(prop);
|
||||
size_t altname_len = nla_len(prop) - 1; // minus \0
|
||||
altnames.emplace_back(altname_ptr, altname_len);
|
||||
}
|
||||
@ -605,9 +605,9 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
case RTM_DELADDR:
|
||||
is_del_event = true;
|
||||
case RTM_NEWADDR: {
|
||||
struct ifaddrmsg *ifa = static_cast<struct ifaddrmsg *>(NLMSG_DATA(nh));
|
||||
struct ifaddrmsg* ifa = static_cast<struct ifaddrmsg*>(NLMSG_DATA(nh));
|
||||
ssize_t attrlen = IFA_PAYLOAD(nh);
|
||||
struct rtattr *ifa_rta = IFA_RTA(ifa);
|
||||
struct rtattr* ifa_rta = IFA_RTA(ifa);
|
||||
|
||||
if ((int)ifa->ifa_index != net->ifid_) {
|
||||
return NL_OK;
|
||||
@ -681,10 +681,10 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
// Based on https://gist.github.com/Yawning/c70d804d4b8ae78cc698
|
||||
// to find the interface used to reach the outside world
|
||||
|
||||
struct rtmsg *rtm = static_cast<struct rtmsg *>(NLMSG_DATA(nh));
|
||||
struct rtmsg* rtm = static_cast<struct rtmsg*>(NLMSG_DATA(nh));
|
||||
int family = rtm->rtm_family;
|
||||
ssize_t attrlen = RTM_PAYLOAD(nh);
|
||||
struct rtattr *attr = RTM_RTA(rtm);
|
||||
struct rtattr* attr = RTM_RTA(rtm);
|
||||
char gateway_addr[INET6_ADDRSTRLEN];
|
||||
bool has_gateway = false;
|
||||
bool has_destination = false;
|
||||
@ -725,17 +725,17 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) {
|
||||
break;
|
||||
}
|
||||
for (uint32_t i = 0; i < dstlen; i += 1) {
|
||||
c |= *((unsigned char *)RTA_DATA(attr) + i);
|
||||
c |= *((unsigned char*)RTA_DATA(attr) + i);
|
||||
}
|
||||
has_destination = (c == 0);
|
||||
break;
|
||||
}
|
||||
case RTA_OIF:
|
||||
/* The output interface index. */
|
||||
temp_idx = *static_cast<int *>(RTA_DATA(attr));
|
||||
temp_idx = *static_cast<int*>(RTA_DATA(attr));
|
||||
break;
|
||||
case RTA_PRIORITY:
|
||||
priority = *(uint32_t *)RTA_DATA(attr);
|
||||
priority = *(uint32_t*)RTA_DATA(attr);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -826,18 +826,18 @@ void waybar::modules::Network::askForStateDump(void) {
|
||||
}
|
||||
}
|
||||
|
||||
int waybar::modules::Network::handleEventsDone(struct nl_msg *msg, void *data) {
|
||||
auto net = static_cast<waybar::modules::Network *>(data);
|
||||
int waybar::modules::Network::handleEventsDone(struct nl_msg* msg, void* data) {
|
||||
auto net = static_cast<waybar::modules::Network*>(data);
|
||||
net->dump_in_progress_ = false;
|
||||
net->askForStateDump();
|
||||
return NL_OK;
|
||||
}
|
||||
|
||||
int waybar::modules::Network::handleScan(struct nl_msg *msg, void *data) {
|
||||
auto net = static_cast<waybar::modules::Network *>(data);
|
||||
auto gnlh = static_cast<genlmsghdr *>(nlmsg_data(nlmsg_hdr(msg)));
|
||||
struct nlattr *tb[NL80211_ATTR_MAX + 1];
|
||||
struct nlattr *bss[NL80211_BSS_MAX + 1];
|
||||
int waybar::modules::Network::handleScan(struct nl_msg* msg, void* data) {
|
||||
auto net = static_cast<waybar::modules::Network*>(data);
|
||||
auto gnlh = static_cast<genlmsghdr*>(nlmsg_data(nlmsg_hdr(msg)));
|
||||
struct nlattr* tb[NL80211_ATTR_MAX + 1];
|
||||
struct nlattr* bss[NL80211_BSS_MAX + 1];
|
||||
struct nla_policy bss_policy[NL80211_BSS_MAX + 1]{};
|
||||
bss_policy[NL80211_BSS_TSF].type = NLA_U64;
|
||||
bss_policy[NL80211_BSS_FREQUENCY].type = NLA_U32;
|
||||
@ -869,9 +869,9 @@ int waybar::modules::Network::handleScan(struct nl_msg *msg, void *data) {
|
||||
return NL_OK;
|
||||
}
|
||||
|
||||
void waybar::modules::Network::parseEssid(struct nlattr **bss) {
|
||||
void waybar::modules::Network::parseEssid(struct nlattr** bss) {
|
||||
if (bss[NL80211_BSS_INFORMATION_ELEMENTS] != nullptr) {
|
||||
auto ies = static_cast<char *>(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]));
|
||||
auto ies = static_cast<char*>(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]));
|
||||
auto ies_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
|
||||
const auto hdr_len = 2;
|
||||
while (ies_len > hdr_len && ies[0] != 0) {
|
||||
@ -888,7 +888,7 @@ void waybar::modules::Network::parseEssid(struct nlattr **bss) {
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Network::parseSignal(struct nlattr **bss) {
|
||||
void waybar::modules::Network::parseSignal(struct nlattr** bss) {
|
||||
if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) {
|
||||
// signalstrength in dBm from mBm
|
||||
signal_strength_dbm_ = nla_get_s32(bss[NL80211_BSS_SIGNAL_MBM]) / 100;
|
||||
@ -924,16 +924,16 @@ void waybar::modules::Network::parseSignal(struct nlattr **bss) {
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Network::parseFreq(struct nlattr **bss) {
|
||||
void waybar::modules::Network::parseFreq(struct nlattr** bss) {
|
||||
if (bss[NL80211_BSS_FREQUENCY] != nullptr) {
|
||||
// in GHz
|
||||
frequency_ = (double)nla_get_u32(bss[NL80211_BSS_FREQUENCY]) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::modules::Network::parseBssid(struct nlattr **bss) {
|
||||
void waybar::modules::Network::parseBssid(struct nlattr** bss) {
|
||||
if (bss[NL80211_BSS_BSSID] != nullptr) {
|
||||
auto bssid = static_cast<uint8_t *>(nla_data(bss[NL80211_BSS_BSSID]));
|
||||
auto bssid = static_cast<uint8_t*>(nla_data(bss[NL80211_BSS_BSSID]));
|
||||
auto bssid_len = nla_len(bss[NL80211_BSS_BSSID]);
|
||||
if (bssid_len == 6) {
|
||||
bssid_ = fmt::format("{:x}:{:x}:{:x}:{:x}:{:x}:{:x}", bssid[0], bssid[1], bssid[2], bssid[3],
|
||||
@ -942,7 +942,7 @@ void waybar::modules::Network::parseBssid(struct nlattr **bss) {
|
||||
}
|
||||
}
|
||||
|
||||
bool waybar::modules::Network::associatedOrJoined(struct nlattr **bss) {
|
||||
bool waybar::modules::Network::associatedOrJoined(struct nlattr** bss) {
|
||||
if (bss[NL80211_BSS_STATUS] == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@ -958,7 +958,7 @@ bool waybar::modules::Network::associatedOrJoined(struct nlattr **bss) {
|
||||
}
|
||||
|
||||
auto waybar::modules::Network::getInfo() -> void {
|
||||
struct nl_msg *nl_msg = nlmsg_alloc();
|
||||
struct nl_msg* nl_msg = nlmsg_alloc();
|
||||
if (nl_msg == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
namespace waybar::modules::niri {
|
||||
|
||||
int IPC::connectToSocket() {
|
||||
const char *socket_path = getenv("NIRI_SOCKET");
|
||||
const char* socket_path = getenv("NIRI_SOCKET");
|
||||
|
||||
if (socket_path == nullptr) {
|
||||
spdlog::warn("Niri is not running, niri IPC will not be available.");
|
||||
@ -43,7 +43,7 @@ int IPC::connectToSocket() {
|
||||
|
||||
int l = sizeof(struct sockaddr_un);
|
||||
|
||||
if (connect(socketfd, (struct sockaddr *)&addr, l) == -1) {
|
||||
if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) {
|
||||
close(socketfd);
|
||||
throw std::runtime_error("unable to connect");
|
||||
}
|
||||
@ -58,7 +58,7 @@ void IPC::startIPC() {
|
||||
int socketfd;
|
||||
try {
|
||||
socketfd = connectToSocket();
|
||||
} catch (std::exception &e) {
|
||||
} catch (std::exception& e) {
|
||||
spdlog::error("Niri IPC: failed to start, reason: {}", e.what());
|
||||
return;
|
||||
}
|
||||
@ -87,7 +87,7 @@ void IPC::startIPC() {
|
||||
|
||||
try {
|
||||
parseIPC(line);
|
||||
} catch (std::exception &e) {
|
||||
} catch (std::exception& e) {
|
||||
spdlog::warn("Failed to parse IPC message: {}, reason: {}", line, e.what());
|
||||
} catch (...) {
|
||||
throw;
|
||||
@ -98,7 +98,7 @@ void IPC::startIPC() {
|
||||
}).detach();
|
||||
}
|
||||
|
||||
void IPC::parseIPC(const std::string &line) {
|
||||
void IPC::parseIPC(const std::string& line) {
|
||||
const auto ev = parser_.parse(line);
|
||||
const auto members = ev.getMemberNames();
|
||||
if (members.size() != 1) throw std::runtime_error("Event must have a single member");
|
||||
@ -106,28 +106,28 @@ void IPC::parseIPC(const std::string &line) {
|
||||
{
|
||||
auto lock = lockData();
|
||||
|
||||
if (const auto &payload = ev["WorkspacesChanged"]) {
|
||||
if (const auto& payload = ev["WorkspacesChanged"]) {
|
||||
workspaces_.clear();
|
||||
const auto &values = payload["workspaces"];
|
||||
const auto& values = payload["workspaces"];
|
||||
std::copy(values.begin(), values.end(), std::back_inserter(workspaces_));
|
||||
|
||||
std::sort(workspaces_.begin(), workspaces_.end(), [](const auto &a, const auto &b) {
|
||||
const auto &aOutput = a["output"].asString();
|
||||
const auto &bOutput = b["output"].asString();
|
||||
std::sort(workspaces_.begin(), workspaces_.end(), [](const auto& a, const auto& b) {
|
||||
const auto& aOutput = a["output"].asString();
|
||||
const auto& bOutput = b["output"].asString();
|
||||
const auto aIdx = a["idx"].asUInt();
|
||||
const auto bIdx = b["idx"].asUInt();
|
||||
if (aOutput == bOutput) return aIdx < bIdx;
|
||||
return aOutput < bOutput;
|
||||
});
|
||||
} else if (const auto &payload = ev["WorkspaceActivated"]) {
|
||||
} else if (const auto& payload = ev["WorkspaceActivated"]) {
|
||||
const auto id = payload["id"].asUInt64();
|
||||
const auto focused = payload["focused"].asBool();
|
||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||
[id](const auto &ws) { return ws["id"].asUInt64() == id; });
|
||||
[id](const auto& ws) { return ws["id"].asUInt64() == id; });
|
||||
if (it != workspaces_.end()) {
|
||||
const auto &ws = *it;
|
||||
const auto &output = ws["output"].asString();
|
||||
for (auto &ws : workspaces_) {
|
||||
const auto& ws = *it;
|
||||
const auto& output = ws["output"].asString();
|
||||
for (auto& ws : workspaces_) {
|
||||
const auto got_activated = (ws["id"].asUInt64() == id);
|
||||
if (ws["output"] == output) ws["is_active"] = got_activated;
|
||||
|
||||
@ -136,70 +136,70 @@ void IPC::parseIPC(const std::string &line) {
|
||||
} else {
|
||||
spdlog::error("Activated unknown workspace");
|
||||
}
|
||||
} else if (const auto &payload = ev["WorkspaceActiveWindowChanged"]) {
|
||||
} else if (const auto& payload = ev["WorkspaceActiveWindowChanged"]) {
|
||||
const auto workspaceId = payload["workspace_id"].asUInt64();
|
||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [workspaceId](const auto &ws) {
|
||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [workspaceId](const auto& ws) {
|
||||
return ws["id"].asUInt64() == workspaceId;
|
||||
});
|
||||
if (it != workspaces_.end()) {
|
||||
auto &ws = *it;
|
||||
auto& ws = *it;
|
||||
ws["active_window_id"] = payload["active_window_id"];
|
||||
} else {
|
||||
spdlog::error("Active window changed on unknown workspace");
|
||||
}
|
||||
} else if (const auto &payload = ev["WorkspaceUrgencyChanged"]) {
|
||||
} else if (const auto& payload = ev["WorkspaceUrgencyChanged"]) {
|
||||
const auto id = payload["id"].asUInt64();
|
||||
const auto urgent = payload["urgent"].asBool();
|
||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||
[id](const auto &ws) { return ws["id"].asUInt64() == id; });
|
||||
[id](const auto& ws) { return ws["id"].asUInt64() == id; });
|
||||
if (it != workspaces_.end()) {
|
||||
auto &ws = *it;
|
||||
auto& ws = *it;
|
||||
ws["is_urgent"] = urgent;
|
||||
} else {
|
||||
spdlog::error("Urgency changed for unknown workspace");
|
||||
}
|
||||
} else if (const auto &payload = ev["KeyboardLayoutsChanged"]) {
|
||||
const auto &layouts = payload["keyboard_layouts"];
|
||||
const auto &names = layouts["names"];
|
||||
} else if (const auto& payload = ev["KeyboardLayoutsChanged"]) {
|
||||
const auto& layouts = payload["keyboard_layouts"];
|
||||
const auto& names = layouts["names"];
|
||||
keyboardLayoutCurrent_ = layouts["current_idx"].asUInt();
|
||||
|
||||
keyboardLayoutNames_.clear();
|
||||
for (const auto &fullName : names) keyboardLayoutNames_.push_back(fullName.asString());
|
||||
} else if (const auto &payload = ev["KeyboardLayoutSwitched"]) {
|
||||
for (const auto& fullName : names) keyboardLayoutNames_.push_back(fullName.asString());
|
||||
} else if (const auto& payload = ev["KeyboardLayoutSwitched"]) {
|
||||
keyboardLayoutCurrent_ = payload["idx"].asUInt();
|
||||
} else if (const auto &payload = ev["WindowsChanged"]) {
|
||||
} else if (const auto& payload = ev["WindowsChanged"]) {
|
||||
windows_.clear();
|
||||
const auto &values = payload["windows"];
|
||||
const auto& values = payload["windows"];
|
||||
std::copy(values.begin(), values.end(), std::back_inserter(windows_));
|
||||
} else if (const auto &payload = ev["WindowOpenedOrChanged"]) {
|
||||
const auto &window = payload["window"];
|
||||
} else if (const auto& payload = ev["WindowOpenedOrChanged"]) {
|
||||
const auto& window = payload["window"];
|
||||
const auto id = window["id"].asUInt64();
|
||||
auto it = std::find_if(windows_.begin(), windows_.end(),
|
||||
[id](const auto &win) { return win["id"].asUInt64() == id; });
|
||||
[id](const auto& win) { return win["id"].asUInt64() == id; });
|
||||
if (it == windows_.end()) {
|
||||
windows_.push_back(window);
|
||||
|
||||
if (window["is_focused"].asBool()) {
|
||||
for (auto &win : windows_) {
|
||||
for (auto& win : windows_) {
|
||||
win["is_focused"] = win["id"].asUInt64() == id;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*it = window;
|
||||
}
|
||||
} else if (const auto &payload = ev["WindowClosed"]) {
|
||||
} else if (const auto& payload = ev["WindowClosed"]) {
|
||||
const auto id = payload["id"].asUInt64();
|
||||
auto it = std::find_if(windows_.begin(), windows_.end(),
|
||||
[id](const auto &win) { return win["id"].asUInt64() == id; });
|
||||
[id](const auto& win) { return win["id"].asUInt64() == id; });
|
||||
if (it != windows_.end()) {
|
||||
windows_.erase(it);
|
||||
} else {
|
||||
spdlog::error("Unknown window closed");
|
||||
}
|
||||
} else if (const auto &payload = ev["WindowFocusChanged"]) {
|
||||
} else if (const auto& payload = ev["WindowFocusChanged"]) {
|
||||
const auto focused = !payload["id"].isNull();
|
||||
const auto id = payload["id"].asUInt64();
|
||||
for (auto &win : windows_) {
|
||||
for (auto& win : windows_) {
|
||||
win["is_focused"] = focused && win["id"].asUInt64() == id;
|
||||
}
|
||||
}
|
||||
@ -207,14 +207,14 @@ void IPC::parseIPC(const std::string &line) {
|
||||
|
||||
std::unique_lock lock(callbackMutex_);
|
||||
|
||||
for (auto &[eventname, handler] : callbacks_) {
|
||||
for (auto& [eventname, handler] : callbacks_) {
|
||||
if (eventname == members[0]) {
|
||||
handler->onEvent(ev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IPC::registerForIPC(const std::string &ev, EventHandler *ev_handler) {
|
||||
void IPC::registerForIPC(const std::string& ev, EventHandler* ev_handler) {
|
||||
if (ev_handler == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -223,7 +223,7 @@ void IPC::registerForIPC(const std::string &ev, EventHandler *ev_handler) {
|
||||
callbacks_.emplace_back(ev, ev_handler);
|
||||
}
|
||||
|
||||
void IPC::unregisterForIPC(EventHandler *ev_handler) {
|
||||
void IPC::unregisterForIPC(EventHandler* ev_handler) {
|
||||
if (ev_handler == nullptr) {
|
||||
return;
|
||||
}
|
||||
@ -231,7 +231,7 @@ void IPC::unregisterForIPC(EventHandler *ev_handler) {
|
||||
std::unique_lock lock(callbackMutex_);
|
||||
|
||||
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
|
||||
auto &[eventname, handler] = *it;
|
||||
auto& [eventname, handler] = *it;
|
||||
if (handler == ev_handler) {
|
||||
it = callbacks_.erase(it);
|
||||
} else {
|
||||
@ -240,7 +240,7 @@ void IPC::unregisterForIPC(EventHandler *ev_handler) {
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value IPC::send(const Json::Value &request) {
|
||||
Json::Value IPC::send(const Json::Value& request) {
|
||||
int socketfd = connectToSocket();
|
||||
if (socketfd == -1) throw std::runtime_error("Niri is not running");
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
namespace waybar::modules::niri {
|
||||
|
||||
Language::Language(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
Language::Language(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: ALabel(config, "language", id, "{}", 0, false), bar_(bar) {
|
||||
label_.hide();
|
||||
|
||||
@ -32,7 +32,7 @@ void Language::updateFromIPC() {
|
||||
auto ipcLock = gIPC->lockData();
|
||||
|
||||
layouts_.clear();
|
||||
for (const auto &fullName : gIPC->keyboardLayoutNames()) layouts_.push_back(getLayout(fullName));
|
||||
for (const auto& fullName : gIPC->keyboardLayoutNames()) layouts_.push_back(getLayout(fullName));
|
||||
|
||||
current_idx_ = gIPC->keyboardLayoutCurrent();
|
||||
}
|
||||
@ -51,7 +51,7 @@ void Language::doUpdate() {
|
||||
label_.hide();
|
||||
return;
|
||||
}
|
||||
const auto &layout = layouts_[current_idx_];
|
||||
const auto& layout = layouts_[current_idx_];
|
||||
|
||||
spdlog::debug("niri language update with full name {}", layout.full_name);
|
||||
spdlog::debug("niri language update with short name {}", layout.short_name);
|
||||
@ -97,7 +97,7 @@ void Language::update() {
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
void Language::onEvent(const Json::Value &ev) {
|
||||
void Language::onEvent(const Json::Value& ev) {
|
||||
if (ev["KeyboardLayoutsChanged"]) {
|
||||
updateFromIPC();
|
||||
} else if (ev["KeyboardLayoutSwitched"]) {
|
||||
@ -109,11 +109,11 @@ void Language::onEvent(const Json::Value &ev) {
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
Language::Layout Language::getLayout(const std::string &fullName) {
|
||||
auto *const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
|
||||
Language::Layout Language::getLayout(const std::string& fullName) {
|
||||
auto* const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
|
||||
rxkb_context_parse_default_ruleset(context);
|
||||
|
||||
rxkb_layout *layout = rxkb_layout_first(context);
|
||||
rxkb_layout* layout = rxkb_layout_first(context);
|
||||
while (layout != nullptr) {
|
||||
std::string nameOfLayout = rxkb_layout_get_description(layout);
|
||||
|
||||
@ -123,10 +123,10 @@ Language::Layout Language::getLayout(const std::string &fullName) {
|
||||
}
|
||||
|
||||
auto name = std::string(rxkb_layout_get_name(layout));
|
||||
const auto *variantPtr = rxkb_layout_get_variant(layout);
|
||||
const auto* variantPtr = rxkb_layout_get_variant(layout);
|
||||
std::string variant = variantPtr == nullptr ? "" : std::string(variantPtr);
|
||||
|
||||
const auto *descriptionPtr = rxkb_layout_get_brief(layout);
|
||||
const auto* descriptionPtr = rxkb_layout_get_brief(layout);
|
||||
std::string description = descriptionPtr == nullptr ? "" : std::string(descriptionPtr);
|
||||
|
||||
Layout info = Layout{nameOfLayout, name, variant, description};
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
namespace waybar::modules::niri {
|
||||
|
||||
Window::Window(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) {
|
||||
if (!gIPC) gIPC = std::make_unique<IPC>();
|
||||
|
||||
@ -23,16 +23,16 @@ Window::Window(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
|
||||
Window::~Window() { gIPC->unregisterForIPC(this); }
|
||||
|
||||
void Window::onEvent(const Json::Value &ev) { dp.emit(); }
|
||||
void Window::onEvent(const Json::Value& ev) { dp.emit(); }
|
||||
|
||||
void Window::doUpdate() {
|
||||
auto ipcLock = gIPC->lockData();
|
||||
|
||||
const auto &windows = gIPC->windows();
|
||||
const auto &workspaces = gIPC->workspaces();
|
||||
const auto& windows = gIPC->windows();
|
||||
const auto& workspaces = gIPC->workspaces();
|
||||
|
||||
const auto separateOutputs = config_["separate-outputs"].asBool();
|
||||
const auto ws_it = std::find_if(workspaces.cbegin(), workspaces.cend(), [&](const auto &ws) {
|
||||
const auto ws_it = std::find_if(workspaces.cbegin(), workspaces.cend(), [&](const auto& ws) {
|
||||
if (separateOutputs) {
|
||||
return ws["is_active"].asBool() && ws["output"].asString() == bar_.output->name;
|
||||
}
|
||||
@ -46,13 +46,13 @@ void Window::doUpdate() {
|
||||
} else {
|
||||
const auto id = (*ws_it)["active_window_id"].asUInt64();
|
||||
it = std::find_if(windows.cbegin(), windows.cend(),
|
||||
[id](const auto &win) { return win["id"].asUInt64() == id; });
|
||||
[id](const auto& win) { return win["id"].asUInt64() == id; });
|
||||
}
|
||||
|
||||
setClass("empty", ws_it == workspaces.cend() || (*ws_it)["active_window_id"].isNull());
|
||||
|
||||
if (it != windows.cend()) {
|
||||
const auto &window = *it;
|
||||
const auto& window = *it;
|
||||
|
||||
const auto title = window["title"].asString();
|
||||
const auto appId = window["app_id"].asString();
|
||||
@ -71,7 +71,7 @@ void Window::doUpdate() {
|
||||
|
||||
const auto id = window["id"].asUInt64();
|
||||
const auto workspaceId = window["workspace_id"].asUInt64();
|
||||
const auto isSolo = std::none_of(windows.cbegin(), windows.cend(), [&](const auto &win) {
|
||||
const auto isSolo = std::none_of(windows.cbegin(), windows.cend(), [&](const auto& win) {
|
||||
return win["id"].asUInt64() != id && win["workspace_id"].asUInt64() == workspaceId;
|
||||
});
|
||||
setClass("solo", isSolo);
|
||||
@ -95,7 +95,7 @@ void Window::update() {
|
||||
AAppIconLabel::update();
|
||||
}
|
||||
|
||||
void Window::setClass(const std::string &className, bool enable) {
|
||||
void Window::setClass(const std::string& className, bool enable) {
|
||||
auto styleContext = bar_.window.get_style_context();
|
||||
if (enable) {
|
||||
if (!styleContext->has_class(className)) {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
namespace waybar::modules::niri {
|
||||
|
||||
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) {
|
||||
box_.set_name("workspaces");
|
||||
if (!id.empty()) {
|
||||
@ -27,16 +27,16 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
|
||||
Workspaces::~Workspaces() { gIPC->unregisterForIPC(this); }
|
||||
|
||||
void Workspaces::onEvent(const Json::Value &ev) { dp.emit(); }
|
||||
void Workspaces::onEvent(const Json::Value& ev) { dp.emit(); }
|
||||
|
||||
void Workspaces::doUpdate() {
|
||||
auto ipcLock = gIPC->lockData();
|
||||
|
||||
const auto alloutputs = config_["all-outputs"].asBool();
|
||||
std::vector<Json::Value> my_workspaces;
|
||||
const auto &workspaces = gIPC->workspaces();
|
||||
const auto& workspaces = gIPC->workspaces();
|
||||
std::copy_if(workspaces.cbegin(), workspaces.cend(), std::back_inserter(my_workspaces),
|
||||
[&](const auto &ws) {
|
||||
[&](const auto& ws) {
|
||||
if (alloutputs) return true;
|
||||
return ws["output"].asString() == bar_.output->name;
|
||||
});
|
||||
@ -44,7 +44,7 @@ void Workspaces::doUpdate() {
|
||||
// Remove buttons for removed workspaces.
|
||||
for (auto it = buttons_.begin(); it != buttons_.end();) {
|
||||
auto ws = std::find_if(my_workspaces.begin(), my_workspaces.end(),
|
||||
[it](const auto &ws) { return ws["id"].asUInt64() == it->first; });
|
||||
[it](const auto& ws) { return ws["id"].asUInt64() == it->first; });
|
||||
if (ws == my_workspaces.end()) {
|
||||
it = buttons_.erase(it);
|
||||
} else {
|
||||
@ -53,9 +53,9 @@ void Workspaces::doUpdate() {
|
||||
}
|
||||
|
||||
// Add buttons for new workspaces, update existing ones.
|
||||
for (const auto &ws : my_workspaces) {
|
||||
for (const auto& ws : my_workspaces) {
|
||||
auto bit = buttons_.find(ws["id"].asUInt64());
|
||||
auto &button = bit == buttons_.end() ? addButton(ws) : bit->second;
|
||||
auto& button = bit == buttons_.end() ? addButton(ws) : bit->second;
|
||||
auto style_context = button.get_style_context();
|
||||
|
||||
if (ws["is_focused"].asBool())
|
||||
@ -103,13 +103,13 @@ void Workspaces::doUpdate() {
|
||||
fmt::arg("output", ws["output"].asString()));
|
||||
}
|
||||
if (!config_["disable-markup"].asBool()) {
|
||||
static_cast<Gtk::Label *>(button.get_children()[0])->set_markup(name);
|
||||
static_cast<Gtk::Label*>(button.get_children()[0])->set_markup(name);
|
||||
} else {
|
||||
button.set_label(name);
|
||||
}
|
||||
|
||||
if (config_["current-only"].asBool()) {
|
||||
const auto *property = alloutputs ? "is_focused" : "is_active";
|
||||
const auto* property = alloutputs ? "is_focused" : "is_active";
|
||||
if (ws[property].asBool())
|
||||
button.show();
|
||||
else
|
||||
@ -121,12 +121,12 @@ void Workspaces::doUpdate() {
|
||||
|
||||
// Refresh the button order.
|
||||
for (auto it = my_workspaces.cbegin(); it != my_workspaces.cend(); ++it) {
|
||||
const auto &ws = *it;
|
||||
const auto& ws = *it;
|
||||
|
||||
auto pos = ws["idx"].asUInt() - 1;
|
||||
if (alloutputs) pos = it - my_workspaces.cbegin();
|
||||
|
||||
auto &button = buttons_[ws["id"].asUInt64()];
|
||||
auto& button = buttons_[ws["id"].asUInt64()];
|
||||
box_.reorder_child(button, pos);
|
||||
}
|
||||
}
|
||||
@ -136,7 +136,7 @@ void Workspaces::update() {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
|
||||
Gtk::Button& Workspaces::addButton(const Json::Value& ws) {
|
||||
std::string name;
|
||||
if (ws["name"]) {
|
||||
name = ws["name"].asString();
|
||||
@ -145,7 +145,7 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
|
||||
}
|
||||
|
||||
auto pair = buttons_.emplace(ws["id"].asUInt64(), name);
|
||||
auto &&button = pair.first->second;
|
||||
auto&& button = pair.first->second;
|
||||
box_.pack_start(button, false, false, 0);
|
||||
button.set_relief(Gtk::RELIEF_NONE);
|
||||
if (!config_["disable-click"].asBool()) {
|
||||
@ -154,13 +154,13 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
|
||||
try {
|
||||
// {"Action":{"FocusWorkspace":{"reference":{"Id":1}}}}
|
||||
Json::Value request(Json::objectValue);
|
||||
auto &action = (request["Action"] = Json::Value(Json::objectValue));
|
||||
auto &focusWorkspace = (action["FocusWorkspace"] = Json::Value(Json::objectValue));
|
||||
auto &reference = (focusWorkspace["reference"] = Json::Value(Json::objectValue));
|
||||
auto& action = (request["Action"] = Json::Value(Json::objectValue));
|
||||
auto& focusWorkspace = (action["FocusWorkspace"] = Json::Value(Json::objectValue));
|
||||
auto& reference = (focusWorkspace["reference"] = Json::Value(Json::objectValue));
|
||||
reference["Id"] = id;
|
||||
|
||||
IPC::send(request);
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Error switching workspace: {}", e.what());
|
||||
}
|
||||
});
|
||||
@ -168,8 +168,8 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) {
|
||||
return button;
|
||||
}
|
||||
|
||||
std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws) {
|
||||
const auto &icons = config_["format-icons"];
|
||||
std::string Workspaces::getIcon(const std::string& value, const Json::Value& ws) {
|
||||
const auto& icons = config_["format-icons"];
|
||||
if (!icons) return value;
|
||||
|
||||
if (ws["is_urgent"].asBool() && icons["urgent"]) return icons["urgent"].asString();
|
||||
@ -181,7 +181,7 @@ std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws)
|
||||
if (ws["is_active"].asBool() && icons["active"]) return icons["active"].asString();
|
||||
|
||||
if (ws["name"]) {
|
||||
const auto &name = ws["name"].asString();
|
||||
const auto& name = ws["name"].asString();
|
||||
if (icons[name]) return icons[name].asString();
|
||||
}
|
||||
|
||||
|
||||
@ -12,9 +12,9 @@
|
||||
|
||||
namespace waybar::modules::privacy {
|
||||
|
||||
PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privacy_type_,
|
||||
std::list<PrivacyNodeInfo *> *nodes_, Gtk::Orientation orientation,
|
||||
const std::string &pos, const uint icon_size,
|
||||
PrivacyItem::PrivacyItem(const Json::Value& config_, enum PrivacyNodeType privacy_type_,
|
||||
std::list<PrivacyNodeInfo*>* nodes_, Gtk::Orientation orientation,
|
||||
const std::string& pos, const uint icon_size,
|
||||
const uint transition_duration)
|
||||
: Gtk::Revealer(),
|
||||
privacy_type(privacy_type_),
|
||||
@ -83,7 +83,7 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac
|
||||
// Sets the window to use when showing the tooltip
|
||||
update_tooltip();
|
||||
this->signal_query_tooltip().connect(sigc::track_obj(
|
||||
[this](int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip> &tooltip) {
|
||||
[this](int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
|
||||
tooltip->set_custom(tooltip_window);
|
||||
return true;
|
||||
},
|
||||
@ -97,23 +97,23 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac
|
||||
|
||||
void PrivacyItem::update_tooltip() {
|
||||
// Removes all old nodes
|
||||
for (auto *child : tooltip_window.get_children()) {
|
||||
for (auto* child : tooltip_window.get_children()) {
|
||||
tooltip_window.remove(*child);
|
||||
// despite the remove, still needs a delete to prevent memory leak. Speculating that this might
|
||||
// work differently in GTK4.
|
||||
delete child;
|
||||
}
|
||||
for (auto *node : *nodes) {
|
||||
auto *box = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL, 4);
|
||||
for (auto* node : *nodes) {
|
||||
auto* box = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL, 4);
|
||||
|
||||
// Set device icon
|
||||
auto *node_icon = Gtk::make_managed<Gtk::Image>();
|
||||
auto* node_icon = Gtk::make_managed<Gtk::Image>();
|
||||
node_icon->set_pixel_size(tooltipIconSize);
|
||||
node_icon->set_from_icon_name(node->getIconName(), Gtk::ICON_SIZE_INVALID);
|
||||
box->add(*node_icon);
|
||||
|
||||
// Set model
|
||||
auto *nodeName = Gtk::make_managed<Gtk::Label>(node->getName());
|
||||
auto* nodeName = Gtk::make_managed<Gtk::Label>(node->getName());
|
||||
box->add(*nodeName);
|
||||
|
||||
tooltip_window.add(*box);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "modules/pulseaudio.hpp"
|
||||
|
||||
waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value &config)
|
||||
waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "pulseaudio", id, "{volume}%") {
|
||||
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleScroll));
|
||||
@ -9,7 +9,7 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
|
||||
backend->setIgnoredSinks(config_["ignored-sinks"]);
|
||||
}
|
||||
|
||||
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) {
|
||||
bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll* e) {
|
||||
// change the pulse volume only when no user provided
|
||||
// events are configured
|
||||
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||
@ -51,7 +51,7 @@ const std::vector<std::string> waybar::modules::Pulseaudio::getPulseIcon() const
|
||||
res.push_back(backend->getDefaultSourceName());
|
||||
std::string nameLC = backend->getSinkPortName() + backend->getFormFactor();
|
||||
std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower);
|
||||
for (auto const &port : ports) {
|
||||
for (auto const& port : ports) {
|
||||
if (nameLC.find(port) != std::string::npos) {
|
||||
if (sink_muted) {
|
||||
res.emplace_back(port + "-muted");
|
||||
|
||||
@ -7,48 +7,48 @@
|
||||
|
||||
namespace waybar::modules::river {
|
||||
|
||||
static void listen_focused_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
static void listen_focused_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1,
|
||||
uint32_t tags) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
struct wl_array *tags) {
|
||||
static void listen_view_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1,
|
||||
struct wl_array* tags) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
static void listen_urgent_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1,
|
||||
uint32_t tags) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_layout_name(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
const char *layout) {
|
||||
static_cast<Layout *>(data)->handle_name(layout);
|
||||
static void listen_layout_name(void* data, struct zriver_output_status_v1* zriver_output_status_v1,
|
||||
const char* layout) {
|
||||
static_cast<Layout*>(data)->handle_name(layout);
|
||||
}
|
||||
|
||||
static void listen_layout_name_clear(void *data,
|
||||
struct zriver_output_status_v1 *zriver_output_status_v1) {
|
||||
static_cast<Layout *>(data)->handle_clear();
|
||||
static void listen_layout_name_clear(void* data,
|
||||
struct zriver_output_status_v1* zriver_output_status_v1) {
|
||||
static_cast<Layout*>(data)->handle_clear();
|
||||
}
|
||||
|
||||
static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
struct wl_output *output) {
|
||||
static_cast<Layout *>(data)->handle_focused_output(output);
|
||||
static void listen_focused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
struct wl_output* output) {
|
||||
static_cast<Layout*>(data)->handle_focused_output(output);
|
||||
}
|
||||
|
||||
static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
struct wl_output *output) {
|
||||
static_cast<Layout *>(data)->handle_unfocused_output(output);
|
||||
static void listen_unfocused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
struct wl_output* output) {
|
||||
static_cast<Layout*>(data)->handle_unfocused_output(output);
|
||||
}
|
||||
|
||||
static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
const char *title) {
|
||||
static void listen_focused_view(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
const char* title) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
const char *mode) {
|
||||
static void listen_mode(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
const char* mode) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
@ -67,8 +67,8 @@ static const zriver_seat_status_v1_listener seat_status_listener_impl{
|
||||
.mode = listen_mode,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
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, 4);
|
||||
|
||||
@ -80,32 +80,32 @@ static void handle_global(void *data, struct wl_registry *registry, uint32_t nam
|
||||
std::to_string(version));
|
||||
return;
|
||||
}
|
||||
static_cast<Layout *>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1 *>(
|
||||
static_cast<Layout*>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1*>(
|
||||
wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version));
|
||||
}
|
||||
|
||||
if (std::strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
version = std::min<uint32_t>(version, 1);
|
||||
static_cast<Layout *>(data)->seat_ = static_cast<struct wl_seat *>(
|
||||
wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
static_cast<Layout*>(data)->seat_ =
|
||||
static_cast<struct wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
// Nobody cares
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Layout::Layout(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
|
||||
Layout::Layout(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
||||
: waybar::ALabel(config, "layout", id, "{}"),
|
||||
status_manager_{nullptr},
|
||||
seat_{nullptr},
|
||||
bar_(bar),
|
||||
output_status_{nullptr} {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
@ -141,7 +141,7 @@ Layout::~Layout() {
|
||||
}
|
||||
}
|
||||
|
||||
void Layout::handle_name(const char *name) {
|
||||
void Layout::handle_name(const char* name) {
|
||||
if (std::strcmp(name, "") == 0 || format_.empty()) {
|
||||
label_.hide(); // hide empty labels or labels with empty format
|
||||
} else {
|
||||
@ -162,7 +162,7 @@ void Layout::handle_clear() {
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
void Layout::handle_focused_output(struct wl_output *output) {
|
||||
void Layout::handle_focused_output(struct wl_output* output) {
|
||||
if (output_ == output) { // if we focused the output this bar belongs to
|
||||
label_.get_style_context()->add_class("focused");
|
||||
ALabel::update();
|
||||
@ -170,7 +170,7 @@ void Layout::handle_focused_output(struct wl_output *output) {
|
||||
focused_output_ = output;
|
||||
}
|
||||
|
||||
void Layout::handle_unfocused_output(struct wl_output *output) {
|
||||
void Layout::handle_unfocused_output(struct wl_output* output) {
|
||||
if (output_ == output) { // if we unfocused the output this bar belongs to
|
||||
label_.get_style_context()->remove_class("focused");
|
||||
ALabel::update();
|
||||
|
||||
@ -7,23 +7,23 @@
|
||||
|
||||
namespace waybar::modules::river {
|
||||
|
||||
static void listen_focused_output(void *data, struct zriver_seat_status_v1 *seat_status,
|
||||
struct wl_output *output) {
|
||||
static void listen_focused_output(void* data, struct zriver_seat_status_v1* seat_status,
|
||||
struct wl_output* output) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *seat_status,
|
||||
struct wl_output *output) {
|
||||
static void listen_unfocused_output(void* data, struct zriver_seat_status_v1* seat_status,
|
||||
struct wl_output* output) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_focused_view(void *data, struct zriver_seat_status_v1 *seat_status,
|
||||
const char *title) {
|
||||
static void listen_focused_view(void* data, struct zriver_seat_status_v1* seat_status,
|
||||
const char* title) {
|
||||
// Intentionally empty
|
||||
}
|
||||
|
||||
static void listen_mode(void *data, struct zriver_seat_status_v1 *seat_status, const char *mode) {
|
||||
static_cast<Mode *>(data)->handle_mode(mode);
|
||||
static void listen_mode(void* data, struct zriver_seat_status_v1* seat_status, const char* mode) {
|
||||
static_cast<Mode*>(data)->handle_mode(mode);
|
||||
}
|
||||
|
||||
static const zriver_seat_status_v1_listener seat_status_listener_impl = {
|
||||
@ -33,8 +33,8 @@ static const zriver_seat_status_v1_listener seat_status_listener_impl = {
|
||||
.mode = listen_mode,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
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, 3);
|
||||
if (version < ZRIVER_SEAT_STATUS_V1_MODE_SINCE_VERSION) {
|
||||
@ -42,31 +42,31 @@ static void handle_global(void *data, struct wl_registry *registry, uint32_t nam
|
||||
"river server does not support the \"mode\" event; the module will be disabled");
|
||||
return;
|
||||
}
|
||||
static_cast<Mode *>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1 *>(
|
||||
static_cast<Mode*>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1*>(
|
||||
wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version));
|
||||
} else if (std::strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
version = std::min<uint32_t>(version, 1);
|
||||
static_cast<Mode *>(data)->seat_ = static_cast<struct wl_seat *>(
|
||||
wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
static_cast<Mode*>(data)->seat_ =
|
||||
static_cast<struct wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
// Nobody cares
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Mode::Mode(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
|
||||
Mode::Mode(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
||||
: waybar::ALabel(config, "mode", id, "{}"),
|
||||
status_manager_{nullptr},
|
||||
seat_{nullptr},
|
||||
bar_(bar),
|
||||
mode_{""},
|
||||
seat_status_{nullptr} {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
@ -94,7 +94,7 @@ Mode::~Mode() {
|
||||
}
|
||||
}
|
||||
|
||||
void Mode::handle_mode(const char *mode) {
|
||||
void Mode::handle_mode(const char* mode) {
|
||||
if (format_.empty()) {
|
||||
label_.hide();
|
||||
} else {
|
||||
|
||||
@ -12,19 +12,19 @@
|
||||
|
||||
namespace waybar::modules::river {
|
||||
|
||||
static void listen_focused_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
static void listen_focused_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1,
|
||||
uint32_t tags) {
|
||||
static_cast<Tags *>(data)->handle_focused_tags(tags);
|
||||
static_cast<Tags*>(data)->handle_focused_tags(tags);
|
||||
}
|
||||
|
||||
static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
struct wl_array *tags) {
|
||||
static_cast<Tags *>(data)->handle_view_tags(tags);
|
||||
static void listen_view_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1,
|
||||
struct wl_array* tags) {
|
||||
static_cast<Tags*>(data)->handle_view_tags(tags);
|
||||
}
|
||||
|
||||
static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1,
|
||||
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_cast<Tags*>(data)->handle_urgent_tags(tags);
|
||||
}
|
||||
|
||||
static const zriver_output_status_v1_listener output_status_listener_impl{
|
||||
@ -33,15 +33,15 @@ static const zriver_output_status_v1_listener output_status_listener_impl{
|
||||
.urgent_tags = listen_urgent_tags,
|
||||
};
|
||||
|
||||
static void listen_command_success(void *data,
|
||||
struct zriver_command_callback_v1 *zriver_command_callback_v1,
|
||||
const char *output) {
|
||||
static void listen_command_success(void* data,
|
||||
struct zriver_command_callback_v1* zriver_command_callback_v1,
|
||||
const char* output) {
|
||||
// Do nothing but keep listener to avoid crashing when command was successful
|
||||
}
|
||||
|
||||
static void listen_command_failure(void *data,
|
||||
struct zriver_command_callback_v1 *zriver_command_callback_v1,
|
||||
const char *output) {
|
||||
static void listen_command_failure(void* data,
|
||||
struct zriver_command_callback_v1* zriver_command_callback_v1,
|
||||
const char* output) {
|
||||
spdlog::error("failure when selecting/toggling tags {}", output);
|
||||
}
|
||||
|
||||
@ -50,38 +50,38 @@ static const zriver_command_callback_v1_listener command_callback_listener_impl{
|
||||
.failure = listen_command_failure,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
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(version, 2u);
|
||||
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 *>(
|
||||
static_cast<Tags*>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1*>(
|
||||
wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version));
|
||||
}
|
||||
|
||||
if (std::strcmp(interface, zriver_control_v1_interface.name) == 0) {
|
||||
version = std::min(version, 1u);
|
||||
static_cast<Tags *>(data)->control_ = static_cast<struct zriver_control_v1 *>(
|
||||
static_cast<Tags*>(data)->control_ = static_cast<struct zriver_control_v1*>(
|
||||
wl_registry_bind(registry, name, &zriver_control_v1_interface, version));
|
||||
}
|
||||
|
||||
if (std::strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
version = std::min(version, 1u);
|
||||
static_cast<Tags *>(data)->seat_ = static_cast<struct wl_seat *>(
|
||||
wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
static_cast<Tags*>(data)->seat_ =
|
||||
static_cast<struct wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
/* Ignore event */
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
|
||||
Tags::Tags(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
||||
: waybar::AModule(config, "tags", id, false, false),
|
||||
status_manager_{nullptr},
|
||||
control_{nullptr},
|
||||
@ -89,8 +89,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
|
||||
bar_(bar),
|
||||
box_{bar.orientation, 0},
|
||||
output_status_{nullptr} {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
@ -129,7 +129,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
|
||||
buttons_.emplace_back(std::to_string(tag + 1));
|
||||
}
|
||||
|
||||
auto &button = buttons_[tag];
|
||||
auto& button = buttons_[tag];
|
||||
button.set_relief(Gtk::RELIEF_NONE);
|
||||
box_.pack_start(button, false, false, 0);
|
||||
|
||||
@ -168,7 +168,7 @@ Tags::~Tags() {
|
||||
}
|
||||
|
||||
void Tags::handle_show() {
|
||||
struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
struct wl_output* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
output_status_ = zriver_status_manager_v1_get_river_output_status(status_manager_, output);
|
||||
zriver_output_status_v1_add_listener(output_status_, &output_status_listener_impl, this);
|
||||
|
||||
@ -178,17 +178,17 @@ void Tags::handle_show() {
|
||||
|
||||
void Tags::handle_primary_clicked(uint32_t tag) {
|
||||
// Send river command to select tag on left mouse click
|
||||
zriver_command_callback_v1 *callback;
|
||||
zriver_command_callback_v1* callback;
|
||||
zriver_control_v1_add_argument(control_, "set-focused-tags");
|
||||
zriver_control_v1_add_argument(control_, std::to_string(tag).c_str());
|
||||
callback = zriver_control_v1_run_command(control_, seat_);
|
||||
zriver_command_callback_v1_add_listener(callback, &command_callback_listener_impl, nullptr);
|
||||
}
|
||||
|
||||
bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) {
|
||||
bool Tags::handle_button_press(GdkEventButton* event_button, uint32_t tag) {
|
||||
if (event_button->type == GDK_BUTTON_PRESS && event_button->button == 3) {
|
||||
// Send river command to toggle tag on right mouse click
|
||||
zriver_command_callback_v1 *callback;
|
||||
zriver_command_callback_v1* callback;
|
||||
zriver_control_v1_add_argument(control_, "toggle-focused-tags");
|
||||
zriver_control_v1_add_argument(control_, std::to_string(tag).c_str());
|
||||
callback = zriver_control_v1_run_command(control_, seat_);
|
||||
@ -217,9 +217,9 @@ void Tags::handle_focused_tags(uint32_t tags) {
|
||||
}
|
||||
}
|
||||
|
||||
void Tags::handle_view_tags(struct wl_array *view_tags) {
|
||||
void Tags::handle_view_tags(struct wl_array* view_tags) {
|
||||
uint32_t tags = 0;
|
||||
auto view_tag = reinterpret_cast<uint32_t *>(view_tags->data);
|
||||
auto view_tag = reinterpret_cast<uint32_t*>(view_tags->data);
|
||||
auto end = view_tag + (view_tags->size / sizeof(uint32_t));
|
||||
for (; view_tag < end; ++view_tag) {
|
||||
tags |= *view_tag;
|
||||
|
||||
@ -9,23 +9,23 @@
|
||||
|
||||
namespace waybar::modules::river {
|
||||
|
||||
static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
const char *title) {
|
||||
static_cast<Window *>(data)->handle_focused_view(title);
|
||||
static void listen_focused_view(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
const char* title) {
|
||||
static_cast<Window*>(data)->handle_focused_view(title);
|
||||
}
|
||||
|
||||
static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
struct wl_output *output) {
|
||||
static_cast<Window *>(data)->handle_focused_output(output);
|
||||
static void listen_focused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
struct wl_output* output) {
|
||||
static_cast<Window*>(data)->handle_focused_output(output);
|
||||
}
|
||||
|
||||
static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
struct wl_output *output) {
|
||||
static_cast<Window *>(data)->handle_unfocused_output(output);
|
||||
static void listen_unfocused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
struct wl_output* output) {
|
||||
static_cast<Window*>(data)->handle_unfocused_output(output);
|
||||
}
|
||||
|
||||
static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1,
|
||||
const char *mode) {
|
||||
static void listen_mode(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1,
|
||||
const char* mode) {
|
||||
// This module doesn't care
|
||||
}
|
||||
|
||||
@ -36,36 +36,36 @@ static const zriver_seat_status_v1_listener seat_status_listener_impl{
|
||||
.mode = listen_mode,
|
||||
};
|
||||
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
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);
|
||||
static_cast<Window *>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1 *>(
|
||||
static_cast<Window*>(data)->status_manager_ = static_cast<struct zriver_status_manager_v1*>(
|
||||
wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version));
|
||||
}
|
||||
|
||||
if (std::strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
version = std::min<uint32_t>(version, 1);
|
||||
static_cast<Window *>(data)->seat_ = static_cast<struct wl_seat *>(
|
||||
wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
static_cast<Window*>(data)->seat_ =
|
||||
static_cast<struct wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
/* Ignore event */
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Window::Window(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
|
||||
Window::Window(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
||||
: waybar::ALabel(config, "window", id, "{}", 30),
|
||||
status_manager_{nullptr},
|
||||
seat_{nullptr},
|
||||
bar_(bar),
|
||||
seat_status_{nullptr} {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
|
||||
@ -95,7 +95,7 @@ Window::~Window() {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::handle_focused_view(const char *title) {
|
||||
void Window::handle_focused_view(const char* title) {
|
||||
// don't change the label on unfocused outputs.
|
||||
// this makes the current output report its currently focused view, and unfocused outputs will
|
||||
// report their last focused views. when freshly starting the bar, unfocused outputs don't have a
|
||||
@ -116,7 +116,7 @@ void Window::handle_focused_view(const char *title) {
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
void Window::handle_focused_output(struct wl_output *output) {
|
||||
void Window::handle_focused_output(struct wl_output* output) {
|
||||
if (output_ == output) { // if we focused the output this bar belongs to
|
||||
label_.get_style_context()->add_class("focused");
|
||||
ALabel::update();
|
||||
@ -124,7 +124,7 @@ void Window::handle_focused_output(struct wl_output *output) {
|
||||
focused_output_ = output;
|
||||
}
|
||||
|
||||
void Window::handle_unfocused_output(struct wl_output *output) {
|
||||
void Window::handle_unfocused_output(struct wl_output* output) {
|
||||
if (output_ == output) { // if we unfocused the output this bar belongs to
|
||||
label_.get_style_context()->remove_class("focused");
|
||||
ALabel::update();
|
||||
|
||||
@ -9,8 +9,8 @@
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
void ondesc(void *arg, struct sioctl_desc *d, int curval) {
|
||||
auto self = static_cast<Sndio *>(arg);
|
||||
void ondesc(void* arg, struct sioctl_desc* d, int curval) {
|
||||
auto self = static_cast<Sndio*>(arg);
|
||||
if (d == NULL) {
|
||||
// d is NULL when the list is done
|
||||
return;
|
||||
@ -18,8 +18,8 @@ void ondesc(void *arg, struct sioctl_desc *d, int curval) {
|
||||
self->set_desc(d, curval);
|
||||
}
|
||||
|
||||
void onval(void *arg, unsigned int addr, unsigned int val) {
|
||||
auto self = static_cast<Sndio *>(arg);
|
||||
void onval(void* arg, unsigned int addr, unsigned int val) {
|
||||
auto self = static_cast<Sndio*>(arg);
|
||||
self->put_val(addr, val);
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ auto Sndio::connect_to_sndio() -> void {
|
||||
pfds_.reserve(sioctl_nfds(hdl_));
|
||||
}
|
||||
|
||||
Sndio::Sndio(const std::string &id, const Json::Value &config)
|
||||
Sndio::Sndio(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "sndio", id, "{volume}%", 1, false, true),
|
||||
hdl_(nullptr),
|
||||
pfds_(0),
|
||||
@ -80,7 +80,7 @@ Sndio::Sndio(const std::string &id, const Json::Value &config)
|
||||
while (thread_.isRunning()) {
|
||||
try {
|
||||
connect_to_sndio();
|
||||
} catch (std::runtime_error const &e) {
|
||||
} catch (std::runtime_error const& e) {
|
||||
// avoid leaking hdl_
|
||||
if (hdl_) {
|
||||
sioctl_close(hdl_);
|
||||
@ -122,7 +122,7 @@ auto Sndio::update() -> void {
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
auto Sndio::set_desc(struct sioctl_desc *d, unsigned int val) -> void {
|
||||
auto Sndio::set_desc(struct sioctl_desc* d, unsigned int val) -> void {
|
||||
std::string name{d->func};
|
||||
std::string node_name{d->node0.name};
|
||||
|
||||
@ -140,7 +140,7 @@ auto Sndio::put_val(unsigned int addr, unsigned int val) -> void {
|
||||
}
|
||||
}
|
||||
|
||||
bool Sndio::handleScroll(GdkEventScroll *e) {
|
||||
bool Sndio::handleScroll(GdkEventScroll* e) {
|
||||
// change the volume only when no user provided
|
||||
// events are configured
|
||||
if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) {
|
||||
@ -180,7 +180,7 @@ bool Sndio::handleScroll(GdkEventScroll *e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Sndio::handleToggle(GdkEventButton *const &e) {
|
||||
bool Sndio::handleToggle(GdkEventButton* const& e) {
|
||||
// toggle mute only when no user provided events are configured
|
||||
if (config_["on-click"].isString()) {
|
||||
return AModule::handleToggle(e);
|
||||
|
||||
@ -13,7 +13,7 @@ namespace waybar::modules::sway {
|
||||
int Workspaces::convertWorkspaceNameToNum(std::string name) {
|
||||
if (isdigit(name[0]) != 0) {
|
||||
errno = 0;
|
||||
char *endptr = nullptr;
|
||||
char* endptr = nullptr;
|
||||
long long parsed_num = strtoll(name.c_str(), &endptr, 10);
|
||||
if (errno != 0 || parsed_num > INT32_MAX || parsed_num < 0 || endptr == name.c_str()) {
|
||||
return -1;
|
||||
@ -23,7 +23,7 @@ int Workspaces::convertWorkspaceNameToNum(std::string name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
|
||||
int Workspaces::windowRewritePriorityFunction(std::string const& window_rule) {
|
||||
// Rules that match against title are prioritized
|
||||
// Rules that don't specify if they're matching against either title or class are deprioritized
|
||||
bool const hasTitle = window_rule.find("title") != std::string::npos;
|
||||
@ -41,12 +41,12 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
|
||||
Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
: AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
|
||||
bar_(bar),
|
||||
box_(bar.orientation, 0) {
|
||||
if (config["format-icons"]["high-priority-named"].isArray()) {
|
||||
for (const auto &it : config["format-icons"]["high-priority-named"]) {
|
||||
for (const auto& it : config["format-icons"]["high-priority-named"]) {
|
||||
high_priority_named_.push_back(it.asString());
|
||||
}
|
||||
}
|
||||
@ -61,9 +61,9 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
} else {
|
||||
m_formatWindowSeparator = " ";
|
||||
}
|
||||
const Json::Value &windowRewrite = config["window-rewrite"];
|
||||
const Json::Value& windowRewrite = config["window-rewrite"];
|
||||
if (windowRewrite.isObject()) {
|
||||
const Json::Value &windowRewriteDefaultConfig = config["window-rewrite-default"];
|
||||
const Json::Value& windowRewriteDefaultConfig = config["window-rewrite-default"];
|
||||
std::string windowRewriteDefault =
|
||||
windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
|
||||
m_windowRewriteRules = waybar::util::RegexCollection(
|
||||
@ -75,7 +75,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd));
|
||||
ipc_.sendCmd(IPC_GET_TREE);
|
||||
if (config["enable-bar-scroll"].asBool()) {
|
||||
auto &window = const_cast<Bar &>(bar_).window;
|
||||
auto& window = const_cast<Bar&>(bar_).window;
|
||||
window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||
window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
|
||||
}
|
||||
@ -83,21 +83,21 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
ipc_.setWorker([this] {
|
||||
try {
|
||||
ipc_.handleEvent();
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Workspaces::onEvent(const struct Ipc::ipc_response &res) {
|
||||
void Workspaces::onEvent(const struct Ipc::ipc_response& res) {
|
||||
try {
|
||||
ipc_.sendCmd(IPC_GET_TREE);
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
void Workspaces::onCmd(const struct Ipc::ipc_response& res) {
|
||||
if (res.type == IPC_GET_TREE) {
|
||||
try {
|
||||
{
|
||||
@ -107,7 +107,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
std::vector<Json::Value> outputs;
|
||||
bool alloutputs = config_["all-outputs"].asBool();
|
||||
std::copy_if(payload["nodes"].begin(), payload["nodes"].end(), std::back_inserter(outputs),
|
||||
[&](const auto &output) {
|
||||
[&](const auto& output) {
|
||||
if (alloutputs && output["name"].asString() != "__i3") {
|
||||
return true;
|
||||
}
|
||||
@ -117,7 +117,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
return false;
|
||||
});
|
||||
|
||||
for (auto &output : outputs) {
|
||||
for (auto& output : outputs) {
|
||||
std::copy(output["nodes"].begin(), output["nodes"].end(),
|
||||
std::back_inserter(workspaces_));
|
||||
std::copy(output["floating_nodes"].begin(), output["floating_nodes"].end(),
|
||||
@ -126,13 +126,13 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
|
||||
// adding persistent workspaces (as per the config file)
|
||||
if (config_["persistent-workspaces"].isObject()) {
|
||||
const Json::Value &p_workspaces = config_["persistent-workspaces"];
|
||||
const Json::Value& p_workspaces = config_["persistent-workspaces"];
|
||||
const std::vector<std::string> p_workspaces_names = p_workspaces.getMemberNames();
|
||||
|
||||
for (const std::string &p_w_name : p_workspaces_names) {
|
||||
const Json::Value &p_w = p_workspaces[p_w_name];
|
||||
for (const std::string& p_w_name : p_workspaces_names) {
|
||||
const Json::Value& p_w = p_workspaces[p_w_name];
|
||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||
[&p_w_name](const Json::Value &node) {
|
||||
[&p_w_name](const Json::Value& node) {
|
||||
return node["name"].asString() == p_w_name;
|
||||
});
|
||||
|
||||
@ -142,7 +142,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
|
||||
if (p_w.isArray() && !p_w.empty()) {
|
||||
// Adding to target outputs
|
||||
for (const Json::Value &output : p_w) {
|
||||
for (const Json::Value& output : p_w) {
|
||||
if (output.asString() == bar_.output->name) {
|
||||
Json::Value v;
|
||||
v["name"] = p_w_name;
|
||||
@ -185,10 +185,10 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
// agreement that the "workspace prev/next" commands may not follow
|
||||
// the order displayed in Waybar.
|
||||
int max_num = -1;
|
||||
for (auto &workspace : workspaces_) {
|
||||
for (auto& workspace : workspaces_) {
|
||||
max_num = std::max(workspace["num"].asInt(), max_num);
|
||||
}
|
||||
for (auto &workspace : workspaces_) {
|
||||
for (auto& workspace : workspaces_) {
|
||||
auto workspace_num = workspace["num"].asInt();
|
||||
if (workspace_num > -1) {
|
||||
workspace["sort"] = workspace_num;
|
||||
@ -197,7 +197,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
}
|
||||
}
|
||||
std::sort(workspaces_.begin(), workspaces_.end(),
|
||||
[this](const Json::Value &lhs, const Json::Value &rhs) {
|
||||
[this](const Json::Value& lhs, const Json::Value& rhs) {
|
||||
auto lname = lhs["name"].asString();
|
||||
auto rname = rhs["name"].asString();
|
||||
int l = lhs["sort"].asInt();
|
||||
@ -217,7 +217,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
});
|
||||
}
|
||||
dp.emit();
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ bool Workspaces::filterButtons() {
|
||||
bool needReorder = false;
|
||||
for (auto it = buttons_.begin(); it != buttons_.end();) {
|
||||
auto ws = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||
[it](const auto &node) { return node["name"].asString() == it->first; });
|
||||
[it](const auto& node) { return node["name"].asString() == it->first; });
|
||||
if (ws == workspaces_.end() ||
|
||||
(!config_["all-outputs"].asBool() && (*ws)["output"].asString() != bar_.output->name)) {
|
||||
it = buttons_.erase(it);
|
||||
@ -239,23 +239,23 @@ bool Workspaces::filterButtons() {
|
||||
return needReorder;
|
||||
}
|
||||
|
||||
bool Workspaces::hasFlag(const Json::Value &node, const std::string &flag) {
|
||||
bool Workspaces::hasFlag(const Json::Value& node, const std::string& flag) {
|
||||
if (node[flag].asBool()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (std::any_of(node["nodes"].begin(), node["nodes"].end(),
|
||||
[&](auto const &e) { return hasFlag(e, flag); })) {
|
||||
[&](auto const& e) { return hasFlag(e, flag); })) {
|
||||
return true;
|
||||
}
|
||||
if (std::any_of(node["floating_nodes"].begin(), node["floating_nodes"].end(),
|
||||
[&](auto const &e) { return hasFlag(e, flag); })) {
|
||||
[&](auto const& e) { return hasFlag(e, flag); })) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Workspaces::updateWindows(const Json::Value &node, std::string &windows) {
|
||||
void Workspaces::updateWindows(const Json::Value& node, std::string& windows) {
|
||||
if ((node["type"].asString() == "con" || node["type"].asString() == "floating_con") &&
|
||||
node["name"].isString()) {
|
||||
std::string title = g_markup_escape_text(node["name"].asString().c_str(), -1);
|
||||
@ -274,10 +274,10 @@ void Workspaces::updateWindows(const Json::Value &node, std::string &windows) {
|
||||
windows.append(m_formatWindowSeparator);
|
||||
}
|
||||
}
|
||||
for (const Json::Value &child : node["nodes"]) {
|
||||
for (const Json::Value& child : node["nodes"]) {
|
||||
updateWindows(child, windows);
|
||||
}
|
||||
for (const Json::Value &child : node["floating_nodes"]) {
|
||||
for (const Json::Value& child : node["floating_nodes"]) {
|
||||
updateWindows(child, windows);
|
||||
}
|
||||
}
|
||||
@ -290,7 +290,7 @@ auto Workspaces::update() -> void {
|
||||
if (bit == buttons_.end()) {
|
||||
needReorder = true;
|
||||
}
|
||||
auto &button = bit == buttons_.end() ? addButton(*it) : bit->second;
|
||||
auto& button = bit == buttons_.end() ? addButton(*it) : bit->second;
|
||||
if (needReorder) {
|
||||
box_.reorder_child(button, it - workspaces_.begin());
|
||||
}
|
||||
@ -344,7 +344,7 @@ auto Workspaces::update() -> void {
|
||||
fmt::arg("output", (*it)["output"].asString()));
|
||||
}
|
||||
if (!config_["disable-markup"].asBool()) {
|
||||
static_cast<Gtk::Label *>(button.get_children()[0])->set_markup(output);
|
||||
static_cast<Gtk::Label*>(button.get_children()[0])->set_markup(output);
|
||||
} else {
|
||||
button.set_label(output);
|
||||
}
|
||||
@ -354,9 +354,9 @@ auto Workspaces::update() -> void {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
||||
Gtk::Button& Workspaces::addButton(const Json::Value& node) {
|
||||
auto pair = buttons_.emplace(node["name"].asString(), node["name"].asString());
|
||||
auto &&button = pair.first->second;
|
||||
auto&& button = pair.first->second;
|
||||
box_.pack_start(button, false, false, 0);
|
||||
button.set_name("sway-workspace-" + node["name"].asString());
|
||||
button.set_relief(Gtk::RELIEF_NONE);
|
||||
@ -375,7 +375,7 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
||||
: "",
|
||||
node["name"].asString()));
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
});
|
||||
@ -383,18 +383,18 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) {
|
||||
return button;
|
||||
}
|
||||
|
||||
std::string Workspaces::getIcon(const std::string &name, const Json::Value &node) {
|
||||
std::string Workspaces::getIcon(const std::string& name, const Json::Value& node) {
|
||||
std::vector<std::string> keys = {"high-priority-named", "urgent", "focused", name, "default"};
|
||||
for (auto const &key : keys) {
|
||||
for (auto const& key : keys) {
|
||||
if (key == "high-priority-named") {
|
||||
auto it = std::find_if(high_priority_named_.begin(), high_priority_named_.end(),
|
||||
[&](const std::string &member) { return member == name; });
|
||||
[&](const std::string& member) { return member == name; });
|
||||
if (it != high_priority_named_.end()) {
|
||||
return config_["format-icons"][name].asString();
|
||||
}
|
||||
|
||||
it = std::find_if(high_priority_named_.begin(), high_priority_named_.end(),
|
||||
[&](const std::string &member) {
|
||||
[&](const std::string& member) {
|
||||
return trimWorkspaceName(member) == trimWorkspaceName(name);
|
||||
});
|
||||
if (it != high_priority_named_.end()) {
|
||||
@ -417,8 +417,8 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node
|
||||
return name;
|
||||
}
|
||||
|
||||
bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||
if (gdk_event_get_pointer_emulated((GdkEvent *)e) != 0) {
|
||||
bool Workspaces::handleScroll(GdkEventScroll* e) {
|
||||
if (gdk_event_get_pointer_emulated((GdkEvent*)e) != 0) {
|
||||
/**
|
||||
* Ignore emulated scroll events on window
|
||||
*/
|
||||
@ -433,7 +433,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||
bool alloutputs = config_["all-outputs"].asBool();
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it =
|
||||
std::find_if(workspaces_.begin(), workspaces_.end(), [alloutputs](const auto &workspace) {
|
||||
std::find_if(workspaces_.begin(), workspaces_.end(), [alloutputs](const auto& workspace) {
|
||||
if (alloutputs) {
|
||||
return hasFlag(workspace, "focused");
|
||||
}
|
||||
@ -460,7 +460,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
||||
}
|
||||
try {
|
||||
ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_cmd_, "--no-auto-back-and-forth", name));
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("Workspaces: {}", e.what());
|
||||
}
|
||||
if (!config_["warp-on-scroll"].isNull() && !config_["warp-on-scroll"].asBool()) {
|
||||
@ -495,7 +495,7 @@ std::string Workspaces::trimWorkspaceName(std::string name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
bool is_focused_recursive(const Json::Value &node) {
|
||||
bool is_focused_recursive(const Json::Value& node) {
|
||||
// If a workspace has a focused container then get_tree will say
|
||||
// that the workspace itself isn't focused. Therefore we need to
|
||||
// check if any of its nodes are focused as well.
|
||||
@ -505,13 +505,13 @@ bool is_focused_recursive(const Json::Value &node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const auto &child : node["nodes"]) {
|
||||
for (const auto& child : node["nodes"]) {
|
||||
if (is_focused_recursive(child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &child : node["floating_nodes"]) {
|
||||
for (const auto& child : node["floating_nodes"]) {
|
||||
if (is_focused_recursive(child)) {
|
||||
return true;
|
||||
}
|
||||
@ -520,7 +520,7 @@ bool is_focused_recursive(const Json::Value &node) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) {
|
||||
void Workspaces::onButtonReady(const Json::Value& node, Gtk::Button& button) {
|
||||
if (config_["current-only"].asBool()) {
|
||||
if (is_focused_recursive(node)) {
|
||||
button.show();
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
UPower::UPower(const std::string &id, const Json::Value &config)
|
||||
UPower::UPower(const std::string& id, const Json::Value& config)
|
||||
: AIconLabel(config, "upower", id, "{percentage}", 0, true, true, true), sleeping_{false} {
|
||||
box_.set_name(name_);
|
||||
box_.set_spacing(0);
|
||||
@ -59,7 +59,7 @@ UPower::UPower(const std::string &id, const Json::Value &config)
|
||||
sigc::mem_fun(*this, &UPower::getConn_cb));
|
||||
|
||||
// Make UPower client
|
||||
GError **gErr = NULL;
|
||||
GError** gErr = NULL;
|
||||
upClient_ = up_client_new_full(NULL, gErr);
|
||||
if (upClient_ == NULL)
|
||||
spdlog::error("Upower. UPower client connection error. {}", (*gErr)->message);
|
||||
@ -92,7 +92,7 @@ UPower::~UPower() {
|
||||
removeDevices();
|
||||
}
|
||||
|
||||
static const std::string getDeviceStatus(UpDeviceState &state) {
|
||||
static const std::string getDeviceStatus(UpDeviceState& state) {
|
||||
switch (state) {
|
||||
case UP_DEVICE_STATE_CHARGING:
|
||||
case UP_DEVICE_STATE_PENDING_CHARGE:
|
||||
@ -109,7 +109,7 @@ static const std::string getDeviceStatus(UpDeviceState &state) {
|
||||
}
|
||||
}
|
||||
|
||||
static const std::string getDeviceIcon(UpDeviceKind &kind) {
|
||||
static const std::string getDeviceIcon(UpDeviceKind& kind) {
|
||||
switch (kind) {
|
||||
case UP_DEVICE_KIND_LINE_POWER:
|
||||
return "ac-adapter-symbolic";
|
||||
@ -222,7 +222,7 @@ auto UPower::update() -> void {
|
||||
label_.set_markup(getText(upDevice_, format_));
|
||||
// Set icon
|
||||
if (upDevice_.icon_name == NULL || !gtkTheme_->has_icon(upDevice_.icon_name))
|
||||
upDevice_.icon_name = (char *)NO_BATTERY.c_str();
|
||||
upDevice_.icon_name = (char*)NO_BATTERY.c_str();
|
||||
image_.set_from_icon_name(upDevice_.icon_name, Gtk::ICON_SIZE_INVALID);
|
||||
|
||||
box_.show();
|
||||
@ -231,7 +231,7 @@ auto UPower::update() -> void {
|
||||
ALabel::update();
|
||||
}
|
||||
|
||||
void UPower::getConn_cb(Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||
void UPower::getConn_cb(Glib::RefPtr<Gio::AsyncResult>& result) {
|
||||
try {
|
||||
conn_ = Gio::DBus::Connection::get_finish(result);
|
||||
// Subscribe DBUs events
|
||||
@ -239,26 +239,26 @@ void UPower::getConn_cb(Glib::RefPtr<Gio::AsyncResult> &result) {
|
||||
"org.freedesktop.login1", "org.freedesktop.login1.Manager",
|
||||
"PrepareForSleep", "/org/freedesktop/login1");
|
||||
|
||||
} catch (const Glib::Error &e) {
|
||||
} catch (const Glib::Error& e) {
|
||||
spdlog::error("Upower. DBus connection error. {}", e.what().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void UPower::onAppear(const Glib::RefPtr<Gio::DBus::Connection> &conn, const Glib::ustring &name,
|
||||
const Glib::ustring &name_owner) {
|
||||
void UPower::onAppear(const Glib::RefPtr<Gio::DBus::Connection>& conn, const Glib::ustring& name,
|
||||
const Glib::ustring& name_owner) {
|
||||
upRunning_ = true;
|
||||
}
|
||||
|
||||
void UPower::onVanished(const Glib::RefPtr<Gio::DBus::Connection> &conn,
|
||||
const Glib::ustring &name) {
|
||||
void UPower::onVanished(const Glib::RefPtr<Gio::DBus::Connection>& conn,
|
||||
const Glib::ustring& name) {
|
||||
upRunning_ = false;
|
||||
}
|
||||
|
||||
void UPower::prepareForSleep_cb(const Glib::RefPtr<Gio::DBus::Connection> &connection,
|
||||
const Glib::ustring &sender_name, const Glib::ustring &object_path,
|
||||
const Glib::ustring &interface_name,
|
||||
const Glib::ustring &signal_name,
|
||||
const Glib::VariantContainerBase ¶meters) {
|
||||
void UPower::prepareForSleep_cb(const Glib::RefPtr<Gio::DBus::Connection>& connection,
|
||||
const Glib::ustring& sender_name, const Glib::ustring& object_path,
|
||||
const Glib::ustring& interface_name,
|
||||
const Glib::ustring& signal_name,
|
||||
const Glib::VariantContainerBase& parameters) {
|
||||
if (parameters.is_of_type(Glib::VariantType("(b)"))) {
|
||||
Glib::Variant<bool> sleeping;
|
||||
parameters.get_child(sleeping, 0);
|
||||
@ -273,33 +273,33 @@ void UPower::prepareForSleep_cb(const Glib::RefPtr<Gio::DBus::Connection> &conne
|
||||
}
|
||||
}
|
||||
|
||||
void UPower::deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data) {
|
||||
UPower *up{static_cast<UPower *>(data)};
|
||||
void UPower::deviceAdded_cb(UpClient* client, UpDevice* device, gpointer data) {
|
||||
UPower* up{static_cast<UPower*>(data)};
|
||||
up->addDevice(device);
|
||||
up->setDisplayDevice();
|
||||
// Update the widget
|
||||
up->dp.emit();
|
||||
}
|
||||
|
||||
void UPower::deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data) {
|
||||
UPower *up{static_cast<UPower *>(data)};
|
||||
void UPower::deviceRemoved_cb(UpClient* client, const gchar* objectPath, gpointer data) {
|
||||
UPower* up{static_cast<UPower*>(data)};
|
||||
up->removeDevice(objectPath);
|
||||
up->setDisplayDevice();
|
||||
// Update the widget
|
||||
up->dp.emit();
|
||||
}
|
||||
|
||||
void UPower::deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer data) {
|
||||
UPower *up{static_cast<UPower *>(data)};
|
||||
void UPower::deviceNotify_cb(UpDevice* device, GParamSpec* pspec, gpointer data) {
|
||||
UPower* up{static_cast<UPower*>(data)};
|
||||
// Update the widget
|
||||
up->dp.emit();
|
||||
}
|
||||
|
||||
void UPower::addDevice(UpDevice *device) {
|
||||
void UPower::addDevice(UpDevice* device) {
|
||||
std::lock_guard<std::mutex> guard{mutex_};
|
||||
|
||||
if (G_IS_OBJECT(device)) {
|
||||
const gchar *objectPath{up_device_get_object_path(device)};
|
||||
const gchar* objectPath{up_device_get_object_path(device)};
|
||||
|
||||
// Due to the device getting cleared after this event is fired, we
|
||||
// create a new object pointing to its objectPath
|
||||
@ -322,7 +322,7 @@ void UPower::addDevice(UpDevice *device) {
|
||||
}
|
||||
}
|
||||
|
||||
void UPower::removeDevice(const gchar *objectPath) {
|
||||
void UPower::removeDevice(const gchar* objectPath) {
|
||||
std::lock_guard<std::mutex> guard{mutex_};
|
||||
if (devices_.find(objectPath) != devices_.cend()) {
|
||||
auto upDevice{devices_[objectPath]};
|
||||
@ -348,10 +348,10 @@ void UPower::resetDevices() {
|
||||
removeDevices();
|
||||
|
||||
// Adds all devices
|
||||
GPtrArray *newDevices = up_client_get_devices2(upClient_);
|
||||
GPtrArray* newDevices = up_client_get_devices2(upClient_);
|
||||
if (newDevices != NULL)
|
||||
for (guint i{0}; i < newDevices->len; ++i) {
|
||||
UpDevice *device{(UpDevice *)g_ptr_array_index(newDevices, i)};
|
||||
UpDevice* device{(UpDevice*)g_ptr_array_index(newDevices, i)};
|
||||
if (device && G_IS_OBJECT(device)) addDevice(device);
|
||||
}
|
||||
}
|
||||
@ -372,8 +372,8 @@ void UPower::setDisplayDevice() {
|
||||
up_client_get_devices2(upClient_),
|
||||
[](gpointer data, gpointer user_data) {
|
||||
upDevice_output upDevice;
|
||||
auto thisPtr{static_cast<UPower *>(user_data)};
|
||||
upDevice.upDevice = static_cast<UpDevice *>(data);
|
||||
auto thisPtr{static_cast<UPower*>(user_data)};
|
||||
upDevice.upDevice = static_cast<UpDevice*>(data);
|
||||
thisPtr->getUpDeviceInfo(upDevice);
|
||||
upDevice_output displayDevice{NULL};
|
||||
if (!thisPtr->nativePath_.empty()) {
|
||||
@ -399,7 +399,7 @@ void UPower::setDisplayDevice() {
|
||||
g_signal_connect(upDevice_.upDevice, "notify", G_CALLBACK(deviceNotify_cb), this);
|
||||
}
|
||||
|
||||
void UPower::getUpDeviceInfo(upDevice_output &upDevice_) {
|
||||
void UPower::getUpDeviceInfo(upDevice_output& upDevice_) {
|
||||
if (upDevice_.upDevice != NULL && G_IS_OBJECT(upDevice_.upDevice)) {
|
||||
g_object_get(upDevice_.upDevice, "kind", &upDevice_.kind, "state", &upDevice_.state,
|
||||
"percentage", &upDevice_.percentage, "icon-name", &upDevice_.icon_name,
|
||||
@ -416,7 +416,7 @@ native_path: \"{7}\". model: \"{8}\"",
|
||||
}
|
||||
}
|
||||
|
||||
const Glib::ustring UPower::getText(const upDevice_output &upDevice_, const std::string &format) {
|
||||
const Glib::ustring UPower::getText(const upDevice_output& upDevice_, const std::string& format) {
|
||||
Glib::ustring ret{""};
|
||||
if (upDevice_.upDevice != NULL) {
|
||||
std::string timeStr{""};
|
||||
@ -445,11 +445,11 @@ const Glib::ustring UPower::getText(const upDevice_output &upDevice_, const std:
|
||||
}
|
||||
|
||||
bool UPower::queryTooltipCb(int x, int y, bool keyboard_tooltip,
|
||||
const Glib::RefPtr<Gtk::Tooltip> &tooltip) {
|
||||
const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
|
||||
std::lock_guard<std::mutex> guard{mutex_};
|
||||
|
||||
// Clear content box
|
||||
contentBox_.forall([this](Gtk::Widget &wg) { contentBox_.remove(wg); });
|
||||
contentBox_.forall([this](Gtk::Widget& wg) { contentBox_.remove(wg); });
|
||||
|
||||
// Fill content box with the content
|
||||
for (auto pairDev : devices_) {
|
||||
@ -459,33 +459,33 @@ bool UPower::queryTooltipCb(int x, int y, bool keyboard_tooltip,
|
||||
if (pairDev.second.kind != UpDeviceKind::UP_DEVICE_KIND_UNKNOWN &&
|
||||
pairDev.second.kind != UpDeviceKind::UP_DEVICE_KIND_LINE_POWER) {
|
||||
// Make box record
|
||||
Gtk::Box *boxRec{new Gtk::Box{box_.get_orientation(), tooltip_spacing_}};
|
||||
Gtk::Box* boxRec{new Gtk::Box{box_.get_orientation(), tooltip_spacing_}};
|
||||
contentBox_.add(*boxRec);
|
||||
Gtk::Box *boxDev{new Gtk::Box{box_.get_orientation()}};
|
||||
Gtk::Box *boxUsr{new Gtk::Box{box_.get_orientation()}};
|
||||
Gtk::Box* boxDev{new Gtk::Box{box_.get_orientation()}};
|
||||
Gtk::Box* boxUsr{new Gtk::Box{box_.get_orientation()}};
|
||||
boxRec->add(*boxDev);
|
||||
boxRec->add(*boxUsr);
|
||||
// Construct device box
|
||||
// Set icon from kind
|
||||
std::string iconNameDev{getDeviceIcon(pairDev.second.kind)};
|
||||
if (!gtkTheme_->has_icon(iconNameDev)) iconNameDev = (char *)NO_BATTERY.c_str();
|
||||
Gtk::Image *iconDev{new Gtk::Image{}};
|
||||
if (!gtkTheme_->has_icon(iconNameDev)) iconNameDev = (char*)NO_BATTERY.c_str();
|
||||
Gtk::Image* iconDev{new Gtk::Image{}};
|
||||
iconDev->set_from_icon_name(iconNameDev, Gtk::ICON_SIZE_INVALID);
|
||||
iconDev->set_pixel_size(iconSize_);
|
||||
boxDev->add(*iconDev);
|
||||
// Set label from model
|
||||
Gtk::Label *labelDev{new Gtk::Label{pairDev.second.model}};
|
||||
Gtk::Label* labelDev{new Gtk::Label{pairDev.second.model}};
|
||||
boxDev->add(*labelDev);
|
||||
// Construct user box
|
||||
// Set icon from icon state
|
||||
if (pairDev.second.icon_name == NULL || !gtkTheme_->has_icon(pairDev.second.icon_name))
|
||||
pairDev.second.icon_name = (char *)NO_BATTERY.c_str();
|
||||
Gtk::Image *iconTooltip{new Gtk::Image{}};
|
||||
pairDev.second.icon_name = (char*)NO_BATTERY.c_str();
|
||||
Gtk::Image* iconTooltip{new Gtk::Image{}};
|
||||
iconTooltip->set_from_icon_name(pairDev.second.icon_name, Gtk::ICON_SIZE_INVALID);
|
||||
iconTooltip->set_pixel_size(iconSize_);
|
||||
boxUsr->add(*iconTooltip);
|
||||
// Set markup text
|
||||
Gtk::Label *labelTooltip{new Gtk::Label{}};
|
||||
Gtk::Label* labelTooltip{new Gtk::Label{}};
|
||||
labelTooltip->set_markup(getText(pairDev.second, tooltipFormat_));
|
||||
boxUsr->add(*labelTooltip);
|
||||
}
|
||||
|
||||
@ -29,42 +29,42 @@ namespace waybar::modules::wlr {
|
||||
/* Task class implementation */
|
||||
uint32_t Task::global_id = 0;
|
||||
|
||||
static void tl_handle_title(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle,
|
||||
const char *title) {
|
||||
return static_cast<Task *>(data)->handle_title(title);
|
||||
static void tl_handle_title(void* data, struct zwlr_foreign_toplevel_handle_v1* handle,
|
||||
const char* title) {
|
||||
return static_cast<Task*>(data)->handle_title(title);
|
||||
}
|
||||
|
||||
static void tl_handle_app_id(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle,
|
||||
const char *app_id) {
|
||||
return static_cast<Task *>(data)->handle_app_id(app_id);
|
||||
static void tl_handle_app_id(void* data, struct zwlr_foreign_toplevel_handle_v1* handle,
|
||||
const char* app_id) {
|
||||
return static_cast<Task*>(data)->handle_app_id(app_id);
|
||||
}
|
||||
|
||||
static void tl_handle_output_enter(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle,
|
||||
struct wl_output *output) {
|
||||
return static_cast<Task *>(data)->handle_output_enter(output);
|
||||
static void tl_handle_output_enter(void* data, struct zwlr_foreign_toplevel_handle_v1* handle,
|
||||
struct wl_output* output) {
|
||||
return static_cast<Task*>(data)->handle_output_enter(output);
|
||||
}
|
||||
|
||||
static void tl_handle_output_leave(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle,
|
||||
struct wl_output *output) {
|
||||
return static_cast<Task *>(data)->handle_output_leave(output);
|
||||
static void tl_handle_output_leave(void* data, struct zwlr_foreign_toplevel_handle_v1* handle,
|
||||
struct wl_output* output) {
|
||||
return static_cast<Task*>(data)->handle_output_leave(output);
|
||||
}
|
||||
|
||||
static void tl_handle_state(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle,
|
||||
struct wl_array *state) {
|
||||
return static_cast<Task *>(data)->handle_state(state);
|
||||
static void tl_handle_state(void* data, struct zwlr_foreign_toplevel_handle_v1* handle,
|
||||
struct wl_array* state) {
|
||||
return static_cast<Task*>(data)->handle_state(state);
|
||||
}
|
||||
|
||||
static void tl_handle_done(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle) {
|
||||
return static_cast<Task *>(data)->handle_done();
|
||||
static void tl_handle_done(void* data, struct zwlr_foreign_toplevel_handle_v1* handle) {
|
||||
return static_cast<Task*>(data)->handle_done();
|
||||
}
|
||||
|
||||
static void tl_handle_parent(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle,
|
||||
struct zwlr_foreign_toplevel_handle_v1 *parent) {
|
||||
static void tl_handle_parent(void* data, struct zwlr_foreign_toplevel_handle_v1* handle,
|
||||
struct zwlr_foreign_toplevel_handle_v1* parent) {
|
||||
/* This is explicitly left blank */
|
||||
}
|
||||
|
||||
static void tl_handle_closed(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle) {
|
||||
return static_cast<Task *>(data)->handle_closed();
|
||||
static void tl_handle_closed(void* data, struct zwlr_foreign_toplevel_handle_v1* handle) {
|
||||
return static_cast<Task*>(data)->handle_closed();
|
||||
}
|
||||
|
||||
static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_impl = {
|
||||
@ -81,8 +81,8 @@ static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_imp
|
||||
static const std::vector<Gtk::TargetEntry> target_entries = {
|
||||
Gtk::TargetEntry("WAYBAR_TOPLEVEL", Gtk::TARGET_SAME_APP, 0)};
|
||||
|
||||
Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
|
||||
struct zwlr_foreign_toplevel_handle_v1 *tl_handle, struct wl_seat *seat)
|
||||
Task::Task(const waybar::Bar& bar, const Json::Value& config, Taskbar* tbar,
|
||||
struct zwlr_foreign_toplevel_handle_v1* tl_handle, struct wl_seat* seat)
|
||||
: bar_{bar},
|
||||
config_{config},
|
||||
tbar_{tbar},
|
||||
@ -189,7 +189,7 @@ std::string Task::state_string(bool shortened) const {
|
||||
return res.substr(0, res.size() - 1);
|
||||
}
|
||||
|
||||
void Task::handle_title(const char *title) {
|
||||
void Task::handle_title(const char* title) {
|
||||
if (title_.empty()) {
|
||||
spdlog::debug(fmt::format("Task ({}) setting title to {}", id_, title_));
|
||||
} else {
|
||||
@ -238,7 +238,7 @@ void Task::hide_if_ignored() {
|
||||
}
|
||||
}
|
||||
|
||||
void Task::handle_app_id(const char *app_id) {
|
||||
void Task::handle_app_id(const char* app_id) {
|
||||
if (app_id_.empty()) {
|
||||
spdlog::debug(fmt::format("Task ({}) setting app_id to {}", id_, app_id));
|
||||
} else {
|
||||
@ -273,20 +273,20 @@ void Task::handle_app_id(const char *app_id) {
|
||||
spdlog::debug("Couldn't find icon for {}", app_id_);
|
||||
}
|
||||
|
||||
void Task::on_button_size_allocated(Gtk::Allocation &alloc) {
|
||||
void Task::on_button_size_allocated(Gtk::Allocation& alloc) {
|
||||
gtk_widget_translate_coordinates(GTK_WIDGET(button.gobj()), GTK_WIDGET(bar_.window.gobj()), 0, 0,
|
||||
&minimize_hint.x, &minimize_hint.y);
|
||||
minimize_hint.w = button.get_width();
|
||||
minimize_hint.h = button.get_height();
|
||||
}
|
||||
|
||||
void Task::handle_output_enter(struct wl_output *output) {
|
||||
void Task::handle_output_enter(struct wl_output* output) {
|
||||
if (ignored_) {
|
||||
spdlog::debug("{} is ignored", repr());
|
||||
return;
|
||||
}
|
||||
|
||||
spdlog::debug("{} entered output {}", repr(), (void *)output);
|
||||
spdlog::debug("{} entered output {}", repr(), (void*)output);
|
||||
|
||||
if (!button_visible_ && (tbar_->all_outputs() || tbar_->show_output(output))) {
|
||||
/* The task entered the output of the current bar make the button visible */
|
||||
@ -299,8 +299,8 @@ void Task::handle_output_enter(struct wl_output *output) {
|
||||
}
|
||||
}
|
||||
|
||||
void Task::handle_output_leave(struct wl_output *output) {
|
||||
spdlog::debug("{} left output {}", repr(), (void *)output);
|
||||
void Task::handle_output_leave(struct wl_output* output) {
|
||||
spdlog::debug("{} left output {}", repr(), (void*)output);
|
||||
|
||||
if (button_visible_ && !tbar_->all_outputs() && tbar_->show_output(output)) {
|
||||
/* The task left the output of the current bar, make the button invisible */
|
||||
@ -311,11 +311,11 @@ void Task::handle_output_leave(struct wl_output *output) {
|
||||
}
|
||||
}
|
||||
|
||||
void Task::handle_state(struct wl_array *state) {
|
||||
void Task::handle_state(struct wl_array* state) {
|
||||
state_ = 0;
|
||||
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];
|
||||
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) state_ |= MINIMIZED;
|
||||
if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED) state_ |= ACTIVE;
|
||||
@ -367,7 +367,7 @@ void Task::handle_closed() {
|
||||
tbar_->remove_task(id_);
|
||||
}
|
||||
|
||||
bool Task::handle_clicked(GdkEventButton *bt) {
|
||||
bool Task::handle_clicked(GdkEventButton* bt) {
|
||||
/* filter out additional events for double/triple clicks */
|
||||
if (bt->type == GDK_BUTTON_PRESS) {
|
||||
/* save where the button press occurred in case it becomes a drag */
|
||||
@ -412,7 +412,7 @@ bool Task::handle_clicked(GdkEventButton *bt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Task::handle_motion_notify(GdkEventMotion *mn) {
|
||||
bool Task::handle_motion_notify(GdkEventMotion* mn) {
|
||||
if (drag_start_button == -1) return false;
|
||||
|
||||
if (button.drag_check_threshold(drag_start_x, drag_start_y, mn->x, mn->y)) {
|
||||
@ -420,25 +420,25 @@ bool Task::handle_motion_notify(GdkEventMotion *mn) {
|
||||
auto target_list = Gtk::TargetList::create(target_entries);
|
||||
auto refptr = Glib::RefPtr<Gtk::TargetList>(target_list);
|
||||
auto drag_context =
|
||||
button.drag_begin(refptr, Gdk::DragAction::ACTION_MOVE, drag_start_button, (GdkEvent *)mn);
|
||||
button.drag_begin(refptr, Gdk::DragAction::ACTION_MOVE, drag_start_button, (GdkEvent*)mn);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Task::handle_drag_data_get(const Glib::RefPtr<Gdk::DragContext> &context,
|
||||
Gtk::SelectionData &selection_data, guint info, guint time) {
|
||||
void Task::handle_drag_data_get(const Glib::RefPtr<Gdk::DragContext>& context,
|
||||
Gtk::SelectionData& selection_data, guint info, guint time) {
|
||||
spdlog::debug("drag_data_get");
|
||||
void *button_addr = (void *)&this->button;
|
||||
void* button_addr = (void*)&this->button;
|
||||
|
||||
selection_data.set("WAYBAR_TOPLEVEL", 32, (const guchar *)&button_addr, sizeof(gpointer));
|
||||
selection_data.set("WAYBAR_TOPLEVEL", 32, (const guchar*)&button_addr, sizeof(gpointer));
|
||||
}
|
||||
|
||||
void Task::handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &context, int x, int y,
|
||||
void Task::handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
|
||||
Gtk::SelectionData selection_data, guint info, guint time) {
|
||||
spdlog::debug("drag_data_received");
|
||||
gpointer handle = *(gpointer *)selection_data.get_data();
|
||||
auto dragged_button = (Gtk::Button *)handle;
|
||||
gpointer handle = *(gpointer*)selection_data.get_data();
|
||||
auto dragged_button = (Gtk::Button*)handle;
|
||||
|
||||
if (dragged_button == &this->button) return;
|
||||
|
||||
@ -447,7 +447,7 @@ void Task::handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &conte
|
||||
|
||||
if (parent_of_dragged != parent_of_dest) return;
|
||||
|
||||
auto box = (Gtk::Box *)parent_of_dragged;
|
||||
auto box = (Gtk::Box*)parent_of_dragged;
|
||||
|
||||
auto position_prop = box->child_property_position(this->button);
|
||||
auto position = position_prop.get_value();
|
||||
@ -455,9 +455,9 @@ void Task::handle_drag_data_received(const Glib::RefPtr<Gdk::DragContext> &conte
|
||||
box->reorder_child(*dragged_button, position);
|
||||
}
|
||||
|
||||
bool Task::operator==(const Task &o) const { return o.id_ == id_; }
|
||||
bool Task::operator==(const Task& o) const { return o.id_ == id_; }
|
||||
|
||||
bool Task::operator!=(const Task &o) const { return o.id_ != id_; }
|
||||
bool Task::operator!=(const Task& o) const { return o.id_ != id_; }
|
||||
|
||||
void Task::update() {
|
||||
bool markup = config_["markup"].isBool() ? config_["markup"].asBool() : false;
|
||||
@ -545,23 +545,23 @@ void Task::fullscreen(bool set) {
|
||||
void Task::close() { zwlr_foreign_toplevel_handle_v1_close(handle_); }
|
||||
|
||||
/* Taskbar class implementation */
|
||||
static void handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
static void handle_global(void* data, struct wl_registry* registry, uint32_t name,
|
||||
const char* interface, uint32_t version) {
|
||||
if (std::strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0) {
|
||||
static_cast<Taskbar *>(data)->register_manager(registry, name, version);
|
||||
static_cast<Taskbar*>(data)->register_manager(registry, name, version);
|
||||
} else if (std::strcmp(interface, wl_seat_interface.name) == 0) {
|
||||
static_cast<Taskbar *>(data)->register_seat(registry, name, version);
|
||||
static_cast<Taskbar*>(data)->register_seat(registry, name, version);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) {
|
||||
static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) {
|
||||
/* Nothing to do here */
|
||||
}
|
||||
|
||||
static const wl_registry_listener registry_listener_impl = {.global = handle_global,
|
||||
.global_remove = handle_global_remove};
|
||||
|
||||
Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
|
||||
Taskbar::Taskbar(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
||||
: waybar::AModule(config, "taskbar", id, false, false),
|
||||
bar_(bar),
|
||||
box_{bar.orientation, 0},
|
||||
@ -575,8 +575,8 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
|
||||
box_.get_style_context()->add_class("empty");
|
||||
event_box_.add(box_);
|
||||
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
struct wl_registry *registry = wl_display_get_registry(display);
|
||||
struct wl_display* display = Client::inst()->wl_display;
|
||||
struct wl_registry* registry = wl_display_get_registry(display);
|
||||
|
||||
wl_registry_add_listener(registry, ®istry_listener_impl, this);
|
||||
wl_display_roundtrip(display);
|
||||
@ -592,7 +592,7 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
|
||||
|
||||
/* Get the configured icon theme if specified */
|
||||
if (config_["icon-theme"].isArray()) {
|
||||
for (auto &c : config_["icon-theme"]) {
|
||||
for (auto& c : config_["icon-theme"]) {
|
||||
icon_loader_.add_custom_icon_theme(c.asString());
|
||||
}
|
||||
} else if (config_["icon-theme"].isString()) {
|
||||
@ -601,28 +601,28 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
|
||||
|
||||
// Load ignore-list
|
||||
if (config_["ignore-list"].isArray()) {
|
||||
for (auto &app_name : config_["ignore-list"]) {
|
||||
for (auto& app_name : config_["ignore-list"]) {
|
||||
ignore_list_.emplace(app_name.asString());
|
||||
}
|
||||
}
|
||||
|
||||
// Load app_id remappings
|
||||
if (config_["app_ids-mapping"].isObject()) {
|
||||
const Json::Value &mapping = config_["app_ids-mapping"];
|
||||
const Json::Value& mapping = config_["app_ids-mapping"];
|
||||
const std::vector<std::string> app_ids = config_["app_ids-mapping"].getMemberNames();
|
||||
for (auto &app_id : app_ids) {
|
||||
for (auto& app_id : app_ids) {
|
||||
app_ids_replace_map_.emplace(app_id, mapping[app_id].asString());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &t : tasks_) {
|
||||
for (auto& t : tasks_) {
|
||||
t->handle_app_id(t->app_id().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Taskbar::~Taskbar() {
|
||||
if (manager_) {
|
||||
struct wl_display *display = Client::inst()->wl_display;
|
||||
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,
|
||||
@ -640,13 +640,13 @@ Taskbar::~Taskbar() {
|
||||
}
|
||||
|
||||
void Taskbar::update() {
|
||||
for (auto &t : tasks_) {
|
||||
for (auto& t : tasks_) {
|
||||
t->update();
|
||||
}
|
||||
|
||||
if (config_["sort-by-app-id"].asBool()) {
|
||||
std::stable_sort(tasks_.begin(), tasks_.end(),
|
||||
[](const std::unique_ptr<Task> &a, const std::unique_ptr<Task> &b) {
|
||||
[](const std::unique_ptr<Task>& a, const std::unique_ptr<Task>& b) {
|
||||
return a->app_id() < b->app_id();
|
||||
});
|
||||
|
||||
@ -658,13 +658,13 @@ void Taskbar::update() {
|
||||
AModule::update();
|
||||
}
|
||||
|
||||
static void tm_handle_toplevel(void *data, struct zwlr_foreign_toplevel_manager_v1 *manager,
|
||||
struct zwlr_foreign_toplevel_handle_v1 *tl_handle) {
|
||||
return static_cast<Taskbar *>(data)->handle_toplevel_create(tl_handle);
|
||||
static void tm_handle_toplevel(void* data, struct zwlr_foreign_toplevel_manager_v1* manager,
|
||||
struct zwlr_foreign_toplevel_handle_v1* tl_handle) {
|
||||
return static_cast<Taskbar*>(data)->handle_toplevel_create(tl_handle);
|
||||
}
|
||||
|
||||
static void tm_handle_finished(void *data, struct zwlr_foreign_toplevel_manager_v1 *manager) {
|
||||
return static_cast<Taskbar *>(data)->handle_finished();
|
||||
static void tm_handle_finished(void* data, struct zwlr_foreign_toplevel_manager_v1* manager) {
|
||||
return static_cast<Taskbar*>(data)->handle_finished();
|
||||
}
|
||||
|
||||
static const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_impl = {
|
||||
@ -672,7 +672,7 @@ static const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_i
|
||||
.finished = tm_handle_finished,
|
||||
};
|
||||
|
||||
void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint32_t version) {
|
||||
void Taskbar::register_manager(struct wl_registry* registry, uint32_t name, uint32_t version) {
|
||||
if (manager_) {
|
||||
spdlog::warn("Register foreign toplevel manager again although already existing!");
|
||||
return;
|
||||
@ -687,7 +687,7 @@ void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint
|
||||
// limit version to a highest supported by the client protocol file
|
||||
version = std::min<uint32_t>(version, zwlr_foreign_toplevel_manager_v1_interface.version);
|
||||
|
||||
manager_ = static_cast<struct zwlr_foreign_toplevel_manager_v1 *>(
|
||||
manager_ = static_cast<struct zwlr_foreign_toplevel_manager_v1*>(
|
||||
wl_registry_bind(registry, name, &zwlr_foreign_toplevel_manager_v1_interface, version));
|
||||
|
||||
if (manager_)
|
||||
@ -696,17 +696,17 @@ void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint
|
||||
spdlog::debug("Failed to register manager");
|
||||
}
|
||||
|
||||
void Taskbar::register_seat(struct wl_registry *registry, uint32_t name, uint32_t version) {
|
||||
void Taskbar::register_seat(struct wl_registry* registry, uint32_t name, uint32_t version) {
|
||||
if (seat_) {
|
||||
spdlog::warn("Register seat again although already existing!");
|
||||
return;
|
||||
}
|
||||
version = std::min<uint32_t>(version, wl_seat_interface.version);
|
||||
|
||||
seat_ = static_cast<wl_seat *>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
seat_ = static_cast<wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
}
|
||||
|
||||
void Taskbar::handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1 *tl_handle) {
|
||||
void Taskbar::handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1* tl_handle) {
|
||||
tasks_.push_back(std::make_unique<Task>(bar_, config_, this, tl_handle, seat_));
|
||||
}
|
||||
|
||||
@ -715,14 +715,14 @@ void Taskbar::handle_finished() {
|
||||
manager_ = nullptr;
|
||||
}
|
||||
|
||||
void Taskbar::add_button(Gtk::Button &bt) {
|
||||
void Taskbar::add_button(Gtk::Button& bt) {
|
||||
box_.pack_start(bt, false, false);
|
||||
box_.get_style_context()->remove_class("empty");
|
||||
}
|
||||
|
||||
void Taskbar::move_button(Gtk::Button &bt, int pos) { box_.reorder_child(bt, pos); }
|
||||
void Taskbar::move_button(Gtk::Button& bt, int pos) { box_.reorder_child(bt, pos); }
|
||||
|
||||
void Taskbar::remove_button(Gtk::Button &bt) {
|
||||
void Taskbar::remove_button(Gtk::Button& bt) {
|
||||
box_.remove(bt);
|
||||
if (box_.get_children().empty()) {
|
||||
box_.get_style_context()->add_class("empty");
|
||||
@ -731,7 +731,7 @@ void Taskbar::remove_button(Gtk::Button &bt) {
|
||||
|
||||
void Taskbar::remove_task(uint32_t id) {
|
||||
auto it = std::find_if(std::begin(tasks_), std::end(tasks_),
|
||||
[id](const TaskPtr &p) { return p->id() == id; });
|
||||
[id](const TaskPtr& p) { return p->id() == id; });
|
||||
|
||||
if (it == std::end(tasks_)) {
|
||||
spdlog::warn("Can't find task with id {}", id);
|
||||
@ -741,7 +741,7 @@ void Taskbar::remove_task(uint32_t id) {
|
||||
tasks_.erase(it);
|
||||
}
|
||||
|
||||
bool Taskbar::show_output(struct wl_output *output) const {
|
||||
bool Taskbar::show_output(struct wl_output* output) const {
|
||||
return output == gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj());
|
||||
}
|
||||
|
||||
@ -749,11 +749,11 @@ bool Taskbar::all_outputs() const {
|
||||
return config_["all-outputs"].isBool() && config_["all-outputs"].asBool();
|
||||
}
|
||||
|
||||
const IconLoader &Taskbar::icon_loader() const { return icon_loader_; }
|
||||
const IconLoader& Taskbar::icon_loader() const { return icon_loader_; }
|
||||
|
||||
const std::unordered_set<std::string> &Taskbar::ignore_list() const { return ignore_list_; }
|
||||
const std::unordered_set<std::string>& Taskbar::ignore_list() const { return ignore_list_; }
|
||||
|
||||
const std::map<std::string, std::string> &Taskbar::app_ids_replace_map() const {
|
||||
const std::map<std::string, std::string>& Taskbar::app_ids_replace_map() const {
|
||||
return app_ids_replace_map_;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user