diff options
Diffstat (limited to 'testing/toxic/windows.c')
-rw-r--r-- | testing/toxic/windows.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/testing/toxic/windows.c b/testing/toxic/windows.c index c0ff3026..8fdf4e19 100644 --- a/testing/toxic/windows.c +++ b/testing/toxic/windows.c | |||
@@ -88,23 +88,25 @@ int add_window(Messenger *m, ToxWindow w) | |||
88 | { | 88 | { |
89 | if (LINES < 2) | 89 | if (LINES < 2) |
90 | return -1; | 90 | return -1; |
91 | 91 | ||
92 | int i; | 92 | int i; |
93 | for(i = 0; i < MAX_WINDOWS_NUM; i++) { | 93 | |
94 | if (windows[i].window) | 94 | for (i = 0; i < MAX_WINDOWS_NUM; i++) { |
95 | if (windows[i].window) | ||
95 | continue; | 96 | continue; |
96 | 97 | ||
97 | w.window = newwin(LINES - 2, COLS, 0, 0); | 98 | w.window = newwin(LINES - 2, COLS, 0, 0); |
99 | |||
98 | if (w.window == NULL) | 100 | if (w.window == NULL) |
99 | return -1; | 101 | return -1; |
100 | 102 | ||
101 | windows[i] = w; | 103 | windows[i] = w; |
102 | w.onInit(&w, m); | 104 | w.onInit(&w, m); |
103 | 105 | ||
104 | active_window = windows+i; | 106 | active_window = windows + i; |
105 | return i; | 107 | return i; |
106 | } | 108 | } |
107 | 109 | ||
108 | return -1; | 110 | return -1; |
109 | } | 111 | } |
110 | 112 | ||
@@ -113,8 +115,10 @@ void del_window(ToxWindow *w) | |||
113 | { | 115 | { |
114 | active_window = windows; // Go to prompt screen | 116 | active_window = windows; // Go to prompt screen |
115 | delwin(w->window); | 117 | delwin(w->window); |
118 | |||
116 | if (w->x) | 119 | if (w->x) |
117 | free(w->x); | 120 | free(w->x); |
121 | |||
118 | w->window = NULL; | 122 | w->window = NULL; |
119 | memset(w, 0, sizeof(ToxWindow)); | 123 | memset(w, 0, sizeof(ToxWindow)); |
120 | clear(); | 124 | clear(); |
@@ -124,19 +128,19 @@ void del_window(ToxWindow *w) | |||
124 | /* Shows next window when tab or back-tab is pressed */ | 128 | /* Shows next window when tab or back-tab is pressed */ |
125 | void set_next_window(int ch) | 129 | void set_next_window(int ch) |
126 | { | 130 | { |
127 | ToxWindow *end = windows+MAX_WINDOWS_NUM-1; | 131 | ToxWindow *end = windows + MAX_WINDOWS_NUM - 1; |
128 | ToxWindow *inf = active_window; | 132 | ToxWindow *inf = active_window; |
129 | while(true) { | 133 | |
134 | while (true) { | ||
130 | if (ch == '\t') { | 135 | if (ch == '\t') { |
131 | if (++active_window > end) | 136 | if (++active_window > end) |
132 | active_window = windows; | 137 | active_window = windows; |
133 | } else | 138 | } else if (--active_window < windows) |
134 | if (--active_window < windows) | 139 | active_window = end; |
135 | active_window = end; | 140 | |
136 | |||
137 | if (active_window->window) | 141 | if (active_window->window) |
138 | return; | 142 | return; |
139 | 143 | ||
140 | if (active_window == inf) { // infinite loop check | 144 | if (active_window == inf) { // infinite loop check |
141 | endwin(); | 145 | endwin(); |
142 | exit(2); | 146 | exit(2); |
@@ -148,14 +152,14 @@ void set_active_window(int index) | |||
148 | { | 152 | { |
149 | if (index < 0 || index >= MAX_WINDOWS_NUM) | 153 | if (index < 0 || index >= MAX_WINDOWS_NUM) |
150 | return; | 154 | return; |
151 | 155 | ||
152 | active_window = windows+index; | 156 | active_window = windows + index; |
153 | } | 157 | } |
154 | 158 | ||
155 | ToxWindow *init_windows() | 159 | ToxWindow *init_windows() |
156 | { | 160 | { |
157 | int n_prompt = add_window(m, new_prompt()); | 161 | int n_prompt = add_window(m, new_prompt()); |
158 | 162 | ||
159 | if (n_prompt == -1 | 163 | if (n_prompt == -1 |
160 | || add_window(m, new_friendlist()) == -1 | 164 | || add_window(m, new_friendlist()) == -1 |
161 | || add_window(m, new_dhtstatus()) == -1) { | 165 | || add_window(m, new_dhtstatus()) == -1) { |
@@ -166,7 +170,7 @@ ToxWindow *init_windows() | |||
166 | 170 | ||
167 | prompt = &windows[n_prompt]; | 171 | prompt = &windows[n_prompt]; |
168 | active_window = prompt; | 172 | active_window = prompt; |
169 | 173 | ||
170 | return prompt; | 174 | return prompt; |
171 | } | 175 | } |
172 | 176 | ||
@@ -189,7 +193,7 @@ static void draw_bar() | |||
189 | 193 | ||
190 | for (i = 0; i < (MAX_WINDOWS_NUM); ++i) { | 194 | for (i = 0; i < (MAX_WINDOWS_NUM); ++i) { |
191 | if (windows[i].window) { | 195 | if (windows[i].window) { |
192 | if (windows+i == active_window) | 196 | if (windows + i == active_window) |
193 | attron(A_BOLD); | 197 | attron(A_BOLD); |
194 | 198 | ||
195 | odd = (odd + 1) % blinkrate; | 199 | odd = (odd + 1) % blinkrate; |
@@ -197,13 +201,13 @@ static void draw_bar() | |||
197 | if (windows[i].blink && (odd < (blinkrate / 2))) | 201 | if (windows[i].blink && (odd < (blinkrate / 2))) |
198 | attron(COLOR_PAIR(3)); | 202 | attron(COLOR_PAIR(3)); |
199 | 203 | ||
200 | clrtoeol(); | 204 | clrtoeol(); |
201 | printw(" %s", windows[i].title); | 205 | printw(" %s", windows[i].title); |
202 | 206 | ||
203 | if (windows[i].blink && (odd < (blinkrate / 2))) | 207 | if (windows[i].blink && (odd < (blinkrate / 2))) |
204 | attroff(COLOR_PAIR(3)); | 208 | attroff(COLOR_PAIR(3)); |
205 | 209 | ||
206 | if (windows+i == active_window) { | 210 | if (windows + i == active_window) { |
207 | attroff(A_BOLD); | 211 | attroff(A_BOLD); |
208 | } | 212 | } |
209 | } | 213 | } |
@@ -225,7 +229,7 @@ void draw_active_window(Messenger *m) | |||
225 | prepare_window(a->window); | 229 | prepare_window(a->window); |
226 | a->blink = false; | 230 | a->blink = false; |
227 | draw_bar(); | 231 | draw_bar(); |
228 | a->onDraw(a); | 232 | a->onDraw(a, m); |
229 | 233 | ||
230 | /* Handle input */ | 234 | /* Handle input */ |
231 | int ch = getch(); | 235 | int ch = getch(); |