This PR includes the code changes that enable users to set an initial position (top left corner) and launch maximized. There are some corner cases: 1. Multiple monitors. The user should be able to set the initial position to any monitors attached. For the monitors on the left side of the major monitor, the initial position values are negative. 2. If the initial position is larger than the screen resolution and the window is off-screen, the current solution is to check if the top left corner of the window intersect with any monitors. If it is not, we set the initial position to the top left corner of the nearest monitor. 3. If the user wants to launch maximized and provides an initial position, we launch the maximized window on the monitor where the position is located. # Testing To test: 1. Check-out this branch and build on VS2019 2. Launch Terminal, and open Settings. Then close the terminal. 3. Add the following setting into Json settings file as part of "globals", just after "initialRows": "initialPosition": "1000, 1000", "launchMode": "default" My test data: I have already tested with the following variables: 1. showTabsInTitlebar true or false 2. The initial position of the top left corner of the window 3. Whether to launch maximized 4. The DPI of the monitor Test data combination: Non-client island window (showTabsInTitlebar true) 1. Three monitors with the same DPI (100%), left, middle and right, with the middle one as the primary, resolution: 1980 * 1200, 1920 * 1200, 1920 * 1080 launchMode: default In-Screen test: (0, 0), (1000, 500), (2000, 300), (-1000, 400), (-100, 200), (-2000, 100), (0, 1119) out-of-screen: (200, -200): initialize to (0, 0) (200, 1500): initialize to (0, 0) (2000, -200): initialize to (1920, 0) (2500, 2000): initialize to (1920, 0) (4000 100): initialize to (1920, 0) (-1000, -100): initialize to (-1920, 0) (-3000, 100): initialize to (-1920, 0) (10000, -10000): initialize to (1920, 0) (-10000, 10000): initialize to (-1920, 0) (0, -10000): initialize to (0, 0) (0, -1): initialize to (0, 0) (0, 1200): initialize to (0, 0) launch mode: maximize (100, 100) (-1000, 100): On the left monitor (0, -2000): On the primary monitor (10000, 10000): On the primary monitor 2. Left monitor 200% DPI, primary monitor 100% DPI In screen: (-1900, 100), (-3000, 100), (-1000, 100) our-of-screen: (-8000, 100): initialize at (-1920, 0) launch Maximized: (-100, 100): launch maximized on the left monitor correctly 3. Left monitor 100% DPI, primary monitor 200% DPI In-screen: (-1900, 100), (300, 100), (-800, 100), (-200, 100) out-of-screen: (-3000, 100): initialize at (-1920, 0) launch maximized: (100, 100), (-1000, 100) For client island window, the test data is the same as above. Issues: 1. If we set the initial position on the monitor with a different DPI as the primary monitor, and the window "lays" across two monitors, then the window still renders as it is on the primary monitor. The size of the window is correct. Closes #1043
69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
/*++
|
|
Copyright (c) Microsoft Corporation
|
|
|
|
Module Name:
|
|
- NonClientIslandWindow.h
|
|
|
|
Abstract:
|
|
- This class represents a window hosting two XAML Islands. One is in the client
|
|
area of the window, as it is in the base IslandWindow class. The second is in
|
|
the titlebar of the window, in the "non-client" area of the window. This
|
|
enables an app to place xaml content in the titlebar.
|
|
- Placing content in the frame is enabled with DwmExtendFrameIntoClientArea. See
|
|
https://docs.microsoft.com/en-us/windows/desktop/dwm/customframe
|
|
for information on how this is done.
|
|
|
|
Author(s):
|
|
Mike Griese (migrie) April-2019
|
|
--*/
|
|
|
|
#include "pch.h"
|
|
#include "IslandWindow.h"
|
|
#include "../../types/inc/Viewport.hpp"
|
|
#include <dwmapi.h>
|
|
#include <wil\resource.h>
|
|
|
|
class NonClientIslandWindow : public IslandWindow
|
|
{
|
|
public:
|
|
NonClientIslandWindow() noexcept;
|
|
virtual ~NonClientIslandWindow() override;
|
|
|
|
virtual void OnSize(const UINT width, const UINT height) override;
|
|
|
|
[[nodiscard]] virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;
|
|
|
|
MARGINS GetFrameMargins() const noexcept;
|
|
|
|
void Initialize() override;
|
|
|
|
void OnAppInitialized() override;
|
|
void SetContent(winrt::Windows::UI::Xaml::UIElement content) override;
|
|
void SetTitlebarContent(winrt::Windows::UI::Xaml::UIElement content);
|
|
|
|
private:
|
|
winrt::TerminalApp::TitlebarControl _titlebar{ nullptr };
|
|
winrt::Windows::UI::Xaml::UIElement _clientContent{ nullptr };
|
|
|
|
wil::unique_hbrush _backgroundBrush;
|
|
wil::unique_hrgn _dragBarRegion;
|
|
|
|
MARGINS _maximizedMargins = { 0 };
|
|
bool _isMaximized;
|
|
winrt::Windows::UI::Xaml::Controls::Border _dragBar{ nullptr };
|
|
|
|
RECT GetDragAreaRect() const noexcept;
|
|
|
|
[[nodiscard]] LRESULT HitTestNCA(POINT ptMouse) const noexcept;
|
|
|
|
[[nodiscard]] HRESULT _UpdateFrameMargins() const noexcept;
|
|
|
|
void _HandleActivateWindow();
|
|
bool _HandleWindowPosChanging(WINDOWPOS* const windowPos);
|
|
void _UpdateDragRegion();
|
|
|
|
void OnDragBarSizeChanged(winrt::Windows::Foundation::IInspectable sender, winrt::Windows::UI::Xaml::SizeChangedEventArgs eventArgs);
|
|
|
|
RECT GetMaxWindowRectInPixels(const RECT* const prcSuggested, _Out_opt_ UINT* pDpiSuggested);
|
|
};
|