shithub: misc

Download patch

ref: 4e7da28c9aec8d91f9484a55b19c762d828a34f3
parent: 437dd078d386f429501f374306dcfdd536d13093
author: Philip Silva <philip.silva@protonmail.com>
date: Sat Sep 18 08:48:11 EDT 2021

patch for adding int dpi fields in dev/libdraw

--- a/README
+++ b/README
@@ -1,3 +1,5 @@
 Various unsorted stuff
 
+- hidpi-1.patch: wip from p9p to add dpi field to Display
+              (p9p commit d0e0701913f3aede1fcb256f3d1e9c60c9a)
 - acme-at.patch: can be applied to open paths containing @s (e.g. the internal Go module paths)
--- /dev/null
+++ b/hidpi-1.patch
@@ -1,0 +1,114 @@
+diff c7dcc82b0be805717efbe77c98eaadf3ee1e31af uncommitted
+--- a/sys/include/ape/draw.h
++++ b/sys/include/ape/draw.h
+@@ -208,6 +208,7 @@
+ 	Image		*windows;
+ 	Image		*screenimage;
+ 	int			_isnewdisplay;
++	int			dpi;
+ };
+ 
+ struct Image
+--- a/sys/include/draw.h
++++ b/sys/include/draw.h
+@@ -200,6 +200,10 @@
+ 	Image		*windows;
+ 	Image		*screenimage;
+ 	int		_isnewdisplay;
++	int		dpi;
+ };
+ 
+ struct Image
+--- a/sys/src/9/port/devdraw.c
++++ b/sys/src/9/port/devdraw.c
+@@ -77,6 +77,8 @@
+ 	int		refreshme;
+ 	int		infoid;
+ 	int		op;
++	int		displaydpi;
++	int		forcedpi;
+ };
+ 
+ struct Refresh
+@@ -166,6 +168,8 @@
+ 	void		drawfreedimage(DImage*);
+ 	Client*		drawclientofpath(ulong);
+ 	DImage*	allocdimage(Memimage*);
++	
++int displaydpi = 100;
+ 
+ static	char Enodrawimage[] =	"unknown id for draw image";
+ static	char Enodrawscreen[] =	"unknown id for draw screen";
+@@ -785,6 +789,7 @@
+ 	cl->slot = i;
+ 	cl->clientid = ++sdraw.clientid;
+ 	cl->op = SoverD;
++	cl->displaydpi=100;
+ 	sdraw.client[i] = cl;
+ 	return cl;
+ }
+@@ -1396,6 +1401,7 @@
+ 	int c, repl, m, y, dstid, scrnid, ni, ci, j, nw, e0, e1, op, ox, oy, oesize, esize, doflush;
+ 	uchar *u, *a, refresh;
+ 	char *fmt;
++	Fmt f;
+ 	ulong value, chan;
+ 	Rectangle r, clipr;
+ 	Point p, q, *pp, sp;
+@@ -1643,6 +1649,35 @@
+ 			font->nfchar = ni;
+ 			font->ascent = a[9];
+ 			continue;
++		
++		/* query: 'Q' n[1] queryspec[n] */
++		case 'q':
++			if(n < 2) {
++				error(Eshortdraw);
++			}
++			m = 1+1+a[1];
++			if(n < m) {
++				error(Eshortdraw);
++			}
++			fmtstrinit(&f);
++			for(c=0; c<a[1]; c++) {
++				switch(a[2+c]) {
++				default:
++					error("unknown query");
++				case 'd':       /* dpi */
++					if(client->forcedpi)
++						fmtprint(&f, "%11d ", client->forcedpi);
++					else
++						fmtprint(&f, "%11d ", client->displaydpi);
++					break;
++				}
++			}
++			client->readdata = (uchar*)fmtstrflush(&f);
++			if(client->readdata == nil)
++				error(Enomem);
++			client->nreaddata = strlen((char*)client->readdata);
++			continue;
++
+ 
+ 		/* load character: 'l' fontid[4] srcid[4] index[2] R[4*4] P[2*4] left[1] width[1] */
+ 		case 'l':
+--- a/sys/src/libdraw/alloc.c
++++ b/sys/src/libdraw/alloc.c
+@@ -170,6 +170,19 @@
+ 	i->clipr.max.y = atoi(buf+11*12);
+ 	i->screen = nil;
+ 	i->next = nil;
++		
++		/* flush pending data so we don't get error allocating the image */
++		flushimage(d, 0);
++		a = bufimage(d, 3);
++		if(a == nil)
++			goto Error;
++		a[0] = 'q';
++		a[1] = 1;
++		a[2] = 'd';
++		d->dpi = 100;
++		if (flushimage(d, 0) >= 0 && pread(d->ctlfd, buf, 12, 0) == 12)
++			d->dpi = atoi(buf);
+ 	return i;
+ }
+