-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for user actions in the link menu
Allows the user to define additional entries in the link menu which will execute the given program/script. Each actions is defined using the "link_action" option. The link URL is stored in the $url enviroment variable and the current page in $origin, so the user can customize how do the handling. Here is a simple example to add three new entries: link_action="Debug variables:echo url=$url origin=$origin" link_action="Open in MPV:mpv $url" link_action="Open in Firefox:firefox $url" The command is spawned in a forked process using the system() call, which uses the shell to expand any variable. In particular, the $url variable is set to the current URL being opened. Fixes: #3
- Loading branch information
Showing
14 changed files
with
233 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ dillo_SOURCES = \ | |
bw.c \ | ||
cookies.c \ | ||
cookies.h \ | ||
actions.c \ | ||
actions.h \ | ||
hsts.c \ | ||
hsts.h \ | ||
auth.c \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* File: actions.c | ||
* | ||
* Copyright (C) 2024 Rodrigo Arias Mallo <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
#include "actions.h" | ||
#include "msg.h" | ||
#include "../dlib/dlib.h" | ||
#include <errno.h> | ||
|
||
static Dlist *link_actions = NULL; | ||
|
||
void | ||
action_parse(char *line) | ||
{ | ||
char *label = strtok(line, ":"); | ||
|
||
if (label == NULL || strlen(label) == 0) { | ||
MSG("Missing action label, ignoring '%s'\n", line); | ||
return; | ||
} | ||
|
||
//MSG("Got label='%s'\n", label); | ||
|
||
char *cmd = strtok(NULL, ""); | ||
|
||
if (cmd == NULL || strlen(cmd) == 0) { | ||
MSG("Missing action command, ignoring '%s'\n", line); | ||
return; | ||
} | ||
|
||
//MSG("Got action label='%s' cmd='%s'\n", label, cmd); | ||
|
||
Action *action = dMalloc(sizeof(Action)); | ||
action->label = dStrdup(label); | ||
action->cmd = dStrdup(cmd); | ||
|
||
dList_append(link_actions, action); | ||
} | ||
|
||
void | ||
a_Actions_init(void) | ||
{ | ||
int n = dList_length(prefs.link_actions); | ||
|
||
link_actions = dList_new(n); | ||
|
||
for (int i = 0; i < n; i++) { | ||
char *line = dList_nth_data(prefs.link_actions, i); | ||
if (line) | ||
action_parse(line); | ||
} | ||
} | ||
|
||
Dlist * | ||
a_Actions_link_get(void) | ||
{ | ||
return link_actions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* File: actions.h | ||
* | ||
* Copyright (C) 2024 Rodrigo Arias Mallo <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
*/ | ||
|
||
#ifndef ACTIONS_H | ||
#define ACTIONS_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif /* __cplusplus */ | ||
|
||
#include "dlib/dlib.h" | ||
|
||
typedef struct { | ||
char *label; | ||
char *cmd; | ||
} Action; | ||
|
||
void a_Actions_init(void); | ||
Dlist *a_Actions_link_get(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif /* __cplusplus */ | ||
#endif /* ACTIONS_H*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters