From 03355b28b52d2fc0797f47f8781ae809eb8182d8 Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Tue, 17 Oct 2023 08:05:01 +0800 Subject: [PATCH] Add option to enable/disable input focus proxy for X11. (#13273) * Add option to enable/disable input focus proxy for X11. * use list instead --- src/Avalonia.X11/X11Platform.cs | 6 ++++++ src/Avalonia.X11/X11Window.cs | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.X11/X11Platform.cs b/src/Avalonia.X11/X11Platform.cs index cd667e6c01..04b427a826 100644 --- a/src/Avalonia.X11/X11Platform.cs +++ b/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. /// public bool? EnableIme { get; set; } + + /// + /// Determines whether to use Input Focus Proxy. + /// The default value is false. + /// + public bool EnableInputFocusProxy { get; set; } /// /// Determines whether to enable support for the diff --git a/src/Avalonia.X11/X11Window.cs b/src/Avalonia.X11/X11Window.cs index 7edf1fd025..06c1d7b2e1 100644 --- a/src/Avalonia.X11/X11Window.cs +++ b/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 { _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()