This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm having this issue, where I want to get the Screen ID at which my window is at currently. So I found this handy DisplayServer.get_window_at_screen_position() function. And I wrote:

var window_pos = DisplayServer.window_get_position()
var current_display_id = DisplayServer.get_window_at_screen_position(window_pos) 

print(current_display_id)

,but it always returns 0.

2x 2650-1440 Monitors

Honeslty this feals like a bug on the DEV Side. Still if somebody knows a fix, can you please help me out? thx

Godot version 4.0.stable
in Engine by (56 points)

According to the docs, window_get_position() takes an optional window_id argument, the defaults to 0 if not supplied. So, you're sample code appears to be asking for the position of window ID 0.

Next, you pass in that position to get_window_at_screen_position(), which returns the ID of the window at the specified position. So, since you requested the position of window id 0, I'd expect that second call to tell you that the window at the specified position is windows 0, as it apparently has.

So, this seems to work as expected based on the posted code.

(Comments based solely on your posted code and the docs. I haven't experimented with any of the above).

Your post should make sense, but evan with changine the window_get_position() parameter or just simulating a variable to act like my window position it always return 0.
As an addition the DisplayServer.get_window_at_screen_position(window_pos) method should also return -1 if the window is out of the screen bounds.

Your post should make sense, but evan with changine the window_get_position() parameter or just simulating a variable to act like my window position it always return 0.
Additionally the DisplayServer.get_window_at_screen_position(window_pos) method should also return -1 if the window is out of the screen bounds.

1 Answer

0 votes

I found a workaround using the DisplayServer.get_screen_from_rect method:

var window_pos = DisplayServer.window_get_position(0)
var window_size = DisplayServer.window_get_size(0)
var window_rect = Rect2(window_pos, window_size)
var current_display_id = DisplayServer.get_screen_from_rect(window_rect)

print(current_display_id)

Hope this helps in the future.

by (56 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.