Skip to content

Commit

Permalink
Fixed bugs with bad workspace rectangles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Nov 4, 2024
1 parent 08d9cbf commit e81a210
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 23 deletions.
19 changes: 9 additions & 10 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void Output::delete_container(std::shared_ptr<miracle::Container> const& contain

void Output::advise_new_workspace(WorkspaceCreationData const&& data)
{
// Workspaces are always kept in sorted order with numbered workspaces in front, then named
// workspaces, and then spooky unmarked workspaces.
// Workspaces are always kept in sorted order with numbered workspaces in front followed by all other workspaces
auto new_workspace = std::make_shared<Workspace>(
this, tools, data.id, data.num, data.name, config, window_controller, state, floating_window_manager);
insert_sorted(workspaces, new_workspace, [](std::shared_ptr<Workspace> const& a, std::shared_ptr<Workspace> const& b)
Expand All @@ -124,14 +123,8 @@ void Output::advise_new_workspace(WorkspaceCreationData const&& data)
return true;
else if (b->num())
return false;
else if (a->name() && b->name())
return a->name().value() < b->name().value();
else if (a->name())
return true;
else if (b->name())
return false;
else
return false;
return true;
});
}

Expand Down Expand Up @@ -352,7 +345,13 @@ void Output::graft(std::shared_ptr<Container> const& container)
geom::Rectangle Output::get_workspace_rectangle(size_t i) const
{
// TODO: Support vertical workspaces one day in the future
const size_t x = (i - 1) * area.size.width.as_int();
auto const& workspace = workspaces[i];
size_t x = 0;
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();

return geom::Rectangle {
geom::Point { geom::X { x }, geom::Y { 0 } },
geom::Size { area.size.width.as_int(), area.size.height.as_int() }
Expand Down
50 changes: 39 additions & 11 deletions src/workspace_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,45 @@ int WorkspaceManager::request_first_available_workspace(Output* output)

bool WorkspaceManager::request_next(std::shared_ptr<Output> const& output)
{
auto const& active = output->active();
if (!active)
return false;

auto const l = workspaces();
for (auto it = l.begin(); it != l.end(); it++)
{
if (*it == active)
{
it++;
if (it == l.end())
it = l.begin();

return focus_existing(*it, false);
}
}

return false;
}

bool WorkspaceManager::request_prev(std::shared_ptr<Output> const& output)
{
auto const& active = output->active();
if (!active)
return false;

auto const l = workspaces();
for (auto it = l.rbegin(); it != l.rend(); it++)
{
if (*it == active)
{
it++;
if (it == l.rend())
it = l.rbegin();

return focus_existing(*it, false);
}
}

return false;
}

Expand Down Expand Up @@ -163,13 +197,13 @@ bool WorkspaceManager::request_prev_on_output(Output const& output)
return false;

auto const& workspaces = output.get_workspaces();
for (auto it = workspaces.end() - 1; it != workspaces.begin(); it--)
for (auto it = workspaces.rbegin(); it != workspaces.rend(); it++)
{
if (it->get() == active)
{
it--;
if (it == workspaces.begin())
it = workspaces.end() - 1;
it++;
if (it == workspaces.rend())
it = workspaces.rbegin();

return focus_existing(it->get(), false);
}
Expand Down Expand Up @@ -270,14 +304,8 @@ std::vector<Workspace const*> WorkspaceManager::workspaces() const
return true;
else if (b->num())
return false;
else if (a->name() && b->name())
return a->name().value() < b->name().value();
else if (a->name())
return true;
else if (b->name())
return false;
else
return false;
return true;
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/workspace_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ class WorkspaceManager
/// Builds and returns a sorted array of all active workspaces.
std::vector<Workspace const*> workspaces() const;

/// The number of default workspaces
static constexpr int NUM_DEFAULT_WORKSPACES = 10;

private:
bool focus_existing(Workspace const*, bool back_and_forth);

/// The number of default workspaces
const int NUM_DEFAULT_WORKSPACES = 10;
uint32_t next_id = 0;

Workspace* workspace(int num) const;
Expand Down

0 comments on commit e81a210

Please sign in to comment.