From 22d38600d0edbb35029b3076c14e0e119dbf3dd2 Mon Sep 17 00:00:00 2001
From: Ryan Dwyer <ryandwyer1@gmail.com>
Date: Mon, 14 May 2018 22:47:10 +1000
Subject: Implement marks

---
 sway/tree/view.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

(limited to 'sway/tree')

diff --git a/sway/tree/view.c b/sway/tree/view.c
index 8da72667..ec7f3031 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -23,6 +23,7 @@ void view_init(struct sway_view *view, enum sway_view_type type,
 	view->type = type;
 	view->impl = impl;
 	view->executed_criteria = create_list();
+	view->marks = create_list();
 	wl_signal_init(&view->events.unmap);
 }
 
@@ -37,6 +38,11 @@ void view_destroy(struct sway_view *view) {
 
 	list_free(view->executed_criteria);
 
+	for (int i = 0; i < view->marks->length; ++i) {
+		free(view->marks->items[i]);
+	}
+	list_free(view->marks);
+
 	container_destroy(view->swayc);
 
 	if (view->impl->destroy) {
@@ -721,3 +727,46 @@ void view_update_title(struct sway_view *view, bool force) {
 	container_notify_child_title_changed(view->swayc->parent);
 	config_update_font_height(false);
 }
+
+static bool find_by_mark_iterator(struct sway_container *con,
+		void *data) {
+	char *mark = data;
+	return con->type == C_VIEW && view_has_mark(con->sway_view, mark);
+}
+
+bool view_find_and_unmark(char *mark) {
+	struct sway_container *container = container_find(&root_container,
+		find_by_mark_iterator, mark);
+	if (!container) {
+		return false;
+	}
+	struct sway_view *view = container->sway_view;
+
+	for (int i = 0; i < view->marks->length; ++i) {
+		char *view_mark = view->marks->items[i];
+		if (strcmp(view_mark, mark) == 0) {
+			free(view_mark);
+			list_del(view->marks, i);
+			return true;
+		}
+	}
+	return false;
+}
+
+void view_clear_marks(struct sway_view *view) {
+	for (int i = 0; i < view->marks->length; ++i) {
+		free(view->marks->items[i]);
+	}
+	list_free(view->marks);
+	view->marks = create_list();
+}
+
+bool view_has_mark(struct sway_view *view, char *mark) {
+	for (int i = 0; i < view->marks->length; ++i) {
+		char *item = view->marks->items[i];
+		if (strcmp(item, mark) == 0) {
+			return true;
+		}
+	}
+	return false;
+}
-- 
cgit v1.2.3