Skip to content

Commit

Permalink
Merge pull request #28 from LegendaryB/develop
Browse files Browse the repository at this point in the history
Release v1.4
  • Loading branch information
LegendaryB authored Sep 15, 2019
2 parents f00a3c9 + 1dd9c5a commit 8355280
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Kirei.Application.System.Input
namespace Kirei.Application.System.InputProcessing
{
public interface IInputActionMapper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Kirei.Application.System.Input
namespace Kirei.Application.System.InputProcessing
{
public interface IInputListener
{
Expand Down
1 change: 1 addition & 0 deletions src/Kirei.Infrastructure/Kirei.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
<PackageReference Include="NeatInput" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
19 changes: 0 additions & 19 deletions src/Kirei.Infrastructure/Native/User32.Wrappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ namespace Kirei.Infrastructure.Native
{
internal static partial class User32
{
internal struct LASTINPUTINFO
{
public uint cbSize;
public uint dwTime;
}

[DllImport("user32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetClassName(
IntPtr hWnd,
Expand All @@ -39,16 +30,6 @@ SetWindowPosFlags uFlags
private static extern bool GetWindowRect(
IntPtr hwnd,
ref RECT rectangle);

internal static long GetUserIdleTime()
{
var lastInputStruct = new LASTINPUTINFO();
lastInputStruct.cbSize = (uint)Marshal.SizeOf(lastInputStruct);

GetLastInputInfo(ref lastInputStruct);

return ((uint)Environment.TickCount - lastInputStruct.dwTime);
}

internal static string GetClassName(IntPtr hWnd)
{
Expand Down
39 changes: 0 additions & 39 deletions src/Kirei.Infrastructure/System/Input/InputListener.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Kirei.Application.System.Input;
using Kirei.Application.System.InputProcessing;

using System;
using System.Collections.Generic;

namespace Kirei.Infrastructure.System.Input
namespace Kirei.Infrastructure.System.InputProcessing
{
public class InputActionMapper : IInputActionMapper
{
Expand Down
57 changes: 57 additions & 0 deletions src/Kirei.Infrastructure/System/InputProcessing/InputListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Kirei.Application.System.InputProcessing;
using Kirei.Infrastructure.Configuration;

using NeatInput;
using NeatInput.Domain.Processing;

using System;
using System.Threading;

namespace Kirei.Infrastructure.System.InputProcessing
{
public class InputListener :
IInputListener
{
private InputProvider _inputProvider;
private IInputActionMapper _inputActionMapper;

private DateTime lastInputReceivedAt;
private bool hasIconsBeenHidden = false;

public void Listen(IInputActionMapper inputActionMapper)
{
_inputProvider = new InputProvider();
_inputActionMapper = inputActionMapper;

lastInputReceivedAt = DateTime.Now;

_inputProvider.InputReceived += OnInputReceived;

var inactiveAfterMs = ConfigurationProvider.Configuration.Application.InactiveAfterMs;
var inputPollingRateMs = ConfigurationProvider.Configuration.Application.InputPollingRate;

while (true)
{
var lastInputInMilliseconds = DateTime.Now.Subtract(lastInputReceivedAt).TotalMilliseconds;

if (lastInputInMilliseconds >= inactiveAfterMs && !hasIconsBeenHidden)
{
_inputActionMapper.HandleInput();
hasIconsBeenHidden = true;
}
else if (lastInputInMilliseconds < inactiveAfterMs && hasIconsBeenHidden)
{
_inputActionMapper.HandleInput();
hasIconsBeenHidden = false;
}

Thread.Sleep(inputPollingRateMs);
}
}

private void OnInputReceived(Input input)
{
lastInputReceivedAt = DateTime.Now;
}
}
}
2 changes: 1 addition & 1 deletion src/Kirei/App.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Kirei.Application;
using Kirei.Application.System;
using Kirei.Application.System.Desktop;
using Kirei.Application.System.Input;
using Kirei.Application.System.InputProcessing;
using Kirei.Infrastructure.Configuration;

namespace Kirei
Expand Down
4 changes: 2 additions & 2 deletions src/Kirei/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Kirei.Application;
using Kirei.Application.System;
using Kirei.Application.System.Desktop;
using Kirei.Application.System.Input;
using Kirei.Application.System.InputProcessing;
using Kirei.Infrastructure;
using Kirei.Infrastructure.System;
using Kirei.Infrastructure.System.Desktop;
using Kirei.Infrastructure.System.Input;
using Kirei.Infrastructure.System.InputProcessing;

using Microsoft.Extensions.DependencyInjection;

Expand Down

0 comments on commit 8355280

Please sign in to comment.