Commit ae73d513331b62732d07ebc66affe93d059f4040

Stefan Sperling 2018-09-24T10:53:16

only allow one tog view per type

diff --git a/tog/tog.c b/tog/tog.c
index fbbf952..75e4fb3 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -507,8 +507,17 @@ view_loop(struct tog_view *view)
 				goto done;
 		}
 		if (new_view) {
+			struct tog_view *v, *t;
 			view->focussed = 0;
-			/* TODO: de-duplicate! */
+			/* Only allow one view per type. */
+			TAILQ_FOREACH_SAFE(v, &views, entry, t) {
+				if (v->type != new_view->type)
+					continue;
+				TAILQ_REMOVE(&views, v, entry);
+				err = view_close(v);
+				if (err)
+					goto done;
+			}
 			TAILQ_INSERT_TAIL(&views, new_view, entry);
 			if (new_view->parent) {
 				err = view_set_child(new_view->parent, new_view);