Skip to content

Commit

Permalink
surface-controller: update subsurfaces positions when toplevel surfac…
Browse files Browse the repository at this point in the history
…e is committed

wlroots updates the positions of these subsurfaces when the main surface is committed.
  • Loading branch information
ammen99 committed Sep 14, 2023
1 parent 55413f8 commit cf63b2a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/view/subsurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ wf::wlr_subsurface_controller_t::wlr_subsurface_controller_t(wlr_subsurface *sub
on_destroy.set_callback([=] (void*)
{
wf::scene::remove_child(subsurface_root_node);
sub->data = NULL;
delete this;
});

Expand Down
2 changes: 1 addition & 1 deletion src/view/subsurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class wlr_subsurface_root_node_t : public wf::scene::translation_node_t
public:
wlr_subsurface_root_node_t(wlr_subsurface *subsurface);
std::string stringify() const override;
void update_offset();

private:
wlr_subsurface *subsurface;
wf::wl_listener_wrapper on_subsurface_destroy;
wf::wl_listener_wrapper on_subsurface_commit;
void update_offset();
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/view/surface-impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class wlr_surface_controller_t

wf::wl_listener_wrapper on_destroy;
wf::wl_listener_wrapper on_new_subsurface;
wf::wl_listener_wrapper on_commit;
};
}
22 changes: 22 additions & 0 deletions src/view/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
#include "wayfire/signal-definitions.hpp"
#include <wayfire/scene-operations.hpp>

static void update_subsurface_position(wlr_surface *surface, int, int, void*)
{
if (wlr_surface_is_subsurface(surface))
{
auto sub = wlr_subsurface_from_wlr_surface(surface);
if (sub->data)
{
((wf::wlr_subsurface_controller_t*)sub->data)->get_subsurface_root()->update_offset();
}
}
}

wf::wlr_surface_controller_t::wlr_surface_controller_t(wlr_surface *surface,
scene::floating_inner_ptr root_node)
{
Expand Down Expand Up @@ -51,6 +63,16 @@ wf::wlr_surface_controller_t::wlr_surface_controller_t(wlr_surface *surface,
{
on_new_subsurface.emit(sub);
}

if (!wlr_surface_is_subsurface(surface))
{
on_commit.set_callback([=] (void*)
{
wlr_surface_for_each_surface(surface, update_subsurface_position, nullptr);
});

on_commit.connect(&surface->events.commit);
}
}

wf::wlr_surface_controller_t::~wlr_surface_controller_t()
Expand Down

0 comments on commit cf63b2a

Please sign in to comment.