Adding openurlonclick patch ref. #32

This commit is contained in:
bakkeby 2021-07-07 10:08:43 +02:00
parent b5c196f009
commit ee4cdc8d6e
8 changed files with 91 additions and 2 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the
### Changelog: ### Changelog:
2021-07-07 - Added sixel scrollback and the openurlonclick patch
2021-06-09 - Added the hide terminal cursor patch 2021-06-09 - Added the hide terminal cursor patch
2021-05-16 - Added swapmouse 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-copied-url](https://st.suckless.org/patches/open_copied_url/)
- open contents of the clipboard in a user-defined browser - 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/) - [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 - 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) implemented in most other terminals (e.g libvte, kitty)

View File

@ -22,6 +22,10 @@ int borderperc = 20;
static int borderpx = 2; static int borderpx = 2;
#endif // RELATIVEBORDER_PATCH #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: * What program is execed by st depends of these precedence rules:
* 1: program passed with -e * 1: program passed with -e

58
patch/openurlonclick.c Normal file
View File

@ -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);
}

1
patch/openurlonclick.h Normal file
View File

@ -0,0 +1 @@
static void openUrlOnClick(int col, int row, char* url_opener);

View File

@ -17,6 +17,9 @@
#if KEYBOARDSELECT_PATCH #if KEYBOARDSELECT_PATCH
#include "keyboardselect_x.c" #include "keyboardselect_x.c"
#endif #endif
#if OPENURLONCLICK_PATCH
#include "openurlonclick.c"
#endif
#if RIGHTCLICKTOPLUMB_PATCH #if RIGHTCLICKTOPLUMB_PATCH
#include "rightclicktoplumb_x.c" #include "rightclicktoplumb_x.c"
#endif #endif

View File

@ -17,6 +17,9 @@
#if NETWMICON_PATCH #if NETWMICON_PATCH
#include "netwmicon.h" #include "netwmicon.h"
#endif #endif
#if OPENURLONCLICK_PATCH
#include "openurlonclick.h"
#endif
#if RIGHTCLICKTOPLUMB_PATCH #if RIGHTCLICKTOPLUMB_PATCH
#include "rightclicktoplumb_x.h" #include "rightclicktoplumb_x.h"
#endif #endif

View File

@ -219,6 +219,13 @@
*/ */
#define OPENCOPIED_PATCH 0 #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, /* 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 * 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/ * (e.g libvte, kitty). Specifically it differs from https://st.suckless.org/patches/osc_10_11_12/

12
x.c
View File

@ -710,11 +710,19 @@ brelease(XEvent *e)
if (mouseaction(e, 1)) if (mouseaction(e, 1))
return; return;
#if VIM_BROWSE_PATCH #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); mousesel(e, 1);
#if OPENURLONCLICK_PATCH
openUrlOnClick(evcol(e), evrow(e), url_opener);
#endif // OPENURLONCLICK_PATCH
}
#else #else
if (e->xbutton.button == Button1) if (e->xbutton.button == Button1) {
mousesel(e, 1); mousesel(e, 1);
#if OPENURLONCLICK_PATCH
openUrlOnClick(evcol(e), evrow(e), url_opener);
#endif // OPENURLONCLICK_PATCH
}
#endif // VIM_BROWSE_PATCH #endif // VIM_BROWSE_PATCH
#if RIGHTCLICKTOPLUMB_PATCH #if RIGHTCLICKTOPLUMB_PATCH
else if (e->xbutton.button == Button3) else if (e->xbutton.button == Button3)