fb964ed6ee97c08db29fcd66ee05e2f2fb1adb8f — Louis Solofrizzo 5 months ago 2a99c26
st: Add open-url patch

Signed-off-by: Louis Solofrizzo <lsolofrizzo@online.net>
3 files changed, 21 insertions(+), 1 deletions(-)

M config.def.h
M st.h
M x.c
M config.def.h => config.def.h +2 -1
@@ 32,7 32,7 @@ *
   * More advanced example: L" `'\"()[]{}"
   */
- wchar_t *worddelimiters = L" `'\"()[]{}:";
+ wchar_t *worddelimiters = L" `'\"()[]{}";
  
  /* selection timeouts (in milliseconds) */
  static unsigned int doubleclicktimeout = 300;


@@ 192,6 192,7 @@ { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
  	{ ShiftMask,            XK_Page_Up,     kscrollup,      {.i = -1} },
  	{ ShiftMask,            XK_Page_Down,   kscrolldown,    {.i = -1} },
+ 	{ MODKEY,               XK_o,           opencopied,     {.v = "xdg-open"} },
  };
  
  /*

M st.h => st.h +1 -0
@@ 87,6 87,7 @@ void printsel(const Arg *);
  void sendbreak(const Arg *);
  void toggleprinter(const Arg *);
+ void opencopied(const Arg *);
  
  int tattrset(int);
  int tisaltscr(void);

M x.c => x.c +18 -0
@@ 2008,3 2008,21 @@   	return 0;
  }
+ 
+ void opencopied(const Arg *arg)
+ {
+        size_t const max_cmd = 2048;
+        char * const clip = xsel.clipboard;
+        if(!clip) {
+                fprintf(stderr, "Warning: nothing copied to clipboard\n");
+                return;
+        }
+ 
+        /* account for space/quote (3) and \0 (1) and & (1) */
+        /* e.g.: xdg-open "https://st.suckless.org"& */
+        size_t const cmd_size = max_cmd + strlen(clip) + 5;
+        char cmd[cmd_size];
+ 
+        snprintf(cmd, cmd_size, "%s \"%s\"&", (char *)arg->v, clip);
+        system(cmd);
+ }