From 7d5190865e7539fe06ce78c563a76fd1bc0f6c22 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Thu, 7 Jan 2021 19:24:27 -0500 Subject: [PATCH] Add a simple demo for using Gdk.Seat to query the mouse position. --- .../Sections/Miscellaneous/SeatSection.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Source/Samples/Sections/Miscellaneous/SeatSection.cs diff --git a/Source/Samples/Sections/Miscellaneous/SeatSection.cs b/Source/Samples/Sections/Miscellaneous/SeatSection.cs new file mode 100644 index 000000000..c7c988500 --- /dev/null +++ b/Source/Samples/Sections/Miscellaneous/SeatSection.cs @@ -0,0 +1,32 @@ +using System; +using Gtk; + +namespace Samples +{ + [Section(ContentType=typeof(SeatDemo), Category = Category.Miscellaneous)] + class SeatSection : ListSection + { + public SeatSection() + { + AddItem("Press button to output mouse location:", new SeatDemo("Press me")); + } + } + + class SeatDemo : Button + { + public SeatDemo(string text) : base(text) + { + } + + protected override void OnPressed() + { + base.OnPressed(); + + var seat = Display.DefaultSeat; + ApplicationOutput.WriteLine($"Default seat: {seat}"); + + seat.Pointer.GetPosition(null, out int x, out int y); + ApplicationOutput.WriteLine($"Position: ({x}, {y})"); + } + } +} \ No newline at end of file