~rabbits/public-inbox

porporo: Respect the usable display bounds when calculating window size v1 PROPOSED

Jason Morley: 1
 Respect the usable display bounds when calculating window size

 1 files changed, 13 insertions(+), 5 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rabbits/public-inbox/patches/48223/mbox | git am -3
Learn more about email & git

[PATCH porporo] Respect the usable display bounds when calculating window size Export this patch

This change uses `SDL_GetDisplayUsableBounds` instead of `SDL_GetCurrentDisplayMode` to determine the available space when calculating the window size. It also centers the window within the usable bounds on platforms that support it.
---
 src/porporo.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/porporo.c b/src/porporo.c
index 9dc8020..0fdb06e 100644
--- a/src/porporo.c
+++ b/src/porporo.c
@@ -1,6 +1,7 @@
#include <SDL2/SDL.h>
#include <stdio.h>

#include "SDL2/SDL_rect.h"
#include "uxn.h"
#include "devices/system.h"
#include "devices/screen.h"
@@ -36,7 +37,6 @@ static int WIDTH, HEIGHT, reqdraw, olen;
static Varvara varvaras[RAM_PAGES], *order[RAM_PAGES], *wallpaper, *menu, *focused, *potato;
static Point2d camera, drag, cursor;
static enum Action action;
static SDL_DisplayMode DM;
static SDL_Window *gWindow = NULL;
static SDL_Renderer *gRenderer = NULL;
static SDL_Texture *gTexture = NULL;
@@ -607,11 +607,19 @@ init(void)
{
	if(SDL_Init(SDL_INIT_VIDEO) < 0)
		return system_error("Init", SDL_GetError());
	SDL_GetCurrentDisplayMode(0, &DM);
	WIDTH = (DM.w >> 3 << 3) - 0x20;
	HEIGHT = (DM.h >> 3 << 3) - 0x80;
	/*
	Get the usable window bounds and calculate the window position.
	This accounts for screen furniture like the dock on macOS. Unfortunately screen position isn't always respected in
	SDL ports (e.g., GNOME), but we do the work for platforms that do use it.
	*/
	SDL_Rect bounds;
	SDL_GetDisplayUsableBounds(0, &bounds);
	WIDTH = (bounds.w >> 3 << 3) - 0x20;
	HEIGHT = (bounds.h >> 3 << 3) - 0x80;
	printf("%dx%d[%02xx%02x]\n", WIDTH, HEIGHT, WIDTH >> 3, HEIGHT >> 3);
	gWindow = SDL_CreateWindow("Porporo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
	int x = ((bounds.w - WIDTH) / 2) + bounds.x;
	int y = ((bounds.h - HEIGHT) / 2) + bounds.y;
	gWindow = SDL_CreateWindow("Porporo", x, y, WIDTH, HEIGHT, SDL_WINDOW_SHOWN);
	if(gWindow == NULL)
		return system_error("Window", SDL_GetError());
	gRenderer = SDL_CreateRenderer(gWindow, -1, 0);
--
2.43.0