From 8d2811c5f9a725960aee703b21c5d8b814feac18 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sat, 10 Jun 2023 20:10:42 -0600 Subject: [PATCH] add max number of tabs --- README.md | 1 + config.h | 1 + rose | Bin 47864 -> 47896 bytes rose.c | 60 ++++++++++++++++++++++++++++++++---------------------- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 7af4db8..171a89e 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ You can also create a rose.desktop file so that it will show up in your desktop - Customize appearance of the browser through css - Built-in rose-mklink script for in-shell static links - Optional adblocking through [wyebadblock](https://github.com/jun7/wyebadblock) +- Max number of tabs (by default 8), configurable. - Plugin system, seeded with: - Libre redirect: Redirect annoying websites to open source frontends - Readability: Strip webpages of unnecessary elements for ease of reading with a custom shortcut diff --git a/config.h b/config.h index d8cb22d..05fad90 100644 --- a/config.h +++ b/config.h @@ -21,6 +21,7 @@ #define ZOOM_VAL .1 /* Zooming value in zoomin/zoomout functions */ #define BG_COLOR "#FEFEFE" /* "FEFEFE", "#1E1E2E" */ #define DEBUG false +#define MAX_NUM_TABS 8 // set to 0 or false if you want unlimited tabs, or look at the relevant rose.c code. typedef enum { goback, diff --git a/rose b/rose index 5c165d2b233aae7e2baee71931daf1e37cdf84cb..8a271d3727621aeba188911f4e56221de704cd7a 100755 GIT binary patch delta 5241 zcmZu#3s_Xu7CvX-h@;{#A|j^Dh$$cvQX-g7ROEQ`aZT~fOTt$Mf}r4|@e47>!+4RM zh1vCO;k{+%_y8(}s7A9}_$akZ$wwVDuc$q+(sTd4_n85|+kD^NYwz{=_gZVOz0aA` z{EMOdS3_x-IDKRITgLKmf&I!iUWjTJ6T>GlF{G3DgfXrIpT;@Iicz9@+kiqY1htwXb;tw(eJ6f(m*qV2dBPM2EhXVsE*-s?z>!Q1I4?Kc{; zr*f^WP4@+LW^Y2nsP zK9h9IsqHx8kU5;u*TCs+a>ryd%zcjJ`i&8*NtIu!_!$W@hl-U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l?nS6&kV{@ZK0S@8*{moBa;QNo+M87 zBuM2DY|Zi4It%C?7BOw8{VAZ*j!L-F_H#}#>T*w_dfq?b9JZb{94uk0|k=Y!Ms@5YAs9xI!sUwI$3^Wlh zf|izCRF-6u2Wx?zdVfpg za*A8BM5dz3d)`eOpY0kJHyD{12e;C4vK+sqjZJg>o};7?Gp92T_J7_r0$~85Hkq!FyFQEsjAQh`Xk7GY8K>cw8TnC+wM}(i3^sICZ zgLs?~kKjEb8}u^XY-WT02v_NSV=r9&0CcKu7#BhPajdn1P6Q1_p_Ss`9}0RAbTVi< zo47DWPGw6MhR79cBgR$iL|g?5xRFHDd%7QHA^-pJC>S1}v< zY_=4AE!(~*K_12~V4TUC(a&Ml;yC#}8&({rMAx!e#eHqhA}0QMn9(iZb>&I_PRd-r z&OVZaHxY?)@gC$^ppr-Km8uYcg+_gxS{qjofWn+aH?{ z%|hfvcM2P!$cb#xx)b;fk+MFM#O}tl`?VS)gocE9NekAWF@qQNXH&GvU0DpD<*Z+`HEP6+Xe2F7<-b?HnIR0!Y z`fxr@WFKPu1Rsy%{Y>7!#{0K+4H8&ec^>U{gVeK4@z=7 zc5U`$U-XD_kKUi*HfB9+yf40%CgE99Z9g3=L@KZ`ZH@;clP;_c$CJSBMH9k qf4BxzB>N^V6zD{EK}BapX$oY;m4kg#cM9%hcC<2C4q?reG5-bakx(W8 diff --git a/rose.c b/rose.c index 5aedc6a..8d7ce42 100644 --- a/rose.c +++ b/rose.c @@ -16,6 +16,7 @@ int LIBRE_REDIRECT_ENABLED = true; int READABILITY_ENABLED = true; int CUSTOM_STYLE_ENABLED = true; int CUSTOM_USER_AGENT = true; +int NUM_TABS = 0; // to enable plugins, // 1. Enable them: @@ -193,13 +194,18 @@ void notebook_append(GtkNotebook* notebook, const char* uri); GtkWidget* handle_create_new_tab(WebKitWebView* self, WebKitNavigationAction* navigation_action, GtkNotebook* notebook) -{ - WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action); - const char* uri = webkit_uri_request_get_uri(uri_request); - printf("Creating new window: %s\n", uri); - notebook_append(notebook, uri); - gtk_notebook_set_show_tabs(notebook, true); - return NULL; +{ + if(NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0){ + WebKitURIRequest* uri_request = webkit_navigation_action_get_request(navigation_action); + const char* uri = webkit_uri_request_get_uri(uri_request); + printf("Creating new window: %s\n", uri); + notebook_append(notebook, uri); + gtk_notebook_set_show_tabs(notebook, true); + return NULL; + } else { + webkit_web_view_run_javascript(notebook_get_webview(notebook), + "alert('Too many tabs, not opening a new one')", NULL, NULL, NULL); + } /* WebKitGTK documentation recommends returning the new webview. * I imagine that this might allow e.g., to go back in a new tab * or generally to keep track of history. @@ -210,27 +216,33 @@ GtkWidget* handle_create_new_tab(WebKitWebView* self, void notebook_append(GtkNotebook* notebook, const char* uri) { - GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window)); - GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen); - GdkRGBA rgba; + if(NUM_TABS < MAX_NUM_TABS || NUM_TABS == 0){ + GdkScreen* screen = gtk_window_get_screen(GTK_WINDOW(window)); + GdkVisual* rgba_visual = gdk_screen_get_rgba_visual(screen); + GdkRGBA rgba; - gdk_rgba_parse(&rgba, BG_COLOR); + gdk_rgba_parse(&rgba, BG_COLOR); - WebKitWebView* view = webview_new(); + WebKitWebView* view = webview_new(); - gtk_widget_set_visual(GTK_WIDGET(window), rgba_visual); - g_signal_connect(view, "load_changed", G_CALLBACK(load_changed), notebook); - g_signal_connect(view, "create", G_CALLBACK(handle_create_new_tab), notebook); + gtk_widget_set_visual(GTK_WIDGET(window), rgba_visual); + g_signal_connect(view, "load_changed", G_CALLBACK(load_changed), notebook); + g_signal_connect(view, "create", G_CALLBACK(handle_create_new_tab), notebook); - int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL); - gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true); - gtk_widget_show_all(GTK_WIDGET(window)); - gtk_widget_hide(GTK_WIDGET(bar)); - webkit_web_view_set_background_color(view, &rgba); - load_uri(view, (uri) ? uri : HOME); - gtk_notebook_set_current_page(notebook, n); - gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-"); - webkit_web_view_set_zoom_level(view, ZOOM); + int n = gtk_notebook_append_page(notebook, GTK_WIDGET(view), NULL); + gtk_notebook_set_tab_reorderable(notebook, GTK_WIDGET(view), true); + gtk_widget_show_all(GTK_WIDGET(window)); + gtk_widget_hide(GTK_WIDGET(bar)); + webkit_web_view_set_background_color(view, &rgba); + load_uri(view, (uri) ? uri : HOME); + gtk_notebook_set_current_page(notebook, n); + gtk_notebook_set_tab_label_text(notebook, GTK_WIDGET(view), "-"); + webkit_web_view_set_zoom_level(view, ZOOM); + NUM_TABS+=1; + } else { + webkit_web_view_run_javascript(notebook_get_webview(notebook), + "alert('Too many tabs, not opening a new one')", NULL, NULL, NULL); + } } void show_bar(GtkNotebook* notebook)