Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r6fe806a r9c7a701  
    4646#include <sys/param.h>
    4747#include <sys/types.h>
     48#include <sys/time.h>
    4849#include <termios.h>
    4950#include <sys/stat.h>
    50 #include <locale.h>
    5151#include "owl.h"
    5252
     
    6161#endif
    6262
     63#define STDIN 0
     64
    6365static const char fileIdent[] = "$Id$";
    6466
     
    7173  owl_popwin *pw;
    7274  int ret, initialsubs, debug, argcsave, followlast;
    73   owl_input j;
    7475  int newmsgs, nexttimediff;
    7576  struct sigaction sigact;
     
    8687  int newstderr;
    8788#endif
    88  
    89   if (!GLIB_CHECK_VERSION (2, 12, 0))
    90     g_error ("GLib version 2.12.0 or above is needed.");
    9189
    9290  argcsave=argc;
     
    9795  debug=0;
    9896  initialsubs=1;
    99 
    100   setlocale(LC_ALL, "");
    101  
    10297  if (argc>0) {
    10398    argv++;
     
    214209  owl_global_set_haveaim(&g);
    215210
     211  /* prepare stdin dispatch */
     212  {
     213    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     214    d->fd = STDIN;
     215    d->cfunc = &owl_process_input;
     216    d->pfunc = NULL;
     217    owl_select_add_dispatch(d);
     218  }
     219 
    216220#ifdef HAVE_LIBZEPHYR
    217221  /* zephyr init */
    218222  ret=owl_zephyr_initialize();
    219   if (!ret)
    220       owl_global_set_havezephyr(&g);
     223  if (!ret) {
     224    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     225    d->fd = ZGetFD();
     226    d->cfunc = &owl_zephyr_process_events;
     227    d->pfunc = NULL;
     228    owl_select_add_dispatch(d);
     229    owl_global_set_havezephyr(&g);
     230  }
     231
    221232#endif
    222233
     
    433444    followlast=owl_global_should_followlast(&g);
    434445   
    435     /* Do AIM stuff */
    436     if (owl_global_is_doaimevents(&g)) {
    437       owl_aim_process_events();
    438 
    439       if (owl_global_is_aimloggedin(&g)) {
    440         if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
    441           /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
    442           owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
    443         }
    444       }
    445     }
    446 
    447446    owl_perlconfig_mainloop();
    448447
     
    462461    }
    463462
    464     owl_zephyr_process_events();
    465    
    466463    /* Grab incoming messages. */
    467464    newmsgs=0;
     
    538535     * little bit, but otherwise do not.  This lets input be grabbed
    539536     * as quickly as possbile */
    540     j.ch = wgetch(typwin);
    541     if (j.ch == ERR) {
    542       usleep(10000);
    543     } else {
    544       j.uch = '\0';
    545       if (j.ch >= KEY_MIN && j.ch <= KEY_MAX) {
    546         /* This is a curses control character. */
    547       }
    548       else if (j.ch > 0x7f && j.ch < 0xfe) {
    549         /* Pull in a full utf-8 character. */
    550         int bytes, i;
    551         char utf8buf[7];
    552         memset(utf8buf, '\0', 7);
    553 
    554         utf8buf[0] = j.ch;
    555 
    556         if ((j.ch & 0xc0) && (~j.ch & 0x20)) bytes = 2;
    557         else if ((j.ch & 0xe0) && (~j.ch & 0x10)) bytes = 3;
    558         else if ((j.ch & 0xf0) && (~j.ch & 0x08)) bytes = 4;
    559         else if ((j.ch & 0xf8) && (~j.ch & 0x04)) bytes = 5;
    560         else if ((j.ch & 0xfc) && (~j.ch & 0x02)) bytes = 6;
    561         else bytes = 1;
    562        
    563         for (i = 1; i < bytes; i++) {
    564           int tmp =  wgetch(typwin);
    565           /* If what we got was not a byte, or not a continuation byte */
    566           if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) {
    567             /* ill-formed UTF-8 code unit subsequence, put back the
    568                char we just got. */
    569             ungetch(tmp);
    570             j.ch = ERR;
    571             break;
    572           }
    573           utf8buf[i] = tmp;
    574         }
    575        
    576         if (j.ch != ERR) {
    577           if (g_utf8_validate(utf8buf, -1, NULL)) {
    578             j.uch = g_utf8_get_char(utf8buf);
    579           }
    580           else {
    581             j.ch = ERR;
    582           }
    583         }
    584       }
    585       else if (j.ch <= 0x7f) {
    586         j.uch = j.ch;
    587       }
    588      
    589       owl_global_update_lastinputtime(&g);
    590       /* find and activate the current keymap.
    591        * TODO: this should really get fixed by activating
    592        * keymaps as we switch between windows...
    593        */
    594       if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
    595         owl_context_set_popless(owl_global_get_context(&g),
    596                                 owl_global_get_viewwin(&g));
    597         owl_function_activate_keymap("popless");
    598       } else if (owl_global_is_typwin_active(&g)
    599                  && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
    600         /*
    601           owl_context_set_editline(owl_global_get_context(&g), tw);
    602           owl_function_activate_keymap("editline");
    603         */
    604       } else if (owl_global_is_typwin_active(&g)
    605                  && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
    606         owl_context_set_editmulti(owl_global_get_context(&g), tw);
    607         owl_function_activate_keymap("editmulti");
    608       } else {
    609         owl_context_set_recv(owl_global_get_context(&g));
    610         owl_function_activate_keymap("recv");
    611       }
    612       /* now actually handle the keypress */
    613       ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
    614       if (ret!=0 && ret!=1) {
    615         owl_function_makemsg("Unable to handle keypress");
    616       }
    617     }
     537
     538    /* select on FDs we know about. */
     539    owl_select();
    618540
    619541    /* Log any error signals */
     
    733655}
    734656
     657void owl_process_aim()
     658{
     659  if (owl_global_is_doaimevents(&g)) {
     660    owl_aim_process_events();
     661   
     662    if (owl_global_is_aimloggedin(&g)) {
     663      if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
     664        /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
     665        owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
     666      }
     667    }
     668  }
     669}
     670
     671void owl_process_input()
     672{
     673  int ret, j;
     674  owl_popwin *pw;
     675  owl_editwin *tw;
     676
     677  j = wgetch(owl_global_get_curs_typwin(&g));
     678  if (j == ERR) return;
     679
     680  owl_global_set_lastinputtime(&g, time(NULL));
     681  pw=owl_global_get_popwin(&g);
     682  tw=owl_global_get_typwin(&g);
     683
     684  /* find and activate the current keymap.
     685   * TODO: this should really get fixed by activating
     686   * keymaps as we switch between windows...
     687   */
     688  if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
     689    owl_context_set_popless(owl_global_get_context(&g),
     690                            owl_global_get_viewwin(&g));
     691    owl_function_activate_keymap("popless");
     692  } else if (owl_global_is_typwin_active(&g)
     693             && owl_editwin_get_style(tw) == OWL_EDITWIN_STYLE_ONELINE) {
     694    /*
     695      owl_context_set_editline(owl_global_get_context(&g), tw);
     696      owl_function_activate_keymap("editline");
     697    */
     698  } else if (owl_global_is_typwin_active(&g)
     699             && owl_editwin_get_style(tw) == OWL_EDITWIN_STYLE_MULTILINE) {
     700    owl_context_set_editmulti(owl_global_get_context(&g), tw);
     701    owl_function_activate_keymap("editmulti");
     702  } else {
     703    owl_context_set_recv(owl_global_get_context(&g));
     704    owl_function_activate_keymap("recv");
     705  }
     706  /* now actually handle the keypress */
     707  ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
     708  if (ret != 0 && ret != 1) {
     709    owl_function_makemsg("Unable to handle keypress");
     710  }
     711}
     712
    735713void sig_handler(int sig, siginfo_t *si, void *data)
    736714{
     
    747725    owl_function_quit();
    748726  }
    749 
    750727}
    751728
Note: See TracChangeset for help on using the changeset viewer.