Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

scene: add functions to place node on top/bottom #3251

Merged
merged 2 commits into from
Oct 14, 2021

Conversation

ifreund
Copy link
Member

@ifreund ifreund commented Oct 12, 2021

Currently these functions remove the node from the scene if the sibling
argument is the same node as the node. Making this case a noop is much
more predictable behavior.

@vyivel
Copy link
Member

vyivel commented Oct 12, 2021

Not sure if noop is a good behavior. Placing a node above/below itself doesn't make sense in the first place, so I'd rather add a node != sibling assertion instead.

@ifreund
Copy link
Member Author

ifreund commented Oct 12, 2021

Not sure if noop is a good behavior. Placing a node above/below itself doesn't make sense in the first place, so I'd rather add a node != sibling assertion instead.

The motivation is to make this tinywl code from #3250 simpler and avoid this special case:

wlroots/tinywl/tinywl.c

Lines 123 to 127 in 3723ddd

struct tinywl_view *top_view = wl_container_of(
server->views.next, top_view, link);
wlr_scene_node_place_above(view->scene_node, top_view->scene_node);
wl_list_remove(&view->link);
wl_list_insert(&server->views, &view->link);

@vyivel
Copy link
Member

vyivel commented Oct 12, 2021

As the order of nodes is modified with "place above/below" operations, placing a node on the top is a special case anyway. IMO, it wouldn't hurt to be a bit explicit and have a check like "does this node need to be moved in the first place?", maybe with a scene_node_raise() function.

That's just my personal preference though. At the very least, your proposed behavior probably needs to be documented in wlr_scene.h.

@vyivel
Copy link
Member

vyivel commented Oct 12, 2021

Barely related, but wl_subsurface.place_{above,below} with the obejct itself as sibling is a protocol error.

@emersion
Copy link
Member

Yeah, I think I'd agree with @vyivel here. We should introduce a way to place on top or at the bottom, because that's a pretty common thing to do for compositors. But in general compositors either want to place above/below or on top/at the bottom -- ie, having functions which do both doesn't make it easier to write compositors.

Currently these functions remove the node from the scene if the sibling
argument is the same node as the node. To prevent confusion when
misusing this API, assert that the nodes are distinct and document this.
@ifreund ifreund changed the title scene: fix place above/below if sibling == node scene: add functions to place node on top/bottom Oct 13, 2021
@ifreund
Copy link
Member Author

ifreund commented Oct 13, 2021

Ok, updated place above/below to assert that the nodes are distinct and added API to place a node on the top/bottom. I think you two are right and making the operation of placing a node above itself an assertion failure is a good idea.

These are very common operations for compositors (including tinywl)
to perform.
@ifreund
Copy link
Member Author

ifreund commented Oct 14, 2021

Renamed the new functions to wlr_scene_node_place_on_top and wlr_scene_node_place_on_bottom. This should be ready to go now barring further feedback.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@emersion emersion merged commit 4fae8f7 into swaywm:master Oct 14, 2021
@ifreund ifreund deleted the scene-place-above-below-fix branch October 14, 2021 20:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants