Package: performous / 1.1+git20190701.9928c27-3

pr477.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Description: Check for invalid window position and size.
 Now performous should more intelligently handle multiple displays.
 If possible, the window will always be created at exactly the position
 and size it had on last launch; if not, it will try to determine which
 window corner(s) is/are outside the drawing space and correct them.
 .
 Should close #474.
Author: Gregorio Litenstein <g.litenstein@gmail.com>
Origin: vendor, commit:df263be229b49cdc7c055d7348c21e2cc5acf9de
Bug: https://github.com/performous/performous/issues/474
Forwarded: https://github.com/performous/performous/pull/477

--- a/data/config/schema.xml
+++ b/data/config/schema.xml
@@ -219,13 +219,13 @@ to save the current settings to XML.
 	</entry>
 	<entry name="graphic/window_pos_x" type="int" value="0" hidden="true">
 		<ui unit=" pixels" />
-		<limits min="0" max="65000" step="256" />
+		<limits min="0" max="16384" step="8" />
 		<short>X-Position of the window</short>
 		<long>The X-Position of the window.</long>
 	</entry>
 	<entry name="graphic/window_pos_y" type="int" value="0" hidden="true">
 		<ui unit=" pixels" />
-		<limits min="0" max="65000" step="256" />
+		<limits min="0" max="16384" step="8" />
 		<short>Y-Position of the window</short>
 		<long>The Y-Position of the window.</long>
 	</entry>
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -10,6 +10,8 @@
 #include "screen.hh"
 #include "util.hh"
 #include <boost/filesystem.hpp>
+#include <SDL2/SDL_rect.h>
+#include <SDL2/SDL_video.h>
 
 namespace {
 	float s_width;
@@ -77,10 +79,62 @@ Window::Window() {
 		int height = config["graphic/window_height"].i();
 		int windowPosX = config["graphic/window_pos_x"].i();
 		int windowPosY = config["graphic/window_pos_y"].i();
-		std::clog << "video/info: Create window dimensions: " << width << "x" << height << " on screen position: " << windowPosX << "x" << windowPosY << std::endl;
-		screen = SDL_CreateWindow(PACKAGE " " VERSION, windowPosX, windowPosY, width, height, flags);
-		if (!screen) throw std::runtime_error(std::string("SDL_SetVideoMode failed: ") + SDL_GetError());
-		SDL_GL_CreateContext(screen);
+		int displayCount = SDL_GetNumVideoDisplays();
+		if (displayCount <= 0) {
+			throw std::runtime_error(std::string("video/error: SDL_GetNumVideoDisplays failed: ") + SDL_GetError());
+		}
+		SDL_Rect totalSize;
+		if (displayCount > 1) {
+			totalSize.x = 0;
+			totalSize.y = 0;
+			totalSize.w = 0;
+			totalSize.h = 0;
+			int displayNum = 0;
+			SDL_Rect displaySize;
+			SDL_Rect prevTotal;
+			while (displayNum < displayCount) {
+				if (SDL_GetDisplayBounds(displayNum, &displaySize) != 0) {
+					throw std::runtime_error(std::string("video/error: SDL_GetDisplayBounds failed: ") + SDL_GetError());
+				}
+				prevTotal.x = totalSize.x;
+				prevTotal.y = totalSize.y;
+				prevTotal.w = totalSize.w;
+				prevTotal.h = totalSize.h;
+				SDL_UnionRect(&prevTotal, &displaySize, &totalSize);
+				++displayNum;
+			}
+		}
+		else {
+			if (SDL_GetDisplayBounds(0, &totalSize) != 0) {
+				throw std::runtime_error(std::string("video/error: SDL_GetDisplayBounds failed: ") + SDL_GetError());
+			}
+		}
+		SDL_Point winOrigin {windowPosX, windowPosY};
+		if (SDL_PointInRect(&winOrigin, &totalSize) == SDL_FALSE) {
+			if (winOrigin.x < totalSize.x) { winOrigin.x = totalSize.x; }
+			else if (winOrigin.x > totalSize.w) { winOrigin.x = (totalSize.w - width); }
+			if (winOrigin.y < totalSize.y) { winOrigin.y = totalSize.y; }
+			else if (winOrigin.y > totalSize.h) { winOrigin.y = (totalSize.h - height); }
+			std::clog << "video/info: Saved window position outside of current display set-up; resetting to " << winOrigin.x << "," << winOrigin.y << std::endl;
+		}
+		SDL_Point winEnd {(winOrigin.x + width), (winOrigin.y + height)};
+		if (SDL_PointInRect(&winEnd, &totalSize) == SDL_FALSE) {
+			if (winEnd.x > totalSize.w) {
+			width = totalSize.w;
+			winOrigin.x = (totalSize.w - width);
+			}
+			if (winEnd.y > totalSize.h) {
+			height = totalSize.h;
+			winOrigin.y = (totalSize.y - height);
+			}
+			std::clog << "video/info: Saved window size outside of current display set-up; resetting to " << width << "x" << height << std::endl;
+		}		
+		std::clog << "video/info: Create window dimensions: " << width << "x" << height << " on screen position: " << winOrigin.x << "x" << winOrigin.y << std::endl;
+		screen = SDL_CreateWindow(PACKAGE " " VERSION, winOrigin.x, winOrigin.y, width, height, flags);
+		if (!screen) throw std::runtime_error(std::string("SDL_CreateWindow failed: ") + SDL_GetError());
+		SDL_GLContext glContext = SDL_GL_CreateContext(screen);
+		if (glContext == nullptr) throw std::runtime_error(std::string("SDL_GL_CreateContext failed with error: ") + SDL_GetError());
+		if (epoxy_gl_version() < 33) throw std::runtime_error("OpenGL 3.3 is required but not available");	
 		glutil::GLErrorChecker error("Initializing buffers");
 		{
 			initBuffers();
@@ -94,7 +148,6 @@ Window::Window() {
 	std::clog << "video/info: GL_RENDERER:   " << glGetString(GL_RENDERER) << std::endl;
 	// Extensions would need more complex outputting, otherwise they will break clog.
 	//std::clog << "video/info: GL_EXTENSIONS: " << glGetString(GL_EXTENSIONS) << std::endl;
-	if (epoxy_gl_version() < 33) throw std::runtime_error("OpenGL 3.3 is required but not available");	
 	createShaders();
 	resize();
 	SDL_ShowWindow(screen);