Changeset d296c9a for global.c


Ignore:
Timestamp:
Jul 18, 2010, 4:48:15 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
205e164
Parents:
1cc9b615 (diff), 8bba1ae (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge branch 'owl_window'

Conflicts:
	global.c
File:
1 edited

Legend:

Unmodified
Added
Removed
  • global.c

    refc460e rd296c9a  
    1313#endif
    1414
     15static void _owl_global_init_windows(owl_global *g);
     16
    1517void owl_global_init(owl_global *g) {
    1618  struct hostent *hent;
    1719  char hostname[MAXHOSTNAMELEN];
    1820  char *cd;
     21
     22  g_type_init();
    1923
    2024  gethostname(hostname, MAXHOSTNAMELEN);
     
    2630  }
    2731
     32  g->lines=LINES;
     33  g->cols=COLS;
     34  /* We shouldn't need this if we initialize lines and cols before the first
     35   * owl_window_get_screen, but to be safe, we synchronize. */
     36  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
     37
    2838  g->context_stack = NULL;
    29   owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL);
     39  owl_global_push_context(g, OWL_CTX_STARTUP, NULL, NULL, NULL);
    3040
    3141  g->curmsg=0;
    3242  g->topmsg=0;
    3343  g->markedmsgid=-1;
    34   g->needrefresh=1;
    3544  g->startupargs=NULL;
    3645
    3746  owl_variable_dict_setup(&(g->vars));
    38 
    39   g->lines=LINES;
    40   g->cols=COLS;
    4147
    4248  g->rightshift=0;
     
    5460  g->curmsg_vert_offset=0;
    5561  g->resizepending=0;
    56   g->relayoutpending = 0;
    5762  g->direction=OWL_DIRECTION_DOWNWARDS;
    5863  g->zaway=0;
     
    7681  g->nextmsgid=0;
    7782
    78   _owl_global_setup_windows(g);
    79 
    8083  /* Fill in some variables which don't have constant defaults */
    8184  /* TODO: come back later and check passwd file first */
     
    8992
    9093  owl_messagelist_create(&(g->msglist));
    91   owl_mainwin_init(&(g->mw));
    92   owl_popwin_init(&(g->pw));
     94
     95  _owl_global_init_windows(g);
    9396
    9497  g->aim_screenname=NULL;
     
    115118  g->timerlist = NULL;
    116119  g->interrupted = FALSE;
     120}
     121
     122static void _owl_global_init_windows(owl_global *g)
     123{
     124  /* Create the main window */
     125  owl_mainpanel_init(&(g->mainpanel));
     126
     127  /* Create the widgets */
     128  owl_mainwin_init(&(g->mw), g->mainpanel.recwin);
     129  owl_popwin_init(&(g->pw));
     130  owl_msgwin_init(&(g->msgwin), g->mainpanel.msgwin);
     131  owl_sepbar_init(g->mainpanel.sepwin);
     132
     133  owl_window_set_default_cursor(g->mainpanel.sepwin);
    117134
    118135  /* set up a pad for input */
     
    121138  keypad(g->input_pad, 1);
    122139  meta(g->input_pad, 1);
     140}
     141
     142void owl_global_sepbar_dirty(owl_global *g)
     143{
     144  owl_window_dirty(g->mainpanel.sepwin);
    123145}
    124146
     
    153175}
    154176
    155 void _owl_global_setup_windows(owl_global *g) {
    156   int cols, typwin_lines;
    157 
    158   cols=g->cols;
    159   typwin_lines=owl_global_get_typwin_lines(g);
    160 
    161   /* set the new window sizes */
    162   g->recwinlines=g->lines-(typwin_lines+2);
    163   if (g->recwinlines<0) {
    164     /* gotta deal with this */
    165     g->recwinlines=0;
    166   }
    167 
    168   /* create the new windows */
    169   _owl_panel_set_window(&g->recpan, newwin(g->recwinlines, cols, 0, 0));
    170   _owl_panel_set_window(&g->seppan, newwin(1, cols, g->recwinlines, 0));
    171   _owl_panel_set_window(&g->msgpan, newwin(1, cols, g->recwinlines+1, 0));
    172   _owl_panel_set_window(&g->typpan, newwin(typwin_lines, cols, g->recwinlines+2, 0));
    173 
    174   if (g->tw)
    175       owl_editwin_set_curswin(g->tw, owl_global_get_curs_typwin(g), typwin_lines, g->cols);
    176 
    177   idlok(owl_global_get_curs_typwin(g), FALSE);
    178   idlok(owl_global_get_curs_recwin(g), FALSE);
    179   idlok(owl_global_get_curs_sepwin(g), FALSE);
    180   idlok(owl_global_get_curs_msgwin(g), FALSE);
    181 
    182   wmove(owl_global_get_curs_typwin(g), 0, 0);
    183 }
    184 
    185177owl_context *owl_global_get_context(owl_global *g) {
    186178  if (!g->context_stack)
     
    189181}
    190182
    191 static void owl_global_lookup_keymap(owl_global *g) {
    192   owl_context *c = owl_global_get_context(g);
    193   if (!c || !c->keymap)
     183static void owl_global_activate_context(owl_global *g, owl_context *c) {
     184  if (!c)
    194185    return;
    195186
    196   if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
    197     owl_function_error("Unable to activate keymap '%s'", c->keymap);
    198   }
    199 }
    200 
    201 void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap) {
     187  if (c->keymap) {
     188    if (!owl_keyhandler_activate(owl_global_get_keyhandler(g), c->keymap)) {
     189      owl_function_error("Unable to activate keymap '%s'", c->keymap);
     190    }
     191  }
     192  owl_window_set_cursor(c->cursor);
     193}
     194
     195void owl_global_push_context(owl_global *g, int mode, void *data, const char *keymap, owl_window *cursor) {
    202196  owl_context *c;
    203197  if (!(mode & OWL_CTX_MODE_BITS))
     
    206200  c->mode = mode;
    207201  c->data = data;
     202  c->cursor = cursor ? g_object_ref(cursor) : NULL;
    208203  c->keymap = owl_strdup(keymap);
    209204  g->context_stack = g_list_prepend(g->context_stack, c);
    210   owl_global_lookup_keymap(g);
     205  owl_global_activate_context(g, owl_global_get_context(g));
    211206}
    212207
     
    218213  g->context_stack = g_list_delete_link(g->context_stack,
    219214                                        g->context_stack);
     215  if (c->cursor)
     216    g_object_unref(c->cursor);
    220217  owl_free(c->keymap);
    221218  owl_free(c);
    222   owl_global_lookup_keymap(g);
     219  owl_global_activate_context(g, owl_global_get_context(g));
    223220}
    224221
     
    232229
    233230int owl_global_get_recwin_lines(const owl_global *g) {
    234   return(g->recwinlines);
     231  return g->mainpanel.recwinlines;
    235232}
    236233
     
    298295}
    299296
    300 /* curses windows */
    301 
    302 WINDOW *owl_global_get_curs_recwin(const owl_global *g) {
    303   return panel_window(g->recpan);
    304 }
    305 
    306 WINDOW *owl_global_get_curs_sepwin(const owl_global *g) {
    307   return panel_window(g->seppan);
    308 }
    309 
    310 WINDOW *owl_global_get_curs_msgwin(const owl_global *g) {
    311   return panel_window(g->msgpan);
    312 }
    313 
    314 WINDOW *owl_global_get_curs_typwin(const owl_global *g) {
    315   return panel_window(g->typpan);
     297/* underlying owl_windows */
     298
     299owl_window *owl_global_get_typwin_window(const owl_global *g) {
     300  return g->mainpanel.typwin;
    316301}
    317302
     
    322307}
    323308
    324 /* refresh */
    325 
    326 int owl_global_is_needrefresh(const owl_global *g) {
    327   if (g->needrefresh==1) return(1);
    328   return(0);
    329 }
    330 
    331 void owl_global_set_needrefresh(owl_global *g) {
    332   g->needrefresh=1;
    333 }
    334 
    335 void owl_global_set_noneedrefresh(owl_global *g) {
    336   g->needrefresh=0;
    337 }
    338 
    339309/* variable dictionary */
    340310
     
    352322
    353323void owl_global_set_rightshift(owl_global *g, int i) {
    354   g->rightshift=i;
     324  g->rightshift = i;
     325  owl_mainwin_redisplay(owl_global_get_mainwin(g));
    355326}
    356327
     
    367338      owl_function_resize_typwin(owl_global_get_typwin_lines(g) + d);
    368339
    369   g->tw = owl_editwin_new(owl_global_get_curs_typwin(g),
     340  if (g->typwin_erase_id) {
     341    g_signal_handler_disconnect(owl_global_get_typwin_window(g), g->typwin_erase_id);
     342    g->typwin_erase_id = 0;
     343  }
     344
     345  g->tw = owl_editwin_new(owl_global_get_typwin_window(g),
    370346                          owl_global_get_typwin_lines(g),
    371347                          g->cols,
     
    380356      owl_function_resize_typwin(owl_global_get_typwin_lines(g) - d);
    381357
    382   werase(owl_global_get_curs_typwin(g));
     358  if (!g->typwin_erase_id) {
     359    g->typwin_erase_id =
     360      g_signal_connect(owl_global_get_typwin_window(g), "redraw", G_CALLBACK(owl_window_erase_cb), NULL);
     361  }
     362  owl_window_dirty(owl_global_get_typwin_window(g));
     363
    383364  g->tw = NULL;
    384365}
     
    388369void owl_global_set_resize_pending(owl_global *g) {
    389370  g->resizepending=1;
    390 }
    391 
    392 void owl_global_set_relayout_pending(owl_global *g) {
    393   g->relayoutpending = 1;
    394371}
    395372
     
    471448 * fail.
    472449 */
    473 static void _owl_global_get_size(int *lines, int *cols) {
     450void owl_global_get_terminal_size(int *lines, int *cols) {
    474451  struct winsize size;
    475452  /* get the new size */
     
    488465}
    489466
    490 void owl_global_resize(owl_global *g, int x, int y) {
    491   /* resize the screen.  If x or y is 0 use the terminal size */
     467void owl_global_check_resize(owl_global *g) {
     468  /* resize the screen.  If lines or cols is 0 use the terminal size */
    492469  if (!g->resizepending) return;
    493470  g->resizepending = 0;
    494471
    495   _owl_global_get_size(&g->lines, &g->cols);
    496   if (x != 0) {
    497     g->lines = x;
    498   }
    499   if (y != 0) {
    500     g->cols = y;
    501   }
    502 
    503   resizeterm(g->lines, g->cols);
     472  owl_global_get_terminal_size(&g->lines, &g->cols);
     473  owl_window_resize(owl_window_get_screen(), g->lines, g->cols);
    504474
    505475  owl_function_debugmsg("New size is %i lines, %i cols.", g->lines, g->cols);
    506   owl_global_set_relayout_pending(g);
    507 }
    508 
    509 void owl_global_relayout(owl_global *g) {
    510   owl_popwin *pw;
    511   owl_viewwin *vw;
    512 
    513   if (!g->relayoutpending) return;
    514   g->relayoutpending = 0;
    515 
    516   owl_function_debugmsg("Relayouting...");
    517 
    518   /* re-initialize the windows */
    519   _owl_global_setup_windows(g);
    520 
    521   /* in case any styles rely on the current width */
    522   owl_messagelist_invalidate_formats(owl_global_get_msglist(g));
    523 
    524   /* recalculate the topmsg to make sure the current message is on
    525    * screen */
    526   owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
    527 
    528   /* recreate the popwin */
    529   pw = owl_global_get_popwin(g);
    530   if (owl_popwin_is_active(pw)) {
    531     /*
    532      * This is somewhat hacky; we probably want a proper windowing layer. We
    533      * destroy the popwin and recreate it. Then the viewwin is redirected to
    534      * the new window.
    535      */
    536     vw = owl_global_get_viewwin(g);
    537     owl_popwin_close(pw);
    538     owl_popwin_up(pw);
    539     owl_viewwin_set_curswin(vw, owl_popwin_get_curswin(pw),
    540         owl_popwin_get_lines(pw), owl_popwin_get_cols(pw));
    541     owl_viewwin_redisplay(vw);
    542   }
    543 
    544   /* refresh stuff */
    545   g->needrefresh=1;
    546   owl_mainwin_redisplay(&(g->mw));
    547   sepbar(NULL);
    548   if (g->tw)
    549       owl_editwin_redisplay(g->tw);
    550   else
    551     werase(owl_global_get_curs_typwin(g));
    552 
    553   owl_function_full_redisplay();
    554 
    555   owl_function_makemsg("");
    556476}
    557477
     
    623543
    624544void owl_global_set_curmsg_vert_offset(owl_global *g, int i) {
    625   g->curmsg_vert_offset=i;
     545  g->curmsg_vert_offset = i;
    626546}
    627547
Note: See TracChangeset for help on using the changeset viewer.