Skip to content

fix: handle display rotation in wallpaper rendering#126

Open
olafkfreund wants to merge 1 commit intopop-os:masterfrom
olafkfreund:fix/display-rotation-transform
Open

fix: handle display rotation in wallpaper rendering#126
olafkfreund wants to merge 1 commit intopop-os:masterfrom
olafkfreund:fix/display-rotation-transform

Conversation

@olafkfreund
Copy link

Summary

  • Implement the transform_changed handler (previously a // TODO stub) to properly track output transform changes
  • When a display is rotated 90° or 270°, swap wallpaper width/height so images are scaled to the correct orientation
  • Add effective_size() method to CosmicBgLayer that accounts for rotation transforms

Problem

On displays with 90°/270° rotation (including flipped variants), wallpapers are rendered with the wrong aspect ratio because the raw layer size is used without accounting for the output transform. The transform_changed handler was left as a TODO stub.

Changes

src/main.rs:

  • Add transform field to CosmicBgLayer struct, initialized from output_info.transform
  • Add is_rotated_90_or_270() helper for detecting rotated transforms
  • Add CosmicBgLayer::effective_size() that swaps width/height when rotated
  • Implement transform_changed() to update the stored transform and trigger a redraw

src/wallpaper.rs:

  • Use layer.effective_size() instead of layer.size in the draw path

Test plan

  • Set a display to normal orientation — wallpaper renders correctly
  • Rotate a display to 90° — wallpaper dimensions swap and render correctly
  • Rotate a display to 270° — wallpaper dimensions swap and render correctly
  • Test with flipped rotations (Flipped90, Flipped270)
  • Runtime rotation change triggers redraw with correct dimensions
  • Non-rotated displays (0°, 180°, Flipped, Flipped180) are unaffected

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings February 12, 2026 19:17

This comment was marked as spam.

}

/// Returns `true` if the given transform represents a 90° or 270° rotation.
fn is_rotated_90_or_270(transform: wl_output::Transform) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform_is_vertical would be more readable.


impl CosmicBgLayer {
/// Returns the effective size, swapping width and height for 90°/270° rotations.
pub fn effective_size(&self) -> Option<(u32, u32)> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rotated_size is also more descriptive

@mmstick mmstick requested a review from a team February 12, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants