Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
zjeffer committed Oct 23, 2023
1 parent b52aaae commit f02d755
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class Workspaces : public AModule, public EventHandler {
{"NAME", SORT_METHOD::NAME},
{"NUMBER", SORT_METHOD::NUMBER},
{"DEFAULT", SORT_METHOD::DEFAULT}};

void create_persistent_workspaces();

std::string format_;

std::map<std::string, std::string> icons_map_;
Expand Down
43 changes: 42 additions & 1 deletion src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,41 @@ void Workspaces::remove_workspace(std::string const &name) {
workspaces_.erase(workspace);
}

void Workspaces::create_persistent_workspaces() {
// get workspaces that need to be persistent for this monitor
// THIS IS STILL VERY MUCH WIP
std::vector<std::string> persistent_workspaces;
auto const &workspaceRules = gIPC->getSocket1JsonReply("workspacerules");
for (auto const &rule : workspaceRules) {
auto const &workspaceString = rule["workspaceString"];
if (workspaceString.isInt()) {
persistent_workspaces.emplace_back(
workspaceString.asInt() == -99 ? "special" : workspaceString.asString());
} else if (workspaceString.isString() && workspaceString.asString().starts_with("name:")) {
persistent_workspaces.emplace_back(workspaceString.asString().substr(5));
}
}


// create the workspaces
for (const std::string &workspace_name : persistent_workspaces) {
Json::Value new_workspace;
try {
// numbered persistent workspaces get the name as ID
new_workspace["id"] = workspace_name == "special" ? -99 : std::stoi(workspace_name);
} catch (const std::exception &e) {
// named persistent workspaces start with ID=0
new_workspace["id"] = 0;
}
new_workspace["name"] = workspace_name;
new_workspace["monitor"] = bar_.output->name;
new_workspace["windows"] = 0;
new_workspace["persistent"] = true;

create_workspace(new_workspace);
}
}

void Workspaces::init() {
active_workspace_name_ = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString();

Expand All @@ -528,7 +563,13 @@ void Workspaces::init() {
}
}

// TODO: initialize add persistent workspaces that haven't been created yet
// TODO: create workspaces that are bound to monitors but not yet created
// 1. get list of workspace rules
// 2. if a workspace is bound and persistent, create it
auto const workspaceRules = gIPC->getSocket1JsonReply("workspacerules");
for (Json::Value const &rule : workspaceRules) {
auto const &workspace = rule["workspaceString"];
}

update_window_count();

Expand Down

0 comments on commit f02d755

Please sign in to comment.