mirror of
https://codeberg.org/frosty/st.git
synced 2024-09-19 03:37:00 -04:00
patch: newterm
This commit is contained in:
parent
57a0ed774d
commit
4d63ceec5f
|
@ -226,6 +226,7 @@ static Shortcut shortcuts[] = {
|
|||
{ ShiftMask, XK_Page_Down, kscrolldown, {.i = -1} },
|
||||
{ XK_NO_MOD, XK_F11, fullscreen, {.i = 0} },
|
||||
{ MODKEY, XK_Return, fullscreen, {.i = 0} },
|
||||
{ TERMMOD, XK_Return, newterm, {.i = 0} },
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
38
st.c
38
st.c
|
@ -20,6 +20,8 @@
|
|||
#include "st.h"
|
||||
#include "win.h"
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
#if defined(__linux)
|
||||
#include <pty.h>
|
||||
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
|
||||
|
@ -166,6 +168,7 @@ typedef struct {
|
|||
} STREscape;
|
||||
|
||||
static void execsh(char *, char **);
|
||||
static int chdir_by_pid(pid_t pid);
|
||||
static void stty(char **);
|
||||
static void sigchld(int);
|
||||
static void ttywriteraw(const char *, size_t);
|
||||
|
@ -822,6 +825,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
|
|||
if (pledge("stdio rpath tty proc", NULL) == -1)
|
||||
die("pledge\n");
|
||||
#endif
|
||||
fcntl(m, F_SETFD, FD_CLOEXEC);
|
||||
close(s);
|
||||
cmdfd = m;
|
||||
signal(SIGCHLD, sigchld);
|
||||
|
@ -1116,6 +1120,40 @@ kscrolldown(const Arg *a)
|
|||
tfulldirt();
|
||||
}
|
||||
|
||||
void
|
||||
newterm(const Arg* a)
|
||||
{
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
die("fork failed: %s\n", strerror(errno));
|
||||
break;
|
||||
case 0:
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
fprintf(stderr, "fork failed: %s\n", strerror(errno));
|
||||
_exit(1);
|
||||
break;
|
||||
case 0:
|
||||
chdir_by_pid(pid);
|
||||
execl("/proc/self/exe", argv0, NULL);
|
||||
_exit(1);
|
||||
break;
|
||||
default:
|
||||
_exit(0);
|
||||
}
|
||||
default:
|
||||
wait(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
chdir_by_pid(pid_t pid)
|
||||
{
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof buf, "/proc/%ld/cwd", (long)pid);
|
||||
return chdir(buf);
|
||||
}
|
||||
|
||||
void
|
||||
tscrolldown(int orig, int n)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue