From c2b4c8fb07b50c064d8ffe5ce02e84e21b6cffaa Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 26 Oct 2020 07:28:06 +0100 Subject: Use [A..Z] instead of [0..F] for representing the context_id --- badwolf.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'badwolf.c') diff --git a/badwolf.c b/badwolf.c index 665f144..0d391e1 100644 --- a/badwolf.c +++ b/badwolf.c @@ -21,7 +21,7 @@ const gchar *homepage = "https://hacktivis.me/projects/badwolf"; const gchar *version = VERSION; static gchar *web_extensions_directory; -static int context_id_counter = 0; +static uint64_t context_id_counter = 0; GtkTreeModel *bookmarks_completion_model; static gboolean WebViewCb_close(WebKitWebView *webView, gpointer user_data); @@ -130,13 +130,36 @@ WebViewCb_notify__uri(WebKitWebView *webView, GParamSpec *pspec, gpointer user_d return TRUE; } +static char * +fmt_context_id(uint64_t num, char *out) +{ + const char alpha_digits[27] = {" ABCDEFGHIJKLMNOPQRSTUVWXYZ"}; + char buf[66] = {'\0'}; + int i, len = 0; + + // Get 0 = 'A' instead of 0 = '' and 1 = 'A' + num++; + + buf[len++] = ' '; + buf[len++] = ':'; + do + { + buf[len++] = alpha_digits[num % 26]; + } while(num /= 26); + + for(i = 0; len > 0; i++) + out[i] = buf[--len]; + + return out; +} + GtkWidget * badwolf_new_tab_box(const gchar *title, struct Client *browser) { (void)browser; - char context_id_str[7]; + char context_id_str[7] = ""; - snprintf(context_id_str, 7, "%4X: ", browser->context_id); + fmt_context_id(browser->context_id, context_id_str); GtkWidget *tab_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_set_name(tab_box, "browser__tabbox"); -- cgit v1.3.1-23-gd82d