Skip to content

WIP [desktop_multi_window | macOS and Windows]: window creation options, window events, window options #400

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d26dada
added windows window creation options
krjw-eyev Feb 26, 2025
1c4675c
finished CreateWindowEx implementation for Windows
krjw-eyev Feb 26, 2025
da19039
added macOS window options to support NSPanel
krjw-eyev Feb 28, 2025
ce927bf
implemented window events
krjw-eyev Mar 4, 2025
e6b02c4
fixed some stuff
krjw-eyev Mar 4, 2025
21e69d3
added setting window style on macos
krjw-eyev Mar 4, 2025
1fe9a42
added windows stuff
krjw-eyev Mar 16, 2025
dc79026
added backgroundColor support for windows
krjw-eyev Mar 16, 2025
b722878
fixed styles although i am not sure the negative stuff really works
krjw-eyev Mar 16, 2025
665b921
added support for setting frame without changing either size or position
krjw-eyev Mar 17, 2025
c81618e
added absolute mouse position event
krjw-eyev Mar 18, 2025
31b729a
fixing mouse hook
krjw-eyev Mar 19, 2025
7b9b77c
added onShow and onHide events
krjw-eyev Mar 20, 2025
0289bf1
added some stuff for macos
krjw-eyev Mar 21, 2025
b6b1e4f
added devicePixelRatio
krjw-eyev Mar 24, 2025
1458c12
added mouse events for macos
krjw-eyev Mar 25, 2025
5d97189
better locking
krjw-eyev Mar 28, 2025
5425cf8
removed prints
krjw-eyev Mar 28, 2025
41c83af
updated window controller to handle device pixel ratio for position a…
krjw-eyev Mar 28, 2025
d6d972a
remove window class background
krjw-eyev Mar 28, 2025
2f91ba4
preventing memory leak
krjw-eyev Mar 28, 2025
e42cefe
Merge branch 'MixinNetwork:main' into feature-window-creation-options
krjw-eyev Mar 28, 2025
3fde76b
added script to test uiaccess=true
krjw-eyev May 14, 2025
d89d529
only embed manifest with uiaccess=true if in release mode
krjw-eyev May 14, 2025
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
7 changes: 6 additions & 1 deletion packages/desktop_multi_window/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
Expand All @@ -27,3 +27,8 @@
.dart_tool/
.packages
build/

.editorconfig

# FVM Version Cache
.fvm/
2 changes: 2 additions & 0 deletions packages/desktop_multi_window/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

FlutterUIAccessTestCert.pfx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# At the top of your script
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell -Verb RunAs -ArgumentList "-NoExit", "-ExecutionPolicy Bypass", "-File `"$PSCommandPath`""
exit
}

# Ensure we're in the project directory
Set-Location -Path "$PSScriptRoot"

# Paths and names
$flutterAppDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$buildDir = "$flutterAppDir\build\windows\x64\runner\Release"
$buildExe = "$buildDir\desktop_multi_window_example.exe"
$certSubject = "CN=FlutterUIAccessTestCert"
$certName = "FlutterUIAccessTestCert"
$certPath = "$flutterAppDir\$certName.pfx"
$secureInstallDir = "C:\Program Files\desktop_multi_window_example App dev"
$signedExe = "$secureInstallDir\desktop_multi_window_example.exe"

# Build the Flutter app
flutter build windows --release
if (-Not (Test-Path $buildExe)) {
Write-Error "Build failed or desktop_multi_window_example.exe not found."
exit 1
}

# Create and trust self-signed cert if needed
if (-Not (Test-Path $certPath)) {
Write-Host "Creating self-signed cert..."
$cert = New-SelfSignedCertificate -Type CodeSigningCert -Subject $certSubject -CertStoreLocation "Cert:\CurrentUser\My"
$pwd = ConvertTo-SecureString -String "password" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath $certPath -Password $pwd
Import-PfxCertificate -FilePath $certPath -CertStoreLocation Cert:\CurrentUser\TrustedPublisher -Password $pwd
Import-PfxCertificate -FilePath $certPath -CertStoreLocation Cert:\CurrentUser\Root -Password $pwd
}

# Copy full build folder to secure location
if (Test-Path $secureInstallDir) {
Remove-Item $secureInstallDir -Recurse -Force
}
Copy-Item -Path $buildDir -Destination $secureInstallDir -Recurse

# Sign the executable
$timestampUrl = "http://timestamp.digicert.com"
& "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe" sign `
/f $certPath `
/p "password" `
/fd sha256 `
/tr $timestampUrl `
/td sha256 `
$signedExe

# Sign all DLLs in the secure install directory
Get-ChildItem -Path $secureInstallDir -Filter *.dll -Recurse | ForEach-Object {
& "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe" sign `
/f $certPath `
/p "password" `
/fd sha256 `
/tr $timestampUrl `
/td sha256 `
$_.FullName
}

# Run the signed app
Start-Process -FilePath "explorer.exe" -ArgumentList "`"$signedExe`""

# Validate manifest
# mt.exe "-inputresource:build\windows\x64\runner\Release\example.exe;#1" -out:example_out_manifest
120 changes: 89 additions & 31 deletions packages/desktop_multi_window/example/lib/event_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class MessageItem {

class _EventWidgetState extends State<EventWidget> {
final messages = <MessageItem>[];
int? _selectedWindowId;
List<int> _windowIds = [0];

final textInputController = TextEditingController();

Expand All @@ -49,6 +51,7 @@ class _EventWidgetState extends State<EventWidget> {
@override
void initState() {
super.initState();
_updateWindowIds();
DesktopMultiWindow.setMethodHandler(_handleMethodCallback);
}

Expand All @@ -58,8 +61,18 @@ class _EventWidgetState extends State<EventWidget> {
super.dispose();
}

Future<dynamic> _handleMethodCallback(
MethodCall call, int fromWindowId) async {
Future<void> _updateWindowIds() async {
// Get all sub-window IDs
final List<int> subWindowIds = await DesktopMultiWindow.getAllSubWindowIds();
setState(() {
// Combine main window (0) with sub-window IDs
_windowIds = [0, ...subWindowIds];
// Set default selection if none selected
_selectedWindowId ??= _windowIds.first;
});
}

Future<dynamic> _handleMethodCallback(MethodCall call, int fromWindowId) async {
if (call.arguments.toString() == "ping") {
return "pong";
}
Expand All @@ -82,11 +95,13 @@ class _EventWidgetState extends State<EventWidget> {
if (text.isEmpty) {
return;
}
final windowId = int.tryParse(windowInputController.text);
textInputController.clear();
final result =
await DesktopMultiWindow.invokeMethod(windowId!, "onSend", text);
debugPrint("onSend result: $result");
if (_selectedWindowId != null) {
textInputController.clear();
final result = await DesktopMultiWindow.invokeMethod(_selectedWindowId!, "onSend", text);
debugPrint("onSend result: $result");
} else {
debugPrint("No window selected");
}
}

return Column(
Expand All @@ -95,36 +110,79 @@ class _EventWidgetState extends State<EventWidget> {
child: ListView.builder(
itemCount: messages.length,
reverse: true,
itemBuilder: (context, index) =>
_MessageItemWidget(item: messages[index]),
itemBuilder: (context, index) => _MessageItemWidget(item: messages[index]),
),
),
Row(
children: [
SizedBox(
width: 100,
child: TextField(
controller: windowInputController,
decoration: const InputDecoration(
labelText: 'Window ID',
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 4,
offset: const Offset(0, -1),
),
],
),
child: Row(
children: [
const Text('To: '),
MouseRegion(
cursor: SystemMouseCursors.click,
child: DropdownButton<int>(
value: _selectedWindowId,
items: _windowIds.map((int id) {
return DropdownMenuItem<int>(
value: id,
child: Text(id == 0 ? 'Main Window' : 'Window $id'),
);
}).toList(),
onTap: () {
// Update window list before showing dropdown
_updateWindowIds();
},
onChanged: (int? newValue) {
setState(() {
_selectedWindowId = newValue;
});
},
),
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
),
),
Expanded(
child: TextField(
controller: textInputController,
decoration: const InputDecoration(
hintText: 'Enter message',
const SizedBox(width: 16),
Expanded(
child: TextField(
controller: textInputController,
decoration: InputDecoration(
hintText: 'Enter message',
filled: true,
fillColor: Theme.of(context).colorScheme.surface,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.outline,
),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onSubmitted: (text) => submit(),
),
onSubmitted: (text) => submit(),
),
),
IconButton(
icon: const Icon(Icons.send),
onPressed: submit,
),
],
const SizedBox(width: 8),
IconButton(
icon: const Icon(Icons.send),
onPressed: submit,
tooltip: 'Send message',
style: IconButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
foregroundColor: Theme.of(context).colorScheme.onPrimaryContainer,
),
),
],
),
),
],
);
Expand Down
Loading