Changeset 428834d


Ignore:
Timestamp:
Jan 9, 2008, 2:17:57 PM (13 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
369479d
Parents:
c10fef0
Message:
take two for input processing
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • keymap.c

    r47519e1b r428834d  
    55
    66/* returns 0 on success */
    7 int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
     7int owl_keymap_init(owl_keymap *km, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
    88{
    99  if (!name || !desc) return(-1);
     
    151151}
    152152
    153 owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(int), void (*prealways_fn)(int), void (*postalways_fn)(int))
     153owl_keymap *owl_keyhandler_create_and_add_keymap(owl_keyhandler *kh, char *name, char *desc, void (*default_fn)(owl_input), void (*prealways_fn)(owl_input), void (*postalways_fn)(owl_input))
    154154{
    155155  owl_keymap *km;
     
    202202/* processes a keypress.  returns 0 if the keypress was handled,
    203203 * 1 if not handled, -1 on error, and -2 if j==ERR. */
    204 int owl_keyhandler_process(owl_keyhandler *kh, gunichar j)
     204int owl_keyhandler_process(owl_keyhandler *kh, owl_input j)
    205205{
    206206  owl_keymap     *km;
     
    214214
    215215  /* temporarily disallow C-`/C-SPACE until we fix associated bugs */
    216   if (j==ERR || j==0) {
     216  if (j.ch == ERR || j.ch == 0) {
    217217        return(-1);
    218218  }
     
    224224
    225225  /* deal with ESC prefixing */
    226   if (!kh->in_esc && j==27) {
     226  if (!kh->in_esc && j.ch == 27) {
    227227    kh->in_esc = 1;
    228228    return(0);
    229229  }
    230230  if (kh->in_esc) {
    231     j = OWL_META(j);
     231    j.ch = OWL_META(j.ch);
    232232    kh->in_esc = 0;
    233233  }
    234234 
    235   kh->kpstack[++(kh->kpstackpos)] = j;
     235  kh->kpstack[++(kh->kpstackpos)] = j.ch;
    236236  if (kh->kpstackpos >= OWL_KEYMAP_MAXSTACK) {
    237237    owl_keyhandler_reset(kh);
     
    260260      } else if (match == 2) {  /* exact match */
    261261        /* owl_function_debugmsg("processkey: found exact match in %s", km->name); */
    262         owl_keybinding_execute(kb, j);
     262        owl_keybinding_execute(kb, j.ch);
    263263        owl_keyhandler_reset(kh);
    264264        if (km->postalways_fn) {
  • keypress.c

    r948b942 r428834d  
    148148  }
    149149  if (!*kb) {
    150     if (j&OWL_META(0)) {
     150    if (j & OWL_META(0)) {
    151151      strcat(kb, "M-");
    152152      j &= ~OWL_META(0);
     
    163163      strcat(kb, kb2);   
    164164    }
     165   
    165166  } 
    166167  if (!*kb) {
  • keys.c

    r8938188 r428834d  
    294294/****************************************************************/
    295295
    296 void owl_keys_recwin_prealways(int j) {
     296void owl_keys_recwin_prealways(owl_input j) {
    297297  /* Clear the message line on subsequent key presses */
    298298  owl_function_makemsg("");
    299299}
    300300
    301 void owl_keys_editwin_default(int j) {
     301void owl_keys_editwin_default(owl_input j) {
    302302  owl_editwin *e;
    303   if (NULL != (e=owl_global_get_typwin(&g))) {
    304     owl_editwin_process_char(e, j);
     303  if (NULL != (e=owl_global_get_typwin(&g))
     304      && j.ch < 0x100) {
     305       owl_editwin_process_char(e, j.uch);
    305306  }
    306307}
    307308
    308 void owl_keys_editwin_postalways(int j) {
     309void owl_keys_editwin_postalways(owl_input j) {
    309310  owl_editwin *e;
    310   if (NULL != (e=owl_global_get_typwin(&g))) {
    311     owl_editwin_post_process_char(e, j);
     311  if (NULL != (e=owl_global_get_typwin(&g))
     312      && j.ch < 0x100) {
     313    owl_editwin_post_process_char(e, j.uch);
    312314  } 
    313315  owl_global_set_needrefresh(&g);
    314316}
    315317
    316 void owl_keys_popless_postalways(int j) {
     318void owl_keys_popless_postalways(owl_input j) {
    317319  owl_viewwin *v = owl_global_get_viewwin(&g);
    318320  owl_popwin *pw = owl_global_get_popwin(&g);
     
    323325}
    324326
    325 void owl_keys_default_invalid(int j) {
    326   if (j==ERR) return;
    327   if (j==410) return;
     327void owl_keys_default_invalid(owl_input j) {
     328  if (j.ch==ERR) return;
     329  if (j.ch==410) return;
    328330  owl_keyhandler_invalidkey(owl_global_get_keyhandler(&g));
    329331}
  • owl.c

    rc10fef0 r428834d  
    7171  owl_popwin *pw;
    7272  int ret, initialsubs, debug, argcsave, followlast;
    73   gunichar j;
     73  owl_input j;
    7474  int newmsgs, nexttimediff;
    7575  struct sigaction sigact;
     
    546546     * little bit, but otherwise do not.  This lets input be grabbed
    547547     * as quickly as possbile */
    548     j=wgetch(typwin);
    549     if (j == ERR
    550 #ifdef KEY_RESIZE
    551         || j == KEY_RESIZE
    552 #endif
    553          ) {
     548    j.ch = wgetch(typwin);
     549    if (j.ch == ERR) {
    554550      usleep(10000);
    555551    } else {
    556       /* Pull in a full utf-8 character. */
    557       if (j & 0x80) {
    558         char utf8buf[7];
     552      j.uch = '\0';
     553      if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
     554        /* This is a curses control character. */
     555      }
     556      else if (j.ch > 0x7f && j.ch < 0xfe) {
     557        /* Pull in a full utf-8 character. */
    559558        int bytes, i;
    560         memset(utf8buf,'\0',7);
    561         utf8buf[0] = j;
    562 
    563         if ((j & 0xc0) && (~j & 0x20)) bytes = 2;
    564         else if ((j & 0xe0) && (~j & 0x10)) bytes = 3;
    565         else if ((j & 0xf0) && (~j & 0x08)) bytes = 4;
    566         else if ((j & 0xf8) && (~j & 0x04)) bytes = 5;
    567         else if ((j & 0xfc) && (~j & 0x02)) bytes = 6;
     559        char *utf8buf[7];
     560        memset(utf8buf, '\0', 7);
     561
     562        utf8buf[0] = j.ch;
     563
     564        if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
     565        else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
     566        else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
     567        else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
     568        else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
    568569        else bytes = 1;
    569570       
     
    572573        }
    573574        if (g_utf8_validate(utf8buf, -1, NULL)) {
    574           j = g_utf8_get_char(utf8buf);
     575          j.uch = g_utf8_get_char(utf8buf);
    575576        }
    576577        else {
    577           j = ERR;
     578          j.ch = ERR;
    578579        }
    579580      }
     581      else if (j.ch <= 0x7f) {
     582        j.uch = j.ch;
     583      }
     584     
    580585      owl_global_update_lastinputtime(&g);
    581586      /* find and activate the current keymap.
  • owl.h

    r9866c3a r428834d  
    272272} owl_variable;
    273273
     274typedef struct _owl_input {
     275  int ch;
     276  char utf8buf[8];
     277  gunichar uch;
     278} owl_input;
     279
    274280typedef struct _owl_fmtext {
    275281  int textlen;
     
    511517  owl_list  bindings;           /* key bindings */
    512518  struct _owl_keymap *submap;   /* submap */
    513   void (*default_fn)(int j);    /* default action (takes a keypress) */
    514   void (*prealways_fn)(int j);  /* always called before a keypress is received */
    515   void (*postalways_fn)(int j); /* always called after keypress is processed */
     519  void (*default_fn)(owl_input j);      /* default action (takes a keypress) */
     520  void (*prealways_fn)(owl_input j);   /* always called before a keypress is received */
     521  void (*postalways_fn)(owl_input j);  /* always called after keypress is processed */
    516522} owl_keymap;
    517523
Note: See TracChangeset for help on using the changeset viewer.