From 736862662dbb5f3458ff14dd2cd636bdf3a8dbb8 Mon Sep 17 00:00:00 2001 From: blam Date: Sat, 9 Sep 2023 00:35:34 -0400 Subject: [PATCH 1/5] improve redraws --- .../PopulateInitialStateHandler.cs | 2 -- .../RefreshMonitorStateHandler.cs | 1 - .../RegisterKeybindingsHandler.cs | 25 +++++++++++-------- .../ReloadUserConfigHandler.cs | 1 - .../CommandHandlers/IgnoreWindowHandler.cs | 2 -- .../CommandHandlers/MoveWindowHandler.cs | 10 -------- .../CommandHandlers/SetFloatingHandler.cs | 1 - .../CommandHandlers/SetTilingHandler.cs | 2 -- .../WindowMovedOrResizedHandler.cs | 1 - .../CommandHandlers/FocusWorkspaceHandler.cs | 1 - .../MoveWindowToWorkspaceHandler.cs | 1 - .../MoveWorkspaceInDirectionHandler.cs | 2 -- 12 files changed, 15 insertions(+), 34 deletions(-) diff --git a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs index 3b32f5ee5..a9f93833f 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); 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..15faf615b 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; @@ -43,18 +44,22 @@ public CommandResponse Handle(RegisterKeybindingsCommand command) { Task.Run(() => { - try + lock (_bus.LockObj) { - // Avoid invoking keybinding if an ignored window currently has focus. - if (_windowService.IgnoredHandles.Contains(GetForegroundWindow())) - return; + try + { + // Avoid invoking keybinding if an ignored window currently has focus. + if (_windowService.IgnoredHandles.Contains(GetForegroundWindow())) + return; - _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); - } - catch (Exception e) - { - _bus.Invoke(new HandleFatalExceptionCommand(e)); - throw; + _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); + _bus.Invoke(new RedrawContainersCommand()); + } + catch (Exception e) + { + _bus.Invoke(new HandleFatalExceptionCommand(e)); + throw; + } } }); }); 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/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/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/EventHandlers/WindowMovedOrResizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs index f06322079..ef284593a 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs @@ -65,7 +65,6 @@ private void UpdateTilingWindow(TilingWindow window) if (hasNoResizableSiblings) { _containerService.ContainersToRedraw.Add(window); - _bus.Invoke(new RedrawContainersCommand()); return; } diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs index 29740b31e..97189d740 100644 --- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs +++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs @@ -72,7 +72,6 @@ public CommandResponse Handle(FocusWorkspaceCommand command) // Display the workspace to switch focus to. _containerService.ContainersToRedraw.Add(displayedWorkspace); _containerService.ContainersToRedraw.Add(workspaceToFocus); - _bus.Invoke(new RedrawContainersCommand()); _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; } From d2f40572032205c5c3252eead2981b4efbb01c97 Mon Sep 17 00:00:00 2001 From: blam Date: Sat, 9 Sep 2023 14:09:48 -0400 Subject: [PATCH 2/5] update --- GlazeWM.App.WindowManager/WmStartup.cs | 2 ++ .../CommandHandlers/PopulateInitialStateHandler.cs | 2 +- .../Windows/CommandHandlers/ManageWindowHandler.cs | 4 ---- .../CommandHandlers/ResizeWindowBordersHandler.cs | 1 - .../Windows/CommandHandlers/ResizeWindowHandler.cs | 6 ------ .../Windows/CommandHandlers/UnmanageWindowHandler.cs | 1 - GlazeWM.Domain/Windows/Commands/ManageWindowCommand.cs | 5 +---- .../Windows/EventHandlers/WindowDestroyedHandler.cs | 2 ++ .../Windows/EventHandlers/WindowHiddenHandler.cs | 2 ++ .../Windows/EventHandlers/WindowMovedOrResizedHandler.cs | 3 ++- .../Windows/EventHandlers/WindowShownHandler.cs | 2 ++ .../Workspaces/CommandHandlers/FocusWorkspaceHandler.cs | 9 ++++++--- 12 files changed, 18 insertions(+), 21 deletions(-) diff --git a/GlazeWM.App.WindowManager/WmStartup.cs b/GlazeWM.App.WindowManager/WmStartup.cs index 94291d37f..58038e874 100644 --- a/GlazeWM.App.WindowManager/WmStartup.cs +++ b/GlazeWM.App.WindowManager/WmStartup.cs @@ -112,6 +112,8 @@ public ExitCode Run() .Subscribe((window) => _bus.InvokeAsync(new CenterCursorOnContainerCommand(window))); } + _bus.Invoke(new RedrawContainersCommand()); + System.Windows.Forms.Application.Run(); return ExitCode.Success; } diff --git a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs index a9f93833f..fbce59374 100644 --- a/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs +++ b/GlazeWM.Domain/Common/CommandHandlers/PopulateInitialStateHandler.cs @@ -83,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/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/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..8568b7239 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); @@ -134,10 +132,6 @@ private void ResizeFloatingWindow(Window windowToResize, ResizeDimension dimensi // Change the window's parent workspace. _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()); } } } 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/WindowMovedOrResizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs index ef284593a..09d4df518 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs @@ -60,7 +60,7 @@ 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) { @@ -83,6 +83,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 97189d740..b84164095 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,8 +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); + if (focusedWorkspace.Parent as Monitor == workspaceToFocus.Parent as Monitor) + { + _containerService.ContainersToRedraw.Add(displayedWorkspace); + _containerService.ContainersToRedraw.Add(workspaceToFocus); + } _bus.Invoke(new SetNativeFocusCommand(containerToFocus)); From a327787c8cd901b528c0474602e08a8c6ec05be3 Mon Sep 17 00:00:00 2001 From: blam Date: Sat, 9 Sep 2023 14:15:06 -0400 Subject: [PATCH 3/5] forgot --- .../Windows/EventHandlers/WindowMovedOrResizedHandler.cs | 7 +++---- .../Workspaces/CommandHandlers/FocusWorkspaceHandler.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs index 09d4df518..b1e933ba5 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; @@ -59,8 +58,8 @@ public void Handle(WindowMovedOrResizedEvent @event) 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(); + var hasNoResizableSiblings = window.Parent is Workspace + && !window.SiblingsOfType().Any(); if (hasNoResizableSiblings) { diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs index b84164095..d70c4f96c 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; From f868025743d96b47f8f69bf28e1579921aa9ed1f Mon Sep 17 00:00:00 2001 From: blam Date: Sat, 9 Sep 2023 15:24:50 -0400 Subject: [PATCH 4/5] comments --- GlazeWM.App.WindowManager/WmStartup.cs | 3 +-- .../RegisterKeybindingsHandler.cs | 25 ++++++++----------- .../CommandHandlers/ResizeWindowHandler.cs | 2 ++ .../WindowLocationChangedHandler.cs | 2 ++ .../WindowMovedOrResizedHandler.cs | 2 +- .../CommandHandlers/FocusWorkspaceHandler.cs | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/GlazeWM.App.WindowManager/WmStartup.cs b/GlazeWM.App.WindowManager/WmStartup.cs index 58038e874..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(); @@ -112,8 +113,6 @@ public ExitCode Run() .Subscribe((window) => _bus.InvokeAsync(new CenterCursorOnContainerCommand(window))); } - _bus.Invoke(new RedrawContainersCommand()); - System.Windows.Forms.Application.Run(); return ExitCode.Success; } diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs index 15faf615b..be7137f54 100644 --- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs +++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs @@ -44,22 +44,19 @@ public CommandResponse Handle(RegisterKeybindingsCommand command) { Task.Run(() => { - lock (_bus.LockObj) + try { - try - { - // Avoid invoking keybinding if an ignored window currently has focus. - if (_windowService.IgnoredHandles.Contains(GetForegroundWindow())) - return; + // Avoid invoking keybinding if an ignored window currently has focus. + if (_windowService.IgnoredHandles.Contains(GetForegroundWindow())) + return; - _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); - _bus.Invoke(new RedrawContainersCommand()); - } - catch (Exception e) - { - _bus.Invoke(new HandleFatalExceptionCommand(e)); - throw; - } + _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); + _bus.Invoke(new RedrawContainersCommand()); + } + catch (Exception e) + { + _bus.Invoke(new HandleFatalExceptionCommand(e)); + throw; } }); }); diff --git a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs index 8568b7239..a32463f34 100644 --- a/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs +++ b/GlazeWM.Domain/Windows/CommandHandlers/ResizeWindowHandler.cs @@ -132,6 +132,8 @@ private void ResizeFloatingWindow(Window windowToResize, ResizeDimension dimensi // 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/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 b1e933ba5..5005ca384 100644 --- a/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs +++ b/GlazeWM.Domain/Windows/EventHandlers/WindowMovedOrResizedHandler.cs @@ -58,7 +58,7 @@ public void Handle(WindowMovedOrResizedEvent @event) private void UpdateTilingWindow(TilingWindow window) { // Snap window to its original position even if it's not being resized. - var hasNoResizableSiblings = window.Parent is Workspace + var hasNoResizableSiblings = window.Parent is Workspace && !window.SiblingsOfType().Any(); if (hasNoResizableSiblings) diff --git a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs index d70c4f96c..8e5239ce8 100644 --- a/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs +++ b/GlazeWM.Domain/Workspaces/CommandHandlers/FocusWorkspaceHandler.cs @@ -70,7 +70,7 @@ public CommandResponse Handle(FocusWorkspaceCommand command) _bus.Emit(new FocusChangedEvent(containerToFocus)); // Display the workspace to switch focus to. - if (focusedWorkspace.Parent as Monitor == workspaceToFocus.Parent as Monitor) + if (focusedWorkspace.Parent == workspaceToFocus.Parent) { _containerService.ContainersToRedraw.Add(displayedWorkspace); _containerService.ContainersToRedraw.Add(workspaceToFocus); From 31ca4a81b65d7e7c482a0f6a4fbe18a2b4e48d43 Mon Sep 17 00:00:00 2001 From: Lars Berger Date: Sun, 10 Sep 2023 18:02:50 +0800 Subject: [PATCH 5/5] actually a lock in `RegisterKeybindingsHandler` is probably needed --- .../CommandHandlers/RegisterKeybindingsHandler.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs index be7137f54..f2eb2de85 100644 --- a/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs +++ b/GlazeWM.Domain/UserConfigs/CommandHandlers/RegisterKeybindingsHandler.cs @@ -46,12 +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 RedrawContainersCommand()); + _bus.Invoke(new RunWithSubjectContainerCommand(commandStrings)); + _bus.Invoke(new RedrawContainersCommand()); + } } catch (Exception e) {