-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: multi threading issue when running many keybinding commands at once
- Loading branch information
1 parent
12614cf
commit 024f68a
Showing
8 changed files
with
112 additions
and
115 deletions.
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
GlazeWM.Domain/UserConfigs/CommandHandlers/RunWithSubjectContainerHandler.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,62 @@ | ||
using GlazeWM.Domain.Containers; | ||
using GlazeWM.Domain.Containers.Commands; | ||
using GlazeWM.Domain.UserConfigs.Commands; | ||
using GlazeWM.Domain.UserConfigs.Events; | ||
using GlazeWM.Domain.Windows; | ||
using GlazeWM.Domain.Windows.Commands; | ||
using GlazeWM.Domain.Workspaces.Commands; | ||
using GlazeWM.Infrastructure.Bussing; | ||
|
||
namespace GlazeWM.Domain.UserConfigs.CommandHandlers | ||
{ | ||
internal sealed class RunWithSubjectContainerHandler | ||
: ICommandHandler<RunWithSubjectContainerCommand> | ||
{ | ||
private readonly Bus _bus; | ||
private readonly CommandParsingService _commandParsingService; | ||
private readonly ContainerService _containerService; | ||
|
||
public RegisterKeybindingsHandler( | ||
Bus bus, | ||
CommandParsingService commandParsingService, | ||
ContainerService containerService) | ||
{ | ||
_bus = bus; | ||
_commandParsingService = commandParsingService; | ||
_containerService = containerService; | ||
} | ||
|
||
public CommandResponse Handle(RunWithSubjectContainerCommand command) | ||
{ | ||
var commandStrings = command.CommandStrings; | ||
var subjectContainer = | ||
command.SubjectContainer ?? _containerService.FocusedContainer; | ||
|
||
var subjectContainerId = subjectContainer.Id; | ||
|
||
// Invoke commands in sequence. | ||
foreach (var commandString in commandStrings) | ||
{ | ||
// Avoid calling command if container gets detached. This is to prevent crashes | ||
// for edge cases like ["close", "move to workspace X"]. | ||
if (subjectContainer?.IsDetached() != false) | ||
return; | ||
|
||
var parsedCommand = _commandParsingService.ParseCommand( | ||
commandString, | ||
subjectContainer | ||
); | ||
|
||
// Use `dynamic` to resolve the command type at runtime and allow multiple | ||
// dispatch. | ||
_bus.Invoke((dynamic)parsedCommand); | ||
|
||
// Update subject container in case the reference changes (eg. when going from a | ||
// tiling to a floating window). | ||
subjectContainer = _containerService.GetContainerById(subjectContainerId); | ||
} | ||
|
||
return CommandResponse.Ok; | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
GlazeWM.Domain/UserConfigs/Commands/RunWithSubjectContainerCommand.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,23 @@ | ||
using GlazeWM.Infrastructure.Bussing; | ||
|
||
namespace GlazeWM.Domain.UserConfigs.Commands | ||
{ | ||
public class RunWithSubjectContainerCommand : Command | ||
{ | ||
public List<string> CommandStrings { get; } | ||
public Container SubjectContainer { get; } | ||
|
||
public RunWithSubjectContainerCommand( | ||
List<string> commandStrings, | ||
Container subjectContainer) | ||
{ | ||
CommandStrings = commandStrings; | ||
SubjectContainer = subjectContainer; | ||
} | ||
|
||
public RunWithSubjectContainerCommand(List<string> commandStrings) | ||
{ | ||
CommandStrings = commandStrings; | ||
} | ||
} | ||
} |
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
57 changes: 0 additions & 57 deletions
57
GlazeWM.Domain/Windows/CommandHandlers/RunWindowRulesHandler.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.