diff --git a/README.md b/README.md index fcf54db..44d7b6e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Refer to [https://st.suckless.org/](https://st.suckless.org/) for details on the ### Changelog: -2025-02-20 - Added the drag-n-drop patch +2025-02-20 - Added the drag-n-drop and open-selected-text patches 2024-05-31 - Added the anygeometry patch @@ -235,6 +235,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 + - [open-selected-text](https://st.suckless.org/patches/open_selected_text) + - open the selected text using `xdg-open` + - [openurlonclick](https://www.reddit.com/r/suckless/comments/cc83om/st_open_url/) - allows for URLs to be opened directly when you click on them diff --git a/config.def.h b/config.def.h index fb5d57b..3a98fb2 100644 --- a/config.def.h +++ b/config.def.h @@ -401,6 +401,9 @@ static uint forcemousemod = ShiftMask; */ static MouseShortcut mshortcuts[] = { /* mask button function argument release screen */ + #if OPEN_SELECTED_TEXT_PATCH + { ControlMask, Button2, selopen, {.i = 0}, 1 }, + #endif // OPEN_SELECTED_TEXT_PATCH #if CLIPBOARD_PATCH { XK_ANY_MOD, Button2, clippaste, {.i = 0}, 1 }, #else diff --git a/patch/openselectedtext.c b/patch/openselectedtext.c new file mode 100644 index 0000000..42d40e2 --- /dev/null +++ b/patch/openselectedtext.c @@ -0,0 +1,13 @@ +void +selopen(const Arg *dummy) +{ + pid_t chpid; + + if ((chpid = fork()) == 0) { + if (fork() == 0) + execlp("xdg-open", "xdg-open", getsel(), NULL); + exit(1); + } + if (chpid > 0) + waitpid(chpid, NULL, 0); +} diff --git a/patch/openselectedtext.h b/patch/openselectedtext.h new file mode 100644 index 0000000..3dccbc6 --- /dev/null +++ b/patch/openselectedtext.h @@ -0,0 +1,3 @@ +#include + +static void selopen(const Arg *); diff --git a/patch/x_include.c b/patch/x_include.c index 20f083b..5a0ba58 100644 --- a/patch/x_include.c +++ b/patch/x_include.c @@ -38,6 +38,9 @@ #elif NETWMICON_LEGACY_PATCH #include "netwmicon_legacy.c" #endif +#if OPEN_SELECTED_TEXT_PATCH +#include "openselectedtext.c" +#endif #if OPENURLONCLICK_PATCH #include "openurlonclick.c" #endif diff --git a/patch/x_include.h b/patch/x_include.h index fef502d..ed10e8c 100644 --- a/patch/x_include.h +++ b/patch/x_include.h @@ -35,6 +35,9 @@ #if NETWMICON_PATCH || NETWMICON_FF_PATCH || NETWMICON_LEGACY_PATCH #include "netwmicon.h" #endif +#if OPEN_SELECTED_TEXT_PATCH +#include "openselectedtext.h" +#endif #if RIGHTCLICKTOPLUMB_PATCH #include "rightclicktoplumb_x.h" #endif diff --git a/patches.def.h b/patches.def.h index 6f02a04..b340aaa 100644 --- a/patches.def.h +++ b/patches.def.h @@ -306,6 +306,11 @@ */ #define OPENCOPIED_PATCH 0 +/* Open the selected text using xdg-open. + * https://st.suckless.org/patches/open_selected_text/ + */ +#define OPEN_SELECTED_TEXT_PATCH 0 + /* This patch allows for URLs to be opened directly when you click on them. This may not work with * all terminal applications. *