txshove: document, tweak - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit ad8d54238b4bafc0306bc4204cdd09e1bfa1fcb7
 (DIR) parent f73497bbafecbedd367eaab16aaf37c701672be0
 (HTM) Author: Russ Cox <rsc@swtch.com>
       Date:   Thu, 31 Jan 2008 21:15:43 -0500
       
       xshove: document, tweak
       
       Diffstat:
         M man/man1/rio.1                      |      34 +++++++++++++++++++++++++++++++
         M src/cmd/rio/xshove.c                |      57 +++++++++++++++++++++++--------
       
       2 files changed, 77 insertions(+), 14 deletions(-)
       ---
 (DIR) diff --git a/man/man1/rio.1 b/man/man1/rio.1
       t@@ -29,6 +29,12 @@ rio \- rio-like Window Manager for X
        |
        .B restart
        ]
       +.PP
       +.B xshove
       +[
       +.I name
       +.I rectangle
       +]
        .SH DESCRIPTION
        .if t .ds 85 8\(12
        .if n .ds 85 8-1/2
       t@@ -187,6 +193,34 @@ option,
        clicking button 2 brings up a menu to select a virtual screen to view.
        Scrolling the mouse wheel while the cursor points at the background
        will cycle through the virtual screens.
       +.PP
       +.I Xshove
       +moves or resizes every window whose X11 class or instance strings contain
       +.IR name .
       +The 
       +.I rectangle
       +argument can be
       +\fIwidth\^\^\fLx\fI\^\^height\fR,
       +\fIwidth\^\^\fLx\fI\^\^height\^\^\fL@\fI\^\^xmin\fL,\fIxmax\fR,
       +\fL'\fIxmin ymin xmax ymax\fL'\fR,
       +\fRor
       +\fIxmin\fL,\fIymin\fL,\fIxmax\fL,\fIymax\fR.
       +A leading 
       +.B +
       +or
       +.B -
       +causes the rectangle to be interpreted as a delta:
       +.L +10,0
       +nudges a window to the right, while
       +.L +100x100
       +grows a window.
       +With no arguments,
       +.I xshove
       +lists all the current X windows.
       +.I Xshove
       +is not specific to 
       +.I rio
       +and can be used with other window managers.
        .SH BUGS
        In
        Plan 9's
 (DIR) diff --git a/src/cmd/rio/xshove.c b/src/cmd/rio/xshove.c
       t@@ -41,16 +41,13 @@ int nw;
        
        void getinfo(void);
        void listwindows(void);
       -int parsewinsize(char*, Rectangle*, int*);
       +int parsewinsize(char*, Rectangle*, int*, int*, int*);
        void shove(char*, char*);
        
        void
        usage(void)
        {
       -        fprint(2, "usage: xshove window rectangle\n"
       -                  "   or  xshove\n"
       -                  "window can be a window ID or a program name\n"
       -                  "rectangle is a p9p window spec (see intro(1))\n");
       +        fprint(2, "usage: xshove [window rectangle]\n");
                exits("usage");
        }
        
       t@@ -183,12 +180,19 @@ void
        shove(char *name, char *geom)
        {
                int i;
       -        int havemin;
       +        int isdelta, havemin, havesize;
       +        int old, new;
                Rectangle r;
        
       -        if(parsewinsize(geom, &r, &havemin) < 0)
       +        if(parsewinsize(geom, &r, &isdelta, &havemin, &havesize) < 0)
                        sysfatal("bad window spec: %s", name);
        
       +        old = 0;
       +        new = 1;
       +        if(isdelta){
       +                old = 1;
       +                new = isdelta;
       +        }
                for(i=0; i<nw; i++){
                        Win *ww = &w[i];
                        if(ww->instance && strstr(ww->instance, name)
       t@@ -197,14 +201,21 @@ shove(char *name, char *geom)
                                XWindowChanges e;
        
                                memset(&e, 0, sizeof e);
       -                        e.width = Dx(r);
       -                        e.height = Dy(r);
       -                        value_mask = CWWidth | CWHeight;
                                if(havemin){
       -                                e.x = r.min.x;
       -                                e.y = r.min.y;
       -                                value_mask |= CWX | CWY;
       +                                e.x = old*ww->x + new*r.min.x;
       +                                e.y = old*ww->y + new*r.min.y;
       +                        }else{
       +                                e.x = ww->x;
       +                                e.y = ww->y;
       +                        }
       +                        if(havesize){
       +                                e.width = old*ww->dx + new*Dx(r);
       +                                e.height = old*ww->dy + new*Dy(r);
       +                        }else{
       +                                e.width = ww->dx;
       +                                e.height = ww->dy;
                                }
       +                        value_mask = CWX | CWY | CWWidth | CWHeight;
                                XConfigureWindow(dpy, ww->xw, value_mask, &e);
                                XFlush(dpy);
                        }
       t@@ -212,13 +223,22 @@ shove(char *name, char *geom)
        }
        
        int
       -parsewinsize(char *s, Rectangle *r, int *havemin)
       +parsewinsize(char *s, Rectangle *r, int *isdelta, int *havemin, int *havesize)
        {
                char c, *os;
                int i, j, k, l;
        
                os = s;
       +        if(*s == '-'){
       +                s++;
       +                *isdelta = -1;
       +        }else if(*s == '+'){
       +                s++;
       +                *isdelta = 1;
       +        }else
       +                *isdelta = 0;
                *havemin = 0;
       +        *havesize = 0;
                memset(r, 0, sizeof *r);
                if(!isdigit((uchar)*s))
                        goto oops;
       t@@ -230,6 +250,7 @@ parsewinsize(char *s, Rectangle *r, int *havemin)
                        j = strtol(s, &s, 0);
                        r->max.x = i;
                        r->max.y = j;
       +                *havesize = 1;
                        if(*s == 0)
                                return 0;
                        if(*s != '@')
       t@@ -251,6 +272,7 @@ parsewinsize(char *s, Rectangle *r, int *havemin)
                        r->max.x += i;
                        r->min.y += j;
                        r->max.y += j;
       +                *havesize = 1;
                        *havemin = 1;
                        return 0;
                }
       t@@ -262,6 +284,12 @@ parsewinsize(char *s, Rectangle *r, int *havemin)
                if(!isdigit((uchar)*s))
                        goto oops;
                j = strtol(s, &s, 0);
       +        if(*s == 0){
       +                r->min.x = i;
       +                r->min.y = j;
       +                *havemin = 1;
       +                return 0;
       +        }
                if(*s != c)
                        goto oops;
                s++;
       t@@ -281,6 +309,7 @@ parsewinsize(char *s, Rectangle *r, int *havemin)
                r->max.x = k;
                r->max.y = l;
                *havemin = 1;
       +        *havesize = 1;
                return 0;
        
        oops: