Ocideck/third_party/desktop_multi_window/windows/flutter_window.cc
Brenno de Winter 2aca44365a Add dual-screen presenter mode (slide on beamer, notes on laptop)
When a second display is connected (macOS), presenting now opens a
borderless audience window on the beamer showing the slide, while the
main window shows the presenter view (current/next slide, speaker notes,
clock, controls) on the laptop. The two windows stay in sync over method
channels: navigation, blank screen, audio-complete and beamer clicks are
forwarded between them, and media plays only on the beamer to avoid
double audio. Falls back to the existing single-window presenter when
there is one display or the second window can't be created.

- Vendors a fork of desktop_multi_window in third_party/ that re-adds the
  native macOS window geometry/fullscreen calls (coverScreen, setFrame,
  close) the published 0.3.0 dropped; wired via a path dependency.
- Registers the app's plugins for sub-windows in MainFlutterWindow so
  video/image rendering works on the beamer.
- Routes the multi_window dart entrypoint to a minimal AudienceWindowApp.

Compiles (flutter analyze + macOS debug build) and all tests pass;
runtime two-screen behaviour still needs verification on real hardware.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-06 21:25:34 +02:00

71 lines
2.2 KiB
C++

#include "flutter_window.h"
#include "flutter_windows.h"
#include "tchar.h"
#include <iostream>
#include "multi_window_manager.h"
#include "multi_window_plugin_internal.h"
FlutterWindow::FlutterWindow(const std::string& id,
const WindowConfiguration config)
: id_(id), window_argument_(config.arguments) {}
bool FlutterWindow::OnCreate() {
// Called when the window is created
RECT frame = GetClientArea();
flutter::DartProject project(L"data");
std::vector<std::string> entrypoint_args = {"multi_window", id_,
window_argument_};
project.set_dart_entrypoint_arguments(entrypoint_args);
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project);
// Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
std::cerr << "Failed to setup FlutterViewController." << std::endl;
return false;
}
auto view_handle = flutter_controller_->view()->GetNativeWindow();
SetChildContent(view_handle);
return true;
}
void FlutterWindow::OnDestroy() {
if (flutter_controller_) {
flutter_controller_ = nullptr;
}
MultiWindowManager::Instance()->RemoveManagedFlutterWindowLater(id_);
}
LRESULT FlutterWindow::MessageHandler(HWND hwnd,
UINT const message,
WPARAM const wparam,
LPARAM const lparam) noexcept {
// Give Flutter, including plugins, an opportunity to handle window messages.
if (flutter_controller_) {
std::optional<LRESULT> result =
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
lparam);
if (result) {
return *result;
}
}
switch (message) {
case WM_FONTCHANGE:
flutter_controller_->engine()->ReloadSystemFonts();
break;
}
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
}
FlutterWindow::~FlutterWindow() {
// Cleanup is handled by Win32Window::Destroy()
}