aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Orzechowski <orzechowski.alexander@gmail.com>2022-04-24 22:32:58 -0400
committerAlexander Orzechowski <orzechowski.alexander@gmail.com>2022-05-19 14:21:22 -0400
commita53eccf2af16cef55bb5ad85204545601584e15e (patch)
tree1b7cec4c01690c99505cc81d789721ed794eb2d8
parentdfeb1309a83ef3ab5ceb189d0b721c2b7cf5680c (diff)
wlr_scene: Add primary_output property to wlr_scene_buffer
-rw-r--r--include/wlr/types/wlr_scene.h8
-rw-r--r--types/scene/wlr_scene.c11
2 files changed, 19 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h
index 99d6ca61..a4d05274 100644
--- a/include/wlr/types/wlr_scene.h
+++ b/include/wlr/types/wlr_scene.h
@@ -117,6 +117,14 @@ struct wlr_scene_buffer {
struct wl_signal output_present; // struct wlr_scene_output
} events;
+ /**
+ * The output that the largest area of this buffer is displayed on.
+ * This may be NULL if the buffer is not currently displayed on any
+ * outputs. This is the output that should be used for frame callbacks,
+ * presentation feedback, etc.
+ */
+ struct wlr_scene_output *primary_output;
+
// private state
uint64_t active_outputs;
diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c
index 86d75ab3..cdb04c9e 100644
--- a/types/scene/wlr_scene.c
+++ b/types/scene/wlr_scene.c
@@ -218,6 +218,9 @@ static void scene_buffer_update_outputs(
struct wlr_box buffer_box = { .x = lx, .y = ly };
scene_node_get_size(&scene_buffer->node, &buffer_box.width, &buffer_box.height);
+ int largest_overlap = 0;
+ scene_buffer->primary_output = NULL;
+
struct wlr_scene_output *scene_output;
wl_list_for_each(scene_output, &scene->outputs, link) {
struct wlr_box output_box = {
@@ -231,6 +234,14 @@ static void scene_buffer_update_outputs(
bool intersects = wlr_box_intersection(&intersection, &buffer_box, &output_box);
bool intersects_before = scene_buffer->active_outputs & (1ull << scene_output->index);
+ if (intersects) {
+ int overlap = intersection.width * intersection.height;
+ if (overlap > largest_overlap) {
+ largest_overlap = overlap;
+ scene_buffer->primary_output = scene_output;
+ }
+ }
+
if (intersects && !intersects_before) {
scene_buffer->active_outputs |= 1ull << scene_output->index;
wlr_signal_emit_safe(&scene_buffer->events.output_enter, scene_output);