Skip to content

Commit

Permalink
[windows] Implement setBrightness method #86
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Mar 6, 2022
1 parent 6eb721c commit 46caa38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/src/window_manager.dart
Expand Up @@ -557,7 +557,6 @@ class WindowManager {
final Map<String, dynamic> arguments = {
'brightness': brightness.name,
};
print(arguments);
await _channel.invokeMethod('setBrightness', arguments);
}

Expand Down
14 changes: 14 additions & 0 deletions windows/window_manager.cpp
Expand Up @@ -22,6 +22,8 @@
#define STATE_MINIMIZED 2
#define STATE_FULLSCREEN_ENTERED 3

#define DWMWA_USE_IMMERSIVE_DARK_MODE 19

namespace {
class WindowManager {
public:
Expand Down Expand Up @@ -93,6 +95,7 @@ class WindowManager {
void WindowManager::SetHasShadow(const flutter::EncodableMap& args);
double WindowManager::GetOpacity();
void WindowManager::SetOpacity(const flutter::EncodableMap& args);
void WindowManager::SetBrightness(const flutter::EncodableMap& args);
void WindowManager::StartDragging();
void WindowManager::StartResizing(const flutter::EncodableMap& args);
flutter::EncodableMap WindowManager::GetPrimaryDisplay(
Expand Down Expand Up @@ -620,6 +623,17 @@ void WindowManager::SetOpacity(const flutter::EncodableMap& args) {
0x02);
}

void WindowManager::SetBrightness(const flutter::EncodableMap& args) {
std::string brightness =
std::get<std::string>(args.at(flutter::EncodableValue("brightness")));

const BOOL is_dark_mode = brightness == "dark";

HWND hWnd = GetMainWindow();
DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &is_dark_mode,
sizeof(is_dark_mode));
}

void WindowManager::StartDragging() {
ReleaseCapture();
SendMessage(GetMainWindow(), WM_SYSCOMMAND, SC_MOVE | HTCAPTION, 0);
Expand Down
5 changes: 5 additions & 0 deletions windows/window_manager_plugin.cpp
Expand Up @@ -434,6 +434,11 @@ void WindowManagerPlugin::HandleMethodCall(
std::get<flutter::EncodableMap>(*method_call.arguments());
window_manager->SetOpacity(args);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("setBrightness") == 0) {
const flutter::EncodableMap& args =
std::get<flutter::EncodableMap>(*method_call.arguments());
window_manager->SetBrightness(args);
result->Success(flutter::EncodableValue(true));
} else if (method_name.compare("startDragging") == 0) {
window_manager->StartDragging();
result->Success(flutter::EncodableValue(true));
Expand Down

0 comments on commit 46caa38

Please sign in to comment.