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] Add minimized/maximized stream event #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const String kNotifyFirstFrameRasterizedMethodName =
const String kWindowMovedMethodName = 'windowMoved';
const String kWindowResizedMethodName = 'windowResized';
const String kWindowActivatedMethodName = 'windowActivated';
const String kWindowMinimizedMethodName = 'windowMinimized';
const String kWindowMaximizedMethodName = 'windowMaximized';

// GTK Exclusives:

Expand Down
36 changes: 30 additions & 6 deletions lib/src/platform/win32_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ class Win32Window extends PlatformWindow {
}
break;
}
case kWindowMinimizedMethodName:
{
try {
minimizedStreamController.add(await minimized);
} on AssertionError catch (_) {
// NOTE: [WindowsPlus.instance.hwnd] is `0` during fresh start until [WindowPlus.ensureInitialized] resolves.
} catch (exception, stacktrace) {
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
break;
}
case kWindowMaximizedMethodName:
{
try {
maximizedStreamController.add(await maximized);
} on AssertionError catch (_) {
// NOTE: [WindowsPlus.instance.hwnd] is `0` during fresh start until [WindowPlus.ensureInitialized] resolves.
} catch (exception, stacktrace) {
debugPrint(exception.toString());
debugPrint(stacktrace.toString());
}
break;
}
case kWindowMovedMethodName:
{
try {
Expand Down Expand Up @@ -316,16 +340,16 @@ class Win32Window extends PlatformWindow {
while (next_hwnd != hwnd) {
if (IsWindowVisible(next_hwnd) == TRUE) {
final cloaked = calloc<Int>();
final dwmWindowAttribute = DwmGetWindowAttribute(next_hwnd,
DWMWINDOWATTRIBUTE.DWMWA_CLOAKED,
cloaked,
final dwmWindowAttribute = DwmGetWindowAttribute(
next_hwnd,
DWMWINDOWATTRIBUTE.DWMWA_CLOAKED,
cloaked,
sizeOf<Int>(),
);
if (dwmWindowAttribute != S_OK)
{
if (dwmWindowAttribute != S_OK) {
cloaked.value = 0;
}
if (cloaked.value == 0){
if (cloaked.value == 0) {
SetForegroundWindow(next_hwnd);
free(cloaked);
return;
Expand Down
2 changes: 2 additions & 0 deletions windows/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ static constexpr auto kNotifyFirstFrameRasterizedMethodName =
static constexpr auto kWindowMovedMethodName = "windowMoved";
static constexpr auto kWindowResizedMethodName = "windowResized";
static constexpr auto kWindowActivatedMethodName = "windowActivated";
static constexpr auto kWindowMinimizedMethodName = "windowMinimized";
static constexpr auto kWindowMaximizedMethodName = "windowMaximized";
static constexpr auto kSingleInstanceDataReceivedMethodName =
"singleInstanceDataReceived";
static constexpr auto kWindows10RTM = 10240;
Expand Down
56 changes: 56 additions & 0 deletions windows/window_plus_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,34 @@ std::optional<HRESULT> WindowPlusPlugin::WindowProcDelegate(
AlignChildContent();
// Notify Flutter.
if (enable_event_streams_) {
switch (wparam)
{
case SIZE_MINIMIZED:
minimized_ = true;
maximized_ = false;
channel_->InvokeMethod(kWindowMinimizedMethodName, nullptr, nullptr);
return 0;
case SIZE_MAXIMIZED:
maximized_ = true;
if (minimized_) {
minimized_ = false;
channel_->InvokeMethod(kWindowMinimizedMethodName, nullptr, nullptr);
}
channel_->InvokeMethod(kWindowMaximizedMethodName, nullptr, nullptr);
break;
case SIZE_RESTORED:
if (minimized_) {
minimized_ = false;
channel_->InvokeMethod(kWindowMinimizedMethodName, nullptr, nullptr);
}
else if (maximized_) {
maximized_ = false;
channel_->InvokeMethod(kWindowMaximizedMethodName, nullptr, nullptr);
}
break;
default:
break;
}
channel_->InvokeMethod(kWindowResizedMethodName, nullptr, nullptr);
}
return 0;
Expand Down Expand Up @@ -476,6 +504,34 @@ std::optional<HRESULT> WindowPlusPlugin::FallbackWindowProcDelegate(
AlignChildContent();
// Notify Flutter.
if (enable_event_streams_) {
switch (wparam)
{
case SIZE_MINIMIZED:
minimized_ = true;
maximized_ = false;
channel_->InvokeMethod(kWindowMinimizedMethodName, nullptr, nullptr);
return 0;
case SIZE_MAXIMIZED:
maximized_ = true;
if (minimized_) {
minimized_ = false;
channel_->InvokeMethod(kWindowMinimizedMethodName, nullptr, nullptr);
}
channel_->InvokeMethod(kWindowMaximizedMethodName, nullptr, nullptr);
break;
case SIZE_RESTORED:
if (minimized_) {
minimized_ = false;
channel_->InvokeMethod(kWindowMinimizedMethodName, nullptr, nullptr);
}
else if (maximized_) {
maximized_ = false;
channel_->InvokeMethod(kWindowMaximizedMethodName, nullptr, nullptr);
}
break;
default:
break;
}
channel_->InvokeMethod(kWindowResizedMethodName, nullptr, nullptr);
}
return 0;
Expand Down
2 changes: 2 additions & 0 deletions windows/window_plus_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class WindowPlusPlugin : public flutter::Plugin {
bool enable_custom_frame_ = false;
bool enable_event_streams_ = false;
bool first_frame_rasterized_ = false;
bool minimized_ = false;
bool maximized_ = false;
// DO NOT ACCESS THIS MEMBER DIRECTLY. Use |GetMonitors| instead.
std::vector<HMONITOR> monitors_ = {};
};
Expand Down