Ported: Add setting to control the window used to run the project for the Android editor

The follow options were added to the (new) `run/window_placement/android_window` editor setting:

- `Auto`: choose how to run the project based on the device screen size
- `Same as Editor`: run the project in the same window as the editor
- `Side-by-side with Editor`: run the project in an adjacent window to the editor
- m4gr3d
b5a908c985
Removed my force launch adjacent solution in favor of this.
This commit is contained in:
Relintai 2023-06-11 09:52:39 +02:00
parent eb8176b701
commit 7e64510427
4 changed files with 43 additions and 20 deletions

View File

@ -539,6 +539,10 @@
<member name="run/output/font_size" type="int" setter="" getter=""> <member name="run/output/font_size" type="int" setter="" getter="">
The size of the font in the [b]Output[/b] panel at the bottom of the editor. This setting does not impact the font size of the script editor (see [member interface/editor/code_font_size]). The size of the font in the [b]Output[/b] panel at the bottom of the editor. This setting does not impact the font size of the script editor (see [member interface/editor/code_font_size]).
</member> </member>
<member name="run/window_placement/android_window" type="int" setter="" getter="">
The Android window to display the project on when starting the project from the editor.
[b]Note:[/b] Only available in the Android editor.
</member>
<member name="run/window_placement/rect" type="int" setter="" getter=""> <member name="run/window_placement/rect" type="int" setter="" getter="">
The window mode to use to display the project when starting the project from the editor. The window mode to use to display the project when starting the project from the editor.
</member> </member>

View File

@ -79,14 +79,6 @@ Error EditorRun::run(const String &p_scene, const String &p_custom_args, const L
} }
#endif #endif
#ifdef ANDROID_ENABLED
const bool android_force_side_by_side_window = EditorSettings::get_singleton()->get("run/window_placement/android_force_launch_adjacent");
if (android_force_side_by_side_window) {
args.push_back("--android-force-launch-adjacent");
}
#endif
args.push_back("--allow_focus_steal_pid"); args.push_back("--allow_focus_steal_pid");
args.push_back(itos(OS::get_singleton()->get_process_id())); args.push_back(itos(OS::get_singleton()->get_process_id()));

View File

@ -629,9 +629,10 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("editors/visual_editors/minimap_opacity", 0.85); _initial_set("editors/visual_editors/minimap_opacity", 0.85);
hints["editors/visual_editors/minimap_opacity"] = PropertyInfo(Variant::REAL, "editors/visual_editors/minimap_opacity", PROPERTY_HINT_RANGE, "0.0,1.0,0.01", PROPERTY_USAGE_DEFAULT); hints["editors/visual_editors/minimap_opacity"] = PropertyInfo(Variant::REAL, "editors/visual_editors/minimap_opacity", PROPERTY_HINT_RANGE, "0.0,1.0,0.01", PROPERTY_USAGE_DEFAULT);
/* Run */ /* Run */
// Window placement // Window placement
#ifndef ANDROID_ENABLED
_initial_set("run/window_placement/rect", 1); _initial_set("run/window_placement/rect", 1);
hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen"); hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen");
String screen_hints = "Same as Editor,Previous Monitor,Next Monitor"; String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
@ -641,8 +642,13 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("run/window_placement/rect_custom_position", Vector2()); _initial_set("run/window_placement/rect_custom_position", Vector2());
_initial_set("run/window_placement/screen", 0); _initial_set("run/window_placement/screen", 0);
hints["run/window_placement/screen"] = PropertyInfo(Variant::INT, "run/window_placement/screen", PROPERTY_HINT_ENUM, screen_hints); hints["run/window_placement/screen"] = PropertyInfo(Variant::INT, "run/window_placement/screen", PROPERTY_HINT_ENUM, screen_hints);
#endif
#ifdef ANDROID_ENABLED #ifdef ANDROID_ENABLED
_initial_set("run/window_placement/android_force_launch_adjacent", false); // Should match the ANDROID_WINDOW_* constants in 'platform/android/java/editor/src/main/java/org/godotengine/editor/GodotEditor.kt'
String android_window_hints = "Auto (based on screen size),Same as Editor,Side-by-side with Editor";
_initial_set("run/window_placement/android_window", 0);
hints["run/window_placement/android_window"] = PropertyInfo(Variant::INT, "run/window_placement/android_window", PROPERTY_HINT_ENUM, android_window_hints);
#endif #endif
// Auto save // Auto save

View File

@ -77,7 +77,15 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
private const val PROJECT_MANAGER_ARG_SHORT = "-p" private const val PROJECT_MANAGER_ARG_SHORT = "-p"
private const val PROJECT_MANAGER_PROCESS_NAME_SUFFIX = ":PandemoniumProjectManager" private const val PROJECT_MANAGER_PROCESS_NAME_SUFFIX = ":PandemoniumProjectManager"
private const val FORCE_LAUNCH_ADJACENT_ARG = "--android-force-launch-adjacent" /**
* Sets of constants to specify the window to use to run the project.
*
* Should match the values in 'editor/editor_settings.cpp' for the
* 'run/window_placement/android_window' setting.
*/
private const val ANDROID_WINDOW_AUTO = 0
private const val ANDROID_WINDOW_SAME_AS_EDITOR = 1
private const val ANDROID_WINDOW_SIDE_BY_SIDE_WITH_EDITOR = 2
} }
private val commandLineParams = ArrayList<String>() private val commandLineParams = ArrayList<String>()
@ -122,7 +130,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
// Whether we should launch the new pandemonium instance in an adjacent window // Whether we should launch the new pandemonium instance in an adjacent window
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT // https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
var launchAdjacent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode || isLargeScreen) var launchAdjacent = shouldGameLaunchAdjacent()
for (arg in args) { for (arg in args) {
if (EDITOR_ARG == arg || EDITOR_ARG_SHORT == arg) { if (EDITOR_ARG == arg || EDITOR_ARG_SHORT == arg) {
@ -140,13 +148,6 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
} }
} }
for (arg in args) {
if (FORCE_LAUNCH_ADJACENT_ARG == arg) {
launchAdjacent = true
break
}
}
// Launch a new activity // Launch a new activity
val newInstance = Intent(this, targetClass).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(COMMAND_LINE_PARAMS, args) val newInstance = Intent(this, targetClass).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(COMMAND_LINE_PARAMS, args)
@ -232,6 +233,26 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
*/ */
protected open fun enablePanAndScaleGestures() = true protected open fun enablePanAndScaleGestures() = true
private fun shouldGameLaunchAdjacent(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
when (Integer.parseInt(GodotLib.getEditorSetting("run/window_placement/android_window"))) {
ANDROID_WINDOW_SAME_AS_EDITOR -> false
ANDROID_WINDOW_SIDE_BY_SIDE_WITH_EDITOR -> true
else -> {
// ANDROID_WINDOW_AUTO
isInMultiWindowMode || isLargeScreen
}
}
} catch (e: NumberFormatException) {
// Fall-back to the 'Auto' behavior
isInMultiWindowMode || isLargeScreen
}
} else {
false
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
// Check if we got the MANAGE_EXTERNAL_STORAGE permission // Check if we got the MANAGE_EXTERNAL_STORAGE permission