From 028b43fde38d410bd5a94b3222c74c4d357bbd01 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Sat, 17 Sep 2022 10:52:11 +0900 Subject: [PATCH] [joystick] update for flutter 3.3.0 release (#55) Signed-off-by: Hidenori Matsubayashi --- packages/joystick/CHANGELOG.md | 3 + packages/joystick/elinux/joystick_plugin.cc | 2 +- packages/joystick/elinux/linux_joystick.cc | 2 +- .../joystick/example/elinux/CMakeLists.txt | 23 ++---- .../example/elinux/runner/command_options.h | 79 +++++++++++++------ .../elinux/runner/flutter_embedder_options.h | 57 +++++++++++-- .../joystick/example/elinux/runner/main.cc | 5 +- packages/joystick/example/pubspec.yaml | 2 +- packages/joystick/lib/joystick.dart | 2 +- packages/joystick/pubspec.yaml | 6 +- 10 files changed, 129 insertions(+), 52 deletions(-) diff --git a/packages/joystick/CHANGELOG.md b/packages/joystick/CHANGELOG.md index 5fdfb4c..3e22790 100644 --- a/packages/joystick/CHANGELOG.md +++ b/packages/joystick/CHANGELOG.md @@ -1,2 +1,5 @@ +## 1.0.1 +* Update for flutter 3.3.0 release + ## 1.0.0 * First version. diff --git a/packages/joystick/elinux/joystick_plugin.cc b/packages/joystick/elinux/joystick_plugin.cc index 97f87d1..c90e4b0 100644 --- a/packages/joystick/elinux/joystick_plugin.cc +++ b/packages/joystick/elinux/joystick_plugin.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Group Corporation. All rights reserved. +// Copyright 2022 Sony Group Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/packages/joystick/elinux/linux_joystick.cc b/packages/joystick/elinux/linux_joystick.cc index 955272e..78b13d5 100644 --- a/packages/joystick/elinux/linux_joystick.cc +++ b/packages/joystick/elinux/linux_joystick.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Group Corporation. All rights reserved. +// Copyright 2022 Sony Group Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/packages/joystick/example/elinux/CMakeLists.txt b/packages/joystick/example/elinux/CMakeLists.txt index c18d81f..bc693c5 100644 --- a/packages/joystick/example/elinux/CMakeLists.txt +++ b/packages/joystick/example/elinux/CMakeLists.txt @@ -1,4 +1,6 @@ cmake_minimum_required(VERSION 3.15) +# stop cmake from taking make from CMAKE_SYSROOT +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) project(runner LANGUAGES CXX) set(BINARY_NAME "joystick_example") @@ -7,21 +9,12 @@ cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") -# Root filesystem for cross-building. -if(FLUTTER_TARGET_PLATFORM_SYSROOT) - set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) - set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) - set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) - set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) - - # Basically we use this include when we got the following error: - # fatal error: 'bits/c++config.h' file not found - if(FLUTTER_TARGET_PLATFORM_SYSROOT) - include_directories(SYSTEM ${FLUTTER_SYSTEM_INCLUDE_DIRECTORIES}) - endif() -endif() +# Basically we use this include when we got the following error: +# fatal error: 'bits/c++config.h' file not found +include_directories(SYSTEM ${FLUTTER_SYSTEM_INCLUDE_DIRECTORIES}) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Configure build options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) diff --git a/packages/joystick/example/elinux/runner/command_options.h b/packages/joystick/example/elinux/runner/command_options.h index 977cdc8..b0de931 100644 --- a/packages/joystick/example/elinux/runner/command_options.h +++ b/packages/joystick/example/elinux/runner/command_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,8 +13,6 @@ #include #include -// todo: Supports other types besides int, string. - namespace commandline { namespace { @@ -39,30 +37,49 @@ class CommandOptions { CommandOptions() = default; ~CommandOptions() = default; - void AddWithoutValue(const std::string& name, const std::string& short_name, - const std::string& description, bool required) { + void AddWithoutValue(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required) { Add(name, short_name, description, "", ReaderString(), required, false); } - void AddInt(const std::string& name, const std::string& short_name, - const std::string& description, const int& default_value, + void AddInt(const std::string& name, + const std::string& short_name, + const std::string& description, + const int& default_value, bool required) { Add(name, short_name, description, default_value, ReaderInt(), required, true); } - void AddString(const std::string& name, const std::string& short_name, + void AddDouble(const std::string& name, + const std::string& short_name, + const std::string& description, + const double& default_value, + bool required) { + Add(name, short_name, description, default_value, + ReaderDouble(), required, true); + } + + void AddString(const std::string& name, + const std::string& short_name, const std::string& description, - const std::string& default_value, bool required) { + const std::string& default_value, + bool required) { Add(name, short_name, description, default_value, ReaderString(), required, true); } template - void Add(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader = F(), bool required = true, bool required_value = true) { + void Add(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader = F(), + bool required = true, + bool required_value = true) { if (options_.find(name) != options_.end()) { std::cerr << "Already registered option: " << name << std::endl; return; @@ -213,7 +230,7 @@ class CommandOptions { } size_t index_adjust = 0; - constexpr int kSpacerNum = 5; + constexpr int kSpacerNum = 10; auto need_value = registration_order_options_[i]->IsRequiredValue(); ostream << kOptionStyleNormal << registration_order_options_[i]->GetName(); @@ -240,10 +257,17 @@ class CommandOptions { std::string operator()(const std::string& value) { return value; } }; + struct ReaderDouble { + double operator()(const std::string& value) { return std::stod(value); } + }; + class Option { public: - Option(const std::string& name, const std::string& short_name, - const std::string& description, bool required, bool required_value) + Option(const std::string& name, + const std::string& short_name, + const std::string& description, + bool required, + bool required_value) : name_(name), short_name_(short_name), description_(description), @@ -288,9 +312,12 @@ class CommandOptions { template class OptionValue : public Option { public: - OptionValue(const std::string& name, const std::string& short_name, - const std::string& description, const T& default_value, - bool required, bool required_value) + OptionValue(const std::string& name, + const std::string& short_name, + const std::string& description, + const T& default_value, + bool required, + bool required_value) : Option(name, short_name, description, required, required_value), default_value_(default_value), value_(default_value){}; @@ -316,10 +343,18 @@ class CommandOptions { template class OptionValueReader : public OptionValue { public: - OptionValueReader(const std::string& name, const std::string& short_name, - const std::string& description, const T default_value, - F reader, bool required, bool required_value) - : OptionValue(name, short_name, description, default_value, required, + OptionValueReader(const std::string& name, + const std::string& short_name, + const std::string& description, + const T default_value, + F reader, + bool required, + bool required_value) + : OptionValue(name, + short_name, + description, + default_value, + required, required_value), reader_(reader) {} ~OptionValueReader() = default; diff --git a/packages/joystick/example/elinux/runner/flutter_embedder_options.h b/packages/joystick/example/elinux/runner/flutter_embedder_options.h index 636fdda..fbb8190 100644 --- a/packages/joystick/example/elinux/runner/flutter_embedder_options.h +++ b/packages/joystick/example/elinux/runner/flutter_embedder_options.h @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,18 +14,24 @@ class FlutterEmbedderOptions { public: FlutterEmbedderOptions() { - options_.AddString("bundle", "b", "Path to Flutter app bundle", "./", - false); + options_.AddString("bundle", "b", "Path to Flutter project bundle", + "./bundle", true); options_.AddWithoutValue("no-cursor", "n", "No mouse cursor/pointer", false); + options_.AddInt("rotation", "r", + "Window rotation(degree) [0(default)|90|180|270]", 0, + false); + options_.AddDouble("force-scale-factor", "s", + "Force a scale factor instead using default value", 1.0, + false); #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) // no more options. #elif defined(FLUTTER_TARGET_BACKEND_X11) options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #else // FLUTTER_TARGET_BACKEND_WAYLAND options_.AddWithoutValue("onscreen-keyboard", "k", "Enable on-screen keyboard", false); @@ -33,8 +39,8 @@ class FlutterEmbedderOptions { "Enable window decorations", false); options_.AddWithoutValue("fullscreen", "f", "Always full-screen display", false); - options_.AddInt("width", "w", "Flutter app window width", 1280, false); - options_.AddInt("height", "h", "Flutter app window height", 720, false); + options_.AddInt("width", "w", "Window width", 1280, false); + options_.AddInt("height", "h", "Window height", 720, false); #endif } ~FlutterEmbedderOptions() = default; @@ -48,6 +54,34 @@ class FlutterEmbedderOptions { bundle_path_ = options_.GetValue("bundle"); use_mouse_cursor_ = !options_.Exist("no-cursor"); + if (options_.Exist("rotation")) { + switch (options_.GetValue("rotation")) { + case 90: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_90; + break; + case 180: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_180; + break; + case 270: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_270; + break; + default: + window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + break; + } + } + + if (options_.Exist("force-scale-factor")) { + is_force_scale_factor_ = true; + scale_factor_ = options_.GetValue("force-scale-factor"); + } else { + is_force_scale_factor_ = false; + scale_factor_ = 1.0; + } #if defined(FLUTTER_TARGET_BACKEND_GBM) || \ defined(FLUTTER_TARGET_BACKEND_EGLSTREAM) @@ -86,6 +120,11 @@ class FlutterEmbedderOptions { } int WindowWidth() const { return window_width_; } int WindowHeight() const { return window_height_; } + flutter::FlutterViewController::ViewRotation WindowRotation() const { + return window_view_rotation_; + } + bool IsForceScaleFactor() const { return is_force_scale_factor_; } + double ScaleFactor() const { return scale_factor_; } private: commandline::CommandOptions options_; @@ -98,6 +137,10 @@ class FlutterEmbedderOptions { flutter::FlutterViewController::ViewMode::kNormal; int window_width_ = 1280; int window_height_ = 720; + flutter::FlutterViewController::ViewRotation window_view_rotation_ = + flutter::FlutterViewController::ViewRotation::kRotation_0; + bool is_force_scale_factor_; + double scale_factor_; }; #endif // FLUTTER_EMBEDDER_OPTIONS_ diff --git a/packages/joystick/example/elinux/runner/main.cc b/packages/joystick/example/elinux/runner/main.cc index 92a6513..dd3e12d 100644 --- a/packages/joystick/example/elinux/runner/main.cc +++ b/packages/joystick/example/elinux/runner/main.cc @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Corporation. All rights reserved. +// Copyright 2022 Sony Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -29,9 +29,12 @@ int main(int argc, char** argv) { view_properties.width = options.WindowWidth(); view_properties.height = options.WindowHeight(); view_properties.view_mode = options.WindowViewMode(); + view_properties.view_rotation = options.WindowRotation(); view_properties.use_mouse_cursor = options.IsUseMouseCursor(); view_properties.use_onscreen_keyboard = options.IsUseOnscreenKeyboard(); view_properties.use_window_decoration = options.IsUseWindowDecoraation(); + view_properties.force_scale_factor = options.IsForceScaleFactor(); + view_properties.scale_factor = options.ScaleFactor(); // The Flutter instance hosted by this window. FlutterWindow window(view_properties, project); diff --git a/packages/joystick/example/pubspec.yaml b/packages/joystick/example/pubspec.yaml index 49cccb2..eb2e2db 100644 --- a/packages/joystick/example/pubspec.yaml +++ b/packages/joystick/example/pubspec.yaml @@ -3,9 +3,9 @@ description: Demonstrates how to use the joystick plugin for eLinux. environment: sdk: ">=2.12.0 <3.0.0" + flutter: ">=2.10.0" dependencies: - cupertino_icons: ^1.0.2 flutter: sdk: flutter joystick: diff --git a/packages/joystick/lib/joystick.dart b/packages/joystick/lib/joystick.dart index 2fb28a6..5aab69e 100644 --- a/packages/joystick/lib/joystick.dart +++ b/packages/joystick/lib/joystick.dart @@ -1,4 +1,4 @@ -// Copyright 2021 Sony Group Corporation. All rights reserved. +// Copyright 2022 Sony Group Corporation. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/packages/joystick/pubspec.yaml b/packages/joystick/pubspec.yaml index f35d19d..4078ed5 100644 --- a/packages/joystick/pubspec.yaml +++ b/packages/joystick/pubspec.yaml @@ -1,16 +1,16 @@ name: joystick description: A Flutter plugin for getting information about and controlling the joystick on eLinux. -version: 1.0.0 +version: 1.0.1 homepage: https://github.com/sony/flutter-elinux-plugins repository: https://github.com/sony/flutter-elinux-plugins/tree/main/packages/joystick environment: sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.20.0" + flutter: ">=2.10.0" dependencies: - ffi: ^1.1.2 + ffi: ^2.0.0 flutter: sdk: flutter