Weirdly low safe_area_top on Google Pixel 7

On my Google Pixel 7, the top of the safe area is weirdly low on the screen, compared to the size of the notch and where it’s located.

My script is as follows:

extends Control

@onready var topbar = $TopBar
@onready var topbar_bg = $TopBarBG

var margin = 8

func _ready():
	var os_name = OS.get_name()
	if os_name == "Android" || os_name == "iOS":
		var safe_area = DisplayServer.get_display_safe_area()
		var safe_area_top = safe_area.position.y
		
		topbar.position.y += safe_area_top
		
		topbar_bg.size.y += safe_area_top + margin
		
		MyUtility.add_log_msg("Safe area = " + str(safe_area))
		MyUtility.add_log_msg("Window size = " + str(DisplayServer.window_get_size()))
		MyUtility.add_log_msg("Safe area_top = " + str(safe_area_top))
		MyUtility.add_log_msg("Top bar pos = " + str(topbar.position))


func _on_pause_button_pressed():
	pass # Replace with function body.

And this is the result I get when playtesting on my phone:


When realistically the notch is located as follows:

Not really sure if this is normal behaviour for the Google Pixel 7 specifically or a bug?

Could be a bug in the misreporting of the size of the safe area on the google pixel 7 as its getting it from the internal DisplayServer

Same problem with Pixel 6 FYI. Safe area is at around (0,128) I’ve done a check where it sees if you’re dealing with pixel.

Fixed it if you’re using a pixel:

extends Control

@onready var topbar_bg: ColorRect = $TopbarBG
@onready var topbar: Control = $Topbar

func _ready() -> void:
	var pixelMargin
	var OS_type = OS.get_name()
	print()
	if OS_type == "iOS" || OS_type == "Android":
		var safe_area = DisplayServer.get_display_safe_area()
		var modelName = OS.get_model_name()
		
		if modelName.contains("Pixel"):
			MyUtility.add_log_msg("Found a pixel")
			pixelMargin = -90
			
		var safe_area_top = safe_area.position.y
		topbar.position.y += safe_area_top + pixelMargin
		var margin = 10
		topbar_bg.size.y += safe_area_top + margin + pixelMargin

		MyUtility.add_log_msg("Safe area: " + str(safe_area))
		MyUtility.add_log_msg("Model: " + modelName)
1 Like

Initially I thought maybe this was a similar issue as the one with iPhones but there is no scaling here so yeah, maybe a bug.

Nice one, I didn’t think of checking the name of the phone to fix it.

I can’t remember exactly th logic, but I think I went with something like “must be because the game is twice as big on my phone, so the gap will be too”.

Because this is what I was seeing in debug:

This is my code with a tweak (I’m not even sure if the logic is sound though…):

func _ready():
	var os_name = OS.get_name()
	if os_name == "Android" || os_name == "iOS":
		var safe_area = DisplayServer.get_display_safe_area()
		var safe_area_top = safe_area.position.y
		
		if os_name == "iOS":
			var screen_scale = DisplayServer.screen_get_scale()
			safe_area_top = (safe_area_top / screen_scale)
			MyUtility.add_log_msg("Screen scale = " + str(screen_scale))
		
		# Added post lesson: take into account the different scale of the screen
		var viewport_size = get_viewport_rect().size
		scale_adjustment = DisplayServer.window_get_size().y / viewport_size.y
		
		# Added post lesson: take into account the different scale of the screen
		# Here I just added the / scale/adjustment
		topbar.position.y += safe_area_top / scale_adjustment
		topbar_bg.size.y += (safe_area_top + margin) / scale_adjustment
		
		MyUtility.add_log_msg("Safe area = " + str(safe_area))
		MyUtility.add_log_msg("Window size = " + str(DisplayServer.window_get_size()))
		MyUtility.add_log_msg("Safe area_top = " + str(safe_area_top))
		MyUtility.add_log_msg("Top bar pos = " + str(topbar.position))
		
		# Added post lesson: take into account the different scale of the screen
		MyUtility.add_log_msg("Viewport size = " + str(viewport_size))
		MyUtility.add_log_msg("Scale adjustment = " + str(scale_adjustment))

Not really sure if what I did makes sense ^^’ !

1 Like

Thanks for the great insight!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms