Browse Source

Add option to enable/disable input focus proxy for X11. (#13273)

* Add option to enable/disable input focus proxy for X11.

* use list instead
pull/13295/head
Jumar Macato 3 years ago
committed by GitHub
parent
commit
03355b28b5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/Avalonia.X11/X11Platform.cs
  2. 22
      src/Avalonia.X11/X11Window.cs

6
src/Avalonia.X11/X11Platform.cs

@ -284,6 +284,12 @@ 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 use Input Focus Proxy.
/// The default value is false.
/// </summary>
public bool EnableInputFocusProxy { get; set; }
/// <summary>
/// Determines whether to enable support for the

22
src/Avalonia.X11/X11Window.cs

@ -64,7 +64,7 @@ namespace Avalonia.X11
private RawEventGrouper? _rawEventGrouper;
private bool _useRenderWindow = false;
private bool _usePositioningFlags = false;
private X11FocusProxy _focusProxy;
private X11FocusProxy? _focusProxy;
private enum XSyncState
{
@ -158,8 +158,13 @@ namespace Avalonia.X11
_renderHandle = _handle;
Handle = new PlatformHandle(_handle, "XID");
_focusProxy = new X11FocusProxy(platform, _handle, OnEvent);
SetWmClass(_focusProxy._handle, "FocusProxy");
if (platform.Options.EnableInputFocusProxy)
{
_focusProxy = new X11FocusProxy(platform, _handle, OnEvent);
SetWmClass(_focusProxy._handle, "FocusProxy");
}
_realSize = new PixelSize(defaultWidth, defaultHeight);
platform.Windows[_handle] = OnEvent;
XEventMask ignoredMask = XEventMask.SubstructureRedirectMask
@ -214,9 +219,14 @@ namespace Avalonia.X11
_nativeMenuExporter = DBusMenuExporter.TryCreateTopLevelNativeMenu(_handle);
_nativeControlHost = new X11NativeControlHost(_platform, this);
InitializeIme();
var data = new List<IntPtr> { _x11.Atoms.WM_DELETE_WINDOW, _x11.Atoms._NET_WM_SYNC_REQUEST };
if(platform.Options.EnableInputFocusProxy)
data.Add(_x11.Atoms.WM_TAKE_FOCUS);
XChangeProperty(_x11.Display, _handle, _x11.Atoms.WM_PROTOCOLS, _x11.Atoms.XA_ATOM, 32,
PropertyMode.Replace, new[] { _x11.Atoms.WM_DELETE_WINDOW, _x11.Atoms.WM_TAKE_FOCUS, _x11.Atoms._NET_WM_SYNC_REQUEST }, 3);
PropertyMode.Replace, data.ToArray(), data.Count);
if (_x11.HasXSync)
{
@ -564,7 +574,7 @@ namespace Avalonia.X11
_xSyncValue.Hi = ev.ClientMessageEvent.ptr4.ToInt32();
_xSyncState = XSyncState.WaitConfigure;
}
else if (ev.ClientMessageEvent.ptr1 == _x11.Atoms.WM_TAKE_FOCUS)
else if (ev.ClientMessageEvent.ptr1 == _x11.Atoms.WM_TAKE_FOCUS && _platform.Options.EnableInputFocusProxy)
{
IntPtr time = ev.ClientMessageEvent.ptr2;
XSetInputFocus(_x11.Display, _focusProxy._handle, RevertTo.Parent, time);
@ -953,7 +963,7 @@ namespace Avalonia.X11
_renderHandle = IntPtr.Zero;
}
_focusProxy.Cleanup();
_focusProxy?.Cleanup();
}
private bool ActivateTransientChildIfNeeded()

Loading…
Cancel
Save