airstruck / luigi

Lovely User Interfaces for Game Inventors
MIT License
114 stars 23 forks source link

Detect OS X and use appropriate keyboard shortcuts #25

Closed airstruck closed 8 years ago

airstruck commented 8 years ago

In general, shortcuts on OS X should use command key instead of control key.

Use love.system.getOS() == 'OS X' in Love and SDL_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?

airstruck commented 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)?

rm-code commented 8 years ago

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

airstruck commented 8 years ago

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?

rm-code commented 8 years ago

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:

airstruck commented 8 years ago

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.

rm-code commented 8 years ago

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: