Skip to content

Commit

Permalink
Fix #69: restore windows position is not always correct, since glass …
Browse files Browse the repository at this point in the history
…frame thickness is not constant.
  • Loading branch information
tom-englert committed Dec 16, 2023
1 parent 595f12c commit ad9a33a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/RegionToShare/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,26 @@ public static string Serialize(this RECT rect)
return $"{rect.Left}\t{rect.Top}\t{rect.Right}\t{rect.Bottom}";
}

public static void DeserializeFrom(this ref RECT rect, string value)
public static bool DeserializeFrom(this ref RECT rect, string value)
{
try
{
var parts = value.Split('\t').Select(int.Parse).ToArray();
if (parts.Length != 4)
return;
return false;

rect.Left = parts[0];
rect.Top = parts[1];
rect.Right = Math.Max(rect.Left + 200, parts[2]);
rect.Bottom = Math.Max(rect.Top + 200, parts[3]);
return true;
}
catch
{
// invalid, just go with input;
}

return false;
}

public static void DrawCursor(this Graphics graphics, RECT nativeRect)
Expand Down
10 changes: 7 additions & 3 deletions src/RegionToShare/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@ protected override void OnSourceInitialized(EventArgs e)
if (Keyboard.Modifiers != (ModifierKeys.Alt | ModifierKeys.Control))
{
var placement = _windowHandle.GetWindowPlacement();
placement.NormalPosition.DeserializeFrom(Settings.WindowPlacement);
_windowHandle.SetWindowPlacement(ref placement);
if (placement.NormalPosition.DeserializeFrom(Settings.WindowPlacement))
{
placement.NormalPosition += GlassFrameThickness;
_windowHandle.SetWindowPlacement(ref placement);
}
}
UpdateSizeAndPos();
Expand Down Expand Up @@ -290,7 +293,8 @@ protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);

Settings.WindowPlacement = _windowHandle.GetWindowPlacement().NormalPosition.Serialize();
var normalPosition = _windowHandle.GetWindowPlacement().NormalPosition - GlassFrameThickness;
Settings.WindowPlacement = normalPosition.Serialize();
Settings.Save();
}

Expand Down

0 comments on commit ad9a33a

Please sign in to comment.