From 84bd5f2ea9d84094b5a2b0cba2eab9b8c3116c53 Mon Sep 17 00:00:00 2001
From: wangxiaoqing <wangxiaoqing@kylinsec.com.cn>
Date: Thu, 28 Jul 2022 14:00:58 +0800
Subject: [PATCH 3/4] Fix the background image can not draw all when rotating
 screen
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 修复旋转屏幕90°时，一半屏幕无法正常显示
  Related #I5I2U6

Signed-off-by: wangxiaoqing <wangxiaoqing@kylinsec.com.cn>
---
 src/caja-desktop-window.c | 37 +++++++++++++++++++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/caja-desktop-window.c b/src/caja-desktop-window.c
index 36ae52c..97b5a0b 100644
--- a/src/caja-desktop-window.c
+++ b/src/caja-desktop-window.c
@@ -148,17 +148,50 @@ caja_desktop_window_update_directory (CajaDesktopWindow *window)
     g_object_unref (location);
 }
 
+static void
+calculate_screen_size (GdkScreen *screen,
+                     int        *width,
+                     int        *height)
+{
+    GdkDisplay *display;
+    gint monitors;
+    gint i, x1, y1, x2, y2;
+
+    display = gdk_screen_get_display (screen);
+    monitors = gdk_display_get_n_monitors (display);
+
+    x1 = y1 = G_MAXINT;
+    x2 = y2 = G_MININT;
+
+    for (i = 0; i < monitors; i++)
+    {
+        GdkMonitor *monitor = gdk_display_get_monitor (display, i);
+        GdkRectangle geometry;
+
+        gdk_monitor_get_geometry (monitor, &geometry);
+        x1 = MIN (x1, geometry.x);
+        y1 = MIN (y1, geometry.y);
+        x2 = MAX (x2, geometry.x + geometry.width);
+        y2 = MAX (y2, geometry.y + geometry.height);
+    }
+
+    *width = x2 - x1;
+    *height = y2 - y1;
+}
+
 static void
 caja_desktop_window_screen_size_changed (GdkScreen             *screen,
         CajaDesktopWindow *window)
 {
     int width_request, height_request;
     int scale;
+    int screen_width, screen_height;
 
     scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
 
-    width_request = WidthOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
-    height_request = HeightOfScreen (gdk_x11_screen_get_xscreen (screen)) / scale;
+    calculate_screen_size (screen, &screen_width, &screen_height);
+    width_request = screen_width / scale;
+    height_request = screen_height / scale;
 
     g_object_set (window,
                   "width_request", width_request,
-- 
2.36.1

