Should SDL2 handle standard keyboard shortcuts?

I asked Sam why SDL2 is not generating a WM_CLOSE when the user presses
ALT+F4 under Windows, and he told me that by design SDL lets the user
handle all combinations of key presses, though this forces the developer to
write some platform dependent code to catch those events (ALT+F4 on
Windows, CMD+Q on OS X…etc?). He said he is on the fence on this issue
and to propose a poll on the list, so here it is…the “Grand 2012 Keyboard
System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.–
Gabriel.

I’m against it mostly. In most SDL apps, the developer needs to recognize
key presses and will have to code this anyway. Plus if a GUI is needed, for
desktop apps, I always use Qt which handles keys very nicely. If anything,
this functionality should be an add on library and not in the SDL core, or
something that can be conditionally added via configure.

  • Swyped from my droid.On Jul 26, 2012 6:04 PM, “Gabriel Jacobo” wrote:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user presses
ALT+F4 under Windows, and he told me that by design SDL lets the user
handle all combinations of key presses, though this forces the developer to
write some platform dependent code to catch those events (ALT+F4 on
Windows, CMD+Q on OS X…etc?). He said he is on the fence on this issue
and to propose a poll on the list, so here it is…the “Grand 2012 Keyboard
System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.


Gabriel.


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

Alt+F4 is a built-in behavior on Windows. If you start an app with no menu
and no accelerators, just CreateWindow(), I’m about 99% sure that Alt+F4
generates WM_CLOSE. To me that sounds like SDL2 must go out of its way to
inhibit the natural behavior of the application. Aside from extra code, I
don’t think this is the right idea: users on their respective platforms
expect to be able to quit it the “usual” way, whatever that may be. If I
made an app with SDL, I would want it to “feel” native, not feel
"crossplatform" ( and believe me, some toolkits and libraries do – Java
Swing, looking at you) in a way that defies my expectations.

So my vote is native actions.

PatrickOn Thu, Jul 26, 2012 at 6:03 PM, Gabriel Jacobo wrote:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user presses
ALT+F4 under Windows, and he told me that by design SDL lets the user
handle all combinations of key presses, though this forces the developer to
write some platform dependent code to catch those events (ALT+F4 on
Windows, CMD+Q on OS X…etc?). He said he is on the fence on this issue
and to propose a poll on the list, so here it is…the “Grand 2012 Keyboard
System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.


Gabriel.


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

Agreed.? If the user hits ALT-F4 (or COMMAND-Q or whatever the equivalent is on other platforms) and your program doesn’t respond to that as a close request, it’s doing something wrong.________________________________
From: Patrick Baggett <baggett.patrick at gmail.com>
To: SDL Development List
Sent: Thursday, July 26, 2012 5:01 PM
Subject: Re: [SDL] Should SDL2 handle standard keyboard shortcuts?

Alt+F4 is a built-in behavior on Windows. If you start an app with no menu and no accelerators, just CreateWindow(), I’m about 99% sure that Alt+F4 generates WM_CLOSE. To me that sounds like SDL2 must go out of its way to inhibit the natural behavior of the application. Aside from extra code, I don’t think this is the right idea: users on their respective platforms expect to be able to quit it the “usual” way, whatever that may be. If I made an app with SDL, I would want it to “feel” native, not feel “crossplatform” ( and believe me, some toolkits and libraries do – Java Swing, looking at you) in a way that defies my expectations.

So my vote is native actions.

Patrick

2012/7/26 Patrick Baggett <baggett.patrick at gmail.com>

Alt+F4 is a built-in behavior on Windows. If you start an app with no menu
and no accelerators, just CreateWindow(), I’m about 99% sure that Alt+F4
generates WM_CLOSE. To me that sounds like SDL2 must go out of its way to
inhibit the natural behavior of the application. Aside from extra code, I
don’t think this is the right idea: users on their respective platforms
expect to be able to quit it the “usual” way, whatever that may be. If I
made an app with SDL, I would want it to “feel” native, not feel
"crossplatform" ( and believe me, some toolkits and libraries do
Java Swing, looking at you) in a way that defies my expectations.

So my vote is native actions.

Patrick

As a sidenote, SDL doesn’t go out of its way to inhibit this behaviour, it
simply swallows the keypresses so they don’t reach the default Windows
handler.–
Gabriel.

Good.? Then it shouldn’t take much to get it to stop doing that.________________________________
From: Gabriel Jacobo
To: SDL Development List
Sent: Thursday, July 26, 2012 5:41 PM
Subject: Re: [SDL] Should SDL2 handle standard keyboard shortcuts?

2012/7/26 Patrick Baggett <baggett.patrick at gmail.com>

Alt+F4 is a built-in behavior on Windows. If you start an app with no menu and no accelerators, just CreateWindow(), I’m about 99% sure that Alt+F4 generates WM_CLOSE. To me that sounds like SDL2 must go out of its way to inhibit the natural behavior of the application. Aside from extra code, I don’t think this is the right idea: users on their respective platforms expect to be able to quit it the “usual” way, whatever that may be. If I made an app with SDL, I would want it to “feel” native, not feel “crossplatform” ( and believe me, some toolkits and libraries do – Java Swing, looking at you) in a way that defies my expectations.

So my vote is native actions.

Patrick

As a sidenote, SDL doesn’t go out of its way to inhibit this behaviour, it simply swallows the keypresses so they don’t reach the default Windows handler.?


Gabriel.


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

Personally, I would rather be in control of this. It does not take
much code to catch a alt-f4, then quit for those that want it.

-1 for builtin alt-f4–
Nathan Coulson (conathan)

Location: British Columbia, Canada
Timezone: PST (-8)
Webpage: http://www.nathancoulson.com

You’re not supposed to be in control of that.? The user is.?

Unless you’re writing some sort of meta-program such as a virtual machine or remote desktop client, the system-defined quit hotkey has one and only one meaning, which is universal and completely unambiguous,and if you don’t honor it there’s a serious problem with your program.________________________________
From: Nathan Coulson
To: Mason Wheeler <@Mason_Wheeler>; SDL Development List
Sent: Thursday, July 26, 2012 7:53 PM
Subject: Re: [SDL] Should SDL2 handle standard keyboard shortcuts?

Personally, I would rather be in control of this.? It does not take
much code to catch a alt-f4, then quit for those that want it.

-1 for builtin alt-f4


Nathan Coulson (conathan)

Location: British Columbia, Canada
Timezone: PST (-8)
Webpage: http://www.nathancoulson.com

Rather than provide this as an automagic transformation inside SDL2,
this could simply be another helper function that maps key events to
WM_CLOSE events and covers all supported platforms using a stack of
#if’s and lives inside the keyboard subsystem. Users can then choose to
chain this into the event processing for ease of use or write their own
event handlers.
–AndreasOn 7/26/2012 4:03 PM, Gabriel Jacobo wrote:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user
presses ALT+F4 under Windows, and he told me that by design SDL lets
the user handle all combinations of key presses, though this forces
the developer to write some platform dependent code to catch those
events (ALT+F4 on Windows, CMD+Q on OS X…etc?). He said he is on the
fence on this issue and to propose a poll on the list, so here it
is…the “Grand 2012 Keyboard System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.


Gabriel.


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

Well, it’s a cross platform lib so I would only add it all platform do the
same. The point is to bring os the os together in a common diagram that
supports making games and applications. If it changes then we need to worry
about how to avoid it if this behavior is not desired too. Since i think
alt f4 is not universal i vote no.

besidesthe code to do it is easily done like a guy said with code you
already are doing.

oh, also if it was expected then windows would just do it without asking
like when u click the x. instead it lets the coder choose since not
everyone wants.On Fri, Jul 27, 2012 at 1:31 AM, R Manard <@R_Manard> wrote:

Well, it’s a cross platform lib so I would only add it all platform do the
same. The point is to bring os the os together in a common diagram that
supports making games and applications. If it changes then we need to worry
about how to avoid it if this behavior is not desired too. Since i think
alt f4 is not universal i vote no.

besidesthe code to do it is easily done like a guy said with code you
already are doing.

This is the important point for me. IMHO SDL shouldn’t swallow
keypresses except when explicitly told to do so or when the platform
won’t handle them anyway.

I know that this will work on Linux (depending on the WM of course) and
if I understood Patrick and Gabriel right this will work on Windows as
well. I guess it will work on OS X too.

So I vote that SDL should only provide default shortcuts if the platform
doesn’t provide it’s own shortcuts and mechanisms for them.On 27.07.2012 02:41, Gabriel Jacobo wrote:

2012/7/26 Patrick Baggett <baggett.patrick at gmail.com>

Alt+F4 is a built-in behavior on Windows. If you start an app with no menu
and no accelerators, just CreateWindow(), I’m about 99% sure that Alt+F4
generates WM_CLOSE. To me that sounds like SDL2 must go out of its way to
inhibit the natural behavior of the application. Aside from extra code, I
don’t think this is the right idea: users on their respective platforms
expect to be able to quit it the “usual” way, whatever that may be. If I
made an app with SDL, I would want it to “feel” native, not feel
"crossplatform" ( and believe me, some toolkits and libraries do
Java Swing, looking at you) in a way that defies my expectations.

So my vote is native actions.

Patrick

As a sidenote, SDL doesn’t go out of its way to inhibit this behaviour, it
simply swallows the keypresses so they don’t reach the default Windows
handler.

Quoth Gabriel Jacobo , on 2012-07-26 20:03:40 -0300:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user presses
ALT+F4 under Windows, and he told me that by design SDL lets the user
handle all combinations of key presses, though this forces the developer to
write some platform dependent code to catch those events (ALT+F4 on
Windows, CMD+Q on OS X…etc?). He said he is on the fence on this issue
and to propose a poll on the list, so here it is…the “Grand 2012 Keyboard
System Shortcuts Poll”.

The point of using SDL is that I don’t have to do extensive research
on the platform UI, and I especially don’t have to keep up to date
with every version of the target platform’s UI or replicate all of
its behavior in my own code. There’s always the possibility of
collisions if I design my application to use a gesture that’s reserved
on a platform I hadn’t “ported” to yet, of course, but those can often
be arranged to be rare.

(I’m not even sure how the “handle everything” case would work on X11
unless you do something silly like grab the keyboard all the time; the
window manager gets first pick, doesn’t it? My X is kind of rusty.)

So to make it simple to make good applications, don’t interfere with
the platform gestures (which means divert them before they hit the
application if that’s how the underlying code needs to work to do
that).

If you want to get fancier, have a switch to defer this processing and
have the user call SDL_DefWindowProc() (though presumably not named
that) on anything they didn’t need, so that they get first capture of
events but any noninterfering platform gestures still happen, where
this is supported. Then if I port to QuuxOS which for some reason
uses the right arrow key as “quit”, I can consciously decide to break
with tradition by toggling the switch only when running on QuuxOS and
adding my own diversion logic, without affecting the code for all
other platforms.

There’s also a case to be made for fullscreen mode being fully
input-opaque, but there’s already input grabs for that, right?

—> Drake Wilson

Hi,

One could write an add on library to handle common keyboard shortcuts.
So no, this doesn’t need to be in the core.

Regards,
– BrianOn 27 July 2012 00:03, Gabriel Jacobo wrote:

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.

The thing is, SDL already does this… but only for some platforms. Take
the example of iOS, where failing to respond to a particular button event
is not acceptable. Each platform has an expected user experience that is
troubling for every single dev to reimplement. It’s especially bad for
libraries with functions that have an event loop.

I vote +1 to mapping standard OS button combos to SDL quit events.
However, there must be a way to override this or else make it enabled
explicitly. You can make it simple (just OS -> quit events) or powerful
(any combo -> callback). I don’t know which is better for SDL2.

Jonny D

Apologies if someone has already suggested this, but is there a case
for making it optional via a hint? It seems like you can make a
convincing case for both possibilities.

The other option is to modify the API in some way that allows you to
specify whether or not to pass on key presses to the OS, as you handle
them in the SDL event loop. This is probably less attractive.

If I had to choose one or the other, I would go with letting the OS
deal with key presses it knows about. One of the nice things about SDL
is that it tends not to “get in the way”. Having SDL swallow the OS
combos seems to violate that.On Thu, 26 Jul 2012 20:03:40 -0300 Gabriel wrote:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user
presses ALT+F4 under Windows, and he told me that by design SDL lets
the user handle all combinations of key presses, though this forces
the developer to write some platform dependent code to catch those
events (ALT+F4 on Windows, CMD+Q on OS X…etc?). He said he is on
the fence on this issue and to propose a poll on the list, so here it
is…the “Grand 2012 Keyboard System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.

2012/7/27 Tim Angus > On Thu, 26 Jul 2012 20:03:40 -0300 Gabriel wrote:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user
presses ALT+F4 under Windows, and he told me that by design SDL lets
the user handle all combinations of key presses, though this forces
the developer to write some platform dependent code to catch those
events (ALT+F4 on Windows, CMD+Q on OS X…etc?). He said he is on
the fence on this issue and to propose a poll on the list, so here it
is…the “Grand 2012 Keyboard System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.

Apologies if someone has already suggested this, but is there a case
for making it optional via a hint? It seems like you can make a
convincing case for both possibilities.

The other option is to modify the API in some way that allows you to
specify whether or not to pass on key presses to the OS, as you handle
them in the SDL event loop. This is probably less attractive.

If I had to choose one or the other, I would go with letting the OS
deal with key presses it knows about. One of the nice things about SDL
is that it tends not to “get in the way”. Having SDL swallow the OS
combos seems to violate that.

I agree that using a hint may provide the best of both options. Ironically,
with the current code, when I press ALT+F4 under KDE, I get a close event
in my app. Under Windows, I do not. I haven’t looked at the X11 keyboard
handling code, but it may be possible that this event handling is happening
before (or completely “outside”) SDL has any chance to process the
keypresses, so that’s something to consider as well (it may not be possible
to capture this shortcuts in every platform).


Gabriel.

In windows microsoft wants the user to handle it if they want alt and f4
to close thte window. You are checking for input anyway. THe reason it’s
gone this long without gettting done is that if you want it you just add
one line of code (maybe two or three if you break it up):

case SDLK_F4:
if(ev->key.keysym.sym == SDLK_RALT) {do_something_first(); SDL_Quit;}
if(ev->key.keysym.sym == SDLK_LALT) {do_something_first(); SDL_Quit;}

so now you have a cross platform way to check and do it. Lib seems like a
lot of effort for that to do that to me. The first time i pressed alt and
f4 to check if sdl made it quit I was relieved that it did not default to
this because it is not a default behavior of windows. Each application
decides to handle or not to handle it. Most of my games do the above but
some dont because I want to ask them if that’s what they really want first.
Online people trick each other by saying “ohh x, you can fix x by pressing
alt and f4” to trick them into exiting the game on accident. If i was doing
a system changes it would be bad to abort it also before it completes too.
The alternate code if it was in sdl would look something like this i think:

case SDL_ALT_N_F4:
do_it = check_if_user_wants_quit();
if(do_it) {do_something_first(); SDL_Quit;}

Could be plenty ways to do it I’m not thinking of. For me the sdl include
of this would not help me. I guess thats all i had to say._______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You’re missing the point.? ALT-F4 shouldn’t be an automatic quit, and no one is saying that it should.? But it absolutely should send the quit signal to the program, to be handled appropriately, whether by quitting or by asking the user if they really want to quit.? But right now SDL does not do that, and in fact it gets in the way.? That needs to change.________________________________
From: R Manard
To: SDL Development List
Sent: Friday, July 27, 2012 7:20 AM
Subject: Re: [SDL] Should SDL2 handle standard keyboard shortcuts?

In windows microsoft wants the user to handle it if they want alt and f4 to close thte window. You are checking for input anyway. THe reason it’s gone this long without gettting done is that if you want it you just add one line of code (maybe two or three if you break it up):
?
case SDLK_F4:
??? if(ev->key.keysym.sym == SDLK_RALT)?{do_something_first(); SDL_Quit;}
??? if(ev->key.keysym.sym == SDLK_LALT)?{do_something_first(); SDL_Quit;}
?
so now you have a cross platform way to check and do it.?Lib seems like a lot of effort for that?to do that to me. The first time i pressed alt and f4 to check if sdl made it quit I was relieved that it did not default to this because it is not a default behavior of windows. Each application decides to handle or not to handle it. Most of my games do the above but some dont because I want to ask them if that’s what they really want first. Online people trick each other by saying “ohh x, you can fix x by pressing alt and f4” to trick them into exiting the game on accident. If i was doing a system?changes it would be bad to abort it also before it completes too. The alternate code if it was in sdl would look something like this i think:
?
case SDL_ALT_N_F4:
do_it = check_if_user_wants_quit();?
if(do_it) {do_something_first(); SDL_Quit;}
?
Could be plenty ways to do it I’m not thinking of. For me the sdl include of this would not help me. I guess thats all i had to say.
??_______________________________________________
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

What about providing a way of determining if a given chord is a system
interaction and what the probable intent is, but stop short of actually
following through with the intent?

-DanOn Jul 26, 2012 4:04 PM, “Gabriel Jacobo” wrote:

I asked Sam why SDL2 is not generating a WM_CLOSE when the user presses
ALT+F4 under Windows, and he told me that by design SDL lets the user
handle all combinations of key presses, though this forces the developer to
write some platform dependent code to catch those events (ALT+F4 on
Windows, CMD+Q on OS X…etc?). He said he is on the fence on this issue
and to propose a poll on the list, so here it is…the “Grand 2012 Keyboard
System Shortcuts Poll”.

I’ll start with my vote, I’m 51% in favor of handling these combos
internally.


Gabriel.


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