video: Added a hint to override the display's usable bounds.
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
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index ab21210..fcc04e9 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -1229,6 +1229,20 @@ extern "C" {
*/
#define SDL_HINT_WAVE_FACT_CHUNK "SDL_WAVE_FACT_CHUNK"
+/*
+ * \brief Override for SDL_GetDisplayUsableBounds()
+ *
+ * If set, this hint will override the expected results for
+ * SDL_GetDisplayUsableBounds() for display index 0. Generally you don't want
+ * to do this, but this allows an embedded system to request that some of the
+ * screen be reserved for other uses when paired with a well-behaved
+ * application.
+ *
+ * The contents of this hint must be 4 comma-separated integers, the first
+ * is the bounds x, then y, width and height, in that order.
+ */
+#define SDL_HINT_DISPLAY_USABLE_BOUNDS "SDL_DISPLAY_USABLE_BOUNDS"
+
/**
* \brief An enumeration of hint priorities
*/
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index b37942a..de0bc1c 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -706,13 +706,25 @@ SDL_GetDisplayBounds(int displayIndex, SDL_Rect * rect)
return 0; /* !!! FIXME: should this be an error if (rect==NULL) ? */
}
-int SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect)
+static int
+ParseDisplayUsableBoundsHint(SDL_Rect *rect)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_DISPLAY_USABLE_BOUNDS);
+ return hint && (SDL_sscanf(hint, "%d,%d,%d,%d", &rect->x, &rect->y, &rect->w, &rect->h) == 4);
+}
+
+int
+SDL_GetDisplayUsableBounds(int displayIndex, SDL_Rect * rect)
{
CHECK_DISPLAY_INDEX(displayIndex, -1);
if (rect) {
SDL_VideoDisplay *display = &_this->displays[displayIndex];
+ if ((displayIndex == 0) && ParseDisplayUsableBoundsHint(rect)) {
+ return 0;
+ }
+
if (_this->GetDisplayUsableBounds) {
if (_this->GetDisplayUsableBounds(_this, display, rect) == 0) {
return 0;