ref: 119d1c2d2cea3360ff0913ba919f143a149add80
parent: 2fe3ed3100c86497b7a4506d9495338609c945e2
author: phil9 <telephil9@gmail.com>
date: Wed Nov 30 09:26:27 EST 2022
force window size (by default 500x500) and disable resizing
--- a/a.h
+++ b/a.h
@@ -16,6 +16,8 @@
Image *i;
};
+void resize(int, int);
+
void drawcanvas(void);
void initstate(void);
void registerfuncs(lua_State*);
@@ -23,3 +25,5 @@
Image* getcolor(int);
extern Image* canvas;
+extern int width;
+extern int height;
--- a/api.c
+++ b/api.c
@@ -1,6 +1,8 @@
#include "a.h"
Image *canvas;
+int width;
+int height;
int nostroke;
Image *stroke;
int strokewidth;
@@ -12,8 +14,10 @@
{
Rectangle r;
- r = rectsubpt(screen->r, screen->r.min);
- canvas = allocimage(display, r, screen->chan, 0, DNofill);
+ width = 500;
+ height = 500;
+ r = Rect(0, 0, width, height);
+ canvas = allocimage(display, r, screen->chan, 0, DWhite);
nostroke = 0;
stroke = display->black;
strokewidth = 1;
--- a/slug.c
+++ b/slug.c
@@ -37,13 +37,30 @@
}
void
+resize(int w, int h)
+{
+ int fd, n;
+ char buf[255];
+
+ fd = open("/dev/wctl", OWRITE|OCEXEC);
+ if(fd < 0)
+ sysfatal("open: %r");
+ n = snprint(buf, sizeof buf, "resize -dx %d -dy %d", w, h);
+ if(write(fd, buf, n) != n)
+ fprint(2, "write error: %r\n");
+ close(fd);
+}
+
+void
threadmain(int argc, char *argv[])
{
lua_State *L;
+ Mouse m;
Rune k;
const char *s;
int r;
Alt alts[] = {
+ { nil, &m, CHANRCV },
{ nil, nil, CHANRCV },
{ nil, &k, CHANRCV },
{ nil, nil, CHANNOBLK },
@@ -56,8 +73,9 @@
sysfatal("initmouse: %r");
if((kc = initkeyboard(nil)) == nil)
sysfatal("initkeyboard: %r");
- alts[0].c = mc->resizec;
- alts[1].c = kc->c;
+ alts[0].c = mc->c;
+ alts[1].c = mc->resizec;
+ alts[2].c = kc->c;
L = luaL_newstate();
luaL_openlibs(L);
r = luaL_dofile(L, argc > 1 ? argv[1] : NULL);
@@ -67,15 +85,20 @@
}
registerfuncs(L);
initstate();
+ resize(width, height);
lsetup(L);
for(;;){
ldraw(L);
switch(alt(alts)){
case 0:
+ break;
+ case 1:
if(getwindow(display, Refnone)<0)
sysfatal("getwindow: %r");
+ resize(width, height);
+ drawcanvas();
break;
- case 1:
+ case 2:
if(k == Kdel)
goto Done;
break;