adji

Adji's a Decisive and Joyful Internet browser
git clone https://noxz.tech/git/adji.git
Log | Files | Tags | LICENSE

commit: 43854af6415d743f4b94639ce1d58288f7f458c3
parent: 2d591e76234a78b7c415ae53cab46b0eda97109d
author: Chris Noxz <chris@noxz.tech>
date:   Fri, 11 Aug 2023 16:00:34 +0200
add feature for custom external handler keys
Madji.110++++++++++
Mbrowser.c18++++++++++++++++--
Mbrowser.h5+++--
Mconfig.h1+
4 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/adji.1 b/adji.1
@@ -113,6 +113,16 @@ disables the janky and annoying \(lqsmooth scrolling\(rq. If you for some
 reason like it, setting this variable will enable it.
 .TP
 .B
+ADJI_EXTERNAL_HANDLER_KEYS
+A list of keys that, when pressed, executes the external handler script located
+at
+.I ~/.config/adji/exthandler
+while at the same time forwarding the pressed key to handler script. This
+enables the user to define custom keys that is referred to custom functions in
+the handler script. The list of keys should be comma-separated
+(e.g. \(lqA,y,P\(rq).
+.TP
+.B
 ADJI_FIFO_NAME
 .B adji
 implements IPC configurations using named pipes in the file system. According
diff --git a/browser.c b/browser.c
@@ -493,6 +493,17 @@ key_common(struct Client                       *c,
 		);
 		return TRUE;
 	}
+
+	/* check external handler keys */
+	if (cfg[ExternalHandlerKeys].v.b &&
+	    event->keyval < 256 &&
+	    g_strv_contains(
+	        CFG_L(ExternalHandlerKeys), (gchar[]){(gchar)event->keyval, 0}
+	    )) {
+		open_external(c, (gchar)event->keyval);
+		return TRUE;
+	}
+
 	return FALSE;
 }
 
@@ -845,14 +856,17 @@ main_window_setup(void)
 }
 
 void
-open_external(struct Client *c)
+open_external(struct Client *c, const gchar s)
 {
 	char                    b[URI_MAX];         /* command line buffer */
 	gchar                  *p = NULL;           /* external handler path */
 	p = g_build_filename(
 	    g_get_user_config_dir(), __NAME__, CFG_S(ExternalHandlerFile), NULL
 	);
-	sprintf(b, "%s %s &", p, gtk_entry_get_text(GTK_ENTRY(c->entry)));
+	if (s)
+		sprintf(b, "%s %c:%s &", p, s, gtk_entry_get_text(GTK_ENTRY(c->entry)));
+	else
+		sprintf(b, "%s %s &", p, gtk_entry_get_text(GTK_ENTRY(c->entry)));
 	g_free(p);
 
 	system(b);
diff --git a/browser.h b/browser.h
@@ -127,6 +127,7 @@ enum config_name {
 	DownloadDirectory,
 	EncryptedMedia,
 	ExternalHandlerFile,
+	ExternalHandlerKeys,
 	FifoName,
 	HistoryFile,
 	HomeUri,
@@ -225,7 +226,7 @@ static void load_state(void);
 static void load_stdin(void);
 static void load_user_styles(WebKitWebView *);
 static void main_window_setup(void);
-static void open_external(struct Client *);
+static void open_external(struct Client *, const gchar);
 static void prepare_download(WebKitDownload *, gchar *);
 static void quit(void);
 static void render_tls_error(struct Client *, gchar *, GTlsCertificate *,
@@ -437,7 +438,7 @@ cb_open_external(GSimpleAction                 *action,
 	(void)action;
 	(void)parameter;
 
-	open_external((struct Client *)data);
+	open_external((struct Client *)data, 0);
 	return FALSE;
 }
 
diff --git a/config.h b/config.h
@@ -35,6 +35,7 @@ static Config cfg[LastConfig] = {
 	[DownloadDirectory]     = { __NAME_UPPERCASE__"_DOWNLOAD_DIR",              NULL,                                       CFG_STRING, FALSE, {.s = "/var/tmp" }},
 	[EncryptedMedia]        = { NULL,                                           "enable-encrypted-media",                   CFG_BOOL,   FALSE, {.b = FALSE }},
 	[ExternalHandlerFile]   = { NULL,                                           NULL,                                       CFG_STRING, FALSE, {.s = "exthandler" }},
+	[ExternalHandlerKeys]   = { __NAME_UPPERCASE__"_EXTERNAL_HANDLER_KEYS",     NULL,                                       CFG_LIST,   FALSE, {.l = NULL }},
 	[FifoName]              = { __NAME_UPPERCASE__"_FIFO_NAME",                 NULL,                                       CFG_STRING, FALSE, {.s = "default" }},
 	[HistoryFile]           = { __NAME_UPPERCASE__"_HISTORY_FILE",              NULL,                                       CFG_STRING, FALSE, {.s = NULL }},
 	[HomeUri]               = { __NAME_UPPERCASE__"_HOME_URI",                  NULL,                                       CFG_STRING, FALSE, {.s = "about:blank" }},