Conformity in the -g geometry handling.

Thanks to Yuri Karaban for suggesting this!

These changes make -g correspond to <cols>x<rows> and honor it so non-tiling
window managers can work with the size hints afterwards. It also adds a -i
flag to force the window size. This is needed so -g keeps being useful in dwm.
dev
Christoph Lohmann 2014-04-25 22:34:24 +02:00
parent 6b7f63bac5
commit fe31a3f634
2 changed files with 56 additions and 58 deletions

8
st.1
View File

@ -10,6 +10,7 @@ st \- simple terminal
.IR font ] .IR font ]
.RB [ \-g .RB [ \-g
.IR geometry ] .IR geometry ]
.RB [ \-i ]
.RB [ \-o .RB [ \-o
.IR file ] .IR file ]
.RB [ \-t .RB [ \-t
@ -36,11 +37,14 @@ defines the
to use when st is run. to use when st is run.
.TP .TP
.BI \-g " geometry" .BI \-g " geometry"
defines the X11 geometry string, which will fixate the height and width of st. defines the X11 geometry string.
The form is [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]. See The form is [=][<cols>{xX}<rows>][{+-}<xoffset>{+-}<yoffset>]. See
.BR XParseGeometry (3) .BR XParseGeometry (3)
for further details. for further details.
.TP .TP
.B \-f
will fixate the position given with the -g option.
.TP
.BI \-o " file" .BI \-o " file"
writes all the I/O to writes all the I/O to
.I file. .I file.

106
st.c
View File

@ -250,7 +250,8 @@ typedef struct {
XSetWindowAttributes attrs; XSetWindowAttributes attrs;
int scr; int scr;
bool isfixed; /* is fixed geometry? */ bool isfixed; /* is fixed geometry? */
int fx, fy, fw, fh; /* fixed geometry */ int l, t; /* left and top offset */
int gm; /* geometry mask */
int tw, th; /* tty width and height */ int tw, th; /* tty width and height */
int w, h; /* window width and height */ int w, h; /* window width and height */
int ch; /* char height */ int ch; /* char height */
@ -406,6 +407,7 @@ static void xdrawcursor(void);
static void xinit(void); static void xinit(void);
static void xloadcols(void); static void xloadcols(void);
static int xsetcolorname(int, const char *); static int xsetcolorname(int, const char *);
static int xgeommasktogravity(int);
static int xloadfont(Font *, FcPattern *); static int xloadfont(Font *, FcPattern *);
static void xloadfonts(char *, double); static void xloadfonts(char *, double);
static int xloadfontset(Font *); static int xloadfontset(Font *);
@ -2804,18 +2806,24 @@ xhints(void) {
XSizeHints *sizeh = NULL; XSizeHints *sizeh = NULL;
sizeh = XAllocSizeHints(); sizeh = XAllocSizeHints();
if(xw.isfixed == False) {
sizeh->flags = PSize | PResizeInc | PBaseSize; sizeh->flags = PSize | PResizeInc | PBaseSize;
sizeh->height = xw.h; sizeh->height = xw.h;
sizeh->width = xw.w; sizeh->width = xw.w;
sizeh->height_inc = xw.ch; sizeh->height_inc = xw.ch;
sizeh->width_inc = xw.cw; sizeh->width_inc = xw.cw;
sizeh->base_height = 2 * borderpx; sizeh->base_height = 2 * borderpx;
sizeh->base_width = 2 * borderpx; sizeh->base_width = 2 * borderpx;
} else { if(xw.isfixed == True) {
sizeh->flags = PMaxSize | PMinSize; sizeh->flags |= PMaxSize | PMinSize;
sizeh->min_width = sizeh->max_width = xw.fw; sizeh->min_width = sizeh->max_width = xw.w;
sizeh->min_height = sizeh->max_height = xw.fh; sizeh->min_height = sizeh->max_height = xw.h;
}
if(xw.gm & (XValue|YValue)) {
sizeh->flags |= USPosition | PWinGravity;
sizeh->x = xw.l;
sizeh->y = xw.t;
sizeh->win_gravity = xgeommasktogravity(xw.gm);
} }
XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm, XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm,
@ -2823,6 +2831,19 @@ xhints(void) {
XFree(sizeh); XFree(sizeh);
} }
int
xgeommasktogravity(int mask) {
switch(mask & (XNegative|YNegative)) {
case 0:
return NorthWestGravity;
case XNegative:
return NorthEastGravity;
case YNegative:
return SouthWestGravity;
}
return SouthEastGravity;
}
int int
xloadfont(Font *f, FcPattern *pattern) { xloadfont(Font *f, FcPattern *pattern) {
FcPattern *match; FcPattern *match;
@ -2968,7 +2989,6 @@ xinit(void) {
XGCValues gcvalues; XGCValues gcvalues;
Cursor cursor; Cursor cursor;
Window parent; Window parent;
int sw, sh;
pid_t thispid = getpid(); pid_t thispid = getpid();
if(!(xw.dpy = XOpenDisplay(NULL))) if(!(xw.dpy = XOpenDisplay(NULL)))
@ -2988,23 +3008,12 @@ xinit(void) {
xloadcols(); xloadcols();
/* adjust fixed window geometry */ /* adjust fixed window geometry */
if(xw.isfixed) { xw.w = 2 * borderpx + term.col * xw.cw;
sw = DisplayWidth(xw.dpy, xw.scr); xw.h = 2 * borderpx + term.row * xw.ch;
sh = DisplayHeight(xw.dpy, xw.scr); if(xw.gm & XNegative)
if(xw.fx < 0) xw.l += DisplayWidth(xw.dpy, xw.scr) - xw.w - 2;
xw.fx = sw + xw.fx - xw.fw - 1; if(xw.gm & YNegative)
if(xw.fy < 0) xw.t += DisplayWidth(xw.dpy, xw.scr) - xw.h - 2;
xw.fy = sh + xw.fy - xw.fh - 1;
xw.h = xw.fh;
xw.w = xw.fw;
} else {
/* window - default size */
xw.h = 2 * borderpx + term.row * xw.ch;
xw.w = 2 * borderpx + term.col * xw.cw;
xw.fx = 0;
xw.fy = 0;
}
/* Events */ /* Events */
xw.attrs.background_pixel = dc.col[defaultbg].pixel; xw.attrs.background_pixel = dc.col[defaultbg].pixel;
@ -3017,7 +3026,7 @@ xinit(void) {
parent = opt_embed ? strtol(opt_embed, NULL, 0) : \ parent = opt_embed ? strtol(opt_embed, NULL, 0) : \
XRootWindow(xw.dpy, xw.scr); XRootWindow(xw.dpy, xw.scr);
xw.win = XCreateWindow(xw.dpy, parent, xw.fx, xw.fy, xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput, xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs); | CWEventMask | CWColormap, &xw.attrs);
@ -3714,10 +3723,7 @@ run(void) {
} }
ttynew(); ttynew();
if(!xw.isfixed) cresize(w, h);
cresize(w, h);
else
cresize(xw.fw, xw.fh);
gettimeofday(&last, NULL); gettimeofday(&last, NULL);
lastblink = last; lastblink = last;
@ -3807,11 +3813,10 @@ usage(void) {
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
int bitm, xr, yr;
uint wr, hr;
char *titles; char *titles;
uint cols = 80, rows = 24;
xw.fw = xw.fh = xw.fx = xw.fy = 0; xw.l = xw.t = 0;
xw.isfixed = False; xw.isfixed = False;
ARGBEGIN { ARGBEGIN {
@ -3835,22 +3840,11 @@ main(int argc, char *argv[]) {
opt_font = EARGF(usage()); opt_font = EARGF(usage());
break; break;
case 'g': case 'g':
bitm = XParseGeometry(EARGF(usage()), &xr, &yr, &wr, &hr); xw.gm = XParseGeometry(EARGF(usage()),
if(bitm & XValue) &xw.l, &xw.t, &cols, &rows);
xw.fx = xr; break;
if(bitm & YValue) case 'i':
xw.fy = yr; xw.isfixed = True;
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 & YNegative && xw.fy == 0)
xw.fy = -1;
if(xw.fh != 0 && xw.fw != 0)
xw.isfixed = True;
break; break;
case 'o': case 'o':
opt_io = EARGF(usage()); opt_io = EARGF(usage());
@ -3869,7 +3863,7 @@ main(int argc, char *argv[]) {
run: run:
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
XSetLocaleModifiers(""); XSetLocaleModifiers("");
tnew(80, 24); tnew(cols? cols : 1, rows? rows : 1);
xinit(); xinit();
selinit(); selinit();
run(); run();