source: mainwin.c @ 074bdaa

release-1.10release-1.8release-1.9
Last change on this file since 074bdaa was 099597c, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Don't reset colorpairs in the middle of drawing Resetting colorpairs while drawing the mainwin causes the existing contents in a popwin to refer to invalid color pairs. We used to draw the mainwin first and redraw the contents of each window from scratch. Moving to libpanel in 1.6 changed this, so background colors occasionally bled into your popwin. This changes the colorpair logic to only trigger when we need to, and to forcibly dirty every window if needed. NOTE: if we don't have enough color-pairs to draw the current screen, this will draw everything twice. But it will probably almost never happen. Reported-by: Alex Dehnert <adehnert@mit.edu> Reviewed-by: Alejandro R. Sedeño <asedeno@mit.edu>
  • Property mode set to 100644
File size: 5.2 KB
Line 
1#include "owl.h"
2
3static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data);
4static void owl_mainwin_resized(owl_window *w, void *user_data);
5
6void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
7{
8  mw->curtruncated=0;
9  mw->lastdisplayed=-1;
10  mw->window = g_object_ref(window);
11  /* for now, just assume this object lasts forever */
12  g_signal_connect(window, "redraw", G_CALLBACK(owl_mainwin_redraw), mw);
13  g_signal_connect(window, "resized", G_CALLBACK(owl_mainwin_resized), mw);
14  owl_window_dirty(window);
15
16  /* For now, we do not bother with connecting up dependencies; that'll be a
17   * future refactor of the mainwin */
18}
19
20static void owl_mainwin_resized(owl_window *w, void *user_data)
21{
22  owl_mainwin *mw = user_data;
23
24  /* in case any styles rely on the current width */
25  owl_messagelist_invalidate_formats(owl_global_get_msglist(&g));
26
27  /* recalculate the topmsg to make sure the current message is on
28   * screen */
29  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
30
31  /* Schedule a redraw */
32  owl_window_dirty(mw->window);
33}
34
35void owl_mainwin_redisplay(owl_mainwin *mw)
36{
37  owl_window_dirty(mw->window);
38}
39
40static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
41{
42  owl_message *m;
43  int i, lines, isfull, viewsize;
44  int x, y, savey, recwinlines, start;
45  int topmsg, curmsg, markedmsgid, fgcolor, bgcolor;
46  const owl_view *v;
47  GList *fl;
48  const owl_filter *f;
49  owl_mainwin *mw = user_data;
50
51  topmsg = owl_global_get_topmsg(&g);
52  curmsg = owl_global_get_curmsg(&g);
53  markedmsgid = owl_global_get_markedmsgid(&g);
54  v = owl_global_get_current_view(&g);
55
56  if (v==NULL) {
57    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
58    return;
59  }
60
61  werase(recwin);
62
63  recwinlines=owl_global_get_recwin_lines(&g);
64  viewsize=owl_view_get_size(v);
65
66  /* if there are no messages or if topmsg is past the end of the messages,
67   * just draw a blank screen */
68  if (viewsize==0 || topmsg>=viewsize) {
69    if (viewsize==0) {
70      owl_global_set_topmsg(&g, 0);
71    }
72    mw->curtruncated=0;
73    mw->lastdisplayed=-1;
74    return;
75  }
76
77  /* write the messages out */
78  isfull=0;
79  mw->curtruncated=0;
80  mw->lasttruncated=0;
81
82  for (i=topmsg; i<viewsize; i++) {
83    if (isfull) break;
84    m=owl_view_get_element(v, i);
85
86    /* hold on to y in case this is the current message or deleted */
87    getyx(recwin, y, x);
88    savey=y;
89
90    /* if it's the current message, account for a vert_offset */
91    if (i==owl_global_get_curmsg(&g)) {
92      start=owl_global_get_curmsg_vert_offset(&g);
93      lines=owl_message_get_numlines(m)-start;
94    } else {
95      start=0;
96      lines=owl_message_get_numlines(m);
97    }
98
99    /* if we match filters set the color */
100    fgcolor=OWL_COLOR_DEFAULT;
101    bgcolor=OWL_COLOR_DEFAULT;
102    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
103      f = fl->data;
104      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
105          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
106        if (owl_filter_message_match(f, m)) {
107          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
108          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
109        }
110      }
111    }
112
113    /* if we'll fill the screen print a partial message */
114    if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
115    if (y+lines > recwinlines) mw->lasttruncated=1;
116    if (y+lines > recwinlines-1) {
117      isfull=1;
118      owl_message_curs_waddstr(m, recwin,
119                               start,
120                               start+recwinlines-y,
121                               owl_global_get_rightshift(&g),
122                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
123                               fgcolor, bgcolor);
124    } else {
125      /* otherwise print the whole thing */
126      owl_message_curs_waddstr(m, recwin,
127                               start,
128                               start+lines,
129                               owl_global_get_rightshift(&g),
130                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
131                               fgcolor, bgcolor);
132    }
133
134
135    /* is it the current message and/or deleted? */
136    getyx(recwin, y, x);
137    wattrset(recwin, A_NORMAL);
138    if (owl_global_get_rightshift(&g)==0) {   /* this lame and should be fixed */
139      if (m==owl_view_get_element(v, curmsg)) {
140        wmove(recwin, savey, 0);
141        wattron(recwin, A_BOLD);       
142        if (owl_global_get_curmsg_vert_offset(&g)>0) {
143          waddstr(recwin, "+");
144        } else {
145          waddstr(recwin, "-");
146        }
147        if (owl_message_is_delete(m)) {
148          waddstr(recwin, "D");
149        } else if (markedmsgid == owl_message_get_id(m)) {
150          waddstr(recwin, "*");
151        } else {
152          waddstr(recwin, ">");
153        }
154        wmove(recwin, y, x);
155        wattroff(recwin, A_BOLD);
156      } else if (owl_message_is_delete(m)) {
157        wmove(recwin, savey, 0);
158        waddstr(recwin, " D");
159        wmove(recwin, y, x);
160      } else if (markedmsgid == owl_message_get_id(m)) {
161        wmove(recwin, savey, 0);
162        waddstr(recwin, " *");
163        wmove(recwin, y, x);
164      }
165    }
166    wattroff(recwin, A_BOLD);
167  }
168  mw->lastdisplayed=i-1;
169}
170
171
172int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
173{
174  if (mw->curtruncated) return(1);
175  return(0);
176}
177
178int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
179{
180  if (mw->lasttruncated) return(1);
181  return(0);
182}
183
184int owl_mainwin_get_last_msg(const owl_mainwin *mw)
185{
186  /* return the number of the last message displayed. -1 if none */
187  return(mw->lastdisplayed);
188}
Note: See TracBrowser for help on using the repository browser.