Commit 5c60c32a7d03db0967a09aee2994a92589d31a8e

Stefan Sperling 2018-10-18T11:29:42

switch between full- and splitscreen when window size changes

diff --git a/tog/tog.c b/tog/tog.c
index a9cdcb7..faaa00b 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -327,6 +327,56 @@ view_split_begin_x(int begin_x)
 	return (COLS >= 120 ? COLS/2 : 0);
 }
 
+static const struct got_error *view_resize(struct tog_view *);
+
+static const struct got_error *
+view_splitscreen(struct tog_view *view)
+{
+	const struct got_error *err = NULL;
+
+	view->begin_y = 0;
+	view->begin_x = view_split_begin_x(0);
+	view->nlines = LINES;
+	view->ncols = COLS - view->begin_x;
+	view->lines = LINES;
+	view->cols = COLS;
+	err = view_resize(view);
+	if (err)
+		return err;
+
+	if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
+		return got_error_from_errno();
+
+	return NULL;
+}
+
+static const struct got_error *
+view_fullscreen(struct tog_view *view)
+{
+	const struct got_error *err = NULL;
+
+	view->begin_x = 0;
+	view->begin_y = 0;
+	view->nlines = LINES;
+	view->ncols = COLS;
+	view->lines = LINES;
+	view->cols = COLS;
+	err = view_resize(view);
+	if (err)
+		return err;
+
+	if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
+		return got_error_from_errno();
+
+	return NULL;
+}
+
+static int
+view_is_parent_view(struct tog_view *view)
+{
+	return view->parent == NULL;
+}
+
 static const struct got_error *
 view_resize(struct tog_view *view)
 {
@@ -351,13 +401,21 @@ view_resize(struct tog_view *view)
 	view->lines = LINES;
 	view->cols = COLS;
 
-	return NULL;
-}
+	if (view_is_parent_view(view)) {
+		view->child->begin_x = view_split_begin_x(view->begin_x);
+		if (view->child->begin_x == 0) {
+			view_fullscreen(view->child);
+			if (view->child->focussed)
+				show_panel(view->child->panel);
+			else
+				show_panel(view->panel);
+		} else {
+			view_splitscreen(view->child);
+			show_panel(view->child->panel);
+		}
+	}
 
-static int
-view_is_parent_view(struct tog_view *view)
-{
-	return view->parent == NULL;
+	return NULL;
 }
 
 static const struct got_error *
@@ -390,48 +448,6 @@ view_is_splitscreen(struct tog_view *view)
 }
 
 static const struct got_error *
-view_splitscreen(struct tog_view *view)
-{
-	const struct got_error *err = NULL;
-
-	view->begin_y = 0;
-	view->begin_x = view_split_begin_x(0);
-	view->nlines = LINES;
-	view->ncols = COLS - view->begin_x;
-	view->lines = LINES;
-	view->cols = COLS;
-	err = view_resize(view);
-	if (err)
-		return err;
-
-	if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
-		return got_error_from_errno();
-
-	return NULL;
-}
-
-static const struct got_error *
-view_fullscreen(struct tog_view *view)
-{
-	const struct got_error *err = NULL;
-
-	view->begin_x = 0;
-	view->begin_y = 0;
-	view->nlines = LINES;
-	view->ncols = COLS;
-	view->lines = LINES;
-	view->cols = COLS;
-	err = view_resize(view);
-	if (err)
-		return err;
-
-	if (mvwin(view->window, view->begin_y, view->begin_x) == ERR)
-		return got_error_from_errno();
-
-	return NULL;
-}
-
-static const struct got_error *
 view_input(struct tog_view **new, struct tog_view **dead,
     struct tog_view **focus, int *done, struct tog_view *view,
     struct tog_view_list_head *views)