From acd4f75d6398b8a7b05b5294f9deaf664ebb3f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pankowski?= Date: Thu, 13 Jan 2022 05:45:41 +0100 Subject: [PATCH] lupan-wm: M-S-F6 switchs theme, use st as terminal st-lupan-0.8.5.diff adapted from http://st.suckless.org/patches/solarized/st-solarized-both-0.8.4.diff by - change to windi colors - switch colors with F6 or select with SIGUS1/SIGUSR2 - use font Iosevka Slab Light --- lupan-wm/src/main.rs | 11 +- patches/st-lupan-0.8.5.diff | 231 +++++++++++++++++++++++++++++++++++ xsession/.xsession | 2 +- xsession/bin/lupan-set-theme | 36 ++++++ 4 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 patches/st-lupan-0.8.5.diff create mode 100755 xsession/bin/lupan-set-theme diff --git a/lupan-wm/src/main.rs b/lupan-wm/src/main.rs index 998eb0b..2fbd104 100644 --- a/lupan-wm/src/main.rs +++ b/lupan-wm/src/main.rs @@ -21,8 +21,9 @@ use std::convert::{TryFrom, TryInto}; pub type Conn = XcbConnection; const EDITOR: &str = "emacsclient -c -n"; -const TERMINAL: &str = "alacritty"; +const TERMINAL: &str = "st"; const SUSPEND: &str = "systemctl suspend"; +const SET_THEME: &str = "lupan-set-theme"; const FONT: &str = "Iosevka Slab Light"; const FONT_SIZE: i32 = 20; @@ -45,12 +46,14 @@ struct Args { font_size: i32, } +#[allow(unused_parens)] fn main() -> Result<()> { let n_main = 1; let ratio = 0.6; let args = Args::parse(); let rofi_theme_str = format!("* {{ text-color: {}; background-color: {}; blue: {}; font: \"{} {}\"; }}", BAR_FG, BAR_BG, BAR_HIGHLIGHT, args.font, args.font_size); + let mut theme = "dark"; let config = Config::default() .builder() .workspaces(vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]) @@ -73,6 +76,12 @@ fn main() -> Result<()> { "M-Return" => run_external!(TERMINAL); "M-S-s" => run_external!(SUSPEND); + // Switch theme + "M-S-F6" => Box::new(move |_: &mut WindowManager<_>| { + theme = if theme == "dark" { "light" } else { "dark" }; + spawn!(SET_THEME, theme) + }); + // Exit Penrose (important to remember this one!) "M-A-C-Escape" => run_internal!(exit); diff --git a/patches/st-lupan-0.8.5.diff b/patches/st-lupan-0.8.5.diff new file mode 100644 index 0000000..10ce7db --- /dev/null +++ b/patches/st-lupan-0.8.5.diff @@ -0,0 +1,231 @@ +diff --git a/config.def.h b/config.def.h +index 91ab8ca..5bbc088 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -5,7 +5,7 @@ + * + * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html + */ +-static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true"; ++static char *font = "Iosevka Slab Light:size=12:antialias=true:autohint=true"; + static int borderpx = 2; + + /* +@@ -95,35 +95,61 @@ unsigned int tabspaces = 8; + + /* Terminal colors (16 first used in escape sequence) */ + static const char *colorname[] = { +- /* 8 normal colors */ +- "black", +- "red3", +- "green3", +- "yellow3", +- "blue2", +- "magenta3", +- "cyan3", +- "gray90", +- +- /* 8 bright colors */ +- "gray50", +- "red", +- "green", +- "yellow", +- "#5c5cff", +- "magenta", +- "cyan", +- "white", ++ /* windi dark */ ++ "#1f1f1f", /* 0: black */ ++ "#ef4444", /* 1: red */ ++ "#22c55e", /* 2: green */ ++ "#eab308", /* 3: yellow */ ++ "#3b82f6", /* 4: blue */ ++ "#d946ef", /* 5: magenta */ ++ "#06b6d4", /* 6: cyan */ ++ "#f2f2f2", /* 7: white */ ++ "#737373", /* 8: brblack */ ++ "#fecaca", /* 9: brred */ ++ "#bbf7d0", /* 10: brgreen */ ++ "#fef08a", /* 11: bryellow */ ++ "#bfdbfe", /* 12: brblue */ ++ "#f5d0fe", /* 13: brmagenta*/ ++ "#a5f3fc", /* 14: brcyan */ ++ "#fafafa", /* 15: brwhite */ + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ +- "#cccccc", +- "#555555", +- "gray90", /* default foreground colour */ +- "black", /* default background colour */ ++ "white", ++ "black", ++ "#E7E7E7", /* default foreground colour */ ++ "#2C444D", + }; + ++/* Terminal colors for alternate (light) palette */ ++static const char *altcolorname[] = { ++ /* windi light */ ++ "#1b1b1b", /* 0: black */ ++ "#b91c1c", /* 1: red */ ++ "#15803d", /* 2: green */ ++ "#a16207", /* 3: yellow */ ++ "#1d4ed8", /* 4: blue */ ++ "#a21caf", /* 5: magenta*/ ++ "#0e7490", /* 6: cyan */ ++ "#e9ecef", /* 7: white */ ++ "#404040", /* 8: brblack */ ++ "#ef4444", /* 9: brred */ ++ "#22c55e", /* 10: brgreen */ ++ "#eab308", /* 11: bryellow */ ++ "#3b82f6", /* 12: brblue */ ++ "#d946ef", /* 13: brmagenta */ ++ "#06b6d4", /* 14: brcyan */ ++ "#f2f2f2", /* 15: brwhite */ ++ ++ [255] = 0, ++ ++ /* more colors can be added after 255 to use with DefaultXX */ ++ "#00638a", ++ "#f2f2f2", ++ "#454545", /* default foreground colour */ ++ "#f2f2f2", ++}; + + /* + * Default colors (colorname index) +@@ -201,6 +227,7 @@ static Shortcut shortcuts[] = { + { TERMMOD, XK_Y, selpaste, {.i = 0} }, + { ShiftMask, XK_Insert, selpaste, {.i = 0} }, + { TERMMOD, XK_Num_Lock, numlock, {.i = 0} }, ++ { XK_ANY_MOD, XK_F6, swapcolors, {.i = 0} }, + }; + + /* +diff --git a/st.h b/st.h +index 519b9bd..c25b693 100644 +--- a/st.h ++++ b/st.h +@@ -122,6 +122,7 @@ extern wchar_t *worddelimiters; + extern int allowaltscreen; + extern int allowwindowops; + extern char *termname; ++extern int usealtcolors; + extern unsigned int tabspaces; + extern unsigned int defaultfg; + extern unsigned int defaultbg; +diff --git a/x.c b/x.c +index 8a16faa..4b569df 100644 +--- a/x.c ++++ b/x.c +@@ -55,6 +55,7 @@ static void clipcopy(const Arg *); + static void clippaste(const Arg *); + static void numlock(const Arg *); + static void selpaste(const Arg *); ++static void swapcolors(const Arg *); + static void zoom(const Arg *); + static void zoomabs(const Arg *); + static void zoomreset(const Arg *); +@@ -254,6 +255,8 @@ static char *opt_title = NULL; + + static int oldbutton = 3; /* button event on startup: 3 = release */ + ++int usealtcolors = 0; /* 1 to use alternate palette */ ++ + void + clipcopy(const Arg *dummy) + { +@@ -292,6 +295,18 @@ numlock(const Arg *dummy) + win.mode ^= MODE_NUMLOCK; + } + ++void ++swapcolors(const Arg *arg) ++{ ++ int next = (arg->i == 'D') ? 0 : (arg->i == 'L') ? 1 : !usealtcolors; ++ ++ if (next != usealtcolors) { ++ usealtcolors = next; ++ xloadcols(); ++ redraw(); ++ } ++} ++ + void + zoom(const Arg *arg) + { +@@ -750,6 +765,11 @@ sixd_to_16bit(int x) + return x == 0 ? 0 : 0x3737 + 0x2828 * x; + } + ++const char* getcolorname(int i) ++{ ++ return (usealtcolors) ? altcolorname[i] : colorname[i]; ++} ++ + int + xloadcolor(int i, const char *name, Color *ncolor) + { +@@ -768,7 +788,7 @@ xloadcolor(int i, const char *name, Color *ncolor) + return XftColorAllocValue(xw.dpy, xw.vis, + xw.cmap, &color, ncolor); + } else +- name = colorname[i]; ++ name = getcolorname(i); + } + + return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); +@@ -791,8 +811,8 @@ xloadcols(void) + + for (i = 0; i < dc.collen; i++) + if (!xloadcolor(i, NULL, &dc.col[i])) { +- if (colorname[i]) +- die("could not allocate color '%s'\n", colorname[i]); ++ if (getcolorname(i)) ++ die("could not allocate color '%s'\n", getcolorname(i)); + else + die("could not allocate color %d\n", i); + } +@@ -1184,13 +1204,13 @@ xinit(int cols, int rows) + cursor = XCreateFontCursor(xw.dpy, mouseshape); + XDefineCursor(xw.dpy, xw.win, cursor); + +- if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) { ++ if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousefg), &xmousefg) == 0) { + xmousefg.red = 0xffff; + xmousefg.green = 0xffff; + xmousefg.blue = 0xffff; + } + +- if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) { ++ if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousebg), &xmousebg) == 0) { + xmousebg.red = 0x0000; + xmousebg.green = 0x0000; + xmousebg.blue = 0x0000; +@@ -2008,6 +2028,15 @@ usage(void) + " [stty_args ...]\n", argv0, argv0); + } + ++void ++sig_usr_handler(int num) ++{ ++ Arg a = { .i = (num == 10) ? 'D' : 'L' }; ++ signal(num, sig_usr_handler); ++ swapcolors(&a); ++} ++ ++ + int + main(int argc, char *argv[]) + { +@@ -2066,6 +2095,8 @@ run: + if (!opt_title) + opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0]; + ++ signal(SIGUSR1, sig_usr_handler); ++ signal(SIGUSR2, sig_usr_handler); + setlocale(LC_CTYPE, ""); + XSetLocaleModifiers(""); + cols = MAX(cols, 1); diff --git a/xsession/.xsession b/xsession/.xsession index c2284f7..d2f7262 100755 --- a/xsession/.xsession +++ b/xsession/.xsession @@ -23,7 +23,7 @@ emacsclient --eval nil -a '' & xsettingsd & if which lupan-wm > /dev/null; then - xsetroot -solid '#0ea5e9' + xsetroot -solid '#4a4a4a' lupan-clock & xsetroot -cursor_name left_ptr exec lupan-wm -s 20 diff --git a/xsession/bin/lupan-set-theme b/xsession/bin/lupan-set-theme new file mode 100755 index 0000000..8c45628 --- /dev/null +++ b/xsession/bin/lupan-set-theme @@ -0,0 +1,36 @@ +#!/bin/sh + +THEME="$1" + +if [ "$THEME" = dark ]; then + SIGNAL=USR1 + BGCOLOR=#4a4a4a +elif [ "$THEME" = light ]; then + SIGNAL=USR2 + BGCOLOR=#dde1e3 +else + echo "error: unknown theme: should be either dark or light" >&2 + exit 1 +fi + +# Background color +xsetroot -solid "$BGCOLOR" + +# Alacritty +if [ -f ~/.config/alacritty/alacritty.yml ]; then + sed -i "s/^colors: [*].*/colors: *lupan-$THEME/" ~/.config/alacritty/alacritty.yml +fi + +# ST (patched) +pkill -$SIGNAL -x st + +# GTK +if [ -f ~/.config/xsettingsd/xsettingsd.conf ]; then + sed -i -E "s#(Net/ThemeName) .*#\\1 \"Materia-$THEME\"#" ~/.config/xsettingsd/xsettingsd.conf + pkill -HUP -x xsettingsd +fi + +# Emacs +if which emacsclient > /dev/null; then + emacsclient --eval "(my-select-theme '$THEME)" +fi