[BACK]Return to tty-keys.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/tty-keys.c between version 1.34 and 1.35

version 1.34, 2011/03/04 23:26:44 version 1.35, 2012/03/15 10:36:00
Line 19 
Line 19 
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/time.h>  #include <sys/time.h>
   
   #include <limits.h>
   #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <termios.h>  #include <termios.h>
 #include <unistd.h>  #include <unistd.h>
Line 40 
Line 42 
 void            tty_keys_callback(int, short, void *);  void            tty_keys_callback(int, short, void *);
 int             tty_keys_mouse(struct tty *,  int             tty_keys_mouse(struct tty *,
                     const char *, size_t, size_t *, struct mouse_event *);                      const char *, size_t, size_t *, struct mouse_event *);
   int             tty_keys_device(struct tty *, const char *, size_t, size_t *);
   
 struct tty_key_ent {  struct tty_key_ent {
         enum tty_code_code      code;          enum tty_code_code      code;
Line 461 
Line 464 
                 goto handle_key;                  goto handle_key;
         }          }
   
           /* Is this device attributes response? */
           switch (tty_keys_device(tty, buf, len, &size)) {
           case 0:         /* yes */
                   evbuffer_drain(tty->event->input, size);
                   key = KEYC_NONE;
                   goto handle_key;
           case -1:        /* no, or not valid */
                   break;
           case 1:         /* partial */
                   goto partial_key;
           }
   
   
         /* Is this a mouse key press? */          /* Is this a mouse key press? */
         switch (tty_keys_mouse(tty, buf, len, &size, &mouse)) {          switch (tty_keys_mouse(tty, buf, len, &size, &mouse)) {
         case 0:         /* yes */          case 0:         /* yes */
Line 559 
Line 575 
 handle_key:  handle_key:
         evtimer_del(&tty->key_timer);          evtimer_del(&tty->key_timer);
   
         tty->key_callback(key, &mouse, tty->key_data);          if (key != KEYC_NONE)
                   tty->key_callback(key, &mouse, tty->key_data);
   
         tty->flags &= ~TTY_ESCAPE;          tty->flags &= ~TTY_ESCAPE;
         return (1);          return (1);
Line 653 
Line 670 
         m->x -= 33;          m->x -= 33;
         m->y -= 33;          m->y -= 33;
         log_debug("mouse position: x=%u y=%u b=%u", m->x, m->y, m->b);          log_debug("mouse position: x=%u y=%u b=%u", m->x, m->y, m->b);
           return (0);
   }
   
   /*
    * Handle device attributes input. Returns 0 for success, -1 for failure, 1 for
    * partial.
    */
   int
   tty_keys_device(struct tty *tty, const char *buf, size_t len, size_t *size)
   {
           u_int i, a, b;
           char  tmp[64], *endptr;
   
           /*
            * Secondary device attributes are \033[>a;b;c. We only request
            * attributes on xterm, so we only care about the middle values which
            * is the xterm version.
            */
   
           *size = 0;
   
           /* First three bytes are always \033[>. */
           if (buf[0] != '\033')
                   return (-1);
           if (len == 1)
                   return (1);
           if (buf[1] != '[')
                   return (-1);
           if (len == 2)
                   return (1);
           if (buf[2] != '>')
                   return (-1);
           if (len == 3)
                   return (1);
   
           /* Copy the rest up to a 'c'. */
           for (i = 0; i < (sizeof tmp) - 1 && buf[3 + i] != 'c'; i++) {
                   if (3 + i == len)
                           return (1);
                   tmp[i] = buf[3 + i];
           }
           if (i == (sizeof tmp) - 1)
                   return (-1);
           tmp[i] = '\0';
           *size = 4 + i;
   
           /* Convert version numbers. */
           a = strtoul(tmp, &endptr, 10);
           if (*endptr == ';') {
                   b = strtoul(endptr + 1, &endptr, 10);
                   if (*endptr != '\0' && *endptr != ';')
                           b = 0;
           } else
                   a = b = 0;
   
           log_debug("received xterm version %u", b);
           if (tty->xterm_version == 0)
                   tty->xterm_version = b;
   
         return (0);          return (0);
 }  }

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.35