about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--input_win.c1
-rw-r--r--status_bar.c40
-rw-r--r--title_bar.c17
-rw-r--r--windows.c59
4 files changed, 102 insertions, 15 deletions
diff --git a/input_win.c b/input_win.c
index 0caa8264..1a895ebd 100644
--- a/input_win.c
+++ b/input_win.c
@@ -63,7 +63,6 @@ void inp_clear(void)
 {
     wclear(inp_win);
     wmove(inp_win, 0, 1);
-    touchwin(inp_win);
     wrefresh(inp_win);
 }
 
diff --git a/status_bar.c b/status_bar.c
index 34de6696..56cae9ce 100644
--- a/status_bar.c
+++ b/status_bar.c
@@ -20,6 +20,8 @@
  *
  */
 
+#include <string.h>
+
 #include <ncurses.h>
 #include "windows.h"
 #include "util.h"
@@ -27,6 +29,9 @@
 static WINDOW *status_bar;
 static char _active[29] = "[ ][ ][ ][ ][ ][ ][ ][ ][  ]";
 
+static int dirty;
+static char curr_time[80];
+
 static void _status_bar_update_time(void);
 
 void create_status_bar(void)
@@ -39,15 +44,27 @@ void create_status_bar(void)
     wattron(status_bar, COLOR_PAIR(4));
     mvwprintw(status_bar, 0, cols - 29, _active);
     wattroff(status_bar, COLOR_PAIR(4));
-    wrefresh(status_bar);
+
+    get_time(curr_time);
+    dirty = TRUE;
 }
 
 void status_bar_refresh(void)
 {
-    _status_bar_update_time();
-    touchwin(status_bar);
-    wrefresh(status_bar);
-    inp_put_back();
+    char new_time[80];
+    get_time(new_time);
+
+    if (strcmp(new_time, curr_time) != 0) {
+        dirty = TRUE;
+        strcpy(curr_time, new_time);
+    }
+
+    if (dirty) {
+        _status_bar_update_time();
+        wrefresh(status_bar);
+        inp_put_back();
+        dirty = FALSE;
+    }
 }
 
 void status_bar_inactive(int win)
@@ -60,6 +77,8 @@ void status_bar_inactive(int win)
     mvwaddch(status_bar, 0, cols - 29 + active_pos, ' ');
     if (win == 9)
         mvwaddch(status_bar, 0, cols - 29 + active_pos + 1, ' ');
+
+    dirty = TRUE;
 }
 
 void status_bar_active(int win)
@@ -73,16 +92,22 @@ void status_bar_active(int win)
         mvwprintw(status_bar, 0, cols - 29 + active_pos, "%d", win+1);
     else
         mvwprintw(status_bar, 0, cols - 29 + active_pos, "10");
+
+    dirty = TRUE;
 }
 
 void status_bar_get_password(void)
 {
     mvwprintw(status_bar, 0, 9, "Enter password:");
+
+    dirty = TRUE;
 }
 
 void status_bar_print_message(const char *msg)
 {
     mvwprintw(status_bar, 0, 9, msg);
+
+    dirty = TRUE;
 }
 
 void status_bar_clear(void)
@@ -94,6 +119,8 @@ void status_bar_clear(void)
     wattron(status_bar, COLOR_PAIR(4));
     mvwprintw(status_bar, 0, cols - 29, _active);
     wattroff(status_bar, COLOR_PAIR(4));
+
+    dirty = TRUE;
 }
 
 static void _status_bar_update_time(void)
@@ -110,6 +137,7 @@ static void _status_bar_update_time(void)
     wattron(status_bar, COLOR_PAIR(4));
     mvwaddch(status_bar, 0, 7, ']');
     wattroff(status_bar, COLOR_PAIR(4));
-    
+
+    dirty = TRUE;
 }
 
diff --git a/title_bar.c b/title_bar.c
index fb70e858..17e2df2a 100644
--- a/title_bar.c
+++ b/title_bar.c
@@ -24,6 +24,7 @@
 #include "windows.h"
 
 static WINDOW *title_bar;
+static int dirty;
 
 void create_title_bar(void)
 {
@@ -34,12 +35,14 @@ void create_title_bar(void)
     wbkgd(title_bar, COLOR_PAIR(3));
     title_bar_title();
     title_bar_disconnected();
+    dirty = TRUE;
 }
 
 void title_bar_title()
 {
     char *title = "Profanity. Type /help for help information.";
     title_bar_show(title);
+    dirty = TRUE;
 }
 
 void title_bar_connected(void)
@@ -56,6 +59,8 @@ void title_bar_connected(void)
     wattron(title_bar, COLOR_PAIR(4));
     mvwaddch(title_bar, 0, cols - 2, ']');
     wattroff(title_bar, COLOR_PAIR(4));
+    
+    dirty = TRUE;
 }
 
 void title_bar_disconnected(void)
@@ -72,13 +77,17 @@ void title_bar_disconnected(void)
     wattron(title_bar, COLOR_PAIR(4));
     mvwaddch(title_bar, 0, cols - 2, ']');
     wattroff(title_bar, COLOR_PAIR(4));
+    
+    dirty = TRUE;
 }
 
 void title_bar_refresh(void)
 {
-    touchwin(title_bar);
-    wrefresh(title_bar);
-    inp_put_back();
+    if (dirty) {
+        wrefresh(title_bar);
+        inp_put_back();
+        dirty = FALSE;
+    }
 }
 
 void title_bar_show(char *title)
@@ -88,5 +97,7 @@ void title_bar_show(char *title)
     for (i = 0; i < 45; i++)
         waddch(title_bar, ' ');
     mvwprintw(title_bar, 0, 0, " %s", title);
+    
+    dirty = TRUE;
 }
 
diff --git a/windows.c b/windows.c
index 8b001032..82d7035a 100644
--- a/windows.c
+++ b/windows.c
@@ -39,6 +39,9 @@ static int _curr_prof_win = 0;
 // shortcut pointer to console window
 static WINDOW * _cons_win = NULL;
 
+// current window state
+static int dirty;
+
 static void _create_windows(void);
 static int _find_prof_win_index(char *contact);
 static int _new_prof_win(char *contact);
@@ -74,13 +77,20 @@ void gui_init(void)
     create_status_bar();
     create_input_window();
     _create_windows();
+
+    dirty = TRUE;
 }
 
 void gui_refresh(void)
 {
     title_bar_refresh();
     status_bar_refresh();
-    _current_window_refresh();
+
+    if (dirty) {
+        _current_window_refresh();
+        dirty = FALSE;
+    }
+
     inp_put_back();
 }
 
@@ -102,6 +112,8 @@ int win_close_win(void)
         // go back to console window
         _curr_prof_win = 0;
         title_bar_title();
+
+        dirty = TRUE;
     
         // success
         return 1;
@@ -141,6 +153,9 @@ void win_show_incomming_msg(char *from, char *message)
     _win_show_message(win, message);
 
     status_bar_active(win_index);
+
+    if (win_index == _curr_prof_win)
+        dirty = TRUE;
 }
 
 void win_show_outgoing_msg(char *from, char *to, char *message)
@@ -155,6 +170,9 @@ void win_show_outgoing_msg(char *from, char *to, char *message)
     _win_show_message(win, message);
     
     status_bar_active(win_index);
+    
+    if (win_index == _curr_prof_win)
+        dirty = TRUE;
 }
 
 void win_contact_online(char *from, char *show, char *status)
@@ -166,6 +184,9 @@ void win_contact_online(char *from, char *show, char *status)
         WINDOW *win = _wins[win_index].win;
         _show_status_string(win, from, show, status, "++", "online");
     }
+    
+    if (win_index == _curr_prof_win)
+        dirty = TRUE;
 }
 
 void win_contact_offline(char *from, char *show, char *status)
@@ -177,6 +198,9 @@ void win_contact_offline(char *from, char *show, char *status)
         WINDOW *win = _wins[win_index].win;
         _show_status_string(win, from, show, status, "--", "offline");
     }
+    
+    if (win_index == _curr_prof_win)
+        dirty = TRUE;
 }
 
 void cons_help(void)
@@ -197,6 +221,9 @@ void cons_help(void)
     cons_show("    UP, DOWN             : Navigate input history.");
     cons_show("    LEFT, RIGHT          : Edit current input.");
     cons_show("    PAGE UP, PAGE DOWN   : Page the chat window.");
+
+    if (_curr_prof_win == 0)
+        dirty = TRUE;
 }
 
 void cons_bad_show(char *msg)
@@ -205,18 +232,27 @@ void cons_bad_show(char *msg)
     wattron(_cons_win, COLOR_PAIR(6));
     wprintw(_cons_win, "%s\n", msg);
     wattroff(_cons_win, COLOR_PAIR(6));
+    
+    if (_curr_prof_win == 0)
+        dirty = TRUE;
 }
 
 void cons_show(char *msg)
 {
     _win_show_time(_cons_win);
     wprintw(_cons_win, "%s\n", msg); 
+    
+    if (_curr_prof_win == 0)
+        dirty = TRUE;
 }
 
 void cons_bad_command(char *cmd)
 {
     _win_show_time(_cons_win);
     wprintw(_cons_win, "Unknown command: %s\n", cmd);
+    
+    if (_curr_prof_win == 0)
+        dirty = TRUE;
 }
 
 void cons_bad_connect(void)
@@ -278,6 +314,8 @@ void win_page_off(void)
     _wins[_curr_prof_win].y_pos = y - (size - 1);
     if (_wins[_curr_prof_win].y_pos < 0)
         _wins[_curr_prof_win].y_pos = 0;
+
+    dirty = TRUE;
 }
 
 void win_handle_page(int *ch)
@@ -291,17 +329,26 @@ void win_handle_page(int *ch)
             _wins[_curr_prof_win].y_pos = 0;
        
         _wins[_curr_prof_win].paged = 1;
+        dirty = TRUE;
     } else if (*ch == KEY_NPAGE) {
         int rows, cols, y, x;
         getmaxyx(stdscr, rows, cols);
         getyx(_wins[_curr_prof_win].win, y, x);
 
         _wins[_curr_prof_win].y_pos = _wins[_curr_prof_win].y_pos + (rows - 4);
-        if (_wins[_curr_prof_win].y_pos >= y)
-            _wins[_curr_prof_win].y_pos = y - 1;
+
+        // only got half a screen, show full screen
+        if ((y - _wins[_curr_prof_win].y_pos) < (rows - 4))
+            _wins[_curr_prof_win].y_pos = y - (rows - 4);
+
+        // went past end, show full screen
+        else if (_wins[_curr_prof_win].y_pos >= y)
+            _wins[_curr_prof_win].y_pos = y - (rows - 4);
            
         _wins[_curr_prof_win].paged = 1;
+        dirty = TRUE;
     }
+
 }
 
 static void _create_windows(void)
@@ -323,8 +370,9 @@ static void _create_windows(void)
     wattrset(_cons_win, A_BOLD);
     _win_show_time(_cons_win);
     wprintw(_cons_win, "Welcome to Profanity.\n");
-    touchwin(_cons_win);
     prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1);
+
+    dirty = TRUE;
     
     // create the chat windows
     int i;
@@ -377,6 +425,8 @@ static void _win_switch_if_active(int i)
         else
             title_bar_show(_wins[i].from);
     }
+
+    dirty = TRUE;
 }
 
 static void _win_show_time(WINDOW *win)
@@ -408,7 +458,6 @@ static void _current_window_refresh()
     getmaxyx(stdscr, rows, cols);
 
     WINDOW *current = _wins[_curr_prof_win].win;
-    touchwin(current);
     prefresh(current, _wins[_curr_prof_win].y_pos, 0, 1, 0, rows-3, cols-1);
 }
 
kkartik.com> 2018-09-23 20:47:11 -0700 4507' href='/akkartik/mu/commit/subx/examples/ex11.subx?h=hlt&id=7e84fc518f4c7d3eb47ae5ab20f2290904be0391'>7e84fc51 ^
33352536 ^
6070c23e ^
1639687b ^
33352536 ^
1639687b ^
33352536 ^
1639687b ^
33352536 ^
1639687b ^


33352536 ^
6323661c ^
6070c23e ^
1639687b ^
33352536 ^
1639687b ^

33352536 ^
1639687b ^
ee9a9237 ^
33352536 ^




7a583220 ^
33352536 ^

6030d7e2 ^
7e84fc51 ^
9d27e966 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^
1639687b ^
ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^
1639687b ^
ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^
1639687b ^
ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^
1639687b ^
ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
03d50cc8 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^
1639687b ^
ee9a9237 ^
1639687b ^
ee9a9237 ^
33352536 ^

ee9a9237 ^
6030d7e2 ^

33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
6030d7e2 ^
7e84fc51 ^
9d27e966 ^
7e84fc51 ^

71eb22a5 ^
7a583220 ^
33352536 ^

ee9a9237 ^
33352536 ^






6030d7e2 ^
9d27e966 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
9d27e966 ^
6030d7e2 ^
9d27e966 ^
03d50cc8 ^
33352536 ^


ee9a9237 ^
33352536 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
7e84fc51 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
33352536 ^
03d50cc8 ^
ee9a9237 ^
33352536 ^

6030d7e2 ^
33352536 ^

6030d7e2 ^
7e84fc51 ^
71eb22a5 ^
7a583220 ^
33352536 ^

ee9a9237 ^
33352536 ^



6030d7e2 ^
9d27e966 ^
33352536 ^
9d27e966 ^
33352536 ^

9d27e966 ^
33352536 ^

9d27e966 ^
ecfbbfb5 ^
ee9a9237 ^
33352536 ^



9d27e966 ^
33352536 ^

6030d7e2 ^
7e84fc51 ^
ecfbbfb5 ^
e5cbbea4 ^
7e84fc51 ^
6030d7e2 ^
9b16f190 ^
6030d7e2 ^

7e84fc51 ^
03d50cc8 ^

6030d7e2 ^
1639687b ^

6030d7e2 ^
7e84fc51 ^
ee9a9237 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355