[gnome-flashback] monitor-transform: fix transform()



commit 11cb40985d9c995f400ba9022f1f91fbbea83966
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Aug 13 14:30:42 2022 +0300

    monitor-transform: fix transform()
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/29cafe6f6c57f8aa6709deed03f1afc061cd82f8

 backends/gf-monitor-transform.c | 46 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)
---
diff --git a/backends/gf-monitor-transform.c b/backends/gf-monitor-transform.c
index 57412e1..c1b0f7c 100644
--- a/backends/gf-monitor-transform.c
+++ b/backends/gf-monitor-transform.c
@@ -18,6 +18,36 @@
 #include "config.h"
 #include "gf-monitor-transform.h"
 
+static GfMonitorTransform
+gf_monitor_transform_flip (GfMonitorTransform transform)
+{
+  switch (transform)
+    {
+      case GF_MONITOR_TRANSFORM_NORMAL:
+        return GF_MONITOR_TRANSFORM_FLIPPED;
+      case GF_MONITOR_TRANSFORM_90:
+        return GF_MONITOR_TRANSFORM_FLIPPED_270;
+      case GF_MONITOR_TRANSFORM_180:
+        return GF_MONITOR_TRANSFORM_FLIPPED_180;
+      case GF_MONITOR_TRANSFORM_270:
+        return GF_MONITOR_TRANSFORM_FLIPPED_90;
+      case GF_MONITOR_TRANSFORM_FLIPPED:
+        return GF_MONITOR_TRANSFORM_NORMAL;
+      case GF_MONITOR_TRANSFORM_FLIPPED_90:
+        return GF_MONITOR_TRANSFORM_270;
+      case GF_MONITOR_TRANSFORM_FLIPPED_180:
+        return GF_MONITOR_TRANSFORM_180;
+      case GF_MONITOR_TRANSFORM_FLIPPED_270:
+        return GF_MONITOR_TRANSFORM_90;
+
+      default:
+        break;
+    }
+
+  g_assert_not_reached ();
+  return 0;
+}
+
 GfMonitorTransform
 gf_monitor_transform_from_orientation (GfOrientation orientation)
 {
@@ -78,11 +108,21 @@ gf_monitor_transform_transform (GfMonitorTransform transform,
                                 GfMonitorTransform other)
 {
   GfMonitorTransform new_transform;
+  gboolean needs_flip;
+
+  if (gf_monitor_transform_is_flipped (other))
+    new_transform = gf_monitor_transform_flip (transform);
+  else
+    new_transform = transform;
+
+  needs_flip = FALSE;
+  if (gf_monitor_transform_is_flipped (new_transform))
+    needs_flip = TRUE;
 
-  new_transform = (transform + other) % GF_MONITOR_TRANSFORM_FLIPPED;
+  new_transform += other;
+  new_transform %= GF_MONITOR_TRANSFORM_FLIPPED;
 
-  if (gf_monitor_transform_is_flipped (transform) !=
-      gf_monitor_transform_is_flipped (other))
+  if (needs_flip)
     new_transform += GF_MONITOR_TRANSFORM_FLIPPED;
 
   return new_transform;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]