mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(Bar): handle widget size changes
This commit is contained in:
@ -8,14 +8,14 @@ Mode::Mode(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
if (!id.empty()) {
|
||||
label_.get_style_context()->add_class(id);
|
||||
}
|
||||
ipc_.subscribe("[ \"mode\" ]");
|
||||
ipc_.subscribe(R"(["mode"])");
|
||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
|
||||
// Launch worker
|
||||
worker();
|
||||
dp.emit();
|
||||
}
|
||||
|
||||
void Mode::onEvent(const struct Ipc::ipc_response res) {
|
||||
void Mode::onEvent(const struct Ipc::ipc_response &res) {
|
||||
if (res.payload["change"] != "default") {
|
||||
mode_ = res.payload["change"].asString();
|
||||
} else {
|
||||
|
@ -12,7 +12,7 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
label_.set_hexpand(true);
|
||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||
}
|
||||
ipc_.subscribe("[\"window\",\"workspace\"]");
|
||||
ipc_.subscribe(R"(["window","workspace"])");
|
||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
||||
getFocusedWindow();
|
||||
@ -20,7 +20,7 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||
worker();
|
||||
}
|
||||
|
||||
void Window::onEvent(const struct Ipc::ipc_response res) {
|
||||
void Window::onEvent(const struct Ipc::ipc_response& res) {
|
||||
auto data = res.payload;
|
||||
// Check for waybar prevents flicker when hovering window module
|
||||
if ((data["change"] == "focus" || data["change"] == "title") &&
|
||||
@ -38,7 +38,7 @@ void Window::onEvent(const struct Ipc::ipc_response res) {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::onCmd(const struct Ipc::ipc_response res) {
|
||||
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||
auto [id, name] = getFocusedNode(res.payload["nodes"]);
|
||||
windowId_ = id;
|
||||
window_ = name;
|
||||
@ -62,7 +62,7 @@ auto Window::update() -> void {
|
||||
}
|
||||
}
|
||||
|
||||
std::tuple<int, std::string> Window::getFocusedNode(Json::Value nodes) {
|
||||
std::tuple<int, std::string> Window::getFocusedNode(const Json::Value& nodes) {
|
||||
for (auto const& node : nodes) {
|
||||
if (node["focused"].asBool() && node["type"] == "con") {
|
||||
return {node["id"].asInt(), node["name"].asString()};
|
||||
|
@ -11,7 +11,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
if (!id.empty()) {
|
||||
box_.get_style_context()->add_class(id);
|
||||
}
|
||||
ipc_.subscribe("[ \"workspace\" ]");
|
||||
ipc_.subscribe(R"(["workspace"])");
|
||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
|
||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd));
|
||||
ipc_.sendCmd(IPC_GET_WORKSPACES);
|
||||
@ -19,9 +19,9 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||
worker();
|
||||
}
|
||||
|
||||
void Workspaces::onEvent(const struct Ipc::ipc_response res) { ipc_.sendCmd(IPC_GET_WORKSPACES); }
|
||||
void Workspaces::onEvent(const struct Ipc::ipc_response &res) { ipc_.sendCmd(IPC_GET_WORKSPACES); }
|
||||
|
||||
void Workspaces::onCmd(const struct Ipc::ipc_response res) {
|
||||
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||
if (res.type == IPC_GET_WORKSPACES) {
|
||||
if (res.payload.isArray()) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@ -209,7 +209,7 @@ const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterat
|
||||
}
|
||||
|
||||
std::string Workspaces::trimWorkspaceName(std::string name) {
|
||||
std::size_t found = name.find(":");
|
||||
std::size_t found = name.find(':');
|
||||
if (found != std::string::npos) {
|
||||
return name.substr(found + 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user