summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2021-01-14 23:29:29 +0100
committerGitHub <noreply@github.com>2021-01-14 23:29:29 +0100
commit0e62a398c7f03ae0bb75980d97dab3f72ecfb26c (patch)
tree5091e0726a490fa7c609efd738acaf255b5646b0 /src/video
parentfa60c1f8b94dd5584a5d5331de277ca23a203422 (diff)
downloadopenttd-0e62a398c7f03ae0bb75980d97dab3f72ecfb26c.tar.xz
Add: [SDL2] video driver parameter to put OpenTTD on a particular display on start. By default use the display where the mouse cursor is. (#8572)
Diffstat (limited to 'src/video')
-rw-r--r--src/video/sdl2_v.cpp28
-rw-r--r--src/video/sdl2_v.h1
2 files changed, 26 insertions, 3 deletions
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp
index f2fbd6d5a..48bd84691 100644
--- a/src/video/sdl2_v.cpp
+++ b/src/video/sdl2_v.cpp
@@ -272,10 +272,15 @@ bool VideoDriver_SDL::CreateMainSurface(uint w, uint h, bool resize)
flags |= SDL_WINDOW_FULLSCREEN;
}
+ int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;
+ SDL_Rect r;
+ if (SDL_GetDisplayBounds(this->startup_display, &r) == 0) {
+ x = r.x + (r.w - w) / 2;
+ y = r.y + (r.h - h) / 4; // decent desktops have taskbars at the bottom
+ }
_sdl_window = SDL_CreateWindow(
caption,
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED,
+ x, y,
w, h,
flags);
@@ -674,6 +679,23 @@ const char *VideoDriver_SDL::Start(const StringList &parm)
}
if (ret_code < 0) return SDL_GetError();
+ this->startup_display = GetDriverParamInt(parm, "display", -1);
+ int num_displays = SDL_GetNumVideoDisplays();
+ if (!IsInsideBS(this->startup_display, 0, num_displays)) {
+ /* Mouse position decides which display to use */
+ int mx, my;
+ SDL_GetGlobalMouseState(&mx, &my);
+ this->startup_display = 0; // used when mouse is on no screen...
+ for (int display = 0; display < num_displays; ++display) {
+ SDL_Rect r;
+ if (SDL_GetDisplayBounds(display, &r) == 0 && IsInsideBS(mx, r.x, r.w) && IsInsideBS(my, r.y, r.h)) {
+ DEBUG(driver, 1, "SDL2: Mouse is at (%d, %d), use display %d (%d, %d, %d, %d)", mx, my, display, r.x, r.y, r.w, r.h);
+ this->startup_display = display;
+ break;
+ }
+ }
+ }
+
this->UpdateAutoResolution();
GetVideoModes();
@@ -935,7 +957,7 @@ void VideoDriver_SDL::ReleaseBlitterLock()
Dimension VideoDriver_SDL::GetScreenSize() const
{
SDL_DisplayMode mode;
- if (SDL_GetCurrentDisplayMode(0, &mode) != 0) return VideoDriver::GetScreenSize();
+ if (SDL_GetCurrentDisplayMode(this->startup_display, &mode) != 0) return VideoDriver::GetScreenSize();
return { static_cast<uint>(mode.w), static_cast<uint>(mode.h) };
}
diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h
index f0f27df79..de10543b5 100644
--- a/src/video/sdl2_v.h
+++ b/src/video/sdl2_v.h
@@ -64,6 +64,7 @@ private:
uint32 last_cur_ticks;
uint32 next_tick;
+ int startup_display;
std::thread draw_thread;
std::unique_lock<std::recursive_mutex> draw_lock;
};