window_size_utils.dart 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright 2019 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import 'dart:async';
  15. import 'dart:ui';
  16. import 'platform_window.dart';
  17. import 'screen.dart';
  18. import 'window_size_channel.dart';
  19. /// Returns a list of [Screen]s for the current screen configuration.
  20. ///
  21. /// It is possible for this list to be empty, if the machine is running in
  22. /// a headless mode.
  23. Future<List<Screen>> getScreenList() async {
  24. return await WindowSizeChannel.instance.getScreenList();
  25. }
  26. /// Returns the [Screen] showing the window that contains this Flutter instance.
  27. ///
  28. /// If the window is not being displayed, returns null. If the window is being
  29. /// displayed on multiple screens, the platform can return any of those screens.
  30. Future<Screen?> getCurrentScreen() async {
  31. final windowInfo = await WindowSizeChannel.instance.getWindowInfo();
  32. return windowInfo.screen;
  33. }
  34. /// Returns information about the window containing this Flutter instance.
  35. Future<PlatformWindow> getWindowInfo() async {
  36. return await WindowSizeChannel.instance.getWindowInfo();
  37. }
  38. /// Sets the frame of the window containing this Flutter instance, in
  39. /// screen coordinates.
  40. ///
  41. /// The platform may adjust the frame as necessary if the provided frame would
  42. /// cause significant usability issues (e.g., a window with no visible portion
  43. /// that can be used to move the window).
  44. void setWindowFrame(Rect frame) async {
  45. WindowSizeChannel.instance.setWindowFrame(frame);
  46. }
  47. /// Sets the minimum [Size] of the window containing this Flutter instance.
  48. void setWindowMinSize(Size size) async {
  49. WindowSizeChannel.instance.setWindowMinSize(size);
  50. }
  51. /// Sets the maximum [Size] of the window containing this Flutter instance.
  52. void setWindowMaxSize(Size size) async {
  53. WindowSizeChannel.instance.setWindowMaxSize(size);
  54. }
  55. /// Sets the window title, as a [String], of the window containing this Flutter instance.
  56. void setWindowTitle(String title) async {
  57. WindowSizeChannel.instance.setWindowTitle(title);
  58. }
  59. /// Shows or hides the window.
  60. void setWindowVisibility({required bool visible}) async {
  61. WindowSizeChannel.instance.setWindowVisibility(visible: visible);
  62. }
  63. /// Sets the window title's represented [Uri], of the window containing this Flutter instance.
  64. ///
  65. /// Only implemented for macOS. If the URL is a file URL, the
  66. /// window shows an icon in its title bar.
  67. void setWindowTitleRepresentedUrl(Uri url) async {
  68. WindowSizeChannel.instance.setWindowTitleRepresentedUrl(url);
  69. }
  70. /// Gets the minimum [Size] of the window containing this Flutter instance.
  71. Future<Size> getWindowMinSize() async {
  72. return WindowSizeChannel.instance.getWindowMinSize();
  73. }
  74. /// Gets the maximum [Size] of the window containing this Flutter instance.
  75. Future<Size> getWindowMaxSize() async {
  76. return WindowSizeChannel.instance.getWindowMaxSize();
  77. }