Beispiel #1
0
        public void RefreshThumbnails()
        {
            IntPtr  foregroundWindowHandle = DwmApiNativeMethods.GetForegroundWindow();
            Boolean hideAllThumbnails      = (this._configuration.HideThumbnailsOnLostFocus && this.IsNonClientWindowActive(foregroundWindowHandle)) || !DwmApiNativeMethods.DwmIsCompositionEnabled();

            this.DisableViewEvents();

            // Hide, show, resize and move
            foreach (KeyValuePair <IntPtr, IThumbnailView> entry in this._thumbnailViews)
            {
                IThumbnailView view = entry.Value;

                if (hideAllThumbnails || !view.IsEnabled)
                {
                    if (view.IsActive)
                    {
                        view.Hide();
                    }
                    continue;
                }

                if (this._configuration.HideActiveClientThumbnail && (view.Id == this._activeClientHandle))
                {
                    if (view.IsActive)
                    {
                        view.Hide();
                    }
                    continue;
                }

                if (!this._isHoverEffectActive)
                {
                    // No need to move Thumbnails while one of them is highlighted
                    view.ThumbnailLocation = this._configuration.GetThumbnailLocation(view.Title, this._activeClientTitle, view.ThumbnailLocation);
                    view.SetOpacity(this._configuration.ThumbnailsOpacity);
                    view.SetTopMost(this._configuration.ShowThumbnailsAlwaysOnTop);
                }

                view.IsOverlayEnabled = this._configuration.ShowThumbnailOverlays;

                if (!view.IsActive)
                {
                    view.Show();
                }
                else
                {
                    view.Refresh(false);
                }
            }

            this.EnableViewEvents();
        }
Beispiel #2
0
        private void UpdateThumbnailsList()
        {
            Process[]     clientProcesses = ThumbnailManager.GetClientProcesses();
            List <IntPtr> processHandles  = new List <IntPtr>(clientProcesses.Length);

            IntPtr foregroundWindowHandle = DwmApiNativeMethods.GetForegroundWindow();

            List <IThumbnailView> viewsAdded   = new List <IThumbnailView>();
            List <IThumbnailView> viewsUpdated = new List <IThumbnailView>();
            List <IThumbnailView> viewsRemoved = new List <IThumbnailView>();

            foreach (Process process in clientProcesses)
            {
                IntPtr processHandle = process.MainWindowHandle;
                string processTitle  = process.MainWindowTitle;
                processHandles.Add(processHandle);

                IThumbnailView view;
                this._thumbnailViews.TryGetValue(processHandle, out view);

                if ((view == null) && (processTitle != ""))
                {
                    view                  = this._thumbnailViewFactory.Create(processHandle, processTitle, this._configuration.ThumbnailSize);
                    view.IsEnabled        = true;
                    view.IsOverlayEnabled = this._configuration.ShowThumbnailOverlays;
                    view.SetSizeLimitations(this._configuration.ThumbnailMinimumSize, this._configuration.ThumbnailMaximumSize);
                    view.SetTopMost(this._configuration.ShowThumbnailsAlwaysOnTop);
                    view.SetFrames(this._configuration.ShowThumbnailFrames);
                    view.ThumbnailLocation = this._configuration.GetThumbnailLocation(processTitle, this._activeClientTitle, view.ThumbnailLocation);

                    view.ThumbnailResized   = this.ThumbnailViewResized;
                    view.ThumbnailMoved     = this.ThumbnailViewMoved;
                    view.ThumbnailFocused   = this.ThumbnailViewFocused;
                    view.ThumbnailLostFocus = this.ThumbnailViewLostFocus;
                    view.ThumbnailActivated = this.ThumbnailActivated;

                    view.RegisterHotkey(this._configuration.GetClientHotkey(processTitle));

                    this._thumbnailViews.Add(processHandle, view);

                    this.ApplyClientLayout(processHandle, processTitle);

                    viewsAdded.Add(view);
                }
                else if ((view != null) && (processTitle != view.Title))                 // update thumbnail title
                {
                    view.Title = processTitle;
                    view.RegisterHotkey(this._configuration.GetClientHotkey(processTitle));

                    this.ApplyClientLayout(processHandle, processTitle);

                    viewsUpdated.Add(view);
                }

                if (process.MainWindowHandle == foregroundWindowHandle)
                {
                    this._activeClientHandle = process.MainWindowHandle;
                    this._activeClientTitle  = process.MainWindowTitle;
                }
            }

            // Cleanup
            IList <IntPtr> obsoleteThumbnails = new List <IntPtr>();

            foreach (IntPtr processHandle in this._thumbnailViews.Keys)
            {
                if (!processHandles.Contains(processHandle))
                {
                    obsoleteThumbnails.Add(processHandle);
                }
            }

            foreach (IntPtr processHandle in obsoleteThumbnails)
            {
                IThumbnailView view = this._thumbnailViews[processHandle];

                this._thumbnailViews.Remove(processHandle);

                view.UnregisterHotkey();

                view.ThumbnailResized   = null;
                view.ThumbnailMoved     = null;
                view.ThumbnailFocused   = null;
                view.ThumbnailLostFocus = null;
                view.ThumbnailActivated = null;

                view.Close();

                viewsRemoved.Add(view);
            }

            this.ThumbnailsAdded?.Invoke(viewsAdded);
            this.ThumbnailsUpdated?.Invoke(viewsUpdated);
            this.ThumbnailsRemoved?.Invoke(viewsRemoved);
        }