aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2014-04-25 22:34:24 +0200
committerChristoph Lohmann <20h@r-36.net>2014-04-25 22:34:24 +0200
commitfe31a3f6344b0a1dbe72540aad63812f1edb6c12 (patch)
tree2e7c2880cc91b8ac74bf12fd864279ce517bbf83 /st.c
parent6b7f63bac597ca03e18fe63ad522b4d1bded08d1 (diff)
downloadst-fe31a3f6344b0a1dbe72540aad63812f1edb6c12.tar.gz
st-fe31a3f6344b0a1dbe72540aad63812f1edb6c12.tar.bz2
st-fe31a3f6344b0a1dbe72540aad63812f1edb6c12.zip
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.
Diffstat (limited to 'st.c')
-rw-r--r--st.c106
1 files changed, 50 insertions, 56 deletions
diff --git a/st.c b/st.c
index e468d73..2741ef8 100644
--- a/st.c
+++ b/st.c
@@ -250,7 +250,8 @@ typedef struct {
XSetWindowAttributes attrs;
int scr;
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 w, h; /* window width and height */
int ch; /* char height */
@@ -406,6 +407,7 @@ static void xdrawcursor(void);
static void xinit(void);
static void xloadcols(void);
static int xsetcolorname(int, const char *);
+static int xgeommasktogravity(int);
static int xloadfont(Font *, FcPattern *);
static void xloadfonts(char *, double);
static int xloadfontset(Font *);
@@ -2804,18 +2806,24 @@ xhints(void) {
XSizeHints *sizeh = NULL;
sizeh = XAllocSizeHints();
- if(xw.isfixed == False) {
- sizeh->flags = PSize | PResizeInc | PBaseSize;
- sizeh->height = xw.h;
- sizeh->width = xw.w;
- sizeh->height_inc = xw.ch;
- sizeh->width_inc = xw.cw;
- sizeh->base_height = 2 * borderpx;
- sizeh->base_width = 2 * borderpx;
- } else {
- sizeh->flags = PMaxSize | PMinSize;
- sizeh->min_width = sizeh->max_width = xw.fw;
- sizeh->min_height = sizeh->max_height = xw.fh;
+
+ sizeh->flags = PSize | PResizeInc | PBaseSize;
+ sizeh->height = xw.h;
+ sizeh->width = xw.w;
+ sizeh->height_inc = xw.ch;
+ sizeh->width_inc = xw.cw;
+ sizeh->base_height = 2 * borderpx;
+ sizeh->base_width = 2 * borderpx;
+ if(xw.isfixed == True) {
+ sizeh->flags |= PMaxSize | PMinSize;
+ sizeh->min_width = sizeh->max_width = xw.w;
+ 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,
@@ -2824,6 +2832,19 @@ xhints(void) {
}
int
+xgeommasktogravity(int mask) {
+ switch(mask & (XNegative|YNegative)) {
+ case 0:
+ return NorthWestGravity;
+ case XNegative:
+ return NorthEastGravity;
+ case YNegative:
+ return SouthWestGravity;
+ }
+ return SouthEastGravity;
+}
+
+int
xloadfont(Font *f, FcPattern *pattern) {
FcPattern *match;
FcResult result;
@@ -2968,7 +2989,6 @@ xinit(void) {
XGCValues gcvalues;
Cursor cursor;
Window parent;
- int sw, sh;
pid_t thispid = getpid();
if(!(xw.dpy = XOpenDisplay(NULL)))
@@ -2988,23 +3008,12 @@ xinit(void) {
xloadcols();
/* adjust fixed window geometry */
- if(xw.isfixed) {
- sw = DisplayWidth(xw.dpy, xw.scr);
- sh = DisplayHeight(xw.dpy, xw.scr);
- if(xw.fx < 0)
- xw.fx = sw + xw.fx - xw.fw - 1;
- if(xw.fy < 0)
- 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;
- }
+ xw.w = 2 * borderpx + term.col * xw.cw;
+ xw.h = 2 * borderpx + term.row * xw.ch;
+ if(xw.gm & XNegative)
+ xw.l += DisplayWidth(xw.dpy, xw.scr) - xw.w - 2;
+ if(xw.gm & YNegative)
+ xw.t += DisplayWidth(xw.dpy, xw.scr) - xw.h - 2;
/* Events */
xw.attrs.background_pixel = dc.col[defaultbg].pixel;
@@ -3017,7 +3026,7 @@ xinit(void) {
parent = opt_embed ? strtol(opt_embed, NULL, 0) : \
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.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs);
@@ -3714,10 +3723,7 @@ run(void) {
}
ttynew();
- if(!xw.isfixed)
- cresize(w, h);
- else
- cresize(xw.fw, xw.fh);
+ cresize(w, h);
gettimeofday(&last, NULL);
lastblink = last;
@@ -3807,11 +3813,10 @@ usage(void) {
int
main(int argc, char *argv[]) {
- int bitm, xr, yr;
- uint wr, hr;
char *titles;
+ uint cols = 80, rows = 24;
- xw.fw = xw.fh = xw.fx = xw.fy = 0;
+ xw.l = xw.t = 0;
xw.isfixed = False;
ARGBEGIN {
@@ -3835,22 +3840,11 @@ main(int argc, char *argv[]) {
opt_font = EARGF(usage());
break;
case 'g':
- bitm = XParseGeometry(EARGF(usage()), &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 & YNegative && xw.fy == 0)
- xw.fy = -1;
-
- if(xw.fh != 0 && xw.fw != 0)
- xw.isfixed = True;
+ xw.gm = XParseGeometry(EARGF(usage()),
+ &xw.l, &xw.t, &cols, &rows);
+ break;
+ case 'i':
+ xw.isfixed = True;
break;
case 'o':
opt_io = EARGF(usage());
@@ -3869,7 +3863,7 @@ main(int argc, char *argv[]) {
run:
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
- tnew(80, 24);
+ tnew(cols? cols : 1, rows? rows : 1);
xinit();
selinit();
run();