Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
maxle5 committed Sep 24, 2023
1 parent b539048 commit d00ba80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions GlazeWM.Domain/Windows/Inspector.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 11 additions & 19 deletions GlazeWM.Domain/Windows/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,34 @@ namespace GlazeWM.Domain.Windows
{
public partial class Inspector : Form
{
private Point? cursorPosition { get; set; }
private IDisposable cursorSubscription { get; set; }
private readonly IDisposable _cursorSubscription;

public Inspector()
{
InitializeComponent();
InitializeCursorSubscription();

MaximizeBox = false;
MinimizeBox = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
StartPosition = FormStartPosition.CenterParent;
}

private void InitializeCursorSubscription()
{
cursorSubscription = MouseEvents.MouseMoves
_cursorSubscription = MouseEvents.MouseMoves
.Sample(TimeSpan.FromMilliseconds(50))
.Subscribe((@event) =>
{
// skip if the cursor hasn't moved
if (cursorPosition?.X == @event.Point.X && cursorPosition?.Y == @event.Point.Y)
{
return;
}
.Subscribe(OnCursorMove);
}

// update last known cursor position
cursorPosition = @event.Point;
private void OnCursorMove(MouseMoveEvent @event)
{
// get handle under cursor
var handle = WindowFromPoint(@event.Point);

// update the inspector info
UpdateInspectorValues(WindowFromPoint(cursorPosition.Value));
});
// update the inspector info
UpdateInspectorValues(handle);
}

public void UpdateInspectorValues(IntPtr? handle)
{
// skip if there is nothing to inspect
if (handle == null)
{
return;
Expand Down

0 comments on commit d00ba80

Please sign in to comment.