code: drawterm

Download patch

ref: 05702a2942dc74613683a1d338c90f29b58c9c7e
parent: 3a300145dedef2e2cad9be0bf4ba2166770bc943
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Apr 18 00:26:52 EDT 2020

x11: add -g geometry arg to set window position and size (thanks joe9)

--- a/cpu.c
+++ b/cpu.c
@@ -38,6 +38,7 @@
 char *secstore;
 char *user, *pass;
 char secstorebuf[65536];
+char *geometry;
 
 extern void	guimain(void);
 
@@ -233,7 +234,9 @@
 		"[-h host] [-u user] [-a authserver] [-s secstore] "
 		"[-e 'crypt hash'] [-k keypattern] "
 		"[-p] [-t timeout] "
-		"[-r root] [-c cmd ...]\n", argv0);
+		"[-r root] "
+		"[-g geometry] "
+		"[-c cmd ...]\n", argv0);
 	exits("usage");
 }
 
@@ -301,6 +304,12 @@
 			cmd = smprint("%s %q", cmd, s);
 			free(old);
 		}
+		break;
+	case 'g':
+		/* X11 geometry string
+			[=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]
+			*/
+		geometry = EARGF(usage());
 		break;
 	default:
 		usage();
--- a/drawterm.1
+++ b/drawterm.1
@@ -34,6 +34,9 @@
 .B -r
 .I root
 ] [
+.B -g
+.I geometry
+] [
 .B -c
 .I cmd \fR...]
 
--- a/gui-x11/x11.c
+++ b/gui-x11/x11.c
@@ -48,6 +48,8 @@
 static	XImage*		xscreenimage;
 static	Visual		*xvis;
 
+extern char		*geometry;	/* defined in main.c */
+
 #include "../glenda-t.xbm"
 
 Memimage*
@@ -188,7 +190,7 @@
 void
 screeninit(void)
 {
-	int i, n;
+	int i, n, x, y;
 	char *argv[2];
 	Window rootwin;
 	Rectangle r;
@@ -303,15 +305,19 @@
 		initmap(rootwin);
 	}
 
-	r.min = ZP;
-	r.max.x = WidthOfScreen(screen)*3/4;
-	r.max.y = HeightOfScreen(screen)*3/4;
+	r = ZR;
+	if(geometry != nil)
+		XParseGeometry(geometry, &x, &y, &r.max.x, &r.max.y);
+	if(r.max.x == 0)
+		r.max.x = WidthOfScreen(screen)*3/4;
+	if(r.max.y == 0)
+		r.max.y = HeightOfScreen(screen)*3/4;
 	
 	attrs.colormap = xcmap;
 	attrs.background_pixel = 0;
 	attrs.border_pixel = 0;
 	/* attrs.override_redirect = 1;*/ /* WM leave me alone! |CWOverrideRedirect */
-	xdrawable = XCreateWindow(xdisplay, rootwin, 0, 0, Dx(r), Dy(r), 0, 
+	xdrawable = XCreateWindow(xdisplay, rootwin, x, y, Dx(r), Dy(r), 0,
 		xscreendepth, InputOutput, xvis, CWBackPixel|CWBorderPixel|CWColormap, &attrs);
 
 	/* load the given bitmap data and create an X pixmap containing it. */