Program.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Controls.Primitives;
  4. using Avalonia.Media;
  5. using ControlCatalog;
  6. using ControlCatalog.Models;
  7. using Gdk;
  8. using Gtk;
  9. using Window = Gtk.Window;
  10. namespace XEmbedSample;
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. HarfbuzzWorkaround.Apply();
  16. AppBuilder.Configure<App>()
  17. .UseSkia()
  18. .With(new X11PlatformOptions()
  19. {
  20. UseGLibMainLoop = true,
  21. ExterinalGLibMainLoopExceptionLogger = e => Console.WriteLine(e.ToString())
  22. })
  23. .UseX11()
  24. .SetupWithoutStarting();
  25. App.SetCatalogThemes(CatalogTheme.Fluent);
  26. Gdk.Global.AllowedBackends = "x11";
  27. Gtk.Application.Init("myapp", ref args);
  28. var w = new Gtk.Window("XEmbed Test Window");
  29. var socket = new AvaloniaXEmbedGtkSocket(GetBackgroundColor(w))
  30. {
  31. Content = new ScrollViewer()
  32. {
  33. Content = new ControlCatalog.Pages.TextBoxPage(),
  34. HorizontalScrollBarVisibility = ScrollBarVisibility.Auto
  35. }
  36. };
  37. var vbox = new Gtk.Box(Gtk.Orientation.Vertical, 5);
  38. var label = new Gtk.Label("Those are GTK controls");
  39. vbox.Add(label);
  40. vbox.Add(new Gtk.Entry());
  41. vbox.Add(new Gtk.Button(new Gtk.Label("Do nothing")));
  42. vbox.PackEnd(socket, true, true, 0);
  43. socket.HeightRequest = 400;
  44. socket.WidthRequest = 400;
  45. w.Add(vbox);
  46. socket.Realize();
  47. w.AddSignalHandler("destroy", new EventHandler((_, __) =>
  48. {
  49. Gtk.Application.Quit();
  50. socket.Destroy();
  51. }));
  52. w.ShowAll();
  53. Gtk.Application.Run();
  54. }
  55. private static RGBA GetBackgroundColor(Window window)
  56. {
  57. #pragma warning disable CS0612 // Type or member is obsolete; OK for a sample.
  58. return window.StyleContext.GetBackgroundColor(StateFlags.Normal);
  59. #pragma warning restore CS0612 // Type or member is obsolete
  60. }
  61. }