Jelajahi Sumber

Change Padding to Margin. Drop dock sizing. Remove from interface.

Ruben 5 bulan lalu
induk
melakukan
381b585863

+ 0 - 35
src/PicView.Avalonia.MacOS/App.axaml.cs

@@ -67,17 +67,6 @@ public class App : Application, IPlatformSpecificService, IPlatformWindowService
                 _mainWindow = new MacMainWindow();
                 desktop.MainWindow = _mainWindow;
             },DispatcherPriority.Send);
-
-            bool dockSizeSet;
-            if (!settingsExists || Settings.WindowProperties.Padding < 0)
-            {
-                await DockSizeHelper.SetDockSizeAsync().ConfigureAwait(false);
-                dockSizeSet = true;
-            }
-            else
-            {
-                dockSizeSet = false;
-            }
         
             _vm = new MainViewModel(this, this);
         
@@ -106,25 +95,6 @@ public class App : Application, IPlatformSpecificService, IPlatformWindowService
             };
             Current.UrlsOpened -= handler;
 
-            if (dockSizeSet)
-            {
-                return;
-            }
-
-            // Check if dock size has changed
-            var dockSize = await DockSizeHelper.GetDockSizeAsync().ConfigureAwait(false);
-            // ReSharper disable once CompareOfFloatsByEqualityOperator
-            if (Settings.WindowProperties.Padding == dockSize)
-            {
-                return;
-            }
-
-            Settings.WindowProperties.Padding = dockSize;
-            if (Settings.WindowProperties.AutoFit)
-            {
-                await WindowResizing.SetSizeAsync(_vm);
-            }
-
         }
         catch (Exception)
         {
@@ -263,11 +233,6 @@ public class App : Application, IPlatformSpecificService, IPlatformWindowService
     
     #endregion
 
-    public double Padding
-    {
-        get => Settings.WindowProperties.Padding / ScreenHelper.ScreenSize.Scaling;
-    }
-
     public int CombinedTitleButtonsWidth { get; set; } = 165;
     
     #region Window interface implementations

+ 0 - 40
src/PicView.Avalonia.MacOS/WindowImpl/DockSizeHelper.cs

@@ -1,40 +0,0 @@
-using PicView.Core.MacOS.AppleScripts;
-
-namespace PicView.Avalonia.MacOS.WindowImpl;
-
-public  static class DockSizeHelper
-{
-    private const string Script = """
-
-                                  set dockSize to do shell script "defaults read com.apple.dock tilesize"
-                                  set dockHidden to do shell script "defaults read com.apple.dock autohide"
-                                  return dockSize & "," & dockHidden
-
-                                  """;
-    
-    public static async Task SetDockSizeAsync()
-    {
-        var result = await GetDockSizeAsync();
-        Settings.WindowProperties.Padding = result;
-    }
-    
-    public static async Task<double> GetDockSizeAsync()
-    {
-        var result = await AppleScriptManager.ExecuteAppleScriptWithResultAsync(Script);
-        if (!string.IsNullOrWhiteSpace(result))
-        {
-            var parts = result.Split(',');
-            if (parts.Length == 2 && int.TryParse(parts[0], out var dockSize) && int.TryParse(parts[1], out var hidden))
-            {
-                if (hidden == 1)
-                {
-                    // ReSharper disable once PossibleLossOfFraction
-                    return dockSize / 2;
-                }
-
-                return dockSize;
-            }
-        }
-        return -1;
-    }
-}

+ 0 - 6
src/PicView.Avalonia.Win32/App.axaml.cs

@@ -9,7 +9,6 @@ using PicView.Avalonia.ColorManagement;
 using PicView.Avalonia.Interfaces;
 using PicView.Avalonia.Navigation;
 using PicView.Avalonia.StartUp;
-using PicView.Avalonia.UI;
 using PicView.Avalonia.ViewModels;
 using PicView.Avalonia.Win32.Views;
 using PicView.Avalonia.Win32.WindowImpl;
@@ -90,11 +89,6 @@ public class App : Application, IPlatformSpecificService, IPlatformWindowService
         }
     }
 
-    public double Padding
-    {
-        get => Settings.WindowProperties.Padding / ScreenHelper.ScreenSize.Scaling;
-    }
-
     public int CombinedTitleButtonsWidth
     {
         get => (int)(Settings.WindowProperties.Maximized && !Settings.WindowProperties.Fullscreen

+ 0 - 5
src/PicView.Avalonia/Interfaces/IPlatformWindowService.cs

@@ -2,11 +2,6 @@
 
 public interface IPlatformWindowService
 {
-    /// <summary>
-    /// Gets or sets the padding used to calculate space between the screen and the window.
-    /// </summary>
-    double Padding { get; }
-
     /// <summary>
     /// Gets or sets the width of the buttons on the respective title bar implementation.
     /// </summary>

+ 3 - 5
src/PicView.Avalonia/StartUp/StartUpHelper.cs

@@ -90,12 +90,10 @@ public static class StartUpHelper
     public static void HandleWindowScalingMode(MainViewModel vm, Window window)
     {
         ScreenHelper.UpdateScreenSize(window);
-        if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+
+        if (Settings.WindowProperties.Margin < 0)
         {
-            if (Settings.WindowProperties.Padding < 0)
-            {
-                Settings.WindowProperties.Padding = 45;
-            }
+            Settings.WindowProperties.Margin = 45;
         }
         if (Settings.WindowProperties.AutoFit)
         {

+ 0 - 2
src/PicView.Avalonia/WindowBehavior/WindowResizing.cs

@@ -226,7 +226,6 @@ public static class WindowResizing
         if (Settings.ImageScaling.ShowImageSideBySide && secondWidth > 0 && secondHeight > 0)
         {
             size = ImageSizeCalculationHelper.GetSideBySideImageSize(
-                vm.PlatformWindowService.Padding,
                 width,
                 height,
                 secondWidth,
@@ -246,7 +245,6 @@ public static class WindowResizing
         else
         {
             size = ImageSizeCalculationHelper.GetImageSize(
-                vm.PlatformWindowService.Padding,
                 width,
                 height,
                 screenSize,

+ 1 - 1
src/PicView.Core/Config/AppSettings.cs

@@ -24,7 +24,7 @@ public class WindowProperties
     public bool Maximized { get; set; } = false;
     public bool Fullscreen { get; set; } = false;
     public bool KeepCentered { get; set; } = false;
-    public double Padding { get; set; } = -1;
+    public double Margin { get; set; } = -1;
 }
 
 public class UIProperties

+ 11 - 13
src/PicView.Core/Sizing/ImageSizeCalculationHelper.cs

@@ -5,7 +5,6 @@ public static class ImageSizeCalculationHelper
     private const int MinTitleWidth = 250;
     
     public static ImageSize GetImageSize(
-        double padding,
         double width,
         double height,
         ScreenSize screenSize,
@@ -33,7 +32,7 @@ public static class ImageSizeCalculationHelper
                          Settings.WindowProperties.Maximized;
             
         var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
-        var borderSpaceWidth = fullscreen ? 0 : padding;
+        var borderSpaceWidth = fullscreen ? 0 : screenSize.Margin;
 
         var workAreaWidth = screenSize.WorkingAreaWidth - borderSpaceWidth;
         var workAreaHeight = screenSize.WorkingAreaHeight - borderSpaceHeight;
@@ -45,19 +44,19 @@ public static class ImageSizeCalculationHelper
 
             maxWidth = Settings.ImageScaling.StretchImage 
                 ? workAreaWidth 
-                : Math.Min(workAreaWidth - padding, width);
+                : Math.Min(workAreaWidth - screenSize.Margin, width);
             
             maxHeight = workAreaHeight;
         }
         else if (Settings.WindowProperties.AutoFit)
         {
             maxWidth = Settings.ImageScaling.StretchImage
-                ? workAreaWidth - padding
-                : Math.Min(workAreaWidth - padding, width);
+                ? workAreaWidth - screenSize.Margin
+                : Math.Min(workAreaWidth - screenSize.Margin, width);
                     
             maxHeight = Settings.ImageScaling.StretchImage
-                ? workAreaHeight - padding
-                : Math.Min(workAreaHeight - padding, height);
+                ? workAreaHeight - screenSize.Margin
+                : Math.Min(workAreaHeight - screenSize.Margin, height);
         }
         else
         {
@@ -130,7 +129,7 @@ public static class ImageSizeCalculationHelper
                 xWidth = width * aspectRatio;
                 xHeight = height * aspectRatio;
 
-                scrollWidth = Math.Max(xWidth + SizeDefaults.ScrollbarSize, SizeDefaults.WindowMinSize + SizeDefaults.ScrollbarSize + padding + 16);
+                scrollWidth = Math.Max(xWidth + SizeDefaults.ScrollbarSize, SizeDefaults.WindowMinSize + SizeDefaults.ScrollbarSize + screenSize.Margin + 16);
                 scrollHeight = containerHeight - margin;
             }
             else
@@ -158,7 +157,6 @@ public static class ImageSizeCalculationHelper
     }
 
     public static ImageSize GetSideBySideImageSize(
-        double padding,
         double width,
         double height,
         double secondaryWidth,
@@ -182,11 +180,11 @@ public static class ImageSizeCalculationHelper
         }
 
         // Get sizes for both images
-        var firstSize = GetImageSize(padding, width, height, screenSize, minWidth, minHeight,
+        var firstSize = GetImageSize(width, height, screenSize, minWidth, minHeight,
             interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize, galleryHeight,
             containerWidth,
             containerHeight);
-        var secondSize = GetImageSize(padding, secondaryWidth, secondaryHeight, screenSize, minWidth,
+        var secondSize = GetImageSize(secondaryWidth, secondaryHeight, screenSize, minWidth,
             minHeight, interfaceSize, rotationAngle, dpiScaling, uiTopSize, uiBottomSize,
             galleryHeight,
             containerWidth, containerHeight);
@@ -203,7 +201,7 @@ public static class ImageSizeCalculationHelper
 
         if (Settings.WindowProperties.AutoFit)
         {
-            var widthPadding = Settings.ImageScaling.StretchImage ? 4 : padding;
+            var widthPadding = Settings.ImageScaling.StretchImage ? 4 : screenSize.Margin;
             var availableWidth = screenSize.WorkingAreaWidth - widthPadding;
             var availableHeight = screenSize.WorkingAreaHeight - (widthPadding + uiBottomSize + uiTopSize);
             if (rotationAngle is 0 or 180)
@@ -274,7 +272,7 @@ public static class ImageSizeCalculationHelper
                 var borderSpaceHeight = fullscreen ? 0 : uiTopSize + uiBottomSize + galleryHeight;
                 var workAreaHeight = screenSize.WorkingAreaHeight * dpiScaling - borderSpaceHeight;
                 scrollHeight = Math.Min(xHeight,
-                    Settings.ImageScaling.StretchImage ? workAreaHeight : workAreaHeight - padding);
+                    Settings.ImageScaling.StretchImage ? workAreaHeight : workAreaHeight - screenSize.Margin);
             }
             else
             {

+ 2 - 0
src/PicView.Core/Sizing/ScreenSize.cs

@@ -25,4 +25,6 @@ public readonly record struct ScreenSize
     /// Gets the DPI scaling factor of the screen.
     /// </summary>
     public double Scaling { get; init; }
+    
+    public double Margin => Settings.WindowProperties.Margin is 0 ? 0 : Settings.WindowProperties.Margin / Scaling;
 }