Stop fighting the WM on resize events
This commit is contained in:
parent
6ec484b679
commit
0514011cd2
|
@ -2,6 +2,7 @@ extends Node
|
||||||
|
|
||||||
var base_resolution: Vector2 = Vector2(ProjectSettings.get_setting('display/window/size/width'), ProjectSettings.get_setting('display/window/size/height')) # Vector2(640, 360)
|
var base_resolution: Vector2 = Vector2(ProjectSettings.get_setting('display/window/size/width'), ProjectSettings.get_setting('display/window/size/height')) # Vector2(640, 360)
|
||||||
var shrink_timer := Timer.new()
|
var shrink_timer := Timer.new()
|
||||||
|
var last_resolution_pre_shrink := Vector2.ZERO
|
||||||
|
|
||||||
static func load_json(filename: String): # Valid JSON will return Array or Dictionary. int error code for anything else.
|
static func load_json(filename: String): # Valid JSON will return Array or Dictionary. int error code for anything else.
|
||||||
var file := File.new()
|
var file := File.new()
|
||||||
|
@ -145,7 +146,16 @@ func update_window_scale():
|
||||||
var scale_f := max(min(scale_vec.x, scale_vec.y), 1)
|
var scale_f := max(min(scale_vec.x, scale_vec.y), 1)
|
||||||
var scale := int(scale_f)
|
var scale := int(scale_f)
|
||||||
if ProjectSettings.get_setting('display/window/size/snap_to_integer'):
|
if ProjectSettings.get_setting('display/window/size/snap_to_integer'):
|
||||||
|
var target_size := base_resolution * scale
|
||||||
# OS.window_size = base_resolution*scale
|
# OS.window_size = base_resolution*scale
|
||||||
|
if size == target_size:
|
||||||
|
print_debug('Config is to shrink down to integer scale, but %s is already a perfect %dx scale' % [size, scale])
|
||||||
|
elif size == self.last_resolution_pre_shrink:
|
||||||
|
# Don't fight the WM if it sets the window size back again
|
||||||
|
print_debug("Config is to shrink down to integer scale, but %s was the last external resize event, so we won't fight the window manager" % size)
|
||||||
|
else:
|
||||||
|
print_debug('Setting lastres to %s, will resize to %dx == %s in 1 second' % [self.last_resolution_pre_shrink, scale, target_size])
|
||||||
|
self.last_resolution_pre_shrink = size
|
||||||
shrink_timer.paused = false
|
shrink_timer.paused = false
|
||||||
shrink_timer.start(1)
|
shrink_timer.start(1)
|
||||||
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT, SceneTree.STRETCH_ASPECT_KEEP, base_resolution*scale, scale)
|
get_tree().set_screen_stretch(SceneTree.STRETCH_MODE_VIEWPORT, SceneTree.STRETCH_ASPECT_KEEP, base_resolution*scale, scale)
|
||||||
|
|
Loading…
Reference in New Issue