From 3c40ccfaee222a8a2b264ab10118149755ce81b9 Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Thu, 5 Nov 2026 18:24:11 -0300
Subject: kuickshow: compose initial modifications with EXIF orientation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 kuickshow/src/imagewindow.cpp | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/kuickshow/src/imagewindow.cpp b/kuickshow/src/imagewindow.cpp
index 3f197ea0..7f68e2a2 100644
--- a/kuickshow/src/imagewindow.cpp
+++ b/kuickshow/src/imagewindow.cpp
@@ -1095,10 +1095,13 @@ void ImageWindow::autoScale( KuickImage *kuim )
 // only called when kdata->isModsEnabled is true
 bool ImageWindow::autoRotate( KuickImage *kuim )
 {
-    if ( kdata->autoRotation && ImlibWidget::autoRotate( kuim ) )
-        return true;
+    // Apply EXIF first. ImlibWidget::autoRotate() also resets any cached
+    // transform state to the metadata orientation, so the user's defaults
+    // below can be composed on top without preserving later manual edits.
+    bool exifApplied = kdata->autoRotation && ImlibWidget::autoRotate( kuim );
 
-    // rotation by metadata not available or not configured
+    // The initial user preferences are applied after metadata handling;
+    // they do not replace the EXIF transform.
     FlipRotation op;
     if ( kdata->flipVertically )
         op = FlipRotation::vflip();
@@ -1107,7 +1110,14 @@ bool ImageWindow::autoRotate( KuickImage *kuim )
     if ( kdata->rotation != ROT_0 )
         op *= kdata->rotation;
 
-    kuim->flipRotateAbs( op );
+    if ( exifApplied )
+    {
+        FlipRotation target( kuim->absRotation(), kuim->flipMode() );
+        target *= op;
+        kuim->flipRotateAbs( target );
+    }
+    else
+        kuim->flipRotateAbs( op );
 
     return true;
 }
-- 
cgit v1.2.3

