Skip to content

Commit

Permalink
wip: visible style
Browse files Browse the repository at this point in the history
  • Loading branch information
zjeffer committed Aug 21, 2023
1 parent e89b800 commit 4773d1e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Expand Up @@ -23,11 +23,13 @@ class Workspace {
bool active() const { return active_; };
bool is_special() const { return is_special_; };
bool is_persistent() const { return is_persistent_; };
bool is_visible() const { return is_visible_; };
bool is_empty() const { return windows_ == 0; };

auto handle_clicked(GdkEventButton* bt) -> bool;
void set_active(bool value = true) { active_ = value; };
void set_persistent(bool value = true) { is_persistent_ = value; };
void set_visible(bool value = true) { is_visible_ = value; };
void set_windows(uint value) { windows_ = value; };

void update(const std::string& format, const std::string& icon);
Expand All @@ -42,6 +44,7 @@ class Workspace {
bool active_ = false;
bool is_special_ = false;
bool is_persistent_ = false;
bool is_visible_ = false;

Gtk::Button button_;
Gtk::Box content_;
Expand Down
41 changes: 38 additions & 3 deletions src/modules/hyprland/workspaces.cpp
Expand Up @@ -78,12 +78,34 @@ auto Workspaces::update() -> void {

workspaces_to_create_.clear();

auto monitors = gIPC->getSocket1JsonReply("monitors");
std::vector<std::string> active_ws;
for (Json::Value &monitor : monitors) {
auto ws = monitor["activeWorkspace"];
if (ws.isObject() && (ws["name"].isString())) {
active_ws.push_back(ws["name"].asString());
}
}

for (auto &workspace : workspaces_) {
workspace->set_active(workspace->name() == active_workspace_name_);
std::string &workspace_icon = icons_map_[""];
if (with_icon_) {
workspace_icon = workspace->select_icon(icons_map_);
}
if (std::find_if(active_ws.begin(), active_ws.end(), [&](const std::string &ws) {
return ws == workspace->name();
}) != active_ws.end()) {
spdlog::info("Workspace {} is visible", workspace->name());
workspace->set_visible(true);
} else {
if (workspace->is_visible())
{
spdlog::info("Workspace {} is not visible", workspace->name());
}
workspace->set_visible(false);

}
workspace->update(format_, workspace_icon);
}
AModule::update();
Expand Down Expand Up @@ -218,9 +240,13 @@ void Workspaces::fill_persistent_workspaces() {
}
}

} else if (value.isArray() && !value.empty()) {
} else if (value.isArray()) {
// value is an array => key is a workspace name
// values are monitor names this workspace should be shown on
if (value.empty()) {
// show on all monitors
persistent_workspaces_to_create_.emplace_back(key);
}
for (const Json::Value &monitor : value) {
if (monitor.isString() && monitor.asString() == bar_.output->name) {
persistent_workspaces_to_create_.emplace_back(key);
Expand Down Expand Up @@ -327,8 +353,9 @@ void add_or_remove_class(const Glib::RefPtr<Gtk::StyleContext> &context, bool co
}

void Workspace::update(const std::string &format, const std::string &icon) {
if (!this->is_persistent() && this->workspace_manager_.active_only() && !this->active()) {
// hide if not active and not persistent
if (!this->is_persistent() && this->workspace_manager_.active_only() && !this->active() &&
!this->is_special()) {
// if active_only is true, hide if not active, persistent or special
button_.hide();
return;
}
Expand All @@ -338,6 +365,7 @@ void Workspace::update(const std::string &format, const std::string &icon) {
add_or_remove_class(style_context, active(), "active");
add_or_remove_class(style_context, is_special(), "special");
add_or_remove_class(style_context, is_empty(), "persistent");
add_or_remove_class(style_context, is_visible(), "visible");

label_.set_markup(fmt::format(fmt::runtime(format), fmt::arg("id", id()),
fmt::arg("name", name()), fmt::arg("icon", icon)));
Expand Down Expand Up @@ -402,6 +430,13 @@ std::string &Workspace::select_icon(std::map<std::string, std::string> &icons_ma
return named_icon_it->second;
}

if (is_visible()) {
auto visible_icon_it = icons_map.find("visible");
if (visible_icon_it != icons_map.end()) {
return visible_icon_it->second;
}
}

if (is_persistent()) {
auto persistent_icon_it = icons_map.find("persistent");
if (persistent_icon_it != icons_map.end()) {
Expand Down

0 comments on commit 4773d1e

Please sign in to comment.