changeset 1158:752b1f8da34f

KeysCommand_t This should make it easier for the casual reader to tell what's what in keys.cc.
author corvid <corvid@lavabit.com>
date Fri, 05 Jun 2009 00:57:13 +0000
parents d4955772f3e0
children fb041759363c
files src/keys.cc src/keys.hh src/ui.cc
diffstat 3 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/keys.cc	Fri Jun 05 00:12:41 2009 +0000
+++ b/src/keys.cc	Fri Jun 05 00:57:13 2009 +0000
@@ -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 @@
  * 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 @@
  * 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 @@
       if (!dStrcasecmp(default_keys[i].name, commandName))
          return default_keys[i].cmd;
    }
-   return -1;
+   return KEYS_INVALID;
 }
 
 /*
@@ -242,13 +243,13 @@
  * 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 @@
 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) ;
--- a/src/keys.hh	Fri Jun 05 00:12:41 2009 +0000
+++ b/src/keys.hh	Fri Jun 05 00:57:13 2009 +0000
@@ -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 @@
    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);
 };
--- a/src/ui.cc	Fri Jun 05 00:12:41 2009 +0000
+++ b/src/ui.cc	Fri Jun 05 00:57:13 2009 +0000
@@ -748,7 +748,7 @@
    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) {