"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: tog: key map to switch split mode
To:
Mark Jamsek <mark@jamsek.com>
Cc:
gameoftrees@openbsd.org
Date:
Mon, 11 Jul 2022 08:49:24 +0200

Download raw body.

Thread
On Sun, Jul 10, 2022 at 09:42:05PM +1000, Mark Jamsek wrote:
> This diff _should_ now implement the desired behaviour :)

Yes, this seems to behave as I expected. Thanks a lot!

Ok by me.
 
> diff refs/heads/main refs/heads/stash/switchsplit
> commit - 3c1dfe12b3f3eae6dc7ef4762772e849794296c5
> commit + 5cec55df8f5fd70d1e7e5e19f4157f5ada2d89ce
> blob - 39cc96c4b079ff1b9f5daafb5f0894e26c52df11
> blob + 983fa45bf1aa8f912574f9bd29fd81395a4f9837
> --- tog/tog.1
> +++ tog/tog.1
> @@ -81,11 +81,11 @@ Toggle fullscreen mode for a split-screen view.
>  will automatically use split-screen views if the size of the terminal
>  window is sufficiently large.
>  .It Cm S
> -When in a split-screen view,
> +Switch the current split mode.
>  .Nm
> -will switch to the alternate split mode.
> -If the current view is in a horizontal split and the terminal window is not
> -wide enough, the view will remain unchanged.
> +will also render the view in the new split mode.
> +If the terminal is not wide enough when switching to a vertical split, the
> +view will render in fullscreen.
>  .It Cm -
>  When in a split-screen view, decrease the size of the focussed split
>  N increments (default: 1).
> blob - 310eb39a0776dd5fb11adc30d6c50fba6d7de13b
> blob + a5d90611997db9815fb80f198f864a0df35e90c5
> --- tog/tog.c
> +++ tog/tog.c
> @@ -1114,10 +1114,7 @@ view_search_start(struct tog_view *view)
>  	return NULL;
>  }
> 
> -/*
> - * If view is a parent or child view and is currently in a splitscreen, switch
> - * to the alternate split. If in a hsplit and LINES < 120, don't vsplit.
> - */
> +/* Switch split mode. If view is a parent or child, draw the new splitscreen. */
>  static const struct got_error *
>  switch_split(struct tog_view *view)
>  {
> @@ -1129,26 +1126,27 @@ switch_split(struct tog_view *view)
>  	else
>  		v = view;
> 
> -	if (!v->child || !view_is_splitscreen(v->child))
> -		return NULL;
> -	if (v->mode == TOG_VIEW_SPLIT_HRZN && v->cols < 120)
> -		return NULL;
> -
> -	if (!v->mode || v->mode == TOG_VIEW_SPLIT_HRZN) {
> -		v->child->nscrolled = LINES - v->child->nlines;
> +	if (v->mode == TOG_VIEW_SPLIT_HRZN)
>  		v->mode = TOG_VIEW_SPLIT_VERT;
> -	} else if (v->mode == TOG_VIEW_SPLIT_VERT)
> +	else
>  		v->mode = TOG_VIEW_SPLIT_HRZN;
> 
> +	if (!v->child)
> +		return NULL;
> +	else if (v->mode == TOG_VIEW_SPLIT_VERT && v->cols < 120)
> +		v->mode = TOG_VIEW_SPLIT_NONE;
> +
>  	view_get_split(v, &v->child->begin_y, &v->child->begin_x);
>  	if (v->mode == TOG_VIEW_SPLIT_HRZN && v->child->resized_y)
>  		v->child->begin_y = v->child->resized_y;
> -	if (v->mode == TOG_VIEW_SPLIT_VERT && v->child->resized_x)
> +	else if (v->mode == TOG_VIEW_SPLIT_VERT && v->child->resized_x)
>  		v->child->begin_x = v->child->resized_x;
> 
> +
>  	if (v->mode == TOG_VIEW_SPLIT_HRZN) {
>  		v->ncols = COLS;
>  		v->child->ncols = COLS;
> +		v->child->nscrolled = LINES - v->child->nlines;
> 
>  		err = view_init_hsplit(v, v->child->begin_y);
>  		if (err)
> @@ -1165,14 +1163,19 @@ switch_split(struct tog_view *view)
>  	if (err)
>  		return err;
> 
> -	if (v->mode == TOG_VIEW_SPLIT_HRZN)
> +	if (v->mode == TOG_VIEW_SPLIT_NONE)
> +		v->mode = TOG_VIEW_SPLIT_VERT;
> +	if (v->mode == TOG_VIEW_SPLIT_HRZN) {
> +		err = offset_selection_down(v);
>  		err = offset_selection_down(v->child);
> -	else if (v->mode == TOG_VIEW_SPLIT_VERT) {
> -		if (v->type == TOG_VIEW_LOG)
> -			err = request_log_commits(v);
> -		else if (v->child->type == TOG_VIEW_LOG)
> -			err = request_log_commits(v->child);
> +	} else {
> +		offset_selection_up(v);
> +		offset_selection_up(v->child);
>  	}
> +	if (v->type == TOG_VIEW_LOG)
> +		err = request_log_commits(v);
> +	else if (v->child->type == TOG_VIEW_LOG)
> +		err = request_log_commits(v->child);
> 
>  	return err;
>  }
> @@ -3091,11 +3094,15 @@ view_get_split(struct tog_view *view, int *y, int *x)
>  	if (view->mode == TOG_VIEW_SPLIT_HRZN) {
>  		if (view->child && view->child->resized_y)
>  			*y = view->child->resized_y;
> +		else if (view->resized_y)
> +			*y = view->resized_y;
>  		else
>  			*y = view_split_begin_y(view->lines);
> -	} else {
> +	} else if (view->mode == TOG_VIEW_SPLIT_VERT) {
>  		if (view->child && view->child->resized_x)
>  			*x = view->child->resized_x;
> +		else if (view->resized_x)
> +			*x = view->resized_x;
>  		else
>  			*x = view_split_begin_x(view->begin_x);
>  	}
> 
> -- 
> Mark Jamsek <fnc.bsdbox.org>
> GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68