commit: 6ee5839da2515bd3d44f549b10da4363b48ae685
parent c5fca92a08a8a63ad4d746b4d3a44a9cf724ea61
Author: striker.sh <strikersh@disroot.org>
Date: Fri, 5 Feb 2021 20:37:24 +0100
Close tab when releasing middle mouse click
Diffstat:
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/badwolf.c b/badwolf.c
@@ -165,16 +165,23 @@ badwolf_new_tab_box(const gchar *title, struct Client *browser)
GtkWidget *tab_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_name(tab_box, "browser__tabbox");
+
GtkWidget *close =
gtk_button_new_from_icon_name("window-close-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_widget_set_name(close, "browser__tabbox__close");
GtkWidget *label = gtk_label_new(title);
gtk_widget_set_name(label, "browser__tabbox__label");
+ GtkWidget *label_event_box = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(label_event_box), label);
GtkWidget *context_label = gtk_label_new(context_id_str);
gtk_widget_set_name(context_label, "browser__tabbox__context_label");
+ GtkWidget *context_label_event_box = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(context_label_event_box), context_label);
GtkWidget *playing =
gtk_image_new_from_icon_name("audio-volume-high-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_widget_set_name(playing, "browser__tabbox__playing");
+ GtkWidget *playing_event_box = gtk_event_box_new();
+ gtk_container_add(GTK_CONTAINER(playing_event_box), playing);
#ifdef BADWOLF_TAB_BOX_WIDTH
gtk_widget_set_size_request(label, BADWOLF_TAB_BOX_WIDTH, -1);
@@ -188,9 +195,9 @@ badwolf_new_tab_box(const gchar *title, struct Client *browser)
gtk_label_set_single_line_mode(GTK_LABEL(label), TRUE);
gtk_label_set_single_line_mode(GTK_LABEL(context_label), TRUE);
- gtk_box_pack_start(GTK_BOX(tab_box), context_label, TRUE, TRUE, 0);
- gtk_box_pack_start(GTK_BOX(tab_box), playing, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(tab_box), label, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(tab_box), context_label_event_box, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(tab_box), playing_event_box, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(tab_box), label_event_box, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(tab_box), close, FALSE, FALSE, 0);
gtk_button_set_relief(GTK_BUTTON(close), GTK_RELIEF_NONE);
@@ -201,6 +208,9 @@ badwolf_new_tab_box(const gchar *title, struct Client *browser)
gtk_widget_show_all(tab_box);
gtk_widget_set_visible(playing, webkit_web_view_is_playing_audio(browser->webView));
+ gtk_widget_set_events(label, GDK_BUTTON_RELEASE_MASK);
+ g_signal_connect(
+ tab_box, "button-release-event", G_CALLBACK(tab_boxCb_button_release_event), browser);
return tab_box;
}
@@ -863,6 +873,7 @@ new_browser(struct Window *window, const gchar *target_url, struct Client *old_b
browser);
g_signal_connect(browser->webView, "create", G_CALLBACK(WebViewCb_create), browser);
g_signal_connect(browser->webView, "close", G_CALLBACK(WebViewCb_close), browser);
+
g_signal_connect(
browser->webView, "key-press-event", G_CALLBACK(WebViewCb_key_press_event), browser);
g_signal_connect(browser->webView, "scroll-event", G_CALLBACK(WebViewCb_scroll_event), browser);
diff --git a/interface.txt b/interface.txt
@@ -1,5 +1,7 @@
# Badwolf
-- A tablist with a new tab button at the end, right-clicking on the tablist gives you the list in a context-menu format
+- A tablist with a new tab button at the end
+- right-clicking on the tablist gives you the list in a context-menu format
+- middle-clicking on the focused tab closes it
- Each tab contains a Browser View or the Downloads View
## Tab Labels
diff --git a/keybindings.c b/keybindings.c
@@ -190,3 +190,17 @@ main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_
return FALSE;
}
+
+gboolean
+tab_boxCb_button_release_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
+{
+ (void)widget;
+ struct Client *browser = (struct Client *)user_data;
+
+ if(((GdkEventButton *)event)->button == GDK_BUTTON_MIDDLE)
+ {
+ webkit_web_view_try_close(browser->webView);
+ return TRUE;
+ }
+ return FALSE;
+}
diff --git a/keybindings.h b/keybindings.h
@@ -9,4 +9,6 @@ gboolean boxCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user
gboolean commonCb_key_press_event(struct Window *window, GdkEvent *event, struct Client *browser);
gboolean main_windowCb_key_press_event(GtkWidget *widget, GdkEvent *event, gpointer user_data);
gboolean WebViewCb_key_press_event(WebKitWebView *webView, GdkEvent *event, gpointer user_data);
+gboolean tab_boxCb_button_release_event(GtkWidget *widget, GdkEvent *event, gpointer user_data);
+
#endif /* KEYBINDINGS_H_INCLUDED */