add max number of tabs

This commit is contained in:
NunoSempere 2023-06-10 20:10:42 -06:00
parent 995f455ece
commit 8d2811c5f9
4 changed files with 38 additions and 24 deletions

View File

@ -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

View File

@ -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,

BIN
rose

Binary file not shown.

12
rose.c
View File

@ -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:
@ -194,12 +195,17 @@ GtkWidget* handle_create_new_tab(WebKitWebView* self,
WebKitNavigationAction* navigation_action,
GtkNotebook* notebook)
{
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,6 +216,7 @@ GtkWidget* handle_create_new_tab(WebKitWebView* self,
void notebook_append(GtkNotebook* notebook, const char* uri)
{
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;
@ -231,6 +238,11 @@ void notebook_append(GtkNotebook* notebook, const char* uri)
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)