Skip to content

Special behavior for special workspace(hyprland/workspaces) [WIP but works in its basic form lol] #4029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/modules/hyprland/workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Workspace {
void setOutput(std::string const& value) { m_output = value; };
bool containsWindow(WindowAddress const& addr) const { return m_windowMap.contains(addr); }
void insertWindow(WindowCreationPayload create_window_paylod);

std::string removeWindow(WindowAddress const& addr);
void initializeWindowMap(const Json::Value& clients_data);

Expand Down
2 changes: 2 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class Workspaces : public AModule, public EventHandler {
bool isWorkspaceIgnored(std::string const& workspace_name);

bool windowRewriteConfigUsesTitle() const { return m_anyWindowRewriteRuleUsesTitle; }
bool specialWorkspaceIsActive() const;


private:
void onEvent(const std::string& e) override;
Expand Down
24 changes: 24 additions & 0 deletions src/modules/hyprland/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ std::string &Workspace::selectIcon(std::map<std::string, std::string> &icons_map
}
}

// Check if both isActive and isSpecial
if (isActive() && isSpecial()) {
auto specialActiveIconIt = icons_map.find("special-active");
if (specialActiveIconIt != icons_map.end()) {
return specialActiveIconIt->second;
}
}

// Check if isActive but not isSpecial
if (isActive() && !isSpecial()) {
auto normalActiveIconIt = icons_map.find("normal-active");
if (normalActiveIconIt != icons_map.end()) {
return normalActiveIconIt->second;
}
}

if (isActive()) {
auto activeIconIt = icons_map.find("active");
if (activeIconIt != icons_map.end()) {
Expand Down Expand Up @@ -192,6 +208,14 @@ void Workspace::update(const std::string &format, const std::string &icon) {

auto styleContext = m_button.get_style_context();
addOrRemoveClass(styleContext, isActive(), "active");
// // Only add 'active' class if:
// // (1) This is the special workspace and it is active
// // OR
// // (2) No special workspace is active, and this is the normal active one
// bool specialIsActive = m_workspaceManager.specialWorkspaceIsActive();
// bool applyActive = isActive() && (!specialIsActive || isSpecial());
// addOrRemoveClass(styleContext, applyActive, "active");

addOrRemoveClass(styleContext, isSpecial(), "special");
addOrRemoveClass(styleContext, isEmpty(), "empty");
addOrRemoveClass(styleContext, isPersistent(), "persistent");
Expand Down
23 changes: 23 additions & 0 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ void Workspaces::init() {
dp.emit();
}

bool Workspaces::specialWorkspaceIsActive() const {
for (const auto &workspace : m_workspaces) {
if (workspace->isActive() && workspace->isSpecial()) {
return true;
}
}
return false;
}

Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name,
std::string const &monitor) {
spdlog::trace("Creating persistent workspace: {} on monitor {}", name, monitor);
Expand All @@ -62,6 +71,15 @@ Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name,
return workspaceData;
}

void addOrRemoveClassWorkspaces(const Glib::RefPtr<Gtk::StyleContext> &context, bool condition,
const std::string &class_name) {
if (condition) {
context->add_class(class_name);
} else {
context->remove_class(class_name);
}
}

void Workspaces::createWorkspace(Json::Value const &workspace_data,
Json::Value const &clients_data) {
auto workspaceName = workspace_data["name"].asString();
Expand Down Expand Up @@ -856,6 +874,11 @@ void Workspaces::setUrgentWorkspace(std::string const &windowaddress) {
auto Workspaces::update() -> void {
doUpdate();
AModule::update();

//pol was here
bool specialActive = specialWorkspaceIsActive();
auto styleContext = m_box.get_style_context();
addOrRemoveClassWorkspaces(styleContext, specialActive, "has-special-active");
}

void Workspaces::updateWindowCount() {
Expand Down