GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
feat: reduce amount of calls to set native focus (#390)
lars-berger12fd5b234133
diff --git a/GlazeWM.App.WindowManager/WmStartup.cs b/GlazeWM.App.WindowManager/WmStartup.csindex 5200efc3..78488316 100644--- a/GlazeWM.App.WindowManager/WmStartup.cs+++ b/GlazeWM.App.WindowManager/WmStartup.cs@@ -49,6 +49,7 @@ namespace GlazeWM.App.WindowManager// Populate initial monitors, windows, workspaces and user config._bus.Invoke(new PopulateInitialStateCommand());_bus.Invoke(new RedrawContainersCommand());+ _bus.Invoke(new SyncNativeFocusCommand());// Listen on registered keybindings._keybindingService.Start();@@ -75,22 +76,14 @@ namespace GlazeWM.App.WindowManager_systemTrayIcon = new SystemTrayIcon(systemTrayIconConfig);_systemTrayIcon.Show();- var nativeFocusReassigned = _bus.Events- .OfType<NativeFocusReassignedEvent>()- .Select((@event) => @event.FocusedContainer);-if (_userConfigService.FocusBorderConfig.Active.Enabled ||_userConfigService.FocusBorderConfig.Inactive.Enabled){- var focusChanged = _bus.Events- .OfType<FocusChangedEvent>()- .Select(@event => @event.FocusedContainer);-- focusChanged- .Merge(nativeFocusReassigned)- .Subscribe((container) =>- _bus.InvokeAsync(new SetActiveWindowBorderCommand(container as Window))- );+ _bus.Events.OfType<FocusChangedEvent>().Subscribe((@event) =>+ _bus.InvokeAsync(+ new SetActiveWindowBorderCommand(@event.FocusedContainer as Window)+ )+ );}// Hook mouse event for focus follows cursor.@@ -108,7 +101,11 @@ namespace GlazeWM.App.WindowManager.OfType<FocusedContainerMovedEvent>().Select(@event => @event.FocusedContainer);- focusedContainerMoved.Merge(nativeFocusReassigned)+ var nativeFocusSynced = _bus.Events+ .OfType<NativeFocusSyncedEvent>()+ .Select((@event) => @event.FocusedContainer);++ focusedContainerMoved.Merge(nativeFocusSynced).Where(container => container is Window).Subscribe((window) => _bus.InvokeAsync(new CenterCursorOnContainerCommand(window)));}diff --git a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.csindex 0929e8a9..772be35c 100644--- a/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs+++ b/GlazeWM.Bar/Components/WorkspacesComponentViewModel.cs@@ -78,6 +78,7 @@ namespace GlazeWM.Bar.Components@event is WorkspaceActivatedEventor WorkspaceDeactivatedEventor FocusChangedEvent+ or FocusedContainerMovedEvent);// Refresh contents of workspaces collection.diff --git a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.csindex fbce5937..a2df4969 100644--- a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs+++ b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs@@ -2,7 +2,6 @@ using System.Linq;using GlazeWM.Domain.Common.Commands;using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;-using GlazeWM.Domain.Containers.Events;using GlazeWM.Domain.Monitors;using GlazeWM.Domain.Monitors.Commands;using GlazeWM.Domain.UserConfigs.Commands;@@ -17,16 +16,20 @@ namespace GlazeWM.Domain.Common.CommandHandlersinternal sealed class PopulateInitialStateHandler : ICommandHandler<PopulateInitialStateCommand>{private readonly Bus _bus;+ private readonly ContainerService _containerService;private readonly MonitorService _monitorService;private readonly WindowService _windowService;private readonly WorkspaceService _workspaceService;- public PopulateInitialStateHandler(Bus bus,+ public PopulateInitialStateHandler(+ Bus bus,+ ContainerService containerService,MonitorService monitorService,WindowService windowService,WorkspaceService workspaceService){_bus = bus;+ _containerService = containerService;_monitorService = monitorService;_windowService = windowService;_workspaceService = workspaceService;@@ -58,8 +61,7 @@ namespace GlazeWM.Domain.Common.CommandHandlers_workspaceService.GetActiveWorkspaces().FirstOrDefault() as Container;_bus.Invoke(new SetFocusedDescendantCommand(containerToFocus));- _bus.Emit(new FocusChangedEvent(containerToFocus));- _bus.Invoke(new SetNativeFocusCommand(containerToFocus));+ _containerService.HasPendingFocusSync = true;return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Common/DomainEvent.cs b/GlazeWM.Domain/Common/DomainEvent.csindex a5291668..7eb80e45 100644--- a/GlazeWM.Domain/Common/DomainEvent.cs+++ b/GlazeWM.Domain/Common/DomainEvent.cs@@ -7,7 +7,7 @@ namespace GlazeWM.Domain.Commonpublic const string FocusedContainerMoved = "focused_container_moved";public const string MonitorAdded = "monitor_added";public const string MonitorRemoved = "monitor_removed";- public const string NativeFocusReassigned = "native_focus_reassigned";+ public const string NativeFocusSynced = "native_focus_synced";public const string TilingDirectionChanged = "tiling_direction_changed";public const string UserConfigReloaded = "user_config_reloaded";public const string WindowManaged = "window_managed";diff --git a/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.csindex 834d5570..0e79d752 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/FocusInDirectionHandler.cs@@ -34,7 +34,9 @@ namespace GlazeWM.Domain.Containers.CommandHandlersif (focusTarget is null || focusTarget == focusedContainer)return CommandResponse.Ok;- _bus.Invoke(new SetNativeFocusCommand(focusTarget));+ _bus.Invoke(new SetFocusedDescendantCommand(focusTarget));+ _containerService.HasPendingFocusSync = true;+return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Containers/CommandHandlers/SetNativeFocusHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/SyncNativeFocusHandler.cssimilarity index 51%rename from GlazeWM.Domain/Containers/CommandHandlers/SetNativeFocusHandler.csrename to GlazeWM.Domain/Containers/CommandHandlers/SyncNativeFocusHandler.csindex e8dbf9b8..26cff51a 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/SetNativeFocusHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/SyncNativeFocusHandler.cs@@ -8,22 +8,33 @@ using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Containers.CommandHandlers{- internal sealed class SetNativeFocusHandler : ICommandHandler<SetNativeFocusCommand>+ internal sealed class SyncNativeFocusHandler : ICommandHandler<SyncNativeFocusCommand>{private readonly Bus _bus;+ private readonly ContainerService _containerService;private readonly WindowService _windowService;- public SetNativeFocusHandler(Bus bus, WindowService windowService)+ public SyncNativeFocusHandler(+ Bus bus,+ ContainerService containerService,+ WindowService windowService){_bus = bus;+ _containerService = containerService;_windowService = windowService;}- public CommandResponse Handle(SetNativeFocusCommand command)+ public CommandResponse Handle(SyncNativeFocusCommand command){- var containerToFocus = command.ContainerToFocus;+ var hasPendingFocusSync = _containerService.HasPendingFocusSync;- var handleToFocus = containerToFocus switch+ if (!hasPendingFocusSync)+ return CommandResponse.Ok;++ // Container that the WM believes should have focus.+ var focusedContainer = _containerService.FocusedContainer;++ var handleToFocus = focusedContainer switch{Window window => window.Handle,Workspace => _windowService.DesktopWindowHandle,@@ -31,21 +42,12 @@ namespace GlazeWM.Domain.Containers.CommandHandlers};// Set focus to the given window handle. If the container is a normal window, then this- // will trigger `EVENT_SYSTEM_FOREGROUND` window event and its handler. This, in turn,- // calls `SetFocusedDescendantCommand`.+ // will trigger `EVENT_SYSTEM_FOREGROUND` window event and its handler.KeybdEvent(0, 0, 0, 0);SetForegroundWindow(handleToFocus);- _bus.Emit(new NativeFocusReassignedEvent(containerToFocus));-- // Setting focus to the desktop window does not emit `EVENT_SYSTEM_FOREGROUND` window event,- // so `SetFocusedDescendantCommand` has to be manually called.- // TODO: This is called twice unnecessarily when setting workspace focus on unmanage.- if (containerToFocus is Workspace)- {- _bus.Invoke(new SetFocusedDescendantCommand(containerToFocus));- _bus.Emit(new FocusChangedEvent(containerToFocus));- }+ _bus.Emit(new NativeFocusSyncedEvent(focusedContainer));+ _bus.Emit(new FocusChangedEvent(focusedContainer));return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs b/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.csindex 366c6b61..a0e18b3d 100644--- a/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs+++ b/GlazeWM.Domain/Containers/CommandHandlers/ToggleFocusModeHandler.cs@@ -34,7 +34,8 @@ namespace GlazeWM.Domain.Containers.CommandHandlersif (windowToFocus is null)return CommandResponse.Ok;- _bus.Invoke(new SetNativeFocusCommand(windowToFocus));+ _bus.Invoke(new SetFocusedDescendantCommand(windowToFocus));+ _containerService.HasPendingFocusSync = true;return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Containers/Commands/SetNativeFocusCommand.cs b/GlazeWM.Domain/Containers/Commands/SetNativeFocusCommand.csdeleted file mode 100644index d5a84789..00000000--- a/GlazeWM.Domain/Containers/Commands/SetNativeFocusCommand.cs+++ /dev/null@@ -1,14 +0,0 @@-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Containers.Commands-{- public class SetNativeFocusCommand : Command- {- public Container ContainerToFocus { get; }-- public SetNativeFocusCommand(Container containerToFocus)- {- ContainerToFocus = containerToFocus;- }- }-}diff --git a/GlazeWM.Domain/Containers/Commands/SyncNativeFocusCommand.cs b/GlazeWM.Domain/Containers/Commands/SyncNativeFocusCommand.csnew file mode 100644index 00000000..7f52faf9--- /dev/null+++ b/GlazeWM.Domain/Containers/Commands/SyncNativeFocusCommand.cs@@ -0,0 +1,8 @@+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Containers.Commands+{+ public class SyncNativeFocusCommand : Command+ {+ }+}diff --git a/GlazeWM.Domain/Containers/ContainerService.cs b/GlazeWM.Domain/Containers/ContainerService.csindex 6bbd7d32..e7b68ed0 100644--- a/GlazeWM.Domain/Containers/ContainerService.cs+++ b/GlazeWM.Domain/Containers/ContainerService.cs@@ -28,6 +28,11 @@ namespace GlazeWM.Domain.Containers/// </summary>public Container FocusedContainer => ContainerTree.LastFocusedDescendant;+ /// <summary>+ /// Whether native focus needs to be reassigned to `FocusedContainer`.+ /// </summary>+ public bool HasPendingFocusSync { get; set; }+/// <summary>/// Whether a tiling or floating container is currently focused./// </summary>diff --git a/GlazeWM.Domain/Containers/Events/NativeFocusReassignedEvent.cs b/GlazeWM.Domain/Containers/Events/NativeFocusReassignedEvent.csdeleted file mode 100644index 7c1795d0..00000000--- a/GlazeWM.Domain/Containers/Events/NativeFocusReassignedEvent.cs+++ /dev/null@@ -1,8 +0,0 @@-using GlazeWM.Domain.Common;-using GlazeWM.Infrastructure.Bussing;--namespace GlazeWM.Domain.Containers.Events-{- public record NativeFocusReassignedEvent(Container FocusedContainer)- : Event(DomainEvent.NativeFocusReassigned);-}diff --git a/GlazeWM.Domain/Containers/Events/NativeFocusSyncedEvent.cs b/GlazeWM.Domain/Containers/Events/NativeFocusSyncedEvent.csnew file mode 100644index 00000000..7c59f9c4--- /dev/null+++ b/GlazeWM.Domain/Containers/Events/NativeFocusSyncedEvent.cs@@ -0,0 +1,8 @@+using GlazeWM.Domain.Common;+using GlazeWM.Infrastructure.Bussing;++namespace GlazeWM.Domain.Containers.Events+{+ public record NativeFocusSyncedEvent(Container FocusedContainer)+ : Event(DomainEvent.NativeFocusSynced);+}diff --git a/GlazeWM.Domain/DependencyInjection.cs b/GlazeWM.Domain/DependencyInjection.csindex 293d0c60..2180e2eb 100644--- a/GlazeWM.Domain/DependencyInjection.cs+++ b/GlazeWM.Domain/DependencyInjection.cs@@ -52,7 +52,7 @@ namespace GlazeWM.Domainservices.AddSingleton<ICommandHandler<ReplaceContainerCommand>, ReplaceContainerHandler>();services.AddSingleton<ICommandHandler<ResizeContainerCommand>, ResizeContainerHandler>();services.AddSingleton<ICommandHandler<SetFocusedDescendantCommand>, SetFocusedDescendantHandler>();- services.AddSingleton<ICommandHandler<SetNativeFocusCommand>, SetNativeFocusHandler>();+ services.AddSingleton<ICommandHandler<SyncNativeFocusCommand>, SyncNativeFocusHandler>();services.AddSingleton<ICommandHandler<ToggleFocusModeCommand>, ToggleFocusModeHandler>();services.AddSingleton<ICommandHandler<AddMonitorCommand>, AddMonitorHandler>();services.AddSingleton<ICommandHandler<RefreshMonitorStateCommand>, RefreshMonitorStateHandler>();diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.csindex f2eb2de8..a6fc2f54 100644--- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs+++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs@@ -54,6 +54,7 @@ namespace GlazeWM.Domain.UserConfigs.CommandHandlers_bus.Invoke(new RunWithSubjectContainerCommand(commandStrings));_bus.Invoke(new RedrawContainersCommand());+ _bus.Invoke(new SyncNativeFocusCommand());}}catch (Exception e)diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.csindex 7e722f77..8c03d829 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs@@ -85,8 +85,8 @@ namespace GlazeWM.Domain.Windows.CommandHandlers_logger.LogWindowEvent("New window managed", window);_bus.Emit(new WindowManagedEvent(window));- // Set OS focus to the newly added window in case it's not already focused.- _bus.Invoke(new SetNativeFocusCommand(window));+ // OS focus should be set to the newly added window in case it's not already focused.+ _containerService.HasPendingFocusSync = true;return CommandResponse.Ok;}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.csindex 6b477b5e..220a1c62 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs@@ -128,9 +128,6 @@ namespace GlazeWM.Domain.Windows.CommandHandlers_bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, workspaceInDirection, true));else_bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, workspaceInDirection, 0, true));-- // Refresh state in bar of which workspace has focus.- _bus.Emit(new FocusChangedEvent(windowToMove));}private void ChangeWorkspaceTilingDirection(Window windowToMove, Direction direction)@@ -289,7 +286,6 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// Change the window's parent workspace._bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, workspaceInDirection, false));- _bus.Emit(new FocusChangedEvent(windowToMove));// Redrawing twice to fix weird WindowsOS dpi behaviourwindowToMove.HasPendingDpiAdjustment = true;diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.csindex a32463f3..ff8f555a 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs@@ -131,7 +131,6 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// Change the window's parent workspace._bus.Invoke(new MoveContainerWithinTreeCommand(windowToResize, targetWorkspace, false));- _bus.Emit(new FocusChangedEvent(windowToResize));windowToResize.HasPendingDpiAdjustment = true;}diff --git a/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.csindex ff88e2f7..5e2b56b1 100644--- a/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs+++ b/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs@@ -34,8 +34,9 @@ namespace GlazeWM.Domain.Windows.CommandHandlers// cause focus to briefly flicker to the OS focus target and then to the WM's focus// target.+ _bus.Invoke(new SetFocusedDescendantCommand(focusTarget));_containerService.PendingFocusContainer = focusTarget;- _bus.InvokeAsync(new SetNativeFocusCommand(focusTarget));+ _containerService.HasPendingFocusSync = true;_bus.Emit(new WindowUnmanagedEvent(window.Id, window.Handle));diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.csindex 2c318b51..63cc3857 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs@@ -47,6 +47,7 @@ namespace GlazeWM.Domain.Windows.EventHandlers// If window is in tree, detach the removed window from its parent._bus.Invoke(new UnmanageWindowCommand(window));_bus.Invoke(new RedrawContainersCommand());+ _bus.Invoke(new SyncNativeFocusCommand());}}}diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.csindex 5be8315c..02b891d7 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowFocusedHandler.cs@@ -4,11 +4,9 @@ using GlazeWM.Domain.Containers;using GlazeWM.Domain.Containers.Commands;using GlazeWM.Domain.Containers.Events;using GlazeWM.Domain.Workspaces;-using GlazeWM.Domain.Workspaces.Commands;using GlazeWM.Infrastructure.Bussing;using GlazeWM.Infrastructure.Common.Events;using Microsoft.Extensions.Logging;-using static GlazeWM.Infrastructure.WindowsApi.WindowsApiService;namespace GlazeWM.Domain.Windows.EventHandlers{@@ -61,7 +59,7 @@ namespace GlazeWM.Domain.Windows.EventHandlersreturn;}- _bus.InvokeAsync(new SetNativeFocusCommand(pendingFocusContainer));+ _bus.InvokeAsync(new SyncNativeFocusCommand());return;}@@ -71,8 +69,15 @@ namespace GlazeWM.Domain.Windows.EventHandlersif (window is null || window?.IsDisplayed == false)return;- _logger.LogWindowEvent("Window focused", window);+ _logger.LogWindowEvent("Native focus event", window);+ var focusedContainer = _containerService.FocusedContainer;++ // Focus is already set to the WM's focused container.+ if (window == focusedContainer)+ return;++ // Update the WM's focus state._bus.Invoke(new SetFocusedDescendantCommand(window));_bus.Emit(new FocusChangedEvent(window));}diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.csindex 47c36430..e7db591a 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs@@ -50,6 +50,7 @@ namespace GlazeWM.Domain.Windows.EventHandlers// Detach the hidden window from its parent._bus.Invoke(new UnmanageWindowCommand(window));_bus.Invoke(new RedrawContainersCommand());+ _bus.Invoke(new SyncNativeFocusCommand());}}}diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.csindex dfdb097c..75e4b02f 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMinimizedHandler.cs@@ -60,11 +60,13 @@ namespace GlazeWM.Domain.Windows.EventHandlers_bus.Invoke(new ReplaceContainerCommand(minimizedWindow, window.Parent, window.Index));- // Reassign focus to appropriate container.- _bus.InvokeAsync(new SetNativeFocusCommand(focusTarget));+ // Focus should be reassigned to appropriate container.+ _bus.Invoke(new SetFocusedDescendantCommand(focusTarget));+ _containerService.HasPendingFocusSync = true;_containerService.ContainersToRedraw.Add(workspace);_bus.Invoke(new RedrawContainersCommand());+ _bus.Invoke(new SyncNativeFocusCommand());}}}diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.csindex e300e124..410b1e9c 100644--- a/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs+++ b/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs@@ -38,6 +38,7 @@ namespace GlazeWM.Domain.Windows.EventHandlers_bus.Invoke(new ManageWindowCommand(@event.WindowHandle));_bus.Invoke(new RedrawContainersCommand());+ _bus.Invoke(new SyncNativeFocusCommand());}}}diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.csindex 8e5239ce..68070880 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs@@ -67,7 +67,7 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers: workspaceToFocus;_bus.Invoke(new SetFocusedDescendantCommand(containerToFocus));- _bus.Emit(new FocusChangedEvent(containerToFocus));+ _containerService.HasPendingFocusSync = true;// Display the workspace to switch focus to.if (focusedWorkspace.Parent == workspaceToFocus.Parent)@@ -76,8 +76,6 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers_containerService.ContainersToRedraw.Add(workspaceToFocus);}- _bus.Invoke(new SetNativeFocusCommand(containerToFocus));-// Get empty workspace to destroy (if any are found). Cannot destroy empty workspaces if// they're the only workspace on the monitor or are pending focus.var workspaceToDestroy = _workspaceServicediff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.csindex a5e74c22..a4ab961d 100644--- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs+++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs@@ -64,7 +64,7 @@ namespace GlazeWM.Domain.Workspaces.CommandHandlers// immediately afterwards and they should behave as if `focusTarget` is the focused// descendant._bus.Invoke(new SetFocusedDescendantCommand(focusTarget));- _bus.Invoke(new SetNativeFocusCommand(focusTarget));+ _containerService.HasPendingFocusSync = true;_containerService.ContainersToRedraw.Add(currentWorkspace);_containerService.ContainersToRedraw.Add(windowToMove);