Skip to content

Commit 3f5043f

Browse files
robert-ancellahmedsameha1
authored andcommitted
Allow windows to be created undecorated (flutter#179859)
This will be useful when we want to render all the window decorations using Flutter. Fixes flutter#183557
1 parent cfd9f58 commit 3f5043f

10 files changed

Lines changed: 113 additions & 1 deletion

File tree

‎examples/multiple_windows/lib/app/dialog_window_content.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class DialogWindowContent extends StatelessWidget {
4444
),
4545
parent: window,
4646
title: 'Dialog',
47+
decorated: windowSettings.dialogDecorated,
4748
),
4849
),
4950
);

‎examples/multiple_windows/lib/app/main_window.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ class _WindowCreatorCard extends StatelessWidget {
243243
),
244244
title: 'Modeless Dialog',
245245
preferredSize: windowSettings.dialogSize,
246+
decorated: windowSettings.dialogDecorated,
246247
),
247248
),
248249
);

‎examples/multiple_windows/lib/app/models.dart‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class WindowSettings {
8888
parentAnchor: WindowPositionerAnchor.right,
8989
childAnchor: WindowPositionerAnchor.left,
9090
),
91+
this.regularDecorated = true,
92+
this.dialogDecorated = true,
9193
});
9294

9395
/// The initial size for newly created regular windows.
@@ -98,6 +100,12 @@ class WindowSettings {
98100

99101
/// The positioner used to determine where new tooltips and popups are placed.
100102
WindowPositioner positioner;
103+
104+
/// True if regular windows are decorated.
105+
bool regularDecorated;
106+
107+
/// True if dialog windows are decorated.
108+
bool dialogDecorated;
101109
}
102110

103111
/// Provides access to the [WindowSettings] from the widget tree.

‎examples/multiple_windows/lib/app/regular_window_content.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class RegularWindowContent extends StatelessWidget {
6565
onDestroyed: () => windowManager.remove(key),
6666
),
6767
title: 'Regular',
68+
decorated: windowSettings.regularDecorated,
6869
),
6970
),
7071
);
@@ -85,6 +86,7 @@ class RegularWindowContent extends StatelessWidget {
8586
),
8687
parent: window,
8788
title: 'Dialog',
89+
decorated: windowSettings.dialogDecorated,
8890
),
8991
),
9092
);

‎examples/multiple_windows/lib/app/window_settings_dialog.dart‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ class _WindowSettingsEditorState extends State<_WindowSettingsEditor> {
128128
decoration: const InputDecoration(labelText: 'Initial height'),
129129
),
130130
),
131+
const SizedBox(height: 20),
132+
Row(
133+
children: [
134+
Text('Decorations'),
135+
const SizedBox(width: 10),
136+
Switch(
137+
value: widget.settings.regularDecorated,
138+
onChanged: (bool value) {
139+
setState(() {
140+
widget.settings.regularDecorated = value;
141+
});
142+
},
143+
),
144+
],
145+
),
131146
],
132147
),
133148
);
@@ -151,6 +166,21 @@ class _WindowSettingsEditorState extends State<_WindowSettingsEditor> {
151166
decoration: const InputDecoration(labelText: 'Initial height'),
152167
),
153168
),
169+
const SizedBox(height: 20),
170+
Row(
171+
children: [
172+
Text('Decorations'),
173+
const SizedBox(width: 10),
174+
Switch(
175+
value: widget.settings.dialogDecorated,
176+
onChanged: (bool value) {
177+
setState(() {
178+
widget.settings.dialogDecorated = value;
179+
});
180+
},
181+
),
182+
],
183+
),
154184
],
155185
),
156186
);

‎packages/flutter/lib/src/widgets/_window.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ abstract class RegularWindowController extends BaseWindowController {
218218
/// The [title] argument configures the window's initial title.
219219
/// If omitted, some platforms might fall back to the app's name.
220220
///
221+
/// The [decorated] argument configures whether the window has decorations
222+
/// such as title bar, borders, etc. If false, the user should provide their
223+
/// own decorations.
224+
///
221225
/// The [delegate] argument can be used to listen to the window's
222226
/// lifecycle. For example, it can be used to save state before
223227
/// a window is closed.
@@ -228,6 +232,7 @@ abstract class RegularWindowController extends BaseWindowController {
228232
Size? preferredSize,
229233
BoxConstraints? preferredConstraints,
230234
String? title,
235+
bool decorated = true,
231236
RegularWindowControllerDelegate? delegate,
232237
}) {
233238
if (!isWindowingEnabled) {
@@ -244,6 +249,7 @@ abstract class RegularWindowController extends BaseWindowController {
244249
preferredSize: preferredSize,
245250
preferredConstraints: preferredConstraints,
246251
title: title,
252+
decorated: decorated,
247253
);
248254
}
249255

@@ -505,6 +511,10 @@ abstract class DialogWindowController extends BaseWindowController {
505511
/// The [title] argument configures the window's initial title.
506512
/// If omitted, some platforms might fall back to the app's name.
507513
///
514+
/// The [decorated] argument configures whether the window has decorations
515+
/// such as title bar, borders, etc. If false, the user should provide their
516+
/// own decorations.
517+
///
508518
/// The [delegate] argument can be used to listen to the window's
509519
/// lifecycle. For example, it can be used to save state before
510520
/// a window is closed.
@@ -515,6 +525,7 @@ abstract class DialogWindowController extends BaseWindowController {
515525
BoxConstraints? preferredConstraints,
516526
BaseWindowController? parent,
517527
String? title,
528+
bool decorated = true,
518529
DialogWindowControllerDelegate? delegate,
519530
}) {
520531
WidgetsFlutterBinding.ensureInitialized();
@@ -524,6 +535,7 @@ abstract class DialogWindowController extends BaseWindowController {
524535
preferredSize: preferredSize,
525536
preferredConstraints: preferredConstraints,
526537
title: title,
538+
decorated: decorated,
527539
parent: parent,
528540
);
529541
}
@@ -1152,6 +1164,7 @@ abstract class WindowingOwner {
11521164
Size? preferredSize,
11531165
BoxConstraints? preferredConstraints,
11541166
String? title,
1167+
bool decorated = true,
11551168
});
11561169

11571170
/// Creates a [DialogWindowController] with the provided properties.
@@ -1168,6 +1181,7 @@ abstract class WindowingOwner {
11681181
BoxConstraints? preferredConstraints,
11691182
BaseWindowController? parent,
11701183
String? title,
1184+
bool decorated = true,
11711185
});
11721186

11731187
/// Creates a [TooltipWindowController] with the provided properties.
@@ -1251,6 +1265,7 @@ class _WindowingOwnerUnsupported extends WindowingOwner {
12511265
Size? preferredSize,
12521266
BoxConstraints? preferredConstraints,
12531267
String? title,
1268+
bool decorated = true,
12541269
}) {
12551270
throw UnsupportedError(errorMessage);
12561271
}
@@ -1262,6 +1277,7 @@ class _WindowingOwnerUnsupported extends WindowingOwner {
12621277
BoxConstraints? preferredConstraints,
12631278
BaseWindowController? parent,
12641279
String? title,
1280+
bool decorated = true,
12651281
}) {
12661282
throw UnsupportedError(errorMessage);
12671283
}

‎packages/flutter/lib/src/widgets/_window_linux.dart‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class WindowingOwnerLinux extends WindowingOwner {
9090
Size? preferredSize,
9191
BoxConstraints? preferredConstraints,
9292
String? title,
93+
bool decorated = true,
9394
required RegularWindowControllerDelegate delegate,
9495
}) {
9596
final controller = RegularWindowControllerLinux(
@@ -98,6 +99,7 @@ class WindowingOwnerLinux extends WindowingOwner {
9899
preferredSize: preferredSize,
99100
preferredConstraints: preferredConstraints,
100101
title: title,
102+
decorated: decorated,
101103
);
102104
_windows[controller.rootView.viewId] = controller._window;
103105
return controller;
@@ -111,6 +113,7 @@ class WindowingOwnerLinux extends WindowingOwner {
111113
BoxConstraints? preferredConstraints,
112114
BaseWindowController? parent,
113115
String? title,
116+
bool decorated = true,
114117
}) {
115118
final controller = DialogWindowControllerLinux(
116119
owner: this,
@@ -119,6 +122,7 @@ class WindowingOwnerLinux extends WindowingOwner {
119122
preferredConstraints: preferredConstraints,
120123
parent: parent,
121124
title: title,
125+
decorated: decorated,
122126
);
123127
_windows[controller.rootView.viewId] = controller._window;
124128
return controller;
@@ -189,6 +193,7 @@ class RegularWindowControllerLinux extends RegularWindowController {
189193
Size? preferredSize,
190194
BoxConstraints? preferredConstraints,
191195
String? title,
196+
bool decorated = true,
192197
}) : _owner = owner,
193198
_delegate = delegate,
194199
_window = _GtkWindow(_GtkWindowType.toplevel),
@@ -217,6 +222,7 @@ class RegularWindowControllerLinux extends RegularWindowController {
217222
if (title != null) {
218223
setTitle(title);
219224
}
225+
_window.setDecorated(decorated);
220226
final engine = _FlEngine.current();
221227
final view = _FlView(engine);
222228
final int viewId = view.getId();
@@ -358,6 +364,7 @@ class DialogWindowControllerLinux extends DialogWindowController {
358364
BoxConstraints? preferredConstraints,
359365
BaseWindowController? parent,
360366
String? title,
367+
bool decorated = true,
361368
}) : _owner = owner,
362369
_delegate = delegate,
363370
_parent = parent,
@@ -396,6 +403,7 @@ class DialogWindowControllerLinux extends DialogWindowController {
396403
if (title != null) {
397404
setTitle(title);
398405
}
406+
_window.setDecorated(decorated);
399407
final engine = _FlEngine.current();
400408
final view = _FlView(engine);
401409
final int viewId = view.getId();
@@ -734,6 +742,11 @@ class _GtkWindow extends _GtkContainer {
734742
_gtkWindowSetTypeHint(instance, hint.index);
735743
}
736744

745+
/// Sets if this window has decorations (titlebar, borders, shadow).
746+
void setDecorated(bool decorated) {
747+
_gtkWindowSetDecorated(instance, decorated);
748+
}
749+
737750
/// Sets the title of the window.
738751
void setTitle(String title) {
739752
final ffi.Pointer<ffi.Uint8> titleBuffer = _stringToNative(title);
@@ -855,6 +868,11 @@ class _GtkWindow extends _GtkContainer {
855868
ffi.Pointer<ffi.Uint8> title,
856869
);
857870

871+
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.NativeType>, ffi.Bool)>(
872+
symbol: 'gtk_window_set_decorated',
873+
)
874+
external static void _gtkWindowSetDecorated(ffi.Pointer<ffi.NativeType> window, bool decorated);
875+
858876
@ffi.Native<ffi.Pointer<ffi.Uint8> Function(ffi.Pointer<ffi.NativeType>)>(
859877
symbol: 'gtk_window_get_title',
860878
)

‎packages/flutter/lib/src/widgets/_window_macos.dart‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ class WindowingOwnerMacOS extends WindowingOwner {
8080
Size? preferredSize,
8181
BoxConstraints? preferredConstraints,
8282
String? title,
83+
bool decorated = true,
8384
}) {
8485
final res = RegularWindowControllerMacOS(
8586
owner: this,
8687
delegate: delegate,
8788
preferredSize: preferredSize,
8889
title: title,
90+
decorated: decorated,
8991
);
9092
_activeControllers.add(res);
9193
return res;
@@ -98,13 +100,15 @@ class WindowingOwnerMacOS extends WindowingOwner {
98100
BoxConstraints? preferredConstraints,
99101
BaseWindowController? parent,
100102
String? title,
103+
bool decorated = true,
101104
}) {
102105
final res = DialogWindowControllerMacOS(
103106
owner: this,
104107
delegate: delegate,
105108
preferredSize: preferredSize,
106109
parent: parent,
107110
title: title,
111+
decorated: decorated,
108112
);
109113
_activeControllers.add(res);
110114
return res;
@@ -141,7 +145,7 @@ class WindowingOwnerMacOS extends WindowingOwner {
141145
required WindowPositioner positioner,
142146
required BaseWindowController parent,
143147
}) {
144-
throw UnimplementedError('Popup windows are not yet implemented on MacOS.');
148+
throw UnimplementedError('Popup windows are not yet implemented on macOS.');
145149
}
146150

147151
final List<_WindowControllerMixin> _activeControllers = <_WindowControllerMixin>[];
@@ -376,8 +380,15 @@ class RegularWindowControllerMacOS extends RegularWindowController with _WindowC
376380
required Size? preferredSize,
377381
BoxConstraints? preferredConstraints,
378382
String? title,
383+
bool decorated = true,
379384
}) : _delegate = delegate,
380385
super.empty() {
386+
if (!decorated) {
387+
// TODO(team-macos): Implement undecorated windows on macOS.
388+
// See https://github.com/flutter/flutter/issues/183560
389+
throw UnimplementedError('Undecorated windows are not yet implemented on macOS.');
390+
}
391+
381392
_initController(owner);
382393

383394
final int viewId = _MacOSPlatformInterface.createRegularWindow(
@@ -511,8 +522,15 @@ class DialogWindowControllerMacOS extends DialogWindowController with _WindowCon
511522
this.parent,
512523
BoxConstraints? preferredConstraints,
513524
String? title,
525+
bool decorated = true,
514526
}) : _delegate = delegate,
515527
super.empty() {
528+
if (!decorated) {
529+
// TODO(team-macos): Implement undecorated windows on macOS.
530+
// See https://github.com/flutter/flutter/issues/183560
531+
throw UnimplementedError('Undecorated windows are not yet implemented on macOS.');
532+
}
533+
516534
_initController(owner);
517535

518536
final int viewId = _MacOSPlatformInterface.createDialogWindow(

0 commit comments

Comments
 (0)