Skip to content

Commit 2f6cf5a

Browse files
committed
refactor: limit default window size to 3x the base resolution, and add a buffer so to always be less than the monitor size
1 parent b3c9429 commit 2f6cf5a

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/base/zapp.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,21 @@ bool is_headless()
138138
return headless;
139139
}
140140

141-
// If (saved_width, saved_height) is not -1, ensures that fits in the primary monitor. If neither are true, fall
141+
// If (saved_width, saved_height) is >0, ensures that fits in the primary monitor. If neither are true, fall
142142
// back to default.
143143
// Default will scale up (base_width, base_height) by an integer amount to fill up the primary monitor
144-
// as much as possible.
144+
// as much as possible, up to 3x.
145145
std::pair<int, int> zc_get_default_display_size(int base_width, int base_height, int saved_width, int saved_height)
146146
{
147147
ALLEGRO_MONITOR_INFO info;
148148
al_get_monitor_info(0, &info);
149149
int mw = info.x2 - info.x1;
150150
int mh = info.y2 - info.y1;
151+
if (saved_width > 0 && saved_height > 0 && saved_width <= mw && saved_height <= mh)
152+
{
153+
return {saved_width, saved_height};
154+
}
155+
151156
#ifdef ALLEGRO_MACOSX
152157
// https://talk.automators.fm/t/getting-screen-dimensions-while-accounting-the-menu-bar-dock-and-multiple-displays/13639
153158
mh -= 38;
@@ -156,11 +161,12 @@ std::pair<int, int> zc_get_default_display_size(int base_width, int base_height,
156161
// Title bar.
157162
mh -= 23;
158163
#endif
159-
if (saved_width != -1 && saved_height != -1 && saved_width <= mw && saved_height <= mh)
160-
{
161-
return {saved_width, saved_height};
162-
}
164+
// Small buffer, so the default window is never as big as the monitor.
165+
mw -= 50;
166+
mh -= 50;
167+
163168
int s = std::min(mh / base_height, mw / base_width);
169+
s = std::min(3, s);
164170
int w = base_width * s;
165171
int h = base_height * s;
166172
return {w, h};

0 commit comments

Comments
 (0)