about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/console.c13
-rw-r--r--src/ui/core.c2
-rw-r--r--src/ui/inputwin.c14
-rw-r--r--src/ui/screen.c123
-rw-r--r--src/ui/screen.h40
-rw-r--r--src/ui/statusbar.c26
-rw-r--r--src/ui/titlebar.c19
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window.c73
9 files changed, 209 insertions, 103 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 8bc7823f..98967206 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1534,7 +1534,7 @@ cons_show_ui_prefs(void)
     cons_beep_setting();
     cons_flash_setting();
     cons_splash_setting();
-    cons_inputwin_setting();
+    cons_winpos_setting();
     cons_wrap_setting();
     cons_winstidy_setting();
     cons_time_setting();
@@ -1753,11 +1753,14 @@ cons_inpblock_setting(void)
 }
 
 void
-cons_inputwin_setting(void)
+cons_winpos_setting(void)
 {
-    char *pos = prefs_get_string(PREF_INPUTWIN);
-    cons_show("Input window postion (/inputwin)    : %s", pos);
-    prefs_free_string(pos);
+    ProfWinPlacement *placement = prefs_get_win_placement();
+    cons_show("Title bar postion (/titlebar)       : %d", placement->titlebar_pos);
+    cons_show("Main window postion (/mainwin)      : %d", placement->mainwin_pos);
+    cons_show("Status bar postion (/statusbar)     : %d", placement->statusbar_pos);
+    cons_show("Input window postion (/inputwin)    : %d", placement->inputwin_pos);
+    prefs_free_win_placement(placement);
 }
 
 void
diff --git a/src/ui/core.c b/src/ui/core.c
index 6c42c422..c471aad7 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -370,7 +370,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured)
             } else {
                 ui_hide_all_room_rosters();
             }
-            ui_redraw();
+            ui_resize();
         } else {
             cons_show("Couldn't find account theme: %s", account->theme);
         }
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 29bf04c4..9197485f 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -62,6 +62,7 @@
 #include "config/preferences.h"
 #include "config/theme.h"
 #include "ui/ui.h"
+#include "ui/screen.h"
 #include "ui/statusbar.h"
 #include "ui/inputwin.h"
 #include "ui/window.h"
@@ -280,16 +281,9 @@ inp_put_back(void)
 static void
 _inp_win_update_virtual(void)
 {
-    int wrows, wcols;
-    getmaxyx(stdscr, wrows, wcols);
-    char *pos = prefs_get_string(PREF_INPUTWIN);
-    if (g_strcmp0(pos, "top") == 0) {
-        pnoutrefresh(inp_win, 0, pad_start, 0, 0, 0, wcols-2);
-    } else {
-        pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-2);
-    }
-    prefs_free_string(pos);
-
+    int wcols = getmaxx(stdscr);
+    int row = screen_inputwin_row();
+    pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols-2);
 }
 
 static void
diff --git a/src/ui/screen.c b/src/ui/screen.c
new file mode 100644
index 00000000..63cdab27
--- /dev/null
+++ b/src/ui/screen.c
@@ -0,0 +1,123 @@
+/*
+ * screen.c
+ *
+ * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
+ *
+ * This file is part of Profanity.
+ *
+ * Profanity is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Profanity is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * In addition, as a special exception, the copyright holders give permission to
+ * link the code of portions of this program with the OpenSSL library under
+ * certain conditions as described in each individual source file, and
+ * distribute linked combinations including the two.
+ *
+ * You must obey the GNU General Public License in all respects for all of the
+ * code used other than OpenSSL. If you modify file(s) with this exception, you
+ * may extend this exception to your version of the file(s), but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version. If you delete this exception statement from all
+ * source files in the program, then also delete it here.
+ *
+ */
+
+#include "config.h"
+
+#ifdef HAVE_NCURSESW_NCURSES_H
+#include <ncursesw/ncurses.h>
+#elif HAVE_NCURSES_H
+#include <ncurses.h>
+#endif
+
+#include "config/preferences.h"
+
+int
+_screen_line_row(int win_pos, int mainwin_pos) {
+    int wrows = getmaxy(stdscr);
+
+    if (win_pos == 1) {
+        return 0;
+    }
+
+    if (win_pos == 2) {
+        int row = 1;
+        if (mainwin_pos == 1) {
+            row = wrows-3;
+        }
+
+        return row;
+    }
+
+    if (win_pos == 3) {
+        int row = 2;
+        if (mainwin_pos == 1 || mainwin_pos == 2) {
+            row = wrows-2;
+        }
+
+        return row;
+    }
+
+    return wrows-1;
+}
+
+int
+screen_titlebar_row(void)
+{
+    ProfWinPlacement *placement = prefs_get_win_placement();
+    int row = _screen_line_row(placement->titlebar_pos, placement->mainwin_pos);
+    prefs_free_win_placement(placement);
+
+    return row;
+}
+
+int
+screen_statusbar_row(void)
+{
+    ProfWinPlacement *placement = prefs_get_win_placement();
+    int row = _screen_line_row(placement->statusbar_pos, placement->mainwin_pos);
+    prefs_free_win_placement(placement);
+
+    return row;
+}
+
+int
+screen_inputwin_row(void)
+{
+    ProfWinPlacement *placement = prefs_get_win_placement();
+    int row = _screen_line_row(placement->inputwin_pos, placement->mainwin_pos);
+    prefs_free_win_placement(placement);
+
+    return row;
+}
+
+int
+screen_mainwin_row_start(void)
+{
+    ProfWinPlacement *placement = prefs_get_win_placement();
+    int row = placement->mainwin_pos-1;
+    prefs_free_win_placement(placement);
+
+    return row;
+}
+
+int
+screen_mainwin_row_end(void)
+{
+    ProfWinPlacement *placement = prefs_get_win_placement();
+    int wrows = getmaxy(stdscr);
+    int row = wrows - (5 - placement->mainwin_pos);
+    prefs_free_win_placement(placement);
+
+    return row;
+}
diff --git a/src/ui/screen.h b/src/ui/screen.h
new file mode 100644
index 00000000..388d6fb5
--- /dev/null
+++ b/src/ui/screen.h
@@ -0,0 +1,40 @@
+/*
+ * screen.h
+ *
+ * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
+ *
+ * This file is part of Profanity.
+ *
+ * Profanity is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Profanity is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ * In addition, as a special exception, the copyright holders give permission to
+ * link the code of portions of this program with the OpenSSL library under
+ * certain conditions as described in each individual source file, and
+ * distribute linked combinations including the two.
+ *
+ * You must obey the GNU General Public License in all respects for all of the
+ * code used other than OpenSSL. If you modify file(s) with this exception, you
+ * may extend this exception to your version of the file(s), but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version. If you delete this exception statement from all
+ * source files in the program, then also delete it here.
+ *
+ */
+
+int screen_titlebar_row(void);
+int screen_statusbar_row(void);
+int screen_inputwin_row(void);
+
+int screen_mainwin_row_start(void);
+int screen_mainwin_row_end(void);
diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c
index 9b87ecdc..9964c314 100644
--- a/src/ui/statusbar.c
+++ b/src/ui/statusbar.c
@@ -49,6 +49,7 @@
 #include "ui/ui.h"
 #include "ui/statusbar.h"
 #include "ui/inputwin.h"
+#include "ui/screen.h"
 
 #define TIME_CHECK 60000000
 
@@ -74,8 +75,8 @@ static void _status_bar_draw(void);
 void
 create_status_bar(void)
 {
-    int rows, cols, i;
-    getmaxyx(stdscr, rows, cols);
+    int i;
+    int cols = getmaxx(stdscr);
 
     is_active[1] = TRUE;
     is_new[1] = FALSE;
@@ -89,13 +90,8 @@ create_status_bar(void)
 
     int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
 
-    char *pos = prefs_get_string(PREF_INPUTWIN);
-    if (g_strcmp0(pos, "top") == 0) {
-        status_bar = newwin(1, cols, rows-1, 0);
-    } else {
-        status_bar = newwin(1, cols, rows-2, 0);
-    }
-    prefs_free_string(pos);
+    int row = screen_statusbar_row();
+    status_bar = newwin(1, cols, row, 0);
     wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT));
     wattron(status_bar, bracket_attrs);
     mvwprintw(status_bar, 0, cols - 34, _active);
@@ -121,20 +117,14 @@ status_bar_update_virtual(void)
 void
 status_bar_resize(void)
 {
-    int rows, cols;
-    getmaxyx(stdscr, rows, cols);
+    int cols = getmaxx(stdscr);
 
     werase(status_bar);
 
     int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);
 
-    char *pos = prefs_get_string(PREF_INPUTWIN);
-    if (g_strcmp0(pos, "top") == 0) {
-        mvwin(status_bar, rows-1, 0);
-    } else {
-        mvwin(status_bar, rows-2, 0);
-    }
-    prefs_free_string(pos);
+    int row = screen_statusbar_row();
+    mvwin(status_bar, row, 0);
     wresize(status_bar, 1, cols);
     wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT));
     wattron(status_bar, bracket_attrs);
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index 90775ce7..436b574c 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -46,6 +46,7 @@
 #include "ui/inputwin.h"
 #include "ui/window_list.h"
 #include "ui/window.h"
+#include "ui/screen.h"
 #include "xmpp/roster_list.h"
 #include "xmpp/chat_session.h"
 
@@ -67,13 +68,8 @@ create_title_bar(void)
 {
     int cols = getmaxx(stdscr);
 
-    char *pos = prefs_get_string(PREF_INPUTWIN);
-    if (g_strcmp0(pos, "top") == 0) {
-        win = newwin(1, cols, 1, 0);
-    } else {
-        win = newwin(1, cols, 0, 0);
-    }
-    prefs_free_string(pos);
+    int row = screen_titlebar_row();
+    win = newwin(1, cols, row, 0);
     wbkgd(win, theme_attrs(THEME_TITLE_TEXT));
     title_bar_console();
     title_bar_set_presence(CONTACT_OFFLINE);
@@ -109,13 +105,8 @@ title_bar_resize(void)
 
     werase(win);
 
-    char *pos = prefs_get_string(PREF_INPUTWIN);
-    if (g_strcmp0(pos, "top") == 0) {
-        mvwin(win, 1, 0);
-    } else {
-        mvwin(win, 0, 0);
-    }
-    prefs_free_string(pos);
+    int row = screen_titlebar_row();
+    mvwin(win, row, 0);
 
     wresize(win, 1, cols);
     wbkgd(win, theme_attrs(THEME_TITLE_TEXT));
diff --git a/src/ui/ui.h b/src/ui/ui.h
index ef0d808f..bff1c921 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -317,7 +317,7 @@ void cons_reconnect_setting(void);
 void cons_autoping_setting(void);
 void cons_autoconnect_setting(void);
 void cons_inpblock_setting(void);
-void cons_inputwin_setting(void);
+void cons_winpos_setting(void);
 void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity);
 void cons_show_contact_offline(PContact contact, char *resource, char *status);
 void cons_theme_properties(void);
diff --git a/src/ui/window.c b/src/ui/window.c
index a8f9ec63..4cbe25f4 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -52,6 +52,7 @@
 #include "config/preferences.h"
 #include "ui/ui.h"
 #include "ui/window.h"
+#include "ui/screen.h"
 #include "xmpp/xmpp.h"
 #include "xmpp/roster_list.h"
 
@@ -604,9 +605,10 @@ win_resize(ProfWin *window)
 void
 win_update_virtual(ProfWin *window)
 {
-    int rows, cols;
-    getmaxyx(stdscr, rows, cols);
+    int cols = getmaxx(stdscr);
 
+    int row_start = screen_mainwin_row_start();
+    int row_end = screen_mainwin_row_end();
     if (window->layout->type == LAYOUT_SPLIT) {
         ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
         if (layout->subwin) {
@@ -616,83 +618,46 @@ win_update_virtual(ProfWin *window)
             } else {
                 subwin_cols = win_roster_cols();
             }
-            char *pos = prefs_get_string(PREF_INPUTWIN);
-            if (g_strcmp0(pos, "top") == 0) {
-                pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 2, 0, rows-2, (cols-subwin_cols)-1);
-                pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 2, (cols-subwin_cols), rows-2, cols-1);
-            } else {
-                pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1);
-                pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1);
-            }
-            prefs_free_string(pos);
+            pnoutrefresh(layout->base.win, layout->base.y_pos, 0, row_start, 0, row_end, (cols-subwin_cols)-1);
+            pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, row_start, (cols-subwin_cols), row_end, cols-1);
         } else {
-            char *pos = prefs_get_string(PREF_INPUTWIN);
-            if (g_strcmp0(pos, "top") == 0) {
-                pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 2, 0, rows-2, cols-1);
-            } else {
-                pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, cols-1);
-            }
-            prefs_free_string(pos);
+            pnoutrefresh(layout->base.win, layout->base.y_pos, 0, row_start, 0, row_end, cols-1);
         }
     } else {
-        char *pos = prefs_get_string(PREF_INPUTWIN);
-        if (g_strcmp0(pos, "top") == 0) {
-            pnoutrefresh(window->layout->win, window->layout->y_pos, 0, 2, 0, rows-2, cols-1);
-        } else {
-            pnoutrefresh(window->layout->win, window->layout->y_pos, 0, 1, 0, rows-3, cols-1);
-        }
-        prefs_free_string(pos);
+        pnoutrefresh(window->layout->win, window->layout->y_pos, 0, row_start, 0, row_end, cols-1);
     }
 }
 
 void
 win_refresh_without_subwin(ProfWin *window)
 {
-    int rows, cols;
-    getmaxyx(stdscr, rows, cols);
+    int cols = getmaxx(stdscr);
 
     if ((window->type == WIN_MUC) || (window->type == WIN_CONSOLE)) {
-        char *pos = prefs_get_string(PREF_INPUTWIN);
-        if (g_strcmp0(pos, "top") == 0) {
-            pnoutrefresh(window->layout->win, window->layout->y_pos, 0, 2, 0, rows-2, cols-1);
-        } else {
-            pnoutrefresh(window->layout->win, window->layout->y_pos, 0, 1, 0, rows-3, cols-1);
-        }
-        prefs_free_string(pos);
+        int row_start = screen_mainwin_row_start();
+        int row_end = screen_mainwin_row_end();
+        pnoutrefresh(window->layout->win, window->layout->y_pos, 0, row_start, 0, row_end, cols-1);
     }
 }
 
 void
 win_refresh_with_subwin(ProfWin *window)
 {
-    int rows, cols;
-    getmaxyx(stdscr, rows, cols);
+    int cols = getmaxx(stdscr);
     int subwin_cols = 0;
 
+    int row_start = screen_mainwin_row_start();
+    int row_end = screen_mainwin_row_end();
     if (window->type == WIN_MUC) {
         ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
         subwin_cols = win_occpuants_cols();
-        char *pos = prefs_get_string(PREF_INPUTWIN);
-        if (g_strcmp0(pos, "top") == 0) {
-            pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 2, 0, rows-2, (cols-subwin_cols)-1);
-            pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 2, (cols-subwin_cols), rows-2, cols-1);
-        } else {
-            pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1);
-            pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1);
-        }
-        prefs_free_string(pos);
+        pnoutrefresh(layout->base.win, layout->base.y_pos, 0, row_start, 0, row_end, (cols-subwin_cols)-1);
+        pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, row_start, (cols-subwin_cols), row_end, cols-1);
     } else if (window->type == WIN_CONSOLE) {
         ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
         subwin_cols = win_roster_cols();
-        char *pos = prefs_get_string(PREF_INPUTWIN);
-        if (g_strcmp0(pos, "top") == 0) {
-            pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 2, 0, rows-2, (cols-subwin_cols)-1);
-            pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 2, (cols-subwin_cols), rows-2, cols-1);
-        } else {
-            pnoutrefresh(layout->base.win, layout->base.y_pos, 0, 1, 0, rows-3, (cols-subwin_cols)-1);
-            pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, 1, (cols-subwin_cols), rows-3, cols-1);
-        }
-        prefs_free_string(pos);
+        pnoutrefresh(layout->base.win, layout->base.y_pos, 0, row_start, 0, row_end, (cols-subwin_cols)-1);
+        pnoutrefresh(layout->subwin, layout->sub_y_pos, 0, row_start, (cols-subwin_cols), row_end, cols-1);
     }
 }