summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCraig Jennings <craigmartinjennings@gmail.com>2023-07-23 17:40:26 -0500
committerCraig Jennings <craigmartinjennings@gmail.com>2023-07-23 17:40:26 -0500
commitf142442605da70b77ba3bccad552d5ac61331282 (patch)
tree71e8b1cf35d7297eb8fcd6f3c3a5e4da6c7975ea
parentb3601bf1c43b332e0b1f696ece869b4edef5e18e (diff)
added xresources signal reloading patch
-rw-r--r--st-xresources-signal-reloading-20220407-ef05519.diff153
-rw-r--r--todo.org56
-rw-r--r--x.c115
3 files changed, 315 insertions, 9 deletions
diff --git a/st-xresources-signal-reloading-20220407-ef05519.diff b/st-xresources-signal-reloading-20220407-ef05519.diff
new file mode 100644
index 0000000..6715ebf
--- /dev/null
+++ b/st-xresources-signal-reloading-20220407-ef05519.diff
@@ -0,0 +1,153 @@
+From b2a9c96cc3c9152c4e8188f341606c914741cb50 Mon Sep 17 00:00:00 2001
+From: wael <40663@protonmail.com>
+Date: Thu, 7 Apr 2022 17:14:02 +0300
+Subject: [PATCH] fix xresources with signal reloading removing arg.h and st.h
+ & remove unneccesary xresources variables(?)
+
+---
+ x.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 1 file changed, 115 insertions(+)
+
+diff --git a/x.c b/x.c
+index 2a3bd38..e8fe7ad 100644
+--- a/x.c
++++ b/x.c
+@@ -14,6 +14,7 @@
+ #include <X11/keysym.h>
+ #include <X11/Xft/Xft.h>
+ #include <X11/XKBlib.h>
++#include <X11/Xresource.h>
+
+ char *argv0;
+ #include "arg.h"
+@@ -2011,6 +2012,118 @@ run(void)
+ }
+ }
+
++
++#define XRESOURCE_LOAD_META(NAME) \
++ if(!XrmGetResource(xrdb, "st." NAME, "st." NAME, &type, &ret)) \
++ XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret); \
++ if (ret.addr != NULL && !strncmp("String", type, 64))
++
++#define XRESOURCE_LOAD_STRING(NAME, DST) \
++ XRESOURCE_LOAD_META(NAME) \
++ DST = ret.addr;
++
++#define XRESOURCE_LOAD_CHAR(NAME, DST) \
++ XRESOURCE_LOAD_META(NAME) \
++ DST = ret.addr[0];
++
++#define XRESOURCE_LOAD_INTEGER(NAME, DST) \
++ XRESOURCE_LOAD_META(NAME) \
++ DST = strtoul(ret.addr, NULL, 10);
++
++#define XRESOURCE_LOAD_FLOAT(NAME, DST) \
++ XRESOURCE_LOAD_META(NAME) \
++ DST = strtof(ret.addr, NULL);
++
++void
++xrdb_load(void)
++{
++ /* XXX */
++ char *xrm;
++ char *type;
++ XrmDatabase xrdb;
++ XrmValue ret;
++ Display *dpy;
++
++ if(!(dpy = XOpenDisplay(NULL)))
++ die("Can't open display\n");
++
++ XrmInitialize();
++ xrm = XResourceManagerString(dpy);
++
++ if (xrm != NULL) {
++ xrdb = XrmGetStringDatabase(xrm);
++
++ /* handling colors here without macros to do via loop. */
++ int i = 0;
++ char loadValue[12] = "";
++ for (i = 0; i < 256; i++)
++ {
++ sprintf(loadValue, "%s%d", "st.color", i);
++
++ if(!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret))
++ {
++ sprintf(loadValue, "%s%d", "*.color", i);
++ if (!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret))
++ /* reset if not found (unless in range for defaults). */
++ if (i > 15)
++ colorname[i] = NULL;
++ }
++
++ if (ret.addr != NULL && !strncmp("String", type, 64))
++ colorname[i] = ret.addr;
++ }
++
++ XRESOURCE_LOAD_STRING("foreground", colorname[defaultfg]);
++ XRESOURCE_LOAD_STRING("background", colorname[defaultbg]);
++ XRESOURCE_LOAD_STRING("cursorColor", colorname[defaultcs])
++ else {
++ // this looks confusing because we are chaining off of the if
++ // in the macro. probably we should be wrapping everything blocks
++ // so this isn't possible...
++ defaultcs = defaultfg;
++ }
++ XRESOURCE_LOAD_STRING("reverse-cursor", colorname[defaultrcs])
++ else {
++ // see above.
++ defaultrcs = defaultbg;
++ }
++
++ XRESOURCE_LOAD_STRING("font", font);
++ XRESOURCE_LOAD_STRING("termname", termname);
++
++ XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout);
++ XRESOURCE_LOAD_INTEGER("bellvolume", bellvolume);
++ XRESOURCE_LOAD_INTEGER("borderpx", borderpx);
++ XRESOURCE_LOAD_INTEGER("cursorshape", cursorshape);
++
++ XRESOURCE_LOAD_FLOAT("cwscale", cwscale);
++ XRESOURCE_LOAD_FLOAT("chscale", chscale);
++ }
++ XFlush(dpy);
++}
++
++void
++reload(int sig)
++{
++ xrdb_load();
++
++ /* colors, fonts */
++ xloadcols();
++ xunloadfonts();
++ xloadfonts(font, 0);
++
++ /* pretend the window just got resized */
++ cresize(win.w, win.h);
++
++ redraw();
++
++ /* triggers re-render if we're visible. */
++ ttywrite("\033[O", 3, 1);
++
++ signal(SIGUSR1, reload);
++}
++
++
+ void
+ usage(void)
+ {
+@@ -2084,6 +2197,8 @@ run:
+
+ setlocale(LC_CTYPE, "");
+ XSetLocaleModifiers("");
++ xrdb_load();
++ signal(SIGUSR1, reload);
+ cols = MAX(cols, 1);
+ rows = MAX(rows, 1);
+ tnew(cols, rows);
+--
+2.35.1
+
diff --git a/todo.org b/todo.org
index eb56595..5cc6971 100644
--- a/todo.org
+++ b/todo.org
@@ -1,19 +1,27 @@
ST Patches
* ST Patches Open Work
-** TODO [#B] xresources with signal reloading
+** TODO [#B] dynamic cursor color
*** Description and URLs
-This patch adds the ability to configure st via Xresources and signal reloading. This patch is not based on xresources patch and is extended from xst's commit on github.
-You can basically pass a USR1 signal to all st processes after updating your Xresources to reload the settings: ` pidof st | xargs kill -s USR1 `
+Swaps the colors of your cursor and the character you're currently on (much like alacritty). Some say the effect is very appealing:)
+Notes
+
+Might be incomplete - I'm new and improvements are very welcome!
+
+ Might have some edge cases where it doesn't work properly
+ Performance degradation considerations? More testing & feedback needed
+
+https://st.suckless.org/patches/dynamic-cursor-color/
+https://st.suckless.org/patches/dynamic-cursor-color/st-dynamic-cursor-color-0.9.diff
-https://st.suckless.org/patches/xresources-with-reload-signal/
-https://st.suckless.org/patches/xresources-with-reload-signal/st-xresources-signal-reloading-20220407-ef05519.diff
-** TODO [#B] swaps the color of the background with the character the cursor is on
-st-dynamic-cursor-color-0.9.diff
** TODO [#C] .desktop entry
st-desktopentry-0.8.5.diff
** TODO [#C] netwmicon
st-netwmicon-0.8.5-v2.diff
-** TODO [#C] colorschemes
+* ST Patches Aborted
+** CANCELLED [#C] colorschemes
+*** 2023-07-23 @ 17:34:43 -0500 Unnecessary
+Not needed now that I can configure st attributes via Xresources
+*** Description and URLs
This patch adds multiple color schemes and lets you change them without having to restart st.
Predefined color schemes:
@@ -38,7 +46,6 @@ Key bindings
https://st.suckless.org/patches/colorschemes/
https://st.suckless.org/patches/colorschemes/st-colorschemes-0.8.5.diff
-* ST Patches Aborted
** CANCELLED [#B] right-click sends paste
*** 2023-07-23 @ 17:12:15 -0500 patching failed, manual intervention failed
I can't locate where in x.c this patch should apply. It's a pretty straightforward one line change, but the constant doesn't exist any longer.
@@ -118,6 +125,37 @@ https://st.suckless.org/patches/externalpipe/st-externalpipe-0.8.4.diff
When using the scrollback patch, you can apply this patch ontop in order to use externalpipe onto the entire terminal history:
https://st.suckless.org/patches/externalpipe/st-externalpipe-eternal-0.8.3.diff
* ST Patches Completed
+** DONE [#B] xresources with signal reloading
+*** 2023-07-23 @ 17:33:40 -0500 Verification Steps Succeeded
+Added configuration options to .Xresources and launched ST to verify them
+
+! ST (suckless terminal) settings
+st.font: FiraCode Nerd Font Mono:size=12
+st.background: gruvbox_bg
+st.foreground: gruvbox_fg
+st.color0: gruvbox_bg
+st.color1: gruvbox_red
+st.color2: gruvbox_green
+st.color3: gruvbox_yellow
+st.color4: gruvbox_blue
+st.color5: gruvbox_purple
+st.color6: gruvbox_aqua
+st.color7: gruvbox_fg
+st.color8: gruvbox_gray
+st.color9: gruvbox_red
+st.color10: gruvbox_green
+st.color11: gruvbox_yellow
+st.color12: gruvbox_blue
+st.color13: gruvbox_purple
+st.color14: gruvbox_aqua
+st.color15: gruvbox_fg
+*** 2023-07-23 @ 17:24:00 -0500 patch successful without issues
+*** Description and URLs
+This patch adds the ability to configure st via Xresources and signal reloading. This patch is not based on xresources patch and is extended from xst's commit on github.
+You can basically pass a USR1 signal to all st processes after updating your Xresources to reload the settings: ` pidof st | xargs kill -s USR1 `
+
+https://st.suckless.org/patches/xresources-with-reload-signal/
+https://st.suckless.org/patches/xresources-with-reload-signal/st-xresources-signal-reloading-20220407-ef05519.diff
** DONE [#A] font2 (fallback font for glyphs + emojis)
*** 2023-07-23 @ 17:08:03 -0500 Patch applied successfully w/o issues
*** Description and URLs
diff --git a/x.c b/x.c
index 5e8ba3e..73a1c7d 100644
--- a/x.c
+++ b/x.c
@@ -14,6 +14,7 @@
#include <X11/keysym.h>
#include <X11/Xft/Xft.h>
#include <X11/XKBlib.h>
+#include <X11/Xresource.h>
char *argv0;
#include "arg.h"
@@ -2190,6 +2191,118 @@ run(void)
}
}
+
+#define XRESOURCE_LOAD_META(NAME) \
+ if(!XrmGetResource(xrdb, "st." NAME, "st." NAME, &type, &ret)) \
+ XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret); \
+ if (ret.addr != NULL && !strncmp("String", type, 64))
+
+#define XRESOURCE_LOAD_STRING(NAME, DST) \
+ XRESOURCE_LOAD_META(NAME) \
+ DST = ret.addr;
+
+#define XRESOURCE_LOAD_CHAR(NAME, DST) \
+ XRESOURCE_LOAD_META(NAME) \
+ DST = ret.addr[0];
+
+#define XRESOURCE_LOAD_INTEGER(NAME, DST) \
+ XRESOURCE_LOAD_META(NAME) \
+ DST = strtoul(ret.addr, NULL, 10);
+
+#define XRESOURCE_LOAD_FLOAT(NAME, DST) \
+ XRESOURCE_LOAD_META(NAME) \
+ DST = strtof(ret.addr, NULL);
+
+void
+xrdb_load(void)
+{
+ /* XXX */
+ char *xrm;
+ char *type;
+ XrmDatabase xrdb;
+ XrmValue ret;
+ Display *dpy;
+
+ if(!(dpy = XOpenDisplay(NULL)))
+ die("Can't open display\n");
+
+ XrmInitialize();
+ xrm = XResourceManagerString(dpy);
+
+ if (xrm != NULL) {
+ xrdb = XrmGetStringDatabase(xrm);
+
+ /* handling colors here without macros to do via loop. */
+ int i = 0;
+ char loadValue[12] = "";
+ for (i = 0; i < 256; i++)
+ {
+ sprintf(loadValue, "%s%d", "st.color", i);
+
+ if(!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret))
+ {
+ sprintf(loadValue, "%s%d", "*.color", i);
+ if (!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret))
+ /* reset if not found (unless in range for defaults). */
+ if (i > 15)
+ colorname[i] = NULL;
+ }
+
+ if (ret.addr != NULL && !strncmp("String", type, 64))
+ colorname[i] = ret.addr;
+ }
+
+ XRESOURCE_LOAD_STRING("foreground", colorname[defaultfg]);
+ XRESOURCE_LOAD_STRING("background", colorname[defaultbg]);
+ XRESOURCE_LOAD_STRING("cursorColor", colorname[defaultcs])
+ else {
+ // this looks confusing because we are chaining off of the if
+ // in the macro. probably we should be wrapping everything blocks
+ // so this isn't possible...
+ defaultcs = defaultfg;
+ }
+ XRESOURCE_LOAD_STRING("reverse-cursor", colorname[defaultrcs])
+ else {
+ // see above.
+ defaultrcs = defaultbg;
+ }
+
+ XRESOURCE_LOAD_STRING("font", font);
+ XRESOURCE_LOAD_STRING("termname", termname);
+
+ XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout);
+ XRESOURCE_LOAD_INTEGER("bellvolume", bellvolume);
+ XRESOURCE_LOAD_INTEGER("borderpx", borderpx);
+ XRESOURCE_LOAD_INTEGER("cursorshape", cursorshape);
+
+ XRESOURCE_LOAD_FLOAT("cwscale", cwscale);
+ XRESOURCE_LOAD_FLOAT("chscale", chscale);
+ }
+ XFlush(dpy);
+}
+
+void
+reload(int sig)
+{
+ xrdb_load();
+
+ /* colors, fonts */
+ xloadcols();
+ xunloadfonts();
+ xloadfonts(font, 0);
+
+ /* pretend the window just got resized */
+ cresize(win.w, win.h);
+
+ redraw();
+
+ /* triggers re-render if we're visible. */
+ ttywrite("\033[O", 3, 1);
+
+ signal(SIGUSR1, reload);
+}
+
+
void
usage(void)
{
@@ -2267,6 +2380,8 @@ run:
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
+ xrdb_load();
+ signal(SIGUSR1, reload);
cols = MAX(cols, 1);
rows = MAX(rows, 1);
tnew(cols, rows);