Skip to content

Commit

Permalink
We can now move containers around again
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkae committed Feb 2, 2025
1 parent b1f2c7c commit 8136258
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ temp-build
*.snap
.idea
.aider*
cmake-build-debug
86 changes: 42 additions & 44 deletions src/command_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ bool CommandController::try_select_floating()
return false;

// TODO: reimplement
// if (auto to_select = state.get_first_with_type(ContainerType::floating_window))
// {
// if (auto const& window = to_select->window())
// {
// window_controller.select_active_window(window.value());
// return true;
// }
// }
// if (auto to_select = state.get_first_with_type(ContainerType::floating_window))
// {
// if (auto const& window = to_select->window())
// {
// window_controller.select_active_window(window.value());
// return true;
// }
// }

return false;
}
Expand Down Expand Up @@ -300,8 +300,8 @@ bool CommandController::try_select_toggle()
if (active->get_type() == ContainerType::leaf)
return try_select_floating();
// TODO: reimplement
// else if (active->get_type() == ContainerType::floating_window)
// return try_select_tiling();
// else if (active->get_type() == ContainerType::floating_window)
// return try_select_tiling();
}

return false;
Expand Down Expand Up @@ -512,32 +512,32 @@ bool CommandController::move_active_to_back_and_forth()
bool CommandController::move_to_scratchpad()
{
// TODO: reimplement
// std::lock_guard lock(mutex);
// if (!can_move_container())
// return false;
//
// // Only floating or tiled windows can be moved to the scratchpad
// auto container = state.focused_container();
// if (container->get_type() != ContainerType::leaf)
// {
// mir::log_error("move_to_scratchpad: cannot move window to scratchpad: %d", static_cast<int>(container->get_type()));
// return false;
// }
//
// // If the window isn't floating already, we should make it floating
// if (container->get_type() != ContainerType::floating_window)
// {
// if (!output_manager->focused())
// return false;
//
// container = toggle_floating_internal(container);
// }
//
// // Remove it from its current workspace since it is no longer wanted there
// if (auto workspace = container->get_workspace())
// workspace->remove_floating_hack(container);
//
// return scratchpad_.move_to(container);
// std::lock_guard lock(mutex);
// if (!can_move_container())
// return false;
//
// // Only floating or tiled windows can be moved to the scratchpad
// auto container = state.focused_container();
// if (container->get_type() != ContainerType::leaf)
// {
// mir::log_error("move_to_scratchpad: cannot move window to scratchpad: %d", static_cast<int>(container->get_type()));
// return false;
// }
//
// // If the window isn't floating already, we should make it floating
// if (container->get_type() != ContainerType::floating_window)
// {
// if (!output_manager->focused())
// return false;
//
// container = toggle_floating_internal(container);
// }
//
// // Remove it from its current workspace since it is no longer wanted there
// if (auto workspace = container->get_workspace())
// workspace->remove_floating_hack(container);
//
// return scratchpad_.move_to(container);
}

bool CommandController::show_scratchpad()
Expand Down Expand Up @@ -588,14 +588,12 @@ std::shared_ptr<Container> CommandController::toggle_floating_internal(std::shar
if (parent.lock()->anchored())
{
geom::Rectangle new_area = {
geom::Point{
container->get_logical_area().top_left.x.as_int() + 50,
container->get_logical_area().top_left.y.as_int() + 50
},
geom::Size{
container->get_logical_area().size.width,
container->get_logical_area().size.height
}
geom::Point {
container->get_logical_area().top_left.x.as_int() + 50,
container->get_logical_area().top_left.y.as_int() + 50 },
geom::Size {
container->get_logical_area().size.width,
container->get_logical_area().size.height }
};
auto new_parent = workspace->create_floating_tree(new_area);
new_parent->graft_existing(container, new_parent->num_nodes());
Expand Down
2 changes: 1 addition & 1 deletion src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ json mode_event_to_json(WindowManagerMode mode)
case WindowManagerMode::moving:
return {
{ "change", "moving" },
{ "pango_markup", true }
{ "pango_markup", true }
};
default:
{
Expand Down
9 changes: 4 additions & 5 deletions src/leaf_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ geom::Rectangle LeafContainer::get_logical_area() const

void LeafContainer::set_logical_area(geom::Rectangle const& target_rect, bool with_animations)
{
if (with_animations)
next_logical_area = target_rect;
else
logical_area = target_rect;
next_logical_area = target_rect;
next_with_animations = with_animations;
}

std::weak_ptr<ParentContainer> LeafContainer::get_parent() const
Expand Down Expand Up @@ -455,7 +453,8 @@ void LeafContainer::commit_changes()
if (is_dragging_ && next_visible_area.top_left != dragged_position)
next_visible_area.top_left = dragged_position;

window_controller.set_rectangle(window_, previous, next_visible_area);
window_controller.set_rectangle(window_, previous, next_visible_area, next_with_animations);
next_with_animations = true;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/leaf_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class LeafContainer : public Container
WindowController& window_controller;
geom::Rectangle logical_area;
std::optional<geom::Rectangle> next_logical_area;
bool next_with_animations = true;
std::shared_ptr<Config> config;
miral::Window window_;
std::weak_ptr<ParentContainer> parent;
Expand Down
2 changes: 1 addition & 1 deletion src/miral_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ AllocationHint MiralWrapperOutput::allocate_position(
if (t == mir_window_type_normal || t == mir_window_type_freestyle)
hint.container_type = ContainerType::leaf;
else
hint.container_type = ContainerType::shell; // This is probably a tooltip or something
hint.container_type = ContainerType::shell; // This is probably a tooltip or something
}

if (hint.container_type == ContainerType::shell)
Expand Down
10 changes: 6 additions & 4 deletions src/move_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#define MIR_LOG_COMPONENT "move_service"
#include "move_service.h"
#include "compositor_state.h"
#include "command_controller.h"
#include "compositor_state.h"
#include "config.h"
#include "output_manager.h"
#include "output.h"
#include "output_manager.h"
#include <mir/log.h>

using namespace miracle;

MoveService::MoveService(
CommandController& command_controller,
std::shared_ptr<Config> const& config,
OutputManager* output_manager)
: command_controller(command_controller), config(config), output_manager(output_manager)
OutputManager* output_manager) :
command_controller(command_controller),
config(config),
output_manager(output_manager)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/move_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ class MoveService

} // miracle

#endif //MIRACLE_WM_MOVE_SERVICE_H
#endif // MIRACLE_WM_MOVE_SERVICE_H
107 changes: 51 additions & 56 deletions src/parent_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,60 +144,60 @@ geom::Rectangle ParentContainer::create_space(int pending_index)
if (scheme == LayoutScheme::horizontal)
{
auto result = insert_node_internal(
placement_area.size.width.as_int(),
placement_area.top_left.x.as_int(),
pending_index,
sub_nodes.size(),
[&](int index)
placement_area.size.width.as_int(),
placement_area.top_left.x.as_int(),
pending_index,
sub_nodes.size(),
[&](int index)
{ return sub_nodes[index]->get_logical_area().size.width.as_int(); },
[&](int index, int size, int pos)
[&](int index, int size, int pos)
{
sub_nodes[index]->set_logical_area({
geom::Point {
pos,
placement_area.top_left.y.as_int() },
geom::Size {
size,
placement_area.size.height.as_int() }
}, false);
geom::Point {
pos,
placement_area.top_left.y.as_int() },
geom::Size {
size,
placement_area.size.height.as_int() }
});
});
geom::Rectangle new_node_logical_rect = {
geom::Point {
result.position,
placement_area.top_left.y.as_int() },
geom::Size {
result.size,
placement_area.size.height.as_int() }
geom::Point {
result.position,
placement_area.top_left.y.as_int() },
geom::Size {
result.size,
placement_area.size.height.as_int() }
};
pending_logical_rect = new_node_logical_rect;
}
else if (scheme == LayoutScheme::vertical)
{
auto result = insert_node_internal(
placement_area.size.height.as_int(),
placement_area.top_left.y.as_int(),
pending_index,
sub_nodes.size(),
[&](int index)
placement_area.size.height.as_int(),
placement_area.top_left.y.as_int(),
pending_index,
sub_nodes.size(),
[&](int index)
{ return sub_nodes[index]->get_logical_area().size.height.as_int(); },
[&](int index, int size, int pos)
[&](int index, int size, int pos)
{
sub_nodes[index]->set_logical_area({
geom::Point {
placement_area.top_left.x.as_int(),
pos },
geom::Size {
placement_area.size.width.as_int(),
size }
}, false);
geom::Point {
placement_area.top_left.x.as_int(),
pos },
geom::Size {
placement_area.size.width.as_int(),
size }
});
});
geom::Rectangle new_node_logical_rect = {
geom::Point {
placement_area.top_left.x.as_int(),
result.position },
geom::Size {
placement_area.size.width.as_int(),
result.size }
geom::Point {
placement_area.top_left.x.as_int(),
result.position },
geom::Size {
placement_area.size.width.as_int(),
result.size }
};
pending_logical_rect = new_node_logical_rect;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ void ParentContainer::graft_existing(std::shared_ptr<Container> const& node, int
{
auto rectangle = create_space(index);
node->set_parent(as_parent(shared_from_this()));
node->set_logical_area(rectangle, true);
node->set_logical_area(rectangle);
sub_nodes.insert(sub_nodes.begin() + index, node);
relayout();
constrain();
Expand Down Expand Up @@ -305,10 +305,7 @@ void ParentContainer::set_logical_area(const geom::Rectangle& target_rect, bool
// We need to look at the target dimension and scale everyone relative to that.
// However, the "non-main-axis" dimension will be consistent across each node.
auto current_logical_area = get_logical_area();
if (with_animations)
logical_area = target_rect;
else
logical_area = target_rect;
logical_area = target_rect;
auto target_placement_area = get_logical_area();
std::vector<geom::Rectangle> pending_size_updates;
pending_size_updates.reserve(sub_nodes.size());
Expand Down Expand Up @@ -618,8 +615,6 @@ void ParentContainer::handle_request_resize(MirInputEvent const* input_event, Mi

void ParentContainer::handle_raise()
{
for (auto const& node : sub_nodes)
node->handle_raise();
}

bool ParentContainer::resize(Direction direction, int pixels)
Expand Down Expand Up @@ -792,11 +787,6 @@ bool ParentContainer::move(Direction direction)
return false;
}

bool ParentContainer::move_by(Direction direction, int pixels)
{
return false;
}

bool ParentContainer::move_by(float dx, float dy)
{
if (auto sh_parent = parent.lock())
Expand All @@ -809,11 +799,16 @@ bool ParentContainer::move_by(float dx, float dy)
auto area = logical_area;
area.top_left.x = geom::X { (float)area.top_left.x.as_int() + dx };
area.top_left.y = geom::Y { (float)area.top_left.y.as_int() + dy };
set_logical_area(area);
set_logical_area(area, false);
commit_changes();
return true;
}

bool ParentContainer::move_by(Direction direction, int pixels)
{
return false;
}

bool ParentContainer::move_to(int x, int y)
{
if (is_anchored)
Expand Down Expand Up @@ -863,6 +858,11 @@ bool ParentContainer::set_layout(LayoutScheme new_scheme)
return true;
}

LayoutScheme ParentContainer::get_layout() const
{
return scheme;
}

bool ParentContainer::set_anchored(bool anchor)
{
is_anchored = anchor;
Expand All @@ -874,11 +874,6 @@ bool ParentContainer::anchored() const
return is_anchored;
}

LayoutScheme ParentContainer::get_layout() const
{
return scheme;
}

nlohmann::json ParentContainer::to_json() const
{
auto const visible_area = get_visible_area();
Expand Down
Loading

0 comments on commit 8136258

Please sign in to comment.