diff options
-rw-r--r-- | doc/dwb.1 | 16 | ||||
-rw-r--r-- | doc/dwb.1.txt | 6 | ||||
-rw-r--r-- | m4/settings.m4 | 1 | ||||
-rw-r--r-- | src/callback.c | 16 | ||||
-rw-r--r-- | src/callback.h | 3 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/dwb.c | 83 | ||||
-rw-r--r-- | src/dwb.h | 3 | ||||
-rw-r--r-- | src/view.c | 1 |
9 files changed, 127 insertions, 4 deletions
@@ -2,12 +2,12 @@ .\" Title: dwb .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.78.0 <http://docbook.sf.net/> -.\" Date: 04/15/2013 +.\" Date: 04/16/2013 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "DWB" "1" "04/15/2013" "\ \&" "\ \&" +.TH "DWB" "1" "04/16/2013" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -3465,6 +3465,18 @@ The maximum number of visible completions, default value: \fI11\fR\&. .RE .PP +\fBmaximum\-tabs\fR +.RS 4 +Limits the maximum number of visible tabs, 0 means no limit\&. If +\fItab\-orientation\fR +is set to +\fIvertical\-left\fR +or +\fIvertical\-right\fR +the number of maximum tabs is computed automatically and maximum\-tabs will be ignored, default value: +\fI0\fR\&. +.RE +.PP \fBmessage\-delay\fR .RS 4 The duration messages are shown\&. Possible values: duration in seconds (integer), default value: diff --git a/doc/dwb.1.txt b/doc/dwb.1.txt index 5dd3e48f..5df09738 100644 --- a/doc/dwb.1.txt +++ b/doc/dwb.1.txt @@ -1436,6 +1436,12 @@ useful on startup and with slow internet connections, default value: 'false'. *max-visible-completions*:: The maximum number of visible completions, default value: '11'. +*maximum-tabs*:: +Limits the maximum number of visible tabs, 0 means no limit. If +'tab-orientation' is set to 'vertical-left' or 'vertical-right' the number of +maximum tabs is computed automatically and maximum-tabs will be ignored, default +value: '0'. + *message-delay*:: The duration messages are shown. Possible values: duration in seconds (integer), default value: '2'. diff --git a/m4/settings.m4 b/m4/settings.m4 index c9822059..76c801ab 100644 --- a/m4/settings.m4 +++ b/m4/settings.m4 @@ -93,6 +93,7 @@ html_input(enable-favicon, checkbox, Whether to enable favicons in the tabbar) html_input(enable-frame-flattening, checkbox, Whether to enable frame flattening) html_input(enforce-96-dpi, checkbox, Enforce a resolution of 96 dpi) html_input(factor, text, Zoom factor of the tiling area) +html_input(maximum-tabs, text, ``Limits the number of visible tabs, 0 means no limit'') html_input(message-delay, text, ``Time messages are shown, in seconds'') html_select(new-tab-position-policy, html_options(right, left, rightmost, leftmost), Controls the position of newly created tabs) html_select(progress-bar-style, html_options(default, simple), The progress bar style) diff --git a/src/callback.c b/src/callback.c index 524635b7..40f54b29 100644 --- a/src/callback.c +++ b/src/callback.c @@ -286,4 +286,20 @@ callback_dns_resolve(SoupAddress *address, guint status, GList *gl) g_free(v->status->request_uri); v->status->request_uri = NULL; } +#ifndef _HAS_GTK3 +void +callback_tab_container_heigth(GtkWidget *tabcontainer, GdkRectangle *rect, gpointer data) +{ + GtkAllocation a; + if (dwb.state.views) + { + gtk_widget_get_allocation(VIEW(dwb.state.views)->tabevent, &a); + if (rect->height > 0 && a.height > 0) + { + // also add 1px padding + dwb_limit_tabs(rect->height / (a.height+1)); + } + } +} +#endif #endif diff --git a/src/callback.h b/src/callback.h index 888b9547..4cb8d0d2 100644 --- a/src/callback.h +++ b/src/callback.h @@ -26,4 +26,7 @@ gboolean callback_delete_event(GtkWidget *w); gboolean callback_key_press(GtkWidget *w, GdkEventKey *e); gboolean callback_key_release(GtkWidget *w, GdkEventKey *e); void callback_dns_resolve(SoupAddress *address, guint status, GList *gl); +#if !_HAS_GTK3 +void callback_tab_container_heigth(GtkWidget *tabcontainer, GtkAllocation *alloc, gpointer data); +#endif #endif diff --git a/src/config.h b/src/config.h index 945788c1..56243c48 100644 --- a/src/config.h +++ b/src/config.h @@ -1197,6 +1197,8 @@ static WebSettings DWB_SETTINGS[] = { #endif { { "mouse-cycles-through-tabs", "Whether mouse scroll wheel cycles through tabs", }, SETTING_GLOBAL, BOOLEAN, { .b = true }, NULL, { 0 }, }, + { { "maximum-tabs", "Maximum number of tabs", }, + SETTING_GLOBAL | SETTING_ONINIT, INTEGER, { .i = 0 }, (S_Func)dwb_set_max_tabs, { 0 }, }, //{ { "javascript-debugging", "If set will be used for 'Accept-Language' header in all requests", }, // SETTING_GLOBAL | SETTING_ONINIT, BOOLEAN, { .b = false }, (S_Func)dwb_set_javascript_debugging, { 0 }, }, };/*}}}*/ @@ -77,6 +77,7 @@ static DwbStatus dwb_set_cookie_accept_policy(GList *, WebSettings *); static DwbStatus dwb_set_favicon(GList *, WebSettings *); static DwbStatus dwb_set_auto_insert_mode(GList *, WebSettings *); static DwbStatus dwb_set_tabbar_delay(GList *, WebSettings *); +static DwbStatus dwb_set_max_tabs(GList *, WebSettings *); static DwbStatus dwb_set_close_last_tab_policy(GList *, WebSettings *); static DwbStatus dwb_set_ntlm(GList *gl, WebSettings *s); static DwbStatus dwb_set_find_delay(GList *gl, WebSettings *s); @@ -143,6 +144,7 @@ static gboolean dwb_user_script_cb(GIOChannel *channel, GIOCondition condition, static int signals[] = { SIGFPE, SIGILL, SIGINT, SIGQUIT, SIGTERM, SIGALRM, SIGSEGV}; +static int s_tab_allocate_id; /*}}}*/ #include "config.h" @@ -198,15 +200,38 @@ static DwbStatus dwb_set_tab_orientation(GList *gl, WebSettings *s) { if (!g_strcmp0(s->arg_local.p, "horizontal")) + { + if (s_tab_allocate_id != 0) + { + g_signal_handler_disconnect(dwb.gui.tabbox, s_tab_allocate_id); + s_tab_allocate_id = 0; + } + dwb.misc.tab_orientation = TAB_HORIZONTAL; + } else if (!g_strcmp0(s->arg_local.p, "vertical-left")) + { + if (! (s->apply & SETTING_INITIALIZE) && s_tab_allocate_id == 0) + { + s_tab_allocate_id = g_signal_connect(dwb.gui.tabbox, "size-allocate", G_CALLBACK(callback_tab_container_heigth), NULL); + } dwb.misc.tab_orientation = TAB_VERTICAL_LEFT; + } else if (!g_strcmp0(s->arg_local.p, "vertical-right")) + { + if (! (s->apply & SETTING_INITIALIZE) && s_tab_allocate_id == 0) + { + s_tab_allocate_id = g_signal_connect(dwb.gui.tabbox, "size-allocate", G_CALLBACK(callback_tab_container_heigth), NULL); + } dwb.misc.tab_orientation = TAB_VERTICAL_RIGHT; + } else return STATUS_ERROR; if (! (s->apply & SETTING_INITIALIZE)) + { dwb_pack(GET_CHAR("widget-packing"), true); + } + return STATUS_OK; }/*}}}*/ static DwbStatus @@ -507,6 +532,21 @@ dwb_set_tabbar_delay(GList *l, WebSettings *s) dwb.misc.tabbar_delay = s->arg_local.i; return STATUS_OK; }/*}}}*/ +/* dwb_set_tabbar_delay {{{*/ +static DwbStatus +dwb_set_max_tabs(GList *l, WebSettings *s) +{ + if (s->arg_local.i >= 0) + { + dwb.misc.max_tabs = s->arg_local.i; +#ifndef _HAS_GTK3 + if (dwb.misc.tab_orientation == TAB_HORIZONTAL) +#endif + dwb_limit_tabs(dwb.misc.max_tabs); + return STATUS_OK; + } + return STATUS_ERROR; +}/*}}}*/ /* dwb_set_favicon(GList *l, WebSettings *s){{{*/ static DwbStatus @@ -1553,6 +1593,33 @@ dwb_hide_tabbar(int *running) return false; }/*}}}*/ +void +dwb_limit_tabs(gint max) +{ + g_return_if_fail(max > 0); + + int length, n, i = 0; + int m, median; + + length = g_list_length(dwb.state.views); + + if (length == 1) + return; + + m = max/2+1; + median = max % 2 == 0 ? max/2 : m; + n = g_list_position(dwb.state.views, dwb.state.fview); + for (GList *l = dwb.state.views; l; l=l->next, i++) + { + if ((n < median && i<max) || + (n > length-median-1 && i>=length-max) || + (i > n-median && i<n+m)) + gtk_widget_show(VIEW(l)->tabevent); + else + gtk_widget_hide(VIEW(l)->tabevent); + } +} + /* dwb_focus_view(GList *gl){{{*/ gboolean dwb_focus_view(GList *gl, const char *event) @@ -1608,6 +1675,15 @@ dwb_focus_view(GList *gl, const char *event) g_source_remove(running); running = g_timeout_add(dwb.misc.tabbar_delay * 1000, (GSourceFunc)dwb_hide_tabbar, &running); } + if ( + dwb.misc.max_tabs > 0 +#ifndef _HAS_GTK3 + && dwb.misc.tab_orientation == TAB_HORIZONTAL +#endif + ) + { + dwb_limit_tabs(dwb.misc.max_tabs); + } return false; } return true; @@ -4218,6 +4294,8 @@ dwb_pack(const char *layout, gboolean rebuild) gtk_orientable_set_orientation(GTK_ORIENTABLE(dwb.gui.tabcontainer), GTK_ORIENTATION_HORIZONTAL); gtk_box_set_child_packing(GTK_BOX(dwb.gui.tabbox), dwb.gui.tabcontainer, false, false, 0, GTK_PACK_START); gtk_widget_set_size_request(dwb.gui.tabcontainer, -1, -1); + if (dwb.misc.max_tabs > 0) + dwb_limit_tabs(dwb.misc.max_tabs); } else { @@ -4238,7 +4316,8 @@ dwb_pack(const char *layout, gboolean rebuild) #endif gtk_widget_show_all(dwb.gui.statusbox); gtk_widget_set_visible(dwb.gui.bottombox, dwb.state.bar_visible & BAR_VIS_STATUS); - gtk_widget_set_visible(dwb.gui.tabbox, dwb.state.bar_visible & BAR_VIS_TOP); + if ((dwb.state.views && dwb.state.views->next) || dwb.misc.show_single_tab) + gtk_widget_set_visible(dwb.gui.tabbox, dwb.state.bar_visible & BAR_VIS_TOP); return ret; } @@ -4301,6 +4380,8 @@ dwb_init_gui() dwb.gui.dummybox = gtk_vbox_new(true, 1); dwb.gui.tabbox = gtk_vbox_new(false, 0); + if (dwb.misc.tab_orientation != TAB_HORIZONTAL) + s_tab_allocate_id = g_signal_connect(dwb.gui.tabbox, "size-allocate", G_CALLBACK(callback_tab_container_heigth), NULL); gtk_box_pack_end(GTK_BOX(dwb.gui.tabbox), dwb.gui.dummybox, true, true, 0); gtk_box_pack_start(GTK_BOX(dwb.gui.tabwrapperbox), dwb.gui.mainbox, true, true, 0); gtk_box_pack_start(GTK_BOX(dwb.gui.tabbox), dwb.gui.tabcontainer, false, false, 0); @@ -813,6 +813,7 @@ struct _Misc { #if ! _HAS_GTK3 TabOrientation tab_orientation; #endif + gint max_tabs; //gboolean javascript_debugging; }; @@ -1017,6 +1018,8 @@ void dwb_init_files(void); void dwb_init_settings(void); void dwb_reload_bookmarks(void); void dwb_reload_quickmarks(void); + +void dwb_limit_tabs(gint max); #if 0 void dwb_hide_tab(GList *gl); void dwb_show_tab(GList *gl); @@ -1897,7 +1897,6 @@ view_add(const char *uri, gboolean background) g_free(json); } - view_init_signals(ret); view_init_settings(ret); if (GET_BOOL("adblocker")) |