mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 18:09:49 +01:00
wlr_scene: Add primary_output property to wlr_scene_buffer
This commit is contained in:
parent
dfeb1309a8
commit
a53eccf2af
2 changed files with 19 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue