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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/wlr/types/wlr_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,24 @@ void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled);
void wlr_scene_node_set_position(struct wlr_scene_node *node, int x, int y);
/**
* Move the node right above the specified sibling.
* Asserts that node and sibling are distinct and share the same parent.
*/
void wlr_scene_node_place_above(struct wlr_scene_node *node,
struct wlr_scene_node *sibling);
/**
* Move the node right below the specified sibling.
* Asserts that node and sibling are distinct and share the same parent.
*/
void wlr_scene_node_place_below(struct wlr_scene_node *node,
struct wlr_scene_node *sibling);
/**
* Move the node above all of its sibling nodes.
*/
void wlr_scene_node_raise_to_top(struct wlr_scene_node *node);
/**
* Move the node below all of its sibling nodes.
*/
void wlr_scene_node_lower_to_bottom(struct wlr_scene_node *node);
/**
* Move the node to another location in the tree.
*/
Expand Down
20 changes: 20 additions & 0 deletions types/scene/wlr_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ void wlr_scene_node_set_position(struct wlr_scene_node *node, int x, int y) {

void wlr_scene_node_place_above(struct wlr_scene_node *node,
struct wlr_scene_node *sibling) {
assert(node != sibling);
assert(node->parent == sibling->parent);

if (node->state.link.prev == &sibling->state.link) {
Expand All @@ -455,6 +456,7 @@ void wlr_scene_node_place_above(struct wlr_scene_node *node,

void wlr_scene_node_place_below(struct wlr_scene_node *node,
struct wlr_scene_node *sibling) {
assert(node != sibling);
assert(node->parent == sibling->parent);

if (node->state.link.next == &sibling->state.link) {
Expand All @@ -468,6 +470,24 @@ void wlr_scene_node_place_below(struct wlr_scene_node *node,
scene_node_damage_whole(sibling);
}

void wlr_scene_node_raise_to_top(struct wlr_scene_node *node) {
struct wlr_scene_node *current_top = wl_container_of(
node->parent->state.children.prev, current_top, state.link);
if (node == current_top) {
return;
}
wlr_scene_node_place_above(node, current_top);
}

void wlr_scene_node_lower_to_bottom(struct wlr_scene_node *node) {
struct wlr_scene_node *current_bottom = wl_container_of(
node->parent->state.children.prev, current_bottom, state.link);
if (node == current_bottom) {
return;
}
wlr_scene_node_place_below(node, current_bottom);
}

void wlr_scene_node_reparent(struct wlr_scene_node *node,
struct wlr_scene_node *new_parent) {
assert(node->type != WLR_SCENE_NODE_ROOT && new_parent != NULL);
Expand Down