sent-pdf-e3b86c2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       sent-pdf-e3b86c2.diff (3295B)
       ---
            1 From e3b86c2910111f7bb004833c8036122d5256ba3c Mon Sep 17 00:00:00 2001
            2 From: Bryce Vandegrift <bryce@brycevandegrift.xyz>
            3 Date: Sun, 23 Apr 2023 14:03:40 -0400
            4 Subject: [PATCH] Use default filename if reading stdin
            5 
            6 ---
            7  config.def.h |  1 +
            8  config.mk    |  7 +++++--
            9  sent.c       | 45 +++++++++++++++++++++++++++++++++++++++++----
           10  3 files changed, 47 insertions(+), 6 deletions(-)
           11 
           12 diff --git a/config.def.h b/config.def.h
           13 index 60eb376..26c01b4 100644
           14 --- a/config.def.h
           15 +++ b/config.def.h
           16 @@ -47,6 +47,7 @@ static Shortcut shortcuts[] = {
           17          { XK_n,           advance,        {.i = +1} },
           18          { XK_p,           advance,        {.i = -1} },
           19          { XK_r,           reload,         {0} },
           20 +        { XK_g,           pdf,            {0} },
           21  };
           22  
           23  static Filter filters[] = {
           24 diff --git a/config.mk b/config.mk
           25 index d61c554..9174687 100644
           26 --- a/config.mk
           27 +++ b/config.mk
           28 @@ -7,14 +7,17 @@ VERSION = 1
           29  PREFIX = /usr/local
           30  MANPREFIX = ${PREFIX}/share/man
           31  
           32 +PKG_CONFIG = pkg-config
           33 +
           34  X11INC = /usr/X11R6/include
           35  X11LIB = /usr/X11R6/lib
           36  
           37  # includes and libs
           38  INCS = -I. -I/usr/include -I/usr/include/freetype2 -I${X11INC}
           39 -LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11
           40 +LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11 -lcairo
           41  # OpenBSD (uncomment)
           42 -#INCS = -I. -I${X11INC} -I${X11INC}/freetype2
           43 +INCS = -I. -I${X11INC} -I${X11INC}/freetype2 `${PKG_CONFIG} --cflags cairo`
           44 +LIBS += -L/usr/local/lib
           45  # FreeBSD (uncomment)
           46  #INCS = -I. -I/usr/local/include -I/usr/local/include/freetype2 -I${X11INC}
           47  #LIBS = -L/usr/local/lib -lc -lm -L${X11LIB} -lXft -lfontconfig -lX11
           48 diff --git a/sent.c b/sent.c
           49 index dfadd3a..a935554 100644
           50 --- a/sent.c
           51 +++ b/sent.c
           52 @@ -19,6 +19,10 @@
           53  #include <X11/Xutil.h>
           54  #include <X11/Xft/Xft.h>
           55  
           56 +#include <cairo/cairo.h>
           57 +#include <cairo/cairo-xlib.h>
           58 +#include <cairo/cairo-pdf.h>
           59 +
           60  #include "arg.h"
           61  #include "util.h"
           62  #include "drw.h"
           63 @@ -97,6 +101,7 @@ static void cleanup(int slidesonly);
           64  static void reload(const Arg *arg);
           65  static void load(FILE *fp);
           66  static void advance(const Arg *arg);
           67 +static void pdf();
           68  static void quit(const Arg *arg);
           69  static void resize(int width, int height);
           70  static void run(void);
           71 @@ -430,10 +435,6 @@ load(FILE *fp)
           72                  maxlines = 0;
           73                  memset((s = &slides[slidecount]), 0, sizeof(Slide));
           74                  do {
           75 -                        /* if there's a leading null, we can't do blen-1 */
           76 -                        if (buf[0] == '\0')
           77 -                                continue;
           78 -
           79                          if (buf[0] == '#')
           80                                  continue;
           81  
           82 @@ -481,6 +482,42 @@ advance(const Arg *arg)
           83          }
           84  }
           85  
           86 +void
           87 +pdf()
           88 +{
           89 +        const Arg next = { .i = 1 };
           90 +        Arg first;
           91 +        cairo_surface_t *cs;
           92 +
           93 +        if (!fname)
           94 +                fname = "slides";
           95 +
           96 +        char filename[strlen(fname) + 5];
           97 +        sprintf(filename, "%s.pdf", fname);
           98 +        cairo_surface_t *pdf = cairo_pdf_surface_create(filename, xw.w, xw.h);
           99 +
          100 +        cairo_t *cr = cairo_create(pdf);
          101 +
          102 +        first.i = -idx;
          103 +        advance(&first);
          104 +
          105 +        cs = cairo_xlib_surface_create(xw.dpy, xw.win, xw.vis, xw.w, xw.h);
          106 +        cairo_set_source_surface(cr, cs, 0.0, 0.0);
          107 +        for (int i = 0; i < slidecount; ++i) {
          108 +                cairo_paint(cr);
          109 +                cairo_show_page(cr);
          110 +                cairo_surface_flush(cs);
          111 +                advance(&next);
          112 +                cairo_surface_mark_dirty(cs);
          113 +        }
          114 +        cairo_surface_destroy(cs);
          115 +
          116 +        cairo_destroy(cr);
          117 +        cairo_surface_destroy(pdf);
          118 +        first.i = -(slidecount-1);
          119 +        advance(&first);
          120 +}
          121 +
          122  void
          123  quit(const Arg *arg)
          124  {
          125 -- 
          126 2.40.0
          127