Re: [dev] st default geometry patch
On Sat, Jan 22, 2011 at 05:02:27PM -0600, Dan White wrote: > I've been using st on and off for a bit. It's been great as a > fast-start popup terminal. However, I go for 80x40 for most uses and > made up this patch to make the initial geometry an option. That was a very nice patch, it inspired me to write this one. I searched through the mail archives, but couldn't find anything similar, hope it's ok. diff -r b76c819df66f st.c --- a/st.c Tue Jan 11 23:33:21 2011 +0100 +++ b/st.c Wed Jan 26 23:48:10 2011 +0100 @@ -32,7 +32,7 @@ #define USAGE \ "st-" VERSION ", (c) 2010 st engineers\n" \ - "usage: st [-t title] [-c class] [-e cmd] [-v]\n" + "usage: st [-t title] [-c class] [-g COLSxROWS] [-e cmd] [-v]\n" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -251,6 +251,8 @@ static char **opt_cmd = NULL; static char *opt_title = NULL; static char *opt_class = NULL; +static int opt_rows= 0; +static int opt_cols= 0; int utf8decode(char *s, long *u) { @@ -1522,8 +1524,8 @@ xloadcols(); /* window - default size */ - xw.bufh = 24 * xw.ch; - xw.bufw = 80 * xw.cw; + xw.bufh = (opt_rows ? opt_rows : 24) * xw.ch; + xw.bufw = (opt_cols ? opt_cols : 80) * xw.cw; xw.h = xw.bufh + 2*BORDER; xw.w = xw.bufw + 2*BORDER; @@ -1860,6 +1862,9 @@ case 'c': if(++i < argc) opt_class = argv[i]; break; + case 'g': + if(++i < argc) sscanf(argv[i], "%dx%d", &opt_cols, &opt_rows); + break; case 'e': if(++i < argc) opt_cmd = &argv[i]; break; @@ -1872,7 +1877,7 @@ break; } setlocale(LC_CTYPE, ""); - tnew(80, 24); + tnew(opt_cols ? opt_cols : 80, opt_rows ? opt_rows : 24); ttynew(); xinit(); selinit();
Re: [dev] st default geometry patch
On Thu, Jan 27, 2011 at 01:32:09PM -0600, Dan White wrote: > I like this better, it makes it easy to use st for an interactive > popup window. Was going dwm-style but the cmd line option generalizes > this without much bloat. I was thinking that, I got scratchpad functionality in dwm a little while ago and was missing this option in st, your patch showed me how easy it was to add it. Though I did update it after someone pointed out something stupid I was doing (thank you!), but I apparently didn't send it to the list. The update makes it a little cleaner :) diff -r b76c819df66f st.c --- a/st.c Tue Jan 11 23:33:21 2011 +0100 +++ b/st.c Thu Jan 27 17:12:21 2011 +0100 @@ -32,7 +32,7 @@ #define USAGE \ "st-" VERSION ", (c) 2010 st engineers\n" \ - "usage: st [-t title] [-c class] [-e cmd] [-v]\n" + "usage: st [-t title] [-c class] [-g COLSxROWS] [-e cmd] [-v]\n" /* Arbitrary sizes */ #define ESC_TITLE_SIZ 256 @@ -251,6 +251,8 @@ static char **opt_cmd = NULL; static char *opt_title = NULL; static char *opt_class = NULL; +static int opt_rows= 24; +static int opt_cols= 80; int utf8decode(char *s, long *u) { @@ -1522,8 +1524,8 @@ xloadcols(); /* window - default size */ - xw.bufh = 24 * xw.ch; - xw.bufw = 80 * xw.cw; + xw.bufh = opt_rows * xw.ch; + xw.bufw = opt_cols * xw.cw; xw.h = xw.bufh + 2*BORDER; xw.w = xw.bufw + 2*BORDER; @@ -1860,6 +1862,9 @@ case 'c': if(++i < argc) opt_class = argv[i]; break; + case 'g': + if(++i < argc) sscanf(argv[i], "%dx%d", &opt_cols, &opt_rows); + break; case 'e': if(++i < argc) opt_cmd = &argv[i]; break; @@ -1872,7 +1877,7 @@ break; } setlocale(LC_CTYPE, ""); - tnew(80, 24); + tnew(opt_cols, opt_rows); ttynew(); xinit(); selinit();
[dev] [st] morefonts patch
Hey everyone, I was looking around the other day and I found a really nice font (tamsyn), but it seemed that st wouldn't work with it because it didn't have a proper name. The creator should update the font soon to include such a name, but I also wrote a patch that allows st to load the font without that proper name. It's mostly copied from dmenu, since that was loading the fonts the same way. I hope it's ok and I didn't miss this already existing. Greetings, Tom diff -r c5a118daa7d5 -r 14cb714c st.c --- a/st.c Thu Jan 27 17:51:01 2011 +0100 +++ b/st.c Thu Feb 03 12:14:02 2011 +0100 @@ -142,6 +142,7 @@ short lbearing; short rbearing; XFontSet set; + XFontStruct *xfont; } font, bfont; } DC; @@ -1474,6 +1475,15 @@ } void +xgetxfontinfo(XFontStruct *font, int *ascent, int *descent, short *lbearing, short *rbearing) +{ + *ascent = font->ascent; + *descent = font->descent; + *lbearing = font->min_bounds.lbearing; + *rbearing = font->max_bounds.rbearing; +} + +void xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short *rbearing) { XFontStruct **xfonts; @@ -1494,13 +1504,22 @@ void initfonts(char *fontstr, char *bfontstr) { - if((dc.font.set = xinitfont(fontstr)) == NULL || - (dc.bfont.set = xinitfont(bfontstr)) == NULL) - die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT); - xgetfontinfo(dc.font.set, &dc.font.ascent, &dc.font.descent, - &dc.font.lbearing, &dc.font.rbearing); - xgetfontinfo(dc.bfont.set, &dc.bfont.ascent, &dc.bfont.descent, - &dc.bfont.lbearing, &dc.bfont.rbearing); + if((dc.font.set = xinitfont(fontstr)) != NULL && + (dc.bfont.set = xinitfont(bfontstr)) != NULL) { + xgetfontinfo(dc.font.set, &dc.font.ascent, &dc.font.descent, + &dc.font.lbearing, &dc.font.rbearing); + xgetfontinfo(dc.bfont.set, &dc.bfont.ascent, &dc.bfont.descent, + &dc.bfont.lbearing, &dc.bfont.rbearing); + } + else if ((dc.font.xfont = XLoadQueryFont(xw.dpy, fontstr)) != NULL && +(dc.bfont.xfont = XLoadQueryFont(xw.dpy, bfontstr)) != NULL) { + xgetxfontinfo(dc.font.xfont, &dc.font.ascent, &dc.font.descent, + &dc.font.lbearing, &dc.font.rbearing); + xgetxfontinfo(dc.bfont.xfont, &dc.bfont.ascent, &dc.bfont.descent, + &dc.bfont.lbearing, &dc.bfont.rbearing); + } + else + die("Can't load font %s\n", dc.font.xfont ? BOLDFONT : FONT); } void @@ -1591,8 +1610,15 @@ } } - XmbDrawImageString(xw.dpy, xw.buf, base.mode & ATTR_BOLD ? dc.bfont.set : dc.font.set, - dc.gc, winx, winy, s, bytelen); + if (((base.mode & ATTR_BOLD) && dc.bfont.set) || dc.font.set) { + XmbDrawImageString(xw.dpy, xw.buf, + base.mode & ATTR_BOLD ? dc.bfont.set : dc.font.set, + dc.gc, winx, winy, s, bytelen); + } + else { + XSetFont(xw.dpy, dc.gc, (base.mode & ATTR_BOLD ? dc.bfont : dc.font).xfont->fid); + XDrawImageString(xw.dpy, xw.buf, dc.gc, winx, winy, s, bytelen); + } if(base.mode & ATTR_UNDERLINE) XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);