Safe Haskell | Safe-Inferred |
---|
Support for efficient keymaps.
The sequence of Cmds which return Continue or Done is flexible, but probably inefficient in the presence of hundreds of commands. In addition, it can't warn about Cmds that respond to overlapping Msgs, e.g. respond to the same key.
Keymaps provide an efficient way to respond to a useful subset of Msgs,
i.e. those which are considered 'key down' type msgs. The exact
definition is in Bindable
.
Keys are bound using SimpleMod
s, which are higher level than the ones in
Ui.Key. This provides allows some abstraction between they key bindings
and which actual modifiers those imply, and allows the conflation of
multiple modifiers.
If you bind to a shifted key, it will be converted to Shift + unshifted by
KeyLayouts.to_unshifted
. But if you want to bind to the same physical
key with and without shift, then you should bind to the unshifted version
and add Shift yourself.
Synopsis
- type Binding m = (Cmd.KeySpec, Cmd.NamedCmd m)
- plain_key :: Cmd.M m => Key.Key -> Text -> m () -> [Binding m]
- plain_char :: Cmd.M m => Char -> Text -> m () -> [Binding m]
- shift_char :: Cmd.M m => Char -> Text -> m () -> [Binding m]
- command_char :: Cmd.M m => Char -> Text -> m () -> [Binding m]
- secondary_char :: Cmd.M m => Char -> Text -> m () -> [Binding m]
- bind_key :: Cmd.M m => [SimpleMod] -> Key.Key -> Text -> m () -> [Binding m]
- bind_key_status :: [SimpleMod] -> Key.Key -> Text -> m Cmd.Status -> [Binding m]
- bind_repeatable :: Cmd.M m => [SimpleMod] -> Key.Key -> Text -> m () -> [Binding m]
- bind_click :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Int -> Text -> (Msg.Msg -> m ()) -> [Binding m]
- bind_drag :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Text -> (Msg.Msg -> m ()) -> [Binding m]
- bind_release :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Text -> (Msg.Msg -> m ()) -> [Binding m]
- bind :: Cmd.M m => [SimpleMod] -> Cmd.Bindable -> Text -> (Msg.Msg -> m ()) -> [Binding m]
- bind_status :: [SimpleMod] -> Cmd.Bindable -> Text -> (Msg.Msg -> m Cmd.Status) -> [Binding m]
- make_keymap :: [Binding m] -> (Cmd.Keymap m, [Text])
- data SimpleMod
- simple_mod_map :: Map SimpleMod Key.Modifier
- simple_to_mod :: SimpleMod -> Maybe Cmd.Modifier
- key_spec :: [Cmd.Modifier] -> Cmd.Bindable -> Cmd.KeySpec
- overlaps :: [Binding m] -> [[Text]]
- expand_bindable :: Cmd.Bindable -> [Cmd.Bindable]
- expand_mods :: Cmd.Bindable -> [SimpleMod] -> [Cmd.Modifier]
binding
type Binding m = (Cmd.KeySpec, Cmd.NamedCmd m) Source #
plain_key :: Cmd.M m => Key.Key -> Text -> m () -> [Binding m] Source #
Bind a Key with no modifiers.
command_char :: Cmd.M m => Char -> Text -> m () -> [Binding m] Source #
Bind a Char with the PrimaryCommand
.
secondary_char :: Cmd.M m => Char -> Text -> m () -> [Binding m] Source #
Bind a Char with the SecondaryCommand
.
bind_key :: Cmd.M m => [SimpleMod] -> Key.Key -> Text -> m () -> [Binding m] Source #
Bind a key with the given modifiers.
bind_key_status :: [SimpleMod] -> Key.Key -> Text -> m Cmd.Status -> [Binding m] Source #
Bind a key with a Cmd that returns Status.
bind_repeatable :: Cmd.M m => [SimpleMod] -> Key.Key -> Text -> m () -> [Binding m] Source #
Like bind_key
, but the binding will be retriggered on key repeat.
bind_click :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Int -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #
bind_click
passes the Msg to the cmd, since mouse cmds are more likely
to want the msg to find out where the click was. clicks
is 1 for a single
click, 2 for a double click, etc.
bind_drag :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #
A bind_drag
binds both the click and the drag. It's conceivable to have
click and drag bound to different commands, but I don't have any yet.
bind_release :: Cmd.M m => [SimpleMod] -> Types.MouseButton -> Cmd.MouseOn -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #
bind :: Cmd.M m => [SimpleMod] -> Cmd.Bindable -> Text -> (Msg.Msg -> m ()) -> [Binding m] Source #
Like bind_status
but the Cmd is expected to return (), which will become
Cmd.Done
. Since the cmd has already been matched on the bound key this is
likely what it would have done anyway.
bind_status :: [SimpleMod] -> Cmd.Bindable -> Text -> (Msg.Msg -> m Cmd.Status) -> [Binding m] Source #
This is the most general Binding constructor: bind any Bindable with any modifiers, and don't assume the cmd returns Done.
A capital letter is shorthand for Shift + Char.toLower c.
Handler
make_keymap :: [Binding m] -> (Cmd.Keymap m, [Text]) Source #
Create a Keymap for efficient lookup and return warnings encountered during construction.
SimpleMod
The Msg contains the low level key information, but most commands should probably use these higher level modifiers. That way left and right shifts work the same, and cmds can use Command as customary on the Mac and Control as customary on linux.
Shift | |
PrimaryCommand | Primary command key: command on Mac, control on Linux and Windows. This should be used for core and global commands. |
SecondaryCommand | Secondary comamnd key: control or option on Mac, alt on Linux and Windows. I'm not sure what this should be used for, but perhaps it can be for more specific event text modifications, while PrimaryCommand is for general purpose modifications. Also, it should have non-primitive cmds, so if you override them locally you won't lose anything essential. |
Mouse Types.MouseButton | Having mouse here allows for mouse button chording. |
simple_mod_map :: Map SimpleMod Key.Modifier Source #
Map a SimpleMod to the Key.Modifiers it implies.
key_spec :: [Cmd.Modifier] -> Cmd.Bindable -> Cmd.KeySpec Source #
Bindable
expand_bindable :: Cmd.Bindable -> [Cmd.Bindable] Source #
A binding that accepts a KeyRepeat should also accept a KeyDown.
expand_mods :: Cmd.Bindable -> [SimpleMod] -> [Cmd.Modifier] Source #