wlr_scene: Add primary_output property to wlr_scene_buffer

Alexander Orzechowski 3 years ago
parent dfeb1309a8
commit a53eccf2af

@ -117,6 +117,14 @@ struct wlr_scene_buffer {
struct wl_signal output_present; // struct wlr_scene_output struct wl_signal output_present; // struct wlr_scene_output
} events; } 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 // private state
uint64_t active_outputs; uint64_t active_outputs;

@ -218,6 +218,9 @@ static void scene_buffer_update_outputs(
struct wlr_box buffer_box = { .x = lx, .y = ly }; struct wlr_box buffer_box = { .x = lx, .y = ly };
scene_node_get_size(&scene_buffer->node, &buffer_box.width, &buffer_box.height); 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; struct wlr_scene_output *scene_output;
wl_list_for_each(scene_output, &scene->outputs, link) { wl_list_for_each(scene_output, &scene->outputs, link) {
struct wlr_box output_box = { 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 = wlr_box_intersection(&intersection, &buffer_box, &output_box);
bool intersects_before = scene_buffer->active_outputs & (1ull << scene_output->index); 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) { if (intersects && !intersects_before) {
scene_buffer->active_outputs |= 1ull << scene_output->index; scene_buffer->active_outputs |= 1ull << scene_output->index;
wlr_signal_emit_safe(&scene_buffer->events.output_enter, scene_output); wlr_signal_emit_safe(&scene_buffer->events.output_enter, scene_output);

Loading…
Cancel
Save