summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-09-27 03:28:57 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-09-27 03:35:03 (EDT)
commit38a3a8214e80cf5102ead3e25a10b6495215230d (patch)
tree2486c836dd3fd569c443bd45abd6ad197f69cca0 /src
parentdfa5fc5f9dafb5f6c56e543da21d000a7498cfaf (diff)
downloadmarquee-38a3a8214e80cf5102ead3e25a10b6495215230d.zip
marquee-38a3a8214e80cf5102ead3e25a10b6495215230d.tar.gz
marquee-38a3a8214e80cf5102ead3e25a10b6495215230d.tar.bz2
MqTabBody: Handle middle mouse clicks on Web view
Open a targeted link in a new tab or load a URI from the primary clipboard.
Diffstat (limited to 'src')
-rw-r--r--src/tab-body.c54
-rw-r--r--src/tab-body.h1
2 files changed, 55 insertions, 0 deletions
diff --git a/src/tab-body.c b/src/tab-body.c
index 58f3eea..6bf95b1 100644
--- a/src/tab-body.c
+++ b/src/tab-body.c
@@ -418,6 +418,56 @@ context_menu_cb(WebKitWebView __attribute__((unused)) *web_view,
return FALSE;
}
+static void
+clipboard_text_recv_cb(GtkClipboard *clipboard, const gchar *text,
+ MqTabBody *body)
+{
+ webkit_web_view_load_uri(body->web_view, text);
+}
+
+/* This callback is a hack to determine on middle mouse click whether to open a
+ * link in a new tab or to load a URI from the primary clipboard. The WebKit1
+ * API provided webkit_web_view_get_hit_test_result() which would have been
+ * easier. */
+static void
+mouse_target_changed_cb(WebKitWebView __attribute__((unused)) *web_view,
+ WebKitHitTestResult *hit_test_result,
+ guint __attribute__((unused)) modifiers,
+ MqTabBody *body)
+{
+ body->mouse_target_hit_test_result = hit_test_result;
+ g_object_ref(body->mouse_target_hit_test_result);
+}
+
+static gboolean
+button_press_cb(WebKitWebView *web_view, GdkEvent *event, MqTabBody *body)
+{
+ WebKitHitTestResult *hit_test_result;
+ GtkClipboard *clipboard;
+
+ /* Make sure this is a middle mouse button press event. */
+ if (event->type != GDK_BUTTON_PRESS || event->button.button != 2) {
+ return FALSE;
+ }
+
+ hit_test_result = body->mouse_target_hit_test_result;
+
+ if (webkit_hit_test_result_context_is_link(hit_test_result)) {
+ mq_tab_new_relative(
+ webkit_hit_test_result_get_link_uri(hit_test_result),
+ body->tab);
+ } else {
+ clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
+ gtk_clipboard_request_text(clipboard,
+ (GtkClipboardTextReceivedFunc) clipboard_text_recv_cb,
+ body);
+ }
+
+ g_object_unref(hit_test_result);
+
+ return TRUE;
+}
+
MqTabBody *
mq_tab_body_new(MqTab *tab, const gchar *uri)
{
@@ -439,6 +489,10 @@ mq_tab_body_new(MqTab *tab, const gchar *uri)
body->hit_test_result = NULL;
g_signal_connect(body->web_view, "context-menu",
G_CALLBACK(context_menu_cb), body);
+ g_signal_connect(body->web_view, "mouse-target-changed",
+ G_CALLBACK(mouse_target_changed_cb), body);
+ g_signal_connect(body->web_view, "button-press-event",
+ G_CALLBACK(button_press_cb), body);
return body;
}
diff --git a/src/tab-body.h b/src/tab-body.h
index 1e3b3f9..0b75b4c 100644
--- a/src/tab-body.h
+++ b/src/tab-body.h
@@ -34,6 +34,7 @@ struct MqTabBody {
GtkWidget *container;
WebKitWebView *web_view;
WebKitHitTestResult *hit_test_result;
+ WebKitHitTestResult *mouse_target_hit_test_result;
};
MqTabBody *