From 144aa04b4ac06439095568b87d7109d074ab3bd5 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 11 Jan 2022 08:12:47 -0600 Subject: [PATCH] made my version --- config.def.h | 9 ++ patches/sent-invertedcolors-72d33d4.diff | 73 ++++++++++++++++ patches/sent-options-20190213-72d33d4.diff | 72 ++++++++++++++++ patches/sent-progress-bar-1.0.diff | 31 +++++++ patches/sent-toggle-scm-20210119-2be4210.diff | 79 +++++++++++++++++ sent.1 | 8 ++ sent.c | 85 ++++++++++++++++--- 7 files changed, 346 insertions(+), 11 deletions(-) create mode 100644 patches/sent-invertedcolors-72d33d4.diff create mode 100644 patches/sent-options-20190213-72d33d4.diff create mode 100644 patches/sent-progress-bar-1.0.diff create mode 100644 patches/sent-toggle-scm-20210119-2be4210.diff diff --git a/config.def.h b/config.def.h index 60eb376..c8a66dd 100644 --- a/config.def.h +++ b/config.def.h @@ -13,12 +13,20 @@ static const char *colors[] = { "#FFFFFF", /* background color */ }; +static const char *inverted_colors[] = { + "#FFFFFF", /* foreground color */ + "#000000", /* background color */ +}; + static const float linespacing = 1.4; /* how much screen estate is to be used at max for the content */ static const float usablewidth = 0.75; static const float usableheight = 0.75; +/* height of the presentation progress bar */ +static const int progressheight = 5; + static Mousekey mshortcuts[] = { /* button function argument */ { Button1, advance, {.i = +1} }, @@ -47,6 +55,7 @@ static Shortcut shortcuts[] = { { XK_n, advance, {.i = +1} }, { XK_p, advance, {.i = -1} }, { XK_r, reload, {0} }, + { XK_i, togglescm, {0} }, }; static Filter filters[] = { diff --git a/patches/sent-invertedcolors-72d33d4.diff b/patches/sent-invertedcolors-72d33d4.diff new file mode 100644 index 0000000..2da5fc5 --- /dev/null +++ b/patches/sent-invertedcolors-72d33d4.diff @@ -0,0 +1,73 @@ +diff --git a/config.def.h b/config.def.h +index 60eb376..ccea9a6 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -13,6 +13,11 @@ static const char *colors[] = { + "#FFFFFF", /* background color */ + }; + ++static const char *inverted_colors[] = { ++ "#FFFFFF", /* foreground color */ ++ "#000000", /* background color */ ++}; ++ + static const float linespacing = 1.4; + + /* how much screen estate is to be used at max for the content */ +diff --git a/sent.1 b/sent.1 +index fabc614..f74d583 100644 +--- a/sent.1 ++++ b/sent.1 +@@ -6,6 +6,7 @@ + .Sh SYNOPSIS + .Nm + .Op Fl v ++.Op Fl i + .Op Ar file + .Sh DESCRIPTION + .Nm +@@ -21,6 +22,8 @@ few minutes. + .Bl -tag -width Ds + .It Fl v + Print version information to stdout and exit. ++.It Fl i ++Use the colors from the inverted color array. + .El + .Sh USAGE + .Bl -tag -width Ds +diff --git a/sent.c b/sent.c +index c50a572..c31f772 100644 +--- a/sent.c ++++ b/sent.c +@@ -25,6 +25,8 @@ + + char *argv0; + ++int use_inverted_colors = 0; ++ + /* macros */ + #define LEN(a) (sizeof(a) / sizeof(a)[0]) + #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) +@@ -586,7 +588,11 @@ xinit() + + if (!(d = drw_create(xw.dpy, xw.scr, xw.win, xw.w, xw.h))) + die("sent: Unable to create drawing context"); +- sc = drw_scm_create(d, colors, 2); ++ if (use_inverted_colors) { ++ sc = drw_scm_create(d, inverted_colors, 2); ++ } else { ++ sc = drw_scm_create(d, colors, 2); ++ } + drw_setscheme(d, sc); + XSetWindowBackground(xw.dpy, xw.win, sc[ColBg].pixel); + +@@ -687,6 +693,9 @@ main(int argc, char *argv[]) + case 'v': + fprintf(stderr, "sent-"VERSION"\n"); + return 0; ++ case 'i': ++ use_inverted_colors = 1; ++ break; + default: + usage(); + } ARGEND diff --git a/patches/sent-options-20190213-72d33d4.diff b/patches/sent-options-20190213-72d33d4.diff new file mode 100644 index 0000000..d13df48 --- /dev/null +++ b/patches/sent-options-20190213-72d33d4.diff @@ -0,0 +1,72 @@ +From 3a348cc15a97df8e8784b129800293dcfba28f3f Mon Sep 17 00:00:00 2001 +From: Sunur Efe Vural +Date: Wed, 13 Feb 2019 14:28:17 -0500 +Subject: [PATCH] Commandline Options + +A simple patch that adds extra commandline options to sent. +--- + sent.1 | 11 +++++++++++ + sent.c | 11 ++++++++++- + 2 files changed, 21 insertions(+), 1 deletion(-) + +diff --git a/sent.1 b/sent.1 +index fabc614..5d55bf4 100644 +--- a/sent.1 ++++ b/sent.1 +@@ -5,6 +5,9 @@ + .Nd simple plaintext presentation tool + .Sh SYNOPSIS + .Nm ++.Op Fl f Ar font ++.Op Fl c Ar fgcolor ++.Op Fl b Ar bgcolor + .Op Fl v + .Op Ar file + .Sh DESCRIPTION +@@ -21,6 +24,14 @@ few minutes. + .Bl -tag -width Ds + .It Fl v + Print version information to stdout and exit. ++.It Fl f Ar font ++Defines the ++.Ar font ++when sent is run. ++.It Fl c Ar fgcolor ++Defines the foreground color when sent is run. ++.It Fl b Ar bgcolor ++Defines the background color when sent is run. + .El + .Sh USAGE + .Bl -tag -width Ds +diff --git a/sent.c b/sent.c +index c50a572..0b36e32 100644 +--- a/sent.c ++++ b/sent.c +@@ -675,7 +675,7 @@ configure(XEvent *e) + void + usage() + { +- die("usage: %s [file]", argv0); ++ die("usage: %s [-c fgcolor] [-b bgcolor] [-f font] [file]", argv0); + } + + int +@@ -687,6 +687,15 @@ main(int argc, char *argv[]) + case 'v': + fprintf(stderr, "sent-"VERSION"\n"); + return 0; ++ case 'f': ++ fontfallbacks[0] = EARGF(usage()); ++ break; ++ case 'c': ++ colors[0] = EARGF(usage()); ++ break; ++ case 'b': ++ colors[1] = EARGF(usage()); ++ break; + default: + usage(); + } ARGEND +-- +2.20.1 + diff --git a/patches/sent-progress-bar-1.0.diff b/patches/sent-progress-bar-1.0.diff new file mode 100644 index 0000000..9d0e7d2 --- /dev/null +++ b/patches/sent-progress-bar-1.0.diff @@ -0,0 +1,31 @@ +diff --git a/config.def.h b/config.def.h +index 60eb376..25d89e0 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -19,6 +19,9 @@ static const float linespacing = 1.4; + static const float usablewidth = 0.75; + static const float usableheight = 0.75; + ++/* height of the presentation progress bar */ ++static const int progressheight = 5; ++ + static Mousekey mshortcuts[] = { + /* button function argument */ + { Button1, advance, {.i = +1} }, +diff --git a/sent.c b/sent.c +index c50a572..046466e 100644 +--- a/sent.c ++++ b/sent.c +@@ -533,6 +533,12 @@ xdraw() + 0, + slides[idx].lines[i], + 0); ++ if (idx != 0 && progressheight != 0) { ++ drw_rect(d, ++ 0, xw.h - progressheight, ++ (xw.w * idx)/(slidecount - 1), progressheight, ++ 1, 0); ++ } + drw_map(d, xw.win, 0, 0, xw.w, xw.h); + } else { + if (!(im->state & SCALED)) diff --git a/patches/sent-toggle-scm-20210119-2be4210.diff b/patches/sent-toggle-scm-20210119-2be4210.diff new file mode 100644 index 0000000..12ba579 --- /dev/null +++ b/patches/sent-toggle-scm-20210119-2be4210.diff @@ -0,0 +1,79 @@ +From 2be4210944d97ddb158feee601ec85c016de0872 Mon Sep 17 00:00:00 2001 +From: Randoragon +Date: Tue, 19 Jan 2021 10:17:47 +0100 +Subject: [PATCH] Add toggle colorscheme functionality + +This patch is meant to be applied on top of the "inverted colors" patch +(https://tools.suckless.org/sent/patches/inverted-colors/). It creates a +new binding, "i", that lets you toggle between two colorschemes during +presentation. +--- + config.def.h | 1 + + sent.1 | 2 ++ + sent.c | 18 ++++++++++++++++++ + 3 files changed, 21 insertions(+) + +diff --git a/config.def.h b/config.def.h +index ccea9a6..c72afc5 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -52,6 +52,7 @@ static Shortcut shortcuts[] = { + { XK_n, advance, {.i = +1} }, + { XK_p, advance, {.i = -1} }, + { XK_r, reload, {0} }, ++ { XK_i, togglescm, {0} }, + }; + + static Filter filters[] = { +diff --git a/sent.1 b/sent.1 +index f74d583..a7564a8 100644 +--- a/sent.1 ++++ b/sent.1 +@@ -44,6 +44,8 @@ Reload the slides. Only works on file input. + Go to next slide, if existent. + .It Sy Left | Backspace | h | k | Up | Prior | p + Go to previous slide, if existent. ++.It Sy i ++Toggle colorschemes. + .El + .El + .Sh FORMAT +diff --git a/sent.c b/sent.c +index 7053ab3..d29fc35 100644 +--- a/sent.c ++++ b/sent.c +@@ -107,6 +107,7 @@ static void xdraw(); + static void xhints(); + static void xinit(); + static void xloadfonts(); ++static void togglescm(); + + static void bpress(XEvent *); + static void cmessage(XEvent *); +@@ -613,6 +614,23 @@ xinit() + XSync(xw.dpy, False); + } + ++void ++togglescm() ++{ ++ if (use_inverted_colors) { ++ free(sc); ++ sc = drw_scm_create(d, colors, 2); ++ use_inverted_colors = 0; ++ } else { ++ sc = drw_scm_create(d, inverted_colors, 2); ++ use_inverted_colors = 1; ++ } ++ drw_setscheme(d, sc); ++ XSetWindowBackground(xw.dpy, xw.win, sc[ColBg].pixel); ++ xdraw(); ++} ++ ++ + void + xloadfonts() + { +-- +2.30.0 + diff --git a/sent.1 b/sent.1 index fabc614..4d137bb 100644 --- a/sent.1 +++ b/sent.1 @@ -5,7 +5,11 @@ .Nd simple plaintext presentation tool .Sh SYNOPSIS .Nm +.Op Fl f Ar font +.Op Fl c Ar fgcolor +.Op Fl b Ar bgcolor .Op Fl v +.Op Fl i .Op Ar file .Sh DESCRIPTION .Nm @@ -21,6 +25,8 @@ few minutes. .Bl -tag -width Ds .It Fl v Print version information to stdout and exit. +.It Fl i +Use the colors from the inverted color array. .El .Sh USAGE .Bl -tag -width Ds @@ -41,6 +47,8 @@ Reload the slides. Only works on file input. Go to next slide, if existent. .It Sy Left | Backspace | h | k | Up | Prior | p Go to previous slide, if existent. +.It Sy i +Toggle colorschemes. .El .El .Sh FORMAT diff --git a/sent.c b/sent.c index 9534fca..701787f 100644 --- a/sent.c +++ b/sent.c @@ -25,6 +25,8 @@ char *argv0; +int use_inverted_colors = 0; + /* macros */ #define LEN(a) (sizeof(a) / sizeof(a)[0]) #define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) @@ -51,6 +53,7 @@ typedef struct { typedef struct { unsigned int linecount; char **lines; + int *invert; Image *img; char *embed; } Slide; @@ -105,6 +108,7 @@ static void xdraw(); static void xhints(); static void xinit(); static void xloadfonts(); +static void togglescm(); static void bpress(XEvent *); static void cmessage(XEvent *); @@ -409,6 +413,7 @@ load(FILE *fp) static size_t size = 0; size_t blen, maxlines; char buf[BUFSIZ], *p; + int inverted = 0; Slide *s; /* read each line from fp and add it to the item list */ @@ -435,13 +440,23 @@ load(FILE *fp) if (buf[0] == '#') continue; + inverted = 0; + if (buf[0] == '$') { + buf[0] = ' '; + inverted = 1; + } + /* grow lines array */ if (s->linecount >= maxlines) { maxlines = 2 * s->linecount + 1; if (!(s->lines = realloc(s->lines, maxlines * sizeof(s->lines[0])))) die("sent: Unable to reallocate %u bytes:", maxlines * sizeof(s->lines[0])); + if (!(s->invert = realloc(s->invert, maxlines * sizeof(s->invert[0])))) + die("sent: Unable to reallocate %u bytes:", maxlines * sizeof(s->invert[0])); } + s->invert[s->linecount] = inverted; + blen = strlen(buf); if (!(s->lines[s->linecount] = strdup(buf))) die("sent: Unable to strdup:"); @@ -528,15 +543,30 @@ xdraw() if (!im) { drw_rect(d, 0, 0, xw.w, xw.h, 1, 1); - for (i = 0; i < slides[idx].linecount; i++) - drw_text(d, - (xw.w - width) / 2, - (xw.h - height) / 2 + i * linespacing * d->fonts->h, - width, - d->fonts->h, - 0, - slides[idx].lines[i], - 0); + for (i = 0; i < slides[idx].linecount; i++) { + if (slides[idx].invert[i]) { + drw_rect(d, + 0, + (xw.h - height) / 2 + i * linespacing * d->fonts->h, + xw.w, + d->fonts->h, 1, 0); + } + + drw_text(d, + (xw.w - width) / 2, + (xw.h - height) / 2 + i * linespacing * d->fonts->h, + width, + d->fonts->h, + 0, + slides[idx].lines[i], + slides[idx].invert[i]); + } + if (idx != 0 && progressheight != 0) { + drw_rect(d, + 0, xw.h - progressheight, + (xw.w * idx)/(slidecount - 1), progressheight, + 1, 0); + } drw_map(d, xw.win, 0, 0, xw.w, xw.h); } else { if (!(im->state & SCALED)) @@ -590,7 +620,11 @@ xinit() if (!(d = drw_create(xw.dpy, xw.scr, xw.win, xw.w, xw.h))) die("sent: Unable to create drawing context"); - sc = drw_scm_create(d, colors, 2); + if (use_inverted_colors) { + sc = drw_scm_create(d, inverted_colors, 2); + } else { + sc = drw_scm_create(d, colors, 2); + } drw_setscheme(d, sc); XSetWindowBackground(xw.dpy, xw.win, sc[ColBg].pixel); @@ -607,6 +641,23 @@ xinit() XSync(xw.dpy, False); } +void +togglescm() +{ + if (use_inverted_colors) { + free(sc); + sc = drw_scm_create(d, colors, 2); + use_inverted_colors = 0; + } else { + sc = drw_scm_create(d, inverted_colors, 2); + use_inverted_colors = 1; + } + drw_setscheme(d, sc); + XSetWindowBackground(xw.dpy, xw.win, sc[ColBg].pixel); + xdraw(); +} + + void xloadfonts() { @@ -679,7 +730,7 @@ configure(XEvent *e) void usage() { - die("usage: %s [file]", argv0); + die("usage: %s [-c fgcolor] [-b bgcolor] [-f font] [file]", argv0); } int @@ -691,6 +742,18 @@ main(int argc, char *argv[]) case 'v': fprintf(stderr, "sent-"VERSION"\n"); return 0; + case 'i': + use_inverted_colors = 1; + break; + case 'f': + fontfallbacks[0] = EARGF(usage()); + break; + case 'c': + colors[0] = EARGF(usage()); + break; + case 'b': + colors[1] = EARGF(usage()); + break; default: usage(); } ARGEND -- 2.25.1