Skip to content

Commit 46caa38

Browse files
committed
[windows] Implement setBrightness method #86
1 parent 6eb721c commit 46caa38

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/src/window_manager.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,6 @@ class WindowManager {
557557
final Map<String, dynamic> arguments = {
558558
'brightness': brightness.name,
559559
};
560-
print(arguments);
561560
await _channel.invokeMethod('setBrightness', arguments);
562561
}
563562

windows/window_manager.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define STATE_MINIMIZED 2
2323
#define STATE_FULLSCREEN_ENTERED 3
2424

25+
#define DWMWA_USE_IMMERSIVE_DARK_MODE 19
26+
2527
namespace {
2628
class WindowManager {
2729
public:
@@ -93,6 +95,7 @@ class WindowManager {
9395
void WindowManager::SetHasShadow(const flutter::EncodableMap& args);
9496
double WindowManager::GetOpacity();
9597
void WindowManager::SetOpacity(const flutter::EncodableMap& args);
98+
void WindowManager::SetBrightness(const flutter::EncodableMap& args);
9699
void WindowManager::StartDragging();
97100
void WindowManager::StartResizing(const flutter::EncodableMap& args);
98101
flutter::EncodableMap WindowManager::GetPrimaryDisplay(
@@ -620,6 +623,17 @@ void WindowManager::SetOpacity(const flutter::EncodableMap& args) {
620623
0x02);
621624
}
622625

626+
void WindowManager::SetBrightness(const flutter::EncodableMap& args) {
627+
std::string brightness =
628+
std::get<std::string>(args.at(flutter::EncodableValue("brightness")));
629+
630+
const BOOL is_dark_mode = brightness == "dark";
631+
632+
HWND hWnd = GetMainWindow();
633+
DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &is_dark_mode,
634+
sizeof(is_dark_mode));
635+
}
636+
623637
void WindowManager::StartDragging() {
624638
ReleaseCapture();
625639
SendMessage(GetMainWindow(), WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);

windows/window_manager_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ void WindowManagerPlugin::HandleMethodCall(
434434
std::get<flutter::EncodableMap>(*method_call.arguments());
435435
window_manager->SetOpacity(args);
436436
result->Success(flutter::EncodableValue(true));
437+
} else if (method_name.compare("setBrightness") == 0) {
438+
const flutter::EncodableMap& args =
439+
std::get<flutter::EncodableMap>(*method_call.arguments());
440+
window_manager->SetBrightness(args);
441+
result->Success(flutter::EncodableValue(true));
437442
} else if (method_name.compare("startDragging") == 0) {
438443
window_manager->StartDragging();
439444
result->Success(flutter::EncodableValue(true));

0 commit comments

Comments
 (0)