-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Toggle fullscreen mode when pressing Alt + Enter by default #39708
base: master
Are you sure you want to change the base?
Conversation
In my experience, |
scene/main/viewport.cpp
Outdated
@@ -2295,6 +2279,20 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { | |||
} | |||
|
|||
if (mm.is_null() && mb.is_null() && p_event->is_action_type()) { | |||
const bool resize_allowed = !DisplayServer::get_singleton()->window_get_flag(DisplayServer::WINDOW_FLAG_RESIZE_DISABLED); | |||
|
|||
if (p_event->is_pressed() && p_event->is_action_pressed("toggle_fullscreen") && resize_allowed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the check && resize_allowed
is superfluous? Some people turn off window resizing but allow fullscreen mode.
And if someone doesn’t need either, then they can simply delete all events from the toogle_fullscreen
action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some people turn off window resizing but allow fullscreen mode.
That doesn't really make sense to me. If your window is set to be non-resizable, it's usually because your game isn't designed for multiple resolutions. Otherwise, there's no reason not to allow it 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your window is set to be non-resizable, it's usually because your game isn't designed for multiple resolutions.
Absolutely true, but the game can still work in fullscreen. The resolution does not change, the picture simply stretches (viewport
mode). This is usually for pixel games.
[display]
window/size/width=320
window/size/height=180
window/size/resizable=false
window/size/test_width=640
window/size/test_height=360
window/stretch/mode="viewport"
window/stretch/aspect="keep"
@aaronfranke It makes sense to bind F11 as well, but it's more likely to conflict with a key already used in the project. That said, since it can easily be removed, it should be safe to do. |
@aaronfranke F11 is more common in applications (browsers, text editors etc.). Most games use Alt + Enter. |
Needs rebase. |
d7896f8
to
a4cf4eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing this, it seems that there is a naming mismatch between toggle_fullscreen
and ui_toggle_fullscreen
. In the project settings input map, it says toggle_fullscreen
, but then when pressing the key, this error appears:
E 0:00:04:0057 event_get_action_status: Request for nonexistent InputMap action 'ui_toggle_fullscreen'.
<C++ Error> Condition "!E" is true. Returning: false
<C++ Source> core/input/input_map.cpp:194 @ event_get_action_status()
Also, it would be nice to get F11 bound:
core/input/input_map.cpp
Outdated
key.instance(); | ||
key->set_keycode(KEY_ENTER); | ||
key->set_alt(true); | ||
action_add_event("ui_toggle_fullscreen", key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
action_add_event("ui_toggle_fullscreen", key); | |
action_add_event("ui_toggle_fullscreen", key); | |
key.instance(); | |
key->set_keycode(KEY_F11); | |
action_add_event("ui_toggle_fullscreen", key); |
core/config/project_settings.cpp
Outdated
key.instance(); | ||
key->set_keycode(KEY_ENTER); | ||
key->set_alt(true); | ||
events.push_back(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
events.push_back(key); | |
events.push_back(key); | |
key.instance(); | |
key->set_keycode(KEY_F11); | |
events.push_back(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the new InputEventKey::create_instance( KEY_MASK_ALT | KEY_ENTER)
here to keep it succinct.
@aaronfranke The issue with adding F11 as a shortcut is that it conflicts with the editor's distraction-free toggle, which defaults to Ctrl + Shift + F11. It no longer works if I add F11 as a key for Anyway, I fixed the issue with the |
a4cf4eb
to
592a5e7
Compare
For F11: Understandable, if there's a reason to not have it then that's fine. Tested this again. When exiting fullscreen on Linux, the window's title bar is gone. This might be unrelated to this PR though, since this is just binding a key. |
scene/main/viewport.cpp
Outdated
const bool resize_allowed = !DisplayServer::get_singleton()->window_get_flag(DisplayServer::WINDOW_FLAG_RESIZE_DISABLED); | ||
|
||
if (p_event->is_pressed() && p_event->is_action_pressed("ui_toggle_fullscreen") && resize_allowed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const bool resize_allowed = !DisplayServer::get_singleton()->window_get_flag(DisplayServer::WINDOW_FLAG_RESIZE_DISABLED); | |
if (p_event->is_pressed() && p_event->is_action_pressed("ui_toggle_fullscreen") && resize_allowed) { | |
if (p_event->is_pressed() && p_event->is_action_pressed("ui_toggle_fullscreen")) { |
See previous discussion. Let's not create artificial restrictions. If a person has window_resizable == false
and they don't need fullscreen, then they can simply remove all events from the ui_toggle_fullscreen
action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the window is not resizable, then we should not allow toggling fullscreen to not break expectations (since making it fullscreen is almost guaranteed to resize it in one way or another).
If you really want to make a non-resizable window fullscreen, you can use a window manager that allows ignoring geometry restrictions like KWin. Either way, this is very much an edge case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @Calinou here, if resizing a window isn't allowed, it shouldn't be resized, whatever keys you press.
I can reproduce this on Linux too. It's most likely a regression from DisplayServer. |
Absolutely do not use F11 for full screen toggle of games. Definitely do use ALT+Enter for full screen toggle of games. Or use both for the sake of people who learned gaming with minecraft or Roblox (Shift+F11) but ALT+Enter should be the priority for the sake of any other gamer. If I'm not mistaken, there is conversation about having the same key combo for Godot editor and games made in Godot? If that is correct: Both F11 and ALT+Enter do nothing in Unity editor, neither should be expected to do anything. Full-screening a game and a game editor are entirely different things - like full-screening a video to watch, vs full-screening a video editor application. If there is some need to fullscreen toggle godot editor, I'd suggest to use F11 (based on most applications that have fullscreen mode). |
@iwanPlays The Godot editor already provides Shift + F11 to toggle fullscreen. We could perhaps change this to just F11 in a future pull request. |
@iwanPlays I think both should be enabled by default. Personally, I learned about the Alt + Enter combination much later than about the F11 key. |
I think the feature and the implementation look good, but the PR needs a rebase. |
scene/main/viewport.cpp
Outdated
@@ -2355,6 +2341,20 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { | |||
} | |||
|
|||
if (mm.is_null() && mb.is_null() && p_event->is_action_type()) { | |||
const bool resize_allowed = !DisplayServer::get_singleton()->window_get_flag(DisplayServer::WINDOW_FLAG_RESIZE_DISABLED); | |||
|
|||
if (p_event->is_pressed() && p_event->is_action_pressed("ui_toggle_fullscreen") && resize_allowed) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (p_event->is_pressed() && p_event->is_action_pressed("ui_toggle_fullscreen") && resize_allowed) { | |
if (resize_allowed && p_event->is_pressed() && p_event->is_action_pressed("ui_toggle_fullscreen")) { |
This way we can skip parsing input if resize is disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs rebase.
Not necessarily against this, but you should check that the window is resizable/borderless before making this happen. |
Rebased against
I've looked into adding a flag to Window (also tried adding a property), but I don't know how I can avoid having to add code to the |
Alt + Enter is a widely followed convention to toggle fullscreen. This adds support for it both in the editor and projects, as long as the window is configured to be resizable. The rationale for providing this feature in all projects is that many developers don't bother about adding a fullscreen toggle, especially for smaller/gamejam games. Yet, this convention is followed by many popular games out there, including AAA games. The shortcut can be modified or disabled by editing the Input Map in the Project Settings.
592a5e7
to
24e441c
Compare
I'm guessing this is a no-op on Android? |
It could work if you have a hardware keyboard connected and floating windows are used, but otherwise I generally expect it to be a no-op on mobile platforms. |
Note: Technically cherry-pickable to
3.x
, but existing projects may already have implemented a fullscreen toggle on their own. I think it's better not to cherry-pick this PR to avoid trouble.Alt + Enter is a widely followed convention to toggle fullscreen. This adds support for it both in the editor and projects, as long as the window is configured to be resizable.
The rationale for providing this feature in all projects is that many developers don't bother about adding a fullscreen toggle, especially for smaller/gamejam games. Yet, this convention is followed by many popular games out there, including AAA games.
The shortcut can be modified or disabled by editing the Input Map in the Project Settings.
This closes godotengine/godot-proposals#1983. See discussion in godotengine/godot-proposals#1087.