diff options
Diffstat (limited to 'testing/toxic/main.c')
-rw-r--r-- | testing/toxic/main.c | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index c8cf73ed..892f812a 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -23,7 +23,7 @@ extern int add_req(uint8_t* public_key); // XXX | |||
23 | char WINDOW_STATUS[MAX_WINDOW_SLOTS]; // Holds status of chat windows | 23 | char WINDOW_STATUS[MAX_WINDOW_SLOTS]; // Holds status of chat windows |
24 | static ToxWindow windows[MAX_WINDOW_SLOTS]; | 24 | static ToxWindow windows[MAX_WINDOW_SLOTS]; |
25 | int w_num; | 25 | int w_num; |
26 | static int w_active; | 26 | int w_active; |
27 | static ToxWindow* prompt; | 27 | static ToxWindow* prompt; |
28 | 28 | ||
29 | // CALLBACKS START | 29 | // CALLBACKS START |
@@ -40,7 +40,7 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) { | |||
40 | 40 | ||
41 | wprintw(prompt->window, "Use \"accept %d\" to accept it.\n", n); | 41 | wprintw(prompt->window, "Use \"accept %d\" to accept it.\n", n); |
42 | 42 | ||
43 | for(i=0; i<w_num; i++) { | 43 | for(i=0; i<MAX_WINDOW_SLOTS; i++) { |
44 | if(windows[i].onFriendRequest != NULL) | 44 | if(windows[i].onFriendRequest != NULL) |
45 | windows[i].onFriendRequest(&windows[i], public_key, data, length); | 45 | windows[i].onFriendRequest(&windows[i], public_key, data, length); |
46 | } | 46 | } |
@@ -51,7 +51,7 @@ void on_message(int friendnumber, uint8_t* string, uint16_t length) { | |||
51 | 51 | ||
52 | wprintw(prompt->window, "\n(message) %d: %s\n", friendnumber, string); | 52 | wprintw(prompt->window, "\n(message) %d: %s\n", friendnumber, string); |
53 | 53 | ||
54 | for(i=0; i<w_num; i++) { | 54 | for(i=0; i<MAX_WINDOW_SLOTS; i++) { |
55 | if(windows[i].onMessage != NULL) | 55 | if(windows[i].onMessage != NULL) |
56 | windows[i].onMessage(&windows[i], friendnumber, string, length); | 56 | windows[i].onMessage(&windows[i], friendnumber, string, length); |
57 | } | 57 | } |
@@ -62,7 +62,7 @@ void on_nickchange(int friendnumber, uint8_t* string, uint16_t length) { | |||
62 | 62 | ||
63 | wprintw(prompt->window, "\n(nickchange) %d: %s!\n", friendnumber, string); | 63 | wprintw(prompt->window, "\n(nickchange) %d: %s!\n", friendnumber, string); |
64 | 64 | ||
65 | for(i=0; i<w_num; i++) { | 65 | for(i=0; i<MAX_WINDOW_SLOTS; i++) { |
66 | if(windows[i].onNickChange != NULL) | 66 | if(windows[i].onNickChange != NULL) |
67 | windows[i].onNickChange(&windows[i], friendnumber, string, length); | 67 | windows[i].onNickChange(&windows[i], friendnumber, string, length); |
68 | } | 68 | } |
@@ -73,7 +73,7 @@ void on_statuschange(int friendnumber, uint8_t* string, uint16_t length) { | |||
73 | 73 | ||
74 | wprintw(prompt->window, "\n(statuschange) %d: %s!\n", friendnumber, string); | 74 | wprintw(prompt->window, "\n(statuschange) %d: %s!\n", friendnumber, string); |
75 | 75 | ||
76 | for(i=0; i<w_num; i++) { | 76 | for(i=0; i<MAX_WINDOW_SLOTS; i++) { |
77 | if(windows[i].onStatusChange != NULL) | 77 | if(windows[i].onStatusChange != NULL) |
78 | windows[i].onStatusChange(&windows[i], friendnumber, string, length); | 78 | windows[i].onStatusChange(&windows[i], friendnumber, string, length); |
79 | } | 79 | } |
@@ -115,31 +115,31 @@ static void init_tox() { | |||
115 | } | 115 | } |
116 | 116 | ||
117 | void init_window_status() { | 117 | void init_window_status() { |
118 | /* Default window values decrement from -2 */ | ||
118 | int i; | 119 | int i; |
119 | for (i = 0; i < N_DEFAULT_WINS; i++) | 120 | for (i = 0; i < N_DEFAULT_WINS; i++) |
120 | WINDOW_STATUS[i] = i; | 121 | WINDOW_STATUS[i] = -(i+2); |
121 | 122 | ||
122 | int j; | 123 | int j; |
123 | for (j = N_DEFAULT_WINS; j < MAX_WINDOW_SLOTS; j++) | 124 | for (j = N_DEFAULT_WINS; j < MAX_WINDOW_SLOTS; j++) |
124 | WINDOW_STATUS[j] = -1; | 125 | WINDOW_STATUS[j] = -1; |
125 | } | 126 | } |
126 | 127 | ||
127 | int add_window(ToxWindow w) { | 128 | int add_window(ToxWindow w, int n) { |
128 | if(w_num == TOXWINDOWS_MAX_NUM) | 129 | if(w_num >= TOXWINDOWS_MAX_NUM) |
129 | return -1; | 130 | return -1; |
130 | 131 | ||
131 | if(LINES < 2) | 132 | if(LINES < 2) |
132 | return -1; | 133 | return -1; |
133 | 134 | ||
134 | w.window = newwin(LINES - 2, COLS, 0, 0); | 135 | w.window = newwin(LINES - 2, COLS, 0, 0); |
135 | |||
136 | if(w.window == NULL) | 136 | if(w.window == NULL) |
137 | return -1; | 137 | return -1; |
138 | 138 | ||
139 | windows[w_num++] = w; | 139 | windows[n] = w; |
140 | w.onInit(&w); | 140 | w.onInit(&w); |
141 | 141 | w_num++; | |
142 | return w_num - 1; | 142 | return n; |
143 | } | 143 | } |
144 | 144 | ||
145 | /* Deletes window w and cleans up */ | 145 | /* Deletes window w and cleans up */ |
@@ -157,24 +157,17 @@ void del_window(ToxWindow *w, int f_num) { | |||
157 | refresh(); | 157 | refresh(); |
158 | } | 158 | } |
159 | 159 | ||
160 | int focus_window(int num) { | ||
161 | if(num >= w_num || num < 0) | ||
162 | return -1; | ||
163 | |||
164 | w_active = num; | ||
165 | return 0; | ||
166 | } | ||
167 | |||
168 | static void init_windows() { | 160 | static void init_windows() { |
169 | w_num = 0; | 161 | w_num = 0; |
170 | 162 | int n_prompt = 0; | |
171 | if(add_window(new_prompt()) == -1 || add_window(new_friendlist()) == -1) { | 163 | int n_friendslist = 1; |
164 | if(add_window(new_prompt(), n_prompt) == -1 | ||
165 | || add_window(new_friendlist(), n_friendslist) == -1) { | ||
172 | fprintf(stderr, "add_window() failed.\n"); | 166 | fprintf(stderr, "add_window() failed.\n"); |
173 | |||
174 | endwin(); | 167 | endwin(); |
175 | exit(1); | 168 | exit(1); |
176 | } | 169 | } |
177 | prompt = &windows[0]; | 170 | prompt = &windows[n_prompt]; |
178 | } | 171 | } |
179 | 172 | ||
180 | static void do_tox() { | 173 | static void do_tox() { |