ref: 7ad0e7ef7f494a83a2240ab548b6f4ad321ca345
parent: 91312db589b1e682488290e59a6358e78d35c772
author: phil9 <[email protected]>
date: Thu Dec 29 02:09:28 EST 2022
enforce a minimal size on window make sure window size can fit the bare minimum to make nc usable
--- a/a.h
+++ b/a.h
@@ -159,6 +159,7 @@
int rmdir(char*);
int cp(char*, Dir, char*, char*);
+int wresize(int, int);
Rectangle boundsrect(Rectangle);
Image* ealloccolor(ulong);
void* emalloc(ulong);
--- a/main.c
+++ b/main.c
@@ -9,6 +9,7 @@
Text *text;
Actionbar *abar;
Binding *bindings;
+Point minbounds;
void
colsinit(void)
@@ -53,12 +54,24 @@
flushimage(display, 1);
}
+int
+max(int x, int y)
+{
+ if(x > y)
+ return x;
+ return y;
+}
+
void
resize(void)
{
Rectangle dr, ar;
- int ah;
+ int ah, sx, sy;
+ sx = Dx(screen->r) + 2*4; /* 4 is rio window border width */
+ sy = Dy(screen->r) + 2*4;
+ if((sx < minbounds.x) || (sy < minbounds.y))
+ wresize(max(sx, minbounds.x), max(sy, minbounds.y));
ah = 2+font->height+2;
dr = screen->r;
dr.max.y -= ah;
@@ -160,6 +173,7 @@
abar = mkactionbar();
colsinit();
tickinit();
+ minbounds = Pt(10*9*stringwidth(font, "X"), 10*font->height); /* 10*9 is 10 action buttons with max 9 chars */
resize();
setmode(Mdir);
alts[Emouse].c = mc->c;
--- a/utils.c
+++ b/utils.c
@@ -99,3 +99,21 @@
cleanname(s);
return s;
}
+
+int
+wresize(int w, int h)
+{
+ int fd, n;
+ char buf[255];
+
+ fd = open("/dev/wctl", OWRITE|OCEXEC);
+ if(fd < 0)
+ return -1;
+ n = snprint(buf, sizeof buf, "resize -dx %d -dy %d", w, h);
+ if(write(fd, buf, n) != n){
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}