-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux: Create linux specific project and services
- Loading branch information
Showing
9 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
YMouseButtonControl.Services.Linux/BackgroundTasksRunner.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using YMouseButtonControl.Core.KeyboardAndMouse; | ||
using YMouseButtonControl.Core.KeyboardAndMouse.Interfaces; | ||
using YMouseButtonControl.Core.Services.BackgroundTasks; | ||
|
||
namespace YMouseButtonControl.Services.Linux; | ||
|
||
public class BackgroundTasksRunner : IBackgroundTasksRunner | ||
{ | ||
private readonly IMouseListener _mouseListener; | ||
private readonly KeyboardSimulatorWorker _keyboardSimulatorWorker; | ||
|
||
public BackgroundTasksRunner( | ||
IMouseListener mouseListener, | ||
KeyboardSimulatorWorker keyboardSimulatorWorker | ||
) | ||
{ | ||
_mouseListener = mouseListener; | ||
_keyboardSimulatorWorker = keyboardSimulatorWorker; | ||
_mouseListener.Run(); | ||
_keyboardSimulatorWorker.Run(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_mouseListener.Dispose(); | ||
_keyboardSimulatorWorker.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using YMouseButtonControl.Core.Processes; | ||
|
||
namespace YMouseButtonControl.Services.Linux; | ||
|
||
public class CurrentWindowService : ICurrentWindowService | ||
{ | ||
// Match every window. If someone figures out how to get the current window in X11 and/or wayland, make a PR please | ||
public string ForegroundWindow { get; } = "*"; | ||
} |
14 changes: 14 additions & 0 deletions
14
YMouseButtonControl.Services.Linux/ProcessMonitorService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Diagnostics; | ||
using YMouseButtonControl.Core.Processes; | ||
using YMouseButtonControl.Core.Services.Abstractions.Models; | ||
|
||
namespace YMouseButtonControl.Services.Linux; | ||
|
||
public class ProcessMonitorService : IProcessMonitorService | ||
{ | ||
public IEnumerable<ProcessModel> GetProcesses() => | ||
Process | ||
.GetProcesses() | ||
.Select(x => new ProcessModel(x)) | ||
.Where(x => !string.IsNullOrWhiteSpace(x.Process.ProcessName)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Serilog; | ||
using YMouseButtonControl.Core.DataAccess.Models.Implementations; | ||
using YMouseButtonControl.Core.KeyboardAndMouse.Interfaces; | ||
using YMouseButtonControl.Core.Processes; | ||
using YMouseButtonControl.Core.Services.Abstractions.Models.EventArgs; | ||
|
||
namespace YMouseButtonControl.Services.Linux; | ||
|
||
public class SkipProfileService(ICurrentWindowService currentWindowService) : ISkipProfileService | ||
{ | ||
private readonly ILogger _myLog = Log.Logger.ForContext<SkipProfileService>(); | ||
|
||
// Returns whether this profile should be skipped on mouse events | ||
public bool ShouldSkipProfile(Profile p, NewMouseHookEventArgs e) | ||
{ | ||
// If the profile's checkbox is checked in the profiles list | ||
if (!p.Checked) | ||
{ | ||
_myLog.Information("Not checked"); | ||
return true; | ||
} | ||
|
||
if (p.Process == "*") | ||
{ | ||
return false; | ||
} | ||
|
||
if (currentWindowService.ForegroundWindow.Contains(p.Process)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (currentWindowService.ForegroundWindow == "*") | ||
{ | ||
return false; | ||
} | ||
|
||
_myLog.Information( | ||
"Foreground window: {ForegroundWindow}", | ||
currentWindowService.ForegroundWindow | ||
); | ||
_myLog.Information("Couldn't find foreground window {Process}", p.Process); | ||
return true; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
YMouseButtonControl.Services.Linux/YMouseButtonControl.Services.Linux.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\YMouseButtonControl.Core\YMouseButtonControl.Core.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters