Consider integer scale factor for LayerSurface and WlSurface

Hopefully this will help displaying the wallpapers correctly
on outputs with higher than 1 integer scale factor:
https://github.com/gergo-salyi/multibg-sway/issues/4
This commit is contained in:
Gergő Sályi 2024-01-02 20:51:14 +01:00
parent 67abbb9a37
commit 8e20b360ae

View file

@ -181,12 +181,18 @@ impl OutputHandler for State {
} }
debug!( debug!(
"New output, name: {}, resolution: {}x{}", "New output, name: {}, resolution: {}x{}, scale factor: {}",
output_name, width, height output_name, width, height, info.scale_factor
); );
let surface = self.compositor_state.create_surface(qh); let surface = self.compositor_state.create_surface(qh);
// We are a wallpaper and we never want to be scaled
// by the compositor. So we declare that we are already
// correctly scaled no matter the scale factor.
// This will handle integer scale factors.
surface.set_buffer_scale(info.scale_factor);
let layer = self.layer_shell.create_layer_surface( let layer = self.layer_shell.create_layer_surface(
qh, qh,
surface, surface,
@ -197,7 +203,10 @@ impl OutputHandler for State {
layer.set_exclusive_zone(-1); // Don't let the status bar push it around layer.set_exclusive_zone(-1); // Don't let the status bar push it around
layer.set_keyboard_interactivity(KeyboardInteractivity::None); layer.set_keyboard_interactivity(KeyboardInteractivity::None);
layer.set_size(width as u32, height as u32); layer.set_size(
(width / info.scale_factor) as u32,
(height / info.scale_factor) as u32
);
layer.commit(); layer.commit();
@ -267,7 +276,7 @@ impl OutputHandler for State {
_qh: &QueueHandle<Self>, _qh: &QueueHandle<Self>,
output: wl_output::WlOutput, output: wl_output::WlOutput,
) { ) {
// This will only be needed if we implement scaling the wallpapers // This will only be fully needed if we implement scaling the wallpapers
// to the output resolution // to the output resolution
let Some(info) = self.output_state.info(&output) let Some(info) = self.output_state.info(&output)
@ -282,12 +291,39 @@ impl OutputHandler for State {
return; return;
}; };
debug!( let Some((width, height)) = info.modes.iter()
"Update output: {}", .find(|mode| mode.current)
.map(|mode| mode.dimensions)
else {
error!(
"New output '{}' has no current mode set, skipping",
name name
); );
return;
};
warn!("Handling of output updates are not yet implemented"); debug!(
"Update output, name: {}, resolution: {}x{}, scale factor: {}",
name, width, height, info.scale_factor
);
if let Some(bg_layer) = self.background_layers.iter()
.find(|bg_layers| bg_layers.output_name == name)
{
let surface = bg_layer.layer.wl_surface();
// We are a wallpaper and we never want to be scaled
// by the compositor. So we declare that we are already
// correctly scaled no matter the scale factor.
// This will handle integer scale factors.
surface.set_buffer_scale(info.scale_factor);
bg_layer.layer.set_size(
(width / info.scale_factor) as u32,
(height / info.scale_factor) as u32
);
surface.commit();
}
warn!("Handling of output updates are not yet fully implemented");
// let Some((width, height)) = info.modes.iter() // let Some((width, height)) = info.modes.iter()
// .find(|mode| mode.current) // .find(|mode| mode.current)