fix(Workspaces): button order
This commit is contained in:
parent
60af51fc17
commit
add9e925f4
|
@ -2,4 +2,4 @@ FROM opensuse/tumbleweed:latest
|
||||||
|
|
||||||
RUN zypper -n up && \
|
RUN zypper -n up && \
|
||||||
zypper -n install -t pattern devel_C_C++ && \
|
zypper -n install -t pattern devel_C_C++ && \
|
||||||
zypper -n install git meson clang libinput libinput-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel
|
zypper -n install git meson clang libinput-devel libwayland-client0 libwayland-cursor0 wayland-protocols-devel wayland-devel Mesa-libEGL-devel Mesa-libGLESv2-devel libgbm-devel libxkbcommon-devel libudev-devel libpixman-1-0-devel gtkmm3-devel jsoncpp-devel
|
|
@ -19,11 +19,12 @@ class Workspaces : public IModule {
|
||||||
operator Gtk::Widget &();
|
operator Gtk::Widget &();
|
||||||
private:
|
private:
|
||||||
void worker();
|
void worker();
|
||||||
void addWorkspace(Json::Value);
|
void addWorkspace(const Json::Value&);
|
||||||
std::string getIcon(std::string, Json::Value);
|
std::string getIcon(const std::string&, const Json::Value&);
|
||||||
bool handleScroll(GdkEventScroll*);
|
bool handleScroll(GdkEventScroll*);
|
||||||
std::string getPrevWorkspace();
|
std::string getPrevWorkspace();
|
||||||
std::string getNextWorkspace();
|
std::string getNextWorkspace();
|
||||||
|
uint16_t getWorkspaceIndex(const std::string &name);
|
||||||
std::string trimWorkspaceName(std::string);
|
std::string trimWorkspaceName(std::string);
|
||||||
|
|
||||||
const Bar& bar_;
|
const Bar& bar_;
|
||||||
|
|
|
@ -17,12 +17,7 @@ void waybar::modules::sway::Workspaces::worker()
|
||||||
{
|
{
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
try {
|
try {
|
||||||
// Wait for the name of the output
|
if (!workspaces_.empty()) {
|
||||||
if (!config_["all-outputs"].asBool() && bar_.output_name.empty()) {
|
|
||||||
while (bar_.output_name.empty()) {
|
|
||||||
thread_.sleep_for(std::chrono::milliseconds(150));
|
|
||||||
}
|
|
||||||
} else if (!workspaces_.empty()) {
|
|
||||||
ipc_.handleEvent();
|
ipc_.handleEvent();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -47,8 +42,7 @@ auto waybar::modules::sway::Workspaces::update() -> void
|
||||||
auto ws = std::find_if(workspaces_.begin(), workspaces_.end(),
|
auto ws = std::find_if(workspaces_.begin(), workspaces_.end(),
|
||||||
[it](auto node) -> bool { return node["name"].asString() == it->first; });
|
[it](auto node) -> bool { return node["name"].asString() == it->first; });
|
||||||
if (ws == workspaces_.end() ||
|
if (ws == workspaces_.end() ||
|
||||||
(!config_["all-outputs"].asBool() &&
|
(!config_["all-outputs"].asBool() && (*ws)["output"].asString() != bar_.output_name)) {
|
||||||
(*ws)["output"].asString() != bar_.output_name)) {
|
|
||||||
it = buttons_.erase(it);
|
it = buttons_.erase(it);
|
||||||
needReorder = true;
|
needReorder = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,7 +76,7 @@ auto waybar::modules::sway::Workspaces::update() -> void
|
||||||
button.get_style_context()->remove_class("urgent");
|
button.get_style_context()->remove_class("urgent");
|
||||||
}
|
}
|
||||||
if (needReorder) {
|
if (needReorder) {
|
||||||
box_.reorder_child(button, node["num"].asInt());
|
box_.reorder_child(button, getWorkspaceIndex(node["name"].asString()));
|
||||||
}
|
}
|
||||||
auto icon = getIcon(node["name"].asString(), node);
|
auto icon = getIcon(node["name"].asString(), node);
|
||||||
if (config_["format"].isString()) {
|
if (config_["format"].isString()) {
|
||||||
|
@ -101,7 +95,7 @@ auto waybar::modules::sway::Workspaces::update() -> void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node)
|
void waybar::modules::sway::Workspaces::addWorkspace(const Json::Value &node)
|
||||||
{
|
{
|
||||||
auto icon = getIcon(node["name"].asString(), node);
|
auto icon = getIcon(node["name"].asString(), node);
|
||||||
auto format = config_["format"].isString()
|
auto format = config_["format"].isString()
|
||||||
|
@ -127,7 +121,7 @@ void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node)
|
||||||
button.signal_scroll_event()
|
button.signal_scroll_event()
|
||||||
.connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
|
.connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
|
||||||
}
|
}
|
||||||
box_.reorder_child(button, node["num"].asInt());
|
box_.reorder_child(button, getWorkspaceIndex(node["name"].asString()));
|
||||||
if (node["focused"].asBool()) {
|
if (node["focused"].asBool()) {
|
||||||
button.get_style_context()->add_class("focused");
|
button.get_style_context()->add_class("focused");
|
||||||
}
|
}
|
||||||
|
@ -140,11 +134,10 @@ void waybar::modules::sway::Workspaces::addWorkspace(Json::Value node)
|
||||||
button.show();
|
button.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string waybar::modules::sway::Workspaces::getIcon(std::string name,
|
std::string waybar::modules::sway::Workspaces::getIcon(const std::string &name,
|
||||||
Json::Value node)
|
const Json::Value &node)
|
||||||
{
|
{
|
||||||
std::vector<std::string> keys = {
|
std::vector<std::string> keys = { name, "urgent", "focused", "visible", "default" };
|
||||||
name, "urgent", "focused", "visible", "default"};
|
|
||||||
for (auto const& key : keys) {
|
for (auto const& key : keys) {
|
||||||
if (key == "focused" || key == "visible" || key == "urgent") {
|
if (key == "focused" || key == "visible" || key == "urgent") {
|
||||||
if (config_["format-icons"][key].isString() && node[key].asBool()) {
|
if (config_["format-icons"][key].isString() && node[key].asBool()) {
|
||||||
|
@ -209,7 +202,7 @@ bool waybar::modules::sway::Workspaces::handleScroll(GdkEventScroll *e)
|
||||||
|
|
||||||
std::string waybar::modules::sway::Workspaces::getPrevWorkspace()
|
std::string waybar::modules::sway::Workspaces::getPrevWorkspace()
|
||||||
{
|
{
|
||||||
for (uint16_t i = 0; i != workspaces_.size(); i += 1) {
|
for (uint16_t i = 0; i < workspaces_.size(); i += 1) {
|
||||||
if (workspaces_[i]["focused"].asBool()) {
|
if (workspaces_[i]["focused"].asBool()) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
return workspaces_[i - 1]["name"].asString();
|
return workspaces_[i - 1]["name"].asString();
|
||||||
|
@ -222,7 +215,7 @@ std::string waybar::modules::sway::Workspaces::getPrevWorkspace()
|
||||||
|
|
||||||
std::string waybar::modules::sway::Workspaces::getNextWorkspace()
|
std::string waybar::modules::sway::Workspaces::getNextWorkspace()
|
||||||
{
|
{
|
||||||
for (uint16_t i = 0; i != workspaces_.size(); i += 1) {
|
for (uint16_t i = 0; i < workspaces_.size(); i += 1) {
|
||||||
if (workspaces_[i]["focused"].asBool()) {
|
if (workspaces_[i]["focused"].asBool()) {
|
||||||
if (i + 1U < workspaces_.size()) {
|
if (i + 1U < workspaces_.size()) {
|
||||||
return workspaces_[i + 1]["name"].asString();
|
return workspaces_[i + 1]["name"].asString();
|
||||||
|
@ -233,8 +226,14 @@ std::string waybar::modules::sway::Workspaces::getNextWorkspace()
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::sway::Workspaces::operator Gtk::Widget &() {
|
uint16_t waybar::modules::sway::Workspaces::getWorkspaceIndex(const std::string &name)
|
||||||
return box_;
|
{
|
||||||
|
for (uint16_t i = 0; i < workspaces_.size(); i += 1) {
|
||||||
|
if (workspaces_[i]["name"].asString() == name) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return workspaces_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string waybar::modules::sway::Workspaces::trimWorkspaceName(std::string name)
|
std::string waybar::modules::sway::Workspaces::trimWorkspaceName(std::string name)
|
||||||
|
@ -245,3 +244,7 @@ std::string waybar::modules::sway::Workspaces::trimWorkspaceName(std::string nam
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
waybar::modules::sway::Workspaces::operator Gtk::Widget &() {
|
||||||
|
return box_;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue