1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-12 08:43:08 +00:00

Pause the app when it loses focus instead of limiting its FPS

This commit is contained in:
Manolis Papadeas 2021-12-11 20:02:51 +02:00
parent 29304ad52f
commit 057318f659
5 changed files with 31 additions and 72 deletions

View file

@ -1058,13 +1058,13 @@ msgstr ""
msgid "Set application FPS limit:" msgid "Set application FPS limit:"
msgstr "" msgstr ""
msgid "Limit FPS to the idle FPS when app loses focus" msgid "Pause application when it loses focus"
msgstr "" msgstr ""
msgid "Sets the limit of the application's frames per second. The lower the number, the lower the CPU usage, but the application gets slower, choppier and unresponsive. 0 means that there is no limit." msgid "Sets the limit of the application's frames per second. The lower the number, the lower the CPU usage, but the application gets slower, choppier and unresponsive. 0 means that there is no limit."
msgstr "" msgstr ""
msgid "If this is toggled on, when the application's window loses focus, the FPS limit of the application is set to the idle FPS. This helps lower CPU usage when idle. The FPS limit is being reset when the mouse enters the application's window." msgid "If this is toggled on, when the application's window loses focus, it gets paused. This helps lower CPU usage when idle. The application gets unpaused when the mouse enters the application's window."
msgstr "" msgstr ""
msgid "Brush:" msgid "Brush:"
@ -1790,9 +1790,3 @@ msgstr ""
msgid "Position:" msgid "Position:"
msgstr "" msgstr ""
msgid "Set idle FPS:"
msgstr ""
msgid "Sets how many FPS Pixelorama uses when out of focus. The less the better the performance."
msgstr ""

View file

@ -70,9 +70,8 @@ var selection_animated_borders := true
var selection_border_color_1 := Color.white var selection_border_color_1 := Color.white
var selection_border_color_2 := Color.black var selection_border_color_2 := Color.black
var fps_limit_focus := true var pause_when_unfocused := true
var fps_limit := 0 var fps_limit := 0
var idle_fps := 1
var autosave_interval := 1.0 var autosave_interval := 1.0
var enable_autosave := true var enable_autosave := true

View file

@ -328,22 +328,22 @@ func _handle_backup() -> void:
func _notification(what: int) -> void: func _notification(what: int) -> void:
match what: match what:
MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
show_quit_dialog() show_quit_dialog()
MainLoop.NOTIFICATION_WM_FOCUS_OUT: # Called when another program is currently focused
Global.has_focus = false
if Global.fps_limit_focus:
# then set the fps to the idle fps (by default 1) to facilitate the CPU
Engine.set_target_fps(Global.idle_fps)
MainLoop.NOTIFICATION_WM_MOUSE_ENTER: # Opposite of the above
if Global.fps_limit_focus:
Engine.set_target_fps(Global.fps_limit) # 0 stands for maximum fps
# If the mouse exits the window and another application has the focus, # If the mouse exits the window and another application has the focus,
# set the fps to the idle fps # pause the application
MainLoop.NOTIFICATION_WM_FOCUS_OUT:
Global.has_focus = false
if Global.pause_when_unfocused:
get_tree().paused = true
MainLoop.NOTIFICATION_WM_MOUSE_EXIT: MainLoop.NOTIFICATION_WM_MOUSE_EXIT:
if !OS.is_window_focused() and Global.fps_limit_focus: if !OS.is_window_focused() and Global.pause_when_unfocused:
Engine.set_target_fps(Global.idle_fps) get_tree().paused = true
# Unpause it when the mouse enters the window or when it gains focus
MainLoop.NOTIFICATION_WM_MOUSE_ENTER:
get_tree().paused = false
MainLoop.NOTIFICATION_WM_FOCUS_IN: MainLoop.NOTIFICATION_WM_FOCUS_IN:
get_tree().paused = false
var mouse_pos := get_global_mouse_position() var mouse_pos := get_global_mouse_position()
var viewport_rect := Rect2( var viewport_rect := Rect2(
Global.main_viewport.rect_global_position, Global.main_viewport.rect_size Global.main_viewport.rect_global_position, Global.main_viewport.rect_size

View file

@ -147,12 +147,11 @@ var preferences = [
], ],
["fps_limit", "Performance/PerformanceContainer/SetFPSLimit", "value", Global.fps_limit], ["fps_limit", "Performance/PerformanceContainer/SetFPSLimit", "value", Global.fps_limit],
[ [
"fps_limit_focus", "pause_when_unfocused",
"Performance/PerformanceContainer/EnableLimitFPSFocus", "Performance/PerformanceContainer/PauseAppFocus",
"pressed", "pressed",
Global.fps_limit_focus Global.pause_when_unfocused
], ],
["idle_fps", "Performance/PerformanceContainer/IdleFPS", "value", Global.idle_fps]
] ]
var selected_item := 0 var selected_item := 0
@ -165,9 +164,6 @@ onready var autosave_interval: SpinBox = right_side.get_node(
) )
onready var shrink_label: Label = right_side.get_node("Interface/ShrinkContainer/ShrinkLabel") onready var shrink_label: Label = right_side.get_node("Interface/ShrinkContainer/ShrinkLabel")
onready var themes: BoxContainer = right_side.get_node("Interface/Themes") onready var themes: BoxContainer = right_side.get_node("Interface/Themes")
onready var idle_fps_spinbox: SpinBox = right_side.get_node(
"Performance/PerformanceContainer/IdleFPS"
)
func _ready() -> void: func _ready() -> void:
@ -331,9 +327,6 @@ func preference_update(prop: String) -> void:
if prop in ["fps_limit"]: if prop in ["fps_limit"]:
Engine.set_target_fps(Global.fps_limit) Engine.set_target_fps(Global.fps_limit)
if prop in ["fps_limit_focus"]:
idle_fps_spinbox.editable = !idle_fps_spinbox.editable
if ( if (
prop prop
in ["selection_animated_borders", "selection_border_color_1", "selection_border_color_2"] in ["selection_animated_borders", "selection_border_color_1", "selection_border_color_2"]

View file

@ -10,8 +10,8 @@
[node name="PreferencesDialog" type="AcceptDialog"] [node name="PreferencesDialog" type="AcceptDialog"]
margin_left = -3.0 margin_left = -3.0
margin_top = 9.0 margin_top = 9.0
margin_right = 419.0 margin_right = 617.0
margin_bottom = 1163.0 margin_bottom = 459.0
rect_min_size = Vector2( 620, 450 ) rect_min_size = Vector2( 620, 450 )
window_title = "Preferences" window_title = "Preferences"
resizable = true resizable = true
@ -39,13 +39,13 @@ __meta__ = {
[node name="List" type="ItemList" parent="HSplitContainer"] [node name="List" type="ItemList" parent="HSplitContainer"]
margin_right = 86.0 margin_right = 86.0
margin_bottom = 1110.0 margin_bottom = 406.0
rect_min_size = Vector2( 85, 0 ) rect_min_size = Vector2( 85, 0 )
[node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer"] [node name="ScrollContainer" type="ScrollContainer" parent="HSplitContainer"]
margin_left = 106.0 margin_left = 106.0
margin_right = 604.0 margin_right = 604.0
margin_bottom = 1110.0 margin_bottom = 406.0
rect_min_size = Vector2( 100, 0 ) rect_min_size = Vector2( 100, 0 )
size_flags_horizontal = 3 size_flags_horizontal = 3
@ -1376,11 +1376,11 @@ __meta__ = {
[node name="Performance" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] [node name="Performance" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
visible = false visible = false
margin_top = 28.0 margin_top = 28.0
margin_right = 553.0 margin_right = 500.0
margin_bottom = 80.0 margin_bottom = 80.0
[node name="PerformanceContainer" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance"] [node name="PerformanceContainer" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance"]
margin_right = 553.0 margin_right = 500.0
margin_bottom = 52.0 margin_bottom = 52.0
columns = 3 columns = 3
@ -1407,20 +1407,20 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="EnableLimitFPSFocusLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance/PerformanceContainer"] [node name="PauseAppFocusLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance/PerformanceContainer"]
margin_left = 324.0 margin_left = 261.0
margin_top = 5.0 margin_top = 5.0
margin_right = 553.0 margin_right = 500.0
margin_bottom = 19.0 margin_bottom = 19.0
hint_tooltip = "If this is toggled on, when the application's window loses focus, the FPS limit of the application is set to the idle FPS. This helps lower CPU usage when idle. The FPS limit is being reset when the mouse enters the application's window." hint_tooltip = "If this is toggled on, when the application's window loses focus, it gets paused. This helps lower CPU usage when idle. The application gets unpaused when the mouse enters the application's window."
mouse_filter = 0 mouse_filter = 0
text = "Limit FPS to the idle FPS when app loses focus" text = "Pause application when it loses focus"
[node name="EnableLimitFPSFocus" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance/PerformanceContainer"] [node name="PauseAppFocus" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance/PerformanceContainer"]
margin_top = 28.0 margin_top = 28.0
margin_right = 158.0 margin_right = 158.0
margin_bottom = 52.0 margin_bottom = 52.0
hint_tooltip = "If this is toggled on, when the application's window loses focus, the FPS limit of the application is set to the idle FPS. This helps lower CPU usage when idle. The FPS limit is being reset when the mouse enters the application's window." hint_tooltip = "If this is toggled on, when the application's window loses focus, it gets paused. This helps lower CPU usage when idle. The application gets unpaused when the mouse enters the application's window."
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
pressed = true pressed = true
text = "On" text = "On"
@ -1428,33 +1428,6 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="IdleFPSLabel" type="Label" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance/PerformanceContainer"]
margin_left = 162.0
margin_top = 33.0
margin_right = 320.0
margin_bottom = 47.0
hint_tooltip = "Sets how many FPS Pixelorama uses when out of focus."
mouse_filter = 0
size_flags_horizontal = 0
text = "Set idle FPS:"
[node name="IdleFPS" type="SpinBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Performance/PerformanceContainer"]
margin_left = 324.0
margin_top = 28.0
margin_right = 419.0
margin_bottom = 52.0
rect_min_size = Vector2( 95, 0 )
hint_tooltip = "Sets how many FPS Pixelorama uses when out of focus."
mouse_default_cursor_shape = 2
size_flags_horizontal = 0
min_value = 1.0
max_value = 60.0
value = 1.0
align = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Indicators" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] [node name="Indicators" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"]
visible = false visible = false
margin_top = 54.0 margin_top = 54.0