From 98a2dd55b09995425fd34ea41f16a9f9225b10e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pankowski?= Date: Thu, 9 Oct 2025 23:09:02 +0200 Subject: [PATCH] add dmenu dark and light variants --- config.def.h | 30 ++++++++++++++++++++++++------ st.c | 14 ++++++++++++-- st.h | 7 ++++++- x.c | 11 +++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/config.def.h b/config.def.h index cda0b00..d101759 100644 --- a/config.def.h +++ b/config.def.h @@ -16,12 +16,30 @@ static char *externaleditcmd[] = { "/bin/sh", "-c", "st -e vis \"$tmpfile\"\n", NULL}; -static char *externalcopycmd[] = { "/bin/sh", "-c", - "sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu -l 10 -w $WINDOWID -p Copy | tr -d '\\n' | vis-clipboard --copy", +int lightmode = 0; + +#define COL_GRAY1 "'#222222'" +#define COL_GRAY2 "'#444444'" +#define COL_GRAY3 "'#bbbbbb'" +#define COL_GRAY4 "'#eeeeee'" +#define COL_CYAN "'#005577'" +#define DMENU_DARK "-l 10 -fn 'FiraCode Nerd Font:size=10' -nb " COL_GRAY1 " -nf " COL_GRAY3 " -sb " COL_CYAN " -sf " COL_GRAY4 +#define DMENU_LIGHT "-l 10 -fn 'FiraCode Nerd Font:size=10' -nb " COL_GRAY3 " -nf " COL_GRAY1 " -sb " COL_CYAN " -sf " COL_GRAY4 + +static char *externalcopydarkcmd[] = { "/bin/sh", "-c", + "sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_DARK " -w $WINDOWID -p Copy | tr -d '\\n' | vis-clipboard --copy", NULL}; -static char *externalinsertcmd[] = { "/bin/sh", "-c", - "sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu -l 10 -w $WINDOWID -p Paste | tr -d '\\n'", +static char *externalpastedarkcmd[] = { "/bin/sh", "-c", + "sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_DARK " -w $WINDOWID -p Paste | tr -d '\\n'", + NULL}; + +static char *externalcopylightcmd[] = { "/bin/sh", "-c", + "sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_LIGHT " -w $WINDOWID -p Copy | tr -d '\\n' | vis-clipboard --copy", + NULL}; + +static char *externalpastelightcmd[] = { "/bin/sh", "-c", + "sed 's/[ \t][ \t]*/\\n/g' | tac | awk 'BEGIN{x[\"\"]++} !x[$0]++' | dmenu " DMENU_LIGHT " -w $WINDOWID -p Paste | tr -d '\\n'", NULL}; /* @@ -216,8 +234,8 @@ static Shortcut shortcuts[] = { { TERMMOD, XK_V, clippaste, {.i = 0} }, { TERMMOD, XK_Y, selpaste, {.i = 0} }, { TERMMOD, XK_E, externalpipe, { .v = externaleditcmd } }, - { TERMMOD, XK_K, externalpipe, { .v = externalcopycmd } }, - { TERMMOD, XK_I, externalpipettycopy, { .v = externalinsertcmd } }, + { TERMMOD, XK_K, externalpipecopy, { 0 } }, + { TERMMOD, XK_I, externalpipepaste, { 0 } }, { ShiftMask, XK_Insert, selpaste, {.i = 0} }, { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, { ShiftMask, XK_Page_Up, kscrollup, {.i = -1} }, diff --git a/st.c b/st.c index 5979e6f..edea681 100644 --- a/st.c +++ b/st.c @@ -2206,9 +2206,19 @@ ttycopy(int fildes) } void -externalpipettycopy(const Arg *arg) +externalpipepaste(const Arg *) { - externalpipeinout(arg, ttycopy); + Arg arg; + arg.v = externalpastecmd(); + externalpipeinout(&arg, ttycopy); +} + +void +externalpipecopy(const Arg *) +{ + Arg arg; + arg.v = externalcopycmd(); + externalpipeinout(&arg, NULL); } void diff --git a/st.h b/st.h index ae57455..5fbba87 100644 --- a/st.h +++ b/st.h @@ -83,7 +83,8 @@ void redraw(void); void draw(void); void externalpipe(const Arg *); -void externalpipettycopy(const Arg *); +void externalpipecopy(const Arg *); +void externalpipepaste(const Arg *); void printscreen(const Arg *); void printsel(const Arg *); void sendbreak(const Arg *); @@ -122,8 +123,12 @@ extern char *vtiden; extern wchar_t *worddelimiters; extern int allowaltscreen; extern int allowwindowops; +extern int lightmode; extern char *termname; extern unsigned int tabspaces; extern unsigned int defaultfg; extern unsigned int defaultbg; extern unsigned int defaultcs; + +char **externalcopycmd(); +char **externalpastecmd(); diff --git a/x.c b/x.c index e9aba01..8bc0c72 100644 --- a/x.c +++ b/x.c @@ -66,6 +66,16 @@ void kscrolldown(const Arg *); /* config.h for applying patches and the configuration. */ #include "config.h" +char **externalcopycmd() +{ + return (lightmode) ? externalcopylightcmd : externalcopydarkcmd; +} + +char **externalpastecmd() +{ + return (lightmode) ? externalpastelightcmd : externalpastedarkcmd; +} + /* XEMBED messages */ #define XEMBED_FOCUS_IN 4 #define XEMBED_FOCUS_OUT 5 @@ -2109,6 +2119,7 @@ xrdb_load(void) XRESOURCE_LOAD_INTEGER("bellvolume", bellvolume); XRESOURCE_LOAD_INTEGER("borderpx", borderpx); XRESOURCE_LOAD_INTEGER("cursorshape", cursorshape); + XRESOURCE_LOAD_INTEGER("lightmode", lightmode); XRESOURCE_LOAD_FLOAT("cwscale", cwscale); XRESOURCE_LOAD_FLOAT("chscale", chscale);