Commit Diff


commit - 871bd038071fdaf6129995ef9f56226616b47d25
commit + 444d532558298b49ff0edc7fc0376d71b5fa00b0
blob - d22799a47ef9bd147f72ae35dbe392bcadb72680
blob + 2735938d75ca2d0cb81fd696523643ed004e53ee
--- tog/tog.c
+++ tog/tog.c
@@ -797,6 +797,13 @@ view_is_fullscreen(struct tog_view *view)
 	return view->nlines == LINES && view->ncols == COLS;
 }
 
+static int
+view_is_hsplit_top(struct tog_view *view)
+{
+	return view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
+	    view_is_splitscreen(view->child);
+}
+
 static void
 view_border(struct tog_view *view)
 {
@@ -972,8 +979,7 @@ view_search_start(struct tog_view *view)
 	if (view->nlines < 1)
 		return NULL;
 
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		v = view->child;
 
 	mvwaddstr(v->window, v->nlines - 1, 0, "/");
@@ -1013,8 +1019,7 @@ get_compound_key(struct tog_view *view, int c)
 	struct tog_view	*v = view;
 	int		 x, n = 0;
 
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		v = view->child;
 	else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent)
 		v = view->parent;
@@ -1754,7 +1759,7 @@ draw_commit(struct tog_view *view, struct got_commit_o
 	if (newline)
 		*newline = '\0';
 	limit = avail - col;
-	if (view->child && view_is_splitscreen(view->child) && limit > 0)
+	if (view->child && !view_is_hsplit_top(view) && limit > 0)
 		limit--;	/* for the border */
 	err = format_line(&wlogmsg, &logmsg_width, &scrollx, logmsg, view->x,
 	    limit, col, 1);
@@ -2335,7 +2340,7 @@ tree_view_walk_path(struct tog_tree_view_state *s,
 }
 
 static const struct got_error *
-browse_commit_tree(struct tog_view **new_view, int begin_x,
+browse_commit_tree(struct tog_view **new_view, int begin_y, int begin_x,
     struct commit_queue_entry *entry, const char *path,
     const char *head_ref_name, struct got_repository *repo)
 {
@@ -2343,7 +2348,7 @@ browse_commit_tree(struct tog_view **new_view, int beg
 	struct tog_tree_view_state *s;
 	struct tog_view *tree_view;
 
-	tree_view = view_open(0, 0, 0, begin_x, TOG_VIEW_TREE);
+	tree_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_TREE);
 	if (tree_view == NULL)
 		return got_error_from_errno("view_open");
 
@@ -2832,8 +2837,7 @@ log_move_cursor_down(struct tog_view *view, int page)
 	if (!page) {
 		int eos = view->nlines - 2;
 
-		if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-		    view_is_splitscreen(view->child))
+		if (view_is_hsplit_top(view))
 			--eos;  /* border consumes the last line */
 		if (s->selected < MIN(eos, s->commits.ncommits - 1))
 			++s->selected;
@@ -2938,11 +2942,9 @@ input_log_view(struct tog_view **new_view, struct tog_
 	}
 
 	eos = nscroll = view->nlines - 1;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--eos;  /* border */
 
-
 	switch (ch) {
 	case 'q':
 		s->quit = 1;
@@ -3042,7 +3044,7 @@ input_log_view(struct tog_view **new_view, struct tog_
 		}
 		break;
 	case KEY_ENTER:
-	case '\r': {
+	case '\r':
 		view->count = 0;
 		if (s->selected_entry == NULL)
 			break;
@@ -3057,7 +3059,8 @@ input_log_view(struct tog_view **new_view, struct tog_
 		if (err)
 			break;
 
-		if (view->mode == TOG_VIEW_SPLIT_HRZN) {  /* safe to split */
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {  /* safe to split */
 			err = view_init_hsplit(view, begin_y);
 			if (err)
 				break;
@@ -3079,20 +3082,27 @@ input_log_view(struct tog_view **new_view, struct tog_
 		} else
 			*new_view = diff_view;
 		break;
-	}
 	case 't':
 		view->count = 0;
 		if (s->selected_entry == NULL)
 			break;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		err = browse_commit_tree(&tree_view, begin_x,
+			view_get_split(view, &begin_y, &begin_x);
+		err = browse_commit_tree(&tree_view, begin_y, begin_x,
 		    s->selected_entry, s->in_repo_path, s->head_ref_name,
 		    s->repo);
 		if (err)
 			break;
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		tree_view->focussed = 1;
+		tree_view->mode = view->mode;
+		tree_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -3171,9 +3181,8 @@ input_log_view(struct tog_view **new_view, struct tog_
 	case 'r':
 		view->count = 0;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		ref_view = view_open(view->nlines, view->ncols,
-		    view->begin_y, begin_x, TOG_VIEW_REF);
+			view_get_split(view, &begin_y, &begin_x);
+		ref_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_REF);
 		if (ref_view == NULL)
 			return got_error_from_errno("view_open");
 		err = open_ref_view(ref_view, s->repo);
@@ -3181,8 +3190,16 @@ input_log_view(struct tog_view **new_view, struct tog_
 			view_close(ref_view);
 			return err;
 		}
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		ref_view->focussed = 1;
+		ref_view->mode = view->mode;
+		ref_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -5403,8 +5420,7 @@ input_blame_view(struct tog_view **new_view, struct to
 	int eos, nscroll, begin_y = 0, begin_x = 0;
 
 	eos = nscroll = view->nlines - 2;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--eos;  /* border */
 
 	switch (ch) {
@@ -5611,7 +5627,8 @@ input_blame_view(struct tog_view **new_view, struct to
 			view_close(diff_view);
 			break;
 		}
-		if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
 			err = view_init_hsplit(view, begin_y);
 			if (err)
 				break;
@@ -5845,8 +5862,7 @@ draw_tree_entries(struct tog_view *view, const char *p
 	int limit = view->nlines;
 
 	s->ndisplayed = 0;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--limit;  /* border */
 
 	werase(view->window);
@@ -6121,7 +6137,7 @@ done:
 }
 
 static const struct got_error *
-log_selected_tree_entry(struct tog_view **new_view, int begin_x,
+log_selected_tree_entry(struct tog_view **new_view, int begin_y, int begin_x,
     struct tog_tree_view_state *s)
 {
 	struct tog_view *log_view;
@@ -6130,7 +6146,7 @@ log_selected_tree_entry(struct tog_view **new_view, in
 
 	*new_view = NULL;
 
-	log_view = view_open(0, 0, 0, begin_x, TOG_VIEW_LOG);
+	log_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_LOG);
 	if (log_view == NULL)
 		return got_error_from_errno("view_open");
 
@@ -6378,7 +6394,7 @@ input_tree_view(struct tog_view **new_view, struct tog
 	struct tog_tree_view_state *s = &view->state.tree;
 	struct tog_view *log_view, *ref_view;
 	struct got_tree_entry *te;
-	int begin_x = 0, n, nscroll = view->nlines - 3;
+	int begin_y = 0, begin_x = 0, n, nscroll = view->nlines - 3;
 
 	switch (ch) {
 	case 'i':
@@ -6390,10 +6406,18 @@ input_tree_view(struct tog_view **new_view, struct tog
 		if (!s->selected_entry)
 			break;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		err = log_selected_tree_entry(&log_view, begin_x, s);
+			view_get_split(view, &begin_y, &begin_x);
+		err = log_selected_tree_entry(&log_view, begin_y, begin_x, s);
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		log_view->focussed = 1;
+		log_view->mode = view->mode;
+		log_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -6408,9 +6432,8 @@ input_tree_view(struct tog_view **new_view, struct tog
 	case 'r':
 		view->count = 0;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		ref_view = view_open(view->nlines, view->ncols,
-		    view->begin_y, begin_x, TOG_VIEW_REF);
+			view_get_split(view, &begin_y, &begin_x);
+		ref_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_REF);
 		if (ref_view == NULL)
 			return got_error_from_errno("view_open");
 		err = open_ref_view(ref_view, s->repo);
@@ -6418,8 +6441,16 @@ input_tree_view(struct tog_view **new_view, struct tog
 			view_close(ref_view);
 			return err;
 		}
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		ref_view->focussed = 1;
+		ref_view->mode = view->mode;
+		ref_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -6587,7 +6618,8 @@ input_tree_view(struct tog_view **new_view, struct tog
 			if (err)
 				break;
 
-			if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+			if (view_is_parent_view(view) &&
+			    view->mode == TOG_VIEW_SPLIT_HRZN) {
 				err = view_init_hsplit(view, begin_y);
 				if (err)
 					break;
@@ -7121,8 +7153,7 @@ show_ref_view(struct tog_view *view)
 	werase(view->window);
 
 	s->ndisplayed = 0;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--limit;  /* border */
 
 	if (limit == 0)
@@ -7260,7 +7291,7 @@ show_ref_view(struct tog_view *view)
 }
 
 static const struct got_error *
-browse_ref_tree(struct tog_view **new_view, int begin_x,
+browse_ref_tree(struct tog_view **new_view, int begin_y, int begin_x,
     struct tog_reflist_entry *re, struct got_repository *repo)
 {
 	const struct got_error *err = NULL;
@@ -7278,7 +7309,7 @@ browse_ref_tree(struct tog_view **new_view, int begin_
 	}
 
 
-	tree_view = view_open(0, 0, 0, begin_x, TOG_VIEW_TREE);
+	tree_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_TREE);
 	if (tree_view == NULL) {
 		err = got_error_from_errno("view_open");
 		goto done;
@@ -7341,7 +7372,8 @@ input_ref_view(struct tog_view **new_view, struct tog_
 		if (err)
 			break;
 
-		if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
 			err = view_init_hsplit(view, begin_y);
 			if (err)
 				break;
@@ -7367,13 +7399,21 @@ input_ref_view(struct tog_view **new_view, struct tog_
 		if (!s->selected_entry)
 			break;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		err = browse_ref_tree(&tree_view, begin_x, s->selected_entry,
-		    s->repo);
+			view_get_split(view, &begin_y, &begin_x);
+		err = browse_ref_tree(&tree_view, begin_y, begin_x,
+		    s->selected_entry, s->repo);
 		if (err || tree_view == NULL)
 			break;
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		tree_view->focussed = 1;
+		tree_view->mode = view->mode;
+		tree_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)