Skip to content

Commit

Permalink
feature: implemented named workspaces that can lack a number entirely (
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae authored Nov 5, 2024
1 parent 0a8809d commit bffda06
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,15 +998,17 @@ bool FilesystemConfiguration::are_animations_enabled() const
return options.animations_enabled;
}

WorkspaceConfig FilesystemConfiguration::get_workspace_config(int key) const
WorkspaceConfig FilesystemConfiguration::get_workspace_config(std::optional<int> const& num, std::optional<std::string> const& name) const
{
for (auto const& config : options.workspace_configs)
{
if (config.num == key)
if (num && config.num == num.value())
return config;
else if (name && config.name == name.value())
return config;
}

return { key, ContainerType::leaf };
return { num, ContainerType::leaf, name };
}

LayoutScheme FilesystemConfiguration::get_default_layout_scheme() const
Expand Down
6 changes: 3 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct BorderConfig

struct WorkspaceConfig
{
int num = -1;
std::optional<int> num;
std::optional<ContainerType> layout;
std::optional<std::string> name;
};
Expand Down Expand Up @@ -173,7 +173,7 @@ class Config
[[nodiscard]] virtual BorderConfig const& get_border_config() const = 0;
[[nodiscard]] virtual std::array<AnimationDefinition, static_cast<int>(AnimateableEvent::max)> const& get_animation_definitions() const = 0;
[[nodiscard]] virtual bool are_animations_enabled() const = 0;
[[nodiscard]] virtual WorkspaceConfig get_workspace_config(int key) const = 0;
[[nodiscard]] virtual WorkspaceConfig get_workspace_config(std::optional<int> const& num, std::optional<std::string> const& name) const = 0;
[[nodiscard]] virtual LayoutScheme get_default_layout_scheme() const = 0;

virtual int register_listener(std::function<void(miracle::Config&)> const&) = 0;
Expand Down Expand Up @@ -210,7 +210,7 @@ class FilesystemConfiguration : public Config
[[nodiscard]] BorderConfig const& get_border_config() const override;
[[nodiscard]] std::array<AnimationDefinition, static_cast<int>(AnimateableEvent::max)> const& get_animation_definitions() const override;
[[nodiscard]] bool are_animations_enabled() const override;
[[nodiscard]] WorkspaceConfig get_workspace_config(int key) const override;
[[nodiscard]] WorkspaceConfig get_workspace_config(std::optional<int> const& num, std::optional<std::string> const& name) const override;
[[nodiscard]] LayoutScheme get_default_layout_scheme() const override;
int register_listener(std::function<void(miracle::Config&)> const&) override;
int register_listener(std::function<void(miracle::Config&)> const&, int priority) override;
Expand Down
14 changes: 12 additions & 2 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void Output::advise_new_workspace(WorkspaceCreationData const&& data)
else if (b->num())
return false;
else
return true;
return false;
});
}

Expand Down Expand Up @@ -351,7 +351,17 @@ geom::Rectangle Output::get_workspace_rectangle(size_t i) const
if (workspace->num())
x = (workspace->num().value() - 1) * area.size.width.as_int();
else
x = ((WorkspaceManager::NUM_DEFAULT_WORKSPACES - 1) + i) * area.size.width.as_int();
{
// Find the index of the first non-numbered workspace
size_t j = 0;
for (; j < workspaces.size(); j++)
{
if (workspaces[j]->num() == std::nullopt)
break;
}

x = ((WorkspaceManager::NUM_DEFAULT_WORKSPACES - 1) + (i - j)) * area.size.width.as_int();
}

return geom::Rectangle {
geom::Point { geom::X { x }, geom::Y { 0 } },
Expand Down
4 changes: 2 additions & 2 deletions src/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ AllocationHint Workspace::allocate_position(
AllocationHint const& hint)
{
// If there's no ideal layout type, use the one provided by the workspace
auto const& workspace_config = config->get_workspace_config(num_.value());
auto const layout = (hint.container_type == ContainerType::none && num_)
auto const& workspace_config = config->get_workspace_config(num_, name_);
auto const layout = hint.container_type == ContainerType::none
? workspace_config.layout ? workspace_config.layout.value() : ContainerType::leaf
: hint.container_type;
switch (layout)
Expand Down
2 changes: 1 addition & 1 deletion src/workspace_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool WorkspaceManager::request_workspace(
return focus_existing(existing, back_and_forth);

uint32_t id = next_id++;
auto const& workspace_config = config->get_workspace_config(num);
auto const& workspace_config = config->get_workspace_config(num, std::nullopt);
output_hint->advise_new_workspace({ .id = id,
.num = num,
.name = workspace_config.name });
Expand Down
4 changes: 2 additions & 2 deletions tests/stub_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ namespace test
return false;
}

[[nodiscard]] WorkspaceConfig get_workspace_config(int key) const override
[[nodiscard]] WorkspaceConfig get_workspace_config(std::optional<int> const& num, std::optional<std::string> const& name) const override
{
return WorkspaceConfig(key);
return { num, ContainerType::leaf, name };
}

int register_listener(std::function<void(miracle::Config&)> const&) override
Expand Down

0 comments on commit bffda06

Please sign in to comment.