1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Changed subwin width to percentage

This commit is contained in:
James Booth 2014-11-15 22:26:43 +00:00
parent dad8e2799d
commit 3642797146
3 changed files with 23 additions and 21 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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);
}
}