Skip to content

Commit 0483433

Browse files
committed
Code optimization
1 parent 6ce7e23 commit 0483433

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

windows/window_manager.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class WindowManager
3636
int last_state = STATE_NORMAL;
3737

3838
bool is_frameless = false;
39-
std::string title_bar_style = "default";
40-
double opacity = 1;
41-
bool is_resizable = true;
39+
std::string title_bar_style_ = "default";
40+
bool is_resizable_ = true;
41+
double opacity_ = 1;
4242

4343
// The minimum size set by the platform channel.
4444
POINT minimum_size = {0, 0};
@@ -439,12 +439,12 @@ void WindowManager::SetMaximumSize(const flutter::EncodableMap &args)
439439

440440
bool WindowManager::IsResizable()
441441
{
442-
return this->is_resizable;
442+
return is_resizable_;
443443
}
444444

445445
void WindowManager::SetResizable(const flutter::EncodableMap &args)
446446
{
447-
this->is_resizable = std::get<bool>(args.at(flutter::EncodableValue("isResizable")));
447+
is_resizable_ = std::get<bool>(args.at(flutter::EncodableValue("isResizable")));
448448
}
449449

450450
bool WindowManager::IsMinimizable()
@@ -511,13 +511,11 @@ void WindowManager::SetTitle(const flutter::EncodableMap &args)
511511

512512
void WindowManager::SetTitleBarStyle(const flutter::EncodableMap &args)
513513
{
514-
std::string titleBarStyle = std::get<std::string>(args.at(flutter::EncodableValue("titleBarStyle")));
515-
516-
this->title_bar_style = titleBarStyle;
514+
title_bar_style_ = std::get<std::string>(args.at(flutter::EncodableValue("titleBarStyle")));
517515

518516
HWND hWnd = GetMainWindow();
519517
DWORD gwlStyle = GetWindowLong(hWnd, GWL_STYLE);
520-
if (titleBarStyle == "hidden")
518+
if (title_bar_style_ == "hidden")
521519
{
522520
gwlStyle = gwlStyle & ~WS_CAPTION;
523521
SetWindowLong(hWnd, GWL_STYLE, gwlStyle);
@@ -559,16 +557,16 @@ void WindowManager::SetSkipTaskbar(const flutter::EncodableMap &args)
559557

560558
double WindowManager::GetOpacity()
561559
{
562-
return this->opacity;
560+
return opacity_;
563561
}
564562

565563
void WindowManager::SetOpacity(const flutter::EncodableMap &args)
566564
{
567-
this->opacity = std::get<double>(args.at(flutter::EncodableValue("opacity")));
565+
opacity_ = std::get<double>(args.at(flutter::EncodableValue("opacity")));
568566
HWND hWnd = GetMainWindow();
569567
long gwlExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
570568
SetWindowLong(hWnd, GWL_EXSTYLE, gwlExStyle | WS_EX_LAYERED);
571-
SetLayeredWindowAttributes(hWnd, 0, static_cast<int8_t>(255 * this->opacity), 0x02);
569+
SetLayeredWindowAttributes(hWnd, 0, static_cast<int8_t>(255 * opacity_), 0x02);
572570
}
573571

574572
void WindowManager::StartDragging()

windows/window_manager_plugin.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
9393
return 1;
9494
}
9595

96-
if (wParam && window_manager->title_bar_style == "hidden")
96+
if (wParam && window_manager->title_bar_style_ == "hidden")
9797
{
9898
WINDOWPLACEMENT wPos;
9999
wPos.length = sizeof(wPos);
@@ -102,7 +102,7 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
102102
SetRectEmpty(&borderThickness);
103103
AdjustWindowRectEx(&borderThickness, GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION, FALSE, NULL);
104104
NCCALCSIZE_PARAMS *sz = reinterpret_cast<NCCALCSIZE_PARAMS *>(lParam);
105-
105+
106106
// Add 1 pixel to the top border to make the window resizable from the top border
107107
sz->rgrc[0].top += 1;
108108
sz->rgrc[0].right -= borderThickness.right;
@@ -114,15 +114,16 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
114114
}
115115
if (message == WM_NCPAINT)
116116
{
117-
if (window_manager->title_bar_style == "hidden")
117+
if (window_manager->title_bar_style_ == "hidden")
118118
return 1;
119119
}
120-
else if (message == WM_NCHITTEST)
120+
else if (message == WM_NCHITTEST)
121121
{
122-
bool isResizable = window_manager->is_resizable;
123-
if (!isResizable) {
124-
return HTNOWHERE;
125-
}
122+
if (!window_manager->is_resizable_)
123+
{
124+
return HTNOWHERE;
125+
}
126+
126127
LONG width = 10;
127128
POINT mouse = {LOWORD(lParam), HIWORD(lParam)};
128129
RECT window;
@@ -172,7 +173,7 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd, UINT mes
172173
_EmitEvent("blur");
173174
}
174175

175-
if (window_manager->title_bar_style == "hidden")
176+
if (window_manager->title_bar_style_ == "hidden")
176177
return 1;
177178
}
178179
else if (message == WM_MOVING)

0 commit comments

Comments
 (0)