about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-10 22:47:53 +0000
committerJames Booth <boothj5@gmail.com>2014-11-10 22:47:53 +0000
commit5d59d17642848ddd8b969cb59b120a65b9d98241 (patch)
tree36347079e6bdd28605202e049252991f8263f1e6 /src/ui
parent04bacdcf385e16f944dccc1f184ea3782e0dd907 (diff)
downloadprofani-tty-5d59d17642848ddd8b969cb59b120a65b9d98241.tar.gz
Refactor subwin sizing and disabled wrapping
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/core.c61
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window.c42
-rw-r--r--src/ui/window.h4
-rw-r--r--src/ui/windows.c24
5 files changed, 94 insertions, 39 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index c7b15f98..7bf1b20d 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -2813,7 +2813,7 @@ _ui_roster(void)
         if (contacts) {
             werase(window->subwin);
             wattron(window->subwin, COLOUR_ROOMINFO);
-            wprintw(window->subwin, " -Roster\n");
+            win_printline_nowrap(window->subwin, " -Roster");
             wattroff(window->subwin, COLOUR_ROOMINFO);
             GSList *curr_contact = contacts;
             while (curr_contact) {
@@ -2824,7 +2824,12 @@ _ui_roster(void)
                     int presence_colour = win_presence_colour(presence);
 
                     wattron(window->subwin, presence_colour);
-                    wprintw(window->subwin, "   %s\n", name);
+
+                    GString *msg = g_string_new("   ");
+                    g_string_append(msg, name);
+                    win_printline_nowrap(window->subwin, msg->str);
+                    g_string_free(msg, TRUE);
+
                     wattroff(window->subwin, presence_colour);
 
                     GList *resources = p_contact_get_available_resources(contact);
@@ -2844,8 +2849,14 @@ _ui_roster(void)
                         const char *resource_presence = string_from_resource_presence(resource->presence);
                         int resource_presence_colour = win_presence_colour(resource_presence);
                         wattron(window->subwin, resource_presence_colour);
-                        wprintw(window->subwin, "     %s\n", resource->name);
+
+                        GString *msg = g_string_new("     ");
+                        g_string_append(msg, resource->name);
+                        win_printline_nowrap(window->subwin, msg->str);
+                        g_string_free(msg, TRUE);
+
                         wattroff(window->subwin, resource_presence_colour);
+
                         ordered_resources = g_list_next(ordered_resources);
                     }
                     g_list_free(ordered_resources);
@@ -2868,72 +2879,84 @@ _ui_muc_roster(const char * const room)
 
             if (prefs_get_boolean(PREF_MUC_PRIVILEGES)) {
                 wattron(window->subwin, COLOUR_ROOMINFO);
-                wprintw(window->subwin, " -Moderators\n");
+                win_printline_nowrap(window->subwin, " -Moderators");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
                 GList *roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     if (occupant->role == MUC_ROLE_MODERATOR) {
-                        wprintw(window->subwin, "   ");
                         const char *presence_str = string_from_resource_presence(occupant->presence);
                         int presence_colour = win_presence_colour(presence_str);
                         wattron(window->subwin, presence_colour);
-                        wprintw(window->subwin, occupant->nick);
+
+                        GString *msg = g_string_new("   ");
+                        g_string_append(msg, occupant->nick);
+                        win_printline_nowrap(window->subwin, msg->str);
+                        g_string_free(msg, TRUE);
+
                         wattroff(window->subwin, presence_colour);
-                        wprintw(window->subwin, "\n");
                     }
                     roster_curr = g_list_next(roster_curr);
                 }
 
                 wattron(window->subwin, COLOUR_ROOMINFO);
-                wprintw(window->subwin, " -Participants\n");
+                win_printline_nowrap(window->subwin, " -Participants");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
                 roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     if (occupant->role == MUC_ROLE_PARTICIPANT) {
-                        wprintw(window->subwin, "   ");
                         const char *presence_str = string_from_resource_presence(occupant->presence);
                         int presence_colour = win_presence_colour(presence_str);
                         wattron(window->subwin, presence_colour);
-                        wprintw(window->subwin, occupant->nick);
+
+                        GString *msg = g_string_new("   ");
+                        g_string_append(msg, occupant->nick);
+                        win_printline_nowrap(window->subwin, msg->str);
+                        g_string_free(msg, TRUE);
+
                         wattroff(window->subwin, presence_colour);
-                        wprintw(window->subwin, "\n");
                     }
                     roster_curr = g_list_next(roster_curr);
                 }
 
                 wattron(window->subwin, COLOUR_ROOMINFO);
-                wprintw(window->subwin, " -Visitors\n");
+                win_printline_nowrap(window->subwin, " -Visitors");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
                 roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
                     if (occupant->role == MUC_ROLE_VISITOR) {
-                        wprintw(window->subwin, "   ");
                         const char *presence_str = string_from_resource_presence(occupant->presence);
                         int presence_colour = win_presence_colour(presence_str);
                         wattron(window->subwin, presence_colour);
-                        wprintw(window->subwin, occupant->nick);
+
+                        GString *msg = g_string_new("   ");
+                        g_string_append(msg, occupant->nick);
+                        win_printline_nowrap(window->subwin, msg->str);
+                        g_string_free(msg, TRUE);
+
                         wattroff(window->subwin, presence_colour);
-                        wprintw(window->subwin, "\n");
                     }
                     roster_curr = g_list_next(roster_curr);
                 }
             } else {
                 wattron(window->subwin, COLOUR_ROOMINFO);
-                wprintw(window->subwin, " -Occupants\n");
+                win_printline_nowrap(window->subwin, " -Occupants\n");
                 wattroff(window->subwin, COLOUR_ROOMINFO);
                 GList *roster_curr = occupants;
                 while (roster_curr) {
                     Occupant *occupant = roster_curr->data;
-                    wprintw(window->subwin, "   ");
                     const char *presence_str = string_from_resource_presence(occupant->presence);
                     int presence_colour = win_presence_colour(presence_str);
                     wattron(window->subwin, presence_colour);
-                    wprintw(window->subwin, occupant->nick);
+
+                        GString *msg = g_string_new("   ");
+                        g_string_append(msg, occupant->nick);
+                        win_printline_nowrap(window->subwin, msg->str);
+                        g_string_free(msg, TRUE);
+
                     wattroff(window->subwin, presence_colour);
-                    wprintw(window->subwin, "\n");
                     roster_curr = g_list_next(roster_curr);
                 }
             }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index a2e7e67b..74171235 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -52,8 +52,6 @@
 #include "xmpp/xmpp.h"
 
 #define INP_WIN_MAX 1000
-#define SUB_WIN_RATIO 5
-#define SUB_WIN_WIDTH 100
 
 void ui_init_module(void);
 void console_init_module(void);
diff --git a/src/ui/window.c b/src/ui/window.c
index 9ded46ca..f5b1679d 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -51,22 +51,32 @@
 #include "ui/window.h"
 #include "xmpp/xmpp.h"
 
+static int sub_win_ratio = 3; // size = (cols / 10) * SUB_WIN_RATIO
+
 static void _win_print(ProfWin *window, const char show_char, const char * const date_fmt,
     int flags, int attrs, const char * const from, const char * const message);
 static void _win_print_wrapped(WINDOW *win, const char * const message);
 
+int
+win_main_width(void)
+{
+    int cols = getmaxx(stdscr);
+    return (cols/(10/sub_win_ratio)) * ((10/sub_win_ratio)-1);
+}
 
 ProfWin*
-win_create(const char * const title, int cols, win_type_t type)
+win_create(const char * const title, win_type_t type)
 {
     ProfWin *new_win = malloc(sizeof(struct prof_win_t));
     new_win->from = strdup(title);
+    int cols = getmaxx(stdscr);
 
     if ((type == WIN_MUC && prefs_get_boolean(PREF_OCCUPANTS)) || (type == WIN_CONSOLE)) {
-        new_win->win = newpad(PAD_SIZE, (cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1));
+        int main_cols = win_main_width();
+        new_win->win = newpad(PAD_SIZE, main_cols);
         wbkgd(new_win->win, COLOUR_TEXT);
 
-        new_win->subwin = newpad(PAD_SIZE, SUB_WIN_WIDTH);
+        new_win->subwin = newpad(PAD_SIZE, cols - main_cols);
         wbkgd(new_win->subwin, COLOUR_TEXT);
     } else {
         new_win->win = newpad(PAD_SIZE, (cols));
@@ -108,11 +118,13 @@ void
 win_show_subwin(ProfWin *window)
 {
     if (!window->subwin) {
-        window->subwin = newpad(PAD_SIZE, SUB_WIN_WIDTH);
+        int cols = getmaxx(stdscr);
+        int main_cols = win_main_width();
+
+        window->subwin = newpad(PAD_SIZE, cols - main_cols);
         wbkgd(window->subwin, COLOUR_TEXT);
 
-        int cols = getmaxx(stdscr);
-        wresize(window->win, PAD_SIZE, (cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1));
+        wresize(window->win, PAD_SIZE, main_cols);
         win_redraw(window);
     }
 }
@@ -135,10 +147,11 @@ win_update_virtual(ProfWin *window)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
+    int main_cols = win_main_width();
 
     if (((window->type == WIN_MUC) || (window->type == WIN_CONSOLE)) && (window->subwin)) {
-        pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, ((cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1)) -1);
-        pnoutrefresh(window->subwin, window->sub_y_pos, 0, 1, (cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1), rows-3, cols-1);
+        pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, main_cols-1);
+        pnoutrefresh(window->subwin, window->sub_y_pos, 0, 1, main_cols, rows-3, cols-1);
     } else {
         pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
     }
@@ -661,3 +674,16 @@ win_redraw(ProfWin *window)
         _win_print(window, e->show_char, e->date_fmt, e->flags, e->attrs, e->from, e->message);
     }
 }
+
+void
+win_printline_nowrap(WINDOW *win, char *msg)
+{
+    int maxx = getmaxx(win);
+    int cury = getcury(win);
+
+    int i = 0;
+    for (i = 0; i<strlen(msg) && i<maxx; i++) {
+        waddch(win, msg[i]);
+    }
+    wmove(win, cury+1, 0);
+}
\ No newline at end of file
diff --git a/src/ui/window.h b/src/ui/window.h
index 4d864232..0862cfff 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -82,7 +82,7 @@ typedef struct prof_win_t {
     DataForm *form;
 } ProfWin;
 
-ProfWin* win_create(const char * const title, int cols, win_type_t type);
+ProfWin* win_create(const char * const title, win_type_t type);
 void win_free(ProfWin *window);
 void win_update_virtual(ProfWin *window);
 void win_move_to_end(ProfWin *window);
@@ -104,5 +104,7 @@ void win_save_newline(ProfWin *window);
 void win_redraw(ProfWin *window);
 void win_hide_subwin(ProfWin *window);
 void win_show_subwin(ProfWin *window);
+int win_main_width(void);
+void win_printline_nowrap(WINDOW *win, char *msg);
 
 #endif
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 89988996..2d917486 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -65,8 +65,7 @@ wins_init(void)
         (GDestroyNotify)win_free);
 
     max_cols = getmaxx(stdscr);
-    int cols = getmaxx(stdscr);
-    ProfWin *console = win_create(CONS_WIN_TITLE, cols, WIN_CONSOLE);
+    ProfWin *console = win_create(CONS_WIN_TITLE, WIN_CONSOLE);
     g_hash_table_insert(windows, GINT_TO_POINTER(1), console);
 
     current = 1;
@@ -261,8 +260,7 @@ wins_new(const char * const from, win_type_t type)
 {
     GList *keys = g_hash_table_get_keys(windows);
     int result = get_next_available_win_num(keys);
-    int cols = getmaxx(stdscr);
-    ProfWin *new = win_create(from, cols, type);
+    ProfWin *new = win_create(from, type);
     g_hash_table_insert(windows, GINT_TO_POINTER(result), new);
     g_list_free(keys);
     return new;
@@ -289,13 +287,20 @@ wins_resize_all(void)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
+    int main_cols = win_main_width();
 
     GList *values = g_hash_table_get_values(windows);
     GList *curr = values;
     while (curr != NULL) {
         ProfWin *window = curr->data;
         if (((window->type == WIN_MUC) || (window->type == WIN_CONSOLE)) && (window->subwin)) {
-            wresize(window->win, PAD_SIZE, (cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1));
+            wresize(window->win, PAD_SIZE, main_cols);
+            wresize(window->subwin, PAD_SIZE, cols - main_cols);
+            if (window->type == WIN_MUC) {
+                ui_muc_roster(window->from);
+            } else if (window->type == WIN_CONSOLE) {
+                ui_roster();
+            }
         } else {
             wresize(window->win, PAD_SIZE, cols);
         }
@@ -306,8 +311,8 @@ wins_resize_all(void)
 
     ProfWin *current_win = wins_get_current();
     if (((current_win->type == WIN_MUC) || (current_win->type == WIN_CONSOLE)) && (current_win->subwin)) {
-        pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, ((cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1)) -1);
-        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, (cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1), rows-3, cols-1);
+        pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, main_cols-1);
+        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, main_cols, rows-3, cols-1);
     } else {
         pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, cols-1);
     }
@@ -332,13 +337,14 @@ wins_show_subwin(ProfWin *window)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
+    int main_cols = win_main_width();
 
     win_show_subwin(window);
 
     ProfWin *current_win = wins_get_current();
     if ((current_win->type == WIN_MUC) || (current_win->type == WIN_CONSOLE)) {
-        pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, ((cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1)) -1);
-        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, (cols/SUB_WIN_RATIO) * (SUB_WIN_RATIO-1), rows-3, cols-1);
+        pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, main_cols-1);
+        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, main_cols, rows-3, cols-1);
     }
 }