Skip to content

Commit d0779aa

Browse files
olafkfreundclaude
andcommitted
fix: handle display rotation in wallpaper rendering
Implement the `transform_changed` handler (previously a TODO stub) to properly track output transform changes. When a display is rotated 90° or 270°, the wallpaper dimensions need to be swapped so the image is scaled to the correct orientation. Changes: - Add `transform` field to `CosmicBgLayer` to track output orientation - Add `effective_size()` method that swaps width/height for rotated displays - Implement `transform_changed()` to update transform and trigger redraw - Use `effective_size()` instead of raw `size` when calculating wallpaper dimensions in the draw path Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 808a50e commit d0779aa

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/main.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ pub struct CosmicBgLayer {
8383
needs_redraw: bool,
8484
size: Option<(u32, u32)>,
8585
fractional_scale: Option<u32>,
86+
transform: wl_output::Transform,
87+
}
88+
89+
/// Returns `true` if the given transform represents a 90° or 270° rotation.
90+
fn is_rotated_90_or_270(transform: wl_output::Transform) -> bool {
91+
matches!(
92+
transform,
93+
wl_output::Transform::_90
94+
| wl_output::Transform::_270
95+
| wl_output::Transform::Flipped90
96+
| wl_output::Transform::Flipped270
97+
)
98+
}
99+
100+
impl CosmicBgLayer {
101+
/// Returns the effective size, swapping width and height for 90°/270° rotations.
102+
pub fn effective_size(&self) -> Option<(u32, u32)> {
103+
self.size.map(|(w, h)| {
104+
if is_rotated_90_or_270(self.transform) {
105+
(h, w)
106+
} else {
107+
(w, h)
108+
}
109+
})
110+
}
86111
}
87112

88113
#[allow(clippy::too_many_lines)]
@@ -356,6 +381,7 @@ impl CosmicBg {
356381
layer,
357382
viewport,
358383
wl_output: output,
384+
transform: output_info.transform,
359385
output_info,
360386
size: None,
361387
fractional_scale,
@@ -401,10 +427,28 @@ impl CompositorHandler for CosmicBg {
401427
&mut self,
402428
_conn: &Connection,
403429
_qh: &QueueHandle<Self>,
404-
_surface: &wl_surface::WlSurface,
405-
_new_transform: wl_output::Transform,
430+
surface: &wl_surface::WlSurface,
431+
new_transform: wl_output::Transform,
406432
) {
407-
// TODO
433+
for wallpaper in &mut self.wallpapers {
434+
if let Some(layer) = wallpaper
435+
.layers
436+
.iter_mut()
437+
.find(|layer| layer.layer.wl_surface() == surface)
438+
{
439+
if layer.transform != new_transform {
440+
tracing::debug!(
441+
old_transform = ?layer.transform,
442+
new_transform = ?new_transform,
443+
"output transform changed"
444+
);
445+
layer.transform = new_transform;
446+
layer.needs_redraw = true;
447+
wallpaper.draw();
448+
}
449+
break;
450+
}
451+
}
408452
}
409453

410454
fn surface_enter(

src/wallpaper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Wallpaper {
109109
continue;
110110
};
111111

112-
let Some((width, height)) = layer.size else {
112+
let Some((width, height)) = layer.effective_size() else {
113113
continue;
114114
};
115115

0 commit comments

Comments
 (0)