Hi Rodrigo,

> >But, these can be two separate features, with optional external link
> >handlers acting as an override for the built-in handling.  
> 
> Yes, they can be two separate features. I don't have a strong opinion 
> about it yet, I'll have to think about the consequences of having two 
> systems.
> 
> On the other hand, I think we can design a very simple rule language 
> just to model the actions that can later be extended to other more 
> complex rules without breaking the compatibility with previous 
> configurations. This way we cover all uses with a unified syntax.
> 
> The previous examples could be written in ~/.dillo/rulesrc as:
> 
>    action "Open with MPV" shell "mpv $url"
>    action "Open with Feh" shell "feh -- $url"
>    action "Open with Firefox" shell "firefox $url"
> 
> Which only defines a set of available actions, and by default they 
> appear on the link menu as you suggest. I think using a small
> language is a more elegant solution than trying to squeeze the menu
> label and the command in a single dillorc option.
 
I like this approach, but not sure how much I can help with it. 

For now, I have taken the example you gave and made barebones patch to
add an external handler to the link menu. It works quite well for me,
in fact its something I'll probably be using every day. A real time saver.

Its obviously nowhere near as featureful as what you are proposing, but
for the time being, it gets the job done :)

Here is the patch for anyone interested, hopefully not too mangled.
Sent as an attachment as well, just in case.
I haven't gotten around to setting up git send-email yet.


diff -u dillorc.orig dillorc
--- dillorc.orig     Wed Jun 12 21:25:35 2024
+++ dillorc Fri Jun 14 16:37:49 2024
@@ -46,6 +46,9 @@
 # height of the visible page area.
 #scroll_step=100
 
+# Set the external link handler
+#ext_handler="mpv"
+
 #-------------------------------------------------------------------------
 #                           RENDERING SECTION
 #-------------------------------------------------------------------------
diff -u src/orig/menu.cc src/menu.cc
--- src/orig/menu.cc    Fri Jun 14 16:14:55 2024
+++ src/menu.cc Fri Jun 14 16:21:34 2024
@@ -122,6 +122,21 @@
 }
 
 /**
+ * Open URL in external handler
+ */
+static void Menu_open_url_ex_cb(Fl_Widget*, void *user_data)
+{
+   DilloUrl *url = (DilloUrl *)user_data;
+   char str[500];
+   strcpy(str, prefs.ext_handler);
+   strcat(str, " ");
+   strcat(str, URL_STR_(url));
+   strcat(str, "> /dev/null 2>&1 &");
+   puts(str);
+   system(str);
+}
+
+/**
  * Add bookmark
  */
 static void Menu_add_bookmark_cb(Fl_Widget*, void *user_data)
@@ -432,8 +447,8 @@
 
 static Fl_Menu_Item link_menu[] = {
    {"Open link in new tab", 0, Menu_open_url_nt_cb,0,0,0,0,0,0},
-   {"Open link in new window", 0, Menu_open_url_nw_cb,0,FL_MENU_DIVIDER,0,0,
-    0,0},
+   {"Open link in new window", 0, Menu_open_url_nw_cb,0,0,0,0,0,0},
+   {"Open with external", 0, Menu_open_url_ex_cb,0,FL_MENU_DIVIDER,0,0,0,0},
    {"Bookmark this link", 0, Menu_add_bookmark_cb,0,0,0,0,0,0},
    {"Copy link location", 0, Menu_copy_urlstr_cb,0,FL_MENU_DIVIDER,0,0,0,0},
    {"Save link as...", 0, Menu_save_link_cb,0,0,0,0,0,0},
diff -u src/orig/prefs.c src/prefs.c
--- src/orig/prefs.c    Fri Jun 14 16:14:55 2024
+++ src/prefs.c Fri Jun 14 16:24:11 2024
@@ -26,6 +26,7 @@
 #define PREFS_HTTP_REFERER    "host"
 #define PREFS_HTTP_USER_AGENT "Dillo/" VERSION
 #define PREFS_THEME           "none"
+#define PREFS_EXT_HANDLER     "mpv"
 
 /*-----------------------------------------------------------------------------
  * Global Data
@@ -71,6 +72,7 @@
    prefs.http_strict_transport_security = TRUE;
    prefs.http_force_https = FALSE;
    prefs.http_user_agent = dStrdup(PREFS_HTTP_USER_AGENT);
+   prefs.ext_handler = dStrdup(PREFS_EXT_HANDLER);
    prefs.limit_text_width = FALSE;
    prefs.adjust_min_width = TRUE;
    prefs.adjust_table_min_width = TRUE;
@@ -151,6 +153,7 @@
    dFree(prefs.http_proxyuser);
    dFree(prefs.http_referer);
    dFree(prefs.http_user_agent);
+   dFree(prefs.ext_handler);
    dFree(prefs.no_proxy);
    dFree(prefs.save_dir);
    for (i = 0; i < dList_length(prefs.search_urls); ++i)
diff -u src/orig/prefs.h src/prefs.h
--- src/orig/prefs.h    Fri Jun 14 16:14:55 2024
+++ src/prefs.h Fri Jun 14 16:24:44 2024
@@ -45,6 +45,7 @@
    char *http_proxyuser;
    char *http_referer;
    char *http_user_agent;
+   char *ext_handler;
    char *no_proxy;
    DilloUrl *start_page;
    DilloUrl *home;
diff -u src/orig/prefsparser.cc src/prefsparser.cc
--- src/orig/prefsparser.cc     Fri Jun 14 16:14:55 2024
+++ src/prefsparser.cc  Fri Jun 14 16:25:40 2024
@@ -187,6 +187,7 @@
       { "adjust_table_min_width", &prefs.adjust_table_min_width, PREFS_BOOL, 0 
},
       { "load_images", &prefs.load_images, PREFS_BOOL, 0 },
       { "load_background_images", &prefs.load_background_images, PREFS_BOOL, 0 
},
+      { "ext_handler", &prefs.ext_handler, PREFS_STRING, 0 },
       { "load_stylesheets", &prefs.load_stylesheets, PREFS_BOOL, 0 },
       { "middle_click_drags_page", &prefs.middle_click_drags_page,
         PREFS_BOOL, 0 },



mpv is just used as a common example. I'm using this with a custom shell 
script which does some basic parsing and takes various actions depending
on the URL. 


Regards,
Alex
diff -u dillorc.orig dillorc
--- dillorc.orig     Wed Jun 12 21:25:35 2024
+++ dillorc Fri Jun 14 16:37:49 2024
@@ -46,6 +46,9 @@
 # height of the visible page area.
 #scroll_step=100
 
+# Set the external link handler
+#ext_handler="mpv"
+
 #-------------------------------------------------------------------------
 #                           RENDERING SECTION
 #-------------------------------------------------------------------------
diff -u src/orig/menu.cc src/menu.cc
--- src/orig/menu.cc	Fri Jun 14 16:14:55 2024
+++ src/menu.cc	Fri Jun 14 16:21:34 2024
@@ -122,6 +122,21 @@
 }
 
 /**
+ * Open URL in external handler
+ */
+static void Menu_open_url_ex_cb(Fl_Widget*, void *user_data)
+{
+   DilloUrl *url = (DilloUrl *)user_data;
+   char str[500];
+   strcpy(str, prefs.ext_handler);
+   strcat(str, " ");
+   strcat(str, URL_STR_(url));
+   strcat(str, "> /dev/null 2>&1 &");
+   puts(str);
+   system(str);
+}
+
+/**
  * Add bookmark
  */
 static void Menu_add_bookmark_cb(Fl_Widget*, void *user_data)
@@ -432,8 +447,8 @@
 
 static Fl_Menu_Item link_menu[] = {
    {"Open link in new tab", 0, Menu_open_url_nt_cb,0,0,0,0,0,0},
-   {"Open link in new window", 0, Menu_open_url_nw_cb,0,FL_MENU_DIVIDER,0,0,
-    0,0},
+   {"Open link in new window", 0, Menu_open_url_nw_cb,0,0,0,0,0,0},
+   {"Open with external", 0, Menu_open_url_ex_cb,0,FL_MENU_DIVIDER,0,0,0,0},
    {"Bookmark this link", 0, Menu_add_bookmark_cb,0,0,0,0,0,0},
    {"Copy link location", 0, Menu_copy_urlstr_cb,0,FL_MENU_DIVIDER,0,0,0,0},
    {"Save link as...", 0, Menu_save_link_cb,0,0,0,0,0,0},
diff -u src/orig/prefs.c src/prefs.c
--- src/orig/prefs.c	Fri Jun 14 16:14:55 2024
+++ src/prefs.c	Fri Jun 14 16:24:11 2024
@@ -26,6 +26,7 @@
 #define PREFS_HTTP_REFERER    "host"
 #define PREFS_HTTP_USER_AGENT "Dillo/" VERSION
 #define PREFS_THEME           "none"
+#define PREFS_EXT_HANDLER     "mpv"
 
 /*-----------------------------------------------------------------------------
  * Global Data
@@ -71,6 +72,7 @@
    prefs.http_strict_transport_security = TRUE;
    prefs.http_force_https = FALSE;
    prefs.http_user_agent = dStrdup(PREFS_HTTP_USER_AGENT);
+   prefs.ext_handler = dStrdup(PREFS_EXT_HANDLER);
    prefs.limit_text_width = FALSE;
    prefs.adjust_min_width = TRUE;
    prefs.adjust_table_min_width = TRUE;
@@ -151,6 +153,7 @@
    dFree(prefs.http_proxyuser);
    dFree(prefs.http_referer);
    dFree(prefs.http_user_agent);
+   dFree(prefs.ext_handler);
    dFree(prefs.no_proxy);
    dFree(prefs.save_dir);
    for (i = 0; i < dList_length(prefs.search_urls); ++i)
diff -u src/orig/prefs.h src/prefs.h
--- src/orig/prefs.h	Fri Jun 14 16:14:55 2024
+++ src/prefs.h	Fri Jun 14 16:24:44 2024
@@ -45,6 +45,7 @@
    char *http_proxyuser;
    char *http_referer;
    char *http_user_agent;
+   char *ext_handler;
    char *no_proxy;
    DilloUrl *start_page;
    DilloUrl *home;
diff -u src/orig/prefsparser.cc src/prefsparser.cc
--- src/orig/prefsparser.cc	Fri Jun 14 16:14:55 2024
+++ src/prefsparser.cc	Fri Jun 14 16:25:40 2024
@@ -187,6 +187,7 @@
       { "adjust_table_min_width", &prefs.adjust_table_min_width, PREFS_BOOL, 0 },
       { "load_images", &prefs.load_images, PREFS_BOOL, 0 },
       { "load_background_images", &prefs.load_background_images, PREFS_BOOL, 0 },
+      { "ext_handler", &prefs.ext_handler, PREFS_STRING, 0 },
       { "load_stylesheets", &prefs.load_stylesheets, PREFS_BOOL, 0 },
       { "middle_click_drags_page", &prefs.middle_click_drags_page,
         PREFS_BOOL, 0 },
_______________________________________________
Dillo-dev mailing list -- dillo-dev@mailman3.com
To unsubscribe send an email to dillo-dev-le...@mailman3.com

Reply via email to