diff --git a/src/Avalonia.X11/X11Platform.cs b/src/Avalonia.X11/X11Platform.cs index baa097a422..a18f91d301 100644 --- a/src/Avalonia.X11/X11Platform.cs +++ b/src/Avalonia.X11/X11Platform.cs @@ -81,7 +81,7 @@ namespace Avalonia.X11 .Bind().ToConstant(new X11IconLoader(Info)) .Bind().ToConstant(new GtkSystemDialog()) .Bind().ToConstant(new LinuxMountedVolumeInfoProvider()) - .Bind().ToConstant(new X11PlatformLifetimeEvents()); + .Bind().ToConstant(new X11PlatformLifetimeEvents(this)); X11Screens = Avalonia.X11.X11Screens.Init(this); Screens = new X11Screens(X11Screens); @@ -231,7 +231,19 @@ namespace Avalonia /// on their input devices by using sequences of characters or mouse operations that are natively available on their input devices. /// public bool? EnableIme { get; set; } - + + /// + /// Determines whether to enable support for the + /// X Session Management Protocol. + /// + /// + /// X Session Management Protocol is a standard implemented on most + /// Linux systems that uses Xorg. This enables apps to control how they + /// can control and/or cancel the pending shutdown requested by the user. + /// + public bool EnableSessionManagement { get; set; } = + Environment.GetEnvironmentVariable("AVALONIA_X11_USE_SESSION_MANAGEMENT") != "0"; + public IList GlProfiles { get; set; } = new List { new GlVersion(GlProfileType.OpenGL, 4, 0), diff --git a/src/Avalonia.X11/X11PlatformLifetimeEvents.cs b/src/Avalonia.X11/X11PlatformLifetimeEvents.cs index ae842b4eec..06e1d8879f 100644 --- a/src/Avalonia.X11/X11PlatformLifetimeEvents.cs +++ b/src/Avalonia.X11/X11PlatformLifetimeEvents.cs @@ -11,8 +11,9 @@ using Avalonia.Threading; namespace Avalonia.X11 { - public unsafe class X11PlatformLifetimeEvents : IDisposable, IPlatformLifetimeEventsImpl + 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; @@ -34,9 +35,6 @@ 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), @@ -51,8 +49,10 @@ namespace Avalonia.X11 private bool _saveYourselfPhase; - public X11PlatformLifetimeEvents() + internal X11PlatformLifetimeEvents(AvaloniaX11Platform platform) { + _platform = platform; + if (ICELib.IceAddConnectionWatch( Marshal.GetFunctionPointerForDelegate(s_iceWatchProcDelegate), IntPtr.Zero) == 0) @@ -229,7 +229,7 @@ namespace Avalonia.X11 { var e = new ShutdownRequestedEventArgs(); - if (AllowShutdownCancellation) + if (_platform.Options?.EnableSessionManagement ?? false) { ShutdownRequested?.Invoke(this, e); }