xwit-3.4.orig/ 40755 32672 31322 0 6574773115 12365 5ustar ees2dbeestaffxwit-3.4.orig/ClientWin.c100644 32672 31322 4253 6017214273 14511 0ustar ees2dbeestaff/* $XConsortium: ClientWin.c,v 1.3 89/12/10 10:26:35 rws Exp $ */ /* * Copyright 1989 by the Massachusetts Institute of Technology * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of M.I.T. not be used in advertising * or publicity pertaining to distribution of the software without specific, * written prior permission. M.I.T. makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * */ #include #include static Window TryChildren(); /* Find a window with WM_STATE, else return win itself, as per ICCCM */ Window XmuClientWindow (dpy, win) Display *dpy; Window win; { Atom WM_STATE; Atom type = None; int format; unsigned long nitems, after; unsigned char *data; Window inf; WM_STATE = XInternAtom(dpy, "WM_STATE", True); if (!WM_STATE) return win; XGetWindowProperty(dpy, win, WM_STATE, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &after, &data); if (type) return win; inf = TryChildren(dpy, win, WM_STATE); if (!inf) inf = win; return inf; } static Window TryChildren (dpy, win, WM_STATE) Display *dpy; Window win; Atom WM_STATE; { Window root, parent; Window *children; unsigned int nchildren; unsigned int i; Atom type = None; int format; unsigned long nitems, after; unsigned char *data; Window inf = 0; if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren)) return 0; for (i = 0; !inf && (i < nchildren); i++) { XGetWindowProperty(dpy, children[i], WM_STATE, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &after, &data); if (type) inf = children[i]; } for (i = 0; !inf && (i < nchildren); i++) inf = TryChildren(dpy, children[i], WM_STATE); if (children) XFree((char *)children); return inf; } xwit-3.4.orig/Imakefile100644 32672 31322 1077 6017214260 14257 0ustar ees2dbeestaff# $Id: Imakefile,v 3.1 95/08/24 17:26:21 dd Exp $ # Imakefile for xwit: window interface tool LOCAL_LIBRARIES = $(XLIB) SRCS = xwit.c dsimple.c ClientWin.c OBJS = xwit.o dsimple.o ClientWin.o DISTFILES = README Imakefile $(SRCS) dsimple.h xwit.man patchlevel.h ComplexProgramTarget(xwit) dist: @echo $(DISTFILES) shar: $(PROGRAM).shar $(PROGRAM).shar: $(DISTFILES) shar $(DISTFILES) > $@ uu: $(PROGRAM).tar.Z.uu $(PROGRAM).tar.Z.uu: $(DISTFILES) tar cf - $(DISTFILES) | compress | uuencode $(PROGRAM).tar.Z > $@ clean:: $(RM) $(PROGRAM).shar $(PROGRAM).tar.Z.uu xwit-3.4.orig/README100644 32672 31322 2020 6423004027 13312 0ustar ees2dbeestaff$Id: README,v 3.4 97/10/20 18:40:31 dd Exp $ xwit version 3.4 Mark M Martin mmm@cetia.fr David DiGiacomo david@slack.com October 1997 xwit ("x window interface tool") is a hodge-podge collection of simple routines to call some of those X11 functions that don't already have any utility commands built around them. The reasoning behind this is that loosely every X function should be accessible from a shell script. For example, XWarpPointer() will move the X pointer, but no utility program exists to do so on those rare occasions when you could really use it. xwit will also resize, iconify, pop, and move windows given by name or id, change an icon, title or name, set the screen saver going, and change individual key autorepeat settings, etc. The program is released into the public domain. The considerate will leave credit for the authors. Changes since version 3.2: 1. returns exit status of 1 if no windows match list, 2 for errors (suggestion of Norman McBride) 2. -current option (suggestion of Andre Delafontaine) xwit-3.4.orig/dsimple.c100644 32672 31322 30652 6041312325 14266 0ustar ees2dbeestaff/* $XConsortium: dsimple.c,v 1.12 91/05/11 21:01:36 gildea Exp $ */ /* $Id: dsimple.c,v 3.2 95/10/18 16:58:55 dd Exp $ */ #include #include #include #include #include /* * Other_stuff.h: Definitions of routines in other_stuff. * * Written by Mark Lillibridge. Last updated 7/1/87 * * Send bugs, etc. to chariot@athena.mit.edu. */ unsigned long Resolve_Color(); Pixmap Bitmap_To_Pixmap(); Window Select_Window(); void out(); void blip(); Window Window_With_Name(); void Fatal_Error(); /* * Just_display: A group of routines designed to make the writting of simple * X11 applications which open a display but do not open * any windows much faster and easier. Unless a routine says * otherwise, it may be assumed to require program_name, dpy, * and screen already defined on entry. * * Written by Mark Lillibridge. Last updated 7/1/87 * * Send bugs, etc. to chariot@athena.mit.edu. */ /* This stuff is defined in the calling program by just_display.h */ extern char *program_name; extern Display *dpy; extern int screen; /* * Malloc: like malloc but handles out of memory using Fatal_Error. */ char *Malloc(size) unsigned size; { char *data, *malloc(); if (!(data = malloc(size))) Fatal_Error("Out of memory!"); return(data); } /* * Realloc: like Malloc except for realloc, handles NULL using Malloc. */ char *Realloc(ptr, size) char *ptr; int size; { char *new_ptr, *realloc(); if (!ptr) return(Malloc(size)); if (!(new_ptr = realloc(ptr, size))) Fatal_Error("Out of memory!"); return(new_ptr); } /* * Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete) * If found, remove it from command line. Don't go past a lone -. */ char *Get_Display_Name(pargc, argv) int *pargc; /* MODIFIED */ char **argv; /* MODIFIED */ { int argc = *pargc; char **pargv = argv+1; char *displayname = NULL; int i; for (i = 1; i < argc; i++) { char *arg = argv[i]; if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) { if (++i >= argc) usage (); displayname = argv[i]; *pargc -= 2; continue; } if (!strcmp(arg,"-")) { while (i Selects window with id . may * be either in decimal or hex. * -name Selects the window with name . * * Call as Select_Window_Args(&argc, argv) in main before * parsing any of your program's command line arguments. * Select_Window_Args will remove its arguments so that * your program does not have to worry about them. * The window returned is the window selected or 0 if * none of the above arguments was present. If 0 is * returned, Select_Window should probably be called after * all command line arguments, and other setup is done. * For examples of usage, see xwininfo, xwd, or xprop. */ Window Select_Window_Args(rargc, argv) int *rargc; char **argv; #define ARGC (*rargc) { int nargc=1; int argc; char **nargv; Window w=0; nargv = argv+1; argc = ARGC; #define OPTION argv[0] #define NXTOPTP ++argv, --argc>0 #define NXTOPT if (++argv, --argc==0) usage() #define COPYOPT nargv++[0]=OPTION; nargc++ while (NXTOPTP) { if (!strcmp(OPTION, "-")) { COPYOPT; while (NXTOPTP) COPYOPT; break; } if (!strcmp(OPTION, "-root")) { w=RootWindow(dpy, screen); continue; } if (!strcmp(OPTION, "-name")) { NXTOPT; w = Window_With_Name(dpy, RootWindow(dpy, screen), OPTION); if (!w) Fatal_Error("No window with name %s exists!",OPTION); continue; } if (!strcmp(OPTION, "-id")) { NXTOPT; w=0; sscanf(OPTION, "0x%lx", &w); if (!w) sscanf(OPTION, "%ld", &w); if (!w) Fatal_Error("Invalid window id format: %s.", OPTION); continue; } COPYOPT; } ARGC = nargc; return(w); } /* * Other_stuff: A group of routines which do common X11 tasks. * * Written by Mark Lillibridge. Last updated 7/1/87 * * Send bugs, etc. to chariot@athena.mit.edu. */ extern Display *dpy; extern int screen; /* * Resolve_Color: This routine takes a color name and returns the pixel # * that when used in the window w will be of color name. * (WARNING: The colormap of w MAY be modified! ) * If colors are run out of, only the first n colors will be * as correct as the hardware can make them where n depends * on the display. This routine does not require wind to * be defined. */ unsigned long Resolve_Color(w, name) Window w; char *name; { XColor c; Colormap colormap; XWindowAttributes wind_info; /* * The following is a hack to insure machines without a rgb table * handle at least white & black right. */ if (!strcmp(name, "white")) name="#ffffffffffff"; if (!strcmp(name, "black")) name="#000000000000"; XGetWindowAttributes(dpy, w, &wind_info); colormap = wind_info.colormap; if (!XParseColor(dpy, colormap, name, &c)) Fatal_Error("Bad color format '%s'.", name); if (!XAllocColor(dpy, colormap, &c)) Fatal_Error("XAllocColor failed!"); return(c.pixel); } /* * Bitmap_To_Pixmap: Convert a bitmap to a 2 colored pixmap. The colors come * from the foreground and background colors of the gc. * Width and height are required solely for efficiency. * If needed, they can be obtained via. XGetGeometry. */ Pixmap Bitmap_To_Pixmap(dpy, d, gc, bitmap, width, height) Display *dpy; Drawable d; GC gc; Pixmap bitmap; int width, height; { Pixmap pix; int x; unsigned int i, depth; Drawable root; if (!XGetGeometry(dpy, d, &root, &x, &x, &i, &i, &i, &depth)) return(0); pix = XCreatePixmap(dpy, d, width, height, (int)depth); XCopyPlane(dpy, bitmap, pix, gc, 0, 0, width, height, 0, 0, 1); return(pix); } /* * blip: a debugging routine. Prints Blip! on stderr with flushing. */ void blip() { outl("blip!"); } /* * Routine to let user select a window using the mouse */ Window Select_Window(dpy) Display *dpy; { int status; Cursor cursor; XEvent event; Window target_win = None, root = RootWindow(dpy,screen); int buttons = 0; /* Make the target cursor */ cursor = XCreateFontCursor(dpy, XC_crosshair); /* Grab the pointer using target cursor, letting it room all over */ status = XGrabPointer(dpy, root, False, ButtonPressMask|ButtonReleaseMask, GrabModeSync, GrabModeAsync, root, cursor, CurrentTime); if (status != GrabSuccess) Fatal_Error("Can't grab the mouse."); /* Let the user select a window... */ while ((target_win == None) || (buttons != 0)) { /* allow one more event */ XAllowEvents(dpy, SyncPointer, CurrentTime); XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) /* there may have been some down before we started */ buttons--; break; } } XUngrabPointer(dpy, CurrentTime); /* Done with pointer */ return(target_win); } /* * Window_With_Name: routine to locate a window with a given name on a display. * If no window with the given name is found, 0 is returned. * If more than one window has the given name, the first * one found will be returned. Only top and its subwindows * are looked at. Normally, top should be the RootWindow. */ Window Window_With_Name(dpy, top, name) Display *dpy; Window top; char *name; { Window *children, dummy; unsigned int nchildren; int i; Window w=0; char *window_name; if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name)) return(top); if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren)) return(0); for (i=0; i|-font |-name }]" /* * Other_stuff.h: Definitions of routines in other_stuff. * * Written by Mark Lillibridge. Last updated 7/1/87 * * Send bugs, etc. to chariot@athena.mit.edu. */ unsigned long Resolve_Color(); Pixmap Bitmap_To_Pixmap(); Window Select_Window(); void out(); void blip(); Window Window_With_Name(); xwit-3.4.orig/xwit.c100644 32672 31322 51313 6423003106 13617 0ustar ees2dbeestaff/* $Id: xwit.c,v 3.4 97/10/20 18:32:49 dd Exp $ */ /* * Pop up or iconify the current xterm window (using its WINDOW_ID in the env) * or a given window id or a list of window matching names. etc... * A miscellany of trivial functions. * * Copyright 1991 CETIA * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of CETIA not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. CETIA makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * CETIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL CETIA * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Original by Mark M Martin. cetia 93/08/13 r1.6 mmm@cetia.fr * * This version by David DiGiacomo, david@slack.com. */ #include #include #include #include #include #include #include "dsimple.h" /* note: called by dsimple.c code, must be global */ usage() { static char Revision[] = "$Revision: 3.4 $"; char *rbeg, *rend; for (rbeg = Revision; *rbeg; rbeg++) { if (*rbeg == ' ') { break; } } if (*rbeg) { for (rend = ++rbeg; *rend; rend++) { if (*rend == ' ') { *rend = 0; break; } } fprintf(stderr, "%s version %s\n\n", program_name, rbeg); } fprintf(stderr, "usage: %s -display -sync\n\ -pop -iconify -unmap\n\ -resize w h -rows r -columns c -[r]move x y\n\ -[r]warp x y -colormap -[no]save\n\ -name -iconname \n\ -bitmap -mask -[r]iconmove x y\n\ -[no]backingstore -[no]saveunder\n\ -[no]keyrepeat keycode ... keycode - keycode\n\ -id -root -current -select\n\ -names ... [must be last]\n", program_name); exit(2); } enum functions { pop, icon, unmap, colormap, move, rmove, warp, rwarp, resize, save, nosave, keyrepeat, nokeyrepeat, name, iconname, rows, columns, iconbitmap, iconmove, riconmove, F_winattr, lastfunc }; static long function; #define FBIT(func) (1 << (func)) /* options that don't need a window */ #define NOWINDOW \ (FBIT(save) | FBIT(nosave) | \ FBIT(keyrepeat) | FBIT(nokeyrepeat) | \ FBIT(rwarp)) static enum winidmode { WID_none, WID_env, WID_num, WID_root, WID_select, WID_curr, WID_names, } Winidmode; static Window root; static int tox, toy; static int Gright, Gbottom; static int towidth, toheight, warpx, warpy; static Colormap cmap; static char **names; /* list of names to avoid */ static int numnames; static int keys[256]; static char *wmname; static char *wmiconname; static int Giconx, Gicony; static int nrows; static int ncolumns; static char *bitmapname; static char *maskname; static int Gbs, Gsu; /* set if we found a window to act on*/ static int Gwinfound; /* forward declarations */ static void doit(); /* * sleep for given millisecs for those without usleep */ static mssleep(ms) int ms; { struct timeval tv; tv.tv_sec = ms/1000; tv.tv_usec = (ms%1000)*1000; select(0,(int*)0,(int*)0,(int*)0,&tv); } /* * find all windows below this and if name matches call doit on it */ static downtree(top) Window top; { Window *child, dummy; unsigned int children, i; char **cpp, *name; if (XQueryTree(dpy, top, &dummy, &dummy, &child, &children)==0) Fatal_Error("XQueryTree failed"); for (i=0; i reports that * this code doesn't work with fvwm2, and I don't have * a fix yet, sorry. - DD */ if (wmframe != window) { if (!XGetWindowAttributes(dpy, wmframe, &frame_attr)) Fatal_Error("XGetWindowAttributes(0x%x)", wmframe); win_attr.width = frame_attr.width; win_attr.height = frame_attr.height; win_attr.border_width += frame_attr.border_width; } #endif /* !FVWM2 */ if (right) x += DisplayWidth(dpy, screen) - win_attr.width - win_attr.border_width; if (bottom) y += DisplayHeight(dpy, screen) - win_attr.height - win_attr.border_width; } values.x = x; values.y = y; value_mask = CWX | CWY; if (XReconfigureWMWindow(dpy, window, screen, value_mask, &values) == 0) Fatal_Error("move failed"); } /* * set window size */ static doresize(window, w, h) Window window; int w, h; { XWindowChanges values; unsigned int value_mask; int try; int nw, nh; values.width = w; values.height = h; value_mask = CWWidth | CWHeight; for (try = 0; try < 2; try++) { if (XReconfigureWMWindow(dpy, window, screen, value_mask, &values) == 0) Fatal_Error("resize: XReconfigureWMWindow"); getsize(window, &nw, &nh); if (values.width == nw && values.height == nh) return; /* give window manager a couple of chances to react */ mssleep(100); getsize(window, &nw, &nh); if (values.width == nw && values.height == nh) return; mssleep(400); getsize(window, &nw, &nh); if (values.width == nw && values.height == nh) return; } /* last chance */ values.width += values.width - nw; values.height += values.height - nh; if (XReconfigureWMWindow(dpy, window, screen, value_mask, &values) == 0) Fatal_Error("resize: XReconfigureWMWindow 2"); } /* * set row/column size */ static rcresize(what, window) enum functions what; Window window; { XSizeHints *hints; long supplied; int w, h; if (!(what & FBIT(rows)) || !(what & FBIT(columns))) getsize(window, &w, &h); if (!(hints = XAllocSizeHints())) Fatal_Error("XAllocSizeHints"); if (XGetWMNormalHints(dpy, window, hints, &supplied) == 0) Fatal_Error("XGetWMNormalHints"); if (!(supplied & PBaseSize) || !(supplied & PResizeInc)) Fatal_Error("missing PBaseSize and/or PResizeInc hint"); if (what & FBIT(columns)) w = hints->base_width + hints->width_inc * ncolumns; if (what & FBIT(rows)) h = hints->base_height + hints->height_inc * nrows; doresize(window, w, h); XFree(hints); } static loadbitmap(window, file, pmp) Window window; char *file; Pixmap *pmp; { unsigned int w, h; int xhot, yhot; if (XReadBitmapFile(dpy, window, file, &w, &h, pmp, &xhot, &yhot) != BitmapSuccess) Fatal_Error("XReadBitmapFile failed"); } static setbitmap(window) Window window; { static XWMHints *hints; static Pixmap bitmap_pm; static Pixmap mask_pm; XWMHints *ohints; if (!hints) { if (!(hints = XAllocWMHints()) || !(ohints = XAllocWMHints())) Fatal_Error("XAllocWMHints"); if (bitmapname) { loadbitmap(window, bitmapname, &bitmap_pm); hints->flags |= IconPixmapHint; hints->icon_pixmap = bitmap_pm; } if (maskname) { loadbitmap(window, maskname, &mask_pm); hints->flags |= IconMaskHint; hints->icon_mask = mask_pm; } XSetCloseDownMode(dpy, RetainTemporary); } if (ohints = XGetWMHints(dpy, window)) { if (ohints->icon_pixmap && hints->icon_pixmap) XFreePixmap(dpy, ohints->icon_pixmap); if (ohints->icon_mask && hints->icon_mask) XFreePixmap(dpy, ohints->icon_mask); XFree(ohints); } XSetWMHints(dpy, window, hints); } static setwinattr(window) Window window; { XSetWindowAttributes swa; unsigned long valuemask; valuemask = 0; if (Gbs) { valuemask |= CWBackingStore | CWBackingPlanes; swa.backing_store = Gbs > 0 ? Always : NotUseful; swa.backing_planes = ~0L; } if (Gsu) { valuemask |= CWSaveUnder; swa.save_under = Gsu > 0; } XChangeWindowAttributes(dpy, window, valuemask, &swa); } /* * iconify the given window, or map and raise it, or whatever */ static void doit(window) Window window; { XWindowChanges values; unsigned int value_mask; XWMHints *wmhp; enum functions f; int i = 0; Gwinfound = 1; f = function; for (i = 0; i < lastfunc; i++) { if ((f & FBIT(i)) == 0) continue; switch (i) { case warp: XWarpPointer(dpy, None, window, 0, 0, 0, 0, warpx, warpy); break; case rwarp: XWarpPointer(dpy, None, None, 0, 0, 0, 0, warpx, warpy); break; case move: domove(window, tox, toy, Gright, Gbottom); break; case rmove: getpos(window, &values.x, &values.y); values.x += tox; values.y += toy; value_mask = CWX | CWY; if (XReconfigureWMWindow(dpy, window, screen, value_mask, &values) == 0) Fatal_Error("rmove failed"); break; case resize: doresize(window, towidth, toheight); break; case colormap: XSetWindowColormap(dpy, window, cmap); break; case pop: XMapRaised(dpy, window); break; case unmap: XUnmapWindow(dpy, window); break; case icon: #if iconify_by_sending_client_message static XClientMessageEvent event; if (event.type == 0) { event.type = ClientMessage; #ifdef XA_WM_CHANGE_STATE event.message_type = XA_WM_CHANGE_STATE; #else event.message_type = XInternAtom(dpy, "WM_CHANGE_STATE", True); if (event.message_type == 0) Fatal_Error("no WM_CHANGE_STATE atom"); #endif event.format = 32; event.data.l[0] = IconicState; } event.window = window; if (XSendEvent(dpy, root, (Bool) False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *) & event) == 0) Fatal_Error("send event failed"); #else /* iconify_by_sending_client_message */ if (XIconifyWindow(dpy, window, screen) == 0) Fatal_Error("iconify failed"); #endif /* iconify_by_sending_client_message */ break; case save: XForceScreenSaver(dpy, ScreenSaverActive); break; case nosave: XForceScreenSaver(dpy, ScreenSaverReset); break; case keyrepeat: case nokeyrepeat: setrepeat(); break; case name: XStoreName(dpy, window, wmname); break; case iconname: XSetIconName(dpy, window, wmiconname); break; case rows: /* don't do it twice */ if (f & FBIT(columns)) break; /* fall through */ case columns: rcresize(f, window); break; case iconbitmap: setbitmap(window); break; case iconmove: wmhp = XGetWMHints(dpy, window); if (wmhp == 0) Fatal_Error("no WM_HINTS"); wmhp->flags |= IconPositionHint; wmhp->icon_x = Giconx; wmhp->icon_y = Gicony; XSetWMHints(dpy, window, wmhp); XFree(wmhp); break; case riconmove: wmhp = XGetWMHints(dpy, window); if (wmhp == 0) Fatal_Error("no WM_HINTS"); if (wmhp->flags & IconPositionHint) { wmhp->icon_x += Giconx; wmhp->icon_y += Gicony; XSetWMHints(dpy, window, wmhp); } else Fatal_Error("no current icon position"); XFree(wmhp); break; case F_winattr: setwinattr(window); break; } } } /* based on xwininfo.c */ static Window xwit_select_window(dpy, current) Display *dpy; int current; { Window window = None; Window wroot; int dummyi; unsigned int dummy; if (current) { XQueryPointer(dpy, RootWindow(dpy, screen), &wroot, &window, &dummyi, &dummyi, &dummyi, &dummyi, &dummy); } else { printf("\n"); printf("%s: select window by clicking the mouse\n", program_name); (void) fflush(stdout); window = Select_Window(dpy); } if (window) { if (XGetGeometry(dpy, window, &wroot, &dummyi, &dummyi, &dummy, &dummy, &dummy, &dummy) && window != wroot) window = XmuClientWindow(dpy, window); } return window; } static Window getxid(s) char *s; { XID id; if (sscanf(s, "0x%lx", &id) == 1) return id; if (sscanf(s, "%ld", &id) == 1) return id; Fatal_Error("Invalid ID format: %s", s); /* NOTREACHED */ } static int matchopt(key, nargs, argc, argv) char *key; int nargs; int *argc; char **argv; { int enough = 0; int match = 1; char *ap, *kp; ap = *argv; if (*ap == '-') ap++; for (kp = key; *kp; kp++, ap++) { if (*kp == '*') { enough = 1; ap--; continue; } if (*ap == 0) { match = enough; break; } if (*ap != *kp) { match = 0; break; } } if (match) { if (argc[0] <= nargs) { char option[32]; int dash, skip; strncpy(option, *argv, sizeof option - 1); option[sizeof option - 1] = 0; dash = *argv[0] == '-'; for (ap = option; *ap; ap++) /* nothing */ ; skip = ap - option - dash; enough = 0; for (kp = key; *kp && skip--; kp++) { if (*kp == '*') skip++; } for (; *kp; kp++) { if (*kp == '*') continue; if (enough == 0) { *ap++ = '('; enough = 1; } *ap++ = *kp; } if (enough) *ap++ = ')'; *ap = 0; fprintf(stderr, "%s: option %s needs %d argument%s\n\n", program_name, option, nargs, nargs > 1 ? "s" : ""); usage(); } argc[0] -= nargs; } return match; } main(argc, argv) int argc; char **argv; { Window window = 0; int *pargc = &argc; program_name = argv[0] + strlen(argv[0]); while (program_name != argv[0] && program_name[-1] != '/') program_name--; Setup_Display_And_Screen(pargc, argv); Winidmode = WID_env; while (argv++, --argc > 0) { /* argv[0] = next argument */ /* argc = # of arguments left */ if (matchopt("ba*ckingstore", 0, pargc, argv) || matchopt("bs", 0, pargc, argv)) { function |= FBIT(F_winattr); Gbs = 1; } else if (matchopt("b*itmap", 1, pargc, argv)) { function |= FBIT(iconbitmap); bitmapname = *++argv; } else if (matchopt("colo*rmap", 1, pargc, argv) || matchopt("cm*ap", 1, pargc, argv)) { function |= FBIT(colormap); cmap = (Colormap) getxid(*++argv); } else if (matchopt("co*lumns", 1, pargc, argv)) { function |= FBIT(columns); ncolumns = atoi(*++argv); } else if (matchopt("c*urrent", 0, pargc, argv)) { Winidmode = WID_curr; } else if (matchopt("iconm*ove", 2, pargc, argv)) { function |= FBIT(iconmove); Giconx = atoi(argv[1]); Gicony = atoi(argv[2]); argv += 2; } else if (matchopt("iconn*ame", 1, pargc, argv) || matchopt("in*ame", 1, pargc, argv)) { function |= FBIT(iconname); wmiconname = *++argv; } else if (matchopt("id", 1, pargc, argv)) { Winidmode = WID_num; window = (Window) getxid(*++argv); } else if (matchopt("i*conify", 0, pargc, argv)) { function |= FBIT(icon); } else if (matchopt("k*eyrepeat", 1, pargc, argv) || matchopt("nok*eyrepeat", 1, pargc, argv)) { int i; function |= argv[0][1] == 'n' ? FBIT(nokeyrepeat) : FBIT(keyrepeat); i = atoi(*++argv); if (i < 0) usage(); while (1) { keys[i & 0xff] = 1; if (argc <= 0) break; if (strcmp(argv[0], "-") == 0) { int from = i; argc--, argv++; if (argc < 0 || (i = atoi(argv[0])) <= 0) usage(); while (from <= i) keys[from++ & 0xff] = 1; argc--, argv++; if (argc <= 0) break; } if ((i = atoi(argv[0])) <= 0) break; argc--, argv++; } } else if (matchopt("li*st", 1, pargc, argv) || matchopt("names", 1, pargc, argv)) { Winidmode = WID_names; /* take rest of arg list */ names = ++argv; numnames = argc; argc = 0; } else if (matchopt("l*abel", 1, pargc, argv)) { function |= FBIT(name); wmname = *++argv; } else if (matchopt("ma*sk", 1, pargc, argv)) { function |= FBIT(iconbitmap); maskname = *++argv; } else if (matchopt("m*ove", 2, pargc, argv)) { function |= FBIT(move); Gright = (argv[1][0] == '-'); Gbottom = (argv[2][0] == '-'); tox = atoi(argv[1]); toy = atoi(argv[2]); argv += 2; } else if (matchopt("noba*ckingstore", 0, pargc, argv) || matchopt("nobs", 0, pargc, argv)) { function |= FBIT(F_winattr); Gbs = -1; } else if (matchopt("nosaveu*nder", 0, pargc, argv) || matchopt("nosu", 0, pargc, argv)) { function |= FBIT(F_winattr); Gsu = -1; } else if (matchopt("nos*ave", 0, pargc, argv)) { function |= FBIT(nosave); } else if (matchopt("n*ame", 1, pargc, argv)) { function |= FBIT(name); wmname = *++argv; } else if (matchopt("o*pen", 0, pargc, argv)) { function |= FBIT(pop); } else if (matchopt("p*op", 0, pargc, argv)) { function |= FBIT(pop); } else if (matchopt("ri*conmove", 2, pargc, argv)) { function |= FBIT(riconmove); Giconx = atoi(argv[1]); Gicony = atoi(argv[2]); argv += 2; } else if (matchopt("rm*ove", 2, pargc, argv)) { function |= FBIT(rmove); tox = atoi(argv[1]); toy = atoi(argv[2]); argv += 2; } else if (matchopt("roo*t", 0, pargc, argv)) { Winidmode = WID_root; } else if (matchopt("ro*ws", 1, pargc, argv)) { function |= FBIT(rows); nrows = atoi(*++argv); } else if (matchopt("rw*arp", 2, pargc, argv)) { function |= FBIT(rwarp); warpx = atoi(argv[1]); warpy = atoi(argv[2]); argv += 2; } else if (matchopt("r*esize", 2, pargc, argv)) { function |= FBIT(resize); towidth = atoi(argv[1]); toheight = atoi(argv[2]); argv += 2; } else if (matchopt("saveu*nder", 0, pargc, argv) || matchopt("su", 0, pargc, argv)) { function |= FBIT(F_winattr); Gsu = argv[0][1] == 1; } else if (matchopt("se*lect", 0, pargc, argv)) { Winidmode = WID_select; } else if (matchopt("sy*nc", 0, pargc, argv)) { XSynchronize(dpy, True); } else if (matchopt("s*ave", 0, pargc, argv)) { function |= FBIT(save); } else if (matchopt("un*map", 0, pargc, argv)) { function |= FBIT(unmap); } else if (matchopt("w*arp", 2, pargc, argv)) { function |= FBIT(warp); warpx = atoi(argv[1]); warpy = atoi(argv[2]); argv += 2; } else usage(); } /* default function: pop */ if (function == 0) function = FBIT(pop); if ((function & ~NOWINDOW) == 0) Winidmode = WID_none; root = DefaultRootWindow(dpy); switch (Winidmode) { case WID_env: { char *s; extern char *getenv(); s = getenv("WINDOWID"); if (s != 0) window = (Window) getxid(s); else { /* no WINDOWID, use window under cursor */ window = xwit_select_window(dpy, 1); if (window == None) Fatal_Error("WINDOWID not set"); } } break; case WID_root: window = root; break; case WID_curr: window = xwit_select_window(dpy, 1); break; case WID_select: window = xwit_select_window(dpy, 0); break; } switch (Winidmode) { case WID_none: doit((Window) 0); break; case WID_names: downtree(root); break; default: if (!window) Fatal_Error("no window selected"); doit(window); break; } XSync(dpy, True); (void) XCloseDisplay(dpy); exit(!Gwinfound); } xwit-3.4.orig/xwit.man100644 32672 31322 12375 6432255650 14172 0ustar ees2dbeestaff.\" $Id: xwit.man,v 3.4 97/10/20 18:32:54 dd Exp $ .TH XWIT 1X .SH NAME xwit \- window interface tool: pop or iconify this xterm window or named windows .SH SYNOPSIS .B xwit 'in \n(.iu+\w'\fBxwit \fR'u .RB [ -display .IR display ] .RB [ -sync ] .RB [ -pop ] .RB [ -iconify ] .RB [ -unmap ] .br .RB [ -resize .IR w\ h ] .RB [ -rows .IR r ] .RB [ -columns .IR c ] .RB [ - [ r ] move .IR x\ y ] .br .RB [ - [ r ] warp .IR x\ y ] .RB [ -colormap .IR colormapid ] .RB [ - [ no ] save ] .br .RB [ -name .IR name ] .RB [ -iconname .IR name ] .br .RB [ -bitmap .IR file ] .RB [ -mask .IR file ] .RB [ - [ r ] iconmove .IR x\ y ] .br .RB [ - [ no ] backingstore ] .RB [ - [ no ] saveunder ] .br .RB [ - [ no ] keyrepeat .IR "keycode ... keycode - keycode ..." ] .br .RB [ -id .IR windowid ] .RB [ -root ] .RB [ -current ] .RB [ -select ] .RB [ -names .IR initialsubstring... ] .in .SH DESCRIPTION .B xwit is an X window interface tool. By default when used with no arguments in an xterm it de-iconifies and raises the window. You can specify a different function to do, such as iconifying the window, and apply it to several windows whose name begins with one of the given strings, or a particular window id given, or the window id found in the environment variable .B WINDOWID (which is set by xterm for the program it runs). .SH OPTIONS .TP -display is followed by the display to open. .TP -sync causes all X requests to be performed synchronously. .TP -pop is the default action. It need only be given if it is wanted as well as some other function. .TP -iconify will iconify the windows instead of popping them. .TP -unmap will iconify windows by unmapping with a non ICCCM compliant window manager. (Beware, this option is not usually what you want). .TP -resize w h resize windows to the given pixel size. .TP -rows r resize windows to the given number of rows. .TP -columns c resize windows to the given number of columns. .TP -move x y move windows to the given absolute position relative to its parent. (If the x or y value is negative it is taken relative to the right or bottom edge of the parent.) .TP -rmove x y move windows by the given relative amount. .TP -warp x y move the cursor to the given position relative to the specified window. Add -root to warp to an absolute position. .TP -rwarp x y move the cursor by the given relative amount. .TP -colormap colormapid install the given colormap into the given window. -save -nosave immediately enable or disable the screen saver. .TP -name name set the WM_NAME property to the given string. .TP -iconname name set the WM_ICON_NAME property to the given string. .TP -bitmap file use the given bitmap file as the icon bitmap for the window. .TP -mask file use the given bitmap file as the icon mask for the window. .TP -iconmove x y move icons to the given absolute position. (Will not work with some window managers.) .TP -riconmove x y move icons by the given relative amount. (Will not work with some window managers.) .TP -backingstore -bs -nobackingstore -nobs enable or disable backing store for the window. .TP -saveunder -su -nosaveunder -nosu enable or disable saveunders for the window. .TP -keyrepeat -nokeyrepeat is followed by a list of keycodes (decimal numbers, see xmodmap(1)). A range can be specified as a lower number, ``-'', and upper number as three separate arguments. The individual setting of auto-repeat for those keycodes is set on or off. The global setting of auto-repeat can be set with xset(1). When off, no keys will repeat. .TP Window Selection .br If no window is specified, $WINDOWID will be used if set; otherwise the window under the cursor will be selected. .TP -id is followed by a single window number, in decimal; or, if it begins with 0x, in hexadecimal. .TP -root selects the root window. .TP -current selects the window under the cursor (default if no window specified and $WINDOWID not set). .TP -select allows the user to interactively select a window with the mouse. .TP -names if given must be the last option and is followed by a list of strings. All windows that have a name that begins exactly like one of the strings will be acted upon. By using a null string (-names ''), all names will be matched. .SH EXAMPLES .\" DD 10/97: seems to crash olvwm, sigh .\" To iconify all windows (probably not quite what you want to do) .\" .ta 1i .\" xwit -names '' To de-iconify and pop ``this'' xterm and warp the cursor into it: xwit -pop -warp 50 50 To interactively select an xterm, and resize it to 34 rows and 80 columns: xwit -select -rows 34 -columns 80 To gently agitate your oclock on the screen: while xwit -rmove 0 10 -name oclock do xwit -rmove 0 -10 -name oclock done .SH DIAGNOSTICS Exit status is 0 if any action is taken, 1 if no window matches the list supplied to -names, 2 if an error occurs. .SH LIMITATIONS Since each application is supposed to request these functions of the window manager, some of them may not like other clients mapping and unmapping them behind their backs. Iconification is requested of the window manager using the ICCCM. Non ICCCM compliant window managers may not react correctly. .SH AUTHORS Mark M Martin, CETIA France, mmm@cetia.fr .br David DiGiacomo, david@slack.com .SH ACKNOWLEDGEMENTS Thanks to Andre Delafontaine, Norman R. McBride, Keith Thompson, and Glen R. Walker for bug reports and suggestions.