From d00ba80a649a7342d24aacef37347c7277e6e39d Mon Sep 17 00:00:00 2001 From: Max Lefebvre Date: Sun, 24 Sep 2023 14:25:05 -0300 Subject: [PATCH] refactor --- GlazeWM.Domain/Windows/Inspector.Designer.cs | 4 +-- GlazeWM.Domain/Windows/Inspector.cs | 30 +++++++------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/GlazeWM.Domain/Windows/Inspector.Designer.cs b/GlazeWM.Domain/Windows/Inspector.Designer.cs index feced0bcb..905273fab 100644 --- a/GlazeWM.Domain/Windows/Inspector.Designer.cs +++ b/GlazeWM.Domain/Windows/Inspector.Designer.cs @@ -20,9 +20,9 @@ protected override void Dispose(bool disposing) components.Dispose(); } - if (disposing && cursorSubscription != null) + if (disposing && _cursorSubscription != null) { - cursorSubscription.Dispose(); + _cursorSubscription.Dispose(); } base.Dispose(disposing); diff --git a/GlazeWM.Domain/Windows/Inspector.cs b/GlazeWM.Domain/Windows/Inspector.cs index ce8532679..e4eb32332 100644 --- a/GlazeWM.Domain/Windows/Inspector.cs +++ b/GlazeWM.Domain/Windows/Inspector.cs @@ -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;