sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-anygeometry-0.8.1.diff (2817B)


      1 From 6a5a862569912e34febe2dbd5244062013840204 Mon Sep 17 00:00:00 2001
      2 From: =?UTF-8?q?Jos=C3=A9=20Miguel=20S=C3=A1nchez=20Garc=C3=ADa?=
      3  <soy.jmi2k@gmail.com>
      4 Date: Thu, 13 Aug 2020 11:02:01 +0000
      5 Subject: [PATCH] add -G to set pixel-based geometry
      6 
      7 ---
      8  config.def.h | 13 +++++++++++++
      9  x.c          | 36 ++++++++++++++++++++++++++++++++----
     10  2 files changed, 45 insertions(+), 4 deletions(-)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 6f05dce..bea316a 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -141,6 +141,12 @@ static unsigned int defaultrcs = 257;
     17   */
     18  static unsigned int cursorshape = 2;
     19  
     20 +/*
     21 + * Whether to use pixel geometry or cell geometry
     22 + */
     23 +
     24 +static Geometry geometry = CellGeometry;
     25 +
     26  /*
     27   * Default columns and rows numbers
     28   */
     29 @@ -148,6 +154,13 @@ static unsigned int cursorshape = 2;
     30  static unsigned int cols = 80;
     31  static unsigned int rows = 24;
     32  
     33 +/*
     34 + * Default width and height (including borders!)
     35 + */
     36 +
     37 +static unsigned int width = 564;
     38 +static unsigned int height = 364;
     39 +
     40  /*
     41   * Default colour and shape of the mouse cursor
     42   */
     43 diff --git a/x.c b/x.c
     44 index 210f184..29e35d0 100644
     45 --- a/x.c
     46 +++ b/x.c
     47 @@ -45,6 +45,11 @@ typedef struct {
     48  	signed char appcursor; /* application cursor */
     49  } Key;
     50  
     51 +typedef enum {
     52 +	PixelGeometry,
     53 +	CellGeometry
     54 +} Geometry;
     55 +
     56  /* X modifiers */
     57  #define XK_ANY_MOD    UINT_MAX
     58  #define XK_NO_MOD     0
     59 @@ -1096,7 +1101,7 @@ xicdestroy(XIC xim, XPointer client, XPointer call)
     60  }
     61  
     62  void
     63 -xinit(int cols, int rows)
     64 +xinit(int w, int h)
     65  {
     66  	XGCValues gcvalues;
     67  	Cursor cursor;
     68 @@ -1121,8 +1126,16 @@ xinit(int cols, int rows)
     69  	xloadcols();
     70  
     71  	/* adjust fixed window geometry */
     72 -	win.w = 2 * borderpx + cols * win.cw;
     73 -	win.h = 2 * borderpx + rows * win.ch;
     74 +	switch (geometry) {
     75 +	case CellGeometry:
     76 +		win.w = 2 * borderpx + w * win.cw;
     77 +		win.h = 2 * borderpx + h * win.ch;
     78 +		break;
     79 +	case PixelGeometry:
     80 +		win.w = w;
     81 +		win.h = h;
     82 +		break;
     83 +	}
     84  	if (xw.gm & XNegative)
     85  		xw.l += DisplayWidth(xw.dpy, xw.scr) - win.w - 2;
     86  	if (xw.gm & YNegative)
     87 @@ -2001,6 +2014,12 @@ main(int argc, char *argv[])
     88  	case 'g':
     89  		xw.gm = XParseGeometry(EARGF(usage()),
     90  				&xw.l, &xw.t, &cols, &rows);
     91 +		geometry = CellGeometry;
     92 +		break;
     93 +	case 'G':
     94 +		xw.gm = XParseGeometry(EARGF(usage()),
     95 +				&xw.l, &xw.t, &width, &height);
     96 +		geometry = PixelGeometry;
     97  		break;
     98  	case 'i':
     99  		xw.isfixed = 1;
    100 @@ -2037,10 +2056,19 @@ run:
    101  
    102  	setlocale(LC_CTYPE, "");
    103  	XSetLocaleModifiers("");
    104 +	switch (geometry) {
    105 +	case CellGeometry:
    106 +		xinit(cols, rows);
    107 +		break;
    108 +	case PixelGeometry:
    109 +		xinit(width, height);
    110 +		cols = (win.w - 2 * borderpx) / win.cw;
    111 +		rows = (win.h - 2 * borderpx) / win.ch;
    112 +		break;
    113 +	}
    114  	cols = MAX(cols, 1);
    115  	rows = MAX(rows, 1);
    116  	tnew(cols, rows);
    117 -	xinit(cols, rows);
    118  	xsetenv();
    119  	selinit();
    120  	run();
    121 -- 
    122 2.28.0
    123