st-openclipboard-20190202-0.8.1.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-0.8.1.diff (1652B)
       ---
            1 From b57f6899b277265f19b6ec94d8c476991f452bc7 Mon Sep 17 00:00:00 2001
            2 From: Michael Buch <michaelbuch12@gmail.com>
            3 Date: Sat, 2 Feb 2019 15:07:21 +0000
            4 Subject: [PATCH] 0.8.1 port
            5 
            6 ---
            7  config.def.h |  1 +
            8  st.h         |  1 +
            9  x.c          | 23 +++++++++++++++++++++++
           10  3 files changed, 25 insertions(+)
           11 
           12 diff --git a/config.def.h b/config.def.h
           13 index 82b1b09..83627db 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          { TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
           19          { TERMMOD,              XK_I,           iso14755,       {.i =  0} },
           20 +        { MODKEY,               XK_o,           opencopied,     {.v = "xdg-open"} },
           21  };
           22  
           23  /*
           24 diff --git a/st.h b/st.h
           25 index dac64d8..762938e 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 iso14755(const Arg *);
           34  void printscreen(const Arg *);
           35  void printsel(const Arg *);
           36 diff --git a/x.c b/x.c
           37 index c343ba2..3dfe122 100644
           38 --- a/x.c
           39 +++ b/x.c
           40 @@ -1950,3 +1950,26 @@ run:
           41  
           42          return 0;
           43  }
           44 +
           45 +void
           46 +opencopied(const Arg *arg)
           47 +{
           48 +        const size_t max_cmd = 2048;
           49 +        const char *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 +        char cmd[max_cmd + strlen(clip) + 5];
           57 +        strncpy(cmd, (char *)arg->v, max_cmd);
           58 +        cmd[max_cmd] = '\0';
           59 +
           60 +        strcat(cmd, " \"");
           61 +        strcat(cmd, clip);
           62 +        strcat(cmd, "\"");
           63 +        strcat(cmd, "&");
           64 +
           65 +        system(cmd);
           66 +}
           67 -- 
           68 2.20.1
           69