protected virtual void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj) { lock (_lock) { if (obj is FrameReceivedMessage lastFrame) { lock (_lock) { _lastReceivedFrame = lastFrame.SequenceId; } Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is ClientSupportedPixelFormatsMessage supportedFormats) { lock (_lock) _supportedFormats = supportedFormats.Formats; Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is MeasureViewportMessage measure) { Dispatcher.UIThread.Post(() => { var m = Measure(new Size(measure.Width, measure.Height)); _transport.Send(new MeasureViewportMessage { Width = m.Width, Height = m.Height }); }); } if (obj is ClientViewportAllocatedMessage allocated) { lock (_lock) { if (_pendingAllocation == null) { Dispatcher.UIThread.Post(() => { ClientViewportAllocatedMessage allocation; lock (_lock) { allocation = _pendingAllocation; _pendingAllocation = null; } _dpi = new Vector(allocation.DpiX, allocation.DpiY); ClientSize = new Size(allocation.Width, allocation.Height); RenderIfNeeded(); }); } _pendingAllocation = allocated; } } } }
protected virtual void OnMessage(IAvaloniaRemoteTransportConnection transport, object obj) { lock (_lock) { if (obj is FrameReceivedMessage lastFrame) { lock (_lock) { _lastReceivedFrame = lastFrame.SequenceId; } Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is ClientRenderInfoMessage renderInfo) { lock (_lock) { _dpi = new Vector(renderInfo.DpiX, renderInfo.DpiY); _invalidated = true; } Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is ClientSupportedPixelFormatsMessage supportedFormats) { lock (_lock) _supportedFormats = supportedFormats.Formats; Dispatcher.UIThread.Post(RenderIfNeeded); } if (obj is MeasureViewportMessage measure) { Dispatcher.UIThread.Post(() => { var m = Measure(new Size(measure.Width, measure.Height)); _transport.Send(new MeasureViewportMessage { Width = m.Width, Height = m.Height }); }); } if (obj is ClientViewportAllocatedMessage allocated) { lock (_lock) { if (_pendingAllocation == null) { Dispatcher.UIThread.Post(() => { ClientViewportAllocatedMessage allocation; lock (_lock) { allocation = _pendingAllocation; _pendingAllocation = null; } _dpi = new Vector(allocation.DpiX, allocation.DpiY); ClientSize = new Size(allocation.Width, allocation.Height); RenderIfNeeded(); }); } _pendingAllocation = allocated; } } if (obj is PointerMovedEventMessage pointer) { Dispatcher.UIThread.Post(() => { Input?.Invoke(new RawMouseEventArgs( MouseDevice, 0, InputRoot, RawMouseEventType.Move, new Point(pointer.X, pointer.Y), GetAvaloniaInputModifiers(pointer.Modifiers))); }, DispatcherPriority.Input); } if (obj is PointerPressedEventMessage pressed) { Dispatcher.UIThread.Post(() => { Input?.Invoke(new RawMouseEventArgs( MouseDevice, 0, InputRoot, GetAvaloniaEventType(pressed.Button, true), new Point(pressed.X, pressed.Y), GetAvaloniaInputModifiers(pressed.Modifiers))); }, DispatcherPriority.Input); } if (obj is PointerPressedEventMessage released) { Dispatcher.UIThread.Post(() => { Input?.Invoke(new RawMouseEventArgs( MouseDevice, 0, InputRoot, GetAvaloniaEventType(released.Button, false), new Point(released.X, released.Y), GetAvaloniaInputModifiers(released.Modifiers))); }, DispatcherPriority.Input); } if (obj is ScrollEventMessage scroll) { Dispatcher.UIThread.Post(() => { Input?.Invoke(new RawMouseWheelEventArgs( MouseDevice, 0, InputRoot, new Point(scroll.X, scroll.Y), new Vector(scroll.DeltaX, scroll.DeltaY), GetAvaloniaInputModifiers(scroll.Modifiers))); }, DispatcherPriority.Input); } if (obj is KeyEventMessage key) { Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); Dispatcher.UIThread.Post(() => { Input?.Invoke(new RawKeyEventArgs( KeyboardDevice, 0, key.IsDown ? RawKeyEventType.KeyDown : RawKeyEventType.KeyUp, (Key)key.Key, GetAvaloniaInputModifiers(key.Modifiers))); }, DispatcherPriority.Input); } if (obj is TextInputEventMessage text) { Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1); Dispatcher.UIThread.Post(() => { Input?.Invoke(new RawTextInputEventArgs( KeyboardDevice, 0, text.Text)); }, DispatcherPriority.Input); } } }