diff --git a/src/Avalonia.X11/SMLib.cs b/src/Avalonia.X11/SMLib.cs index 6ffcad60bf..e2b39cfcff 100644 --- a/src/Avalonia.X11/SMLib.cs +++ b/src/Avalonia.X11/SMLib.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Runtime.InteropServices; @@ -7,20 +8,19 @@ namespace Avalonia.X11 { private const string LibSm = "libSM.so.6"; - [DllImport(LibSm, CharSet = CharSet.Ansi)] + [DllImport(LibSm, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] public static extern IntPtr SmcOpenConnection( - [MarshalAs(UnmanagedType.LPWStr)] string networkId, + [MarshalAs(UnmanagedType.LPStr)] string? networkId, IntPtr content, int xsmpMajorRev, int xsmpMinorRev, - ulong mask, + nuint mask, ref SmcCallbacks callbacks, - [MarshalAs(UnmanagedType.LPWStr)] [Out] - out string previousId, - [MarshalAs(UnmanagedType.LPWStr)] [Out] - out string clientIdRet, + [MarshalAs(UnmanagedType.LPStr)] string? previousId, + ref IntPtr clientIdRet, int errorLength, - [Out] char[] errorStringRet); + [Out] byte[] errorStringRet + ); [DllImport(LibSm, CallingConvention = CallingConvention.StdCall)] public static extern int SmcCloseConnection( diff --git a/src/Avalonia.X11/X11PlatformLifetimeEvents.cs b/src/Avalonia.X11/X11PlatformLifetimeEvents.cs index 06e1d8879f..1a17a018e8 100644 --- a/src/Avalonia.X11/X11PlatformLifetimeEvents.cs +++ b/src/Avalonia.X11/X11PlatformLifetimeEvents.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Text; using System.Collections.Concurrent; using System.Runtime.InteropServices; using System.Threading; @@ -14,10 +15,10 @@ namespace Avalonia.X11 internal unsafe class X11PlatformLifetimeEvents : IDisposable, IPlatformLifetimeEventsImpl { private readonly AvaloniaX11Platform _platform; - private const ulong SmcSaveYourselfProcMask = 1L; - private const ulong SmcDieProcMask = 2L; - private const ulong SmcSaveCompleteProcMask = 4L; - private const ulong SmcShutdownCancelledProcMask = 8L; + private const nuint SmcSaveYourselfProcMask = 1; + private const nuint SmcDieProcMask = 2; + private const nuint SmcSaveCompleteProcMask = 4; + private const nuint SmcShutdownCancelledProcMask = 8; private static readonly ConcurrentDictionary s_nativeToManagedMapper = new ConcurrentDictionary(); @@ -62,24 +63,24 @@ namespace Avalonia.X11 return; } - var errorBuf = new char[255]; - - var smcConn = SMLib.SmcOpenConnection(null!, + byte[] errorBuf = new byte[255]; + IntPtr clientIdRet = IntPtr.Zero; + var smcConn = SMLib.SmcOpenConnection(null, IntPtr.Zero, 1, 0, SmcSaveYourselfProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask | SmcDieProcMask, ref s_callbacks, - out _, - out _, + null, + ref clientIdRet, errorBuf.Length, errorBuf); if (smcConn == IntPtr.Zero) { Logger.TryGet(LogEventLevel.Warning, LogArea.X11Platform)?.Log(this, - $"SMLib/ICELib reported a new error: {new string(errorBuf)}"); + $"SMLib/ICELib reported a new error: {Encoding.ASCII.GetString(errorBuf)}"); return; } diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 1e1cd482f4..d1945e6c85 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -265,7 +265,7 @@ namespace Avalonia.Win32 { if (IsWindowVisible(_hwnd)) { - ShowWindow(value, true); + ShowWindow(value, value != WindowState.Minimized); // If the window is minimized, it shouldn't be activated } _showWindowState = value; @@ -973,7 +973,7 @@ namespace Avalonia.Win32 { case WindowState.Minimized: newWindowProperties.IsFullScreen = false; - command = activate ? ShowWindowCommand.Minimize : ShowWindowCommand.ShowMinNoActive; + command = ShowWindowCommand.Minimize; break; case WindowState.Maximized: newWindowProperties.IsFullScreen = false;