summaryrefslogtreecommitdiffstats
path: root/src/tab.c
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-09-24 13:55:09 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-09-24 13:55:09 (EDT)
commit85609f6ae792a5797ee14bb36eda7a41c14d0a33 (patch)
tree4db31a3d0acb8f58d96366589548c310c34cff8d /src/tab.c
parent0cfe967819c1dc21b8697929cee3533013727a24 (diff)
downloadmarquee-85609f6ae792a5797ee14bb36eda7a41c14d0a33.zip
marquee-85609f6ae792a5797ee14bb36eda7a41c14d0a33.tar.gz
marquee-85609f6ae792a5797ee14bb36eda7a41c14d0a33.tar.bz2
MqTab: Add tree manipulation functions
Diffstat (limited to 'src/tab.c')
-rw-r--r--src/tab.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/tab.c b/src/tab.c
index 47d048c..b633344 100644
--- a/src/tab.c
+++ b/src/tab.c
@@ -28,6 +28,67 @@
#include "tab-body.h"
static void
+update_positions(MqTab *node, step)
+{
+ if (node) {
+ node->position += step;
+ update_tab_label(node);
+ if (node->next) {
+ update_positions(node->next);
+ } else if (node->parent && node->parent->next) {
+ update_positions(node->parent->next);
+ }
+ }
+}
+
+static void
+update_tree_sizes(MqTab node, guint step)
+{
+ if (node) {
+ node->tree_size += step;
+ update_tree_sizes(node->parent, step);
+ }
+}
+
+static void
+append_child(MqTab *new_node, MqTab *parent)
+{
+ new_node->parent = parent;
+ new_node->next = NULL;
+ new_node->prev = parent->last_child; /* May be NULL */
+ new_node->first_child = new_node->last_child = NULL;
+ new_node->position = parent->position; /* Will be updated */
+ new_node->tree_size = 0; /* Will be updated */
+ if (parent->last_child) {
+ parent->last_child->next = new_node;
+ } else {
+ parent->first_child = new_node;
+ }
+ parent->last_child = new_node;
+ update_positions(new_node, 1);
+ update_tree_sizes(new_node, 1);
+}
+
+static void
+append_sibling(MqTab *new_node, MqTab *prev_sibling)
+{
+ new_node->parent = prev_sibling->parent;
+ new_node->prev = prev_sibling;
+ new_node->next = prev_sibling->next; /* May be NULL */
+ new_node->first_child = new_node->last_child = NULL;
+ new_node->position = prev_sibling->position; /* Will be updated */
+ new_node->tree_size = 0; /* Will be updated */
+ if (parent->last_child) {
+ parent->last_child->next = new_node;
+ } else {
+ parent->first_child = new_node;
+ }
+ parent->last_child = new_node;
+ update_positions(new_node, 1);
+ update_tree_sizes(new_node, 1);
+}
+
+static void
reload_tab_clicked_cb(GtkWidget __attribute__((unused)) *button, MqTab *tab)
{
webkit_web_view_reload(tab->web_view);