Skip to content

Commit

Permalink
Allow re-ordering subsurfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
wmww committed Jun 23, 2022
1 parent 06db9a5 commit d2c622f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/server/frontend_wayland/wl_subcompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,22 @@ void mf::WlSubsurface::set_position(int32_t x, int32_t y)

void mf::WlSubsurface::place_above(struct wl_resource* sibling)
{
(void)sibling;
log_warning("TODO: wl_subsurface.place_above not implemented");
if (parent)
{
auto const sibling_surface = WlSurface::from(sibling);
parent.value().reorder_subsurface(this, sibling_surface, true);
}
surface->pending_invalidate_surface_data();
}

void mf::WlSubsurface::place_below(struct wl_resource* sibling)
{
(void)sibling;
log_warning("TODO: wl_subsurface.place_below not implemented");
if (parent)
{
auto const sibling_surface = WlSurface::from(sibling);
parent.value().reorder_subsurface(this, sibling_surface, false);
}
surface->pending_invalidate_surface_data();
}

void mf::WlSubsurface::set_sync()
Expand Down
3 changes: 2 additions & 1 deletion src/server/frontend_wayland/wl_subcompositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class WlSubsurface: public WlSurfaceRole, wayland::Subsurface

auto subsurface_at(geometry::Point point) -> std::optional<WlSurface*>;

WlSurface* const surface;

private:
void set_position(int32_t x, int32_t y) override;
void place_above(struct wl_resource* sibling) override;
Expand All @@ -75,7 +77,6 @@ class WlSubsurface: public WlSurfaceRole, wayland::Subsurface
virtual void commit(WlSurfaceState const& state) override;
void surface_destroyed() override;

WlSurface* const surface;
/// This class is responsible for removing itself from the parent's children list when needed
wayland::Weak<WlSurface> const parent;
wayland::Weak<WlClient> const weak_client;
Expand Down
20 changes: 20 additions & 0 deletions src/server/frontend_wayland/wl_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ void mf::WlSurface::remove_subsurface(WlSubsurface* child)
children.end());
}

void mf::WlSurface::reorder_subsurface(WlSubsurface* child, WlSurface* sibling, bool above)
{
if (!child)
{
// Unlikely, but resulting error would be hard to catch otherwise
fatal_error("subsurface null");
}
auto iter = std::find_if(begin(children), end(children), [&](WlSubsurface* subsurface)
{
auto const surface = subsurface ? subsurface->surface : this;
return surface == sibling;
});
if (!above)
{
// place below
iter--;
}
children.insert(iter, child);
}

void mf::WlSurface::refresh_surface_data_now()
{
role->refresh_surface_data_now();
Expand Down
2 changes: 2 additions & 0 deletions src/server/frontend_wayland/wl_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class WlSurface : public wayland::Surface
void set_pending_offset(std::optional<geometry::Displacement> const& offset);
void add_subsurface(WlSubsurface* child);
void remove_subsurface(WlSubsurface* child);
/// Place a subsurface directly above or below the sibling surface
void reorder_subsurface(WlSubsurface* child, WlSurface* sibling, bool above);
void refresh_surface_data_now();
void pending_invalidate_surface_data() { pending.invalidate_surface_data(); }
void populate_surface_data(std::vector<shell::StreamSpecification>& buffer_streams,
Expand Down

0 comments on commit d2c622f

Please sign in to comment.