From b9e262f0209bf50bab6d8e57ead6b86a4c740d07 Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Tue, 23 Nov 2021 15:12:19 +0800 Subject: [PATCH] add EnvVar to disable the x11 shutdown cancellation feature --- src/Avalonia.X11/X11PlatformLifetimeEvents.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.X11/X11PlatformLifetimeEvents.cs b/src/Avalonia.X11/X11PlatformLifetimeEvents.cs index beb3533e73..ae842b4eec 100644 --- a/src/Avalonia.X11/X11PlatformLifetimeEvents.cs +++ b/src/Avalonia.X11/X11PlatformLifetimeEvents.cs @@ -34,6 +34,9 @@ namespace Avalonia.X11 private static readonly ICELib.IceIOErrorHandler s_iceIoErrorHandlerDelegate = StaticIceIOErrorHandler; private static readonly SMLib.IceWatchProc s_iceWatchProcDelegate = IceWatchHandler; + private bool AllowShutdownCancellation => + Environment.GetEnvironmentVariable("AVALONIA_X11_USE_SESSION_MANAGER") != "0"; + private static SMLib.SmcCallbacks s_callbacks = new SMLib.SmcCallbacks() { ShutdownCancelled = Marshal.GetFunctionPointerForDelegate(s_shutdownCancelledDelegate), @@ -226,7 +229,10 @@ namespace Avalonia.X11 { var e = new ShutdownRequestedEventArgs(); - ShutdownRequested?.Invoke(this, e); + if (AllowShutdownCancellation) + { + ShutdownRequested?.Invoke(this, e); + } SMLib.SmcInteractDone(smcConn, e.Cancel);