示例#1
0
        private void updateWindows()
        {
            this.tmpWindows = new List <WinSbS>();


            if (this.Is3DActive)
            {
                User32.EnumWindows(windowFound, 0);
            }

            int updateAllIndex = -1;

            int offsetLevel = 0;

            WinSbS taskBarWindow = null;

            WinSbS tmpWindow = this.tmpWindows.FirstOrDefault(w => w.SourceRect.IsMaximized());

            try
            {
                if (tmpWindow != null &&
                    Options.ExcludedApplications.Contains(Path.GetFileName(User32.GetFilePath(tmpWindow.Handle))))
                {
                    this.tmpWindows.Clear();
                }
            }
            catch (Exception e)
            {
            }


            for (int i = this.tmpWindows.Count - 1; i >= 0; --i)
            {
                tmpWindow = this.tmpWindows[i];

                if (i < this.tmpWindows.Count - 1)
                {
                    tmpWindow.Owner = this.tmpWindows[i + 1];
                }
                else
                {
                    tmpWindow.Owner = null;
                }


                if (tmpWindow.SourceRect.Left <= 0 && tmpWindow.SourceRect.Right >= Options.ScreenWidth)
                {
                    offsetLevel = 0;
                }
                else
                {
                    offsetLevel++;
                }
                tmpWindow.OffsetLevel = offsetLevel;

                int oldIndex = this.windows.FindIndex(w => w.Handle == tmpWindow.Handle);
                if (oldIndex < 0)
                {
                    tmpWindow.RegisterThumbs();
                }
                else
                {
                    tmpWindow.CopyThumbInstances(this.windows[oldIndex]);

                    if (updateAllIndex < 0 && this.windows[oldIndex].Owner?.Handle != tmpWindow.Owner?.Handle)
                    {
                        updateAllIndex = i;
                    }
                    else if (!this.windows[oldIndex].SourceRect.Equals(tmpWindow.SourceRect))
                    {
                        tmpWindow.UpdateThumbs();
                    }
                    this.windows.RemoveAt(oldIndex);
                }

                if (tmpWindow.SourceRect.Left <= 0 &&
                    tmpWindow.SourceRect.Right >= Options.ScreenWidth &&
                    tmpWindow.SourceRect.Bottom - tmpWindow.SourceRect.Top == Options.TaskBarHeight)
                {
                    taskBarWindow = tmpWindow;
                }
            }
            for (int i = 0; i < this.windows.Count; ++i)
            {
                this.windows[i].UnRegisterThumbs();
            }

            this.windows = this.tmpWindows;

            if (this.hasToUpdate)
            {
                updateAllIndex   = this.windows.Count - 1;
                this.hasToUpdate = false;
            }

            if (updateAllIndex > -1)
            {
                for (int i = updateAllIndex; i >= 0; --i)
                {
                    if (this.windows[i] != taskBarWindow)
                    {
                        this.windows[i].UpdateThumbs();
                    }
                }
            }

            taskBarWindow?.UpdateThumbs(true);
            this.cursorSbS.UpdateThumbs((this.windows.Any() ? this.windows.Max(w => w.OffsetLevel) : 0) + 1);
        }
        private void updateWindows()
        {
            this.tmpWindows = new List <WinSbS>();

            if (this.Is3DActive)
            {
                User32.EnumWindows(windowFound, 0);
            }

            int updateAllIndex = -1;

            int offsetLevel = 0;

            WinSbS taskBarWindow = null;

            WinSbS tmpWindow = this.tmpWindows.FirstOrDefault(w => w.SourceRect.IsMaximized());

            try
            {
                if (tmpWindow != null &&
                    Options.ExcludedApplications?.Contains(Path.GetFileName(User32.GetFilePath(tmpWindow.Handle))) == true)
                {
                    this.tmpWindows.Clear();
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{e}");
            }


            for (int i = this.tmpWindows.Count - 1; i >= 0; --i)
            {
                tmpWindow = this.tmpWindows[i];

                if (i < this.tmpWindows.Count - 1)
                {
                    tmpWindow.Owner = this.tmpWindows[i + 1];
                }
                else
                {
                    tmpWindow.Owner = null;
                }


                if (tmpWindow.SourceRect.Left <= Options.AreaSrcBounds.Left && tmpWindow.SourceRect.Right >= Options.AreaSrcBounds.Right)
                {
                    offsetLevel = 0;
                }
                else
                {
                    offsetLevel++;
                }
                tmpWindow.OffsetLevel = offsetLevel;

                int oldIndex = this.windows.FindIndex(w => w.Handle == tmpWindow.Handle);
                if (oldIndex < 0)
                {
                    App.Current.Dispatcher.Invoke(tmpWindow.RegisterThumbs);
                }
                else
                {
                    tmpWindow.CopyThumbInstances(this.windows[oldIndex]);

                    if (updateAllIndex < 0 && this.windows[oldIndex].Owner?.Handle != tmpWindow.Owner?.Handle)
                    {
                        updateAllIndex = i;
                    }
                    else if (!this.windows[oldIndex].SourceRect.Equals(tmpWindow.SourceRect))
                    {
                        tmpWindow.UpdateThumbs();
                    }
                    this.windows.RemoveAt(oldIndex);
                }

                if (tmpWindow.SourceRect.Left <= Options.ScreenSrcBounds.Left &&
                    tmpWindow.SourceRect.Right >= Options.ScreenSrcBounds.Right &&
                    tmpWindow.SourceRect.Bottom - tmpWindow.SourceRect.Top == Options.ScreenSrcBounds.Height - Options.ScreenSrcWorkspace.Height)
                {
                    taskBarWindow = tmpWindow;
                }
            }
            for (int i = 0; i < this.windows.Count; ++i)
            {
                App.Current.Dispatcher.Invoke(this.windows[i].UnRegisterThumbs);
            }

            this.windows = this.tmpWindows;

            if (this.isAboutOpened)
            {
                return;
            }


            if (this.hasToUpdate)
            {
                Options.ComputedVariables.UpdateVariables();
                updateAllIndex   = this.windows.Count - 1;
                this.hasToUpdate = false;
            }

            if (updateAllIndex > -1)
            {
                for (int i = updateAllIndex; i >= 0; --i)
                {
                    if (this.windows[i] != taskBarWindow)
                    {
                        this.windows[i].UpdateThumbs();
                    }
                }
            }

            taskBarWindow?.UpdateThumbs(true);
            this.cursorSbS.UpdateThumbs((this.windows.Any() ? this.windows.Max(w => w.OffsetLevel) : 0) + 1);
        }