small improvements
parent
2bfc0e1da6
commit
2721e19ee6
|
@ -11,7 +11,7 @@ namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
class Workspace {
|
class Workspace {
|
||||||
public:
|
public:
|
||||||
Workspace(const Json::Value& value);
|
Workspace(const Json::Value& workspace_data);
|
||||||
std::string& select_icon(std::map<std::string, std::string>& icons_map);
|
std::string& select_icon(std::map<std::string, std::string>& icons_map);
|
||||||
Gtk::Button& button() { return button_; };
|
Gtk::Button& button() { return button_; };
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class Workspace {
|
||||||
class Workspaces : public AModule, public EventHandler {
|
class Workspaces : public AModule, public EventHandler {
|
||||||
public:
|
public:
|
||||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||||
virtual ~Workspaces();
|
~Workspaces() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
|
||||||
}
|
}
|
||||||
event_box_.add(box_);
|
event_box_.add(box_);
|
||||||
modulesReady = true;
|
modulesReady = true;
|
||||||
if (!gIPC.get()) {
|
if (!gIPC) {
|
||||||
gIPC = std::make_unique<IPC>();
|
gIPC = std::make_unique<IPC>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,11 +104,11 @@ void Workspaces::onEvent(const std::string &ev) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (eventName == "focusedmon") {
|
} else if (eventName == "focusedmon") {
|
||||||
active_workspace_name = payload.substr(payload.find(",") + 1);
|
active_workspace_name = payload.substr(payload.find(',') + 1);
|
||||||
|
|
||||||
} else if (eventName == "moveworkspace" && !all_outputs()) {
|
} else if (eventName == "moveworkspace" && !all_outputs()) {
|
||||||
std::string workspace = payload.substr(0, payload.find(","));
|
std::string workspace = payload.substr(0, payload.find(','));
|
||||||
std::string new_output = payload.substr(payload.find(",") + 1);
|
std::string new_output = payload.substr(payload.find(',') + 1);
|
||||||
if (bar_.output->name == new_output) { // TODO: implement this better
|
if (bar_.output->name == new_output) { // TODO: implement this better
|
||||||
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces");
|
const Json::Value workspaces_json = gIPC->getSocket1JsonReply("workspaces");
|
||||||
for (Json::Value workspace_json : workspaces_json) {
|
for (Json::Value workspace_json : workspaces_json) {
|
||||||
|
@ -167,19 +167,18 @@ Workspaces::~Workspaces() {
|
||||||
std::lock_guard<std::mutex> lg(mutex_);
|
std::lock_guard<std::mutex> lg(mutex_);
|
||||||
}
|
}
|
||||||
|
|
||||||
Workspace::Workspace(const Json::Value &value)
|
Workspace::Workspace(const Json::Value &workspace_data)
|
||||||
: id_(value["id"].asInt()),
|
: id_(workspace_data["id"].asInt()),
|
||||||
name_(value["name"].asString()),
|
name_(workspace_data["name"].asString()),
|
||||||
output_(value["monitor"].asString()), // TODO:allow using monitor desc
|
output_(workspace_data["monitor"].asString()), // TODO:allow using monitor desc
|
||||||
windows_(value["id"].asInt()) {
|
windows_(workspace_data["id"].asInt()),
|
||||||
active_ = true;
|
active_(true),
|
||||||
is_special_ = false;
|
is_special_(false) {
|
||||||
|
|
||||||
if (name_.find("name:") == 0) {
|
if (name_.find("name:") == 0) {
|
||||||
name_ = name_.substr(5);
|
name_ = name_.substr(5);
|
||||||
} else if (name_.find("special") == 0) {
|
} else if (name_.find("special") == 0) {
|
||||||
name_ = id_ == -99 ? name_ : name_.substr(13);
|
name_ = id_ == -99 ? name_ : name_.substr(13);
|
||||||
is_special_ = 1;
|
is_special_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
button_.add_events(Gdk::BUTTON_PRESS_MASK);
|
button_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||||
|
@ -191,7 +190,7 @@ Workspace::Workspace(const Json::Value &value)
|
||||||
button_.add(content_);
|
button_.add(content_);
|
||||||
};
|
};
|
||||||
|
|
||||||
void add_or_remove_class(Glib::RefPtr<Gtk::StyleContext> context, bool condition,
|
void add_or_remove_class(const Glib::RefPtr<Gtk::StyleContext> &context, bool condition,
|
||||||
const std::string &class_name) {
|
const std::string &class_name) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
context->add_class(class_name);
|
context->add_class(class_name);
|
||||||
|
@ -201,7 +200,7 @@ void add_or_remove_class(Glib::RefPtr<Gtk::StyleContext> context, bool condition
|
||||||
}
|
}
|
||||||
|
|
||||||
void Workspace::update(const std::string &format, const std::string &icon) {
|
void Workspace::update(const std::string &format, const std::string &icon) {
|
||||||
Glib::RefPtr<Gtk::StyleContext> style_context = button_.get_style_context();
|
auto style_context = button_.get_style_context();
|
||||||
add_or_remove_class(style_context, active(), "active");
|
add_or_remove_class(style_context, active(), "active");
|
||||||
|
|
||||||
label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
|
label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
|
||||||
|
@ -218,9 +217,8 @@ void Workspaces::sort_workspaces() {
|
||||||
if (a->id() < 0 && b->id() < 0) {
|
if (a->id() < 0 && b->id() < 0) {
|
||||||
if ((a->is_special()) ^ (a->is_special())) {
|
if ((a->is_special()) ^ (a->is_special())) {
|
||||||
return a->id() > b->id();
|
return a->id() > b->id();
|
||||||
} else {
|
|
||||||
return a->id() < b->id();
|
|
||||||
}
|
}
|
||||||
|
return a->id() < b->id();
|
||||||
}
|
}
|
||||||
if ((a->id() > 0) ^ (b->id() > 0)) {
|
if ((a->id() > 0) ^ (b->id() > 0)) {
|
||||||
return a->id() > b->id();
|
return a->id() > b->id();
|
||||||
|
|
Loading…
Reference in New Issue