Closed airstruck closed 8 years ago
@rm-code any thoughts on this?
What about shortcut attribute, if someone creates a widget with a shortcut like 'ctrl-s' should that be command-s on a Mac? Is the control key not something an application usually cares about as a modifier on Mac, like the Windows logo key on Windows (something that belongs more to the window manager than to individual apps)?
@airstruck The ctrl key is used on OSX in some cases and shouldn't be replaced by default. How about making the keys interchangeable? They could be loaded like a theme then:
local Keymap = {
['OSX'] = { -- Backend returns same identifier regardless of SDL or LÖVE.
text_moveCaretRight = { 'lgui', 'rgui' },
-- ...
},
['Windows'] = {
text_moveCaretRight = { 'lctrl', 'rctrl' },
-- ...
}
}
moveCaretLeft(self, Backend.isKeyDown( Keymap[Backend.getOS()].text_moveCaretLeft ))
Just a quick and dirty idea.
If not then I'd simply suggest adding special cases like I did in #24. Shouldn't be too many anyway.
Here's the thing I'm mostly worried about, actually. When a Windows user creates a UI with something like:
{ type = 'button', text = 'Save', shortcut = 'ctrl-s' }
What does this mean on a Mac? Should they press ctrl-s to save, or cmd-s?
Maybe UI author could write something like shortcut = 'c-s'
to mean ctrl-s on Win and cmd-s on Mac?
Well ctrl-s
would simply be ctrl-s
on a mac. How about simply allowing multiple keys for the shortcut?
{ type = 'button', text = 'Save', shortcut = { 'ctrl-s', 'lgui-s' }
The problem with forcing ctrl to be cmd on OSX automatically is that you'd essentially take away one key from Mac users :grin:
Doesn't #24 also leave Mac users with one less key? ctrl-a still selects all on Mac, so you can't use it for something else.
I just pushed a commit that has shortcuts treat ctrl and lgui/rgui as both being a ctrl key, so a shortcut = 'ctrl-s'
can be activated with either ctrl-s or command-s. It's far from perfect and I'm definitely open to any suggestions for improving it, but I don't think I want users to have to write things like shortcut = { 'ctrl-s', 'command-s' }
everywhere.
Multiple shortcuts per widget is a good idea in general though, should probably support that anyway.
Doesn't #24 also leave Mac users with one less key? ctrl-a still selects all on Mac, so you can't use it for something else.
That's true if we don't have different key maps for osx and windows. No idea how to implement that nicely though.
I think the current approach is okay for now :+1:
In general, shortcuts on OS X should use command key instead of control key.
Use
love.system.getOS() == 'OS X'
in Love andSDL_GetPlatform() == 'Mac OS X'
in SDL to figure out if user is on a Mac.Add a special function like
Backend.isControlPressed
that detects command key on Mac and control key everywhere else. Is there a better name for this, some word that refers to either a command or control key?