aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--st.18
-rw-r--r--st.c106
2 files changed, 56 insertions, 58 deletions
diff --git a/st.1 b/st.1
index ab90908..7174da2 100644
--- a/st.1
+++ b/st.1
@@ -10,6 +10,7 @@ st \- simple terminal
10.IR font ] 10.IR font ]
11.RB [ \-g 11.RB [ \-g
12.IR geometry ] 12.IR geometry ]
13.RB [ \-i ]
13.RB [ \-o 14.RB [ \-o
14.IR file ] 15.IR file ]
15.RB [ \-t 16.RB [ \-t
@@ -36,11 +37,14 @@ defines the
36to use when st is run. 37to use when st is run.
37.TP 38.TP
38.BI \-g " geometry" 39.BI \-g " geometry"
39defines the X11 geometry string, which will fixate the height and width of st. 40defines the X11 geometry string.
40The form is [=][<width>{xX}<height>][{+-}<xoffset>{+-}<yoffset>]. See 41The form is [=][<cols>{xX}<rows>][{+-}<xoffset>{+-}<yoffset>]. See
41.BR XParseGeometry (3) 42.BR XParseGeometry (3)
42for further details. 43for further details.
43.TP 44.TP
45.B \-f
46will fixate the position given with the -g option.
47.TP
44.BI \-o " file" 48.BI \-o " file"
45writes all the I/O to 49writes all the I/O to
46.I file. 50.I file.
diff --git a/st.c b/st.c
index e468d73..2741ef8 100644
--- a/st.c
+++ b/st.c
@@ -250,7 +250,8 @@ typedef struct {
250 XSetWindowAttributes attrs; 250 XSetWindowAttributes attrs;
251 int scr; 251 int scr;
252 bool isfixed; /* is fixed geometry? */ 252 bool isfixed; /* is fixed geometry? */
253 int fx, fy, fw, fh; /* fixed geometry */ 253 int l, t; /* left and top offset */
254 int gm; /* geometry mask */
254 int tw, th; /* tty width and height */ 255 int tw, th; /* tty width and height */
255 int w, h; /* window width and height */ 256 int w, h; /* window width and height */
256 int ch; /* char height */ 257 int ch; /* char height */
@@ -406,6 +407,7 @@ static void xdrawcursor(void);
406static void xinit(void); 407static void xinit(void);
407static void xloadcols(void); 408static void xloadcols(void);
408static int xsetcolorname(int, const char *); 409static int xsetcolorname(int, const char *);
410static int xgeommasktogravity(int);
409static int xloadfont(Font *, FcPattern *); 411static int xloadfont(Font *, FcPattern *);
410static void xloadfonts(char *, double); 412static void xloadfonts(char *, double);
411static int xloadfontset(Font *); 413static int xloadfontset(Font *);
@@ -2804,18 +2806,24 @@ xhints(void) {
2804 XSizeHints *sizeh = NULL; 2806 XSizeHints *sizeh = NULL;
2805 2807
2806 sizeh = XAllocSizeHints(); 2808 sizeh = XAllocSizeHints();
2807 if(xw.isfixed == False) { 2809
2808 sizeh->flags = PSize | PResizeInc | PBaseSize; 2810 sizeh->flags = PSize | PResizeInc | PBaseSize;
2809 sizeh->height = xw.h; 2811 sizeh->height = xw.h;
2810 sizeh->width = xw.w; 2812 sizeh->width = xw.w;
2811 sizeh->height_inc = xw.ch; 2813 sizeh->height_inc = xw.ch;
2812 sizeh->width_inc = xw.cw; 2814 sizeh->width_inc = xw.cw;
2813 sizeh->base_height = 2 * borderpx; 2815 sizeh->base_height = 2 * borderpx;
2814 sizeh->base_width = 2 * borderpx; 2816 sizeh->base_width = 2 * borderpx;
2815 } else { 2817 if(xw.isfixed == True) {
2816 sizeh->flags = PMaxSize | PMinSize; 2818 sizeh->flags |= PMaxSize | PMinSize;
2817 sizeh->min_width = sizeh->max_width = xw.fw; 2819 sizeh->min_width = sizeh->max_width = xw.w;
2818 sizeh->min_height = sizeh->max_height = xw.fh; 2820 sizeh->min_height = sizeh->max_height = xw.h;
2821 }
2822 if(xw.gm & (XValue|YValue)) {
2823 sizeh->flags |= USPosition | PWinGravity;
2824 sizeh->x = xw.l;
2825 sizeh->y = xw.t;
2826 sizeh->win_gravity = xgeommasktogravity(xw.gm);
2819 } 2827 }
2820 2828
2821 XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm, 2829 XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm,
@@ -2824,6 +2832,19 @@ xhints(void) {
2824} 2832}
2825 2833
2826int 2834int
2835xgeommasktogravity(int mask) {
2836 switch(mask & (XNegative|YNegative)) {
2837 case 0:
2838 return NorthWestGravity;
2839 case XNegative:
2840 return NorthEastGravity;
2841 case YNegative:
2842 return SouthWestGravity;
2843 }
2844 return SouthEastGravity;
2845}
2846
2847int
2827xloadfont(Font *f, FcPattern *pattern) { 2848xloadfont(Font *f, FcPattern *pattern) {
2828 FcPattern *match; 2849 FcPattern *match;
2829 FcResult result; 2850 FcResult result;
@@ -2968,7 +2989,6 @@ xinit(void) {
2968 XGCValues gcvalues; 2989 XGCValues gcvalues;
2969 Cursor cursor; 2990 Cursor cursor;
2970 Window parent; 2991 Window parent;
2971 int sw, sh;
2972 pid_t thispid = getpid(); 2992 pid_t thispid = getpid();
2973 2993
2974 if(!(xw.dpy = XOpenDisplay(NULL))) 2994 if(!(xw.dpy = XOpenDisplay(NULL)))
@@ -2988,23 +3008,12 @@ xinit(void) {
2988 xloadcols(); 3008 xloadcols();
2989 3009
2990 /* adjust fixed window geometry */ 3010 /* adjust fixed window geometry */
2991 if(xw.isfixed) { 3011 xw.w = 2 * borderpx + term.col * xw.cw;
2992 sw = DisplayWidth(xw.dpy, xw.scr); 3012 xw.h = 2 * borderpx + term.row * xw.ch;
2993 sh = DisplayHeight(xw.dpy, xw.scr); 3013 if(xw.gm & XNegative)
2994 if(xw.fx < 0) 3014 xw.l += DisplayWidth(xw.dpy, xw.scr) - xw.w - 2;
2995 xw.fx = sw + xw.fx - xw.fw - 1; 3015 if(xw.gm & YNegative)
2996 if(xw.fy < 0) 3016 xw.t += DisplayWidth(xw.dpy, xw.scr) - xw.h - 2;
2997 xw.fy = sh + xw.fy - xw.fh - 1;
2998
2999 xw.h = xw.fh;
3000 xw.w = xw.fw;
3001 } else {
3002 /* window - default size */
3003 xw.h = 2 * borderpx + term.row * xw.ch;
3004 xw.w = 2 * borderpx + term.col * xw.cw;
3005 xw.fx = 0;
3006 xw.fy = 0;
3007 }
3008 3017
3009 /* Events */ 3018 /* Events */
3010 xw.attrs.background_pixel = dc.col[defaultbg].pixel; 3019 xw.attrs.background_pixel = dc.col[defaultbg].pixel;
@@ -3017,7 +3026,7 @@ xinit(void) {
3017 3026
3018 parent = opt_embed ? strtol(opt_embed, NULL, 0) : \ 3027 parent = opt_embed ? strtol(opt_embed, NULL, 0) : \
3019 XRootWindow(xw.dpy, xw.scr); 3028 XRootWindow(xw.dpy, xw.scr);
3020 xw.win = XCreateWindow(xw.dpy, parent, xw.fx, xw.fy, 3029 xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
3021 xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput, 3030 xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
3022 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity 3031 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
3023 | CWEventMask | CWColormap, &xw.attrs); 3032 | CWEventMask | CWColormap, &xw.attrs);
@@ -3714,10 +3723,7 @@ run(void) {
3714 } 3723 }
3715 3724
3716 ttynew(); 3725 ttynew();
3717 if(!xw.isfixed) 3726 cresize(w, h);
3718 cresize(w, h);
3719 else
3720 cresize(xw.fw, xw.fh);
3721 3727
3722 gettimeofday(&last, NULL); 3728 gettimeofday(&last, NULL);
3723 lastblink = last; 3729 lastblink = last;
@@ -3807,11 +3813,10 @@ usage(void) {
3807 3813
3808int 3814int
3809main(int argc, char *argv[]) { 3815main(int argc, char *argv[]) {
3810 int bitm, xr, yr;
3811 uint wr, hr;
3812 char *titles; 3816 char *titles;
3817 uint cols = 80, rows = 24;
3813 3818
3814 xw.fw = xw.fh = xw.fx = xw.fy = 0; 3819 xw.l = xw.t = 0;
3815 xw.isfixed = False; 3820 xw.isfixed = False;
3816 3821
3817 ARGBEGIN { 3822 ARGBEGIN {
@@ -3835,22 +3840,11 @@ main(int argc, char *argv[]) {
3835 opt_font = EARGF(usage()); 3840 opt_font = EARGF(usage());
3836 break; 3841 break;
3837 case 'g': 3842 case 'g':
3838 bitm = XParseGeometry(EARGF(usage()), &xr, &yr, &wr, &hr); 3843 xw.gm = XParseGeometry(EARGF(usage()),
3839 if(bitm & XValue) 3844 &xw.l, &xw.t, &cols, &rows);
3840 xw.fx = xr; 3845 break;
3841 if(bitm & YValue) 3846 case 'i':
3842 xw.fy = yr; 3847 xw.isfixed = True;
3843 if(bitm & WidthValue)
3844 xw.fw = (int)wr;
3845 if(bitm & HeightValue)
3846 xw.fh = (int)hr;
3847 if(bitm & XNegative && xw.fx == 0)
3848 xw.fx = -1;
3849 if(bitm & YNegative && xw.fy == 0)
3850 xw.fy = -1;
3851
3852 if(xw.fh != 0 && xw.fw != 0)
3853 xw.isfixed = True;
3854 break; 3848 break;
3855 case 'o': 3849 case 'o':
3856 opt_io = EARGF(usage()); 3850 opt_io = EARGF(usage());
@@ -3869,7 +3863,7 @@ main(int argc, char *argv[]) {
3869run: 3863run:
3870 setlocale(LC_CTYPE, ""); 3864 setlocale(LC_CTYPE, "");
3871 XSetLocaleModifiers(""); 3865 XSetLocaleModifiers("");
3872 tnew(80, 24); 3866 tnew(cols? cols : 1, rows? rows : 1);
3873 xinit(); 3867 xinit();
3874 selinit(); 3868 selinit();
3875 run(); 3869 run();