-
Notifications
You must be signed in to change notification settings - Fork 605
Initial window size plugin (macOS) #362
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
Merged
stuartmorgan-g
merged 6 commits into
google:master
from
stuartmorgan-g:screen-size-plugin
May 1, 2019
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c5d208
Initial window size plugin, with just screen-fetching support; macOS …
stuartmorgan-g 7aa3d15
Fix testbed project issues due to earlier manual edit
stuartmorgan-g f7e9735
Complete initial plugin functionality
stuartmorgan-g 51d8418
Guard the plugin call in a platform check
stuartmorgan-g ca0922c
Format and typo cleanup
stuartmorgan-g f926623
Account for Cocoa using y-flipped coordinates
stuartmorgan-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .packages | ||
| pubspec.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include: ../../analysis_options.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #include "plugins/window_size/common/channel_constants.h" | ||
|
|
||
| namespace plugins_window_size { | ||
|
|
||
| const char kChannelName[] = "flutter/windowsize"; | ||
|
|
||
| const char kGetScreenListMethod[] = "getScreenList"; | ||
| const char kGetWindowInfoMethod[] = "getWindowInfo"; | ||
| const char kSetWindowFrameMethod[] = "setWindowFrame"; | ||
|
|
||
| const char kFrameKey[] = "frame"; | ||
| const char kVisibleFrameKey[] = "visibleFrame"; | ||
| const char kScaleFactorKey[] = "scaleFactor"; | ||
| const char kScreenKey[] = "screen"; | ||
|
|
||
| } // namespace plugins_window_size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| #ifndef PLUGINS_WINDOW_SIZE_COMMON_CHANNEL_CONSTANTS_H_ | ||
| #define PLUGINS_WINDOW_SIZE_COMMON_CHANNEL_CONSTANTS_H_ | ||
|
|
||
| namespace plugins_window_size { | ||
|
|
||
| // This file contains constants used in the platform channel, which are shared | ||
| // across all native platform implementations. | ||
|
|
||
| // The name of the plugin's platform channel. | ||
| extern const char kChannelName[]; | ||
|
|
||
| // The method name to request information about the available screens. | ||
| // | ||
| // Returns a list of screen info maps; see keys below. | ||
| extern const char kGetScreenListMethod[]; | ||
|
|
||
| // The method name to request information about the window containing the | ||
| // Flutter instance. | ||
| // | ||
| // Returns a list of window info maps; see keys below. | ||
| extern const char kGetWindowInfoMethod[]; | ||
|
|
||
| // The method name to set the frame of a window. | ||
| // | ||
| // Takes a frame array, as documented for the value of kFrameKey. | ||
| extern const char kSetWindowFrameMethod[]; | ||
|
|
||
| // Keys for screen and window maps returned by kGetScreenListMethod. | ||
|
|
||
| // The frame of a screen or window. The value is an array of four doubles: | ||
| // [left, top, width, height] | ||
| extern const char kFrameKey[]; | ||
|
|
||
| // The frame of a screen available for use by applications. The value format | ||
| // is the same as kFrameKey's. | ||
| // | ||
| // Only used for screens. | ||
| extern const char kVisibleFrameKey[]; | ||
|
|
||
| // The scale factor for a screen or window, as a double. | ||
| // | ||
| // This is the number of pixels per screen coordinate, and thus the ratio | ||
| // between sizes as seen by Flutter and sizes in native screen coordinates. | ||
| extern const char kScaleFactorKey[]; | ||
|
|
||
| // The screen containing this window, if any. The value is a screen map, or null | ||
| // if the window is not visible on a screen. | ||
| // | ||
| // Only used for windows. | ||
| // | ||
| // If a window is on multiple screens, it is up to the platform to decide which | ||
| // screen to report. | ||
| extern const char kScreenKey[]; | ||
|
|
||
| } // namespace plugins_window_size | ||
|
|
||
| #endif // PLUGINS_WINDOW_SIZE_COMMON_CHANNEL_CONSTANTS_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| import 'dart:ui'; | ||
|
|
||
| import 'screen.dart'; | ||
|
|
||
| /// Represents a window, containing information about its size, position, and | ||
| /// properties. | ||
| /// | ||
| /// TODO: Evaluate how to reconcile this with the highly mobile-centric Window | ||
| /// class in dart::ui | ||
| class PlatformWindow { | ||
| /// Create a new window. | ||
| PlatformWindow(this.frame, this.scaleFactor, this.screen); | ||
|
|
||
| /// The frame of the screen, in screen coordinates. | ||
| final Rect frame; | ||
|
|
||
| /// The number of pixels per screen coordinate for this screen. | ||
| final double scaleFactor; | ||
|
|
||
| /// The (or a) screen containing this window, if any. | ||
| final Screen screen; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| import 'dart:ui'; | ||
|
|
||
| /// Represents a screen, containing information about its size, position, and | ||
| /// properties. | ||
| class Screen { | ||
| /// Create a new screen. | ||
| Screen(this.frame, this.visibleFrame, this.scaleFactor); | ||
|
|
||
| /// The frame of the screen, in screen coordinates. | ||
| final Rect frame; | ||
|
|
||
| /// The portion of the screen's frame that is available for use by application | ||
| /// windows. E.g., on macOS, this excludes the menu bar. | ||
| final Rect visibleFrame; | ||
|
|
||
| /// The number of pixels per screen coordinate for this screen. | ||
| final double scaleFactor; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| import 'dart:async'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
|
|
||
| import 'platform_window.dart'; | ||
| import 'screen.dart'; | ||
|
|
||
| // Plugin channel constants. See common/channel_constants.h for details. | ||
| const String _windowSizeChannelName = 'flutter/windowsize'; | ||
| const String _getScreenListMethod = 'getScreenList'; | ||
| const String _getCurrentScreenMethod = 'getCurrentScreen'; | ||
| const String _getWindowInfoMethod = 'getWindowInfo'; | ||
| const String _setWindowFrameMethod = 'setWindowFrame'; | ||
| const String _frameKey = 'frame'; | ||
| const String _visibleFrameKey = 'visibleFrame'; | ||
| const String _scaleFactorKey = 'scaleFactor'; | ||
| const String _screenKey = 'screen'; | ||
|
|
||
| /// A singleton object that handles the interaction with the platform channel. | ||
| class WindowSizeChannel { | ||
| /// Private constructor. | ||
| WindowSizeChannel._(); | ||
|
|
||
| final MethodChannel _platformChannel = | ||
| const MethodChannel(_windowSizeChannelName); | ||
|
|
||
| /// The static instance of the menu channel. | ||
| static final WindowSizeChannel instance = new WindowSizeChannel._(); | ||
|
|
||
| /// Returns a list of screens. | ||
| Future<List<Screen>> getScreenList() async { | ||
| try { | ||
| final screenList = <Screen>[]; | ||
| final response = | ||
| await _platformChannel.invokeMethod(_getScreenListMethod); | ||
|
|
||
| for (final screenInfo in response) { | ||
| screenList.add(_screenFromInfoMap(screenInfo)); | ||
| } | ||
| return screenList; | ||
| } on PlatformException catch (e) { | ||
| print('Platform exception getting screen list: ${e.message}'); | ||
| } | ||
| return <Screen>[]; | ||
| } | ||
|
|
||
| /// Returns information about the window containing this Flutter instance. | ||
| Future<PlatformWindow> getWindowInfo() async { | ||
| try { | ||
| final response = | ||
| await _platformChannel.invokeMethod(_getWindowInfoMethod); | ||
|
|
||
| return PlatformWindow( | ||
| _rectFromLTWHList(response[_frameKey].cast<double>()), | ||
| response[_scaleFactorKey], | ||
| _screenFromInfoMap(response[_screenKey])); | ||
| } on PlatformException catch (e) { | ||
| print('Platform exception getting window info: ${e.message}'); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /// Sets the frame of the window containing this Flutter instance, in | ||
| /// screen coordinates. | ||
| /// | ||
| /// The platform may adjust the frame as necessary if the provided frame would | ||
| /// cause significant usability issues (e.g., a window with no visible portion | ||
| /// that can be used to move the window). | ||
| void setWindowFrame(Rect frame) async { | ||
| try { | ||
| await _platformChannel.invokeMethod(_setWindowFrameMethod, | ||
| [frame.left, frame.top, frame.width, frame.height]); | ||
| } on PlatformException catch (e) { | ||
| print('Platform exception setting window frame: ${e.message}'); | ||
| } | ||
| } | ||
|
|
||
| /// Given an array of the form [left, top, width, height], return the | ||
| /// corresponding [Rect]. | ||
| /// | ||
| /// Used for frame deserialization in the platform channel. | ||
| Rect _rectFromLTWHList(List<double> ltwh) { | ||
| return Rect.fromLTWH(ltwh[0], ltwh[1], ltwh[2], ltwh[3]); | ||
| } | ||
|
|
||
| /// Given a map of information about a screen, return the corresponding | ||
| /// [Screen] object, or null. | ||
| /// | ||
| /// Used for screen deserialization in the platform channel. | ||
| Screen _screenFromInfoMap(Map<dynamic, dynamic> map) { | ||
| if (map == null) { | ||
| return null; | ||
| } | ||
| return Screen( | ||
| _rectFromLTWHList(map[_frameKey].cast<double>()), | ||
| _rectFromLTWHList(map[_visibleFrameKey].cast<double>()), | ||
| map[_scaleFactorKey]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| import 'dart:async'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'platform_window.dart'; | ||
| import 'screen.dart'; | ||
| import 'window_size_channel.dart'; | ||
|
|
||
| /// Returns a list of [Screen]s for the current screen configuration. | ||
| /// | ||
| /// It is possible for this list to be empty, if the machine is running in | ||
| /// a headless mode. | ||
| Future<List<Screen>> getScreenList() async { | ||
| return await WindowSizeChannel.instance.getScreenList(); | ||
| } | ||
|
|
||
| /// Returns the [Screen] showing the window that contains this Flutter instance. | ||
| /// | ||
| /// If the window is not being displayed, returns null. If the window is being | ||
| /// displayed on multiple screens, the platform can return any of those screens. | ||
| Future<Screen> getCurrentScreen() async { | ||
| final windowInfo = await WindowSizeChannel.instance.getWindowInfo(); | ||
| return windowInfo.screen; | ||
| } | ||
|
|
||
| /// Returns information about the window containing this Flutter instance. | ||
| Future<PlatformWindow> getWindowInfo() async { | ||
| return await WindowSizeChannel.instance.getWindowInfo(); | ||
| } | ||
|
|
||
| /// Sets the frame of the window containing this Flutter instance, in | ||
| /// screen coordinates. | ||
| /// | ||
| /// The platform may adjust the frame as necessary if the provided frame would | ||
| /// cause significant usability issues (e.g., a window with no visible portion | ||
| /// that can be used to move the window). | ||
| void setWindowFrame(Rect frame) async { | ||
| WindowSizeChannel.instance.setWindowFrame(frame); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright 2019 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| export 'src/platform_window.dart'; | ||
| export 'src/screen.dart'; | ||
| export 'src/window_size_utils.dart'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright 2018 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #import <Foundation/Foundation.h> | ||
|
|
||
| #import <FlutterMacOS/FlutterMacOS.h> | ||
|
|
||
| /** | ||
| * A FlutterPlugin to manage macOS's shared NSColorPanel singleton. | ||
| * Responsible for managing the panel's display state and sending selected color data to Flutter. | ||
| */ | ||
| @interface FLEWindowSizePlugin : NSObject <FLEPlugin, NSWindowDelegate> | ||
|
|
||
| @end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.