These changes should fix some issues with losing focus before capturing. [skip ci]

This commit is contained in:
RKrom 2014-12-14 22:19:46 +01:00
parent ccd809d4ed
commit dda5b53976
2 changed files with 37 additions and 16 deletions

View file

@ -250,18 +250,6 @@ namespace Greenshot.Helpers {
AddConfiguredDestination(); AddConfiguredDestination();
} }
// Workaround for proble with DPI retrieval, the FromHwnd activates the window...
WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
// Workaround for changed DPI settings in Windows 7
using (Graphics graphics = Graphics.FromHwnd(MainForm.Instance.Handle)) {
_capture.CaptureDetails.DpiX = graphics.DpiX;
_capture.CaptureDetails.DpiY = graphics.DpiY;
}
if (previouslyActiveWindow != null) {
// Set previouslyActiveWindow as foreground window
previouslyActiveWindow.ToForeground();
}
// Delay for the Context menu // Delay for the Context menu
if (conf.CaptureDelay > 0) { if (conf.CaptureDelay > 0) {
Thread.Sleep(conf.CaptureDelay); Thread.Sleep(conf.CaptureDelay);
@ -283,6 +271,7 @@ namespace Greenshot.Helpers {
case CaptureMode.Window: case CaptureMode.Window:
_capture = WindowCapture.CaptureScreen(_capture); _capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "Screen"); _capture.CaptureDetails.AddMetaData("source", "Screen");
SetDPI();
CaptureWithFeedback(); CaptureWithFeedback();
break; break;
case CaptureMode.ActiveWindow: case CaptureMode.ActiveWindow:
@ -296,11 +285,13 @@ namespace Greenshot.Helpers {
_capture.CaptureDetails.AddMetaData("source", "Screen"); _capture.CaptureDetails.AddMetaData("source", "Screen");
_capture.CaptureDetails.Title = "Screen"; _capture.CaptureDetails.Title = "Screen";
} }
SetDPI();
HandleCapture(); HandleCapture();
break; break;
case CaptureMode.IE: case CaptureMode.IE:
if (IECaptureHelper.CaptureIE(_capture, SelectedCaptureWindow) != null) { if (IECaptureHelper.CaptureIE(_capture, SelectedCaptureWindow) != null) {
_capture.CaptureDetails.AddMetaData("source", "Internet Explorer"); _capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
SetDPI();
HandleCapture(); HandleCapture();
} }
break; break;
@ -331,6 +322,7 @@ namespace Greenshot.Helpers {
if (!captureTaken) { if (!captureTaken) {
_capture = WindowCapture.CaptureScreen(_capture); _capture = WindowCapture.CaptureScreen(_capture);
} }
SetDPI();
HandleCapture(); HandleCapture();
break; break;
case CaptureMode.Clipboard: case CaptureMode.Clipboard:
@ -424,6 +416,7 @@ namespace Greenshot.Helpers {
//capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y); //capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
_capture.CaptureDetails.AddMetaData("source", "screen"); _capture.CaptureDetails.AddMetaData("source", "screen");
SetDPI();
HandleCapture(); HandleCapture();
} }
break; break;
@ -432,10 +425,12 @@ namespace Greenshot.Helpers {
if (Rectangle.Empty.Equals(_captureRect)) { if (Rectangle.Empty.Equals(_captureRect)) {
_capture = WindowCapture.CaptureScreen(_capture); _capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "screen"); _capture.CaptureDetails.AddMetaData("source", "screen");
SetDPI();
CaptureWithFeedback(); CaptureWithFeedback();
} else { } else {
_capture = WindowCapture.CaptureRectangle(_capture, _captureRect); _capture = WindowCapture.CaptureRectangle(_capture, _captureRect);
_capture.CaptureDetails.AddMetaData("source", "screen"); _capture.CaptureDetails.AddMetaData("source", "screen");
SetDPI();
HandleCapture(); HandleCapture();
} }
break; break;
@ -943,6 +938,24 @@ namespace Greenshot.Helpers {
return captureForWindow; return captureForWindow;
} }
private void SetDPI() {
// Workaround for proble with DPI retrieval, the FromHwnd activates the window...
WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
// Workaround for changed DPI settings in Windows 7
using (Graphics graphics = Graphics.FromHwnd(MainForm.Instance.Handle)) {
_capture.CaptureDetails.DpiX = graphics.DpiX;
_capture.CaptureDetails.DpiY = graphics.DpiY;
}
if (previouslyActiveWindow != null) {
// Set previouslyActiveWindow as foreground window
previouslyActiveWindow.ToForeground();
}
if (_capture.CaptureDetails != null && _capture.Image != null) {
((Bitmap)_capture.Image).SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY);
}
}
#region capture with feedback #region capture with feedback
private void CaptureWithFeedback() { private void CaptureWithFeedback() {
// The following, to be precise the HideApp, causes the app to close as described in BUG-1620 // The following, to be precise the HideApp, causes the app to close as described in BUG-1620

View file

@ -589,12 +589,20 @@ namespace GreenshotPlugin.Core {
if (capture == null) { if (capture == null) {
capture = new Capture(); capture = new Capture();
} }
Image capturedImage = null;
// If the CaptureHandler has a handle use this, otherwise use the CaptureRectangle here // If the CaptureHandler has a handle use this, otherwise use the CaptureRectangle here
capture.Image = CaptureHandler.CaptureScreenRectangle != null ? CaptureHandler.CaptureScreenRectangle(captureBounds) : CaptureRectangle(captureBounds); if (CaptureHandler.CaptureScreenRectangle != null) {
capture.Location = captureBounds.Location; try {
if (capture.CaptureDetails != null) { capturedImage = CaptureHandler.CaptureScreenRectangle(captureBounds);
((Bitmap)capture.Image).SetResolution(capture.CaptureDetails.DpiX, capture.CaptureDetails.DpiY); } catch {
}
} }
// If no capture, use the normal screen capture
if (capturedImage == null) {
capturedImage = CaptureRectangle(captureBounds);
}
capture.Image = capturedImage;
capture.Location = captureBounds.Location;
return capture.Image == null ? null : capture; return capture.Image == null ? null : capture;
} }