From 79ca3605fb683eabb612c3ae823f52076f1a23e0 Mon Sep 17 00:00:00 2001
From: Rudolf Polzer <divVerent@xonotic.org>
Date: Tue, 17 Mar 2015 12:03:11 +0100
Subject: [PATCH] Support workarea limiting of the window size.

Requires an engine change to support getresolution(-2) to return the workarea.
---
 qcsrc/menu/xonotic/slider_resolution.qc | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/qcsrc/menu/xonotic/slider_resolution.qc b/qcsrc/menu/xonotic/slider_resolution.qc
index 476c441ed..c14436281 100644
--- a/qcsrc/menu/xonotic/slider_resolution.qc
+++ b/qcsrc/menu/xonotic/slider_resolution.qc
@@ -7,6 +7,8 @@ CLASS(XonoticResolutionSlider) EXTENDS(XonoticTextSlider)
 	METHOD(XonoticResolutionSlider, saveCvars, void(entity))
 	METHOD(XonoticResolutionSlider, draw, void(entity))
 	ATTRIB(XonoticResolutionSlider, vid_fullscreen, float, -1)
+	ATTRIB(XonoticResolutionSlider, maxAllowedWidth, float, 0)
+	ATTRIB(XonoticResolutionSlider, maxAllowedHeight, float, 0)
 ENDCLASS(XonoticResolutionSlider)
 entity makeXonoticResolutionSlider();
 float updateConwidths(float width, float height, float pixelheight);
@@ -87,6 +89,10 @@ entity makeXonoticResolutionSlider()
 }
 void XonoticResolutionSlider_addResolution(entity me, float w, float h, float pixelheight)
 {
+	if (me.maxAllowedWidth && w > me.maxAllowedWidth)
+		return;
+	if (me.maxAllowedHeight && h > me.maxAllowedHeight)
+		return;
 	float i;
 	for (i = 0; i < me.nValues; ++i)
 	{
@@ -138,6 +144,8 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
 	}
 	// NOW we can safely clear.
 	me.clearValues(me);
+	me.maxAllowedWidth = 0;
+	me.maxAllowedHeight = 0;
 
 	if (fullscreen)
 	{
@@ -161,6 +169,21 @@ void XonoticResolutionSlider_loadResolutions(entity me, float fullscreen)
 
 	if(me.nValues == 0)
 	{
+		// Get workarea.
+		r = getresolution(-2);
+		// If workarea is not supported, get desktop size.
+		if(r.x == 0 && r.y == 0)
+			r = getresolution(-1);
+
+		// Add it, and limit all other resolutions to the workarea/desktop size.
+		if(r.x != 0 || r.y != 0)
+		{
+			me.maxAllowedWidth = r.x;
+			me.maxAllowedHeight = r.y;
+			me.addResolution(me, r.x, r.y, r.z);
+		}
+
+		// Add nice hardcoded defaults.
 		me.addResolution(me, 640, 480, 1); // pc res
 #if 0
 		me.addResolution(me, 720, 480, 1.125); // DVD NTSC 4:3
-- 
2.39.5