shithub: misc

ref: 001e60ea4b45fec9cb40ab8fbbebc334b4d3e9f4
dir: misc/hidpi-3.patch

View raw version
diff 75d8e460a00505c2b21a0d06ceb4300c93d9c4d6 uncommitted
--- a/sys/include/ape/draw.h
+++ b/sys/include/ape/draw.h
@@ -69,6 +69,7 @@
 	Displaybufsize	= 8000,
 	ICOSSCALE	= 1024,
 	Borderwidth =	4,
+	DefaultDPI  =	100,
 };
 
 enum
@@ -358,6 +359,7 @@
 extern Image*	namedimage(Display*, char*);
 extern int	nameimage(Image*, char*, int);
 extern Image* allocimagemix(Display*, ulong, ulong);
+extern int scalesize(Display*, int);
 
 /*
  * Colors
--- a/sys/include/draw.h
+++ b/sys/include/draw.h
@@ -61,6 +61,7 @@
 	Displaybufsize	= 8000,
 	ICOSSCALE	= 1024,
 	Borderwidth =	4,
+	DefaultDPI  =	100,
 };
 
 enum
@@ -354,6 +355,7 @@
 extern Image*	namedimage(Display*, char*);
 extern int	nameimage(Image*, char*, int);
 extern Image* allocimagemix(Display*, ulong, ulong);
+extern int scalesize(Display*, int);
 
 /*
  * Colors
--- a/sys/src/cmd/acme/dat.h
+++ b/sys/src/cmd/acme/dat.h
@@ -473,11 +473,14 @@
 	BUFSIZE = Maxblock+IOHDRSZ,	/* size from fbufalloc() */
 	RBUFSIZE = BUFSIZE/sizeof(Rune),
 	EVENTSIZE = 256,
-	Scrollwid = 12,	/* width of scroll bar */
-	Scrollgap = 4,	/* gap right of scroll bar */
-	Margin = 4,	/* margin around text */
-	Border = 2,	/* line between rows, cols, windows */
 };
+
+// like in p9p c96d832
+#define Scrollwid scalesize(display, 12)	/* width of scroll bar */
+#define Scrollgap scalesize(display, 4)	/* gap right of scroll bar */
+#define Margin scalesize(display, 4)	/* margin around text */
+#define Border scalesize(display, 2)	/* line between rows, cols, windows */
+#define ButtonBorder scalesize(display, 2)
 
 #define	QID(w,q)	((w<<8)|(q))
 #define	WIN(q)	((((ulong)(q).path)>>8) & 0xFFFFFF)
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -12,6 +12,14 @@
 #include "dat.h"
 #include "fns.h"
 
+static int
+wscale(Window *w, int n)
+{
+        if(w == nil || w->i == nil)
+                return n;
+        return scalesize(w->i->display, n);
+}
+
 Window*
 wlookid(int id)
 {
@@ -308,7 +316,7 @@
 		else
 			col = lighttitlecol;
 	}
-	border(w->i, w->i->r, Selborder, col, ZP);
+	border(w->i, w->i->r, wscale(w, Selborder), col, ZP);
 }
 
 static void
@@ -353,17 +361,17 @@
 
 	w->i = i;
 	w->mc.image = i;
-	r = insetrect(i->r, Selborder+1);
+	r = insetrect(i->r, wscale(w, Selborder)+wscale(w, 1));
 	w->scrollr = r;
-	w->scrollr.max.x = r.min.x+Scrollwid;
+	w->scrollr.max.x = r.min.x+wscale(w, Scrollwid);
 	w->lastsr = ZR;
-	r.min.x += Scrollwid+Scrollgap;
+	r.min.x += wscale(w, Scrollwid)+wscale(w, Scrollgap);
 	frclear(w, FALSE);
 	frinit(w, r, w->font, w->i, cols);
 	wsetcols(w, w == input);
 	w->maxtab = maxtab*stringwidth(w->font, "0");
 	if(!w->mouseopen || !w->winnameread){
-		r = insetrect(w->i->r, Selborder);
+		r = insetrect(w->i->r, wscale(w, Selborder));
 		draw(w->i, r, cols[BACK], nil, w->entire.min);
 		wfill(w);
 		wsetselect(w, w->q0, w->q1);
@@ -370,7 +378,7 @@
 		wscrdraw(w);
 	}
 	if(w == input)
-		wborder(w, Selborder);
+		wborder(w, wscale(w, Selborder));
 	else
 		wborder(w, Unselborder);
 	flushimage(display, 1);
@@ -390,9 +398,9 @@
 	if(!w->mouseopen || !w->winnameread)
 		frredraw(w);
 	if(w == input)
-		wborder(w, Selborder);
+		wborder(w, wscale(w, Selborder));
 	else
-		wborder(w, Unselborder);
+		wborder(w, wscale(w, Unselborder));
 }
 
 static void
@@ -401,9 +409,9 @@
 	Rectangle r;
 
 	if(w == input)
-		wborder(w, Selborder);
+		wborder(w, wscale(w, Selborder));
 	else
-		wborder(w, Unselborder);
+		wborder(w, wscale(w, Unselborder));
 	r = insetrect(w->i->r, Selborder);
 	draw(w->i, r, w->cols[BACK], nil, w->entire.min);
 	wfill(w);
@@ -1249,7 +1257,7 @@
 
 	w = emalloc(sizeof(Window));
 	w->screenr = i->r;
-	r = insetrect(i->r, Selborder+1);
+	r = insetrect(i->r, wscale(w, Selborder)+wscale(w, 1));
 	w->i = i;
 	w->mc = *mc;
 	w->ck = ck;
@@ -1263,9 +1271,9 @@
 	w->complete = chancreate(sizeof(Completion*), 0);
 	w->gone = chancreate(sizeof(char*), 0);
 	w->scrollr = r;
-	w->scrollr.max.x = r.min.x+Scrollwid;
+	w->scrollr.max.x = r.min.x+wscale(w, Scrollwid);
 	w->lastsr = ZR;
-	r.min.x += Scrollwid+Scrollgap;
+	r.min.x += wscale(w, Scrollwid)+wscale(w, Scrollgap);
 	frinit(w, r, font, i, cols);
 	w->maxtab = maxtab*stringwidth(font, "0");
 	w->topped = ++topped;
@@ -1274,9 +1282,9 @@
 	w->scrolling = scrolling;
 	w->dir = estrdup(startdir);
 	w->label = estrdup("<unnamed>");
-	r = insetrect(w->i->r, Selborder);
+	r = insetrect(w->i->r, wscale(w, Selborder));
 	draw(w->i, r, cols[BACK], nil, w->entire.min);
-	wborder(w, Selborder);
+	wborder(w, wscale(w, Selborder));
 	wscrdraw(w);
 	incref(w);	/* ref will be removed after mounting; avoids delete before ready to be deleted */
 	return w;
--- a/sys/src/libdraw/init.c
+++ b/sys/src/libdraw/init.c
@@ -454,3 +467,10 @@
  	return p;
 }
 
+int
+scalesize(Display *d, int n)
+{
+	if(d == nil || d->dpi <= DefaultDPI)
+		return n;
+	return (n*d->dpi+DefaultDPI/2)/DefaultDPI;
+}