Alt-F4 not working on Windows

Hi,
I’ve been using the SDL for one week now and I’m quite happy with it.

But there’s one thing I noticed: When I press Alt-F4 to close the App it won’t.
I’m catching the SDL_QUIT event, but it only occurs when I press the X to close the window, Alt-F4 won’t do the job.

In the release notes it says that from version 1.2.10 this problem is fixed, I use the SDL-devel-1.2.13-VC6.zip package.

Any Ideas?

You need to check your code. Alt + F4 works on windows. You have to
check for the event of Alt + F4 and then quit.

    SDL_Event event;
int flag;
flag = SDL_PollEvent(&event);
if(flag) { // flag == 1 implies event to be checked for
	switch(event.type) {
		case SDL_QUIT:
			return false; // no need for break;
		case SDL_KEYUP:
		case SDL_KEYDOWN:
			cout << "Key !\n";
			if(event.key.keysym.sym == SDLK_F4 && (event.key.keysym.mod ==

KMOD_LALT || event.key.keysym.mod == KMOD_RALT) ) return false;
//return true;
break;
default:
break;
}

This is a code snippet of how I catch alt + f4 in one of my apps. the
snippet returns whether to keep running or not.On Wed, Apr 30, 2008 at 11:53 PM, Christoph Kobe wrote:

Hi,
I’ve been using the SDL for one week now and I’m quite happy with it.

But there’s one thing I noticed: When I press Alt-F4 to close the App it won’t.
I’m catching the SDL_QUIT event, but it only occurs when I press the X to close the window, Alt-F4 won’t do the job.

In the release notes it says that from version 1.2.10 this problem is fixed, I use the SDL-devel-1.2.13-VC6.zip package.

Any Ideas?


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

If that’s what has to be done, then IMO it hasn’t been fixed. - is a Windows standard. It always means “quit” on every program. (A few games I’ve seen override this behavior, which I consider very poor design.) Since by default, - means “quit”, it should always generate a SDL_QUIT event, not a SDL_KEYDOWN event. (Same goes for -Q on Macs.)> ----- Original Message -----

From: abhinav.lele@gmail.com (Abhinav Lele)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, April 30, 2008 3:07:10 PM
Subject: Re: [SDL] Alt-F4 not working on Windows

You need to check your code. Alt + F4 works on windows. You have to
check for the event of Alt + F4 and then quit.

I disagree. Why don’t you just exit your application if want ALT-F4 to quit?On Wed, Apr 30, 2008 at 03:49:43PM -0700, Mason Wheeler wrote:

If that’s what has to be done, then IMO it hasn’t been fixed. - is a Windows standard. It always means “quit” on every program. (A few games I’ve seen override this behavior, which I consider very poor design.) Since by default, - means “quit”, it should always generate a SDL_QUIT event, not a SDL_KEYDOWN event. (Same goes for -Q on Macs.)

----- Original Message ----
From: Abhinav Lele <abhinav.lele at gmail.com>
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, April 30, 2008 3:07:10 PM
Subject: Re: [SDL] Alt-F4 not working on Windows

You need to check your code. Alt + F4 works on windows. You have to
check for the event of Alt + F4 and then quit.


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

Mason,

Why do you presume Alt+F4 to be a quit trigger. Here is an example.
Blender. Famous 3D design application. Although blender traps alt+f4,
but if you look the shortcut given for exit in its menu, it shows Ctrl

  • Q.
    SDL has to be generic you cannot always assume that Alt+F4 is quit.> If that’s what has to be done, then IMO it hasn’t been fixed. - is a Windows standard. It always means “quit” on every program. (A few games I’ve seen override this behavior, which I consider very poor design.) Since by default, - means “quit”, it should always generate a SDL_QUIT event, not a SDL_KEYDOWN event. (Same goes for -Q on Macs.)

SDL runs on more than just windows.

-JustinOn Wed, Apr 30, 2008 at 6:49 PM, Mason Wheeler wrote:

- is a Windows standard.

That’s the point. Alt-F4 is part of the operating system’s interface;
that should not concern the programmer any more than “minimize” or
Alt-Tab. If you check for Alt-F4 events yourself, you’re making the
unreasonable assumption that all operating systems supported by SDL have
this convention, which is not the case. On Linux it is perfectly
reasonable for the user to remap Alt-F4 to something else, and have some
other shortcut for “close”.On Linux, the Close button, Alt-F4, Ctrl+C, SIGTERM etc. all generate an SDL_QUIT event; I assume this is also the intended behavior on Windows, and it ought to be if it’s not. Abhinav Lele wrote:

Mason,

Why do you presume Alt+F4 to be a quit trigger. Here is an example.
Blender. Famous 3D design application. Although blender traps alt+f4,
but if you look the shortcut given for exit in its menu, it shows Ctrl

  • Q.
    SDL has to be generic you cannot always assume that Alt+F4 is quit.

If that’s what has to be done, then IMO it hasn’t been fixed. - is a Windows standard. It always means “quit” on every program. (A few games I’ve seen override this behavior, which I consider very poor design.) Since by default, - means “quit”, it should always generate a SDL_QUIT event, not a SDL_KEYDOWN event. (Same goes for -Q on Macs.)


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


Jacob Welsh
TJHSST, Class of 2008
@Jacob_Welsh | http://www.tjhsst.edu/~jwelsh/

Which is why I said that UNDER WINDOWS, - should always generate SDL_QUIT. Other platforms can have other behavior.> ----- Original Message -----

From: jmcoleman@gmail.com (Justin Coleman)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, April 30, 2008 4:34:42 PM
Subject: Re: [SDL] Alt-F4 not working on Windows

On Wed, Apr 30, 2008 at 6:49 PM, Mason Wheeler <@Mason_Wheeler> wrote:

- is a Windows standard.

SDL runs on more than just windows.

-Justin

That’s what I was gonna say: If you specifically code to catch the conventional alt-F4, then your program will not follow the conventions on other systems (i.e. no longer multi-OS-friendly). But if alt-F4 does generate an SDL_QUIT event, I think it would be tougher to work around than having to use preprocessor directives in the other case. Despite this, my personal preference would be to send SDL_QUIT… Someone should make the call on this, but until then, preprocessor is the way to go. Just add an #ifdef WIN32 or something.

Jonny DDate: Wed, 30 Apr 2008 19:36:37 -0400
From: welshjf@gmail.com
To: sdl at lists.libsdl.org
Subject: Re: [SDL] Alt-F4 not working on Windows

That’s the point. Alt-F4 is part of the operating system’s interface;
that should not concern the programmer any more than “minimize” or
Alt-Tab. If you check for Alt-F4 events yourself, you’re making the
unreasonable assumption that all operating systems supported by SDL
have this convention, which is not the case. On Linux it is perfectly
reasonable for the user to remap Alt-F4 to something else, and have
some other shortcut for “close”.

On Linux, the Close button, Alt-F4, Ctrl+C, SIGTERM etc. all generate an SDL_QUIT event; I assume this is also the intended behavior on Windows, and it ought to be if it’s not. Abhinav Lele wrote:

Mason,

Why do you presume Alt+F4 to be a quit trigger. Here is an example.
Blender. Famous 3D design application. Although blender traps alt+f4,
but if you look the shortcut given for exit in its menu, it shows Ctrl

  • Q.
    SDL has to be generic you cannot always assume that Alt+F4 is quit.

    If that’s what has to be done, then IMO it hasn’t been fixed. - is a Windows standard. It always means “quit” on every program. (A few games I’ve seen override this behavior, which I consider very poor design.) Since by default, - means “quit”, it should always generate a SDL_QUIT event, not a SDL_KEYDOWN event. (Same goes for -Q on Macs.)


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


Jacob Welsh
TJHSST, Class of 2008
welshjf at gmail.com | http://www.tjhsst.edu/~jwelsh/


Express yourself wherever you are. Mobilize!
http://www.gowindowslive.com/Mobile/Landing/Messenger/Default.aspx?Locale=en-US?ocid=TAG_APRIL

Which means it’s not a standard. If it should be a standard for Windows,
then it’s up to Windows to handle it by gracefully terminating the program.
If that’s the way you want it to work, complain to Bill Gates.

JeffOn Wed April 30 2008 15:49, Mason Wheeler wrote:

- is a Windows standard.

Thats pretty short sighted Jeff, I’m an OSS proponent as well, but come on :stuck_out_tongue:

---- Jeff <j_post at pacbell.net> wrote:> On Wed April 30 2008 15:49, Mason Wheeler wrote:

- is a Windows standard.

Which means it’s not a standard. If it should be a standard for Windows,
then it’s up to Windows to handle it by gracefully terminating the program.
If that’s the way you want it to work, complain to Bill Gates.

Jeff


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

Windows (or any operating system) can’t gracefully terminate any non-trivial program. The program has to gracefully terminate itself with its own cleanup routines to take care of allocated memory, temporary files, network connections, and howevermany other things.> ----- Original Message -----

From: j_post@pacbell.net (Jeff Post)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, April 30, 2008 8:10:16 PM
Subject: Re: [SDL] Alt-F4 not working on Windows

On Wed April 30 2008 15:49, Mason Wheeler wrote:

- is a Windows standard.

Which means it’s not a standard. If it should be a standard for Windows,
then it’s up to Windows to handle it by gracefully terminating the program.
If that’s the way you want it to work, complain to Bill Gates.

Jeff

Except it’s not up to the OS to terminate programs; programs generally
terminate themselves, and in this case SDL is providing the means. Your
comment probably doesn’t progress the discussion very well. The question
is, should SDL adhere to the standards of the operating system which is
supports or not. To weigh in, I think it’s a good idea in this case.

chaz> ----- Original Message -----

From: j_post@pacbell.net (Jeff Post)
To: "A list for developers using the SDL library. (includes SDL-announce)"

Sent: Wednesday, April 30, 2008 9:10 PM
Subject: Re: [SDL] Alt-F4 not working on Windows

On Wed April 30 2008 15:49, Mason Wheeler wrote:

- is a Windows standard.

Which means it’s not a standard. If it should be a standard for Windows,
then it’s up to Windows to handle it by gracefully terminating the
program.
If that’s the way you want it to work, complain to Bill Gates.

Jeff


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

Hi,
I’ve been using the SDL for one week now and I’m quite happy with it.

But there’s one thing I noticed: When I press Alt-F4 to close the App it won’t.
I’m catching the SDL_QUIT event, but it only occurs when I press the X to close the window, Alt-F4 won’t do the job.

Strange, can you enter a bug into bugzilla for it?
http://bugzilla.libsdl.org

Thanks!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

Except it’s not up to the OS to terminate programs;

If a particular key combination is alleged to be a universal quit for any
program, then it is up to the OS to terminate the program. It’s the
equivalent of the Unix ‘kill -9’ command. Or have I not understood Mason’s
complaint?

The question
is, should SDL adhere to the standards of the operating system which is
supports or not. To weigh in, I think it’s a good idea in this case.

I agree. A good idea, however, is not the same as a requirement. I don’t see
the failure to exit upon receiving the key combination in Windows
without explicit code provided by the programmer as a failure of SDL. As
someone else pointed out, the programmer should provide such code (through
ifdef’s if necessary).

Sam certainly has the ability to detect in the low level code, and
if the underlying OS is Windows, convert it into an SDL_Quit event. It might
be a good idea, but it’s not his obligation.

To be fair, I should point out that if my original post caused contention,
it’s my fault. In my later years I’ve become exceedingly weary of
Windows-centric people thinking that they are computer experts because they
are Windows experts. It’s like claiming to be a master chef because you’ve
learned how to cook spaghetti very well.

Sam has proven himself to be a master chef. Most of us have not.

JeffOn Wed April 30 2008 20:36, Charles McGarvey wrote:

Any decent OS will indeed take care of allocated memory, temp files, and other
resources used by a program when it terminates. I believe even Windows does,
but since I don’t use Windows I can’t say for sure.

JeffOn Wed April 30 2008 20:22, Mason Wheeler wrote:

Windows (or any operating system) can’t gracefully terminate any
non-trivial program. The program has to gracefully terminate itself with
its own cleanup routines to take care of allocated memory, temporary files,
network connections, and howevermany other things.

I’m sorry, but have you ever written a program that requires any serious cleanup? Because you’re beginning to sound like you haven’t. Yes, the OS can deallocate a block on the heap or close files. In your other post you mentioned the Unix ‘kill -9’ command, which does these things. Windows has something similar, through the Task Manager. But that’s forced termination without the benefit of cleanup, and there’s a big difference between that and a “graceful” shutdown.

Some programs open data files with write access, and need to set them to certain states before closing or risk data loss or corruption. (Especially certain database styles! One game I have is pretty stable, and I’m glad about that because if it ever crashes you have to reinstall the whole program to fix the resulting database corruption.) Some programs open network connections to other computers and would like to let the other system know they’re logging off. And if you’re working directly with video memory, terminating abruptly under certain circumstances can leave it in an undefined state, with all sorts of nasty consequences for the rest of the system. These are things that the OS can’t handle automatically because it doesn’t know the details.

- is not a “kill” command. It’s a “close” command. It’s another way to do the exact same thing as clicking the red X in the corner: send a signal through Windows’s event system to the program that it’s time to close the current window, which usually also means shutting down the program, unless there are other independent windows active. The program is then responsible for actually closing the window when it receives this event, giving it the chance to clean up after itself. In other words, precisely what SDL_QUIT is there for.

The original point that was made is that clicking the X button generates an SDL_QUIT event, and under Windows - is supposed to be EXACTLY functionally equivalent to it, but it isn’t because SDL grabs input away from the window controller and someone overlooked that. The Mac has something similar, the - combination, which also ought to automatically generate SDL_QUIT on a Mac. Not sure about *nix, but if it does, then that keystroke should do the same under *nix platforms. It’s part of the “SDL just works” magic that makes so many of us like programming with it.

Besides, Sam’s already acknowledged this as a bug. So would you mind dropping the “Windows is not God” crusading, please?> ----- Original Message -----

From: j_post@pacbell.net (Jeff Post)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, April 30, 2008 10:34:34 PM
Subject: Re: [SDL] Alt-F4 not working on Windows

On Wed April 30 2008 20:22, Mason Wheeler wrote:

Windows (or any operating system) can’t gracefully terminate any
? non-trivial program. The program has to gracefully terminate itself with
its own cleanup routines to take care of allocated memory, temporary files,
network connections, and howevermany other things.

Any decent OS will indeed take care of allocated memory, temp files, and other
resources used by a program when it terminates. I believe even Windows does,
but since I don’t use Windows I can’t say for sure.

Jeff

Hi,
I’ve been using the SDL for one week now and I’m quite happy with it.

But there’s one thing I noticed: When I press Alt-F4 to close the App it won’t.
I’m catching the SDL_QUIT event, but it only occurs when I press the X to close the window, Alt-F4 won’t do the job.

Strange, can you enter a bug into bugzilla for it?
http://bugzilla.libsdl.org

Thanks!
-Sam Lantinga, Lead Software Engineer, Blizzard Entertainment

It is now Bug 576:
ALT-F4 does not generate an SDL_QUIT event on WindowsOn Wed, 30 Apr 2008 20:50:06 -0700 Sam Lantinga wrote:

Christoph
from Hamburg, Germany

- is a Windows standard. It always means “quit” on every program.

Alt-F4 on Windows means “close window”, not “quit”. In SDL 1.2, it’s
pretty much the same, but with 1.3 supporting multiple windows, it
won’t be.On Wed, Apr 30, 2008 at 6:49 PM, Mason Wheeler wrote:


http://pphaneuf.livejournal.com/

While I’m not a majorly active developer in SDL at the moment, nor
very active in the mailing lists… I wouldn’t mind throwing my two
cents into this foray.

Synopsis: this doesn’t belong in SDL… much like many of the other
’why doesnt SDL do foo?’ requests that penetrate beyond the 'SIMPLE’
part of the SDL name. If there’s a desire for a nice global ‘catch
all common program termination keyboard combinations’, I’d suggest the
creation of SDL_quit library or similar.

Clicking on the lil X, red circle, etc etc etc, causes the window
manager or similar to give SDL an eventual SDL_QUIT message. It’s
therefore up to window manager to signal the ‘please close’.

I’ve played plenty of games under windows where ALT-F4 doesn’t close
the game. And in my humble opinion it shouldn’t. Granted, ALT-F4 is
a strange keyboard combination, but what if it was plausible to bind
something as such ? Similar to CTRL-number, ALT-number, etc.

If ALT-F4 is supposed to generate an SDL_QUIT under windows, then what
about lining up code that generates an SDL_QUIT via some automagical
window manager / OS detection routine and associated keyboard
combinations ? And what if I wanted to make any of those given key
combinations usable within my application rather than force a program
close ?

-Will> On Wed, Apr 30, 2008 at 6:49 PM, Mason Wheeler wrote:

- is a Windows standard. It always means “quit” on every program.