From 0e9b289bc8ded7e6fc7e84ac260c7e8a1800621a Mon Sep 17 00:00:00 2001 From: lars-berger Date: Thu, 25 Jan 2024 03:54:51 +0800 Subject: [PATCH] fix: crash when detaching monitor on display settings change (#519) --- GlazeWM.Domain/Containers/Container.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/GlazeWM.Domain/Containers/Container.cs b/GlazeWM.Domain/Containers/Container.cs index c9fe480b4..bf72b2486 100644 --- a/GlazeWM.Domain/Containers/Container.cs +++ b/GlazeWM.Domain/Containers/Container.cs @@ -41,14 +41,18 @@ public abstract class Container /// public int FocusIndex => this is RootContainer ? 0 : Parent.ChildFocusOrder.IndexOf(this); - public List SelfAndSiblings => Parent.Children; + public List SelfAndSiblings => + this is RootContainer ? new List() { this } : Parent.Children; - public IEnumerable Siblings => Parent.Children.Where(children => children != this); + public IEnumerable Siblings => + this is RootContainer + ? Array.Empty() + : Parent.Children.Where(children => children != this); /// /// Index of this container amongst its siblings. /// - public int Index => Parent.Children.IndexOf(this); + public int Index => this is RootContainer ? 0 : Parent.Children.IndexOf(this); /// /// Get the last focused descendant by traversing downwards.