Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit db83da9
Merge: 2227cd3 39ca2bb
Author: Marco van den Oever <[email protected]>
Date:   Sun Jul 14 13:18:44 2024 +0200

    Merge branch 'master' into kwin-2

commit 39ca2bb
Author: Marco van den Oever <[email protected]>
Date:   Sun Jul 14 13:09:25 2024 +0200

    Removed UI test project for now

commit 69c1282
Author: Marco van den Oever <[email protected]>
Date:   Sun Jul 14 13:07:18 2024 +0200

    Async extensions (NoCtx)

commit 4db65ef
Author: Marco van den Oever <[email protected]>
Date:   Sun Jul 14 13:03:34 2024 +0200

    [WtqRect] Contains()

commit 84e1060
Author: Marco van den Oever <[email protected]>
Date:   Sun Jul 14 12:57:50 2024 +0200

    Package updates

commit edf0abc
Author: Marco van den Oever <[email protected]>
Date:   Fri Jul 12 21:27:59 2024 +0200

    [Build/GitHub] Added manual workflow dispatch

commit 2227cd3
Author: Marco van den Oever <[email protected]>
Date:   Fri Jun 7 02:25:16 2024 +0200

    Workspace

commit 1eefb4d
Author: Marco van den Oever <[email protected]>
Date:   Sun Jun 2 18:46:16 2024 +0200

    Workspace

commit 71729f9
Merge: d3fef7c cb7ba77
Author: Marco van den Oever <[email protected]>
Date:   Sun Jun 2 18:42:43 2024 +0200

    Merge branch 'app-repo-refactor' into kwin-2

commit cb7ba77
Author: Marco van den Oever <[email protected]>
Date:   Sun Jun 2 18:35:14 2024 +0200

    Workspace

commit 1fbe3d8
Merge: 9d9a975 25f118d
Author: Marco van den Oever <[email protected]>
Date:   Sun Jun 2 18:31:18 2024 +0200

    Merge branch 'master' into app-repo-refactor

commit 25f118d
Author: Marco van den Oever <[email protected]>
Date:   Sun Jun 2 18:29:40 2024 +0200

    Some cleanup

commit 7da241c
Author: Marco van den Oever <[email protected]>
Date:   Sun Jun 2 18:20:26 2024 +0200

    Removed SharpHook

commit 9d9a975
Author: Marco van den Oever <[email protected]>
Date:   Mon May 20 23:57:40 2024 +0200

    Workspace

commit f29e90e
Merge: aa1848b 95cef86
Author: Marco van den Oever <[email protected]>
Date:   Mon May 20 23:47:42 2024 +0200

    Merge branch 'master' into app-repo-refactor

commit aa1848b
Author: Marco van den Oever <[email protected]>
Date:   Mon May 20 23:38:02 2024 +0200

    Merge 'master' into 'app-repo-refactor'.

commit 32bf51d
Author: Marco van den Oever <[email protected]>
Date:   Mon May 20 14:49:59 2024 +0200

    Reworked how new app instances are created
  • Loading branch information
flyingpie committed Jul 14, 2024
1 parent d3fef7c commit 9d03c3b
Show file tree
Hide file tree
Showing 49 changed files with 661 additions and 743 deletions.
6 changes: 2 additions & 4 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@
"PublishWin64Aot",
"PublishWin64FrameworkDependent",
"PublishWin64SelfContained",
"ReportInfo",
"Restore"
"ReportInfo"
]
}
},
Expand All @@ -115,8 +114,7 @@
"PublishWin64Aot",
"PublishWin64FrameworkDependent",
"PublishWin64SelfContained",
"ReportInfo",
"Restore"
"ReportInfo"
]
}
},
Expand Down
23 changes: 6 additions & 17 deletions src/01-Build/NukeBuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,11 @@ public sealed class Build : NukeBuild
OutputDirectory.CreateOrCleanDirectory();
});

/// <summary>
/// NuGet restore.
/// </summary>
public Target Restore => _ => _
.DependsOn(Clean)
.Executes(() =>
{
// DotNetRestore(_ => _
// .SetProcessWorkingDirectory(Solution.));
});

/// <summary>
/// Linux x64 AOT.
/// </summary>
private Target PublishLinux64Aot => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Produces(PathToLinux64AotZip)
.Executes(() =>
{
Expand Down Expand Up @@ -145,7 +134,7 @@ public sealed class Build : NukeBuild
/// Linux x64 framework dependent.
/// </summary>
private Target PublishLinux64FrameworkDependent => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Produces(PathToLinux64FrameworkDependentZip)
.Executes(() =>
{
Expand Down Expand Up @@ -173,7 +162,7 @@ public sealed class Build : NukeBuild
/// Windows x64 self contained.
/// </summary>
private Target PublishLinux64SelfContained => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Produces(PathToLinux64SelfContainedZip)
.Executes(() =>
{
Expand Down Expand Up @@ -201,7 +190,7 @@ public sealed class Build : NukeBuild
/// Windows x64 AOT.
/// </summary>
private Target PublishWin64Aot => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Produces(PathToWin64AotZip)
.Executes(() =>
{
Expand Down Expand Up @@ -229,7 +218,7 @@ public sealed class Build : NukeBuild
/// Windows x64 framework dependent.
/// </summary>
private Target PublishWin64FrameworkDependent => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Produces(PathToWin64FrameworkDependentZip)
.Executes(() =>
{
Expand Down Expand Up @@ -257,7 +246,7 @@ public sealed class Build : NukeBuild
/// Windows x64 self contained.
/// </summary>
private Target PublishWin64SelfContained => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Produces(PathToWin64SelfContainedZip)
.Executes(() =>
{
Expand Down
13 changes: 12 additions & 1 deletion src/10-Core/Wtq/Data/WtqRect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Wtq.Data;
using System.Drawing;

namespace Wtq.Data;

public struct WtqRect : IEquatable<WtqRect>
{
Expand Down Expand Up @@ -36,6 +38,15 @@ public static WtqRect Lerp(WtqRect b1, WtqRect b2, float by)
};
}

public readonly bool Contains(Point pos)
{
return
X < pos.X &&
Y < pos.Y &&
X + Width > pos.X &&
Y + Height > pos.Y;
}

public readonly bool Contains(WtqVec2I pos)
{
return
Expand Down
8 changes: 2 additions & 6 deletions src/10-Core/Wtq/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.Extensions.Hosting;
using Wtq.Events;
using Wtq.Services;
using Wtq.Services.Apps;

namespace Wtq;

Expand Down Expand Up @@ -34,14 +33,11 @@ public static IServiceCollection AddWtqCore(this IServiceCollection services)
// Core App Logic
.AddSingleton<IWtqAppToggleService, WtqAppToggleService>()
.AddSingleton<IWtqBus, WtqBus>()
.AddSingleton<IWtqAppRepo, WtqAppRepo>()
.AddSingleton<IWtqProcessFactory, WtqProcessFactory>()
.AddSingletonHostedService<IWtqAppRepo, WtqAppRepo>()
.AddSingletonHostedService<IWtqHotKeyService, WtqHotKeyService>()
.AddSingletonHostedService<IWtqFocusTracker, WtqFocusTracker>()

.AddHostedService<WtqService>()

.AddSingleton<WtqAppMonitorService>()
.AddHostedService(p => p.GetRequiredService<WtqAppMonitorService>());
.AddHostedService<WtqService>();
}
}
82 changes: 0 additions & 82 deletions src/10-Core/Wtq/Services/Apps/WtqAppMonitorService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Wtq.Services.Apps;
namespace Wtq.Services;

public interface IWtqAppRepo : IAsyncDisposable
{
Expand All @@ -8,9 +8,5 @@ public interface IWtqAppRepo : IAsyncDisposable

WtqApp GetAppByNameRequired(string name);

WtqAppOptions? GetOptionsByName(string name);

WtqAppOptions GetOptionsByNameRequired(string name);

Task UpdateAppsAsync();
}
2 changes: 2 additions & 0 deletions src/10-Core/Wtq/Services/IWtqFocusTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public interface IWtqFocusTracker
{
// TODO: Remove after refactoring to event.
WtqWindow? LastNonWtqForeground { get; }

Task FocusLastNonWtqAppAsync();
}
2 changes: 1 addition & 1 deletion src/10-Core/Wtq/Services/IWtqProcessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IWtqProcessService
/// <summary>
/// Create a new process instance as defined by <see cref="WtqAppOptions"/>'s parameters.
/// </summary>
Task<WtqWindow?> CreateAsync(WtqAppOptions opts);
Task CreateAsync(WtqAppOptions opts);

/// <summary>
/// Looks for a process that matches the specified <paramref name="opts"/>.
Expand Down
6 changes: 3 additions & 3 deletions src/10-Core/Wtq/Services/IWtqScreenInfoProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Wtq.Services;

public interface IWtqScreenInfoProvider
{
WtqRect GetPrimaryScreenRect();
Task<WtqRect> GetPrimaryScreenRectAsync();

WtqRect[] GetScreenRects();
Task<WtqRect[]> GetScreenRectsAsync();

WtqRect GetScreenWithCursor();
Task<WtqRect> GetScreenWithCursorAsync();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Wtq.Services.Apps;
using Microsoft.Extensions.Hosting;

public sealed class WtqAppRepo : IWtqAppRepo
namespace Wtq.Services;

public sealed class WtqAppRepo : IHostedService, IWtqAppRepo
{
private readonly IWtqProcessFactory _procFactory;
private readonly IWtqProcessService _procService;
Expand Down Expand Up @@ -61,19 +63,6 @@ public WtqApp GetAppByNameRequired(string name)
?? throw new WtqException($"No instance found of type '{nameof(WtqApp)}' found with name '{name}'.");
}

public WtqAppOptions? GetOptionsByName(string name)
{
Guard.Against.NullOrWhiteSpace(name);

return _opts.CurrentValue.Apps.FirstOrDefault(o => o.Name?.Equals(name, StringComparison.OrdinalIgnoreCase) ?? false);
}

public WtqAppOptions GetOptionsByNameRequired(string name)
{
return GetOptionsByName(name)
?? throw new WtqException($"No instance found of type '{nameof(WtqAppOptions)}' found with name '{name}'.");
}

public async ValueTask DisposeAsync()
{
foreach (var app in Apps)
Expand All @@ -94,4 +83,27 @@ public WtqApp Create(WtqAppOptions app)
() => GetOptionsByNameRequired(app.Name),
app.Name);
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await UpdateAppsAsync().ConfigureAwait(false);
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

private WtqAppOptions? GetOptionsByName(string name)
{
Guard.Against.NullOrWhiteSpace(name);

return _opts.CurrentValue.Apps.FirstOrDefault(o => o.Name?.Equals(name, StringComparison.OrdinalIgnoreCase) ?? false);
}

private WtqAppOptions GetOptionsByNameRequired(string name)
{
return GetOptionsByName(name)
?? throw new WtqException($"No instance found of type '{nameof(WtqAppOptions)}' found with name '{name}'.");
}
}
18 changes: 9 additions & 9 deletions src/10-Core/Wtq/Services/WtqAppToggleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public async Task ToggleOnAsync(WtqApp app, ToggleModifiers mods)
Guard.Against.Null(app);

// Make sure the app has focus.
await app.BringToForegroundAsync();
await app.BringToForegroundAsync().NoCtx();

var durationMs = GetDurationMs(app, mods);
var screen = GetToggleOnToScreenRect(app);
var screen = await GetToggleOnToScreenRectAsync(app).NoCtx();
var to = GetToggleOnToWindowRect(app, screen);
var from = GetToggleOnFromWindowRect(to);

Expand Down Expand Up @@ -94,7 +94,7 @@ private WtqRect GetToggleOnFromWindowRect(WtqRect to)
/// Returns a rectangle representing the screen we want to toggle the terminal onto.
/// </summary>
/// <param name="app">The app for which we're figuring out the screen bounds.</param>
private WtqRect GetToggleOnToScreenRect(WtqApp app)
private async Task<WtqRect> GetToggleOnToScreenRectAsync(WtqApp app)
{
Guard.Against.Null(app);

Expand All @@ -105,7 +105,7 @@ private WtqRect GetToggleOnToScreenRect(WtqApp app)
{
case PreferMonitor.AtIndex:
{
var screens = _scrInfoProvider.GetScreenRects();
var screens = await _scrInfoProvider.GetScreenRectsAsync().NoCtx();

if (screens.Length > monInd)
{
Expand All @@ -118,14 +118,14 @@ private WtqRect GetToggleOnToScreenRect(WtqApp app)
monInd,
screens.Length);

return _scrInfoProvider.GetPrimaryScreenRect();
return await _scrInfoProvider.GetPrimaryScreenRectAsync().NoCtx();
}

case PreferMonitor.Primary:
return _scrInfoProvider.GetPrimaryScreenRect();
return await _scrInfoProvider.GetPrimaryScreenRectAsync().NoCtx();

case PreferMonitor.WithCursor:
return _scrInfoProvider.GetScreenWithCursor();
return await _scrInfoProvider.GetScreenWithCursorAsync().NoCtx();

default:
{
Expand All @@ -134,13 +134,13 @@ private WtqRect GetToggleOnToScreenRect(WtqApp app)
prefMon,
nameof(app.Options.PreferMonitor));

return _scrInfoProvider.GetPrimaryScreenRect();
return await _scrInfoProvider.GetPrimaryScreenRectAsync().NoCtx();
}
}
}

/// <summary>
/// Returns the target bounds of the specified <param name="app"/>, when its toggling onto the screen.
/// Returns the target bounds of the specified <paramref name="app"/>, within the specified <paramref name="screenBounds"/> when its toggling onto the screen.
/// </summary>
private WtqRect GetToggleOnToWindowRect(
WtqApp app,
Expand Down
Loading

0 comments on commit 9d03c3b

Please sign in to comment.