FramebufferToplevelImpl.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1.  using System;
  2. using System.Collections.Generic;
  3. using Avalonia.Controls;
  4. using Avalonia.Input;
  5. using Avalonia.Input.Raw;
  6. using Avalonia.LinuxFramebuffer.Input;
  7. using Avalonia.LinuxFramebuffer.Output;
  8. using Avalonia.Platform;
  9. using Avalonia.Rendering;
  10. using Avalonia.Rendering.Composition;
  11. namespace Avalonia.LinuxFramebuffer
  12. {
  13. class FramebufferToplevelImpl : ITopLevelImpl, IScreenInfoProvider
  14. {
  15. private readonly IOutputBackend _outputBackend;
  16. private readonly IInputBackend _inputBackend;
  17. public IInputRoot InputRoot { get; private set; }
  18. public FramebufferToplevelImpl(IOutputBackend outputBackend, IInputBackend inputBackend)
  19. {
  20. _outputBackend = outputBackend;
  21. _inputBackend = inputBackend;
  22. Surfaces = new object[] { _outputBackend };
  23. _inputBackend.Initialize(this, e => Input?.Invoke(e));
  24. }
  25. public IRenderer CreateRenderer(IRenderRoot root)
  26. {
  27. return new CompositingRenderer(root, LinuxFramebufferPlatform.Compositor, () => Surfaces);
  28. }
  29. public void Dispose()
  30. {
  31. throw new NotSupportedException();
  32. }
  33. public void SetInputRoot(IInputRoot inputRoot)
  34. {
  35. InputRoot = inputRoot;
  36. _inputBackend.SetInputRoot(inputRoot);
  37. }
  38. public Point PointToClient(PixelPoint p) => p.ToPoint(1);
  39. public PixelPoint PointToScreen(Point p) => PixelPoint.FromPoint(p, 1);
  40. public void SetCursor(ICursorImpl cursor)
  41. {
  42. }
  43. public Size ClientSize => ScaledSize;
  44. public Size? FrameSize => null;
  45. public IMouseDevice MouseDevice => new MouseDevice();
  46. public IPopupImpl CreatePopup() => null;
  47. public double RenderScaling => _outputBackend.Scaling;
  48. public IEnumerable<object> Surfaces { get; }
  49. public Action<RawInputEventArgs> Input { get; set; }
  50. public Action<Rect> Paint { get; set; }
  51. public Action<Size, PlatformResizeReason> Resized { get; set; }
  52. public Action<double> ScalingChanged { get; set; }
  53. public Action<WindowTransparencyLevel> TransparencyLevelChanged { get; set; }
  54. public Action Closed { get; set; }
  55. public Action LostFocus { get; set; }
  56. public Size ScaledSize => _outputBackend.PixelSize.ToSize(RenderScaling);
  57. public void SetTransparencyLevelHint(WindowTransparencyLevel transparencyLevel) { }
  58. public WindowTransparencyLevel TransparencyLevel { get; private set; }
  59. public void SetFrameThemeVariant(PlatformThemeVariant themeVariant) { }
  60. public AcrylicPlatformCompensationLevels AcrylicCompensationLevels { get; } = new AcrylicPlatformCompensationLevels(1, 1, 1);
  61. public object TryGetFeature(Type featureType) => null;
  62. }
  63. }