commit 5c60c32a7d03db0967a09aee2994a92589d31a8e from: Stefan Sperling date: Thu Oct 18 09:29:42 2018 UTC switch between full- and splitscreen when window size changes commit - 86c66b02a69560b032d978b11c60f5524ba417e4 commit + 5c60c32a7d03db0967a09aee2994a92589d31a8e blob - a9cdcb7e8b48cb53470643edfee2b4177b528ac2 blob + faaa00b87b84667bb9b053f2e40a63d9b2cb7eac --- tog/tog.c +++ tog/tog.c @@ -325,8 +325,58 @@ view_split_begin_x(int begin_x) if (begin_x > 0) return 0; 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)