1 /*
2 * screen.c
3 * vim: expandtab:ts=4:sts=4:sw=4
4 *
5 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
6 *
7 * This file is part of Profanity.
8 *
9 * Profanity is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Profanity is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Profanity. If not, see <https://www.gnu.org/licenses/>.
21 *
22 * In addition, as a special exception, the copyright holders give permission to
23 * link the code of portions of this program with the OpenSSL library under
24 * certain conditions as described in each individual source file, and
25 * distribute linked combinations including the two.
26 *
27 * You must obey the GNU General Public License in all respects for all of the
28 * code used other than OpenSSL. If you modify file(s) with this exception, you
29 * may extend this exception to your version of the file(s), but you are not
30 * obligated to do so. If you do not wish to do so, delete this exception
31 * statement from your version. If you delete this exception statement from all
32 * source files in the program, then also delete it here.
33 *
34 */
35
36 #include "config.h"
37
38 #ifdef HAVE_NCURSESW_NCURSES_H
39 #include <ncursesw/ncurses.h>
40 #elif HAVE_NCURSES_H
41 #include <ncurses.h>
42 #elif HAVE_CURSES_H
43 #include <curses.h>
44 #endif
45
46 #include "config/preferences.h"
47
48 int
_screen_line_row(int win_pos,int mainwin_pos)49 _screen_line_row(int win_pos, int mainwin_pos)
50 {
51 int wrows = getmaxy(stdscr);
52
53 if (win_pos == 1) {
54 return 0;
55 }
56
57 if (win_pos == 2) {
58 int row = 1;
59 if (mainwin_pos == 1) {
60 row = wrows - 3;
61 }
62
63 return row;
64 }
65
66 if (win_pos == 3) {
67 int row = 2;
68 if (mainwin_pos == 1 || mainwin_pos == 2) {
69 row = wrows - 2;
70 }
71
72 return row;
73 }
74
75 return wrows - 1;
76 }
77
78 int
screen_titlebar_row(void)79 screen_titlebar_row(void)
80 {
81 ProfWinPlacement* placement = prefs_get_win_placement();
82 int row = _screen_line_row(placement->titlebar_pos, placement->mainwin_pos);
83 prefs_free_win_placement(placement);
84
85 return row;
86 }
87
88 int
screen_statusbar_row(void)89 screen_statusbar_row(void)
90 {
91 ProfWinPlacement* placement = prefs_get_win_placement();
92 int row = _screen_line_row(placement->statusbar_pos, placement->mainwin_pos);
93 prefs_free_win_placement(placement);
94
95 return row;
96 }
97
98 int
screen_inputwin_row(void)99 screen_inputwin_row(void)
100 {
101 ProfWinPlacement* placement = prefs_get_win_placement();
102 int row = _screen_line_row(placement->inputwin_pos, placement->mainwin_pos);
103 prefs_free_win_placement(placement);
104
105 return row;
106 }
107
108 int
screen_mainwin_row_start(void)109 screen_mainwin_row_start(void)
110 {
111 ProfWinPlacement* placement = prefs_get_win_placement();
112 int row = placement->mainwin_pos - 1;
113 prefs_free_win_placement(placement);
114
115 return row;
116 }
117
118 int
screen_mainwin_row_end(void)119 screen_mainwin_row_end(void)
120 {
121 ProfWinPlacement* placement = prefs_get_win_placement();
122 int wrows = getmaxy(stdscr);
123 int row = wrows - (5 - placement->mainwin_pos);
124 prefs_free_win_placement(placement);
125
126 return row;
127 }
128