st-openclipboard-20190202-3be4cf1.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       st-openclipboard-20190202-3be4cf1.diff (1692B)
       ---
            1 From 8a3e3d9f0de95c55321761e2763cf43666da312d Mon Sep 17 00:00:00 2001
            2 From: Michael Buch <michaelbuch12@gmail.com>
            3 Date: Sat, 2 Feb 2019 14:52:56 +0000
            4 Subject: [PATCH] Add ability to open clipboard with configured program
            5 
            6 ---
            7  config.def.h |  1 +
            8  st.h         |  1 +
            9  x.c          | 19 +++++++++++++++++++
           10  3 files changed, 21 insertions(+)
           11 
           12 diff --git a/config.def.h b/config.def.h
           13 index 0e01717..c273252 100644
           14 --- a/config.def.h
           15 +++ b/config.def.h
           16 @@ -178,6 +178,7 @@ static Shortcut shortcuts[] = {
           17          { TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
           18          { ShiftMask,            XK_Insert,      selpaste,       {.i =  0} },
           19          { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
           20 +        { MODKEY,               XK_o,           opencopied,     {.v = "xdg-open"} },
           21  };
           22  
           23  /*
           24 diff --git a/st.h b/st.h
           25 index 38c61c4..a0d7a83 100644
           26 --- a/st.h
           27 +++ b/st.h
           28 @@ -80,6 +80,7 @@ void die(const char *, ...);
           29  void redraw(void);
           30  void draw(void);
           31  
           32 +void opencopied(const Arg *);
           33  void printscreen(const Arg *);
           34  void printsel(const Arg *);
           35  void sendbreak(const Arg *);
           36 diff --git a/x.c b/x.c
           37 index 0422421..af75e85 100644
           38 --- a/x.c
           39 +++ b/x.c
           40 @@ -1953,3 +1953,22 @@ run:
           41  
           42          return 0;
           43  }
           44 +
           45 +void
           46 +opencopied(const Arg *arg)
           47 +{
           48 +        size_t const max_cmd = 2048;
           49 +        char * const clip = xsel.clipboard;
           50 +        if(!clip) {
           51 +                fprintf(stderr, "Warning: nothing copied to clipboard\n");
           52 +                return;
           53 +        }
           54 +
           55 +        /* account for space/quote (3) and \0 (1) and & (1) */
           56 +        /* e.g.: xdg-open "https://st.suckless.org"& */
           57 +        size_t const cmd_size = max_cmd + strlen(clip) + 5;
           58 +        char cmd[cmd_size];
           59 +
           60 +        snprintf(cmd, cmd_size, "%s \"%s\"&", (char *)arg->v, clip);
           61 +        system(cmd);
           62 +}
           63 -- 
           64 2.20.1
           65