Skip to content
  • Rui Matos's avatar
    keybindings: Keep keybindings in an hash table instead of an array · 46af3ef9
    Rui Matos authored
    This allows us to look for a match with an O(1) search instead of O(n)
    which is nice, particularly when running as a wayland compositor in
    which case we have to do this search for every key press event (as
    opposed to only when our passive grab triggers in the X compositor
    case).
    
    We actually need two hash tables. On one we keep all the keybindings
    themselves which allows us to add external grabs without constantly
    re-allocating the array we were using previously.
    
    The other hash table is an index of the keybindings in the first table
    by their keycodes and mask which is how we actually match the key
    press events. This second table thus needs to be rebuilt when the
    keymap changes since keycodes have to be resolved then but since we're
    only keeping pointers to the first table it's a fast operation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725588
    46af3ef9