void BootPromptWindow::_ActivateKeymap(const BMessage* message) const { entry_ref ref; if (message == NULL || message->FindRef("ref", &ref) != B_OK) return; // Load and use the new keymap Keymap keymap; if (keymap.Load(ref) != B_OK) { fprintf(stderr, "Failed to load new keymap file (%s).\n", ref.name); return; } // Get entry_ref to the Key_map file in the user settings. entry_ref currentRef; if (_GetCurrentKeymapRef(currentRef) != B_OK) { fprintf(stderr, "Failed to get ref to user keymap file.\n"); return; } if (keymap.Save(currentRef) != B_OK) { fprintf(stderr, "Failed to save new keymap file (%s).\n", ref.name); return; } keymap.Use(); }
void BootPromptWindow::_StoreKeymap() const { KeymapListItem* item = dynamic_cast<KeymapListItem*>( fKeymapsListView->ItemAt(fKeymapsListView->CurrentSelection(0))); if (item == NULL) return; // Load and use the new keymap Keymap keymap; if (keymap.Load(item->EntryRef()) != B_OK) { fprintf(stderr, "Failed to load new keymap file (%s).\n", item->EntryRef().name); return; } // Get entry_ref to the Key_map file in the user settings. entry_ref ref; if (_GetCurrentKeymapRef(ref) != B_OK) { fprintf(stderr, "Failed to get ref to user keymap file.\n"); return; } if (keymap.Save(ref) != B_OK) { fprintf(stderr, "Failed to save new keymap file (%s).\n", item->EntryRef().name); return; } keymap.Use(); }
static void setupKeymapper(OSystem &system) { #ifdef ENABLE_KEYMAPPER using namespace Common; Keymapper *mapper = system.getEventManager()->getKeymapper(); HardwareInputSet *inputSet = system.getHardwareInputSet(); // Query backend for hardware keys and register them mapper->registerHardwareInputSet(inputSet); // Now create the global keymap Keymap *primaryGlobalKeymap = new Keymap(kGlobalKeymapName); Action *act; act = new Action(primaryGlobalKeymap, "MENU", _("Menu")); act->addEvent(EVENT_MAINMENU); act = new Action(primaryGlobalKeymap, "SKCT", _("Skip")); act->addKeyEvent(KeyState(KEYCODE_ESCAPE, ASCII_ESCAPE, 0)); act = new Action(primaryGlobalKeymap, "PAUS", _("Pause")); act->addKeyEvent(KeyState(KEYCODE_SPACE, ' ', 0)); act = new Action(primaryGlobalKeymap, "SKLI", _("Skip line")); act->addKeyEvent(KeyState(KEYCODE_PERIOD, '.', 0)); #ifdef ENABLE_VKEYBD act = new Action(primaryGlobalKeymap, "VIRT", _("Display keyboard")); act->addEvent(EVENT_VIRTUAL_KEYBOARD); #endif act = new Action(primaryGlobalKeymap, "REMP", _("Remap keys")); act->addEvent(EVENT_KEYMAPPER_REMAP); act = new Action(primaryGlobalKeymap, "FULS", _("Toggle fullscreen")); act->addKeyEvent(KeyState(KEYCODE_RETURN, ASCII_RETURN, KBD_ALT)); mapper->addGlobalKeymap(primaryGlobalKeymap); mapper->pushKeymap(kGlobalKeymapName, true); // Get the platform-specific global keymap (if it exists) Keymap *platformGlobalKeymap = system.getGlobalKeymap(); if (platformGlobalKeymap) { String platformGlobalKeymapName = platformGlobalKeymap->getName(); mapper->addGlobalKeymap(platformGlobalKeymap); mapper->pushKeymap(platformGlobalKeymapName, true); } #endif }
static void load_keymap(Keymap& keymap, const char* name, bool source) { status_t status; if (source) { if (name != NULL) status = keymap.LoadSource(name); else status = keymap.LoadSource(stdin); } else { if (name != NULL) status = keymap.Load(name); else status = keymap.Load(stdin); } if (status != B_OK) { fprintf(stderr, "%s: error when loading the keymap: %s\n", sProgramName, keymap_error(status)); exit(1); } }
void Landscape::fillPartialPayoffs( int kTotal ) /* fills the "payoffs" vector, which is all the individual choices' fitness levels */ { // cout << "fillPartialPayoffs called..." << endl; double randomTemp = 0; string configuration; unsigned short int ii = 0, jj = 0; for ( ii = 0 ; ii < itsN ; ii++ ){ payoffs.push_back( vector < Payoff >() ); // adds an empty vector for ( jj = 0 ; jj < pow(2,kTotal+1) ; jj++ ) { configuration = key.Get(ii, jj); // gets the key corresponding to d_ii, for configuration jj randomTemp = (double)rand() / ((double)(RAND_MAX)+(double)(1)); // random float bewteen 0 and 1 payoffs[ii].push_back(Payoff(configuration, randomTemp)); // filling the map with keys from 0 to n^(k+1), and values [0,1]l; // cout << "payoffs[" << ii << "][" << jj << "]: " << configuration << "," << randomTemp << ":" << payoffs[ii][jj].GetFitness() << endl; } } // cout << "fillPartialPayoffs finished..." << endl; }
void RemapDialog::loadKeymap() { _currentActions.clear(); const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack(); debug(3, "RemapDialog::loadKeymap active keymaps: %u", activeKeymaps.size()); if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) { // This is the "effective" view which shows all effective actions: // - all of the topmost keymap action // - all mapped actions that are reachable List<const HardwareInput *> freeInputs(_keymapper->getHardwareInputs()); int topIndex = activeKeymaps.size() - 1; // This is a WORKAROUND for changing the popup list selected item and changing it back // to the top entry. Upon changing it back, the top keymap is always "gui". if (!_topKeymapIsGui && activeKeymaps[topIndex].keymap->getName() == kGuiKeymapName) --topIndex; // add most active keymap's keys Keymapper::MapRecord top = activeKeymaps[topIndex]; List<Action *>::iterator actIt; debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str()); for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) { Action *act = *actIt; ActionInfo info = {act, false, act->description}; _currentActions.push_back(info); if (act->getMappedInput()) freeInputs.remove(act->getMappedInput()); } // loop through remaining finding mappings for unmapped keys if (top.transparent && topIndex >= 0) { for (int i = topIndex - 1; i >= 0; --i) { Keymapper::MapRecord mr = activeKeymaps[i]; debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str()); List<const HardwareInput *>::iterator inputIt = freeInputs.begin(); const HardwareInput *input = *inputIt; while (inputIt != freeInputs.end()) { Action *act = 0; if (input->type == kHardwareInputTypeKeyboard) act = mr.keymap->getMappedAction(input->key); else if (input->type == kHardwareInputTypeGeneric) act = mr.keymap->getMappedAction(input->inputCode); if (act) { ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"}; _currentActions.push_back(info); freeInputs.erase(inputIt); } else { ++inputIt; } } if (mr.transparent == false || freeInputs.empty()) break; } } } else if (_kmPopUp->getSelected() != -1) { // This is the regular view of a keymap that isn't the topmost one. // It shows all of that keymap's actions Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()]; List<Action *>::iterator it; for (it = km->getActions().begin(); it != km->getActions().end(); ++it) { ActionInfo info = {*it, false, (*it)->description}; _currentActions.push_back(info); } } // refresh scroll bar _scrollBar->_currentPos = 0; _scrollBar->_numEntries = _currentActions.size(); _scrollBar->recalc(); // force refresh _topAction = -1; refreshKeymap(); }
int main(int argc, char** argv) { const char* output = NULL; const char* input = NULL; enum { kUnspecified, kLoadBinary, kLoadText, kSaveText, kRestore, kCompile, kSaveHeader, } mode = kUnspecified; static struct option const kLongOptions[] = { {"output", required_argument, 0, 'o'}, {"dump", optional_argument, 0, 'd'}, {"load", optional_argument, 0, 'l'}, {"load-source", optional_argument, 0, 's'}, {"restore", no_argument, 0, 'r'}, {"compile", optional_argument, 0, 'c'}, {"header", optional_argument, 0, 'h'}, {"help", no_argument, 0, 'H'}, {NULL} }; int c; while ((c = getopt_long(argc, argv, "o:dblsrchH", kLongOptions, NULL)) != -1) { switch (c) { case 0: break; case 'o': output = optarg; break; case 'd': mode = kSaveText; input = optarg; break; case 'l': case 'b': mode = kLoadBinary; input = optarg; break; case 's': mode = kLoadText; input = optarg; break; case 'r': mode = kRestore; break; case 'c': mode = kCompile; input = optarg; break; case 'h': mode = kSaveHeader; input = optarg; break; case 'H': default: mode = kUnspecified; break; } } if (argc > optind && input == NULL) input = argv[optind]; BApplication* app = new BApplication("application/x-vnd.Haiku-keymap-cli"); Keymap keymap; switch (mode) { case kUnspecified: usage(); break; case kLoadBinary: case kLoadText: { load_keymap(keymap, input, mode == kLoadText); status_t status = keymap.SaveAsCurrent(); if (status != B_OK) { fprintf(stderr, "%s: error when saving as current: %s", sProgramName, strerror(status)); return 1; } printf("Key map loaded.\n"); break; } case kSaveText: { if (input == NULL) { status_t status = keymap.SetToCurrent(); if (status != B_OK) { fprintf(stderr, "%s: error while getting keymap: %s!\n", sProgramName, keymap_error(status)); return 1; } } else load_keymap(keymap, input, false); if (output != NULL) keymap.SaveAsSource(output); else keymap.SaveAsSource(stdout); break; } case kRestore: keymap.RestoreSystemDefault(); break; case kCompile: { load_keymap(keymap, input, true); if (output == NULL) output = "keymap.out"; status_t status = keymap.Save(output); if (status != B_OK) { fprintf(stderr, "%s: error saving \"%s\": %s\n", sProgramName, output, strerror(status)); return 1; } break; } case kSaveHeader: { load_keymap(keymap, input, true); if (output == NULL) output = "keymap.h"; status_t status = keymap.SaveAsCppHeader(output, input); if (status != B_OK) { fprintf(stderr, "%s: error saving \"%s\": %s\n", sProgramName, output, strerror(status)); return 1; } break; } } return 0; }
void RemapDialog::loadKeymap() { _currentActions.clear(); const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack(); if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) { // load active keymaps List<const HardwareKey*> freeKeys(_keymapper->getHardwareKeys()); // add most active keymap's keys Keymapper::MapRecord top = activeKeymaps.top(); List<Action*>::iterator actIt; for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) { Action *act = *actIt; ActionInfo info = {act, false, act->description}; _currentActions.push_back(info); if (act->getMappedKey()) freeKeys.remove(act->getMappedKey()); } // loop through remaining finding mappings for unmapped keys if (top.inherit) { for (int i = activeKeymaps.size() - 2; i >= 0; --i) { Keymapper::MapRecord mr = activeKeymaps[i]; List<const HardwareKey*>::iterator keyIt = freeKeys.begin(); while (keyIt != freeKeys.end()) { Action *act = mr.keymap->getMappedAction((*keyIt)->key); if (act) { ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"}; _currentActions.push_back(info); freeKeys.erase(keyIt++); } else { ++keyIt; } } if (mr.inherit == false || freeKeys.empty()) break; } } } else if (_kmPopUp->getSelected() != -1) { Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()]; List<Action*>::iterator it; for (it = km->getActions().begin(); it != km->getActions().end(); ++it) { ActionInfo info = {*it, false, (*it)->description}; _currentActions.push_back(info); } } // refresh scroll bar _scrollBar->_currentPos = 0; _scrollBar->_numEntries = (_currentActions.size() + _colCount - 1) / _colCount; _scrollBar->recalc(); // force refresh _topAction = -1; refreshKeymap(); }
void RemapDialog::loadKeymap() { _currentActions.clear(); const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack(); debug(3, "RemapDialog::loadKeymap active keymaps: %u", activeKeymaps.size()); if (!activeKeymaps.empty() && _kmPopUp->getSelected() == 0) { // load active keymaps List<const HardwareKey*> freeKeys(_keymapper->getHardwareKeys()); int topIndex = activeKeymaps.size() - 1; // skip the top gui keymap since it is for the keymapper itself // TODO: Don't use the keymap name as a way to discriminate GUI maps if (topIndex > 0 && activeKeymaps[topIndex].keymap->getName().equals(kGuiKeymapName)) --topIndex; // add most active keymap's keys Keymapper::MapRecord top = activeKeymaps[topIndex]; List<Action*>::iterator actIt; debug(3, "RemapDialog::loadKeymap top keymap: %s", top.keymap->getName().c_str()); for (actIt = top.keymap->getActions().begin(); actIt != top.keymap->getActions().end(); ++actIt) { Action *act = *actIt; ActionInfo info = {act, false, act->description}; _currentActions.push_back(info); if (act->getMappedKey()) freeKeys.remove(act->getMappedKey()); } // loop through remaining finding mappings for unmapped keys if (top.transparent && topIndex >= 0) { for (int i = topIndex - 1; i >= 0; --i) { Keymapper::MapRecord mr = activeKeymaps[i]; debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str()); List<const HardwareKey*>::iterator keyIt = freeKeys.begin(); while (keyIt != freeKeys.end()) { Action *act = mr.keymap->getMappedAction((*keyIt)->key); if (act) { ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"}; _currentActions.push_back(info); freeKeys.erase(keyIt++); } else { ++keyIt; } } if (mr.transparent == false || freeKeys.empty()) break; } } } else if (_kmPopUp->getSelected() != -1) { Keymap *km = _keymapTable[_kmPopUp->getSelectedTag()]; List<Action*>::iterator it; for (it = km->getActions().begin(); it != km->getActions().end(); ++it) { ActionInfo info = {*it, false, (*it)->description}; _currentActions.push_back(info); } } // refresh scroll bar _scrollBar->_currentPos = 0; _scrollBar->_numEntries = _currentActions.size(); _scrollBar->recalc(); // force refresh _topAction = -1; refreshKeymap(); }
void Landscape::ReplaceKeys( vector < vector <string> > & replacement) { key.Replace(replacement); }