Skip to content

Commit d95a21f

Browse files
committed
[windows] Implement getOpacity & setOpacity methods #45
1 parent fd0b0c8 commit d95a21f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

windows/window_manager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class WindowManager
3737

3838
bool is_frameless = false;
3939
std::string title_bar_style = "default";
40+
double opacity = 1;
4041

4142
// The minimum size set by the platform channel.
4243
POINT minimum_size = {0, 0};
@@ -80,6 +81,8 @@ class WindowManager
8081
void WindowManager::SetSkipTaskbar(const flutter::EncodableMap &args);
8182
bool WindowManager::HasShadow();
8283
void WindowManager::SetHasShadow(const flutter::EncodableMap &args);
84+
double WindowManager::GetOpacity();
85+
void WindowManager::SetOpacity(const flutter::EncodableMap &args);
8386
void WindowManager::StartDragging();
8487

8588
private:
@@ -541,6 +544,20 @@ void WindowManager::SetSkipTaskbar(const flutter::EncodableMap &args)
541544
}
542545
}
543546

547+
double WindowManager::GetOpacity()
548+
{
549+
return this->opacity;
550+
}
551+
552+
void WindowManager::SetOpacity(const flutter::EncodableMap &args)
553+
{
554+
this->opacity = std::get<double>(args.at(flutter::EncodableValue("opacity")));
555+
HWND hWnd = GetMainWindow();
556+
long gwlExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
557+
SetWindowLong(hWnd, GWL_EXSTYLE, gwlExStyle | WS_EX_LAYERED);
558+
SetLayeredWindowAttributes(hWnd, 0, static_cast<int8_t>(255 * this->opacity), 0x02);
559+
}
560+
544561
void WindowManager::StartDragging()
545562
{
546563
ReleaseCapture();

windows/window_manager_plugin.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,17 @@ void WindowManagerPlugin::HandleMethodCall(const flutter::MethodCall<flutter::En
405405
window_manager->SetSkipTaskbar(args);
406406
result->Success(flutter::EncodableValue(true));
407407
}
408+
else if (method_name.compare("getOpacity") == 0)
409+
{
410+
double value = window_manager->GetOpacity();
411+
result->Success(flutter::EncodableValue(value));
412+
}
413+
else if (method_name.compare("setOpacity") == 0)
414+
{
415+
const flutter::EncodableMap &args = std::get<flutter::EncodableMap>(*method_call.arguments());
416+
window_manager->SetOpacity(args);
417+
result->Success(flutter::EncodableValue(true));
418+
}
408419
else if (method_name.compare("startDragging") == 0)
409420
{
410421
window_manager->StartDragging();

0 commit comments

Comments
 (0)