mirror of https://github.com/bakkeby/patches
Adding st-newterm-orphan-20210712-4536f46.diff
parent
bc89938099
commit
419aef2d56
@ -0,0 +1,48 @@
|
||||
From 89d9a5046a6af6b80fd4804a71f8dc7496020a6e Mon Sep 17 00:00:00 2001
|
||||
From: bakkeby <bakkeby@gmail.com>
|
||||
Date: Wed, 12 May 2021 09:13:47 +0200
|
||||
Subject: [PATCH] Make st interpret cursor 0 as the default cursor.
|
||||
|
||||
According to the specification the "Set cursor style
|
||||
(DECSCUSR), VT520." escape sequences define both values of 0 and 1 as a blinking block,
|
||||
with 1 being the default.
|
||||
|
||||
Refer to:
|
||||
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-SP-q.1D81
|
||||
|
||||
This patch allows the default cursor to be set when value 0 is used, as opposed to
|
||||
setting the cursor to a blinking block.
|
||||
|
||||
This allows a command like this to restore the cursor to what st is configured with:
|
||||
$ echo -ne "\e[ q"
|
||||
|
||||
While many terminal emulators do this it is not adhering to specification. xterm is an
|
||||
example terminal that sets a blinking block instead of the configured one, same as st.
|
||||
|
||||
Example use case is changing cursor shape in vim depending on what mode is used:
|
||||
|
||||
https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes
|
||||
https://askubuntu.com/questions/42663/how-to-make-cursor-change-from-thin-line-to-block-based-on-normal-or-insert-mode
|
||||
|
||||
The alternative in this case would be to explicitly set the cursor back to what you expect
|
||||
it to be (underline, bar) in the vim configuration.
|
||||
---
|
||||
x.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/x.c b/x.c
|
||||
index 7186040..0e4b4ee 100644
|
||||
--- a/x.c
|
||||
+++ b/x.c
|
||||
@@ -1708,7 +1708,7 @@ xsetcursor(int cursor)
|
||||
{
|
||||
if (!BETWEEN(cursor, 0, 7)) /* 7: st extension */
|
||||
return 1;
|
||||
- win.cursor = cursor;
|
||||
+ win.cursor = (cursor ? cursor : cursorshape);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
2.31.1
|
||||
|
@ -0,0 +1,105 @@
|
||||
From e6ac257f362f8b879b62225bedca9e8aafef4f3b Mon Sep 17 00:00:00 2001
|
||||
From: bakkeby <bakkeby@gmail.com>
|
||||
Date: Mon, 12 Jul 2021 09:35:04 +0200
|
||||
Subject: [PATCH] Add shortcut to spawn new terminal in the current dir
|
||||
|
||||
Ctrl-Shift-Return now creates a new ST terminal, whose CWD is the same
|
||||
as the parent st's CWD.
|
||||
|
||||
This version of the patch does a double fork, a technique commonly used
|
||||
by daemons to spawn orphan processes.
|
||||
|
||||
This solution is specific to the swallow patch for dwm which traverses
|
||||
the process tree to determine if the new window is a decendant of a
|
||||
terminal window, in which case the new window should take the place of
|
||||
the terminal window.
|
||||
|
||||
The way the original newterm patch worked the new st terminal would be
|
||||
a direct decendant of the parent st terminal process, which could lead
|
||||
to the wrong terminal window being swallowed.
|
||||
|
||||
The double fork method avoids this by leaving all new st terminals as
|
||||
orphans, i.e. they will have no parent process.
|
||||
---
|
||||
config.def.h | 1 +
|
||||
st.c | 32 ++++++++++++++++++++++++++++++++
|
||||
st.h | 1 +
|
||||
3 files changed, 34 insertions(+)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 6f05dce..9029e8d 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -199,6 +199,7 @@ static Shortcut shortcuts[] = {
|
||||
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
|
||||
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
|
||||
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
|
||||
+ { TERMMOD, XK_Return, newterm, {.i = 0} },
|
||||
};
|
||||
|
||||
/*
|
||||
diff --git a/st.c b/st.c
|
||||
index ebdf360..cb79bc0 100644
|
||||
--- a/st.c
|
||||
+++ b/st.c
|
||||
@@ -153,6 +153,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);
|
||||
@@ -1060,6 +1061,37 @@ tswapscreen(void)
|
||||
tfulldirt();
|
||||
}
|
||||
|
||||
+void
|
||||
+newterm(const Arg* a)
|
||||
+{
|
||||
+ int res;
|
||||
+ switch (fork()) {
|
||||
+ case -1:
|
||||
+ die("fork failed: %s\n", strerror(errno));
|
||||
+ break;
|
||||
+ case 0:
|
||||
+ switch (fork()) {
|
||||
+ case -1:
|
||||
+ die("fork failed: %s\n", strerror(errno));
|
||||
+ break;
|
||||
+ case 0:
|
||||
+ res = chdir(getcwd_by_pid(pid));
|
||||
+ execlp("st", "./st", NULL);
|
||||
+ break;
|
||||
+ default:
|
||||
+ exit(0);
|
||||
+ }
|
||||
+ default:
|
||||
+ wait(NULL);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static char *getcwd_by_pid(pid_t pid) {
|
||||
+ char buf[32];
|
||||
+ snprintf(buf, sizeof buf, "/proc/%d/cwd", pid);
|
||||
+ return realpath(buf, NULL);
|
||||
+}
|
||||
+
|
||||
void
|
||||
tscrolldown(int orig, int n)
|
||||
{
|
||||
diff --git a/st.h b/st.h
|
||||
index fa2eddf..b13399b 100644
|
||||
--- a/st.h
|
||||
+++ b/st.h
|
||||
@@ -81,6 +81,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 *);
|
||||
--
|
||||
2.32.0
|
||||
|
Loading…
Reference in New Issue