Skip to content
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

Improve OS.set_current_screen #63192

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2536,8 +2536,24 @@ static int get_screen_index(NSScreen *screen) {
return;
}

if (get_current_screen() == p_screen) {
return;
}

bool was_fullscreen = false;
if (zoomed) {
// Temporary exit fullscreen mode to move window.
[window_object toggleFullScreen:nil];
was_fullscreen = true;
}

Vector2 wpos = get_window_position() - get_screen_position(get_current_screen());
set_window_position(wpos + get_screen_position(p_screen));

if (was_fullscreen) {
// Re-enter fullscreen mode.
[window_object toggleFullScreen:nil];
}
};

Point2 OS_OSX::get_native_screen_position(int p_screen) const {
Expand Down
15 changes: 13 additions & 2 deletions platform/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,19 @@ int OS_Windows::get_current_screen() const {
}

void OS_Windows::set_current_screen(int p_screen) {
Vector2 ofs = get_window_position() - get_screen_position(get_current_screen());
set_window_position(ofs + get_screen_position(p_screen));
if (video_mode.fullscreen) {
int cs = get_current_screen();
if (cs == p_screen) {
return;
}
Point2 pos = get_screen_position(p_screen);
Size2 size = get_screen_size(p_screen);

MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE);
} else {
Vector2 ofs = get_window_position() - get_screen_position(get_current_screen());
set_window_position(ofs + get_screen_position(p_screen));
}
}

static BOOL CALLBACK _MonitorEnumProcPos(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
Expand Down
4 changes: 2 additions & 2 deletions platform/x11/os_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,8 @@ void OS_X11::set_current_screen(int p_screen) {
XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y);
} else {
if (p_screen != get_current_screen()) {
Point2i position = get_screen_position(p_screen);
XMoveWindow(x11_display, x11_window, position.x, position.y);
Vector2 ofs = get_window_position() - get_screen_position(get_current_screen());
set_window_position(ofs + get_screen_position(p_screen));
}
}
}
Expand Down