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);