Skip to content

Commit

Permalink
Merge branch 'main' into rename-floating-and-free-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
dalyIsaac committed Aug 2, 2024
2 parents 6b1192f + 54813b0 commit 964cd0c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void ProcessEvent_UntilCloaked(uint eventType, IContext ctx, IWindow wind
WindowProcessorResult result = processor.ProcessEvent(eventType, 0, 0, 0, 0);

// Then the event should be ignored
Assert.Equal(WindowProcessorResult.Ignore, result);
Assert.Equal(WindowProcessorResult.IgnoreAndLayout, result);
}

[Theory, AutoSubstituteData]
Expand Down Expand Up @@ -108,7 +108,7 @@ public void ShouldBeRemoved(IContext ctx, IWindow window)
WindowProcessorResult result = processor.ProcessEvent(PInvoke.EVENT_OBJECT_DESTROY, 0, 0, 0, 0);

// Then the processor should be removed
Assert.Equal(WindowProcessorResult.RemoveProcessor, result);
Assert.Equal(WindowProcessorResult.ProcessAndRemove, result);
}

[Theory, AutoSubstituteData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,19 @@ public void ShouldBeIgnored_ProcessorExists_RemoveProcessor(IContext ctx, IWindo
Assert.False(firstProcessorResult);
Assert.True(secondProcessorResult);
}

[Theory, AutoSubstituteData]
public void ShouldBeIgnored_LayoutAllActiveWorkspacesTransform(IContext ctx, IWindow window)
{
// Given a window which is a Firefox window
window.ProcessFileName.Returns("firefox.exe");
WindowProcessorManager sut = new(ctx);

// When ShouldBeIgnored is called with a ProcessAndRemove result
bool result = sut.ShouldBeIgnored(window, default, PInvoke.EVENT_OBJECT_LOCATIONCHANGE, 0, 0, 0, 0);

// Then the result should be true, and a LayoutAllActiveWorkspacesTransform should be dispatched
Assert.True(result);
ctx.Store.Received().Dispatch(Arg.Any<LayoutAllActiveWorkspacesTransform>());
}
}
30 changes: 22 additions & 8 deletions src/Whim/Store/WindowSector/Processors/FirefoxWindowProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ namespace Whim;
public class FirefoxWindowProcessor : IWindowProcessor
{
private readonly IContext _ctx;
private readonly int _startTime;
private bool _hasExceededStartTime;
private bool _hasSeenFirstCloaked;
private const int _maxStartupTimeMs = 5000;

/// <inheritdoc/>
public IWindow Window { get; }

private FirefoxWindowProcessor(IContext ctx, IWindow window)
{
_ctx = ctx;
_startTime = Environment.TickCount;
Window = window;

if (_ctx.Store.Pick(PickIsStartupWindow(Window.Handle)))
{
_hasExceededStartTime = true;
}
}

/// <summary>
Expand Down Expand Up @@ -69,30 +78,35 @@ private FirefoxWindowProcessor(IContext ctx, IWindow window)
uint dwmsEventTime
)
{
Logger.Debug($"Processing Firefox event 0x{eventType:X4}");

if (eventType == PInvoke.EVENT_OBJECT_DESTROY)
{
return WindowProcessorResult.RemoveProcessor;
return WindowProcessorResult.ProcessAndRemove;
}

if (_ctx.Store.Pick(PickIsStartupWindow(Window.Handle)))
if (_hasSeenFirstCloaked)
{
return WindowProcessorResult.Process;
}

if (_hasExceededStartTime || Environment.TickCount - _startTime > _maxStartupTimeMs)
{
Logger.Debug("Firefox has exceeded startup time, listening to all events");
_hasExceededStartTime = true;
return WindowProcessorResult.Process;
}

if (eventType == PInvoke.EVENT_OBJECT_CLOAKED)
{
if (!_hasSeenFirstCloaked)
{
Logger.Debug("Firefox has been cloaked for the first time, listening to all events");
_hasSeenFirstCloaked = true;
return WindowProcessorResult.Ignore;
}
}

if (!_hasSeenFirstCloaked)
{
return WindowProcessorResult.Ignore;
}

return WindowProcessorResult.Process;
return WindowProcessorResult.IgnoreAndLayout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ uint dwmsEventTime
);
switch (result)
{
case WindowProcessorResult.Process:
return false;
case WindowProcessorResult.Ignore:
return true;
case WindowProcessorResult.RemoveProcessor:
case WindowProcessorResult.IgnoreAndLayout:
_ctx.Store.Dispatch(new LayoutAllActiveWorkspacesTransform());
return true;
case WindowProcessorResult.Process:
return false;
case WindowProcessorResult.ProcessAndRemove:
_processors.Remove(window.Handle);
return false;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public enum WindowProcessorResult
/// </summary>
Ignore,

/// <summary>
/// The event should be ignored, and the active workspaces should be laid out.
/// </summary>
IgnoreAndLayout,

/// <summary>
/// The event should be processed.
/// </summary>
Expand All @@ -18,5 +23,5 @@ public enum WindowProcessorResult
/// <summary>
/// The event should be processed and the processor should be removed.
/// </summary>
RemoveProcessor
ProcessAndRemove
}

0 comments on commit 964cd0c

Please sign in to comment.