Changeset - r24666:516313d51875
[Not reviewed]
master
0 2 0
frosch - 4 years ago 2021-01-14 22:29:29
frosch@openttd.org
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)
2 files changed with 26 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/video/sdl2_v.cpp
Show inline comments
 
@@ -272,10 +272,15 @@ bool VideoDriver_SDL::CreateMainSurface(
 
			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
 
	}
 
	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) };
 
}
src/video/sdl2_v.h
Show inline comments
 
@@ -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;
 
};
0 comments (0 inline, 0 general)