Skip to content

Commit

Permalink
Prevent the window from being moved as well
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Apr 9, 2021
1 parent 8d9c1f1 commit 2db7fd5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ LRESULT IslandWindow::_OnSizing(const WPARAM wParam, const LPARAM lParam)
return true;
}

// TODO! is there a way to prevent _moving_ the window as well?

if (wParam != WMSZ_TOP && wParam != WMSZ_BOTTOM)
{
// If user has dragged anything but the top or bottom border (so e.g. left border,
Expand Down Expand Up @@ -259,6 +257,30 @@ LRESULT IslandWindow::_OnSizing(const WPARAM wParam, const LPARAM lParam)
return TRUE;
}

// Method Description:
// - Handle the WM_MOVING message
// - If we're the quake window, then we don't want to be able to be moved.
// Immediately return our current window position, which will prevent us from
// being moved at all.
// Arguments:
// - lParam: a LPRECT with the proposed window position, that should be filled
// with the resultant position.
// Return Value:
// - true iff we handled this message.
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)
{
// Stuff our current window into the lParam, and return true. This
// will tell User32 to use our current position to move to.
::GetWindowRect(_window.get(), winRect);
return true;
}
return false;
}

void IslandWindow::Initialize()
{
const bool initialized = (_interopWindowHandle != nullptr);
Expand Down Expand Up @@ -417,6 +439,10 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
{
return _OnSizing(wparam, lparam);
}
case WM_MOVING:
{
return _OnMoving(wparam, lparam);
}
case WM_CLOSE:
{
// If the user wants to close the app by clicking 'X' button,
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class IslandWindow :

void _HandleCreateWindow(const WPARAM wParam, const LPARAM lParam) noexcept;
[[nodiscard]] LRESULT _OnSizing(const WPARAM wParam, const LPARAM lParam);
[[nodiscard]] LRESULT _OnMoving(const WPARAM wParam, const LPARAM lParam);

bool _borderless{ false };
bool _fullscreen{ false };
Expand Down

0 comments on commit 2db7fd5

Please sign in to comment.