Skip to content

Commit

Permalink
Opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie committed Apr 18, 2024
1 parent 5b661b4 commit 74c3d3f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/10-Core/Wtq.Core/Configuration/WtqAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class WtqAppOptions
public AttachMode? AttachMode { get; set; }

// TODO: Use dict key?
[NotNull]
[Required]
public string? Name { get; set; }

Expand All @@ -33,6 +34,13 @@ public class WtqAppOptions
/// </summary>
public PreferMonitor? PreferMonitor { get; set; }

/// <summary>
/// <para>Make the window see-through (applies to the entire window, including the title bar).</para>
/// <para>0 (invisible) - 100 (opaque).</para>.
/// <para>Defaults to "100".</para>
/// </summary>
public int? Opacity { get; set; }

#region Sizes

public HorizontalAlign? HorizontalAlign { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions src/10-Core/Wtq.Core/Configuration/WtqOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ public sealed class WtqOptions
/// </summary>
public PreferMonitor PreferMonitor { get; set; } = PreferMonitor.WithCursor;

/// <summary>
/// <para>Make the window see-through (applies to the entire window, including the title bar).</para>
/// <para>0 (invisible) - 100 (opaque).</para>.
/// <para>Defaults to "100".</para>
/// </summary>
public int Opacity { get; set; } = 100;

public int GetOpacityForApp(WtqAppOptions opts)
{
Guard.Against.Null(opts, nameof(opts));

return opts.Opacity ?? Opacity;
}

#region Sizes

public HorizontalAlign HorizontalAlign { get; set; } = HorizontalAlign.Center;
Expand Down
15 changes: 12 additions & 3 deletions src/10-Core/Wtq.Core/Services/WtqApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ public sealed class WtqApp : IAsyncDisposable
{
private readonly ILogger _log = Log.For<WtqApp>();

private readonly IOptionsMonitor<WtqOptions> _opts;
private readonly IWtqProcessFactory _procFactory;
private readonly IWtqProcessService _procService;
private readonly IWtqAppToggleService _toggler;
private readonly Func<WtqAppOptions> _optionsAccessor;

public WtqApp(
IOptionsMonitor<WtqOptions> opts,
IWtqProcessFactory procFactory,
IWtqProcessService procService,
IWtqAppToggleService toggler,
Func<WtqAppOptions> optionsAccessor,
string name)
{
_opts = Guard.Against.Null(opts, nameof(opts));
_procFactory = procFactory ?? throw new ArgumentNullException(nameof(procFactory));
_procService = procService ?? throw new ArgumentNullException(nameof(procService));
_toggler = toggler ?? throw new ArgumentNullException(nameof(toggler));
//_appRepo = Guard.Against.Null(appRepo, nameof(appRepo));
_optionsAccessor = Guard.Against.Null(optionsAccessor, nameof(optionsAccessor));

Name = Guard.Against.NullOrWhiteSpace(name, nameof(name));
Expand All @@ -37,11 +39,14 @@ public WtqApp(

/// <summary>
/// Whether an active process is being tracked by this app instance.
/// TODO: Include check for whether the process has been killed etc.
/// </summary>
public bool IsActive => Process != null;

public Process? Process { get; set; }

// TODO: Track whether the app is currently open, has focus, etc.

public string? ProcessDescription => Process == null
? "<no process attached>"
: $"[{Process.Id}] {Process.ProcessName}";
Expand Down Expand Up @@ -98,8 +103,6 @@ public async ValueTask DisposeAsync()

_log.LogInformation("Restoring process '{Process}' to its original bounds of '{Bounds}'", ProcessDescription, bounds);

//_procService.MoveWindow(Process, bounds);

await OpenAsync(ToggleModifiers.Instant).ConfigureAwait(false);

_procService.SetTaskbarIconVisibility(Process, true);
Expand Down Expand Up @@ -193,6 +196,12 @@ public async Task UpdateAsync()

await AttachAsync(process).ConfigureAwait(false);
}

// Update opacity.
if (IsActive)
{
_procService.SetTransparency(Process, _opts.CurrentValue.GetOpacityForApp(Options));
}
}

public async Task AttachAsync(Process process)
Expand Down
1 change: 1 addition & 0 deletions src/10-Core/Wtq.Core/Services/WtqAppRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public WtqApp Create(WtqAppOptions app)
Guard.Against.Null(app, nameof(app));

return new WtqApp(
_opts,
_procFactory,
_procService,
_toggleService,
Expand Down

0 comments on commit 74c3d3f

Please sign in to comment.