Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dragging with the entire titlebar #1948

Merged
merged 38 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
15a1f48
This definitely works for getting shadow, pointy corners back
zadjii-msft Jul 9, 2019
0bc9969
The window style was _not_ important
zadjii-msft Jul 9, 2019
bf239b6
Still getting a black xaml islands area (the HRGN) when we switch to …
zadjii-msft Jul 9, 2019
22e1023
I don't know if this affects anything.
zadjii-msft Jul 9, 2019
aad9f56
heyo this works.
zadjii-msft Jul 9, 2019
5fd4191
Add more comments and cleanup
zadjii-msft Jul 9, 2019
b02d9eb
Merge branch 'dev/migrie/f/1625-less-round-more-shadow' into dev/migr…
zadjii-msft Jul 10, 2019
5c50804
Try making the button RightCustomContent
zadjii-msft Jul 10, 2019
10bcf6e
* Make the MinMaxClose's drag bar's min size the same as a caption bu…
zadjii-msft Jul 10, 2019
ea1298e
Create a TitlebarControl
zadjii-msft Jul 11, 2019
cf939cc
Fix the MMC buttons not working
zadjii-msft Jul 11, 2019
a6ad655
Make the titlebar less magenta
zadjii-msft Jul 11, 2019
ac1f20b
Resize the drag region as we add/remove tabs
zadjii-msft Jul 11, 2019
1905852
Move the actual MMC handling to the TitlebarControl
zadjii-msft Jul 11, 2019
9040940
Some PR nits, fix the titlebar painting on maximize
zadjii-msft Jul 12, 2019
96c5da2
Merge branch 'dev/migrie/f/1625-less-round-more-shadow' into dev/migr…
zadjii-msft Jul 12, 2019
2636b11
Put the TabRow in our XAML
zadjii-msft Jul 12, 2019
dcdbdca
Merge remote-tracking branch 'origin/master' into dev/migrie/f/newtab…
zadjii-msft Jul 12, 2019
69a78d4
Remove dead code in preparation for review
zadjii-msft Jul 12, 2019
e038b5d
Horrifyingly try Gdi Plus as a solution, that is _wrong_ though
zadjii-msft Jul 15, 2019
faef5c7
Revert "Horrifyingly try Gdi Plus as a solution, that is _wrong_ though"
zadjii-msft Jul 15, 2019
83dc600
This fixes the bottom border but breaks the titlebar painting
zadjii-msft Jul 15, 2019
8712f1e
Fix the NC bottom border
zadjii-msft Jul 15, 2019
08e9d6f
A bunch of the more minor PR nits
zadjii-msft Jul 15, 2019
5704084
Add a MinimizeClick event to the MMCControl
zadjii-msft Jul 15, 2019
1fb6943
Add events for _all_ of the buttons, not just the Minimize btn
zadjii-msft Jul 15, 2019
052fabd
Change hoe setting the titlebar content works
zadjii-msft Jul 15, 2019
4fd75f1
Merge remote-tracking branch 'origin/master' into dev/migrie/f/newtab…
zadjii-msft Jul 15, 2019
bfab953
Move the tab row to the bottom of it's available space
zadjii-msft Jul 15, 2019
ce04e72
Fix the theme reloading
zadjii-msft Jul 15, 2019
8e057ea
Merge remote-tracking branch 'origin/master' into dev/migrie/f/newtab…
zadjii-msft Jul 16, 2019
c4a398b
PR nits from @miniksa
zadjii-msft Jul 16, 2019
bf534c6
Update src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
zadjii-msft Jul 16, 2019
f0dc01e
Merge remote-tracking branch 'origin/master' into dev/migrie/f/newtab…
zadjii-msft Jul 17, 2019
6e41097
This needed to be fixed, was missed in other PR nits
zadjii-msft Jul 17, 2019
744a27f
runformat
zadjii-msft Jul 18, 2019
e2fde7a
Merge remote-tracking branch 'origin/master' into dev/migrie/f/newtab…
zadjii-msft Jul 18, 2019
dc5b18a
Does this fix the CI build?
zadjii-msft Jul 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 39 additions & 35 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,13 @@ namespace winrt::TerminalApp::implementation
// - <none>
// Return Value:
// - <none>
void App::Create(uint64_t hWnd)
void App::Create()
{
// Assert that we've already loaded our settings. We have to do
// this as a MTA, before the app is Create()'d
WINRT_ASSERT(_loadedInitialSettings);
TraceLoggingRegister(g_hTerminalAppProvider);
_Create(hWnd);
}

App::~App()
{
TraceLoggingUnregister(g_hTerminalAppProvider);
}

// Method Description:
// - Create all of the initial UI elements of the Terminal app.
// * Initializes the first terminal control, using the default profile,
// and adds it to our list of tabs.
void App::_Create(uint64_t parentHwnd)
{
/* !!! TODO
This is not the correct way to host a XAML page. This exists today because we valued
getting a .xaml over tearing out all of the terminal logic and splitting it across App
Expand All @@ -92,15 +79,21 @@ namespace winrt::TerminalApp::implementation
_root = terminalPage.as<winrt::Windows::UI::Xaml::Controls::Control>();
_tabContent = terminalPage->TabContent();
_tabRow = terminalPage->TabRow();
_tabView = terminalPage->TabView();
_newTabButton = terminalPage->NewTabButton();

_minMaxCloseControl = terminalPage->MinMaxCloseControl();
_minMaxCloseControl.ParentWindowHandle(parentHwnd);
_tabView = _tabRow.TabView();
_newTabButton = _tabRow.NewTabButton();

if (!_settings->GlobalSettings().GetShowTabsInTitlebar())
if (_settings->GlobalSettings().GetShowTabsInTitlebar())
{
_minMaxCloseControl.Visibility(Visibility::Collapsed);
// Remove the TabView from the page. We'll hang on to it, we need to
// put it in the titlebar.
uint32_t index = 0;
if (terminalPage->Root().Children().IndexOf(_tabRow, index))
{
terminalPage->Root().Children().RemoveAt(index);
}

// Inform the host that our titlebar content has changed.
_setTitleBarContentHandlers(*this, _tabRow);
}

// Event Bindings (Early)
Expand All @@ -118,6 +111,14 @@ namespace winrt::TerminalApp::implementation
_tabContent.SizeChanged({ this, &App::_OnContentSizeChanged });
}

App::~App()
{
if (g_hTerminalAppProvider)
{
TraceLoggingUnregister(g_hTerminalAppProvider);
}
}

// Method Description:
// - Show a ContentDialog with a single button to dismiss. Uses the
// FrameworkElements provided as the title and content of this dialog, and
Expand Down Expand Up @@ -456,16 +457,6 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::System::Launcher::LaunchUriAsync({ feedbackUriValue });
}

Windows::UI::Xaml::Controls::Border App::GetDragBar() noexcept
{
if (_minMaxCloseControl)
{
return _minMaxCloseControl.DragBar();
}

return nullptr;
}

// Method Description:
// - Called when the about button is clicked. See _ShowAboutDialog for more info.
// Arguments:
Expand Down Expand Up @@ -741,13 +732,16 @@ namespace winrt::TerminalApp::implementation
}

// Method Description:
// - Update the current theme of the application. This will manually update
// all of the elements in our UI to match the given theme.
// - Update the current theme of the application. This will trigger our
// RequestedThemeChanged event, to have our host change the theme of the
// root of the application.
// Arguments:
// - newTheme: The ElementTheme to apply to our elements.
void App::_ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme)
{
_root.RequestedTheme(newTheme);
// Propagate the event to the host layer, so it can update its own UI
_requestedThemeChangedHandlers(*this, newTheme);
}

UIElement App::GetRoot() noexcept
Expand Down Expand Up @@ -916,7 +910,11 @@ namespace winrt::TerminalApp::implementation
// Initialize the new tab

// Create a Conhost connection based on the values in our settings object.
TerminalConnection::ITerminalConnection connection = TerminalConnection::ConhostConnection(settings.Commandline(), settings.StartingDirectory(), 30, 80, winrt::guid());
auto connection = TerminalConnection::ConhostConnection(settings.Commandline(),
settings.StartingDirectory(),
30,
80,
winrt::guid());

TermControl term{ settings, connection };

Expand Down Expand Up @@ -1303,7 +1301,11 @@ namespace winrt::TerminalApp::implementation
const auto controlSettings = _settings->MakeSettings(realGuid);

// Create a Conhost connection based on the values in our settings object.
TerminalConnection::ITerminalConnection controlConnection = TerminalConnection::ConhostConnection(controlSettings.Commandline(), controlSettings.StartingDirectory(), 30, 80, winrt::guid());
auto controlConnection = TerminalConnection::ConhostConnection(controlSettings.Commandline(),
controlSettings.StartingDirectory(),
30,
80,
winrt::guid());

TermControl newControl{ controlSettings, controlConnection };

Expand Down Expand Up @@ -1404,4 +1406,6 @@ namespace winrt::TerminalApp::implementation
// These macros will define them both for you.
DEFINE_EVENT(App, TitleChanged, _titleChangeHandlers, TerminalControl::TitleChangedEventArgs);
DEFINE_EVENT(App, LastTabClosed, _lastTabClosedHandlers, winrt::TerminalApp::LastTabClosedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(App, SetTitleBarContent, _setTitleBarContentHandlers, TerminalApp::App, winrt::Windows::UI::Xaml::UIElement);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(App, RequestedThemeChanged, _requestedThemeChangedHandlers, TerminalApp::App, winrt::Windows::UI::Xaml::ElementTheme);
}
11 changes: 4 additions & 7 deletions src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ namespace winrt::TerminalApp::implementation

Windows::UI::Xaml::UIElement GetRoot() noexcept;

// Gets the current dragglable area in the non client region of the top level window
Windows::UI::Xaml::Controls::Border GetDragBar() noexcept;

void Create(uint64_t hParentWnd);
void Create();
void LoadSettings();

Windows::Foundation::Point GetLaunchDimensions(uint32_t dpi);
Expand All @@ -43,6 +40,8 @@ namespace winrt::TerminalApp::implementation
// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT(TitleChanged, _titleChangeHandlers, winrt::Microsoft::Terminal::TerminalControl::TitleChangedEventArgs);
DECLARE_EVENT(LastTabClosed, _lastTabClosedHandlers, winrt::TerminalApp::LastTabClosedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(SetTitleBarContent, _setTitleBarContentHandlers, TerminalApp::App, winrt::Windows::UI::Xaml::UIElement);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(RequestedThemeChanged, _requestedThemeChangedHandlers, TerminalApp::App, winrt::Windows::UI::Xaml::ElementTheme);

private:
// If you add controls here, but forget to null them either here or in
Expand All @@ -53,10 +52,9 @@ namespace winrt::TerminalApp::implementation
// (which is a root when the tabs are in the titlebar.)
Windows::UI::Xaml::Controls::Control _root{ nullptr };
Microsoft::UI::Xaml::Controls::TabView _tabView{ nullptr };
Windows::UI::Xaml::Controls::Grid _tabRow{ nullptr };
TerminalApp::TabRowControl _tabRow{ nullptr };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not necessary any longer, yes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically yes, the TabRowControl isn't totally necessary, but I was inclined to keep it, to keep each piece more atomic. If you feel strongly, I can change it back

Windows::UI::Xaml::Controls::Grid _tabContent{ nullptr };
Windows::UI::Xaml::Controls::SplitButton _newTabButton{ nullptr };
winrt::TerminalApp::MinMaxCloseControl _minMaxCloseControl{ nullptr };

std::vector<std::shared_ptr<Tab>> _tabs;

Expand All @@ -71,7 +69,6 @@ namespace winrt::TerminalApp::implementation

std::atomic<bool> _settingsReloadQueued{ false };

void _Create(uint64_t parentHWnd);
void _CreateNewTabFlyout();

fire_and_forget _ShowDialog(const winrt::Windows::Foundation::IInspectable& titleElement,
Expand Down
8 changes: 4 additions & 4 deletions src/cascadia/TerminalApp/App.idl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
namespace TerminalApp
{
delegate void LastTabClosedEventArgs();
[default_interface]
runtimeclass App : Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication
[default_interface] runtimeclass App : Microsoft.Toolkit.Win32.UI.XamlHost.XamlApplication
{
App();

Expand All @@ -16,18 +15,19 @@ namespace TerminalApp
// then it might look like TermApp just failed to activate, which will
// cause you to chase down the rabbit hole of "why is TermApp not
// registered?" when it definitely is.
void Create(UInt64 hParentWnd);
void Create();

void LoadSettings();

Windows.UI.Xaml.UIElement GetRoot();
Windows.UI.Xaml.Controls.Border GetDragBar{ get; };

Windows.Foundation.Point GetLaunchDimensions(UInt32 dpi);
Boolean GetShowTabsInTitlebar();

event Microsoft.Terminal.TerminalControl.TitleChangedEventArgs TitleChanged;
event LastTabClosedEventArgs LastTabClosed;
event Windows.Foundation.TypedEventHandler<App, Windows.UI.Xaml.UIElement> SetTitleBarContent;
event Windows.Foundation.TypedEventHandler<App, Windows.UI.Xaml.ElementTheme> RequestedThemeChanged;

String GetTitle();
}
Expand Down
63 changes: 22 additions & 41 deletions src/cascadia/TerminalApp/MinMaxCloseControl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
// MinMaxCloseControl.xaml.cpp
// Implementation of the MinMaxCloseControl class
//
Expand All @@ -8,6 +10,7 @@
#include "MinMaxCloseControl.h"

#include "MinMaxCloseControl.g.cpp"
using namespace winrt::Windows::UI::Xaml;

namespace winrt::TerminalApp::implementation
{
Expand All @@ -16,59 +19,37 @@ namespace winrt::TerminalApp::implementation
InitializeComponent();
}

uint64_t MinMaxCloseControl::ParentWindowHandle() const
void MinMaxCloseControl::Maximize()
{
return reinterpret_cast<uint64_t>(_window);
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateMaximized", false);
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
}

void MinMaxCloseControl::ParentWindowHandle(uint64_t handle)
void MinMaxCloseControl::RestoreDown()
{
_window = reinterpret_cast<HWND>(handle);
VisualStateManager::GoToState(MaximizeButton(), L"WindowStateNormal", false);
}

void MinMaxCloseControl::_OnMaximize(byte flag)
// These event handlers simply forward each buttons click events up to the
// events we've exposed.
void MinMaxCloseControl::_MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
RoutedEventArgs const& e)
{
if (_window)
{
POINT point1 = {};
::GetCursorPos(&point1);
const LPARAM lParam = MAKELPARAM(point1.x, point1.y);
WINDOWPLACEMENT placement = { sizeof(placement) };
::GetWindowPlacement(_window, &placement);
if (placement.showCmd == SW_SHOWNORMAL)
{
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(this->Maximize(), L"WindowStateMaximized", false);
::PostMessage(_window, WM_SYSCOMMAND, SC_MAXIMIZE | flag, lParam);
}
else if (placement.showCmd == SW_SHOWMAXIMIZED)
{
winrt::Windows::UI::Xaml::VisualStateManager::GoToState(this->Maximize(), L"WindowStateNormal", false);
::PostMessage(_window, WM_SYSCOMMAND, SC_RESTORE | flag, lParam);
}
}
_minimizeClickHandlers(*this, e);
}

void MinMaxCloseControl::Maximize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e)
void MinMaxCloseControl::_MaximizeClick(winrt::Windows::Foundation::IInspectable const& sender,
RoutedEventArgs const& e)
{
_OnMaximize(HTMAXBUTTON);
_maximizeClickHandlers(*this, e);
}

void MinMaxCloseControl::DragBar_DoubleTapped(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Input::DoubleTappedRoutedEventArgs const& e)
void MinMaxCloseControl::_CloseClick(winrt::Windows::Foundation::IInspectable const& sender,
RoutedEventArgs const& e)
{
_OnMaximize(HTCAPTION);
_closeClickHandlers(*this, e);
}

void MinMaxCloseControl::Minimize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e)
{
if (_window)
{
::PostMessage(_window, WM_SYSCOMMAND, SC_MINIMIZE | HTMINBUTTON, 0);
}
}

void MinMaxCloseControl::Close_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e)
{
::PostQuitMessage(0);
}
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);
DEFINE_EVENT_WITH_TYPED_EVENT_HANDLER(MinMaxCloseControl, CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, RoutedEventArgs);

}
25 changes: 15 additions & 10 deletions src/cascadia/TerminalApp/MinMaxCloseControl.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
// Declaration of the MainUserControl class.
//

Expand All @@ -8,24 +10,27 @@
#include "winrt/Windows.UI.Xaml.Markup.h"
#include "winrt/Windows.UI.Xaml.Interop.h"
#include "MinMaxCloseControl.g.h"
#include "../../cascadia/inc/cppwinrt_utils.h"

namespace winrt::TerminalApp::implementation
{
struct MinMaxCloseControl : MinMaxCloseControlT<MinMaxCloseControl>
{
MinMaxCloseControl();

void Minimize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
void Maximize_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
void Close_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
void DragBar_DoubleTapped(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Input::DoubleTappedRoutedEventArgs const& e);
void Maximize();
void RestoreDown();

uint64_t ParentWindowHandle() const;
void ParentWindowHandle(uint64_t handle);
void _MinimizeClick(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
void _MaximizeClick(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
void _CloseClick(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);

private:
void _OnMaximize(byte flag);
HWND _window{ nullptr }; // non-owning handle; should not be freed in the dtor.
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(MinimizeClick, _minimizeClickHandlers, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(MaximizeClick, _maximizeClickHandlers, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
DECLARE_EVENT_WITH_TYPED_EVENT_HANDLER(CloseClick, _closeClickHandlers, TerminalApp::MinMaxCloseControl, winrt::Windows::UI::Xaml::RoutedEventArgs);
};
}

Expand Down
16 changes: 10 additions & 6 deletions src/cascadia/TerminalApp/MinMaxCloseControl.idl
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
namespace TerminalApp
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

namespace TerminalApp
{
[default_interface]
runtimeclass MinMaxCloseControl : Windows.UI.Xaml.Controls.StackPanel
[default_interface] runtimeclass MinMaxCloseControl : Windows.UI.Xaml.Controls.StackPanel
{
MinMaxCloseControl();

Windows.UI.Xaml.Controls.Grid Content{ get; };
Windows.UI.Xaml.Controls.Border DragBar{ get; };
void Maximize();
void RestoreDown();

UInt64 ParentWindowHandle;
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MinimizeClick;
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> MaximizeClick;
event Windows.Foundation.TypedEventHandler<MinMaxCloseControl, Windows.UI.Xaml.RoutedEventArgs> CloseClick;
}
}
Loading