Ejemplo n.º 1
0
  void
  KeyCode::reverseNormalizeKey(KeyCode& key, Flags& flags, EventType eventType, KeyboardType keyboardType)
  {
    if (! Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_disable_numpad_hack)) {
      for (unsigned int i = 0; i < sizeof(fnkeyhack) / sizeof(fnkeyhack[0]); ++i) {
        if (fnkeyhack[i].reverse(key, flags, eventType)) break;
      }
    }

    if (keyboardType == KeyboardType::POWERBOOK ||
        keyboardType == KeyboardType::POWERBOOK_G4 ||
        keyboardType == KeyboardType::POWERBOOK_G4_TI) {
      if (key == KeyCode::ENTER) { key = KeyCode::ENTER_POWERBOOK; }
    }

    // ------------------------------------------------------------
    // Don't add ModifierFlag::FN automatically for F-keys, PageUp/PageDown/Home/End and Forward Delete.
    //
    // PageUp/PageDown/Home/End and Forward Delete are entered by fn+arrow, fn+delete normally,
    // And, from Cocoa Application, F-keys and PageUp,... keys have Fn modifier
    // even if Fn key is not pressed actually.
    // So, it's natural adding ModifierFlag::FN to these keys.
    // However, there is a reason we must not add ModifierFlag::FN to there keys.
    //
    // Mission Control may have "fn" as shortcut key.
    // If we add ModifierFlag::FN here,
    // "XXX to PageUp" launches Mission Control because Mission Control recognizes fn key was pressed.
    //
    // It's not intended behavior from users.
    // Therefore, we don't add ModifierFlag::FN for these keys.

    // ------------------------------------------------------------
    // set ModifierFlag::KEYPAD, ModifierFlag::CURSOR
    flags.stripCURSOR().stripKEYPAD();

    // Note: KEYPAD_CLEAR, KEYPAD_COMMA have no ModifierFlag::KEYPAD bit.
    if (key == KeyCode::KEYPAD_0 || key == KeyCode::KEYPAD_1 || key == KeyCode::KEYPAD_2 ||
        key == KeyCode::KEYPAD_3 || key == KeyCode::KEYPAD_4 || key == KeyCode::KEYPAD_5 ||
        key == KeyCode::KEYPAD_6 || key == KeyCode::KEYPAD_7 || key == KeyCode::KEYPAD_8 ||
        key == KeyCode::KEYPAD_9 ||
        key == KeyCode::KEYPAD_DOT ||
        key == KeyCode::KEYPAD_MULTIPLY ||
        key == KeyCode::KEYPAD_PLUS ||
        key == KeyCode::KEYPAD_SLASH ||
        key == KeyCode::KEYPAD_MINUS ||
        key == KeyCode::KEYPAD_EQUAL) {
      flags.add(ModifierFlag::KEYPAD);
    }

    if (key == KeyCode::CURSOR_UP ||
        key == KeyCode::CURSOR_DOWN ||
        key == KeyCode::CURSOR_LEFT ||
        key == KeyCode::CURSOR_RIGHT) {
      flags.add(ModifierFlag::CURSOR);
    }
  }
Ejemplo n.º 2
0
TEST(Flags, add) {
  Flags mask = ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R;
  Flags flags = mask;
  EXPECT_EQ(mask, flags.stripFN());

  flags.add(ModifierFlag::OPTION_L);
  EXPECT_EQ(mask | ModifierFlag::OPTION_L, flags);

  flags.add(ModifierFlag::NONE);
  EXPECT_EQ(mask | ModifierFlag::OPTION_L | ModifierFlag::NONE, flags);
}
Ejemplo n.º 3
0
TEST(Flags, stripEXTRA) {
  Flags mask = ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R;
  Flags flags = mask;
  EXPECT_EQ(mask, flags.stripEXTRA());

  flags.add(ModifierFlag::EXTRA1);
  EXPECT_EQ(mask, flags.stripEXTRA());

  flags.add(ModifierFlag::EXTRA2);
  EXPECT_EQ(mask, flags.stripEXTRA());

  flags.add(ModifierFlag::EXTRA3 | ModifierFlag::EXTRA5);
  EXPECT_EQ(mask, flags.stripEXTRA());
}
Ejemplo n.º 4
0
  void
  FlagStatus::updateStatusMessage(void)
  {
#ifndef FLAGSTATUS_TEST
    Flags f = FlagStatus::getLockedFlags();
    if (Config::get_essential_config(BRIDGE_ESSENTIAL_CONFIG_INDEX_general_show_sticky_modifier_status)) {
      f.add(FlagStatus::getStickyFlags());
    }
    if (f != statusMessageFlags_) {
      int index = BRIDGE_USERCLIENT_STATUS_MESSAGE_MODIFIER;
      CommonData::clear_statusmessage(index);

      if (f.isOn(ModifierFlag::FN))                                           { CommonData::append_statusmessage(index, "FN "); }
      if (f.isOn(ModifierFlag::COMMAND_L) || f.isOn(ModifierFlag::COMMAND_R)) { CommonData::append_statusmessage(index, "Cmd "); }
      if (f.isOn(ModifierFlag::CONTROL_L) || f.isOn(ModifierFlag::CONTROL_R)) { CommonData::append_statusmessage(index, "Ctrl "); }
      if (f.isOn(ModifierFlag::OPTION_L) || f.isOn(ModifierFlag::OPTION_R))   { CommonData::append_statusmessage(index, "Opt "); }
      if (f.isOn(ModifierFlag::SHIFT_L) || f.isOn(ModifierFlag::SHIFT_R))     { CommonData::append_statusmessage(index, "Shift "); }
      if (f.isOn(ModifierFlag::EXTRA1))                                       { CommonData::append_statusmessage(index, "Ex1 "); }
      if (f.isOn(ModifierFlag::EXTRA2))                                       { CommonData::append_statusmessage(index, "Ex2 "); }
      if (f.isOn(ModifierFlag::EXTRA3))                                       { CommonData::append_statusmessage(index, "Ex3 "); }
      if (f.isOn(ModifierFlag::EXTRA4))                                       { CommonData::append_statusmessage(index, "Ex4 "); }
      if (f.isOn(ModifierFlag::EXTRA5))                                       { CommonData::append_statusmessage(index, "Ex5 "); }

      CommonData::send_notification_statusmessage(index);
    }
    statusMessageFlags_ = f;
#endif
  }
Ejemplo n.º 5
0
TEST(Flags, stripFN) {
  Flags mask = ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_R | ModifierFlag::COMMAND_R;
  Flags flags = mask;
  EXPECT_EQ(mask, flags.stripFN());

  flags.add(ModifierFlag::FN);
  EXPECT_EQ(mask, flags.stripFN());
}
Ejemplo n.º 6
0
 Flags
 FlagStatus::makeFlags(void)
 {
   Flags flags;
   for (int i = 0; item_[i].flag_ != ModifierFlag::NONE; ++i) {
     flags.add(item_[i].makeFlag());
   }
   return flags;
 }
Ejemplo n.º 7
0
Flags FlagStatus::makeFlags(void) const {
  Flags flags;
  for (size_t i = 0; i < item_.size(); ++i) {
    if (item_[i].sum(false) > 0) {
      flags.add(item_[i].flag_);
    }
  }
  return flags;
}
Ejemplo n.º 8
0
TEST(KeyCode, reverseNormalizeKey) {
  std::vector<NormalizeItem> vec;

  // ENTER_POWERBOOK
  vec.push_back(NormalizeItem(KeyCode::ENTER_POWERBOOK, ModifierFlag::SHIFT_L,
                              KeyCode::ENTER_POWERBOOK, ModifierFlag::SHIFT_L, KeyboardType::POWERBOOK));

  // ENTER_POWERBOOK(+FN)
  vec.push_back(NormalizeItem(KeyCode::ENTER_POWERBOOK, ModifierFlag::SHIFT_L | ModifierFlag::FN,
                              KeyCode::ENTER_POWERBOOK, ModifierFlag::SHIFT_L | ModifierFlag::FN, KeyboardType::POWERBOOK));

  // ----------------------------------------
  // normal key (without FN)
  vec.push_back(NormalizeItem(KeyCode::A, ModifierFlag::SHIFT_L,
                              KeyCode::A, ModifierFlag::SHIFT_L, KeyboardType::MACBOOK));

  // KEYPAD (without FN)
  for (size_t i = 0; i < sizeof(keypads) / sizeof(keypads[0]); ++i) {
    KeyCode key = keypads[i][0];
    Flags fromFlags = ModifierFlag::SHIFT_L;
    Flags toFlags = fromFlags;
    if (key != KeyCode::KEYPAD_CLEAR && key != KeyCode::KEYPAD_COMMA) toFlags.add(ModifierFlag::KEYPAD);

    vec.push_back(NormalizeItem(key, fromFlags,
                                key, toFlags, KeyboardType::MACBOOK));
  }

  // PAGEUP (without FN)
  for (size_t i = 0; i < sizeof(cursors) / sizeof(cursors[0]); ++i) {
    vec.push_back(NormalizeItem(cursors[i][0], ModifierFlag::SHIFT_L,
                                cursors[i][0], ModifierFlag::SHIFT_L, KeyboardType::MACBOOK));
  }

  // ENTER (without FN)
  vec.push_back(NormalizeItem(KeyCode::ENTER, ModifierFlag::SHIFT_L,
                              KeyCode::ENTER, ModifierFlag::SHIFT_L, KeyboardType::MACBOOK));

  // FORWARD_DELETE (without FN)
  vec.push_back(NormalizeItem(KeyCode::FORWARD_DELETE, ModifierFlag::SHIFT_L,
                              KeyCode::FORWARD_DELETE, ModifierFlag::SHIFT_L, KeyboardType::MACBOOK));

  // CURSOR (without FN)
  for (size_t i = 0; i < sizeof(cursors) / sizeof(cursors[0]); ++i) {
    vec.push_back(NormalizeItem(cursors[i][1], ModifierFlag::CURSOR,
                                cursors[i][1], ModifierFlag::CURSOR, KeyboardType::MACBOOK));
  }

  // ----------------------------------------
  // normal key(+FN)
  vec.push_back(NormalizeItem(KeyCode::A, ModifierFlag::SHIFT_L | ModifierFlag::FN,
                              KeyCode::A, ModifierFlag::SHIFT_L | ModifierFlag::FN, KeyboardType::MACBOOK));

  // KEYPAD(+FN)
  for (size_t i = 0; i < sizeof(keypads) / sizeof(keypads[0]); ++i) {
    KeyCode key = keypads[i][0];
    Flags fromFlags = ModifierFlag::SHIFT_L | ModifierFlag::FN;
    Flags toFlags = fromFlags;
    if (key != KeyCode::KEYPAD_CLEAR && key != KeyCode::KEYPAD_COMMA) toFlags.add(ModifierFlag::KEYPAD);

    vec.push_back(NormalizeItem(key, fromFlags,
                                key, toFlags, KeyboardType::MACBOOK));
  }

  // PAGEUP(+FN)
  for (size_t i = 0; i < sizeof(cursors) / sizeof(cursors[0]); ++i) {
    vec.push_back(NormalizeItem(cursors[i][0], ModifierFlag::SHIFT_L | ModifierFlag::FN,
                                cursors[i][0], ModifierFlag::SHIFT_L | ModifierFlag::FN, KeyboardType::MACBOOK));
  }

  // ENTER(+FN)
  vec.push_back(NormalizeItem(KeyCode::ENTER, ModifierFlag::SHIFT_L | ModifierFlag::FN,
                              KeyCode::ENTER, ModifierFlag::SHIFT_L | ModifierFlag::FN, KeyboardType::MACBOOK));

  // FORWARD_DELETE(+FN)
  vec.push_back(NormalizeItem(KeyCode::FORWARD_DELETE, ModifierFlag::SHIFT_L | ModifierFlag::FN,
                              KeyCode::FORWARD_DELETE, ModifierFlag::SHIFT_L | ModifierFlag::FN, KeyboardType::MACBOOK));

  // ----------------------------------------
  for (std::vector<NormalizeItem>::iterator it = vec.begin(); it != vec.end(); ++it) {
    KeyCode key;

    // Down
    key = it->fromKeyCode;
    KeyCode::normalizeKey(key, it->fromFlags, EventType::DOWN, it->keyboardType);
    KeyCode::reverseNormalizeKey(key, it->fromFlags, EventType::DOWN, it->keyboardType);
    EXPECT_EQ(it->toKeyCode, key);
    EXPECT_EQ(it->fromFlags, it->toFlags);

    // Up
    key = it->fromKeyCode;
    KeyCode::normalizeKey(key, it->fromFlags, EventType::UP, it->keyboardType);
    KeyCode::reverseNormalizeKey(key, it->fromFlags, EventType::UP, it->keyboardType);
    EXPECT_EQ(it->toKeyCode, key);
    EXPECT_EQ(it->fromFlags, it->toFlags);
  }

  // ======================================================================
  // Test case for the following key sequence.
  //  (1) FN Down
  //  (2) Right-Arrow Down
  //  (3) FN Up
  //  (4) Right-Arrow Up
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 12, flags 0x800000, key 63, kbdType 37
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 10, flags 0x800000, key 119, kbdType 37
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 12, flags 0x0, key 63, kbdType 37
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 11, flags 0x0, key 119, kbdType 37
  {
    KeyCode key = KeyCode::END;
    Flags flags = ModifierFlag::FN;
    KeyCode::normalizeKey(key, flags, EventType::DOWN, KeyboardType::MACBOOK);
    KeyCode::reverseNormalizeKey(key, flags, EventType::DOWN, KeyboardType::MACBOOK);
    EXPECT_EQ(key, KeyCode::END);
    EXPECT_EQ(flags, ModifierFlag::FN);

    key = KeyCode::END;
    flags = Flags(0);
    KeyCode::normalizeKey(key, flags, EventType::UP, KeyboardType::MACBOOK);
    KeyCode::reverseNormalizeKey(key, flags, EventType::UP, KeyboardType::MACBOOK);
    EXPECT_EQ(key, KeyCode::END);
    EXPECT_EQ(flags, 0);
  }

  // Test case for the following key sequence.
  //  (1) Right-Arrow Down
  //  (2) FN Down
  //  (3) Right-Arrow UP
  //  (4) FN Up
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 10, flags 0x200000, key 124, kbdType 37
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 12, flags 0xa00000, key 63, kbdType 37
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 11, flags 0xa00000, key 124, kbdType 37
  // KeyRemap4MacBook KeyboardEventCallback [ caught]: eventType 12, flags 0x0, key 63, kbdType 37
  {
    KeyCode key = KeyCode::CURSOR_RIGHT;
    Flags flags = Flags(ModifierFlag::CURSOR);
    KeyCode::normalizeKey(key, flags, EventType::DOWN, KeyboardType::MACBOOK);
    KeyCode::reverseNormalizeKey(key, flags, EventType::DOWN, KeyboardType::MACBOOK);
    EXPECT_EQ(key, KeyCode::CURSOR_RIGHT);
    EXPECT_EQ(flags, ModifierFlag::CURSOR);

    key = KeyCode::CURSOR_RIGHT;
    flags = Flags(ModifierFlag::FN | ModifierFlag::CURSOR);
    KeyCode::normalizeKey(key, flags, EventType::UP, KeyboardType::MACBOOK);
    KeyCode::reverseNormalizeKey(key, flags, EventType::UP, KeyboardType::MACBOOK);
    EXPECT_EQ(key, KeyCode::CURSOR_RIGHT);
    EXPECT_EQ(flags, ModifierFlag::FN | ModifierFlag::CURSOR);
  }
}