aboutsummaryrefslogtreecommitdiff
path: root/src/chat.c
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-08-03 23:47:05 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-08-03 23:47:05 +0200
commitc1344f9692273f2e1bd5688adfb39bda33394a0b (patch)
tree5b98c1e38a9d0793d9c016cfa7fd9e36e5c3295b /src/chat.c
parent0616015bc457d387dbaa86cd428f119d51511341 (diff)
downloadmessenger-cli-c1344f9692273f2e1bd5688adfb39bda33394a0b.tar.gz
messenger-cli-c1344f9692273f2e1bd5688adfb39bda33394a0b.zip
Implemented dynamic layout with subwindows
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat (limited to 'src/chat.c')
-rw-r--r--src/chat.c200
1 files changed, 184 insertions, 16 deletions
diff --git a/src/chat.c b/src/chat.c
index fac192e..b7ed4fa 100644
--- a/src/chat.c
+++ b/src/chat.c
@@ -25,32 +25,26 @@
25#include "chat.h" 25#include "chat.h"
26 26
27#include "application.h" 27#include "application.h"
28#include "util.h"
28 29
29static void 30static void
30_chat_refresh(MESSENGER_Application *app) 31_chat_refresh(MESSENGER_Application *app)
31{ 32{
32 const struct GNUNET_CHAT_Account *account = GNUNET_CHAT_get_connected(
33 app->chat.handle
34 );
35
36 application_clear(app); 33 application_clear(app);
37 34 chat_update_layout(&(app->chat), app);
38 if (!account)
39 app->accounts.window = app->window;
40 else if (app->chat.context)
41 {
42 if (app->chat.show_members)
43 app->current.members.window = app->window;
44 else
45 app->current.messages.window = app->window;
46 }
47 else
48 app->chats.window = app->window;
49 35
50 accounts_print(&(app->accounts), app); 36 accounts_print(&(app->accounts), app);
51 chats_print(&(app->chats), app); 37 chats_print(&(app->chats), app);
52 members_print(&(app->current.members)); 38 members_print(&(app->current.members));
53 messages_print(&(app->current.messages)); 39 messages_print(&(app->current.messages));
40
41 if (!app->ui.logo)
42 return;
43
44 werase(app->ui.logo);
45 wmove(app->ui.logo, 0, 0);
46
47 util_print_logo(app->ui.logo);
54} 48}
55 49
56static bool 50static bool
@@ -160,6 +154,180 @@ chat_stop(MESSENGER_Chat *chat)
160} 154}
161 155
162void 156void
157_chat_update_layout_accounts(struct MESSENGER_Application *app)
158{
159 int rows, cols;
160 getmaxyx(app->window, rows, cols);
161
162 if (rows >= UTIL_LOGO_ROWS + UI_ACCOUNTS_ROWS_MIN)
163 {
164 const int offset = UTIL_LOGO_ROWS + 1;
165
166 app->ui.logo = subwin(app->window, UTIL_LOGO_ROWS, cols, 0, 0);
167 app->ui.main = subwin(app->window, rows - offset, cols, offset, 0);
168
169 wmove(app->window, UTIL_LOGO_ROWS, 0);
170 whline(app->window, ACS_HLINE, cols);
171 }
172 else
173 app->ui.main = subwin(app->window, rows, cols, 0, 0);
174
175 app->accounts.window = app->ui.main;
176}
177
178void
179_chat_update_layout_chats(struct MESSENGER_Application *app)
180{
181 int rows, cols;
182 getmaxyx(app->window, rows, cols);
183
184 int min_rows = UI_CHATS_ROWS_MIN;
185 int offset_x = 0;
186 int offset_y = 0;
187
188 if (cols >= UI_ACCOUNTS_COLS_MIN + UI_CHATS_COLS_MIN)
189 {
190 offset_x = UI_ACCOUNTS_COLS_MIN + 1;
191
192 if (UI_ACCOUNTS_ROWS_MIN > min_rows) min_rows = UI_ACCOUNTS_ROWS_MIN;
193 }
194
195 if (rows >= UTIL_LOGO_ROWS + min_rows)
196 {
197 offset_y = UTIL_LOGO_ROWS + 1;
198
199 app->ui.logo = subwin(app->window, UTIL_LOGO_ROWS, cols, 0, 0);
200
201 wmove(app->window, UTIL_LOGO_ROWS, 0);
202 whline(app->window, ACS_HLINE, cols);
203 }
204
205 if (offset_x > 0)
206 {
207 app->ui.left = subwin(
208 app->window,
209 rows - offset_y,
210 UI_ACCOUNTS_COLS_MIN,
211 offset_y,
212 0
213 );
214
215 wmove(app->window, offset_y > 0? offset_y : 0, UI_ACCOUNTS_COLS_MIN);
216 wvline(app->window, ACS_VLINE, rows - offset_y);
217
218 if (offset_y > 0)
219 {
220 wmove(app->window, offset_y - 1, UI_ACCOUNTS_COLS_MIN);
221 waddch(app->window, ACS_TTEE);
222 }
223 }
224
225 app->ui.main = subwin(
226 app->window,
227 rows - offset_y,
228 cols - offset_x,
229 offset_y,
230 offset_x
231 );
232
233 app->accounts.window = app->ui.left;
234 app->chats.window = app->ui.main;
235}
236
237void
238_chat_update_layout_messages(struct MESSENGER_Application *app)
239{
240 int rows, cols;
241 getmaxyx(app->window, rows, cols);
242
243 const int cols_min_left = (UTIL_LOGO_COLS > UI_CHATS_COLS_MIN?
244 UTIL_LOGO_COLS : UI_CHATS_COLS_MIN
245 );
246
247 int offset_x = 0;
248
249 if (cols >= cols_min_left + UI_MESSAGES_COLS_MIN)
250 offset_x = cols_min_left + 1;
251 else
252 goto skip_left_split;
253
254 if (rows >= UTIL_LOGO_ROWS + UI_CHATS_ROWS_MIN)
255 {
256 const int offset = UTIL_LOGO_ROWS + 1;
257
258 app->ui.logo = subwin(app->window, UTIL_LOGO_ROWS, cols_min_left, 0, 0);
259 app->ui.left = subwin(app->window, rows - offset, cols_min_left, offset, 0);
260
261 wmove(app->window, UTIL_LOGO_ROWS, 0);
262 whline(app->window, ACS_HLINE, cols_min_left);
263 }
264 else
265 app->ui.left = subwin(app->window, rows, cols_min_left, 0, 0);
266
267 int cut_x = 0;
268
269 if (cols >= cols_min_left + UI_MESSAGES_COLS_MIN + UI_MEMBERS_COLS_MIN)
270 {
271 cut_x = UI_MEMBERS_COLS_MIN + 1;
272
273 app->ui.right = subwin(
274 app->window,
275 rows,
276 UI_MEMBERS_COLS_MIN,
277 0,
278 cols - UI_MEMBERS_COLS_MIN
279 );
280
281 wmove(app->window, 0, cols - cut_x);
282 wvline(app->window, ACS_VLINE, rows);
283 }
284
285 wmove(app->window, 0, cols_min_left);
286 wvline(app->window, ACS_VLINE, rows);
287
288skip_left_split:
289 app->ui.main = subwin(
290 app->window,
291 rows,
292 cols - offset_x - cut_x,
293 0,
294 offset_x
295 );
296
297 app->chats.window = app->ui.left;
298
299 if (app->ui.right)
300 {
301 app->current.members.window = app->ui.right;
302 app->current.messages.window = app->ui.main;
303 return;
304 }
305
306 if (app->chat.show_members)
307 app->current.members.window = app->ui.main;
308 else
309 app->current.messages.window = app->ui.main;
310}
311
312void
313chat_update_layout(MESSENGER_Chat *chat,
314 struct MESSENGER_Application *app)
315{
316 const struct GNUNET_CHAT_Account *account = GNUNET_CHAT_get_connected(
317 chat->handle
318 );
319
320 application_refresh(app);
321
322 if (!account)
323 _chat_update_layout_accounts(app);
324 else if (app->chat.context)
325 _chat_update_layout_messages(app);
326 else
327 _chat_update_layout_chats(app);
328}
329
330void
163chat_process_message(UNUSED MESSENGER_Chat *chat, 331chat_process_message(UNUSED MESSENGER_Chat *chat,
164 struct GNUNET_CHAT_Context *context, 332 struct GNUNET_CHAT_Context *context,
165 const struct GNUNET_CHAT_Message *message) 333 const struct GNUNET_CHAT_Message *message)