Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added viewonly mode #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/MarcusW.VncClient.Avalonia/VncView.KeyInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -69,6 +69,9 @@ protected override void OnKeyUp(KeyEventArgs e)
protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);
if (ViewOnly)
return;

ResetKeyPresses();
}

Expand Down
8 changes: 4 additions & 4 deletions src/MarcusW.VncClient.Avalonia/VncView.MouseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
28 changes: 24 additions & 4 deletions src/MarcusW.VncClient.Avalonia/VncView.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -16,10 +14,15 @@ public partial class VncView : RfbRenderTarget, IOutputHandler
/// <summary>
/// Defines the <see cref="Connection"/> property.
/// </summary>
public static readonly DirectProperty<VncView, RfbConnection?> ConnectionProperty =
AvaloniaProperty.RegisterDirect<VncView, RfbConnection?>(nameof(Connection), o => o.Connection, (o, v) => o.Connection = v);
public static readonly DirectProperty<VncView, RfbConnection?> ConnectionProperty = AvaloniaProperty.RegisterDirect<VncView, RfbConnection?>(nameof(Connection), o => o.Connection, (o, v) => o.Connection = v);

/// <summary>
/// Defines the <see cref="ViewOnly"/> property.
/// </summary>
public static readonly DirectProperty<VncView, bool> ViewOnlyProperty = AvaloniaProperty.RegisterDirect<VncView, bool>(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();
Expand Down Expand Up @@ -76,6 +79,20 @@ public RfbConnection? Connection
}
}

/// <summary>
/// Gets or sets the view only mode
/// </summary>
public bool ViewOnly
{
get => _viewOnly;
set
{
_viewOnly = value;
if (_viewOnly)
ResetKeyPresses();
}
}

public VncView()
{
InitSizing();
Expand All @@ -91,6 +108,9 @@ public virtual void RingBell()
/// <inheritdoc />
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);
Expand Down