[dev] [st] [PATCH 3/3] Move geometry initialization to xinit()

From: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
Date: Thu, 13 Sep 2012 23:19:59 +0200

xinit() is the function which performs all the X Windows initilization, so
it can be desired doing the geometry parsing into that function, and let the
argv loop of main as simple like other parameter cases.
---
 st.c |   53 +++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/st.c b/st.c
index 868300c..e87a0cd 100644
--- a/st.c
+++ b/st.c
_AT_@ -358,6 +358,7 @@ static Selection sel;
 static int iofd = -1;
 static char **opt_cmd  = NULL;
 static char *opt_io    = NULL;
+static char *opt_geo   = NULL;
 static char *opt_title = NULL;
 static char *opt_embed = NULL;
 static char *opt_class = NULL;
_AT_@ -1965,6 +1966,11 @@ xinit(void) {
 	Cursor cursor;
 	Window parent;
 	int sw, sh;
+	int bitm, xr, yr;
+	unsigned int wr, hr;
+
+	xw.fw = xw.fh = xw.fx = xw.fy = 0;
+	xw.isfixed = False;
 	if(!(xw.dpy = XOpenDisplay(NULL)))
 		die("Can't open display\n");
_AT_@ -1981,6 +1987,23 @@ xinit(void) {
 	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
 	xloadcols();
+	if(opt_geo) {
+		bitm = XParseGeometry(opt_geo, &xr, &yr, &wr, &hr);
+		if(bitm & XValue)
+			xw.fx = xr;
+		if(bitm & YValue)
+			xw.fy = yr;
+		if(bitm & WidthValue)
+			xw.fw = (int)wr;
+		if(bitm & HeightValue)
+			xw.fh = (int)hr;
+		if(bitm & XNegative && xw.fx == 0)
+			xw.fx = -1;
+		if(bitm & XNegative && xw.fy == 0)
+			xw.fy = -1;
+		if(xw.fh != 0 && xw.fw != 0)
+			xw.isfixed = True;
+	}
 	/* adjust fixed window geometry */
 	if(xw.isfixed) {
 		sw = DisplayWidth(xw.dpy, xw.scr);
_AT_@ -2378,11 +2401,7 @@ run(void) {
 int
 main(int argc, char *argv[]) {
-	int i, bitm, xr, yr;
-	unsigned int wr, hr;
-
-	xw.fw = xw.fh = xw.fx = xw.fy = 0;
-	xw.isfixed = False;
+	int i;
 	for(i = 1; i < argc; i++) {
 		switch(argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) {
_AT_@ -2398,31 +2417,13 @@ main(int argc, char *argv[]) {
 		case 'f':
 			if(++i < argc) opt_io = argv[i];
 			break;
+		case 'g':
+			if(++i < argc) opt_geo = argv[i];
+			break;
 		case 'e':
 			/* eat every remaining arguments */
 			if(++i < argc) opt_cmd = &argv[i];
 			goto run;
-		case 'g':
-			if(++i >= argc)
-				break;
-
-			bitm = XParseGeometry(argv[i], &xr, &yr, &wr, &hr);
-			if(bitm & XValue)
-				xw.fx = xr;
-			if(bitm & YValue)
-				xw.fy = yr;
-			if(bitm & WidthValue)
-				xw.fw = (int)wr;
-			if(bitm & HeightValue)
-				xw.fh = (int)hr;
-			if(bitm & XNegative && xw.fx == 0)
-				xw.fx = -1;
-			if(bitm & XNegative && xw.fy == 0)
-				xw.fy = -1;
-
-			if(xw.fh != 0 && xw.fw != 0)
-				xw.isfixed = True;
-			break;
 		case 'v':
 		default:
 			die(USAGE);
--
1.7.10.4
Received on Thu Sep 13 2012 - 23:19:59 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 23:24:04 CEST