Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r8bba1ae r26ad412  
    1313#endif
    1414
    15 static void _owl_global_init_windows(owl_global *g);
    16 
    1715void owl_global_init(owl_global *g) {
    1816  struct hostent *hent;
     
    2220  g->malloced=0;
    2321  g->freed=0;
    24 
    25   g_type_init();
    2622
    2723  gethostname(hostname, MAXHOSTNAMELEN);
     
    3329  }
    3430
    35   g->lines=LINES;
    36   g->cols=COLS;
    37   /* We shouldn't need this if we initialize lines and cols before the first
    38    * owl_window_get_screen, but to be safe, we synchronize. */
    39   owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
    40 
    4131  g->context_stack = NULL;
    42   owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
     32  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL);
    4333
    4434  g->curmsg=0;
    4535  g->topmsg=0;
    4636  g->markedmsgid=-1;
     37  g->needrefresh=1;
    4738  g->startupargs=NULL;
    4839
    4940  owl_variable_dict_setup(&(g->vars));
     41
     42  g->lines=LINES;
     43  g->cols=COLS;
    5044
    5145  g->rightshift=0;
     
    5953  g->filterlist = NULL;
    6054  owl_list_create(&(g->puntlist));
    61   g->messagequeue = g_queue_new();
     55  owl_list_create(&(g->messagequeue));
    6256  owl_dict_create(&(g->styledict));
    6357  g->curmsg_vert_offset=0;
    6458  g->resizepending=0;
     59  g->relayoutpending = 0;
    6560  g->direction=OWL_DIRECTION_DOWNWARDS;
    6661  g->zaway=0;
     
    8479  g->nextmsgid=0;
    8580
     81  _owl_global_setup_windows(g);
     82
    8683  /* Fill in some variables which don't have constant defaults */
    8784  /* TODO: come back later and check passwd file first */
     
    9592
    9693  owl_messagelist_create(&(g->msglist));
    97 
    98   _owl_global_init_windows(g);
     94  owl_mainwin_init(&(g->mw));
     95  owl_popwin_init(&(g->pw));
    9996
    10097  g->aim_screenname=NULL;
     
    115112  g->zaldlist = NULL;
    116113  g->pseudologin_notify = 0;
     114
     115  owl_obarray_init(&(g->obarray));
    117116
    118117  owl_message_init_fmtext_cache();
     
    121120  g->timerlist = NULL;
    122121  g->interrupted = FALSE;
    123 }
    124 
    125 static void _owl_global_init_windows(owl_global *g)
    126 {
    127   /* Create the main window */
    128   owl_mainpanel_init(&(g->mainpanel));
    129 
    130   /* Create the widgets */
    131   owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
    132   owl_popwin_init(&(g->pw));
    133   owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
    134   owl_sepbar_init(g->mainpanel.sepwin);
    135 
    136   owl_window_set_default_cursor(g->mainpanel.sepwin);
    137122
    138123  /* set up a pad for input */
     
    141126  keypad(g->input_pad, 1);
    142127  meta(g->input_pad, 1);
    143 }
    144 
    145 void owl_global_sepbar_dirty(owl_global *g)
    146 {
    147   owl_window_dirty(g->mainpanel.sepwin);
    148128}
    149129
     
    178158}
    179159
     160void _owl_global_setup_windows(owl_global *g) {
     161  int cols, typwin_lines;
     162
     163  cols=g->cols;
     164  typwin_lines=owl_global_get_typwin_lines(g);
     165
     166  /* set the new window sizes */
     167  g->recwinlines=g->lines-(typwin_lines+2);
     168  if (g->recwinlines<0) {
     169    /* gotta deal with this */
     170    g->recwinlines=0;
     171  }
     172
     173  /* create the new windows */
     174  _owl_panel_set_window(&g->recpan, newwin(g->recwinlines, cols, 0, 0));
     175  _owl_panel_set_window(&g->seppan, newwin(1, cols, g->recwinlines, 0));
     176  _owl_panel_set_window(&g->msgpan, newwin(1, cols, g->recwinlines+1, 0));
     177  _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));
     178
     179  if (g->tw)
     180      owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
     181
     182  idlok(owl_global_get_curs_typwin(g), FALSE);
     183  idlok(owl_global_get_curs_recwin(g), FALSE);
     184  idlok(owl_global_get_curs_sepwin(g), FALSE);
     185  idlok(owl_global_get_curs_msgwin(g), FALSE);
     186
     187  wmove(owl_global_get_curs_typwin(g), 0, 0);
     188}
     189
    180190owl_context *owl_global_get_context(owl_global *g) {
    181191  if (!g->context_stack)
     
    184194}
    185195
    186 static void owl_global_activate_context(owl_global *g, owl_context *c) {
    187   if (!c)
     196static void owl_global_lookup_keymap(owl_global *g) {
     197  owl_context *c = owl_global_get_context(g);
     198  if (!c || !c->keymap)
    188199    return;
    189200
    190   if (c->keymap) {
    191     if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
    192       owl_function_error("Unable to activate keymap '%s'", c->keymap);
    193     }
    194   }
    195   owl_window_set_cursor(c->cursor);
    196 }
    197 
    198 void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
     201  if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
     202    owl_function_error("Unable to activate keymap '%s'", c->keymap);
     203  }
     204}
     205
     206void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) {
    199207  owl_context *c;
    200208  if (!(mode & OWL_CTX_MODE_BITS))
     
    203211  c->mode = mode;
    204212  c->data = data;
    205   c->cursor = cursor ? g_object_ref(cursor) : NULL;
    206213  c->keymap = owl_strdup(keymap);
    207214  g->context_stack = g_list_prepend(g->context_stack, c);
    208   owl_global_activate_context(g, owl_global_get_context(g));
     215  owl_global_lookup_keymap(g);
    209216}
    210217
     
    216223  g->context_stack = g_list_delete_link(g->context_stack,
    217224                                        g->context_stack);
    218   if (c->cursor)
    219     g_object_unref(c->cursor);
    220225  owl_free(c->keymap);
    221226  owl_free(c);
    222   owl_global_activate_context(g, owl_global_get_context(g));
     227  owl_global_lookup_keymap(g);
    223228}
    224229
     
    232237
    233238int owl_global_get_recwin_lines(const owl_global *g) {
    234   return g->mainpanel.recwinlines;
     239  return(g->recwinlines);
    235240}
    236241
     
    298303}
    299304
    300 /* underlying owl_windows */
    301 
    302 owl_window *owl_global_get_typwin_window(const owl_global *g) {
    303   return g->mainpanel.typwin;
     305/* curses windows */
     306
     307WINDOW *owl_global_get_curs_recwin(const owl_global *g) {
     308  return panel_window(g->recpan);
     309}
     310
     311WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
     312  return panel_window(g->seppan);
     313}
     314
     315WINDOW *owl_global_get_curs_msgwin(const owl_global *g) {
     316  return panel_window(g->msgpan);
     317}
     318
     319WINDOW *owl_global_get_curs_typwin(const owl_global *g) {
     320  return panel_window(g->typpan);
    304321}
    305322
     
    310327}
    311328
     329/* refresh */
     330
     331int owl_global_is_needrefresh(const owl_global *g) {
     332  if (g->needrefresh==1) return(1);
     333  return(0);
     334}
     335
     336void owl_global_set_needrefresh(owl_global *g) {
     337  g->needrefresh=1;
     338}
     339
     340void owl_global_set_noneedrefresh(owl_global *g) {
     341  g->needrefresh=0;
     342}
     343
    312344/* variable dictionary */
    313345
     
    325357
    326358void owl_global_set_rightshift(owl_global *g, int i) {
    327   g->rightshift = i;
    328   owl_mainwin_redisplay(owl_global_get_mainwin(g));
     359  g->rightshift=i;
    329360}
    330361
     
    341372      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
    342373
    343   if (g->typwin_erase_id) {
    344     g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id);
    345     g->typwin_erase_id = 0;
    346   }
    347 
    348   g->tw = owl_editwin_new(owl_global_get_typwin_window(g),
     374  g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
    349375                          owl_global_get_typwin_lines(g),
    350376                          g->cols,
     
    359385      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
    360386
    361   if (!g->typwin_erase_id) {
    362     g->typwin_erase_id =
    363       g_signal_connect(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
    364   }
    365   owl_window_dirty(owl_global_get_typwin_window(g));
    366 
     387  werase(owl_global_get_curs_typwin(g));
    367388  g->tw = NULL;
    368389}
     
    372393void owl_global_set_resize_pending(owl_global *g) {
    373394  g->resizepending=1;
     395}
     396
     397void owl_global_set_relayout_pending(owl_global *g) {
     398  g->relayoutpending = 1;
    374399}
    375400
     
    451476 * fail.
    452477 */
    453 void owl_global_get_terminal_size(int *lines, int *cols) {
     478static void _owl_global_get_size(int *lines, int *cols) {
    454479  struct winsize size;
    455480  /* get the new size */
     
    468493}
    469494
    470 void owl_global_check_resize(owl_global *g) {
    471   /* resize the screen.  If lines or cols is 0 use the terminal size */
     495void owl_global_resize(owl_global *g, int x, int y) {
     496  /* resize the screen.  If x or y is 0 use the terminal size */
    472497  if (!g->resizepending) return;
    473498  g->resizepending = 0;
    474499
    475   owl_global_get_terminal_size(&g->lines, &g->cols);
    476   owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
     500  _owl_global_get_size(&g->lines, &g->cols);
     501  if (x != 0) {
     502    g->lines = x;
     503  }
     504  if (y != 0) {
     505    g->cols = y;
     506  }
     507
     508  resizeterm(g->lines, g->cols);
    477509
    478510  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
     511  owl_global_set_relayout_pending(g);
     512}
     513
     514void owl_global_relayout(owl_global *g) {
     515  owl_popwin *pw;
     516  owl_viewwin *vw;
     517
     518  if (!g->relayoutpending) return;
     519  g->relayoutpending = 0;
     520
     521  owl_function_debugmsg("Relayouting...");
     522
     523  /* re-initialize the windows */
     524  _owl_global_setup_windows(g);
     525
     526  /* in case any styles rely on the current width */
     527  owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
     528
     529  /* recalculate the topmsg to make sure the current message is on
     530   * screen */
     531  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
     532
     533  /* recreate the popwin */
     534  pw = owl_global_get_popwin(g);
     535  if (owl_popwin_is_active(pw)) {
     536    /*
     537     * This is somewhat hacky; we probably want a proper windowing layer. We
     538     * destroy the popwin and recreate it. Then the viewwin is redirected to
     539     * the new window.
     540     */
     541    vw = owl_global_get_viewwin(g);
     542    owl_popwin_close(pw);
     543    owl_popwin_up(pw);
     544    owl_viewwin_set_curswin(vw, owl_popwin_get_curswin(pw),
     545        owl_popwin_get_lines(pw), owl_popwin_get_cols(pw));
     546    owl_viewwin_redisplay(vw);
     547  }
     548
     549  /* refresh stuff */
     550  g->needrefresh=1;
     551  owl_mainwin_redisplay(&(g->mw));
     552  sepbar(NULL);
     553  if (g->tw)
     554      owl_editwin_redisplay(g->tw);
     555  else
     556    werase(owl_global_get_curs_typwin(g));
     557
     558  owl_function_full_redisplay();
     559
     560  owl_function_makemsg("");
    479561}
    480562
     
    546628
    547629void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
    548   g->curmsg_vert_offset = i;
     630  g->curmsg_vert_offset=i;
    549631}
    550632
     
    782864void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
    783865{
    784   g_queue_push_tail(g->messagequeue, m);
     866  owl_list_append_element(&(g->messagequeue), m);
    785867}
    786868
     
    793875  owl_message *out;
    794876
    795   if (g_queue_is_empty(g->messagequeue))
    796     return NULL;
    797   out = g_queue_pop_head(g->messagequeue);
    798   return out;
     877  if (owl_list_get_size(&(g->messagequeue))==0) return(NULL);
     878  out=owl_list_get_element(&(g->messagequeue), 0);
     879  owl_list_remove_element(&(g->messagequeue), 0);
     880  return(out);
    799881}
    800882
    801883int owl_global_messagequeue_pending(owl_global *g)
    802884{
    803   return !g_queue_is_empty(g->messagequeue);
     885  if (owl_list_get_size(&(g->messagequeue))==0) return(0);
     886  return(1);
    804887}
    805888
     
    9291012}
    9301013
     1014const char * owl_global_intern(owl_global *g, const char * string)
     1015{
     1016  return owl_obarray_insert(&(g->obarray), string);
     1017}
     1018
    9311019owl_list *owl_global_get_io_dispatch_list(owl_global *g)
    9321020{
     
    9551043  g->interrupted = 0;
    9561044}
     1045
     1046void owl_global_setup_default_filters(owl_global *g)
     1047{
     1048  int i;
     1049  static const struct {
     1050    const char *name;
     1051    const char *desc;
     1052  } filters[] = {
     1053    { "personal",
     1054      "private ^true$ and ( not type ^zephyr$ or "
     1055      "( class ^message and ( instance ^personal$ or instance ^urgent$ ) ) )" },
     1056    { "trash",
     1057      "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )" },
     1058    { "wordwrap", "not ( type ^admin$ or type ^zephyr$ )" },
     1059    { "ping", "opcode ^ping$" },
     1060    { "auto", "opcode ^auto$" },
     1061    { "login", "not login ^none$" },
     1062    { "reply-lockout", "class ^noc or class ^mail$" },
     1063    { "out", "direction ^out$" },
     1064    { "aim", "type ^aim$" },
     1065    { "zephyr", "type ^zephyr$" },
     1066    { "none", "false" },
     1067    { "all", "true" },
     1068    { NULL, NULL }
     1069  };
     1070
     1071  owl_function_debugmsg("startup: creating default filters");
     1072
     1073  for (i = 0; filters[i].name != NULL; i++)
     1074    owl_global_add_filter(g, owl_filter_new_fromstring(filters[i].name,
     1075                                                       filters[i].desc));
     1076}
     1077
     1078FILE *owl_global_get_debug_file_handle(owl_global *g) {
     1079  static char *open_file = NULL;
     1080  const char *filename = owl_global_get_debug_file(g);
     1081  if (g->debug_file == NULL ||
     1082      (open_file && strcmp(filename, open_file) != 0)) {
     1083    char *path;
     1084    int fd;
     1085
     1086    if (g->debug_file)
     1087      fclose(g->debug_file);
     1088
     1089    g->debug_file = NULL;
     1090
     1091    path = owl_sprintf("%s.%d", filename, getpid());
     1092    fd = open(path, O_CREAT|O_WRONLY|O_EXCL, 0600);
     1093    owl_free(path);
     1094
     1095    if (fd >= 0)
     1096      g->debug_file = fdopen(fd, "a");
     1097
     1098    owl_free(open_file);
     1099    open_file = owl_strdup(filename);
     1100  }
     1101  return g->debug_file;
     1102}
Note: See TracChangeset for help on using the changeset viewer.