diff options
author | corvid <corvid@lavabit.com> | 2009-06-05 00:57:13 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2009-06-05 00:57:13 +0000 |
commit | d75d8d25b56183f5e65b03c3d20533cc4c7b3782 (patch) | |
tree | 074c17cc7e66c6c4baa3e4c58eb9503a9946803e | |
parent | 03949fea7859bb716ea4389fcf253d04a1b6c6fc (diff) |
KeysCommand_t
This should make it easier for the casual reader to tell what's what in
keys.cc.
-rw-r--r-- | src/keys.cc | 23 | ||||
-rw-r--r-- | src/keys.hh | 11 | ||||
-rw-r--r-- | src/ui.cc | 2 |
3 files changed, 19 insertions, 17 deletions
diff --git a/src/keys.cc b/src/keys.cc index 17735822..a8b0b7ad 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -23,7 +23,8 @@ */ typedef struct { const char *name; - int cmd, modifier, key; + KeysCommand_t cmd; + int modifier, key; } KeyBinding_t; typedef struct { @@ -151,9 +152,9 @@ int Keys::nodeByKeyCmp(const void *node, const void *key) * Look if the just pressed key is bound to a command. * Return value: The command if found, KEYS_NOP otherwise. */ -int Keys::getKeyCmd() +KeysCommand_t Keys::getKeyCmd() { - int ret = KEYS_NOP; + KeysCommand_t ret = KEYS_NOP; KeyBinding_t keyNode; if (fltk::event_state() == fltk::SHIFT && @@ -211,7 +212,7 @@ int Keys::getKeyCode(char *keyName) * Takes a command name and searches it in the mapping table. * Return value: command code if found, -1 otherwise */ -int Keys::getCmdCode(const char *commandName) +KeysCommand_t Keys::getCmdCode(const char *commandName) { uint_t i; @@ -219,7 +220,7 @@ int Keys::getCmdCode(const char *commandName) if (!dStrcasecmp(default_keys[i].name, commandName)) return default_keys[i].cmd; } - return -1; + return KEYS_INVALID; } /* @@ -242,13 +243,13 @@ int Keys::getModifier(char *modifierName) * Given a keys command, return a shortcut for it, or 0 if there is none * (e.g., for KEYS_NEW_WINDOW, return CTRL+'n'). */ -int Keys::getShortcut(int command) +int Keys::getShortcut(KeysCommand_t cmd) { int len = dList_length(bindings); for (int i = 0; i < len; i++) { KeyBinding_t *node = (KeyBinding_t*)dList_nth_data(bindings, i); - if (command == node->cmd) + if (cmd == node->cmd) return node->modifier + node->key; } return 0; @@ -261,16 +262,16 @@ int Keys::getShortcut(int command) void Keys::parseKey(char *key, char *commandName) { char *p, *modstr, *keystr; - int st, symcode = 0, keymod = 0, keycode = 0; + KeysCommand_t symcode; + int st, keymod = 0, keycode = 0; _MSG("Keys::parseKey key='%s' commandName='%s'\n", key, commandName); // Get command code - if ((st = getCmdCode(commandName)) == -1) { + if ((symcode = getCmdCode(commandName)) == KEYS_INVALID) { MSG("Keys::parseKey: Invalid command name: '%s'\n", commandName); return; - } else - symcode = st; + } // Skip space for ( ; isspace(*key); ++key) ; diff --git a/src/keys.hh b/src/keys.hh index cf3f57f3..88b7f89d 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -13,7 +13,8 @@ #define __KEYS_HH__ -enum { +typedef enum { + KEYS_INVALID = -1, KEYS_NOP, /* No operation bound */ KEYS_OPEN, KEYS_NEW_WINDOW, @@ -35,19 +36,19 @@ enum { KEYS_FORWARD, KEYS_GOTO, KEYS_HOME -}; +} KeysCommand_t; class Keys { public: static void init(); static void free(); static int nodeByKeyCmp(const void *node, const void *key); - static int getKeyCmd(void); + static KeysCommand_t getKeyCmd(void); static void delKeyCmd(int key, int mod); - static int getCmdCode(const char *symbolName); + static KeysCommand_t getCmdCode(const char *symbolName); static int getKeyCode(char *keyName); static int getModifier(char *modifierName); - static int getShortcut(int command); + static int getShortcut(KeysCommand_t cmd); static void parseKey(char *key, char *symbol); static void parse(FILE *fp); }; @@ -748,7 +748,7 @@ int UI::handle(int event) if (event == KEY) { return 0; // Receive as shortcut } else if (event == SHORTCUT) { - int cmd = Keys::getKeyCmd(); + KeysCommand_t cmd = Keys::getKeyCmd(); if (cmd == KEYS_NOP) { // Do nothing } else if (cmd == KEYS_BACK) { |