Skip to content

Commit

Permalink
api: split view into view and toplevel-view
Browse files Browse the repository at this point in the history
Fixes #1309
  • Loading branch information
ammen99 committed Jun 26, 2023
1 parent 8fba32c commit d1f33e5
Show file tree
Hide file tree
Showing 75 changed files with 1,468 additions and 1,410 deletions.
2 changes: 1 addition & 1 deletion plugins/animate/animate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct animation_hook : public animation_hook_base
/* We don't want to change the state of the view if it was detached */
if ((type == ANIMATION_TYPE_MINIMIZE) && !detached)
{
view->set_minimized(true);
toplevel_cast(view)->set_minimized(true);
}

view->erase_data(name);
Expand Down
7 changes: 5 additions & 2 deletions plugins/animate/basic_animations.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "animate.hpp"
#include "wayfire/toplevel-view.hpp"
#include <memory>
#include <wayfire/plugin.hpp>
#include <wayfire/opengl.hpp>
Expand Down Expand Up @@ -96,13 +97,15 @@ class zoom_animation : public animation_base

if (type & MINIMIZE_STATE_ANIMATION)
{
auto hint = view->get_minimize_hint();
auto toplevel = wf::toplevel_cast(view);
wf::dassert(toplevel != nullptr, "We cannot minimize non-toplevel views!");
auto hint = toplevel->get_minimize_hint();
if ((hint.width > 0) && (hint.height > 0))
{
int hint_cx = hint.x + hint.width / 2;
int hint_cy = hint.y + hint.height / 2;

auto bbox = view->get_wm_geometry();
auto bbox = toplevel->get_wm_geometry();
int view_cx = bbox.x + bbox.width / 2;
int view_cy = bbox.y + bbox.height / 2;

Expand Down
26 changes: 12 additions & 14 deletions plugins/common/wayfire/plugins/common/move-drag-interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct drag_done_signal
struct view_t
{
/** Dragged view. */
wayfire_view view;
wayfire_toplevel_view view;

/**
* The position relative to the view where the grab was.
Expand All @@ -107,7 +107,7 @@ struct drag_done_signal
std::vector<view_t> all_views;

/** The main view which was dragged. */
wayfire_view main_view;
wayfire_toplevel_view main_view;

/**
* The position of the input when the view was dropped.
Expand Down Expand Up @@ -256,7 +256,7 @@ static const std::string move_drag_transformer = "move-drag-transformer";
struct dragged_view_t
{
// The view being dragged
wayfire_view view;
wayfire_toplevel_view view;

// Its transformer
std::shared_ptr<scale_around_grab_t> transformer;
Expand All @@ -267,7 +267,7 @@ struct dragged_view_t
wf::geometry_t last_bbox;
};

inline wayfire_view get_toplevel(wayfire_view view)
inline wayfire_toplevel_view get_toplevel(wayfire_toplevel_view view)
{
while (view->parent)
{
Expand All @@ -277,10 +277,10 @@ inline wayfire_view get_toplevel(wayfire_view view)
return view;
}

inline std::vector<wayfire_view> get_target_views(wayfire_view grabbed,
inline std::vector<wayfire_toplevel_view> get_target_views(wayfire_toplevel_view grabbed,
bool join_views)
{
std::vector<wayfire_view> r = {grabbed};
std::vector<wayfire_toplevel_view> r = {grabbed};
if (join_views)
{
r = grabbed->enumerate_views();
Expand Down Expand Up @@ -419,7 +419,7 @@ class core_drag_t : public signal::provider_t
* Rebuild the wobbly model after a change in the scaling, so that the wobbly
* model does not try to animate the scaling change itself.
*/
void rebuild_wobbly(wayfire_view view, wf::point_t grab, wf::pointf_t relative)
void rebuild_wobbly(wayfire_toplevel_view view, wf::point_t grab, wf::pointf_t relative)
{
auto dim = wf::dimensions(wf::view_bounding_box_up_to(view, "wobbly"));
modify_wobbly(view, find_geometry_around(dim, grab, relative));
Expand All @@ -433,7 +433,7 @@ class core_drag_t : public signal::provider_t
* @param grab_position The position of the input, in output-layout coordinates.
* @param relative The position of the grab_position relative to view.
*/
void start_drag(wayfire_view grab_view, wf::point_t grab_position,
void start_drag(wayfire_toplevel_view grab_view, wf::point_t grab_position,
wf::pointf_t relative,
const drag_options_t& options)
{
Expand Down Expand Up @@ -501,8 +501,7 @@ class core_drag_t : public signal::provider_t
}
}

void start_drag(wayfire_view view, wf::point_t grab_position,
const drag_options_t& options)
void start_drag(wayfire_toplevel_view view, wf::point_t grab_position, const drag_options_t& options)
{
if (options.join_views)
{
Expand All @@ -511,8 +510,7 @@ class core_drag_t : public signal::provider_t

auto bbox = view->get_transformed_node()->get_bounding_box() +
wf::origin(view->get_output()->get_layout_geometry());
start_drag(view, grab_position,
find_relative_grab(bbox, grab_position), options);
start_drag(view, grab_position, find_relative_grab(bbox, grab_position), options);
}

void handle_motion(wf::point_t to)
Expand Down Expand Up @@ -631,7 +629,7 @@ class core_drag_t : public signal::provider_t
}

// View currently being moved.
wayfire_view view;
wayfire_toplevel_view view;

// Output where the action is happening.
wf::output_t *current_output = NULL;
Expand Down Expand Up @@ -779,7 +777,7 @@ inline void adjust_view_on_output(drag_done_signal *ev)
/**
* Adjust the view's state after snap-off.
*/
inline void adjust_view_on_snap_off(wayfire_view view)
inline void adjust_view_on_snap_off(wayfire_toplevel_view view)
{
if (view->tiled_edges && !view->fullscreen)
{
Expand Down
13 changes: 7 additions & 6 deletions plugins/decor/deco-subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <wayfire/decorator.hpp>
#include <wayfire/view-transform.hpp>
#include <wayfire/signal-definitions.hpp>
#include <wayfire/toplevel-view.hpp>
#include "deco-subsurface.hpp"
#include "deco-layout.hpp"
#include "deco-theme.hpp"
Expand All @@ -28,7 +29,7 @@
class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_interaction_t,
public wf::touch_interaction_t
{
wayfire_view view;
wayfire_toplevel_view view;
wf::signal::connection_t<wf::view_title_changed_signal> title_set =
[=] (wf::view_title_changed_signal *ev)
{
Expand Down Expand Up @@ -68,7 +69,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
int current_thickness;
int current_titlebar;

simple_decoration_node_t(wayfire_view view) :
simple_decoration_node_t(wayfire_toplevel_view view) :
node_t(false),
theme{},
layout{theme, [=] (wlr_box box) { wf::scene::damage_node(shared_from_this(), box + get_offset()); }}
Expand Down Expand Up @@ -314,7 +315,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in

class simple_decorator_t : public wf::decorator_frame_t_t
{
wayfire_view view;
wayfire_toplevel_view view;
std::shared_ptr<simple_decoration_node_t> deco;

wf::signal::connection_t<wf::view_activated_state_signal> on_view_activated = [&] (auto)
Expand All @@ -337,7 +338,7 @@ class simple_decorator_t : public wf::decorator_frame_t_t
};

public:
simple_decorator_t(wayfire_view view)
simple_decorator_t(wayfire_toplevel_view view)
{
this->view = view;
deco = std::make_shared<simple_decoration_node_t>(view);
Expand Down Expand Up @@ -365,13 +366,13 @@ class simple_decorator_t : public wf::decorator_frame_t_t
}
};

void init_view(wayfire_view view)
void init_view(wayfire_toplevel_view view)
{
auto decor = std::make_unique<simple_decorator_t>(view);
view->set_decoration(std::move(decor));
}

void deinit_view(wayfire_view view)
void deinit_view(wayfire_toplevel_view view)
{
view->set_decoration(nullptr);
}
4 changes: 2 additions & 2 deletions plugins/decor/deco-subsurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include <wayfire/view.hpp>

void init_view(wayfire_view view);
void deinit_view(wayfire_view view);
void init_view(wayfire_toplevel_view view);
void deinit_view(wayfire_toplevel_view view);

#endif /* end of include guard: DECO_SUBSURFACE_HPP */
19 changes: 13 additions & 6 deletions plugins/decor/decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "wayfire/core.hpp"
#include "wayfire/plugin.hpp"
#include "wayfire/signal-provider.hpp"
#include "wayfire/toplevel-view.hpp"

class wayfire_decoration : public wf::plugin_interface_t
{
Expand Down Expand Up @@ -41,7 +42,10 @@ class wayfire_decoration : public wf::plugin_interface_t
{
for (auto view : wf::get_core().get_all_views())
{
deinit_view(view);
if (auto toplevel = wf::toplevel_cast(view))
{
deinit_view(toplevel);
}
}
}

Expand All @@ -59,12 +63,15 @@ class wayfire_decoration : public wf::plugin_interface_t

void update_view_decoration(wayfire_view view)
{
if (view->should_be_decorated() && !ignore_decoration_of_view(view))
if (auto toplevel = wf::toplevel_cast(view))
{
init_view(view);
} else
{
deinit_view(view);
if (toplevel->should_be_decorated() && !ignore_decoration_of_view(view))
{
init_view(toplevel);
} else
{
deinit_view(toplevel);
}
}
}
};
Expand Down
13 changes: 6 additions & 7 deletions plugins/grid/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class wf_grid_slot_data : public wf::custom_data_t
int slot;
};

nonstd::observer_ptr<wf::grid::grid_animation_t> ensure_grid_view(wayfire_view view)
nonstd::observer_ptr<wf::grid::grid_animation_t> ensure_grid_view(wayfire_toplevel_view view)
{
if (!view->has_data<wf::grid::grid_animation_t>())
{
Expand Down Expand Up @@ -117,14 +117,13 @@ class wayfire_grid : public wf::per_output_plugin_instance_t
return false;
}

auto view = output->get_active_view();
if (!view || (view->role != wf::VIEW_ROLE_TOPLEVEL))
auto view = toplevel_cast(output->get_active_view());
if (!view)
{
return false;
}

view->tile_request(0);

return true;
};

Expand All @@ -136,7 +135,7 @@ class wayfire_grid : public wf::per_output_plugin_instance_t
keys[i].load_option("grid/slot_" + slots[i]);
bindings[i] = [=] (auto)
{
auto view = output->get_active_view();
auto view = toplevel_cast(output->get_active_view());
if (!view || (view->role != wf::VIEW_ROLE_TOPLEVEL))
{
return false;
Expand All @@ -163,13 +162,13 @@ class wayfire_grid : public wf::per_output_plugin_instance_t
output->connect(&on_fullscreen_signal);
}

bool can_adjust_view(wayfire_view view)
bool can_adjust_view(wayfire_toplevel_view view)
{
uint32_t req_actions = wf::VIEW_ALLOW_MOVE | wf::VIEW_ALLOW_RESIZE;
return (view->get_allowed_actions() & req_actions) == req_actions;
}

void handle_slot(wayfire_view view, int slot, wf::point_t delta = {0, 0})
void handle_slot(wayfire_toplevel_view view, int slot, wf::point_t delta = {0, 0})
{
if (!can_adjust_view(view))
{
Expand Down
7 changes: 4 additions & 3 deletions plugins/grid/wayfire/plugins/crossfade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "wayfire/signal-provider.hpp"
#include <memory>
#include <wayfire/view-transform.hpp>
#include <wayfire/toplevel-view.hpp>
#include <wayfire/output.hpp>
#include <wayfire/nonstd/wlroots.hpp>
#include <wayfire/plugins/common/geometry-animation.hpp>
Expand Down Expand Up @@ -37,7 +38,7 @@ class crossfade_node_t : public scene::view_2d_transformer_t
wf::geometry_t displayed_geometry;
double overlay_alpha;

crossfade_node_t(wayfire_view view) : view_2d_transformer_t(view)
crossfade_node_t(wayfire_toplevel_view view) : view_2d_transformer_t(view)
{
displayed_geometry = view->get_wm_geometry();
this->view = view;
Expand Down Expand Up @@ -173,7 +174,7 @@ class grid_animation_t : public wf::custom_data_t
* @param type Indicates which animation method to use.
* @param duration Indicates the duration of the animation (only for crossfade)
*/
grid_animation_t(wayfire_view view, type_t type,
grid_animation_t(wayfire_toplevel_view view, type_t type,
wf::option_sptr_t<int> duration)
{
this->view = view;
Expand Down Expand Up @@ -284,7 +285,7 @@ class grid_animation_t : public wf::custom_data_t
}

wf::geometry_t original;
wayfire_view view;
wayfire_toplevel_view view;
wf::output_t *output;
wf::signal::connection_t<view_disappeared_signal> on_disappear = [=] (view_disappeared_signal *ev)
{
Expand Down
2 changes: 1 addition & 1 deletion plugins/grid/wayfire/plugins/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct grid_query_geometry_signal
*/
struct grid_snap_view_signal
{
wayfire_view view;
wayfire_toplevel_view view;
slot_t slot;
};
}
Expand Down
16 changes: 12 additions & 4 deletions plugins/ipc/demo-ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <wayfire/per-output-plugin.hpp>
#include <wayfire/view.hpp>
#include <wayfire/output.hpp>
#include <wayfire/toplevel-view.hpp>
#include <set>

#include "ipc-helpers.hpp"
Expand Down Expand Up @@ -81,8 +82,13 @@ class wayfire_demo_ipc : public wf::plugin_interface_t
{
if (auto geometry = wf::ipc::geometry_from_json(data["geometry"]))
{
view->set_geometry(geometry.value());
return wf::ipc::json_ok();
if (auto toplevel = toplevel_cast(view))
{
toplevel->set_geometry(geometry.value());
return wf::ipc::json_ok();
}

return wf::ipc::json_error("view is not toplevel");
}

return wf::ipc::json_error("geometry incorrect");
Expand Down Expand Up @@ -119,8 +125,10 @@ class wayfire_demo_ipc : public wf::plugin_interface_t
description["id"] = view->get_id();
description["app-id"] = view->get_app_id();
description["title"] = view->get_title();
description["geometry"] = wf::ipc::geometry_to_json(view->get_wm_geometry());
description["output"] = view->get_output() ? view->get_output()->get_id() : -1;
auto toplevel = wf::toplevel_cast(view);
description["geometry"] =
wf::ipc::geometry_to_json(toplevel ? toplevel->get_wm_geometry() : view->get_bounding_box());
description["output"] = view->get_output() ? view->get_output()->get_id() : -1;
return description;
}
};
Expand Down
Loading

0 comments on commit d1f33e5

Please sign in to comment.