Fix for issue #33: window position/size now restores correctly even when chrome is disabled on closing.

This commit is contained in:
Lorenz Cuno Klopfenstein 2012-11-27 03:33:09 +01:00
parent c73605d9ca
commit 1a6197d892
4 changed files with 32 additions and 17 deletions

View file

@ -96,10 +96,11 @@ namespace OnTopReplica {
ClientSize = new Size(newWidth, newHeight);
//Move form vertically to adapt to new size
if (Location.Y + Size.Height > workingArea.Y + workingArea.Height) {
//REMOVED: allows the window to correctly be restored slightly off screen
/*if (Location.Y + Size.Height > workingArea.Y + workingArea.Height) {
int offsetY = (workingArea.Y + workingArea.Height) - (Location.Y + Size.Height);
Location = new Point(Location.X, Location.Y - offsetY);
}
}*/
}
/// <summary>

View file

@ -60,7 +60,12 @@ namespace OnTopReplica {
//Enter GUI loop
Application.Run(_mainForm);
//HACK: re-enable chrome to fix position persistence (ideally, chrome status should be stored and restored - but this is not always possible)
if (!_mainForm.IsChromeVisible)
_mainForm.IsChromeVisible = true;
//Persist settings
System.Diagnostics.Trace.WriteLine(string.Format("Persisting {0} size {1} to settings.", _mainForm.Location, _mainForm.ClientSize));
Settings.Default.RestoreLastPosition = _mainForm.Location;
Settings.Default.RestoreLastSize = _mainForm.ClientSize;
Settings.Default.Save();

View file

@ -33,6 +33,8 @@ namespace OnTopReplica.StartupOptions {
if (Settings.Default.RestoreSizeAndPosition) {
options.StartLocation = Settings.Default.RestoreLastPosition;
options.StartSize = Settings.Default.RestoreLastSize;
System.Diagnostics.Trace.WriteLine(string.Format("Restoring window at {0} size {1}.", Settings.Default.RestoreLastPosition, Settings.Default.RestoreLastSize));
}
if (Settings.Default.RestoreLastWindow) {
@ -74,11 +76,11 @@ namespace OnTopReplica.StartupOptions {
})
.Add<Size>("position=", "Target {X,Y} of the OnTopReplica window.", s => {
options.StartLocation = new Point(s.Width, s.Height);
options.StartScreenPosition = null;
options.StartPositionLock = null;
})
.Add<ScreenPosition>("screenPosition=", "Resolution independent window position on current screen, with locking. Values: {TR|TL|C|BR|BL}.", pos => {
options.StartLocation = null;
options.StartScreenPosition = pos;
options.StartPositionLock = pos;
})
.Add<Rectangle>("r|region=", "Region {X,Y,W,H} of the cloned window.", region => {
options.Region = new ThumbnailRegion(region);

View file

@ -25,7 +25,7 @@ namespace OnTopReplica.StartupOptions {
public Point? StartLocation { get; set; }
public ScreenPosition? StartScreenPosition { get; set; }
public ScreenPosition? StartPositionLock { get; set; }
public Size? StartSize { get; set; }
@ -96,7 +96,7 @@ namespace OnTopReplica.StartupOptions {
form.IsChromeVisible = !DisableChrome;
form.Opacity = (double)Opacity / 255.0;
//Thumbnail cloning
//Seek handle for thumbnail cloning
WindowHandle handle = null;
if (WindowId.HasValue) {
handle = WindowHandle.FromHandle(WindowId.Value);
@ -119,23 +119,30 @@ namespace OnTopReplica.StartupOptions {
handle = seeker.Windows.FirstOrDefault();
}
//Set any found handle
if (handle != null) {
form.SetThumbnail(handle, Region);
//Position lock
if (StartPositionLock.HasValue) {
form.PositionLock = StartPositionLock.Value;
}
//Size
if (StartSize.HasValue) {
//Size and location start values
if (StartLocation.HasValue && StartSize.HasValue) {
form.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
form.Location = StartLocation.Value;
form.ClientSize = StartSize.Value;
}
//Position
if (StartLocation.HasValue) {
else if (StartLocation.HasValue) {
form.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultBounds;
form.Location = StartLocation.Value;
}
else if (StartScreenPosition.HasValue) {
form.PositionLock = StartScreenPosition.Value;
else if (StartSize.HasValue) {
form.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
form.ClientSize = StartSize.Value;
}
//Clone any found handle
if (handle != null) {
form.SetThumbnail(handle, Region);
}
//Other features