Skip to content

Commit

Permalink
Renaming a window to _quake will snap it into quake mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Apr 9, 2021
1 parent 04a4249 commit 87c6c2d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ namespace winrt::TerminalApp::implementation
FORWARDED_TYPED_EVENT(SetTaskbarProgress, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, _root, SetTaskbarProgress);
FORWARDED_TYPED_EVENT(IdentifyWindowsRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IdentifyWindowsRequested);
FORWARDED_TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs, _root, RenameWindowRequested);
FORWARDED_TYPED_EVENT(IsQuakeWindowChanged, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IsQuakeWindowChanged);

#ifdef UNIT_TESTING
friend class TerminalAppLocalTests::CommandlineTest;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, Object> SetTaskbarProgress;
event Windows.Foundation.TypedEventHandler<Object, Object> IdentifyWindowsRequested;
event Windows.Foundation.TypedEventHandler<Object, RenameWindowRequestedArgs> RenameWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
}
}
25 changes: 22 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2049,9 +2049,17 @@ namespace winrt::TerminalApp::implementation
// - <none>
void TerminalPage::ToggleFocusMode()
{
_isInFocusMode = !_isInFocusMode || IsQuakeWindow();
_UpdateTabView();
_FocusModeChangedHandlers(*this, nullptr);
_SetFocusMode(!_isInFocusMode);
}

void TerminalPage::_SetFocusMode(const bool inFocusMode)
{
if (inFocusMode != FocusMode())
{
_isInFocusMode = inFocusMode || IsQuakeWindow();
_UpdateTabView();
_FocusModeChangedHandlers(*this, nullptr);
}
}

// Method Description:
Expand Down Expand Up @@ -2596,10 +2604,21 @@ namespace winrt::TerminalApp::implementation
}
void TerminalPage::WindowName(const winrt::hstring& value)
{
const bool oldIsQuakeMode = IsQuakeWindow();
if (_WindowName != value)
{
_WindowName = value;
_PropertyChangedHandlers(*this, WUX::Data::PropertyChangedEventArgs{ L"WindowNameForDisplay" });

// If we're entering quake mode, or leaving it
if (IsQuakeWindow() != oldIsQuakeMode)
{
// If we're entering QM from ~FM, then this will enter FM
// If we're entering QM from FM, then this will do nothing
// If we're leaving QM (we're already in FM), then this will do nothing
_SetFocusMode(_isInFocusMode);
_IsQuakeWindowChangedHandlers(*this, nullptr);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(Initialized, IInspectable, winrt::Windows::UI::Xaml::RoutedEventArgs);
TYPED_EVENT(IdentifyWindowsRequested, IInspectable, IInspectable);
TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs);
TYPED_EVENT(IsQuakeWindowChanged, IInspectable, IInspectable);

private:
friend struct TerminalPageT<TerminalPage>; // for Xaml to bind events
Expand Down Expand Up @@ -331,6 +332,8 @@ namespace winrt::TerminalApp::implementation

void _UpdateTeachingTipTheme(winrt::Windows::UI::Xaml::FrameworkElement element);

void _SetFocusMode(const bool inFocusMode);

#pragma region ActionHandlers
// These are all defined in AppActionHandlers.cpp
#define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, Object> SetTaskbarProgress;
event Windows.Foundation.TypedEventHandler<Object, Object> IdentifyWindowsRequested;
event Windows.Foundation.TypedEventHandler<Object, RenameWindowRequestedArgs> RenameWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
}
}
8 changes: 7 additions & 1 deletion src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ void AppHost::Initialize()
_logic.FullscreenChanged({ this, &AppHost::_FullscreenChanged });
_logic.FocusModeChanged({ this, &AppHost::_FocusModeChanged });
_logic.AlwaysOnTopChanged({ this, &AppHost::_AlwaysOnTopChanged });
_logic.RaiseVisualBell({ this, &AppHost::_RaiseVisualBell });

_logic.Create();

Expand All @@ -253,6 +252,7 @@ void AppHost::Initialize()
_logic.SetTaskbarProgress({ this, &AppHost::SetTaskbarProgress });
_logic.IdentifyWindowsRequested({ this, &AppHost::_IdentifyWindowsRequested });
_logic.RenameWindowRequested({ this, &AppHost::_RenameWindowRequested });
_logic.IsQuakeWindowChanged({ this, &AppHost::_IsQuakeWindowChanged });

_window->UpdateTitle(_logic.Title());

Expand Down Expand Up @@ -687,3 +687,9 @@ winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Fou
}
}
}

void AppHost::_IsQuakeWindowChanged(const winrt::Windows::Foundation::IInspectable&,
const winrt::Windows::Foundation::IInspectable&)
{
_window->IsQuakeWindow(_logic.IsQuakeWindow());
}
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ class AppHost
const winrt::TerminalApp::RenameWindowRequestedArgs args);

GUID _CurrentDesktopGuid();

void _IsQuakeWindowChanged(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::Foundation::IInspectable& args);
};
52 changes: 50 additions & 2 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ LRESULT IslandWindow::_OnSizing(const WPARAM wParam, const LPARAM lParam)

// If we're the quake window, prevent resizing on all sides except the
// bottom. This also applies to resising with the Alt+Space menu
if (_IsQuakeWindow && wParam != WMSZ_BOTTOM)
if (IsQuakeWindow() && wParam != WMSZ_BOTTOM)
{
// Stuff our current window size into the lParam, and return true. This
// will tell User32 to use our current dimensions to resize to.
Expand Down Expand Up @@ -271,7 +271,7 @@ LRESULT IslandWindow::_OnMoving(const WPARAM /*wParam*/, const LPARAM lParam)
{
LPRECT winRect = reinterpret_cast<LPRECT>(lParam);
// If we're the quake window, prevent moving the window
if (_IsQuakeWindow)
if (IsQuakeWindow())
{
// Stuff our current window into the lParam, and return true. This
// will tell User32 to use our current position to move to.
Expand Down Expand Up @@ -787,6 +787,7 @@ void IslandWindow::_SetIsBorderless(const bool borderlessEnabled)
// Resize the window, with SWP_FRAMECHANGED, to trigger user32 to
// recalculate the non/client areas
const til::rectangle windowPos{ GetWindowRect() };

SetWindowPos(GetHandle(),
HWND_TOP,
windowPos.left<int>(),
Expand Down Expand Up @@ -918,5 +919,52 @@ winrt::fire_and_forget IslandWindow::SummonWindow()
LOG_IF_WIN32_BOOL_FALSE(ShowWindow(_window.get(), SW_SHOW));
}

bool IslandWindow::IsQuakeWindow() const noexcept
{
return _isQuakeWindow;
}

void IslandWindow::IsQuakeWindow(bool isQuakeWindow) noexcept
{
if (_isQuakeWindow != isQuakeWindow)
{
_isQuakeWindow = isQuakeWindow;
if (IsQuakeWindow())
{
_enterQuakeMode();
}
}
}

void IslandWindow::_enterQuakeMode()
{
RECT windowRect = GetWindowRect();
HMONITOR hmon = MonitorFromRect(&windowRect, MONITOR_DEFAULTTONEAREST);
MONITORINFO nearestMonitorInfo;
nearestMonitorInfo.cbSize = sizeof(MONITORINFO);
// Get monitor dimensions:
GetMonitorInfo(hmon, &nearestMonitorInfo);
const COORD desktopDimensions{ gsl::narrow<short>(nearestMonitorInfo.rcWork.right - nearestMonitorInfo.rcWork.left),
gsl::narrow<short>(nearestMonitorInfo.rcWork.bottom - nearestMonitorInfo.rcWork.top) };

const til::point origin{
::base::saturated_cast<short>(nearestMonitorInfo.rcWork.left),
::base::saturated_cast<short>(nearestMonitorInfo.rcWork.top)
};
const til::size dimensions{
desktopDimensions.X,
desktopDimensions.Y / 2
};

const til::rectangle newRect{ origin, dimensions };
SetWindowPos(GetHandle(),
HWND_TOP,
newRect.left<int>(),
newRect.top<int>(),
newRect.width<int>(),
newRect.height<int>(),
SWP_SHOWWINDOW | SWP_FRAMECHANGED | SWP_NOACTIVATE);
}

DEFINE_EVENT(IslandWindow, DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
DEFINE_EVENT(IslandWindow, WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
6 changes: 5 additions & 1 deletion src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class IslandWindow :

winrt::fire_and_forget SummonWindow();

WINRT_PROPERTY(bool, IsQuakeWindow, false);
bool IsQuakeWindow() const noexcept;
void IsQuakeWindow(bool isQuakeWindow) noexcept;

DECLARE_EVENT(DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
DECLARE_EVENT(WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
Expand Down Expand Up @@ -86,6 +87,9 @@ class IslandWindow :
void _OnGetMinMaxInfo(const WPARAM wParam, const LPARAM lParam);
long _calculateTotalSize(const bool isWidth, const long clientSize, const long nonClientSize);

bool _isQuakeWindow{ false };
void _enterQuakeMode();

private:
// This minimum width allows for width the tabs fit
static constexpr long minimumWidth = 460L;
Expand Down

1 comment on commit 87c6c2d

@github-actions

This comment was marked as resolved.

Please sign in to comment.