commit 05892601bf8ffdd54e764d358b0cf5f07d6c53d8
parent 90566170227e8dcf74af5dfa3654c08faa18095b
Author: siduck76 <siduckk76@protonmail.com>
Date: Wed, 13 Jan 2021 22:30:31 +0530
newterm patch
Diffstat:
4 files changed, 32 insertions(+), 18 deletions(-)
diff --git a/config.h b/config.h
@@ -224,7 +224,7 @@ static MouseShortcut mshortcuts[] = {
/* Internal keyboard shortcuts. */
#define MODKEY Mod1Mask
-#define TERMMOD (Mod1Mask|ShiftMask)
+#define TERMMOD (Mod4Mask|ShiftMask)
MouseKey mkeys[] = {
/* button mask function argument */
@@ -278,6 +278,8 @@ static Shortcut shortcuts[] = {
{ MODKEY, XK_l, externalpipe, {.v = openurlcmd } },
{ MODKEY, XK_y, externalpipe, {.v = copyurlcmd } },
{ MODKEY, XK_o, externalpipe, {.v = copyoutput } },
+ { TERMMOD, XK_Return, newterm, {.i = 0} },
+
};
/*
diff --git a/st.c b/st.c
@@ -168,6 +168,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);
@@ -1080,6 +1081,26 @@ tswapscreen(void)
}
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
kscrolldown(const Arg* a)
{
int n = a->i;
diff --git a/st.h b/st.h
@@ -100,6 +100,7 @@ void externalpipe(const Arg *);
void iso14755(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 *);
diff --git a/st.h.rej b/st.h.rej
@@ -1,20 +1,10 @@
--- st.h
+++ st.h
-@@ -11,7 +11,8 @@
- #define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
- #define DEFAULT(a, b) (a) = (a) ? (a) : (b)
- #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
--#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
-+#define ATTRCMP(a, b) (((a).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) != ((b).mode & (~ATTR_WRAP) & (~ATTR_LIGA)) || \
-+ (a).fg != (b).fg || \
- (a).bg != (b).bg)
- #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \
- (t1.tv_nsec-t2.tv_nsec)/1E6)
-@@ -33,6 +34,7 @@ enum glyph_attribute {
- ATTR_WRAP = 1 << 8,
- ATTR_WIDE = 1 << 9,
- ATTR_WDUMMY = 1 << 10,
-+ ATTR_LIGA = 1 << 11,
- ATTR_BOLD_FAINT = ATTR_BOLD | ATTR_FAINT,
- };
+@@ -80,6 +80,7 @@ void die(const char *, ...);
+ void redraw(void);
+ void draw(void);
++void newterm(const Arg *);
+ void printscreen(const Arg *);
+ void printsel(const Arg *);
+ void sendbreak(const Arg *);