Skip to content

Commit

Permalink
wsets: allow other plugins to create workspace sets too
Browse files Browse the repository at this point in the history
  • Loading branch information
ammen99 committed Aug 10, 2023
1 parent f616a42 commit 4f1ce6e
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions plugins/single_plugins/wsets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,39 @@ class wayfire_wsets_plugin_t : public wf::plugin_interface_t
});
}

void select_workspace(int index)
/**
* Find the workspace set with the given index, or create a new one if it does not exist already.
* In addition, take a reference to it.
*/
void locate_or_create_wset(int64_t index)
{
auto wo = wf::get_core().get_active_output();
if (!wo)
if (available_sets.count(index))
{
return;
}

if (!available_sets.count(index))
auto all_wsets = wf::workspace_set_t::get_all();
auto it = std::find_if(all_wsets.begin(), all_wsets.end(),
[&] (auto wset) { return wset->get_index() == index; });

if (it == all_wsets.end())
{
available_sets[index] = wf::workspace_set_t::create(index);
} else
{
available_sets[index] = (*it)->shared_from_this();
}
}

void select_workspace(int index)
{
auto wo = wf::get_core().get_active_output();
if (!wo)
{
return;
}

locate_or_create_wset(index);
if (wo->wset() != available_sets[index])
{
LOGC(WSET, "Output ", wo->to_string(), " selecting workspace set id=", index);
Expand Down Expand Up @@ -260,10 +280,7 @@ class wayfire_wsets_plugin_t : public wf::plugin_interface_t
return;
}

if (!available_sets.count(index))
{
available_sets[index] = wf::workspace_set_t::create(index);
}
locate_or_create_wset(index);

auto target_wset = available_sets[index];
const auto& old_wset = view->get_wset();
Expand Down

0 comments on commit 4f1ce6e

Please sign in to comment.