propagate tog window resize events across all active views
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
diff --git a/tog/tog.c b/tog/tog.c
index ffde15b..f1de40e 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -87,6 +87,7 @@ struct tog_view {
PANEL *panel;
int nlines, ncols, begin_y, begin_x;
int lines, cols; /* copies of LINES and COLS */
+ struct tog_view *parent;
};
static const struct got_error *
@@ -113,13 +114,15 @@ close_view(struct tog_view *view)
}
static struct tog_view *
-open_view(int nlines, int ncols, int begin_y, int begin_x)
+open_view(int nlines, int ncols, int begin_y, int begin_x,
+ struct tog_view *parent)
{
struct tog_view *view = malloc(sizeof(*view));
if (view == NULL)
return NULL;
+ view->parent = parent;
view->lines = LINES;
view->cols = COLS;
view->nlines = nlines ? nlines : LINES - begin_y;
@@ -146,23 +149,28 @@ view_resize(struct tog_view *view)
{
int nlines, ncols;
- if (view->lines > LINES)
- nlines = view->nlines - (view->lines - LINES);
- else
- nlines = view->nlines + (LINES - view->lines);
+ while (view) {
+ if (view->lines > LINES)
+ nlines = view->nlines - (view->lines - LINES);
+ else
+ nlines = view->nlines + (LINES - view->lines);
- if (view->cols > COLS)
- ncols = view->ncols - (view->cols - COLS);
- else
- ncols = view->ncols + (COLS - view->cols);
+ if (view->cols > COLS)
+ ncols = view->ncols - (view->cols - COLS);
+ else
+ ncols = view->ncols + (COLS - view->cols);
- if (wresize(view->window, nlines, ncols) == ERR)
- return got_error_from_errno();
+ if (wresize(view->window, nlines, ncols) == ERR)
+ return got_error_from_errno();
+
+ view->nlines = nlines;
+ view->ncols = ncols;
+ view->lines = LINES;
+ view->cols = COLS;
+
+ view = view->parent;
+ }
- view->nlines = nlines;
- view->ncols = ncols;
- view->lines = LINES;
- view->cols = COLS;
return NULL;
}
@@ -715,7 +723,8 @@ scroll_down(struct commit_queue_entry **first_displayed_entry, int maxscroll,
}
static const struct got_error *
-show_commit(struct commit_queue_entry *entry, struct got_repository *repo)
+show_commit(struct tog_view *parent_view, struct commit_queue_entry *entry,
+ struct got_repository *repo)
{
const struct got_error *err;
struct got_object *obj1 = NULL, *obj2 = NULL;
@@ -733,7 +742,7 @@ show_commit(struct commit_queue_entry *entry, struct got_repository *repo)
goto done;
}
- view = open_view(0, 0, 0, 0);
+ view = open_view(0, 0, 0, 0, parent_view);
if (view == NULL) {
err = got_error_from_errno();
goto done;
@@ -750,7 +759,8 @@ done:
}
static const struct got_error *
-browse_commit(struct commit_queue_entry *entry, struct got_repository *repo)
+browse_commit(struct tog_view *parent_view, struct commit_queue_entry *entry,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_tree_object *tree;
@@ -760,7 +770,7 @@ browse_commit(struct commit_queue_entry *entry, struct got_repository *repo)
if (err)
return err;
- view = open_view(0, 0, 0, 0);
+ view = open_view(0, 0, 0, 0, parent_view);
if (view == NULL) {
err = got_error_from_errno();
goto done;
@@ -904,13 +914,13 @@ show_log_view(struct tog_view *view, struct got_object_id *start_id,
break;
case KEY_ENTER:
case '\r':
- err = show_commit(selected_entry, repo);
+ err = show_commit(view, selected_entry, repo);
if (err)
goto done;
show_panel(view->panel);
break;
case 't':
- err = browse_commit(selected_entry, repo);
+ err = browse_commit(view, selected_entry, repo);
if (err)
goto done;
show_panel(view->panel);
@@ -1006,7 +1016,7 @@ cmd_log(int argc, char *argv[])
if (error != NULL)
goto done;
- view = open_view(0, 0, 0, 0);
+ view = open_view(0, 0, 0, 0, NULL);
if (view == NULL) {
error = got_error_from_errno();
goto done;
@@ -1241,7 +1251,7 @@ cmd_diff(int argc, char *argv[])
if (error)
goto done;
- view = open_view(0, 0, 0, 0);
+ view = open_view(0, 0, 0, 0, NULL);
if (view == NULL) {
error = got_error_from_errno();
goto done;
@@ -1844,7 +1854,7 @@ show_blame_view(struct tog_view *view, const char *path,
break;
if (pobj == NULL && obj == NULL)
break;
- diff_view = open_view(0, 0, 0, 0);
+ diff_view = open_view(0, 0, 0, 0, view);
if (diff_view == NULL) {
err = got_error_from_errno();
break;
@@ -1978,7 +1988,7 @@ cmd_blame(int argc, char *argv[])
if (error != NULL)
goto done;
- view = open_view(0, 0, 0, 0);
+ view = open_view(0, 0, 0, 0, NULL);
if (view == NULL) {
error = got_error_from_errno();
goto done;
@@ -2300,7 +2310,7 @@ show_tree_view(struct tog_view *view, struct got_tree_object *root,
case 'l':
if (selected_entry) {
struct tog_view *log_view;
- log_view = open_view(0, 0, 0, 0);
+ log_view = open_view(0, 0, 0, 0, view);
if (log_view == NULL) {
err = got_error_from_errno();
goto done;
@@ -2392,8 +2402,8 @@ show_tree_view(struct tog_view *view, struct got_tree_object *root,
selected = 0;
first_displayed_entry = NULL;
} else if (S_ISREG(selected_entry->mode)) {
- struct tog_view *blame_view;
- blame_view = open_view(0, 0, 0, 0);
+ struct tog_view *blame_view =
+ open_view(0, 0, 0, 0, view);
if (blame_view == NULL) {
err = got_error_from_errno();
goto done;
@@ -2513,7 +2523,7 @@ cmd_tree(int argc, char *argv[])
if (error != NULL)
goto done;
- view = open_view(0, 0, 0, 0);
+ view = open_view(0, 0, 0, 0, NULL);
if (view == NULL) {
error = got_error_from_errno();
goto done;