Add a simple demo for using Gdk.Seat to query the mouse position.
This commit is contained in:
parent
216cfd941e
commit
7d5190865e
1 changed files with 32 additions and 0 deletions
32
Source/Samples/Sections/Miscellaneous/SeatSection.cs
Normal file
32
Source/Samples/Sections/Miscellaneous/SeatSection.cs
Normal file
|
@ -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})");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue