private void UpdateClientLayouts() { Process[] clientProcesses = ThumbnailManager.GetClientProcesses(); foreach (Process process in clientProcesses) { RECT rect; DwmApiNativeMethods.GetWindowRect(process.MainWindowHandle, out rect); int left = Math.Abs(rect.Left); int right = Math.Abs(rect.Right); int clientWidth = Math.Abs(left - right); int top = Math.Abs(rect.Top); int bottom = Math.Abs(rect.Bottom); int clientHeight = Math.Abs(top - bottom); ClientLayout clientLayout = new ClientLayout(); clientLayout.X = rect.Left; clientLayout.Y = rect.Top; clientLayout.Width = clientWidth; clientLayout.Height = clientHeight; this._configuration.SetClientLayout(process.MainWindowTitle, clientLayout); } }
private void ThumbnailActivated(IntPtr id) { DwmApiNativeMethods.SetForegroundWindow(id); int style = DwmApiNativeMethods.GetWindowLong(id, DwmApiNativeMethods.GWL_STYLE); // If the window was minimized then its thumbnail should be reset if ((style & DwmApiNativeMethods.WS_MINIMIZE) == DwmApiNativeMethods.WS_MINIMIZE) { DwmApiNativeMethods.ShowWindowAsync(id, DwmApiNativeMethods.SW_SHOWNORMAL); IThumbnailView view; if (this._thumbnailViews.TryGetValue(id, out view)) { view.Refresh(true); } } if (this._configuration.EnableClientLayoutTracking) { this.UpdateClientLayouts(); } this.RefreshThumbnails(); this._configurationStorage.Save(); }
public void Register(IntPtr destination, IntPtr source) { this._properties = new DWM_THUMBNAIL_PROPERTIES(); this._properties.dwFlags = DWM_TNP_CONSTANTS.DWM_TNP_VISIBLE + DWM_TNP_CONSTANTS.DWM_TNP_OPACITY + DWM_TNP_CONSTANTS.DWM_TNP_RECTDESTINATION + DWM_TNP_CONSTANTS.DWM_TNP_SOURCECLIENTAREAONLY; this._properties.opacity = 255; this._properties.fVisible = true; this._properties.fSourceClientAreaOnly = true; if (!this._windowManager.IsCompositionEnabled) { return; } try { this._handle = DwmApiNativeMethods.DwmRegisterThumbnail(destination, source); } catch (ArgumentException) { // This exception is raised if the source client is already closed // Can happen on a really slow CPU's that the window is still being // lised in the process list yet it already cannot be used as // a thumbnail source this._handle = IntPtr.Zero; } }
private void UnregisterThumbnail(IntPtr thumbnailHandle) { try { DwmApiNativeMethods.DwmUnregisterThumbnail(thumbnailHandle); } catch (ArgumentException) { } }
private void ApplyClientLayout(IntPtr clientHandle, string clientTitle) { ClientLayout clientLayout = this._configuration.GetClientLayout(clientTitle); if (clientLayout == null) { return; } DwmApiNativeMethods.MoveWindow(clientHandle, clientLayout.X, clientLayout.Y, clientLayout.Width, clientLayout.Height, true); }
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(); }
private void RegisterThumbnail() { this._thumbnailHandle = DwmApiNativeMethods.DwmRegisterThumbnail(this.Handle, this.Id); this._thumbnail = new DWM_THUMBNAIL_PROPERTIES(); this._thumbnail.dwFlags = DWM_TNP_CONSTANTS.DWM_TNP_VISIBLE + DWM_TNP_CONSTANTS.DWM_TNP_OPACITY + DWM_TNP_CONSTANTS.DWM_TNP_RECTDESTINATION + DWM_TNP_CONSTANTS.DWM_TNP_SOURCECLIENTAREAONLY; this._thumbnail.opacity = 255; this._thumbnail.fVisible = true; this._thumbnail.fSourceClientAreaOnly = true; this._isThumbnailSetUp = true; }
public void Unregister() { if ((!this._windowManager.IsCompositionEnabled) || (this._handle == IntPtr.Zero)) { return; } try { DwmApiNativeMethods.DwmUnregisterThumbnail(this._handle); } catch (ArgumentException) { } }
public void Update() { if ((!this._windowManager.IsCompositionEnabled) || (this._handle == IntPtr.Zero)) { return; } try { DwmApiNativeMethods.DwmUpdateThumbnailProperties(this._handle, this._properties); } catch (ArgumentException) { //This exception will be thrown if the EVE client disappears while this method is running } }
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); }
public void Refresh(bool forceRefresh) { // To prevent flickering the old broken thumbnail is removed AFTER the new shiny one is created IntPtr obsoleteThumbnailHanlde = forceRefresh ? this._thumbnailHandle : IntPtr.Zero; if ((this._isThumbnailSetUp == false) || forceRefresh) { this.RegisterThumbnail(); } bool sizeChanged = this._isSizeChanged || forceRefresh; bool locationChanged = this._isPositionChanged || forceRefresh; if (sizeChanged) { this._thumbnail.rcDestination = new RECT(0, 0, this.ClientSize.Width, this.ClientSize.Height); try { DwmApiNativeMethods.DwmUpdateThumbnailProperties(this._thumbnailHandle, this._thumbnail); } catch (ArgumentException) { //This exception will be thrown if the EVE client disappears while this method is running } this._isSizeChanged = false; } if (obsoleteThumbnailHanlde != IntPtr.Zero) { this.UnregisterThumbnail(obsoleteThumbnailHanlde); } if (!this.IsOverlayEnabled) { if (this._isOverlayVisible) { this._overlay.Hide(); this._isOverlayVisible = false; } return; } if (!this._isOverlayVisible) { this._overlay.Show(); this._isOverlayVisible = true; } else if (!(sizeChanged || locationChanged)) { // No need to adjust in the overlay location if it is already visible and properly set return; } Size overlaySize = this.ClientSize; overlaySize.Width -= 2 * 5; overlaySize.Height -= 2 * 5; Point overlayLocation = this.Location; overlayLocation.X += 5 + (this.Size.Width - this.ClientSize.Width) / 2; overlayLocation.Y += 5 + (this.Size.Height - this.ClientSize.Height) - (this.Size.Width - this.ClientSize.Width) / 2; this._isPositionChanged = false; this._overlay.Size = overlaySize; this._overlay.Location = overlayLocation; }
public WindowManager() { this.IsCompositionEnabled = DwmApiNativeMethods.DwmIsCompositionEnabled(); }