History log of /haiku/src/kits/shared/Keymap.cpp
Revision Date Author Comments
# f7db2734 21-Mar-2020 X512 <danger_mail@list.ru>

Keymap: remove iterator change inside for loop, no functional change

Pointed by clang.

Change-Id: I3aaad5b1e03385358ccb729251fa31d35108f389
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2392
Reviewed-by: John Scipione <jscipione@gmail.com>
Reviewed-by: Alex von Gluck IV <kallisti5@unixzen.com>


# a7536efa 19-Aug-2019 Simon South <simon@simonsouth.net>

BKeymap: Add unit tests and fix issues

Add a preliminary set of unit tests for BKeymap and fix these issues:

* BKeymap::operator=() caused a crash by allocating a zero-byte array to hold
the other object's character data.
* BKeymap::SetToCurrent() and SetToDefault() leaked memory by not freeing an
existing character array before allocating a new one.
* BKeymap::SetToCurrent() incorrectly determined the size of the current
keymap's character array, causing GetChars() to fail whenever the current
keymap was loaded. Now SetToCurrent() uses the _get_key_map() private
function, which accurately reports the size of the array.

This commit also updates a Jamfile by replacing a use of "UseHeaders" to
include private header files with the more concise and expressive
"UsePrivateHeaders".

Change-Id: If6f71b209f1bd395be57835c4dd89f0e3f845994
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1724
Reviewed-by: Ryan Leavengood <leavengood@gmail.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
Reviewed-by: Stephan Aßmus <superstippi@gmx.de>


# a75fc8a7 23-Oct-2013 John Scipione <jscipione@gmail.com>

Keymap: simplification

Call already existing Offset() method instead of reproducing it.

Set fCharsSize in BKeymap::SetToCurrent()


# 103e868b 19-Oct-2013 John Scipione <jscipione@gmail.com>

Style fix, spaces to tabs


# bd336e3a 19-Oct-2013 John Scipione <jscipione@gmail.com>

Update semantic shortcuts

Update BKeymap::GetModifiedCharacters() to translate a given character
and set of modifiers filling out a list of all characters that match for another
set of modifiers.

This allows us to, for example, get all characters in the normal map that
have the '+' character in the corresponding shift map.

It is fully generic allowing one to get a list of characters in any map given
a character and modifiers of another map.

Also I converted from using a BList to using a BObjectList.

With this, along with BWindow::HasShortcut(), the semantic shortcuts now
work not only with Command+'=', but any key in the normal map that has
'+' in it's shift map as long as it isn't already taken by another shortcut.


# 1d043104 18-Oct-2013 John Scipione <jscipione@gmail.com>

Keymap: Add a method to get modified characters for a key

This method fills out the passed-in BList of modified utf-8 characters for
a given utf-8 character and set of modifiers.

For example if you pass in "=" and B_SHIFT_KEY the list will get filled
out with each character in the shift map that has "=" in the normal map.

Each supported keymap modifier combination is available.

The reason this is useful will soon become apparent.

A BList is used because the character might be mapped multiple times,
for example if you have a Mac keyboard you've got two "=" keys, one in
0x1d and one in 0x6a.

The caller is responsible for creating the BList and destroying it as well as
freeing the resulting character strings.


# 3cee15aa 28-Mar-2012 John Scipione <jscipione@gmail.com>

Keymap changes from recent activity. No AltGr yet.

Below is a mostly complete summary of the changes in this commit.

* Set the DeadKeys for the US-International Keymap to use the Option map.
* Rename American keymap to US
* Update the US, US-International, and United-Kingdom keymaps to take
out unneeded spaces in the option layer. Also updated the dead keys
and some other keys on the US-International keyboard to use UTF-8
characters rather than there ASCII equivalents when different.
* Make the Option key fall-through when there is no mapping in the Option
table. Option is for special characters, if none, print the regular one.
This is mostly meant for the US keymap which has an empty option map. But
also so that you don't have to repeat the normal, shift, and caps maps in
the option map needlessly. Although the keymaps are still not empty in
some cases that it could be like numpad keys and space.
* Update the /bin/keymap app to use fputs() instead of printf() when there
is no actual formatting taking place. I've gotten into trouble for doing
this before and it is faster to not process the string unnecessarily.
* Also several 80-char limit style fixes and updated comments.
* In Keymap class Reorder the modifier keys to match the keymap files.
Put B_CONTROL_KEY check above B_OPTION_KEY. Neither change has any effect,
they are purely aesthetic.
* Update DumpKeymap() method to use the abbreviated modifier letters so it
will fit in your 80-char wide terminal.
* Tiny style fix in InputServer
* 80-char limit style fix in BWindow and add a comment that the shortcut
gets eaten in the case of Cmd+Q
* Implement IndexForModifier() in KeyboardLayout, although I am not using it.
* Take Caps Lock out of the Modifier keys window because I couldn't get
it to work the way I wanted it to.
* Move key roles to the left column, and the key label on the left. Add column
header labels. Thanks Rimas!
* Add validation and improve marking menu options. Add a 'Disabled' option
to control, option, and command menus to disable the key. Make the key
role text grey if the key roles is disabled. Validation ensures that you
cannot repeat the same key twice in the Modifier keys window since that
won't work. You can't define 2 sets of option keys even if you really want
to. You can disable your control, option, and command keys if you
want, but that is not recommended.
* Rename kUpdateModifiers to kUpdateModifierKeys message to differetiate
it from kUpdateModifier.
* Add shift key to Modifier keys window, use the stop icon instead of the
warning icon to indicate conflicts.
* Allow the Layout system to control the size of the Modifier keys window
again, set the width's of the key role lables to the widest, set the width
of the menu fields to take up the rest of the space minus room for the
conflict views. I didn't like it that the Modifier keys window would change
size based on what options you had selected in the menu fields. Now it
doesn't, but, the layout system still makes it all fit.


# cd715563 26-Dec-2010 Michael Lotz <mmlr@mlotz.ch>

CID 8115: Fix wrong size parameter to memcmp() which lead to a broken equality
operator.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39957 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 44628746 07-Aug-2010 Jérôme Duval <korli@users.berlios.de>

CID 1463: Delete an array with delete[]


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b19e758b 21-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* The Keymap::IsDeadKey() of the Keymap preferences which was the main source
of BKeymap was not compatible with IsDeadKey() of the other Keymap
incarnations.
* Now, I've renamed IsDeadKey() to DeadKey(), and introduced a new
ActiveDeadKey() method that works like the other former IsDeadKey().
* This fixes the dead key problems my earlier BKeymap work introduced.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36400 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a41cc8a7 20-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* Fixed build on the Haiku platform.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36375 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4dfce2e4 19-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* We cannot include the SystemKeymap.h with the tool that is supposed to
generate it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36370 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 910f10f2 20-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* Added libshared_build.a, currently only contains Keymap.cpp.
* keymap and <build>keymap are now using the BKeymap class as a base as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36368 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 697e17ff 20-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* The scroll_lock also counts as a modifier; this was obviously not present
in all Keymap variations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36366 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b44c25de 16-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* Factored out a single base class out of the three Keymap implementations we
had in our tree.
* Adapted Keymap, <input>keyboard, and consoled to use it - the additional
functionality is implemented via a subclass in the first two cases.
* "keymap" will come next.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36328 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 103e868bf9b18e47d858c111efb8bb235daa1d08 19-Oct-2013 John Scipione <jscipione@gmail.com>

Style fix, spaces to tabs


# bd336e3abc7e939d2db16cff48d4cb9a2fe0dc60 19-Oct-2013 John Scipione <jscipione@gmail.com>

Update semantic shortcuts

Update BKeymap::GetModifiedCharacters() to translate a given character
and set of modifiers filling out a list of all characters that match for another
set of modifiers.

This allows us to, for example, get all characters in the normal map that
have the '+' character in the corresponding shift map.

It is fully generic allowing one to get a list of characters in any map given
a character and modifiers of another map.

Also I converted from using a BList to using a BObjectList.

With this, along with BWindow::HasShortcut(), the semantic shortcuts now
work not only with Command+'=', but any key in the normal map that has
'+' in it's shift map as long as it isn't already taken by another shortcut.


# 1d043104595fbf5f7e6068e749981bd3913b4369 18-Oct-2013 John Scipione <jscipione@gmail.com>

Keymap: Add a method to get modified characters for a key

This method fills out the passed-in BList of modified utf-8 characters for
a given utf-8 character and set of modifiers.

For example if you pass in "=" and B_SHIFT_KEY the list will get filled
out with each character in the shift map that has "=" in the normal map.

Each supported keymap modifier combination is available.

The reason this is useful will soon become apparent.

A BList is used because the character might be mapped multiple times,
for example if you have a Mac keyboard you've got two "=" keys, one in
0x1d and one in 0x6a.

The caller is responsible for creating the BList and destroying it as well as
freeing the resulting character strings.


# 3cee15aac2ef8c6ae8975d9add34c36aa4224c29 28-Mar-2012 John Scipione <jscipione@gmail.com>

Keymap changes from recent activity. No AltGr yet.

Below is a mostly complete summary of the changes in this commit.

* Set the DeadKeys for the US-International Keymap to use the Option map.
* Rename American keymap to US
* Update the US, US-International, and United-Kingdom keymaps to take
out unneeded spaces in the option layer. Also updated the dead keys
and some other keys on the US-International keyboard to use UTF-8
characters rather than there ASCII equivalents when different.
* Make the Option key fall-through when there is no mapping in the Option
table. Option is for special characters, if none, print the regular one.
This is mostly meant for the US keymap which has an empty option map. But
also so that you don't have to repeat the normal, shift, and caps maps in
the option map needlessly. Although the keymaps are still not empty in
some cases that it could be like numpad keys and space.
* Update the /bin/keymap app to use fputs() instead of printf() when there
is no actual formatting taking place. I've gotten into trouble for doing
this before and it is faster to not process the string unnecessarily.
* Also several 80-char limit style fixes and updated comments.
* In Keymap class Reorder the modifier keys to match the keymap files.
Put B_CONTROL_KEY check above B_OPTION_KEY. Neither change has any effect,
they are purely aesthetic.
* Update DumpKeymap() method to use the abbreviated modifier letters so it
will fit in your 80-char wide terminal.
* Tiny style fix in InputServer
* 80-char limit style fix in BWindow and add a comment that the shortcut
gets eaten in the case of Cmd+Q
* Implement IndexForModifier() in KeyboardLayout, although I am not using it.
* Take Caps Lock out of the Modifier keys window because I couldn't get
it to work the way I wanted it to.
* Move key roles to the left column, and the key label on the left. Add column
header labels. Thanks Rimas!
* Add validation and improve marking menu options. Add a 'Disabled' option
to control, option, and command menus to disable the key. Make the key
role text grey if the key roles is disabled. Validation ensures that you
cannot repeat the same key twice in the Modifier keys window since that
won't work. You can't define 2 sets of option keys even if you really want
to. You can disable your control, option, and command keys if you
want, but that is not recommended.
* Rename kUpdateModifiers to kUpdateModifierKeys message to differetiate
it from kUpdateModifier.
* Add shift key to Modifier keys window, use the stop icon instead of the
warning icon to indicate conflicts.
* Allow the Layout system to control the size of the Modifier keys window
again, set the width's of the key role lables to the widest, set the width
of the menu fields to take up the rest of the space minus room for the
conflict views. I didn't like it that the Modifier keys window would change
size based on what options you had selected in the menu fields. Now it
doesn't, but, the layout system still makes it all fit.


# cd7155635d5a3b49feb42058151dffa4e341213f 26-Dec-2010 Michael Lotz <mmlr@mlotz.ch>

CID 8115: Fix wrong size parameter to memcmp() which lead to a broken equality
operator.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39957 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 446287462bb8fd32dd7a4602deb6977138e89539 07-Aug-2010 Jérôme Duval <korli@users.berlios.de>

CID 1463: Delete an array with delete[]


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b19e758b80e6eca2e5d81b75c738b4b5c9e70f18 21-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* The Keymap::IsDeadKey() of the Keymap preferences which was the main source
of BKeymap was not compatible with IsDeadKey() of the other Keymap
incarnations.
* Now, I've renamed IsDeadKey() to DeadKey(), and introduced a new
ActiveDeadKey() method that works like the other former IsDeadKey().
* This fixes the dead key problems my earlier BKeymap work introduced.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36400 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a41cc8a74bef7264d096f94ed1f8c2a4ed648e60 20-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* Fixed build on the Haiku platform.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36375 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4dfce2e401f26b780baca36eb70f345be821f737 19-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* We cannot include the SystemKeymap.h with the tool that is supposed to
generate it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36370 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 910f10f2fcf05e0973ffc60734515b369c103ca6 20-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* Added libshared_build.a, currently only contains Keymap.cpp.
* keymap and <build>keymap are now using the BKeymap class as a base as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36368 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 697e17ffcdfefd59450c3f256013c9949705c8da 20-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* The scroll_lock also counts as a modifier; this was obviously not present
in all Keymap variations.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36366 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b44c25de42ce39022f701d5637797b2f57e63679 16-Apr-2010 Axel Dörfler <axeld@pinc-software.de>

* Factored out a single base class out of the three Keymap implementations we
had in our tree.
* Adapted Keymap, <input>keyboard, and consoled to use it - the additional
functionality is implemented via a subclass in the first two cases.
* "keymap" will come next.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36328 a95241bf-73f2-0310-859d-f6bbb57e9c96