Skip to content

Commit d1f33e5

Browse files
committed
api: split view into view and toplevel-view
Fixes #1309
1 parent 8fba32c commit d1f33e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1468
-1410
lines changed

plugins/animate/animate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct animation_hook : public animation_hook_base
142142
/* We don't want to change the state of the view if it was detached */
143143
if ((type == ANIMATION_TYPE_MINIMIZE) && !detached)
144144
{
145-
view->set_minimized(true);
145+
toplevel_cast(view)->set_minimized(true);
146146
}
147147

148148
view->erase_data(name);

plugins/animate/basic_animations.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "animate.hpp"
2+
#include "wayfire/toplevel-view.hpp"
23
#include <memory>
34
#include <wayfire/plugin.hpp>
45
#include <wayfire/opengl.hpp>
@@ -96,13 +97,15 @@ class zoom_animation : public animation_base
9697

9798
if (type & MINIMIZE_STATE_ANIMATION)
9899
{
99-
auto hint = view->get_minimize_hint();
100+
auto toplevel = wf::toplevel_cast(view);
101+
wf::dassert(toplevel != nullptr, "We cannot minimize non-toplevel views!");
102+
auto hint = toplevel->get_minimize_hint();
100103
if ((hint.width > 0) && (hint.height > 0))
101104
{
102105
int hint_cx = hint.x + hint.width / 2;
103106
int hint_cy = hint.y + hint.height / 2;
104107

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

plugins/common/wayfire/plugins/common/move-drag-interface.hpp

+12-14
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct drag_done_signal
9494
struct view_t
9595
{
9696
/** Dragged view. */
97-
wayfire_view view;
97+
wayfire_toplevel_view view;
9898

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

109109
/** The main view which was dragged. */
110-
wayfire_view main_view;
110+
wayfire_toplevel_view main_view;
111111

112112
/**
113113
* The position of the input when the view was dropped.
@@ -256,7 +256,7 @@ static const std::string move_drag_transformer = "move-drag-transformer";
256256
struct dragged_view_t
257257
{
258258
// The view being dragged
259-
wayfire_view view;
259+
wayfire_toplevel_view view;
260260

261261
// Its transformer
262262
std::shared_ptr<scale_around_grab_t> transformer;
@@ -267,7 +267,7 @@ struct dragged_view_t
267267
wf::geometry_t last_bbox;
268268
};
269269

270-
inline wayfire_view get_toplevel(wayfire_view view)
270+
inline wayfire_toplevel_view get_toplevel(wayfire_toplevel_view view)
271271
{
272272
while (view->parent)
273273
{
@@ -277,10 +277,10 @@ inline wayfire_view get_toplevel(wayfire_view view)
277277
return view;
278278
}
279279

280-
inline std::vector<wayfire_view> get_target_views(wayfire_view grabbed,
280+
inline std::vector<wayfire_toplevel_view> get_target_views(wayfire_toplevel_view grabbed,
281281
bool join_views)
282282
{
283-
std::vector<wayfire_view> r = {grabbed};
283+
std::vector<wayfire_toplevel_view> r = {grabbed};
284284
if (join_views)
285285
{
286286
r = grabbed->enumerate_views();
@@ -419,7 +419,7 @@ class core_drag_t : public signal::provider_t
419419
* Rebuild the wobbly model after a change in the scaling, so that the wobbly
420420
* model does not try to animate the scaling change itself.
421421
*/
422-
void rebuild_wobbly(wayfire_view view, wf::point_t grab, wf::pointf_t relative)
422+
void rebuild_wobbly(wayfire_toplevel_view view, wf::point_t grab, wf::pointf_t relative)
423423
{
424424
auto dim = wf::dimensions(wf::view_bounding_box_up_to(view, "wobbly"));
425425
modify_wobbly(view, find_geometry_around(dim, grab, relative));
@@ -433,7 +433,7 @@ class core_drag_t : public signal::provider_t
433433
* @param grab_position The position of the input, in output-layout coordinates.
434434
* @param relative The position of the grab_position relative to view.
435435
*/
436-
void start_drag(wayfire_view grab_view, wf::point_t grab_position,
436+
void start_drag(wayfire_toplevel_view grab_view, wf::point_t grab_position,
437437
wf::pointf_t relative,
438438
const drag_options_t& options)
439439
{
@@ -501,8 +501,7 @@ class core_drag_t : public signal::provider_t
501501
}
502502
}
503503

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

512511
auto bbox = view->get_transformed_node()->get_bounding_box() +
513512
wf::origin(view->get_output()->get_layout_geometry());
514-
start_drag(view, grab_position,
515-
find_relative_grab(bbox, grab_position), options);
513+
start_drag(view, grab_position, find_relative_grab(bbox, grab_position), options);
516514
}
517515

518516
void handle_motion(wf::point_t to)
@@ -631,7 +629,7 @@ class core_drag_t : public signal::provider_t
631629
}
632630

633631
// View currently being moved.
634-
wayfire_view view;
632+
wayfire_toplevel_view view;
635633

636634
// Output where the action is happening.
637635
wf::output_t *current_output = NULL;
@@ -779,7 +777,7 @@ inline void adjust_view_on_output(drag_done_signal *ev)
779777
/**
780778
* Adjust the view's state after snap-off.
781779
*/
782-
inline void adjust_view_on_snap_off(wayfire_view view)
780+
inline void adjust_view_on_snap_off(wayfire_toplevel_view view)
783781
{
784782
if (view->tiled_edges && !view->fullscreen)
785783
{

plugins/decor/deco-subsurface.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <wayfire/decorator.hpp>
1818
#include <wayfire/view-transform.hpp>
1919
#include <wayfire/signal-definitions.hpp>
20+
#include <wayfire/toplevel-view.hpp>
2021
#include "deco-subsurface.hpp"
2122
#include "deco-layout.hpp"
2223
#include "deco-theme.hpp"
@@ -28,7 +29,7 @@
2829
class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_interaction_t,
2930
public wf::touch_interaction_t
3031
{
31-
wayfire_view view;
32+
wayfire_toplevel_view view;
3233
wf::signal::connection_t<wf::view_title_changed_signal> title_set =
3334
[=] (wf::view_title_changed_signal *ev)
3435
{
@@ -68,7 +69,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
6869
int current_thickness;
6970
int current_titlebar;
7071

71-
simple_decoration_node_t(wayfire_view view) :
72+
simple_decoration_node_t(wayfire_toplevel_view view) :
7273
node_t(false),
7374
theme{},
7475
layout{theme, [=] (wlr_box box) { wf::scene::damage_node(shared_from_this(), box + get_offset()); }}
@@ -314,7 +315,7 @@ class simple_decoration_node_t : public wf::scene::node_t, public wf::pointer_in
314315

315316
class simple_decorator_t : public wf::decorator_frame_t_t
316317
{
317-
wayfire_view view;
318+
wayfire_toplevel_view view;
318319
std::shared_ptr<simple_decoration_node_t> deco;
319320

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

339340
public:
340-
simple_decorator_t(wayfire_view view)
341+
simple_decorator_t(wayfire_toplevel_view view)
341342
{
342343
this->view = view;
343344
deco = std::make_shared<simple_decoration_node_t>(view);
@@ -365,13 +366,13 @@ class simple_decorator_t : public wf::decorator_frame_t_t
365366
}
366367
};
367368

368-
void init_view(wayfire_view view)
369+
void init_view(wayfire_toplevel_view view)
369370
{
370371
auto decor = std::make_unique<simple_decorator_t>(view);
371372
view->set_decoration(std::move(decor));
372373
}
373374

374-
void deinit_view(wayfire_view view)
375+
void deinit_view(wayfire_toplevel_view view)
375376
{
376377
view->set_decoration(nullptr);
377378
}

plugins/decor/deco-subsurface.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include <wayfire/view.hpp>
55

6-
void init_view(wayfire_view view);
7-
void deinit_view(wayfire_view view);
6+
void init_view(wayfire_toplevel_view view);
7+
void deinit_view(wayfire_toplevel_view view);
88

99
#endif /* end of include guard: DECO_SUBSURFACE_HPP */

plugins/decor/decoration.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "wayfire/core.hpp"
1010
#include "wayfire/plugin.hpp"
1111
#include "wayfire/signal-provider.hpp"
12+
#include "wayfire/toplevel-view.hpp"
1213

1314
class wayfire_decoration : public wf::plugin_interface_t
1415
{
@@ -41,7 +42,10 @@ class wayfire_decoration : public wf::plugin_interface_t
4142
{
4243
for (auto view : wf::get_core().get_all_views())
4344
{
44-
deinit_view(view);
45+
if (auto toplevel = wf::toplevel_cast(view))
46+
{
47+
deinit_view(toplevel);
48+
}
4549
}
4650
}
4751

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

6064
void update_view_decoration(wayfire_view view)
6165
{
62-
if (view->should_be_decorated() && !ignore_decoration_of_view(view))
66+
if (auto toplevel = wf::toplevel_cast(view))
6367
{
64-
init_view(view);
65-
} else
66-
{
67-
deinit_view(view);
68+
if (toplevel->should_be_decorated() && !ignore_decoration_of_view(view))
69+
{
70+
init_view(toplevel);
71+
} else
72+
{
73+
deinit_view(toplevel);
74+
}
6875
}
6976
}
7077
};

plugins/grid/grid.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class wf_grid_slot_data : public wf::custom_data_t
2525
int slot;
2626
};
2727

28-
nonstd::observer_ptr<wf::grid::grid_animation_t> ensure_grid_view(wayfire_view view)
28+
nonstd::observer_ptr<wf::grid::grid_animation_t> ensure_grid_view(wayfire_toplevel_view view)
2929
{
3030
if (!view->has_data<wf::grid::grid_animation_t>())
3131
{
@@ -117,14 +117,13 @@ class wayfire_grid : public wf::per_output_plugin_instance_t
117117
return false;
118118
}
119119

120-
auto view = output->get_active_view();
121-
if (!view || (view->role != wf::VIEW_ROLE_TOPLEVEL))
120+
auto view = toplevel_cast(output->get_active_view());
121+
if (!view)
122122
{
123123
return false;
124124
}
125125

126126
view->tile_request(0);
127-
128127
return true;
129128
};
130129

@@ -136,7 +135,7 @@ class wayfire_grid : public wf::per_output_plugin_instance_t
136135
keys[i].load_option("grid/slot_" + slots[i]);
137136
bindings[i] = [=] (auto)
138137
{
139-
auto view = output->get_active_view();
138+
auto view = toplevel_cast(output->get_active_view());
140139
if (!view || (view->role != wf::VIEW_ROLE_TOPLEVEL))
141140
{
142141
return false;
@@ -163,13 +162,13 @@ class wayfire_grid : public wf::per_output_plugin_instance_t
163162
output->connect(&on_fullscreen_signal);
164163
}
165164

166-
bool can_adjust_view(wayfire_view view)
165+
bool can_adjust_view(wayfire_toplevel_view view)
167166
{
168167
uint32_t req_actions = wf::VIEW_ALLOW_MOVE | wf::VIEW_ALLOW_RESIZE;
169168
return (view->get_allowed_actions() & req_actions) == req_actions;
170169
}
171170

172-
void handle_slot(wayfire_view view, int slot, wf::point_t delta = {0, 0})
171+
void handle_slot(wayfire_toplevel_view view, int slot, wf::point_t delta = {0, 0})
173172
{
174173
if (!can_adjust_view(view))
175174
{

plugins/grid/wayfire/plugins/crossfade.hpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "wayfire/signal-provider.hpp"
1111
#include <memory>
1212
#include <wayfire/view-transform.hpp>
13+
#include <wayfire/toplevel-view.hpp>
1314
#include <wayfire/output.hpp>
1415
#include <wayfire/nonstd/wlroots.hpp>
1516
#include <wayfire/plugins/common/geometry-animation.hpp>
@@ -37,7 +38,7 @@ class crossfade_node_t : public scene::view_2d_transformer_t
3738
wf::geometry_t displayed_geometry;
3839
double overlay_alpha;
3940

40-
crossfade_node_t(wayfire_view view) : view_2d_transformer_t(view)
41+
crossfade_node_t(wayfire_toplevel_view view) : view_2d_transformer_t(view)
4142
{
4243
displayed_geometry = view->get_wm_geometry();
4344
this->view = view;
@@ -173,7 +174,7 @@ class grid_animation_t : public wf::custom_data_t
173174
* @param type Indicates which animation method to use.
174175
* @param duration Indicates the duration of the animation (only for crossfade)
175176
*/
176-
grid_animation_t(wayfire_view view, type_t type,
177+
grid_animation_t(wayfire_toplevel_view view, type_t type,
177178
wf::option_sptr_t<int> duration)
178179
{
179180
this->view = view;
@@ -284,7 +285,7 @@ class grid_animation_t : public wf::custom_data_t
284285
}
285286

286287
wf::geometry_t original;
287-
wayfire_view view;
288+
wayfire_toplevel_view view;
288289
wf::output_t *output;
289290
wf::signal::connection_t<view_disappeared_signal> on_disappear = [=] (view_disappeared_signal *ev)
290291
{

plugins/grid/wayfire/plugins/grid.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct grid_query_geometry_signal
4747
*/
4848
struct grid_snap_view_signal
4949
{
50-
wayfire_view view;
50+
wayfire_toplevel_view view;
5151
slot_t slot;
5252
};
5353
}

plugins/ipc/demo-ipc.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <wayfire/per-output-plugin.hpp>
33
#include <wayfire/view.hpp>
44
#include <wayfire/output.hpp>
5+
#include <wayfire/toplevel-view.hpp>
56
#include <set>
67

78
#include "ipc-helpers.hpp"
@@ -81,8 +82,13 @@ class wayfire_demo_ipc : public wf::plugin_interface_t
8182
{
8283
if (auto geometry = wf::ipc::geometry_from_json(data["geometry"]))
8384
{
84-
view->set_geometry(geometry.value());
85-
return wf::ipc::json_ok();
85+
if (auto toplevel = toplevel_cast(view))
86+
{
87+
toplevel->set_geometry(geometry.value());
88+
return wf::ipc::json_ok();
89+
}
90+
91+
return wf::ipc::json_error("view is not toplevel");
8692
}
8793

8894
return wf::ipc::json_error("geometry incorrect");
@@ -119,8 +125,10 @@ class wayfire_demo_ipc : public wf::plugin_interface_t
119125
description["id"] = view->get_id();
120126
description["app-id"] = view->get_app_id();
121127
description["title"] = view->get_title();
122-
description["geometry"] = wf::ipc::geometry_to_json(view->get_wm_geometry());
123-
description["output"] = view->get_output() ? view->get_output()->get_id() : -1;
128+
auto toplevel = wf::toplevel_cast(view);
129+
description["geometry"] =
130+
wf::ipc::geometry_to_json(toplevel ? toplevel->get_wm_geometry() : view->get_bounding_box());
131+
description["output"] = view->get_output() ? view->get_output()->get_id() : -1;
124132
return description;
125133
}
126134
};

0 commit comments

Comments
 (0)