about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-15 22:26:43 +0000
committerJames Booth <boothj5@gmail.com>2014-11-15 22:26:43 +0000
commit36427971468ff81a55b77e3f75ab5dd36f2bd9a6 (patch)
tree56a4664df6bd5fdcccf7c2e894b4dd83c386618a
parentdad8e2799d210d5029cf0fd8bdccf2cb31adf160 (diff)
downloadprofani-tty-36427971468ff81a55b77e3f75ab5dd36f2bd9a6.tar.gz
Changed subwin width to percentage
-rw-r--r--src/ui/window.c26
-rw-r--r--src/ui/window.h2
-rw-r--r--src/ui/windows.c16
3 files changed, 23 insertions, 21 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index bf7afe74..dbb3a25c 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -51,17 +51,19 @@
 #include "ui/window.h"
 #include "xmpp/xmpp.h"
 
-static int sub_win_ratio = 3; // size = (cols / 10) * SUB_WIN_RATIO
+#define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
+
+static int roster_win_percent = 20;
 
 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)
+win_roster_cols(void)
 {
     int cols = getmaxx(stdscr);
-    return (cols/(10/sub_win_ratio)) * ((10/sub_win_ratio)-1);
+    return CEILING( (((double)cols) / 100) * roster_win_percent);
 }
 
 ProfWin*
@@ -72,11 +74,11 @@ win_create(const char * const title, win_type_t type)
     int cols = getmaxx(stdscr);
 
     if (type == WIN_MUC && prefs_get_boolean(PREF_OCCUPANTS)) {
-        int main_cols = win_main_width();
-        new_win->win = newpad(PAD_SIZE, main_cols);
+        int subwin_cols = win_roster_cols();
+        new_win->win = newpad(PAD_SIZE, cols - subwin_cols);
         wbkgd(new_win->win, COLOUR_TEXT);
 
-        new_win->subwin = newpad(PAD_SIZE, cols - main_cols);
+        new_win->subwin = newpad(PAD_SIZE, subwin_cols);
         wbkgd(new_win->subwin, COLOUR_TEXT);
     } else {
         new_win->win = newpad(PAD_SIZE, (cols));
@@ -119,12 +121,12 @@ win_show_subwin(ProfWin *window)
 {
     if (!window->subwin) {
         int cols = getmaxx(stdscr);
-        int main_cols = win_main_width();
+        int subwin_cols = win_roster_cols();
 
-        window->subwin = newpad(PAD_SIZE, cols - main_cols);
+        window->subwin = newpad(PAD_SIZE, subwin_cols);
         wbkgd(window->subwin, COLOUR_TEXT);
 
-        wresize(window->win, PAD_SIZE, main_cols);
+        wresize(window->win, PAD_SIZE, cols - subwin_cols);
         win_redraw(window);
     }
 }
@@ -147,11 +149,11 @@ win_update_virtual(ProfWin *window)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
-    int main_cols = win_main_width();
+    int subwin_cols = win_roster_cols();
 
     if (((window->type == WIN_MUC) || (window->type == WIN_CONSOLE)) && (window->subwin)) {
-        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);
+        pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1);
+        pnoutrefresh(window->subwin, window->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1);
     } else {
         pnoutrefresh(window->win, window->y_pos, 0, 1, 0, rows-3, cols-1);
     }
diff --git a/src/ui/window.h b/src/ui/window.h
index 0862cfff..e635f221 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -104,7 +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);
+int win_roster_cols(void);
 void win_printline_nowrap(WINDOW *win, char *msg);
 
 #endif
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 2d917486..81e02965 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -287,15 +287,15 @@ wins_resize_all(void)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
-    int main_cols = win_main_width();
+    int roster_cols = win_roster_cols();
 
     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, main_cols);
-            wresize(window->subwin, PAD_SIZE, cols - main_cols);
+            wresize(window->win, PAD_SIZE, cols - roster_cols);
+            wresize(window->subwin, PAD_SIZE, roster_cols);
             if (window->type == WIN_MUC) {
                 ui_muc_roster(window->from);
             } else if (window->type == WIN_CONSOLE) {
@@ -311,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, main_cols-1);
-        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, main_cols, rows-3, cols-1);
+        pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, (cols-roster_cols)-1);
+        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, (cols-roster_cols), rows-3, cols-1);
     } else {
         pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, cols-1);
     }
@@ -337,14 +337,14 @@ wins_show_subwin(ProfWin *window)
 {
     int rows, cols;
     getmaxyx(stdscr, rows, cols);
-    int main_cols = win_main_width();
+    int roster_cols = win_roster_cols();
 
     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, main_cols-1);
-        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, main_cols, rows-3, cols-1);
+        pnoutrefresh(current_win->win, current_win->y_pos, 0, 1, 0, rows-3, (cols-roster_cols)-1);
+        pnoutrefresh(current_win->subwin, current_win->sub_y_pos, 0, 1, (cols-roster_cols), rows-3, cols-1);
     }
 }