Skip to content
Closed
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
15 changes: 15 additions & 0 deletions packages/window_manager/lib/src/window_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ abstract mixin class WindowListener {
/// Emitted when the window leaves a full-screen state.
void onWindowLeaveFullScreen() {}

/// Emitted when the taskbar created.
///
/// @platforms windows
void onWindowTaskbarCreated() {}

/// Emitted when the device is going to shutdown.
///
/// @platforms windows
void onWindowDeviceShutdown() {}

/// Emitted when the user is logoff.
///
/// @platforms windows
void onWindowUserSessionDisconnect() {}

/// Emitted when the window entered a docked state.
///
/// @platforms windows
Expand Down
8 changes: 7 additions & 1 deletion packages/window_manager/lib/src/window_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const kWindowEventMove = 'move';
const kWindowEventMoved = 'moved';
const kWindowEventEnterFullScreen = 'enter-full-screen';
const kWindowEventLeaveFullScreen = 'leave-full-screen';

const kWindowEventTaskbarCreated = 'taskbar-created';
const kWindowEventDeviceShutdown = 'device-shutdown';
const kWindowEventUserSessionDisconnect = 'user-session-disconnect';
const kWindowEventDocked = 'docked';
const kWindowEventUndocked = 'undocked';

Expand Down Expand Up @@ -69,6 +71,10 @@ class WindowManager {
kWindowEventMoved: listener.onWindowMoved,
kWindowEventEnterFullScreen: listener.onWindowEnterFullScreen,
kWindowEventLeaveFullScreen: listener.onWindowLeaveFullScreen,
kWindowEventTaskbarCreated: listener.onWindowTaskbarCreated,
kWindowEventDeviceShutdown: listener.onWindowDeviceShutdown,
kWindowEventUserSessionDisconnect:
listener.onWindowUserSessionDisconnect,
kWindowEventDocked: listener.onWindowDocked,
kWindowEventUndocked: listener.onWindowUndocked,
};
Expand Down
21 changes: 20 additions & 1 deletion packages/window_manager/windows/window_manager_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// This must be included before many other Windows headers.
#include <windows.h>
#include <WtsApi32.h>
#pragma comment(lib,"WtsApi32.lib")

#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
Expand Down Expand Up @@ -50,6 +52,10 @@ class WindowManagerPlugin : public flutter::Plugin {

// The ID of the WindowProc delegate registration.
int window_proc_id = -1;
// session
bool session_notification_registered = false;
// taskbar create
UINT WM_TASKBARCREATED = 0;

void WindowManagerPlugin::_EmitEvent(std::string eventName);
// Called for top-level WindowProc delegation.
Expand Down Expand Up @@ -117,6 +123,7 @@ WindowManagerPlugin::WindowManagerPlugin(
[this](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
return HandleWindowProc(hWnd, message, wParam, lParam);
});
WM_TASKBARCREATED = RegisterWindowMessageA("TaskbarCreated");
}

WindowManagerPlugin::~WindowManagerPlugin() {
Expand All @@ -139,7 +146,11 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
WPARAM wParam,
LPARAM lParam) {
std::optional<LRESULT> result = std::nullopt;

if(!session_notification_registered){
session_notification_registered = true;
WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION);
}

if (message == WM_DPICHANGED) {
window_manager->pixel_ratio_ =
(float)LOWORD(wParam) / USER_DEFAULT_SCREEN_DPI;
Expand Down Expand Up @@ -336,6 +347,14 @@ std::optional<LRESULT> WindowManagerPlugin::HandleWindowProc(HWND hWnd,
flutter::EncodableValue(true)}};
window_manager->SetAlwaysOnBottom(args);
}
} else if(WM_TASKBARCREATED == message){
_EmitEvent("taskbar-created");
} else if (WM_QUERYENDSESSION == message){
_EmitEvent("device-shutdown");
} else if(WM_WTSSESSION_CHANGE == message){
if(WTS_CONSOLE_DISCONNECT == wParam) {
_EmitEvent("user-session-disconnect");
}
}

return result;
Expand Down