Skip to content

Commit

Permalink
It builds but doesn't work!
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Nov 4, 2024
1 parent fb5d53f commit ff15594
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 146 deletions.
15 changes: 12 additions & 3 deletions src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ glm::mat4 Container::get_workspace_transform() const
if (!output)
return glm::mat4(1.f);

auto const workspace_rect = output->get_workspace_rectangle(get_workspace()->get_workspace());
return glm::translate(
glm::vec3(workspace_rect.top_left.x.as_int(), workspace_rect.top_left.y.as_int(), 0));
auto const& workspaces = output->get_workspaces();
for (size_t i = 0; i < workspaces.size(); i++)
{
if (workspaces[i].get() == get_workspace())
{
auto const workspace_rect = output->get_workspace_rectangle(i);
return glm::translate(
glm::vec3(workspace_rect.top_left.x.as_int(), workspace_rect.top_left.y.as_int(), 0));
}
}

return glm::mat4(1.f);
}

glm::mat4 Container::get_output_transform() const
Expand Down
2 changes: 1 addition & 1 deletion src/container_group_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ ContainerGroupContainer::confirm_placement(MirWindowState state, mir::geometry::

Workspace* ContainerGroupContainer::get_workspace() const
{
return state.active_output->get_active_workspace().get();
return state.active_output->active();
}

Output* ContainerGroupContainer::get_output() const
Expand Down
10 changes: 3 additions & 7 deletions src/floating_window_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void FloatingWindowContainer::on_open()

void FloatingWindowContainer::on_focus_gained()
{
if (get_output()->get_active_workspace()->get_workspace() != workspace_->get_workspace())
if (get_output()->active() != workspace_)
return;

wm->advise_focus_gained(window_controller.info_for(window_));
Expand Down Expand Up @@ -270,11 +270,7 @@ glm::mat4 FloatingWindowContainer::get_workspace_transform() const
if (pinned())
return glm::mat4(1.f);

auto output = get_output();
auto workspace = get_workspace();
auto const workspace_rect = output->get_workspace_rectangle(workspace->get_workspace());
return glm::translate(
glm::vec3(workspace_rect.top_left.x.as_int(), workspace_rect.top_left.y.as_int(), 0));
return Container::get_workspace_transform();
}

glm::mat4 FloatingWindowContainer::get_output_transform() const
Expand Down Expand Up @@ -357,7 +353,7 @@ nlohmann::json FloatingWindowContainer::to_json() const
if (!output->is_active())
visible = false;

if (output->get_active_workspace_num() != workspace->get_workspace())
if (output->active() != workspace)
visible = false;

return {
Expand Down
2 changes: 1 addition & 1 deletion src/i3_command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void I3CommandExecutor::process_focus(I3Command const& command, I3ScopedCommandL
auto window = get_window_meeting_criteria(command_list);
auto container = window_controller.get_container(window);
if (container)
workspace_manager.request_focus(container->get_workspace()->get_workspace());
workspace_manager.request_focus(container->get_workspace()->id());
}
else if (arg == "left")
policy.try_select(Direction::left);
Expand Down
57 changes: 28 additions & 29 deletions src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,35 @@ bool fd_is_valid(int fd)
return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
}

json workspace_to_json(Output const& screen, int key)
json workspace_to_json(WorkspaceManager const& workspace_manager, uint32_t id)
{
auto workspace = screen.workspace(key);
bool is_focused = screen.get_active_workspace_num() == key;
auto const& workspace = workspace_manager.workspace(id);
if (!workspace)
return {};

auto screen = workspace->get_output();
bool is_focused = screen->active() == workspace;

// Note: The reported workspace area appears to be the placement
// area of the root tree.
// See: https://i3wm.org/docs/ipc.html#_tree_reply
auto area = workspace->get_tree()->get_area();

return {
{ "num", key },
{ "id", reinterpret_cast<std::uintptr_t>(workspace) },
{ "type", "workspace" },
{ "name", std::to_string(key) },
{ "visible", screen.is_active() && is_focused },
{ "focused", screen.is_active() && is_focused },
{ "urgent", false },
{ "output", screen.get_output().name() },
{ "num", workspace->num() ? workspace->num().value() : -1 },
{ "id", reinterpret_cast<std::uintptr_t>(workspace) },
{ "type", "workspace" },
{ "name", "TODO" },
{ "visible", screen->is_active() && is_focused },
{ "focused", screen->is_active() && is_focused },
{ "urgent", false },
{ "output", screen->get_output().name() },
{ "rect", {
{ "x", area.top_left.x.as_int() },
{ "y", area.top_left.y.as_int() },
{ "width", area.size.width.as_int() },
{ "height", area.size.height.as_int() },
} }
} }
};
}

Expand Down Expand Up @@ -369,12 +373,12 @@ Ipc::~Ipc()
{
}

void Ipc::on_created(Output const& info, int key)
void Ipc::on_created(uint32_t id)
{
json j = {
{ "change", "init" },
{ "old", nullptr },
{ "current", workspace_to_json(info, key) }
{ "current", workspace_to_json(workspace_manager, id) }
};

auto serialized_value = to_string(j);
Expand All @@ -389,11 +393,11 @@ void Ipc::on_created(Output const& info, int key)
}
}

void Ipc::on_removed(Output const& screen, int key)
void Ipc::on_removed(uint32_t id)
{
json j = {
{ "change", "empty" },
{ "current", workspace_to_json(screen, key) }
{ "current", workspace_to_json(workspace_manager, id) }
};

auto serialized_value = to_string(j);
Expand All @@ -409,18 +413,16 @@ void Ipc::on_removed(Output const& screen, int key)
}

void Ipc::on_focused(
Output const* previous,
int previous_key,
Output const* current,
int current_key)
std::optional<uint32_t> previous_id,
uint32_t current_id)
{
json j = {
{ "change", "focus" },
{ "current", workspace_to_json(*current, current_key) }
{ "current", workspace_to_json(workspace_manager, current_id) }
};

if (previous)
j["old"] = workspace_to_json(*previous, previous_key);
if (previous_id)
j["old"] = workspace_to_json(workspace_manager, previous_id.value());
else
j["old"] = nullptr;

Expand Down Expand Up @@ -540,12 +542,9 @@ void Ipc::handle_command(miracle::Ipc::IpcClient& client, uint32_t payload_lengt
case IPC_GET_WORKSPACES:
{
json j = json::array();
for (int i = 0; i < WorkspaceManager::NUM_WORKSPACES; i++)
{
auto workspace = workspace_manager.get_output_to_workspace_mapping()[i].get();
if (workspace)
j.push_back(workspace_to_json(*workspace, i));
}
for (auto const& workspace : workspace_manager.workspaces())
j.push_back(workspace_to_json(workspace_manager, workspace->id()));

auto json_string = to_string(j);
send_reply(client, payload_type, json_string);
break;
Expand Down
6 changes: 3 additions & 3 deletions src/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class Ipc : public virtual WorkspaceObserver, public virtual ModeObserver
std::shared_ptr<Config> const&);
~Ipc();

void on_created(Output const& info, int key) override;
void on_removed(Output const& info, int key) override;
void on_focused(Output const* previous, int, Output const* current, int) override;
void on_created(uint32_t id) override;
void on_removed(uint32_t id) override;
void on_focused(std::optional<uint32_t>, uint32_t) override;
void on_changed(WindowManagerMode mode) override;
void on_shutdown();

Expand Down
2 changes: 1 addition & 1 deletion src/leaf_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ nlohmann::json LeafContainer::to_json() const
if (!output->is_active())
visible = false;

if (output->get_active_workspace_num() != workspace->get_workspace())
if (output->active() != workspace)
visible = false;

if (locked_parent == nullptr)
Expand Down
10 changes: 5 additions & 5 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ Output::Output(
{
}

std::shared_ptr<Workspace> Output::active() const
Workspace* Output::active() const
{
if (active_workspace.expired())
return nullptr;

return active_workspace.lock();
return active_workspace.lock().get();
}

std::shared_ptr<Container> Output::intersect(const MirPointerEvent* event)
Expand Down Expand Up @@ -95,13 +95,13 @@ AllocationHint Output::allocate_position(
if (hint.container_type == ContainerType::shell)
return hint;

return get_active_workspace()->allocate_position(app_info, requested_specification, hint);
return active()->allocate_position(app_info, requested_specification, hint);
}

std::shared_ptr<Container> Output::create_container(
miral::WindowInfo const& window_info, AllocationHint const& hint) const
{
return get_active_workspace()->create_container(window_info, hint);
return active()->create_container(window_info, hint);
}

void Output::delete_container(std::shared_ptr<miracle::Container> const& container)
Expand Down Expand Up @@ -346,7 +346,7 @@ void Output::add_immediately(miral::Window& window, AllocationHint hint)

void Output::graft(std::shared_ptr<Container> const& container)
{
get_active_workspace()->graft(container);
active()->graft(container);
}

geom::Rectangle Output::get_workspace_rectangle(size_t i) const
Expand Down
2 changes: 1 addition & 1 deletion src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Output
// Getters

[[nodiscard]] std::vector<miral::Window> collect_all_windows() const;
[[nodiscard]] std::shared_ptr<Workspace> active() const;
[[nodiscard]] Workspace* active() const;
[[nodiscard]] std::vector<std::shared_ptr<Workspace>> const& get_workspaces() const { return workspaces; }
[[nodiscard]] geom::Rectangle const& get_area() const { return area; }
[[nodiscard]] std::vector<miral::Zone> const& get_app_zones() const { return application_zone_list; }
Expand Down
2 changes: 1 addition & 1 deletion src/parent_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ nlohmann::json ParentContainer::to_json() const
if (!output->is_active())
visible = false;

if (output->get_active_workspace_num() != workspace->get_workspace())
if (output->active() != workspace)
visible = false;

if (locked_parent == nullptr)
Expand Down
39 changes: 23 additions & 16 deletions src/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ Policy::Policy(
workspace_manager { WorkspaceManager(
tools,
workspace_observer_registrar,
[&]()
{ return get_active_output(); }) },
[this]()
{ return get_active_output(); },
[this]()
{ return get_output_list(); }) },
animator(server.the_main_loop(), config),
window_controller(tools, animator, state),
i3_command_executor(*this, workspace_manager, tools, external_client_launcher, window_controller),
Expand Down Expand Up @@ -220,7 +222,8 @@ bool Policy::handle_pointer_event(MirPointerEvent const* event)
state.active_output->set_is_active(false);
state.active_output = output;
state.active_output->set_is_active(true);
workspace_manager.request_focus(output->get_active_workspace_num());
if (auto active = output->active())
workspace_manager.request_focus(active->id());
}
break;
}
Expand Down Expand Up @@ -390,7 +393,7 @@ void Policy::advise_focus_gained(const miral::WindowInfo& window_info)
default:
{
auto const* workspace = container->get_workspace();
if (workspace && workspace != state.active_output->get_active_workspace().get())
if (workspace && workspace != state.active_output->active())
return;

state.active = container;
Expand Down Expand Up @@ -459,7 +462,7 @@ void Policy::advise_output_create(miral::Output const& output)
auto output_content = std::make_shared<Output>(
output, workspace_manager, output.extents(), window_manager_tools,
floating_window_manager, state, config, window_controller, animator);
workspace_manager.request_first_available_workspace(output_content);
workspace_manager.request_first_available_workspace(output_content.get());
output_list.push_back(output_content);
if (state.active_output == nullptr)
{
Expand Down Expand Up @@ -501,12 +504,12 @@ void Policy::advise_output_delete(miral::Output const& output)
auto const remove_workspaces = [&]()
{
// WARNING: We copy the workspace numbers first because we shouldn't delete while iterating
std::vector<int> workspaces;
std::vector<uint32_t> workspaces;
workspaces.reserve(other_output->get_workspaces().size());
for (auto const& workspace : other_output->get_workspaces())
workspaces.push_back(workspace->get_workspace());
workspaces.push_back(workspace->id());

for (auto w : workspaces)
for (auto const w : workspaces)
workspace_manager.delete_workspace(w);
};

Expand Down Expand Up @@ -553,7 +556,7 @@ void Policy::handle_modify_window(
}

auto const* workspace = container->get_workspace();
if (workspace && workspace != state.active_output->get_active_workspace().get())
if (workspace && workspace != state.active_output->active())
return;

container->handle_modify(modifications);
Expand Down Expand Up @@ -798,7 +801,7 @@ bool Policy::select_workspace(int number, bool back_and_forth)
if (!state.active_output)
return false;

workspace_manager.request_workspace(state.active_output, number, back_and_forth);
workspace_manager.request_workspace(state.active_output.get(), number, back_and_forth);
return true;
}

Expand All @@ -808,7 +811,7 @@ bool Policy::select_workspace(std::string const& name, bool back_and_forth)
if (state.mode == WindowManagerMode::resizing)
return false;

return workspace_manager.request_workspace(name, back_and_forth);
return workspace_manager.request_workspace(state.active_output.get(), name, back_and_forth);
}

bool Policy::next_workspace()
Expand Down Expand Up @@ -863,10 +866,14 @@ bool Policy::move_active_to_workspace(int number, bool back_and_forth)
container->get_output()->delete_container(container);
state.active = nullptr;

auto output = workspace_manager.request_workspace(
state.active_output, number, back_and_forth);
output->graft(container);
return true;
if (workspace_manager.request_workspace(
state.active_output.get(), number, back_and_forth))
{
state.active_output->graft(container);
return true;
}

return false;
}

bool Policy::move_active_to_workspace_named(std::string const& name, bool back_and_forth)
Expand All @@ -878,7 +885,7 @@ bool Policy::move_active_to_workspace_named(std::string const& name, bool back_a
container->get_output()->delete_container(container);
state.active = nullptr;

if (workspace_manager.request_workspace(name, back_and_forth))
if (workspace_manager.request_workspace(state.active_output.get(), name, back_and_forth))
{
state.active_output->graft(container);
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Policy : public miral::WindowManagementPolicy
std::vector<std::shared_ptr<Output>> output_list;
std::weak_ptr<Output> pending_output;
AllocationHint pending_allocation;
std::vector<Window> orphaned_window_list;
std::vector<miral::Window> orphaned_window_list;
miral::WindowManagerTools window_manager_tools;
std::shared_ptr<MinimalWindowManager> floating_window_manager;
AutoRestartingLauncher& external_client_launcher;
Expand Down
Loading

0 comments on commit ff15594

Please sign in to comment.