Skip to content

Commit fdc76e3

Browse files
committedNov 1, 2018
fix: Incorrect v-position for parent centered windows
If a user had a secondary monitor above the primary monitor, and the main windows was opened on the secondary monitor, child windows that persist their locations would get opened on the primary monitor. The fix places new windows at the center of their parent.
1 parent bb451e0 commit fdc76e3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed
 

‎GitUI/GitExtensionsForm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected virtual void RestorePosition()
139139
// Calculate location for modal form with parent
140140
Location = new Point(
141141
Owner.Left + (Owner.Width / 2) - (Width / 2),
142-
Math.Max(0, Owner.Top + (Owner.Height / 2) - (Height / 2)));
142+
Owner.Top + (Owner.Height / 2) - (Height / 2));
143143
}
144144

145145
if (WindowState != position.State)

‎UnitTests/GitUITests/GitExtensionsFormTests.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ public void RestorePosition_should_scale_sizable_window_if_different_dpi(int sav
142142
form.Size.Should().Be(new Size(expectedHeightAt96dpi, expectedHeightAt96dpi));
143143
}
144144

145-
[Test]
146-
public void RestorePosition_should_position_window_with_Owner_set_and_CenterParent()
145+
[TestCase(-1000, 100, /* -1000 + (800 - 300)/2 */ -750, /* 100 + (600-200)/2 */300)]
146+
[TestCase(0, 0, /* 0 + (800 - 300)/2 */ 250, /* 0 + (600-200)/2 */200)]
147+
[TestCase(1000, -400, /* 1000 + (800 - 300)/2 */ 1250, /* -400 + (600-200)/2 */ -200)]
148+
public void RestorePosition_should_position_window_with_Owner_set_and_CenterParent(int ownerFormTop, int ownerFormLeft, int expectFormTop, int expectedFormLeft)
147149
{
148150
var owner = new Form
149151
{
150-
Location = new Point(-1000, 100),
152+
Location = new Point(ownerFormTop, ownerFormLeft),
151153
Size = new Size(800, 600)
152154
};
153155
var form = new MockForm(true)
@@ -169,7 +171,7 @@ public void RestorePosition_should_position_window_with_Owner_set_and_CenterPare
169171

170172
form.InvokeRestorePosition();
171173

172-
form.Location.Should().Be(new Point(/* -1000 + (800 - 300)/2 */-750, /* 100 + (600-200)/2 */300));
174+
form.Location.Should().Be(new Point(expectFormTop, expectedFormLeft));
173175
}
174176

175177
private class MockForm : GitExtensionsForm

0 commit comments

Comments
 (0)
Please sign in to comment.