The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Should SDL2 handle standard keyboard shortcuts?
gabomdq


Joined: 28 Jul 2011
Posts: 495
Location: Argentina
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.
Should SDL2 handle standard keyboard shortcuts?
Jonathan Greig
Guest

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.
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Should SDL2 handle standard keyboard shortcuts?
Patrick Baggett
Guest

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


On Thu, Jul 26, 2012 at 6:03 PM, Gabriel Jacobo wrote:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Should SDL2 handle standard keyboard shortcuts?
Mason Wheeler
Guest

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
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
Should SDL2 handle standard keyboard shortcuts?
gabomdq


Joined: 28 Jul 2011
Posts: 495
Location: Argentina
2012/7/26 Patrick Baggett
Quote:
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.
Should SDL2 handle standard keyboard shortcuts?
Mason Wheeler
Guest

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
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Nathan Coulson
Guest

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 (-Cool
Webpage: http://www.nathancoulson.com
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Mason Wheeler
Guest

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; 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 (-Cool
Webpage: http://www.nathancoulson.com
Should SDL2 handle standard keyboard shortcuts?
Andreas Schiffler
Guest

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.
--Andreas

On 7/26/2012 4:03 PM, Gabriel Jacobo wrote:

Quote:
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.



Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
R Manard
Guest

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.
Should SDL2 handle standard keyboard shortcuts?
R Manard
Guest

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 wrote:
Quote:

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.
Should SDL2 handle standard keyboard shortcuts?
Karl F. Glatzer
Guest

On 27.07.2012 02:41, Gabriel Jacobo wrote:
Quote:
2012/7/26 Patrick Baggett

Quote:
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.


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.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Drake Wilson
Guest

Quoth Gabriel Jacobo, on 2012-07-26 20:03:40 -0300:
Quote:
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
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Brian Barrett
Guest

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,
-- Brian

On 27 July 2012 00:03, Gabriel Jacobo wrote:
Quote:
I'll start with my vote, I'm 51% in favor of handling these combos
internally.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Jonny D


Joined: 12 Sep 2009
Posts: 932
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
Should SDL2 handle standard keyboard shortcuts?
Tim Angus
Guest

On Thu, 26 Jul 2012 20:03:40 -0300 Gabriel wrote:
Quote:
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.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
gabomdq


Joined: 28 Jul 2011
Posts: 495
Location: Argentina
2012/7/27 Tim Angus
Quote:
On Thu, 26 Jul 2012 20:03:40 -0300 Gabriel wrote:
Quote:
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.
Should SDL2 handle standard keyboard shortcuts?
R Manard
Guest

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Mason Wheeler
Guest

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org






_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Daniel Leslie
Guest

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?
-Dan On Jul 26, 2012 4:04 PM, "Gabriel Jacobo" wrote:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: Should SDL2 handle standard keyboard shortcuts?
RodrigoCard


Joined: 23 Apr 2011
Posts: 113
Location: Brazil
I vote for not getting in the way for default system shortcuts since it is *not* the behavior the user expects.

And a "SDL_DONTSWALLOWSYSTEMKEYSHORTCUTSHINT" for the current behavior for the cases it is useful =]

Some other points:
* Handling the COMMAND+Q (and other combinations) manually in OSX produces a "beep" sound, because of the way OS X treats CMD+SOMETHING key presses, which is not desirable;
* It is Annoying that lots os SDL games in Linux does not respond to Alt+tab and Alt+F4 when in Fullscreen.
Should SDL2 handle standard keyboard shortcuts?
R Manard
Guest

yes, this is the code maker job. He is the decider. A cross platform lib lrts me make one app that does the same thing on all os. i do this. When i am in the os making changes it's crazy to plan for the quit so i check but don't do anything unless im not busy. Even microsost os will be destroyed if its stopped when doing an update. the key press are there to check which is easy and i dont worry about alternate methods and what they mean unless all are the same. I have to write the same ammount of code to handle sdl if its included and if its not. it's about 1 line of code no matter what the caes.

On Thu, Jul 26, 2012 at 7:28 PM, Daniel Leslie wrote:
Quote:

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?
-Dan On Jul 26, 2012 4:04 PM, "Gabriel Jacobo" wrote:

Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Should SDL2 handle standard keyboard shortcuts?
Forest Hale
Guest

My understanding (having written Win32 code before) is that the event handler must return a bool status to indicate whether the event should be passed on to the system for handling, the common
behavior is to pass on all events after handling them - with some exceptions (like if you want to suppress screensavers you can intentionally not accept the screensaver event).

My expectation of SDL2 is that it will pass along all events that it has not been hinted by the app should be suppressed, so for example alt-f4 requires no special handling in SDL2 or the app as long
as it passes on keyboard events, which will in turn produce a WM_CLOSE event that will be delivered by SDL2 to the app to react to.

On 07/27/2012 08:14 AM, Mason Wheeler wrote:
Quote:
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
<mailto:
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
<mailto:
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--
LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Ryan C. Gordon
Guest

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

As an anecdote: Every game I port to the Mac with SDL 1.2 ends up with
this code...

while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_KEYDOWN:
#ifdef __APPLE__
if ((e.key.keysym.sym == SDLK_q) && (e.key.keysym.mod &
KMOD_META))
doTheSameThingThatSDL_QUITHandlerWouldDo();
#endif
}
}


And, not to mention: if you want to handle the standard minimize, etc
hotkeys, you catch them much the same way, but then you have to have a
small Objective-C file to invoke the proper Cocoa:


http://hg.icculus.org/icculus/hge-unix/file/99e499f0cc69/src/core/unix/macosx_support.mm

...which is annoying if your project is otherwise all C/C++. Similar
issues exist on other platforms, and this is even more egregious on
Unix, where the proper thing to do is less clear than a standard Cocoa
or Win32 call.

My thought is that SDL _should_ handle these things; it already handles
them for mouse clicks on the window decorations, and it prevents
annoying code that must be implemented in every app.

Perhaps a SDL_HINT_HANDLE_OS_HOTKEYS should be added (that defaults to
catching this stuff inside SDL, but can be turned off for apps that care
deeply about this stuff)?

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Ryan C. Gordon
Guest

Quote:
case SDL_KEYDOWN:
#ifdef __APPLE__

Two more thoughts:

- This code is buggy, because you don't want iOS to respond to this event.

- If your app doesn't respond to the Apple-Q hotkey by quitting, your
Mac App Store submission will be rejected, so there's an added benefit
to SDL converting this to an SDL_QUIT event.

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Ryan C. Gordon
Guest

Quote:
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.

There is precedent for both. If you send a SIGINT to an SDL app, SDL
catches it and converts it to an SDL_QUIT event, which seems way more
outrageous than catching standard hotkeys.

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
Fair enough, let's make it so.

As an additional data point, most X11 window managers catch shortcuts before they get to SDL applications, so there's really no way to avoid shortcut handling in that environment.


Also Apple, as Ryan said, will reject applications which don't conform to the system standards.


I'm fine with SDL 2.0 having well behaved OS semantics.  If people really want a hint to disable that when possible, that's fine too, but that should be the exception.

On Sat, Jul 28, 2012 at 2:37 PM, Ryan C. Gordon wrote:
Quote:

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


As an anecdote: Every game I port to the Mac with SDL 1.2 ends up with this code...

while (SDL_PollEvent(&e)) {
    switch (e.type) {
        case SDL_KEYDOWN:
            #ifdef __APPLE__
            if ((e.key.keysym.sym == SDLK_q) && (e.key.keysym.mod & KMOD_META))
                doTheSameThingThatSDL_QUITHandlerWouldDo();
            #endif
     }
}


And, not to mention: if you want to handle the standard minimize, etc hotkeys, you catch them much the same way, but then you have to have a small Objective-C file to invoke the proper Cocoa:


http://hg.icculus.org/icculus/hge-unix/file/99e499f0cc69/src/core/unix/macosx_support.mm

...which is annoying if your project is otherwise all C/C++. Similar issues exist on other platforms, and this is even more egregious on Unix, where the proper thing to do is less clear than a standard Cocoa or Win32 call.

My thought is that SDL _should_ handle these things; it already handles them for mouse clicks on the window decorations, and it prevents annoying code that must be implemented in every app.

Perhaps a SDL_HINT_HANDLE_OS_HOTKEYS should be added (that defaults to catching this stuff inside SDL, but can be turned off for apps that care deeply about this stuff)?

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Should SDL2 handle standard keyboard shortcuts?
Mason Wheeler
Guest

Glad to see you're in agreement here. Smile


From: Sam Lantinga
To: SDL Development List
Sent: Tuesday, July 31, 2012 7:44 PM
Subject: Re: [SDL] Should SDL2 handle standard keyboard shortcuts?


Fair enough, let's make it so.

As an additional data point, most X11 window managers catch shortcuts before they get to SDL applications, so there's really no way to avoid shortcut handling in that environment.


Also Apple, as Ryan said, will reject applications which don't conform to the system standards.


I'm fine with SDL 2.0 having well behaved OS semantics. If people really want a hint to disable that when possible, that's fine too, but that should be the exception.

On Sat, Jul 28, 2012 at 2:37 PM, Ryan C. Gordon wrote:
Quote:

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


As an anecdote: Every game I port to the Mac with SDL 1.2 ends up with this code...

while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_KEYDOWN:
#ifdef __APPLE__
if ((e.key.keysym.sym == SDLK_q) && (e.key.keysym.mod & KMOD_META))
doTheSameThingThatSDL_QUITHandlerWouldDo();
#endif
}
}


And, not to mention: if you want to handle the standard minimize, etc hotkeys, you catch them much the same way, but then you have to have a small Objective-C file to invoke the proper Cocoa:


http://hg.icculus.org/icculus/hge-unix/file/99e499f0cc69/src/core/unix/macosx_support.mm

...which is annoying if your project is otherwise all C/C++. Similar issues exist on other platforms, and this is even more egregious on Unix, where the proper thing to do is less clear than a standard Cocoa or Win32 call.

My thought is that SDL _should_ handle these things; it already handles them for mouse clicks on the window decorations, and it prevents annoying code that must be implemented in every app.

Perhaps a SDL_HINT_HANDLE_OS_HOTKEYS should be added (that defaults to catching this stuff inside SDL, but can be turned off for apps that care deeply about this stuff)?

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org







_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
Petr Pisar
Guest

On Tue, Jul 31, 2012 at 10:44:54PM -0400, Sam Lantinga wrote:
Quote:
As an additional data point, most X11 window managers catch shortcuts
before they get to SDL applications, so there's really no way to avoid
shortcut handling in that environment.

Unless you put put the SDL window to fullscreen. Then the SDL grabs keyboard
input, so the window manager cannot handle it. This realy irritates me.

-- Petr
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Should SDL2 handle standard keyboard shortcuts?
R Manard
Guest

I think i tricked you. i said i don't want it because i do want it. Too late to back up now. My real opinion is that sdl should act like most apps do in each enviroment so people get what they expect unless the coder decides different. My opinion is that sdl is here to handle that stuff so i don't have to. 100% for it Smile

On Tue, Jul 31, 2012 at 9:44 PM, Sam Lantinga wrote:
Quote:
Fair enough, let's make it so.

As an additional data point, most X11 window managers catch shortcuts before they get to SDL applications, so there's really no way to avoid shortcut handling in that environment.


Also Apple, as Ryan said, will reject applications which don't conform to the system standards.


I'm fine with SDL 2.0 having well behaved OS semantics.  If people really want a hint to disable that when possible, that's fine too, but that should be the exception.

On Sat, Jul 28, 2012 at 2:37 PM, Ryan C. Gordon wrote:
Quote:

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


As an anecdote: Every game I port to the Mac with SDL 1.2 ends up with this code...

while (SDL_PollEvent(&e)) {
    switch (e.type) {
        case SDL_KEYDOWN:
            #ifdef __APPLE__
            if ((e.key.keysym.sym == SDLK_q) && (e.key.keysym.mod & KMOD_META))
                doTheSameThingThatSDL_QUITHandlerWouldDo();
            #endif
     }
}


And, not to mention: if you want to handle the standard minimize, etc hotkeys, you catch them much the same way, but then you have to have a small Objective-C file to invoke the proper Cocoa:


http://hg.icculus.org/icculus/hge-unix/file/99e499f0cc69/src/core/unix/macosx_support.mm

...which is annoying if your project is otherwise all C/C++. Similar issues exist on other platforms, and this is even more egregious on Unix, where the proper thing to do is less clear than a standard Cocoa or Win32 call.

My thought is that SDL _should_ handle these things; it already handles them for mouse clicks on the window decorations, and it prevents annoying code that must be implemented in every app.

Perhaps a SDL_HINT_HANDLE_OS_HOTKEYS should be added (that defaults to catching this stuff inside SDL, but can be turned off for apps that care deeply about this stuff)?

--ryan.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org






_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org