Skip to content

Commit

Permalink
Merge pull request #13993 from unoplatform/dev/mazi/dpi-scaling
Browse files Browse the repository at this point in the history
fix: Avoid DPI scaling issues on GTK
  • Loading branch information
MartinZikmund authored Oct 17, 2023
2 parents 34ec321 + eb339e5 commit 72dc180
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public GtkDisplayInformationExtension(object owner)
private void GtkDisplayInformationExtension_MainWindowShown(object? sender, EventArgs e)
{
_dpiHelper.DpiChanged += OnDpiChanged;
OnDpiChanged(null, EventArgs.Empty);
}

private Window GetWindow()
Expand Down Expand Up @@ -54,7 +55,7 @@ public float LogicalDpi
var nativeWindow = window.Window;
if (nativeWindow is not null)
{
_dpi = window.Display.GetMonitorAtWindow(nativeWindow).ScaleFactor * DisplayInformation.BaseDpi;
_dpi = _dpiHelper.GetNativeDpi();
}
}

Expand All @@ -71,7 +72,7 @@ public float LogicalDpi

private void OnDpiChanged(object? sender, EventArgs args)
{
_dpi = GetWindow().Display.GetMonitorAtWindow(GetWindow().Window).ScaleFactor * DisplayInformation.BaseDpi;
_dpi = _dpiHelper.GetNativeDpi();
_displayInformation.NotifyDpiChanged();
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI.Runtime.Skia.Gtk/Helpers/Dpi/DpiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private void CheckDpiUpdate()
}
}

private float GetNativeDpi()
internal float GetNativeDpi()
{
if (GetWindow().Window == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public GLRenderSurfaceBase(IXamlRootHost host)
{
_displayInformation = DisplayInformation.GetForCurrentView();
_displayInformation.DpiChanged += OnDpiChanged;
UpdateDpi();

// Set some event handlers
Render += UnoGLDrawingArea_Render;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public SoftwareRenderSurface(IXamlRootHost host)
{
_displayInformation = DisplayInformation.GetForCurrentView();
_displayInformation.DpiChanged += OnDpiChanged;
UpdateDpi();

_colorType = SKImageInfo.PlatformColorType;
// R and B channels are inverted on macOS running on arm64 CPU and this is not detected by Skia
Expand Down

0 comments on commit 72dc180

Please sign in to comment.