-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Settings, OOBE] set location to center screen (#10022)
and ensure the window is inside the screen work area
- Loading branch information
1 parent
f7e2fa5
commit 8f3e051
Showing
5 changed files
with
85 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Windows; | ||
|
||
namespace PowerToys.Settings | ||
{ | ||
internal class Utils | ||
{ | ||
public static void FitToScreen(Window window) | ||
{ | ||
if (SystemParameters.WorkArea.Width < window.Width) | ||
{ | ||
window.Width = SystemParameters.WorkArea.Width; | ||
} | ||
|
||
if (SystemParameters.WorkArea.Height < window.Height) | ||
{ | ||
window.Height = SystemParameters.WorkArea.Height; | ||
} | ||
} | ||
|
||
public static void CenterToScreen(Window window) | ||
{ | ||
if (SystemParameters.WorkArea.Height <= window.Height) | ||
{ | ||
window.Top = 0; | ||
} | ||
else | ||
{ | ||
window.Top = (SystemParameters.WorkArea.Height - window.Height) / 2; | ||
} | ||
|
||
if (SystemParameters.WorkArea.Width <= window.Width) | ||
{ | ||
window.Left = 0; | ||
} | ||
else | ||
{ | ||
window.Left = (SystemParameters.WorkArea.Width - window.Width) / 2; | ||
} | ||
} | ||
|
||
public static void ShowHide(Window window) | ||
{ | ||
// To limit the visual flickering, show the window with a size of 0,0 | ||
// and don't show it in the taskbar | ||
var originalHeight = window.Height; | ||
var originalWidth = window.Width; | ||
var originalMinHeight = window.MinHeight; | ||
var originalMinWidth = window.MinWidth; | ||
|
||
window.MinHeight = 0; | ||
window.MinWidth = 0; | ||
window.Height = 0; | ||
window.Width = 0; | ||
window.ShowInTaskbar = false; | ||
|
||
window.Show(); | ||
window.Hide(); | ||
|
||
window.Height = originalHeight; | ||
window.Width = originalWidth; | ||
window.MinHeight = originalMinHeight; | ||
window.MinWidth = originalMinWidth; | ||
window.ShowInTaskbar = true; | ||
} | ||
} | ||
} |