mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Using background thread to retrieve the window details, this should speed up the time until the CaptureForm is shown.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1610 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
73cfc30d49
commit
6ecba18fae
2 changed files with 64 additions and 52 deletions
|
@ -230,6 +230,7 @@ namespace Greenshot.Forms {
|
|||
// Iterate over the found windows and check if the current location is inside a window
|
||||
Point cursorPosition = Cursor.Position;
|
||||
selectedCaptureWindow = null;
|
||||
lock (windows) {
|
||||
foreach (WindowDetails window in windows) {
|
||||
if (window.Contains(cursorPosition)) {
|
||||
// Only go over the children if we are in window mode
|
||||
|
@ -241,6 +242,7 @@ namespace Greenshot.Forms {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (selectedCaptureWindow != null && !selectedCaptureWindow.Equals(lastWindow)) {
|
||||
capture.CaptureDetails.Title = selectedCaptureWindow.Text;
|
||||
capture.CaptureDetails.AddMetaData("windowtitle", selectedCaptureWindow.Text);
|
||||
|
|
|
@ -25,15 +25,16 @@ using System.Drawing;
|
|||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Printing;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Greenshot.Configuration;
|
||||
using Greenshot.Drawing;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Helpers;
|
||||
using Greenshot.Plugin;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using GreenshotPlugin.Core;
|
||||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
using IniFile;
|
||||
|
||||
namespace Greenshot.Helpers {
|
||||
|
@ -133,7 +134,6 @@ namespace Greenshot.Helpers {
|
|||
/// Make Capture with specified destinations
|
||||
/// </summary>
|
||||
private void MakeCapture() {
|
||||
|
||||
// Experimental code
|
||||
if (screenCapture != null) {
|
||||
screenCapture.Stop();
|
||||
|
@ -141,14 +141,16 @@ namespace Greenshot.Helpers {
|
|||
return;
|
||||
}
|
||||
|
||||
LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1})", captureMode, captureMouseCursor));
|
||||
LOG.Debug(String.Format("Capturing with mode {0} and using Cursor {1}", captureMode, captureMouseCursor));
|
||||
capture.CaptureDetails.CaptureMode = captureMode;
|
||||
|
||||
// Get the windows details in a seperate thread
|
||||
PrepareForCaptureWithFeedback();
|
||||
|
||||
// Add destinations if no-one passed a handler
|
||||
if (capture.CaptureDetails.CaptureDestinations == null || capture.CaptureDetails.CaptureDestinations.Count == 0) {
|
||||
AddConfiguredDestination();
|
||||
}
|
||||
PrepareForCaptureWithFeedback();
|
||||
|
||||
// Workaround for proble with DPI retrieval, the FromHwnd activates the window...
|
||||
WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
|
||||
|
@ -302,6 +304,8 @@ namespace Greenshot.Helpers {
|
|||
/// </summary>
|
||||
private void PrepareForCaptureWithFeedback() {
|
||||
windows = new List<WindowDetails>();
|
||||
|
||||
Thread getWindowDetailsThread= new Thread (delegate() {
|
||||
// Start Enumeration of "active" windows
|
||||
foreach (WindowDetails window in WindowDetails.GetAllWindows()) {
|
||||
// Window should be visible and not ourselves
|
||||
|
@ -325,7 +329,9 @@ namespace Greenshot.Helpers {
|
|||
goLevelDeep = 20;
|
||||
}
|
||||
window.GetChildren(goLevelDeep);
|
||||
lock (windows) {
|
||||
windows.Add(window);
|
||||
}
|
||||
|
||||
// Get window rectangle as capture Element
|
||||
CaptureElement windowCaptureElement = new CaptureElement(windowRectangle);
|
||||
|
@ -340,10 +346,14 @@ namespace Greenshot.Helpers {
|
|||
} else {
|
||||
AddCaptureElementsForWindow(windowCaptureElement, window, goLevelDeep);
|
||||
}
|
||||
|
||||
}
|
||||
lock (windows) {
|
||||
windows = WindowDetails.SortByZOrder(IntPtr.Zero, windows);
|
||||
}
|
||||
});
|
||||
getWindowDetailsThread.IsBackground = true;
|
||||
getWindowDetailsThread.Start();
|
||||
}
|
||||
|
||||
private void AddCaptureElementsForWindow(ICaptureElement parentElement, WindowDetails parentWindow, int level) {
|
||||
foreach(WindowDetails childWindow in parentWindow.Children) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue