Handling maximized windows using SDL

Hello,

A colleague of mine, with whom I work on the game Bitfighter
(bitfighter.org), posted the following question on stackoverflow.com
and asked that I also post it to the SDL mailing list:

Here is the text:

—snip—
We recently ported Bitfighter from GLUT to SDL. There were numerous
benefits to doing this, but a few drawbacks as well, especially in the
area of window management.

Bitfighter runs in a fixed-aspect-ratio window (800x600 pixels). Users
can make their window any size they want, but we capture the resize
event and make adjustments to the requested size to ensure the window
keeps the correct proportions (using SDL_SetVideoMode).

(The following problem applies to Windows, but has not yet been tested
on other platforms. What I describe below refers specifically to
Windows, though I am looking for a platform-independent solution.)

Ordinarily, this works great, except when users maximze their window
by double clicking on the title bar or using the maximize button. In
that case, the window resize event is called with the a window size
approximating the screen size (minus some pixels for window
ornamentation). Unfortunately, when the window is maximized,
SDL_SetVideoMode has no effect (unlike GLUT which was able to resize a
maximized window). Furthermore, subsequent calls to SDL_GetVideoInfo
report the size we requested, not the actual current size of the
window, so it is hard to tell if the attempted resizing worked.

I am looking for a platform independent way to do any of the following
(in descending order of preference):

  1. Resize a window after it’s been maximized
  2. Detect when a window has been maximized so that, knowing I can’t
    resize it, I can at least adjust the video to be centered
  3. Prevent a window from being maximized (block double clicks on
    window title bar, use of the maximize button, and dragging the window
    to the top of the screen)

Bitfighter is written in C++, and we’re using the latest official
release of SDL.
—snap—

We are using SDL 1.2.14 at one of the most recent mercurial revisions
for Windows/Mac.

Would there be solutions to any of the above?

Thanks!
D

I have yet to have an issue with setting the video mode at any time or with
maximize or minimize. I’m thinking your issues are code specific. On an
additional note I’m not for anyone trying to block windows from working as
intended. What you do with it after it works as intended is another matter.
Please post some code so we can see what’s going on here.On Mon, Jan 2, 2012 at 9:56 AM, D B wrote:

Hello,

A colleague of mine, with whom I work on the game Bitfighter
(bitfighter.org), posted the following question on stackoverflow.com
and asked that I also post it to the SDL mailing list:

http://stackoverflow.com/questions/8679560/handling-maximized-windows-using-sdl

Here is the text:

—snip—
We recently ported Bitfighter from GLUT to SDL. There were numerous
benefits to doing this, but a few drawbacks as well, especially in the
area of window management.

Bitfighter runs in a fixed-aspect-ratio window (800x600 pixels). Users
can make their window any size they want, but we capture the resize
event and make adjustments to the requested size to ensure the window
keeps the correct proportions (using SDL_SetVideoMode).

(The following problem applies to Windows, but has not yet been tested
on other platforms. What I describe below refers specifically to
Windows, though I am looking for a platform-independent solution.)

Ordinarily, this works great, except when users maximze their window
by double clicking on the title bar or using the maximize button. In
that case, the window resize event is called with the a window size
approximating the screen size (minus some pixels for window
ornamentation). Unfortunately, when the window is maximized,
SDL_SetVideoMode has no effect (unlike GLUT which was able to resize a
maximized window). Furthermore, subsequent calls to SDL_GetVideoInfo
report the size we requested, not the actual current size of the
window, so it is hard to tell if the attempted resizing worked.

I am looking for a platform independent way to do any of the following
(in descending order of preference):

  1. Resize a window after it’s been maximized
  2. Detect when a window has been maximized so that, knowing I can’t
    resize it, I can at least adjust the video to be centered
  3. Prevent a window from being maximized (block double clicks on
    window title bar, use of the maximize button, and dragging the window
    to the top of the screen)

Bitfighter is written in C++, and we’re using the latest official
release of SDL.
—snap—

We are using SDL 1.2.14 at one of the most recent mercurial revisions
for Windows/Mac.

Would there be solutions to any of the above?

Thanks!
D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,

Here is a code sample that gets fired when SDL reports a window is
resized or maximized.

—snip—
void Event::onResize(ClientGame *game, S32 width, S32 height)
{
S32 canvasHeight = 600;
S32 canvasWidth = 800;

// Constrain window to correct proportions...
if((width - canvasWidth) > (height - canvasHeight))      // Wider

than taller
winSizeFact = max((F32) height / (F32)canvasHeight, .15);
else
winSizeFact = max((F32) width / (F32)canvasWidth, .15);

// Calculate new window size that best honors the user's intent
S32 newWidth  = (S32)floor(canvasWidth  * winSizeFact + 0.5f);

// virtual * (physical/virtual) = physical
S32 newHeight = (S32)floor(canvasHeight * winSizeFact + 0.5f);

S32 flags = 0;
flags = SDL_OPENGL | SDL_RESIZABLE;
SDL_SetVideoMode(newWidth, newHeight, 0, flags);

// Everything is fine if window hasn't been maximized
// If window HAS been maximized, the above line does nothing, and

SDL_GetVideoInfo will lie, reporting window size as newWidth and
newHeight
// How can we tell if we are in full screen mode? If we knew, we
could honor the maximize event, skip most of the above, and set our
// viewport appropriately, so the user got what they wanted!

glViewport(0, 0, newWidth, newHeight);

}
—snap—

This can be found in our codebase here:

Thanks!
DOn Thu, Jan 5, 2012 at 10:57 AM, R Manard wrote:

I have yet to have an issue with setting the video mode at any time or with
maximize or minimize. I’m thinking your issues are code specific. On an
additional note I’m not for anyone trying to block windows from working as
intended. What you do with it after it works as intended is another matter.
Please post some code so we can see what’s going on here.

On Mon, Jan 2, 2012 at 9:56 AM, D B <@D_B> wrote:

Hello,

A colleague of mine, with whom I work on the game Bitfighter
(bitfighter.org), posted the following question on stackoverflow.com
and asked that I also post it to the SDL mailing list:

http://stackoverflow.com/questions/8679560/handling-maximized-windows-using-sdl

Here is the text:

—snip—
We recently ported Bitfighter from GLUT to SDL. There were numerous
benefits to doing this, but a few drawbacks as well, especially in the
area of window management.

Bitfighter runs in a fixed-aspect-ratio window (800x600 pixels). Users
can make their window any size they want, but we capture the resize
event and make adjustments to the requested size to ensure the window
keeps the correct proportions (using SDL_SetVideoMode).

(The following problem applies to Windows, but has not yet been tested
on other platforms. What I describe below refers specifically to
Windows, though I am looking for a platform-independent solution.)

Ordinarily, this works great, except when users maximze their window
by double clicking on the title bar or using the maximize button. In
that case, the window resize event is called with the a window size
approximating the screen size (minus some pixels for window
ornamentation). Unfortunately, when the window is maximized,
SDL_SetVideoMode has no effect (unlike GLUT which was able to resize a
maximized window). Furthermore, subsequent calls to SDL_GetVideoInfo
report the size we requested, not the actual current size of the
window, so it is hard to tell if the attempted resizing worked.

I am looking for a platform independent way to do any of the following
(in descending order of preference):

  1. ? ?Resize a window after it’s been maximized
  2. ? ?Detect when a window has been maximized so that, knowing I can’t
    resize it, I can at least adjust the video to be centered
  3. ? ?Prevent a window from being maximized (block double clicks on
    window title bar, use of the maximize button, and dragging the window
    to the top of the screen)

Bitfighter is written in C++, and we’re using the latest official
release of SDL.
—snap—

We are using SDL 1.2.14 at one of the most recent mercurial revisions
for Windows/Mac.

Would there be solutions to any of the above?

Thanks!
D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org