cosmic-comp/src/wayland/handlers/fractional_scale.rs

62 lines
2.3 KiB
Rust
Raw Normal View History

2023-06-14 14:44:36 +02:00
use crate::{state::State, utils::prelude::SeatExt};
use smithay::{
delegate_fractional_scale,
desktop::utils::surface_primary_scanout_output,
reexports::wayland_server::protocol::wl_surface::WlSurface,
wayland::{
compositor::{get_parent, with_states},
fractional_scale::{with_fractional_scale, FractionalScaleHandler},
},
};
impl FractionalScaleHandler for State {
fn new_fractional_scale(&mut self, surface: WlSurface) {
// Here we can set the initial fractional scale
//
// First we look if the surface already has a primary scan-out output, if not
// we test if the surface is a subsurface and try to use the primary scan-out output
// of the root surface. If the root also has no primary scan-out output we just try
// to use the first output of the toplevel.
// If the surface is the root we also try to use the first output of the toplevel.
//
// If all the above tests do not lead to a output we just use the active output
// of the last active seat (which will also be the output a toplevel will
// initially be placed on)
2023-06-15 12:43:52 +02:00
let output = with_states(&surface, |states| {
surface_primary_scanout_output(&surface, states)
})
.or_else(|| {
let mut root = surface.clone();
while let Some(parent) = get_parent(&root) {
root = parent;
}
2023-06-14 14:44:36 +02:00
2023-06-15 12:43:52 +02:00
(root != surface)
.then(|| {
with_states(&root, |states| {
surface_primary_scanout_output(&root, states)
})
})
.flatten()
2023-06-14 14:44:36 +02:00
.or_else(|| {
2023-06-15 12:43:52 +02:00
self.common
.shell
.visible_outputs_for_surface(&surface)
.next()
2023-06-14 14:44:36 +02:00
})
2023-06-15 12:43:52 +02:00
})
.unwrap_or_else(|| {
let seat = self.common.last_active_seat();
seat.active_output()
});
with_states(&surface, |states| {
2023-06-14 14:44:36 +02:00
with_fractional_scale(states, |fractional_scale| {
fractional_scale.set_preferred_scale(output.current_scale().fractional_scale());
});
});
}
}
delegate_fractional_scale!(State);