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

[Windows] Fix animation titlebar=hidden, add startResize() #75

Merged
merged 2 commits into from Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/src/window_manager.dart
Expand Up @@ -545,6 +545,26 @@ class WindowManager {
Future<void> startDragging() async {
await _channel.invokeMethod('startDragging');
}

Future<void> startResize(DragPosition position) {
return _channel.invokeMethod<bool>(
'startResize',
{
"top": position == DragPosition.top ||
position == DragPosition.topLeft ||
position == DragPosition.topRight,
"bottom": position == DragPosition.bottom ||
position == DragPosition.bottomLeft ||
position == DragPosition.bottomRight,
"right": position == DragPosition.right ||
position == DragPosition.topRight ||
position == DragPosition.bottomRight,
"left": position == DragPosition.left ||
position == DragPosition.topLeft ||
position == DragPosition.bottomLeft,
},
);
}

Future<Map<String, dynamic>> _getPrimaryDisplay() async {
final Map<String, dynamic> arguments = {
Expand Down Expand Up @@ -578,3 +598,14 @@ class WindowManager {
}

final windowManager = WindowManager.instance;

enum DragPosition {
top,
left,
right,
bottom,
topLeft,
bottomLeft,
topRight,
bottomRight
}
48 changes: 46 additions & 2 deletions windows/window_manager.cpp
Expand Up @@ -93,6 +93,7 @@ class WindowManager {
double WindowManager::GetOpacity();
void WindowManager::SetOpacity(const flutter::EncodableMap& args);
void WindowManager::StartDragging();
void WindowManager::StartResize(const flutter::EncodableMap &args);
flutter::EncodableMap WindowManager::GetPrimaryDisplay(
const flutter::EncodableMap& args);

Expand Down Expand Up @@ -538,10 +539,10 @@ void WindowManager::SetTitleBarStyle(const flutter::EncodableMap& args) {
HWND hWnd = GetMainWindow();
DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
if (title_bar_style_ == "hidden") {
gwlStyle = gwlStyle & ~WS_CAPTION;
gwlStyle = gwlStyle | WS_POPUP;
SetWindowLong(hWnd, GWL_STYLE, gwlStyle);
} else {
gwlStyle = gwlStyle | WS_CAPTION;
gwlStyle = gwlStyle & ~WS_POPUP;
SetWindowLong(hWnd, GWL_STYLE, gwlStyle);
}

Expand Down Expand Up @@ -607,6 +608,49 @@ void WindowManager::StartDragging() {
SendMessage(GetMainWindow(), WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
}

void WindowManager::StartResize(const flutter::EncodableMap &args) {
bool top = std::get<bool>(args.at(flutter::EncodableValue("top")));
bool bottom = std::get<bool>(args.at(flutter::EncodableValue("bottom")));
bool left = std::get<bool>(args.at(flutter::EncodableValue("left")));
bool right = std::get<bool>(args.at(flutter::EncodableValue("right")));
HWND hWnd = GetMainWindow();
ReleaseCapture();
LONG command = SC_SIZE;
if (top && !bottom && !right && !left)
{
command |= WMSZ_TOP;
}
else if (top && left && !bottom && !right)
{
command |= WMSZ_TOPLEFT;
}
else if (left && !top && !bottom && !right)
{
command |= WMSZ_LEFT;
}
else if (right && !top && !left && !bottom)
{
command |= WMSZ_RIGHT;
}
else if (top && right && !left && !bottom)
{
command |= WMSZ_TOPRIGHT;
}
else if (bottom && !top && !right && !left)
{
command |= WMSZ_BOTTOM;
}
else if (bottom && left && !top && !right)
{
command |= WMSZ_BOTTOMLEFT;
}
else if (bottom && right && !top && !left)
{
command |= WMSZ_BOTTOMRIGHT;
}
SendMessage(hWnd, WM_SYSCOMMAND, command, 0);
}

flutter::EncodableMap WindowManager::GetPrimaryDisplay(
const flutter::EncodableMap& args) {
double devicePixelRatio =
Expand Down
22 changes: 11 additions & 11 deletions windows/window_manager_plugin.cpp
Expand Up @@ -105,23 +105,19 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
RECT borderThickness;
SetRectEmpty(&borderThickness);
AdjustWindowRectEx(&borderThickness,
GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION, FALSE,
GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUP, FALSE,
NULL);
NCCALCSIZE_PARAMS* sz = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);

// Add 1 pixel to the top border to make the window resizable from the top
// border
sz->rgrc[0].top += 1;
sz->rgrc[0].right -= borderThickness.right;
sz->rgrc[0].bottom -= borderThickness.bottom;
sz->rgrc[0].left -= borderThickness.left;
// Add 8 pixel to the top border when maximized so the app isn't cut off
// Top resize border is still not working.
sz->rgrc[0].top += window_manager->IsMaximized() ? 8 : 0;
sz->rgrc[0].right -= 8;
sz->rgrc[0].bottom -= 8;
sz->rgrc[0].left -= -8;

return (WVR_HREDRAW | WVR_VREDRAW);
}
}
if (message == WM_NCPAINT) {
if (window_manager->title_bar_style_ == "hidden")
return 1;
} else if (message == WM_NCHITTEST) {
if (!window_manager->is_resizable_) {
return HTNOWHERE;
Expand Down Expand Up @@ -420,6 +416,10 @@ void WindowManagerPlugin::HandleMethodCall(
} else if (method_name.compare("startDragging") == 0) {
window_manager->StartDragging();
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("startResize") == 0) {
const flutter::EncodableMap &args = std::get<flutter::EncodableMap>(*method_call.arguments());
window_manager->StartResize(args);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("getPrimaryDisplay") == 0) {
const flutter::EncodableMap& args =
std::get<flutter::EncodableMap>(*method_call.arguments());
Expand Down