diff --git a/GlazeWM.App.WindowManager/WmStartup.cs b/GlazeWM.App.WindowManager/WmStartup.cs index 94291d37f..5200efc3a 100644 --- a/GlazeWM.App.WindowManager/WmStartup.cs +++ b/GlazeWM.App.WindowManager/WmStartup.cs @@ -48,6 +48,7 @@ public ExitCode Run() // Populate initial monitors, windows, workspaces and user config. _bus.Invoke(new PopulateInitialStateCommand()); + _bus.Invoke(new RedrawContainersCommand()); // Listen on registered keybindings. _keybindingService.Start(); diff --git a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs index 3b32f5ee5..fbce59374 100644 --- a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs +++ b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs @@ -45,8 +45,6 @@ public CommandResponse Handle(PopulateInitialStateCommand command) if (_windowService.IsHandleAppBar(windowHandle)) _windowService.AppBarHandles.Add(windowHandle); - _bus.Invoke(new RedrawContainersCommand()); - // Get the originally focused window when the WM is started. var focusedWindow = _windowService.GetWindows().FirstOrDefault(window => window.Handle == focusedHandle); @@ -85,7 +83,7 @@ private void PopulateContainerTree() var targetMonitor = _monitorService.GetMonitorFromHandleLocation(windowHandle); var targetWorkspace = targetMonitor.DisplayedWorkspace; - _bus.Invoke(new ManageWindowCommand(windowHandle, targetWorkspace, false)); + _bus.Invoke(new ManageWindowCommand(windowHandle, targetWorkspace)); } } } diff --git a/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs b/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs index 8d66672cd..c15d59469 100644 --- a/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs +++ b/GlazeWM.Domain/Monitors/CommandHandlers/RefreshMonitorStateHandler.cs @@ -78,7 +78,6 @@ public CommandResponse Handle(RefreshMonitorStateCommand command) // Redraw full container tree. _containerService.ContainersToRedraw.Add(_containerService.ContainerTree); - _bus.Invoke(new RedrawContainersCommand()); return CommandResponse.Ok; } diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs index e41470a41..f2eb2de85 100644 --- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs +++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading.Tasks; +using GlazeWM.Domain.Containers.Commands; using GlazeWM.Domain.UserConfigs.Commands; using GlazeWM.Domain.Windows; using GlazeWM.Infrastructure.Bussing; @@ -45,11 +46,15 @@ public CommandResponse Handle(RegisterKeybindingsCommand command) { try { - // Avoid invoking keybinding if an ignored window currently has focus. - if (_windowService.IgnoredHandles.Contains(GetForegroundWindow())) - return; + lock (_bus.LockObj) + { + // Avoid invoking keybinding if an ignored window currently has focus. + if (_windowService.IgnoredHandles.Contains(GetForegroundWindow())) + return; - _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); + _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); + _bus.Invoke(new RedrawContainersCommand()); + } } catch (Exception e) { diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs index ba2858732..53a989cfb 100644 --- a/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs +++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/ReloadUserConfigHandler.cs @@ -49,7 +49,6 @@ public CommandResponse Handle(ReloadUserConfigCommand command) // Redraw full container tree. _containerService.ContainersToRedraw.Add(_containerService.ContainerTree); - _bus.Invoke(new RedrawContainersCommand()); _bus.Emit(new UserConfigReloadedEvent()); diff --git a/GlazeWM.Domain/Windows/CommandHandlers/IgnoreWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/IgnoreWindowHandler.cs index b9784974f..8399c5790 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/IgnoreWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/IgnoreWindowHandler.cs @@ -28,8 +28,6 @@ public CommandResponse Handle(IgnoreWindowCommand command) else _bus.Invoke(new DetachContainerCommand(windowToIgnore)); - _bus.Invoke(new RedrawContainersCommand()); - return CommandResponse.Ok; } } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs index 11e8721b5..7e722f77b 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/ManageWindowHandler.cs @@ -44,7 +44,6 @@ public ManageWindowHandler( public CommandResponse Handle(ManageWindowCommand command) { var windowHandle = command.WindowHandle; - var shouldRedraw = command.ShouldRedraw; // Attach the new window as first child of the target parent (if provided), otherwise, add as // a sibling of the focused container. @@ -83,9 +82,6 @@ public CommandResponse Handle(ManageWindowCommand command) if (window?.IsDetached() != false) return CommandResponse.Ok; - if (shouldRedraw) - _bus.Invoke(new RedrawContainersCommand()); - _logger.LogWindowEvent("New window managed", window); _bus.Emit(new WindowManagedEvent(window)); diff --git a/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs index bc6f19f9f..6b477b5ea 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/MoveWindowHandler.cs @@ -85,7 +85,6 @@ private void SwapSiblingContainers(Window windowToMove, Direction direction) ) ); - _bus.Invoke(new RedrawContainersCommand()); return; } @@ -105,8 +104,6 @@ private void SwapSiblingContainers(Window windowToMove, Direction direction) _bus.Invoke( new MoveContainerWithinTreeCommand(windowToMove, targetParent, insertionIndex, true) ); - - _bus.Invoke(new RedrawContainersCommand()); } private void MoveToWorkspaceInDirection(Window windowToMove, Direction direction) @@ -132,8 +129,6 @@ private void MoveToWorkspaceInDirection(Window windowToMove, Direction direction else _bus.Invoke(new MoveContainerWithinTreeCommand(windowToMove, workspaceInDirection, 0, true)); - _bus.Invoke(new RedrawContainersCommand()); - // Refresh state in bar of which workspace has focus. _bus.Emit(new FocusChangedEvent(windowToMove)); } @@ -147,8 +142,6 @@ private void ChangeWorkspaceTilingDirection(Window windowToMove, Direction direc // TODO: Should probably descend into sibling if possible. if (HasSiblingInDirection(windowToMove, direction)) SwapSiblingContainers(windowToMove, direction); - - _bus.Invoke(new RedrawContainersCommand()); } private void InsertIntoAncestor( @@ -201,8 +194,6 @@ private void InsertIntoAncestor( ) ); } - - _bus.Invoke(new RedrawContainersCommand()); } private void MoveTilingWindow(TilingWindow windowToMove, Direction direction) @@ -307,7 +298,6 @@ private void MoveFloatingWindow(Window windowToMove, Direction direction) windowToMove.FloatingPlacement = newPlacement; _containerService.ContainersToRedraw.Add(windowToMove); - _bus.Invoke(new RedrawContainersCommand()); } } } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs index 50b340f70..3fe452d68 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowBordersHandler.cs @@ -37,7 +37,6 @@ public CommandResponse Handle(ResizeWindowBordersCommand command) return CommandResponse.Ok; _containerService.ContainersToRedraw.Add(windowToResize); - _bus.Invoke(new RedrawContainersCommand()); return CommandResponse.Ok; } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs index 60c564c98..a32463f34 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs @@ -59,7 +59,6 @@ public CommandResponse Handle(ResizeWindowCommand command) // TODO: Return early if `clampedResizePercentage` is 0 to avoid unnecessary redraws. _containerService.ContainersToRedraw.Add(containerToResize.Parent); - _bus.Invoke(new RedrawContainersCommand()); return CommandResponse.Ok; } @@ -116,7 +115,6 @@ private void ResizeFloatingWindow(Window windowToResize, ResizeDimension dimensi windowToResize.FloatingPlacement = Rect.FromXYCoordinates(windowToResize.FloatingPlacement.X, windowToResize.FloatingPlacement.Y, width, height); _containerService.ContainersToRedraw.Add(windowToResize); - _bus.Invoke(new RedrawContainersCommand()); // Check if window now takes up more of another screen after moving var currentWorkspace = WorkspaceService.GetWorkspaceFromChildContainer(windowToResize); @@ -135,9 +133,7 @@ private void ResizeFloatingWindow(Window windowToResize, ResizeDimension dimensi _bus.Invoke(new MoveContainerWithinTreeCommand(windowToResize, targetWorkspace, false)); _bus.Emit(new FocusChangedEvent(windowToResize)); - // Redrawing again to fix weird WindowsOS dpi change behaviour - _containerService.ContainersToRedraw.Add(windowToResize); - _bus.Invoke(new RedrawContainersCommand()); + windowToResize.HasPendingDpiAdjustment = true; } } } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs index 3c4bcf377..929973d81 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/SetFloatingHandler.cs @@ -41,7 +41,6 @@ public CommandResponse Handle(SetFloatingCommand command) }; _bus.Invoke(new ReplaceContainerCommand(floatingWindow, window.Parent, window.Index)); - _bus.Invoke(new RedrawContainersCommand()); return CommandResponse.Ok; } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs index 8ef607532..60e4d6235 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/SetTilingHandler.cs @@ -53,8 +53,6 @@ public CommandResponse Handle(SetTilingCommand command) ) ); - _bus.Invoke(new RedrawContainersCommand()); - return CommandResponse.Ok; } } diff --git a/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs index 0f7632636..ff88e2f77 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/UnmanageWindowHandler.cs @@ -34,7 +34,6 @@ public CommandResponse Handle(UnmanageWindowCommand command) // cause focus to briefly flicker to the OS focus target and then to the WM's focus // target. - _bus.Invoke(new RedrawContainersCommand()); _containerService.PendingFocusContainer = focusTarget; _bus.InvokeAsync(new SetNativeFocusCommand(focusTarget)); diff --git a/GlazeWM.Domain/Windows/Commands/ManageWindowCommand.cs b/GlazeWM.Domain/Windows/Commands/ManageWindowCommand.cs index a25c58db1..263f1eb45 100644 --- a/GlazeWM.Domain/Windows/Commands/ManageWindowCommand.cs +++ b/GlazeWM.Domain/Windows/Commands/ManageWindowCommand.cs @@ -8,16 +8,13 @@ public class ManageWindowCommand : Command { public IntPtr WindowHandle { get; } public SplitContainer TargetParent { get; } - public bool ShouldRedraw { get; } public ManageWindowCommand( IntPtr windowHandle, - SplitContainer targetParent = null, - bool shouldRedraw = true) + SplitContainer targetParent = null) { WindowHandle = windowHandle; TargetParent = targetParent; - ShouldRedraw = shouldRedraw; } } } diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs index 1ab211236..2c318b517 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowDestroyedHandler.cs @@ -1,5 +1,6 @@ using System.Linq; using GlazeWM.Domain.Common.Utils; +using GlazeWM.Domain.Containers.Commands; using GlazeWM.Domain.Monitors.Commands; using GlazeWM.Domain.Windows.Commands; using GlazeWM.Infrastructure.Bussing; @@ -45,6 +46,7 @@ public void Handle(WindowDestroyedEvent @event) // If window is in tree, detach the removed window from its parent. _bus.Invoke(new UnmanageWindowCommand(window)); + _bus.Invoke(new RedrawContainersCommand()); } } } diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs index 439b3803b..47c36430c 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowHiddenHandler.cs @@ -1,5 +1,6 @@ using System.Linq; using GlazeWM.Domain.Common.Utils; +using GlazeWM.Domain.Containers.Commands; using GlazeWM.Domain.Monitors.Commands; using GlazeWM.Domain.Windows.Commands; using GlazeWM.Infrastructure.Bussing; @@ -48,6 +49,7 @@ public void Handle(WindowHiddenEvent @event) // Detach the hidden window from its parent. _bus.Invoke(new UnmanageWindowCommand(window)); + _bus.Invoke(new RedrawContainersCommand()); } } } diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs index ed661fa28..f0d52ee83 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowLocationChangedHandler.cs @@ -1,3 +1,4 @@ +using GlazeWM.Domain.Containers.Commands; using GlazeWM.Domain.Monitors.Commands; using GlazeWM.Infrastructure.Bussing; using GlazeWM.Infrastructure.Common.Events; @@ -23,6 +24,7 @@ public void Handle(WindowLocationChangedEvent @event) return; _bus.Invoke(new RefreshMonitorStateCommand()); + _bus.Invoke(new RedrawContainersCommand()); } } } diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs index f06322079..5005ca384 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs @@ -38,8 +38,7 @@ public WindowMovedOrResizedHandler( public void Handle(WindowMovedOrResizedEvent @event) { - var window = _windowService.GetWindows() - .FirstOrDefault(window => window.Handle == @event.WindowHandle); + var window = _windowService.GetWindows().FirstOrDefault(window => window.Handle == @event.WindowHandle); if (window is null) return; @@ -60,12 +59,11 @@ private void UpdateTilingWindow(TilingWindow window) { // Snap window to its original position even if it's not being resized. var hasNoResizableSiblings = window.Parent is Workspace - && !window.SiblingsOfType().Any(); + && !window.SiblingsOfType().Any(); if (hasNoResizableSiblings) { _containerService.ContainersToRedraw.Add(window); - _bus.Invoke(new RedrawContainersCommand()); return; } @@ -84,6 +82,7 @@ private void UpdateTilingWindow(TilingWindow window) _bus.Invoke(new ResizeWindowCommand(window, ResizeDimension.Width, $"{deltaWidth}px")); _bus.Invoke(new ResizeWindowCommand(window, ResizeDimension.Height, $"{deltaHeight}px")); + _bus.Invoke(new RedrawContainersCommand()); } private void UpdateFloatingWindow(FloatingWindow window) diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs index 50e704434..e300e1243 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowShownHandler.cs @@ -1,4 +1,5 @@ using System.Linq; +using GlazeWM.Domain.Containers.Commands; using GlazeWM.Domain.Monitors.Commands; using GlazeWM.Domain.Windows.Commands; using GlazeWM.Infrastructure.Bussing; @@ -36,6 +37,7 @@ public void Handle(WindowShownEvent @event) return; _bus.Invoke(new ManageWindowCommand(@event.WindowHandle)); + _bus.Invoke(new RedrawContainersCommand()); } } } diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs index 29740b31e..8e5239ce8 100644 --- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs +++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs @@ -52,7 +52,7 @@ public CommandResponse Handle(FocusWorkspaceCommand command) // Get workspace to focus. If it's currently inactive, then activate it. var workspaceToFocus = _workspaceService.GetActiveWorkspaceByName(workspaceName) - ?? ActivateWorkspace(workspaceName); + ?? ActivateWorkspace(workspaceName); var displayedWorkspace = (workspaceToFocus.Parent as Monitor).DisplayedWorkspace; @@ -70,9 +70,11 @@ public CommandResponse Handle(FocusWorkspaceCommand command) _bus.Emit(new FocusChangedEvent(containerToFocus)); // Display the workspace to switch focus to. - _containerService.ContainersToRedraw.Add(displayedWorkspace); - _containerService.ContainersToRedraw.Add(workspaceToFocus); - _bus.Invoke(new RedrawContainersCommand()); + if (focusedWorkspace.Parent == workspaceToFocus.Parent) + { + _containerService.ContainersToRedraw.Add(displayedWorkspace); + _containerService.ContainersToRedraw.Add(workspaceToFocus); + } _bus.Invoke(new SetNativeFocusCommand(containerToFocus)); diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs index 8ff474f89..a5e74c229 100644 --- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs +++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWindowToWorkspaceHandler.cs @@ -68,7 +68,6 @@ public CommandResponse Handle(MoveWindowToWorkspaceCommand command) _containerService.ContainersToRedraw.Add(currentWorkspace); _containerService.ContainersToRedraw.Add(windowToMove); - _bus.Invoke(new RedrawContainersCommand()); return CommandResponse.Ok; } diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWorkspaceInDirectionHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWorkspaceInDirectionHandler.cs index 4cef0130b..0f5cd52df 100644 --- a/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWorkspaceInDirectionHandler.cs +++ b/GlazeWM.Domain/Workspaces/CommandHandlers/MoveWorkspaceInDirectionHandler.cs @@ -64,8 +64,6 @@ public CommandResponse Handle(MoveWorkspaceInDirectionCommand command) // TODO: Consider creating separate event `WorkspaceMovedEvent`. _bus.Emit(new WorkspaceActivatedEvent(focusedWorkspace)); - _bus.Invoke(new RedrawContainersCommand()); - return CommandResponse.Ok; }