Exemple #1
0
void RemapDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
	debug(0, "Command!");

	if (cmd >= kRemapCmd && cmd < kRemapCmd + _keymapWidgets.size()) {
		startRemapping(cmd - kRemapCmd);
	} else if (cmd == GUI::kPopUpItemSelectedCmd) {
		loadKeymap();
	} else if (cmd == GUI::kSetPositionCmd) {
		refreshKeymap();
	} else if (cmd == kCloseCmd) {
		close();
	} else {
		GUI::Dialog::handleCommand(sender, cmd, data);
	}
}
int isysLoadKeymap(char * keymap) {
    int num = -1;
    int rc;
    gzFile f;
    struct kmapHeader hdr;
    struct kmapInfo * infoTable;
    char buf[16384]; 			/* I hope this is big enough */
    int i;

    f = gzopen("/etc/keymaps.gz", "r");
    if (!f) return -EACCES;

    if (gzread(f, &hdr, sizeof(hdr)) != sizeof(hdr)) {
	gzclose(f);
	return -EINVAL;
    }

    i = hdr.numEntries * sizeof(*infoTable);
    infoTable = alloca(i);
    if (gzread(f, infoTable, i) != i) {
	gzclose(f);
	return -EIO;
    }

    for (i = 0; i < hdr.numEntries; i++)
	if (!strcmp(infoTable[i].name, keymap)) {
	    num = i;
	    break;
	}

    if (num == -1) {
	gzclose(f);
	return -ENOENT;
    }

    for (i = 0; i < num; i++) {
	if (gzread(f, buf, infoTable[i].size) != infoTable[i].size) {
	    gzclose(f);
	    return -EIO;
	}
    }

    rc = loadKeymap(f);

    gzclose(f);

    return rc;
}
Exemple #3
0
int
dmenuSetKmapVariable(dialogMenuItem *tmp)
{
    char *lang;
    int err;

    variable_set((char *)tmp->data, TRUE);
    lang = variable_get(VAR_KEYMAP);
    if (lang != NULL)
    {
	err = loadKeymap(lang);
	if (err == -1)
	    msgConfirm("No appropriate keyboard map found, sorry.");
	else if (err == -2)
	    msgConfirm("Error installing keyboard map, errno = %d.", errno);
    }
    return DITEM_SUCCESS;
}
QEvdevKeyboardHandler::QEvdevKeyboardHandler(const QString &device, int fd, bool disableZap, bool enableCompose, const QString &keymapFile)
    : m_device(device), m_fd(fd), m_notify(Q_NULLPTR),
      m_modifiers(0), m_composing(0), m_dead_unicode(0xffff),
      m_no_zap(disableZap), m_do_compose(enableCompose),
      m_keymap(0), m_keymap_size(0), m_keycompose(0), m_keycompose_size(0)
{
    qCDebug(qLcEvdevKey) << "Create keyboard handler with for device" << device;

    setObjectName(QLatin1String("LinuxInput Keyboard Handler"));

    memset(m_locks, 0, sizeof(m_locks));

    if (keymapFile.isEmpty() || !loadKeymap(keymapFile))
        unloadKeymap();

    // socket notifier for events on the keyboard device
    m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
    connect(m_notify, SIGNAL(activated(int)), this, SLOT(readKeycode()));
}
Exemple #5
0
void RemapDialog::open() {
	const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();

	if (activeKeymaps.size() > 0) {
		if (activeKeymaps.top().keymap->getName() == Common::kGuiKeymapName)
			_topKeymapIsGui = true;
		// Add the entry for the "effective" special view. See RemapDialog::loadKeymap()
		_kmPopUp->appendEntry(activeKeymaps.top().keymap->getName() + _(" (Effective)"));
	}

	Keymapper::Domain *_globalKeymaps = &_keymapper->getGlobalDomain();
	Keymapper::Domain *_gameKeymaps = 0;

	int keymapCount = 0;

	if (_globalKeymaps->empty())
		_globalKeymaps = 0;
	else
		keymapCount += _globalKeymaps->size();

	if (ConfMan.getActiveDomain() != 0) {
		_gameKeymaps = &_keymapper->getGameDomain();

		if (_gameKeymaps->empty())
			_gameKeymaps = 0;
		else
			keymapCount += _gameKeymaps->size();
	}

	if (activeKeymaps.size() > 1) {
		keymapCount += activeKeymaps.size() - 1;
	}

	debug(3, "RemapDialog::open keymaps: %d", keymapCount);

	_keymapTable = (Keymap **)malloc(sizeof(Keymap *) * keymapCount);

	Keymapper::Domain::iterator it;
	uint32 idx = 0;

	if (activeKeymaps.size() > 1) {
		int topIndex = activeKeymaps.size() - 1;
		bool active = activeKeymaps[topIndex].transparent;
		for (int i = topIndex - 1; i >= 0; --i) {
			Keymapper::MapRecord mr = activeKeymaps[i];
			// Add an entry for each keymap in the stack after the top keymap. Mark it Active if it is
			// reachable or Blocked if an opaque keymap is on top of it thus blocking access to it.
			_kmPopUp->appendEntry(mr.keymap->getName() + (active ? _(" (Active)") : _(" (Blocked)")), idx);
			_keymapTable[idx++] = mr.keymap;
			active &= mr.transparent;
		}
	}

	_kmPopUp->appendEntry("");

	// Now add entries for all known keymaps. Note that there will be duplicates with the stack entries.

	if (_globalKeymaps) {
		for (it = _globalKeymaps->begin(); it != _globalKeymaps->end(); ++it) {
			// "global" means its keybindings apply to all games; saved in a global conf domain
			_kmPopUp->appendEntry(it->_value->getName() + _(" (Global)"), idx);
			_keymapTable[idx++] = it->_value;
		}
	}

	if (_gameKeymaps) {
		for (it = _gameKeymaps->begin(); it != _gameKeymaps->end(); ++it) {
			// "game" means its keybindings are saved per-target
			_kmPopUp->appendEntry(it->_value->getName() + _(" (Game)"), idx);
			_keymapTable[idx++] = it->_value;
		}
	}

	_changes = false;

	Dialog::open();

	_kmPopUp->setSelected(0);
	loadKeymap();
}
Exemple #6
0
/**
 * Loads the configuration specified keymap file if keymapping is enabled
 * using convertStringToSymbol to convert strings to client constants
 **/
void bx_keymap_c::loadKeymap(u32 stringToSymbol (const char*))
{
  if(myCfg->get_bool_value("keyboard.use_mapping", false))
    loadKeymap(stringToSymbol, myCfg->get_text_value("keyboard.map", "keys.map"));
}
Exemple #7
0
void RemapDialog::open() {
	bool divider = false;
	const Stack<Keymapper::MapRecord> &activeKeymaps = _keymapper->getActiveStack();

	if (!(activeKeymaps.size() > 0)) {
		_kmPopUp->appendEntry(activeKeymaps.top().keymap->getName() + _(" (Active)"));
		divider = true;
	}

	Keymapper::Domain *_globalKeymaps = &_keymapper->getGlobalDomain();
	Keymapper::Domain *_gameKeymaps = 0;

	int keymapCount = 0;

	if (_globalKeymaps->empty())
		_globalKeymaps = 0;
	else
		keymapCount += _globalKeymaps->size();

	if (ConfMan.getActiveDomain() != 0) {
		_gameKeymaps = &_keymapper->getGameDomain();

		if (_gameKeymaps->empty())
			_gameKeymaps = 0;
		else
			keymapCount += _gameKeymaps->size();
	}

	debug(3, "keymaps: %d", keymapCount);

	_keymapTable = (Keymap **)malloc(sizeof(Keymap*) * keymapCount);

	Keymapper::Domain::iterator it;
	uint32 idx = 0;

	if (_globalKeymaps) {
		if (divider)
			_kmPopUp->appendEntry("");
		for (it = _globalKeymaps->begin(); it != _globalKeymaps->end(); ++it) {
			_kmPopUp->appendEntry(it->_value->getName() + _(" (Global)"), idx);
			_keymapTable[idx++] = it->_value;
		}
		divider = true;
	}

	if (_gameKeymaps) {
		if (divider)
			_kmPopUp->appendEntry("");
		for (it = _gameKeymaps->begin(); it != _gameKeymaps->end(); ++it) {
			_kmPopUp->appendEntry(it->_value->getName() + _(" (Game)"), idx);
			_keymapTable[idx++] = it->_value;
		}
	}

	_changes = false;

	Dialog::open();

	_kmPopUp->setSelected(0);
	loadKeymap();
}
int chooseKeyboard(struct loaderData_s * loaderData, char ** kbdtypep) {
    int num = -1;
    int rc;
    gzFile f;
    struct kmapHeader hdr;
    struct kmapInfo * infoTable;
    struct langInfo * languages;
    int numLanguages;
    char ** kbds;
    char buf[16384]; 			/* I hope this is big enough */
    int i;
    char * defkbd = loaderData->kbd ? loaderData->kbd : NULL;
    char *lang;

#if defined(__s390__) || defined(__s390x__)
    return LOADER_NOOP;
#endif

    if (FL_SERIAL (flags) || FL_VIRTPCONSOLE(flags)) return LOADER_NOOP;

    numLanguages = getLangInfo(&languages);

    lang = getenv("LANG");
    if (!lang)
       lang = loaderData->lang;

    if (!defkbd && lang) {
	for (i = 0; i < numLanguages; i++) {
	    if (!strncmp(languages[i].lc_all, lang, 2)) {
		defkbd = languages[i].keyboard;
		break;
	    }
	}
    }

    if (!defkbd)
	defkbd = "us";

    f = gzopen("/etc/keymaps.gz", "r");
    if (!f) {
	errorWindow("cannot open /etc/keymaps.gz: %s");
	return LOADER_ERROR;
    }

    if (gzread(f, &hdr, sizeof(hdr)) != sizeof(hdr)) {
	errorWindow("failed to read keymaps header: %s");
	gzclose(f);
	return LOADER_ERROR;
    }

    logMessage(INFO, "%d keymaps are available", hdr.numEntries);

    i = hdr.numEntries * sizeof(*infoTable);
    infoTable = alloca(i);
    if (gzread(f, infoTable, i) != i) {
	errorWindow("failed to read keymap information: %s");
	gzclose(f);
	return LOADER_ERROR;
    }

    if (num == -1 ) {
	kbds = alloca(sizeof(*kbds) * (hdr.numEntries + 1));
	for (i = 0; i < hdr.numEntries; i++)  {
	    kbds[i] = infoTable[i].name;
	}

	kbds[i] = NULL;
	qsort(kbds, i, sizeof(*kbds), simpleStringCmp);

	for (i = 0; i < hdr.numEntries; i++) 
	    if (!strcmp(kbds[i], defkbd)) 
		num = i;

	rc = newtWinMenu(_("Keyboard Type"), 
			_("What type of keyboard do you have?"),
		        40, 5, 5, 8, kbds, &num, _("OK"), _("Back"), NULL);
	if (rc == 2) return LOADER_BACK;

	/* num needs to index the right keyboard infoTable */
	for (i = 0; i < hdr.numEntries; i++)
	    if (!strcmp(kbds[num], infoTable[i].name)) break;
	num = i;
    }

    rc = 0;

    for (i = 0; i < num; i++) {
	if (gzread(f, buf, infoTable[i].size) != infoTable[i].size) {
	    logMessage(ERROR, "error reading %d bytes from file: %m",
		       infoTable[i].size);
	    gzclose(f);
	    rc = LOADER_ERROR;
	}
    }

    if (!rc) rc = loadKeymap(f);

    /* normalize the error condition */
    /* MSWFIXME - do we want to warn the user that setting the
       keyboard didn't work?
    */
    if (rc != 0)
	rc = LOADER_ERROR;
    else
        gzclose(f);

    loaderData->kbd = strdup(infoTable[num].name);

    return rc;
}
Exemple #9
0
int main(int argc, char *argv[])
{
#ifdef BROGUE_TCOD
		currentConsole = tcodConsole;
#elif BROGUE_WEB
                currentConsole = webConsole;
#elif BROGUE_CURSES
		currentConsole = cursesConsole;
#endif

	rogue.nextGame = NG_NOTHING;
	rogue.nextGamePath[0] = '\0';
	rogue.nextGameSeed = 0;

	int i;
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "--scores") == 0) {
			// just dump the scores and quit!
			dumpScores();
			return 0;
		}

		if (strcmp(argv[i], "--seed") == 0 || strcmp(argv[i], "-s") == 0) {
			// pick a seed!
			if (i + 1 < argc) {
				unsigned int seed = atof(argv[i + 1]); // plenty of precision in a double, and simpler than any other option
				if (seed != 0) {
					i++;
					rogue.nextGameSeed = seed;
					rogue.nextGame = NG_NEW_GAME_WITH_SEED;
					continue;
				}
			}
		}

		if(strcmp(argv[i], "-n") == 0) {
			if (rogue.nextGameSeed == 0) {
				rogue.nextGame = NG_NEW_GAME;
			} else {
				rogue.nextGame = NG_NEW_GAME_WITH_SEED;
			}
			continue;
		}

		if(strcmp(argv[i], "--no-menu") == 0 || strcmp(argv[i], "-M") == 0) {
			rogue.nextGame = NG_NEW_GAME;
			noMenu = true;
			continue;
		}

		if(strcmp(argv[i], "--no-scores") == 0) {
    	noScores = true;
    	continue;
    }

    if(strcmp(argv[i], "--no-recording") == 0) {
    	noRecording = true;
      continue;
    }

    if(strcmp(argv[i], "--no-saves") == 0) {
      noSaves = true;
      continue;
    }

		if(strcmp(argv[i], "--noteye-hack") == 0) {
			serverMode = true;
			continue;
		}

		if(strcmp(argv[i], "-o") == 0 || strcmp(argv[i], "--open") == 0) {
			if (i + 1 < argc) {
				strncpy(rogue.nextGamePath, argv[i + 1], 4096);
				rogue.nextGamePath[4095] = '\0';
				rogue.nextGame = NG_OPEN_GAME;

				if (!endswith(rogue.nextGamePath, GAME_SUFFIX)) {
					append(rogue.nextGamePath, GAME_SUFFIX, 4096);
				}

				i++;
				continue;
			}
		}

		if(strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--view") == 0) {
			if (i + 1 < argc) {
				strncpy(rogue.nextGamePath, argv[i + 1], 4096);
				rogue.nextGamePath[4095] = '\0';
				rogue.nextGame = NG_VIEW_RECORDING;

				if (!endswith(rogue.nextGamePath, RECORDING_SUFFIX)) {
					append(rogue.nextGamePath, RECORDING_SUFFIX, 4096);
				}

				i++;
				continue;
			}
		}

		if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
			printf("%s\n", BROGUE_VERSION_STRING);
			return 0;
		}

		if (strcmp(argv[i], "--target") == 0) {
			printf("%s\n", BROGUE_TARGET_STRING);
			return 0;
		}

		if (!(strcmp(argv[i], "-?") && strcmp(argv[i], "-h") && strcmp(argv[i], "--help"))) {
			printCommandlineHelp();
			return 0;
		}

#ifdef BROGUE_TCOD
		if (strcmp(argv[i], "--SDL") == 0) {
			renderer = TCOD_RENDERER_SDL;
			currentConsole = tcodConsole;
			continue;
		}
		if (strcmp(argv[i], "--opengl") == 0 || strcmp(argv[i], "-gl") == 0) {
			renderer = TCOD_RENDERER_OPENGL;
			currentConsole = tcodConsole;
			continue;
		}
		if (strcmp(argv[i], "--size") == 0) {
			// pick a font size
			int size = atoi(argv[i + 1]);
			if (size != 0) {
				i++;
				brogueFontSize = size;
				continue;
			}
		}
#endif
#ifdef BROGUE_CURSES
		if (strcmp(argv[i], "--term") == 0 || strcmp(argv[i], "-t") == 0) {
			currentConsole = cursesConsole;
			continue;
		}
#endif

		// maybe it ends with .broguesave or .broguerec, then?
		if (endswith(argv[i], GAME_SUFFIX)) {
			strncpy(rogue.nextGamePath, argv[i], 4096);
			rogue.nextGamePath[4095] = '\0';
			rogue.nextGame = NG_OPEN_GAME;
			continue;
		}

		if (endswith(argv[i], RECORDING_SUFFIX)) {
			strncpy(rogue.nextGamePath, argv[i], 4096);
			rogue.nextGamePath[4095] = '\0';
			rogue.nextGame = NG_VIEW_RECORDING;
			continue;
		}
		
		badArgument(argv[i]);
		return 1;
	}
	
	loadKeymap();
	currentConsole.gameLoop();
	
	return 0;
}
Exemple #10
0
void bx_keymap_c::loadKeymap(Bit32u stringToSymbol(const char*))
{
  if (SIM->get_param_bool(BXPN_KBD_USEMAPPING)->get()) {
    loadKeymap(stringToSymbol, SIM->get_param_string(BXPN_KBD_KEYMAP)->getptr());
  }
}