Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r26ad412 r8bba1ae  
    1313#endif
    1414
     15static void _owl_global_init_windows(owl_global *g);
     16
    1517void owl_global_init(owl_global *g) {
    1618  struct hostent *hent;
     
    2022  g->malloced=0;
    2123  g->freed=0;
     24
     25  g_type_init();
    2226
    2327  gethostname(hostname, MAXHOSTNAMELEN);
     
    2933  }
    3034
     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
    3141  g->context_stack = NULL;
    32   owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL);
     42  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
    3343
    3444  g->curmsg=0;
    3545  g->topmsg=0;
    3646  g->markedmsgid=-1;
    37   g->needrefresh=1;
    3847  g->startupargs=NULL;
    3948
    4049  owl_variable_dict_setup(&(g->vars));
    41 
    42   g->lines=LINES;
    43   g->cols=COLS;
    4450
    4551  g->rightshift=0;
     
    5359  g->filterlist = NULL;
    5460  owl_list_create(&(g->puntlist));
    55   owl_list_create(&(g->messagequeue));
     61  g->messagequeue = g_queue_new();
    5662  owl_dict_create(&(g->styledict));
    5763  g->curmsg_vert_offset=0;
    5864  g->resizepending=0;
    59   g->relayoutpending = 0;
    6065  g->direction=OWL_DIRECTION_DOWNWARDS;
    6166  g->zaway=0;
     
    7984  g->nextmsgid=0;
    8085
    81   _owl_global_setup_windows(g);
    82 
    8386  /* Fill in some variables which don't have constant defaults */
    8487  /* TODO: come back later and check passwd file first */
     
    9295
    9396  owl_messagelist_create(&(g->msglist));
    94   owl_mainwin_init(&(g->mw));
    95   owl_popwin_init(&(g->pw));
     97
     98  _owl_global_init_windows(g);
    9699
    97100  g->aim_screenname=NULL;
     
    112115  g->zaldlist = NULL;
    113116  g->pseudologin_notify = 0;
    114 
    115   owl_obarray_init(&(g->obarray));
    116117
    117118  owl_message_init_fmtext_cache();
     
    120121  g->timerlist = NULL;
    121122  g->interrupted = FALSE;
     123}
     124
     125static 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);
    122137
    123138  /* set up a pad for input */
     
    126141  keypad(g->input_pad, 1);
    127142  meta(g->input_pad, 1);
     143}
     144
     145void owl_global_sepbar_dirty(owl_global *g)
     146{
     147  owl_window_dirty(g->mainpanel.sepwin);
    128148}
    129149
     
    158178}
    159179
    160 void _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 
    190180owl_context *owl_global_get_context(owl_global *g) {
    191181  if (!g->context_stack)
     
    194184}
    195185
    196 static void owl_global_lookup_keymap(owl_global *g) {
    197   owl_context *c = owl_global_get_context(g);
    198   if (!c || !c->keymap)
     186static void owl_global_activate_context(owl_global *g, owl_context *c) {
     187  if (!c)
    199188    return;
    200189
    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 
    206 void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) {
     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
     198void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
    207199  owl_context *c;
    208200  if (!(mode & OWL_CTX_MODE_BITS))
     
    211203  c->mode = mode;
    212204  c->data = data;
     205  c->cursor = cursor ? g_object_ref(cursor) : NULL;
    213206  c->keymap = owl_strdup(keymap);
    214207  g->context_stack = g_list_prepend(g->context_stack, c);
    215   owl_global_lookup_keymap(g);
     208  owl_global_activate_context(g, owl_global_get_context(g));
    216209}
    217210
     
    223216  g->context_stack = g_list_delete_link(g->context_stack,
    224217                                        g->context_stack);
     218  if (c->cursor)
     219    g_object_unref(c->cursor);
    225220  owl_free(c->keymap);
    226221  owl_free(c);
    227   owl_global_lookup_keymap(g);
     222  owl_global_activate_context(g, owl_global_get_context(g));
    228223}
    229224
     
    237232
    238233int owl_global_get_recwin_lines(const owl_global *g) {
    239   return(g->recwinlines);
     234  return g->mainpanel.recwinlines;
    240235}
    241236
     
    303298}
    304299
    305 /* curses windows */
    306 
    307 WINDOW *owl_global_get_curs_recwin(const owl_global *g) {
    308   return panel_window(g->recpan);
    309 }
    310 
    311 WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
    312   return panel_window(g->seppan);
    313 }
    314 
    315 WINDOW *owl_global_get_curs_msgwin(const owl_global *g) {
    316   return panel_window(g->msgpan);
    317 }
    318 
    319 WINDOW *owl_global_get_curs_typwin(const owl_global *g) {
    320   return panel_window(g->typpan);
     300/* underlying owl_windows */
     301
     302owl_window *owl_global_get_typwin_window(const owl_global *g) {
     303  return g->mainpanel.typwin;
    321304}
    322305
     
    327310}
    328311
    329 /* refresh */
    330 
    331 int owl_global_is_needrefresh(const owl_global *g) {
    332   if (g->needrefresh==1) return(1);
    333   return(0);
    334 }
    335 
    336 void owl_global_set_needrefresh(owl_global *g) {
    337   g->needrefresh=1;
    338 }
    339 
    340 void owl_global_set_noneedrefresh(owl_global *g) {
    341   g->needrefresh=0;
    342 }
    343 
    344312/* variable dictionary */
    345313
     
    357325
    358326void owl_global_set_rightshift(owl_global *g, int i) {
    359   g->rightshift=i;
     327  g->rightshift = i;
     328  owl_mainwin_redisplay(owl_global_get_mainwin(g));
    360329}
    361330
     
    372341      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
    373342
    374   g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
     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),
    375349                          owl_global_get_typwin_lines(g),
    376350                          g->cols,
     
    385359      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
    386360
    387   werase(owl_global_get_curs_typwin(g));
     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
    388367  g->tw = NULL;
    389368}
     
    393372void owl_global_set_resize_pending(owl_global *g) {
    394373  g->resizepending=1;
    395 }
    396 
    397 void owl_global_set_relayout_pending(owl_global *g) {
    398   g->relayoutpending = 1;
    399374}
    400375
     
    476451 * fail.
    477452 */
    478 static void _owl_global_get_size(int *lines, int *cols) {
     453void owl_global_get_terminal_size(int *lines, int *cols) {
    479454  struct winsize size;
    480455  /* get the new size */
     
    493468}
    494469
    495 void owl_global_resize(owl_global *g, int x, int y) {
    496   /* resize the screen.  If x or y is 0 use the terminal size */
     470void owl_global_check_resize(owl_global *g) {
     471  /* resize the screen.  If lines or cols is 0 use the terminal size */
    497472  if (!g->resizepending) return;
    498473  g->resizepending = 0;
    499474
    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);
     475  owl_global_get_terminal_size(&g->lines, &g->cols);
     476  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
    509477
    510478  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
    511   owl_global_set_relayout_pending(g);
    512 }
    513 
    514 void 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("");
    561479}
    562480
     
    628546
    629547void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
    630   g->curmsg_vert_offset=i;
     548  g->curmsg_vert_offset = i;
    631549}
    632550
     
    864782void owl_global_messagequeue_addmsg(owl_global *g, owl_message *m)
    865783{
    866   owl_list_append_element(&(g->messagequeue), m);
     784  g_queue_push_tail(g->messagequeue, m);
    867785}
    868786
     
    875793  owl_message *out;
    876794
    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);
     795  if (g_queue_is_empty(g->messagequeue))
     796    return NULL;
     797  out = g_queue_pop_head(g->messagequeue);
     798  return out;
    881799}
    882800
    883801int owl_global_messagequeue_pending(owl_global *g)
    884802{
    885   if (owl_list_get_size(&(g->messagequeue))==0) return(0);
    886   return(1);
     803  return !g_queue_is_empty(g->messagequeue);
    887804}
    888805
     
    1012929}
    1013930
    1014 const char * owl_global_intern(owl_global *g, const char * string)
    1015 {
    1016   return owl_obarray_insert(&(g->obarray), string);
    1017 }
    1018 
    1019931owl_list *owl_global_get_io_dispatch_list(owl_global *g)
    1020932{
     
    1043955  g->interrupted = 0;
    1044956}
    1045 
    1046 void 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 
    1078 FILE *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.