commit ee4cdc8d6e8b1463f726178a86b5a575eff8c510
parent b5c196f0095e56b119fe5539ae6bad6c208bd499
Author: bakkeby <bakkeby@gmail.com>
Date: Wed, 7 Jul 2021 10:08:43 +0200
Adding openurlonclick patch ref. #32
Diffstat:
8 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog:
+2021-07-07 - Added sixel scrollback and the openurlonclick patch
+
2021-06-09 - Added the hide terminal cursor patch
2021-05-16 - Added swapmouse patch
@@ -178,6 +180,9 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
- [open-copied-url](https://st.suckless.org/patches/open_copied_url/)
- open contents of the clipboard in a user-defined browser
+ - [openurlonclick](https://www.reddit.com/r/suckless/comments/cc83om/st_open_url/)
+ - allows for URLs to be opened directly when you click on them
+
- [osc_10_11_12_2](https://st.suckless.org/patches/osc_10_11_12_2/)
- this patch adds support for OSC escape sequences 10, 11, and 12 in the way they are
implemented in most other terminals (e.g libvte, kitty)
diff --git a/config.def.h b/config.def.h
@@ -22,6 +22,10 @@ int borderperc = 20;
static int borderpx = 2;
#endif // RELATIVEBORDER_PATCH
+#if OPENURLONCLICK_PATCH
+static char *url_opener = "xdg-open";
+#endif // OPENURLONCLICK_PATCH
+
/*
* What program is execed by st depends of these precedence rules:
* 1: program passed with -e
diff --git a/patch/openurlonclick.c b/patch/openurlonclick.c
@@ -0,0 +1,58 @@
+void
+openUrlOnClick(int col, int row, char* url_opener)
+{
+ int row_start = row;
+ int col_start = col;
+ int row_end = row;
+ int col_end = col;
+
+ if (term.line[row][col].u == ' ')
+ return;
+
+ /* while previous character is not space */
+ while (term.line[row_start][col_start-1].u != ' ') {
+ if (col_start == 0)
+ {
+ // Before moving start pointer to the previous line we check if it ends with space
+ if (term.line[row_start - 1][term.col - 1].u == ' ')
+ break;
+ col_start=term.col - 1;
+ row_start--;
+ } else {
+ col_start--;
+ }
+ }
+
+ /* while next character is not space nor end of line */
+ while (term.line[row_end][col_end].u != ' ') {
+ col_end++;
+ if (col_end == term.col - 1)
+ {
+ if (term.line[row_end + 1][0].u == ' ')
+ break;
+ col_end=0;
+ row_end++;
+ }
+ }
+
+ char url[200] = "";
+ int url_index=0;
+ do {
+ url[url_index] = term.line[row_start][col_start].u;
+ url_index++;
+ col_start++;
+ if (col_start == term.col)
+ {
+ col_start = 0;
+ row_start++;
+ }
+ } while (row_start != row_end || col_start != col_end);
+
+ if (strncmp("http", url, 4) != 0) {
+ return;
+ }
+
+ char command[strlen(url_opener)+1+strlen(url)];
+ sprintf(command, "%s %s", url_opener, url);
+ system(command);
+}
+\ No newline at end of file
diff --git a/patch/openurlonclick.h b/patch/openurlonclick.h
@@ -0,0 +1 @@
+static void openUrlOnClick(int col, int row, char* url_opener);
+\ No newline at end of file
diff --git a/patch/x_include.c b/patch/x_include.c
@@ -17,6 +17,9 @@
#if KEYBOARDSELECT_PATCH
#include "keyboardselect_x.c"
#endif
+#if OPENURLONCLICK_PATCH
+#include "openurlonclick.c"
+#endif
#if RIGHTCLICKTOPLUMB_PATCH
#include "rightclicktoplumb_x.c"
#endif
diff --git a/patch/x_include.h b/patch/x_include.h
@@ -17,6 +17,9 @@
#if NETWMICON_PATCH
#include "netwmicon.h"
#endif
+#if OPENURLONCLICK_PATCH
+#include "openurlonclick.h"
+#endif
#if RIGHTCLICKTOPLUMB_PATCH
#include "rightclicktoplumb_x.h"
#endif
diff --git a/patches.def.h b/patches.def.h
@@ -219,6 +219,13 @@
*/
#define OPENCOPIED_PATCH 0
+/* This patch allows for URLs to be opened directly when you click on them. This may not work with
+ * all terminal applications.
+ *
+ * https://www.reddit.com/r/suckless/comments/cc83om/st_open_url/
+ */
+#define OPENURLONCLICK_PATCH 0
+
/* This patch adds support for OSC escape sequences 10, 11 and 12 that modify the background,
* foreground and cursor colors in the way they are implemented in most other terminals
* (e.g libvte, kitty). Specifically it differs from https://st.suckless.org/patches/osc_10_11_12/
diff --git a/x.c b/x.c
@@ -710,11 +710,19 @@ brelease(XEvent *e)
if (mouseaction(e, 1))
return;
#if VIM_BROWSE_PATCH
- if (e->xbutton.button == Button1 && !IS_SET(MODE_NORMAL))
+ if (e->xbutton.button == Button1 && !IS_SET(MODE_NORMAL)) {
mousesel(e, 1);
+ #if OPENURLONCLICK_PATCH
+ openUrlOnClick(evcol(e), evrow(e), url_opener);
+ #endif // OPENURLONCLICK_PATCH
+ }
#else
- if (e->xbutton.button == Button1)
+ if (e->xbutton.button == Button1) {
mousesel(e, 1);
+ #if OPENURLONCLICK_PATCH
+ openUrlOnClick(evcol(e), evrow(e), url_opener);
+ #endif // OPENURLONCLICK_PATCH
+ }
#endif // VIM_BROWSE_PATCH
#if RIGHTCLICKTOPLUMB_PATCH
else if (e->xbutton.button == Button3)