Browse Source

Mapped Dmenu Paste to C-Shift-V

main
Yiğit Çolakoğlu 4 years ago
parent
commit
bda506ccb5
8 changed files with 186 additions and 17 deletions
  1. +1
    -1
      misc/profile
  2. +0
    -1
      suckless/dmenu/config.h
  3. +15
    -12
      suckless/dmenu/dmenu.c
  4. +16
    -2
      suckless/st/config.h
  5. +92
    -0
      suckless/st/patches/st-externalpipe-0.8.4.diff
  6. +60
    -1
      suckless/st/st.c
  7. +1
    -0
      suckless/st/st.h
  8. +1
    -0
      zsh/aliases

+ 1
- 1
misc/profile View File

@ -14,7 +14,7 @@ export EDITOR=vim
export GOPATH=$HOME/go
export ANDROID_HOME=/home/yigit/Android
export DEFAULT_RECIPIENT="yigitcolakoglu@hotmail.com"
export CM_SYNC_PRIMARY_TO_CLIPBOARD=1
#export CM_SYNC_PRIMARY_TO_CLIPBOARD=1
# Setup PATH
export PATH=$ANDROID_HOME/tools:$PATH


+ 0
- 1
suckless/dmenu/config.h View File

@ -17,7 +17,6 @@ static unsigned int lines = 0;
static int dmx = 10; /* put dmenu at this x offset */
static int dmy = 10; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
static unsigned int dmw = 1900; /* make dmenu this wide */
static char **hpitems = {"firefox-developer-edition", "st"};
/*
* Characters not considered part of a word while deleting words


+ 15
- 12
suckless/dmenu/dmenu.c View File

@ -36,8 +36,9 @@ struct item {
double distance;
};
static int hplength = 0;
static int hplength = 0;
static char **hpitems;
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
@ -65,7 +66,7 @@ static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
static char *(*fstrstr)(const char *, const char *) = strstr;
static char**
tokenize(char *source, const char *delim, int *llen) {
tokenize(char *source, char *delim, int *llen) {
int listlength = 0;
char **list = malloc(1 * sizeof(char*));
char *token = strtok(source, delim);
@ -514,19 +515,16 @@ keypress(XKeyEvent *ev)
case XK_e: ksym = XK_End; break;
case XK_f: ksym = XK_Right; break;
case XK_g: ksym = XK_Escape; break;
case XK_h: ksym = XK_BackSpace; break;
case XK_i: ksym = XK_Tab; break;
case XK_j: /* fallthrough */
case XK_J: /* fallthrough */
case XK_m: /* fallthrough */
case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break;
case XK_n: ksym = XK_Down; break;
case XK_p: ksym = XK_Up; break;
case XK_k: /* delete right */
text[cursor] = '\0';
match();
break;
case XK_V:
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime);
return;
case XK_u: /* delete left */
insert(NULL, 0 - cursor);
break;
@ -536,8 +534,8 @@ keypress(XKeyEvent *ev)
while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
insert(NULL, nextrune(-1) - cursor);
break;
case XK_y: /* paste selection */
case XK_Y:
case XK_Y: /* paste selection */
case XK_y:
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime);
return;
@ -553,6 +551,10 @@ keypress(XKeyEvent *ev)
case XK_bracketleft:
cleanup();
exit(1);
case XK_h: ksym = XK_Up; break;
case XK_j: ksym = XK_Next; break;
case XK_k: ksym = XK_Prior; break;
case XK_l: ksym = XK_Down; break;
default:
return;
}
@ -947,8 +949,9 @@ main(int argc, char *argv[])
colors[SchemeSelHighlight][ColBg] = argv[++i];
else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
colors[SchemeSelHighlight][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-hp"))
else if (!strcmp(argv[i], "-hp")){
hpitems = tokenize(argv[++i], ",", &hplength);
}
else
usage();


+ 16
- 2
suckless/st/config.h View File

@ -192,6 +192,11 @@ static MouseShortcut mshortcuts[] = {
/* Internal keyboard shortcuts. */
#define MODKEY Mod1Mask
#define TERMMOD (ControlMask|ShiftMask)
#define ALTMOD (Mod1Mask|ShiftMask)
static char *openurlcmd[] = { "/bin/sh", "-c", "/home/yigit/.scripts/st-urlhandler -o", "externalpipe", NULL };
static char *copyurlcmd[] = { "/bin/sh", "-c", "/home/yigit/.scripts/st-urlhandler -c", "externalpipe", NULL };
static char *copyoutput[] = { "/bin/sh", "-c", "/home/yigit/.scripts/st-copyout", "externalpipe", NULL };
static unsigned int cursorstyle = 1;
static Rune stcursor = 0x2603; /* snowman (U+2603) */
@ -209,8 +214,17 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_V, clippaste, {.i = 0} },
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
{ TERMMOD, XK_I, iso14755, {.i = 0} },
{ ALTMOD, XK_Num_Lock, numlock, {.i = 0} },
{ ALTMOD, XK_I, iso14755, {.i = 0} },
{ ALTMOD, XK_Up, zoom, {.f = +1} },
{ ALTMOD, XK_Down, zoom, {.f = -1} },
{ ALTMOD, XK_K, zoom, {.f = +1} },
{ ALTMOD, XK_J, zoom, {.f = -1} },
{ ALTMOD, XK_U, zoom, {.f = +2} },
{ ALTMOD, XK_D, zoom, {.f = -2} },
{ MODKEY, XK_l, externalpipe, {.v = openurlcmd } },
{ MODKEY, XK_y, externalpipe, {.v = copyurlcmd } },
{ MODKEY, XK_o, externalpipe, {.v = copyoutput } },
};
/*


+ 92
- 0
suckless/st/patches/st-externalpipe-0.8.4.diff View File

@ -0,0 +1,92 @@
diff --git a/st.c b/st.c
index 76b7e0d..0e9a614 100644
--- a/st.c
+++ b/st.c
@@ -723,8 +723,14 @@ sigchld(int a)
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
- if (pid != p)
+ if (pid != p) {
+ if (p == 0 && wait(&stat) < 0)
+ die("wait: %s\n", strerror(errno));
+
+ /* reinstall sigchld handler */
+ signal(SIGCHLD, sigchld);
return;
+ }
if (WIFEXITED(stat) && WEXITSTATUS(stat))
die("child exited with status %d\n", WEXITSTATUS(stat));
@@ -1926,6 +1932,59 @@ strparse(void)
}
}
+void
+externalpipe(const Arg *arg)
+{
+ int to[2];
+ char buf[UTF_SIZ];
+ void (*oldsigpipe)(int);
+ Glyph *bp, *end;
+ int lastpos, n, newline;
+
+ if (pipe(to) == -1)
+ return;
+
+ switch (fork()) {
+ case -1:
+ close(to[0]);
+ close(to[1]);
+ return;
+ case 0:
+ dup2(to[0], STDIN_FILENO);
+ close(to[0]);
+ close(to[1]);
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
+ perror("failed");
+ exit(0);
+ }
+
+ close(to[0]);
+ /* ignore sigpipe for now, in case child exists early */
+ oldsigpipe = signal(SIGPIPE, SIG_IGN);
+ newline = 0;
+ for (n = 0; n < term.row; n++) {
+ bp = term.line[n];
+ lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
+ if (lastpos < 0)
+ break;
+ end = &bp[lastpos + 1];
+ for (; bp < end; ++bp)
+ if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
+ break;
+ if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
+ continue;
+ if (xwrite(to[1], "\n", 1) < 0)
+ break;
+ newline = 0;
+ }
+ if (newline)
+ (void)xwrite(to[1], "\n", 1);
+ close(to[1]);
+ /* restore */
+ signal(SIGPIPE, oldsigpipe);
+}
+
void
strdump(void)
{
diff --git a/st.h b/st.h
index 3d351b6..392b64e 100644
--- a/st.h
+++ b/st.h
@@ -81,6 +81,7 @@ void die(const char *, ...);
void redraw(void);
void draw(void);
+void externalpipe(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);

+ 60
- 1
suckless/st/st.c View File

@ -723,8 +723,14 @@ sigchld(int a)
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
if (pid != p)
if (pid != p) {
if (p == 0 && wait(&stat) < 0)
die("wait: %s\n", strerror(errno));
/* reinstall sigchld handler */
signal(SIGCHLD, sigchld);
return;
}
if (WIFEXITED(stat) && WEXITSTATUS(stat))
die("child exited with status %d\n", WEXITSTATUS(stat));
@ -1939,6 +1945,59 @@ strparse(void)
}
}
void
externalpipe(const Arg *arg)
{
int to[2];
char buf[UTF_SIZ];
void (*oldsigpipe)(int);
Glyph *bp, *end;
int lastpos, n, newline;
if (pipe(to) == -1)
return;
switch (fork()) {
case -1:
close(to[0]);
close(to[1]);
return;
case 0:
dup2(to[0], STDIN_FILENO);
close(to[0]);
close(to[1]);
execvp(((char **)arg->v)[0], (char **)arg->v);
fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
perror("failed");
exit(0);
}
close(to[0]);
/* ignore sigpipe for now, in case child exists early */
oldsigpipe = signal(SIGPIPE, SIG_IGN);
newline = 0;
for (n = 0; n < term.row; n++) {
bp = term.line[n];
lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
if (lastpos < 0)
break;
end = &bp[lastpos + 1];
for (; bp < end; ++bp)
if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
break;
if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
continue;
if (xwrite(to[1], "\n", 1) < 0)
break;
newline = 0;
}
if (newline)
(void)xwrite(to[1], "\n", 1);
close(to[1]);
/* restore */
signal(SIGPIPE, oldsigpipe);
}
void
strdump(void)
{


+ 1
- 0
suckless/st/st.h View File

@ -82,6 +82,7 @@ void redraw(void);
void draw(void);
void iso14755(const Arg *);
void externalpipe(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);


+ 1
- 0
zsh/aliases View File

@ -26,6 +26,7 @@ alias lights_off="curl 'http://yeetclock/setcolor?R=2000&G=10&B=000&O=0'"
# Git
alias ga="git add"
alias gcl="git clone --recursive"
alias gc="git commit"
alias gcm="git commit -m"
alias gp="git push"


Loading…
Cancel
Save