Browse Source

refactor so that this can be set on X11Options as well

pull/6883/head
Jumar Macato 5 years ago
parent
commit
98836a5dd7
No known key found for this signature in database GPG Key ID: 85076C4D9D3155A3
  1. 16
      src/Avalonia.X11/X11Platform.cs
  2. 12
      src/Avalonia.X11/X11PlatformLifetimeEvents.cs

16
src/Avalonia.X11/X11Platform.cs

@ -81,7 +81,7 @@ namespace Avalonia.X11
.Bind<IPlatformIconLoader>().ToConstant(new X11IconLoader(Info))
.Bind<ISystemDialogImpl>().ToConstant(new GtkSystemDialog())
.Bind<IMountedVolumeInfoProvider>().ToConstant(new LinuxMountedVolumeInfoProvider())
.Bind<IPlatformLifetimeEventsImpl>().ToConstant(new X11PlatformLifetimeEvents());
.Bind<IPlatformLifetimeEventsImpl>().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.
/// </remarks>
public bool? EnableIme { get; set; }
/// <summary>
/// Determines whether to enable support for the
/// X Session Management Protocol.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public bool EnableSessionManagement { get; set; } =
Environment.GetEnvironmentVariable("AVALONIA_X11_USE_SESSION_MANAGEMENT") != "0";
public IList<GlVersion> GlProfiles { get; set; } = new List<GlVersion>
{
new GlVersion(GlProfileType.OpenGL, 4, 0),

12
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);
}

Loading…
Cancel
Save