diff --git a/src/MarcusW.VncClient.Avalonia/VncView.KeyInput.cs b/src/MarcusW.VncClient.Avalonia/VncView.KeyInput.cs index c5e4d33..29ca22f 100644 --- a/src/MarcusW.VncClient.Avalonia/VncView.KeyInput.cs +++ b/src/MarcusW.VncClient.Avalonia/VncView.KeyInput.cs @@ -13,7 +13,7 @@ public partial class VncView protected override void OnTextInput(TextInputEventArgs e) { base.OnTextInput(e); - if (e.Handled) + if (ViewOnly || e.Handled) return; // Get connection @@ -39,7 +39,7 @@ protected override void OnTextInput(TextInputEventArgs e) protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); - if (e.Handled || e.Key == Key.None) + if (ViewOnly || e.Handled || e.Key == Key.None) return; // Send key press @@ -53,7 +53,7 @@ protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyUp(KeyEventArgs e) { base.OnKeyUp(e); - if (e.Handled || e.Key == Key.None) + if (ViewOnly|| e.Handled || e.Key == Key.None) return; // Send key release @@ -69,6 +69,9 @@ protected override void OnKeyUp(KeyEventArgs e) protected override void OnLostFocus(RoutedEventArgs e) { base.OnLostFocus(e); + if (ViewOnly) + return; + ResetKeyPresses(); } diff --git a/src/MarcusW.VncClient.Avalonia/VncView.MouseInput.cs b/src/MarcusW.VncClient.Avalonia/VncView.MouseInput.cs index e7a4d17..b3b1050 100644 --- a/src/MarcusW.VncClient.Avalonia/VncView.MouseInput.cs +++ b/src/MarcusW.VncClient.Avalonia/VncView.MouseInput.cs @@ -10,7 +10,7 @@ public partial class VncView protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); - if (e.Handled) + if (ViewOnly || e.Handled) return; PointerPoint point = e.GetCurrentPoint(this); @@ -22,7 +22,7 @@ protected override void OnPointerMoved(PointerEventArgs e) protected override void OnPointerPressed(PointerPressedEventArgs e) { base.OnPointerPressed(e); - if (e.Handled) + if (ViewOnly || e.Handled) return; PointerPoint point = e.GetCurrentPoint(this); @@ -34,7 +34,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e) protected override void OnPointerReleased(PointerReleasedEventArgs e) { base.OnPointerReleased(e); - if (e.Handled) + if (ViewOnly || e.Handled) return; PointerPoint point = e.GetCurrentPoint(this); @@ -46,7 +46,7 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e) protected override void OnPointerWheelChanged(PointerWheelEventArgs e) { base.OnPointerWheelChanged(e); - if (e.Handled) + if (ViewOnly || e.Handled) return; PointerPoint point = e.GetCurrentPoint(this); diff --git a/src/MarcusW.VncClient.Avalonia/VncView.cs b/src/MarcusW.VncClient.Avalonia/VncView.cs index 3bd5fb9..fc91e6a 100644 --- a/src/MarcusW.VncClient.Avalonia/VncView.cs +++ b/src/MarcusW.VncClient.Avalonia/VncView.cs @@ -1,10 +1,8 @@ using System; using System.Reactive.Disposables; using Avalonia; -using Avalonia.Input; using Avalonia.Threading; using MarcusW.VncClient.Output; -using MarcusW.VncClient.Protocol.Implementation.MessageTypes.Outgoing; namespace MarcusW.VncClient.Avalonia { @@ -16,10 +14,15 @@ public partial class VncView : RfbRenderTarget, IOutputHandler /// /// Defines the property. /// - public static readonly DirectProperty ConnectionProperty = - AvaloniaProperty.RegisterDirect(nameof(Connection), o => o.Connection, (o, v) => o.Connection = v); + public static readonly DirectProperty ConnectionProperty = AvaloniaProperty.RegisterDirect(nameof(Connection), o => o.Connection, (o, v) => o.Connection = v); + + /// + /// Defines the property. + /// + public static readonly DirectProperty ViewOnlyProperty = AvaloniaProperty.RegisterDirect(nameof(ViewOnly), o => o.ViewOnly, (o, v) => o.ViewOnly = v); private RfbConnection? _connection; + private bool _viewOnly; // Disposable for cleaning up after connection detaches private CompositeDisposable _connectionDetachDisposable = new CompositeDisposable(); @@ -76,6 +79,20 @@ public RfbConnection? Connection } } + /// + /// Gets or sets the view only mode + /// + public bool ViewOnly + { + get => _viewOnly; + set + { + _viewOnly = value; + if (_viewOnly) + ResetKeyPresses(); + } + } + public VncView() { InitSizing(); @@ -91,6 +108,9 @@ public virtual void RingBell() /// public virtual void HandleServerClipboardUpdate(string text) { + if (ViewOnly) + return; + Dispatcher.UIThread.Post(async () => { // Copy the text to the local clipboard await Application.Current.Clipboard.SetTextAsync(text).ConfigureAwait(true);