-
-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Project setting for Joypad on unfocused Window #82965
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
Open
Chtau
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
Chtau:joypad-focus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| #include "core/input/default_controller_mappings.h" | ||
| #include "core/input/input_map.h" | ||
| #include "core/os/os.h" | ||
| #include "servers/display_server.h" | ||
|
|
||
| #ifdef DEV_ENABLED | ||
| #include "core/os/thread.h" | ||
|
|
@@ -270,6 +271,19 @@ bool Input::is_mouse_button_pressed(MouseButton p_button) const { | |
| return mouse_button_mask.has_flag(mouse_button_to_mask(p_button)); | ||
| } | ||
|
|
||
| void Input::_project_settings_changed() { | ||
| ignore_joypad_on_unfocused = bool(GLOBAL_GET("input_devices/config/ignore_joypad_on_unfocused_window")); | ||
| } | ||
|
|
||
| bool Input::_config_ignore_joypad_on_unfocused_window() { | ||
| if (ignore_joypad_on_unfocused) { | ||
| if (!DisplayServer::get_singleton()->window_is_focused(DisplayServer::MAIN_WINDOW_ID)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach doesn't cover the case, that an application can have multiple OS-Windows. Perhaps a better approach would be to take application focus instead of window focus into consideration. |
||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static JoyAxis _combine_device(JoyAxis p_value, int p_device) { | ||
| return JoyAxis((int)p_value | (p_device << 20)); | ||
| } | ||
|
|
@@ -1053,6 +1067,9 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) { | |
|
|
||
| void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) { | ||
| _THREAD_SAFE_METHOD_; | ||
| if (_config_ignore_joypad_on_unfocused_window()) { | ||
| return; | ||
| } | ||
| Joypad &joy = joy_names[p_device]; | ||
| ERR_FAIL_INDEX((int)p_button, (int)JoyButton::MAX); | ||
|
|
||
|
|
@@ -1080,7 +1097,9 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) { | |
|
|
||
| void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) { | ||
| _THREAD_SAFE_METHOD_; | ||
|
|
||
| if (_config_ignore_joypad_on_unfocused_window()) { | ||
| return; | ||
| } | ||
| ERR_FAIL_INDEX((int)p_axis, (int)JoyAxis::MAX); | ||
|
|
||
| Joypad &joy = joy_names[p_device]; | ||
|
|
@@ -1147,6 +1166,10 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) { | |
|
|
||
| void Input::joy_hat(int p_device, BitField<HatMask> p_val) { | ||
| _THREAD_SAFE_METHOD_; | ||
| if (_config_ignore_joypad_on_unfocused_window()) { | ||
| return; | ||
| } | ||
|
|
||
| const Joypad &joy = joy_names[p_device]; | ||
|
|
||
| JoyEvent map[(size_t)HatDir::MAX]; | ||
|
|
@@ -1616,6 +1639,8 @@ Input::Input() { | |
| // Always use standard behavior in the editor. | ||
| legacy_just_pressed_behavior = false; | ||
| } | ||
|
|
||
| ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Input::_project_settings_changed)); | ||
| } | ||
|
|
||
| Input::~Input() { | ||
|
|
||
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
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
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.
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.
This was discussed in a PR-review meeting and Input should not depend on display_server.
An alternative approach would be to notify Input from the main loop about application focus changes.