commit c5fc131fdb8be15b0a418f597d96d4268428d7af
parent c77b27e0d0363e4470eaf32104228ea51d3097d1
Author: hhvn <hayden@haydenvh.com>
Date: Sat, 17 Oct 2020 12:21:54 +0100
Apply newterm patch
Makes usage more comfortable on systems where you can't easily open
duplicate X programs. i,e, maemo-leste.
Diffstat:
4 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,2 +1,4 @@
*.o
+*.orig
+*.rej
st
diff --git a/config.h b/config.h
@@ -179,20 +179,21 @@ static char *dgrep[] = { "/bin/sh", "-c",
static Shortcut shortcuts[] = {
/* mask keysym function argument */
- { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
- { ControlMask, XK_Print, toggleprinter, {.i = 0} },
- { ShiftMask, XK_Print, printscreen, {.i = 0} },
- { XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
- { TERMMOD, XK_U, zoom, {.f = +1} },
- { TERMMOD, XK_I, zoom, {.f = -1} },
- { TERMMOD, XK_Home, zoomreset, {.f = 0} },
- { ControlMask, XK_p, selpaste, {.i = 0} },
- { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
- { TERMMOD, XK_K, kscrollup, {.i = -1} },
- { TERMMOD, XK_J, kscrolldown, {.i = -1} },
- { TERMMOD, XK_Escape, keyboard_select,{.i = 0} },
+ { XK_ANY_MOD, XK_Break, sendbreak, {.i = 0} },
+ { ControlMask, XK_Print, toggleprinter, {.i = 0} },
+ { ShiftMask, XK_Print, printscreen, {.i = 0} },
+ { XK_ANY_MOD, XK_Print, printsel, {.i = 0} },
+ { TERMMOD, XK_U, zoom, {.f = +1} },
+ { TERMMOD, XK_I, zoom, {.f = -1} },
+ { TERMMOD, XK_Home, zoomreset, {.f = 0} },
+ { ControlMask, XK_p, selpaste, {.i = 0} },
+ { TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
+ { TERMMOD, XK_K, kscrollup, {.i = -1} },
+ { TERMMOD, XK_J, kscrolldown, {.i = -1} },
+ { TERMMOD, XK_Escape, keyboard_select,{.i = 0} },
{ TERMMOD, XK_L, externalpipe, {.v = urlhand } },
- { TERMMOD, XK_C, externalpipe, {.v = dgrep } },
+ { TERMMOD, XK_C, externalpipe, {.v = dgrep } },
+ { TERMMOD, XK_Return, newterm, {.i = 0} },
};
diff --git a/st.c b/st.c
@@ -163,6 +163,7 @@ typedef struct {
} STREscape;
static void execsh(char *, char **);
+static char *getcwd_by_pid(pid_t pid);
static void stty(char **);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
@@ -1078,6 +1079,26 @@ kscrolldown(const Arg* a)
}
void
+newterm(const Arg* a)
+{
+ switch (fork()) {
+ case -1:
+ die("fork failed: %s\n", strerror(errno));
+ break;
+ case 0:
+ chdir(getcwd_by_pid(pid));
+ execlp("st", "./st", NULL);
+ break;
+ }
+}
+
+static char *getcwd_by_pid(pid_t pid) {
+ char buf[32];
+ snprintf(buf, sizeof buf, "/proc/%d/cwd", pid);
+ return realpath(buf, NULL);
+}
+
+void
kscrollup(const Arg* a)
{
int n = a->i;
diff --git a/st.h b/st.h
@@ -84,6 +84,7 @@ void draw(void);
void externalpipe(const Arg *);
void kscrolldown(const Arg *);
void kscrollup(const Arg *);
+void newterm(const Arg *);
void printscreen(const Arg *);
void printsel(const Arg *);
void sendbreak(const Arg *);