adji

Adji's a Decisive and Joyful Internet browser
git clone https://noxz.tech/git/adji.git
adji

commit: 810c9f1d7b82d89a39cf7e377c689bd7f32ec4ea
parent: d93ca09078807233810c80803984684f25a373c5
author: Chris Noxz <chris@noxz.tech>
date:   Wed, 22 Mar 2023 13:32:58 +0100
modify context menu

* Add feature to open page externally if no other context than document exists.
* Move additional context menu items to top by prepending them.
* Add separator between new context menu items and existing ones.
Mbrowser.c32++++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/browser.c b/browser.c
@@ -232,6 +232,28 @@ create_context_menu(struct Client              *c,
 
 	x = webkit_hit_test_result_get_context(hit_test_result);
 
+	webkit_context_menu_prepend(
+	    context_menu, webkit_context_menu_item_new_separator()
+	);
+
+	/* if document is the only context */
+	if (x == WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT) {
+		CB(
+		    (a = (GAction*)g_simple_action_new("open-external", NULL)),
+		    "activate",
+		    cb_open_external,
+		    c
+		);
+		webkit_context_menu_prepend(
+		    context_menu,
+		    webkit_context_menu_item_new_from_gaction(
+		        a, "Open Page Externally", NULL
+		    )
+		);
+		g_object_unref(a);
+		return; /* no need to check further */
+	}
+
 	if (x & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
 		CB(
 		    (a = (GAction*)g_simple_action_new("open-external", NULL)),
@@ -239,12 +261,11 @@ create_context_menu(struct Client              *c,
 		    cb_open_external,
 		    c
 		);
-		webkit_context_menu_insert(
+		webkit_context_menu_prepend(
 		    context_menu,
 		    webkit_context_menu_item_new_from_gaction(
 		        a, "Open Link Externally", NULL
-		    ),
-		    2
+		    )
 		);
 		g_object_unref(a);
 	}
@@ -259,12 +280,11 @@ create_context_menu(struct Client              *c,
 		    cb_selection_search,
 		    c
 		);
-		webkit_context_menu_insert(
+		webkit_context_menu_prepend(
 		    context_menu,
 		    webkit_context_menu_item_new_from_gaction(
 		        a, "Search Selection", NULL
-		    ),
-		    x & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK ? 3 : 1
+		    )
 		);
 		g_object_unref(a);
 	}