summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2018-02-05 22:25:33 +0100
committerGitHub <noreply@github.com>2018-02-05 22:25:33 +0100
commit3c1bc5f9162c90aa247d024422699710419658f6 (patch)
tree65a0a1efbff85869d4b582ee3250eb4a7a7f5c0a
parent442f6f08b4d99e86c3961be71638abec0f0f8070 (diff)
parentb33ce255a9df6e951d90f3d3c519b005dacb7010 (diff)
downloadirssi-3c1bc5f9162c90aa247d024422699710419658f6.zip
Merge pull request #836 from ailin-nemui/resize
Fix resizing of windows when used incorrectly
-rw-r--r--src/fe-text/mainwindows.c86
1 files changed, 54 insertions, 32 deletions
diff --git a/src/fe-text/mainwindows.c b/src/fe-text/mainwindows.c
index 0c77bcf1..83a3e0cc 100644
--- a/src/fe-text/mainwindows.c
+++ b/src/fe-text/mainwindows.c
@@ -915,6 +915,8 @@ static int try_shrink_lower(MAIN_WINDOW_REC *window, int count)
{
MAIN_WINDOW_REC *shrink_win;
+ g_return_val_if_fail(count >= 0, FALSE);
+
shrink_win = mainwindows_find_lower(window);
if (shrink_win != NULL) {
int ok;
@@ -959,6 +961,8 @@ static int try_shrink_upper(MAIN_WINDOW_REC *window, int count)
{
MAIN_WINDOW_REC *shrink_win;
+ g_return_val_if_fail(count >= 0, FALSE);
+
shrink_win = mainwindows_find_upper(window);
if (shrink_win != NULL) {
int ok;
@@ -1063,6 +1067,8 @@ static int try_grow_upper(MAIN_WINDOW_REC *window, int count)
static int mainwindow_shrink(MAIN_WINDOW_REC *window, int count, int resize_lower)
{
+ g_return_val_if_fail(count >= 0, FALSE);
+
if (MAIN_WINDOW_TEXT_HEIGHT(window)-count < WINDOW_MIN_SIZE)
return FALSE;
@@ -1091,6 +1097,8 @@ static int try_rshrink_right(MAIN_WINDOW_REC *window, int count)
{
MAIN_WINDOW_REC *shrink_win;
+ g_return_val_if_fail(count >= 0, FALSE);
+
shrink_win = mainwindows_find_right(window, FALSE);
if (shrink_win != NULL) {
if (MAIN_WINDOW_TEXT_WIDTH(shrink_win)-count < NEW_WINDOW_WIDTH) {
@@ -1111,6 +1119,8 @@ static int try_rshrink_left(MAIN_WINDOW_REC *window, int count)
{
MAIN_WINDOW_REC *shrink_win;
+ g_return_val_if_fail(count >= 0, FALSE);
+
shrink_win = mainwindows_find_left(window, FALSE);
if (shrink_win != NULL) {
if (MAIN_WINDOW_TEXT_WIDTH(shrink_win)-count < NEW_WINDOW_WIDTH) {
@@ -1168,6 +1178,8 @@ static int try_rgrow_left(MAIN_WINDOW_REC *window, int count)
static int mainwindow_rshrink(MAIN_WINDOW_REC *window, int count)
{
+ g_return_val_if_fail(count >= 0, FALSE);
+
if (MAIN_WINDOW_TEXT_WIDTH(window)-count < NEW_WINDOW_WIDTH)
return FALSE;
@@ -1220,19 +1232,29 @@ void mainwindows_redraw_dirty(void)
}
}
+static void mainwindow_grow_int(int count)
+{
+ if (count == 0) {
+ return;
+ } else if (count < 0) {
+ if (!mainwindow_shrink(WINDOW_MAIN(active_win), -count, FALSE)) {
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_TOO_SMALL);
+ }
+ } else {
+ if (!mainwindow_grow(WINDOW_MAIN(active_win), count, FALSE)) {
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_TOO_SMALL);
+ }
+ }
+}
+
/* SYNTAX: WINDOW GROW [<lines>] */
static void cmd_window_grow(const char *data)
{
- MAIN_WINDOW_REC *window;
int count;
count = *data == '\0' ? 1 : atoi(data);
- window = WINDOW_MAIN(active_win);
- if (!mainwindow_grow(window, count, FALSE)) {
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
- TXT_WINDOW_TOO_SMALL);
- }
+ mainwindow_grow_int(count);
}
/* SYNTAX: WINDOW SHRINK [<lines>] */
@@ -1241,16 +1263,14 @@ static void cmd_window_shrink(const char *data)
int count;
count = *data == '\0' ? 1 : atoi(data);
- if (!mainwindow_shrink(WINDOW_MAIN(active_win), count, FALSE)) {
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
- TXT_WINDOW_TOO_SMALL);
- }
+ if (count < -INT_MAX) count = -INT_MAX;
+
+ mainwindow_grow_int(-count);
}
/* SYNTAX: WINDOW SIZE <lines> */
static void cmd_window_size(const char *data)
{
- char sizestr[MAX_INT_STRLEN];
int size;
if (!is_numeric(data, 0)) return;
@@ -1258,13 +1278,9 @@ static void cmd_window_size(const char *data)
size -= WINDOW_MAIN(active_win)->height -
WINDOW_MAIN(active_win)->statusbar_lines;
- if (size == 0) return;
+ if (size < -INT_MAX) size = -INT_MAX;
- ltoa(sizestr, size < 0 ? -size : size);
- if (size < 0)
- cmd_window_shrink(sizestr);
- else
- cmd_window_grow(sizestr);
+ mainwindow_grow_int(size);
}
/* SYNTAX: WINDOW BALANCE */
@@ -1420,16 +1436,29 @@ static void cmd_window_rshow(const char *data)
_cmd_window_show_opt(data, TRUE);
}
+static void window_rgrow_int(int count)
+{
+ if (count == 0) {
+ return;
+ } else if (count < 0) {
+ if (!mainwindow_rshrink(WINDOW_MAIN(active_win), -count)) {
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_TOO_SMALL);
+ }
+ } else {
+ if (!mainwindow_rgrow(WINDOW_MAIN(active_win), count)) {
+ printformat_window(active_win, MSGLEVEL_CLIENTNOTICE, TXT_WINDOW_TOO_SMALL);
+ }
+ }
+}
+
/* SYNTAX: WINDOW RGROW [<columns>] */
static void cmd_window_rgrow(const char *data)
{
int count;
count = *data == '\0' ? 1 : atoi(data);
- if (!mainwindow_rgrow(WINDOW_MAIN(active_win), count)) {
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
- TXT_WINDOW_TOO_SMALL);
- }
+
+ window_rgrow_int(count);
}
/* SYNTAX: WINDOW RSHRINK [<lines>] */
@@ -1438,29 +1467,22 @@ static void cmd_window_rshrink(const char *data)
int count;
count = *data == '\0' ? 1 : atoi(data);
- if (!mainwindow_rshrink(WINDOW_MAIN(active_win), count)) {
- printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
- TXT_WINDOW_TOO_SMALL);
- }
+ if (count < -INT_MAX) count = -INT_MAX;
+
+ window_rgrow_int(-count);
}
/* SYNTAX: WINDOW RSIZE <columns> */
static void cmd_window_rsize(const char *data)
{
- char rsizestr[MAX_INT_STRLEN];
int rsize;
if (!is_numeric(data, 0)) return;
rsize = atoi(data);
rsize -= MAIN_WINDOW_TEXT_WIDTH(WINDOW_MAIN(active_win));
- if (rsize == 0) return;
- ltoa(rsizestr, rsize < 0 ? -rsize : rsize);
- if (rsize < 0)
- cmd_window_rshrink(rsizestr);
- else
- cmd_window_rgrow(rsizestr);
+ window_rgrow_int(rsize);
}
/* SYNTAX: WINDOW RBALANCE */