Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

fix: issues with workspace toggle on refocus (#303)

s-v-o021ff2f1b493
diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs
index 9cff5b22..29740b31 100644
--- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs
+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs
@@ -6,12 +6,14 @@ using GlazeWM.Domain.Monitors;
using GlazeWM.Domain.UserConfigs;
using GlazeWM.Domain.Workspaces.Commands;
using GlazeWM.Infrastructure.Bussing;
+using Microsoft.Extensions.Logging;
namespace GlazeWM.Domain.Workspaces.CommandHandlers
{
internal sealed class FocusWorkspaceHandler : ICommandHandler<FocusWorkspaceCommand>
{
private readonly Bus _bus;
+ private readonly ILogger<FocusWorkspaceHandler> _logger;
private readonly ContainerService _containerService;
private readonly MonitorService _monitorService;
private readonly UserConfigService _userConfigService;
@@ -19,12 +21,14 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
public FocusWorkspaceHandler(
Bus bus,
+ ILogger<FocusWorkspaceHandler> logger,
ContainerService containerService,
MonitorService monitorService,
UserConfigService userConfigService,
WorkspaceService workspaceService)
{
_bus = bus;
+ _logger = logger;
_containerService = containerService;
_monitorService = monitorService;
_userConfigService = userConfigService;
@@ -33,28 +37,31 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers
public CommandResponse Handle(FocusWorkspaceCommand command)
{
- var workspaceName = command.WorkspaceName;
+ var workspaceName = "";
+ var focusedWorkspace = _workspaceService.GetFocusedWorkspace();
+ if (focusedWorkspace.Name == command.WorkspaceName)
+ {
+ if (!_userConfigService.GeneralConfig.ToggleWorkspaceOnRefocus || _workspaceService.MostRecentWorkspace == null)
+ return CommandResponse.Ok;
+ workspaceName = _workspaceService.MostRecentWorkspace.Name;
+ }
+ else
+ {
+ workspaceName = command.WorkspaceName;
+ }
// Get workspace to focus. If it's currently inactive, then activate it.
var workspaceToFocus = _workspaceService.GetActiveWorkspaceByName(workspaceName)
?? ActivateWorkspace(workspaceName);
- // Get the currently focused and displayed workspaces.
- var focusedWorkspace = _workspaceService.GetFocusedWorkspace();
var displayedWorkspace = (workspaceToFocus.Parent as Monitor).DisplayedWorkspace;
- if (focusedWorkspace == workspaceToFocus)
- {
- if (!_userConfigService.GeneralConfig.ToggleWorkspaceOnRefocus)
- return CommandResponse.Ok;
- workspaceToFocus = _workspaceService.MostRecentWorkspace;
- }
-
// Save currently focused workspace as recent for command "recent"
_workspaceService.MostRecentWorkspace = focusedWorkspace;
// Set focus to the last focused window in workspace. If the workspace has no descendant
// windows, then set focus to the workspace itself.
+ _logger.LogDebug("WorkspaceToFocus: {WorkspaceToFocusName}", workspaceToFocus.Name);
var containerToFocus = workspaceToFocus.HasChildren()
? workspaceToFocus.LastFocusedDescendant
: workspaceToFocus;