commit: 25a012501935d75b91a2e58240a66b084ae3cef7
parent: ca033900b0bd276d7c4b758b8bff5807f6af8957
author: Chris Noxz <chris@noxz.tech>
date: Thu, 28 Dec 2023 17:50:41 +0100
enable opening downloads using xdg-open
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/browser.c b/browser.c
@@ -918,7 +918,7 @@ prepare_download(WebKitDownload *d,
CB(d, "notify::estimated-progress", cb_download_changed_progress, b);
CB(d, "finished", cb_download_finished, b);
g_object_ref(d);
- CB(b, "clicked", cb_download_cancel, d);
+ CB(b, "button-press-event", cb_download_press, d);
} else { /* could not find a free suffix under the SUFFIX_MAX limit */
fprintf(stderr, __NAME__": Limit reached for filename suffix\n");
webkit_download_cancel(d);
@@ -989,8 +989,8 @@ render_tls_error(struct Client *c,
g_free(h);
g_free(s);
g_free(i);
- g_free(a);
g_free(b);
+ g_free(a);
g_free(p);
g_date_time_unref(ad);
g_date_time_unref(bd);
diff --git a/browser.h b/browser.h
@@ -257,7 +257,7 @@ static void xdg_open(const gchar *, const gchar *);
/* callback functions */
static gboolean cb_context_menu(WebKitWebView *, WebKitContextMenu *,
GdkEvent *, WebKitHitTestResult *, gpointer);
-static void cb_download_cancel(GtkWidget *, gpointer);
+static void cb_download_press(GtkWidget *, GdkEventButton *, gpointer);
static void cb_download_changed_progress(GObject *, GParamSpec *, gpointer);
static void cb_download_finished(GObject *, gpointer);
static gboolean cb_download_prepare(WebKitDownload *, gchar *, gpointer);
@@ -307,13 +307,21 @@ cb_context_menu(WebKitWebView *web_view,
}
void
-cb_download_cancel(GtkWidget *btn,
- gpointer data)
+cb_download_press(GtkWidget *btn,
+ GdkEventButton *event,
+ gpointer data)
{
- if (!(*((gboolean*)g_object_get_data(G_OBJECT(btn), __NAME__"-finished"))))
- webkit_download_cancel(WEBKIT_DOWNLOAD(data));
- g_object_unref(WEBKIT_DOWNLOAD(data));
- gtk_widget_destroy(btn);
+ switch (event->button) {
+ case 2: /* middle button: cancel and/or remove */
+ if (!(*((gboolean*)g_object_get_data(G_OBJECT(btn), __NAME__"-finished"))))
+ webkit_download_cancel(WEBKIT_DOWNLOAD(data));
+ g_object_unref(WEBKIT_DOWNLOAD(data));
+ gtk_widget_destroy(btn);
+ break;
+ case 1: /* left click: open downloaded file */
+ xdg_open("", webkit_download_get_destination(WEBKIT_DOWNLOAD(data)));
+ break;
+ }
}
void