diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-09-29 03:09:46 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-09-29 03:09:46 (EDT) |
commit | 08bf27821fe5e1444e993820adb5d874fbe04820 (patch) | |
tree | e1d369c7112a1427c0f20f1b5794bf52d13b4852 | |
parent | 28ebf0ef8595715158b840c6213315efa634bfbd (diff) | |
download | marquee-08bf27821fe5e1444e993820adb5d874fbe04820.zip marquee-08bf27821fe5e1444e993820adb5d874fbe04820.tar.gz marquee-08bf27821fe5e1444e993820adb5d874fbe04820.tar.bz2 |
MARQUEE MODE
Only works on ASCII titles so far. Crashes on UTF-8 titles.
-rw-r--r-- | src/application.c | 46 | ||||
-rw-r--r-- | src/application.h | 12 | ||||
-rw-r--r-- | src/tab.c | 97 | ||||
-rw-r--r-- | src/tab.h | 11 | ||||
-rw-r--r-- | src/window.c | 18 | ||||
-rw-r--r-- | src/window.h | 9 |
6 files changed, 186 insertions, 7 deletions
diff --git a/src/application.c b/src/application.c index d4fa802..531eb53 100644 --- a/src/application.c +++ b/src/application.c @@ -70,3 +70,49 @@ mq_application_delete_window(MqApplication *application, MqWindow *window) gtk_main_quit(); } } + +static gboolean +scroll_tab_labels(MqApplication *application) +{ + GList *item; + + if (application->marquee_mode) { + for (item = application->windows; item; item = item->next) { + mq_window_scroll_tab_labels(item->data); + } + return G_SOURCE_CONTINUE; + } else { + return G_SOURCE_REMOVE; + } +} + +void +mq_application_marquee_mode_activate(MqApplication *application) +{ + GList *item; + + for (item = application->windows; item; item = item->next) { + mq_window_begin_scrolling_tab_labels(item->data); + } + + application->marquee_mode = TRUE; + g_timeout_add(125, (GSourceFunc) scroll_tab_labels, application); +} + +void +mq_application_marquee_mode_deactivate(MqApplication *application) +{ + GList *item; + + for (item = application->windows; item; item = item->next) { + mq_window_end_scrolling_tab_labels(item->data); + } + + application->marquee_mode = FALSE; +} + +gboolean +mq_application_marquee_mode_on(MqApplication *application) +{ + return application->marquee_mode; +} diff --git a/src/application.h b/src/application.h index a4b373c..901fd22 100644 --- a/src/application.h +++ b/src/application.h @@ -29,7 +29,8 @@ typedef struct MqApplication MqApplication; #include "window.h" struct MqApplication { - GList *windows; + GList *windows; + gboolean marquee_mode; }; MqApplication * @@ -44,4 +45,13 @@ mq_application_add_window(MqApplication *application, const gchar **uris); void mq_application_delete_window(MqApplication *application, MqWindow *window); +void +mq_application_marquee_mode_activate(MqApplication *application); + +void +mq_application_marquee_mode_deactivate(MqApplication *application); + +gboolean +mq_application_marquee_mode_on(MqApplication *application); + #endif @@ -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); +} @@ -51,6 +51,8 @@ struct MqTab { const gchar *title; WebKitWebView *web_view; GtkWidget *popover; + gboolean scrolling; + gchar *scrolled_title; }; MqTab * @@ -74,4 +76,13 @@ mq_tab_get_title(MqTab *tab); MqTab * mq_tab_seek(MqTab *node, guint position); +void +mq_tab_scroll_tab_labels(MqTab *root); + +void +mq_tab_begin_scrolling_tab_labels(MqTab *root); + +void +mq_tab_end_scrolling_tab_labels(MqTab *root); + #endif diff --git a/src/window.c b/src/window.c index 7244f1e..aa91f8b 100644 --- a/src/window.c +++ b/src/window.c @@ -147,3 +147,21 @@ mq_window_update_tab_title(MqWindow *window, guint position, const gchar *title) set_title(window, title); } } + +void +mq_window_scroll_tab_labels(MqWindow *window) +{ + mq_tab_scroll_tab_labels(window->root_tab); +} + +void +mq_window_begin_scrolling_tab_labels(MqWindow *window) +{ + mq_tab_begin_scrolling_tab_labels(window->root_tab); +} + +void +mq_window_end_scrolling_tab_labels(MqWindow *window) +{ + mq_tab_end_scrolling_tab_labels(window->root_tab); +} diff --git a/src/window.h b/src/window.h index e5a6314..26d02b3 100644 --- a/src/window.h +++ b/src/window.h @@ -57,4 +57,13 @@ void mq_window_update_tab_title(MqWindow *window, guint position, const gchar *title); +void +mq_window_scroll_tab_labels(MqWindow *window); + +void +mq_window_begin_scrolling_tab_labels(MqWindow *window); + +void +mq_window_end_scrolling_tab_labels(MqWindow *window); + #endif |