[wiki] [sites] [sent][patch][pdf] Updated pdf patch to generate pdf from stdin || Bryce Vandegrift

From: <git_AT_suckless.org>
Date: Sun, 23 Apr 2023 20:22:48 +0200

commit b53e6536f9d00546616250dec5c19ee7cd460f5f
Author: Bryce Vandegrift <bryce_AT_brycevandegrift.xyz>
Date: Sun Apr 23 14:19:16 2023 -0400

    [sent][patch][pdf] Updated pdf patch to generate pdf from stdin

diff --git a/tools.suckless.org/sent/patches/pdf/index.md b/tools.suckless.org/sent/patches/pdf/index.md
index 27568fcd..5fa0e78b 100644
--- a/tools.suckless.org/sent/patches/pdf/index.md
+++ b/tools.suckless.org/sent/patches/pdf/index.md
_AT_@ -10,6 +10,7 @@ generated using the current window resolution.
 Download
 --------
 * [sent-pdf-2649e8d.diff](sent-pdf-2649e8d.diff) (20201114)
+* [sent-pdf-e3b86c2.diff](sent-pdf-e3b86c2.diff) (20230423)
 
 Authors
 ------
diff --git a/tools.suckless.org/sent/patches/pdf/sent-pdf-e3b86c2.diff b/tools.suckless.org/sent/patches/pdf/sent-pdf-e3b86c2.diff
new file mode 100644
index 00000000..56b7d205
--- /dev/null
+++ b/tools.suckless.org/sent/patches/pdf/sent-pdf-e3b86c2.diff
_AT_@ -0,0 +1,127 @@
+From e3b86c2910111f7bb004833c8036122d5256ba3c Mon Sep 17 00:00:00 2001
+From: Bryce Vandegrift <bryce_AT_brycevandegrift.xyz>
+Date: Sun, 23 Apr 2023 14:03:40 -0400
+Subject: [PATCH] Use default filename if reading stdin
+
+---
+ config.def.h | 1 +
+ config.mk | 7 +++++--
+ sent.c | 45 +++++++++++++++++++++++++++++++++++++++++----
+ 3 files changed, 47 insertions(+), 6 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 60eb376..26c01b4 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -47,6 +47,7 @@ static Shortcut shortcuts[] = {
+ { XK_n, advance, {.i = +1} },
+ { XK_p, advance, {.i = -1} },
+ { XK_r, reload, {0} },
++ { XK_g, pdf, {0} },
+ };
+
+ static Filter filters[] = {
+diff --git a/config.mk b/config.mk
+index d61c554..9174687 100644
+--- a/config.mk
++++ b/config.mk
+_AT_@ -7,14 +7,17 @@ VERSION = 1
+ PREFIX = /usr/local
+ MANPREFIX = ${PREFIX}/share/man
+
++PKG_CONFIG = pkg-config
++
+ X11INC = /usr/X11R6/include
+ X11LIB = /usr/X11R6/lib
+
+ # includes and libs
+ INCS = -I. -I/usr/include -I/usr/include/freetype2 -I${X11INC}
+-LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11
++LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 -lcairo
+ # OpenBSD (uncomment)
+-#INCS = -I. -I${X11INC} -I${X11INC}/freetype2
++INCS = -I. -I${X11INC} -I${X11INC}/freetype2 `${PKG_CONFIG} --cflags cairo`
++LIBS += -L/usr/local/lib
+ # FreeBSD (uncomment)
+ #INCS = -I. -I/usr/local/include -I/usr/local/include/freetype2 -I${X11INC}
+ #LIBS = -L/usr/local/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11
+diff --git a/sent.c b/sent.c
+index dfadd3a..a935554 100644
+--- a/sent.c
++++ b/sent.c
+_AT_@ -19,6 +19,10 @@
+ #include <X11/Xutil.h>
+ #include <X11/Xft/Xft.h>
+
++#include <cairo/cairo.h>
++#include <cairo/cairo-xlib.h>
++#include <cairo/cairo-pdf.h>
++
+ #include "arg.h"
+ #include "util.h"
+ #include "drw.h"
+_AT_@ -97,6 +101,7 @@ static void cleanup(int slidesonly);
+ static void reload(const Arg *arg);
+ static void load(FILE *fp);
+ static void advance(const Arg *arg);
++static void pdf();
+ static void quit(const Arg *arg);
+ static void resize(int width, int height);
+ static void run(void);
+_AT_@ -430,10 +435,6 @@ load(FILE *fp)
+ maxlines = 0;
+ memset((s = &slides[slidecount]), 0, sizeof(Slide));
+ do {
+- /* if there's a leading null, we can't do blen-1 */
+- if (buf[0] == '+- continue;
+-
+ if (buf[0] == '#')
+ continue;
+
+_AT_@ -481,6 +482,42 @@ advance(const Arg *arg)
+ }
+ }
+
++void
++pdf()
++{
++ const Arg next = { .i = 1 };
++ Arg first;
++ cairo_surface_t *cs;
++
++ if (!fname)
++ fname = "slides";
++
++ char filename[strlen(fname) + 5];
++ sprintf(filename, "%s.pdf", fname);
++ cairo_surface_t *pdf = cairo_pdf_surface_create(filename, xw.w, xw.h);
++
++ cairo_t *cr = cairo_create(pdf);
++
++ first.i = -idx;
++ advance(&first);
++
++ cs = cairo_xlib_surface_create(xw.dpy, xw.win, xw.vis, xw.w, xw.h);
++ cairo_set_source_surface(cr, cs, 0.0, 0.0);
++ for (int i = 0; i < slidecount; ++i) {
++ cairo_paint(cr);
++ cairo_show_page(cr);
++ cairo_surface_flush(cs);
++ advance(&next);
++ cairo_surface_mark_dirty(cs);
++ }
++ cairo_surface_destroy(cs);
++
++ cairo_destroy(cr);
++ cairo_surface_destroy(pdf);
++ first.i = -(slidecount-1);
++ advance(&first);
++}
++
+ void
+ quit(const Arg *arg)
+ {
+--
+2.40.0
+
Received on Sun Apr 23 2023 - 20:22:48 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 23 2023 - 20:24:52 CEST