summaryrefslogtreecommitdiffstats
path: root/src/tab.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tab.c')
-rw-r--r--src/tab.c97
1 files changed, 91 insertions, 6 deletions
diff --git a/src/tab.c b/src/tab.c
index 7ad667c..80d3972 100644
--- a/src/tab.c
+++ b/src/tab.c
@@ -28,6 +28,15 @@
#include "tab-body.h"
static void
+foreach_tab(MqTab *node, void (*cb)(MqTab *node))
+{
+ for (; node; node = node->next) {
+ cb(node);
+ foreach_tab(node->first_child, cb);
+ }
+}
+
+static void
update_tab_image(MqTab *tab, GdkPixbuf *favicon)
{
if (favicon) {
@@ -41,9 +50,11 @@ update_tab_image(MqTab *tab, GdkPixbuf *favicon)
static void
update_tab_label(MqTab *tab)
{
- gchar *label;
+ const gchar *title;
+ gchar *label;
- label = g_strdup_printf("%d. %s", tab->position, tab->title);
+ title = tab->scrolling ? tab->scrolled_title : tab->title;
+ label = g_strdup_printf("%d. %s", tab->position, title);
gtk_label_set_text(GTK_LABEL(tab->tab_label), label);
gtk_widget_set_tooltip_text(tab->tab, label);
g_free(label);
@@ -403,6 +414,9 @@ title_cb(WebKitWebView __attribute__((unused)) *web_view,
GParamSpec __attribute__((unused)) *paramspec, MqTab *tab)
{
tab->title = webkit_web_view_get_title(tab->web_view);
+ if (tab->scrolling) {
+ tab->scrolled_title = g_strdup_printf("%s ", tab->title);
+ }
update_tab_label(tab);
mq_window_update_tab_title(tab->window, tab->position, tab->title);
}
@@ -439,6 +453,47 @@ init_non_root(const gchar *uri)
return tab;
}
+static void
+scroll_tab_label(MqTab *tab)
+{
+ gchar c;
+ guint i;
+
+ /* Save the first character. */
+ c = tab->scrolled_title[0];
+
+ /* Shift all characters. */
+ for (i = 1; tab->scrolled_title[i]; ++i) {
+ tab->scrolled_title[i - 1] = tab->scrolled_title[i];
+ }
+
+ /* Set the last character. */
+ tab->scrolled_title[i - 1] = c;
+
+ update_tab_label(tab);
+}
+
+static void
+begin_scrolling_tab_label(MqTab *tab)
+{
+ PangoFontDescription *font_desc;
+
+ tab->scrolling = TRUE;
+ tab->scrolled_title = g_strdup_printf("%s ", tab->title);
+
+ font_desc = pango_font_description_new();
+ pango_font_description_set_family_static(font_desc, "monospace");
+ gtk_widget_override_font(tab->tab_label, font_desc);
+}
+
+static void
+end_scrolling_tab_label(MqTab *tab)
+{
+ tab->scrolling = FALSE;
+
+ gtk_widget_override_font(tab->tab_label, NULL);
+}
+
MqTab *
mq_tab_new(const gchar *uri, MqTab *source)
{
@@ -446,11 +501,17 @@ mq_tab_new(const gchar *uri, MqTab *source)
tab = init_non_root(uri);
- append_sibling(tab, source);
-
tab->window = source->window;
tab->application = mq_window_get_application(tab->window);
+ if (mq_application_marquee_mode_on(tab->application)) {
+ begin_scrolling_tab_label(tab);
+ } else {
+ tab->scrolling = FALSE;
+ }
+
+ append_sibling(tab, source);
+
mq_window_insert_tab(tab->window, tab->container, tab->tab,
tab->position);
@@ -464,11 +525,17 @@ mq_tab_new_relative(const gchar *uri, MqTab *source)
tab = init_non_root(uri);
- append_child(tab, source);
-
tab->window = source->window;
tab->application = mq_window_get_application(tab->window);
+ if (mq_application_marquee_mode_on(tab->application)) {
+ begin_scrolling_tab_label(tab);
+ } else {
+ tab->scrolling = FALSE;
+ }
+
+ append_child(tab, source);
+
mq_window_insert_tab(tab->window, tab->container, tab->tab,
tab->position);
@@ -533,3 +600,21 @@ mq_tab_seek(MqTab *node, guint position)
/* Recurse down the subtree. */
return mq_tab_seek(node->first_child, position);
}
+
+void
+mq_tab_scroll_tab_labels(MqTab *root)
+{
+ foreach_tab(root->first_child, scroll_tab_label);
+}
+
+void
+mq_tab_begin_scrolling_tab_labels(MqTab *root)
+{
+ foreach_tab(root->first_child, begin_scrolling_tab_label);
+}
+
+void
+mq_tab_end_scrolling_tab_labels(MqTab *root)
+{
+ foreach_tab(root->first_child, end_scrolling_tab_label);
+}