OpenBSD FVWM 2.2.5: Core Program + Libraries Rewrite (non-GPL changes) ======================================================================== All changes to the main fvwm program and shared library EXCEPT the GPL code replacement (which is in 0001-gpl-removal.patch). Major changes: - Removed all non-OpenBSD portability code (48 autoconf probes, Solaris #ifdefs, GCC compat, sys/bsdtypes.h, waitpid/wait3, etc.) - Removed custom allocation wrappers (safemalloc/saferealloc); replaced with xalloc.h inline helpers using err(3) - Added privilege separation: fvwm_exec helper via imsg(3)/socketpair(2) - Added per-process pledge(2) and unveil(2) via fvwm_sandbox.h - Fixed CRITICAL bugs: negative-size text[-1] write, gradient double-free, DestroyModConfig NULL ptr, infinite Read recursion - Fixed HIGH bugs: exit()->_exit() in forked children, pointer aliasing, putenv() leak, body_length underflow, wrong strlcpy size - Fixed MEDIUM bugs: uninit error buffer, style fixes throughout - Rewrote man page in semantic mdoc(7) - Removed CVS directories NEW: fvwm/fvwm/exec.c imsg(3) exec helper interface NEW: fvwm/fvwm/fvwm_exec.c Privilege-separated helper binary NEW: fvwm/fvwm/fvwm_sandbox.h Shared pledge(2)/unveil(2) helpers NEW: fvwm/fvwm/xalloc.h xmalloc/xrealloc/xcalloc/xstrdup (inline) DELETED: fvwm/libs/safemalloc.c Replaced by xalloc.h Apply after 0001-gpl-removal.patch To apply: cd && patch -p0 < this-file Index: fvwm/config.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/config.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/config.h --- fvwm/config.h +++ fvwm/config.h @@ -1,366 +1,42 @@ -/* config.h. Generated automatically by configure. */ -/* config.h.in. Generated automatically from configure.in by autoheader. */ -/** Compatibility stuff **/ +/* config.h -- OpenBSD fvwm configuration */ -/* Where to search for the fvwm icons. */ -#define FVWM_ICONDIR "/usr/include/X11/bitmaps:/usr/include/X11/pixmaps" +#define FVWM_ICONDIR "/usr/X11R6/lib/X11/fvwm/icons" -/* Define if Xpm library is used. */ #define XPM 1 - -/* Define if rplay library is used. */ -/* #undef HAVE_RPLAY */ - -/* Define if readline is available. */ -#define HAVE_READLINE 1 - -/* Define to disable motif applications ability to have modal dialogs. - * Use with care. */ -/* #undef MODALITY_IS_EVIL */ - -/* Tells the WM not to request save unders for pop-up - * menus. A quick test using monochrome X11 shows that save - * unders cost about 4Kbytes RAM, but saves a lot of - * window redraws if you have windows that take a while - * to refresh. For xcolor, I assume the cost is more like - * 4Kbytesx8 = 32kbytes (256 color). */ -/* #undef NO_SAVEUNDERS */ - -/* Define if you want the Shaped window extensions. - * Shaped window extensions seem to increase the window managers RSS - * by about 60 Kbytes. They provide for leaving a title-bar on the window - * without a border. - * If you don't use shaped window extension, you can either make your - * shaped windows undecorated, or live with a border and backdrop around - * all your shaped windows (oclock, xeyes) - * - * If you normally use a shaped window (xeyes or oclock), you might as - * well compile this extension in, since the memory cost is minimal in - * this case (The shaped window shared libs will be loaded anyway). If you - * don't normally use a shaped window, you have to decide for yourself. - * - * Note: if it is compiled in, run time detection is used to make sure that - * the currently running X server supports it. */ #define SHAPE 1 - -/* Enables the ActiveDown button state. This allows different button - * styles for pressed down buttons on active windows (also for the - * title-bar if EXTENDED_TITLESTYLE is enabled below). The man page - * refers to this button state as "ActiveDown." If not defined, the - * "ActiveUp" state is used instead. Disabling this reduces memory - * usage. */ #define ACTIVEDOWN_BTNS 1 - -/* Enables the Inactive button state. This allows different button - * styles for inactive windows (also for the title-bar if - * EXTENDED_TITLESTYLE is enabled below). The man page refers to this - * button state as "Inactive." If not defined, the "ActiveUp" state - * is used instead. Disabling this reduces memory usage. */ #define INACTIVE_BTNS 1 - -/* Enables the "MiniIcon" Style option to specify a small pixmap which - * can be used as one of the title-bar buttons, shown in window list, - * utilized by modules, etc. Requires PIXMAP_BUTTONS to be defined - * (see below). */ #define MINI_ICONS 1 - -/* Enables the vector button style. This button type is considered - * "standard," so it is recommended that you leave it in. */ #define VECTOR_BUTTONS 1 - -/* Enables the pixmap button style. You must have Xpm support to use - * color pixmaps. See the man page button style entries for "Pixmap" - * and "TiledPixmap" for usage information. */ #define PIXMAP_BUTTONS 1 - -/* Enables the gradient button style. See the man page button style - * entries for "HGradient" and "VGradient" for usage information. */ #define GRADIENT_BUTTONS 1 - -/* Enables stacked button styles (also for the title-bar if - * EXTENDED_TITLESTYLE is enabled below). There is a slight memory - * penalty for each additional style. See the man page entries for - * AddButtonStyle and AddTitleStyle for usage information. */ #define MULTISTYLE 1 - -/* Enables styled title-bars (specified with the TitleStyle command in - * a similar fashion to the ButtonStyle command). It also compiles in - * support to change the title-bar height. */ #define EXTENDED_TITLESTYLE 1 - -/* Enables the BorderStyle command. Not all button styles are - * available. See the man page entry for BorderStyle for usage - * information. If you are also using PIXMAP_BUTTONS, you can also - * texture your borders with tiled pixmaps. The BorderStyle command - * has Active and Inactive states, regardless of the -DACTIVEDOWN_BTNS - * and -DINACTIVE_BTNS defines. */ #define BORDERSTYLE 1 - -/* Enables tagged general decoration styles which can be assigned to - * windows using the UseDecor Style option, or dynamically updated - * with ChangeDecor. To create and destroy "decor" definitions, see - * the man page entries for AddToDecor and DestroyDecor. There is a - * slight memory penalty for each additionally defined decor. */ #define USEDECOR 1 - -/* Enables the WindowShade function. This function "rolls" the window - * up so only the title-bar remains. See the man page entry for - * "WindowShade" for more information. */ #define WINDOWSHADE 1 -/* Specify a type for sig_atomic_t if it's not available. */ -/* #undef sig_atomic_t */ - - - -/* Define to empty if the keyword does not work. */ -/* #undef const */ - -/* Define if you have the strftime function. */ -#define HAVE_STRFTIME 1 - -/* Define if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define as __inline if that's what the C compiler calls it. */ -#define inline __inline - -/* Define if on MINIX. */ -/* #undef _MINIX */ - -/* Define to `long' if doesn't define. */ -/* #undef off_t */ - -/* Define to `int' if doesn't define. */ -/* #undef pid_t */ - -/* Define if the system does not provide POSIX.1 features except - with this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define if you need to in order for stat and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define as the return type of signal handlers (int or void). */ -#define RETSIGTYPE void - -/* Define to the type of arg1 for select(). */ -#define SELECT_TYPE_ARG1 int - -/* Define to the type of args 2, 3 and 4 for select(). */ -#define SELECT_TYPE_ARG234 (fd_set *) - -/* Define to the type of arg5 for select(). */ -#define SELECT_TYPE_ARG5 (struct timeval *) - -/* Define if the setvbuf function takes the buffering type as its second - argument and the buffer pointer as the third, as on System V - before release 3. */ -/* #undef SETVBUF_REVERSED */ - -/* Define to `unsigned' if doesn't define. */ -/* #undef size_t */ - -/* Define if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define if the X Window System is missing or not being used. */ -/* #undef X_DISPLAY_MISSING */ - -/* Define if lex declares yytext as a char * by default, not a char[]. */ -#define YYTEXT_POINTER 1 - -/* -** if you would like to see lots of debug messages from fvwm, for debugging -** purposes, uncomment the next line -*/ -/* #undef FVWM_DEBUG_MSGS */ - -#ifdef FVWM_DEBUG_MSGS -# define DBUG(x,y) fvwm_msg(DBG,x,y) -#else -# define DBUG(x,y) /* no messages */ -#endif - -/* Define if you have the atexit function. */ -#define HAVE_ATEXIT 1 - -/* Define if you have the div function. */ -#define HAVE_DIV 1 - -/* Define if you have the gethostname function. */ -#define HAVE_GETHOSTNAME 1 - -/* Define if you have the gettimeofday function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define if you have the memcpy function. */ -#define HAVE_MEMCPY 1 - -/* Define if you have the memmove function. */ -#define HAVE_MEMMOVE 1 - -/* Define if you have the mkfifo function. */ -#define HAVE_MKFIFO 1 - -/* Define if you have the on_exit function. */ -/* #undef HAVE_ON_EXIT */ - -/* Define if you have the putenv function. */ -#define HAVE_PUTENV 1 - -/* Define if you have the select function. */ -#define HAVE_SELECT 1 - -/* Define if you have the setvbuf function. */ -#define HAVE_SETVBUF 1 +#define PACKAGE "fvwm" +#define VERSION "2.2.5" -/* Define if you have the sigaction function. */ +#define HAVE_FCNTL_H 1 #define HAVE_SIGACTION 1 - -/* Define if you have the siginterrupt function. */ #define HAVE_SIGINTERRUPT 1 - -/* Define if you have the socket function. */ -#define HAVE_SOCKET 1 - -/* Define if you have the strcasecmp function. */ -#define HAVE_STRCASECMP 1 - -/* Define if you have the strchr function. */ -#define HAVE_STRCHR 1 - -/* Define if you have the strdup function. */ -#define HAVE_STRDUP 1 - -/* Define if you have the strerror function. */ -#define HAVE_STRERROR 1 - -/* Define if you have the strncasecmp function. */ -#define HAVE_STRNCASECMP 1 - -/* Define if you have the strstr function. */ -#define HAVE_STRSTR 1 - -/* Define if you have the strtol function. */ -#define HAVE_STRTOL 1 - -/* Define if you have the sysconf function. */ -#define HAVE_SYSCONF 1 - -/* Define if you have the uname function. */ -#define HAVE_UNAME 1 - -/* Define if you have the usleep function. */ -#define HAVE_USLEEP 1 - -/* Define if you have the vfprintf function. */ -#define HAVE_VFPRINTF 1 - -/* Define if you have the wait3 function. */ -/* #undef HAVE_WAIT3 */ - -/* Define if you have the wait4 function. */ -/* #undef HAVE_WAIT4 */ - -/* Define if you have the waitpid function. */ -#define HAVE_WAITPID 1 - -/* Define if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_GETOPT_H */ - -/* Define if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_MALLOC_H */ - -/* Define if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define if you have the header file. */ #define HAVE_SYS_SELECT_H 1 +#define HAVE_SYS_WAIT_H 1 +#define HAVE_WAITPID 1 -/* Define if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define if you have the header file. */ -/* #undef HAVE_SYS_SYSTEMINFO_H */ - -/* Define if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Name of package */ -#define PACKAGE "fvwm" - -/* Version number of package */ -#define VERSION "2.2.5" - - -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STRING_H -# include -# else -# include -# endif -# ifdef HAVE_MEMORY_H -# include -# endif -# ifdef HAVE_STDLIB_H -# include -# endif -# ifdef HAVE_MALLOC_H -# include -# endif -# ifndef HAVE_STRCHR -# define strchr(_s,_c) index((_s),(_c)) -# define strrchr(_s,_c) rindex((_s),(_c)) -# endif -#endif - -#ifndef HAVE_MEMCPY -# define memcpy(_d,_s,_l) bcopy((_s),(_d),(_l)) -#endif -#ifndef HAVE_MEMMOVE -# define memmove(_d,_s,_l) bcopy((_s),(_d),(_l)) -#endif - -#if HAVE_SYS_TYPES_H -# include -#endif - -#if HAVE_UNISTD_H -# include -#endif +#include +#include +#include +#include #ifndef min -# define min(a,b) (((a)<(b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef max -# define max(a,b) (((a)>(b)) ? (a) : (b)) +#define max(a, b) (((a) > (b)) ? (a) : (b)) #endif #ifndef abs -# define abs(a) (((a)>=0)?(a):-(a)) +#define abs(a) (((a) >= 0) ? (a) : -(a)) #endif - Index: fvwm/fvwm/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/Makefile --- fvwm/fvwm/Makefile +++ fvwm/fvwm/Makefile @@ -5,7 +5,7 @@ PROG= fvwm SRCS= add_window.c bindings.c borders.c \ builtins.c colormaps.c colors.c complex.c decorations.c \ - events.c focus.c functions.c fvwm.c fvwmdebug.c icons.c \ + events.c exec.c focus.c functions.c fvwm.c fvwmdebug.c icons.c \ menus.c misc.c modconf.c module.c move.c \ placement.c read.c resize.c style.c \ virtual.c windows.c @@ -14,12 +14,20 @@ CPPFLAGS+= -DFVWM_MODULEDIR=\"$(FVWMLIBDIR)\" \ -DFVWMRC=\".fvwmrc\" \ -DFVWM_CONFIGDIR=\"$(FVWMLIBDIR)\" -LDADD+= -lXpm -lXt -lICE -lSM -lXext -lX11 -lxcb -lXdmcp -lXau +LDADD+= -lXpm -lXt -lICE -lSM -lXext -lX11 -lxcb -lXdmcp -lXau -lutil fvwm.1: fvwm2.1 sed -e "s,__projectroot__,${X11BASE}," ${.CURDIR}/fvwm2.1 > fvwm.1 CLEANFILES= fvwm.1 +SCRIPTS= fvwm_exec +SCRIPTSDIR= $(FVWMLIBDIR) + +.all: fvwm_exec + +fvwm_exec: fvwm_exec.c ${.CURDIR}/../config.h + ${CC} ${CFLAGS} ${CPPFLAGS} -o fvwm_exec fvwm_exec.c -lutil + .include .include Index: fvwm/fvwm/add_window.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/add_window.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/add_window.c --- fvwm/fvwm/add_window.c +++ fvwm/fvwm/add_window.c @@ -29,40 +29,40 @@ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ - /********************************************************************** * * Add a new window, put the titlbar and other stuff around * the window * **********************************************************************/ -#include "config.h" - +#include #include -#include #include +#include + +#include "config.h" #include "fvwm.h" -#include -#include "screen.h" #include "misc.h" +#include "screen.h" #ifdef SHAPE -#include #include +#include #endif /* SHAPE */ #include "module.h" -/* Used to parse command line of clients for specific desk requests. */ -/* Todo: check for multiple desks. */ +/* Parse client command line for desktop hints (-workspace N, -xrm). + * Only a single desk resource is checked; multiple -workspace flags + * are not handled. */ static XrmDatabase db; -static XrmOptionDescRec table [] = { - /* Want to accept "-workspace N" or -xrm "fvwm*desk:N" as options - * to specify the desktop. I have to include dummy options that - * are meaningless since Xrm seems to allow -w to match -workspace - * if there would be no ambiguity. */ - {"-workspacf", "*junk", XrmoptionSepArg, (caddr_t) NULL}, - {"-workspace", "*desk", XrmoptionSepArg, (caddr_t) NULL}, - {"-xrn", NULL, XrmoptionResArg, (caddr_t) NULL}, - {"-xrm", NULL, XrmoptionResArg, (caddr_t) NULL}, +static XrmOptionDescRec table[] = { + /* Want to accept "-workspace N" or -xrm "fvwm*desk:N" as options + * to specify the desktop. I have to include dummy options that + * are meaningless since Xrm seems to allow -w to match -workspace + * if there would be no ambiguity. */ + {"-workspacf", "*junk", XrmoptionSepArg, (caddr_t)NULL}, + {"-workspace", "*desk", XrmoptionSepArg, (caddr_t)NULL}, + {"-xrn", NULL, XrmoptionResArg, (caddr_t)NULL}, + {"-xrm", NULL, XrmoptionResArg, (caddr_t)NULL}, }; extern char *IconPath; @@ -83,701 +83,672 @@ static void merge_styles(name_list *, name_list *); /* prototype */ * iconm - flag to tell if this is an icon manager window * ***********************************************************************/ -FvwmWindow *AddWindow(Window w) +FvwmWindow * +AddWindow(Window w) { - FvwmWindow *tmp_win; /* new fvwm window structure */ - unsigned long valuemask; /* mask for create windows */ + FvwmWindow *tmp_win; /* new fvwm window structure */ + unsigned long valuemask; /* mask for create windows */ #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - Pixmap TexturePixmap = None, TexturePixmapSave = None; + Pixmap TexturePixmap = None, TexturePixmapSave = None; #endif - unsigned long valuemask_save = 0; - XSetWindowAttributes attributes; /* attributes for create windows */ - name_list styles; /* area for merged styles */ - int i,width,height; - int a,b; -/* RBW - 11/02/1998 */ - int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; -/**/ - extern Bool NeedToResizeToo; - extern FvwmWindow *colormap_win; - int client_argc; - char **client_argv = NULL, *str_type; - Bool status; - XrmValue rm_value; - XTextProperty text_prop; - extern Boolean PPosOverride; - - NeedToResizeToo = False; - /* allocate space for the fvwm window */ - tmp_win = (FvwmWindow *)calloc(1, sizeof(FvwmWindow)); - if (tmp_win == (FvwmWindow *)0) - { - return NULL; - } - tmp_win->flags = 0; - tmp_win->tmpflags.ViewportMoved = 0; - tmp_win->tmpflags.IconifiedByParent = 0; - tmp_win->w = w; - - tmp_win->cmap_windows = (Window *)NULL; + unsigned long valuemask_save = 0; + XSetWindowAttributes attributes; /* attributes for create windows */ + name_list styles; /* area for merged styles */ + int i, width, height; + int a, b; + /* RBW - 11/02/1998 */ + int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; + /**/ + extern Bool NeedToResizeToo; + extern FvwmWindow *colormap_win; + int client_argc; + char **client_argv = NULL, *str_type; + Bool status; + XrmValue rm_value; + XTextProperty text_prop; + extern Boolean PPosOverride; + + NeedToResizeToo = False; + /* allocate space for the fvwm window */ + tmp_win = (FvwmWindow *)calloc(1, sizeof(FvwmWindow)); + if (tmp_win == (FvwmWindow *)0) { + return NULL; + } + tmp_win->flags = 0; + tmp_win->tmpflags.ViewportMoved = 0; + tmp_win->tmpflags.IconifiedByParent = 0; + tmp_win->w = w; + + tmp_win->cmap_windows = (Window *)NULL; #ifdef MINI_ICONS - tmp_win->mini_pixmap_file = NULL; - tmp_win->mini_icon = NULL; + tmp_win->mini_pixmap_file = NULL; + tmp_win->mini_icon = NULL; #endif - if(!PPosOverride) - if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) - { - free((char *)tmp_win); - return(NULL); - } - if ( XGetWMName(dpy, tmp_win->w, &text_prop) != 0 ) - tmp_win->name = (char *)text_prop.value; - else - tmp_win->name = NoName; - - /* removing NoClass change for now... */ -#if 0 - tmp_win->class.res_name = tmp_win->class.res_class = NULL; -#else - tmp_win->class.res_name = NoResource; - tmp_win->class.res_class = NoClass; -#endif /* 0 */ - XGetClassHint(dpy, tmp_win->w, &tmp_win->class); + if (!PPosOverride) + if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) { + free((char *)tmp_win); + return (NULL); + } + if (XGetWMName(dpy, tmp_win->w, &text_prop) != 0) + tmp_win->name = (char *)text_prop.value; + else + tmp_win->name = NoName; + + tmp_win->class.res_name = NoResource; + tmp_win->class.res_class = NoClass; + XGetClassHint(dpy, tmp_win->w, &tmp_win->class); #if 1 - if (tmp_win->class.res_name == NULL) - tmp_win->class.res_name = NoResource; - if (tmp_win->class.res_class == NULL) - tmp_win->class.res_class = NoClass; + if (tmp_win->class.res_name == NULL) + tmp_win->class.res_name = NoResource; + if (tmp_win->class.res_class == NULL) + tmp_win->class.res_class = NoClass; #endif /* 1 */ - FetchWmProtocols (tmp_win); - FetchWmColormapWindows (tmp_win); - if(!(XGetWindowAttributes(dpy,tmp_win->w,&(tmp_win->attr)))) - tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; + FetchWmProtocols(tmp_win); + FetchWmColormapWindows(tmp_win); + if (!(XGetWindowAttributes(dpy, tmp_win->w, &(tmp_win->attr)))) + tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; - tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w); + tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w); - if(XGetTransientForHint(dpy, tmp_win->w, &tmp_win->transientfor)) - tmp_win->flags |= TRANSIENT; - else - tmp_win->flags &= ~TRANSIENT; + if (XGetTransientForHint(dpy, tmp_win->w, &tmp_win->transientfor)) + tmp_win->flags |= TRANSIENT; + else + tmp_win->flags &= ~TRANSIENT; - tmp_win->old_bw = tmp_win->attr.border_width; + tmp_win->old_bw = tmp_win->attr.border_width; #ifdef SHAPE - if (ShapesSupported) - { - int xws, yws, xbs, ybs; - unsigned wws, hws, wbs, hbs; - int boundingShaped, clipShaped; - - XShapeSelectInput (dpy, tmp_win->w, ShapeNotifyMask); - XShapeQueryExtents (dpy, tmp_win->w, - &boundingShaped, &xws, &yws, &wws, &hws, - &clipShaped, &xbs, &ybs, &wbs, &hbs); - tmp_win->wShaped = boundingShaped; - } + if (ShapesSupported) { + int xws, yws, xbs, ybs; + unsigned wws, hws, wbs, hbs; + int boundingShaped, clipShaped; + + XShapeSelectInput(dpy, tmp_win->w, ShapeNotifyMask); + XShapeQueryExtents(dpy, tmp_win->w, &boundingShaped, &xws, &yws, + &wws, &hws, &clipShaped, &xbs, &ybs, &wbs, &hbs); + tmp_win->wShaped = boundingShaped; + } #endif /* SHAPE */ + /* if the window is in the NoTitle list, or is a transient, + * dont decorate it. + * If its a transient, and DecorateTransients was specified, + * decorate anyway + */ + /* Assume that we'll decorate */ + tmp_win->flags |= BORDER; + tmp_win->flags |= TITLE; - /* if the window is in the NoTitle list, or is a transient, - * dont decorate it. - * If its a transient, and DecorateTransients was specified, - * decorate anyway - */ - /* Assume that we'll decorate */ - tmp_win->flags |= BORDER; - tmp_win->flags |= TITLE; + LookInList(tmp_win, &styles); /* get merged styles */ - LookInList(tmp_win, &styles); /* get merged styles */ - - tmp_win->IconBoxes = styles.IconBoxes; /* copy iconboxes ptr (if any) */ - tmp_win->buttons = styles.on_buttons; /* on and off buttons combined. */ + tmp_win->IconBoxes = styles.IconBoxes; /* copy iconboxes ptr (if any) */ + tmp_win->buttons = styles.on_buttons; /* on and off buttons combined. */ #ifdef USEDECOR - /* search for a UseDecor tag in the Style */ - tmp_win->fl = NULL; - if (styles.Decor != NULL) { - FvwmDecor *fl = &Scr.DefaultDecor; - for (; fl; fl = fl->next) - if (strcasecmp(styles.Decor,fl->tag)==0) { - tmp_win->fl = fl; - break; - } - } - if (tmp_win->fl == NULL) - tmp_win->fl = &Scr.DefaultDecor; + /* search for a UseDecor tag in the Style */ + tmp_win->fl = NULL; + if (styles.Decor != NULL) { + FvwmDecor *fl = &Scr.DefaultDecor; + for (; fl; fl = fl->next) + if (strcasecmp(styles.Decor, fl->tag) == 0) { + tmp_win->fl = fl; + break; + } + } + if (tmp_win->fl == NULL) + tmp_win->fl = &Scr.DefaultDecor; #endif - tmp_win->title_height = GetDecor(tmp_win,TitleHeight) + tmp_win->bw; + tmp_win->title_height = GetDecor(tmp_win, TitleHeight) + tmp_win->bw; - GetMwmHints(tmp_win); - GetOlHints(tmp_win); + GetMwmHints(tmp_win); + GetOlHints(tmp_win); - SelectDecor(tmp_win,styles.on_flags,styles.border_width,styles.resize_width); + SelectDecor( + tmp_win, styles.on_flags, styles.border_width, styles.resize_width); #ifdef SHAPE - /* set boundary width to zero for shaped windows */ - if (tmp_win->wShaped) tmp_win->boundary_width = 0; + /* set boundary width to zero for shaped windows */ + if (tmp_win->wShaped) + tmp_win->boundary_width = 0; #endif /* SHAPE */ - tmp_win->flags |= styles.on_flags & ALL_COMMON_FLAGS; - /* find a suitable icon pixmap */ - if(styles.on_flags & ICON_FLAG) - { - /* an icon was specified */ - tmp_win->icon_bitmap_file = styles.value; - } - else if((tmp_win->wmhints) - &&(tmp_win->wmhints->flags & (IconWindowHint|IconPixmapHint))) - { - /* window has its own icon */ - tmp_win->icon_bitmap_file = NULL; - } - else - { - /* use default icon */ - tmp_win->icon_bitmap_file = Scr.DefaultIcon; - } + tmp_win->flags |= styles.on_flags & ALL_COMMON_FLAGS; + /* find a suitable icon pixmap */ + if (styles.on_flags & ICON_FLAG) { + /* an icon was specified */ + tmp_win->icon_bitmap_file = styles.value; + } else if ((tmp_win->wmhints) && + (tmp_win->wmhints->flags & + (IconWindowHint | IconPixmapHint))) { + /* window has its own icon */ + tmp_win->icon_bitmap_file = NULL; + } else { + /* use default icon */ + tmp_win->icon_bitmap_file = Scr.DefaultIcon; + } #ifdef MINI_ICONS - if (styles.on_flags & MINIICON_FLAG) { - tmp_win->mini_pixmap_file = styles.mini_value; - } - else { - tmp_win->mini_pixmap_file = NULL; - } + if (styles.on_flags & MINIICON_FLAG) { + tmp_win->mini_pixmap_file = styles.mini_value; + } else { + tmp_win->mini_pixmap_file = NULL; + } #endif - GetWindowSizeHints (tmp_win); - - /* Tentative size estimate */ - tmp_win->frame_width = tmp_win->attr.width+2*tmp_win->boundary_width; - tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height+ - 2*tmp_win->boundary_width; - - ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, False, - 0, 0); - - /* Find out if the client requested a specific desk on the command line. */ - /* RBW - 11/20/1998 - allow a desk of -1 to work. */ - if (XGetCommand (dpy, tmp_win->w, &client_argv, &client_argc)) { - XrmParseCommand (&db, table, 4, "fvwm", &client_argc, client_argv); - XFreeStringList(client_argv); - status = XrmGetResource (db, "fvwm.desk", "Fvwm.Desk", - &str_type, &rm_value); - if ((status == True) && (rm_value.size != 0)) { - styles.Desk = atoi(rm_value.addr); - /* RBW - 11/20/1998 */ - if (styles.Desk > -1) - { - styles.Desk++; - } - /**/ - styles.on_flags |= STARTSONDESK_FLAG; - } -/* RBW - 11/02/1998 */ -/* RBW - 11/20/1998 - allow desk or page specs of -1 to work. */ - /* Handle the X Resource equivalent of StartsOnPage. */ - status = XrmGetResource (db, "fvwm.page", "Fvwm.Page", &str_type, - &rm_value); - if ((status == True) && (rm_value.size != 0)) { - spargs = sscanf (rm_value.addr, "%d %d %d", &tmpno1, &tmpno2, - &tmpno3); - switch (spargs) - { - case 1: - { - styles.on_flags |= STARTSONDESK_FLAG; - styles.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - break; - } - case 2: - { - styles.on_flags |= STARTSONDESK_FLAG; - styles.PageX = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - styles.PageY = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - break; - } - case 3: - { - styles.on_flags |= STARTSONDESK_FLAG; - styles.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - styles.PageX = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - styles.PageY = (tmpno3 > -1) ? tmpno3 + 1 : tmpno3; - break; - } - default: - { - break; - } - } - } -/**/ - XrmDestroyDatabase (db); - db = NULL; - } - -/* RBW - 11/02/1998 */ - if(!PlaceWindow(tmp_win, styles.on_flags, styles.Desk, styles.PageX, styles.PageY)) - return NULL; - - /* - * Make sure the client window still exists. We don't want to leave an - * orphan frame window if it doesn't. Since we now have the server - * grabbed, the window can't disappear later without having been - * reparented, so we'll get a DestroyNotify for it. We won't have - * gotten one for anything up to here, however. - */ - MyXGrabServer(dpy); - if(XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, - &JunkBW, &JunkDepth) == 0) - { - free((char *)tmp_win); - MyXUngrabServer(dpy); - return(NULL); - } - - XSetWindowBorderWidth (dpy, tmp_win->w,0); - if (XGetWMIconName (dpy, tmp_win->w, &text_prop)) - tmp_win->icon_name = (char *)text_prop.value; - if(tmp_win->icon_name==(char *)NULL) - tmp_win->icon_name = tmp_win->name; - - tmp_win->flags &= ~ICONIFIED; - tmp_win->flags &= ~ICON_UNMAPPED; - tmp_win->flags &= ~MAXIMIZED; - - tmp_win->TextPixel = Scr.StdColors.fore; - tmp_win->ReliefPixel = Scr.StdRelief.fore; - tmp_win->ShadowPixel = Scr.StdRelief.back; - tmp_win->BackPixel = Scr.StdColors.back; - - if(styles.ForeColor != NULL) { - XColor color; - - if((XParseColor (dpy, Scr.FvwmRoot.attr.colormap, styles.ForeColor, &color)) - &&(XAllocColor (dpy, Scr.FvwmRoot.attr.colormap, &color))) - { - tmp_win->TextPixel = color.pixel; - } - } - if(styles.BackColor != NULL) { - XColor color; - - if((XParseColor (dpy, Scr.FvwmRoot.attr.colormap,styles.BackColor, &color)) - &&(XAllocColor (dpy, Scr.FvwmRoot.attr.colormap, &color))) - - { - tmp_win->BackPixel = color.pixel; - } - tmp_win->ShadowPixel = GetShadow(tmp_win->BackPixel); - tmp_win->ReliefPixel = GetHilite(tmp_win->BackPixel); - } - - - /* add the window to the end of the fvwm list */ - tmp_win->next = Scr.FvwmRoot.next; - tmp_win->prev = &Scr.FvwmRoot; - while (tmp_win->next != NULL) - { - tmp_win->prev = tmp_win->next; - tmp_win->next = tmp_win->next->next; - } - /* tmp_win->prev points to the last window in the list, tmp_win->next is NULL. - Now fix the last window to point to tmp_win */ - tmp_win->prev->next = tmp_win; - - /* - RBW - 11/13/1998 - add it into the stacking order chain also. - This chain is anchored at both ends on Scr.FvwmRoot, there are - no null pointers. - */ - tmp_win->stack_next = Scr.FvwmRoot.stack_next; - Scr.FvwmRoot.stack_next->stack_prev = tmp_win; - tmp_win->stack_prev = &Scr.FvwmRoot; - Scr.FvwmRoot.stack_next = tmp_win; - - - /* create windows */ - tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; - tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; - - tmp_win->frame_width = tmp_win->attr.width+2*tmp_win->boundary_width; - tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height+ - 2*tmp_win->boundary_width; - ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, False, - 0, 0); - - valuemask = CWBorderPixel | CWCursor | CWEventMask; - if(Scr.d_depth < 2) - { - attributes.background_pixmap = Scr.light_gray_pixmap; - if(tmp_win->flags & STICKY) - attributes.background_pixmap = Scr.sticky_gray_pixmap; - valuemask |= CWBackPixmap; - } - else - { - attributes.background_pixmap = None; - attributes.background_pixel = tmp_win->BackPixel; - valuemask |= CWBackPixel; - } - - attributes.border_pixel = tmp_win->ShadowPixel; - - attributes.cursor = Scr.FvwmCursors[DEFAULT]; - attributes.event_mask = (SubstructureRedirectMask | ButtonPressMask | - ButtonReleaseMask | EnterWindowMask | - LeaveWindowMask | ExposureMask | - VisibilityChangeMask); + GetWindowSizeHints(tmp_win); + + /* Tentative size estimate */ + tmp_win->frame_width = + tmp_win->attr.width + 2 * tmp_win->boundary_width; + tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height + + 2 * tmp_win->boundary_width; + + ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, + False, 0, 0); + + /* Find out if the client requested a specific desk on the command line. + */ + /* RBW - 11/20/1998 - allow a desk of -1 to work. */ + if (XGetCommand(dpy, tmp_win->w, &client_argv, &client_argc)) { + XrmParseCommand( + &db, table, 4, "fvwm", &client_argc, client_argv); + XFreeStringList(client_argv); + status = XrmGetResource( + db, "fvwm.desk", "Fvwm.Desk", &str_type, &rm_value); + if ((status == True) && (rm_value.size != 0)) { + styles.Desk = atoi(rm_value.addr); + /* RBW - 11/20/1998 */ + if (styles.Desk > -1) { + styles.Desk++; + } + /**/ + styles.on_flags |= STARTSONDESK_FLAG; + } + /* RBW - 11/02/1998 */ + /* RBW - 11/20/1998 - allow desk or page specs of -1 to work. + */ + /* Handle the X Resource equivalent of StartsOnPage. */ + status = XrmGetResource( + db, "fvwm.page", "Fvwm.Page", &str_type, &rm_value); + if ((status == True) && (rm_value.size != 0)) { + spargs = sscanf(rm_value.addr, "%d %d %d", &tmpno1, + &tmpno2, &tmpno3); + switch (spargs) { + case 1: { + styles.on_flags |= STARTSONDESK_FLAG; + styles.Desk = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + break; + } + case 2: { + styles.on_flags |= STARTSONDESK_FLAG; + styles.PageX = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + styles.PageY = + (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; + break; + } + case 3: { + styles.on_flags |= STARTSONDESK_FLAG; + styles.Desk = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + styles.PageX = + (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; + styles.PageY = + (tmpno3 > -1) ? tmpno3 + 1 : tmpno3; + break; + } + default: { + break; + } + } + } + /**/ + XrmDestroyDatabase(db); + db = NULL; + } + + /* RBW - 11/02/1998 */ + if (!PlaceWindow(tmp_win, styles.on_flags, styles.Desk, styles.PageX, + styles.PageY)) + return NULL; + + /* + * Make sure the client window still exists. We don't want to leave an + * orphan frame window if it doesn't. Since we now have the server + * grabbed, the window can't disappear later without having been + * reparented, so we'll get a DestroyNotify for it. We won't have + * gotten one for anything up to here, however. + */ + MyXGrabServer(dpy); + if (XGetGeometry(dpy, w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth) == 0) { + free((char *)tmp_win); + MyXUngrabServer(dpy); + return (NULL); + } + + XSetWindowBorderWidth(dpy, tmp_win->w, 0); + if (XGetWMIconName(dpy, tmp_win->w, &text_prop)) + tmp_win->icon_name = (char *)text_prop.value; + if (tmp_win->icon_name == (char *)NULL) + tmp_win->icon_name = tmp_win->name; + + tmp_win->flags &= ~ICONIFIED; + tmp_win->flags &= ~ICON_UNMAPPED; + tmp_win->flags &= ~MAXIMIZED; + + tmp_win->TextPixel = Scr.StdColors.fore; + tmp_win->ReliefPixel = Scr.StdRelief.fore; + tmp_win->ShadowPixel = Scr.StdRelief.back; + tmp_win->BackPixel = Scr.StdColors.back; + + if (styles.ForeColor != NULL) { + XColor color; + + if ((XParseColor(dpy, Scr.FvwmRoot.attr.colormap, + styles.ForeColor, &color)) && + (XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &color))) { + tmp_win->TextPixel = color.pixel; + } + } + if (styles.BackColor != NULL) { + XColor color; + + if ((XParseColor(dpy, Scr.FvwmRoot.attr.colormap, + styles.BackColor, &color)) && + (XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &color))) { + tmp_win->BackPixel = color.pixel; + } + tmp_win->ShadowPixel = GetShadow(tmp_win->BackPixel); + tmp_win->ReliefPixel = GetHilite(tmp_win->BackPixel); + } + + /* add the window to the end of the fvwm list */ + tmp_win->next = Scr.FvwmRoot.next; + tmp_win->prev = &Scr.FvwmRoot; + while (tmp_win->next != NULL) { + tmp_win->prev = tmp_win->next; + tmp_win->next = tmp_win->next->next; + } + /* tmp_win->prev points to the last window in the list, tmp_win->next is + NULL. Now fix the last window to point to tmp_win */ + tmp_win->prev->next = tmp_win; + + /* + RBW - 11/13/1998 - add it into the stacking order chain also. + This chain is anchored at both ends on Scr.FvwmRoot, there are + no null pointers. + */ + tmp_win->stack_next = Scr.FvwmRoot.stack_next; + Scr.FvwmRoot.stack_next->stack_prev = tmp_win; + tmp_win->stack_prev = &Scr.FvwmRoot; + Scr.FvwmRoot.stack_next = tmp_win; + + /* create windows */ + tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; + tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; + + tmp_win->frame_width = + tmp_win->attr.width + 2 * tmp_win->boundary_width; + tmp_win->frame_height = tmp_win->attr.height + tmp_win->title_height + + 2 * tmp_win->boundary_width; + ConstrainSize(tmp_win, &tmp_win->frame_width, &tmp_win->frame_height, + False, 0, 0); + + valuemask = CWBorderPixel | CWCursor | CWEventMask; + if (Scr.d_depth < 2) { + attributes.background_pixmap = Scr.light_gray_pixmap; + if (tmp_win->flags & STICKY) + attributes.background_pixmap = Scr.sticky_gray_pixmap; + valuemask |= CWBackPixmap; + } else { + attributes.background_pixmap = None; + attributes.background_pixel = tmp_win->BackPixel; + valuemask |= CWBackPixel; + } + + attributes.border_pixel = tmp_win->ShadowPixel; + + attributes.cursor = Scr.FvwmCursors[DEFAULT]; + attributes.event_mask = + (SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask | + EnterWindowMask | LeaveWindowMask | ExposureMask | + VisibilityChangeMask); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if ((GetDecor(tmp_win,BorderStyle.inactive.style) & ButtonFaceTypeMask) - == TiledPixmapButton) - TexturePixmap = GetDecor(tmp_win,BorderStyle.inactive.u.p->picture); - - if (TexturePixmap) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if ((GetDecor(tmp_win, BorderStyle.inactive.style) & + ButtonFaceTypeMask) == TiledPixmapButton) + TexturePixmap = + GetDecor(tmp_win, BorderStyle.inactive.u.p->picture); + + if (TexturePixmap) { + TexturePixmapSave = attributes.background_pixmap; + attributes.background_pixmap = TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; + } #endif - /* What the heck, we'll always reparent everything from now on! */ - tmp_win->frame = - XCreateWindow (dpy, Scr.Root, tmp_win->frame_x,tmp_win->frame_y, - tmp_win->frame_width, tmp_win->frame_height, - tmp_win->bw,CopyFromParent, InputOutput, - CopyFromParent, - valuemask, - &attributes); + /* What the heck, we'll always reparent everything from now on! */ + tmp_win->frame = XCreateWindow(dpy, Scr.Root, tmp_win->frame_x, + tmp_win->frame_y, tmp_win->frame_width, tmp_win->frame_height, + tmp_win->bw, CopyFromParent, InputOutput, CopyFromParent, valuemask, + &attributes); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmapSave; + valuemask = valuemask_save; + } #endif - attributes.save_under = FALSE; - attributes.event_mask &= ~VisibilityChangeMask; - - /* Thats not all, we'll double-reparent the window ! */ - attributes.cursor = Scr.FvwmCursors[DEFAULT]; - - /* make sure this does not have a BackPixel or BackPixmap so that - that when the window dies there is no flash of BackPixel/BackPixmap */ - valuemask_save = valuemask; - valuemask = valuemask & ~CWBackPixel & ~CWBackPixmap; - tmp_win->Parent = - XCreateWindow (dpy, tmp_win->frame, - tmp_win->boundary_width, - tmp_win->boundary_width+tmp_win->title_height, - (tmp_win->frame_width - 2*tmp_win->boundary_width), - (tmp_win->frame_height - 2*tmp_win->boundary_width - - tmp_win->title_height),tmp_win->bw, CopyFromParent, - InputOutput,CopyFromParent, valuemask,&attributes); - valuemask = valuemask_save; - - attributes.event_mask = (ButtonPressMask|ButtonReleaseMask|ExposureMask| - EnterWindowMask|LeaveWindowMask); - tmp_win->title_x = tmp_win->title_y = 0; - tmp_win->title_w = 0; - tmp_win->title_width = tmp_win->frame_width - 2*tmp_win->corner_width - - 3 + tmp_win->bw; - if(tmp_win->title_width < 1) - tmp_win->title_width = 1; - if(tmp_win->flags & BORDER) - { + attributes.save_under = FALSE; + attributes.event_mask &= ~VisibilityChangeMask; + + /* Thats not all, we'll double-reparent the window ! */ + attributes.cursor = Scr.FvwmCursors[DEFAULT]; + + /* make sure this does not have a BackPixel or BackPixmap so that + that when the window dies there is no flash of BackPixel/BackPixmap + */ + valuemask_save = valuemask; + valuemask = valuemask & ~CWBackPixel & ~CWBackPixmap; + tmp_win->Parent = + XCreateWindow(dpy, tmp_win->frame, tmp_win->boundary_width, + tmp_win->boundary_width + tmp_win->title_height, + (tmp_win->frame_width - 2 * tmp_win->boundary_width), + (tmp_win->frame_height - 2 * tmp_win->boundary_width - + tmp_win->title_height), + tmp_win->bw, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + valuemask = valuemask_save; + + attributes.event_mask = + (ButtonPressMask | ButtonReleaseMask | ExposureMask | + EnterWindowMask | LeaveWindowMask); + tmp_win->title_x = tmp_win->title_y = 0; + tmp_win->title_w = 0; + tmp_win->title_width = + tmp_win->frame_width - 2 * tmp_win->corner_width - 3 + tmp_win->bw; + if (tmp_win->title_width < 1) + tmp_win->title_width = 1; + if (tmp_win->flags & BORDER) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap) { + TexturePixmapSave = attributes.background_pixmap; + attributes.background_pixmap = TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; + } #endif - /* Just dump the windows any old place and left SetupFrame take - * care of the mess */ - for(i=0;i<4;i++) - { - attributes.cursor = Scr.FvwmCursors[TOP_LEFT+i]; - tmp_win->corners[i] = - XCreateWindow (dpy, tmp_win->frame, 0,0, - tmp_win->corner_width, tmp_win->corner_width, - 0, CopyFromParent,InputOutput, - CopyFromParent, - valuemask, - &attributes); - } + /* Just dump the windows any old place and left SetupFrame take + * care of the mess */ + for (i = 0; i < 4; i++) { + attributes.cursor = Scr.FvwmCursors[TOP_LEFT + i]; + tmp_win->corners[i] = XCreateWindow(dpy, tmp_win->frame, + 0, 0, tmp_win->corner_width, tmp_win->corner_width, + 0, CopyFromParent, InputOutput, CopyFromParent, + valuemask, &attributes); + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - - if (tmp_win->flags & TITLE) - { - tmp_win->title_x = tmp_win->boundary_width +tmp_win->title_height+1; - tmp_win->title_y = tmp_win->boundary_width; - attributes.cursor = Scr.FvwmCursors[TITLE_CURSOR]; - tmp_win->title_w = - XCreateWindow (dpy, tmp_win->frame, tmp_win->title_x, tmp_win->title_y, - tmp_win->title_width, tmp_win->title_height,0, - CopyFromParent, InputOutput, CopyFromParent, - valuemask,&attributes); - attributes.cursor = Scr.FvwmCursors[SYS]; - for(i=4;i>=0;i--) - { - if((ileft_w[i] > 0)) - { + } + + if (tmp_win->flags & TITLE) { + tmp_win->title_x = + tmp_win->boundary_width + tmp_win->title_height + 1; + tmp_win->title_y = tmp_win->boundary_width; + attributes.cursor = Scr.FvwmCursors[TITLE_CURSOR]; + tmp_win->title_w = XCreateWindow(dpy, tmp_win->frame, + tmp_win->title_x, tmp_win->title_y, tmp_win->title_width, + tmp_win->title_height, 0, CopyFromParent, InputOutput, + CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[SYS]; + for (i = 4; i >= 0; i--) { + if ((i < Scr.nr_left_buttons) && + (tmp_win->left_w[i] > 0)) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,left_buttons[i].flags) & UseBorderStyle) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap && + GetDecor(tmp_win, left_buttons[i].flags) & + UseBorderStyle) { + TexturePixmapSave = + attributes.background_pixmap; + attributes.background_pixmap = + TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | + CWBackPixmap; + } #endif - tmp_win->left_w[i] = - XCreateWindow (dpy, tmp_win->frame, tmp_win->title_height*i, 0, - tmp_win->title_height, tmp_win->title_height, 0, - CopyFromParent, InputOutput, - CopyFromParent, - valuemask, - &attributes); + tmp_win->left_w[i] = XCreateWindow(dpy, + tmp_win->frame, tmp_win->title_height * i, + 0, tmp_win->title_height, + tmp_win->title_height, 0, CopyFromParent, + InputOutput, CopyFromParent, valuemask, + &attributes); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,left_buttons[i].flags) & UseBorderStyle) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap && + GetDecor(tmp_win, left_buttons[i].flags) & + UseBorderStyle) { + attributes.background_pixmap = + TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - else - tmp_win->left_w[i] = None; + } else + tmp_win->left_w[i] = None; - if((iright_w[i] >0)) { + if ((i < Scr.nr_right_buttons) && + (tmp_win->right_w[i] > 0)) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,right_buttons[i].flags) & UseBorderStyle) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap && + GetDecor(tmp_win, right_buttons[i].flags) & + UseBorderStyle) { + TexturePixmapSave = + attributes.background_pixmap; + attributes.background_pixmap = + TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | + CWBackPixmap; + } #endif - tmp_win->right_w[i] = - XCreateWindow (dpy, tmp_win->frame, - tmp_win->title_width- - tmp_win->title_height*(i+1), - 0, tmp_win->title_height, - tmp_win->title_height, - 0, CopyFromParent, InputOutput, - CopyFromParent, - valuemask, - &attributes); + tmp_win->right_w[i] = + XCreateWindow(dpy, tmp_win->frame, + tmp_win->title_width - + tmp_win->title_height * (i + 1), + 0, tmp_win->title_height, + tmp_win->title_height, 0, + CopyFromParent, InputOutput, + CopyFromParent, valuemask, &attributes); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap - && GetDecor(tmp_win,right_buttons[i].flags) & UseBorderStyle) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap && + GetDecor(tmp_win, right_buttons[i].flags) & + UseBorderStyle) { + attributes.background_pixmap = + TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - else - tmp_win->right_w[i] = None; + } else + tmp_win->right_w[i] = None; + } } - } - if(tmp_win->flags & BORDER) - { + if (tmp_win->flags & BORDER) { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - TexturePixmapSave = attributes.background_pixmap; - attributes.background_pixmap = TexturePixmap; - valuemask_save = valuemask; - valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; - } + if (TexturePixmap) { + TexturePixmapSave = attributes.background_pixmap; + attributes.background_pixmap = TexturePixmap; + valuemask_save = valuemask; + valuemask = (valuemask & ~CWBackPixel) | CWBackPixmap; + } #endif - for(i=0;i<4;i++) - { - attributes.cursor = Scr.FvwmCursors[TOP+i]; - tmp_win->sides[i] = - XCreateWindow (dpy, tmp_win->frame, 0, 0, tmp_win->boundary_width, - tmp_win->boundary_width, 0, CopyFromParent, - InputOutput, CopyFromParent, - valuemask, - &attributes); - } + for (i = 0; i < 4; i++) { + attributes.cursor = Scr.FvwmCursors[TOP + i]; + tmp_win->sides[i] = XCreateWindow(dpy, tmp_win->frame, + 0, 0, tmp_win->boundary_width, + tmp_win->boundary_width, 0, CopyFromParent, + InputOutput, CopyFromParent, valuemask, + &attributes); + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) { - attributes.background_pixmap = TexturePixmapSave; - valuemask = valuemask_save; - } + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmapSave; + valuemask = valuemask_save; + } #endif - } - + } #ifdef MINI_ICONS - if (tmp_win->mini_pixmap_file) { - tmp_win->mini_icon = CachePicture (dpy, Scr.Root, - IconPath, - PixmapPath, - tmp_win->mini_pixmap_file, - Scr.ColorLimit); - } - else { - tmp_win->mini_icon = NULL; - } + if (tmp_win->mini_pixmap_file) { + tmp_win->mini_icon = CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, tmp_win->mini_pixmap_file, Scr.ColorLimit); + } else { + tmp_win->mini_icon = NULL; + } #endif - XMapSubwindows (dpy, tmp_win->frame); - XRaiseWindow(dpy,tmp_win->Parent); - XReparentWindow(dpy, tmp_win->w, tmp_win->Parent,0,0); - - valuemask = (CWEventMask | CWDontPropagate); - attributes.event_mask = (StructureNotifyMask | PropertyChangeMask | - EnterWindowMask | LeaveWindowMask | - ColormapChangeMask | FocusChangeMask); - - attributes.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; - - XChangeWindowAttributes (dpy, tmp_win->w, valuemask, &attributes); - - XAddToSaveSet(dpy, tmp_win->w); - - /* - * Reparenting generates an UnmapNotify event, followed by a MapNotify. - * Set the map state to FALSE to prevent a transition back to - * WithdrawnState in HandleUnmapNotify. Map state gets set correctly - * again in HandleMapNotify. - */ - tmp_win->flags &= ~MAPPED; - width = tmp_win->frame_width; - tmp_win->frame_width = 0; - height = tmp_win->frame_height; - tmp_win->frame_height = 0; - SetupFrame (tmp_win, tmp_win->frame_x, tmp_win->frame_y,width,height, True); - - /* wait until the window is iconified and the icon window is mapped - * before creating the icon window - */ - tmp_win->icon_w = None; - GrabButtons(tmp_win); - GrabKeys(tmp_win); - - XSaveContext(dpy, tmp_win->w, FvwmContext, (caddr_t) tmp_win); - XSaveContext(dpy, tmp_win->frame, FvwmContext, (caddr_t) tmp_win); - XSaveContext(dpy, tmp_win->Parent, FvwmContext, (caddr_t) tmp_win); - if (tmp_win->flags & TITLE) - { - XSaveContext(dpy, tmp_win->title_w, FvwmContext, (caddr_t) tmp_win); - for(i=0;ileft_w[i], FvwmContext, (caddr_t) tmp_win); - for(i=0;iright_w[i] != None) - XSaveContext(dpy, tmp_win->right_w[i], FvwmContext, - (caddr_t) tmp_win); - } - if (tmp_win->flags & BORDER) - { - for(i=0;i<4;i++) - { - XSaveContext(dpy, tmp_win->sides[i], FvwmContext, (caddr_t) tmp_win); - XSaveContext(dpy,tmp_win->corners[i],FvwmContext, (caddr_t) tmp_win); + XMapSubwindows(dpy, tmp_win->frame); + XRaiseWindow(dpy, tmp_win->Parent); + XReparentWindow(dpy, tmp_win->w, tmp_win->Parent, 0, 0); + + valuemask = (CWEventMask | CWDontPropagate); + attributes.event_mask = + (StructureNotifyMask | PropertyChangeMask | EnterWindowMask | + LeaveWindowMask | ColormapChangeMask | FocusChangeMask); + + attributes.do_not_propagate_mask = ButtonPressMask | ButtonReleaseMask; + + XChangeWindowAttributes(dpy, tmp_win->w, valuemask, &attributes); + + XAddToSaveSet(dpy, tmp_win->w); + + /* + * Reparenting generates an UnmapNotify event, followed by a MapNotify. + * Set the map state to FALSE to prevent a transition back to + * WithdrawnState in HandleUnmapNotify. Map state gets set correctly + * again in HandleMapNotify. + */ + tmp_win->flags &= ~MAPPED; + width = tmp_win->frame_width; + tmp_win->frame_width = 0; + height = tmp_win->frame_height; + tmp_win->frame_height = 0; + SetupFrame( + tmp_win, tmp_win->frame_x, tmp_win->frame_y, width, height, True); + + /* wait until the window is iconified and the icon window is mapped + * before creating the icon window + */ + tmp_win->icon_w = None; + GrabButtons(tmp_win); + GrabKeys(tmp_win); + + XSaveContext(dpy, tmp_win->w, FvwmContext, (caddr_t)tmp_win); + XSaveContext(dpy, tmp_win->frame, FvwmContext, (caddr_t)tmp_win); + XSaveContext(dpy, tmp_win->Parent, FvwmContext, (caddr_t)tmp_win); + if (tmp_win->flags & TITLE) { + XSaveContext( + dpy, tmp_win->title_w, FvwmContext, (caddr_t)tmp_win); + for (i = 0; i < Scr.nr_left_buttons; i++) + XSaveContext(dpy, tmp_win->left_w[i], FvwmContext, + (caddr_t)tmp_win); + for (i = 0; i < Scr.nr_right_buttons; i++) + if (tmp_win->right_w[i] != None) + XSaveContext(dpy, tmp_win->right_w[i], + FvwmContext, (caddr_t)tmp_win); } - } - RaiseWindow(tmp_win); - KeepOnTop(); - MyXUngrabServer(dpy); - - XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - XTranslateCoordinates(dpy,tmp_win->frame,Scr.Root,JunkX,JunkY, - &a,&b,&JunkChild); - tmp_win->xdiff -= a; - tmp_win->ydiff -= b; - if((tmp_win->flags & ClickToFocus) || Scr.MouseFocusClickRaises) - { - /* need to grab all buttons for window that we are about to - * unhighlight */ - for(i=1;i<=3;i++) - if(Scr.buttons2grab & (1<frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); - XGrabButton(dpy,(i),LockMask,tmp_win->frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); -#else - /* should we accept any modifier on this button? */ - /* domivogt (2-Jan-1999): No. Or at least not like this. In the - * present form no button presses go through to the title bar - * anymore. They are all swallowed by the frame window. */ - XGrabButton(dpy,(i),AnyModifier,tmp_win->frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); -#endif - } - } - BroadcastConfig(M_ADD_WINDOW,tmp_win); - - BroadcastName(M_WINDOW_NAME,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->name); - BroadcastName(M_ICON_NAME,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->icon_name); - if (tmp_win->icon_bitmap_file != NULL && - tmp_win->icon_bitmap_file != Scr.DefaultIcon) - BroadcastName(M_ICON_FILE,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->icon_bitmap_file); - BroadcastName(M_RES_CLASS,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->class.res_class); - BroadcastName(M_RES_NAME,tmp_win->w,tmp_win->frame, - (unsigned long)tmp_win,tmp_win->class.res_name); + if (tmp_win->flags & BORDER) { + for (i = 0; i < 4; i++) { + XSaveContext(dpy, tmp_win->sides[i], FvwmContext, + (caddr_t)tmp_win); + XSaveContext(dpy, tmp_win->corners[i], FvwmContext, + (caddr_t)tmp_win); + } + } + RaiseWindow(tmp_win); + KeepOnTop(); + MyXUngrabServer(dpy); + + XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth); + XTranslateCoordinates( + dpy, tmp_win->frame, Scr.Root, JunkX, JunkY, &a, &b, &JunkChild); + tmp_win->xdiff -= a; + tmp_win->ydiff -= b; + if ((tmp_win->flags & ClickToFocus) || Scr.MouseFocusClickRaises) { + /* need to grab all buttons for window that we are about to + * unhighlight */ + for (i = 1; i <= 3; i++) + if (Scr.buttons2grab & (1 << i)) { + /* should we accept any modifier on this button? + */ + /* domivogt (2-Jan-1999): No. Or at least not + * like this. In the present form no button + * presses go through to the title bar anymore. + * They are all swallowed by the frame window. + */ + XGrabButton(dpy, (i), AnyModifier, + tmp_win->frame, True, ButtonPressMask, + GrabModeSync, GrabModeAsync, None, + Scr.FvwmCursors[SYS]); + } + } + BroadcastConfig(M_ADD_WINDOW, tmp_win); + + BroadcastName(M_WINDOW_NAME, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->name); + BroadcastName(M_ICON_NAME, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_name); + if (tmp_win->icon_bitmap_file != NULL && + tmp_win->icon_bitmap_file != Scr.DefaultIcon) + BroadcastName(M_ICON_FILE, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_bitmap_file); + BroadcastName(M_RES_CLASS, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->class.res_class); + BroadcastName(M_RES_NAME, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->class.res_name); #ifdef MINI_ICONS - if (tmp_win->mini_icon != NULL) - BroadcastMiniIcon(M_MINI_ICON, - tmp_win->w, tmp_win->frame, (unsigned long)tmp_win, - tmp_win->mini_icon->width, - tmp_win->mini_icon->height, - tmp_win->mini_icon->depth, - tmp_win->mini_icon->picture, - tmp_win->mini_icon->mask, - tmp_win->mini_pixmap_file); + if (tmp_win->mini_icon != NULL) + BroadcastMiniIcon(M_MINI_ICON, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->mini_icon->width, + tmp_win->mini_icon->height, tmp_win->mini_icon->depth, + tmp_win->mini_icon->picture, tmp_win->mini_icon->mask, + tmp_win->mini_pixmap_file); #endif - FetchWmProtocols (tmp_win); - FetchWmColormapWindows (tmp_win); - if(!(XGetWindowAttributes(dpy,tmp_win->w,&(tmp_win->attr)))) - tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; - if(NeedToResizeToo) - { - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, - tmp_win->frame_x + (tmp_win->frame_width>>1), - tmp_win->frame_y + (tmp_win->frame_height>>1)); - Event.xany.type = ButtonPress; - Event.xbutton.button = 1; - Event.xbutton.x_root = tmp_win->frame_x + (tmp_win->frame_width>>1); - Event.xbutton.y_root = tmp_win->frame_y + (tmp_win->frame_height>>1); - Event.xbutton.x = (tmp_win->frame_width>>1); - Event.xbutton.y = (tmp_win->frame_height>>1); - Event.xbutton.subwindow = None; - Event.xany.window = tmp_win->w; - resize_window(&Event , tmp_win->w, tmp_win, C_WINDOW, "", 0); - } - InstallWindowColormaps(colormap_win); - return (tmp_win); + FetchWmProtocols(tmp_win); + FetchWmColormapWindows(tmp_win); + if (!(XGetWindowAttributes(dpy, tmp_win->w, &(tmp_win->attr)))) + tmp_win->attr.colormap = Scr.FvwmRoot.attr.colormap; + if (NeedToResizeToo) { + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, + tmp_win->frame_x + (tmp_win->frame_width >> 1), + tmp_win->frame_y + (tmp_win->frame_height >> 1)); + Event.xany.type = ButtonPress; + Event.xbutton.button = 1; + Event.xbutton.x_root = + tmp_win->frame_x + (tmp_win->frame_width >> 1); + Event.xbutton.y_root = + tmp_win->frame_y + (tmp_win->frame_height >> 1); + Event.xbutton.x = (tmp_win->frame_width >> 1); + Event.xbutton.y = (tmp_win->frame_height >> 1); + Event.xbutton.subwindow = None; + Event.xany.window = tmp_win->w; + resize_window(&Event, tmp_win->w, tmp_win, C_WINDOW, "", 0); + } + InstallWindowColormaps(colormap_win); + return (tmp_win); } /*********************************************************************** @@ -789,76 +760,71 @@ FvwmWindow *AddWindow(Window w) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabButtons(FvwmWindow *tmp_win) +void +GrabButtons(FvwmWindow *tmp_win) { - Binding *MouseEntry; - - MouseEntry = Scr.AllBindings; - while(MouseEntry != (Binding *)0) - { - if((MouseEntry->Action != NULL)&&(MouseEntry->Context & C_WINDOW) - &&(MouseEntry->IsMouse == 1)) - { - if(MouseEntry->Button_Key >0) - { - XGrabButton(dpy, MouseEntry->Button_Key, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - if(MouseEntry->Modifier != AnyModifier) - { - XGrabButton(dpy, MouseEntry->Button_Key, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - } - } - else - { - XGrabButton(dpy, 1, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 2, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 3, MouseEntry->Modifier, - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - if(MouseEntry->Modifier != AnyModifier) - { - XGrabButton(dpy, 1, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 2, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 3, - (MouseEntry->Modifier | LockMask), - tmp_win->w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); + Binding *MouseEntry; + + MouseEntry = Scr.AllBindings; + while (MouseEntry != (Binding *)0) { + if ((MouseEntry->Action != NULL) && + (MouseEntry->Context & C_WINDOW) && + (MouseEntry->IsMouse == 1)) { + if (MouseEntry->Button_Key > 0) { + XGrabButton(dpy, MouseEntry->Button_Key, + MouseEntry->Modifier, tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + if (MouseEntry->Modifier != AnyModifier) { + XGrabButton(dpy, MouseEntry->Button_Key, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + } + } else { + XGrabButton(dpy, 1, MouseEntry->Modifier, + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 2, MouseEntry->Modifier, + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 3, MouseEntry->Modifier, + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + if (MouseEntry->Modifier != AnyModifier) { + XGrabButton(dpy, 1, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 2, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 3, + (MouseEntry->Modifier | LockMask), + tmp_win->w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + } + } } - } + MouseEntry = MouseEntry->NextBinding; } - MouseEntry = MouseEntry->NextBinding; - } - return; + return; } /*********************************************************************** @@ -870,25 +836,24 @@ void GrabButtons(FvwmWindow *tmp_win) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabKeys(FvwmWindow *tmp_win) +void +GrabKeys(FvwmWindow *tmp_win) { - Binding *tmp; - for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) - { - if((tmp->Context & (C_WINDOW|C_TITLE|C_RALL|C_LALL|C_SIDEBAR))&& - (tmp->IsMouse == 0)) - { - XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, tmp_win->frame, True, - GrabModeAsync, GrabModeAsync); - if(tmp->Modifier != AnyModifier) - { - XGrabKey(dpy, tmp->Button_Key, tmp->Modifier|LockMask, - tmp_win->frame, True, - GrabModeAsync, GrabModeAsync); - } + Binding *tmp; + for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) { + if ((tmp->Context & + (C_WINDOW | C_TITLE | C_RALL | C_LALL | C_SIDEBAR)) && + (tmp->IsMouse == 0)) { + XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, + tmp_win->frame, True, GrabModeAsync, GrabModeAsync); + if (tmp->Modifier != AnyModifier) { + XGrabKey(dpy, tmp->Button_Key, + tmp->Modifier | LockMask, tmp_win->frame, + True, GrabModeAsync, GrabModeAsync); + } + } } - } - return; + return; } /*********************************************************************** @@ -900,46 +865,48 @@ void GrabKeys(FvwmWindow *tmp_win) * tmp - the fvwm window structure to use * ***********************************************************************/ -void FetchWmProtocols (FvwmWindow *tmp) +void +FetchWmProtocols(FvwmWindow *tmp) { - unsigned long flags = 0L; - Atom *protocols = NULL, *ap; - int i, n; - Atom atype; - int aformat; - unsigned long bytes_remain,nitems; - - if(tmp == NULL) return; - /* First, try the Xlib function to read the protocols. - * This is what Twm uses. */ - if (XGetWMProtocols (dpy, tmp->w, &protocols, &n)) - { - for (i = 0, ap = protocols; i < n; i++, ap++) - { - if (*ap == (Atom)_XA_WM_TAKE_FOCUS) flags |= DoesWmTakeFocus; - if (*ap == (Atom)_XA_WM_DELETE_WINDOW) flags |= DoesWmDeleteWindow; - } - if (protocols) XFree ((char *) protocols); - } - else - { - /* Next, read it the hard way. mosaic from Coreldraw needs to - * be read in this way. */ - if ((XGetWindowProperty(dpy, tmp->w, _XA_WM_PROTOCOLS, 0L, 10L, False, - _XA_WM_PROTOCOLS, &atype, &aformat, &nitems, - &bytes_remain, - (unsigned char **)&protocols))==Success) - { - for (i = 0, ap = protocols; i < nitems; i++, ap++) - { - if (*ap == (Atom)_XA_WM_TAKE_FOCUS) flags |= DoesWmTakeFocus; - if (*ap == (Atom)_XA_WM_DELETE_WINDOW) flags |= DoesWmDeleteWindow; - } - if (protocols) XFree ((char *) protocols); + unsigned long flags = 0L; + Atom *protocols = NULL, *ap; + int i, n; + Atom atype; + int aformat; + unsigned long bytes_remain, nitems; + + if (tmp == NULL) + return; + /* First, try the Xlib function to read the protocols. + * This is what Twm uses. */ + if (XGetWMProtocols(dpy, tmp->w, &protocols, &n)) { + for (i = 0, ap = protocols; i < n; i++, ap++) { + if (*ap == (Atom)_XA_WM_TAKE_FOCUS) + flags |= DoesWmTakeFocus; + if (*ap == (Atom)_XA_WM_DELETE_WINDOW) + flags |= DoesWmDeleteWindow; + } + if (protocols) + XFree((char *)protocols); + } else { + /* Next, read it the hard way. mosaic from Coreldraw needs to + * be read in this way. */ + if ((XGetWindowProperty(dpy, tmp->w, _XA_WM_PROTOCOLS, 0L, 10L, + False, _XA_WM_PROTOCOLS, &atype, &aformat, &nitems, + &bytes_remain, (unsigned char **)&protocols)) == + Success) { + for (i = 0, ap = protocols; i < nitems; i++, ap++) { + if (*ap == (Atom)_XA_WM_TAKE_FOCUS) + flags |= DoesWmTakeFocus; + if (*ap == (Atom)_XA_WM_DELETE_WINDOW) + flags |= DoesWmDeleteWindow; + } + if (protocols) + XFree((char *)protocols); + } } - } - tmp->flags |= flags; - return; + tmp->flags |= flags; + return; } /*********************************************************************** @@ -951,108 +918,99 @@ void FetchWmProtocols (FvwmWindow *tmp) * tmp - the fvwm window structure to use * ***********************************************************************/ -void GetWindowSizeHints(FvwmWindow *tmp) +void +GetWindowSizeHints(FvwmWindow *tmp) { - long supplied = 0; - - if (!XGetWMNormalHints (dpy, tmp->w, &tmp->hints, &supplied)) - tmp->hints.flags = 0; - - /* Beat up our copy of the hints, so that all important field are - * filled in! */ - if (tmp->hints.flags & PResizeInc) - { - if (tmp->hints.width_inc == 0) tmp->hints.width_inc = 1; - if (tmp->hints.height_inc == 0) tmp->hints.height_inc = 1; - } - else - { - tmp->hints.width_inc = 1; - tmp->hints.height_inc = 1; - } - - /* - * ICCCM says that PMinSize is the default if no PBaseSize is given, - * and vice-versa. - */ - - if(!(tmp->hints.flags & PBaseSize)) - { - if(tmp->hints.flags & PMinSize) - { - tmp->hints.base_width = tmp->hints.min_width; - tmp->hints.base_height = tmp->hints.min_height; + long supplied = 0; + + if (!XGetWMNormalHints(dpy, tmp->w, &tmp->hints, &supplied)) + tmp->hints.flags = 0; + + /* Beat up our copy of the hints, so that all important field are + * filled in! */ + if (tmp->hints.flags & PResizeInc) { + if (tmp->hints.width_inc == 0) + tmp->hints.width_inc = 1; + if (tmp->hints.height_inc == 0) + tmp->hints.height_inc = 1; + } else { + tmp->hints.width_inc = 1; + tmp->hints.height_inc = 1; + } + + /* + * ICCCM says that PMinSize is the default if no PBaseSize is given, + * and vice-versa. + */ + + if (!(tmp->hints.flags & PBaseSize)) { + if (tmp->hints.flags & PMinSize) { + tmp->hints.base_width = tmp->hints.min_width; + tmp->hints.base_height = tmp->hints.min_height; + } else { + tmp->hints.base_width = 0; + tmp->hints.base_height = 0; + } + } + if (!(tmp->hints.flags & PMinSize)) { + tmp->hints.min_width = tmp->hints.base_width; + tmp->hints.min_height = tmp->hints.base_height; + } + if (!(tmp->hints.flags & PMaxSize)) { + tmp->hints.max_width = MAX_WINDOW_WIDTH; + tmp->hints.max_height = MAX_WINDOW_HEIGHT; } - else - { - tmp->hints.base_width = 0; - tmp->hints.base_height = 0; + if (tmp->hints.max_width < tmp->hints.min_width) + tmp->hints.max_width = MAX_WINDOW_WIDTH; + if (tmp->hints.max_height < tmp->hints.min_height) + tmp->hints.max_height = MAX_WINDOW_HEIGHT; + + /* Zero width/height windows are bad news! */ + if (tmp->hints.min_height <= 0) + tmp->hints.min_height = 1; + if (tmp->hints.min_width <= 0) + tmp->hints.min_width = 1; + + if (!(tmp->hints.flags & PWinGravity)) { + tmp->hints.win_gravity = NorthWestGravity; + tmp->hints.flags |= PWinGravity; } - } - if(!(tmp->hints.flags & PMinSize)) - { - tmp->hints.min_width = tmp->hints.base_width; - tmp->hints.min_height = tmp->hints.base_height; - } - if(!(tmp->hints.flags & PMaxSize)) - { - tmp->hints.max_width = MAX_WINDOW_WIDTH; - tmp->hints.max_height = MAX_WINDOW_HEIGHT; - } - if(tmp->hints.max_width < tmp->hints.min_width) - tmp->hints.max_width = MAX_WINDOW_WIDTH; - if(tmp->hints.max_height < tmp->hints.min_height) - tmp->hints.max_height = MAX_WINDOW_HEIGHT; - - /* Zero width/height windows are bad news! */ - if(tmp->hints.min_height <= 0) - tmp->hints.min_height = 1; - if(tmp->hints.min_width <= 0) - tmp->hints.min_width = 1; - - if(!(tmp->hints.flags & PWinGravity)) - { - tmp->hints.win_gravity = NorthWestGravity; - tmp->hints.flags |= PWinGravity; - } - - if (tmp->hints.flags & PAspect) - { - /* - ** check to make sure min/max aspect ratios look valid - */ + + if (tmp->hints.flags & PAspect) { + /* + ** check to make sure min/max aspect ratios look valid + */ #define maxAspectX tmp->hints.max_aspect.x #define maxAspectY tmp->hints.max_aspect.y #define minAspectX tmp->hints.min_aspect.x #define minAspectY tmp->hints.min_aspect.y - /* - ** The math looks like this: - ** - ** minAspectX maxAspectX - ** ---------- <= ---------- - ** minAspectY maxAspectY - ** - ** If that is multiplied out, this must be satisfied: - ** - ** minAspectX * maxAspectY <= maxAspectX * minAspectY - ** - ** So, what to do if this isn't met? Ignoring it entirely - ** seems safest. - ** - */ - if ((minAspectX * maxAspectY) > (maxAspectX * minAspectY)) - { - tmp->hints.flags &= ~PAspect; - fvwm_msg(WARN, - "GetWindowSizeHints", - "window id 0x%08x max_aspect ratio is < min_aspect ratio -> ignoring, but program displaying this window should be fixed!!!!", - tmp->w); - } - } + /* + ** The math looks like this: + ** + ** minAspectX maxAspectX + ** ---------- <= ---------- + ** minAspectY maxAspectY + ** + ** If that is multiplied out, this must be satisfied: + ** + ** minAspectX * maxAspectY <= maxAspectX * minAspectY + ** + ** So, what to do if this isn't met? Ignoring it entirely + ** seems safest. + ** + */ + if ((minAspectX * maxAspectY) > (maxAspectX * minAspectY)) { + tmp->hints.flags &= ~PAspect; + fvwm_msg(WARN, "GetWindowSizeHints", + "window id 0x%08x max_aspect ratio is < min_aspect " + "ratio -> ignoring, but program displaying this " + "window " + "should be fixed!!!!", + tmp->w); + } + } } - - /*********************************************************************** * * Procedure: @@ -1073,23 +1031,26 @@ void GetWindowSizeHints(FvwmWindow *tmp) * Point at iconboxes chain, not single iconboxes elements. * ***********************************************************************/ -void LookInList( FvwmWindow *tmp_win, name_list *styles) +void +LookInList(FvwmWindow *tmp_win, name_list *styles) { - name_list *nptr; - - memset(styles, 0, sizeof(name_list)); /* clear callers return area */ - /* look thru all styles in order defined. */ - for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { - /* If name/res_class/res_name match, merge */ - if (matchWildcards(nptr->name,tmp_win->class.res_class) == TRUE) { - merge_styles(styles, nptr); - } else if (matchWildcards(nptr->name,tmp_win->class.res_name) == TRUE) { - merge_styles(styles, nptr); - } else if (matchWildcards(nptr->name,tmp_win->name) == TRUE) { - merge_styles(styles, nptr); - } - } - return; + name_list *nptr; + + memset(styles, 0, sizeof(name_list)); /* clear callers return area */ + /* look thru all styles in order defined. */ + for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { + /* If name/res_class/res_name match, merge */ + if (matchWildcards(nptr->name, tmp_win->class.res_class) == + TRUE) { + merge_styles(styles, nptr); + } else if (matchWildcards( + nptr->name, tmp_win->class.res_name) == TRUE) { + merge_styles(styles, nptr); + } else if (matchWildcards(nptr->name, tmp_win->name) == TRUE) { + merge_styles(styles, nptr); + } + } + return; } /*********************************************************************** @@ -1110,37 +1071,42 @@ void LookInList( FvwmWindow *tmp_win, name_list *styles) * ***********************************************************************/ -static void merge_styles(name_list *styles, name_list *nptr) { - if(nptr->value != NULL) styles->value = nptr->value; +static void +merge_styles(name_list *styles, name_list *nptr) +{ + if (nptr->value != NULL) + styles->value = nptr->value; #ifdef MINI_ICONS - if(nptr->mini_value != NULL) styles->mini_value = nptr->mini_value; + if (nptr->mini_value != NULL) + styles->mini_value = nptr->mini_value; #endif #ifdef USEDECOR - if (nptr->Decor != NULL) styles->Decor = nptr->Decor; + if (nptr->Decor != NULL) + styles->Decor = nptr->Decor; #endif - if(nptr->off_flags & STARTSONDESK_FLAG) - /* RBW - 11/02/1998 */ - { - styles->Desk = nptr->Desk; - styles->PageX = nptr->PageX; - styles->PageY = nptr->PageY; - } - if(nptr->off_flags & BW_FLAG) - styles->border_width = nptr->border_width; - if(nptr->off_flags & FORE_COLOR_FLAG) - styles->ForeColor = nptr->ForeColor; - if(nptr->off_flags & BACK_COLOR_FLAG) - styles->BackColor = nptr->BackColor; - if(nptr->off_flags & NOBW_FLAG) - styles->resize_width = nptr->resize_width; - styles->on_flags |= nptr->off_flags; /* combine on and off flags */ - styles->on_flags &= ~(nptr->on_flags); - styles->on_buttons |= nptr->off_buttons; /* combine buttons */ - styles->on_buttons &= ~(nptr->on_buttons); - /* Note, only one style cmd can define a windows iconboxes, - the last one encountered. */ - if(nptr->IconBoxes != NULL) { /* If style has iconboxes */ - styles->IconBoxes = nptr->IconBoxes; /* copy it */ - } - return; /* return */ + if (nptr->off_flags & STARTSONDESK_FLAG) + /* RBW - 11/02/1998 */ + { + styles->Desk = nptr->Desk; + styles->PageX = nptr->PageX; + styles->PageY = nptr->PageY; + } + if (nptr->off_flags & BW_FLAG) + styles->border_width = nptr->border_width; + if (nptr->off_flags & FORE_COLOR_FLAG) + styles->ForeColor = nptr->ForeColor; + if (nptr->off_flags & BACK_COLOR_FLAG) + styles->BackColor = nptr->BackColor; + if (nptr->off_flags & NOBW_FLAG) + styles->resize_width = nptr->resize_width; + styles->on_flags |= nptr->off_flags; /* combine on and off flags */ + styles->on_flags &= ~(nptr->on_flags); + styles->on_buttons |= nptr->off_buttons; /* combine buttons */ + styles->on_buttons &= ~(nptr->on_buttons); + /* Note, only one style cmd can define a windows iconboxes, + the last one encountered. */ + if (nptr->IconBoxes != NULL) { /* If style has iconboxes */ + styles->IconBoxes = nptr->IconBoxes; /* copy it */ + } + return; /* return */ } Index: fvwm/fvwm/bindings.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/bindings.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/bindings.c --- fvwm/fvwm/bindings.c +++ fvwm/fvwm/bindings.c @@ -1,109 +1,87 @@ -#include "config.h" - -#include +#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" -#include -struct charstring -{ - char key; - int value; +struct charstring { + char key; + int value; }; - /* The keys musat be in lower case! */ -struct charstring win_contexts[]= -{ - {'w',C_WINDOW}, - {'t',C_TITLE}, - {'i',C_ICON}, - {'r',C_ROOT}, - {'f',C_FRAME}, - {'s',C_SIDEBAR}, - {'1',C_L1}, - {'2',C_R1}, - {'3',C_L2}, - {'4',C_R2}, - {'5',C_L3}, - {'6',C_R3}, - {'7',C_L4}, - {'8',C_R4}, - {'9',C_L5}, - {'0',C_R5}, - {'a',C_WINDOW|C_TITLE|C_ICON|C_ROOT|C_FRAME|C_SIDEBAR| - C_L1|C_L2|C_L3|C_L4|C_L5|C_R1|C_R2|C_R3|C_R4|C_R5}, - {0,0} -}; +struct charstring win_contexts[] = {{'w', C_WINDOW}, {'t', C_TITLE}, + {'i', C_ICON}, {'r', C_ROOT}, {'f', C_FRAME}, {'s', C_SIDEBAR}, {'1', C_L1}, + {'2', C_R1}, {'3', C_L2}, {'4', C_R2}, {'5', C_L3}, {'6', C_R3}, + {'7', C_L4}, {'8', C_R4}, {'9', C_L5}, {'0', C_R5}, + {'a', C_WINDOW | C_TITLE | C_ICON | C_ROOT | C_FRAME | C_SIDEBAR | C_L1 | + C_L2 | C_L3 | C_L4 | C_L5 | C_R1 | C_R2 | C_R3 | C_R4 | C_R5}, + {0, 0}}; /* The keys musat be in lower case! */ -struct charstring key_modifiers[]= +struct charstring key_modifiers[] = {{'s', ShiftMask}, {'c', ControlMask}, + {'m', Mod1Mask}, {'1', Mod1Mask}, {'2', Mod2Mask}, {'3', Mod3Mask}, + {'4', Mod4Mask}, {'5', Mod5Mask}, {'a', AnyModifier}, {'n', 0}, {0, 0}}; + +void find_context( + char *string, int *output, struct charstring *table, char *tline); + +static void +RegrabAllKeys(void) { - {'s',ShiftMask}, - {'c',ControlMask}, - {'m',Mod1Mask}, - {'1',Mod1Mask}, - {'2',Mod2Mask}, - {'3',Mod3Mask}, - {'4',Mod4Mask}, - {'5',Mod5Mask}, - {'a',AnyModifier}, - {'n',0}, - {0,0} -}; + FvwmWindow *t; -void find_context(char *string, int *output, struct charstring *table, - char *tline); + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + GrabKeys(t); + } +} /* ** to remove a binding from the global list (probably needs more processing ** for mouse binding lines though, like when context is a title bar button). */ -void remove_binding(int contexts, int mods, int button, KeySym keysym, - int mouse_binding) +void +remove_binding( + int contexts, int mods, int button, KeySym keysym, int mouse_binding) { - Binding *temp=Scr.AllBindings, *temp2, *prev=NULL; - KeyCode keycode = 0; - - if (!mouse_binding) - keycode=XKeysymToKeycode(dpy,keysym); - - while (temp) - { - temp2 = temp->NextBinding; - if (temp->IsMouse == mouse_binding) - { - if ((temp->Button_Key == ((mouse_binding)?(button):(keycode))) && - (temp->Context == contexts) && - (temp->Modifier == mods)) - { - /* we found it, remove it from list */ - if (prev) /* middle of list */ - { - prev->NextBinding = temp2; - } - else /* must have been first one, set new start */ - { - Scr.AllBindings = temp2; - } - free(temp->key_name); - free(temp->Action); - free(temp); - temp=NULL; - } - } - if (temp) - prev=temp; - temp=temp2; - } + Binding *temp = Scr.AllBindings, *temp2, *prev = NULL; + KeyCode keycode = 0; + + if (!mouse_binding) + keycode = XKeysymToKeycode(dpy, keysym); + + while (temp) { + temp2 = temp->NextBinding; + if (temp->IsMouse == mouse_binding) { + if ((temp->Button_Key == + ((mouse_binding) ? (button) : (keycode))) && + (temp->Context == contexts) && + (temp->Modifier == mods)) { + /* we found it, remove it from list */ + if (prev) { /* middle of list */ + prev->NextBinding = temp2; + } else /* must have been first one, set new + start */ { + Scr.AllBindings = temp2; + } + free(temp->key_name); + free(temp->Action); + free(temp); + temp = NULL; + } + } + if (temp) + prev = temp; + temp = temp2; + } } /**************************************************************************** @@ -111,175 +89,194 @@ void remove_binding(int contexts, int mods, int button, KeySym keysym, * Parses a mouse or key binding * ****************************************************************************/ -void ParseBindEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long junk, char *tline,int* Module, Bool fKey) +void +ParseBindEntry(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long junk, char *tline, int *Module, Bool fKey) { - char *action,context[20],modifiers[20],key[20],*ptr, *token; - Binding *temp; - int button,i,min,max; - int n1=0,n2=0,n3=0; - KeySym keysym; - KeySym tkeysym; - int contexts; - int mods; - int maxmods; - int m; - - /* tline points after the key word "Mouse" or "Key" */ - ptr = GetNextToken(tline, &token); - if(token != NULL) - { - if (fKey) - n1 = sscanf(token,"%19s",key); - else - n1 = sscanf(token,"%d",&button); - free(token); - } - - ptr = GetNextToken(ptr,&token); - if(token != NULL) - { - n2 = sscanf(token,"%19s",context); - free(token); - } - - action = GetNextToken(ptr,&token); - if(token != NULL) - { - n3 = sscanf(token,"%19s",modifiers); - free(token); - } - - if((n1 != 1)||(n2 != 1)||(n3 != 1)) - { - fvwm_msg(ERR,"ParseBindEntry","Syntax error in line %s",tline); - return; - } - - find_context(context,&contexts,win_contexts,tline); - find_context(modifiers,&mods,key_modifiers,tline); - - if (fKey) - { - /* - * Don't let a 0 keycode go through, since that means AnyKey to the - * XGrabKey call in GrabKeys(). - */ - if ((keysym = XStringToKeysym(key)) == NoSymbol || - (XKeysymToKeycode(dpy, keysym)) == 0) - return; - } - - /* - ** strip leading whitespace from action if necessary - */ - while (*action && (*action == ' ' || *action == '\t')) - action++; - - /* - ** is this an unbind request? - */ - if (!action || action[0] == '-') - { - if (fKey) - remove_binding(contexts,mods,0,keysym,0); - else - remove_binding(contexts,mods,button,0,1); - return; - } - - if (!fKey) - { - int j; - - if((contexts != C_ALL) && (contexts & C_LALL)) - { - /* check for nr_left_buttons */ - i=0; - j=(contexts &C_LALL)/C_L1; - while(j>0) - { - i++; - j=j>>1; - } - if(Scr.nr_left_buttons 0) - { - i++; - j=j>>1; - } - if(Scr.nr_right_buttons IsMouse = !fKey; - Scr.AllBindings->Button_Key = i; - Scr.AllBindings->key_name = fKey ? stripcpy(key) : NULL; - Scr.AllBindings->Context = contexts; - Scr.AllBindings->Modifier = mods; - Scr.AllBindings->Action = stripcpy(action); - Scr.AllBindings->NextBinding = temp; - } - } - return; + + action = GetNextToken(ptr, &token); + if (token != NULL) { + n3 = sscanf(token, "%19s", modifiers); + free(token); + } + + if ((n1 != 1) || (n2 != 1) || (n3 != 1)) { + fvwm_msg( + ERR, "ParseBindEntry", "Syntax error in line %s", tline); + return; + } + + find_context(context, &contexts, win_contexts, tline); + find_context(modifiers, &mods, key_modifiers, tline); + + if (fKey) { + /* + * Don't let a 0 keycode go through, since that means AnyKey to + * the XGrabKey call in GrabKeys(). + */ + if ((keysym = XStringToKeysym(key)) == NoSymbol || + (XKeysymToKeycode(dpy, keysym)) == 0) + return; + } + + /* + ** strip leading whitespace from action if necessary + */ + while (*action && (*action == ' ' || *action == '\t')) + action++; + + /* + ** is this an unbind request? + */ + if (!action || action[0] == '-') { + if (fKey) + remove_binding(contexts, mods, 0, keysym, 0); + else + remove_binding(contexts, mods, button, 0, 1); + return; + } + + if (!fKey) { + int j; + + if ((contexts != C_ALL) && (contexts & C_LALL)) { + /* check for nr_left_buttons */ + i = 0; + j = (contexts & C_LALL) / C_L1; + while (j > 0) { + i++; + j = j >> 1; + } + if (Scr.nr_left_buttons < i) + Scr.nr_left_buttons = i; + } + if ((contexts != C_ALL) && (contexts & C_RALL)) { + /* check for nr_right_buttons */ + i = 0; + j = (contexts & C_RALL) / C_R1; + while (j > 0) { + i++; + j = j >> 1; + } + if (Scr.nr_right_buttons < i) + Scr.nr_right_buttons = i; + } + } + + if ((mods & AnyModifier) && (mods & (~AnyModifier))) { + fvwm_msg(WARN, "ParseBindEntry", + "Binding specified AnyModifier and other modifers too. " + "Excess modifiers will be ignored."); + mods &= AnyModifier; + } + + if ((!fKey) && (contexts & C_WINDOW) && + (((mods == 0) || mods == AnyModifier))) { + Scr.buttons2grab &= ~(1 << (button - 1)); + } + + /* + ** Unfortunately a keycode can be bound to multiple keysyms and a keysym + * can + ** be bound to multiple keycodes. Thus we have to check every keycode + * with + ** any single modifier. + */ + if (fKey) { + XDisplayKeycodes(dpy, &min, &max); + maxmods = 8; + } else { + min = button; + max = button; + maxmods = 0; + } + for (i = min; i <= max; i++) { + KeySym *mapping = NULL; + int mapping_width = 0; + int column_limit = maxmods; + + if (fKey) { + mapping = + XGetKeyboardMapping(dpy, i, 1, &mapping_width); + if (mapping == NULL || mapping_width <= 0) { + if (mapping) + XFree(mapping); + continue; + } + column_limit = mapping_width - 1; + if (column_limit > maxmods) + column_limit = maxmods; + } + + for (m = 0; m <= column_limit; m++) { + KeySym current = NoSymbol; + + if (fKey) { + current = mapping[m]; + if (current == NoSymbol) + break; + } + + if (!fKey || current == keysym) { + temp = Scr.AllBindings; + Scr.AllBindings = + (Binding *)xmalloc(sizeof(Binding)); + Scr.AllBindings->IsMouse = !fKey; + Scr.AllBindings->Button_Key = i; + Scr.AllBindings->key_name = + fKey ? stripcpy(key) : NULL; + Scr.AllBindings->Context = contexts; + Scr.AllBindings->Modifier = mods; + Scr.AllBindings->Action = stripcpy(action); + Scr.AllBindings->NextBinding = temp; + } + } + + if (mapping) + XFree(mapping); + } + if (fKey) + RegrabAllKeys(); + return; } -void ParseMouseEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long junk, char *tline,int* Module) +void +ParseMouseEntry(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long junk, char *tline, int *Module) { - ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, False); + ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, False); } -void ParseKeyEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long junk, char *tline,int* Module) +void +ParseKeyEntry(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long junk, + char *tline, int *Module) { - ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, True); + ParseBindEntry(eventp, w, tmp_win, junk, tline, Module, True); } /**************************************************************************** @@ -288,42 +285,37 @@ void ParseKeyEntry(XEvent *eventp,Window w,FvwmWindow *tmp_win, * true/false values (bits) * ****************************************************************************/ -void find_context(char *string, int *output, struct charstring *table, - char *tline) +void +find_context(char *string, int *output, struct charstring *table, char *tline) { - int i=0,j=0; - Bool matched; - char tmp1; - - *output=0; - i=0; - while(i #include +#include #include +#include "config.h" #include "fvwm.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" #ifdef SHAPE #include #endif -void DrawButton(FvwmWindow *t, - Window win, - int W, - int H, - ButtonFace *bf, - GC ReliefGC, GC ShadowGC, - Boolean inverted, - int stateflags); +void DrawButton(FvwmWindow *t, Window win, int W, int H, ButtonFace *bf, + GC ReliefGC, GC ShadowGC, Boolean inverted, int stateflags); #ifdef VECTOR_BUTTONS -void DrawLinePattern(Window win, - GC ReliefGC, - GC ShadowGC, - struct vector_coords *coords, - int w, int h); +void DrawLinePattern(Window win, GC ReliefGC, GC ShadowGC, + struct vector_coords *coords, int w, int h); #endif /* macro rules to get button state */ #if defined(ACTIVEDOWN_BTNS) && defined(INACTIVE_BTNS) -#define GetButtonState(window) \ - (onoroff ? ((PressedW == (window)) ? ActiveDown : ActiveUp) \ - : Inactive) +#define GetButtonState(window) \ + (onoroff ? ((PressedW == (window)) ? ActiveDown : ActiveUp) : Inactive) #else #ifdef ACTIVEDOWN_BTNS -#define GetButtonState(window) \ - ((PressedW == (window)) ? ActiveDown : ActiveUp) +#define GetButtonState(window) ((PressedW == (window)) ? ActiveDown : ActiveUp) #endif #ifdef INACTIVE_BTNS #define GetButtonState(window) (onoroff ? ActiveUp : Inactive) @@ -66,13 +53,14 @@ void DrawLinePattern(Window win, #endif /* macro to change window background color/pixmap */ -#define ChangeWindowColor(window,valuemask) { \ - if(NewColor) \ - { \ - XChangeWindowAttributes(dpy,window,valuemask, &attributes); \ - XClearWindow(dpy,window); \ - } \ - } +#define ChangeWindowColor(window, valuemask) \ + { \ + if (NewColor) { \ + XChangeWindowAttributes( \ + dpy, window, valuemask, &attributes); \ + XClearWindow(dpy, window); \ + } \ + } extern Window PressedW; XGCValues Globalgcv; @@ -82,476 +70,547 @@ unsigned long Globalgcm; * Redraws the windows borders * ****************************************************************************/ -void SetBorder (FvwmWindow *t, Bool onoroff,Bool force,Bool Mapped, - Window expose_win) +void +SetBorder( + FvwmWindow *t, Bool onoroff, Bool force, Bool Mapped, Window expose_win) { - int y, i, x; - GC ReliefGC,ShadowGC; - Pixel BorderColor,BackColor; - Pixmap BackPixmap,TextColor; + int y, i, x; + GC ReliefGC, ShadowGC; + Pixel BorderColor, BackColor; + Pixmap BackPixmap, TextColor; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - Pixmap TexturePixmap = None; - XSetWindowAttributes notex_attributes; - unsigned long notex_valuemask; + Pixmap TexturePixmap = None; + XSetWindowAttributes notex_attributes; + unsigned long notex_valuemask; #endif - Bool NewColor = False; - XSetWindowAttributes attributes; - unsigned long valuemask; - static unsigned int corners[4]; - Window w; + Bool NewColor = False; + XSetWindowAttributes attributes; + unsigned long valuemask; + static unsigned int corners[4]; + Window w; - corners[0] = TOP_HILITE | LEFT_HILITE; - corners[1] = TOP_HILITE | RIGHT_HILITE; - corners[2] = BOTTOM_HILITE | LEFT_HILITE; - corners[3] = BOTTOM_HILITE | RIGHT_HILITE; + corners[0] = TOP_HILITE | LEFT_HILITE; + corners[1] = TOP_HILITE | RIGHT_HILITE; + corners[2] = BOTTOM_HILITE | LEFT_HILITE; + corners[3] = BOTTOM_HILITE | RIGHT_HILITE; - if(!t) - return; + if (!t) + return; - if (onoroff) - { - /* don't re-draw just for kicks */ - if((!force)&&(Scr.Hilite == t)) - return; + if (onoroff) { + /* don't re-draw just for kicks */ + if ((!force) && (Scr.Hilite == t)) + return; - if(Scr.Hilite != t) - NewColor = True; + if (Scr.Hilite != t) + NewColor = True; - /* make sure that the previously highlighted window got unhighlighted */ - if((Scr.Hilite != t)&&(Scr.Hilite != NULL)) - SetBorder(Scr.Hilite,False,False,True,None); + /* make sure that the previously highlighted window got + * unhighlighted */ + if ((Scr.Hilite != t) && (Scr.Hilite != NULL)) + SetBorder(Scr.Hilite, False, False, True, None); #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - /* are we using textured borders? */ - if ((GetDecor(t,BorderStyle.active.style) - & ButtonFaceTypeMask) == TiledPixmapButton) - TexturePixmap = GetDecor(t,BorderStyle.active.u.p->picture); + /* are we using textured borders? */ + if ((GetDecor(t, BorderStyle.active.style) & + ButtonFaceTypeMask) == TiledPixmapButton) + TexturePixmap = + GetDecor(t, BorderStyle.active.u.p->picture); #endif - /* set the keyboard focus */ - if((Mapped)&&(t->flags&MAPPED)&&(Scr.Hilite != t)) - w = t->w; - else if((t->flags&ICONIFIED)&& - (Scr.Hilite !=t)&&(!(t->flags &SUPPRESSICON))) - w = t->icon_w; - Scr.Hilite = t; - - TextColor = GetDecor(t,HiColors.fore); - BackPixmap= Scr.gray_pixmap; - BackColor = GetDecor(t,HiColors.back); - ReliefGC = GetDecor(t,HiReliefGC); - ShadowGC = GetDecor(t,HiShadowGC); - BorderColor = GetDecor(t,HiRelief.back); - } - else - { - /* don't re-draw just for kicks */ - if((!force)&&(Scr.Hilite != t)) - return; - - if(Scr.Hilite == t) - { - Scr.Hilite = NULL; - NewColor = True; - } + /* set the keyboard focus */ + if ((Mapped) && (t->flags & MAPPED) && (Scr.Hilite != t)) + w = t->w; + else if ((t->flags & ICONIFIED) && (Scr.Hilite != t) && + (!(t->flags & SUPPRESSICON))) + w = t->icon_w; + Scr.Hilite = t; + + TextColor = GetDecor(t, HiColors.fore); + BackPixmap = Scr.gray_pixmap; + BackColor = GetDecor(t, HiColors.back); + ReliefGC = GetDecor(t, HiReliefGC); + ShadowGC = GetDecor(t, HiShadowGC); + BorderColor = GetDecor(t, HiRelief.back); + } else { + /* don't re-draw just for kicks */ + if ((!force) && (Scr.Hilite != t)) + return; + + if (Scr.Hilite == t) { + Scr.Hilite = NULL; + NewColor = True; + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if ((GetDecor(t,BorderStyle.inactive.style) - & ButtonFaceTypeMask) == TiledPixmapButton) - TexturePixmap = GetDecor(t,BorderStyle.inactive.u.p->picture); + if ((GetDecor(t, BorderStyle.inactive.style) & + ButtonFaceTypeMask) == TiledPixmapButton) + TexturePixmap = + GetDecor(t, BorderStyle.inactive.u.p->picture); #endif - TextColor =t->TextPixel; - BackPixmap = Scr.light_gray_pixmap; - if(t->flags & STICKY) - BackPixmap = Scr.sticky_gray_pixmap; - BackColor = t->BackPixel; - Globalgcv.foreground = t->ReliefPixel; - Globalgcm = GCForeground; - XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); - ReliefGC = Scr.ScratchGC1; - - Globalgcv.foreground = t->ShadowPixel; - XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); - ShadowGC = Scr.ScratchGC2; - BorderColor = t->ShadowPixel; - } - - if(t->flags & ICONIFIED) - { - DrawIconWindow(t); - return; - } + TextColor = t->TextPixel; + BackPixmap = Scr.light_gray_pixmap; + if (t->flags & STICKY) + BackPixmap = Scr.sticky_gray_pixmap; + BackColor = t->BackPixel; + Globalgcv.foreground = t->ReliefPixel; + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + ReliefGC = Scr.ScratchGC1; + + Globalgcv.foreground = t->ShadowPixel; + XChangeGC(dpy, Scr.ScratchGC2, Globalgcm, &Globalgcv); + ShadowGC = Scr.ScratchGC2; + BorderColor = t->ShadowPixel; + } + + if (t->flags & ICONIFIED) { + DrawIconWindow(t); + return; + } #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - valuemask = - notex_valuemask = - CWBorderPixel; - attributes.border_pixel = - notex_attributes.border_pixel = - BorderColor; + valuemask = notex_valuemask = CWBorderPixel; + attributes.border_pixel = notex_attributes.border_pixel = BorderColor; #else - valuemask = CWBorderPixel; - attributes.border_pixel = BorderColor; + valuemask = CWBorderPixel; + attributes.border_pixel = BorderColor; #endif #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (TexturePixmap) - { - attributes.background_pixmap = TexturePixmap; - valuemask |= CWBackPixmap; - if (Scr.d_depth < 2) { - notex_attributes.background_pixmap = BackPixmap; - notex_valuemask |= CWBackPixmap; - } else { - notex_attributes.background_pixel = BackColor; - notex_valuemask |= CWBackPixel; - } - } - else + if (TexturePixmap) { + attributes.background_pixmap = TexturePixmap; + valuemask |= CWBackPixmap; + if (Scr.d_depth < 2) { + notex_attributes.background_pixmap = BackPixmap; + notex_valuemask |= CWBackPixmap; + } else { + notex_attributes.background_pixel = BackColor; + notex_valuemask |= CWBackPixel; + } + } else #endif - if (Scr.d_depth < 2) - { - attributes.background_pixmap = BackPixmap; - valuemask |= CWBackPixmap; + if (Scr.d_depth < 2) { + attributes.background_pixmap = BackPixmap; + valuemask |= CWBackPixmap; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - notex_attributes.background_pixmap = BackPixmap; - notex_valuemask |= CWBackPixmap; + notex_attributes.background_pixmap = BackPixmap; + notex_valuemask |= CWBackPixmap; #endif - } - else - { - attributes.background_pixel = BackColor; - valuemask |= CWBackPixel; + } else { + attributes.background_pixel = BackColor; + valuemask |= CWBackPixel; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - notex_attributes.background_pixel = BackColor; - notex_valuemask |= CWBackPixel; + notex_attributes.background_pixel = BackColor; + notex_valuemask |= CWBackPixel; #endif - } - - if(t->flags & (TITLE|BORDER)) - { - XSetWindowBorder(dpy,t->Parent,BorderColor); - XSetWindowBorder(dpy,t->frame,BorderColor); - } - if(t->flags & TITLE) - { - ChangeWindowColor(t->title_w,valuemask); - for(i=0;ileft_w[i] != None) - { - enum ButtonState bs = GetButtonState(t->left_w[i]); - ButtonFace *bf = &GetDecor(t,left_buttons[i].state[bs]); + } + + if (t->flags & (TITLE | BORDER)) { + XSetWindowBorder(dpy, t->Parent, BorderColor); + XSetWindowBorder(dpy, t->frame, BorderColor); + } + if (t->flags & TITLE) { + ChangeWindowColor(t->title_w, valuemask); + for (i = 0; i < Scr.nr_left_buttons; ++i) { + if (t->left_w[i] != None) { + enum ButtonState bs = + GetButtonState(t->left_w[i]); + ButtonFace *bf = + &GetDecor(t, left_buttons[i].state[bs]); #if !(defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE)) - ChangeWindowColor(t->left_w[i],valuemask); + ChangeWindowColor(t->left_w[i], valuemask); #endif - if(flush_expose(t->left_w[i])||(expose_win == t->left_w[i])|| - (expose_win == None) + if (flush_expose(t->left_w[i]) || + (expose_win == t->left_w[i]) || + (expose_win == None) #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - || NewColor + || NewColor #endif - ) - { - int inverted = PressedW == t->left_w[i]; + ) { + int inverted = PressedW == t->left_w[i]; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (bf->style & UseBorderStyle) - XChangeWindowAttributes(dpy, t->left_w[i], - valuemask, &attributes); - else - XChangeWindowAttributes(dpy, t->left_w[i], - notex_valuemask, ¬ex_attributes); - XClearWindow(dpy, t->left_w[i]); + if (bf->style & UseBorderStyle) + XChangeWindowAttributes(dpy, + t->left_w[i], valuemask, + &attributes); + else + XChangeWindowAttributes(dpy, + t->left_w[i], + notex_valuemask, + ¬ex_attributes); + XClearWindow(dpy, t->left_w[i]); #endif #ifdef EXTENDED_TITLESTYLE - if (bf->style & UseTitleStyle) { - ButtonFace *tsbf = &GetDecor(t,titlebar.state[bs]); + if (bf->style & UseTitleStyle) { + ButtonFace *tsbf = &GetDecor( + t, titlebar.state[bs]); #ifdef MULTISTYLE - for (; tsbf; tsbf = tsbf->next) + for (; tsbf; tsbf = tsbf->next) #endif - DrawButton(t, t->left_w[i], - t->title_height, t->title_height, - tsbf, ReliefGC, ShadowGC, - inverted, GetDecor(t,left_buttons[i].flags)); - } + DrawButton(t, + t->left_w[i], + t->title_height, + t->title_height, + tsbf, ReliefGC, + ShadowGC, inverted, + GetDecor(t, + left_buttons[i] + .flags)); + } #endif /* EXTENDED_TITLESTYLE */ #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->left_w[i], - t->title_height, t->title_height, - bf, ReliefGC, ShadowGC, - inverted, GetDecor(t,left_buttons[i].flags)); - - if (!(GetDecor(t,left_buttons[i].state[bs].style) & FlatButton)) { - if (GetDecor(t,left_buttons[i].state[bs].style) & SunkButton) - RelieveWindow(t,t->left_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ReliefGC : ShadowGC), - (inverted ? ShadowGC : ReliefGC), - BOTTOM_HILITE); - else - RelieveWindow(t,t->left_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ShadowGC : ReliefGC), - (inverted ? ReliefGC : ShadowGC), - BOTTOM_HILITE); + DrawButton(t, t->left_w[i], + t->title_height, + t->title_height, bf, + ReliefGC, ShadowGC, + inverted, + GetDecor(t, + left_buttons[i].flags)); + + if (!(GetDecor(t, left_buttons[i] + .state[bs] + .style) & + FlatButton)) { + if (GetDecor(t, left_buttons[i] + .state[bs] + .style) & + SunkButton) + RelieveWindow(t, + t->left_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ReliefGC : + ShadowGC), + (inverted ? + ShadowGC : + ReliefGC), + BOTTOM_HILITE); + else + RelieveWindow(t, + t->left_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ShadowGC : + ReliefGC), + (inverted ? + ReliefGC : + ShadowGC), + BOTTOM_HILITE); + } + } + } } - } - } - } - for(i=0;iright_w[i] != None) - { - enum ButtonState bs = GetButtonState(t->right_w[i]); - ButtonFace *bf = &GetDecor(t,right_buttons[i].state[bs]); + for (i = 0; i < Scr.nr_right_buttons; ++i) { + if (t->right_w[i] != None) { + enum ButtonState bs = + GetButtonState(t->right_w[i]); + ButtonFace *bf = + &GetDecor(t, right_buttons[i].state[bs]); #if !(defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE)) - ChangeWindowColor(t->right_w[i],valuemask); + ChangeWindowColor(t->right_w[i], valuemask); #endif - if(flush_expose(t->right_w[i])||(expose_win==t->right_w[i])|| - (expose_win == None) + if (flush_expose(t->right_w[i]) || + (expose_win == t->right_w[i]) || + (expose_win == None) #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - || NewColor + || NewColor #endif - ) - { - int inverted = PressedW == t->right_w[i]; + ) { + int inverted = + PressedW == t->right_w[i]; #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - if (bf->style & UseBorderStyle) - XChangeWindowAttributes(dpy, t->right_w[i], - valuemask, &attributes); - else - XChangeWindowAttributes(dpy, t->right_w[i], - notex_valuemask, ¬ex_attributes); - XClearWindow(dpy, t->right_w[i]); + if (bf->style & UseBorderStyle) + XChangeWindowAttributes(dpy, + t->right_w[i], valuemask, + &attributes); + else + XChangeWindowAttributes(dpy, + t->right_w[i], + notex_valuemask, + ¬ex_attributes); + XClearWindow(dpy, t->right_w[i]); #endif #ifdef EXTENDED_TITLESTYLE - if (bf->style & UseTitleStyle) { - ButtonFace *tsbf = &GetDecor(t,titlebar.state[bs]); + if (bf->style & UseTitleStyle) { + ButtonFace *tsbf = &GetDecor( + t, titlebar.state[bs]); #ifdef MULTISTYLE - for (; tsbf; tsbf = tsbf->next) + for (; tsbf; tsbf = tsbf->next) #endif - DrawButton(t, t->right_w[i], - t->title_height, t->title_height, - tsbf, ReliefGC, ShadowGC, - inverted, GetDecor(t,right_buttons[i].flags)); - } + DrawButton(t, + t->right_w[i], + t->title_height, + t->title_height, + tsbf, ReliefGC, + ShadowGC, inverted, + GetDecor(t, + right_buttons[i] + .flags)); + } #endif /* EXTENDED_TITLESTYLE */ #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->right_w[i], - t->title_height, t->title_height, - bf, ReliefGC, ShadowGC, - inverted, GetDecor(t,right_buttons[i].flags)); - - if (!(GetDecor(t,right_buttons[i].state[bs].style) & FlatButton)) { - if (GetDecor(t,right_buttons[i].state[bs].style) & SunkButton) - RelieveWindow(t,t->right_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ReliefGC : ShadowGC), - (inverted ? ShadowGC : ReliefGC), - BOTTOM_HILITE); - else - RelieveWindow(t,t->right_w[i],0,0, - t->title_height, t->title_height, - (inverted ? ShadowGC : ReliefGC), - (inverted ? ReliefGC : ShadowGC), - BOTTOM_HILITE); + DrawButton(t, t->right_w[i], + t->title_height, + t->title_height, bf, + ReliefGC, ShadowGC, + inverted, + GetDecor(t, right_buttons[i] + .flags)); + + if (!(GetDecor(t, right_buttons[i] + .state[bs] + .style) & + FlatButton)) { + if (GetDecor(t, right_buttons[i] + .state[bs] + .style) & + SunkButton) + RelieveWindow(t, + t->right_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ReliefGC : + ShadowGC), + (inverted ? + ShadowGC : + ReliefGC), + BOTTOM_HILITE); + else + RelieveWindow(t, + t->right_w[i], 0, 0, + t->title_height, + t->title_height, + (inverted ? + ShadowGC : + ReliefGC), + (inverted ? + ReliefGC : + ShadowGC), + BOTTOM_HILITE); + } + } + } } - } + SetTitleBar(t, onoroff, False); } - } - SetTitleBar(t,onoroff, False); - - } - if(t->flags & BORDER) - { - /* draw relief lines */ - y= t->frame_height - 2*t->corner_width; - x = t->frame_width- 2*t->corner_width +t->bw; + if (t->flags & BORDER) { + /* draw relief lines */ + y = t->frame_height - 2 * t->corner_width; + x = t->frame_width - 2 * t->corner_width + t->bw; - for(i=0;i<4;i++) - { - int vertical = i % 2; + for (i = 0; i < 4; i++) { + int vertical = i % 2; #ifdef BORDERSTYLE - int flags = onoroff - ? GetDecor(t,BorderStyle.active.style) - : GetDecor(t,BorderStyle.inactive.style); + int flags = + onoroff ? GetDecor(t, BorderStyle.active.style) : + GetDecor(t, BorderStyle.inactive.style); #endif /* BORDERSTYLE */ - ChangeWindowColor(t->sides[i],valuemask); - if((flush_expose (t->sides[i]))||(expose_win == t->sides[i])|| - (expose_win == None)) - { - GC sgc,rgc; - - sgc=ShadowGC; - rgc=ReliefGC; - if(!(t->flags & MWMButtons)&&(PressedW == t->sides[i])) - { - sgc = ReliefGC; - rgc = ShadowGC; - } - /* index side - * 0 TOP - * 1 RIGHT - * 2 BOTTOM - * 3 LEFT - */ + ChangeWindowColor(t->sides[i], valuemask); + if ((flush_expose(t->sides[i])) || + (expose_win == t->sides[i]) || + (expose_win == None)) { + GC sgc, rgc; + + sgc = ShadowGC; + rgc = ReliefGC; + if (!(t->flags & MWMButtons) && + (PressedW == t->sides[i])) { + sgc = ReliefGC; + rgc = ShadowGC; + } + /* index side + * 0 TOP + * 1 RIGHT + * 2 BOTTOM + * 3 LEFT + */ #ifdef BORDERSTYLE - if (flags&HiddenHandles) { - if (flags&NoInset) - RelieveWindowHH(t,t->sides[i],0,0, - ((vertical)?t->boundary_width:x), - ((vertical)?y:t->boundary_width), - rgc, sgc, vertical - ? (i == 3 ? LEFT_HILITE : RIGHT_HILITE) - : (i ? BOTTOM_HILITE : TOP_HILITE), - (0x0001<sides[i],0,0, - ((vertical)?t->boundary_width:x), - ((vertical)?y:t->boundary_width), - rgc, sgc, vertical - ? (LEFT_HILITE|RIGHT_HILITE) - : (TOP_HILITE|BOTTOM_HILITE), - (0x0001<sides[i], + 0, 0, + ((vertical) ? + t->boundary_width : + x), + ((vertical) ? + y : + t->boundary_width), + rgc, sgc, + vertical ? + (i == 3 ? LEFT_HILITE : + RIGHT_HILITE) : + (i ? BOTTOM_HILITE : + TOP_HILITE), + (0x0001 << i)); + else + RelieveWindowHH(t, t->sides[i], + 0, 0, + ((vertical) ? + t->boundary_width : + x), + ((vertical) ? + y : + t->boundary_width), + rgc, sgc, + vertical ? + (LEFT_HILITE | + RIGHT_HILITE) : + (TOP_HILITE | + BOTTOM_HILITE), + (0x0001 << i)); + } else #endif /* BORDERSTYLE */ - RelieveWindow(t,t->sides[i],0,0, - ((i%2)?t->boundary_width:x), - ((i%2)?y:t->boundary_width), - rgc, sgc, (0x0001<corners[i],valuemask); - if((flush_expose(t->corners[i]))||(expose_win==t->corners[i])|| - (expose_win == None)) - { - GC rgc,sgc; - - rgc = ReliefGC; - sgc = ShadowGC; - if(!(t->flags & MWMButtons)&&(PressedW == t->corners[i])) - { - sgc = ReliefGC; - rgc = ShadowGC; - } + RelieveWindow(t, t->sides[i], 0, 0, + ((i % 2) ? t->boundary_width : x), + ((i % 2) ? y : t->boundary_width), + rgc, sgc, (0x0001 << i)); + } + ChangeWindowColor(t->corners[i], valuemask); + if ((flush_expose(t->corners[i])) || + (expose_win == t->corners[i]) || + (expose_win == None)) { + GC rgc, sgc; + + rgc = ReliefGC; + sgc = ShadowGC; + if (!(t->flags & MWMButtons) && + (PressedW == t->corners[i])) { + sgc = ReliefGC; + rgc = ShadowGC; + } #ifdef BORDERSTYLE - if (flags&HiddenHandles) { - RelieveWindowHH(t,t->corners[i],0,0,t->corner_width, - ((i/2)?t->corner_width+t->bw:t->corner_width), - rgc,sgc, corners[i], corners[i]); - - if (!(flags&NoInset)) { - if (t->boundary_width > 1) - RelieveParts(t,i|HH_HILITE, - ((i/2)?rgc:sgc),(vertical?rgc:sgc)); - else - RelieveParts(t,i|HH_HILITE, - ((i/2)?sgc:sgc),(vertical?sgc:sgc)); - } - } else { + if (flags & HiddenHandles) { + RelieveWindowHH(t, t->corners[i], 0, 0, + t->corner_width, + ((i / 2) ? t->corner_width + t->bw : + t->corner_width), + rgc, sgc, corners[i], corners[i]); + + if (!(flags & NoInset)) { + if (t->boundary_width > 1) + RelieveParts(t, + i | HH_HILITE, + ((i / 2) ? rgc : + sgc), + (vertical ? rgc : + sgc)); + else + RelieveParts(t, + i | HH_HILITE, + ((i / 2) ? sgc : + sgc), + (vertical ? sgc : + sgc)); + } + } else { #endif /* ! BORDERSTYLE */ - RelieveWindow(t,t->corners[i],0,0,t->corner_width, - ((i/2)?t->corner_width+t->bw:t->corner_width), - rgc,sgc, corners[i]); - - if(t->boundary_width > 1) - RelieveParts(t,i,((i/2)?rgc:sgc),(vertical?rgc:sgc)); - else - RelieveParts(t,i,((i/2)?sgc:sgc),(vertical?sgc:sgc)); + RelieveWindow(t, t->corners[i], 0, 0, + t->corner_width, + ((i / 2) ? t->corner_width + t->bw : + t->corner_width), + rgc, sgc, corners[i]); + + if (t->boundary_width > 1) + RelieveParts(t, i, + ((i / 2) ? rgc : sgc), + (vertical ? rgc : sgc)); + else + RelieveParts(t, i, + ((i / 2) ? sgc : sgc), + (vertical ? sgc : sgc)); #ifdef BORDERSTYLE - } + } #endif - } - } - } - else /* no decorative border */ - { - /* for mono - put a black border on - * for color, make it the color of the decoration background */ - if(t->boundary_width < 2) - { - flush_expose (t->frame); - if(Scr.d_depth <2) - { - XSetWindowBorder(dpy,t->frame,TextColor); - XSetWindowBorder(dpy,t->Parent,TextColor); - XSetWindowBackgroundPixmap(dpy,t->frame,BackPixmap); - XClearWindow(dpy,t->frame); - XSetWindowBackgroundPixmap(dpy,t->Parent,BackPixmap); - XClearWindow(dpy,t->Parent); - } - else - { + } + } + } else /* no decorative border */ { + /* for mono - put a black border on + * for color, make it the color of the decoration background */ + if (t->boundary_width < 2) { + flush_expose(t->frame); + if (Scr.d_depth < 2) { + XSetWindowBorder(dpy, t->frame, TextColor); + XSetWindowBorder(dpy, t->Parent, TextColor); + XSetWindowBackgroundPixmap( + dpy, t->frame, BackPixmap); + XClearWindow(dpy, t->frame); + XSetWindowBackgroundPixmap( + dpy, t->Parent, BackPixmap); + XClearWindow(dpy, t->Parent); + } else { #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - XSetWindowBackgroundPixmap(dpy,t->frame,TexturePixmap); + XSetWindowBackgroundPixmap( + dpy, t->frame, TexturePixmap); #endif - XSetWindowBorder(dpy,t->frame,BorderColor); - XClearWindow(dpy,t->frame); - XSetWindowBackground(dpy,t->Parent,BorderColor); - XSetWindowBorder(dpy,t->Parent,BorderColor); - XClearWindow(dpy,t->Parent); - XSetWindowBorder(dpy,t->w,BorderColor); - } - } - else - { - GC rgc,sgc; - - XSetWindowBorder(dpy,t->Parent,BorderColor); - XSetWindowBorder(dpy,t->frame,BorderColor); - - rgc=ReliefGC; - sgc=ShadowGC; - if(!(t->flags & MWMButtons)&&(PressedW == t->frame)) - { - sgc=ReliefGC; - rgc=ShadowGC; - } - ChangeWindowColor(t->frame, valuemask); - if((flush_expose(t->frame))||(expose_win == t->frame)|| - (expose_win == None)) - { - if(t->boundary_width > 2) - { - RelieveWindow(t,t->frame,t->boundary_width-1 - t->bw, - t->boundary_width-1-t->bw, - t->frame_width- - (t->boundary_width<<1)+2+3*t->bw, - t->frame_height- - (t->boundary_width<<1)+2+3*t->bw, - sgc,rgc, - TOP_HILITE|LEFT_HILITE|RIGHT_HILITE| - BOTTOM_HILITE); - RelieveWindow(t,t->frame,0,0,t->frame_width+t->bw, - t->frame_height+t->bw,rgc,sgc, - TOP_HILITE|LEFT_HILITE|RIGHT_HILITE| - BOTTOM_HILITE); - } - else - { - RelieveWindow(t,t->frame,0,0,t->frame_width+t->bw, - t->frame_height+t->bw,rgc,rgc, - TOP_HILITE|LEFT_HILITE|RIGHT_HILITE| - BOTTOM_HILITE); - } - } - else - { - XSetWindowBackground(dpy,t->Parent,BorderColor); - } - } - } - /* Sync to make the border-color change look fast! */ - XSync(dpy,0); - + XSetWindowBorder(dpy, t->frame, BorderColor); + XClearWindow(dpy, t->frame); + XSetWindowBackground( + dpy, t->Parent, BorderColor); + XSetWindowBorder(dpy, t->Parent, BorderColor); + XClearWindow(dpy, t->Parent); + XSetWindowBorder(dpy, t->w, BorderColor); + } + } else { + GC rgc, sgc; + + XSetWindowBorder(dpy, t->Parent, BorderColor); + XSetWindowBorder(dpy, t->frame, BorderColor); + + rgc = ReliefGC; + sgc = ShadowGC; + if (!(t->flags & MWMButtons) && + (PressedW == t->frame)) { + sgc = ReliefGC; + rgc = ShadowGC; + } + ChangeWindowColor(t->frame, valuemask); + if ((flush_expose(t->frame)) || + (expose_win == t->frame) || (expose_win == None)) { + if (t->boundary_width > 2) { + RelieveWindow(t, t->frame, + t->boundary_width - 1 - t->bw, + t->boundary_width - 1 - t->bw, + t->frame_width - + (t->boundary_width << 1) + 2 + + 3 * t->bw, + t->frame_height - + (t->boundary_width << 1) + 2 + + 3 * t->bw, + sgc, rgc, + TOP_HILITE | LEFT_HILITE | + RIGHT_HILITE | BOTTOM_HILITE); + RelieveWindow(t, t->frame, 0, 0, + t->frame_width + t->bw, + t->frame_height + t->bw, rgc, sgc, + TOP_HILITE | LEFT_HILITE | + RIGHT_HILITE | BOTTOM_HILITE); + } else { + RelieveWindow(t, t->frame, 0, 0, + t->frame_width + t->bw, + t->frame_height + t->bw, rgc, rgc, + TOP_HILITE | LEFT_HILITE | + RIGHT_HILITE | BOTTOM_HILITE); + } + } else { + XSetWindowBackground( + dpy, t->Parent, BorderColor); + } + } + } + /* Sync to make the border-color change look fast! */ + XSync(dpy, 0); } /**************************************************************************** @@ -559,144 +618,145 @@ void SetBorder (FvwmWindow *t, Bool onoroff,Bool force,Bool Mapped, * Redraws buttons (veliaa@rpi.edu) * ****************************************************************************/ -void DrawButton(FvwmWindow *t, Window win, int w, int h, - ButtonFace *bf, GC ReliefGC, GC ShadowGC, - Boolean inverted, int stateflags) +void +DrawButton(FvwmWindow *t, Window win, int w, int h, ButtonFace *bf, GC ReliefGC, + GC ShadowGC, Boolean inverted, int stateflags) { - register int type = bf->style & ButtonFaceTypeMask; + register int type = bf->style & ButtonFaceTypeMask; #ifdef PIXMAP_BUTTONS - FvwmPicture *p; - int border = 0; - int width, height, x, y; + FvwmPicture *p; + int border = 0; + int width, height, x, y; #endif - switch (type) - { - case SimpleButton: - break; + switch (type) { + case SimpleButton: + break; - case SolidButton: - XSetWindowBackground(dpy, win, bf->u.back); - flush_expose(win); - XClearWindow(dpy,win); - break; + case SolidButton: + XSetWindowBackground(dpy, win, bf->u.back); + flush_expose(win); + XClearWindow(dpy, win); + break; #ifdef VECTOR_BUTTONS - case VectorButton: - if((t->flags & MWMButtons) - && (stateflags & MWMDecorMaximize) - && (t->flags & MAXIMIZED)) - DrawLinePattern(win, - ShadowGC, ReliefGC, - &bf->vector, - w, h); - else - DrawLinePattern(win, - ReliefGC, ShadowGC, - &bf->vector, - w, h); - break; + case VectorButton: + if ((t->flags & MWMButtons) && + (stateflags & MWMDecorMaximize) && (t->flags & MAXIMIZED)) + DrawLinePattern( + win, ShadowGC, ReliefGC, &bf->vector, w, h); + else + DrawLinePattern( + win, ReliefGC, ShadowGC, &bf->vector, w, h); + break; #endif /* VECTOR_BUTTONS */ #ifdef PIXMAP_BUTTONS #ifdef MINI_ICONS - case MiniIconButton: - case PixmapButton: - if (type == PixmapButton) - p = bf->u.p; - else { - if (!t->mini_icon) - break; - p = t->mini_icon; - } + case MiniIconButton: + case PixmapButton: + if (type == PixmapButton) + p = bf->u.p; + else { + if (!t->mini_icon) + break; + p = t->mini_icon; + } #else - case PixmapButton: - p = bf->u.p; + case PixmapButton: + p = bf->u.p; #endif /* MINI_ICONS */ - if (bf->style & FlatButton) - border = 0; - else - border = t->flags & MWMBorders ? 1 : 2; - width = w - border * 2; height = h - border * 2; - - x = border; - if (bf->style&HOffCenter) { - if (bf->style&HRight) - x += (int)(width - p->width); - } else - x += (int)(width - p->width) / 2; + if (bf->style & FlatButton) + border = 0; + else + border = t->flags & MWMBorders ? 1 : 2; + width = w - border * 2; + height = h - border * 2; + + x = border; + if (bf->style & HOffCenter) { + if (bf->style & HRight) + x += (int)(width - p->width); + } else + x += (int)(width - p->width) / 2; + + y = border; + if (bf->style & VOffCenter) { + if (bf->style & VBottom) + y += (int)(height - p->height); + } else + y += (int)(height - p->height) / 2; + + if (x < border) + x = border; + if (y < border) + y = border; + if (width > p->width) + width = p->width; + if (height > p->height) + height = p->height; + if (width > w - x - border) + width = w - x - border; + if (height > h - y - border) + height = h - y - border; + + XSetClipMask(dpy, Scr.TransMaskGC, p->mask); + XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); + XCopyArea(dpy, p->picture, win, Scr.TransMaskGC, 0, 0, width, + height, x, y); + break; - y = border; - if (bf->style&VOffCenter) { - if (bf->style&VBottom) - y += (int)(height - p->height); - } else - y += (int)(height - p->height) / 2; - - if (x < border) x = border; - if (y < border) y = border; - if (width > p->width) width = p->width; - if (height > p->height) height = p->height; - if (width > w - x - border) width = w - x - border; - if (height > h - y - border) height = h - y - border; - - XSetClipMask(dpy, Scr.TransMaskGC, p->mask); - XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); - XCopyArea(dpy, p->picture, win, Scr.TransMaskGC, - 0, 0, width, height, x, y); - break; - - case TiledPixmapButton: - XSetWindowBackgroundPixmap(dpy, win, bf->u.p->picture); - flush_expose(win); - XClearWindow(dpy,win); - break; + case TiledPixmapButton: + XSetWindowBackgroundPixmap(dpy, win, bf->u.p->picture); + flush_expose(win); + XClearWindow(dpy, win); + break; #endif /* PIXMAP_BUTTONS */ #ifdef GRADIENT_BUTTONS - case HGradButton: - case VGradButton: - { - XRectangle bounds; - bounds.x = bounds.y = 0; - bounds.width = w; - bounds.height = h; - flush_expose(win); + case HGradButton: + case VGradButton: { + XRectangle bounds; + bounds.x = bounds.y = 0; + bounds.width = w; + bounds.height = h; + flush_expose(win); #ifdef PIXMAP_BUTTONS - XSetClipMask(dpy, Scr.TransMaskGC, None); + XSetClipMask(dpy, Scr.TransMaskGC, None); #endif - if (type == HGradButton) { - register int i = 0, dw = bounds.width - / bf->u.grad.npixels + 1; - while (i < bf->u.grad.npixels) - { - unsigned short x = i * bounds.width / bf->u.grad.npixels; - XSetForeground(dpy, Scr.TransMaskGC, bf->u.grad.pixels[ i++ ]); - XFillRectangle(dpy, win, Scr.TransMaskGC, - bounds.x + x, bounds.y, - dw, bounds.height); - } - } else { - register int i = 0, dh = bounds.height - / bf->u.grad.npixels + 1; - while (i < bf->u.grad.npixels) - { - unsigned short y = i * bounds.height / bf->u.grad.npixels; - XSetForeground(dpy, Scr.TransMaskGC, bf->u.grad.pixels[ i++ ]); - XFillRectangle(dpy, win, Scr.TransMaskGC, - bounds.x, bounds.y + y, - bounds.width, dh); - } + if (type == HGradButton) { + register int i = 0, + dw = bounds.width / bf->u.grad.npixels + 1; + while (i < bf->u.grad.npixels) { + unsigned short x = + i * bounds.width / bf->u.grad.npixels; + XSetForeground(dpy, Scr.TransMaskGC, + bf->u.grad.pixels[i++]); + XFillRectangle(dpy, win, Scr.TransMaskGC, + bounds.x + x, bounds.y, dw, bounds.height); + } + } else { + register int i = 0, + dh = + bounds.height / bf->u.grad.npixels + 1; + while (i < bf->u.grad.npixels) { + unsigned short y = + i * bounds.height / bf->u.grad.npixels; + XSetForeground(dpy, Scr.TransMaskGC, + bf->u.grad.pixels[i++]); + XFillRectangle(dpy, win, Scr.TransMaskGC, + bounds.x, bounds.y + y, bounds.width, dh); + } + } } - } - break; + break; #endif /* GRADIENT_BUTTONS */ - default: - fvwm_msg(ERR,"DrawButton","unknown button type"); - break; - } + default: + fvwm_msg(ERR, "DrawButton", "unknown button type"); + break; + } } /**************************************************************************** @@ -704,252 +764,270 @@ void DrawButton(FvwmWindow *t, Window win, int w, int h, * Redraws just the title bar * ****************************************************************************/ -void SetTitleBar (FvwmWindow *t,Bool onoroff, Bool NewTitle) +void +SetTitleBar(FvwmWindow *t, Bool onoroff, Bool NewTitle) { - int hor_off, w, i; - enum ButtonState title_state; - ButtonFaceStyle tb_style; - int tb_flags; - GC ReliefGC, ShadowGC, tGC; - Pixel Forecolor, BackColor; - - if(!t) - return; - if(!(t->flags & TITLE)) - return; - - if (onoroff) - { - Forecolor = GetDecor(t,HiColors.fore); - BackColor = GetDecor(t,HiColors.back); - ReliefGC = GetDecor(t,HiReliefGC); - ShadowGC = GetDecor(t,HiShadowGC); - } - else - { - Forecolor =t->TextPixel; - BackColor = t->BackPixel; - Globalgcv.foreground = t->ReliefPixel; - Globalgcm = GCForeground; - XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); - ReliefGC = Scr.ScratchGC1; - - Globalgcv.foreground = t->ShadowPixel; - XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); - ShadowGC = Scr.ScratchGC2; - } - if(PressedW==t->title_w) - { - tGC = ShadowGC; - ShadowGC = ReliefGC; - ReliefGC = tGC; - } - flush_expose(t->title_w); - - if(t->name != (char *)NULL) - { - w=XTextWidth(GetDecor(t,WindowFont.font),t->name,strlen(t->name)); - if(w > t->title_width-12) - w = t->title_width-4; - if(w < 0) - w = 0; - } - else - w = 0; - - title_state = GetButtonState(t->title_w); - tb_style = GetDecor(t,titlebar.state[title_state].style); - tb_flags = GetDecor(t,titlebar.flags); - if (tb_flags & HOffCenter) { - if (tb_flags & HRight) - hor_off = t->title_width - w - 10; - else - hor_off = 10; - } else - hor_off = (t->title_width - w) / 2; - - NewFontAndColor(GetDecor(t,WindowFont.font->fid),Forecolor, BackColor); - - /* the next bit tries to minimize redraw based upon compilation options (veliaa@rpi.edu) */ + int hor_off, w, i; + enum ButtonState title_state; + ButtonFaceStyle tb_style; + int tb_flags; + GC ReliefGC, ShadowGC, tGC; + Pixel Forecolor, BackColor; + + if (!t) + return; + if (!(t->flags & TITLE)) + return; + + if (onoroff) { + Forecolor = GetDecor(t, HiColors.fore); + BackColor = GetDecor(t, HiColors.back); + ReliefGC = GetDecor(t, HiReliefGC); + ShadowGC = GetDecor(t, HiShadowGC); + } else { + Forecolor = t->TextPixel; + BackColor = t->BackPixel; + Globalgcv.foreground = t->ReliefPixel; + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + ReliefGC = Scr.ScratchGC1; + + Globalgcv.foreground = t->ShadowPixel; + XChangeGC(dpy, Scr.ScratchGC2, Globalgcm, &Globalgcv); + ShadowGC = Scr.ScratchGC2; + } + if (PressedW == t->title_w) { + tGC = ShadowGC; + ShadowGC = ReliefGC; + ReliefGC = tGC; + } + flush_expose(t->title_w); + + if (t->name != (char *)NULL) { + w = XTextWidth( + GetDecor(t, WindowFont.font), t->name, strlen(t->name)); + if (w > t->title_width - 12) + w = t->title_width - 4; + if (w < 0) + w = 0; + } else + w = 0; + + title_state = GetButtonState(t->title_w); + tb_style = GetDecor(t, titlebar.state[title_state].style); + tb_flags = GetDecor(t, titlebar.flags); + if (tb_flags & HOffCenter) { + if (tb_flags & HRight) + hor_off = t->title_width - w - 10; + else + hor_off = 10; + } else + hor_off = (t->title_width - w) / 2; + + NewFontAndColor( + GetDecor(t, WindowFont.font->fid), Forecolor, BackColor); + + /* the next bit tries to minimize redraw based upon compilation options + * (veliaa@rpi.edu) */ #ifdef EXTENDED_TITLESTYLE #if defined(PIXMAP_BUTTONS) && defined(BORDERSTYLE) - /* we need to check for UseBorderStyle for the titlebar */ - { - ButtonFace *bf = onoroff - ? &GetDecor(t,BorderStyle.active) - : &GetDecor(t,BorderStyle.inactive); - - if ((tb_style & UseBorderStyle) - && ((bf->style & ButtonFaceTypeMask) == TiledPixmapButton)) - XSetWindowBackgroundPixmap(dpy,t->title_w,bf->u.p->picture); - } + /* we need to check for UseBorderStyle for the titlebar */ + { + ButtonFace *bf = onoroff ? &GetDecor(t, BorderStyle.active) : + &GetDecor(t, BorderStyle.inactive); + + if ((tb_style & UseBorderStyle) && + ((bf->style & ButtonFaceTypeMask) == TiledPixmapButton)) + XSetWindowBackgroundPixmap( + dpy, t->title_w, bf->u.p->picture); + } #endif /* PIXMAP_BUTTONS && BORDERSTYLE */ - XClearWindow(dpy,t->title_w); -#else /* ! EXTENDED_TITLESTYLE */ - /* if no extended titlestyle, only clear when necessary */ - if (NewTitle) - XClearWindow(dpy,t->title_w); + XClearWindow(dpy, t->title_w); +#else /* ! EXTENDED_TITLESTYLE */ + /* if no extended titlestyle, only clear when necessary */ + if (NewTitle) + XClearWindow(dpy, t->title_w); #endif /* EXTENDED_TITLESTYLE */ - /* for mono, we clear an area in the title bar where the window - * title goes, so that its more legible. For color, no need */ - if(Scr.d_depth<2) - { - RelieveWindow(t,t->title_w,0,0,hor_off-2,t->title_height, - ReliefGC, ShadowGC, BOTTOM_HILITE); - RelieveWindow(t,t->title_w,hor_off+w+2,0, - t->title_width - w - hor_off-2,t->title_height, - ReliefGC, ShadowGC, BOTTOM_HILITE); - XFillRectangle(dpy,t->title_w, - (PressedW==t->title_w?ShadowGC:ReliefGC), - hor_off - 2, 0, w+4,t->title_height); - - XDrawLine(dpy,t->title_w,ShadowGC,hor_off+w+1,0,hor_off+w+1, - t->title_height); - if(t->name != (char *)NULL) - XDrawString (dpy, t->title_w,Scr.ScratchGC3,hor_off, - GetDecor(t,WindowFont.y)+1, - t->name, strlen(t->name)); - } - else - { + /* for mono, we clear an area in the title bar where the window + * title goes, so that its more legible. For color, no need */ + if (Scr.d_depth < 2) { + RelieveWindow(t, t->title_w, 0, 0, hor_off - 2, t->title_height, + ReliefGC, ShadowGC, BOTTOM_HILITE); + RelieveWindow(t, t->title_w, hor_off + w + 2, 0, + t->title_width - w - hor_off - 2, t->title_height, ReliefGC, + ShadowGC, BOTTOM_HILITE); + XFillRectangle(dpy, t->title_w, + (PressedW == t->title_w ? ShadowGC : ReliefGC), hor_off - 2, + 0, w + 4, t->title_height); + + XDrawLine(dpy, t->title_w, ShadowGC, hor_off + w + 1, 0, + hor_off + w + 1, t->title_height); + if (t->name != (char *)NULL) + XDrawString(dpy, t->title_w, Scr.ScratchGC3, hor_off, + GetDecor(t, WindowFont.y) + 1, t->name, + strlen(t->name)); + } else { #ifdef EXTENDED_TITLESTYLE - ButtonFace *bf = &GetDecor(t,titlebar.state[title_state]); - /* draw compound titlebar (veliaa@rpi.edu) */ - if (PressedW == t->title_w) { + ButtonFace *bf = &GetDecor(t, titlebar.state[title_state]); + /* draw compound titlebar (veliaa@rpi.edu) */ + if (PressedW == t->title_w) { #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->title_w, t->title_width, t->title_height, - bf, ShadowGC, ReliefGC, True, 0); - } else { + DrawButton(t, t->title_w, t->title_width, + t->title_height, bf, ShadowGC, ReliefGC, + True, 0); + } else { #ifdef MULTISTYLE - for (; bf; bf = bf->next) + for (; bf; bf = bf->next) #endif - DrawButton(t, t->title_w, t->title_width, t->title_height, - bf, ReliefGC, ShadowGC, False, 0); - } + DrawButton(t, t->title_w, t->title_width, + t->title_height, bf, ReliefGC, ShadowGC, + False, 0); + } #endif /* EXTENDED_TITLESTYLE */ - if (!(tb_style & FlatButton)) { - if (tb_style & SunkButton) - RelieveWindow(t,t->title_w,0,0,t->title_width,t->title_height, - ShadowGC, ReliefGC, BOTTOM_HILITE); - else - RelieveWindow(t,t->title_w,0,0,t->title_width,t->title_height, - ReliefGC, ShadowGC, BOTTOM_HILITE); - } - - if(t->name != (char *)NULL) - XDrawString (dpy, t->title_w,Scr.ScratchGC3,hor_off, - GetDecor(t,WindowFont.y)+1, - t->name, strlen(t->name)); - } - /* now, draw lines in title bar if it's a sticky window */ - if(t->flags & STICKY || Scr.StipledTitles) - { - for(i=0 ;i< t->title_height/2-3;i+=4) - { - XDrawLine(dpy,t->title_w,ShadowGC,4,t->title_height/2 - i-1, - hor_off-6,t->title_height/2-i-1); - XDrawLine(dpy,t->title_w,ShadowGC,6+hor_off+w,t->title_height/2 -i-1, - t->title_width-5,t->title_height/2- i-1); - XDrawLine(dpy,t->title_w,ReliefGC,4,t->title_height/2 - i, - hor_off-6,t->title_height/2 - i); - XDrawLine(dpy,t->title_w,ReliefGC,6+hor_off+w,t->title_height/2-i, - t->title_width-5,t->title_height/2 - i); - - XDrawLine(dpy,t->title_w,ShadowGC,4,t->title_height/2 + i-1, - hor_off-6,t->title_height/2+i-1); - XDrawLine(dpy,t->title_w,ShadowGC,6+hor_off+w,t->title_height/2+i-1, - t->title_width-5,t->title_height/2 + i-1); - XDrawLine(dpy,t->title_w,ReliefGC,4,t->title_height/2 + i, - hor_off-6,t->title_height/2 + i); - XDrawLine(dpy,t->title_w,ReliefGC,6+hor_off+w,t->title_height/2+i, - t->title_width-5,t->title_height/2 + i); - } - } - - - XFlush(dpy); -} - + if (!(tb_style & FlatButton)) { + if (tb_style & SunkButton) + RelieveWindow(t, t->title_w, 0, 0, + t->title_width, t->title_height, ShadowGC, + ReliefGC, BOTTOM_HILITE); + else + RelieveWindow(t, t->title_w, 0, 0, + t->title_width, t->title_height, ReliefGC, + ShadowGC, BOTTOM_HILITE); + } + if (t->name != (char *)NULL) + XDrawString(dpy, t->title_w, Scr.ScratchGC3, hor_off, + GetDecor(t, WindowFont.y) + 1, t->name, + strlen(t->name)); + } + /* now, draw lines in title bar if it's a sticky window */ + if (t->flags & STICKY || Scr.StipledTitles) { + for (i = 0; i < t->title_height / 2 - 3; i += 4) { + XDrawLine(dpy, t->title_w, ShadowGC, 4, + t->title_height / 2 - i - 1, hor_off - 6, + t->title_height / 2 - i - 1); + XDrawLine(dpy, t->title_w, ShadowGC, 6 + hor_off + w, + t->title_height / 2 - i - 1, t->title_width - 5, + t->title_height / 2 - i - 1); + XDrawLine(dpy, t->title_w, ReliefGC, 4, + t->title_height / 2 - i, hor_off - 6, + t->title_height / 2 - i); + XDrawLine(dpy, t->title_w, ReliefGC, 6 + hor_off + w, + t->title_height / 2 - i, t->title_width - 5, + t->title_height / 2 - i); + + XDrawLine(dpy, t->title_w, ShadowGC, 4, + t->title_height / 2 + i - 1, hor_off - 6, + t->title_height / 2 + i - 1); + XDrawLine(dpy, t->title_w, ShadowGC, 6 + hor_off + w, + t->title_height / 2 + i - 1, t->title_width - 5, + t->title_height / 2 + i - 1); + XDrawLine(dpy, t->title_w, ReliefGC, 4, + t->title_height / 2 + i, hor_off - 6, + t->title_height / 2 + i); + XDrawLine(dpy, t->title_w, ReliefGC, 6 + hor_off + w, + t->title_height / 2 + i, t->title_width - 5, + t->title_height / 2 + i); + } + } + XFlush(dpy); +} /**************************************************************************** * * Draws the relief pattern around a window * ****************************************************************************/ -void RelieveWindow(FvwmWindow *t,Window win, int x,int y,int w,int h, - GC ReliefGC, GC ShadowGC, int hilite) +void +RelieveWindow(FvwmWindow *t, Window win, int x, int y, int w, int h, + GC ReliefGC, GC ShadowGC, int hilite) { - XSegment seg[4]; - int i; - int edge; - - edge = 0; - if((win == t->sides[0])||(win == t->sides[1])|| - (win == t->sides[2])||(win == t->sides[3])) - edge = -1; - if(win == t->corners[0]) - edge = 1; - if(win == t->corners[1]) - edge = 2; - if(win == t->corners[2]) - edge = 3; - if(win == t->corners[3]) - edge = 4; - - i=0; - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; - - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & TOP_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+1; - } - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & LEFT_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+1; - seg[i].x2 = x+1; seg[i++].y2 = y+h-2; - } - XDrawSegments(dpy, win, ReliefGC, seg, i); - - i=0; - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & BOTTOM_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+h-2; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - } - - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & RIGHT_HILITE)))) - { - seg[i].x1 = x+w-2; seg[i].y1 = y+1; - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-2; - } - XDrawSegments(dpy, win, ShadowGC, seg, i); + XSegment seg[4]; + int i; + int edge; + + edge = 0; + if ((win == t->sides[0]) || (win == t->sides[1]) || + (win == t->sides[2]) || (win == t->sides[3])) + edge = -1; + if (win == t->corners[0]) + edge = 1; + if (win == t->corners[1]) + edge = 2; + if (win == t->corners[2]) + edge = 3; + if (win == t->corners[3]) + edge = 4; + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & TOP_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + 1; + } + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & LEFT_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + 1; + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 2; + } + XDrawSegments(dpy, win, ReliefGC, seg, i); + + i = 0; + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & BOTTOM_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + } + + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & RIGHT_HILITE)))) { + seg[i].x1 = x + w - 2; + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 2; + } + XDrawSegments(dpy, win, ShadowGC, seg, i); } #ifdef BORDERSTYLE @@ -960,296 +1038,311 @@ void RelieveWindow(FvwmWindow *t,Window win, int x,int y,int w,int h, * (veliaa@rpi.edu) * ****************************************************************************/ -void RelieveWindowHH(FvwmWindow *t,Window win, int x,int y,int w,int h, - GC ReliefGC, GC ShadowGC, int draw, int hilite) +void +RelieveWindowHH(FvwmWindow *t, Window win, int x, int y, int w, int h, + GC ReliefGC, GC ShadowGC, int draw, int hilite) { - XSegment seg[4]; - int i = 0; - int edge = 0, a = 0, b = 0; - - if(win == t->sides[0]) { - edge = 5; - b = 1; - } - else if (win == t->sides[1]) { - a = 1; - edge = 6; - } - else if (win == t->sides[2]) { - edge = 7; - b = 1; - } - else if (win == t->sides[3]) { - edge = 8; - a = 1; - } else if (win == t->corners[0]) - edge = 1; - else if (win == t->corners[1]) - edge = 2; - else if (win == t->corners[2]) - edge = 3; - else if (win == t->corners[3]) - edge = 4; - - if (draw & TOP_HILITE) { - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = w+x-1; seg[i++].y2 = y; - - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & TOP_HILITE)))) - { - seg[i].x1 = x+((edge == 2)|| b ? 0 : 1); seg[i].y1 = y+1; - seg[i].x2 = x+w-1-((edge == 1)|| b ? 0 : 1); seg[i++].y2 = y+1; + XSegment seg[4]; + int i = 0; + int edge = 0, a = 0, b = 0; + + if (win == t->sides[0]) { + edge = 5; + b = 1; + } else if (win == t->sides[1]) { + a = 1; + edge = 6; + } else if (win == t->sides[2]) { + edge = 7; + b = 1; + } else if (win == t->sides[3]) { + edge = 8; + a = 1; + } else if (win == t->corners[0]) + edge = 1; + else if (win == t->corners[1]) + edge = 2; + else if (win == t->corners[2]) + edge = 3; + else if (win == t->corners[3]) + edge = 4; + + if (draw & TOP_HILITE) { + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y; + + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & TOP_HILITE)))) { + seg[i].x1 = x + ((edge == 2) || b ? 0 : 1); + seg[i].y1 = y + 1; + seg[i].x2 = x + w - 1 - ((edge == 1) || b ? 0 : 1); + seg[i++].y2 = y + 1; + } } - } - - if (draw & LEFT_HILITE) { - seg[i].x1 = x; seg[i].y1 = y; - seg[i].x2 = x; seg[i++].y2 = h+y-1; - if(((t->boundary_width > 2)||(edge == 0))&& - ((t->boundary_width > 3)||(edge < 1))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & LEFT_HILITE)))) - { - seg[i].x1 = x+1; seg[i].y1 = y+((edge == 3)|| a ? 0 : 1); - seg[i].x2 = x+1; seg[i++].y2 = y+h-1-((edge == 1)|| a ? 0 : 1); + if (draw & LEFT_HILITE) { + seg[i].x1 = x; + seg[i].y1 = y; + seg[i].x2 = x; + seg[i++].y2 = h + y - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + ((t->boundary_width > 3) || (edge < 1)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & LEFT_HILITE)))) { + seg[i].x1 = x + 1; + seg[i].y1 = y + ((edge == 3) || a ? 0 : 1); + seg[i].x2 = x + 1; + seg[i++].y2 = y + h - 1 - ((edge == 1) || a ? 0 : 1); + } } - } - XDrawSegments(dpy, win, ReliefGC, seg, i); - - i=0; - - if (draw & BOTTOM_HILITE) { - seg[i].x1 = x; seg[i].y1 = y+h-1; - seg[i].x2 = w+x-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & BOTTOM_HILITE)))) - { - seg[i].x1 = x+(b ||(edge == 4) ? 0 : 1); seg[i].y1 = y+h-2; - seg[i].x2 = x+w-((edge == 3) ? 0 : 1); seg[i++].y2 = y+h-2; + XDrawSegments(dpy, win, ReliefGC, seg, i); + + i = 0; + + if (draw & BOTTOM_HILITE) { + seg[i].x1 = x; + seg[i].y1 = y + h - 1; + seg[i].x2 = w + x - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & BOTTOM_HILITE)))) { + seg[i].x1 = x + (b || (edge == 4) ? 0 : 1); + seg[i].y1 = y + h - 2; + seg[i].x2 = x + w - ((edge == 3) ? 0 : 1); + seg[i++].y2 = y + h - 2; + } } - } - if (draw & RIGHT_HILITE) { - seg[i].x1 = x+w-1; seg[i].y1 = y; - seg[i].x2 = x+w-1; seg[i++].y2 = y+h-1; - - if(((t->boundary_width > 2)||(edge == 0))&& - (!(t->flags & MWMBorders)|| - (((edge==0)||(t->boundary_width > 3))&&(hilite & RIGHT_HILITE)))) - { - seg[i].x1 = x+w-2; seg[i].y1 = y+(a ||(edge == 4) ? 0 : 1); - seg[i].x2 = x+w-2; seg[i++].y2 = y+h-1-((edge == 2)|| a ? 0 : 1); + if (draw & RIGHT_HILITE) { + seg[i].x1 = x + w - 1; + seg[i].y1 = y; + seg[i].x2 = x + w - 1; + seg[i++].y2 = y + h - 1; + + if (((t->boundary_width > 2) || (edge == 0)) && + (!(t->flags & MWMBorders) || + (((edge == 0) || (t->boundary_width > 3)) && + (hilite & RIGHT_HILITE)))) { + seg[i].x1 = x + w - 2; + seg[i].y1 = y + (a || (edge == 4) ? 0 : 1); + seg[i].x2 = x + w - 2; + seg[i++].y2 = y + h - 1 - ((edge == 2) || a ? 0 : 1); + } } - } - XDrawSegments(dpy, win, ShadowGC, seg, i); + XDrawSegments(dpy, win, ShadowGC, seg, i); } #endif /* BORDERSTYLE */ -void RelieveParts(FvwmWindow *t,int i,GC hor, GC vert) +void +RelieveParts(FvwmWindow *t, int i, GC hor, GC vert) { - XSegment seg[2]; - int n = 0, hh = i & HH_HILITE; - i &= FULL_HILITE; - - if((t->flags & MWMBorders)||(t->boundary_width < 3)) - { - switch(i) - { - case 0: - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->corner_width; - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->boundary_width-1; - n=1; - break; - case 1: - seg[0].x1 = 0; - seg[0].x2 = t->corner_width - t->boundary_width /* -1*/ ; - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->boundary_width-1; - n=1; - break; - case 2: - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->corner_width - (hh ? 1 : 2); - seg[0].y1 = t->corner_width - t->boundary_width+t->bw; - seg[0].y2 = t->corner_width - t->boundary_width+t->bw; - n=1; - break; - case 3: - seg[0].x1 = 0; - seg[0].x2 = t->corner_width - t->boundary_width; - seg[0].y1 = t->corner_width - t->boundary_width+t->bw; - seg[0].y2 = t->corner_width - t->boundary_width+t->bw; - n=1; - break; - } - XDrawSegments(dpy, t->corners[i], hor, seg, n); - switch(i) - { - case 0: - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->corner_width; - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->boundary_width-1; - n=1; - break; - case 1: - seg[0].y1 = t->boundary_width -1; - seg[0].y2 = t->corner_width - (hh ? 0 : 2); - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - break; - case 2: - seg[0].y1 = 0; - seg[0].y2 = t->corner_width - t->boundary_width; - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->boundary_width-1; - n=1; - break; - case 3: - seg[0].y1 = 0; - seg[0].y2 = t->corner_width - t->boundary_width + t->bw; - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - break; - } - XDrawSegments(dpy, t->corners[i], vert, seg, 1); - } - else - { - switch(i) - { - case 0: - seg[0].x1 = t->boundary_width-2; - seg[0].x2 = t->corner_width; - seg[0].y1 = t->boundary_width-2; - seg[0].y2 = t->boundary_width-2; - - seg[1].x1 = t->boundary_width-2; - seg[1].x2 = t->corner_width; - seg[1].y1 = t->boundary_width-1; - seg[1].y2 = t->boundary_width-1; - n=2; - break; - case 1: - seg[0].x1 = (hh ? 0 : 1); - seg[0].x2 = t->corner_width - t->boundary_width; - seg[0].y1 = t->boundary_width-2; - seg[0].y2 = t->boundary_width-2; - - seg[1].x1 = 0; - seg[1].x2 = t->corner_width - t->boundary_width-1; - seg[1].y1 = t->boundary_width-1; - seg[1].y2 = t->boundary_width-1; - n=2; - break; - case 2: - seg[0].x1 = t->boundary_width-1; - seg[0].x2 = t->corner_width - (hh ? 1 : 2); - seg[0].y1 = t->corner_width - t->boundary_width+1; - seg[0].y2 = t->corner_width - t->boundary_width+1; - n=1; - if(t->boundary_width > 3) - { - seg[1].x1 = t->boundary_width-2; - seg[1].x2 = t->corner_width - (hh ? 1 : 3); - seg[1].y1 = t->corner_width - t->boundary_width + 2; - seg[1].y2 = t->corner_width - t->boundary_width + 2; - n=2; - } - break; - case 3: - seg[0].x1 = 0; - seg[0].x2 = t->corner_width - t->boundary_width; - seg[0].y1 = t->corner_width - t->boundary_width+1; - seg[0].y2 = t->corner_width - t->boundary_width+1; - n=1; - if(t->boundary_width > 3) - { - seg[0].x2 = t->corner_width - t->boundary_width + 1; - - seg[1].x1 = 0; - seg[1].x2 = t->corner_width - t->boundary_width + 1; - seg[1].y1 = t->corner_width - t->boundary_width + 2; - seg[1].y2 = t->corner_width - t->boundary_width + 2; - n=2; - } - break; - } - XDrawSegments(dpy, t->corners[i], hor, seg, n); - switch(i) - { - case 0: - seg[0].y1 = t->boundary_width-2; - seg[0].y2 = t->corner_width; - seg[0].x1 = t->boundary_width-2; - seg[0].x2 = t->boundary_width-2; - - seg[1].y1 = t->boundary_width-2; - seg[1].y2 = t->corner_width; - seg[1].x1 = t->boundary_width-1; - seg[1].x2 = t->boundary_width-1; - n=2; - break; - case 1: - seg[0].y1 = t->boundary_width-1; - seg[0].y2 = t->corner_width - (hh ? 1 : 2); - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - if(t->boundary_width > 3) - { - seg[1].y1 = t->boundary_width-2; - seg[1].y2 = t->corner_width - (hh ? 1 : 3); - seg[1].x1 = t->corner_width - t->boundary_width+1; - seg[1].x2 = t->corner_width - t->boundary_width+1; - n=2; - } - break; - case 2: - seg[0].y1 = (hh ? 0 : 1); - seg[0].y2 = t->corner_width - t->boundary_width+1; - seg[0].x1 = t->boundary_width-2; - seg[0].x2 = t->boundary_width-2; - n=1; - - if(t->boundary_width > 3) - { - seg[1].y1 = 0; - seg[1].y2 = t->corner_width - t->boundary_width; - seg[1].x1 = t->boundary_width-1; - seg[1].x2 = t->boundary_width-1; - } - break; - case 3: - seg[0].y1 = 0; - seg[0].y2 = t->corner_width - t->boundary_width + 1; - seg[0].x1 = t->corner_width - t->boundary_width; - seg[0].x2 = t->corner_width - t->boundary_width; - n=1; - - if(t->boundary_width > 3) - { - seg[0].y2 = t->corner_width - t->boundary_width + 2; - seg[1].y1 = 0; - seg[1].y2 = t->corner_width - t->boundary_width + 2; - seg[1].x1 = t->corner_width - t->boundary_width + 1; - seg[1].x2 = t->corner_width - t->boundary_width + 1; - n=2; - } - break; - } - XDrawSegments(dpy, t->corners[i], vert, seg, n); - } + XSegment seg[2]; + int n = 0, hh = i & HH_HILITE; + i &= FULL_HILITE; + + if ((t->flags & MWMBorders) || (t->boundary_width < 3)) { + switch (i) { + case 0: + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->corner_width; + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->boundary_width - 1; + n = 1; + break; + case 1: + seg[0].x1 = 0; + seg[0].x2 = t->corner_width - t->boundary_width /* -1*/; + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->boundary_width - 1; + n = 1; + break; + case 2: + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->corner_width - (hh ? 1 : 2); + seg[0].y1 = t->corner_width - t->boundary_width + t->bw; + seg[0].y2 = t->corner_width - t->boundary_width + t->bw; + n = 1; + break; + case 3: + seg[0].x1 = 0; + seg[0].x2 = t->corner_width - t->boundary_width; + seg[0].y1 = t->corner_width - t->boundary_width + t->bw; + seg[0].y2 = t->corner_width - t->boundary_width + t->bw; + n = 1; + break; + } + XDrawSegments(dpy, t->corners[i], hor, seg, n); + switch (i) { + case 0: + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->corner_width; + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->boundary_width - 1; + n = 1; + break; + case 1: + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->corner_width - (hh ? 0 : 2); + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + break; + case 2: + seg[0].y1 = 0; + seg[0].y2 = t->corner_width - t->boundary_width; + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->boundary_width - 1; + n = 1; + break; + case 3: + seg[0].y1 = 0; + seg[0].y2 = t->corner_width - t->boundary_width + t->bw; + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + break; + } + XDrawSegments(dpy, t->corners[i], vert, seg, 1); + } else { + switch (i) { + case 0: + seg[0].x1 = t->boundary_width - 2; + seg[0].x2 = t->corner_width; + seg[0].y1 = t->boundary_width - 2; + seg[0].y2 = t->boundary_width - 2; + + seg[1].x1 = t->boundary_width - 2; + seg[1].x2 = t->corner_width; + seg[1].y1 = t->boundary_width - 1; + seg[1].y2 = t->boundary_width - 1; + n = 2; + break; + case 1: + seg[0].x1 = (hh ? 0 : 1); + seg[0].x2 = t->corner_width - t->boundary_width; + seg[0].y1 = t->boundary_width - 2; + seg[0].y2 = t->boundary_width - 2; + + seg[1].x1 = 0; + seg[1].x2 = t->corner_width - t->boundary_width - 1; + seg[1].y1 = t->boundary_width - 1; + seg[1].y2 = t->boundary_width - 1; + n = 2; + break; + case 2: + seg[0].x1 = t->boundary_width - 1; + seg[0].x2 = t->corner_width - (hh ? 1 : 2); + seg[0].y1 = t->corner_width - t->boundary_width + 1; + seg[0].y2 = t->corner_width - t->boundary_width + 1; + n = 1; + if (t->boundary_width > 3) { + seg[1].x1 = t->boundary_width - 2; + seg[1].x2 = t->corner_width - (hh ? 1 : 3); + seg[1].y1 = + t->corner_width - t->boundary_width + 2; + seg[1].y2 = + t->corner_width - t->boundary_width + 2; + n = 2; + } + break; + case 3: + seg[0].x1 = 0; + seg[0].x2 = t->corner_width - t->boundary_width; + seg[0].y1 = t->corner_width - t->boundary_width + 1; + seg[0].y2 = t->corner_width - t->boundary_width + 1; + n = 1; + if (t->boundary_width > 3) { + seg[0].x2 = + t->corner_width - t->boundary_width + 1; + + seg[1].x1 = 0; + seg[1].x2 = + t->corner_width - t->boundary_width + 1; + seg[1].y1 = + t->corner_width - t->boundary_width + 2; + seg[1].y2 = + t->corner_width - t->boundary_width + 2; + n = 2; + } + break; + } + XDrawSegments(dpy, t->corners[i], hor, seg, n); + switch (i) { + case 0: + seg[0].y1 = t->boundary_width - 2; + seg[0].y2 = t->corner_width; + seg[0].x1 = t->boundary_width - 2; + seg[0].x2 = t->boundary_width - 2; + + seg[1].y1 = t->boundary_width - 2; + seg[1].y2 = t->corner_width; + seg[1].x1 = t->boundary_width - 1; + seg[1].x2 = t->boundary_width - 1; + n = 2; + break; + case 1: + seg[0].y1 = t->boundary_width - 1; + seg[0].y2 = t->corner_width - (hh ? 1 : 2); + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + if (t->boundary_width > 3) { + seg[1].y1 = t->boundary_width - 2; + seg[1].y2 = t->corner_width - (hh ? 1 : 3); + seg[1].x1 = + t->corner_width - t->boundary_width + 1; + seg[1].x2 = + t->corner_width - t->boundary_width + 1; + n = 2; + } + break; + case 2: + seg[0].y1 = (hh ? 0 : 1); + seg[0].y2 = t->corner_width - t->boundary_width + 1; + seg[0].x1 = t->boundary_width - 2; + seg[0].x2 = t->boundary_width - 2; + n = 1; + + if (t->boundary_width > 3) { + seg[1].y1 = 0; + seg[1].y2 = t->corner_width - t->boundary_width; + seg[1].x1 = t->boundary_width - 1; + seg[1].x2 = t->boundary_width - 1; + } + break; + case 3: + seg[0].y1 = 0; + seg[0].y2 = t->corner_width - t->boundary_width + 1; + seg[0].x1 = t->corner_width - t->boundary_width; + seg[0].x2 = t->corner_width - t->boundary_width; + n = 1; + + if (t->boundary_width > 3) { + seg[0].y2 = + t->corner_width - t->boundary_width + 2; + seg[1].y1 = 0; + seg[1].y2 = + t->corner_width - t->boundary_width + 2; + seg[1].x1 = + t->corner_width - t->boundary_width + 1; + seg[1].x2 = + t->corner_width - t->boundary_width + 1; + n = 2; + } + break; + } + XDrawSegments(dpy, t->corners[i], vert, seg, n); + } } #ifdef VECTOR_BUTTONS @@ -1258,26 +1351,19 @@ void RelieveParts(FvwmWindow *t,int i,GC hor, GC vert) * Draws a little pattern within a window (more complex) * ****************************************************************************/ -void DrawLinePattern(Window win, - GC ReliefGC, - GC ShadowGC, - struct vector_coords *coords, - int w, int h) +void +DrawLinePattern(Window win, GC ReliefGC, GC ShadowGC, + struct vector_coords *coords, int w, int h) { - int i = 1; - for (; i < coords->num; ++i) - { - XDrawLine(dpy,win, - coords->line_style[i] ? ReliefGC : ShadowGC, - w * coords->x[i-1]/100, - h * coords->y[i-1]/100, - w * coords->x[i]/100, - h * coords->y[i]/100); - } + int i = 1; + for (; i < coords->num; ++i) { + XDrawLine(dpy, win, coords->line_style[i] ? ReliefGC : ShadowGC, + w * coords->x[i - 1] / 100, h * coords->y[i - 1] / 100, + w * coords->x[i] / 100, h * coords->y[i] / 100); + } } #endif /* VECTOR_BUTTONS */ - /*********************************************************************** * * Procedure: @@ -1303,309 +1389,303 @@ void DrawLinePattern(Window win, * ************************************************************************/ -void SetupFrame(FvwmWindow *tmp_win,int x,int y,int w,int h,Bool sendEvent) +void +SetupFrame(FvwmWindow *tmp_win, int x, int y, int w, int h, Bool sendEvent) { - XEvent client_event; - XWindowChanges frame_wc, xwc; - unsigned long frame_mask, xwcm; - int cx,cy,i; - Bool Resized = False, Moved = False; - int xwidth,ywidth,left,right; + XEvent client_event; + XWindowChanges frame_wc, xwc; + unsigned long frame_mask, xwcm; + int cx, cy, i; + Bool Resized = False, Moved = False; + int xwidth, ywidth, left, right; #ifdef WINDOWSHADE - int shaded = tmp_win->buttons & WSHADE; + int shaded = tmp_win->buttons & WSHADE; #endif #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"SetupFrame", - "Routine Entered (x == %d, y == %d, w == %d, h == %d)", - x, y, w, h); + fvwm_msg(DBG, "SetupFrame", + "Routine Entered (x == %d, y == %d, w == %d, h == %d)", x, y, w, h); #endif - /* if windows is not being maximized, save size in case of maximization */ - if (!(tmp_win->flags & MAXIMIZED) + /* if windows is not being maximized, save size in case of maximization + */ + if (!(tmp_win->flags & MAXIMIZED) #ifdef WINDOWSHADE - && !shaded + && !shaded #endif - ) - { - tmp_win->orig_x = x; - tmp_win->orig_y = y; - tmp_win->orig_wd = w; - tmp_win->orig_ht = h; - } - - if((w != tmp_win->frame_width) || (h != tmp_win->frame_height)) - Resized = True; - if ((x != tmp_win->frame_x || y != tmp_win->frame_y)) - Moved = True; - - /* - * According to the July 27, 1988 ICCCM draft, we should send a - * "synthetic" ConfigureNotify event to the client if the window - * was moved but not resized. - */ - if (Moved && !Resized) - sendEvent = True; - - if (Resized) - { - left = tmp_win->nr_left_buttons; - right = tmp_win->nr_right_buttons; - - if (tmp_win->flags & TITLE) - tmp_win->title_height = GetDecor(tmp_win,TitleHeight) + tmp_win->bw; - - tmp_win->title_width= w- - (left+right)*tmp_win->title_height - -2*tmp_win->boundary_width+tmp_win->bw; - - - if(tmp_win->title_width < 1) - tmp_win->title_width = 1; - - if (tmp_win->flags & TITLE) - { - xwcm = CWWidth | CWX | CWY | CWHeight; - tmp_win->title_x = tmp_win->boundary_width+ - (left)*tmp_win->title_height; - if(tmp_win->title_x >= w - tmp_win->boundary_width) - tmp_win->title_x = -10; - tmp_win->title_y = tmp_win->boundary_width; - - xwc.width = tmp_win->title_width; - - xwc.height = tmp_win->title_height; - xwc.x = tmp_win->title_x; - xwc.y = tmp_win->title_y; - XConfigureWindow(dpy, tmp_win->title_w, xwcm, &xwc); - - - xwcm = CWX | CWY | CWHeight | CWWidth; - xwc.height = tmp_win->title_height; - xwc.width = tmp_win->title_height; - - xwc.y = tmp_win->boundary_width; - xwc.x = tmp_win->boundary_width; - for(i=0;ileft_w[i] != None) - { - if(xwc.x + tmp_win->title_height < w-tmp_win->boundary_width) - XConfigureWindow(dpy, tmp_win->left_w[i], xwcm, &xwc); - else - { - xwc.x = -tmp_win->title_height; - XConfigureWindow(dpy, tmp_win->left_w[i], xwcm, &xwc); - } - xwc.x += tmp_win->title_height; - } - } - - xwc.x=w-tmp_win->boundary_width+tmp_win->bw; - for(i=0;iright_w[i] != None) - { - xwc.x -=tmp_win->title_height; - if(xwc.x > tmp_win->boundary_width) - XConfigureWindow(dpy, tmp_win->right_w[i], xwcm, &xwc); - else - { - xwc.x = -tmp_win->title_height; - XConfigureWindow(dpy, tmp_win->right_w[i], xwcm, &xwc); - } - } - } - } - - if(tmp_win->flags & BORDER) - { - tmp_win->corner_width = GetDecor(tmp_win,TitleHeight) + tmp_win->bw + - tmp_win->boundary_width ; - - if(w < 2*tmp_win->corner_width) - tmp_win->corner_width = w/3; - if((h < 2*tmp_win->corner_width) + ) { + tmp_win->orig_x = x; + tmp_win->orig_y = y; + tmp_win->orig_wd = w; + tmp_win->orig_ht = h; + } + + if ((w != tmp_win->frame_width) || (h != tmp_win->frame_height)) + Resized = True; + if ((x != tmp_win->frame_x || y != tmp_win->frame_y)) + Moved = True; + + /* + * According to the July 27, 1988 ICCCM draft, we should send a + * "synthetic" ConfigureNotify event to the client if the window + * was moved but not resized. + */ + if (Moved && !Resized) + sendEvent = True; + + if (Resized) { + left = tmp_win->nr_left_buttons; + right = tmp_win->nr_right_buttons; + + if (tmp_win->flags & TITLE) + tmp_win->title_height = + GetDecor(tmp_win, TitleHeight) + tmp_win->bw; + + tmp_win->title_width = + w - (left + right) * tmp_win->title_height - + 2 * tmp_win->boundary_width + tmp_win->bw; + + if (tmp_win->title_width < 1) + tmp_win->title_width = 1; + + if (tmp_win->flags & TITLE) { + xwcm = CWWidth | CWX | CWY | CWHeight; + tmp_win->title_x = tmp_win->boundary_width + + (left)*tmp_win->title_height; + if (tmp_win->title_x >= w - tmp_win->boundary_width) + tmp_win->title_x = -10; + tmp_win->title_y = tmp_win->boundary_width; + + xwc.width = tmp_win->title_width; + + xwc.height = tmp_win->title_height; + xwc.x = tmp_win->title_x; + xwc.y = tmp_win->title_y; + XConfigureWindow(dpy, tmp_win->title_w, xwcm, &xwc); + + xwcm = CWX | CWY | CWHeight | CWWidth; + xwc.height = tmp_win->title_height; + xwc.width = tmp_win->title_height; + + xwc.y = tmp_win->boundary_width; + xwc.x = tmp_win->boundary_width; + for (i = 0; i < Scr.nr_left_buttons; i++) { + if (tmp_win->left_w[i] != None) { + if (xwc.x + tmp_win->title_height < + w - tmp_win->boundary_width) + XConfigureWindow(dpy, + tmp_win->left_w[i], xwcm, + &xwc); + else { + xwc.x = -tmp_win->title_height; + XConfigureWindow(dpy, + tmp_win->left_w[i], xwcm, + &xwc); + } + xwc.x += tmp_win->title_height; + } + } + + xwc.x = w - tmp_win->boundary_width + tmp_win->bw; + for (i = 0; i < Scr.nr_right_buttons; i++) { + if (tmp_win->right_w[i] != None) { + xwc.x -= tmp_win->title_height; + if (xwc.x > tmp_win->boundary_width) + XConfigureWindow(dpy, + tmp_win->right_w[i], xwcm, + &xwc); + else { + xwc.x = -tmp_win->title_height; + XConfigureWindow(dpy, + tmp_win->right_w[i], xwcm, + &xwc); + } + } + } + } + + if (tmp_win->flags & BORDER) { + tmp_win->corner_width = GetDecor(tmp_win, TitleHeight) + + tmp_win->bw + + tmp_win->boundary_width; + + if (w < 2 * tmp_win->corner_width) + tmp_win->corner_width = w / 3; + if ((h < 2 * tmp_win->corner_width) #ifdef WINDOWSHADE - &&!shaded + && !shaded #endif - ) - tmp_win->corner_width = h/3; - xwidth = w - 2*tmp_win->corner_width+tmp_win->bw; - ywidth = h - 2*tmp_win->corner_width; - xwcm = CWWidth | CWHeight | CWX | CWY; - if(xwidth<2) - xwidth = 2; - if(ywidth<2) - ywidth = 2; - - for(i=0;i<4;i++) - { - if(i==0) - { - xwc.x = tmp_win->corner_width; - xwc.y = 0; - xwc.height = tmp_win->boundary_width; - xwc.width = xwidth; - } - else if (i==1) - { - xwc.x = w - tmp_win->boundary_width+tmp_win->bw; - xwc.y = tmp_win->corner_width; - xwc.width = tmp_win->boundary_width; - xwc.height = ywidth; - - } - else if(i==2) - { - xwc.x = tmp_win->corner_width; - xwc.y = h - tmp_win->boundary_width+tmp_win->bw; - xwc.height = tmp_win->boundary_width+tmp_win->bw; - xwc.width = xwidth; - } - else - { - xwc.x = 0; - xwc.y = tmp_win->corner_width; - xwc.width = tmp_win->boundary_width; - xwc.height = ywidth; - } + ) + tmp_win->corner_width = h / 3; + xwidth = w - 2 * tmp_win->corner_width + tmp_win->bw; + ywidth = h - 2 * tmp_win->corner_width; + xwcm = CWWidth | CWHeight | CWX | CWY; + if (xwidth < 2) + xwidth = 2; + if (ywidth < 2) + ywidth = 2; + + for (i = 0; i < 4; i++) { + if (i == 0) { + xwc.x = tmp_win->corner_width; + xwc.y = 0; + xwc.height = tmp_win->boundary_width; + xwc.width = xwidth; + } else if (i == 1) { + xwc.x = w - tmp_win->boundary_width + + tmp_win->bw; + xwc.y = tmp_win->corner_width; + xwc.width = tmp_win->boundary_width; + xwc.height = ywidth; + } else if (i == 2) { + xwc.x = tmp_win->corner_width; + xwc.y = h - tmp_win->boundary_width + + tmp_win->bw; + xwc.height = tmp_win->boundary_width + + tmp_win->bw; + xwc.width = xwidth; + } else { + xwc.x = 0; + xwc.y = tmp_win->corner_width; + xwc.width = tmp_win->boundary_width; + xwc.height = ywidth; + } #ifdef WINDOWSHADE - if (!shaded||(i!=2)) + if (!shaded || (i != 2)) #endif - XConfigureWindow(dpy, tmp_win->sides[i], xwcm, &xwc); - } - - xwcm = CWX|CWY|CWWidth|CWHeight; - xwc.width = tmp_win->corner_width; - xwc.height = tmp_win->corner_width; - for(i=0;i<4;i++) - { - if(i%2) - xwc.x = w - tmp_win->corner_width+tmp_win->bw; - else - xwc.x = 0; - - if(i/2) - xwc.y = h - tmp_win->corner_width; - else - xwc.y = 0; + XConfigureWindow( + dpy, tmp_win->sides[i], xwcm, &xwc); + } + + xwcm = CWX | CWY | CWWidth | CWHeight; + xwc.width = tmp_win->corner_width; + xwc.height = tmp_win->corner_width; + for (i = 0; i < 4; i++) { + if (i % 2) + xwc.x = w - tmp_win->corner_width + + tmp_win->bw; + else + xwc.x = 0; + + if (i / 2) + xwc.y = h - tmp_win->corner_width; + else + xwc.y = 0; #ifdef WINDOWSHADE - if (!shaded||(i==0)||(i==1)) + if (!shaded || (i == 0) || (i == 1)) #endif - XConfigureWindow(dpy, tmp_win->corners[i], xwcm, &xwc); - } - - } - } - tmp_win->attr.width = w - 2*tmp_win->boundary_width; - tmp_win->attr.height = h - tmp_win->title_height - - 2*tmp_win->boundary_width; - /* may need to omit the -1 for shaped windows, next two lines*/ - cx = tmp_win->boundary_width-tmp_win->bw; - cy = tmp_win->title_height + tmp_win->boundary_width-tmp_win->bw; + XConfigureWindow(dpy, + tmp_win->corners[i], xwcm, &xwc); + } + } + } + tmp_win->attr.width = w - 2 * tmp_win->boundary_width; + tmp_win->attr.height = + h - tmp_win->title_height - 2 * tmp_win->boundary_width; + /* may need to omit the -1 for shaped windows, next two lines*/ + cx = tmp_win->boundary_width - tmp_win->bw; + cy = tmp_win->title_height + tmp_win->boundary_width - tmp_win->bw; #ifdef WINDOWSHADE - if (!shaded) { + if (!shaded) { #endif - XResizeWindow(dpy, tmp_win->w, tmp_win->attr.width, - tmp_win->attr.height); - XMoveResizeWindow(dpy, tmp_win->Parent, cx,cy, - tmp_win->attr.width, tmp_win->attr.height); + XResizeWindow( + dpy, tmp_win->w, tmp_win->attr.width, tmp_win->attr.height); + XMoveResizeWindow(dpy, tmp_win->Parent, cx, cy, + tmp_win->attr.width, tmp_win->attr.height); #ifdef WINDOWSHADE - } + } #endif - /* - * fix up frame and assign size/location values in tmp_win - */ - frame_wc.x = tmp_win->frame_x = x; - frame_wc.y = tmp_win->frame_y = y; - frame_wc.width = tmp_win->frame_width = w; - frame_wc.height = tmp_win->frame_height = h; - frame_mask = (CWX | CWY | CWWidth | CWHeight); - XConfigureWindow (dpy, tmp_win->frame, frame_mask, &frame_wc); + /* + * fix up frame and assign size/location values in tmp_win + */ + frame_wc.x = tmp_win->frame_x = x; + frame_wc.y = tmp_win->frame_y = y; + frame_wc.width = tmp_win->frame_width = w; + frame_wc.height = tmp_win->frame_height = h; + frame_mask = (CWX | CWY | CWWidth | CWHeight); + XConfigureWindow(dpy, tmp_win->frame, frame_mask, &frame_wc); #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"SetupFrame", - "New frame dimensions (x == %d, y == %d, w == %d, h == %d)", - frame_wc.x, frame_wc.y, frame_wc.width, frame_wc.height); + fvwm_msg(DBG, "SetupFrame", + "New frame dimensions (x == %d, y == %d, w == %d, h == %d)", + frame_wc.x, frame_wc.y, frame_wc.width, frame_wc.height); #endif #ifdef SHAPE - if (ShapesSupported) - { - if ((Resized)&&(tmp_win->wShaped)) - { - SetShape(tmp_win,w); - } - } + if (ShapesSupported) { + if ((Resized) && (tmp_win->wShaped)) { + SetShape(tmp_win, w); + } + } #endif /* SHAPE */ - XSync(dpy,0); - if (sendEvent + XSync(dpy, 0); + if (sendEvent #ifdef WINDOWSHADE - && !shaded + && !shaded #endif - ) - { - client_event.type = ConfigureNotify; - client_event.xconfigure.display = dpy; - client_event.xconfigure.event = tmp_win->w; - client_event.xconfigure.window = tmp_win->w; - - client_event.xconfigure.x = x + tmp_win->boundary_width; - client_event.xconfigure.y = y + tmp_win->title_height+ - tmp_win->boundary_width; - client_event.xconfigure.width = w-2*tmp_win->boundary_width; - client_event.xconfigure.height =h-2*tmp_win->boundary_width - - tmp_win->title_height; - - client_event.xconfigure.border_width =tmp_win->bw; - /* Real ConfigureNotify events say we're above title window, so ... */ - /* what if we don't have a title ????? */ - client_event.xconfigure.above = tmp_win->frame; - client_event.xconfigure.override_redirect = False; - XSendEvent(dpy, tmp_win->w, False, StructureNotifyMask, &client_event); + ) { + client_event.type = ConfigureNotify; + client_event.xconfigure.display = dpy; + client_event.xconfigure.event = tmp_win->w; + client_event.xconfigure.window = tmp_win->w; + + client_event.xconfigure.x = x + tmp_win->boundary_width; + client_event.xconfigure.y = + y + tmp_win->title_height + tmp_win->boundary_width; + client_event.xconfigure.width = w - 2 * tmp_win->boundary_width; + client_event.xconfigure.height = + h - 2 * tmp_win->boundary_width - tmp_win->title_height; + + client_event.xconfigure.border_width = tmp_win->bw; + /* Real ConfigureNotify events say we're above title window, so + * ... */ + /* what if we don't have a title ????? */ + client_event.xconfigure.above = tmp_win->frame; + client_event.xconfigure.override_redirect = False; + XSendEvent( + dpy, tmp_win->w, False, StructureNotifyMask, &client_event); #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"SetupFrame","Sent ConfigureNotify (w == %d, h == %d)", - client_event.xconfigure.width,client_event.xconfigure.height); + fvwm_msg(DBG, "SetupFrame", + "Sent ConfigureNotify (w == %d, h == %d)", + client_event.xconfigure.width, + client_event.xconfigure.height); #endif - } - XSync(dpy,0); + } + XSync(dpy, 0); - BroadcastConfig(M_CONFIGURE_WINDOW,tmp_win); + BroadcastConfig(M_CONFIGURE_WINDOW, tmp_win); } - /**************************************************************************** * * Sets up the shaped window borders * ****************************************************************************/ -void SetShape(FvwmWindow *tmp_win, int w) +void +SetShape(FvwmWindow *tmp_win, int w) { #ifdef SHAPE - if (ShapesSupported) - { - XRectangle rect; - - XShapeCombineShape (dpy, tmp_win->frame, ShapeBounding, - tmp_win->boundary_width, - tmp_win->title_height+tmp_win->boundary_width, - tmp_win->w, - ShapeBounding, ShapeSet); - if (tmp_win->title_w) - { - /* windows w/ titles */ - rect.x = tmp_win->boundary_width; - rect.y = tmp_win->title_y; - rect.width = w - 2*tmp_win->boundary_width+tmp_win->bw; - rect.height = tmp_win->title_height; - - - XShapeCombineRectangles(dpy,tmp_win->frame,ShapeBounding, - 0,0,&rect,1,ShapeUnion,Unsorted); - } - } + if (ShapesSupported) { + XRectangle rect; + + XShapeCombineShape(dpy, tmp_win->frame, ShapeBounding, + tmp_win->boundary_width, + tmp_win->title_height + tmp_win->boundary_width, tmp_win->w, + ShapeBounding, ShapeSet); + if (tmp_win->title_w) { + /* windows w/ titles */ + rect.x = tmp_win->boundary_width; + rect.y = tmp_win->title_y; + rect.width = + w - 2 * tmp_win->boundary_width + tmp_win->bw; + rect.height = tmp_win->title_height; + + XShapeCombineRectangles(dpy, tmp_win->frame, + ShapeBounding, 0, 0, &rect, 1, ShapeUnion, + Unsorted); + } + } #endif } Index: fvwm/fvwm/builtins.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/builtins.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/builtins.c --- fvwm/fvwm/builtins.c +++ fvwm/fvwm/builtins.c @@ -6,36 +6,35 @@ * copyright remains in the source code and all documentation ****************************************************************************/ -#include "config.h" - +#include +#include +#include +#include #include #include -#include #include -#include #include -#include -#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" static Boolean ReadMenuFace(char *s, MenuFace *mf, int verbose); static void FreeMenuFace(Display *dpy, MenuFace *mf); -static char *exec_shell_name="/bin/sh"; +static char *exec_shell_name = "/bin/sh"; /* button state strings must match the enumerated states */ -static char *button_states[MaxButtonState]={ - "ActiveUp", +static char *button_states[MaxButtonState] = { + "ActiveUp", #ifdef ACTIVEDOWN_BTNS - "ActiveDown", + "ActiveDown", #endif #ifdef INACTIVE_BTNS - "Inactive", + "Inactive", #endif }; @@ -49,264 +48,235 @@ static char *button_states[MaxButtonState]={ * eventp - pointer to XEvent to patch up * w - pointer to Window to patch up * tmp_win - pointer to FvwmWindow Structure to patch up - * context - the context in which the mouse button was pressed - * func - the function to defer - * cursor - the cursor to display while waiting + * context - the context in which the mouse button was pressed + * func - the function to defer + * cursor - the cursor to display while waiting * finishEvent - ButtonRelease or ButtonPress; tells what kind of event to * terminate on. * ***********************************************************************/ -int DeferExecution(XEvent *eventp, Window *w,FvwmWindow **tmp_win, - unsigned long *context, int cursor, int FinishEvent) - +int +DeferExecution(XEvent *eventp, Window *w, FvwmWindow **tmp_win, + unsigned long *context, int cursor, int FinishEvent) { - int done; - int finished = 0; - Window dummy; - Window original_w; - - original_w = *w; - - if((*context != C_ROOT)&&(*context != C_NO_CONTEXT)&&(tmp_win != NULL)) - { - if((FinishEvent == ButtonPress)||((FinishEvent == ButtonRelease) && - (eventp->type != ButtonPress))) - { - return FALSE; - } - } - if(!GrabEm(cursor)) - { - XBell(dpy, 0); - return True; - } - - while (!finished) - { - done = 0; - /* block until there is an event */ - XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | - ExposureMask |KeyPressMask | VisibilityChangeMask | - ButtonMotionMask| PointerMotionMask/* | EnterWindowMask | - LeaveWindowMask*/, eventp); - StashEventTime(eventp); - - if(eventp->type == KeyPress) - Keyboard_shortcuts(eventp, NULL, FinishEvent); - if(eventp->type == FinishEvent) - finished = 1; - if(eventp->type == ButtonPress) - { - XAllowEvents(dpy,ReplayPointer,CurrentTime); - done = 1; - } - if(eventp->type == ButtonRelease) - done = 1; - if(eventp->type == KeyPress) - done = 1; - - if(!done) - { - DispatchEvent(); - } - - } - - - *w = eventp->xany.window; - if(((*w == Scr.Root)||(*w == Scr.NoFocusWin)) - && (eventp->xbutton.subwindow != (Window)0)) - { - *w = eventp->xbutton.subwindow; - eventp->xany.window = *w; - } - if (*w == Scr.Root) - { - *context = C_ROOT; - XBell(dpy, 0); - UngrabEm(); - return TRUE; - } - if (XFindContext (dpy, *w, FvwmContext, (caddr_t *)tmp_win) == XCNOENT) - { - *tmp_win = NULL; - XBell(dpy, 0); - UngrabEm(); - return (TRUE); - } - - if(*w == (*tmp_win)->Parent) - *w = (*tmp_win)->w; - - if(original_w == (*tmp_win)->Parent) - original_w = (*tmp_win)->w; - - /* this ugly mess attempts to ensure that the release and press - * are in the same window. */ - if((*w != original_w)&&(original_w != Scr.Root)&& - (original_w != None)&&(original_w != Scr.NoFocusWin)) - if(!((*w == (*tmp_win)->frame)&& - (original_w == (*tmp_win)->w))) - { - *context = C_ROOT; - XBell(dpy, 0); - UngrabEm(); - return TRUE; - } - - *context = GetContext(*tmp_win,eventp,&dummy); - - UngrabEm(); - return FALSE; -} + int done; + int finished = 0; + Window dummy; + Window original_w; + + original_w = *w; + + if ((*context != C_ROOT) && (*context != C_NO_CONTEXT) && + (tmp_win != NULL)) { + if ((FinishEvent == ButtonPress) || + ((FinishEvent == ButtonRelease) && + (eventp->type != ButtonPress))) { + return FALSE; + } + } + if (!GrabEm(cursor)) { + XBell(dpy, 0); + return True; + } + + while (!finished) { + done = 0; + /* block until there is an event */ + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | ExposureMask | + KeyPressMask | VisibilityChangeMask | ButtonMotionMask | + PointerMotionMask /* | EnterWindowMask | + LeaveWindowMask*/ + , + eventp); + StashEventTime(eventp); + + if (eventp->type == KeyPress) + Keyboard_shortcuts(eventp, NULL, FinishEvent); + if (eventp->type == FinishEvent) + finished = 1; + if (eventp->type == ButtonPress) { + XAllowEvents(dpy, ReplayPointer, CurrentTime); + done = 1; + } + if (eventp->type == ButtonRelease) + done = 1; + if (eventp->type == KeyPress) + done = 1; + + if (!done) { + DispatchEvent(); + } + } + + *w = eventp->xany.window; + if (((*w == Scr.Root) || (*w == Scr.NoFocusWin)) && + (eventp->xbutton.subwindow != (Window)0)) { + *w = eventp->xbutton.subwindow; + eventp->xany.window = *w; + } + if (*w == Scr.Root) { + *context = C_ROOT; + XBell(dpy, 0); + UngrabEm(); + return TRUE; + } + if (XFindContext(dpy, *w, FvwmContext, (caddr_t *)tmp_win) == XCNOENT) { + *tmp_win = NULL; + XBell(dpy, 0); + UngrabEm(); + return (TRUE); + } + if (*w == (*tmp_win)->Parent) + *w = (*tmp_win)->w; + + if (original_w == (*tmp_win)->Parent) + original_w = (*tmp_win)->w; + + /* this ugly mess attempts to ensure that the release and press + * are in the same window. */ + if ((*w != original_w) && (original_w != Scr.Root) && + (original_w != None) && (original_w != Scr.NoFocusWin)) + if (!((*w == (*tmp_win)->frame) && + (original_w == (*tmp_win)->w))) { + *context = C_ROOT; + XBell(dpy, 0); + UngrabEm(); + return TRUE; + } + *context = GetContext(*tmp_win, eventp, &dummy); + UngrabEm(); + return FALSE; +} /************************************************************************** * * Moves focus to specified window * *************************************************************************/ -void FocusOn(FvwmWindow *t,Bool FocusByMouse) +void +FocusOn(FvwmWindow *t, Bool FocusByMouse) { #ifndef NON_VIRTUAL - int dx,dy; - int cx,cy; + int dx, dy; + int cx, cy; #endif - int x,y; + int x, y; - if(t == (FvwmWindow *)0) - return; + if (t == (FvwmWindow *)0) + return; - if(t->Desk != Scr.CurrentDesk) - { - changeDesks(t->Desk); - } + if (t->Desk != Scr.CurrentDesk) { + changeDesks(t->Desk); + } #ifndef NON_VIRTUAL - if(t->flags & ICONIFIED) - { - cx = t->icon_xl_loc + t->icon_w_width/2; - cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - cx = t->frame_x + t->frame_width/2; - cy = t->frame_y + t->frame_height/2; - } - - dx = (cx + Scr.Vx)/Scr.MyDisplayWidth*Scr.MyDisplayWidth; - dy = (cy +Scr.Vy)/Scr.MyDisplayHeight*Scr.MyDisplayHeight; - - MoveViewport(dx,dy,True); -#endif + if (t->flags & ICONIFIED) { + cx = t->icon_xl_loc + t->icon_w_width / 2; + cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + cx = t->frame_x + t->frame_width / 2; + cy = t->frame_y + t->frame_height / 2; + } - if(t->flags & ICONIFIED) - { - x = t->icon_xl_loc + t->icon_w_width/2; - y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - x = t->frame_x; - y = t->frame_y; - } -#if 0 /* don't want to warp the pointer by default anymore */ - if(!(t->flags & ClickToFocus)) - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x+2,y+2); -#endif /* 0 */ -#if 0 /* don't want to raise anymore either */ - RaiseWindow(t); -#endif /* 0 */ - KeepOnTop(); - - /* If the window is still not visible, make it visible! */ - if(((t->frame_x + t->frame_height)< 0)||(t->frame_y + t->frame_width < 0)|| - (t->frame_x >Scr.MyDisplayWidth)||(t->frame_y>Scr.MyDisplayHeight)) - { - SetupFrame(t,0,0,t->frame_width, t->frame_height,False); - if(!(t->flags & ClickToFocus)) - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2,2); - } - UngrabEm(); - SetFocus(t->w,t,FocusByMouse); -} + dx = (cx + Scr.Vx) / Scr.MyDisplayWidth * Scr.MyDisplayWidth; + dy = (cy + Scr.Vy) / Scr.MyDisplayHeight * Scr.MyDisplayHeight; + MoveViewport(dx, dy, True); +#endif + if (t->flags & ICONIFIED) { + x = t->icon_xl_loc + t->icon_w_width / 2; + y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + x = t->frame_x; + y = t->frame_y; + } + KeepOnTop(); + + /* If the window is still not visible, make it visible! */ + if (((t->frame_x + t->frame_height) < 0) || + (t->frame_y + t->frame_width < 0) || + (t->frame_x > Scr.MyDisplayWidth) || + (t->frame_y > Scr.MyDisplayHeight)) { + SetupFrame(t, 0, 0, t->frame_width, t->frame_height, False); + if (!(t->flags & ClickToFocus)) + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2, 2); + } + UngrabEm(); + SetFocus(t->w, t, FocusByMouse); +} /************************************************************************** * * Moves pointer to specified window * *************************************************************************/ -void WarpOn(FvwmWindow *t,int warp_x, int x_unit, int warp_y, int y_unit) +void +WarpOn(FvwmWindow *t, int warp_x, int x_unit, int warp_y, int y_unit) { #ifndef NON_VIRTUAL - int dx,dy; - int cx,cy; + int dx, dy; + int cx, cy; #endif - int x,y; + int x, y; - if(t == (FvwmWindow *)0 || (t->flags & ICONIFIED && t->icon_w == None)) - return; + if (t == (FvwmWindow *)0 || (t->flags & ICONIFIED && t->icon_w == None)) + return; - if(t->Desk != Scr.CurrentDesk) - { - changeDesks(t->Desk); - } + if (t->Desk != Scr.CurrentDesk) { + changeDesks(t->Desk); + } #ifndef NON_VIRTUAL - if(t->flags & ICONIFIED) - { - cx = t->icon_xl_loc + t->icon_w_width/2; - cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - cx = t->frame_x + t->frame_width/2 + t->bw; - cy = t->frame_y + t->frame_height/2 + t->bw; - } - - dx = (cx + Scr.Vx)/Scr.MyDisplayWidth*Scr.MyDisplayWidth; - dy = (cy +Scr.Vy)/Scr.MyDisplayHeight*Scr.MyDisplayHeight; - - MoveViewport(dx,dy,True); -#endif + if (t->flags & ICONIFIED) { + cx = t->icon_xl_loc + t->icon_w_width / 2; + cy = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + cx = t->frame_x + t->frame_width / 2 + t->bw; + cy = t->frame_y + t->frame_height / 2 + t->bw; + } - if(t->flags & ICONIFIED) - { - x = t->icon_xl_loc + t->icon_w_width/2; - y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT/2; - } - else - { - if (x_unit != Scr.MyDisplayWidth) - x = t->frame_x + t->bw + warp_x; - else - x = t->frame_x + t->bw + (t->frame_width - 1) * warp_x / 100; - if (y_unit != Scr.MyDisplayHeight) - y = t->frame_y + t->bw + warp_y; - else - y = t->frame_y + t->bw + (t->frame_height - 1) * warp_y / 100; - } - if (warp_x >= 0 && warp_y >= 0) { - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x, y); - } - RaiseWindow(t); - KeepOnTop(); - - /* If the window is still not visible, make it visible! */ - if(((t->frame_x + t->frame_height)< 0)||(t->frame_y + t->frame_width < 0)|| - (t->frame_x >Scr.MyDisplayWidth)||(t->frame_y>Scr.MyDisplayHeight)) - { - SetupFrame(t,0,0,t->frame_width, t->frame_height,False); - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2,2); - } - UngrabEm(); -} + dx = (cx + Scr.Vx) / Scr.MyDisplayWidth * Scr.MyDisplayWidth; + dy = (cy + Scr.Vy) / Scr.MyDisplayHeight * Scr.MyDisplayHeight; + MoveViewport(dx, dy, True); +#endif + if (t->flags & ICONIFIED) { + x = t->icon_xl_loc + t->icon_w_width / 2; + y = t->icon_y_loc + t->icon_p_height + ICON_HEIGHT / 2; + } else { + if (x_unit != Scr.MyDisplayWidth) + x = t->frame_x + t->bw + warp_x; + else + x = t->frame_x + t->bw + + (t->frame_width - 1) * warp_x / 100; + if (y_unit != Scr.MyDisplayHeight) + y = t->frame_y + t->bw + warp_y; + else + y = t->frame_y + t->bw + + (t->frame_height - 1) * warp_y / 100; + } + if (warp_x >= 0 && warp_y >= 0) { + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x, y); + } + RaiseWindow(t); + KeepOnTop(); + + /* If the window is still not visible, make it visible! */ + if (((t->frame_x + t->frame_height) < 0) || + (t->frame_y + t->frame_width < 0) || + (t->frame_x > Scr.MyDisplayWidth) || + (t->frame_y > Scr.MyDisplayHeight)) { + SetupFrame(t, 0, 0, t->frame_width, t->frame_height, False); + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, 2, 2); + } + UngrabEm(); +} /*********************************************************************** * @@ -314,71 +284,100 @@ void WarpOn(FvwmWindow *t,int warp_x, int x_unit, int warp_y, int y_unit) * (Un)Maximize a window. * ***********************************************************************/ -void Maximize(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +static int +virtual_page_origin(int coordinate, int span) +{ + int base; + + if (span <= 0) + return 0; + if (coordinate >= 0) + return (coordinate / span) * span; + + base = -((-coordinate) / span) * span; + if ((-coordinate) % span != 0) + base -= span; + return base; +} + +void +Maximize(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int new_width, new_height,new_x,new_y; - int val1, val2, val1_unit,val2_unit,n; + int new_width, new_height, new_x, new_y; + int val1, val2, val1_unit, val2_unit, n; - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - if(tmp_win == NULL) - return; + if (tmp_win == NULL) + return; - if(check_allowed_function2(F_MAXIMIZE,tmp_win) == 0 + if (check_allowed_function2(F_MAXIMIZE, tmp_win) == 0 #ifdef WINDOWSHADE - || (tmp_win->buttons & WSHADE) + || (tmp_win->buttons & WSHADE) +#endif + ) { + XBell(dpy, 0); + return; + } + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + if (n != 2) { + val1 = 100; + val2 = 100; + val1_unit = Scr.MyDisplayWidth; + val2_unit = Scr.MyDisplayHeight; + } + + if (tmp_win->flags & MAXIMIZED) { + int orig_wd = tmp_win->orig_wd; + int orig_ht = tmp_win->orig_ht; + + tmp_win->flags &= ~MAXIMIZED; + ConstrainSize(tmp_win, &orig_wd, &orig_ht, False, 0, 0); + SetupFrame(tmp_win, tmp_win->orig_x, tmp_win->orig_y, + orig_wd, orig_ht, TRUE); + SetBorder(tmp_win, True, True, True, None); + } else { + new_width = tmp_win->frame_width; + new_height = tmp_win->frame_height; + new_x = tmp_win->frame_x; + new_y = tmp_win->frame_y; +#ifndef NON_VIRTUAL + { + const int page_x = virtual_page_origin( + tmp_win->frame_x, Scr.MyDisplayWidth); + const int page_y = virtual_page_origin( + tmp_win->frame_y, Scr.MyDisplayHeight); +#else + { + const int page_x = 0; + const int page_y = 0; #endif - ) - { - XBell(dpy, 0); - return; - } - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - if(n != 2) - { - val1 = 100; - val2 = 100; - val1_unit = Scr.MyDisplayWidth; - val2_unit = Scr.MyDisplayHeight; - } - - if (tmp_win->flags & MAXIMIZED) - { - tmp_win->flags &= ~MAXIMIZED; - SetupFrame(tmp_win, tmp_win->orig_x, tmp_win->orig_y, tmp_win->orig_wd, - tmp_win->orig_ht,TRUE); - SetBorder(tmp_win,True,True,True,None); - } - else - { - new_width = tmp_win->frame_width; - new_height = tmp_win->frame_height; - new_x = tmp_win->frame_x; - new_y = tmp_win->frame_y; - if(val1 >0) - { - new_width = val1*val1_unit/100-2; - new_x = 0; - } - if(val2 >0) - { - new_height = val2*val2_unit/100-2; - new_y = 0; - } - if((val1==0)&&(val2==0)) - { - new_x = 0; - new_y = 0; - new_height = Scr.MyDisplayHeight-2; - new_width = Scr.MyDisplayWidth-2; - } - tmp_win->flags |= MAXIMIZED; - ConstrainSize (tmp_win, &new_width, &new_height, False, 0, 0); - SetupFrame(tmp_win,new_x,new_y,new_width,new_height,TRUE); - SetBorder(tmp_win,Scr.Hilite == tmp_win,True,True,None); - } + if (val1 > 0) { + new_width = val1 * val1_unit / 100 - 2; + new_x = page_x; + } + if (val2 > 0) { + new_height = val2 * val2_unit / 100 - 2; + new_y = page_y; + } + if ((val1 == 0) && (val2 == 0)) { + new_x = page_x; + new_y = page_y; + new_height = Scr.MyDisplayHeight - 2; + new_width = Scr.MyDisplayWidth - 2; + } + tmp_win->flags |= MAXIMIZED; + ConstrainSize( + tmp_win, &new_width, &new_height, False, 0, 0); + SetupFrame( + tmp_win, new_x, new_y, new_width, new_height, TRUE); + SetBorder( + tmp_win, Scr.Hilite == tmp_win, True, True, None); + } + } } #ifdef WINDOWSHADE @@ -389,973 +388,936 @@ void Maximize(XEvent *eventp,Window w,FvwmWindow *tmp_win, * Args: 1 -- force shade, 2 -- force unshade No Arg: toggle * ***********************************************************************/ -void WindowShade(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +WindowShade(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int n = 0; + int n = 0; - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - if (!(tmp_win->flags & TITLE) || (tmp_win->flags & MAXIMIZED)) { - XBell(dpy, 0); - return; - } - while (isspace(*action))++action; - if (isdigit(*action)) - sscanf(action,"%d",&n); - - if (((tmp_win->buttons & WSHADE)||(n==2))&&(n!=1)) - { - tmp_win->buttons &= ~WSHADE; - SetupFrame(tmp_win, - tmp_win->frame_x, - tmp_win->frame_y, - tmp_win->orig_wd, - tmp_win->orig_ht, - True); - BroadcastPacket(M_DEWINDOWSHADE, 3, - tmp_win->w, tmp_win->frame, (unsigned long)tmp_win); - } - else - { - tmp_win->buttons |= WSHADE; - SetupFrame(tmp_win, - tmp_win->frame_x, - tmp_win->frame_y, - tmp_win->frame_width, - tmp_win->title_height + tmp_win->boundary_width - tmp_win->bw, - False); - BroadcastPacket(M_WINDOWSHADE, 3, - tmp_win->w, tmp_win->frame, (unsigned long)tmp_win); - } + if (!(tmp_win->flags & TITLE) || (tmp_win->flags & MAXIMIZED)) { + XBell(dpy, 0); + return; + } + while (isspace(*action)) + ++action; + if (isdigit(*action)) + sscanf(action, "%d", &n); + + if (((tmp_win->buttons & WSHADE) || (n == 2)) && (n != 1)) { + tmp_win->buttons &= ~WSHADE; + SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, + tmp_win->orig_wd, tmp_win->orig_ht, True); + BroadcastPacket(M_DEWINDOWSHADE, 3, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win); + } else { + tmp_win->buttons |= WSHADE; + SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, + tmp_win->frame_width, + tmp_win->title_height + tmp_win->boundary_width - + tmp_win->bw, + False); + BroadcastPacket(M_WINDOWSHADE, 3, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win); + } } #endif /* WINDOWSHADE */ /* For Ultrix 4.2 */ -#include #include +#include - -MenuRoot *FindPopup(char *action) +MenuRoot * +FindPopup(char *action) { - char *tmp; - MenuRoot *mr; - - GetNextToken(action,&tmp); - - if(tmp == NULL) - return NULL; - - mr = Scr.menus.all; - while(mr != NULL) - { - if(mr->name != NULL) - if(strcasecmp(tmp,mr->name)== 0) - { - free(tmp); - return mr; - } - mr = mr->next; - } - free(tmp); - return NULL; + char *tmp; + MenuRoot *mr; -} + GetNextToken(action, &tmp); + if (tmp == NULL) + return NULL; + mr = Scr.menus.all; + while (mr != NULL) { + if (mr->name != NULL) + if (strcasecmp(tmp, mr->name) == 0) { + free(tmp); + return mr; + } + mr = mr->next; + } + free(tmp); + return NULL; +} -void Bell(XEvent *eventp,Window w,FvwmWindow *tmp_win,unsigned long context, - char *action, int *Module) +void +Bell(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - XBell(dpy, 0); + XBell(dpy, 0); } - #ifdef USEDECOR static FvwmDecor *last_decor = NULL, *cur_decor = NULL; #endif -MenuRoot *last_menu=NULL; -void add_item_to_menu(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +MenuRoot *last_menu = NULL; +void +add_item_to_menu(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - MenuRoot *mrPrior; - char *token, *rest,*item; + MenuRoot *mr; + MenuRoot *mrPrior; + char *token, *rest, *item; #ifdef USEDECOR - last_decor = NULL; + last_decor = NULL; #endif - rest = GetNextToken(action,&token); - if (!token) - return; - mr = FollowMenuContinuations(FindPopup(token),&mrPrior); - if(mr == NULL) - mr = NewMenuRoot(token, False); - last_menu = mr; - - rest = GetNextToken(rest,&item); - AddToMenu(mr, item,rest,TRUE /* pixmap scan */, TRUE); - if (item) - free(item); - /* These lines are correct! We must not release token if the string is empty. - * It cannot be NULL! GetNextToken never returns an empty string! */ - if (*token) - free(token); - - MakeMenu(mr); - return; -} + rest = GetNextToken(action, &token); + if (!token) + return; + mr = FollowMenuContinuations(FindPopup(token), &mrPrior); + if (mr == NULL) + mr = NewMenuRoot(token, False); + last_menu = mr; + + rest = GetNextToken(rest, &item); + AddToMenu(mr, item, rest, TRUE /* pixmap scan */, TRUE); + if (item) + free(item); + /* These lines are correct! We must not release token if the string is + * empty. It cannot be NULL! GetNextToken never returns an empty string! + */ + if (*token) + free(token); + MakeMenu(mr); + return; +} -void add_another_item(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +void +add_another_item(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { #ifdef USEDECOR - extern void AddToDecor(FvwmDecor *, char *); + extern void AddToDecor(FvwmDecor *, char *); #endif - MenuRoot *mr; - MenuRoot *mrPrior; - char *rest,*item; - - if (last_menu != NULL) { - mr = FollowMenuContinuations(last_menu,&mrPrior); - if(mr == NULL) - return; - rest = GetNextToken(action,&item); - AddToMenu(mr, item,rest,TRUE /* pixmap scan */, FALSE); - if (item) - free(item); - MakeMenu(mr); - } + MenuRoot *mr; + MenuRoot *mrPrior; + char *rest, *item; + + if (last_menu != NULL) { + mr = FollowMenuContinuations(last_menu, &mrPrior); + if (mr == NULL) + return; + rest = GetNextToken(action, &item); + AddToMenu(mr, item, rest, TRUE /* pixmap scan */, FALSE); + if (item) + free(item); + MakeMenu(mr); + } #ifdef USEDECOR - else if (last_decor != NULL) { - FvwmDecor *tmp = &Scr.DefaultDecor; - for (; tmp; tmp = tmp->next) - if (tmp == last_decor) - break; - if (!tmp) - return; - AddToDecor(tmp, action); - } + else if (last_decor != NULL) { + FvwmDecor *tmp = &Scr.DefaultDecor; + for (; tmp; tmp = tmp->next) + if (tmp == last_decor) + break; + if (!tmp) + return; + AddToDecor(tmp, action); + } #endif /* USEDECOR */ } -void destroy_menu(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +void +destroy_menu(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - MenuRoot *mrContinuation; - - char *token, *rest; - - rest = GetNextToken(action,&token); - if (!token) - return; - mr = FindPopup(token); - free(token); - while (mr) - { - mrContinuation = mr->continuation; /* save continuation before destroy */ - DestroyMenu(mr); - mr = mrContinuation; - } - return; + MenuRoot *mr; + MenuRoot *mrContinuation; + + char *token, *rest; + + rest = GetNextToken(action, &token); + if (!token) + return; + mr = FindPopup(token); + free(token); + while (mr) { + if (mr == last_menu) + last_menu = NULL; + mrContinuation = + mr->continuation; /* save continuation before destroy */ + DestroyMenu(mr); + mr = mrContinuation; + } + return; } -void add_item_to_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) +void +add_item_to_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - - char *token, *rest,*item; - - rest = GetNextToken(action,&token); - if (!token) - return; - mr = FindPopup(token); - if(mr == NULL) - mr = NewMenuRoot(token, True); - last_menu = mr; - if (token) - free(token); - rest = GetNextToken(rest,&item); - AddToMenu(mr, item,rest,FALSE,FALSE); - if (item) - free(item); - - return; -} + MenuRoot *mr; + char *token, *rest, *item; -void Nop_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) -{ + rest = GetNextToken(action, &token); + if (!token) + return; + mr = FindPopup(token); + if (mr == NULL) + mr = NewMenuRoot(token, True); + last_menu = mr; + if (token) + free(token); + rest = GetNextToken(rest, &item); + AddToMenu(mr, item, rest, FALSE, FALSE); + if (item) + free(item); + return; } +void +Nop_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) +{ +} -void movecursor(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +movecursor(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int x = 0, y = 0; - int val1, val2, val1_unit, val2_unit; + int x = 0, y = 0; + int val1, val2, val1_unit, val2_unit; #ifndef NON_VIRTUAL - int virtual_x, virtual_y; - int pan_x, pan_y; - int x_pages, y_pages; + int virtual_x, virtual_y; + int pan_x, pan_y; + int x_pages, y_pages; #endif - if (GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit) != 2) - { - fvwm_msg(ERR, "movecursor", "CursorMove needs 2 arguments"); - return; - } + if (GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit) != + 2) { + fvwm_msg(ERR, "movecursor", "CursorMove needs 2 arguments"); + return; + } - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); - x = x + val1 * val1_unit / 100; - y = y + val2 * val2_unit / 100; + x = x + val1 * val1_unit / 100; + y = y + val2 * val2_unit / 100; #ifndef NON_VIRTUAL - virtual_x = Scr.Vx; - virtual_y = Scr.Vy; - if (x >= 0) - x_pages = x / Scr.MyDisplayWidth; - else - x_pages = ((x + 1) / Scr.MyDisplayWidth) - 1; - virtual_x += x_pages * Scr.MyDisplayWidth; - x -= x_pages * Scr.MyDisplayWidth; - if (virtual_x < 0) - { - x += virtual_x; - virtual_x = 0; - } - else if (virtual_x > Scr.VxMax) - { - x += virtual_x - Scr.VxMax; - virtual_x = Scr.VxMax; - } - - if (y >= 0) - y_pages = y / Scr.MyDisplayHeight; - else - y_pages = ((y + 1) / Scr.MyDisplayHeight) - 1; - virtual_y += y_pages * Scr.MyDisplayHeight; - y -= y_pages * Scr.MyDisplayHeight; - if (virtual_y < 0) - { - y += virtual_y; - virtual_y = 0; - } - else if (virtual_y > Scr.VyMax) - { - y += virtual_y - Scr.VyMax; - virtual_y = Scr.VyMax; - } - if (virtual_x != Scr.Vx || virtual_y != Scr.Vy) - MoveViewport(virtual_x, virtual_y, True); - pan_x = (Scr.EdgeScrollX != 0) ? 2 : 0; - pan_y = (Scr.EdgeScrollY != 0) ? 2 : 0; - /* prevent paging if EdgeScroll is active */ - if (x >= Scr.MyDisplayWidth - pan_x) - x = Scr.MyDisplayWidth - pan_x -1; - else if (x < pan_x) - x = pan_x; - if (y >= Scr.MyDisplayHeight - pan_y) - y = Scr.MyDisplayHeight - pan_y - 1; - else if (y < pan_y) - y = pan_y; + virtual_x = Scr.Vx; + virtual_y = Scr.Vy; + if (x >= 0) + x_pages = x / Scr.MyDisplayWidth; + else + x_pages = ((x + 1) / Scr.MyDisplayWidth) - 1; + virtual_x += x_pages * Scr.MyDisplayWidth; + x -= x_pages * Scr.MyDisplayWidth; + if (virtual_x < 0) { + x += virtual_x; + virtual_x = 0; + } else if (virtual_x > Scr.VxMax) { + x += virtual_x - Scr.VxMax; + virtual_x = Scr.VxMax; + } + + if (y >= 0) + y_pages = y / Scr.MyDisplayHeight; + else + y_pages = ((y + 1) / Scr.MyDisplayHeight) - 1; + virtual_y += y_pages * Scr.MyDisplayHeight; + y -= y_pages * Scr.MyDisplayHeight; + if (virtual_y < 0) { + y += virtual_y; + virtual_y = 0; + } else if (virtual_y > Scr.VyMax) { + y += virtual_y - Scr.VyMax; + virtual_y = Scr.VyMax; + } + if (virtual_x != Scr.Vx || virtual_y != Scr.Vy) + MoveViewport(virtual_x, virtual_y, True); + pan_x = (Scr.EdgeScrollX != 0) ? 2 : 0; + pan_y = (Scr.EdgeScrollY != 0) ? 2 : 0; + /* prevent paging if EdgeScroll is active */ + if (x >= Scr.MyDisplayWidth - pan_x) + x = Scr.MyDisplayWidth - pan_x - 1; + else if (x < pan_x) + x = pan_x; + if (y >= Scr.MyDisplayHeight - pan_y) + y = Scr.MyDisplayHeight - pan_y - 1; + else if (y < pan_y) + y = pan_y; #endif - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, x, y); - return; + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x, y); + return; } +void +iconify_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) +{ + int val = 0; + + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; -void iconify_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) + GetIntegerArguments(action, NULL, &val, 1); -{ - int val = 0; - - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT, ButtonRelease)) - return; - - GetIntegerArguments(action, NULL, &val, 1); - - if (tmp_win->flags & ICONIFIED) - { - if(val <=0) - DeIconify(tmp_win); - } - else - { - if(check_allowed_function2(F_ICONIFY,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - if(val >=0) - Iconify(tmp_win,eventp->xbutton.x_root-5,eventp->xbutton.y_root-5); - } + if (tmp_win->flags & ICONIFIED) { + if (val <= 0) + DeIconify(tmp_win); + } else { + if (check_allowed_function2(F_ICONIFY, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + if (val >= 0) + Iconify(tmp_win, eventp->xbutton.x_root - 5, + eventp->xbutton.y_root - 5); + } } -void raise_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +raise_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - name_list styles; /* place for merged styles */ + name_list styles; /* place for merged styles */ - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - if(tmp_win) - RaiseWindow(tmp_win); + if (tmp_win) + RaiseWindow(tmp_win); - LookInList(tmp_win, &styles); /* get merged styles */ - if (styles.on_flags & STAYSONTOP_FLAG) { - tmp_win->flags |= ONTOP; - } - KeepOnTop(); + LookInList(tmp_win, &styles); /* get merged styles */ + if (styles.on_flags & STAYSONTOP_FLAG) { + tmp_win->flags |= ONTOP; + } + KeepOnTop(); } -void lower_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +lower_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT, ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - LowerWindow(tmp_win); + LowerWindow(tmp_win); - tmp_win->flags &= ~ONTOP; + tmp_win->flags &= ~ONTOP; } -void destroy_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +destroy_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, DESTROY, ButtonRelease)) - return; - - if(check_allowed_function2(F_DESTROY,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - - if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) - Destroy(tmp_win); - else - XKillClient(dpy, tmp_win->w); - XSync(dpy,0); + if (DeferExecution( + eventp, &w, &tmp_win, &context, DESTROY, ButtonRelease)) + return; + + if (check_allowed_function2(F_DESTROY, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + + if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth) == 0) + Destroy(tmp_win); + else + XKillClient(dpy, tmp_win->w); + XSync(dpy, 0); } -void delete_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +delete_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, DESTROY,ButtonRelease)) - return; - - if(check_allowed_function2(F_DELETE,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - - if (tmp_win->flags & DoesWmDeleteWindow) - { - send_clientmessage (dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); - return; - } - else - XBell (dpy, 0); - XSync(dpy,0); + if (DeferExecution( + eventp, &w, &tmp_win, &context, DESTROY, ButtonRelease)) + return; + + if (check_allowed_function2(F_DELETE, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + + if (tmp_win->flags & DoesWmDeleteWindow) { + send_clientmessage( + dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); + return; + } else + XBell(dpy, 0); + XSync(dpy, 0); } -void close_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +close_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context, DESTROY,ButtonRelease)) - return; - - if(check_allowed_function2(F_CLOSE,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - - if (tmp_win->flags & DoesWmDeleteWindow) - { - send_clientmessage (dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); - return; - } - else if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) - Destroy(tmp_win); - else - XKillClient(dpy, tmp_win->w); - XSync(dpy,0); + if (DeferExecution( + eventp, &w, &tmp_win, &context, DESTROY, ButtonRelease)) + return; + + if (check_allowed_function2(F_CLOSE, tmp_win) == 0) { + XBell(dpy, 0); + return; + } + + if (tmp_win->flags & DoesWmDeleteWindow) { + send_clientmessage( + dpy, tmp_win->w, _XA_WM_DELETE_WINDOW, CurrentTime); + return; + } else if (XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0) + Destroy(tmp_win); + else + XKillClient(dpy, tmp_win->w); + XSync(dpy, 0); } -void restart_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +restart_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Done(1, action); + Done(1, action); } -void exec_setup(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +exec_setup(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - char *arg=NULL; - static char shell_set = 0; - - if (shell_set) - free(exec_shell_name); - shell_set = 1; - action = GetNextToken(action,&arg); - if (arg) /* specific shell was specified */ - { - exec_shell_name = arg; - } - else /* no arg, so use $SHELL -- not working??? */ - { - if (getenv("SHELL")) - exec_shell_name = strdup(getenv("SHELL")); - else - /* if $SHELL not set, use default */ - exec_shell_name = strdup("/bin/sh"); - } + char *arg = NULL; + static char shell_set = 0; + + if (shell_set) + free(exec_shell_name); + shell_set = 1; + action = GetNextToken(action, &arg); + if (arg) { + exec_shell_name = xstrdup(arg); + } else { + if (getenv("SHELL")) + exec_shell_name = xstrdup(getenv("SHELL")); + else + exec_shell_name = xstrdup("/bin/sh"); + } } -void exec_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +exec_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *cmd=NULL; - - /* if it doesn't already have an 'exec' as the first word, add that - * to keep down number of procs started */ - /* need to parse string better to do this right though, so not doing this - for now... */ -#if 0 - if (strncasecmp(action,"exec",4)!=0) - { - cmd = (char *)safemalloc(strlen(action)+6); - strcpy(cmd,"exec "); - strcat(cmd,action); - } - else -#endif - { - cmd = strdup(action); - } - if (!cmd) - return; - /* Use to grab the pointer here, but the fork guarantees that - * we wont be held up waiting for the function to finish, - * so the pointer-gram just caused needless delay and flashing - * on the screen */ - /* Thought I'd try vfork and _exit() instead of regular fork(). - * The man page says that its better. */ - /* Not everyone has vfork! */ - if (!(fork())) /* child process */ - { - if (execl(exec_shell_name, exec_shell_name, "-c", cmd, (char *)NULL)==-1) - { - fvwm_msg(ERR,"exec_function","execl failed (%s)",strerror(errno)); - exit(100); - } - } - free(cmd); - return; + char *cmd = NULL; + + { + cmd = strdup(action); + } + if (!cmd) + return; + /* Use to grab the pointer here, but the fork guarantees that + * we wont be held up waiting for the function to finish, + * so the pointer-gram just caused needless delay and flashing + * on the screen */ + /* Thought I'd try vfork and _exit() instead of regular fork(). + * The man page says that its better. */ + /* Not everyone has vfork! */ + if (!(fork())) { /* child process */ + if (execl(exec_shell_name, exec_shell_name, "-c", cmd, + (char *)NULL) == -1) { + fvwm_msg(ERR, "exec_function", "execl failed (%s)", + strerror(errno)); + _exit(100); + } + } + free(cmd); + return; } -void refresh_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +refresh_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - XSetWindowAttributes attributes; - unsigned long valuemask; - -#if 0 - valuemask = (CWBackPixel); - attributes.background_pixel = 0; -#else /* CKH - i'd like to try this a little differently (clear window)*/ - valuemask = CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; - attributes.override_redirect = True; - attributes.save_under = False; - attributes.background_pixmap = None; -#endif - attributes.backing_store = NotUseful; - w = XCreateWindow (dpy, Scr.Root, 0, 0, - (unsigned int) Scr.MyDisplayWidth, - (unsigned int) Scr.MyDisplayHeight, - (unsigned int) 0, - CopyFromParent, (unsigned int) CopyFromParent, - (Visual *) CopyFromParent, valuemask, - &attributes); - XMapWindow (dpy, w); - XDestroyWindow (dpy, w); - XFlush (dpy); + XSetWindowAttributes attributes; + unsigned long valuemask; + + valuemask = + CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; + attributes.override_redirect = True; + attributes.save_under = False; + attributes.background_pixmap = None; + attributes.backing_store = NotUseful; + w = XCreateWindow(dpy, Scr.Root, 0, 0, (unsigned int)Scr.MyDisplayWidth, + (unsigned int)Scr.MyDisplayHeight, (unsigned int)0, CopyFromParent, + (unsigned int)CopyFromParent, (Visual *)CopyFromParent, valuemask, + &attributes); + XMapWindow(dpy, w); + XDestroyWindow(dpy, w); + XFlush(dpy); } - -void refresh_win_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +refresh_win_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - XSetWindowAttributes attributes; - unsigned long valuemask; - - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; - - valuemask = CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; - attributes.override_redirect = True; - attributes.save_under = False; - attributes.background_pixmap = None; - attributes.backing_store = NotUseful; - w = XCreateWindow (dpy, - (context == C_ICON)?(tmp_win->icon_w):(tmp_win->frame), - 0, 0, - (unsigned int) Scr.MyDisplayWidth, - (unsigned int) Scr.MyDisplayHeight, - (unsigned int) 0, - CopyFromParent, (unsigned int) CopyFromParent, - (Visual *) CopyFromParent, valuemask, - &attributes); - XMapWindow (dpy, w); - XDestroyWindow (dpy, w); - XFlush (dpy); -} + XSetWindowAttributes attributes; + unsigned long valuemask; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; -void stick_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) -{ - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; - - if(tmp_win->flags & STICKY) - { - tmp_win->flags &= ~STICKY; - } - else - { - tmp_win->flags |=STICKY; - move_window_doit(eventp, w, tmp_win, context, "", Module, FALSE, TRUE); - } - BroadcastConfig(M_CONFIGURE_WINDOW,tmp_win); - SetTitleBar(tmp_win,(Scr.Hilite==tmp_win),True); + valuemask = + CWOverrideRedirect | CWBackingStore | CWSaveUnder | CWBackPixmap; + attributes.override_redirect = True; + attributes.save_under = False; + attributes.background_pixmap = None; + attributes.backing_store = NotUseful; + w = XCreateWindow(dpy, + (context == C_ICON) ? (tmp_win->icon_w) : (tmp_win->frame), 0, 0, + (unsigned int)Scr.MyDisplayWidth, (unsigned int)Scr.MyDisplayHeight, + (unsigned int)0, CopyFromParent, (unsigned int)CopyFromParent, + (Visual *)CopyFromParent, valuemask, &attributes); + XMapWindow(dpy, w); + XDestroyWindow(dpy, w); + XFlush(dpy); } -void wait_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +stick_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Bool done = False; - extern FvwmWindow *Tmp_win; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - while(!done) - { -#if 0 - GrabEm(WAIT); -#endif - if(My_XNextEvent(dpy, &Event)) - { - DispatchEvent (); - if(Event.type == MapNotify) - { - if((Tmp_win)&&(matchWildcards(action,Tmp_win->name)==True)) - done = True; - if((Tmp_win)&&(Tmp_win->class.res_class)&& - (matchWildcards(action,Tmp_win->class.res_class)==True)) - done = True; - if((Tmp_win)&&(Tmp_win->class.res_name)&& - (matchWildcards(action,Tmp_win->class.res_name)==True)) - done = True; - } - else if (Event.type == KeyPress && - XLookupKeysym(&(Event.xkey),0) == XK_Escape && - Event.xbutton.state & ControlMask) - { - done = 1; - } - } - } -#if 0 - UngrabEm(); -#endif + if (tmp_win->flags & STICKY) { + tmp_win->flags &= ~STICKY; + } else { + tmp_win->flags |= STICKY; + move_window_doit( + eventp, w, tmp_win, context, "", Module, FALSE, TRUE); + } + BroadcastConfig(M_CONFIGURE_WINDOW, tmp_win); + SetTitleBar(tmp_win, (Scr.Hilite == tmp_win), True); } -void flip_focus_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +wait_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; - - /* Reorder the window list */ - FocusOn(tmp_win,TRUE); + Bool done = False; + extern FvwmWindow *Tmp_win; + + while (!done) { + if (My_XNextEvent(dpy, &Event)) { + DispatchEvent(); + if (Event.type == MapNotify) { + if ((Tmp_win) && (matchWildcards(action, + Tmp_win->name) == True)) + done = True; + if ((Tmp_win) && (Tmp_win->class.res_class) && + (matchWildcards(action, + Tmp_win->class.res_class) == True)) + done = True; + if ((Tmp_win) && (Tmp_win->class.res_name) && + (matchWildcards(action, + Tmp_win->class.res_name) == True)) + done = True; + } else if (Event.type == KeyPress && + XLookupKeysym(&(Event.xkey), 0) == + XK_Escape && + Event.xbutton.state & ControlMask) { + done = 1; + } + } + } } - -void focus_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +flip_focus_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - FocusOn(tmp_win,FALSE); + /* Reorder the window list */ + FocusOn(tmp_win, TRUE); } +void +focus_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) +{ + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; + + FocusOn(tmp_win, FALSE); +} -void warp_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +warp_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int val1_unit, val2_unit, n; - int val1, val2; + int val1_unit, val2_unit, n; + int val1, val2; - if (DeferExecution(eventp,&w,&tmp_win,&context,SELECT,ButtonRelease)) - return; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; - n = GetTwoArguments (action, &val1, &val2, &val1_unit, &val2_unit); + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - if (n == 2) - WarpOn (tmp_win, val1, val1_unit, val2, val2_unit); - else - WarpOn (tmp_win, 0, 0, 0, 0); + if (n == 2) + WarpOn(tmp_win, val1, val1_unit, val2, val2_unit); + else + WarpOn(tmp_win, 0, 0, 0, 0); } - -static void menu_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module, - Bool fStaysUp) +static void +menu_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module, Bool fStaysUp) { - extern int menuFromFrameOrWindowOrTitlebar; - MenuRoot *menu; - MenuItem *miExecuteAction = NULL; - MenuOptions mops; - char *menu_name = NULL; - XEvent *teventp; - - mops.flags.allflags = 0; - action = GetNextToken(action,&menu_name); - action = GetMenuOptions(action,w,tmp_win,NULL,&mops); - while (action && *action && isspace(*action)) - action++; - if (action && *action == 0) - action = NULL; - menu = FindPopup(menu_name); - if(menu == NULL) - { - if(menu_name != NULL) - { - fvwm_msg(ERR,"menu_func","No such menu %s",menu_name); - free(menu_name); - } - return; - } - if(menu_name != NULL) - free(menu_name); - menuFromFrameOrWindowOrTitlebar = FALSE; - - if (!action && eventp && eventp->type == KeyPress) - teventp = (XEvent *)1; - else - teventp = eventp; - if ((do_menu(menu, NULL, &miExecuteAction, 0, fStaysUp, teventp, &mops) == - MENU_DOUBLE_CLICKED) && action) - { - ExecuteFunction(action,tmp_win,eventp,context,*Module); - } + extern int menuFromFrameOrWindowOrTitlebar; + MenuRoot *menu; + MenuItem *miExecuteAction = NULL; + MenuOptions mops; + char *menu_name = NULL; + XEvent *teventp; + + mops.flags.allflags = 0; + action = GetNextToken(action, &menu_name); + action = GetMenuOptions(action, w, tmp_win, NULL, &mops); + while (action && *action && isspace(*action)) + action++; + if (action && *action == 0) + action = NULL; + menu = FindPopup(menu_name); + if (menu == NULL) { + if (menu_name != NULL) { + fvwm_msg( + ERR, "menu_func", "No such menu %s", menu_name); + free(menu_name); + } + return; + } + if (menu_name != NULL) + free(menu_name); + menuFromFrameOrWindowOrTitlebar = FALSE; + + if (!action && eventp && eventp->type == KeyPress) + teventp = (XEvent *)1; + else + teventp = eventp; + if ((do_menu(menu, NULL, &miExecuteAction, 0, fStaysUp, teventp, + &mops) == MENU_DOUBLE_CLICKED) && + action) { + ExecuteFunction(action, tmp_win, eventp, context, *Module); + } } /* the function for the "Popup" command */ -void popup_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +popup_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - menu_func(eventp, w, tmp_win, context, action, Module, False); + menu_func(eventp, w, tmp_win, context, action, Module, False); } /* the function for the "Menu" command */ -void staysup_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +staysup_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - menu_func(eventp, w, tmp_win, context, action, Module, True); + menu_func(eventp, w, tmp_win, context, action, Module, True); } - -void quit_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +quit_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - if (master_pid != getpid()) - kill(master_pid, SIGTERM); - Done(0,NULL); + if (master_pid != getpid()) + kill(master_pid, SIGTERM); + Done(0, NULL); } -void quit_screen_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +quit_screen_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Done(0,NULL); + Done(0, NULL); } -void echo_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +echo_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - unsigned int len; - - if (!action) - action = ""; - len = strlen(action); - if (len != 0) - { - if (action[len-1]=='\n') - action[len-1]='\0'; - } - fvwm_msg(INFO,"Echo",action); + unsigned int len; + + if (!action) + action = ""; + len = strlen(action); + if (len != 0) { + if (action[len - 1] == '\n') + action[len - 1] = '\0'; + } + fvwm_msg(INFO, "Echo", action); } -void raiselower_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +raiselower_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - name_list styles; - - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; - if(tmp_win == NULL) - return; - - if((tmp_win == Scr.LastWindowRaised)|| - (tmp_win->flags & VISIBLE)) - { - LowerWindow(tmp_win); - tmp_win->flags &= ~ONTOP; - } - else - { - RaiseWindow(tmp_win); - LookInList(tmp_win, &styles); /* get merged styles */ - if (styles.on_flags & STAYSONTOP_FLAG) { - tmp_win->flags |= ONTOP; - } - KeepOnTop(); - } + name_list styles; + + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; + if (tmp_win == NULL) + return; + + if ((tmp_win == Scr.LastWindowRaised) || (tmp_win->flags & VISIBLE)) { + LowerWindow(tmp_win); + tmp_win->flags &= ~ONTOP; + } else { + RaiseWindow(tmp_win); + LookInList(tmp_win, &styles); /* get merged styles */ + if (styles.on_flags & STAYSONTOP_FLAG) { + tmp_win->flags |= ONTOP; + } + KeepOnTop(); + } } -void SetEdgeScroll(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetEdgeScroll(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val1, val2, val1_unit,val2_unit,n; - - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - if(n != 2) - { - fvwm_msg(ERR,"SetEdgeScroll","EdgeScroll requires two arguments"); - return; - } - - /* - * if edgescroll >1000 and < 100000m - * wrap at edges of desktop (a "spherical" desktop) - */ - if (val1 >= 1000) - { - val1 /= 1000; - Scr.flags |= EdgeWrapX; - } - else - { - Scr.flags &= ~EdgeWrapX; - } - if (val2 >= 1000) - { - val2 /= 1000; - Scr.flags |= EdgeWrapY; - } - else - { - Scr.flags &= ~EdgeWrapY; - } - - Scr.EdgeScrollX = val1*val1_unit/100; - Scr.EdgeScrollY = val2*val2_unit/100; - - checkPanFrames(); + int val1, val2, val1_unit, val2_unit, n; + + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + if (n != 2) { + fvwm_msg( + ERR, "SetEdgeScroll", "EdgeScroll requires two arguments"); + return; + } + + /* + * if edgescroll >1000 and < 100000m + * wrap at edges of desktop (a "spherical" desktop) + */ + if (val1 >= 1000) { + val1 /= 1000; + Scr.flags |= EdgeWrapX; + } else { + Scr.flags &= ~EdgeWrapX; + } + if (val2 >= 1000) { + val2 /= 1000; + Scr.flags |= EdgeWrapY; + } else { + Scr.flags &= ~EdgeWrapY; + } + + Scr.EdgeScrollX = val1 * val1_unit / 100; + Scr.EdgeScrollY = val2 * val2_unit / 100; + + checkPanFrames(); } -void SetEdgeResistance(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetEdgeResistance(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2]; + int val[2]; - if (GetIntegerArguments(action, NULL, val, 2) != 2) - { - fvwm_msg(ERR,"SetEdgeResistance","EdgeResistance requires two arguments"); - return; - } + if (GetIntegerArguments(action, NULL, val, 2) != 2) { + fvwm_msg(ERR, "SetEdgeResistance", + "EdgeResistance requires two arguments"); + return; + } - Scr.ScrollResistance = val[0]; - Scr.MoveResistance = val[1]; + Scr.ScrollResistance = val[0]; + Scr.MoveResistance = val[1]; } -void SetColormapFocus(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetColormapFocus(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - if (MatchToken(action,"FollowsFocus")) - { - Scr.ColormapFocus = COLORMAP_FOLLOWS_FOCUS; - } - else if (MatchToken(action,"FollowsMouse")) - { - Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; - } - else - { - fvwm_msg(ERR,"SetColormapFocus", - "ColormapFocus requires 1 arg: FollowsFocus or FollowsMouse"); - return; - } + if (MatchToken(action, "FollowsFocus")) { + Scr.ColormapFocus = COLORMAP_FOLLOWS_FOCUS; + } else if (MatchToken(action, "FollowsMouse")) { + Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; + } else { + fvwm_msg(ERR, "SetColormapFocus", + "ColormapFocus requires 1 arg: FollowsFocus or " + "FollowsMouse"); + return; + } } -void SetClick(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetClick(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int val; - - if(GetIntegerArguments(action, NULL, &val, 1) != 1) - { - Scr.ClickTime = DEFAULT_CLICKTIME; - } - else - { - Scr.ClickTime = (val < 0)? 0 : val; - } - - /* Use a negative value during startup and change sign afterwards. This - * speeds things up quite a bit. */ - if (fFvwmInStartup) - Scr.ClickTime = -Scr.ClickTime; -} + int val; + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + Scr.ClickTime = DEFAULT_CLICKTIME; + } else { + Scr.ClickTime = (val < 0) ? 0 : val; + } -void SetSnapAttraction(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) -{ - int val; - char *token; - - if(GetIntegerArguments(action, &action, &val, 1) != 1) - { - fvwm_msg(ERR,"SetSnapAttraction", - "SnapAttraction requires at least 1 argument"); - return; - } - Scr.SnapAttraction = val; - - action = GetNextToken(action, &token); - if(token == NULL) - { - return; - } - - if(StrEquals(token,"All")) - { Scr.SnapMode = 0; } - if(StrEquals(token,"SameType")) - { Scr.SnapMode = 1; } - if(StrEquals(token,"Icons")) - { Scr.SnapMode = 2; } - if(StrEquals(token,"Windows")) - { Scr.SnapMode = 3; } - - free(token); + /* Use a negative value during startup and change sign afterwards. This + * speeds things up quite a bit. */ + if (fFvwmInStartup) + Scr.ClickTime = -Scr.ClickTime; } -void SetSnapGrid(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetSnapAttraction(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2]; - - if(GetIntegerArguments(action, NULL, &val[0], 2) != 2) - { - fvwm_msg(ERR,"SetSnapGrid","SetSnapGrid requires 2 arguments"); - return; - } - - Scr.SnapGridX = val[0]; - if(Scr.SnapGridX < 1) - { Scr.SnapGridX = 1;} - Scr.SnapGridY = val[1]; - if(Scr.SnapGridY < 1) - { Scr.SnapGridY = 1;} -} + int val; + char *token; + + if (GetIntegerArguments(action, &action, &val, 1) != 1) { + fvwm_msg(ERR, "SetSnapAttraction", + "SnapAttraction requires at least 1 argument"); + return; + } + Scr.SnapAttraction = val; + + action = GetNextToken(action, &token); + if (token == NULL) { + return; + } + + if (StrEquals(token, "All")) { + Scr.SnapMode = 0; + } + if (StrEquals(token, "SameType")) { + Scr.SnapMode = 1; + } + if (StrEquals(token, "Icons")) { + Scr.SnapMode = 2; + } + if (StrEquals(token, "Windows")) { + Scr.SnapMode = 3; + } + free(token); +} -void SetXOR(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetSnapGrid(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val; - XGCValues gcv; - unsigned long gcm; - - if(GetIntegerArguments(action, NULL, &val, 1) != 1) - { - fvwm_msg(ERR,"SetXOR","XORValue requires 1 argument"); - return; - } - - gcm = GCFunction|GCLineWidth|GCForeground|GCSubwindowMode; - gcv.function = GXxor; - gcv.line_width = 0; - /* use passed in value, or try to calculate appropriate value if 0 */ - /* ctwm method: */ - /* - gcv.foreground = (val1)?(val1):((((unsigned long) 1) << Scr.d_depth) - 1); - */ - /* Xlib programming manual suggestion: */ - gcv.foreground = (val)? - (val):(BlackPixel(dpy,Scr.screen) ^ WhitePixel(dpy,Scr.screen)); - gcv.subwindow_mode = IncludeInferiors; - if (Scr.DrawGC) - XFreeGC(dpy, Scr.DrawGC); - Scr.DrawGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + int val[2]; + + if (GetIntegerArguments(action, NULL, &val[0], 2) != 2) { + fvwm_msg( + ERR, "SetSnapGrid", "SetSnapGrid requires 2 arguments"); + return; + } + + Scr.SnapGridX = val[0]; + if (Scr.SnapGridX < 1) { + Scr.SnapGridX = 1; + } + Scr.SnapGridY = val[1]; + if (Scr.SnapGridY < 1) { + Scr.SnapGridY = 1; + } } -void SetOpaque(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetXOR(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int val; + int val; + XGCValues gcv; + unsigned long gcm; - if(GetIntegerArguments(action, NULL, &val, 1) != 1) - { - fvwm_msg(ERR,"SetOpaque","OpaqueMoveSize requires 1 argument"); - return; - } + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + fvwm_msg(ERR, "SetXOR", "XORValue requires 1 argument"); + return; + } - Scr.OpaqueSize = val; + gcm = GCFunction | GCLineWidth | GCForeground | GCSubwindowMode; + gcv.function = GXxor; + gcv.line_width = 0; + /* use passed in value, or try to calculate appropriate value if 0 */ + /* ctwm method: */ + /* + gcv.foreground = (val1)?(val1):((((unsigned long) 1) << Scr.d_depth) - + 1); + */ + /* Xlib programming manual suggestion: */ + gcv.foreground = + (val) ? (val) : + (BlackPixel(dpy, Scr.screen) ^ WhitePixel(dpy, Scr.screen)); + gcv.subwindow_mode = IncludeInferiors; + if (Scr.DrawGC) + XFreeGC(dpy, Scr.DrawGC); + Scr.DrawGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); } +void +SetOpaque(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) +{ + int val; + + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + fvwm_msg( + ERR, "SetOpaque", "OpaqueMoveSize requires 1 argument"); + return; + } + + Scr.OpaqueSize = val; +} -void SetDeskSize(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetDeskSize(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2]; + int val[2]; - if (GetIntegerArguments(action, NULL, val, 2) != 2 && - GetRectangleArguments(action, &val[0], &val[1]) != 2) - { - fvwm_msg(ERR,"SetDeskSize","DesktopSize requires two arguments"); - return; - } + if (GetIntegerArguments(action, NULL, val, 2) != 2 && + GetRectangleArguments(action, &val[0], &val[1]) != 2) { + fvwm_msg( + ERR, "SetDeskSize", "DesktopSize requires two arguments"); + return; + } - Scr.VxMax = (val[0] <= 0)? 0: val[0]*Scr.MyDisplayWidth-Scr.MyDisplayWidth; - Scr.VyMax = (val[1] <= 0)? 0: val[1]*Scr.MyDisplayHeight-Scr.MyDisplayHeight; - BroadcastPacket(M_NEW_PAGE, 5, - Scr.Vx, Scr.Vy, Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); + Scr.VxMax = (val[0] <= 0) ? + 0 : + val[0] * Scr.MyDisplayWidth - Scr.MyDisplayWidth; + Scr.VyMax = (val[1] <= 0) ? + 0 : + val[1] * Scr.MyDisplayHeight - Scr.MyDisplayHeight; + BroadcastPacket(M_NEW_PAGE, 5, Scr.Vx, Scr.Vy, Scr.CurrentDesk, + Scr.VxMax, Scr.VyMax); - checkPanFrames(); + checkPanFrames(); } #ifdef XPM @@ -1363,975 +1325,946 @@ char *PixmapPath = FVWM_ICONDIR; #else char *PixmapPath = ""; #endif -void setPixmapPath(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +setPixmapPath(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { #ifdef XPM - static char *ptemp = NULL; - char *tmp; + static char *ptemp = NULL; + char *tmp; - if(ptemp == NULL) - ptemp = PixmapPath; + if (ptemp == NULL) + ptemp = PixmapPath; - if((PixmapPath != ptemp)&&(PixmapPath != NULL)) - free(PixmapPath); - tmp = stripcpy(action); - PixmapPath = envDupExpand(tmp, 0); - free(tmp); + if ((PixmapPath != ptemp) && (PixmapPath != NULL)) + free(PixmapPath); + tmp = stripcpy(action); + PixmapPath = envDupExpand(tmp, 0); + free(tmp); #else - fvwm_msg(ERR, "setPixmapPath", - "XPM support has not been included in this version of Fvwm2."); + fvwm_msg(ERR, "setPixmapPath", + "XPM support has not been included in this version of Fvwm2."); #endif } char *IconPath = FVWM_ICONDIR; -void setIconPath(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +setIconPath(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - static char *ptemp = NULL; - char *tmp; + static char *ptemp = NULL; + char *tmp; - if(ptemp == NULL) - ptemp = IconPath; + if (ptemp == NULL) + ptemp = IconPath; - if((IconPath != ptemp)&&(IconPath != NULL)) - free(IconPath); - tmp = stripcpy(action); - IconPath = envDupExpand(tmp, 0); - free(tmp); + if ((IconPath != ptemp) && (IconPath != NULL)) + free(IconPath); + tmp = stripcpy(action); + IconPath = envDupExpand(tmp, 0); + free(tmp); } char *ModulePath = FVWM_MODULEDIR; -void setModulePath(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +setModulePath(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - static int need_to_free = 0; - char *tmp; + static int need_to_free = 0; + char *tmp; - if ( need_to_free && ModulePath != NULL ) - free(ModulePath); + if (need_to_free && ModulePath != NULL) + free(ModulePath); - tmp = stripcpy(action); - ModulePath = envDupExpand(tmp, 0); - need_to_free = 1; - free(tmp); + tmp = stripcpy(action); + ModulePath = envDupExpand(tmp, 0); + need_to_free = 1; + free(tmp); } - -void SetHiColor(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetHiColor(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - XGCValues gcv; - unsigned long gcm; - char *hifore=NULL, *hiback=NULL; - FvwmWindow *hilight; + XGCValues gcv; + unsigned long gcm; + char *hifore = NULL, *hiback = NULL; + FvwmWindow *hilight; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action,&hifore); - GetNextToken(action,&hiback); - if(Scr.d_depth > 2) - { - if(hifore != NULL) - { - fl->HiColors.fore = GetColor(hifore); - } - if(hiback != NULL) - { - fl->HiColors.back = GetColor(hiback); - } - fl->HiRelief.back = GetShadow(fl->HiColors.back); - fl->HiRelief.fore = GetHilite(fl->HiColors.back); - } - else - { - fl->HiColors.back = GetColor("white"); - fl->HiColors.fore = GetColor("black"); - fl->HiRelief.back = GetColor("black"); - fl->HiRelief.fore = GetColor("white"); - } - if (hifore) free(hifore); - if (hiback) free(hiback); - gcm = GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth|GCForeground| - GCBackground; - gcv.foreground = fl->HiRelief.fore; - gcv.background = fl->HiRelief.back; - gcv.fill_style = FillSolid; - gcv.plane_mask = AllPlanes; - gcv.function = GXcopy; - gcv.graphics_exposures = False; - gcv.line_width = 0; - if(fl->HiReliefGC != NULL) - { - XFreeGC(dpy,fl->HiReliefGC); - } - fl->HiReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = fl->HiRelief.back; - gcv.background = fl->HiRelief.fore; - if(fl->HiShadowGC != NULL) - { - XFreeGC(dpy,fl->HiShadowGC); - } - fl->HiShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if((Scr.flags & WindowsCaptured)&&(Scr.Hilite != NULL)) - { - hilight = Scr.Hilite; - SetBorder(Scr.Hilite,False,True,True,None); - SetBorder(hilight,True,True,True,None); - } -} + action = GetNextToken(action, &hifore); + GetNextToken(action, &hiback); + if (Scr.d_depth > 2) { + if (hifore != NULL) { + fl->HiColors.fore = GetColor(hifore); + } + if (hiback != NULL) { + fl->HiColors.back = GetColor(hiback); + } + fl->HiRelief.back = GetShadow(fl->HiColors.back); + fl->HiRelief.fore = GetHilite(fl->HiColors.back); + } else { + fl->HiColors.back = GetColor("white"); + fl->HiColors.fore = GetColor("black"); + fl->HiRelief.back = GetColor("black"); + fl->HiRelief.fore = GetColor("white"); + } + if (hifore) + free(hifore); + if (hiback) + free(hiback); + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | GCLineWidth | + GCForeground | GCBackground; + gcv.foreground = fl->HiRelief.fore; + gcv.background = fl->HiRelief.back; + gcv.fill_style = FillSolid; + gcv.plane_mask = AllPlanes; + gcv.function = GXcopy; + gcv.graphics_exposures = False; + gcv.line_width = 0; + if (fl->HiReliefGC != NULL) { + XFreeGC(dpy, fl->HiReliefGC); + } + fl->HiReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + gcv.foreground = fl->HiRelief.back; + gcv.background = fl->HiRelief.fore; + if (fl->HiShadowGC != NULL) { + XFreeGC(dpy, fl->HiShadowGC); + } + fl->HiShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); -void SafeDefineCursor(Window w, Cursor cursor) -{ - if (w) XDefineCursor(dpy,w,cursor); + if ((Scr.flags & WindowsCaptured) && (Scr.Hilite != NULL)) { + hilight = Scr.Hilite; + SetBorder(Scr.Hilite, False, True, True, None); + SetBorder(hilight, True, True, True, None); + } } -void CursorStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SafeDefineCursor(Window w, Cursor cursor) { - char *cname=NULL, *newcursor=NULL; - int index,nc,i; - FvwmWindow *fw; - MenuRoot *mr; - - action = GetNextToken(action,&cname); - action = GetNextToken(action,&newcursor); - if (!cname || !newcursor) - { - fvwm_msg(ERR,"CursorStyle","Bad cursor style"); - if (cname) - free(cname); - if (newcursor) - free(newcursor); - return; - } - if (StrEquals("POSITION",cname)) index = POSITION; - else if (StrEquals("DEFAULT",cname)) index = DEFAULT; - else if (StrEquals("SYS",cname)) index = SYS; - else if (StrEquals("TITLE",cname)) index = TITLE_CURSOR; - else if (StrEquals("MOVE",cname)) index = MOVE; - else if (StrEquals("MENU",cname)) index = MENU; - else if (StrEquals("WAIT",cname)) index = WAIT; - else if (StrEquals("SELECT",cname)) index = SELECT; - else if (StrEquals("DESTROY",cname)) index = DESTROY; - else if (StrEquals("LEFT",cname)) index = LEFT; - else if (StrEquals("RIGHT",cname)) index = RIGHT; - else if (StrEquals("TOP",cname)) index = TOP; - else if (StrEquals("BOTTOM",cname)) index = BOTTOM; - else if (StrEquals("TOP_LEFT",cname)) index = TOP_LEFT; - else if (StrEquals("TOP_RIGHT",cname)) index = TOP_RIGHT; - else if (StrEquals("BOTTOM_LEFT",cname)) index = BOTTOM_LEFT; - else if (StrEquals("BOTTOM_RIGHT",cname)) index = BOTTOM_RIGHT; - else - { - fvwm_msg(ERR,"CursorStyle","Unknown cursor name %s",cname); - free(cname); - free(newcursor); - return; - } - nc = atoi(newcursor); - free(cname); - if ((nc < 0) || (nc >= XC_num_glyphs) || ((nc % 2) != 0)) - { - fvwm_msg(ERR, "CursorStyle", "Bad cursor number %s", newcursor); - free(newcursor); - return; - } - free(newcursor); - - /* replace the cursor defn */ - if (Scr.FvwmCursors[index]) XFreeCursor(dpy,Scr.FvwmCursors[index]); - Scr.FvwmCursors[index] = XCreateFontCursor(dpy,nc); - - /* redefine all the windows using cursors */ - fw = Scr.FvwmRoot.next; - while(fw != NULL) - { - for (i=0;i<4;i++) - { - SafeDefineCursor(fw->corners[i],Scr.FvwmCursors[TOP_LEFT+i]); - SafeDefineCursor(fw->sides[i],Scr.FvwmCursors[TOP+i]); - } - for (i=0;ileft_w[i],Scr.FvwmCursors[SYS]); - } - for (i=0;iright_w[i],Scr.FvwmCursors[SYS]); - } - SafeDefineCursor(fw->title_w, Scr.FvwmCursors[TITLE_CURSOR]); - fw = fw->next; - } - - /* Do the menus for good measure */ - mr = Scr.menus.all; - while(mr != NULL) - { - SafeDefineCursor(mr->w,Scr.FvwmCursors[MENU]); - mr = mr->next; - } + if (w) + XDefineCursor(dpy, w, cursor); } -MenuStyle *FindMenuStyle(char *name) +void +CursorStyle(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuStyle *ms = Scr.menus.DefaultStyle; - - while(ms != NULL ) - { - if(strcasecmp(ms->name,name)==0) - return ms; - ms = ms->next; - } - return NULL; -} + char *cname = NULL, *newcursor = NULL; + int index, nc, i; + FvwmWindow *fw; + MenuRoot *mr; + + action = GetNextToken(action, &cname); + action = GetNextToken(action, &newcursor); + if (!cname || !newcursor) { + fvwm_msg(ERR, "CursorStyle", "Bad cursor style"); + if (cname) + free(cname); + if (newcursor) + free(newcursor); + return; + } + if (StrEquals("POSITION", cname)) + index = POSITION; + else if (StrEquals("DEFAULT", cname)) + index = DEFAULT; + else if (StrEquals("SYS", cname)) + index = SYS; + else if (StrEquals("TITLE", cname)) + index = TITLE_CURSOR; + else if (StrEquals("MOVE", cname)) + index = MOVE; + else if (StrEquals("MENU", cname)) + index = MENU; + else if (StrEquals("WAIT", cname)) + index = WAIT; + else if (StrEquals("SELECT", cname)) + index = SELECT; + else if (StrEquals("DESTROY", cname)) + index = DESTROY; + else if (StrEquals("LEFT", cname)) + index = LEFT; + else if (StrEquals("RIGHT", cname)) + index = RIGHT; + else if (StrEquals("TOP", cname)) + index = TOP; + else if (StrEquals("BOTTOM", cname)) + index = BOTTOM; + else if (StrEquals("TOP_LEFT", cname)) + index = TOP_LEFT; + else if (StrEquals("TOP_RIGHT", cname)) + index = TOP_RIGHT; + else if (StrEquals("BOTTOM_LEFT", cname)) + index = BOTTOM_LEFT; + else if (StrEquals("BOTTOM_RIGHT", cname)) + index = BOTTOM_RIGHT; + else { + fvwm_msg(ERR, "CursorStyle", "Unknown cursor name %s", cname); + free(cname); + free(newcursor); + return; + } + nc = atoi(newcursor); + free(cname); + if ((nc < 0) || (nc >= XC_num_glyphs) || ((nc % 2) != 0)) { + fvwm_msg(ERR, "CursorStyle", "Bad cursor number %s", newcursor); + free(newcursor); + return; + } + free(newcursor); + + /* replace the cursor defn */ + if (Scr.FvwmCursors[index]) + XFreeCursor(dpy, Scr.FvwmCursors[index]); + Scr.FvwmCursors[index] = XCreateFontCursor(dpy, nc); + + /* redefine all the windows using cursors */ + fw = Scr.FvwmRoot.next; + while (fw != NULL) { + for (i = 0; i < 4; i++) { + SafeDefineCursor( + fw->corners[i], Scr.FvwmCursors[TOP_LEFT + i]); + SafeDefineCursor( + fw->sides[i], Scr.FvwmCursors[TOP + i]); + } + for (i = 0; i < Scr.nr_left_buttons; i++) { + SafeDefineCursor(fw->left_w[i], Scr.FvwmCursors[SYS]); + } + for (i = 0; i < Scr.nr_right_buttons; i++) { + SafeDefineCursor(fw->right_w[i], Scr.FvwmCursors[SYS]); + } + SafeDefineCursor(fw->title_w, Scr.FvwmCursors[TITLE_CURSOR]); + fw = fw->next; + } -static void FreeMenuStyle(MenuStyle *ms) -{ - MenuRoot *mr; - MenuStyle *before = Scr.menus.DefaultStyle; - - if (!ms) - return; - mr = Scr.menus.all; - while(mr != NULL) - { - if(mr->ms == ms) - mr->ms = Scr.menus.DefaultStyle; - mr = mr->next; - } - if(ms->look.MenuGC) - XFreeGC(dpy, ms->look.MenuGC); - if(ms->look.MenuActiveGC) - XFreeGC(dpy, ms->look.MenuActiveGC); - if(ms->look.MenuActiveBackGC) - XFreeGC(dpy, ms->look.MenuActiveBackGC); - if(ms->look.MenuReliefGC) - XFreeGC(dpy, ms->look.MenuReliefGC); - if(ms->look.MenuStippleGC) - XFreeGC(dpy, ms->look.MenuStippleGC); - if(ms->look.MenuShadowGC) - XFreeGC(dpy, ms->look.MenuShadowGC); - if (ms->look.sidePic) - DestroyPicture(dpy, ms->look.sidePic); - if (ms->look.f.hasSideColor == 1) - FreeColors(&ms->look.sideColor, 1); - - while(before->next != ms) - /* Not too many checks, may segfaults in race conditions */ - before = before->next; - - before->next = ms->next; - free(ms->name); - free(ms); + /* Do the menus for good measure */ + mr = Scr.menus.all; + while (mr != NULL) { + SafeDefineCursor(mr->w, Scr.FvwmCursors[MENU]); + mr = mr->next; + } } -void DestroyMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +MenuStyle * +FindMenuStyle(char *name) { - MenuStyle *ms = NULL; - char *name = NULL; - MenuRoot *mr; - - action = GetNextToken(action,&name); - if (name == NULL) - { - fvwm_msg(ERR,"DestroyMenuStyle", "needs one parameter"); - return; - } - - ms = FindMenuStyle(name); - if(ms == NULL) - fvwm_msg(ERR,"DestroyMenuStyle", "cannot find style %s", name); - else if (ms == Scr.menus.DefaultStyle) - fvwm_msg(ERR,"DestroyMenuStyle", "cannot destroy Default Menu Face"); - else - { - FreeMenuFace(dpy, &ms->look.face); - FreeMenuStyle(ms); - MakeMenus(); - } - free(name); - for (mr = Scr.menus.all; mr != NULL; mr = mr->next) - { - if (mr->ms == ms) - mr->ms = Scr.menus.DefaultStyle; - } - MakeMenus(); -} + MenuStyle *ms = Scr.menus.DefaultStyle; -static void UpdateMenuStyle(MenuStyle *ms) -{ - XGCValues gcv; - unsigned long gcm; - - if (ms->look.pStdFont != NULL && ms->look.pStdFont != &Scr.StdFont) - { - ms->look.pStdFont->y = ms->look.pStdFont->font->ascent; - ms->look.pStdFont->height = - ms->look.pStdFont->font->ascent + - ms->look.pStdFont->font->descent; - } - ms->look.EntryHeight = - ms->look.pStdFont->height + HEIGHT_EXTRA; - - /* calculate colors based on foreground */ - if (!ms->look.f.hasActiveFore) - ms->look.MenuActiveColors.fore=ms->look.MenuColors.fore; - - /* calculate colors based on background */ - if (!ms->look.f.hasActiveBack) - ms->look.MenuActiveColors.back = ms->look.MenuColors.back; - if (!ms->look.f.hasStippleFore) - ms->look.MenuStippleColors.fore = ms->look.MenuColors.back; - if(Scr.d_depth > 2) { /* if not black and white */ - ms->look.MenuRelief.back = GetShadow(ms->look.MenuColors.back); - ms->look.MenuRelief.fore = GetHilite(ms->look.MenuColors.back); - } else { /* black and white */ - ms->look.MenuRelief.back = GetColor("black"); - ms->look.MenuRelief.fore = GetColor("white"); - } - ms->look.MenuStippleColors.back = ms->look.MenuColors.back; - - /* make GC's */ - gcm = GCFunction|GCPlaneMask|GCFont|GCGraphicsExposures| - GCLineWidth|GCForeground|GCBackground; - gcv.fill_style = FillSolid; - gcv.font = ms->look.pStdFont->font->fid; - gcv.plane_mask = AllPlanes; - gcv.function = GXcopy; - gcv.graphics_exposures = False; - gcv.line_width = 0; - - gcv.foreground = ms->look.MenuRelief.fore; - gcv.background = ms->look.MenuRelief.back; - if(ms->look.MenuReliefGC != NULL) - XFreeGC(dpy,ms->look.MenuReliefGC); - ms->look.MenuReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = ms->look.MenuRelief.back; - gcv.background = ms->look.MenuRelief.fore; - if(ms->look.MenuShadowGC != NULL) - XFreeGC(dpy,ms->look.MenuShadowGC); - ms->look.MenuShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = (ms->look.f.hasActiveBack) ? - ms->look.MenuActiveColors.back : ms->look.MenuRelief.back; - gcv.background = (ms->look.f.hasActiveFore) ? - ms->look.MenuActiveColors.fore : ms->look.MenuRelief.fore; - if(ms->look.MenuActiveBackGC != NULL) - XFreeGC(dpy,ms->look.MenuActiveBackGC); - ms->look.MenuActiveBackGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = ms->look.MenuColors.fore; - gcv.background = ms->look.MenuColors.back; - if(ms->look.MenuGC != NULL) - XFreeGC(dpy,ms->look.MenuGC); - ms->look.MenuGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = ms->look.MenuActiveColors.fore; - gcv.background = ms->look.MenuActiveColors.back; - if(ms->look.MenuActiveGC != NULL) - XFreeGC(dpy,ms->look.MenuActiveGC); - ms->look.MenuActiveGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - if(ms->look.MenuStippleGC != NULL) - XFreeGC(dpy,ms->look.MenuStippleGC); - if(Scr.d_depth < 2) - { - gcv.fill_style = FillStippled; - gcv.stipple = Scr.gray_bitmap; - gcm=GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth| - GCForeground|GCBackground|GCFont|GCStipple|GCFillStyle; - ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcm=GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth| - GCForeground|GCBackground|GCFont; - gcv.fill_style = FillSolid; - } - else - { - gcv.foreground = ms->look.MenuStippleColors.fore; - gcv.background = ms->look.MenuStippleColors.back; - ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - } + while (ms != NULL) { + if (strcasecmp(ms->name, name) == 0) + return ms; + ms = ms->next; + } + return NULL; } - -static int GetMenuStyleIndex(char *option) +static void +FreeMenuStyle(MenuStyle *ms) { - char *optlist[] = { - "fvwm", "mwm", "win", - "Foreground", "Background", "Greyed", - "HilightBack", "HilightBackOff", - "ActiveFore", "ActiveForeOff", - "Hilight3DThick", "Hilight3DThin", "Hilight3DOff", - "Animation", "AnimationOff", - "Font", - "MenuFace", - "PopupDelay", "PopupOffset", - "TitleWarp", "TitleWarpOff", - "TitleUnderlines0", "TitleUnderlines1", "TitleUnderlines2", - "SeparatorsLong", "SeparatorsShort", - "TrianglesSolid", "TrianglesRelief", - "PopupImmediately", "PopupDelayed", - "DoubleClickTime", - "SidePic", "SideColor", - NULL - }; - return GetTokenIndex(option, optlist, 0, NULL); + MenuRoot *mr; + MenuStyle *before = Scr.menus.DefaultStyle; + + if (!ms) + return; + mr = Scr.menus.all; + while (mr != NULL) { + if (mr->ms == ms) + mr->ms = Scr.menus.DefaultStyle; + mr = mr->next; + } + if (ms->look.MenuGC) + XFreeGC(dpy, ms->look.MenuGC); + if (ms->look.MenuActiveGC) + XFreeGC(dpy, ms->look.MenuActiveGC); + if (ms->look.MenuActiveBackGC) + XFreeGC(dpy, ms->look.MenuActiveBackGC); + if (ms->look.MenuReliefGC) + XFreeGC(dpy, ms->look.MenuReliefGC); + if (ms->look.MenuStippleGC) + XFreeGC(dpy, ms->look.MenuStippleGC); + if (ms->look.MenuShadowGC) + XFreeGC(dpy, ms->look.MenuShadowGC); + if (ms->look.sidePic) + DestroyPicture(dpy, ms->look.sidePic); + if (ms->look.f.hasSideColor == 1) + FreeColors(&ms->look.sideColor, 1); + + while (before != NULL && before->next != ms) + before = before->next; + + before->next = ms->next; + free(ms->name); + free(ms); } -static void NewMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +DestroyMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *name; - char *option = NULL; - char *optstring = NULL; - char *nextarg; - char *args; - char *arg1; - MenuStyle *ms; - MenuStyle *tmpms; - Bool is_initialised = True; - Bool gc_changed = False; - Bool is_default_style = False; - int val[2]; - int n; - XFontStruct *xfs = NULL; - int i; - - action = GetNextToken(action, &name); - if (!name) - { - fvwm_msg(ERR,"NewMenuStyle", "error in %s style specification",action); - return; - } - - tmpms = (MenuStyle *)safemalloc(sizeof(MenuStyle)); - memset(tmpms, 0, sizeof(MenuStyle)); - ms = FindMenuStyle(name); - if (ms != NULL) - { - /* copy the structure over our temporary menu face. */ - memcpy(tmpms, ms, sizeof(MenuStyle)); - if (ms == Scr.menus.DefaultStyle) - is_default_style = True; - free(name); - } - else - { - tmpms->name = name; - is_initialised = False; - } - - /* Parse the options. */ - while (action && *action) - { - if (is_initialised == False) - { - /* some default configuration goes here for the new menu style */ - tmpms->look.MenuColors.back = GetColor("white"); - tmpms->look.MenuColors.fore = GetColor("black"); - tmpms->look.pStdFont = &Scr.StdFont; - tmpms->look.face.type = SimpleMenu; - tmpms->look.f.hasActiveFore = 0; - tmpms->look.f.hasActiveBack = 0; - gc_changed = True; - option = "fvwm"; - } - else - { - /* Read next option specification (delimited by a comma or \0). */ - args = action; - action = GetQuotedString(action, &optstring, ",", NULL, NULL, NULL); - if (!optstring) - break; - - args = GetNextToken(optstring, &option); - if (!option) - { - free(optstring); - break; - } - nextarg = GetNextToken(args, &arg1); - } - - switch((i = GetMenuStyleIndex(option))) - { - case 0: /* fvwm */ - case 1: /* mwm */ - case 2: /* win */ - if (i == 0) { - tmpms->feel.PopupOffsetPercent = 67; - tmpms->feel.PopupOffsetAdd = 0; - tmpms->feel.f.PopupImmediately = 0; - tmpms->feel.f.TitleWarp = 1; - tmpms->look.ReliefThickness = 1; - tmpms->look.TitleUnderlines = 1; - tmpms->look.f.LongSeparators = 0; - tmpms->look.f.TriangleRelief = 1; - tmpms->look.f.Hilight = 0; - } else if (i == 1) { - tmpms->feel.PopupOffsetPercent = 100; - tmpms->feel.PopupOffsetAdd = -3; - tmpms->feel.f.PopupImmediately = 1; - tmpms->feel.f.TitleWarp = 0; - tmpms->look.ReliefThickness = 2; - tmpms->look.TitleUnderlines = 2; - tmpms->look.f.LongSeparators = 1; - tmpms->look.f.TriangleRelief = 1; - tmpms->look.f.Hilight = 0; - } else /* i == 2 */ { - tmpms->feel.PopupOffsetPercent = 100; - tmpms->feel.PopupOffsetAdd = -5; - tmpms->feel.f.PopupImmediately = 1; - tmpms->feel.f.TitleWarp = 0; - tmpms->look.ReliefThickness = 0; - tmpms->look.TitleUnderlines = 1; - tmpms->look.f.LongSeparators = 0; - tmpms->look.f.TriangleRelief = 0; - tmpms->look.f.Hilight = 1; - } - - /* common settings */ - tmpms->feel.f.Animated = 0; - FreeMenuFace(dpy, &tmpms->look.face); - tmpms->look.face.type = SimpleMenu; - if (tmpms->look.pStdFont && tmpms->look.pStdFont != &Scr.StdFont) - { - XFreeFont(dpy, tmpms->look.pStdFont->font); - free(tmpms->look.pStdFont); - } - tmpms->look.pStdFont = &Scr.StdFont; - gc_changed = True; - if (tmpms->look.f.hasSideColor == 1) - { - FreeColors(&tmpms->look.sideColor, 1); - tmpms->look.f.hasSideColor = 0; - } - tmpms->look.f.hasSideColor = 0; - if (tmpms->look.sidePic) - { - DestroyPicture(dpy, tmpms->look.sidePic); - tmpms->look.sidePic = NULL; - } + MenuStyle *ms = NULL; + char *name = NULL; + MenuRoot *mr; - if (is_initialised == False) - { - /* now begin the real work */ - is_initialised = True; - continue; + action = GetNextToken(action, &name); + if (name == NULL) { + fvwm_msg(ERR, "DestroyMenuStyle", "needs one parameter"); + return; } - break; - case 3: /* Foreground */ - FreeColors(&tmpms->look.MenuColors.fore, 1); - if (arg1) - tmpms->look.MenuColors.fore = GetColor(arg1); - else - tmpms->look.MenuColors.fore = GetColor("black"); - gc_changed = True; - break; - - case 4: /* Background */ - FreeColors(&tmpms->look.MenuColors.back, 1); - if (arg1) - tmpms->look.MenuColors.back = GetColor(arg1); - else - tmpms->look.MenuColors.back = GetColor("grey"); - gc_changed = True; - break; - - case 5: /* Greyed */ - if (tmpms->look.f.hasStippleFore) - FreeColors(&tmpms->look.MenuStippleColors.fore, 1); - if (arg1 == NULL) - { - tmpms->look.f.hasStippleFore = 0; + ms = FindMenuStyle(name); + if (ms == NULL) + fvwm_msg(ERR, "DestroyMenuStyle", "cannot find style %s", name); + else if (ms == Scr.menus.DefaultStyle) + fvwm_msg(ERR, "DestroyMenuStyle", + "cannot destroy Default Menu Face"); + else { + FreeMenuFace(dpy, &ms->look.face); + FreeMenuStyle(ms); + MakeMenus(); } - else - { - tmpms->look.MenuStippleColors.fore = GetColor(arg1); - tmpms->look.f.hasStippleFore = 1; + free(name); + for (mr = Scr.menus.all; mr != NULL; mr = mr->next) { + if (mr->ms == ms) + mr->ms = Scr.menus.DefaultStyle; } - gc_changed = True; - break; + MakeMenus(); +} - case 6: /* HilightBack */ - if (tmpms->look.f.hasActiveBack) - FreeColors(&tmpms->look.MenuActiveColors.back, 1); - if (arg1 == NULL) - { - tmpms->look.f.hasActiveBack = 0; +static void +UpdateMenuStyle(MenuStyle *ms) +{ + XGCValues gcv; + unsigned long gcm; + + if (ms->look.pStdFont != NULL && ms->look.pStdFont != &Scr.StdFont) { + ms->look.pStdFont->y = ms->look.pStdFont->font->ascent; + ms->look.pStdFont->height = ms->look.pStdFont->font->ascent + + ms->look.pStdFont->font->descent; } - else - { - tmpms->look.MenuActiveColors.back = GetColor(arg1); - tmpms->look.f.hasActiveBack = 1; - } - tmpms->look.f.Hilight = 1; - gc_changed = True; - break; - - case 7: /* HilightBackOff */ - tmpms->look.f.Hilight = 0; - gc_changed = True; - break; - - case 8: /* ActiveFore */ - if (tmpms->look.f.hasActiveFore) - FreeColors(&tmpms->look.MenuActiveColors.fore, 1); - if (arg1 == NULL) - { - tmpms->look.f.hasActiveFore = 0; + ms->look.EntryHeight = ms->look.pStdFont->height + HEIGHT_EXTRA; + + /* calculate colors based on foreground */ + if (!ms->look.f.hasActiveFore) + ms->look.MenuActiveColors.fore = ms->look.MenuColors.fore; + + /* calculate colors based on background */ + if (!ms->look.f.hasActiveBack) + ms->look.MenuActiveColors.back = ms->look.MenuColors.back; + if (!ms->look.f.hasStippleFore) + ms->look.MenuStippleColors.fore = ms->look.MenuColors.back; + if (Scr.d_depth > 2) { /* if not black and white */ + ms->look.MenuRelief.back = GetShadow(ms->look.MenuColors.back); + ms->look.MenuRelief.fore = GetHilite(ms->look.MenuColors.back); + } else { /* black and white */ + ms->look.MenuRelief.back = GetColor("black"); + ms->look.MenuRelief.fore = GetColor("white"); } - else - { - tmpms->look.MenuActiveColors.fore = GetColor(arg1); - tmpms->look.f.hasActiveFore = 1; + ms->look.MenuStippleColors.back = ms->look.MenuColors.back; + + /* make GC's */ + gcm = GCFunction | GCPlaneMask | GCFont | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground; + gcv.fill_style = FillSolid; + gcv.font = ms->look.pStdFont->font->fid; + gcv.plane_mask = AllPlanes; + gcv.function = GXcopy; + gcv.graphics_exposures = False; + gcv.line_width = 0; + + gcv.foreground = ms->look.MenuRelief.fore; + gcv.background = ms->look.MenuRelief.back; + if (ms->look.MenuReliefGC != NULL) + XFreeGC(dpy, ms->look.MenuReliefGC); + ms->look.MenuReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = ms->look.MenuRelief.back; + gcv.background = ms->look.MenuRelief.fore; + if (ms->look.MenuShadowGC != NULL) + XFreeGC(dpy, ms->look.MenuShadowGC); + ms->look.MenuShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = (ms->look.f.hasActiveBack) ? + ms->look.MenuActiveColors.back : + ms->look.MenuRelief.back; + gcv.background = (ms->look.f.hasActiveFore) ? + ms->look.MenuActiveColors.fore : + ms->look.MenuRelief.fore; + if (ms->look.MenuActiveBackGC != NULL) + XFreeGC(dpy, ms->look.MenuActiveBackGC); + ms->look.MenuActiveBackGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = ms->look.MenuColors.fore; + gcv.background = ms->look.MenuColors.back; + if (ms->look.MenuGC != NULL) + XFreeGC(dpy, ms->look.MenuGC); + ms->look.MenuGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = ms->look.MenuActiveColors.fore; + gcv.background = ms->look.MenuActiveColors.back; + if (ms->look.MenuActiveGC != NULL) + XFreeGC(dpy, ms->look.MenuActiveGC); + ms->look.MenuActiveGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + if (ms->look.MenuStippleGC != NULL) + XFreeGC(dpy, ms->look.MenuStippleGC); + if (Scr.d_depth < 2) { + gcv.fill_style = FillStippled; + gcv.stipple = Scr.gray_bitmap; + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground | GCFont | + GCStipple | GCFillStyle; + ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground | GCFont; + gcv.fill_style = FillSolid; + } else { + gcv.foreground = ms->look.MenuStippleColors.fore; + gcv.background = ms->look.MenuStippleColors.back; + ms->look.MenuStippleGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); } - gc_changed = True; - break; +} - case 9: /* ActiveForeOff */ - tmpms->look.f.hasActiveFore = 0; - gc_changed = True; - break; +static int +GetMenuStyleIndex(char *option) +{ + char *optlist[] = {"fvwm", "mwm", "win", "Foreground", "Background", + "Greyed", "HilightBack", "HilightBackOff", "ActiveFore", + "ActiveForeOff", "Hilight3DThick", "Hilight3DThin", "Hilight3DOff", + "Animation", "AnimationOff", "Font", "MenuFace", "PopupDelay", + "PopupOffset", "TitleWarp", "TitleWarpOff", "TitleUnderlines0", + "TitleUnderlines1", "TitleUnderlines2", "SeparatorsLong", + "SeparatorsShort", "TrianglesSolid", "TrianglesRelief", + "PopupImmediately", "PopupDelayed", "DoubleClickTime", "SidePic", + "SideColor", NULL}; + return GetTokenIndex(option, optlist, 0, NULL); +} - case 10: /* Hilight3DThick */ - tmpms->look.ReliefThickness = 2; - break; +static void +NewMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) +{ + char *name; + char *option = NULL; + char *optstring = NULL; + char *nextarg; + char *args; + char *arg1; + MenuStyle *ms; + MenuStyle *tmpms; + Bool is_initialised = True; + Bool gc_changed = False; + Bool is_default_style = False; + int val[2]; + int n; + XFontStruct *xfs = NULL; + int i; + + action = GetNextToken(action, &name); + if (!name) { + fvwm_msg(ERR, "NewMenuStyle", "error in %s style specification", + action); + return; + } - case 11: /* Hilight3DThin */ - tmpms->look.ReliefThickness = 1; - break; + tmpms = (MenuStyle *)xmalloc(sizeof(MenuStyle)); + memset(tmpms, 0, sizeof(MenuStyle)); + ms = FindMenuStyle(name); + if (ms != NULL) { + /* copy the structure over our temporary menu face. */ + memcpy(tmpms, ms, sizeof(MenuStyle)); + if (ms == Scr.menus.DefaultStyle) + is_default_style = True; + free(name); + } else { + tmpms->name = name; + is_initialised = False; + } - case 12: /* Hilight3DOff */ - tmpms->look.ReliefThickness = 0; - break; + /* Parse the options. */ + while (action && *action) { + if (is_initialised == False) { + /* some default configuration goes here for the new menu + * style */ + tmpms->look.MenuColors.back = GetColor("white"); + tmpms->look.MenuColors.fore = GetColor("black"); + tmpms->look.pStdFont = &Scr.StdFont; + tmpms->look.face.type = SimpleMenu; + tmpms->look.f.hasActiveFore = 0; + tmpms->look.f.hasActiveBack = 0; + gc_changed = True; + option = "fvwm"; + } else { + /* Read next option specification (delimited by a comma + * or \0). */ + args = action; + action = GetQuotedString( + action, &optstring, ",", NULL, NULL, NULL); + if (!optstring) + break; + + args = GetNextToken(optstring, &option); + if (!option) { + free(optstring); + break; + } + nextarg = GetNextToken(args, &arg1); + } - case 13: /* Animation */ - tmpms->feel.f.Animated = 1; - break; + switch ((i = GetMenuStyleIndex(option))) { + case 0: /* fvwm */ + case 1: /* mwm */ + case 2: /* win */ + if (i == 0) { + tmpms->feel.PopupOffsetPercent = 67; + tmpms->feel.PopupOffsetAdd = 0; + tmpms->feel.f.PopupImmediately = 0; + tmpms->feel.f.TitleWarp = 1; + tmpms->look.ReliefThickness = 1; + tmpms->look.TitleUnderlines = 1; + tmpms->look.f.LongSeparators = 0; + tmpms->look.f.TriangleRelief = 1; + tmpms->look.f.Hilight = 0; + } else if (i == 1) { + tmpms->feel.PopupOffsetPercent = 100; + tmpms->feel.PopupOffsetAdd = -3; + tmpms->feel.f.PopupImmediately = 1; + tmpms->feel.f.TitleWarp = 0; + tmpms->look.ReliefThickness = 2; + tmpms->look.TitleUnderlines = 2; + tmpms->look.f.LongSeparators = 1; + tmpms->look.f.TriangleRelief = 1; + tmpms->look.f.Hilight = 0; + } else /* i == 2 */ { + tmpms->feel.PopupOffsetPercent = 100; + tmpms->feel.PopupOffsetAdd = -5; + tmpms->feel.f.PopupImmediately = 1; + tmpms->feel.f.TitleWarp = 0; + tmpms->look.ReliefThickness = 0; + tmpms->look.TitleUnderlines = 1; + tmpms->look.f.LongSeparators = 0; + tmpms->look.f.TriangleRelief = 0; + tmpms->look.f.Hilight = 1; + } - case 14: /* AnimationOff */ - tmpms->feel.f.Animated = 0; - break; + /* common settings */ + tmpms->feel.f.Animated = 0; + FreeMenuFace(dpy, &tmpms->look.face); + tmpms->look.face.type = SimpleMenu; + if (tmpms->look.pStdFont && + tmpms->look.pStdFont != &Scr.StdFont) { + XFreeFont(dpy, tmpms->look.pStdFont->font); + free(tmpms->look.pStdFont); + } + tmpms->look.pStdFont = &Scr.StdFont; + gc_changed = True; + if (tmpms->look.f.hasSideColor == 1) { + FreeColors(&tmpms->look.sideColor, 1); + tmpms->look.f.hasSideColor = 0; + } + tmpms->look.f.hasSideColor = 0; + if (tmpms->look.sidePic) { + DestroyPicture(dpy, tmpms->look.sidePic); + tmpms->look.sidePic = NULL; + } - case 15: /* Font */ - if (arg1 != NULL && (xfs = GetFontOrFixed(dpy, arg1)) == NULL) - { - fvwm_msg(ERR,"NewMenuStyle", - "Couldn't load font '%s' or 'fixed'\n", arg1); - break; - } - if (tmpms->look.pStdFont && tmpms->look.pStdFont != &Scr.StdFont) - { - if (tmpms->look.pStdFont->font != NULL) - XFreeFont(dpy, tmpms->look.pStdFont->font); - free(tmpms->look.pStdFont); - } - if (arg1 == NULL) - { - /* reset to screen font */ - tmpms->look.pStdFont = &Scr.StdFont; - } - else - { - tmpms->look.pStdFont = (MyFont *)safemalloc(sizeof(MyFont)); - tmpms->look.pStdFont->font = xfs; - } - gc_changed = True; - break; + if (is_initialised == False) { + /* now begin the real work */ + is_initialised = True; + continue; + } + break; - case 16: /* MenuFace */ - while (args && *args != '\0' && isspace(*args)) - args++; - ReadMenuFace(args, &tmpms->look.face, True); - break; + case 3: /* Foreground */ + FreeColors(&tmpms->look.MenuColors.fore, 1); + if (arg1) + tmpms->look.MenuColors.fore = GetColor(arg1); + else + tmpms->look.MenuColors.fore = GetColor("black"); + gc_changed = True; + break; + + case 4: /* Background */ + FreeColors(&tmpms->look.MenuColors.back, 1); + if (arg1) + tmpms->look.MenuColors.back = GetColor(arg1); + else + tmpms->look.MenuColors.back = GetColor("grey"); + gc_changed = True; + break; + + case 5: /* Greyed */ + if (tmpms->look.f.hasStippleFore) + FreeColors( + &tmpms->look.MenuStippleColors.fore, 1); + if (arg1 == NULL) { + tmpms->look.f.hasStippleFore = 0; + } else { + tmpms->look.MenuStippleColors.fore = + GetColor(arg1); + tmpms->look.f.hasStippleFore = 1; + } + gc_changed = True; + break; + + case 6: /* HilightBack */ + if (tmpms->look.f.hasActiveBack) + FreeColors( + &tmpms->look.MenuActiveColors.back, 1); + if (arg1 == NULL) { + tmpms->look.f.hasActiveBack = 0; + } else { + tmpms->look.MenuActiveColors.back = + GetColor(arg1); + tmpms->look.f.hasActiveBack = 1; + } + tmpms->look.f.Hilight = 1; + gc_changed = True; + break; + + case 7: /* HilightBackOff */ + tmpms->look.f.Hilight = 0; + gc_changed = True; + break; + + case 8: /* ActiveFore */ + if (tmpms->look.f.hasActiveFore) + FreeColors( + &tmpms->look.MenuActiveColors.fore, 1); + if (arg1 == NULL) { + tmpms->look.f.hasActiveFore = 0; + } else { + tmpms->look.MenuActiveColors.fore = + GetColor(arg1); + tmpms->look.f.hasActiveFore = 1; + } + gc_changed = True; + break; + + case 9: /* ActiveForeOff */ + tmpms->look.f.hasActiveFore = 0; + gc_changed = True; + break; + + case 10: /* Hilight3DThick */ + tmpms->look.ReliefThickness = 2; + break; + + case 11: /* Hilight3DThin */ + tmpms->look.ReliefThickness = 1; + break; + + case 12: /* Hilight3DOff */ + tmpms->look.ReliefThickness = 0; + break; + + case 13: /* Animation */ + tmpms->feel.f.Animated = 1; + break; + + case 14: /* AnimationOff */ + tmpms->feel.f.Animated = 0; + break; + + case 15: /* Font */ + if (arg1 != NULL && + (xfs = GetFontOrFixed(dpy, arg1)) == NULL) { + fvwm_msg(ERR, "NewMenuStyle", + "Couldn't load font '%s' or 'fixed'\n", + arg1); + break; + } + if (tmpms->look.pStdFont && + tmpms->look.pStdFont != &Scr.StdFont) { + if (tmpms->look.pStdFont->font != NULL) + XFreeFont( + dpy, tmpms->look.pStdFont->font); + free(tmpms->look.pStdFont); + } + if (arg1 == NULL) { + /* reset to screen font */ + tmpms->look.pStdFont = &Scr.StdFont; + } else { + tmpms->look.pStdFont = + (MyFont *)xmalloc(sizeof(MyFont)); + tmpms->look.pStdFont->font = xfs; + } + gc_changed = True; + break; + + case 16: /* MenuFace */ + while (args && *args != '\0' && isspace(*args)) + args++; + ReadMenuFace(args, &tmpms->look.face, True); + break; + + case 17: /* PopupDelay */ + if (GetIntegerArguments(args, NULL, val, 1) == 0 || + *val < 0) + Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; + else + Scr.menus.PopupDelay10ms = (*val + 9) / 10; + if (!is_default_style) { + fvwm_msg(WARN, "NewMenuStyle", + "PopupDelay applied to style '%s' will " + "affect all menus", + tmpms->name); + } + break; + + case 18: /* PopupOffset */ + if ((n = GetIntegerArguments(args, NULL, val, 2)) == + 0) { + fvwm_msg(ERR, "NewMenuStyle", + "PopupOffset requires one or two " + "arguments"); + } else { + tmpms->feel.PopupOffsetAdd = val[0]; + if (n == 2 && val[1] <= 100 && val[1] >= 0) + tmpms->feel.PopupOffsetPercent = val[1]; + else + tmpms->feel.PopupOffsetPercent = 100; + } + break; - case 17: /* PopupDelay */ - if (GetIntegerArguments(args, NULL, val, 1) == 0 || *val < 0) - Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; - else - Scr.menus.PopupDelay10ms = (*val+9)/10; - if (!is_default_style) - { - fvwm_msg(WARN, "NewMenuStyle", - "PopupDelay applied to style '%s' will affect all menus", - tmpms->name); - } - break; + case 19: /* TitleWarp */ + tmpms->feel.f.TitleWarp = 1; + break; - case 18: /* PopupOffset */ - if ((n = GetIntegerArguments(args, NULL, val, 2)) == 0) - { - fvwm_msg(ERR,"NewMenuStyle", - "PopupOffset requires one or two arguments"); - } - else - { - tmpms->feel.PopupOffsetAdd = val[0]; - if (n == 2 && val[1] <= 100 && val[1] >= 0) - tmpms->feel.PopupOffsetPercent = val[1]; - else - tmpms->feel.PopupOffsetPercent = 100; - } - break; + case 20: /* TitleWarpOff */ + tmpms->feel.f.TitleWarp = 0; + break; - case 19: /* TitleWarp */ - tmpms->feel.f.TitleWarp = 1; - break; + case 21: /* TitleUnderlines0 */ + tmpms->look.TitleUnderlines = 0; + break; - case 20: /* TitleWarpOff */ - tmpms->feel.f.TitleWarp = 0; - break; + case 22: /* TitleUnderlines1 */ + tmpms->look.TitleUnderlines = 1; + break; - case 21: /* TitleUnderlines0 */ - tmpms->look.TitleUnderlines = 0; - break; + case 23: /* TitleUnderlines2 */ + tmpms->look.TitleUnderlines = 2; + break; - case 22: /* TitleUnderlines1 */ - tmpms->look.TitleUnderlines = 1; - break; + case 24: /* SeparatorsLong */ + tmpms->look.f.LongSeparators = 1; + break; - case 23: /* TitleUnderlines2 */ - tmpms->look.TitleUnderlines = 2; - break; + case 25: /* SeparatorsShort */ + tmpms->look.f.LongSeparators = 0; + break; - case 24: /* SeparatorsLong */ - tmpms->look.f.LongSeparators = 1; - break; + case 26: /* TrianglesSolid */ + tmpms->look.f.TriangleRelief = 0; + break; - case 25: /* SeparatorsShort */ - tmpms->look.f.LongSeparators = 0; - break; + case 27: /* TrianglesRelief */ + tmpms->look.f.TriangleRelief = 1; + break; - case 26: /* TrianglesSolid */ - tmpms->look.f.TriangleRelief = 0; - break; + case 28: /* PopupImmediately */ + tmpms->feel.f.PopupImmediately = 1; + break; - case 27: /* TrianglesRelief */ - tmpms->look.f.TriangleRelief = 1; - break; + case 29: /* PopupDelayed */ + tmpms->feel.f.PopupImmediately = 0; + break; - case 28: /* PopupImmediately */ - tmpms->feel.f.PopupImmediately = 1; - break; + case 30: /* DoubleClickTime */ + if (GetIntegerArguments(args, NULL, val, 1) == 0 || + *val < 0) + Scr.menus.DoubleClickTime = + DEFAULT_MENU_CLICKTIME; + else + Scr.menus.DoubleClickTime = *val; + if (!is_default_style) { + fvwm_msg(WARN, "NewMenuStyle", + "DoubleClickTime for style '%s' will " + "affect all menus", + tmpms->name); + } + break; - case 29: /* PopupDelayed */ - tmpms->feel.f.PopupImmediately = 0; - break; + case 31: /* SidePic */ + if (tmpms->look.sidePic) { + DestroyPicture(dpy, tmpms->look.sidePic); + tmpms->look.sidePic = NULL; + } + if (arg1 != NULL) { + tmpms->look.sidePic = + CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, arg1, Scr.ColorLimit); + if (!tmpms->look.sidePic) + fvwm_msg(WARN, "NewMenuStyle", + "Couldn't find pixmap %s", arg1); + } + break; - case 30: /* DoubleClickTime */ - if (GetIntegerArguments(args, NULL, val, 1) == 0 || *val < 0) - Scr.menus.DoubleClickTime = DEFAULT_MENU_CLICKTIME; - else - Scr.menus.DoubleClickTime = *val; - if (!is_default_style) - { - fvwm_msg(WARN, "NewMenuStyle", - "DoubleClickTime for style '%s' will affect all menus", - tmpms->name); - } - break; + case 32: /* SideColor */ + if (tmpms->look.f.hasSideColor == 1) { + FreeColors(&tmpms->look.sideColor, 1); + tmpms->look.f.hasSideColor = 0; + } + if (arg1 != NULL) { + tmpms->look.sideColor = GetColor(arg1); + tmpms->look.f.hasSideColor = 1; + } + break; - case 31: /* SidePic */ - if (tmpms->look.sidePic) - { - DestroyPicture(dpy, tmpms->look.sidePic); - tmpms->look.sidePic = NULL; - } - if (arg1 != NULL) - { - tmpms->look.sidePic = CachePicture(dpy, Scr.Root, IconPath, - PixmapPath, arg1, Scr.ColorLimit); - if (!tmpms->look.sidePic) - fvwm_msg(WARN, "NewMenuStyle", "Couldn't find pixmap %s", arg1); - } - break; + default: + fvwm_msg( + ERR, "NewMenuStyle", "unknown option '%s'", option); + break; + } /* switch */ - case 32: /* SideColor */ - if (tmpms->look.f.hasSideColor == 1) - { - FreeColors(&tmpms->look.sideColor, 1); - tmpms->look.f.hasSideColor = 0; - } - if (arg1 != NULL) - { - tmpms->look.sideColor = GetColor(arg1); - tmpms->look.f.hasSideColor = 1; - } - break; + if (option) { + free(option); + option = NULL; + } + free(optstring); + optstring = NULL; + if (arg1) { + free(arg1); + arg1 = NULL; + } + } /* while */ + + if (gc_changed) { + UpdateMenuStyle(tmpms); + } /* if (gc_changed) */ + + if (Scr.menus.DefaultStyle == NULL) { + /* First MenuStyle MUST be the default style */ + Scr.menus.DefaultStyle = tmpms; + tmpms->next = NULL; + } else if (ms != NULL) { + /* copy our new menu face over the old one */ + memcpy(ms, tmpms, sizeof(MenuStyle)); + free(tmpms); + } else { + MenuStyle *before = Scr.menus.DefaultStyle; -#if 0 - case 33: /* PositionHints */ - break; -#endif + /* add a new menu face to list */ + tmpms->next = NULL; + while (before->next != NULL) + before = before->next; + before->next = tmpms; + } - default: - fvwm_msg(ERR,"NewMenuStyle", "unknown option '%s'", option); - break; - } /* switch */ + MakeMenus(); - if (option) - { - free(option); - option = NULL; - } - free(optstring); - optstring = NULL; - if (arg1) - { - free(arg1); - arg1 = NULL; - } - } /* while */ - - if (gc_changed) - { - UpdateMenuStyle(tmpms); - } /* if (gc_changed) */ - - if(Scr.menus.DefaultStyle == NULL) - { - /* First MenuStyle MUST be the default style */ - Scr.menus.DefaultStyle = tmpms; - tmpms->next = NULL; - } - else if (ms != NULL) - { - /* copy our new menu face over the old one */ - memcpy(ms, tmpms, sizeof(MenuStyle)); - free(tmpms); - } - else - { - MenuStyle *before = Scr.menus.DefaultStyle; - - /* add a new menu face to list */ - tmpms->next = NULL; - while(before->next != NULL) - before = before->next; - before->next = tmpms; - } - - MakeMenus(); - - return; + return; } -static void OldMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +static void +OldMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *buffer, *rest; - char *fore, *back, *stipple, *font, *style, *animated; - size_t len; - - rest = GetNextToken(action,&fore); - rest = GetNextToken(rest,&back); - rest = GetNextToken(rest,&stipple); - rest = GetNextToken(rest,&font); - rest = GetNextToken(rest,&style); - rest = GetNextToken(rest,&animated); - - if(!fore || !back || !stipple || !font || !style) - { - fvwm_msg(ERR,"OldMenuStyle", "error in %s style specification", action); - } - else - { - len = strlen(action) + 100; - buffer = (char *)safemalloc(len); - snprintf(buffer, len, - "* %s, Foreground %s, Background %s, Greyed %s, Font %s, %s", - style, fore, back, stipple, font, - (animated != NULL && StrEquals(animated, "anim")) ? - "Animation" : "AnimationOff"); - NewMenuStyle(eventp, w, tmp_win, context, buffer, Module); - free(buffer); - } - - if(fore != NULL) - free(fore); - if(back != NULL) - free(back); - if(stipple != NULL) - free(stipple); - if(font != NULL) - free(font); - if(style != NULL) - free(style); - if(animated != NULL) - free(animated); -} + char *buffer, *rest; + char *fore, *back, *stipple, *font, *style, *animated; + size_t len; + + rest = GetNextToken(action, &fore); + rest = GetNextToken(rest, &back); + rest = GetNextToken(rest, &stipple); + rest = GetNextToken(rest, &font); + rest = GetNextToken(rest, &style); + rest = GetNextToken(rest, &animated); + + if (!fore || !back || !stipple || !font || !style) { + fvwm_msg(ERR, "OldMenuStyle", "error in %s style specification", + action); + } else { + len = strlen(action) + 100; + buffer = (char *)xmalloc(len); + snprintf(buffer, len, + "* %s, Foreground %s, Background %s, Greyed %s, Font %s, " + "%s", + style, fore, back, stipple, font, + (animated != NULL && StrEquals(animated, "anim")) ? + "Animation" : + "AnimationOff"); + NewMenuStyle(eventp, w, tmp_win, context, buffer, Module); + free(buffer); + } + if (fore != NULL) + free(fore); + if (back != NULL) + free(back); + if (stipple != NULL) + free(stipple); + if (font != NULL) + free(font); + if (style != NULL) + free(style); + if (animated != NULL) + free(animated); +} -void SetMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *option; - - GetNextOption(SkipNTokens(action, 1), &option); - if (option == NULL || GetMenuStyleIndex(option) != -1) - NewMenuStyle(eventp, w, tmp_win, context, action, Module); - else - OldMenuStyle(eventp, w, tmp_win, context, action, Module); - if (option) - free(option); - return; -} + char *option; + GetNextOption(SkipNTokens(action, 1), &option); + if (option == NULL || GetMenuStyleIndex(option) != -1) + NewMenuStyle(eventp, w, tmp_win, context, action, Module); + else + OldMenuStyle(eventp, w, tmp_win, context, action, Module); + if (option) + free(option); + return; +} -void ChangeMenuStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +ChangeMenuStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *name = NULL, *menuname = NULL; - MenuStyle *ms = NULL; - MenuRoot *mr = NULL; - - - action = GetNextToken(action,&name); - if (name == NULL) - { - fvwm_msg(ERR,"ChangeMenuStyle", "needs at least two parameters"); - return; - } - - ms = FindMenuStyle(name); - if(ms == NULL) - { - fvwm_msg(ERR,"ChangeMenuStyle", "cannot find style %s", name); - free(name); - return; - } - free(name); - - action = GetNextToken(action,&menuname); - while(menuname != NULL && *menuname) - { - mr = FindPopup(menuname); - if(mr == NULL) - { - fvwm_msg(ERR,"ChangeMenuStyle", "cannot find menu %s", menuname); - free(menuname); - break; - } - mr->ms = ms; - MakeMenu(mr); - free(menuname); - action = GetNextToken(action,&menuname); - } -} + char *name = NULL, *menuname = NULL; + MenuStyle *ms = NULL; + MenuRoot *mr = NULL; + + action = GetNextToken(action, &name); + if (name == NULL) { + fvwm_msg( + ERR, "ChangeMenuStyle", "needs at least two parameters"); + return; + } + ms = FindMenuStyle(name); + if (ms == NULL) { + fvwm_msg(ERR, "ChangeMenuStyle", "cannot find style %s", name); + free(name); + return; + } + free(name); + + action = GetNextToken(action, &menuname); + while (menuname != NULL && *menuname) { + mr = FindPopup(menuname); + if (mr == NULL) { + fvwm_msg(ERR, "ChangeMenuStyle", "cannot find menu %s", + menuname); + free(menuname); + break; + } + mr->ms = ms; + MakeMenu(mr); + free(menuname); + action = GetNextToken(action, &menuname); + } +} Boolean ReadButtonFace(char *s, ButtonFace *bf, int button, int verbose); void FreeButtonFace(Display *dpy, ButtonFace *bf); @@ -2342,91 +2275,94 @@ void FreeButtonFace(Display *dpy, ButtonFace *bf); * Sets the border style (veliaa@rpi.edu) * ****************************************************************************/ -void SetBorderStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetBorderStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *parm = NULL, *prev = action; + char *parm = NULL, *prev = action; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action, &parm); - while (parm) - { - if (StrEquals(parm,"active") || StrEquals(parm,"inactive")) - { - int len; - char *end, *tmp; - ButtonFace tmpbf, *bf; - tmpbf.style = SimpleButton; + action = GetNextToken(action, &parm); + while (parm) { + if (StrEquals(parm, "active") || StrEquals(parm, "inactive")) { + int len; + char *end, *tmp; + ButtonFace tmpbf, *bf; + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif #ifdef MINI_ICONS - tmpbf.u.p = NULL; + tmpbf.u.p = NULL; #endif - if (StrEquals(parm,"active")) - bf = &fl->BorderStyle.active; - else - bf = &fl->BorderStyle.inactive; - while (isspace(*action)) ++action; - if ('(' != *action) { - if (!*action) { - fvwm_msg(ERR,"SetBorderStyle", - "error in %s border specification", parm); - free(parm); - return; - } - free(parm); - if (ReadButtonFace(action, &tmpbf,-1,True)) { - FreeButtonFace(dpy, bf); - *bf = tmpbf; - } - break; - } - end = strchr(++action, ')'); - if (!end) { - fvwm_msg(ERR,"SetBorderStyle", - "error in %s border specification", parm); - free(parm); - return; - } - len = end - action + 1; - tmp = safemalloc(len); - strncpy(tmp, action, len - 1); - tmp[len - 1] = 0; - ReadButtonFace(tmp, bf,-1,True); - free(tmp); - action = end + 1; - } - else if (strcmp(parm,"--")==0) { - if (ReadButtonFace(prev, &fl->BorderStyle.active,-1,True)) - ReadButtonFace(prev, &fl->BorderStyle.inactive,-1,False); - free(parm); - break; - } else { - ButtonFace tmpbf; - tmpbf.style = SimpleButton; + if (StrEquals(parm, "active")) + bf = &fl->BorderStyle.active; + else + bf = &fl->BorderStyle.inactive; + while (isspace(*action)) + ++action; + if ('(' != *action) { + if (!*action) { + fvwm_msg(ERR, "SetBorderStyle", + "error in %s border specification", + parm); + free(parm); + return; + } + free(parm); + if (ReadButtonFace(action, &tmpbf, -1, True)) { + FreeButtonFace(dpy, bf); + *bf = tmpbf; + } + break; + } + end = strchr(++action, ')'); + if (!end) { + fvwm_msg(ERR, "SetBorderStyle", + "error in %s border specification", parm); + free(parm); + return; + } + len = end - action + 1; + tmp = xmalloc(len); + strncpy(tmp, action, len - 1); + tmp[len - 1] = 0; + ReadButtonFace(tmp, bf, -1, True); + free(tmp); + action = end + 1; + } else if (strcmp(parm, "--") == 0) { + if (ReadButtonFace( + prev, &fl->BorderStyle.active, -1, True)) + ReadButtonFace( + prev, &fl->BorderStyle.inactive, -1, False); + free(parm); + break; + } else { + ButtonFace tmpbf; + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif #ifdef MINI_ICONS - tmpbf.u.p = NULL; + tmpbf.u.p = NULL; #endif - if (ReadButtonFace(prev, &tmpbf,-1,True)) { - FreeButtonFace(dpy,&fl->BorderStyle.active); - fl->BorderStyle.active = tmpbf; - ReadButtonFace(prev, &fl->BorderStyle.inactive,-1,False); - } - free(parm); - break; + if (ReadButtonFace(prev, &tmpbf, -1, True)) { + FreeButtonFace(dpy, &fl->BorderStyle.active); + fl->BorderStyle.active = tmpbf; + ReadButtonFace( + prev, &fl->BorderStyle.inactive, -1, False); + } + free(parm); + break; + } + free(parm); + prev = action; + action = GetNextToken(action, &parm); } - free(parm); - prev = action; - action = GetNextToken(action,&parm); - } } #endif @@ -2438,449 +2374,436 @@ char *ReadTitleButton(char *s, TitleButton *tb, Boolean append, int button); * Appends a titlestyle (veliaa@rpi.edu) * ****************************************************************************/ -void AddTitleStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +AddTitleStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - char *parm=NULL; - - /* See if there's a next token. We actually don't care what it is, so - GetNextToken allocating memory is overkill, but... */ - GetNextToken(action,&parm); - while (parm) - { - free(parm); - if ((action = ReadTitleButton(action, &fl->titlebar, True, -1)) == NULL) - break; - GetNextToken(action, &parm); - } + char *parm = NULL; + + /* See if there's a next token. We actually don't care what it is, so + GetNextToken allocating memory is overkill, but... */ + GetNextToken(action, &parm); + while (parm) { + free(parm); + if ((action = ReadTitleButton( + action, &fl->titlebar, True, -1)) == NULL) + break; + GetNextToken(action, &parm); + } } #endif /* MULTISTYLE && EXTENDED_TITLESTYLE */ -void SetTitleStyle(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetTitleStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *parm=NULL, *prev = action; + char *parm = NULL, *prev = action; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action,&parm); - while(parm) - { - if (StrEquals(parm,"centered")) - { - fl->titlebar.flags &= ~HOffCenter; - } - else if (StrEquals(parm,"leftjustified")) - { - fl->titlebar.flags |= HOffCenter; - fl->titlebar.flags &= ~HRight; - } - else if (StrEquals(parm,"rightjustified")) - { - fl->titlebar.flags |= HOffCenter | HRight; - } + action = GetNextToken(action, &parm); + while (parm) { + if (StrEquals(parm, "centered")) { + fl->titlebar.flags &= ~HOffCenter; + } else if (StrEquals(parm, "leftjustified")) { + fl->titlebar.flags |= HOffCenter; + fl->titlebar.flags &= ~HRight; + } else if (StrEquals(parm, "rightjustified")) { + fl->titlebar.flags |= HOffCenter | HRight; + } #ifdef EXTENDED_TITLESTYLE - else if (StrEquals(parm,"height")) - { - int height, next; - if ( sscanf(action, "%d%n", &height, &next) > 0 - && height > 4 - && height <= 256) - { - int x,y,w,h,extra_height; - FvwmWindow *tmp = Scr.FvwmRoot.next, *hi = Scr.Hilite; - - extra_height = fl->TitleHeight; - fl->TitleHeight = height; - extra_height -= fl->TitleHeight; - - fl->WindowFont.y = fl->WindowFont.font->ascent - + (height - (fl->WindowFont.font->ascent - + fl->WindowFont.font->descent + 3)) / 2; - if (fl->WindowFont.y < fl->WindowFont.font->ascent) - fl->WindowFont.y = fl->WindowFont.font->ascent; - - tmp = Scr.FvwmRoot.next; - hi = Scr.Hilite; - while(tmp != NULL) - { - if (!(tmp->flags & TITLE) + else if (StrEquals(parm, "height")) { + int height, next; + if (sscanf(action, "%d%n", &height, &next) > 0 && + height > 4 && height <= 256) { + int x, y, w, h, extra_height; + FvwmWindow *tmp = Scr.FvwmRoot.next, + *hi = Scr.Hilite; + + extra_height = fl->TitleHeight; + fl->TitleHeight = height; + extra_height -= fl->TitleHeight; + + fl->WindowFont.y = + fl->WindowFont.font->ascent + + (height - + (fl->WindowFont.font->ascent + + fl->WindowFont.font->descent + 3)) / + 2; + if (fl->WindowFont.y < + fl->WindowFont.font->ascent) + fl->WindowFont.y = + fl->WindowFont.font->ascent; + + tmp = Scr.FvwmRoot.next; + hi = Scr.Hilite; + while (tmp != NULL) { + if (!(tmp->flags & TITLE) #ifdef USEDECOR - || (tmp->fl != fl) + || (tmp->fl != fl) #endif - ) { - tmp = tmp->next; - continue; + ) { + tmp = tmp->next; + continue; + } + x = tmp->frame_x; + y = tmp->frame_y; + w = tmp->frame_width; + h = tmp->frame_height - extra_height; + tmp->frame_x = 0; + tmp->frame_y = 0; + tmp->frame_height = 0; + tmp->frame_width = 0; + SetupFrame(tmp, x, y, w, h, True); + SetTitleBar(tmp, True, True); + SetTitleBar(tmp, False, True); + tmp = tmp->next; + } + SetTitleBar(hi, True, True); + } else + fvwm_msg(ERR, "SetTitleStyle", + "bad height argument (height must be from " + "5 to 256)"); + action += next; + } else { + if (!(action = ReadTitleButton( + prev, &fl->titlebar, False, -1))) { + free(parm); + break; + } + } +#else /* ! EXTENDED_TITLESTYLE */ + else if (strcmp(parm, "--") == 0) { + if (!(action = ReadTitleButton( + prev, &fl->titlebar, False, -1))) { + free(parm); + break; + } } - x = tmp->frame_x; - y = tmp->frame_y; - w = tmp->frame_width; - h = tmp->frame_height-extra_height; - tmp->frame_x = 0; - tmp->frame_y = 0; - tmp->frame_height = 0; - tmp->frame_width = 0; - SetupFrame(tmp,x,y,w,h,True); - SetTitleBar(tmp,True,True); - SetTitleBar(tmp,False,True); - tmp = tmp->next; - } - SetTitleBar(hi,True,True); - } - else - fvwm_msg(ERR,"SetTitleStyle", - "bad height argument (height must be from 5 to 256)"); - action += next; - } - else - { - if (!(action = ReadTitleButton(prev, &fl->titlebar, False, -1))) { - free(parm); - break; - } - } -#else /* ! EXTENDED_TITLESTYLE */ - else if (strcmp(parm,"--")==0) { - if (!(action = ReadTitleButton(prev, &fl->titlebar, False, -1))) { - free(parm); - break; - } - } #endif /* EXTENDED_TITLESTYLE */ - free(parm); - prev = action; - action = GetNextToken(action,&parm); - } + free(parm); + prev = action; + action = GetNextToken(action, &parm); + } } /* SetTitleStyle */ -static void ApplyDefaultFontAndColors(void) +static void +ApplyDefaultFontAndColors(void) { - XGCValues gcv; - unsigned long gcm; - MenuStyle *ms; - int wid; - int hei; - - Scr.StdFont.y = Scr.StdFont.font->ascent; - Scr.StdFont.height = Scr.StdFont.font->ascent + Scr.StdFont.font->descent; - - /* make GC's */ - gcm = GCFunction|GCPlaneMask|GCFont|GCGraphicsExposures| - GCLineWidth|GCForeground|GCBackground; - gcv.fill_style = FillSolid; - gcv.font = Scr.StdFont.font->fid; - gcv.plane_mask = AllPlanes; - gcv.function = GXcopy; - gcv.graphics_exposures = False; - gcv.line_width = 0; - - gcv.foreground = Scr.StdColors.fore; - gcv.background = Scr.StdColors.back; - if(Scr.StdGC != NULL) - XFreeGC(dpy, Scr.StdGC); - Scr.StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = Scr.StdRelief.fore; - gcv.background = Scr.StdRelief.back; - if(Scr.StdReliefGC != NULL) - XFreeGC(dpy, Scr.StdReliefGC); - Scr.StdReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - gcv.foreground = Scr.StdRelief.back; - gcv.background = Scr.StdRelief.fore; - if(Scr.StdShadowGC != NULL) - XFreeGC(dpy, Scr.StdShadowGC); - Scr.StdShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); - - /* update the geometry window for move/resize */ - if(Scr.SizeWindow != None) - { - XSetWindowBackground(dpy, Scr.SizeWindow, Scr.StdColors.back); - Scr.SizeStringWidth = XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); - wid = Scr.SizeStringWidth + 2 * SIZE_HINDENT; - hei = Scr.StdFont.height + 2 * SIZE_VINDENT; - if(Scr.gs.EmulateMWM) - { - XMoveResizeWindow(dpy,Scr.SizeWindow, - (Scr.MyDisplayWidth - wid)/2, - (Scr.MyDisplayHeight - hei)/2, wid, hei); - } - else - { - XMoveResizeWindow(dpy,Scr.SizeWindow,0, 0, wid,hei); - } - } - - if (Scr.hasIconFont == False) - { - Scr.IconFont.font = Scr.StdFont.font; - ApplyIconFont(); - } - - if (Scr.hasWindowFont == False) - { - Scr.DefaultDecor.WindowFont.font = Scr.StdFont.font; - ApplyWindowFont(&Scr.DefaultDecor); - } - - for (ms = Scr.menus.DefaultStyle; ms != NULL; ms = ms->next) - { - if (ms->look.pStdFont == &Scr.StdFont) - ms->look.EntryHeight = Scr.StdFont.height + HEIGHT_EXTRA; - UpdateMenuStyle(ms); - } - MakeMenus(); + XGCValues gcv; + unsigned long gcm; + MenuStyle *ms; + int wid; + int hei; + + Scr.StdFont.y = Scr.StdFont.font->ascent; + Scr.StdFont.height = + Scr.StdFont.font->ascent + Scr.StdFont.font->descent; + + /* make GC's */ + gcm = GCFunction | GCPlaneMask | GCFont | GCGraphicsExposures | + GCLineWidth | GCForeground | GCBackground; + gcv.fill_style = FillSolid; + gcv.font = Scr.StdFont.font->fid; + gcv.plane_mask = AllPlanes; + gcv.function = GXcopy; + gcv.graphics_exposures = False; + gcv.line_width = 0; + + gcv.foreground = Scr.StdColors.fore; + gcv.background = Scr.StdColors.back; + if (Scr.StdGC != NULL) + XFreeGC(dpy, Scr.StdGC); + Scr.StdGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = Scr.StdRelief.fore; + gcv.background = Scr.StdRelief.back; + if (Scr.StdReliefGC != NULL) + XFreeGC(dpy, Scr.StdReliefGC); + Scr.StdReliefGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + gcv.foreground = Scr.StdRelief.back; + gcv.background = Scr.StdRelief.fore; + if (Scr.StdShadowGC != NULL) + XFreeGC(dpy, Scr.StdShadowGC); + Scr.StdShadowGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + + /* update the geometry window for move/resize */ + if (Scr.SizeWindow != None) { + XSetWindowBackground(dpy, Scr.SizeWindow, Scr.StdColors.back); + Scr.SizeStringWidth = + XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); + wid = Scr.SizeStringWidth + 2 * SIZE_HINDENT; + hei = Scr.StdFont.height + 2 * SIZE_VINDENT; + if (Scr.gs.EmulateMWM) { + XMoveResizeWindow(dpy, Scr.SizeWindow, + (Scr.MyDisplayWidth - wid) / 2, + (Scr.MyDisplayHeight - hei) / 2, wid, hei); + } else { + XMoveResizeWindow(dpy, Scr.SizeWindow, 0, 0, wid, hei); + } + } + + if (Scr.hasIconFont == False) { + Scr.IconFont.font = Scr.StdFont.font; + ApplyIconFont(); + } + + if (Scr.hasWindowFont == False) { + Scr.DefaultDecor.WindowFont.font = Scr.StdFont.font; + ApplyWindowFont(&Scr.DefaultDecor); + } + + for (ms = Scr.menus.DefaultStyle; ms != NULL; ms = ms->next) { + if (ms->look.pStdFont == &Scr.StdFont) + ms->look.EntryHeight = + Scr.StdFont.height + HEIGHT_EXTRA; + UpdateMenuStyle(ms); + } + MakeMenus(); } -void SetDefaultColors(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetDefaultColors(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *fore = NULL; - char *back = NULL; - - action = GetNextToken(action, &fore); - action = GetNextToken(action, &back); - - if (!back) - back = strdup("grey"); - if (!fore) - back = strdup("black"); - - if (!StrEquals(fore, "-")) - { - FreeColors(&Scr.StdColors.fore, 1); - Scr.StdColors.fore = GetColor(fore); - } - if (!StrEquals(back, "-")) - { - FreeColors(&Scr.StdColors.back, 1); - FreeColors(&Scr.StdRelief.back, 1); - FreeColors(&Scr.StdRelief.fore, 1); - Scr.StdColors.back = GetColor(back); - Scr.StdRelief.fore = GetHilite(Scr.StdColors.back); - Scr.StdRelief.back = GetShadow(Scr.StdColors.back); - } - free(fore); - free(back); - - ApplyDefaultFontAndColors(); + char *fore = NULL; + char *back = NULL; + + action = GetNextToken(action, &fore); + action = GetNextToken(action, &back); + + if (!back) + back = strdup("grey"); + if (!fore) + back = strdup("black"); + + if (!StrEquals(fore, "-")) { + FreeColors(&Scr.StdColors.fore, 1); + Scr.StdColors.fore = GetColor(fore); + } + if (!StrEquals(back, "-")) { + FreeColors(&Scr.StdColors.back, 1); + FreeColors(&Scr.StdRelief.back, 1); + FreeColors(&Scr.StdRelief.fore, 1); + Scr.StdColors.back = GetColor(back); + Scr.StdRelief.fore = GetHilite(Scr.StdColors.back); + Scr.StdRelief.back = GetShadow(Scr.StdColors.back); + } + free(fore); + free(back); + + ApplyDefaultFontAndColors(); } -void LoadDefaultFont(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +LoadDefaultFont(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *font; - XFontStruct *xfs = NULL; - - action = GetNextToken(action,&font); - if (!font) - { - /* Try 'fixed' */ - font = strdup(""); - } - - if ((xfs = GetFontOrFixed(dpy, font)) == NULL) - { - fvwm_msg(ERR,"SetDefaultFont","Couldn't load font '%s' or 'fixed'\n", - font); - free(font); - if (Scr.StdFont.font == NULL) - exit(1); - else - return; - } - free(font); - if (Scr.StdFont.font != NULL) - XFreeFont(dpy, Scr.StdFont.font); - Scr.StdFont.font = xfs; - - ApplyDefaultFontAndColors(); + char *font; + XFontStruct *xfs = NULL; + + action = GetNextToken(action, &font); + if (!font) { + /* Try 'fixed' */ + font = strdup(""); + } + + if ((xfs = GetFontOrFixed(dpy, font)) == NULL) { + fvwm_msg(ERR, "SetDefaultFont", + "Couldn't load font '%s' or 'fixed'\n", font); + free(font); + if (Scr.StdFont.font == NULL) + exit(1); + else + return; + } + free(font); + if (Scr.StdFont.font != NULL) + XFreeFont(dpy, Scr.StdFont.font); + Scr.StdFont.font = xfs; + + ApplyDefaultFontAndColors(); } -void ApplyIconFont(void) +void +ApplyIconFont(void) { - FvwmWindow *tmp; - - Scr.IconFont.height = Scr.IconFont.font->ascent+Scr.IconFont.font->descent; - Scr.IconFont.y = Scr.IconFont.font->ascent; - - tmp = Scr.FvwmRoot.next; - while(tmp != NULL) - { - RedoIconName(tmp); - - if(tmp->flags& ICONIFIED) - { - DrawIconWindow(tmp); - } - tmp = tmp->next; - } + FvwmWindow *tmp; + + Scr.IconFont.height = + Scr.IconFont.font->ascent + Scr.IconFont.font->descent; + Scr.IconFont.y = Scr.IconFont.font->ascent; + + tmp = Scr.FvwmRoot.next; + while (tmp != NULL) { + RedoIconName(tmp); + + if (tmp->flags & ICONIFIED) { + DrawIconWindow(tmp); + } + tmp = tmp->next; + } } -void LoadIconFont(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +LoadIconFont(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *font; - XFontStruct *newfont; - - action = GetNextToken(action,&font); - if (!font) - { - if (Scr.hasIconFont == True) - { - /* reset to default font */ - XFreeFont(dpy, Scr.IconFont.font); - Scr.hasIconFont = False; - } - Scr.IconFont.font = Scr.StdFont.font; - ApplyIconFont(); - return; - } - - if ((newfont = GetFontOrFixed(dpy, font))!=NULL) - { - if (Scr.IconFont.font != NULL && Scr.hasIconFont == True) - XFreeFont(dpy, Scr.IconFont.font); - Scr.hasIconFont = True; - Scr.IconFont.font = newfont; - ApplyIconFont(); - } - else - { - fvwm_msg(ERR,"LoadIconFont","Couldn't load font '%s' or 'fixed'\n", font); - } - free(font); + char *font; + XFontStruct *newfont; + + action = GetNextToken(action, &font); + if (!font) { + if (Scr.hasIconFont == True) { + /* reset to default font */ + XFreeFont(dpy, Scr.IconFont.font); + Scr.hasIconFont = False; + } + Scr.IconFont.font = Scr.StdFont.font; + ApplyIconFont(); + return; + } + + if ((newfont = GetFontOrFixed(dpy, font)) != NULL) { + if (Scr.IconFont.font != NULL && Scr.hasIconFont == True) + XFreeFont(dpy, Scr.IconFont.font); + Scr.hasIconFont = True; + Scr.IconFont.font = newfont; + ApplyIconFont(); + } else { + fvwm_msg(ERR, "LoadIconFont", + "Couldn't load font '%s' or 'fixed'\n", font); + } + free(font); } -void ApplyWindowFont(FvwmDecor *fl) +void +ApplyWindowFont(FvwmDecor *fl) { - FvwmWindow *tmp,*hi; - int x,y,w,h,extra_height; - - fl->WindowFont.height = - fl->WindowFont.font->ascent+fl->WindowFont.font->descent; - fl->WindowFont.y = fl->WindowFont.font->ascent; - extra_height = fl->TitleHeight; - fl->TitleHeight=fl->WindowFont.font->ascent+fl->WindowFont.font->descent+3; - extra_height -= fl->TitleHeight; - - tmp = Scr.FvwmRoot.next; - hi = Scr.Hilite; - while(tmp != NULL) - { - if (!(tmp->flags & TITLE) + FvwmWindow *tmp, *hi; + int x, y, w, h, extra_height; + + fl->WindowFont.height = + fl->WindowFont.font->ascent + fl->WindowFont.font->descent; + fl->WindowFont.y = fl->WindowFont.font->ascent; + extra_height = fl->TitleHeight; + fl->TitleHeight = + fl->WindowFont.font->ascent + fl->WindowFont.font->descent + 3; + extra_height -= fl->TitleHeight; + + tmp = Scr.FvwmRoot.next; + hi = Scr.Hilite; + while (tmp != NULL) { + if (!(tmp->flags & TITLE) #ifdef USEDECOR - || (tmp->fl != fl) + || (tmp->fl != fl) #endif - ) - { - tmp = tmp->next; - continue; - } - x = tmp->frame_x; - y = tmp->frame_y; - w = tmp->frame_width; - h = tmp->frame_height-extra_height; - tmp->frame_x = 0; - tmp->frame_y = 0; - tmp->frame_height = 0; - tmp->frame_width = 0; - SetupFrame(tmp,x,y,w,h,True); - SetTitleBar(tmp,True,True); - SetTitleBar(tmp,False,True); - tmp = tmp->next; - } - SetTitleBar(hi,True,True); + ) { + tmp = tmp->next; + continue; + } + x = tmp->frame_x; + y = tmp->frame_y; + w = tmp->frame_width; + h = tmp->frame_height - extra_height; + tmp->frame_x = 0; + tmp->frame_y = 0; + tmp->frame_height = 0; + tmp->frame_width = 0; + SetupFrame(tmp, x, y, w, h, True); + SetTitleBar(tmp, True, True); + SetTitleBar(tmp, False, True); + tmp = tmp->next; + } + SetTitleBar(hi, True, True); } -void LoadWindowFont(XEvent *eventp,Window win,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +LoadWindowFont(XEvent *eventp, Window win, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *font; - XFontStruct *newfont; + char *font; + XFontStruct *newfont; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - action = GetNextToken(action,&font); - if (!font) - { - /* reset to default font */ - if (Scr.hasWindowFont) - { - XFreeFont(dpy, Scr.DefaultDecor.WindowFont.font); - Scr.hasWindowFont = False; - fl->WindowFont.font = Scr.StdFont.font; - ApplyWindowFont(&Scr.DefaultDecor); - } - return; - } - - if ((newfont = GetFontOrFixed(dpy, font))!=NULL) - { - if (fl->WindowFont.font != NULL && - (fl != &Scr.DefaultDecor || Scr.hasWindowFont == True)) - XFreeFont(dpy, fl->WindowFont.font); - if (fl == &Scr.DefaultDecor) - Scr.hasWindowFont = True; - fl->WindowFont.font = newfont; - ApplyWindowFont(fl); - } - else - { - fvwm_msg(ERR,"LoadWindowFont","Couldn't load font '%s' or 'fixed'\n",font); - } - - free(font); + action = GetNextToken(action, &font); + if (!font) { + /* reset to default font */ + if (Scr.hasWindowFont) { + XFreeFont(dpy, Scr.DefaultDecor.WindowFont.font); + Scr.hasWindowFont = False; + fl->WindowFont.font = Scr.StdFont.font; + ApplyWindowFont(&Scr.DefaultDecor); + } + return; + } + + if ((newfont = GetFontOrFixed(dpy, font)) != NULL) { + if (fl->WindowFont.font != NULL && + (fl != &Scr.DefaultDecor || Scr.hasWindowFont == True)) + XFreeFont(dpy, fl->WindowFont.font); + if (fl == &Scr.DefaultDecor) + Scr.hasWindowFont = True; + fl->WindowFont.font = newfont; + ApplyWindowFont(fl); + } else { + fvwm_msg(ERR, "LoadWindowFont", + "Couldn't load font '%s' or 'fixed'\n", font); + } + + free(font); } -void FreeButtonFace(Display *dpy, ButtonFace *bf) +void +FreeButtonFace(Display *dpy, ButtonFace *bf) { - switch (bf->style) - { + switch (bf->style) { #ifdef GRADIENT_BUTTONS - case HGradButton: - case VGradButton: - /* - should we check visual is not TrueColor before doing this? - - XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, - bf->u.grad.pixels, bf->u.grad.npixels, - AllPlanes); */ - free(bf->u.grad.pixels); - bf->u.grad.pixels = NULL; - break; + case HGradButton: + case VGradButton: + /* - should we check visual is not TrueColor before doing this? + + XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, + bf->u.grad.pixels, bf->u.grad.npixels, + AllPlanes); */ + free(bf->u.grad.pixels); + bf->u.grad.pixels = NULL; + break; #endif #ifdef PIXMAP_BUTTONS - case PixmapButton: - case TiledPixmapButton: - if (bf->u.p) - DestroyPicture(dpy, bf->u.p); - bf->u.p = NULL; - break; + case PixmapButton: + case TiledPixmapButton: + if (bf->u.p) + DestroyPicture(dpy, bf->u.p); + bf->u.p = NULL; + break; #endif - default: - break; - } + default: + break; + } #ifdef MULTISTYLE - /* delete any compound styles */ - if (bf->next) { - FreeButtonFace(dpy, bf->next); - free(bf->next); - } - bf->next = NULL; + /* delete any compound styles */ + if (bf->next) { + FreeButtonFace(dpy, bf->next); + free(bf->next); + } + bf->next = NULL; #endif - bf->style = SimpleButton; + bf->style = SimpleButton; } /***************************************************************************** @@ -2888,517 +2811,509 @@ void FreeButtonFace(Display *dpy, ButtonFace *bf) * Reads a button face line into a structure (veliaa@rpi.edu) * ****************************************************************************/ -Boolean ReadButtonFace(char *s, ButtonFace *bf, int button, int verbose) +Boolean +ReadButtonFace(char *s, ButtonFace *bf, int button, int verbose) { - int offset; - char style[256], *file; - char *action = s; - - if (sscanf(s, "%s%n", style, &offset) < 1) { - if (verbose) - fvwm_msg(ERR, "ReadButtonFace", "error in face `%s'", s); - return False; - } - - if (strncasecmp(style, "--", 2) != 0) { - s += offset; - - FreeButtonFace(dpy, bf); - - /* determine button style */ - if (strncasecmp(style,"Simple",6)==0) - { - bf->style = SimpleButton; - } - else if (strncasecmp(style,"Default",7)==0) { - int b = -1, n = sscanf(s, "%d%n", &b, &offset); - - if (n < 1) { - if (button == -1) { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "need default button number to load"); - return False; - } - b = button; - } - s += offset; - if ((b > 0) && (b <= 10)) - LoadDefaultButton(bf, b); - else { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "button number out of range: %d", b); + int offset; + char style[256], *file; + char *action = s; + + if (sscanf(s, "%s%n", style, &offset) < 1) { + if (verbose) + fvwm_msg( + ERR, "ReadButtonFace", "error in face `%s'", s); return False; - } } -#ifdef VECTOR_BUTTONS - else if (strncasecmp(style,"Vector",6)==0 || - (strlen(style)<=2 && isdigit(*style))) - { - /* normal coordinate list button style */ - int i, num_coords, num; - struct vector_coords *vc = &bf->vector; - /* get number of points */ - if (strncasecmp(style,"Vector",6)==0) { - num = sscanf(s,"%d%n",&num_coords,&offset); + if (strncasecmp(style, "--", 2) != 0) { s += offset; - } else - num = sscanf(style,"%d",&num_coords); - if((num != 1)||(num_coords>20)||(num_coords<2)) - { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "Bad button style (2) in line: %s",action); - return False; - } - - vc->num = num_coords; + FreeButtonFace(dpy, bf); + + /* determine button style */ + if (strncasecmp(style, "Simple", 6) == 0) { + bf->style = SimpleButton; + } else if (strncasecmp(style, "Default", 7) == 0) { + int b = -1, n = sscanf(s, "%d%n", &b, &offset); + + if (n < 1) { + if (button == -1) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "need default button " + "number to load"); + return False; + } + b = button; + } + s += offset; + if ((b > 0) && (b <= 10)) + LoadDefaultButton(bf, b); + else { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "button number out of range: %d", + b); + return False; + } + } +#ifdef VECTOR_BUTTONS + else if (strncasecmp(style, "Vector", 6) == 0 || + (strlen(style) <= 2 && isdigit(*style))) { + /* normal coordinate list button style */ + int i, num_coords, num; + struct vector_coords *vc = &bf->vector; + + /* get number of points */ + if (strncasecmp(style, "Vector", 6) == 0) { + num = sscanf(s, "%d%n", &num_coords, &offset); + s += offset; + } else + num = sscanf(style, "%d", &num_coords); + + if ((num != 1) || (num_coords > 20) || + (num_coords < 2)) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "Bad button style (2) in line: %s", + action); + return False; + } - /* get the points */ - for(i = 0; i < vc->num; ++i) - { - /* X x Y @ line_style */ - num = sscanf(s,"%dx%d@%d%n",&vc->x[i],&vc->y[i], - &vc->line_style[i], &offset); - if(num != 3) - { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "Bad button style (3) in line %s", - action); - return False; + vc->num = num_coords; + + /* get the points */ + for (i = 0; i < vc->num; ++i) { + /* X x Y @ line_style */ + num = sscanf(s, "%dx%d@%d%n", &vc->x[i], + &vc->y[i], &vc->line_style[i], &offset); + if (num != 3) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "Bad button style (3) in " + "line %s", + action); + return False; + } + s += offset; + } + bf->style = VectorButton; } - s += offset; - } - bf->style = VectorButton; - } #endif - else if (strncasecmp(style,"Solid",5)==0) - { - s = GetNextToken(s, &file); - if (file) { - bf->style = SolidButton; - bf->u.back = GetColor(file); - free(file); - } else { - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", - "no color given for Solid face type: %s", action); - return False; - } - } -#ifdef GRADIENT_BUTTONS - else if (strncasecmp(style,"HGradient",9)==0 - || strncasecmp(style,"VGradient",9)==0) - { - char *item, **s_colors; - int npixels, nsegs, i, sum, *perc; - Pixel *pixels; - - if (!(s = GetNextToken(s, &item)) || (item == NULL)) { - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", - "expected number of colors to allocate in gradient"); - if (item) - free(item); - return False; - } - npixels = atoi(item); - free(item); - - if (!(s = GetNextToken(s, &item)) || (item == NULL)) { - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", "incomplete gradient style"); - if (item) - free(item); - return False; - } - - if (!(isdigit(*item))) { - s_colors = (char **)safemalloc(sizeof(char *) * 2); - perc = (int *)safemalloc(sizeof(int)); - nsegs = 1; - s_colors[0] = item; - s = GetNextToken(s, &s_colors[1]); - perc[0] = 100; - } else { - nsegs = atoi(item); - free(item); - if (nsegs < 1) nsegs = 1; - if (nsegs > 128) nsegs = 128; - s_colors = (char **)safemalloc(sizeof(char *) * (nsegs + 1)); - perc = (int *)safemalloc(sizeof(int) * nsegs); - for (i = 0; i <= nsegs; ++i) { - s =GetNextToken(s, &s_colors[i]); - if (i < nsegs) { - s = GetNextToken(s, &item); - if (item) - { - perc[i] = atoi(item); - free(item); - } - else - perc[i] = 0; - } + else if (strncasecmp(style, "Solid", 5) == 0) { + s = GetNextToken(s, &file); + if (file) { + bf->style = SolidButton; + bf->u.back = GetColor(file); + free(file); + } else { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "no color given for Solid face " + "type: %s", + action); + return False; + } } - } - - for (i = 0, sum = 0; i < nsegs; ++i) - sum += perc[i]; - - if (sum != 100) { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "multi gradient lengths must sum to 100"); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(s_colors); - free(perc); - return False; - } +#ifdef GRADIENT_BUTTONS + else if (strncasecmp(style, "HGradient", 9) == 0 || + strncasecmp(style, "VGradient", 9) == 0) { + char *item, **s_colors; + int npixels, nsegs, i, sum, *perc; + Pixel *pixels; + + if (!(s = GetNextToken(s, &item)) || (item == NULL)) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "expected number of colors to " + "allocate in gradient"); + if (item) + free(item); + return False; + } + npixels = atoi(item); + free(item); + + if (!(s = GetNextToken(s, &item)) || (item == NULL)) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "incomplete gradient style"); + if (item) + free(item); + return False; + } - if (npixels < 2) npixels = 2; - if (npixels > 128) npixels = 128; + if (!(isdigit(*item))) { + s_colors = + (char **)xmalloc(sizeof(char *) * 2); + perc = (int *)xmalloc(sizeof(int)); + nsegs = 1; + s_colors[0] = item; + s = GetNextToken(s, &s_colors[1]); + perc[0] = 100; + } else { + nsegs = atoi(item); + free(item); + if (nsegs < 1) + nsegs = 1; + if (nsegs > 128) + nsegs = 128; + s_colors = (char **)xmalloc( + sizeof(char *) * (nsegs + 1)); + perc = (int *)xmalloc(sizeof(int) * nsegs); + for (i = 0; i <= nsegs; ++i) { + s = GetNextToken(s, &s_colors[i]); + if (i < nsegs) { + s = GetNextToken(s, &item); + if (item) { + perc[i] = atoi(item); + free(item); + } else + perc[i] = 0; + } + } + } - pixels = AllocNonlinearGradient(s_colors, perc, nsegs, npixels); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(s_colors); - free(perc); + for (i = 0, sum = 0; i < nsegs; ++i) + sum += perc[i]; + + if (sum != 100) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "multi gradient lengths must sum " + "to 100"); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(s_colors); + free(perc); + return False; + } - if (!pixels) { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "couldn't create gradient"); - return False; - } + if (npixels < 2) + npixels = 2; + if (npixels > 128) + npixels = 128; + + pixels = AllocNonlinearGradient( + s_colors, perc, nsegs, npixels); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(s_colors); + free(perc); + + if (!pixels) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "couldn't create gradient"); + return False; + } - bf->u.grad.pixels = pixels; - bf->u.grad.npixels = npixels; + bf->u.grad.pixels = pixels; + bf->u.grad.npixels = npixels; - if (strncasecmp(style,"H",1)==0) - bf->style = HGradButton; - else - bf->style = VGradButton; - } + if (strncasecmp(style, "H", 1) == 0) + bf->style = HGradButton; + else + bf->style = VGradButton; + } #endif /* GRADIENT_BUTTONS */ #ifdef PIXMAP_BUTTONS - else if (strncasecmp(style,"Pixmap",6)==0 - || strncasecmp(style,"TiledPixmap",11)==0) - { - s = GetNextToken(s, &file); - bf->u.p = CachePicture(dpy, Scr.Root, - IconPath, - PixmapPath, - file,Scr.ColorLimit); - if (bf->u.p == NULL) - { - if (file) - { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "couldn't load pixmap %s", file); - free(file); - } - return False; - } - if (file) - { - free(file); - file = NULL; - } + else if (strncasecmp(style, "Pixmap", 6) == 0 || + strncasecmp(style, "TiledPixmap", 11) == 0) { + s = GetNextToken(s, &file); + bf->u.p = CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, file, Scr.ColorLimit); + if (bf->u.p == NULL) { + if (file) { + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "couldn't load pixmap %s", + file); + free(file); + } + return False; + } + if (file) { + free(file); + file = NULL; + } - if (strncasecmp(style,"Tiled",5)==0) - bf->style = TiledPixmapButton; - else - bf->style = PixmapButton; - } + if (strncasecmp(style, "Tiled", 5) == 0) + bf->style = TiledPixmapButton; + else + bf->style = PixmapButton; + } #ifdef MINI_ICONS - else if (strncasecmp (style, "MiniIcon", 8) == 0) { - bf->style = MiniIconButton; -#if 0 -/* Have to remove this again. This is all so badly written there is no chance - * to prevent a coredump and a memory leak the same time without a rewrite of - * large parts of the code. */ - if (bf->u.p) - DestroyPicture(dpy, bf->u.p); -#endif - bf->u.p = NULL; /* pixmap read in when the window is created */ - } + else if (strncasecmp(style, "MiniIcon", 8) == 0) { + bf->style = MiniIconButton; + bf->u.p = NULL; /* pixmap read in when the window is + created */ + } #endif #endif /* PIXMAP_BUTTONS */ - else { - if(verbose)fvwm_msg(ERR,"ReadButtonFace", - "unknown style %s: %s", style, action); - return False; - } - } - - /* Process button flags ("--" signals start of flags, - it is also checked for above) */ - s = GetNextToken(s, &file); - if (file && (strcmp(file,"--")==0)) { - char *tok; - s = GetNextToken(s, &tok); - while (tok&&*tok) - { - int set = 1; - - if (*tok == '!') { /* flag negate */ - set = 0; - ++tok; - } - if (StrEquals(tok,"Clear")) { - if (set) - bf->style &= ButtonFaceTypeMask; - else - bf->style |= ~ButtonFaceTypeMask; /* ? */ - } - else if (StrEquals(tok,"Left")) - { - if (set) { - bf->style |= HOffCenter; - bf->style &= ~HRight; - } else - bf->style |= HOffCenter | HRight; - } - else if (StrEquals(tok,"Right")) - { - if (set) - bf->style |= HOffCenter | HRight; else { - bf->style |= HOffCenter; - bf->style &= ~HRight; + if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "unknown style %s: %s", style, action); + return False; } - } - else if (StrEquals(tok,"Centered")) { - bf->style &= ~HOffCenter; - bf->style &= ~VOffCenter; - } - else if (StrEquals(tok,"Top")) - { - if (set) { - bf->style |= VOffCenter; - bf->style &= ~VBottom; - } else - bf->style |= VOffCenter | VBottom; + } - } - else if (StrEquals(tok,"Bottom")) - { - if (set) - bf->style |= VOffCenter | VBottom; - else { - bf->style |= VOffCenter; - bf->style &= ~VBottom; - } - } - else if (StrEquals(tok,"Flat")) - { - if (set) { - bf->style &= ~SunkButton; - bf->style |= FlatButton; - } else - bf->style &= ~FlatButton; - } - else if (StrEquals(tok,"Sunk")) - { - if (set) { - bf->style &= ~FlatButton; - bf->style |= SunkButton; - } else - bf->style &= ~SunkButton; - } - else if (StrEquals(tok,"Raised")) - { - if (set) { - bf->style &= ~FlatButton; - bf->style &= ~SunkButton; - } else { - bf->style |= SunkButton; - bf->style &= ~FlatButton; - } - } + /* Process button flags ("--" signals start of flags, + it is also checked for above) */ + s = GetNextToken(s, &file); + if (file && (strcmp(file, "--") == 0)) { + char *tok; + s = GetNextToken(s, &tok); + while (tok && *tok) { + int set = 1; + + if (*tok == '!') { /* flag negate */ + set = 0; + ++tok; + } + if (StrEquals(tok, "Clear")) { + if (set) + bf->style &= ButtonFaceTypeMask; + else + bf->style |= + ~ButtonFaceTypeMask; /* ? */ + } else if (StrEquals(tok, "Left")) { + if (set) { + bf->style |= HOffCenter; + bf->style &= ~HRight; + } else + bf->style |= HOffCenter | HRight; + } else if (StrEquals(tok, "Right")) { + if (set) + bf->style |= HOffCenter | HRight; + else { + bf->style |= HOffCenter; + bf->style &= ~HRight; + } + } else if (StrEquals(tok, "Centered")) { + bf->style &= ~HOffCenter; + bf->style &= ~VOffCenter; + } else if (StrEquals(tok, "Top")) { + if (set) { + bf->style |= VOffCenter; + bf->style &= ~VBottom; + } else + bf->style |= VOffCenter | VBottom; + } else if (StrEquals(tok, "Bottom")) { + if (set) + bf->style |= VOffCenter | VBottom; + else { + bf->style |= VOffCenter; + bf->style &= ~VBottom; + } + } else if (StrEquals(tok, "Flat")) { + if (set) { + bf->style &= ~SunkButton; + bf->style |= FlatButton; + } else + bf->style &= ~FlatButton; + } else if (StrEquals(tok, "Sunk")) { + if (set) { + bf->style &= ~FlatButton; + bf->style |= SunkButton; + } else + bf->style &= ~SunkButton; + } else if (StrEquals(tok, "Raised")) { + if (set) { + bf->style &= ~FlatButton; + bf->style &= ~SunkButton; + } else { + bf->style |= SunkButton; + bf->style &= ~FlatButton; + } + } #ifdef EXTENDED_TITLESTYLE - else if (StrEquals(tok,"UseTitleStyle")) - { - if (set) { - bf->style |= UseTitleStyle; + else if (StrEquals(tok, "UseTitleStyle")) { + if (set) { + bf->style |= UseTitleStyle; #ifdef BORDERSTYLE - bf->style &= ~UseBorderStyle; + bf->style &= ~UseBorderStyle; #endif - } else - bf->style &= ~UseTitleStyle; - } + } else + bf->style &= ~UseTitleStyle; + } #endif #ifdef BORDERSTYLE - else if (StrEquals(tok,"HiddenHandles")) - { - if (set) - bf->style |= HiddenHandles; - else - bf->style &= ~HiddenHandles; - } - else if (StrEquals(tok,"NoInset")) - { - if (set) - bf->style |= NoInset; - else - bf->style &= ~NoInset; - } - else if (StrEquals(tok,"UseBorderStyle")) - { - if (set) { - bf->style |= UseBorderStyle; + else if (StrEquals(tok, "HiddenHandles")) { + if (set) + bf->style |= HiddenHandles; + else + bf->style &= ~HiddenHandles; + } else if (StrEquals(tok, "NoInset")) { + if (set) + bf->style |= NoInset; + else + bf->style &= ~NoInset; + } else if (StrEquals(tok, "UseBorderStyle")) { + if (set) { + bf->style |= UseBorderStyle; #ifdef EXTENDED_TITLESTYLE - bf->style &= ~UseTitleStyle; + bf->style &= ~UseTitleStyle; #endif - } else - bf->style &= ~UseBorderStyle; - } + } else + bf->style &= ~UseBorderStyle; + } #endif - else - if(verbose) - fvwm_msg(ERR,"ReadButtonFace", - "unknown button face flag %s -- line: %s", - tok, action); - if (set) - free(tok); - else - free(tok - 1); - s = GetNextToken(s, &tok); - } - } - if (file) - free(file); - return True; + else if (verbose) + fvwm_msg(ERR, "ReadButtonFace", + "unknown button face flag %s -- line: %s", + tok, action); + if (set) + free(tok); + else + free(tok - 1); + s = GetNextToken(s, &tok); + } + } + if (file) + free(file); + return True; } - /***************************************************************************** * * Reads a title button description (veliaa@rpi.edu) * ****************************************************************************/ -char *ReadTitleButton(char *s, TitleButton *tb, Boolean append, int button) +char * +ReadTitleButton(char *s, TitleButton *tb, Boolean append, int button) { - char *end = NULL, *spec; - ButtonFace tmpbf; - enum ButtonState bs = MaxButtonState; - int i = 0, all = 0, pstyle = 0; - - while(isspace(*s))++s; - for (; i < MaxButtonState; ++i) - if (strncasecmp(button_states[i],s, - strlen(button_states[i]))==0) { - bs = i; - break; - } - if (bs != MaxButtonState) - s += strlen(button_states[bs]); - else - all = 1; - while(isspace(*s))++s; - if ('(' == *s) { - int len; - pstyle = 1; - if (!(end = strchr(++s, ')'))) { - fvwm_msg(ERR,"ReadTitleButton", - "missing parenthesis: %s", s); - return NULL; - } - len = end - s + 1; - spec = safemalloc(len); - strncpy(spec, s, len - 1); - spec[len - 1] = 0; - } else - spec = s; - - while(isspace(*spec))++spec; - /* setup temporary in case button read fails */ - tmpbf.style = SimpleButton; + char *end = NULL, *spec; + ButtonFace tmpbf; + enum ButtonState bs = MaxButtonState; + int i = 0, all = 0, pstyle = 0; + + while (isspace(*s)) + ++s; + for (; i < MaxButtonState; ++i) + if (strncasecmp( + button_states[i], s, strlen(button_states[i])) == 0) { + bs = i; + break; + } + if (bs != MaxButtonState) + s += strlen(button_states[bs]); + else + all = 1; + while (isspace(*s)) + ++s; + if ('(' == *s) { + int len; + pstyle = 1; + if (!(end = strchr(++s, ')'))) { + fvwm_msg(ERR, "ReadTitleButton", + "missing parenthesis: %s", s); + return NULL; + } + len = end - s + 1; + spec = xmalloc(len); + strncpy(spec, s, len - 1); + spec[len - 1] = 0; + } else + spec = s; + + while (isspace(*spec)) + ++spec; + /* setup temporary in case button read fails */ + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif #ifdef MINI_ICONS - tmpbf.u.p = NULL; + tmpbf.u.p = NULL; #endif - if (strncmp(spec, "--",2)==0) { - /* only change flags */ - if (ReadButtonFace(spec, &tb->state[all ? 0 : bs],button,True) && all) { - for (i = 0; i < MaxButtonState; ++i) - ReadButtonFace(spec, &tb->state[i],-1,False); - } - } - else if (ReadButtonFace(spec, &tmpbf,button,True)) { - int b = all ? 0 : bs; -#ifdef MULTISTYLE - if (append) { - ButtonFace *tail = &tb->state[b]; - while (tail->next) tail = tail->next; - tail->next = (ButtonFace *)safemalloc(sizeof(ButtonFace)); - *tail->next = tmpbf; - if (all) - for (i = 1; i < MaxButtonState; ++i) { - tail = &tb->state[i]; - while (tail->next) tail = tail->next; - tail->next = (ButtonFace *)safemalloc(sizeof(ButtonFace)); - tail->next->style = SimpleButton; - tail->next->next = NULL; - ReadButtonFace(spec, tail->next, button, False); + if (strncmp(spec, "--", 2) == 0) { + /* only change flags */ + if (ReadButtonFace( + spec, &tb->state[all ? 0 : bs], button, True) && + all) { + for (i = 0; i < MaxButtonState; ++i) + ReadButtonFace(spec, &tb->state[i], -1, False); } - } - else { + } else if (ReadButtonFace(spec, &tmpbf, button, True)) { + int b = all ? 0 : bs; +#ifdef MULTISTYLE + if (append) { + ButtonFace *tail = &tb->state[b]; + while (tail->next) + tail = tail->next; + tail->next = + (ButtonFace *)xmalloc(sizeof(ButtonFace)); + *tail->next = tmpbf; + if (all) + for (i = 1; i < MaxButtonState; ++i) { + tail = &tb->state[i]; + while (tail->next) + tail = tail->next; + tail->next = (ButtonFace *)xmalloc( + sizeof(ButtonFace)); + tail->next->style = SimpleButton; + tail->next->next = NULL; + ReadButtonFace( + spec, tail->next, button, False); + } + } else { #endif - FreeButtonFace(dpy, &tb->state[b]); - tb->state[b] = tmpbf; - if (all) - for (i = 1; i < MaxButtonState; ++i) - ReadButtonFace(spec, &tb->state[i],button,False); + FreeButtonFace(dpy, &tb->state[b]); + tb->state[b] = tmpbf; + if (all) + for (i = 1; i < MaxButtonState; ++i) + ReadButtonFace( + spec, &tb->state[i], button, False); #ifdef MULTISTYLE - } + } #endif - - } - if (pstyle) { - free(spec); - ++end; - while(isspace(*end))++end; - } - return end; + } + if (pstyle) { + free(spec); + ++end; + while (isspace(*end)) + ++end; + } + return end; } -static void FreeMenuFace(Display *dpy, MenuFace *mf) +static void +FreeMenuFace(Display *dpy, MenuFace *mf) { - switch (mf->type) - { + switch (mf->type) { #ifdef GRADIENT_BUTTONS - case HGradMenu: - case VGradMenu: - case DGradMenu: - /* - should we check visual is not TrueColor before doing this? - * - * XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, - * ms->u.grad.pixels, ms->u.grad.npixels, - * AllPlanes); */ - free(mf->u.grad.pixels); - mf->u.grad.pixels = NULL; - break; + case HGradMenu: + case VGradMenu: + case DGradMenu: + /* - should we check visual is not TrueColor before doing this? + * + * XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, + * ms->u.grad.pixels, ms->u.grad.npixels, + * AllPlanes); */ + free(mf->u.grad.pixels); + mf->u.grad.pixels = NULL; + break; #endif #ifdef PIXMAP_BUTTONS - case PixmapMenu: - case TiledPixmapMenu: - if (mf->u.p) - DestroyPicture(dpy, mf->u.p); - mf->u.p = NULL; - break; + case PixmapMenu: + case TiledPixmapMenu: + if (mf->u.p) + DestroyPicture(dpy, mf->u.p); + mf->u.p = NULL; + break; #endif - case SolidMenu: - FreeColors(&mf->u.back, 1); - default: - break; - } - mf->type = SimpleMenu; + case SolidMenu: + FreeColors(&mf->u.back, 1); + default: + break; + } + mf->type = SimpleMenu; } /***************************************************************************** @@ -3406,213 +3321,202 @@ static void FreeMenuFace(Display *dpy, MenuFace *mf) * Reads a menu face line into a structure (veliaa@rpi.edu) * ****************************************************************************/ -static Boolean ReadMenuFace(char *s, MenuFace *mf, int verbose) +static Boolean +ReadMenuFace(char *s, MenuFace *mf, int verbose) { - char *style; - char *token; - char *action = s; - - s = GetNextToken(s, &style); - if (style && strncasecmp(style, "--", 2) == 0) - { - free(style); - return True; - } - - FreeMenuFace(dpy, mf); - mf->type = SimpleMenu; - - /* determine menu style */ - if (!style) - return True; - else if (StrEquals(style,"Solid")) - { - s = GetNextToken(s, &token); - if (token) - { - mf->type = SolidMenu; - mf->u.back = GetColor(token); - free(token); - } - else - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "no color given for Solid face type: %s", - action); - free(style); - return False; - } - } + char *style; + char *token; + char *action = s; + + s = GetNextToken(s, &style); + if (style && strncasecmp(style, "--", 2) == 0) { + free(style); + return True; + } + FreeMenuFace(dpy, mf); + mf->type = SimpleMenu; + + /* determine menu style */ + if (!style) + return True; + else if (StrEquals(style, "Solid")) { + s = GetNextToken(s, &token); + if (token) { + mf->type = SolidMenu; + mf->u.back = GetColor(token); + free(token); + } else { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "no color given for Solid face type: %s", + action); + free(style); + return False; + } + } #ifdef GRADIENT_BUTTONS - else if (StrEquals(style,"HGradient") || StrEquals(style, "VGradient") || - StrEquals(style,"DGradient") || StrEquals(style, "BGradient")) - { - char *item, **s_colors; - int npixels, nsegs, i, sum, perc[128]; - Pixel *pixels; - char gtype = style[0]; - - s = GetNextToken(s, &item); - if (!item) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", - "expected number of colors to allocate in gradient"); - free(style); - return False; - } - npixels = atoi(item); - free(item); - - s = GetNextToken(s, &item); - if (!item) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "incomplete gradient style"); - free(style); - return False; - } - - if (!(isdigit(*item))) - { - s_colors = (char **)safemalloc(sizeof(char *) * 2); - nsegs = 1; - s_colors[0] = item; - s = GetNextToken(s, &s_colors[1]); - if (!s_colors[1]) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "incomplete gradient style"); - free(s_colors); - free(item); - free(style); - return False; - } - perc[0] = 100; - } - else - { - nsegs = atoi(item); - free(item); - if (nsegs < 1) - nsegs = 1; - if (nsegs > 128) - nsegs = 128; - s_colors = (char **)safemalloc(sizeof(char *) * (nsegs + 1)); - for (i = 0; i <= nsegs; ++i) - { - s = GetNextToken(s, &s_colors[i]); - if (i < nsegs) - { - s = GetNextToken(s, &item); - perc[i] = (item) ? atoi(item) : 0; - if (item) - free(item); - } - } - } - - for (i = 0, sum = 0; i < nsegs; ++i) - sum += perc[i]; - - if (sum != 100) - { - if(verbose) - fvwm_msg(ERR,"ReadMenuFace", "multi gradient lenghts must sum to 100"); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(style); - free(s_colors); - return False; - } - - if (npixels < 2) - npixels = 2; - if (npixels > 128) - npixels = 128; - - pixels = AllocNonlinearGradient(s_colors, perc, nsegs, npixels); - for (i = 0; i <= nsegs; ++i) - if (s_colors[i]) - free(s_colors[i]); - free(s_colors); - - if (!pixels) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "couldn't create gradient"); - free(style); - return False; - } - - mf->u.grad.pixels = pixels; - mf->u.grad.npixels = npixels; - - switch (gtype) - { - case 'h': - case 'H': - mf->type = HGradMenu; - break; - case 'v': - case 'V': - mf->type = VGradMenu; - break; - case 'd': - case 'D': - mf->type = DGradMenu; - break; - default: - mf->type = BGradMenu; - break; - } - } + else if (StrEquals(style, "HGradient") || + StrEquals(style, "VGradient") || + StrEquals(style, "DGradient") || + StrEquals(style, "BGradient")) { + char *item, **s_colors; + int npixels, nsegs, i, sum, perc[128]; + Pixel *pixels; + char gtype = style[0]; + + s = GetNextToken(s, &item); + if (!item) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "expected number of colors to allocate in " + "gradient"); + free(style); + return False; + } + npixels = atoi(item); + free(item); + + s = GetNextToken(s, &item); + if (!item) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "incomplete gradient style"); + free(style); + return False; + } + + if (!(isdigit(*item))) { + s_colors = (char **)xmalloc(sizeof(char *) * 2); + nsegs = 1; + s_colors[0] = item; + s = GetNextToken(s, &s_colors[1]); + if (!s_colors[1]) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "incomplete gradient style"); + free(item); + free(s_colors); + free(style); + return False; + } + perc[0] = 100; + } else { + nsegs = atoi(item); + free(item); + if (nsegs < 1) + nsegs = 1; + if (nsegs > 128) + nsegs = 128; + s_colors = + (char **)xmalloc(sizeof(char *) * (nsegs + 1)); + for (i = 0; i <= nsegs; ++i) { + s = GetNextToken(s, &s_colors[i]); + if (i < nsegs) { + s = GetNextToken(s, &item); + perc[i] = (item) ? atoi(item) : 0; + if (item) + free(item); + } + } + } + + for (i = 0, sum = 0; i < nsegs; ++i) + sum += perc[i]; + + if (sum != 100) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "multi gradient lengths must sum to 100"); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(style); + free(s_colors); + return False; + } + + if (npixels < 2) + npixels = 2; + if (npixels > 128) + npixels = 128; + + pixels = AllocNonlinearGradient(s_colors, perc, nsegs, npixels); + for (i = 0; i <= nsegs; ++i) + if (s_colors[i]) + free(s_colors[i]); + free(s_colors); + + if (!pixels) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "couldn't create gradient"); + free(style); + return False; + } + + mf->u.grad.pixels = pixels; + mf->u.grad.npixels = npixels; + + switch (gtype) { + case 'h': + case 'H': + mf->type = HGradMenu; + break; + case 'v': + case 'V': + mf->type = VGradMenu; + break; + case 'd': + case 'D': + mf->type = DGradMenu; + break; + default: + mf->type = BGradMenu; + break; + } + } #endif /* GRADIENT_BUTTONS */ #ifdef PIXMAP_BUTTONS - else if (StrEquals(style,"Pixmap") || StrEquals(style,"TiledPixmap")) - { - s = GetNextToken(s, &token); - if (token) - { - mf->u.p = CachePicture(dpy, Scr.Root, IconPath, - PixmapPath, - token, Scr.ColorLimit); - if (mf->u.p == NULL) - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "couldn't load pixmap %s", token); - free(token); - free(style); - return False; - } - free(token); - mf->type = (StrEquals(style,"TiledPixmap")) ? - TiledPixmapMenu : PixmapMenu; - } - else - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "missing pixmap name for style %s", - style); - free(style); - return False; - } - } + else if (StrEquals(style, "Pixmap") || + StrEquals(style, "TiledPixmap")) { + s = GetNextToken(s, &token); + if (token) { + mf->u.p = CachePicture(dpy, Scr.Root, IconPath, + PixmapPath, token, Scr.ColorLimit); + if (mf->u.p == NULL) { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "couldn't load pixmap %s", token); + free(token); + free(style); + return False; + } + free(token); + mf->type = (StrEquals(style, "TiledPixmap")) ? + TiledPixmapMenu : + PixmapMenu; + } else { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", + "missing pixmap name for style %s", style); + free(style); + return False; + } + } #endif /* PIXMAP_BUTTONS */ - else - { - if(verbose) - fvwm_msg(ERR, "ReadMenuFace", "unknown style %s: %s", style, action); - free(style); - return False; - } + else { + if (verbose) + fvwm_msg(ERR, "ReadMenuFace", "unknown style %s: %s", + style, action); + free(style); + return False; + } - free(style); - return True; + free(style); + return True; } #ifdef USEDECOR @@ -3621,14 +3525,18 @@ static Boolean ReadMenuFace(char *s, MenuFace *mf, int verbose) * Diverts a style definition to an FvwmDecor structure (veliaa@rpi.edu) * ****************************************************************************/ -void AddToDecor(FvwmDecor *fl, char *s) +void +AddToDecor(FvwmDecor *fl, char *s) { - if (!s) return; - while (*s&&isspace(*s))++s; - if (!*s) return; - cur_decor = fl; - ExecuteFunction(s,NULL,&Event,C_ROOT,-1); - cur_decor = NULL; + if (!s) + return; + while (*s && isspace(*s)) + ++s; + if (!*s) + return; + cur_decor = fl; + ExecuteFunction(s, NULL, &Event, C_ROOT, -1); + cur_decor = NULL; } /***************************************************************************** @@ -3636,47 +3544,49 @@ void AddToDecor(FvwmDecor *fl, char *s) * Changes the window's FvwmDecor pointer (veliaa@rpi.edu) * ****************************************************************************/ -void ChangeDecor(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +ChangeDecor(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *item; - int x,y,width,height,old_height,extra_height; - FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonRelease)) - return; - action = GetNextToken(action, &item); - if (!action || !item) - { - if (item) - free(item); - return; - } - /* search for tag */ - for (; fl; fl = fl->next) - if (fl->tag) - if (StrEquals(item, fl->tag)) { - found = fl; - break; - } - free(item); - if (!found) { - XBell(dpy, 0); - return; - } - old_height = tmp_win->fl->TitleHeight; - tmp_win->fl = found; - extra_height = (tmp_win->flags & TITLE) ? - (old_height - tmp_win->fl->TitleHeight) : 0; - x = tmp_win->frame_x; - y = tmp_win->frame_y; - width = tmp_win->frame_width; - height = tmp_win->frame_height - extra_height; - tmp_win->frame_x = 0; - tmp_win->frame_y = 0; - tmp_win->frame_height = 0; - tmp_win->frame_width = 0; - SetupFrame(tmp_win,x,y,width,height,True); - SetBorder(tmp_win,Scr.Hilite == tmp_win,True,True,None); + char *item; + int x, y, width, height, old_height, extra_height; + FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonRelease)) + return; + action = GetNextToken(action, &item); + if (!action || !item) { + if (item) + free(item); + return; + } + /* search for tag */ + for (; fl; fl = fl->next) + if (fl->tag) + if (StrEquals(item, fl->tag)) { + found = fl; + break; + } + free(item); + if (!found) { + XBell(dpy, 0); + return; + } + old_height = tmp_win->fl->TitleHeight; + tmp_win->fl = found; + extra_height = (tmp_win->flags & TITLE) ? + (old_height - tmp_win->fl->TitleHeight) : + 0; + x = tmp_win->frame_x; + y = tmp_win->frame_y; + width = tmp_win->frame_width; + height = tmp_win->frame_height - extra_height; + tmp_win->frame_x = 0; + tmp_win->frame_y = 0; + tmp_win->frame_height = 0; + tmp_win->frame_width = 0; + SetupFrame(tmp_win, x, y, width, height, True); + SetBorder(tmp_win, Scr.Hilite == tmp_win, True, True, None); } /***************************************************************************** @@ -3684,45 +3594,44 @@ void ChangeDecor(XEvent *eventp,Window w,FvwmWindow *tmp_win, * Destroys an FvwmDecor (veliaa@rpi.edu) * ****************************************************************************/ -void DestroyDecor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +DestroyDecor(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *item; - FvwmDecor *fl = Scr.DefaultDecor.next; - FvwmDecor *prev = &Scr.DefaultDecor, *found = NULL; + char *item; + FvwmDecor *fl = Scr.DefaultDecor.next; + FvwmDecor *prev = &Scr.DefaultDecor, *found = NULL; - action = GetNextToken(action, &item); - if (!action || !item) - { - if (item) - free(item); - return; - } + action = GetNextToken(action, &item); + if (!action || !item) { + if (item) + free(item); + return; + } - /* search for tag */ - for (; fl; fl = fl->next) { - if (fl->tag) - if (StrEquals(item, fl->tag)) { - found = fl; - break; - } - prev = fl; - } - free(item); + /* search for tag */ + for (; fl; fl = fl->next) { + if (fl->tag) + if (StrEquals(item, fl->tag)) { + found = fl; + break; + } + prev = fl; + } + free(item); - if (found && (found != &Scr.DefaultDecor)) { - FvwmWindow *fw = Scr.FvwmRoot.next; - while(fw != NULL) - { - if (fw->fl == found) - ExecuteFunction("ChangeDecor Default",fw,eventp, - C_WINDOW,*Module); - fw = fw->next; - } - prev->next = found->next; - DestroyFvwmDecor(found); - free(found); - } + if (found && (found != &Scr.DefaultDecor)) { + FvwmWindow *fw = Scr.FvwmRoot.next; + while (fw != NULL) { + if (fw->fl == found) + ExecuteFunction("ChangeDecor Default", fw, + eventp, C_WINDOW, *Module); + fw = fw->next; + } + prev->next = found->next; + DestroyFvwmDecor(found); + free(found); + } } /***************************************************************************** @@ -3730,265 +3639,289 @@ void DestroyDecor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Initiates an AddToDecor (veliaa@rpi.edu) * ****************************************************************************/ -void add_item_to_decor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +add_item_to_decor(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmDecor *fl, *found = NULL; - char *item = NULL, *s = action; + FvwmDecor *fl, *found = NULL; + char *item = NULL, *s = action; - last_menu = NULL; + last_menu = NULL; - s = GetNextToken(s, &item); + s = GetNextToken(s, &item); - if (!item) - return; - if (!s) - { - free(item); - return; - } - /* search for tag */ - for (fl = &Scr.DefaultDecor; fl; fl = fl->next) - if (fl->tag) - if (StrEquals(item, fl->tag)) { - found = fl; - break; - } - if (!found) { /* then make a new one */ - found = (FvwmDecor *)safemalloc(sizeof( FvwmDecor )); - InitFvwmDecor(found); - found->tag = item; /* tag it */ - /* add it to list */ - for (fl = &Scr.DefaultDecor; fl->next; fl = fl->next); - fl->next = found; - } else - free(item); - if (found) { - AddToDecor(found, s); - last_decor = found; - } + if (!item) + return; + if (!s) { + free(item); + return; + } + /* search for tag */ + for (fl = &Scr.DefaultDecor; fl; fl = fl->next) + if (fl->tag) + if (StrEquals(item, fl->tag)) { + found = fl; + break; + } + if (!found) { /* then make a new one */ + found = (FvwmDecor *)xmalloc(sizeof(FvwmDecor)); + InitFvwmDecor(found); + found->tag = item; /* tag it */ + /* add it to list */ + for (fl = &Scr.DefaultDecor; fl->next; fl = fl->next) + ; + fl->next = found; + } else + free(item); + if (found) { + AddToDecor(found, s); + last_decor = found; + } } #endif /* USEDECOR */ - /***************************************************************************** * * Updates window decoration styles (veliaa@rpi.edu) * ****************************************************************************/ -void UpdateDecor(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +UpdateDecor(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *fw = Scr.FvwmRoot.next; + FvwmWindow *fw = Scr.FvwmRoot.next; #ifdef USEDECOR - FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; - char *item = NULL; - action = GetNextToken(action, &item); - if (item) { - /* search for tag */ - for (; fl; fl = fl->next) - if (fl->tag) - if (strcasecmp(item, fl->tag)==0) { - found = fl; - break; - } - free(item); - } + FvwmDecor *fl = &Scr.DefaultDecor, *found = NULL; + char *item = NULL; + action = GetNextToken(action, &item); + if (item) { + /* search for tag */ + for (; fl; fl = fl->next) + if (fl->tag) + if (strcasecmp(item, fl->tag) == 0) { + found = fl; + break; + } + free(item); + } #endif - for (; fw != NULL; fw = fw->next) - { + for (; fw != NULL; fw = fw->next) { #ifdef USEDECOR - /* update specific decor, or all */ - if (found) { - if (fw->fl == found) { - SetBorder(fw,True,True,True,None); - SetBorder(fw,False,True,True,None); - } - } - else + /* update specific decor, or all */ + if (found) { + if (fw->fl == found) { + SetBorder(fw, True, True, True, None); + SetBorder(fw, False, True, True, None); + } + } else #endif - { - SetBorder(fw,True,True,True,None); - SetBorder(fw,False,True,True,None); + { + SetBorder(fw, True, True, True, None); + SetBorder(fw, False, True, True, None); + } } - } - SetBorder(Scr.Hilite,True,True,True,None); + SetBorder(Scr.Hilite, True, True, True, None); } - /***************************************************************************** * * Changes a button decoration style (changes by veliaa@rpi.edu) * ****************************************************************************/ -#define SetButtonFlag(a) \ - do { \ - int i; \ - if (multi) { \ - if (multi&1) \ - for (i=0;i<5;++i) { \ - if (set) \ - fl->left_buttons[i].flags |= (a); \ - else \ - fl->left_buttons[i].flags &= ~(a); \ - } \ - if (multi&2) \ - for (i=0;i<5;++i) { \ - if (set) \ - fl->right_buttons[i].flags |= (a); \ - else \ - fl->right_buttons[i].flags &= ~(a); \ - } \ - } else \ - if (set) \ - tb->flags |= (a); \ - else \ - tb->flags &= ~(a); } while (0) - -void ButtonStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +#define SetButtonFlag(a) \ + do { \ + int i; \ + if (multi) { \ + if (multi & 1) \ + for (i = 0; i < 5; ++i) { \ + if (set) \ + fl->left_buttons[i].flags |=\ + (a); \ + else \ + fl->left_buttons[i].flags &=\ + ~(a); \ + } \ + if (multi & 2) \ + for (i = 0; i < 5; ++i) { \ + if (set) \ + fl->right_buttons[i].flags |=\ + (a); \ + else \ + fl->right_buttons[i].flags &=\ + ~(a); \ + } \ + } else if (set) \ + tb->flags |= (a); \ + else \ + tb->flags &= ~(a); \ + } while (0) + +void +ButtonStyle(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int button = 0,n; - int multi = 0; - char *text = action, *prev; - char *parm = NULL; - TitleButton *tb = NULL; + int button = 0, n; + int multi = 0; + char *text = action, *prev; + char *parm = NULL; + TitleButton *tb = NULL; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - text = GetNextToken(text, &parm); - if (parm && isdigit(*parm)) - button = atoi(parm); + text = GetNextToken(text, &parm); + if (parm && isdigit(*parm)) + button = atoi(parm); - if ((parm == NULL) || (button > 10) || (button < 0)) { - fvwm_msg(ERR,"ButtonStyle","Bad button style (1) in line %s",action); - if (parm) - free(parm); - return; - } - - if (!isdigit(*parm)) { - if (StrEquals(parm,"left")) - multi = 1; /* affect all left buttons */ - else if (StrEquals(parm,"right")) - multi = 2; /* affect all right buttons */ - else if (StrEquals(parm,"all")) - multi = 3; /* affect all buttons */ - else { - /* we're either resetting buttons or - an invalid button set was specified */ - if (StrEquals(parm,"reset")) - ResetAllButtons(fl); - else - fvwm_msg(ERR,"ButtonStyle","Bad button style (2) in line %s", - action); - free(parm); - return; - } - } - free(parm); - if (multi == 0) { - /* a single button was specified */ - if (button==10) button=0; - /* which arrays to use? */ - n=button/2; - if((n*2) == button) - { - /* right */ - n = n - 1; - if(n<0)n=4; - tb = &fl->right_buttons[n]; + if ((parm == NULL) || (button > 10) || (button < 0)) { + fvwm_msg(ERR, "ButtonStyle", "Bad button style (1) in line %s", + action); + if (parm) + free(parm); + return; } - else { - /* left */ - tb = &fl->left_buttons[n]; - } - } - - prev = text; - text = GetNextToken(text,&parm); - while(parm) - { - if (strcmp(parm,"-")==0) { - char *tok; - text = GetNextToken(text, &tok); - while (tok) - { - int set = 1; - - if (*tok == '!') { /* flag negate */ - set = 0; - ++tok; + + if (!isdigit(*parm)) { + if (StrEquals(parm, "left")) + multi = 1; /* affect all left buttons */ + else if (StrEquals(parm, "right")) + multi = 2; /* affect all right buttons */ + else if (StrEquals(parm, "all")) + multi = 3; /* affect all buttons */ + else { + /* we're either resetting buttons or + an invalid button set was specified */ + if (StrEquals(parm, "reset")) + ResetAllButtons(fl); + else + fvwm_msg(ERR, "ButtonStyle", + "Bad button style (2) in line %s", action); + free(parm); + return; } - if (StrEquals(tok,"Clear")) { - int i; - if (multi) { - if (multi&1) { - for (i=0;i<5;++i) - if (set) - fl->left_buttons[i].flags = 0; - else - fl->left_buttons[i].flags = ~0; - } - if (multi&2) { - for (i=0;i<5;++i) { + } + free(parm); + if (multi == 0) { + /* a single button was specified */ + if (button == 10) + button = 0; + /* which arrays to use? */ + n = button / 2; + if ((n * 2) == button) { + /* right */ + n = n - 1; + if (n < 0) + n = 4; + tb = &fl->right_buttons[n]; + } else { + /* left */ + tb = &fl->left_buttons[n]; + } + } + + prev = text; + text = GetNextToken(text, &parm); + while (parm) { + if (strcmp(parm, "-") == 0) { + char *tok; + text = GetNextToken(text, &tok); + while (tok) { + int set = 1; + + if (*tok == '!') { /* flag negate */ + set = 0; + ++tok; + } + if (StrEquals(tok, "Clear")) { + int i; + if (multi) { + if (multi & 1) { + for (i = 0; i < 5; ++i) + if (set) + fl + ->left_buttons + [i] + .flags = + 0; + else + fl + ->left_buttons + [i] + .flags = + ~0; + } + if (multi & 2) { + for (i = 0; i < 5; + ++i) { + if (set) + fl + ->right_buttons + [i] + .flags = + 0; + else + fl + ->right_buttons + [i] + .flags = + ~0; + } + } + } else { + if (set) + tb->flags = 0; + else + tb->flags = ~0; + } + } else if (strncasecmp( + tok, "MWMDecorMenu", 12) == 0) { + SetButtonFlag(MWMDecorMenu); + } else if (strncasecmp( + tok, "MWMDecorMin", 11) == 0) { + SetButtonFlag(MWMDecorMinimize); + } else if (strncasecmp( + tok, "MWMDecorMax", 11) == 0) { + SetButtonFlag(MWMDecorMaximize); + } else { + fvwm_msg(ERR, "ButtonStyle", + "unknown title button flag %s -- " + "line: %s", + tok, text); + } if (set) - fl->right_buttons[i].flags = 0; + free(tok); else - fl->right_buttons[i].flags = ~0; - } + free(tok - 1); + text = GetNextToken(text, &tok); } - } else { - if (set) - tb->flags = 0; - else - tb->flags = ~0; - } - } - else if (strncasecmp(tok,"MWMDecorMenu",12)==0) { - SetButtonFlag(MWMDecorMenu); - } else if (strncasecmp(tok,"MWMDecorMin",11)==0) { - SetButtonFlag(MWMDecorMinimize); - } else if (strncasecmp(tok,"MWMDecorMax",11)==0) { - SetButtonFlag(MWMDecorMaximize); + free(parm); + break; } else { - fvwm_msg(ERR, "ButtonStyle", - "unknown title button flag %s -- line: %s", - tok, text); + if (multi) { + int i; + if (multi & 1) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->left_buttons[i], False, + i * 2 + 1); + if (multi & 2) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->right_buttons[i], + False, i * 2); + } else if (!(text = ReadTitleButton( + prev, tb, False, button))) { + free(parm); + break; + } } - if (set) - free(tok); - else - free(tok - 1); - text = GetNextToken(text, &tok); - } - free(parm); - break; - } else { - if (multi) { - int i; - if (multi&1) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->left_buttons[i], - False, i*2+1); - if (multi&2) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->right_buttons[i], - False, i*2); - } - else if (!(text = ReadTitleButton(prev, tb, False, button))) { free(parm); - break; - } + prev = text; + text = GetNextToken(text, &parm); } - free(parm); - prev = text; - text = GetNextToken(text,&parm); - } } #ifdef MULTISTYLE @@ -3997,118 +3930,122 @@ void ButtonStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Appends a button decoration style (veliaa@rpi.edu) * ****************************************************************************/ -void AddButtonStyle(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +AddButtonStyle(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int button = 0,n; - int multi = 0; - char *text = action, *prev; - char *parm = NULL; - TitleButton *tb = NULL; + int button = 0, n; + int multi = 0; + char *text = action, *prev; + char *parm = NULL; + TitleButton *tb = NULL; #ifdef USEDECOR - FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; + FvwmDecor *fl = cur_decor ? cur_decor : &Scr.DefaultDecor; #else - FvwmDecor *fl = &Scr.DefaultDecor; + FvwmDecor *fl = &Scr.DefaultDecor; #endif - text = GetNextToken(text, &parm); - if (parm && isdigit(*parm)) - button = atoi(parm); + text = GetNextToken(text, &parm); + if (parm && isdigit(*parm)) + button = atoi(parm); - if ((parm == NULL) || (button > 10) || (button < 0)) { - fvwm_msg(ERR,"ButtonStyle","Bad button style (1) in line %s",action); - if (parm) - free(parm); - return; - } - - if (!isdigit(*parm)) { - if (StrEquals(parm,"left")) - multi = 1; /* affect all left buttons */ - else if (StrEquals(parm,"right")) - multi = 2; /* affect all right buttons */ - else if (StrEquals(parm,"all")) - multi = 3; /* affect all buttons */ - else { - /* we're either resetting buttons or - an invalid button set was specified */ - if (StrEquals(parm,"reset")) - ResetAllButtons(fl); - else - fvwm_msg(ERR,"ButtonStyle","Bad button style (2) in line %s", - action); - free(parm); - return; - } - } - free(parm); - if (multi == 0) { - /* a single button was specified */ - if (button==10) button=0; - /* which arrays to use? */ - n=button/2; - if((n*2) == button) - { - /* right */ - n = n - 1; - if(n<0)n=4; - tb = &fl->right_buttons[n]; + if ((parm == NULL) || (button > 10) || (button < 0)) { + fvwm_msg(ERR, "ButtonStyle", "Bad button style (1) in line %s", + action); + if (parm) + free(parm); + return; } - else { - /* left */ - tb = &fl->left_buttons[n]; - } - } - - prev = text; - text = GetNextToken(text,&parm); - while(parm) - { - if (multi) { - int i; - if (multi&1) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->left_buttons[i], True, i*2+1); - if (multi&2) - for (i=0;i<5;++i) - text = ReadTitleButton(prev, &fl->right_buttons[i], True, i*2); - } - else if (!(text = ReadTitleButton(prev, tb, True, button))) { - free(parm); - break; + + if (!isdigit(*parm)) { + if (StrEquals(parm, "left")) + multi = 1; /* affect all left buttons */ + else if (StrEquals(parm, "right")) + multi = 2; /* affect all right buttons */ + else if (StrEquals(parm, "all")) + multi = 3; /* affect all buttons */ + else { + /* we're either resetting buttons or + an invalid button set was specified */ + if (StrEquals(parm, "reset")) + ResetAllButtons(fl); + else + fvwm_msg(ERR, "ButtonStyle", + "Bad button style (2) in line %s", action); + free(parm); + return; + } } free(parm); + if (multi == 0) { + /* a single button was specified */ + if (button == 10) + button = 0; + /* which arrays to use? */ + n = button / 2; + if ((n * 2) == button) { + /* right */ + n = n - 1; + if (n < 0) + n = 4; + tb = &fl->right_buttons[n]; + } else { + /* left */ + tb = &fl->left_buttons[n]; + } + } + prev = text; - text = GetNextToken(text,&parm); - } + text = GetNextToken(text, &parm); + while (parm) { + if (multi) { + int i; + if (multi & 1) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->left_buttons[i], True, + i * 2 + 1); + if (multi & 2) + for (i = 0; i < 5; ++i) + text = ReadTitleButton(prev, + &fl->right_buttons[i], True, i * 2); + } else if (!(text = ReadTitleButton(prev, tb, True, button))) { + free(parm); + break; + } + free(parm); + prev = text; + text = GetNextToken(text, &parm); + } } #endif /* MULTISTYLE */ - -void SetEnv(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetEnv(XEvent *eventp, Window junk, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - char *szVar = NULL; - char *szValue = NULL; - char *szPutenv = NULL; - size_t len; - - action = GetNextToken(action,&szVar); - if (!szVar) - return; - action = GetNextToken(action,&szValue); - if (!szValue) - { + char *szVar = NULL; + char *szValue = NULL; + char *szPutenv = NULL; + size_t len; + + action = GetNextToken(action, &szVar); + if (!szVar) + return; + action = GetNextToken(action, &szValue); + if (!szValue) { + free(szVar); + return; + } + + len = strlen(szVar) + strlen(szValue) + 2; + szPutenv = xmalloc(len); + snprintf(szPutenv, len, "%s=%s", szVar, szValue); + if (setenv(szVar, szValue, 1) == -1) + fvwm_msg(WARN, "PutEnvironment", "setenv failed"); + free(szPutenv); free(szVar); - return; - } - - len = strlen(szVar)+strlen(szValue)+2; - szPutenv = safemalloc(len); - snprintf(szPutenv,len,"%s=%s",szVar,szValue); - putenv(szPutenv); - free(szVar); - free(szValue); + free(szValue); } /********************************************************************** @@ -4117,221 +4054,219 @@ void SetEnv(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Note that the returned string is allocated here and it must be * freed when it is not needed anymore. **********************************************************************/ -char *CreateFlagString(char *string, char **restptr) +char * +CreateFlagString(char *string, char **restptr) { - char *retval; - char *c; - char *start; - char closeopt; - int length; - - c = string; - while (isspace(*c) && (*c != 0)) - c++; - - if (*c == '[' || *c == '(') - { - /* Get the text between [ ] or ( ) */ - if (*c == '[') - closeopt = ']'; - else - closeopt = ')'; - c++; - start = c; - length = 0; - while (*c != closeopt) { - if (*c == 0) { - fvwm_msg(ERR, "CreateConditionMask", - "Conditionals require closing parenthesis"); - *restptr = NULL; - return NULL; - } - c++; - length++; - } - - /* We must allocate a new string because we null terminate the string - * between the [ ] or ( ) characters. - */ - retval = safemalloc(length + 1); - strncpy(retval, start, length); - retval[length] = 0; - - *restptr = c + 1; - } - else { - retval = NULL; - *restptr = c; - } - - return retval; + char *retval; + char *c; + char *start; + char closeopt; + int length; + + c = string; + while (isspace(*c) && (*c != 0)) + c++; + + if (*c == '[' || *c == '(') { + /* Get the text between [ ] or ( ) */ + if (*c == '[') + closeopt = ']'; + else + closeopt = ')'; + c++; + start = c; + length = 0; + while (*c != closeopt) { + if (*c == 0) { + fvwm_msg(ERR, "CreateConditionMask", + "Conditionals require closing parenthesis"); + *restptr = NULL; + return NULL; + } + c++; + length++; + } + + /* We must allocate a new string because we null terminate the + * string between the [ ] or ( ) characters. + */ + retval = xmalloc(length + 1); + strncpy(retval, start, length); + retval[length] = 0; + + *restptr = c + 1; + } else { + retval = NULL; + *restptr = c; + } + + return retval; } /********************************************************************** * The name field of the mask is allocated in CreateConditionMask. * It must be freed. **********************************************************************/ -void FreeConditionMask(WindowConditionMask *mask) +void +FreeConditionMask(WindowConditionMask *mask) { - if (mask->needsName) - free(mask->name); - else if (mask->needsNotName) - free(mask->name - 1); + if (mask->needsName) + free(mask->name); + else if (mask->needsNotName) + free(mask->name - 1); } /* Assign the default values for the window mask */ -void DefaultConditionMask(WindowConditionMask *mask) +void +DefaultConditionMask(WindowConditionMask *mask) { - mask->name = NULL; - mask->needsCurrentDesk = 0; - mask->needsCurrentPage = 0; - mask->needsName = 0; - mask->needsNotName = 0; - mask->useCirculateHit = 0; - mask->useCirculateHitIcon = 0; - mask->onFlags = 0; - mask->offFlags = 0; + mask->name = NULL; + mask->needsCurrentDesk = 0; + mask->needsCurrentPage = 0; + mask->needsName = 0; + mask->needsNotName = 0; + mask->useCirculateHit = 0; + mask->useCirculateHitIcon = 0; + mask->onFlags = 0; + mask->offFlags = 0; } /********************************************************************** * Note that this function allocates the name field of the mask struct. * FreeConditionMask must be called for the mask when the mask is discarded. **********************************************************************/ -void CreateConditionMask(char *flags, WindowConditionMask *mask) +void +CreateConditionMask(char *flags, WindowConditionMask *mask) { - char *condition; - char *prev_condition = NULL; - char *tmp; - - if (flags == NULL) - return; - - /* Next parse the flags in the string. */ - tmp = flags; - tmp = GetNextToken(tmp, &condition); - - while (condition) - { - if (StrEquals(condition,"Iconic")) - mask->onFlags |= ICONIFIED; - else if(StrEquals(condition,"!Iconic")) - mask->offFlags |= ICONIFIED; - else if(StrEquals(condition,"Visible")) - mask->onFlags |= VISIBLE; - else if(StrEquals(condition,"!Visible")) - mask->offFlags |= VISIBLE; - else if(StrEquals(condition,"Sticky")) - mask->onFlags |= STICKY; - else if(StrEquals(condition,"!Sticky")) - mask->offFlags |= STICKY; - else if(StrEquals(condition,"Maximized")) - mask->onFlags |= MAXIMIZED; - else if(StrEquals(condition,"!Maximized")) - mask->offFlags |= MAXIMIZED; - else if(StrEquals(condition,"Transient")) - mask->onFlags |= TRANSIENT; - else if(StrEquals(condition,"!Transient")) - mask->offFlags |= TRANSIENT; - else if(StrEquals(condition,"Raised")) - mask->onFlags |= RAISED; - else if(StrEquals(condition,"!Raised")) - mask->offFlags |= RAISED; - else if(StrEquals(condition,"CurrentDesk")) - mask->needsCurrentDesk = 1; - else if(StrEquals(condition,"CurrentPage")) - { - mask->needsCurrentDesk = 1; - mask->needsCurrentPage = 1; - } - else if(StrEquals(condition,"CurrentPageAnyDesk") || - StrEquals(condition,"CurrentScreen")) - mask->needsCurrentPage = 1; - else if(StrEquals(condition,"CirculateHit")) - mask->useCirculateHit = 1; - else if(StrEquals(condition,"CirculateHitIcon")) - mask->useCirculateHitIcon = 1; - else if(!mask->needsName && !mask->needsNotName) - { - /* only 1st name to avoid mem leak */ - mask->name = condition; - condition = NULL; - if (mask->name[0] == '!') - { - mask->needsNotName = 1; - mask->name++; - } - else - mask->needsName = 1; - } - - if (prev_condition) - free(prev_condition); - - prev_condition = condition; - tmp = GetNextToken(tmp, &condition); - } - - if(prev_condition != NULL) - free(prev_condition); + char *condition; + char *prev_condition = NULL; + char *tmp; + + if (flags == NULL) + return; + + /* Next parse the flags in the string. */ + tmp = flags; + tmp = GetNextToken(tmp, &condition); + + while (condition) { + if (StrEquals(condition, "Iconic")) + mask->onFlags |= ICONIFIED; + else if (StrEquals(condition, "!Iconic")) + mask->offFlags |= ICONIFIED; + else if (StrEquals(condition, "Visible")) + mask->onFlags |= VISIBLE; + else if (StrEquals(condition, "!Visible")) + mask->offFlags |= VISIBLE; + else if (StrEquals(condition, "Sticky")) + mask->onFlags |= STICKY; + else if (StrEquals(condition, "!Sticky")) + mask->offFlags |= STICKY; + else if (StrEquals(condition, "Maximized")) + mask->onFlags |= MAXIMIZED; + else if (StrEquals(condition, "!Maximized")) + mask->offFlags |= MAXIMIZED; + else if (StrEquals(condition, "Transient")) + mask->onFlags |= TRANSIENT; + else if (StrEquals(condition, "!Transient")) + mask->offFlags |= TRANSIENT; + else if (StrEquals(condition, "Raised")) + mask->onFlags |= RAISED; + else if (StrEquals(condition, "!Raised")) + mask->offFlags |= RAISED; + else if (StrEquals(condition, "CurrentDesk")) + mask->needsCurrentDesk = 1; + else if (StrEquals(condition, "CurrentPage")) { + mask->needsCurrentDesk = 1; + mask->needsCurrentPage = 1; + } else if (StrEquals(condition, "CurrentPageAnyDesk") || + StrEquals(condition, "CurrentScreen")) + mask->needsCurrentPage = 1; + else if (StrEquals(condition, "CirculateHit")) + mask->useCirculateHit = 1; + else if (StrEquals(condition, "CirculateHitIcon")) + mask->useCirculateHitIcon = 1; + else if (!mask->needsName && !mask->needsNotName) { + /* only 1st name to avoid mem leak */ + mask->name = condition; + condition = NULL; + if (mask->name[0] == '!') { + mask->needsNotName = 1; + mask->name++; + } else + mask->needsName = 1; + } + + if (prev_condition) + free(prev_condition); + + prev_condition = condition; + tmp = GetNextToken(tmp, &condition); + } + + if (prev_condition != NULL) + free(prev_condition); } /********************************************************************** * Checks whether the given window matches the mask created with * CreateConditionMask. **********************************************************************/ -Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask) +Bool +MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask) { - Bool fMatchesName; - Bool fMatchesIconName; - Bool fMatchesClass; - Bool fMatchesResource; - Bool fMatches; - - if ((mask->onFlags & fw->flags) != mask->onFlags) - return 0; - - if ((mask->offFlags & fw->flags) != 0) - return 0; - - if (!mask->useCirculateHit && (fw->flags & CirculateSkip)) - return 0; - - /* This logic looks terribly wrong to me, but it was this way before so I - * did not change it (domivogt (24-Dec-1998)) */ - if (!mask->useCirculateHitIcon && fw->flags & ICONIFIED && - fw->flags & CirculateSkipIcon) - return 0; - - if (fw->flags & ICONIFIED && fw->flags & TRANSIENT && - fw->tmpflags.IconifiedByParent) - return 0; - - if (mask->needsCurrentDesk && fw->Desk != Scr.CurrentDesk) - return 0; - - if (mask->needsCurrentPage && !(fw->frame_x < Scr.MyDisplayWidth && - fw->frame_y < Scr.MyDisplayHeight && - fw->frame_x + fw->frame_width > 0 && - fw->frame_y + fw->frame_height > 0)) - return 0; - - /* Yes, I know this could be shorter, but it's hard to understand then */ - fMatchesName = matchWildcards(mask->name, fw->name); - fMatchesIconName = matchWildcards(mask->name, fw->icon_name); - fMatchesClass = (fw->class.res_class && - matchWildcards(mask->name,fw->class.res_class)); - fMatchesResource = (fw->class.res_name && - matchWildcards(mask->name, fw->class.res_name)); - fMatches = (fMatchesName || fMatchesIconName || fMatchesClass || - fMatchesResource); - - if (mask->needsName && !fMatches) - return 0; - - if (mask->needsNotName && fMatches) - return 0; - - return 1; + Bool fMatchesName; + Bool fMatchesIconName; + Bool fMatchesClass; + Bool fMatchesResource; + Bool fMatches; + + if ((mask->onFlags & fw->flags) != mask->onFlags) + return 0; + + if ((mask->offFlags & fw->flags) != 0) + return 0; + + if (!mask->useCirculateHit && (fw->flags & CirculateSkip)) + return 0; + + /* This logic looks terribly wrong to me, but it was this way before so + * I did not change it (domivogt (24-Dec-1998)) */ + if (!mask->useCirculateHitIcon && fw->flags & ICONIFIED && + fw->flags & CirculateSkipIcon) + return 0; + + if (fw->flags & ICONIFIED && fw->flags & TRANSIENT && + fw->tmpflags.IconifiedByParent) + return 0; + + if (mask->needsCurrentDesk && fw->Desk != Scr.CurrentDesk) + return 0; + + if (mask->needsCurrentPage && !(fw->frame_x < Scr.MyDisplayWidth && + fw->frame_y < Scr.MyDisplayHeight && + fw->frame_x + fw->frame_width > 0 && + fw->frame_y + fw->frame_height > 0)) + return 0; + + /* Yes, I know this could be shorter, but it's hard to understand then + */ + fMatchesName = matchWildcards(mask->name, fw->name); + fMatchesIconName = matchWildcards(mask->name, fw->icon_name); + fMatchesClass = (fw->class.res_class && + matchWildcards(mask->name, fw->class.res_class)); + fMatchesResource = (fw->class.res_name && + matchWildcards(mask->name, fw->class.res_name)); + fMatches = (fMatchesName || fMatchesIconName || fMatchesClass || + fMatchesResource); + + if (mask->needsName && !fMatches) + return 0; + + if (mask->needsNotName && fMatches) + return 0; + + return 1; } /************************************************************************** @@ -4341,318 +4276,305 @@ Bool MatchesConditionMask(FvwmWindow *fw, WindowConditionMask *mask) * Direction = 0 ==> operation on current window (returns pass or fail) * **************************************************************************/ -FvwmWindow *Circulate(char *action, int Direction, char **restofline) +FvwmWindow * +Circulate(char *action, int Direction, char **restofline) { - int pass = 0; - FvwmWindow *fw, *found = NULL; - WindowConditionMask mask; - char *flags; - - /* Create window mask */ - flags = CreateFlagString(action, restofline); - DefaultConditionMask(&mask); - if (Direction == 0) { /* override for Current [] */ - mask.useCirculateHit = 1; - mask.useCirculateHitIcon = 1; - } - CreateConditionMask(flags, &mask); - if (flags) - free(flags); - - if(Scr.Focus != NULL) - { - if(Direction == 1) - fw = Scr.Focus->prev; - else if(Direction == -1) - fw = Scr.Focus->next; - else - fw = Scr.Focus; - } - else - fw = NULL; - - while((pass < 3)&&(found == NULL)) - { - while((fw != NULL)&&(found==NULL)&&(fw != &Scr.FvwmRoot)) - { + int pass = 0; + FvwmWindow *fw, *found = NULL; + WindowConditionMask mask; + char *flags; + + /* Create window mask */ + flags = CreateFlagString(action, restofline); + DefaultConditionMask(&mask); + if (Direction == 0) { /* override for Current [] */ + mask.useCirculateHit = 1; + mask.useCirculateHitIcon = 1; + } + CreateConditionMask(flags, &mask); + if (flags) + free(flags); + + if (Scr.Focus != NULL) { + if (Direction == 1) + fw = Scr.Focus->prev; + else if (Direction == -1) + fw = Scr.Focus->next; + else + fw = Scr.Focus; + } else + fw = NULL; + + while ((pass < 3) && (found == NULL)) { + while ((fw != NULL) && (found == NULL) && + (fw != &Scr.FvwmRoot)) { #ifdef FVWM_DEBUG_MSGS - fvwm_msg(DBG,"Circulate","Trying %s",fw->name); + fvwm_msg(DBG, "Circulate", "Trying %s", fw->name); #endif /* FVWM_DEBUG_MSGS */ - /* Make CirculateUp and CirculateDown take args. by Y.NOMURA */ - if (MatchesConditionMask(fw, &mask)) - found = fw; - else - { - if(Direction == 1) - fw = fw->prev; - else - fw = fw->next; - } - if (Direction == 0) - { + /* Make CirculateUp and CirculateDown take args. by + * Y.NOMURA */ + if (MatchesConditionMask(fw, &mask)) + found = fw; + else { + if (Direction == 1) + fw = fw->prev; + else + fw = fw->next; + } + if (Direction == 0) { + FreeConditionMask(&mask); + return found; + } + } + if ((fw == NULL) || (fw == &Scr.FvwmRoot)) { + if (Direction == 1) { + /* Go to end of list */ + fw = &Scr.FvwmRoot; + while ((fw) && (fw->next != NULL)) { + fw = fw->next; + } + } else { + /* GO to top of list */ + fw = Scr.FvwmRoot.next; + } + } + pass++; + } FreeConditionMask(&mask); - return found; - } - } - if((fw == NULL)||(fw == &Scr.FvwmRoot)) - { - if(Direction == 1) - { - /* Go to end of list */ - fw = &Scr.FvwmRoot; - while((fw) && (fw->next != NULL)) - { - fw = fw->next; - } - } - else - { - /* GO to top of list */ - fw = Scr.FvwmRoot.next; - } - } - pass++; - } - FreeConditionMask(&mask); - return found; + return found; } -void PrevFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +PrevFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, -1, &restofline); - if(found != NULL && restofline != NULL) - { - ExecuteFunction(restofline,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found; + char *restofline; + found = Circulate(action, -1, &restofline); + if (found != NULL && restofline != NULL) { + ExecuteFunction(restofline, found, eventp, C_WINDOW, *Module); + } } -void NextFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +NextFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, 1, &restofline); - if(found != NULL && restofline != NULL) - { - ExecuteFunction(restofline,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found; + char *restofline; + found = Circulate(action, 1, &restofline); + if (found != NULL && restofline != NULL) { + ExecuteFunction(restofline, found, eventp, C_WINDOW, *Module); + } } -void NoneFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +NoneFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, 1, &restofline); - if(found == NULL && restofline != NULL) - { - ExecuteFunction(restofline,NULL,eventp,C_ROOT,*Module); - } + FvwmWindow *found; + char *restofline; + + found = Circulate(action, 1, &restofline); + if (found == NULL && restofline != NULL) { + ExecuteFunction(restofline, NULL, eventp, C_ROOT, *Module); + } } -void CurrentFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +CurrentFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found; - char *restofline; - - found = Circulate(action, 0, &restofline); - if(found != NULL && restofline != NULL) - { - ExecuteFunction(restofline,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found; + char *restofline; + + found = Circulate(action, 0, &restofline); + if (found != NULL && restofline != NULL) { + ExecuteFunction(restofline, found, eventp, C_WINDOW, *Module); + } } -static void GetDirectionReference(FvwmWindow *w, int *x, int *y) +static void +GetDirectionReference(FvwmWindow *w, int *x, int *y) { - if ((w->flags & ICONIFIED) != 0) - { - *x = w->icon_x_loc + w->icon_w_width / 2; - *y = w->icon_y_loc + w->icon_w_height / 2; - } - else - { - *x = w->frame_x + w->frame_width / 2; - *y = w->frame_y + w->frame_height / 2; - } + if ((w->flags & ICONIFIED) != 0) { + *x = w->icon_x_loc + w->icon_w_width / 2; + *y = w->icon_y_loc + w->icon_w_height / 2; + } else { + *x = w->frame_x + w->frame_width / 2; + *y = w->frame_y + w->frame_height / 2; + } } /********************************************************************** * Execute a function to the closest window in the given * direction. **********************************************************************/ -void DirectionFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +DirectionFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *directions[] = { "North", "East", "South", "West", "NorthEast", - "SouthEast", "SouthWest", "NorthWest", NULL }; - int my_x; - int my_y; - int his_x; - int his_y; - int score; - int offset; - int distance; - int best_score; - FvwmWindow *window; - FvwmWindow *best_window; - int dir; - char *flags; - char *restofline; - char *tmp; - WindowConditionMask mask; - - /* Parse the direction. */ - action = GetNextToken(action, &tmp); - dir = GetTokenIndex(tmp, directions, 0, NULL); - if (dir == -1) - { - fvwm_msg(ERR, "Direction","Invalid direction %s", (tmp)? tmp : ""); - if (tmp) - free(tmp); - return; - } - if (tmp) - free(tmp); - - /* Create the mask for flags */ - flags = CreateFlagString(action, &restofline); - if (!restofline) - { - if (flags) - free(flags); - return; - } - DefaultConditionMask(&mask); - CreateConditionMask(flags, &mask); - if (flags) - free(flags); - - /* If there is a focused window, use that as a starting point. - * Otherwise we use the pointer as a starting point. */ - if (tmp_win != NULL) - { - GetDirectionReference(tmp_win, &my_x, &my_y); - } - else - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &my_x, &my_y, &JunkX, &JunkY, &JunkMask); - - /* Next we iterate through all windows and choose the closest one in - * the wanted direction. - */ - best_window = NULL; - best_score = -1; - for (window = Scr.FvwmRoot.next; window != NULL; window = window->next) { - /* Skip every window that does not match conditionals. - * Skip also currently focused window. That would be too close. :) - */ - if (window == tmp_win || !MatchesConditionMask(window, &mask)) - continue; - - /* Calculate relative location of the window. */ - GetDirectionReference(window, &his_x, &his_y); - his_x -= my_x; - his_y -= my_y; - - if (dir > 3) - { - int tx; - /* Rotate the diagonals 45 degrees counterclockwise. To do this, - * multiply the matrix /+h +h\ with the vector (x y). - * \-h +h/ - * h = sqrt(0.5). We can set h := 1 since absolute distance doesn't - * matter here. */ - tx = his_x + his_y; - his_y = -his_x + his_y; - his_x = tx; - } - /* Arrange so that distance and offset are positive in desired direction. - */ - switch (dir) - { - case 0: /* N */ - case 2: /* S */ - case 4: /* NE */ - case 6: /* SW */ - offset = (his_x < 0) ? -his_x : his_x; - distance = (dir == 0 || dir == 4) ? -his_y : his_y; - break; - case 1: /* E */ - case 3: /* W */ - case 5: /* SE */ - case 7: /* NW */ - offset = (his_y < 0) ? -his_y : his_y; - distance = (dir == 3 || dir == 7) ? -his_x : his_x; - break; - } - - /* Target must be in given direction. */ - if (distance <= 0) continue; - - /* Calculate score for this window. The smaller the better. */ - score = 1024 * offset / distance + 2 * distance + 2 * offset; - if (best_score == -1 || score < best_score) { - best_window = window; - best_score = score; - } - } /* for */ - - if (best_window != NULL) - ExecuteFunction(restofline, best_window, eventp, C_WINDOW, *Module); - - FreeConditionMask(&mask); + char *directions[] = {"North", "East", "South", "West", "NorthEast", + "SouthEast", "SouthWest", "NorthWest", NULL}; + int my_x; + int my_y; + int his_x; + int his_y; + int score; + int offset; + int distance; + int best_score; + FvwmWindow *window; + FvwmWindow *best_window; + int dir; + char *flags; + char *restofline; + char *tmp; + WindowConditionMask mask; + + /* Parse the direction. */ + action = GetNextToken(action, &tmp); + dir = GetTokenIndex(tmp, directions, 0, NULL); + if (dir == -1) { + fvwm_msg( + ERR, "Direction", "Invalid direction %s", (tmp) ? tmp : ""); + if (tmp) + free(tmp); + return; + } + if (tmp) + free(tmp); + + /* Create the mask for flags */ + flags = CreateFlagString(action, &restofline); + if (!restofline) { + if (flags) + free(flags); + return; + } + DefaultConditionMask(&mask); + CreateConditionMask(flags, &mask); + if (flags) + free(flags); + + /* If there is a focused window, use that as a starting point. + * Otherwise we use the pointer as a starting point. */ + if (tmp_win != NULL) { + GetDirectionReference(tmp_win, &my_x, &my_y); + } else + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &my_x, + &my_y, &JunkX, &JunkY, &JunkMask); + + /* Next we iterate through all windows and choose the closest one in + * the wanted direction. + */ + best_window = NULL; + best_score = -1; + for (window = Scr.FvwmRoot.next; window != NULL; + window = window->next) { + /* Skip every window that does not match conditionals. + * Skip also currently focused window. That would be too close. + * :) + */ + if (window == tmp_win || !MatchesConditionMask(window, &mask)) + continue; + + /* Calculate relative location of the window. */ + GetDirectionReference(window, &his_x, &his_y); + his_x -= my_x; + his_y -= my_y; + + if (dir > 3) { + int tx; + /* Rotate the diagonals 45 degrees counterclockwise. To + * do this, multiply the matrix /+h +h\ with the vector + * (x y). + * \-h +h/ + * h = sqrt(0.5). We can set h := 1 since absolute + * distance doesn't matter here. */ + tx = his_x + his_y; + his_y = -his_x + his_y; + his_x = tx; + } + /* Arrange so that distance and offset are positive in desired + * direction. + */ + switch (dir) { + case 0: /* N */ + case 2: /* S */ + case 4: /* NE */ + case 6: /* SW */ + offset = (his_x < 0) ? -his_x : his_x; + distance = (dir == 0 || dir == 4) ? -his_y : his_y; + break; + case 1: /* E */ + case 3: /* W */ + case 5: /* SE */ + case 7: /* NW */ + offset = (his_y < 0) ? -his_y : his_y; + distance = (dir == 3 || dir == 7) ? -his_x : his_x; + break; + } + + /* Target must be in given direction. */ + if (distance <= 0) + continue; + + /* Calculate score for this window. The smaller the better. */ + score = 1024 * offset / distance + 2 * distance + 2 * offset; + if (best_score == -1 || score < best_score) { + best_window = window; + best_score = score; + } + } /* for */ + + if (best_window != NULL) + ExecuteFunction( + restofline, best_window, eventp, C_WINDOW, *Module); + + FreeConditionMask(&mask); } -void WindowIdFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +WindowIdFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *found=NULL,*t; - char *num; - unsigned long win; - - action = GetNextToken(action, &num); - - if (num) - { - win = (unsigned long)strtol(num,NULL,0); /* SunOS doesn't have strtoul */ - free(num); - } - else - win = 0; - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if (t->w == win) - { - found = t; - break; - } - } - if(found) - { - ExecuteFunction(action,found,eventp,C_WINDOW,*Module); - } + FvwmWindow *found = NULL, *t; + char *num; + unsigned long win; + + action = GetNextToken(action, &num); + + if (num) { + win = (unsigned long)strtol( + num, NULL, 0); /* SunOS doesn't have strtoul */ + free(num); + } else + win = 0; + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if (t->w == win) { + found = t; + break; + } + } + if (found) { + ExecuteFunction(action, found, eventp, C_WINDOW, *Module); + } } - -void module_zapper(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +module_zapper(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *condition; + char *condition; - GetNextToken(action,&condition); - if (!condition) - return; - KillModuleByName(condition); - free(condition); + GetNextToken(action, &condition); + if (!condition) + return; + KillModuleByName(condition); + free(condition); } /*********************************************************************** @@ -4661,213 +4583,172 @@ void module_zapper(XEvent *eventp,Window junk,FvwmWindow *tmp_win, * Reborder - Removes fvwm border windows * ************************************************************************/ -void Recapture(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +Recapture(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - XEvent event; - - /* Wow, this grabbing speeds up recapture tremendously! I think that is the - * solution for this weird -blackout option. */ - MyXGrabServer(dpy); - GrabEm(WAIT); - BlackoutScreen(); /* if they want to hide the recapture */ - CaptureAllWindows(); - UnBlackoutScreen(); - /* Throw away queued up events. We don't want user input during a - * recapture. The window the user clicks in might disapper at the very same - * moment and the click goes through to the root window. Not goot */ - while (XCheckMaskEvent(dpy, ButtonPressMask|ButtonReleaseMask| - ButtonMotionMask|PointerMotionMask|EnterWindowMask| - LeaveWindowMask, &event) != False) - ; - UngrabEm(); - MyXUngrabServer(dpy); - XSync(dpy, 0); + XEvent event; + + /* Wow, this grabbing speeds up recapture tremendously! I think that is + * the solution for this weird -blackout option. */ + MyXGrabServer(dpy); + GrabEm(WAIT); + BlackoutScreen(); /* if they want to hide the recapture */ + CaptureAllWindows(); + UnBlackoutScreen(); + /* Throw away queued up events. We don't want user input during a + * recapture. The window the user clicks in might disapper at the very + * same moment and the click goes through to the root window. Not goot + */ + while (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | + PointerMotionMask | EnterWindowMask | LeaveWindowMask, + &event) != False) + ; + UngrabEm(); + MyXUngrabServer(dpy); + XSync(dpy, 0); } -void SetGlobalOptions(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetGlobalOptions(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *opt; - - /* fvwm_msg(DBG,"SetGlobalOptions","init action == '%s'\n",action); */ - for (action = GetNextOption(action, &opt); opt; - action = GetNextOption(action, &opt)) - { - /* fvwm_msg(DBG,"SetGlobalOptions"," opt == '%s'\n",opt); */ - /* fvwm_msg(DBG,"SetGlobalOptions"," remaining == '%s'\n", - action?action:"(NULL)"); */ - if (StrEquals(opt,"SMARTPLACEMENTISREALLYSMART")) - { - Scr.SmartPlacementIsClever = True; - } - else if (StrEquals(opt,"SMARTPLACEMENTISNORMAL")) - { - Scr.SmartPlacementIsClever = False; - } - else if (StrEquals(opt,"CLICKTOFOCUSDOESNTPASSCLICK")) - { - Scr.ClickToFocusPassesClick = False; - } - else if (StrEquals(opt,"CLICKTOFOCUSPASSESCLICK")) - { - Scr.ClickToFocusPassesClick = True; - } - else if (StrEquals(opt,"CLICKTOFOCUSDOESNTRAISE")) - { - Scr.ClickToFocusRaises = False; - } - else if (StrEquals(opt,"CLICKTOFOCUSRAISES")) - { - Scr.ClickToFocusRaises = True; - } - else if (StrEquals(opt,"MOUSEFOCUSCLICKDOESNTRAISE")) - { - Scr.MouseFocusClickRaises = False; - } - else if (StrEquals(opt,"MOUSEFOCUSCLICKRAISES")) - { - Scr.MouseFocusClickRaises = True; - } - else if (StrEquals(opt,"NOSTIPLEDTITLES")) - { - Scr.StipledTitles = False; - } - else if (StrEquals(opt,"STIPLEDTITLES")) - { - Scr.StipledTitles = True; - } - /* RBW - 11/14/1998 - I'll eventually remove these. */ -/* - else if (StrEquals(opt,"STARTSONPAGEMODIFIESUSPOSITION")) - { - Scr.go.ModifyUSP = True; - } - else if (StrEquals(opt,"STARTSONPAGEHONORSUSPOSITION")) - { - Scr.go.ModifyUSP = False; - } -*/ - else if (StrEquals(opt,"CAPTUREHONORSSTARTSONPAGE")) - { - Scr.go.CaptureHonorsStartsOnPage = True; - } - else if (StrEquals(opt,"CAPTUREIGNORESSTARTSONPAGE")) - { - Scr.go.CaptureHonorsStartsOnPage = False; - } - else if (StrEquals(opt,"RECAPTUREHONORSSTARTSONPAGE")) - { - Scr.go.RecaptureHonorsStartsOnPage = True; - } - else if (StrEquals(opt,"RECAPTUREIGNORESSTARTSONPAGE")) - { - Scr.go.RecaptureHonorsStartsOnPage = False; - } - else if (StrEquals(opt,"ACTIVEPLACEMENTHONORSSTARTSONPAGE")) - { - Scr.go.ActivePlacementHonorsStartsOnPage = True; - } - else if (StrEquals(opt,"ACTIVEPLACEMENTIGNORESSTARTSONPAGE")) - { - Scr.go.ActivePlacementHonorsStartsOnPage = False; - } - else - fvwm_msg(ERR,"SetGlobalOptions","Unknown Global Option '%s'",opt); - if (opt) /* should never be null, but checking anyways... */ - free(opt); - } - if (opt) - free(opt); + char *opt; + + /* fvwm_msg(DBG,"SetGlobalOptions","init action == '%s'\n",action); */ + for (action = GetNextOption(action, &opt); opt; + action = GetNextOption(action, &opt)) { + /* fvwm_msg(DBG,"SetGlobalOptions"," opt == '%s'\n",opt); */ + /* fvwm_msg(DBG,"SetGlobalOptions"," remaining == '%s'\n", + action?action:"(NULL)"); */ + if (StrEquals(opt, "SMARTPLACEMENTISREALLYSMART")) { + Scr.SmartPlacementIsClever = True; + } else if (StrEquals(opt, "SMARTPLACEMENTISNORMAL")) { + Scr.SmartPlacementIsClever = False; + } else if (StrEquals(opt, "CLICKTOFOCUSDOESNTPASSCLICK")) { + Scr.ClickToFocusPassesClick = False; + } else if (StrEquals(opt, "CLICKTOFOCUSPASSESCLICK")) { + Scr.ClickToFocusPassesClick = True; + } else if (StrEquals(opt, "CLICKTOFOCUSDOESNTRAISE")) { + Scr.ClickToFocusRaises = False; + } else if (StrEquals(opt, "CLICKTOFOCUSRAISES")) { + Scr.ClickToFocusRaises = True; + } else if (StrEquals(opt, "MOUSEFOCUSCLICKDOESNTRAISE")) { + Scr.MouseFocusClickRaises = False; + } else if (StrEquals(opt, "MOUSEFOCUSCLICKRAISES")) { + Scr.MouseFocusClickRaises = True; + } else if (StrEquals(opt, "NOSTIPLEDTITLES")) { + Scr.StipledTitles = False; + } else if (StrEquals(opt, "STIPLEDTITLES")) { + Scr.StipledTitles = True; + } else if (StrEquals(opt, "CAPTUREHONORSSTARTSONPAGE")) { + Scr.go.CaptureHonorsStartsOnPage = True; + } else if (StrEquals(opt, "CAPTUREIGNORESSTARTSONPAGE")) { + Scr.go.CaptureHonorsStartsOnPage = False; + } else if (StrEquals(opt, "RECAPTUREHONORSSTARTSONPAGE")) { + Scr.go.RecaptureHonorsStartsOnPage = True; + } else if (StrEquals(opt, "RECAPTUREIGNORESSTARTSONPAGE")) { + Scr.go.RecaptureHonorsStartsOnPage = False; + } else if (StrEquals( + opt, "ACTIVEPLACEMENTHONORSSTARTSONPAGE")) { + Scr.go.ActivePlacementHonorsStartsOnPage = True; + } else if (StrEquals( + opt, "ACTIVEPLACEMENTIGNORESSTARTSONPAGE")) { + Scr.go.ActivePlacementHonorsStartsOnPage = False; + } else + fvwm_msg(ERR, "SetGlobalOptions", + "Unknown Global Option '%s'", opt); + if (opt) /* should never be null, but checking anyways... */ + free(opt); + } + if (opt) + free(opt); } -void Emulate(XEvent *eventp, Window junk, FvwmWindow *tmp_win, - unsigned long context, char *action, int* Module) +void +Emulate(XEvent *eventp, Window junk, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - char *style; - - GetNextToken(action, &style); - if (!style || StrEquals(style, "fvwm")) - { - Scr.gs.EmulateMWM = False; - Scr.gs.EmulateWIN = False; - } - else if (StrEquals(style, "mwm")) - { - Scr.gs.EmulateMWM = True; - Scr.gs.EmulateWIN = False; - } - else if (StrEquals(style, "win")) - { - Scr.gs.EmulateMWM = False; - Scr.gs.EmulateWIN = True; - } - else - { - fvwm_msg(ERR, "Emulate", "Unknown style '%s'", style); - } - free(style); - ApplyDefaultFontAndColors(); - return; + char *style; + + GetNextToken(action, &style); + if (!style || StrEquals(style, "fvwm")) { + Scr.gs.EmulateMWM = False; + Scr.gs.EmulateWIN = False; + } else if (StrEquals(style, "mwm")) { + Scr.gs.EmulateMWM = True; + Scr.gs.EmulateWIN = False; + } else if (StrEquals(style, "win")) { + Scr.gs.EmulateMWM = False; + Scr.gs.EmulateWIN = True; + } else { + fvwm_msg(ERR, "Emulate", "Unknown style '%s'", style); + } + free(style); + ApplyDefaultFontAndColors(); + return; } -void SetColorLimit(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SetColorLimit(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val; + int val; - if (GetIntegerArguments(action, NULL, &val, 1) != 1) - { - fvwm_msg(ERR,"SetColorLimit","ColorLimit requires one argument"); - return; - } + if (GetIntegerArguments(action, NULL, &val, 1) != 1) { + fvwm_msg( + ERR, "SetColorLimit", "ColorLimit requires one argument"); + return; + } - Scr.ColorLimit = (long)val; + Scr.ColorLimit = (long)val; } - extern float rgpctMovementDefault[32]; extern int cpctMovementDefault; extern int cmsDelayDefault; - /* set animation parameters */ -void set_animation(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +set_animation(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *opt; - int delay; - float pct; - int i = 0; - - action = GetNextToken(action, &opt); - if (!opt || sscanf(opt,"%d",&delay) != 1) { - fvwm_msg(ERR,"SetAnimation", - "Improper milli-second delay as first argument"); - if (opt) - free(opt); - return; - } - free(opt); - if (delay > 500) { - fvwm_msg(WARN,"SetAnimation", - "Using longer than .5 seconds as between frame animation delay"); - } - cmsDelayDefault = delay; - action = GetNextToken(action, &opt); - while (opt) { - if (sscanf(opt,"%f",&pct) != 1) { - fvwm_msg(ERR,"SetAnimation", - "Use fractional values ending in 1.0 as args 2 and on"); - free(opt); - return; - } - rgpctMovementDefault[i++] = pct; - free(opt); - action = GetNextToken(action, &opt); - } - /* No pct entries means don't change them at all */ - if (i>0 && rgpctMovementDefault[i-1] != 1.0) { - rgpctMovementDefault[i++] = 1.0; - } + char *opt; + int delay; + float pct; + int i = 0; + + action = GetNextToken(action, &opt); + if (!opt || sscanf(opt, "%d", &delay) != 1) { + fvwm_msg(ERR, "SetAnimation", + "Improper milli-second delay as first argument"); + if (opt) + free(opt); + return; + } + free(opt); + if (delay > 500) { + fvwm_msg(WARN, "SetAnimation", + "Using longer than .5 seconds as between frame animation " + "delay"); + } + cmsDelayDefault = delay; + action = GetNextToken(action, &opt); + while (opt) { + if (sscanf(opt, "%f", &pct) != 1) { + fvwm_msg(ERR, "SetAnimation", + "Use fractional values ending in 1.0 as args 2 and " + "on"); + free(opt); + return; + } + rgpctMovementDefault[i++] = pct; + free(opt); + action = GetNextToken(action, &opt); + } + /* No pct entries means don't change them at all */ + if (i > 0 && rgpctMovementDefault[i - 1] != 1.0) { + rgpctMovementDefault[i++] = 1.0; + } } Index: fvwm/fvwm/colormaps.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/colormaps.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/colormaps.c --- fvwm/fvwm/colormaps.c +++ fvwm/fvwm/colormaps.c @@ -9,16 +9,16 @@ * warrantees of any sort whatsoever are given or implied or anything. ****************************************************************************/ -#include "config.h" - +#include #include #include + +#include "config.h" #include "fvwm.h" -#include #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" FvwmWindow *colormap_win; Colormap last_cmap = None; @@ -34,66 +34,56 @@ extern FvwmWindow *Tmp_win; * manager should do that, so we must set it correctly). * ***********************************************************************/ -void HandleColormapNotify(void) +void +HandleColormapNotify(void) { - XColormapEvent *cevent = (XColormapEvent *)&Event; - Bool ReInstall = False; - - - if(!Tmp_win) - { - return; - } - if(cevent->new) - { - XGetWindowAttributes(dpy,Tmp_win->w,&(Tmp_win->attr)); - if((Tmp_win == colormap_win)&&(Tmp_win->number_cmap_windows == 0)) - last_cmap = Tmp_win->attr.colormap; - ReInstall = True; - } - else if((cevent->state == ColormapUninstalled)&& - (last_cmap == cevent->colormap)) - { - /* Some window installed its colormap, change it back */ - ReInstall = True; - } + XColormapEvent *cevent = (XColormapEvent *)&Event; + Bool ReInstall = False; - while(XCheckTypedEvent(dpy,ColormapNotify,&Event)) - { - if (XFindContext (dpy, cevent->window, - FvwmContext, (caddr_t *) &Tmp_win) == XCNOENT) - Tmp_win = NULL; - if((Tmp_win)&&(cevent->new)) - { - XGetWindowAttributes(dpy,Tmp_win->w,&(Tmp_win->attr)); - if((Tmp_win == colormap_win)&&(Tmp_win->number_cmap_windows == 0)) - last_cmap = Tmp_win->attr.colormap; - ReInstall = True; + if (!Tmp_win) { + return; } - else if((Tmp_win)&& - (cevent->state == ColormapUninstalled)&& - (last_cmap == cevent->colormap)) - { - /* Some window installed its colormap, change it back */ - ReInstall = True; + if (cevent->new) { + XGetWindowAttributes(dpy, Tmp_win->w, &(Tmp_win->attr)); + if ((Tmp_win == colormap_win) && + (Tmp_win->number_cmap_windows == 0)) + last_cmap = Tmp_win->attr.colormap; + ReInstall = True; + } else if ((cevent->state == ColormapUninstalled) && + (last_cmap == cevent->colormap)) { + /* Some window installed its colormap, change it back */ + ReInstall = True; } - else if((Tmp_win)&& - (cevent->state == ColormapInstalled)&& - (last_cmap == cevent->colormap)) - { - /* The last color map installed was the correct one. Don't - * change anything */ - ReInstall = False; + + while (XCheckTypedEvent(dpy, ColormapNotify, &Event)) { + if (XFindContext(dpy, cevent->window, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; + if ((Tmp_win) && (cevent->new)) { + XGetWindowAttributes(dpy, Tmp_win->w, &(Tmp_win->attr)); + if ((Tmp_win == colormap_win) && + (Tmp_win->number_cmap_windows == 0)) + last_cmap = Tmp_win->attr.colormap; + ReInstall = True; + } else if ((Tmp_win) && + (cevent->state == ColormapUninstalled) && + (last_cmap == cevent->colormap)) { + /* Some window installed its colormap, change it back */ + ReInstall = True; + } else if ((Tmp_win) && (cevent->state == ColormapInstalled) && + (last_cmap == cevent->colormap)) { + /* The last color map installed was the correct one. + * Don't change anything */ + ReInstall = False; + } } - } - /* Reinstall the colormap that we think should be installed, - * UNLESS and unrecognized window has the focus - it might be - * an override-redirect window that has its own colormap. */ - if((ReInstall)&&(Scr.UnknownWinFocused == None)) - { - XInstallColormap(dpy,last_cmap); - } + /* Reinstall the colormap that we think should be installed, + * UNLESS and unrecognized window has the focus - it might be + * an override-redirect window that has its own colormap. */ + if ((ReInstall) && (Scr.UnknownWinFocused == None)) { + XInstallColormap(dpy, last_cmap); + } } /************************************************************************ @@ -101,9 +91,10 @@ void HandleColormapNotify(void) * Re-Install the active colormap * *************************************************************************/ -void ReInstallActiveColormap(void) +void +ReInstallActiveColormap(void) { - InstallWindowColormaps(colormap_win); + InstallWindowColormaps(colormap_win); } /*********************************************************************** @@ -118,72 +109,57 @@ void ReInstallActiveColormap(void) * ************************************************************************/ -void InstallWindowColormaps (FvwmWindow *tmp) +void +InstallWindowColormaps(FvwmWindow *tmp) { - int i; - XWindowAttributes attributes; - Window w; - Bool ThisWinInstalled = False; - - - /* If no window, then install root colormap */ - if(!tmp) - tmp = &Scr.FvwmRoot; - - colormap_win = tmp; - /* Save the colormap to be loaded for when force loading of - * root colormap(s) ends. - */ - Scr.pushed_window = tmp; - /* Don't load any new colormap if root colormap(s) has been - * force loaded. - */ - if (Scr.root_pushes) - { - return; - } - - if(tmp->number_cmap_windows > 0) - { - for(i=tmp->number_cmap_windows -1; i>=0;i--) - { - w = tmp->cmap_windows[i]; - if(w == tmp->w) - ThisWinInstalled = True; - XGetWindowAttributes(dpy,w,&attributes); + int i; + XWindowAttributes attributes; + Window w; + Bool ThisWinInstalled = False; + + /* If no window, then install root colormap */ + if (!tmp) + tmp = &Scr.FvwmRoot; + + colormap_win = tmp; + /* Save the colormap to be loaded for when force loading of + * root colormap(s) ends. + */ + Scr.pushed_window = tmp; + /* Don't load any new colormap if root colormap(s) has been + * force loaded. + */ + if (Scr.root_pushes) { + return; + } - /* - * On Sun X servers, don't install 24 bit TrueColor colourmaps. - * Despite what the server says, these colourmaps are always - * installed. - */ - if(last_cmap != attributes.colormap -#if defined(sun) && defined(TRUECOLOR_ALWAYS_INSTALLED) - && !(attributes.depth == 24 && attributes.visual->class == TrueColor) -#endif - ) - { - last_cmap = attributes.colormap; - XInstallColormap(dpy,attributes.colormap); - } + if (tmp->number_cmap_windows > 0) { + for (i = tmp->number_cmap_windows - 1; i >= 0; i--) { + w = tmp->cmap_windows[i]; + if (w == tmp->w) + ThisWinInstalled = True; + XGetWindowAttributes(dpy, w, &attributes); + + /* + * On Sun X servers, don't install 24 bit TrueColor + * colourmaps. Despite what the server says, these + * colourmaps are always installed. + */ + if (last_cmap != attributes.colormap) { + last_cmap = attributes.colormap; + XInstallColormap(dpy, attributes.colormap); + } + } } - } - if(!ThisWinInstalled) - { - if(last_cmap != tmp->attr.colormap -#if defined(sun) && defined(TRUECOLOR_ALWAYS_INSTALLED) - && !(tmp->attr.depth == 24 && tmp->attr.visual->class == TrueColor) -#endif - ) - { - last_cmap = tmp->attr.colormap; - XInstallColormap(dpy,tmp->attr.colormap); + if (!ThisWinInstalled) { + if (last_cmap != tmp->attr.colormap) { + last_cmap = tmp->attr.colormap; + XInstallColormap(dpy, tmp->attr.colormap); + } } - } } - /*********************************************************************** * * Procedures: @@ -201,17 +177,17 @@ void InstallWindowColormaps (FvwmWindow *tmp) * Enter or Leave Notify events are queued, indicating some * other colormap list would potentially be loaded anyway. ***********************************************************************/ -void InstallRootColormap() +void +InstallRootColormap() { - FvwmWindow *tmp; - if (Scr.root_pushes == 0) - { - tmp = Scr.pushed_window; - InstallWindowColormaps(&Scr.FvwmRoot); - Scr.pushed_window = tmp; - } - Scr.root_pushes++; - return; + FvwmWindow *tmp; + if (Scr.root_pushes == 0) { + tmp = Scr.pushed_window; + InstallWindowColormaps(&Scr.FvwmRoot); + Scr.pushed_window = tmp; + } + Scr.root_pushes++; + return; } /*************************************************************************** @@ -220,21 +196,19 @@ void InstallRootColormap() * If we peel off the last layer, re-install th e application colormap * ***************************************************************************/ -void UninstallRootColormap() +void +UninstallRootColormap() { - if (Scr.root_pushes) - Scr.root_pushes--; + if (Scr.root_pushes) + Scr.root_pushes--; - if (!Scr.root_pushes) - { - InstallWindowColormaps(Scr.pushed_window); - } + if (!Scr.root_pushes) { + InstallWindowColormaps(Scr.pushed_window); + } - return; + return; } - - /***************************************************************************** * * Gets the WM_COLORMAP_WINDOWS property from the window @@ -242,17 +216,15 @@ void UninstallRootColormap() * use it. These seem to occur mostly on SGI machines. * ****************************************************************************/ -void FetchWmColormapWindows (FvwmWindow *tmp) +void +FetchWmColormapWindows(FvwmWindow *tmp) { - if(tmp->cmap_windows != (Window *)NULL) - XFree((void *)tmp->cmap_windows); + if (tmp->cmap_windows != (Window *)NULL) + XFree((void *)tmp->cmap_windows); - if(!XGetWMColormapWindows (dpy, tmp->w, &(tmp->cmap_windows), - &(tmp->number_cmap_windows))) - { - tmp->number_cmap_windows = 0; - tmp->cmap_windows = NULL; - } + if (!XGetWMColormapWindows(dpy, tmp->w, &(tmp->cmap_windows), + &(tmp->number_cmap_windows))) { + tmp->number_cmap_windows = 0; + tmp->cmap_windows = NULL; + } } - - Index: fvwm/fvwm/colors.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/colors.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/colors.c --- fvwm/fvwm/colors.c +++ fvwm/fvwm/colors.c @@ -10,22 +10,18 @@ * ************************************************************************* */ - -#include "config.h" - -#include -#include -#include +#include +#include #include -#include #include -#include #include +#include +#include +#include +#include +#include -#include -#include - - +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" @@ -39,47 +35,45 @@ * want to do this once, hence the first_time flag. * ***********************************************************************/ -void CreateGCs(void) +void +CreateGCs(void) { - XGCValues gcv; - unsigned long gcm; + XGCValues gcv; + unsigned long gcm; - /* create scratch GC's */ - gcm = GCFunction|GCPlaneMask|GCGraphicsExposures|GCLineWidth; - gcv.line_width = 0; - gcv.function = GXcopy; - gcv.plane_mask = AllPlanes; - gcv.graphics_exposures = False; + /* create scratch GC's */ + gcm = GCFunction | GCPlaneMask | GCGraphicsExposures | GCLineWidth; + gcv.line_width = 0; + gcv.function = GXcopy; + gcv.plane_mask = AllPlanes; + gcv.graphics_exposures = False; - Scr.ScratchGC1 = XCreateGC(dpy, Scr.Root, gcm, &gcv); - Scr.ScratchGC2 = XCreateGC(dpy, Scr.Root, gcm, &gcv); - Scr.ScratchGC3 = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.ScratchGC1 = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.ScratchGC2 = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.ScratchGC3 = XCreateGC(dpy, Scr.Root, gcm, &gcv); #if defined(PIXMAP_BUTTONS) || defined(GRADIENT_BUTTONS) - Scr.TransMaskGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); + Scr.TransMaskGC = XCreateGC(dpy, Scr.Root, gcm, &gcv); #endif } - /**************************************************************************** * * Loads a single color * ****************************************************************************/ -Pixel GetColor(char *name) +Pixel +GetColor(char *name) { - XColor color; + XColor color; - color.pixel = 0; - if (!XParseColor (dpy, Scr.FvwmRoot.attr.colormap, name, &color)) - { - nocolor("parse",name); - } - else if(!XAllocColor (dpy, Scr.FvwmRoot.attr.colormap, &color)) - { - nocolor("alloc",name); - } - return color.pixel; + color.pixel = 0; + if (!XParseColor(dpy, Scr.FvwmRoot.attr.colormap, name, &color)) { + nocolor("parse", name); + } else if (!XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &color)) { + nocolor("alloc", name); + } + return color.pixel; } /**************************************************************************** @@ -87,16 +81,18 @@ Pixel GetColor(char *name) * Free an array of colours (n colours), never free black * ****************************************************************************/ -void FreeColors(Pixel *pixels, int n) +void +FreeColors(Pixel *pixels, int n) { - int i; - - /* We don't ever free "black" - dirty hack to allow freeing colours at all */ - for (i = 0; i < n; i++) - { - if (pixels[i] != 0) - XFreeColors(dpy, Scr.FvwmRoot.attr.colormap, pixels + i, 1, 0); - } + int i; + + /* We don't ever free "black" - dirty hack to allow freeing colours at + * all */ + for (i = 0; i < n; i++) { + if (pixels[i] != 0) + XFreeColors( + dpy, Scr.FvwmRoot.attr.colormap, pixels + i, 1, 0); + } } #ifdef GRADIENT_BUTTONS @@ -105,39 +101,39 @@ void FreeColors(Pixel *pixels, int n) * Allocates a nonlinear color gradient (veliaa@rpi.edu) * ****************************************************************************/ -Pixel *AllocNonlinearGradient(char *s_colors[], int clen[], - int nsegs, int npixels) +Pixel * +AllocNonlinearGradient(char *s_colors[], int clen[], int nsegs, int npixels) { - Pixel *pixels = (Pixel *)safemalloc(sizeof(Pixel) * npixels); - int i = 0, curpixel = 0, perc = 0; - if (nsegs < 1) { - fvwm_msg(ERR,"AllocNonlinearGradient", - "must specify at least one segment"); - free(pixels); - return NULL; - } - for (; i < npixels; i++) - pixels[i] = 0; - - for (i = 0; (i < nsegs) && (curpixel < npixels) && (perc <= 100); ++i) { - Pixel *p; - int j = 0, n = clen[i] * npixels / 100; - p = AllocLinearGradient(s_colors[i], s_colors[i + 1], n); - if (!p) { - fvwm_msg(ERR, "AllocNonlinearGradient", - "couldn't allocate gradient"); - free(pixels); - return NULL; + Pixel *pixels = (Pixel *)xmalloc(sizeof(Pixel) * npixels); + int i = 0, curpixel = 0, perc = 0; + if (nsegs < 1) { + fvwm_msg(ERR, "AllocNonlinearGradient", + "must specify at least one segment"); + free(pixels); + return NULL; + } + for (; i < npixels; i++) + pixels[i] = 0; + + for (i = 0; (i < nsegs) && (curpixel < npixels) && (perc <= 100); ++i) { + Pixel *p; + int j = 0, n = clen[i] * npixels / 100; + p = AllocLinearGradient(s_colors[i], s_colors[i + 1], n); + if (!p) { + fvwm_msg(ERR, "AllocNonlinearGradient", + "couldn't allocate gradient"); + free(pixels); + return NULL; + } + for (; j < n; ++j) + pixels[curpixel + j] = p[j]; + perc += clen[i]; + curpixel += n; + free(p); } - for (; j < n; ++j) - pixels[curpixel + j] = p[j]; - perc += clen[i]; - curpixel += n; - free(p); - } - for (i = curpixel; i < npixels; ++i) - pixels[i] = pixels[i - 1]; - return pixels; + for (i = curpixel; i < npixels; ++i) + pixels[i] = pixels[i - 1]; + return pixels; } /**************************************************************************** @@ -145,52 +141,57 @@ Pixel *AllocNonlinearGradient(char *s_colors[], int clen[], * Allocates a linear color gradient (veliaa@rpi.edu) * ****************************************************************************/ -Pixel *AllocLinearGradient(char *s_from, char *s_to, int npixels) +Pixel * +AllocLinearGradient(char *s_from, char *s_to, int npixels) { - Pixel *pixels; - XColor from, to, c; - int r, dr, g, dg, b, db; - int i = 0, got_all = 1; - - if (npixels < 1) { - fvwm_msg(ERR, "AllocLinearGradient", "Invalid number of pixels: %d", - npixels); - return NULL; - } - if (!s_from || !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_from, - &from)) { - nocolor("parse", s_from); - return NULL; - } - if (!s_to || !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_to, &to)) { - nocolor("parse", s_to); - return NULL; - } - c = from; - r = from.red; dr = (to.red - from.red) / npixels; - g = from.green; dg = (to.green - from.green) / npixels; - b = from.blue; db = (to.blue - from.blue) / npixels; - pixels = (Pixel *)safemalloc(sizeof(Pixel) * npixels); - c.flags = DoRed | DoGreen | DoBlue; - for (; i < npixels; ++i) - { - if (!XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &c)) - got_all = 0; - pixels[ i ] = c.pixel; - c.red = (unsigned short) (r += dr); - c.green = (unsigned short) (g += dg); - c.blue = (unsigned short) (b += db); - } - if (!got_all) { - char s[256]; - snprintf(s, 256, "color gradient %s to %s", s_from, s_to); - nocolor("alloc", s); - } - return pixels; + Pixel *pixels; + XColor from, to, c; + int r, dr, g, dg, b, db; + int i = 0, got_all = 1; + + if (npixels < 1) { + fvwm_msg(ERR, "AllocLinearGradient", + "Invalid number of pixels: %d", npixels); + return NULL; + } + if (!s_from || + !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_from, &from)) { + nocolor("parse", s_from); + return NULL; + } + if (!s_to || !XParseColor(dpy, Scr.FvwmRoot.attr.colormap, s_to, &to)) { + nocolor("parse", s_to); + return NULL; + } + c = from; + r = from.red; + dr = (to.red - from.red) / npixels; + g = from.green; + dg = (to.green - from.green) / npixels; + b = from.blue; + db = (to.blue - from.blue) / npixels; + pixels = (Pixel *)xmalloc(sizeof(Pixel) * npixels); + c.flags = DoRed | DoGreen | DoBlue; + for (; i < npixels; ++i) { + if (!XAllocColor(dpy, Scr.FvwmRoot.attr.colormap, &c)) + got_all = 0; + pixels[i] = c.pixel; + c.red = (unsigned short)(r += dr); + c.green = (unsigned short)(g += dg); + c.blue = (unsigned short)(b += db); + } + if (!got_all) { + char s[256]; + snprintf(s, 256, "color gradient %s to %s", s_from, s_to); + nocolor("alloc", s); + } + return pixels; } #endif /* GRADIENT_BUTTONS */ -void nocolor(char *note, char *name) +void +nocolor(char *note, char *name) { - fvwm_msg(ERR,"nocolor","can't %s color %s", note, name ? name : ""); + fvwm_msg( + ERR, "nocolor", "can't %s color %s", note, name ? name : ""); } Index: fvwm/fvwm/complex.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/complex.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/complex.c --- fvwm/fvwm/complex.c +++ fvwm/fvwm/complex.c @@ -5,20 +5,19 @@ * as long as the copyright notice is preserved ****************************************************************************/ -#include "config.h" - -#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" /***************************************************************************** * @@ -26,36 +25,34 @@ * clicking, but is moving the cursor * ****************************************************************************/ -static Bool IsClick(int x,int y,long EndMask, XEvent *d) +static Bool +IsClick(int x, int y, long EndMask, XEvent *d) { - int xcurrent,ycurrent,total = 0; - Time t0; - extern Time lastTimestamp; + int xcurrent, ycurrent, total = 0; + Time t0; + extern Time lastTimestamp; - xcurrent = x; - ycurrent = y; - t0 = lastTimestamp; + xcurrent = x; + ycurrent = y; + t0 = lastTimestamp; - while((total < Scr.ClickTime)&& - (x - xcurrent < 3)&&(x - xcurrent > -3)&& - (y - ycurrent < 3)&&(y - ycurrent > -3)&& - ((lastTimestamp - t0) < Scr.ClickTime)) - { - usleep(20000); - total+=20; - if(XCheckMaskEvent (dpy,EndMask, d)) - { - StashEventTime(d); - return True; + while ((total < Scr.ClickTime) && (x - xcurrent < 3) && + (x - xcurrent > -3) && (y - ycurrent < 3) && + (y - ycurrent > -3) && ((lastTimestamp - t0) < Scr.ClickTime)) { + usleep(20000); + total += 20; + if (XCheckMaskEvent(dpy, EndMask, d)) { + StashEventTime(d); + return True; + } + if (XCheckMaskEvent( + dpy, ButtonMotionMask | PointerMotionMask, d)) { + xcurrent = d->xmotion.x_root; + ycurrent = d->xmotion.y_root; + StashEventTime(d); + } } - if(XCheckMaskEvent (dpy,ButtonMotionMask|PointerMotionMask, d)) - { - xcurrent = d->xmotion.x_root; - ycurrent = d->xmotion.y_root; - StashEventTime(d); - } - } - return False; + return False; } /***************************************************************************** @@ -63,240 +60,216 @@ static Bool IsClick(int x,int y,long EndMask, XEvent *d) * Builtin which determines if the button press was a click or double click... * ****************************************************************************/ -void ComplexFunction(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +ComplexFunction(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char type = MOTION; - char c; - MenuItem *mi; - Bool Persist = False; - Bool HaveDoubleClick = False; - Bool NeedsTarget = False; - char *arguments[10], *junk, *taction; - int x, y ,i; - XEvent d, *ev; - MenuRoot *mr; - extern Bool desperate; + char type = MOTION; + char c; + MenuItem *mi; + Bool Persist = False; + Bool HaveDoubleClick = False; + Bool NeedsTarget = False; + char *arguments[10], *junk, *taction; + int x, y, i; + XEvent d, *ev; + MenuRoot *mr; + extern Bool desperate; - mr = FindPopup(action); - if(mr == NULL) - { - if(!desperate) - fvwm_msg(ERR,"ComplexFunction","No such function %s",action); - return; - } - desperate = 0; - /* Get the argument list */ - /* First entry in action is the function-name, ignore it */ - action = GetNextToken(action,&junk); - if(junk != NULL) - free(junk); - for(i=0;i<10;i++) - action = GetNextToken(action,&arguments[i]); - /* see functions.c to find out which functions need a window to operate on */ - ev = eventp; - /* In case we want to perform an action on a button press, we - * need to fool other routines */ - if(eventp->type == ButtonPress) - eventp->type = ButtonRelease; - mi = mr->first; - while(mi != NULL) - { - /* make lower case */ - c = *(mi->item); - NeedsTarget = mi->func_needs_window; - if(isupper(c)) - c=tolower(c); - if(c==DOUBLE_CLICK) - { - HaveDoubleClick = True; - Persist = True; + mr = FindPopup(action); + if (mr == NULL) { + if (!desperate) + fvwm_msg(ERR, "ComplexFunction", "No such function %s", + action); + return; } - else if(c == IMMEDIATE) - { - if(tmp_win) - w = tmp_win->frame; - else - w = None; - taction = expand(mi->action,arguments,tmp_win); - ExecuteFunction(taction,tmp_win,eventp,context,-2); - free(taction); + desperate = 0; + /* Get the argument list */ + /* First entry in action is the function-name, ignore it */ + action = GetNextToken(action, &junk); + if (junk != NULL) + free(junk); + for (i = 0; i < 10; i++) + action = GetNextToken(action, &arguments[i]); + /* see functions.c to find out which functions need a window to operate + * on */ + ev = eventp; + /* In case we want to perform an action on a button press, we + * need to fool other routines */ + if (eventp->type == ButtonPress) + eventp->type = ButtonRelease; + mi = mr->first; + while (mi != NULL) { + /* make lower case */ + c = *(mi->item); + NeedsTarget = mi->func_needs_window; + if (isupper(c)) + c = tolower(c); + if (c == DOUBLE_CLICK) { + HaveDoubleClick = True; + Persist = True; + } else if (c == IMMEDIATE) { + if (tmp_win) + w = tmp_win->frame; + else + w = None; + taction = expand(mi->action, arguments, tmp_win); + ExecuteFunction(taction, tmp_win, eventp, context, -2); + free(taction); + } else + Persist = True; + mi = mi->next; } - else - Persist = True; - mi = mi->next; - } - - if(!Persist) - { - for(i=0;i<10;i++) - if(arguments[i] != NULL)free(arguments[i]); - return; - } - /* Only defer execution if there is a possibility of needing - * a window to operate on */ - if(NeedsTarget) - { - if (DeferExecution(eventp,&w,&tmp_win,&context, SELECT,ButtonPress)) - { - WaitForButtonsUp(); - for(i=0;i<10;i++) - if(arguments[i] != NULL)free(arguments[i]); - return; + if (!Persist) { + for (i = 0; i < 10; i++) + if (arguments[i] != NULL) + free(arguments[i]); + return; } - } - if(!GrabEm(SELECT)) - { - XBell(dpy, 0); - for(i=0;i<10;i++) - if(arguments[i] != NULL)free(arguments[i]); - return; - } - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x,&y,&JunkX, &JunkY, &JunkMask); + /* Only defer execution if there is a possibility of needing + * a window to operate on */ + if (NeedsTarget) { + if (DeferExecution( + eventp, &w, &tmp_win, &context, SELECT, ButtonPress)) { + WaitForButtonsUp(); + for (i = 0; i < 10; i++) + if (arguments[i] != NULL) + free(arguments[i]); + return; + } + } + if (!GrabEm(SELECT)) { + XBell(dpy, 0); + for (i = 0; i < 10; i++) + if (arguments[i] != NULL) + free(arguments[i]); + return; + } + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); - /* Wait and see if we have a click, or a move */ - /* wait 100 msec, see if the user releases the button */ - if(IsClick(x,y,ButtonReleaseMask,&d)) - { - ev = &d; - type = CLICK; - } + /* Wait and see if we have a click, or a move */ + /* wait 100 msec, see if the user releases the button */ + if (IsClick(x, y, ButtonReleaseMask, &d)) { + ev = &d; + type = CLICK; + } - /* If it was a click, wait to see if its a double click */ - if((HaveDoubleClick) && (type == CLICK) && - (IsClick(x,y,ButtonPressMask, &d))) - { - type = ONE_AND_A_HALF_CLICKS; - ev = &d; - } - if((HaveDoubleClick) && (type == ONE_AND_A_HALF_CLICKS) && - (IsClick(x,y,ButtonReleaseMask, &d))) - { - type = DOUBLE_CLICK; - ev = &d; - } - /* some functions operate on button release instead of - * presses. These gets really weird for complex functions ... */ - if(ev->type == ButtonPress) - ev->type = ButtonRelease; + /* If it was a click, wait to see if its a double click */ + if ((HaveDoubleClick) && (type == CLICK) && + (IsClick(x, y, ButtonPressMask, &d))) { + type = ONE_AND_A_HALF_CLICKS; + ev = &d; + } + if ((HaveDoubleClick) && (type == ONE_AND_A_HALF_CLICKS) && + (IsClick(x, y, ButtonReleaseMask, &d))) { + type = DOUBLE_CLICK; + ev = &d; + } + /* some functions operate on button release instead of + * presses. These gets really weird for complex functions ... */ + if (ev->type == ButtonPress) + ev->type = ButtonRelease; - mi = mr->first; - while(mi != NULL) - { - /* make lower case */ - c = *(mi->item); - if(isupper(c)) - c=tolower(c); - if(c == type) - { - if(tmp_win) - w = tmp_win->frame; - else - w = None; - taction = expand(mi->action,arguments,tmp_win); - ExecuteFunction(taction,tmp_win,ev,context,-2); - free(taction); + mi = mr->first; + while (mi != NULL) { + /* make lower case */ + c = *(mi->item); + if (isupper(c)) + c = tolower(c); + if (c == type) { + if (tmp_win) + w = tmp_win->frame; + else + w = None; + taction = expand(mi->action, arguments, tmp_win); + ExecuteFunction(taction, tmp_win, ev, context, -2); + free(taction); + } + mi = mi->next; } - mi = mi->next; - } - WaitForButtonsUp(); - UngrabEm(); - for(i=0;i<10;i++) - if(arguments[i] != NULL)free(arguments[i]); + WaitForButtonsUp(); + UngrabEm(); + for (i = 0; i < 10; i++) + if (arguments[i] != NULL) + free(arguments[i]); } - -char *expand(char *input, char *arguments[],FvwmWindow *tmp_win) +char * +expand(char *input, char *arguments[], FvwmWindow *tmp_win) { - int l,i,l2,n,k,j; - char *out; - int addto = 0; /*special cas if doing addtofunc */ - size_t outlen; + int l, i, l2, n, k, j; + char *out; + int addto = 0; /*special cas if doing addtofunc */ + size_t outlen; - l = strlen(input); - l2 = l; + l = strlen(input); + l2 = l; - if(strncasecmp(input, "AddToFunc", 9) == 0 || input[0] == '+') - { - addto = 1; - } - i=0; - while(i= 0)&&(n <= 9)&&(arguments[n] != NULL)) - { - l2 += strlen(arguments[n])-2; - i++; - } - else if(input[i+1]=='w' || input[i+1] == 'd') - { - l2 += 16; - i++; - } + if (strncasecmp(input, "AddToFunc", 9) == 0 || input[0] == '+') { + addto = 1; + } + i = 0; + while (i < l) { + if (input[i] == '$') { + n = input[i + 1] - '0'; + if ((n >= 0) && (n <= 9) && (arguments[n] != NULL)) { + l2 += strlen(arguments[n]) - 2; + i++; + } else if (input[i + 1] == 'w' || input[i + 1] == 'd') { + l2 += 16; + i++; + } + } + i++; } - i++; - } - outlen = l2 + 1; - out = safemalloc(outlen); - i=0; - j=0; - while(i= 0)&&(n <= 9)) - { - if (arguments[n] != NULL) - { - for(k=0;kw); - else - snprintf(&out[j],outlen -j,"$w"); - j += strlen(&out[j]); - i++; - } - else if(input[i+1] == 'd') - { - snprintf(&out[j], outlen - j,"%d", Scr.CurrentDesk); - j += strlen(&out[j]); - i++; - } - else if(input[i+1] == '$') - { - out[j++] = '$'; - i++; - } - else - out[j++] = input[i]; + outlen = l2 + 1; + out = xmalloc(outlen); + i = 0; + j = 0; + while (i < l) { + if (input[i] == '$') { + n = input[i + 1] - '0'; + if ((n >= 0) && (n <= 9)) { + if (arguments[n] != NULL) { + for (k = 0; k < strlen(arguments[n]); + k++) + out[j++] = arguments[n][k]; + i++; + } else if (addto == 1) { + out[j++] = '$'; + } else { + i++; + if (isspace(input[i + 1])) + i++; /*eliminates extra white + space*/ + } + } else if (input[i + 1] == 'w') { + if (tmp_win) + snprintf(&out[j], outlen - j, "0x%x", + (unsigned int)tmp_win->w); + else + snprintf(&out[j], outlen - j, "$w"); + j += strlen(&out[j]); + i++; + } else if (input[i + 1] == 'd') { + snprintf( + &out[j], outlen - j, "%d", Scr.CurrentDesk); + j += strlen(&out[j]); + i++; + } else if (input[i + 1] == '$') { + out[j++] = '$'; + i++; + } else + out[j++] = input[i]; + } else + out[j++] = input[i]; + i++; } - else - out[j++] = input[i]; - i++; - } - out[j] = 0; - return out; + out[j] = 0; + return out; } Index: fvwm/fvwm/decorations.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/decorations.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/decorations.c --- fvwm/fvwm/decorations.c +++ fvwm/fvwm/decorations.c @@ -33,65 +33,65 @@ * ****************************************************************************/ -#include "config.h" - +#include +#include #include -#include #include +#include + +#include "config.h" #include "fvwm.h" -#include -#include +#include "lang-strings.h" +#include "menus.h" #include "misc.h" -#include "screen.h" #include "parse.h" -#include "menus.h" -#include "lang-strings.h" - +#include "screen.h" extern Atom _XA_MwmAtom; /* Motif window hints */ -typedef struct -{ - unsigned long flags; - unsigned long functions; - unsigned long decorations; - long inputMode; +typedef struct { + unsigned long flags; + unsigned long functions; + unsigned long decorations; + long inputMode; } PropMotifWmHints; -typedef PropMotifWmHints PropMwmHints; +typedef PropMotifWmHints PropMwmHints; /* Motif window hints */ -#define MWM_HINTS_FUNCTIONS (1L << 0) -#define MWM_HINTS_DECORATIONS (1L << 1) +#define MWM_HINTS_FUNCTIONS (1L << 0) +#define MWM_HINTS_DECORATIONS (1L << 1) /* bit definitions for MwmHints.functions */ -#define MWM_FUNC_ALL (1L << 0) -#define MWM_FUNC_RESIZE (1L << 1) -#define MWM_FUNC_MOVE (1L << 2) -#define MWM_FUNC_MINIMIZE (1L << 3) -#define MWM_FUNC_MAXIMIZE (1L << 4) -#define MWM_FUNC_CLOSE (1L << 5) +#define MWM_FUNC_ALL (1L << 0) +#define MWM_FUNC_RESIZE (1L << 1) +#define MWM_FUNC_MOVE (1L << 2) +#define MWM_FUNC_MINIMIZE (1L << 3) +#define MWM_FUNC_MAXIMIZE (1L << 4) +#define MWM_FUNC_CLOSE (1L << 5) /* bit definitions for MwmHints.decorations */ -#define MWM_DECOR_ALL (1L << 0) -#define MWM_DECOR_BORDER (1L << 1) -#define MWM_DECOR_RESIZEH (1L << 2) -#define MWM_DECOR_TITLE (1L << 3) -#define MWM_DECOR_MENU (1L << 4) -#define MWM_DECOR_MINIMIZE (1L << 5) -#define MWM_DECOR_MAXIMIZE (1L << 6) +#define MWM_DECOR_ALL (1L << 0) +#define MWM_DECOR_BORDER (1L << 1) +#define MWM_DECOR_RESIZEH (1L << 2) +#define MWM_DECOR_TITLE (1L << 3) +#define MWM_DECOR_MENU (1L << 4) +#define MWM_DECOR_MINIMIZE (1L << 5) +#define MWM_DECOR_MAXIMIZE (1L << 6) -#define PROP_MOTIF_WM_HINTS_ELEMENTS 4 -#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS +#define PROP_MOTIF_WM_HINTS_ELEMENTS 4 +#define PROP_MWM_HINTS_ELEMENTS PROP_MOTIF_WM_HINTS_ELEMENTS /* bit definitions for OL hints; I just * made these up, OL stores hints as atoms */ -#define OL_DECOR_CLOSE (1L << 0) -#define OL_DECOR_RESIZEH (1L << 1) -#define OL_DECOR_HEADER (1L << 2) -#define OL_DECOR_ICON_NAME (1L << 3) -#define OL_DECOR_ALL (OL_DECOR_CLOSE | OL_DECOR_RESIZEH | OL_DECOR_HEADER | OL_DECOR_ICON_NAME) +#define OL_DECOR_CLOSE (1L << 0) +#define OL_DECOR_RESIZEH (1L << 1) +#define OL_DECOR_HEADER (1L << 2) +#define OL_DECOR_ICON_NAME (1L << 3) +#define OL_DECOR_ALL \ + (OL_DECOR_CLOSE | OL_DECOR_RESIZEH | OL_DECOR_HEADER | \ + OL_DECOR_ICON_NAME) extern FvwmWindow *Tmp_win; @@ -100,23 +100,22 @@ extern FvwmWindow *Tmp_win; * Reads the property MOTIF_WM_HINTS * *****************************************************************************/ -void GetMwmHints(FvwmWindow *t) +void +GetMwmHints(FvwmWindow *t) { - int actual_format; - Atom actual_type; - unsigned long nitems, bytesafter; - - if(XGetWindowProperty (dpy, t->w, _XA_MwmAtom, 0L, 20L, False, - _XA_MwmAtom, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&t->mwm_hints)==Success) - { - if(nitems >= PROP_MOTIF_WM_HINTS_ELEMENTS) - { - return; + int actual_format; + Atom actual_type; + unsigned long nitems, bytesafter; + + if (XGetWindowProperty(dpy, t->w, _XA_MwmAtom, 0L, 20L, False, + _XA_MwmAtom, &actual_type, &actual_format, &nitems, &bytesafter, + (unsigned char **)&t->mwm_hints) == Success) { + if (nitems >= PROP_MOTIF_WM_HINTS_ELEMENTS) { + return; + } } - } - t->mwm_hints = NULL; + t->mwm_hints = NULL; } /**************************************************************************** @@ -146,318 +145,318 @@ void GetMwmHints(FvwmWindow *t) * (M&T Books), and the olvwm source code (available at ftp.x.org in * /R5contrib). *****************************************************************************/ -void GetOlHints(FvwmWindow *t) +void +GetOlHints(FvwmWindow *t) { - int actual_format; - Atom actual_type; - unsigned long nitems, bytesafter; - Atom *hints; - int i; - Atom win_type; - - t->ol_hints = OL_DECOR_ALL; - - if (XGetWindowProperty (dpy, t->w, _XA_OL_WIN_ATTR, 0L, 20L, False, - _XA_OL_WIN_ATTR, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&hints)==Success) - { - if (nitems > 0) - { - if (nitems == 3) - win_type = hints[0]; - else - win_type = hints[1]; - - /* got this from olvwm and sort of mapped it to - * FVWM/MWM hints */ - if (win_type == _XA_OL_WT_BASE) - t->ol_hints = OL_DECOR_ALL; - else if (win_type == _XA_OL_WT_CMD) - t->ol_hints = OL_DECOR_ALL & ~OL_DECOR_CLOSE; - else if (win_type == _XA_OL_WT_HELP) - t->ol_hints = OL_DECOR_ALL & ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH); - else if (win_type == _XA_OL_WT_NOTICE) - t->ol_hints = OL_DECOR_ALL & ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH | - OL_DECOR_HEADER | OL_DECOR_ICON_NAME); - else if (win_type == _XA_OL_WT_OTHER) - t->ol_hints = 0; - else - t->ol_hints = OL_DECOR_ALL; - - if (nitems == 3) - t->ol_hints &= ~OL_DECOR_ICON_NAME; + int actual_format; + Atom actual_type; + unsigned long nitems, bytesafter; + Atom *hints; + int i; + Atom win_type; + + t->ol_hints = OL_DECOR_ALL; + + if (XGetWindowProperty(dpy, t->w, _XA_OL_WIN_ATTR, 0L, 20L, False, + _XA_OL_WIN_ATTR, &actual_type, &actual_format, &nitems, + &bytesafter, (unsigned char **)&hints) == Success) { + if (nitems > 0) { + if (nitems == 3) + win_type = hints[0]; + else + win_type = hints[1]; + + /* got this from olvwm and sort of mapped it to + * FVWM/MWM hints */ + if (win_type == _XA_OL_WT_BASE) + t->ol_hints = OL_DECOR_ALL; + else if (win_type == _XA_OL_WT_CMD) + t->ol_hints = OL_DECOR_ALL & ~OL_DECOR_CLOSE; + else if (win_type == _XA_OL_WT_HELP) + t->ol_hints = + OL_DECOR_ALL & + ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH); + else if (win_type == _XA_OL_WT_NOTICE) + t->ol_hints = + OL_DECOR_ALL & + ~(OL_DECOR_CLOSE | OL_DECOR_RESIZEH | + OL_DECOR_HEADER | OL_DECOR_ICON_NAME); + else if (win_type == _XA_OL_WT_OTHER) + t->ol_hints = 0; + else + t->ol_hints = OL_DECOR_ALL; + + if (nitems == 3) + t->ol_hints &= ~OL_DECOR_ICON_NAME; + } + + if (hints) + XFree(hints); } - if (hints) - XFree (hints); - } - - if(XGetWindowProperty (dpy, t->w, _XA_OL_DECOR_ADD, 0L, 20L, False, - XA_ATOM, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&hints)==Success) - { - for (i = 0; i < nitems; i++) { - if (hints[i] == _XA_OL_DECOR_CLOSE) - t->ol_hints |= OL_DECOR_CLOSE; - else if (hints[i] == _XA_OL_DECOR_RESIZE) - t->ol_hints |= OL_DECOR_RESIZEH; - else if (hints[i] == _XA_OL_DECOR_HEADER) - t->ol_hints |= OL_DECOR_HEADER; - else if (hints[i] == _XA_OL_DECOR_ICON_NAME) - t->ol_hints |= OL_DECOR_ICON_NAME; - } - if (hints) - XFree (hints); - } - - if(XGetWindowProperty (dpy, t->w, _XA_OL_DECOR_DEL, 0L, 20L, False, - XA_ATOM, &actual_type, &actual_format, &nitems, - &bytesafter,(unsigned char **)&hints)==Success) - { - for (i = 0; i < nitems; i++) { - if (hints[i] == _XA_OL_DECOR_CLOSE) - t->ol_hints &= ~OL_DECOR_CLOSE; - else if (hints[i] == _XA_OL_DECOR_RESIZE) - t->ol_hints &= ~OL_DECOR_RESIZEH; - else if (hints[i] == _XA_OL_DECOR_HEADER) - t->ol_hints &= ~OL_DECOR_HEADER; - else if (hints[i] == _XA_OL_DECOR_ICON_NAME) - t->ol_hints &= ~OL_DECOR_ICON_NAME; - } - if (hints) - XFree (hints); - } + if (XGetWindowProperty(dpy, t->w, _XA_OL_DECOR_ADD, 0L, 20L, False, + XA_ATOM, &actual_type, &actual_format, &nitems, &bytesafter, + (unsigned char **)&hints) == Success) { + for (i = 0; i < nitems; i++) { + if (hints[i] == _XA_OL_DECOR_CLOSE) + t->ol_hints |= OL_DECOR_CLOSE; + else if (hints[i] == _XA_OL_DECOR_RESIZE) + t->ol_hints |= OL_DECOR_RESIZEH; + else if (hints[i] == _XA_OL_DECOR_HEADER) + t->ol_hints |= OL_DECOR_HEADER; + else if (hints[i] == _XA_OL_DECOR_ICON_NAME) + t->ol_hints |= OL_DECOR_ICON_NAME; + } + if (hints) + XFree(hints); + } + if (XGetWindowProperty(dpy, t->w, _XA_OL_DECOR_DEL, 0L, 20L, False, + XA_ATOM, &actual_type, &actual_format, &nitems, &bytesafter, + (unsigned char **)&hints) == Success) { + for (i = 0; i < nitems; i++) { + if (hints[i] == _XA_OL_DECOR_CLOSE) + t->ol_hints &= ~OL_DECOR_CLOSE; + else if (hints[i] == _XA_OL_DECOR_RESIZE) + t->ol_hints &= ~OL_DECOR_RESIZEH; + else if (hints[i] == _XA_OL_DECOR_HEADER) + t->ol_hints &= ~OL_DECOR_HEADER; + else if (hints[i] == _XA_OL_DECOR_ICON_NAME) + t->ol_hints &= ~OL_DECOR_ICON_NAME; + } + if (hints) + XFree(hints); + } } - /**************************************************************************** * * Interprets the property MOTIF_WM_HINTS, sets decoration and functions * accordingly * *****************************************************************************/ -void SelectDecor(FvwmWindow *t, unsigned long tflags, int border_width, - int resize_width) +void +SelectDecor( + FvwmWindow *t, unsigned long tflags, int border_width, int resize_width) { - int decor,i; - PropMwmHints *prop; - - if(!(tflags & BW_FLAG)) - border_width = Scr.NoBoundaryWidth; - - if(!(tflags & NOBW_FLAG)) - resize_width = Scr.BoundaryWidth; - - for(i=0;i<5;i++) - { - t->left_w[i] = 1; - t->right_w[i] = 1; - } - - decor = MWM_DECOR_ALL; - t->functions = MWM_FUNC_ALL; - if(t->mwm_hints) - { - prop = (PropMwmHints *)t->mwm_hints; - if(tflags & MWM_DECOR_FLAG) - if(prop->flags & MWM_HINTS_DECORATIONS) - decor = prop->decorations; - if(tflags & MWM_FUNCTIONS_FLAG) - if(prop->flags & MWM_HINTS_FUNCTIONS) - t->functions = prop->functions; - } - - /* functions affect the decorations! if the user says - * no iconify function, then the iconify button doesn't show - * up. */ - if(t->functions & MWM_FUNC_ALL) - { - /* If we get ALL + some other things, that means to use - * ALL except the other things... */ - t->functions &= ~MWM_FUNC_ALL; - t->functions = (MWM_FUNC_RESIZE | MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | - MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE) & (~(t->functions)); - } - if((tflags & MWM_FUNCTIONS_FLAG) && (t->flags & TRANSIENT)) - { - t->functions &= ~(MWM_FUNC_MAXIMIZE|MWM_FUNC_MINIMIZE); - } - - if(decor & MWM_DECOR_ALL) - { - /* If we get ALL + some other things, that means to use - * ALL except the other things... */ - decor &= ~MWM_DECOR_ALL; - decor = (MWM_DECOR_BORDER | MWM_DECOR_RESIZEH | MWM_DECOR_TITLE | - MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE) - & (~decor); - } - - /* now remove any functions specified in the OL hints */ - if (tflags & OL_DECOR_FLAG) - { - if (!(t->ol_hints & OL_DECOR_CLOSE)) - t->functions &= ~MWM_FUNC_MINIMIZE; - if (!(t->ol_hints & OL_DECOR_RESIZEH)) - t->functions &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); - if (!(t->ol_hints & OL_DECOR_HEADER)) - t->functions &= ~(MWM_DECOR_MENU | MWM_FUNC_MINIMIZE | - MWM_FUNC_MAXIMIZE | MWM_DECOR_TITLE); - if (!(t->ol_hints & OL_DECOR_ICON_NAME)) - t->flags |= NOICON_TITLE; - } - - /* Now I have the un-altered decor and functions, but with the - * ALL attribute cleared and interpreted. I need to modify the - * decorations that are affected by the functions */ - if(!(t->functions & MWM_FUNC_RESIZE)) - decor &= ~MWM_DECOR_RESIZEH; - /* MWM_FUNC_MOVE has no impact on decorations. */ - if(!(t->functions & MWM_FUNC_MINIMIZE)) - decor &= ~MWM_DECOR_MINIMIZE; - if(!(t->functions & MWM_FUNC_MAXIMIZE)) - decor &= ~MWM_DECOR_MAXIMIZE; - /* MWM_FUNC_CLOSE has no impact on decorations. */ - - /* This rule is implicit, but its easier to deal with if - * I take care of it now */ - if(decor & (MWM_DECOR_MENU| MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE)) - decor |= MWM_DECOR_TITLE; - - /* Selected the mwm-decor field, now trim down, based on - * .fvwmrc entries */ - if ((tflags & NOTITLE_FLAG)|| - ((!(tflags & DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) - decor &= ~MWM_DECOR_TITLE; - - if ((tflags & NOBORDER_FLAG)|| - ((!(tflags&DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) - decor &= ~MWM_DECOR_RESIZEH; - - if((tflags & MWM_DECOR_FLAG) && (t->flags & TRANSIENT)) - { - decor &= ~(MWM_DECOR_MAXIMIZE|MWM_DECOR_MINIMIZE); - } + int decor, i; + PropMwmHints *prop; + + if (!(tflags & BW_FLAG)) + border_width = Scr.NoBoundaryWidth; + + if (!(tflags & NOBW_FLAG)) + resize_width = Scr.BoundaryWidth; + + for (i = 0; i < 5; i++) { + t->left_w[i] = 1; + t->right_w[i] = 1; + } + + decor = MWM_DECOR_ALL; + t->functions = MWM_FUNC_ALL; + if (t->mwm_hints) { + prop = (PropMwmHints *)t->mwm_hints; + if (tflags & MWM_DECOR_FLAG) + if (prop->flags & MWM_HINTS_DECORATIONS) + decor = prop->decorations; + if (tflags & MWM_FUNCTIONS_FLAG) + if (prop->flags & MWM_HINTS_FUNCTIONS) + t->functions = prop->functions; + } + + /* functions affect the decorations! if the user says + * no iconify function, then the iconify button doesn't show + * up. */ + if (t->functions & MWM_FUNC_ALL) { + /* If we get ALL + some other things, that means to use + * ALL except the other things... */ + t->functions &= ~MWM_FUNC_ALL; + t->functions = + (MWM_FUNC_RESIZE | MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE | + MWM_FUNC_MAXIMIZE | MWM_FUNC_CLOSE) & + (~(t->functions)); + } + if ((tflags & MWM_FUNCTIONS_FLAG) && (t->flags & TRANSIENT)) { + t->functions &= ~(MWM_FUNC_MAXIMIZE | MWM_FUNC_MINIMIZE); + } + + if (decor & MWM_DECOR_ALL) { + /* If we get ALL + some other things, that means to use + * ALL except the other things... */ + decor &= ~MWM_DECOR_ALL; + decor = (MWM_DECOR_BORDER | MWM_DECOR_RESIZEH | + MWM_DECOR_TITLE | MWM_DECOR_MENU | + MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE) & + (~decor); + } + + /* now remove any functions specified in the OL hints */ + if (tflags & OL_DECOR_FLAG) { + if (!(t->ol_hints & OL_DECOR_CLOSE)) + t->functions &= ~MWM_FUNC_MINIMIZE; + if (!(t->ol_hints & OL_DECOR_RESIZEH)) + t->functions &= ~(MWM_FUNC_RESIZE | MWM_FUNC_MAXIMIZE); + if (!(t->ol_hints & OL_DECOR_HEADER)) + t->functions &= ~(MWM_DECOR_MENU | MWM_FUNC_MINIMIZE | + MWM_FUNC_MAXIMIZE | MWM_DECOR_TITLE); + if (!(t->ol_hints & OL_DECOR_ICON_NAME)) + t->flags |= NOICON_TITLE; + } + + /* Now I have the un-altered decor and functions, but with the + * ALL attribute cleared and interpreted. I need to modify the + * decorations that are affected by the functions */ + if (!(t->functions & MWM_FUNC_RESIZE)) + decor &= ~MWM_DECOR_RESIZEH; + /* MWM_FUNC_MOVE has no impact on decorations. */ + if (!(t->functions & MWM_FUNC_MINIMIZE)) + decor &= ~MWM_DECOR_MINIMIZE; + if (!(t->functions & MWM_FUNC_MAXIMIZE)) + decor &= ~MWM_DECOR_MAXIMIZE; + /* MWM_FUNC_CLOSE has no impact on decorations. */ + + /* This rule is implicit, but its easier to deal with if + * I take care of it now */ + if (decor & (MWM_DECOR_MENU | MWM_DECOR_MINIMIZE | MWM_DECOR_MAXIMIZE)) + decor |= MWM_DECOR_TITLE; + + /* Selected the mwm-decor field, now trim down, based on + * .fvwmrc entries */ + if ((tflags & NOTITLE_FLAG) || + ((!(tflags & DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) + decor &= ~MWM_DECOR_TITLE; + + if ((tflags & NOBORDER_FLAG) || + ((!(tflags & DECORATE_TRANSIENT_FLAG)) && (t->flags & TRANSIENT))) + decor &= ~MWM_DECOR_RESIZEH; + + if ((tflags & MWM_DECOR_FLAG) && (t->flags & TRANSIENT)) { + decor &= ~(MWM_DECOR_MAXIMIZE | MWM_DECOR_MINIMIZE); + } #ifdef SHAPE - if (ShapesSupported) - { - if(t->wShaped) - decor &= ~(BORDER|MWM_DECOR_RESIZEH); - } + if (ShapesSupported) { + if (t->wShaped) + decor &= ~(BORDER | MWM_DECOR_RESIZEH); + } #endif - /* Assume no decorations, and build up */ - t->flags &= ~(BORDER|TITLE); - if(tflags & MWM_BORDER_FLAG) - t->flags |= MWMBorders; - if(tflags & MWM_BUTTON_FLAG) - t->flags |= MWMButtons; - if(tflags & MWM_OVERRIDE_FLAG) - t->flags |= HintOverride; - t->boundary_width = 0; - t->corner_width = 0; - t->title_height = 0; - - if(decor & MWM_DECOR_BORDER) - { - /* A narrow border is displayed (5 pixels - 2 relief, 1 top, - * (2 shadow) */ - t->boundary_width = border_width; - } - if(decor & MWM_DECOR_TITLE) - { - /* A title barm with no buttons in it - * window gets a 1 pixel wide black border. */ - t->flags |= TITLE; - t->title_height = GetDecor(t,TitleHeight); - } - if(decor & MWM_DECOR_RESIZEH) - { - /* A wide border, with corner tiles is desplayed - * (10 pixels - 2 relief, 2 shadow) */ - t->flags |= BORDER; - t->boundary_width = resize_width; - t->corner_width = GetDecor(t,TitleHeight) + t->boundary_width; - } - if(!(decor & MWM_DECOR_MENU)) - { - /* title-bar menu button omitted - * window gets 1 pixel wide black border */ - /* disable any buttons with the MWMDecorMenu flag */ - int i; - for (i = 0; i < 5; ++i) { - if (GetDecor(t,left_buttons[i].flags)&MWMDecorMenu) - t->left_w[i] = None; - if (GetDecor(t,right_buttons[i].flags)&MWMDecorMenu) - t->right_w[i] = None; - } - } - if(!(decor & MWM_DECOR_MINIMIZE)) - { - /* title-bar + iconify button, no menu button. - * window gets 1 pixel wide black border */ - /* disable any buttons with the MWMDecorMinimize flag */ - int i; - for (i = 0; i < 5; ++i) { - if (GetDecor(t,left_buttons[i].flags)&MWMDecorMinimize) - t->left_w[i] = None; - if (GetDecor(t,right_buttons[i].flags)&MWMDecorMinimize) - t->right_w[i] = None; - } - } - if(!(decor & MWM_DECOR_MAXIMIZE)) - { - /* title-bar + maximize button, no menu button, no iconify. - * window has 1 pixel wide black border */ - /* disable any buttons with the MWMDecorMaximize flag */ - int i; - for (i = 0; i < 5; ++i) { - if (GetDecor(t,left_buttons[i].flags)&MWMDecorMaximize) - t->left_w[i] = None; - if (GetDecor(t,right_buttons[i].flags)&MWMDecorMaximize) - t->right_w[i] = None; - } - } - if (t->buttons & BUTTON1) t->left_w[0]=None; - if (t->buttons & BUTTON3) t->left_w[1]=None; - if (t->buttons & BUTTON5) t->left_w[2]=None; - if (t->buttons & BUTTON7) t->left_w[3]=None; - if (t->buttons & BUTTON9) t->left_w[4]=None; - - if (t->buttons & BUTTON2) t->right_w[0]=None; - if (t->buttons & BUTTON4) t->right_w[1]=None; - if (t->buttons & BUTTON6) t->right_w[2]=None; - if (t->buttons & BUTTON8) t->right_w[3]=None; - if (t->buttons & BUTTON10)t->right_w[4]=None; - - t->nr_left_buttons = Scr.nr_left_buttons; - t->nr_right_buttons = Scr.nr_right_buttons; - - for(i=0;ileft_w[i] == None) - t->nr_left_buttons--; - - for(i=0;iright_w[i] == None) - t->nr_right_buttons--; - - if(tflags & MWM_BORDER_FLAG) - t->bw = 0; - else if(t->boundary_width <= 0) - { - t->boundary_width = 0; - t->bw = 0; - } - else - { - t->bw = BW; - t->boundary_width = t->boundary_width - 1; - } - if(t->title_height > 0) - t->title_height += t->bw; - if(t->boundary_width == 0) - t->flags &= ~BORDER; + /* Assume no decorations, and build up */ + t->flags &= ~(BORDER | TITLE); + if (tflags & MWM_BORDER_FLAG) + t->flags |= MWMBorders; + if (tflags & MWM_BUTTON_FLAG) + t->flags |= MWMButtons; + if (tflags & MWM_OVERRIDE_FLAG) + t->flags |= HintOverride; + t->boundary_width = 0; + t->corner_width = 0; + t->title_height = 0; + + if (decor & MWM_DECOR_BORDER) { + /* A narrow border is displayed (5 pixels - 2 relief, 1 top, + * (2 shadow) */ + t->boundary_width = border_width; + } + if (decor & MWM_DECOR_TITLE) { + /* A title barm with no buttons in it + * window gets a 1 pixel wide black border. */ + t->flags |= TITLE; + t->title_height = GetDecor(t, TitleHeight); + } + if (decor & MWM_DECOR_RESIZEH) { + /* A wide border, with corner tiles is desplayed + * (10 pixels - 2 relief, 2 shadow) */ + t->flags |= BORDER; + t->boundary_width = resize_width; + t->corner_width = GetDecor(t, TitleHeight) + t->boundary_width; + } + if (!(decor & MWM_DECOR_MENU)) { + /* title-bar menu button omitted + * window gets 1 pixel wide black border */ + /* disable any buttons with the MWMDecorMenu flag */ + int i; + for (i = 0; i < 5; ++i) { + if (GetDecor(t, left_buttons[i].flags) & MWMDecorMenu) + t->left_w[i] = None; + if (GetDecor(t, right_buttons[i].flags) & MWMDecorMenu) + t->right_w[i] = None; + } + } + if (!(decor & MWM_DECOR_MINIMIZE)) { + /* title-bar + iconify button, no menu button. + * window gets 1 pixel wide black border */ + /* disable any buttons with the MWMDecorMinimize flag */ + int i; + for (i = 0; i < 5; ++i) { + if (GetDecor(t, left_buttons[i].flags) & + MWMDecorMinimize) + t->left_w[i] = None; + if (GetDecor(t, right_buttons[i].flags) & + MWMDecorMinimize) + t->right_w[i] = None; + } + } + if (!(decor & MWM_DECOR_MAXIMIZE)) { + /* title-bar + maximize button, no menu button, no iconify. + * window has 1 pixel wide black border */ + /* disable any buttons with the MWMDecorMaximize flag */ + int i; + for (i = 0; i < 5; ++i) { + if (GetDecor(t, left_buttons[i].flags) & + MWMDecorMaximize) + t->left_w[i] = None; + if (GetDecor(t, right_buttons[i].flags) & + MWMDecorMaximize) + t->right_w[i] = None; + } + } + if (t->buttons & BUTTON1) + t->left_w[0] = None; + if (t->buttons & BUTTON3) + t->left_w[1] = None; + if (t->buttons & BUTTON5) + t->left_w[2] = None; + if (t->buttons & BUTTON7) + t->left_w[3] = None; + if (t->buttons & BUTTON9) + t->left_w[4] = None; + + if (t->buttons & BUTTON2) + t->right_w[0] = None; + if (t->buttons & BUTTON4) + t->right_w[1] = None; + if (t->buttons & BUTTON6) + t->right_w[2] = None; + if (t->buttons & BUTTON8) + t->right_w[3] = None; + if (t->buttons & BUTTON10) + t->right_w[4] = None; + + t->nr_left_buttons = Scr.nr_left_buttons; + t->nr_right_buttons = Scr.nr_right_buttons; + + for (i = 0; i < Scr.nr_left_buttons; i++) + if (t->left_w[i] == None) + t->nr_left_buttons--; + + for (i = 0; i < Scr.nr_right_buttons; i++) + if (t->right_w[i] == None) + t->nr_right_buttons--; + + if (tflags & MWM_BORDER_FLAG) + t->bw = 0; + else if (t->boundary_width <= 0) { + t->boundary_width = 0; + t->bw = 0; + } else { + t->bw = BW; + t->boundary_width = t->boundary_width - 1; + } + if (t->title_height > 0) + t->title_height += t->bw; + if (t->boundary_width == 0) + t->flags &= ~BORDER; } /* @@ -465,98 +464,95 @@ void SelectDecor(FvwmWindow *t, unsigned long tflags, int border_width, ** check_allowed_function2 partially overlapping in their checks, so I ** combined them here and made them wrapper functions instead. */ -static int check_if_function_allowed(int function, - FvwmWindow *t, - MenuItem *mi) +static int +check_if_function_allowed(int function, FvwmWindow *t, MenuItem *mi) { - if (t) /* should always be ok */ - { - if (!mi) /* no menu item, must be exec check, so allow overrides */ - { - if(t->flags & HintOverride) - return 1; - } - - switch(function) - { - case F_DELETE: - if (!(t->flags & DoesWmDeleteWindow)) - return 0; - /* fall through to close clause */ - case F_CLOSE: - if (!(t->functions & MWM_FUNC_CLOSE)) - return 0; - break; - case F_DESTROY: /* shouldn't destroy always be allowed??? */ - if (!(t->functions & MWM_FUNC_CLOSE)) - return 0; - break; - case F_RESIZE: - if (!(t->functions & MWM_FUNC_RESIZE)) - return 0; - break; - case F_ICONIFY: - if ((!(t->flags & ICONIFIED))&& - (!(t->functions & MWM_FUNC_MINIMIZE))) - return 0; - break; - case F_MAXIMIZE: - if (!(t->functions & MWM_FUNC_MAXIMIZE)) - return 0; - break; - case F_MOVE: - /* Move is a funny hint. Keeps it out of the menu, but you're - * still allowed to move. */ - if((!(t->functions & MWM_FUNC_MOVE))&&mi) - return 0; - break; - case F_FUNCTION: - /* Hard part! What to do now? */ - /* Hate to do it, but for lack of a better idea, - * check based on the menu entry name */ - /* Complex functions are a little tricky, ignore them if no menu item*/ - if (mi && mi->item) - { - if((!(t->functions & MWM_FUNC_MOVE))&& - (StrEquals(mi->item,MOVE_STRING))) - return 0; - if((!(t->functions & MWM_FUNC_RESIZE))&& - (StrEquals(mi->item,RESIZE_STRING1))) - return 0; - if((!(t->functions & MWM_FUNC_RESIZE))&& - (StrEquals(mi->item,RESIZE_STRING2))) - return 0; - if((!(t->functions & MWM_FUNC_MINIMIZE))&& - (!(t->flags & ICONIFIED))&& - (StrEquals(mi->item,MINIMIZE_STRING))) - return 0; - if((!(t->functions & MWM_FUNC_MINIMIZE))&& - (StrEquals(mi->item,MINIMIZE_STRING2))) - return 0; - if((!(t->functions & MWM_FUNC_MAXIMIZE))&& - (StrEquals(mi->item,MAXIMIZE_STRING))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING1))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING2))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING3))) - return 0; - if((!(t->functions & MWM_FUNC_CLOSE))&& - (StrEquals(mi->item,CLOSE_STRING4))) - return 0; - } - break; - default: - break; - } /* end of switch */ - } /* end of if */ - - /* if we fell through, just return a 1 */ - return 1; + if (t) { /* should always be ok */ + if (!mi) { /* no menu item, must be exec check, so allow overrides + */ + if (t->flags & HintOverride) + return 1; + } + + switch (function) { + case F_DELETE: + if (!(t->flags & DoesWmDeleteWindow)) + return 0; + /* fall through to close clause */ + case F_CLOSE: + if (!(t->functions & MWM_FUNC_CLOSE)) + return 0; + break; + case F_DESTROY: /* shouldn't destroy always be allowed??? */ + if (!(t->functions & MWM_FUNC_CLOSE)) + return 0; + break; + case F_RESIZE: + if (!(t->functions & MWM_FUNC_RESIZE)) + return 0; + break; + case F_ICONIFY: + if ((!(t->flags & ICONIFIED)) && + (!(t->functions & MWM_FUNC_MINIMIZE))) + return 0; + break; + case F_MAXIMIZE: + if (!(t->functions & MWM_FUNC_MAXIMIZE)) + return 0; + break; + case F_MOVE: + /* Move is a funny hint. Keeps it out of the menu, but + * you're still allowed to move. */ + if ((!(t->functions & MWM_FUNC_MOVE)) && mi) + return 0; + break; + case F_FUNCTION: + /* Hard part! What to do now? */ + /* Hate to do it, but for lack of a better idea, + * check based on the menu entry name */ + /* Complex functions are a little tricky, ignore them if + * no menu item*/ + if (mi && mi->item) { + if ((!(t->functions & MWM_FUNC_MOVE)) && + (StrEquals(mi->item, MOVE_STRING))) + return 0; + if ((!(t->functions & MWM_FUNC_RESIZE)) && + (StrEquals(mi->item, RESIZE_STRING1))) + return 0; + if ((!(t->functions & MWM_FUNC_RESIZE)) && + (StrEquals(mi->item, RESIZE_STRING2))) + return 0; + if ((!(t->functions & MWM_FUNC_MINIMIZE)) && + (!(t->flags & ICONIFIED)) && + (StrEquals(mi->item, MINIMIZE_STRING))) + return 0; + if ((!(t->functions & MWM_FUNC_MINIMIZE)) && + (StrEquals(mi->item, MINIMIZE_STRING2))) + return 0; + if ((!(t->functions & MWM_FUNC_MAXIMIZE)) && + (StrEquals(mi->item, MAXIMIZE_STRING))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING1))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING2))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING3))) + return 0; + if ((!(t->functions & MWM_FUNC_CLOSE)) && + (StrEquals(mi->item, CLOSE_STRING4))) + return 0; + } + break; + default: + break; + } /* end of switch */ + } /* end of if */ + + /* if we fell through, just return a 1 */ + return 1; } /**************************************************************************** @@ -568,9 +564,10 @@ static int check_if_function_allowed(int function, * This routine is used to determine whether or not to grey out menu items. * ****************************************************************************/ -int check_allowed_function(MenuItem *mi) +int +check_allowed_function(MenuItem *mi) { - return check_if_function_allowed(mi->func_type,Tmp_win,mi); + return check_if_function_allowed(mi->func_type, Tmp_win, mi); } /**************************************************************************** @@ -580,10 +577,8 @@ int check_allowed_function(MenuItem *mi) * This routine is used to decide if we should refuse to perform a function. * ****************************************************************************/ -int check_allowed_function2(int function, FvwmWindow *t) +int +check_allowed_function2(int function, FvwmWindow *t) { - return check_if_function_allowed(function,t,NULL); + return check_if_function_allowed(function, t, NULL); } - - - Index: fvwm/fvwm/defaults.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/defaults.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/defaults.h --- fvwm/fvwm/defaults.h +++ fvwm/fvwm/defaults.h @@ -7,6 +7,6 @@ * 23 Dec 1998 - Dominik Vogt */ -#define DEFAULT_CLICKTIME 150 /* ms */ -#define DEFAULT_POPUP_DELAY 15 /* ms*10 */ -#define DEFAULT_MENU_CLICKTIME (3*DEFAULT_CLICKTIME) +#define DEFAULT_CLICKTIME 150 /* ms */ +#define DEFAULT_POPUP_DELAY 15 /* ms*10 */ +#define DEFAULT_MENU_CLICKTIME (3 * DEFAULT_CLICKTIME) Index: fvwm/fvwm/events.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/events.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/events.c --- fvwm/fvwm/events.c +++ fvwm/fvwm/events.c @@ -29,7 +29,6 @@ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ - /*********************************************************************** * * fvwm event handling @@ -38,23 +37,23 @@ #include "config.h" -#if HAVE_SYS_BSDTYPES_H -#include #endif +#include +#include + +#include #include #include -#include -#include #include -#include #if HAVE_SYS_SELECT_H #include #endif -#include "fvwm.h" #include + +#include "fvwm.h" #include "menus.h" #include "misc.h" #include "parse.h" @@ -64,20 +63,20 @@ #endif /* SHAPE */ #include "module.h" -unsigned int mods_used = (ShiftMask | ControlMask | Mod1Mask | - Mod2Mask| Mod3Mask| Mod4Mask| Mod5Mask); +unsigned int mods_used = (ShiftMask | ControlMask | Mod1Mask | Mod2Mask | + Mod3Mask | Mod4Mask | Mod5Mask); extern int menuFromFrameOrWindowOrTitlebar; extern Boolean debugging; -int Context = C_NO_CONTEXT; /* current button press context */ +int Context = C_NO_CONTEXT; /* current button press context */ int Button = 0; -FvwmWindow *ButtonWindow; /* button press window structure */ -XEvent Event; /* the current event */ -FvwmWindow *Tmp_win; /* the current fvwm window */ +FvwmWindow *ButtonWindow; /* button press window structure */ +XEvent Event; /* the current event */ +FvwmWindow *Tmp_win; /* the current fvwm window */ -int last_event_type=0; -Window last_event_window=0; +int last_event_type = 0; +Window last_event_window = 0; #ifdef SHAPE extern int ShapeEventBase; @@ -98,38 +97,39 @@ Window PressedW; #endif /* !LASTEvent */ typedef void (*PFEH)(void); PFEH EventHandlerJumpTable[LASTEvent]; -void ResyncFvwmStackRing(void); +void ResyncFvwmStackRing(void); /* ** Procedure: ** InitEventHandlerJumpTable */ -void InitEventHandlerJumpTable(void) +void +InitEventHandlerJumpTable(void) { - int i; - - for (i=0; ixany.window; - - if(*w == Scr.NoFocusWin) - return C_ROOT; - - /* Since key presses and button presses are grabbed in the frame - * when we have re-parented windows, we need to find out the real - * window where the event occured */ -#if 0 - /* domivogt (2-Jan-1999): Causes a bug with ClickToFocus. - * keys and buttons are treated differently here because keys are bound to - * the frame window and buttons are bound to the client window (with - * XGrabKey/XGrabButton). */ - if((e->type == KeyPress)&&(e->xkey.subwindow != None)) - *w = e->xkey.subwindow; - - if((e->type == ButtonPress)&&(e->xbutton.subwindow != None)&& - ((e->xbutton.subwindow == t->w)||(e->xbutton.subwindow == t->Parent))) - *w = e->xbutton.subwindow; -#else - if(e->xkey.subwindow != None) - { - if (e->type == KeyPress) - *w = e->xkey.subwindow; - else if ((*w != t->w && *w != t->Parent) || - e->xbutton.subwindow == t->w || - e->xbutton.subwindow == t->Parent) - /* domivogt (6-Jan-198): I don't understand what's happening here. If - * the mouse is over the client window. The subwindow has an unique id - * that no visible part of the FvwmWindow has. */ - *w = e->xbutton.subwindow; - } -#endif + int Context, i; + + if (!t) + return C_ROOT; + + Context = C_NO_CONTEXT; + *w = e->xany.window; + + if (*w == Scr.NoFocusWin) + return C_ROOT; + + /* Since key presses and button presses are grabbed in the frame + * when we have re-parented windows, we need to find out the real + * window where the event occured */ + if (e->xkey.subwindow != None) { + if (e->type == KeyPress) + *w = e->xkey.subwindow; + else if ((*w != t->w && *w != t->Parent) || + e->xbutton.subwindow == t->w || + e->xbutton.subwindow == t->Parent) + /* domivogt (6-Jan-198): I don't understand what's + * happening here. If the mouse is over the client + * window. The subwindow has an unique id that no + * visible part of the FvwmWindow has. */ + *w = e->xbutton.subwindow; + } - if (*w == Scr.Root) - Context = C_ROOT; - if (t) - { - if (*w == t->title_w) - Context = C_TITLE; - else if ((*w == t->w)||(*w == t->Parent)) - Context = C_WINDOW; - else if (*w == t->icon_w || *w == t->icon_pixmap_w) - Context = C_ICON; - else if (*w == t->frame) - Context = C_SIDEBAR; - else - { - for(i=0;i<4;i++) - { - if(*w == t->corners[i]) - { - Context = C_FRAME; - break; - } - if(*w == t->sides[i]) - { - Context = C_SIDEBAR; - break; - } - } - if (i < 4) - Button = i; - else - { - for(i=0;ileft_w[i]) - { - Context = (1<right_w[i]) - { - Context = (1<title_w) + Context = C_TITLE; + else if ((*w == t->w) || (*w == t->Parent)) + Context = C_WINDOW; + else if (*w == t->icon_w || *w == t->icon_pixmap_w) + Context = C_ICON; + else if (*w == t->frame) + Context = C_SIDEBAR; + else { + for (i = 0; i < 4; i++) { + if (*w == t->corners[i]) { + Context = C_FRAME; + break; + } + if (*w == t->sides[i]) { + Context = C_SIDEBAR; + break; + } + } + if (i < 4) + Button = i; + else { + for (i = 0; i < Scr.nr_left_buttons; i++) { + if (*w == t->left_w[i]) { + Context = (1 << i) * C_L1; + break; + } + } + if (i < Scr.nr_left_buttons) + Button = i; + else { + for (i = 0; i < Scr.nr_right_buttons; + i++) { + if (*w == t->right_w[i]) { + Context = + (1 << i) * C_R1; + Button = i; + break; + } + } + } + } /* if (i < 4) */ + } /* else */ + } /* if (t) */ + return Context; } /*********************************************************************** @@ -299,69 +277,53 @@ int GetContext(FvwmWindow *t, XEvent *e, Window *w) * HandleFocusIn - handles focus in events * ************************************************************************/ -void HandleFocusIn() +void +HandleFocusIn() { - XEvent d; - Window w; - - DBUG("HandleFocusIn","Routine Entered"); - - w= Event.xany.window; - while(XCheckTypedEvent(dpy,FocusIn,&d)) - { - w = d.xany.window; - } - if (XFindContext (dpy, w, FvwmContext, (caddr_t *) &Tmp_win) == XCNOENT) - { - Tmp_win = NULL; - } - - if(!Tmp_win) - { - if(w != Scr.NoFocusWin) - { - Scr.UnknownWinFocused = w; + XEvent d; + Window w; + + DBUG("HandleFocusIn", "Routine Entered"); + + w = Event.xany.window; + while (XCheckTypedEvent(dpy, FocusIn, &d)) { + w = d.xany.window; } - else - { - SetBorder(Scr.Hilite,False,True,True,None); - BroadcastPacket(M_FOCUS_CHANGE, 5, - 0, 0, 0, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) - { - if((Scr.Hilite)&&(!(Scr.Hilite->flags & ICONIFIED))) - { - InstallWindowColormaps(Scr.Hilite); + if (XFindContext(dpy, w, FvwmContext, (caddr_t *)&Tmp_win) == XCNOENT) { + Tmp_win = NULL; + } + + if (!Tmp_win) { + if (w != Scr.NoFocusWin) { + Scr.UnknownWinFocused = w; + } else { + SetBorder(Scr.Hilite, False, True, True, None); + BroadcastPacket(M_FOCUS_CHANGE, 5, 0, 0, 0, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) { + if ((Scr.Hilite) && + (!(Scr.Hilite->flags & ICONIFIED))) { + InstallWindowColormaps(Scr.Hilite); + } else { + InstallWindowColormaps(NULL); + } + } } - else - { - InstallWindowColormaps(NULL); + } else if (Tmp_win != Scr.Hilite) { + SetBorder(Tmp_win, True, True, True, None); + BroadcastPacket(M_FOCUS_CHANGE, 5, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, GetDecor(Tmp_win, HiColors.fore), + GetDecor(Tmp_win, HiColors.back)); + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) { + if ((Scr.Hilite) && + (!(Scr.Hilite->flags & ICONIFIED))) { + InstallWindowColormaps(Scr.Hilite); + } else { + InstallWindowColormaps(NULL); + } } - } - } - } - else if(Tmp_win != Scr.Hilite) - { - SetBorder(Tmp_win,True,True,True,None); - BroadcastPacket(M_FOCUS_CHANGE, 5, - Tmp_win->w, Tmp_win->frame, (unsigned long)Tmp_win, - GetDecor(Tmp_win,HiColors.fore), - GetDecor(Tmp_win,HiColors.back)); - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_FOCUS) - { - if((Scr.Hilite)&&(!(Scr.Hilite->flags & ICONIFIED))) - { - InstallWindowColormaps(Scr.Hilite); - } - else - { - InstallWindowColormaps(NULL); - } - } - } } /*********************************************************************** @@ -370,52 +332,61 @@ void HandleFocusIn() * HandleKeyPress - key press event handler * ************************************************************************/ -void HandleKeyPress() +void +HandleKeyPress() { - Binding *key; - unsigned int modifier; - modifier = (Event.xkey.state & mods_used); - ButtonWindow = Tmp_win; - - DBUG("HandleKeyPress","Routine Entered"); - - Context = GetContext(Tmp_win,&Event, &PressedW); - PressedW = None; - - /* Here's a real hack - some systems have two keys with the - * same keysym and different keycodes. This converts all - * the cases to one keycode. */ - Event.xkey.keycode = - XKeysymToKeycode(dpy,XKeycodeToKeysym(dpy,Event.xkey.keycode,0)); - - for (key = Scr.AllBindings; key != NULL; key = key->NextBinding) - { - if ((key->Button_Key == Event.xkey.keycode) && - ((key->Modifier == (modifier&(~LockMask)))|| - (key->Modifier == AnyModifier)) && - (key->Context & Context)&& - (key->IsMouse == 0)) + Binding *key; + unsigned int modifier; + modifier = (Event.xkey.state & mods_used); + ButtonWindow = Tmp_win; + + DBUG("HandleKeyPress", "Routine Entered"); + + Context = GetContext(Tmp_win, &Event, &PressedW); + PressedW = None; + + /* Normalize keycodes that map to the same keysym. */ { - ExecuteFunction(key->Action,Tmp_win, &Event,Context,-1); - return; + KeySym *mapping; + int width; + + mapping = + XGetKeyboardMapping(dpy, Event.xkey.keycode, 1, &width); + if (mapping != NULL && width > 0) { + KeySym primary = mapping[0]; + KeyCode canonical = XKeysymToKeycode(dpy, primary); + + if (canonical != 0) + Event.xkey.keycode = canonical; + } + if (mapping != NULL) + XFree(mapping); } - } - - /* if we get here, no function key was bound to the key. Send it - * to the client if it was in a window we know about. - */ - if (Tmp_win) - { - if(Event.xkey.window != Tmp_win->w) - { - Event.xkey.window = Tmp_win->w; - XSendEvent(dpy, Tmp_win->w, False, KeyPressMask, &Event); + + for (key = Scr.AllBindings; key != NULL; key = key->NextBinding) { + if ((key->Button_Key == Event.xkey.keycode) && + ((key->Modifier == (modifier & (~LockMask))) || + (key->Modifier == AnyModifier)) && + (key->Context & Context) && (key->IsMouse == 0)) { + ExecuteFunction( + key->Action, Tmp_win, &Event, Context, -1); + return; + } } - } - ButtonWindow = NULL; -} + /* if we get here, no function key was bound to the key. Send it + * to the client if it was in a window we know about. + */ + if (Tmp_win) { + if (Event.xkey.window != Tmp_win->w) { + Event.xkey.window = Tmp_win->w; + XSendEvent( + dpy, Tmp_win->w, False, KeyPressMask, &Event); + } + } + ButtonWindow = NULL; +} /*********************************************************************** * @@ -423,253 +394,222 @@ void HandleKeyPress() * HandlePropertyNotify - property notify event handler * ***********************************************************************/ -#define MAX_NAME_LEN 200L /* truncate to this many */ -#define MAX_ICON_NAME_LEN 200L /* ditto */ +#define MAX_NAME_LEN 200L /* truncate to this many */ +#define MAX_ICON_NAME_LEN 200L /* ditto */ -void HandlePropertyNotify() +void +HandlePropertyNotify() { - XTextProperty text_prop; - Boolean OnThisPage = False; - - DBUG("HandlePropertyNotify","Routine Entered"); - - if ((!Tmp_win)|| - (XGetGeometry(dpy, Tmp_win->w, &JunkRoot, &JunkX, &JunkY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)) - return; - - /* - Make sure at least part of window is on this page - before giving it focus... - */ - if ( (Tmp_win->Desk == Scr.CurrentDesk) && - ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && - Tmp_win->frame_x < Scr.MyDisplayWidth) && - ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && - Tmp_win->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - - switch (Event.xproperty.atom) - { - case XA_WM_TRANSIENT_FOR: - { - if(XGetTransientForHint(dpy, Tmp_win->w, &Tmp_win->transientfor)) - { - Tmp_win->flags |= TRANSIENT; - RaiseWindow(Tmp_win); - } - else - { - Tmp_win->flags &= ~TRANSIENT; - } - } - break; - - case XA_WM_NAME: - if (!XGetWMName(dpy, Tmp_win->w, &text_prop)) - return; - - free_window_names (Tmp_win, True, False); - - Tmp_win->name = (char *)text_prop.value; - if (Tmp_win->name && strlen(Tmp_win->name) > 200) - /* limit to prevent hanging X server */ - Tmp_win->name[200] = 0; - - if (Tmp_win->name == NULL) - Tmp_win->name = NoName; - BroadcastName(M_WINDOW_NAME,Tmp_win->w,Tmp_win->frame, - (unsigned long)Tmp_win,Tmp_win->name); - - /* fix the name in the title bar */ - if(!(Tmp_win->flags & ICONIFIED)) - SetTitleBar(Tmp_win,(Scr.Hilite==Tmp_win),True); + XTextProperty text_prop; + Boolean OnThisPage = False; + + DBUG("HandlePropertyNotify", "Routine Entered"); + + if ((!Tmp_win) || + (XGetGeometry(dpy, Tmp_win->w, &JunkRoot, &JunkX, &JunkY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth) == 0)) + return; + + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Tmp_win->Desk == Scr.CurrentDesk) && + (((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && + Tmp_win->frame_x < Scr.MyDisplayWidth) && + ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && + Tmp_win->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } - /* - * if the icon name is NoName, set the name of the icon to be - * the same as the window - */ - if (Tmp_win->icon_name == NoName) - { - Tmp_win->icon_name = Tmp_win->name; - BroadcastName(M_ICON_NAME,Tmp_win->w,Tmp_win->frame, - (unsigned long)Tmp_win,Tmp_win->icon_name); - RedoIconName(Tmp_win); + switch (Event.xproperty.atom) { + case XA_WM_TRANSIENT_FOR: { + if (XGetTransientForHint( + dpy, Tmp_win->w, &Tmp_win->transientfor)) { + Tmp_win->flags |= TRANSIENT; + RaiseWindow(Tmp_win); + } else { + Tmp_win->flags &= ~TRANSIENT; + } } - break; + break; - case XA_WM_ICON_NAME: - if (!XGetWMIconName (dpy, Tmp_win->w, &text_prop)) - return; - free_window_names (Tmp_win, False, True); - Tmp_win->icon_name = (char *) text_prop.value; - if (Tmp_win->icon_name && strlen(Tmp_win->icon_name) > 200) - /* limit to prevent hanging X server */ - Tmp_win->icon_name[200] = 0; - if (Tmp_win->icon_name == NULL) - Tmp_win->icon_name = NoName; - BroadcastName(M_ICON_NAME,Tmp_win->w,Tmp_win->frame, - (unsigned long)Tmp_win,Tmp_win->icon_name); - RedoIconName(Tmp_win); - break; - - case XA_WM_HINTS: - if (Tmp_win->wmhints) - XFree ((char *) Tmp_win->wmhints); - Tmp_win->wmhints = XGetWMHints(dpy, Event.xany.window); - - if(Tmp_win->wmhints == NULL) - return; + case XA_WM_NAME: + if (!XGetWMName(dpy, Tmp_win->w, &text_prop)) + return; + + free_window_names(Tmp_win, True, False); + + Tmp_win->name = (char *)text_prop.value; + if (Tmp_win->name && strlen(Tmp_win->name) > 200) + /* limit to prevent hanging X server */ + Tmp_win->name[200] = 0; + + if (Tmp_win->name == NULL) + Tmp_win->name = NoName; + BroadcastName(M_WINDOW_NAME, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, Tmp_win->name); + + /* fix the name in the title bar */ + if (!(Tmp_win->flags & ICONIFIED)) + SetTitleBar(Tmp_win, (Scr.Hilite == Tmp_win), True); + + /* + * if the icon name is NoName, set the name of the icon to be + * the same as the window + */ + if (Tmp_win->icon_name == NoName) { + Tmp_win->icon_name = Tmp_win->name; + BroadcastName(M_ICON_NAME, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, Tmp_win->icon_name); + RedoIconName(Tmp_win); + } + break; - if((Tmp_win->wmhints->flags & IconPixmapHint)|| - (Tmp_win->wmhints->flags & IconWindowHint)) - if(Tmp_win->icon_bitmap_file == Scr.DefaultIcon) - Tmp_win->icon_bitmap_file = (char *)0; + case XA_WM_ICON_NAME: + if (!XGetWMIconName(dpy, Tmp_win->w, &text_prop)) + return; + free_window_names(Tmp_win, False, True); + Tmp_win->icon_name = (char *)text_prop.value; + if (Tmp_win->icon_name && strlen(Tmp_win->icon_name) > 200) + /* limit to prevent hanging X server */ + Tmp_win->icon_name[200] = 0; + if (Tmp_win->icon_name == NULL) + Tmp_win->icon_name = NoName; + BroadcastName(M_ICON_NAME, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win, Tmp_win->icon_name); + RedoIconName(Tmp_win); + break; - if((Tmp_win->wmhints->flags & IconPixmapHint)|| - (Tmp_win->wmhints->flags & IconWindowHint)) - { - if (!(Tmp_win->flags & SUPPRESSICON)) - { - if (Tmp_win->icon_w) - XDestroyWindow(dpy,Tmp_win->icon_w); - XDeleteContext(dpy, Tmp_win->icon_w, FvwmContext); - if(Tmp_win->flags & ICON_OURS) - { - if(Tmp_win->icon_pixmap_w != None) - { - XDestroyWindow(dpy,Tmp_win->icon_pixmap_w); - XDeleteContext(dpy, Tmp_win->icon_pixmap_w, FvwmContext); - } + case XA_WM_HINTS: + if (Tmp_win->wmhints) + XFree((char *)Tmp_win->wmhints); + Tmp_win->wmhints = XGetWMHints(dpy, Event.xany.window); + + if (Tmp_win->wmhints == NULL) + return; + + if ((Tmp_win->wmhints->flags & IconPixmapHint) || + (Tmp_win->wmhints->flags & IconWindowHint)) + if (Tmp_win->icon_bitmap_file == Scr.DefaultIcon) + Tmp_win->icon_bitmap_file = (char *)0; + + if ((Tmp_win->wmhints->flags & IconPixmapHint) || + (Tmp_win->wmhints->flags & IconWindowHint)) { + if (!(Tmp_win->flags & SUPPRESSICON)) { + if (Tmp_win->icon_w) + XDestroyWindow(dpy, Tmp_win->icon_w); + XDeleteContext( + dpy, Tmp_win->icon_w, FvwmContext); + if (Tmp_win->flags & ICON_OURS) { + if (Tmp_win->icon_pixmap_w != None) { + XDestroyWindow(dpy, + Tmp_win->icon_pixmap_w); + XDeleteContext(dpy, + Tmp_win->icon_pixmap_w, + FvwmContext); + } + } else + XUnmapWindow( + dpy, Tmp_win->icon_pixmap_w); + } + Tmp_win->icon_w = None; + Tmp_win->icon_pixmap_w = None; + Tmp_win->iconPixmap = (Window)NULL; + if (Tmp_win->flags & ICONIFIED) { + Tmp_win->flags &= ~ICONIFIED; + Tmp_win->flags &= ~ICON_UNMAPPED; + CreateIconWindow(Tmp_win, Tmp_win->icon_x_loc, + Tmp_win->icon_y_loc); + BroadcastPacket(M_ICONIFY, 7, Tmp_win->w, + Tmp_win->frame, (unsigned long)Tmp_win, + Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, + Tmp_win->icon_w_width, + Tmp_win->icon_w_height); + BroadcastConfig(M_CONFIGURE_WINDOW, Tmp_win); + + if (!(Tmp_win->flags & SUPPRESSICON)) { + LowerWindow(Tmp_win); + AutoPlace(Tmp_win); + if (Tmp_win->Desk == Scr.CurrentDesk) { + if (Tmp_win->icon_w) + XMapWindow(dpy, + Tmp_win->icon_w); + if (Tmp_win->icon_pixmap_w != + None) + XMapWindow(dpy, + Tmp_win + ->icon_pixmap_w); + } + } + Tmp_win->flags |= ICONIFIED; + DrawIconWindow(Tmp_win); + } } - else - XUnmapWindow(dpy,Tmp_win->icon_pixmap_w); - } - Tmp_win->icon_w = None; - Tmp_win->icon_pixmap_w = None; - Tmp_win->iconPixmap = (Window)NULL; - if(Tmp_win->flags & ICONIFIED) - { - Tmp_win->flags &= ~ICONIFIED; - Tmp_win->flags &= ~ICON_UNMAPPED; - CreateIconWindow(Tmp_win, - Tmp_win->icon_x_loc,Tmp_win->icon_y_loc); - BroadcastPacket(M_ICONIFY, 7, - Tmp_win->w, Tmp_win->frame, - (unsigned long)Tmp_win, - Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, - Tmp_win->icon_w_width, Tmp_win->icon_w_height); - BroadcastConfig(M_CONFIGURE_WINDOW, Tmp_win); - - if (!(Tmp_win->flags & SUPPRESSICON)) - { - LowerWindow(Tmp_win); - AutoPlace(Tmp_win); - if(Tmp_win->Desk == Scr.CurrentDesk) - { - if(Tmp_win->icon_w) - XMapWindow(dpy, Tmp_win->icon_w); - if(Tmp_win->icon_pixmap_w != None) - XMapWindow(dpy, Tmp_win->icon_pixmap_w); - } + break; + + case XA_WM_NORMAL_HINTS: + GetWindowSizeHints(Tmp_win); + BroadcastConfig(M_CONFIGURE_WINDOW, Tmp_win); + break; + + default: + if (Event.xproperty.atom == _XA_WM_PROTOCOLS) + FetchWmProtocols(Tmp_win); + else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) { + FetchWmColormapWindows(Tmp_win); /* frees old data */ + ReInstallActiveColormap(); + } else if (Event.xproperty.atom == _XA_WM_STATE) { + if ((Tmp_win != NULL) && + (Tmp_win->flags & ClickToFocus) && + (Tmp_win == Scr.Focus)) { + if (OnThisPage) { + Scr.Focus = NULL; + SetFocus(Tmp_win->w, Tmp_win, 0); + } + } } - Tmp_win->flags |= ICONIFIED; - DrawIconWindow(Tmp_win); - } - } - break; - - case XA_WM_NORMAL_HINTS: - GetWindowSizeHints (Tmp_win); -#if 0 - /* - ** ckh - not sure why this next stuff was here, but fvwm 1.xx - ** didn't do this, and it seems to cause a bug when changing - ** fonts in XTerm - */ - { - int new_width, new_height; - new_width = Tmp_win->frame_width; - new_height = Tmp_win->frame_height; - ConstrainSize(Tmp_win, &new_width, &new_height, False, 0, 0); - if((new_width != Tmp_win->frame_width)|| - (new_height != Tmp_win->frame_height)) - SetupFrame(Tmp_win,Tmp_win->frame_x, Tmp_win->frame_y, - new_width,new_height,False); - } -#endif /* 0 */ - BroadcastConfig(M_CONFIGURE_WINDOW,Tmp_win); - break; - - default: - if(Event.xproperty.atom == _XA_WM_PROTOCOLS) - FetchWmProtocols (Tmp_win); - else if (Event.xproperty.atom == _XA_WM_COLORMAP_WINDOWS) - { - FetchWmColormapWindows (Tmp_win); /* frees old data */ - ReInstallActiveColormap(); - } - else if(Event.xproperty.atom == _XA_WM_STATE) - { - if((Tmp_win != NULL)&&(Tmp_win->flags & ClickToFocus) - &&(Tmp_win == Scr.Focus)) - { - if (OnThisPage) - { - Scr.Focus = NULL; - SetFocus(Tmp_win->w,Tmp_win,0); - } - } + break; } - break; - } } - /*********************************************************************** * * Procedure: * HandleClientMessage - client message event handler * ************************************************************************/ -void HandleClientMessage() +void +HandleClientMessage() { - XEvent button; - - DBUG("HandleClientMessage","Routine Entered"); - - if ((Event.xclient.message_type == _XA_WM_CHANGE_STATE)&& - (Tmp_win)&&(Event.xclient.data.l[0]==IconicState)&& - !(Tmp_win->flags & ICONIFIED)) - { - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &(button.xmotion.x_root), - &(button.xmotion.y_root), - &JunkX, &JunkY, &JunkMask); - button.type = 0; - ExecuteFunction("Iconify",Tmp_win, &button,C_FRAME,-1); - return; - } - - /* - ** CKH - if we get here, it was an unknown client message, so send - ** it to the client if it was in a window we know about. I'm not so - ** sure this should be done or not, since every other window manager - ** I've looked at doesn't. But it might be handy for a free drag and - ** drop setup being developed for Linux. - */ - if (Tmp_win) - { - if(Event.xclient.window != Tmp_win->w) - { - Event.xclient.window = Tmp_win->w; - XSendEvent(dpy, Tmp_win->w, False, NoEventMask, &Event); - } - } + XEvent button; + + DBUG("HandleClientMessage", "Routine Entered"); + + if ((Event.xclient.message_type == _XA_WM_CHANGE_STATE) && (Tmp_win) && + (Event.xclient.data.l[0] == IconicState) && + !(Tmp_win->flags & ICONIFIED)) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, + &(button.xmotion.x_root), &(button.xmotion.y_root), &JunkX, + &JunkY, &JunkMask); + button.type = 0; + ExecuteFunction("Iconify", Tmp_win, &button, C_FRAME, -1); + return; + } + + /* + ** CKH - if we get here, it was an unknown client message, so send + ** it to the client if it was in a window we know about. I'm not so + ** sure this should be done or not, since every other window manager + ** I've looked at doesn't. But it might be handy for a free drag and + ** drop setup being developed for Linux. + */ + if (Tmp_win) { + if (Event.xclient.window != Tmp_win->w) { + Event.xclient.window = Tmp_win->w; + XSendEvent(dpy, Tmp_win->w, False, NoEventMask, &Event); + } + } } /*********************************************************************** @@ -678,259 +618,234 @@ void HandleClientMessage() * HandleExpose - expose event handler * ***********************************************************************/ -void HandleExpose() +void +HandleExpose() { - if (Event.xexpose.count != 0) - return; + if (Event.xexpose.count != 0) + return; - DBUG("HandleExpose","Routine Entered"); + DBUG("HandleExpose", "Routine Entered"); - if (Tmp_win) - { - if (Event.xany.window == Tmp_win->title_w) - { - SetTitleBar(Tmp_win,(Scr.Hilite == Tmp_win),False); - } - else - { - SetBorder(Tmp_win,(Scr.Hilite == Tmp_win),True,True, - Event.xany.window); + if (Tmp_win) { + if (Event.xany.window == Tmp_win->title_w) { + SetTitleBar(Tmp_win, (Scr.Hilite == Tmp_win), False); + } else { + SetBorder(Tmp_win, (Scr.Hilite == Tmp_win), True, True, + Event.xany.window); + } } - } - return; + return; } - - /*********************************************************************** * * Procedure: * HandleDestroyNotify - DestroyNotify event handler * ***********************************************************************/ -void HandleDestroyNotify() +void +HandleDestroyNotify() { - DBUG("HandleDestroyNotify","Routine Entered"); + DBUG("HandleDestroyNotify", "Routine Entered"); - Destroy(Tmp_win); + Destroy(Tmp_win); } - - - /*********************************************************************** * * Procedure: * HandleMapRequest - MapRequest event handler * ************************************************************************/ -void HandleMapRequest() +void +HandleMapRequest() { - DBUG("HandleMapRequest","Routine Entered"); + DBUG("HandleMapRequest", "Routine Entered"); - HandleMapRequestKeepRaised(None); + HandleMapRequestKeepRaised(None); } -void HandleMapRequestKeepRaised(Window KeepRaised) + +void +HandleMapRequestKeepRaised(Window KeepRaised) { - extern long isIconicState; - extern Boolean PPosOverride; - Boolean OnThisPage = False; + extern long isIconicState; + extern Boolean PPosOverride; + Boolean OnThisPage = False; - Event.xany.window = Event.xmaprequest.window; + Event.xany.window = Event.xmaprequest.window; - if(XFindContext(dpy, Event.xany.window, FvwmContext, - (caddr_t *)&Tmp_win)==XCNOENT) - Tmp_win = NULL; + if (XFindContext(dpy, Event.xany.window, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; - if(!PPosOverride) - XFlush(dpy); + if (!PPosOverride) + XFlush(dpy); - /* If the window has never been mapped before ... */ - if(!Tmp_win) - { - /* Add decorations. */ - Tmp_win = AddWindow(Event.xany.window); - if (Tmp_win == NULL) - return; - } - /* - Make sure at least part of window is on this page - before giving it focus... - */ - if ( (Tmp_win->Desk == Scr.CurrentDesk) && - ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && - Tmp_win->frame_x < Scr.MyDisplayWidth) && - ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && - Tmp_win->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - - if(KeepRaised != None) - XRaiseWindow(dpy,KeepRaised); - /* If it's not merely iconified, and we have hints, use them. */ - if (!(Tmp_win->flags & ICONIFIED)) - { - int state; - - if(Tmp_win->wmhints && (Tmp_win->wmhints->flags & StateHint)) - state = Tmp_win->wmhints->initial_state; - else - state = NormalState; - - if(Tmp_win->flags & STARTICONIC) - state = IconicState; - - if(isIconicState != DontCareState) - state = isIconicState; - - MyXGrabServer(dpy); - switch (state) - { - case DontCareState: - case NormalState: - case InactiveState: - default: - if (Tmp_win->Desk == Scr.CurrentDesk) - { - XMapWindow(dpy, Tmp_win->w); - XMapWindow(dpy, Tmp_win->frame); - Tmp_win->flags |= MAP_PENDING; - SetMapStateProp(Tmp_win, NormalState); - if((Tmp_win->flags & ClickToFocus)&& - ((!Scr.Focus)||(Scr.Focus->flags & ClickToFocus))) - { - if (OnThisPage) - { - SetFocus(Tmp_win->w,Tmp_win,1); - } + /* If the window has never been mapped before ... */ + if (!Tmp_win) { + /* Add decorations. */ + Tmp_win = AddWindow(Event.xany.window); + if (Tmp_win == NULL) + return; + } + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Tmp_win->Desk == Scr.CurrentDesk) && + (((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && + Tmp_win->frame_x < Scr.MyDisplayWidth) && + ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && + Tmp_win->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } + + if (KeepRaised != None) + XRaiseWindow(dpy, KeepRaised); + /* If it's not merely iconified, and we have hints, use them. */ + if (!(Tmp_win->flags & ICONIFIED)) { + int state; + + if (Tmp_win->wmhints && (Tmp_win->wmhints->flags & StateHint)) + state = Tmp_win->wmhints->initial_state; + else + state = NormalState; + + if (Tmp_win->flags & STARTICONIC) + state = IconicState; + + if (isIconicState != DontCareState) + state = isIconicState; + + MyXGrabServer(dpy); + switch (state) { + case DontCareState: + case NormalState: + case InactiveState: + default: + if (Tmp_win->Desk == Scr.CurrentDesk) { + XMapWindow(dpy, Tmp_win->w); + XMapWindow(dpy, Tmp_win->frame); + Tmp_win->flags |= MAP_PENDING; + SetMapStateProp(Tmp_win, NormalState); + if ((Tmp_win->flags & ClickToFocus) && + ((!Scr.Focus) || + (Scr.Focus->flags & ClickToFocus))) { + if (OnThisPage) { + SetFocus( + Tmp_win->w, Tmp_win, 1); + } + } + } else { + XMapWindow(dpy, Tmp_win->w); + SetMapStateProp(Tmp_win, NormalState); + } + break; + + case IconicState: + if (Tmp_win->wmhints) { + Iconify(Tmp_win, Tmp_win->wmhints->icon_x, + Tmp_win->wmhints->icon_y); + } else { + Iconify(Tmp_win, 0, 0); + } + break; } - } - else - { - XMapWindow(dpy, Tmp_win->w); - SetMapStateProp(Tmp_win, NormalState); - } - break; - - case IconicState: - if (Tmp_win->wmhints) - { - Iconify(Tmp_win, - Tmp_win->wmhints->icon_x, Tmp_win->wmhints->icon_y); - } - else - { - Iconify(Tmp_win, 0, 0); - } - break; + if (!PPosOverride) + XSync(dpy, 0); + MyXUngrabServer(dpy); } - if(!PPosOverride) - XSync(dpy,0); - MyXUngrabServer(dpy); - } - /* If no hints, or currently an icon, just "deiconify" */ - else - { - DeIconify(Tmp_win); - } - if(!PPosOverride) - KeepOnTop(); + /* If no hints, or currently an icon, just "deiconify" */ + else { + DeIconify(Tmp_win); + } + if (!PPosOverride) + KeepOnTop(); } - /*********************************************************************** * * Procedure: * HandleMapNotify - MapNotify event handler * ***********************************************************************/ -void HandleMapNotify() +void +HandleMapNotify() { - Boolean OnThisPage = False; + Boolean OnThisPage = False; - DBUG("HandleMapNotify","Routine Entered"); + DBUG("HandleMapNotify", "Routine Entered"); - if (!Tmp_win) - { - if((Event.xmap.override_redirect == True)&& - (Event.xmap.window != Scr.NoFocusWin)) - { - XSelectInput(dpy,Event.xmap.window,FocusChangeMask); - Scr.UnknownWinFocused = Event.xmap.window; + if (!Tmp_win) { + if ((Event.xmap.override_redirect == True) && + (Event.xmap.window != Scr.NoFocusWin)) { + XSelectInput(dpy, Event.xmap.window, FocusChangeMask); + Scr.UnknownWinFocused = Event.xmap.window; + } + return; + } + + /* Except for identifying over-ride redirect window mappings, we + * don't need or want windows associated with the sunstructurenotifymask + */ + if (Event.xmap.event != Event.xmap.window) + return; + + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Tmp_win->Desk == Scr.CurrentDesk) && + (((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && + Tmp_win->frame_x < Scr.MyDisplayWidth) && + ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && + Tmp_win->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } + + /* + * Need to do the grab to avoid race condition of having server send + * MapNotify to client before the frame gets mapped; this is bad because + * the client would think that the window has a chance of being viewable + * when it really isn't. + */ + MyXGrabServer(dpy); + if (Tmp_win->icon_w) + XUnmapWindow(dpy, Tmp_win->icon_w); + if (Tmp_win->icon_pixmap_w != None) + XUnmapWindow(dpy, Tmp_win->icon_pixmap_w); + XMapSubwindows(dpy, Tmp_win->frame); + + if (Tmp_win->Desk == Scr.CurrentDesk) { + XMapWindow(dpy, Tmp_win->frame); } - return; - } - - /* Except for identifying over-ride redirect window mappings, we - * don't need or want windows associated with the sunstructurenotifymask */ - if(Event.xmap.event != Event.xmap.window) - return; - - /* - Make sure at least part of window is on this page - before giving it focus... - */ - if ( (Tmp_win->Desk == Scr.CurrentDesk) && - ( ((Tmp_win->frame_x + Tmp_win->frame_width) >= 0 && - Tmp_win->frame_x < Scr.MyDisplayWidth) && - ((Tmp_win->frame_y + Tmp_win->frame_height) >= 0 && - Tmp_win->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - - /* - * Need to do the grab to avoid race condition of having server send - * MapNotify to client before the frame gets mapped; this is bad because - * the client would think that the window has a chance of being viewable - * when it really isn't. - */ - MyXGrabServer (dpy); - if (Tmp_win->icon_w) - XUnmapWindow(dpy, Tmp_win->icon_w); - if(Tmp_win->icon_pixmap_w != None) - XUnmapWindow(dpy, Tmp_win->icon_pixmap_w); - XMapSubwindows(dpy, Tmp_win->frame); - - if(Tmp_win->Desk == Scr.CurrentDesk) - { - XMapWindow(dpy, Tmp_win->frame); - } - - if(Tmp_win->flags & ICONIFIED) - BroadcastPacket(M_DEICONIFY, 3, - Tmp_win->w, Tmp_win->frame, (unsigned long)Tmp_win); - else - BroadcastPacket(M_MAP, 3, - Tmp_win->w,Tmp_win->frame, (unsigned long)Tmp_win); - - if((Tmp_win->flags & ClickToFocus)&& - ((!Scr.Focus)||(Scr.Focus->flags & ClickToFocus))) - { - if (OnThisPage) - { - SetFocus(Tmp_win->w,Tmp_win,1); - } - } - if((!(Tmp_win->flags &(BORDER|TITLE)))&&(Tmp_win->boundary_width <2)) - { - SetBorder(Tmp_win,False,True,True,Tmp_win->frame); - } - XSync(dpy,0); - MyXUngrabServer (dpy); - XFlush (dpy); - Tmp_win->flags |= MAPPED; - Tmp_win->flags &= ~MAP_PENDING; - Tmp_win->flags &= ~ICONIFIED; - Tmp_win->flags &= ~ICON_UNMAPPED; - KeepOnTop(); -} + if (Tmp_win->flags & ICONIFIED) + BroadcastPacket(M_DEICONIFY, 3, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win); + else + BroadcastPacket(M_MAP, 3, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win); + + if ((Tmp_win->flags & ClickToFocus) && + ((!Scr.Focus) || (Scr.Focus->flags & ClickToFocus))) { + if (OnThisPage) { + SetFocus(Tmp_win->w, Tmp_win, 1); + } + } + if ((!(Tmp_win->flags & (BORDER | TITLE))) && + (Tmp_win->boundary_width < 2)) { + SetBorder(Tmp_win, False, True, True, Tmp_win->frame); + } + XSync(dpy, 0); + MyXUngrabServer(dpy); + XFlush(dpy); + Tmp_win->flags |= MAPPED; + Tmp_win->flags &= ~MAP_PENDING; + Tmp_win->flags &= ~ICONIFIED; + Tmp_win->flags &= ~ICON_UNMAPPED; + KeepOnTop(); +} /*********************************************************************** * @@ -938,135 +853,129 @@ void HandleMapNotify() * HandleUnmapNotify - UnmapNotify event handler * ************************************************************************/ -void HandleUnmapNotify() +void +HandleUnmapNotify() { - int dstx, dsty; - Window dumwin; - XEvent dummy; - extern FvwmWindow *colormap_win; - int weMustUnmap; - - DBUG("HandleUnmapNotify","Routine Entered"); - - /* - * Don't ignore events as described below. - */ - if((Event.xunmap.event != Event.xunmap.window) && - (Event.xunmap.event != Scr.Root || !Event.xunmap.send_event)) - { - return; - } - - /* - * The July 27, 1988 ICCCM spec states that a client wishing to switch - * to WithdrawnState should send a synthetic UnmapNotify with the - * event field set to (pseudo-)root, in case the window is already - * unmapped (which is the case for fvwm for IconicState). Unfortunately, - * we looked for the FvwmContext using that field, so try the window - * field also. - */ - weMustUnmap = 0; - if (!Tmp_win) - { - Event.xany.window = Event.xunmap.window; - weMustUnmap = 1; - if (XFindContext(dpy, Event.xany.window, - FvwmContext, (caddr_t *)&Tmp_win) == XCNOENT) - Tmp_win = NULL; - } - - if(!Tmp_win) - return; - - if(weMustUnmap) - XUnmapWindow(dpy, Event.xunmap.window); - - if(Tmp_win == Scr.Hilite) - Scr.Hilite = NULL; - - if(Scr.PreviousFocus == Tmp_win) - Scr.PreviousFocus = NULL; - - if((Tmp_win == Scr.Focus)&&(Tmp_win->flags & ClickToFocus)) - { - if(Tmp_win->next) - { - HandleHardFocus(Tmp_win->next); + int dstx, dsty; + Window dumwin; + XEvent dummy; + extern FvwmWindow *colormap_win; + int weMustUnmap; + + DBUG("HandleUnmapNotify", "Routine Entered"); + + /* + * Don't ignore events as described below. + */ + if ((Event.xunmap.event != Event.xunmap.window) && + (Event.xunmap.event != Scr.Root || !Event.xunmap.send_event)) { + return; } - else - SetFocus(Scr.NoFocusWin,NULL,1); - } - - if(Scr.Focus == Tmp_win) - SetFocus(Scr.NoFocusWin,NULL,1); - - if(Tmp_win == Scr.pushed_window) - Scr.pushed_window = NULL; - - if(Tmp_win == colormap_win) - colormap_win = NULL; - - if ((!(Tmp_win->flags & MAPPED)&&!(Tmp_win->flags&ICONIFIED))) - { - return; - } - - MyXGrabServer(dpy); - - if(XCheckTypedWindowEvent (dpy, Event.xunmap.window, DestroyNotify,&dummy)) - { - Destroy(Tmp_win); - MyXUngrabServer (dpy); - return; - } - - /* - * The program may have unmapped the client window, from either - * NormalState or IconicState. Handle the transition to WithdrawnState. - * - * We need to reparent the window back to the root (so that fvwm exiting - * won't cause it to get mapped) and then throw away all state (pretend - * that we've received a DestroyNotify). - */ - if (XTranslateCoordinates (dpy, Event.xunmap.window, Scr.Root, - 0, 0, &dstx, &dsty, &dumwin)) - { - XEvent ev; - Bool reparented; - - reparented = XCheckTypedWindowEvent (dpy, Event.xunmap.window, - ReparentNotify, &ev); - SetMapStateProp (Tmp_win, WithdrawnState); - if (reparented) - { - if (Tmp_win->old_bw) - XSetWindowBorderWidth (dpy, Event.xunmap.window, Tmp_win->old_bw); - if((!(Tmp_win->flags & SUPPRESSICON))&& - (Tmp_win->wmhints && (Tmp_win->wmhints->flags & IconWindowHint))) - XUnmapWindow (dpy, Tmp_win->wmhints->icon_window); + + /* + * The July 27, 1988 ICCCM spec states that a client wishing to switch + * to WithdrawnState should send a synthetic UnmapNotify with the + * event field set to (pseudo-)root, in case the window is already + * unmapped (which is the case for fvwm for IconicState). Unfortunately, + * we looked for the FvwmContext using that field, so try the window + * field also. + */ + weMustUnmap = 0; + if (!Tmp_win) { + Event.xany.window = Event.xunmap.window; + weMustUnmap = 1; + if (XFindContext(dpy, Event.xany.window, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; } - else - { - RestoreWithdrawnLocation (Tmp_win,False); + + if (!Tmp_win) + return; + + if (weMustUnmap) + XUnmapWindow(dpy, Event.xunmap.window); + + if (Tmp_win == Scr.Hilite) + Scr.Hilite = NULL; + + if (Scr.PreviousFocus == Tmp_win) + Scr.PreviousFocus = NULL; + + if ((Tmp_win == Scr.Focus) && (Tmp_win->flags & ClickToFocus)) { + if (Tmp_win->next) { + HandleHardFocus(Tmp_win->next); + } else + SetFocus(Scr.NoFocusWin, NULL, 1); + } + + if (Scr.Focus == Tmp_win) + SetFocus(Scr.NoFocusWin, NULL, 1); + + if (Tmp_win == Scr.pushed_window) + Scr.pushed_window = NULL; + + if (Tmp_win == colormap_win) + colormap_win = NULL; + + if ((!(Tmp_win->flags & MAPPED) && !(Tmp_win->flags & ICONIFIED))) { + return; } - XRemoveFromSaveSet (dpy, Event.xunmap.window); - XSelectInput (dpy, Event.xunmap.window, NoEventMask); - Destroy(Tmp_win); /* do not need to mash event before */ - /* - * Flush any pending events for the window. - */ - /* Bzzt! it could be about to re-map */ -/* while(XCheckWindowEvent(dpy, Event.xunmap.window, - StructureNotifyMask | PropertyChangeMask | - ColormapChangeMask | VisibilityChangeMask | - EnterWindowMask | LeaveWindowMask, &dummy)); - */ - } /* else window no longer exists and we'll get a destroy notify */ - MyXUngrabServer(dpy); - - XFlush (dpy); -} + MyXGrabServer(dpy); + + if (XCheckTypedWindowEvent( + dpy, Event.xunmap.window, DestroyNotify, &dummy)) { + Destroy(Tmp_win); + MyXUngrabServer(dpy); + return; + } + + /* + * The program may have unmapped the client window, from either + * NormalState or IconicState. Handle the transition to WithdrawnState. + * + * We need to reparent the window back to the root (so that fvwm exiting + * won't cause it to get mapped) and then throw away all state (pretend + * that we've received a DestroyNotify). + */ + if (XTranslateCoordinates(dpy, Event.xunmap.window, Scr.Root, 0, 0, + &dstx, &dsty, &dumwin)) { + XEvent ev; + Bool reparented; + + reparented = XCheckTypedWindowEvent( + dpy, Event.xunmap.window, ReparentNotify, &ev); + SetMapStateProp(Tmp_win, WithdrawnState); + if (reparented) { + if (Tmp_win->old_bw) + XSetWindowBorderWidth( + dpy, Event.xunmap.window, Tmp_win->old_bw); + if ((!(Tmp_win->flags & SUPPRESSICON)) && + (Tmp_win->wmhints && + (Tmp_win->wmhints->flags & IconWindowHint))) + XUnmapWindow( + dpy, Tmp_win->wmhints->icon_window); + } else { + RestoreWithdrawnLocation(Tmp_win, False); + } + XRemoveFromSaveSet(dpy, Event.xunmap.window); + XSelectInput(dpy, Event.xunmap.window, NoEventMask); + Destroy(Tmp_win); /* do not need to mash event before */ + /* + * Flush any pending events for the window. + */ + /* Bzzt! it could be about to re-map */ + /* while(XCheckWindowEvent(dpy, Event.xunmap.window, + StructureNotifyMask | + PropertyChangeMask | ColormapChangeMask | + VisibilityChangeMask | EnterWindowMask | LeaveWindowMask, + &dummy)); + */ + } /* else window no longer exists and we'll get a destroy notify */ + MyXUngrabServer(dpy); + + XFlush(dpy); +} /*********************************************************************** * @@ -1074,105 +983,103 @@ void HandleUnmapNotify() * HandleButtonPress - ButtonPress event handler * ***********************************************************************/ -void HandleButtonPress() +void +HandleButtonPress() { - unsigned int modifier; - Binding *MouseEntry; - Window x; - int LocalContext; - - DBUG("HandleButtonPress","Routine Entered"); - - /* click to focus stuff goes here */ - if((Tmp_win)&&(Tmp_win->flags & ClickToFocus)&&(Tmp_win != Scr.Ungrabbed) && - ((Event.xbutton.state& - (ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0)) - { - SetFocus(Tmp_win->w,Tmp_win,1); -/* #ifdef CLICKY_MODE_1 */ - if (Scr.ClickToFocusRaises || - ((Event.xany.window != Tmp_win->w)&& - (Event.xbutton.subwindow != Tmp_win->w)&& - (Event.xany.window != Tmp_win->Parent)&& - (Event.xbutton.subwindow != Tmp_win->Parent))) -/* #endif */ - { - RaiseWindow(Tmp_win); - } - - KeepOnTop(); - /* Why is this here? Seems to cause breakage with - * non-focusing windows! */ - if(!(Tmp_win->flags & ICONIFIED)) - { - XSync(dpy,0); - /* pass click event to just clicked to focus window? */ - if (Scr.ClickToFocusPassesClick) - XAllowEvents(dpy,ReplayPointer,CurrentTime); - else /* don't pass click to just focused window */ - XAllowEvents(dpy,AsyncPointer,CurrentTime); - XSync(dpy,0); - return; - } - } - else if ((Tmp_win) && !(Tmp_win->flags & ClickToFocus) && - (Event.xbutton.window == Tmp_win->frame) && - Scr.MouseFocusClickRaises) - { - if (Tmp_win != Scr.LastWindowRaised && - (Event.xbutton.state & - (ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) == 0 && - GetContext(Tmp_win,&Event, &PressedW) == C_WINDOW) - { - RaiseWindow(Tmp_win); - KeepOnTop(); - } - XSync(dpy,0); - XAllowEvents(dpy,ReplayPointer,CurrentTime); - XSync(dpy,0); - return; - } - - XSync(dpy,0); - XAllowEvents(dpy,ReplayPointer,CurrentTime); - XSync(dpy,0); - - Context = GetContext(Tmp_win,&Event, &PressedW); - LocalContext = Context; - x= PressedW; - if(Context == C_TITLE) - SetTitleBar(Tmp_win,(Scr.Hilite == Tmp_win),False); - else - SetBorder(Tmp_win,(Scr.Hilite == Tmp_win),True,True,PressedW); - - ButtonWindow = Tmp_win; - - /* we have to execute a function or pop up a menu - */ - - modifier = (Event.xbutton.state & mods_used); - /* need to search for an appropriate mouse binding */ - for (MouseEntry = Scr.AllBindings; MouseEntry != NULL; - MouseEntry= MouseEntry->NextBinding) - { - if(((MouseEntry->Button_Key == Event.xbutton.button)|| - (MouseEntry->Button_Key == 0))&& - (MouseEntry->Context & Context)&& - ((MouseEntry->Modifier == AnyModifier)|| - (MouseEntry->Modifier == (modifier& (~LockMask))))&& - (MouseEntry->IsMouse == 1)) - { - /* got a match, now process it */ - ExecuteFunction(MouseEntry->Action,Tmp_win, &Event,Context,-1); - break; - } - } - PressedW = None; - if(LocalContext!=C_TITLE) - SetBorder(ButtonWindow,(Scr.Hilite == ButtonWindow),True,True,x); - else - SetTitleBar(ButtonWindow,(Scr.Hilite==ButtonWindow),False); - ButtonWindow = NULL; + unsigned int modifier; + Binding *MouseEntry; + Window x; + int LocalContext; + + DBUG("HandleButtonPress", "Routine Entered"); + + /* click to focus stuff goes here */ + if ((Tmp_win) && (Tmp_win->flags & ClickToFocus) && + (Tmp_win != Scr.Ungrabbed) && + ((Event.xbutton.state & (ControlMask | Mod1Mask | Mod2Mask | + Mod3Mask | Mod4Mask | Mod5Mask)) == + 0)) { + SetFocus(Tmp_win->w, Tmp_win, 1); + /* CLICKY_MODE_1: raise window on click */ + if (Scr.ClickToFocusRaises || + ((Event.xany.window != Tmp_win->w) && + (Event.xbutton.subwindow != Tmp_win->w) && + (Event.xany.window != Tmp_win->Parent) && + (Event.xbutton.subwindow != Tmp_win->Parent))) { + RaiseWindow(Tmp_win); + } + + KeepOnTop(); + /* Why is this here? Seems to cause breakage with + * non-focusing windows! */ + if (!(Tmp_win->flags & ICONIFIED)) { + XSync(dpy, 0); + /* pass click event to just clicked to focus window? */ + if (Scr.ClickToFocusPassesClick) + XAllowEvents(dpy, ReplayPointer, CurrentTime); + else /* don't pass click to just focused window */ + XAllowEvents(dpy, AsyncPointer, CurrentTime); + XSync(dpy, 0); + return; + } + } else if ((Tmp_win) && !(Tmp_win->flags & ClickToFocus) && + (Event.xbutton.window == Tmp_win->frame) && + Scr.MouseFocusClickRaises) { + if (Tmp_win != Scr.LastWindowRaised && + (Event.xbutton.state & + (ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | + Mod4Mask | Mod5Mask)) == 0 && + GetContext(Tmp_win, &Event, &PressedW) == C_WINDOW) { + RaiseWindow(Tmp_win); + KeepOnTop(); + } + XSync(dpy, 0); + XAllowEvents(dpy, ReplayPointer, CurrentTime); + XSync(dpy, 0); + return; + } + + XSync(dpy, 0); + XAllowEvents(dpy, ReplayPointer, CurrentTime); + XSync(dpy, 0); + + Context = GetContext(Tmp_win, &Event, &PressedW); + LocalContext = Context; + x = PressedW; + if (Context == C_TITLE) + SetTitleBar(Tmp_win, (Scr.Hilite == Tmp_win), False); + else + SetBorder( + Tmp_win, (Scr.Hilite == Tmp_win), True, True, PressedW); + + ButtonWindow = Tmp_win; + + /* we have to execute a function or pop up a menu + */ + + modifier = (Event.xbutton.state & mods_used); + /* need to search for an appropriate mouse binding */ + for (MouseEntry = Scr.AllBindings; MouseEntry != NULL; + MouseEntry = MouseEntry->NextBinding) { + if (((MouseEntry->Button_Key == Event.xbutton.button) || + (MouseEntry->Button_Key == 0)) && + (MouseEntry->Context & Context) && + ((MouseEntry->Modifier == AnyModifier) || + (MouseEntry->Modifier == (modifier & (~LockMask)))) && + (MouseEntry->IsMouse == 1)) { + /* got a match, now process it */ + ExecuteFunction( + MouseEntry->Action, Tmp_win, &Event, Context, -1); + break; + } + } + PressedW = None; + if (LocalContext != C_TITLE) + SetBorder( + ButtonWindow, (Scr.Hilite == ButtonWindow), True, True, x); + else + SetTitleBar(ButtonWindow, (Scr.Hilite == ButtonWindow), False); + ButtonWindow = NULL; } /*********************************************************************** @@ -1181,78 +1088,72 @@ void HandleButtonPress() * HandleEnterNotify - EnterNotify event handler * ************************************************************************/ -void HandleEnterNotify() +void +HandleEnterNotify() { - XEnterWindowEvent *ewp = &Event.xcrossing; - XEvent d; - - DBUG("HandleEnterNotify","Routine Entered"); - - /* look for a matching leaveNotify which would nullify this enterNotify */ - if(XCheckTypedWindowEvent (dpy, ewp->window, LeaveNotify, &d)) - { - /* - RBW - if we're in startup, this is a coerced focus, so we don't - want to save the event time, or exit prematurely. - */ - if (! fFvwmInStartup) - { - StashEventTime(&d); - if((d.xcrossing.mode==NotifyNormal)&& - (d.xcrossing.detail!=NotifyInferior)) - return; - } - } + XEnterWindowEvent *ewp = &Event.xcrossing; + XEvent d; + + DBUG("HandleEnterNotify", "Routine Entered"); + + /* look for a matching leaveNotify which would nullify this enterNotify + */ + if (XCheckTypedWindowEvent(dpy, ewp->window, LeaveNotify, &d)) { + /* + RBW - if we're in startup, this is a coerced focus, so we + don't want to save the event time, or exit prematurely. + */ + if (!fFvwmInStartup) { + StashEventTime(&d); + if ((d.xcrossing.mode == NotifyNormal) && + (d.xcrossing.detail != NotifyInferior)) + return; + } + } /* an EnterEvent in one of the PanFrameWindows activates the Paging */ #ifndef NON_VIRTUAL - if (ewp->window==Scr.PanFrameTop.win - || ewp->window==Scr.PanFrameLeft.win - || ewp->window==Scr.PanFrameRight.win - || ewp->window==Scr.PanFrameBottom.win ) - { - int delta_x=0, delta_y=0; - /* this was in the HandleMotionNotify before, HEDU */ - HandlePaging(Scr.EdgeScrollX,Scr.EdgeScrollY, - &Event.xcrossing.x_root,&Event.xcrossing.y_root, - &delta_x,&delta_y,True); - return; - } + if (ewp->window == Scr.PanFrameTop.win || + ewp->window == Scr.PanFrameLeft.win || + ewp->window == Scr.PanFrameRight.win || + ewp->window == Scr.PanFrameBottom.win) { + int delta_x = 0, delta_y = 0; + /* this was in the HandleMotionNotify before, HEDU */ + HandlePaging(Scr.EdgeScrollX, Scr.EdgeScrollY, + &Event.xcrossing.x_root, &Event.xcrossing.y_root, &delta_x, + &delta_y, True); + return; + } #endif /* NON_VIRTUAL */ - /* multi screen? */ - if (Event.xany.window == Scr.Root) - { - if (!Scr.Focus || (!(Scr.Focus->flags&ClickToFocus)&& - !(Scr.Focus->flags&SloppyFocus))) - { - SetFocus(Scr.NoFocusWin,NULL,1); - } - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) - { - InstallWindowColormaps(NULL); - } - return; - } - - /* make sure its for one of our windows */ - if (!Tmp_win) - return; - - if(!(Tmp_win->flags & ClickToFocus)) - { - SetFocus(Tmp_win->w,Tmp_win,1); - } - if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) - { - if((!(Tmp_win->flags & ICONIFIED))&&(Event.xany.window == Tmp_win->w)) - InstallWindowColormaps(Tmp_win); - else - InstallWindowColormaps(NULL); - } - return; -} + /* multi screen? */ + if (Event.xany.window == Scr.Root) { + if (!Scr.Focus || (!(Scr.Focus->flags & ClickToFocus) && + !(Scr.Focus->flags & SloppyFocus))) { + SetFocus(Scr.NoFocusWin, NULL, 1); + } + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) { + InstallWindowColormaps(NULL); + } + return; + } + + /* make sure its for one of our windows */ + if (!Tmp_win) + return; + if (!(Tmp_win->flags & ClickToFocus)) { + SetFocus(Tmp_win->w, Tmp_win, 1); + } + if (Scr.ColormapFocus == COLORMAP_FOLLOWS_MOUSE) { + if ((!(Tmp_win->flags & ICONIFIED)) && + (Event.xany.window == Tmp_win->w)) + InstallWindowColormaps(Tmp_win); + else + InstallWindowColormaps(NULL); + } + return; +} /*********************************************************************** * @@ -1260,212 +1161,215 @@ void HandleEnterNotify() * HandleLeaveNotify - LeaveNotify event handler * ************************************************************************/ -void HandleLeaveNotify() +void +HandleLeaveNotify() { - DBUG("HandleLeaveNotify","Routine Entered"); - - /* If we leave the root window, then we're really moving - * another screen on a multiple screen display, and we - * need to de-focus and unhighlight to make sure that we - * don't end up with more than one highlighted window at a time */ - if(Event.xcrossing.window == Scr.Root) - { - if(Event.xcrossing.mode == NotifyNormal) - { - if (Event.xcrossing.detail != NotifyInferior) - { - if(Scr.Focus != NULL) - { - SetFocus(Scr.NoFocusWin,NULL,1); + DBUG("HandleLeaveNotify", "Routine Entered"); + + /* If we leave the root window, then we're really moving + * another screen on a multiple screen display, and we + * need to de-focus and unhighlight to make sure that we + * don't end up with more than one highlighted window at a time */ + if (Event.xcrossing.window == Scr.Root) { + if (Event.xcrossing.mode == NotifyNormal) { + if (Event.xcrossing.detail != NotifyInferior) { + if (Scr.Focus != NULL) { + SetFocus(Scr.NoFocusWin, NULL, 1); + } + if (Scr.Hilite != NULL) + SetBorder(Scr.Hilite, False, True, True, + None); + } } - if(Scr.Hilite != NULL) - SetBorder(Scr.Hilite,False,True,True,None); - } } - } } - /*********************************************************************** * * Procedure: * HandleConfigureRequest - ConfigureRequest event handler * ************************************************************************/ -void HandleConfigureRequest() +void +HandleConfigureRequest() { - XWindowChanges xwc; - unsigned long xwcm; - int x, y, width, height; - XConfigureRequestEvent *cre = &Event.xconfigurerequest; - Bool sendEvent=False; - FvwmWindow *FvwmSib; - - DBUG("HandleConfigureRequest","Routine Entered"); - - /* - * Event.xany.window is Event.xconfigurerequest.parent, so Tmp_win will - * be wrong - */ - Event.xany.window = cre->window; /* mash parent field */ - if (XFindContext (dpy, cre->window, FvwmContext, (caddr_t *) &Tmp_win) == - XCNOENT) - Tmp_win = NULL; - - /* - * According to the July 27, 1988 ICCCM draft, we should ignore size and - * position fields in the WM_NORMAL_HINTS property when we map a window. - * Instead, we'll read the current geometry. Therefore, we should respond - * to configuration requests for windows which have never been mapped. - */ - if (!Tmp_win || cre->window == Tmp_win->icon_w || - cre->window == Tmp_win->icon_pixmap_w) - { - - xwcm = cre->value_mask & - (CWX | CWY | CWWidth | CWHeight | CWBorderWidth); - xwc.x = cre->x; - xwc.y = cre->y; - if((Tmp_win)&&((Tmp_win->icon_pixmap_w == cre->window))) - { - Tmp_win->icon_p_height = cre->height+ cre->border_width + - cre->border_width; - } - else if((Tmp_win)&&((Tmp_win->icon_w == cre->window))) - { - Tmp_win->icon_xl_loc = cre->x; - Tmp_win->icon_x_loc = cre->x + - (Tmp_win->icon_w_width - Tmp_win->icon_p_width)/2; - Tmp_win->icon_y_loc = cre->y - Tmp_win->icon_p_height; - if(!(Tmp_win->flags & ICON_UNMAPPED)) - BroadcastPacket(M_ICON_LOCATION, 7, - Tmp_win->w, Tmp_win->frame, - (unsigned long)Tmp_win, - Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, - Tmp_win->icon_w_width, - Tmp_win->icon_w_height + Tmp_win->icon_p_height); - } - xwc.width = cre->width; - xwc.height = cre->height; - xwc.border_width = cre->border_width; - - XConfigureWindow(dpy, Event.xany.window, xwcm, &xwc); - - if(Tmp_win) - { - if (cre->window != Tmp_win->icon_pixmap_w && - Tmp_win->icon_pixmap_w != None) - { - xwc.x = Tmp_win->icon_x_loc; - xwc.y = Tmp_win->icon_y_loc - Tmp_win->icon_p_height; - xwcm = cre->value_mask & (CWX | CWY); - XConfigureWindow(dpy, Tmp_win->icon_pixmap_w, xwcm, &xwc); - } - if(Tmp_win->icon_w != None) - { - xwc.x = Tmp_win->icon_x_loc; - xwc.y = Tmp_win->icon_y_loc; - xwcm = cre->value_mask & (CWX | CWY); - XConfigureWindow(dpy, Tmp_win->icon_w, xwcm, &xwc); - } - } - return; - } - - /* Stacking order change requested... */ - if (cre->value_mask & CWStackMode) - { - FvwmWindow *otherwin; - - otherwin = NULL; - xwc.sibling = (((cre->value_mask & CWSibling) && - (XFindContext (dpy, cre->above, FvwmContext, - (caddr_t *) &otherwin) == XCSUCCESS)) - ? otherwin->frame : cre->above); - xwc.stack_mode = cre->detail; - XConfigureWindow (dpy, Tmp_win->frame, - cre->value_mask & (CWSibling | CWStackMode), &xwc); - sendEvent = True; - - /* - RBW - Update the stacking order ring. - */ - if (xwc.stack_mode == Above || xwc.stack_mode == Below) - { - FvwmSib = (otherwin != NULL ) ? otherwin: Scr.FvwmRoot.stack_next; /* Set up for Above. */ - if (xwc.stack_mode == Below) - { - /* - If Below-sibling, raise above next lower window. If no sibling, - bottom of stack is "above" Scr.FvwmRoot in the ring. - */ - FvwmSib = (FvwmSib == otherwin) ? FvwmSib->stack_next: FvwmSib->stack_prev; - } - if (Tmp_win != FvwmSib) /* Don't chain it to itself! */ - { - Tmp_win->stack_prev->stack_next = Tmp_win->stack_next; /* Pluck from chain. */ - Tmp_win->stack_next->stack_prev = Tmp_win->stack_prev; - Tmp_win->stack_next = FvwmSib; /* Set new pointers. */ - Tmp_win->stack_prev = FvwmSib->stack_prev; - FvwmSib->stack_prev->stack_next = Tmp_win; /* Re-insert above sibling. */ - FvwmSib->stack_prev = Tmp_win; - } - } - else - { - /* - Oh, bother! We have to rebuild the stacking order ring to figure - out where this one went (TopIf, BottomIf, or Opposite). - */ - ResyncFvwmStackRing(); - } - } + XWindowChanges xwc; + unsigned long xwcm; + int x, y, width, height; + XConfigureRequestEvent *cre = &Event.xconfigurerequest; + Bool sendEvent = False; + FvwmWindow *FvwmSib; + + DBUG("HandleConfigureRequest", "Routine Entered"); + + /* + * Event.xany.window is Event.xconfigurerequest.parent, so Tmp_win will + * be wrong + */ + Event.xany.window = cre->window; /* mash parent field */ + if (XFindContext(dpy, cre->window, FvwmContext, (caddr_t *)&Tmp_win) == + XCNOENT) + Tmp_win = NULL; + + /* + * According to the July 27, 1988 ICCCM draft, we should ignore size and + * position fields in the WM_NORMAL_HINTS property when we map a window. + * Instead, we'll read the current geometry. Therefore, we should + * respond to configuration requests for windows which have never been + * mapped. + */ + if (!Tmp_win || cre->window == Tmp_win->icon_w || + cre->window == Tmp_win->icon_pixmap_w) { + xwcm = cre->value_mask & + (CWX | CWY | CWWidth | CWHeight | CWBorderWidth); + xwc.x = cre->x; + xwc.y = cre->y; + if ((Tmp_win) && ((Tmp_win->icon_pixmap_w == cre->window))) { + Tmp_win->icon_p_height = + cre->height + cre->border_width + cre->border_width; + } else if ((Tmp_win) && ((Tmp_win->icon_w == cre->window))) { + Tmp_win->icon_xl_loc = cre->x; + Tmp_win->icon_x_loc = + cre->x + + (Tmp_win->icon_w_width - Tmp_win->icon_p_width) / 2; + Tmp_win->icon_y_loc = cre->y - Tmp_win->icon_p_height; + if (!(Tmp_win->flags & ICON_UNMAPPED)) + BroadcastPacket(M_ICON_LOCATION, 7, Tmp_win->w, + Tmp_win->frame, (unsigned long)Tmp_win, + Tmp_win->icon_x_loc, Tmp_win->icon_y_loc, + Tmp_win->icon_w_width, + Tmp_win->icon_w_height + + Tmp_win->icon_p_height); + } + xwc.width = cre->width; + xwc.height = cre->height; + xwc.border_width = cre->border_width; + + XConfigureWindow(dpy, Event.xany.window, xwcm, &xwc); + + if (Tmp_win) { + if (cre->window != Tmp_win->icon_pixmap_w && + Tmp_win->icon_pixmap_w != None) { + xwc.x = Tmp_win->icon_x_loc; + xwc.y = Tmp_win->icon_y_loc - + Tmp_win->icon_p_height; + xwcm = cre->value_mask & (CWX | CWY); + XConfigureWindow( + dpy, Tmp_win->icon_pixmap_w, xwcm, &xwc); + } + if (Tmp_win->icon_w != None) { + xwc.x = Tmp_win->icon_x_loc; + xwc.y = Tmp_win->icon_y_loc; + xwcm = cre->value_mask & (CWX | CWY); + XConfigureWindow( + dpy, Tmp_win->icon_w, xwcm, &xwc); + } + } + return; + } + + /* Stacking order change requested... */ + if (cre->value_mask & CWStackMode) { + FvwmWindow *otherwin; + + otherwin = NULL; + xwc.sibling = (((cre->value_mask & CWSibling) && + (XFindContext(dpy, cre->above, FvwmContext, + (caddr_t *)&otherwin) == XCSUCCESS)) ? + otherwin->frame : + cre->above); + xwc.stack_mode = cre->detail; + XConfigureWindow(dpy, Tmp_win->frame, + cre->value_mask & (CWSibling | CWStackMode), &xwc); + sendEvent = True; + + /* + RBW - Update the stacking order ring. + */ + if (xwc.stack_mode == Above || xwc.stack_mode == Below) { + FvwmSib = + (otherwin != NULL) ? + otherwin : + Scr.FvwmRoot + .stack_next; /* Set up for Above. */ + if (xwc.stack_mode == Below) { + /* + If Below-sibling, raise above next lower + window. If no sibling, bottom of stack is + "above" Scr.FvwmRoot in the ring. + */ + FvwmSib = (FvwmSib == otherwin) ? + FvwmSib->stack_next : + FvwmSib->stack_prev; + } + if (Tmp_win != + FvwmSib) { /* Don't chain it to itself! */ + Tmp_win->stack_prev->stack_next = + Tmp_win->stack_next; /* Pluck from chain. */ + Tmp_win->stack_next->stack_prev = + Tmp_win->stack_prev; + Tmp_win->stack_next = + FvwmSib; /* Set new pointers. */ + Tmp_win->stack_prev = FvwmSib->stack_prev; + FvwmSib->stack_prev->stack_next = + Tmp_win; /* Re-insert above sibling. */ + FvwmSib->stack_prev = Tmp_win; + } + } else { + /* + Oh, bother! We have to rebuild the stacking order + ring to figure out where this one went (TopIf, + BottomIf, or Opposite). + */ + ResyncFvwmStackRing(); + } + } #ifdef SHAPE - if (ShapesSupported) - { - int xws, yws, xbs, ybs; - unsigned wws, hws, wbs, hbs; - int boundingShaped, clipShaped; - - XShapeQueryExtents (dpy, Tmp_win->w,&boundingShaped, &xws, &yws, &wws, - &hws,&clipShaped, &xbs, &ybs, &wbs, &hbs); - Tmp_win->wShaped = boundingShaped; - } + if (ShapesSupported) { + int xws, yws, xbs, ybs; + unsigned wws, hws, wbs, hbs; + int boundingShaped, clipShaped; + + XShapeQueryExtents(dpy, Tmp_win->w, &boundingShaped, &xws, &yws, + &wws, &hws, &clipShaped, &xbs, &ybs, &wbs, &hbs); + Tmp_win->wShaped = boundingShaped; + } #endif /* SHAPE */ - /* Don't modify frame_XXX fields before calling SetupWindow! */ - x = Tmp_win->frame_x; - y = Tmp_win->frame_y; - width = Tmp_win->frame_width; - height = Tmp_win->frame_height; - - /* for restoring */ - if (cre->value_mask & CWBorderWidth) - { - Tmp_win->old_bw = cre->border_width; - } - /* override even if border change */ - - if (cre->value_mask & CWX) - x = cre->x - Tmp_win->boundary_width - Tmp_win->bw; - if (cre->value_mask & CWY) - y = cre->y - Tmp_win->boundary_width - Tmp_win->title_height - Tmp_win->bw; - if (cre->value_mask & CWWidth) - width = cre->width + 2*Tmp_win->boundary_width; - if (cre->value_mask & CWHeight) - height = cre->height+Tmp_win->title_height+2*Tmp_win->boundary_width; - - /* - * SetupWindow (x,y) are the location of the upper-left outer corner and - * are passed directly to XMoveResizeWindow (frame). The (width,height) - * are the inner size of the frame. The inner width is the same as the - * requested client window width; the inner height is the same as the - * requested client window height plus any title bar slop. - */ - ConstrainSize(Tmp_win, &width, &height, False, 0, 0); - SetupFrame (Tmp_win, x, y, width, height,sendEvent); - KeepOnTop(); + /* Don't modify frame_XXX fields before calling SetupWindow! */ + x = Tmp_win->frame_x; + y = Tmp_win->frame_y; + width = Tmp_win->frame_width; + height = Tmp_win->frame_height; + + /* for restoring */ + if (cre->value_mask & CWBorderWidth) { + Tmp_win->old_bw = cre->border_width; + } + /* override even if border change */ + + if (cre->value_mask & CWX) + x = cre->x - Tmp_win->boundary_width - Tmp_win->bw; + if (cre->value_mask & CWY) + y = cre->y - Tmp_win->boundary_width - Tmp_win->title_height - + Tmp_win->bw; + if (cre->value_mask & CWWidth) + width = cre->width + 2 * Tmp_win->boundary_width; + if (cre->value_mask & CWHeight) + height = cre->height + Tmp_win->title_height + + 2 * Tmp_win->boundary_width; + + /* + * SetupWindow (x,y) are the location of the upper-left outer corner and + * are passed directly to XMoveResizeWindow (frame). The (width,height) + * are the inner size of the frame. The inner width is the same as the + * requested client window width; the inner height is the same as the + * requested client window height plus any title bar slop. + */ + ConstrainSize(Tmp_win, &width, &height, False, 0, 0); + SetupFrame(Tmp_win, x, y, width, height, sendEvent); + KeepOnTop(); } /*********************************************************************** @@ -1475,23 +1379,23 @@ void HandleConfigureRequest() * ***********************************************************************/ #ifdef SHAPE -void HandleShapeNotify (void) +void +HandleShapeNotify(void) { - DBUG("HandleShapeNotify","Routine Entered"); - - if (ShapesSupported) - { - XShapeEvent *sev = (XShapeEvent *) &Event; - - if (!Tmp_win) - return; - if (sev->kind != ShapeBounding) - return; - Tmp_win->wShaped = sev->shaped; - SetShape(Tmp_win,Tmp_win->frame_width); - } + DBUG("HandleShapeNotify", "Routine Entered"); + + if (ShapesSupported) { + XShapeEvent *sev = (XShapeEvent *)&Event; + + if (!Tmp_win) + return; + if (sev->kind != ShapeBounding) + return; + Tmp_win->wShaped = sev->shaped; + SetShape(Tmp_win, Tmp_win->frame_width); + } } -#endif /* SHAPE*/ +#endif /* SHAPE*/ /*********************************************************************** * @@ -1500,127 +1404,114 @@ void HandleShapeNotify (void) * use in the RaiseLower function and the OnTop type windows. * ************************************************************************/ -void HandleVisibilityNotify() +void +HandleVisibilityNotify() { - XVisibilityEvent *vevent = (XVisibilityEvent *) &Event; - - DBUG("HandleVisibilityNotify","Routine Entered"); - - if(Tmp_win && Tmp_win->frame == last_event_window) - { - if(vevent->state == VisibilityUnobscured) - Tmp_win->flags |= VISIBLE; - else - Tmp_win->flags &= ~VISIBLE; - - /* For the most part, we'll raised partially obscured ONTOP windows - * here. The exception is ONTOP windows that are obscured by - * other ONTOP windows, which are raised in KeepOnTop(). This - * complicated set-up saves us from continually re-raising - * every on top window */ - if(((vevent->state == VisibilityPartiallyObscured)|| - (vevent->state == VisibilityFullyObscured))&& - (Tmp_win->flags&ONTOP)&&(Tmp_win->flags & RAISED)) - { - RaiseWindow(Tmp_win); - Tmp_win->flags &= ~RAISED; + XVisibilityEvent *vevent = (XVisibilityEvent *)&Event; + + DBUG("HandleVisibilityNotify", "Routine Entered"); + + if (Tmp_win && Tmp_win->frame == last_event_window) { + if (vevent->state == VisibilityUnobscured) + Tmp_win->flags |= VISIBLE; + else + Tmp_win->flags &= ~VISIBLE; + + /* For the most part, we'll raised partially obscured ONTOP + * windows here. The exception is ONTOP windows that are + * obscured by other ONTOP windows, which are raised in + * KeepOnTop(). This complicated set-up saves us from + * continually re-raising every on top window */ + if (((vevent->state == VisibilityPartiallyObscured) || + (vevent->state == VisibilityFullyObscured)) && + (Tmp_win->flags & ONTOP) && (Tmp_win->flags & RAISED)) { + RaiseWindow(Tmp_win); + Tmp_win->flags &= ~RAISED; + } } - } } - /*************************************************************************** * * Waits for next X event, or for an auto-raise timeout. * ****************************************************************************/ -int My_XNextEvent(Display *dpy, XEvent *event) +int +My_XNextEvent(Display *dpy, XEvent *event) { - extern int fd_width, x_fd; - fd_set in_fdset, out_fdset; - Window targetWindow; - int i; - - DBUG("My_XNextEvent","Routine Entered"); - - /* Do this IMMEDIATELY prior to select, to prevent any nasty - * queued up X events from just hanging around waiting to be - * flushed */ - XFlush(dpy); - if(XPending(dpy)) - { - DBUG("My_XNextEvent","taking care of queued up events & returning"); - XNextEvent(dpy,event); - StashEventTime(event); - return 1; - } - - DBUG("My_XNextEvent","no X events waiting - about to reap children"); - /* Zap all those zombies! */ - /* If we get to here, then there are no X events waiting to be processed. - * Just take a moment to check for dead children. */ - ReapChildren(); - - FD_ZERO(&in_fdset); - FD_SET(x_fd,&in_fdset); - FD_ZERO(&out_fdset); - for(i=0; i=0) - { - FD_SET(readPipes[i], &in_fdset); + extern int fd_width, x_fd; + fd_set in_fdset, out_fdset; + Window targetWindow; + int i; + + DBUG("My_XNextEvent", "Routine Entered"); + + /* Do this IMMEDIATELY prior to select, to prevent any nasty + * queued up X events from just hanging around waiting to be + * flushed */ + XFlush(dpy); + if (XPending(dpy)) { + DBUG("My_XNextEvent", + "taking care of queued up events & returning"); + XNextEvent(dpy, event); + StashEventTime(event); + return 1; } - if(pipeQueue[i]!= NULL) - { - FD_SET(writePipes[i], &out_fdset); - } - } - - DBUG("My_XNextEvent","waiting for module input/output"); - XFlush(dpy); - if (select((SELECT_TYPE_ARG1)fd_width, - SELECT_TYPE_ARG234 &in_fdset, - SELECT_TYPE_ARG234 &out_fdset, - SELECT_TYPE_ARG234 0, - SELECT_TYPE_ARG5 NULL) > 0) - { - - /* Check for module input. */ - for(i=0;i= 0) - { - if(FD_ISSET(readPipes[i], &in_fdset)) - { - if( read(readPipes[i],&targetWindow, sizeof(Window)) >0 ) - { - DBUG("My_XNextEvent","calling HandleModuleInput"); - HandleModuleInput(targetWindow,i); + + DBUG("My_XNextEvent", "no X events waiting - about to reap children"); + /* Zap all those zombies! */ + /* If we get to here, then there are no X events waiting to be + * processed. Just take a moment to check for dead children. */ + ReapChildren(); + + FD_ZERO(&in_fdset); + FD_SET(x_fd, &in_fdset); + FD_ZERO(&out_fdset); + for (i = 0; i < npipes; i++) { + if (readPipes[i] >= 0) { + FD_SET(readPipes[i], &in_fdset); } - else - { - DBUG("My_XNextEvent","calling KillModule"); - KillModule(i,10); + if (pipeQueue[i] != NULL) { + FD_SET(writePipes[i], &out_fdset); } - } } - if(writePipes[i] >= 0) - { - if(FD_ISSET(writePipes[i], &out_fdset)) - { - DBUG("My_XNextEvent","calling FlushQueue"); - FlushQueue(i); - } + + DBUG("My_XNextEvent", "waiting for module input/output"); + XFlush(dpy); + if (select((SELECT_TYPE_ARG1)fd_width, SELECT_TYPE_ARG234 & in_fdset, + SELECT_TYPE_ARG234 & out_fdset, SELECT_TYPE_ARG234 0, + SELECT_TYPE_ARG5 NULL) > 0) { + /* Check for module input. */ + for (i = 0; i < npipes; i++) { + if (readPipes[i] >= 0) { + if (FD_ISSET(readPipes[i], &in_fdset)) { + if (read(readPipes[i], &targetWindow, + sizeof(Window)) > 0) { + DBUG("My_XNextEvent", + "calling " + "HandleModuleInput"); + HandleModuleInput( + targetWindow, i); + } else { + DBUG("My_XNextEvent", + "calling KillModule"); + KillModule(i, 10); + } + } + } + if (writePipes[i] >= 0) { + if (FD_ISSET(writePipes[i], &out_fdset)) { + DBUG("My_XNextEvent", + "calling FlushQueue"); + FlushQueue(i); + } + } + } /* for */ } - } /* for */ - } - DBUG("My_XNextEvent","leaving My_XNextEvent"); - return 0; + DBUG("My_XNextEvent", "leaving My_XNextEvent"); + return 0; } - - - /* RBW - 01/07/1998 - this is here temporarily - I mean to move it to libfvwm eventually, along with some other chain manipulation functions. @@ -1633,65 +1524,56 @@ int My_XNextEvent(Display *dpy, XEvent *event) determine exactly where they ended up in the stacking order. - Based on code from Matthias Clasen. */ -void ResyncFvwmStackRing (void) +void +ResyncFvwmStackRing(void) { - Window root, parent, *children; - unsigned int nchildren, i; - FvwmWindow *t1, *t2; - - MyXGrabServer (dpy); - - if (!XQueryTree (dpy, Scr.Root, &root, &parent, &children, &nchildren)) - { - MyXUngrabServer (dpy); - return; - } - - t2 = &Scr.FvwmRoot; - for (i = 0; i < nchildren; i++) - { - for (t1 = Scr.FvwmRoot.next; t1 != NULL; t1 = t1->next) - { - if (t1->flags & ICONIFIED && (!(t1->flags & SUPPRESSICON))) - { - if (t1->icon_w == children[i]) - { - break; - } - else if (t1->icon_pixmap_w == children[i]) - { - break; - } - } - else - { - if (t1->frame == children[i]) - { - break; - } - } - } + Window root, parent, *children; + unsigned int nchildren, i; + FvwmWindow *t1, *t2; - if (t1 != NULL && t1 != t2) - { - /* - Move the window to its new position, working from the bottom up - (that's the way XQueryTree presents the list). - */ - t1->stack_prev->stack_next = t1->stack_next; /* Pluck from chain. */ - t1->stack_next->stack_prev = t1->stack_prev; - t1->stack_next = t2; /* Set new pointers. */ - t1->stack_prev = t2->stack_prev; - t2->stack_prev->stack_next = t1; /* Insert in new position. */ - t2->stack_prev = t1; - t2 = t1; + MyXGrabServer(dpy); + if (!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) { + MyXUngrabServer(dpy); + return; } - } - MyXUngrabServer (dpy); + t2 = &Scr.FvwmRoot; + for (i = 0; i < nchildren; i++) { + for (t1 = Scr.FvwmRoot.next; t1 != NULL; t1 = t1->next) { + if (t1->flags & ICONIFIED && + (!(t1->flags & SUPPRESSICON))) { + if (t1->icon_w == children[i]) { + break; + } else if (t1->icon_pixmap_w == children[i]) { + break; + } + } else { + if (t1->frame == children[i]) { + break; + } + } + } - XFree (children); -} + if (t1 != NULL && t1 != t2) { + /* + Move the window to its new position, working + from the bottom up (that's the way XQueryTree + presents the list). + */ + t1->stack_prev->stack_next = + t1->stack_next; /* Pluck from chain. */ + t1->stack_next->stack_prev = t1->stack_prev; + t1->stack_next = t2; /* Set new pointers. */ + t1->stack_prev = t2->stack_prev; + t2->stack_prev->stack_next = + t1; /* Insert in new position. */ + t2->stack_prev = t1; + t2 = t1; + } + } + MyXUngrabServer(dpy); + XFree(children); +} Index: fvwm/fvwm/exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/exec.c --- /dev/null +++ fvwm/fvwm/exec.c @@ -0,0 +1,208 @@ +/* + * exec.c -- interface to the privilege-separated execution helper. + * + * The main fvwm process communicates with fvwm_exec via imsg(3) + * over a socketpair(2). The helper executes external commands + * without inheriting the X11 connection. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "fvwm.h" +#include "misc.h" + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +static struct imsgbuf *exec_ibuf; +static int exec_fd = -1; +static pid_t exec_pid = -1; + +/* + * exec_helper_start -- fork and exec the execution helper. + * The helper receives one end of a socketpair for imsg communication. + */ +void +exec_helper_start(void) +{ + int sv[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sv) == -1) + err(1, "socketpair"); + + exec_pid = fork(); + if (exec_pid == -1) + err(1, "fork"); + + if (exec_pid == 0) { + char fdstr[32]; + + close(sv[0]); + snprintf(fdstr, sizeof(fdstr), "%d", sv[1]); + setenv("FVWM_EXEC_FD", fdstr, 1); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + execl(FVWMLIBDIR "/fvwm_exec", "fvwm_exec", NULL); + err(1, "execl %s/fvwm_exec", FVWMLIBDIR); + } + + close(sv[1]); + exec_fd = sv[0]; + + exec_ibuf = malloc(sizeof(struct imsgbuf)); + if (exec_ibuf == NULL) + err(1, "malloc"); + imsg_init(exec_ibuf, exec_fd); +} + +/* + * exec_helper_stop -- request helper shutdown and reap. + */ +void +exec_helper_stop(void) +{ + if (exec_ibuf == NULL) + return; + + imsg_clear(exec_ibuf); + close(exec_fd); + free(exec_ibuf); + exec_ibuf = NULL; + exec_fd = -1; + + if (exec_pid > 0) { + kill(exec_pid, SIGTERM); + waitpid(exec_pid, NULL, 0); + exec_pid = -1; + } +} + +/* + * exec_helper_handle -- process imsg responses from the helper. + * Called from the event loop when exec_fd is readable. + */ +void +exec_helper_handle(void) +{ + struct imsg imsg; + ssize_t n; + + if (exec_ibuf == NULL) + return; + + if ((n = imsg_read(exec_ibuf)) == -1 && errno != EAGAIN) + warn("imsg_read"); + if (n == 0) { + warnx("exec helper disconnected"); + exec_helper_stop(); + return; + } + + while ((n = imsg_get(exec_ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_OK: { + pid_t pid; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(pid_t))) + break; + memcpy(&pid, imsg.data, sizeof(pid_t)); + break; + } + case IMSG_EXEC_ERROR: { + int errnum; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(int))) + break; + memcpy(&errnum, imsg.data, sizeof(int)); + warnc(errnum, "exec helper reported error"); + break; + } + case IMSG_EXEC_EXIT: { + /* Module/command exit; handled by signal watching */ + break; + } + default: + break; + } + imsg_free(&imsg); + } +} + +/* + * exec_helper_launch -- request the helper to execute a command. + * On success, returns 0. On failure (fork error in helper), returns -1. + */ +int +exec_helper_launch(int argc, char **argv, char **envp) +{ + struct ibuf *buf; + size_t datalen, total; + int cargc = argc - 1; /* skip argv[0] which is the path */ + int envc = 0; + int i, ret = -1; + int fd; + + if (exec_ibuf == NULL) + return -1; + + /* Calculate total payload size: sizeof(int)*2 + all strings */ + datalen = sizeof(int) * 2; + for (i = 1; i < argc; i++) + datalen += strlen(argv[i]) + 1; + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + datalen += strlen(envp[i]) + 1; + envc++; + } + } + + if (datalen > MAX_BODY_SIZE * sizeof(unsigned long)) { + warnx("exec argument too large"); + return -1; + } + + /* Compose and send the request */ + buf = imsg_create(exec_ibuf, IMSG_EXEC_RUN, 0, 0, datalen); + if (buf == NULL) + return -1; + + /* argc */ + buf->wpos += imsg_add(buf, &cargc, sizeof(int)); + /* envc */ + buf->wpos += imsg_add(buf, &envc, sizeof(int)); + /* strings */ + for (i = 1; i < argc; i++) { + buf->wpos += imsg_add(buf, argv[i], strlen(argv[i]) + 1); + } + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + buf->wpos += imsg_add(buf, envp[i], + strlen(envp[i]) + 1); + } + } + imsg_close(exec_ibuf, buf); + imsg_flush(exec_ibuf); + + return 0; +} Index: fvwm/fvwm/focus.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/focus.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/focus.c --- fvwm/fvwm/focus.c +++ fvwm/fvwm/focus.c @@ -1,6 +1,6 @@ /**************************************************************************** - * This module is all original code - * by Rob Nation + * This module is all original code + * by Rob Nation * Copyright 1993, Robert Nation * You may use this code for any purpose, as long as the original * copyright remains in the source code and all documentation @@ -12,19 +12,17 @@ * ***********************************************************************/ -#include "config.h" - -#include #include +#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" - /******************************************************************** * @@ -32,183 +30,173 @@ * **********************************************************************/ -void SetFocus(Window w, FvwmWindow *Fw, Bool FocusByMouse) +void +SetFocus(Window w, FvwmWindow *Fw, Bool FocusByMouse) { - int i; - Boolean OnThisPage = False; - extern Time lastTimestamp; - - /* ClickToFocus focus queue manipulation - only performed for - * Focus-by-mouse type focus events */ - /* Watch out: Fw may not be on the windowlist and the windowlist may be empty */ - if (Fw && Fw != Scr.Focus && Fw != &Scr.FvwmRoot) { - if (FocusByMouse) /* pluck window from list and deposit at top */ - { - /* remove Fw from list */ - if (Fw->prev) Fw->prev->next = Fw->next; - if (Fw->next) Fw->next->prev = Fw->prev; - - /* insert Fw at start */ - Fw->next = Scr.FvwmRoot.next; - if (Scr.FvwmRoot.next) Scr.FvwmRoot.next->prev = Fw; - Scr.FvwmRoot.next = Fw; - Fw->prev = &Scr.FvwmRoot; - } - else - { - /* move the windowlist around so that Fw is at the top */ - - FvwmWindow *tmp_win; - - /* find the window on the windowlist */ - tmp_win = &Scr.FvwmRoot; - while (tmp_win && tmp_win != Fw) - tmp_win = tmp_win->next; - - if (tmp_win) /* the window is on the (non-zero length) windowlist */ - { - /* make tmp_win point to the last window on the list */ - while (tmp_win->next) - tmp_win = tmp_win->next; - - /* close the ends of the windowlist */ - tmp_win->next = Scr.FvwmRoot.next; - Scr.FvwmRoot.next->prev = tmp_win; - - /* make Fw the new start of the list */ - Scr.FvwmRoot.next = Fw; - /* open the closed loop windowlist */ - Fw->prev->next = NULL; - Fw->prev = &Scr.FvwmRoot; - } - } - } - - if(Scr.NumberOfScreens > 1) - { - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &JunkX, &JunkY, &JunkMask); - if(JunkRoot != Scr.Root) - { - if((Scr.Ungrabbed != NULL)&&(Scr.Ungrabbed->flags & ClickToFocus)) - { - /* Need to grab buttons for focus window */ - XSync(dpy,0); - for(i=0;i<3;i++) - if(Scr.buttons2grab & (1<frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync, - None,Scr.FvwmCursors[SYS]); - XGrabButton(dpy,(i+1),LockMask,Scr.Ungrabbed->frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync, - None,Scr.FvwmCursors[SYS]); - } - Scr.Focus = NULL; - Scr.Ungrabbed = NULL; - XSetInputFocus(dpy, Scr.NoFocusWin,RevertToParent,lastTimestamp); - } - return; + int i; + Boolean OnThisPage = False; + extern Time lastTimestamp; + + /* ClickToFocus focus queue manipulation - only performed for + * Focus-by-mouse type focus events */ + /* Watch out: Fw may not be on the windowlist and the windowlist may be + * empty */ + if (Fw && Fw != Scr.Focus && Fw != &Scr.FvwmRoot) { + if (FocusByMouse) { /* pluck window from list and deposit at top + */ + /* remove Fw from list */ + if (Fw->prev) + Fw->prev->next = Fw->next; + if (Fw->next) + Fw->next->prev = Fw->prev; + + /* insert Fw at start */ + Fw->next = Scr.FvwmRoot.next; + if (Scr.FvwmRoot.next) + Scr.FvwmRoot.next->prev = Fw; + Scr.FvwmRoot.next = Fw; + Fw->prev = &Scr.FvwmRoot; + } else { + /* move the windowlist around so that Fw is at the top + */ + + FvwmWindow *tmp_win; + + /* find the window on the windowlist */ + tmp_win = &Scr.FvwmRoot; + while (tmp_win && tmp_win != Fw) + tmp_win = tmp_win->next; + + if (tmp_win) { /* the window is on the (non-zero length) + windowlist */ + /* make tmp_win point to the last window on the + * list */ + while (tmp_win->next) + tmp_win = tmp_win->next; + + /* close the ends of the windowlist */ + tmp_win->next = Scr.FvwmRoot.next; + Scr.FvwmRoot.next->prev = tmp_win; + + /* make Fw the new start of the list */ + Scr.FvwmRoot.next = Fw; + /* open the closed loop windowlist */ + Fw->prev->next = NULL; + Fw->prev = &Scr.FvwmRoot; + } + } } - } - if (Fw != NULL) - { - /* - Make sure at least part of window is on this page - before giving it focus... + if (Scr.NumberOfScreens > 1) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, + &JunkY, &JunkX, &JunkY, &JunkMask); + if (JunkRoot != Scr.Root) { + if ((Scr.Ungrabbed != NULL) && + (Scr.Ungrabbed->flags & ClickToFocus)) { + /* Need to grab buttons for focus window */ + XSync(dpy, 0); + for (i = 0; i < 3; i++) + if (Scr.buttons2grab & (1 << i)) { + XGrabButton(dpy, (i + 1), 0, + Scr.Ungrabbed->frame, True, + ButtonPressMask, + GrabModeSync, GrabModeAsync, + None, Scr.FvwmCursors[SYS]); + XGrabButton(dpy, (i + 1), + LockMask, + Scr.Ungrabbed->frame, True, + ButtonPressMask, + GrabModeSync, GrabModeAsync, + None, Scr.FvwmCursors[SYS]); + } + Scr.Focus = NULL; + Scr.Ungrabbed = NULL; + XSetInputFocus(dpy, Scr.NoFocusWin, + RevertToParent, lastTimestamp); + } + return; + } + } + + if (Fw != NULL) { + /* + Make sure at least part of window is on this page + before giving it focus... + */ + if ((Fw->Desk == Scr.CurrentDesk) && + (((Fw->frame_x + Fw->frame_width) >= 0 && + Fw->frame_x < Scr.MyDisplayWidth) && + ((Fw->frame_y + Fw->frame_height) >= 0 && + Fw->frame_y < Scr.MyDisplayHeight))) { + OnThisPage = True; + } + } + + if ((Fw != NULL) && (!OnThisPage)) { + Fw = NULL; + w = Scr.NoFocusWin; + } + + if ((Scr.Ungrabbed != NULL) && (Scr.Ungrabbed->flags & ClickToFocus) && + (Scr.Ungrabbed != Fw)) { + /* need to grab all buttons for window that we are about to + * unfocus */ + XSync(dpy, 0); + for (i = 0; i < 3; i++) + if (Scr.buttons2grab & (1 << i)) + XGrabButton(dpy, (i + 1), 0, + Scr.Ungrabbed->frame, True, ButtonPressMask, + GrabModeSync, GrabModeAsync, None, + Scr.FvwmCursors[SYS]); + Scr.Ungrabbed = NULL; + } + /* if we do click to focus, remove the grab on mouse events that + * was made to detect the focus change */ + if ((Fw != NULL) && (Fw->flags & ClickToFocus)) { + for (i = 0; i < 3; i++) + if (Scr.buttons2grab & (1 << i)) { + XUngrabButton(dpy, (i + 1), 0, Fw->frame); + XUngrabButton( + dpy, (i + 1), LockMask, Fw->frame); + } + Scr.Ungrabbed = Fw; + } + /* RBW - allow focus to go to a NoIconTitle icon window so + auto-raise will work on it... + if((Fw)&&(Fw->flags & ICONIFIED)&&(Fw->icon_w)) + w= Fw->icon_w; */ - if ( (Fw->Desk == Scr.CurrentDesk) && - ( ((Fw->frame_x + Fw->frame_width) >= 0 && - Fw->frame_x < Scr.MyDisplayWidth) && - ((Fw->frame_y + Fw->frame_height) >= 0 && - Fw->frame_y < Scr.MyDisplayHeight) - ) - ) - { - OnThisPage = True; - } - } - - if((Fw != NULL)&&(! OnThisPage)) - { - Fw = NULL; - w = Scr.NoFocusWin; - } - - if((Scr.Ungrabbed != NULL)&& - (Scr.Ungrabbed->flags & ClickToFocus) - && (Scr.Ungrabbed != Fw)) - { - /* need to grab all buttons for window that we are about to - * unfocus */ - XSync(dpy,0); - for(i=0;i<3;i++) - if(Scr.buttons2grab & (1<frame,True, - ButtonPressMask, GrabModeSync,GrabModeAsync,None, - Scr.FvwmCursors[SYS]); - Scr.Ungrabbed = NULL; - } - /* if we do click to focus, remove the grab on mouse events that - * was made to detect the focus change */ - if((Fw != NULL)&&(Fw->flags&ClickToFocus)) - { - for(i=0;i<3;i++) - if(Scr.buttons2grab & (1<frame); - XUngrabButton(dpy,(i+1),LockMask,Fw->frame); - } - Scr.Ungrabbed = Fw; - } -/* RBW - allow focus to go to a NoIconTitle icon window so - auto-raise will work on it... - if((Fw)&&(Fw->flags & ICONIFIED)&&(Fw->icon_w)) - w= Fw->icon_w; -*/ - if((Fw)&&(Fw->flags & ICONIFIED)) - { - if (Fw->icon_w) - { - w = Fw->icon_w; - } - else if (Fw->icon_pixmap_w) - { - w = Fw->icon_pixmap_w; - } - } - - if((Fw)&&(Fw->flags & Lenience)) - { - XSetInputFocus (dpy, w, RevertToParent, lastTimestamp); - Scr.Focus = Fw; - Scr.UnknownWinFocused = None; - } - else if(!((Fw)&&(Fw->wmhints)&&(Fw->wmhints->flags & InputHint)&& - (Fw->wmhints->input == False))) - { - /* Window will accept input focus */ - XSetInputFocus (dpy, w, RevertToParent, lastTimestamp); - Scr.Focus = Fw; - Scr.UnknownWinFocused = None; - } - else if ((Scr.Focus)&&(Scr.Focus->Desk == Scr.CurrentDesk)) - { - /* Window doesn't want focus. Leave focus alone */ - /* XSetInputFocus (dpy,Scr.Hilite->w , RevertToParent, lastTimestamp);*/ - } - else - { - XSetInputFocus (dpy, Scr.NoFocusWin, RevertToParent, lastTimestamp); - Scr.Focus = NULL; - } - - - if ((Fw)&&(Fw->flags & DoesWmTakeFocus)) - send_clientmessage (dpy, w, _XA_WM_TAKE_FOCUS, lastTimestamp); - - XSync(dpy,0); + if ((Fw) && (Fw->flags & ICONIFIED)) { + if (Fw->icon_w) { + w = Fw->icon_w; + } else if (Fw->icon_pixmap_w) { + w = Fw->icon_pixmap_w; + } + } -} + if ((Fw) && (Fw->flags & Lenience)) { + XSetInputFocus(dpy, w, RevertToParent, lastTimestamp); + Scr.Focus = Fw; + Scr.UnknownWinFocused = None; + } else if (!((Fw) && (Fw->wmhints) && + (Fw->wmhints->flags & InputHint) && + (Fw->wmhints->input == False))) { + /* Window will accept input focus */ + XSetInputFocus(dpy, w, RevertToParent, lastTimestamp); + Scr.Focus = Fw; + Scr.UnknownWinFocused = None; + } else if ((Scr.Focus) && (Scr.Focus->Desk == Scr.CurrentDesk)) { + /* Window doesn't want focus. Leave focus alone */ + /* XSetInputFocus (dpy,Scr.Hilite->w , RevertToParent, + * lastTimestamp);*/ + } else { + XSetInputFocus( + dpy, Scr.NoFocusWin, RevertToParent, lastTimestamp); + Scr.Focus = NULL; + } + if ((Fw) && (Fw->flags & DoesWmTakeFocus)) + send_clientmessage(dpy, w, _XA_WM_TAKE_FOCUS, lastTimestamp); + + XSync(dpy, 0); +} Index: fvwm/fvwm/functions.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/functions.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/functions.c --- fvwm/fvwm/functions.c +++ fvwm/fvwm/functions.c @@ -12,20 +12,19 @@ * ***********************************************************************/ -#include "config.h" - -#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" extern XEvent Event; extern FvwmWindow *Tmp_win; @@ -53,130 +52,126 @@ void setImagePath(F_CMD_ARGS); * how that goes. * dje 12/19/98. */ -static struct functions func_config[] = -{ - {"+", add_another_item, F_ADDMENU2, FUNC_NO_WINDOW}, +static struct functions func_config[] = { + {"+", add_another_item, F_ADDMENU2, FUNC_NO_WINDOW}, #ifdef MULTISTYLE - {"AddButtonStyle",AddButtonStyle, F_ADD_BUTTON_STYLE, FUNC_NO_WINDOW}, + {"AddButtonStyle", AddButtonStyle, F_ADD_BUTTON_STYLE, FUNC_NO_WINDOW}, #endif /* MULTISTYLE */ - {"AddModuleConfig", AddModConfig, F_ADD_MOD, FUNC_NO_WINDOW}, + {"AddModuleConfig", AddModConfig, F_ADD_MOD, FUNC_NO_WINDOW}, #ifdef MULTISTYLE #ifdef EXTENDED_TITLESTYLE - {"AddTitleStyle",AddTitleStyle, F_ADD_TITLE_STYLE, FUNC_NO_WINDOW}, + {"AddTitleStyle", AddTitleStyle, F_ADD_TITLE_STYLE, FUNC_NO_WINDOW}, #endif /* EXTENDED_TITLESTYLE */ #endif /* MULTISTYLE */ #ifdef USEDECOR - {"AddToDecor", add_item_to_decor,F_ADD_DECOR, FUNC_NO_WINDOW}, + {"AddToDecor", add_item_to_decor, F_ADD_DECOR, FUNC_NO_WINDOW}, #endif /* USEDECOR */ - {"AddToFunc", add_item_to_func, F_ADDFUNC, FUNC_NO_WINDOW}, - {"AddToMenu", add_item_to_menu, F_ADDMENU, FUNC_NO_WINDOW}, - {"AnimatedMove", animated_move_window,F_ANIMATED_MOVE, FUNC_NEEDS_WINDOW}, - {"Beep", Bell, F_BEEP, FUNC_NO_WINDOW}, + {"AddToFunc", add_item_to_func, F_ADDFUNC, FUNC_NO_WINDOW}, + {"AddToMenu", add_item_to_menu, F_ADDMENU, FUNC_NO_WINDOW}, + {"AnimatedMove", animated_move_window, F_ANIMATED_MOVE, FUNC_NEEDS_WINDOW}, + {"Beep", Bell, F_BEEP, FUNC_NO_WINDOW}, #ifdef BORDERSTYLE - {"BorderStyle", SetBorderStyle, F_BORDERSTYLE, FUNC_NO_WINDOW}, + {"BorderStyle", SetBorderStyle, F_BORDERSTYLE, FUNC_NO_WINDOW}, #endif /* BORDERSTYLE */ - {"ButtonStyle", ButtonStyle, F_BUTTON_STYLE, FUNC_NO_WINDOW}, + {"ButtonStyle", ButtonStyle, F_BUTTON_STYLE, FUNC_NO_WINDOW}, #ifdef USEDECOR - {"ChangeDecor", ChangeDecor, F_CHANGE_DECOR, FUNC_NEEDS_WINDOW}, + {"ChangeDecor", ChangeDecor, F_CHANGE_DECOR, FUNC_NEEDS_WINDOW}, #endif /* USEDECOR */ - {"ChangeMenuStyle", ChangeMenuStyle, F_CHANGE_MENUSTYLE, FUNC_NO_WINDOW}, - {"ClickTime", SetClick, F_CLICK, FUNC_NO_WINDOW}, - {"Close", close_function, F_CLOSE, FUNC_NEEDS_WINDOW}, - {"ColorLimit", SetColorLimit, F_COLOR_LIMIT, FUNC_NO_WINDOW}, - {"ColormapFocus",SetColormapFocus, F_COLORMAP_FOCUS, FUNC_NO_WINDOW}, - {"Current", CurrentFunc, F_CURRENT, FUNC_NO_WINDOW}, - {"CursorMove", movecursor, F_MOVECURSOR, FUNC_NO_WINDOW}, - {"CursorStyle", CursorStyle, F_CURSOR_STYLE, FUNC_NO_WINDOW}, - {"DefaultColors",SetDefaultColors, F_DFLT_COLORS, FUNC_NO_WINDOW}, - {"DefaultFont", LoadDefaultFont, F_DFLT_FONT, FUNC_NO_WINDOW}, - {"Delete", delete_function, F_DELETE, FUNC_NEEDS_WINDOW}, - {"Desk", changeDesks_func, F_DESK, FUNC_NO_WINDOW}, - {"DesktopSize", SetDeskSize, F_SETDESK, FUNC_NO_WINDOW}, - {"Destroy", destroy_function, F_DESTROY, FUNC_NEEDS_WINDOW}, + {"ChangeMenuStyle", ChangeMenuStyle, F_CHANGE_MENUSTYLE, FUNC_NO_WINDOW}, + {"ClickTime", SetClick, F_CLICK, FUNC_NO_WINDOW}, + {"Close", close_function, F_CLOSE, FUNC_NEEDS_WINDOW}, + {"ColorLimit", SetColorLimit, F_COLOR_LIMIT, FUNC_NO_WINDOW}, + {"ColormapFocus", SetColormapFocus, F_COLORMAP_FOCUS, FUNC_NO_WINDOW}, + {"Current", CurrentFunc, F_CURRENT, FUNC_NO_WINDOW}, + {"CursorMove", movecursor, F_MOVECURSOR, FUNC_NO_WINDOW}, + {"CursorStyle", CursorStyle, F_CURSOR_STYLE, FUNC_NO_WINDOW}, + {"DefaultColors", SetDefaultColors, F_DFLT_COLORS, FUNC_NO_WINDOW}, + {"DefaultFont", LoadDefaultFont, F_DFLT_FONT, FUNC_NO_WINDOW}, + {"Delete", delete_function, F_DELETE, FUNC_NEEDS_WINDOW}, + {"Desk", changeDesks_func, F_DESK, FUNC_NO_WINDOW}, + {"DesktopSize", SetDeskSize, F_SETDESK, FUNC_NO_WINDOW}, + {"Destroy", destroy_function, F_DESTROY, FUNC_NEEDS_WINDOW}, #ifdef USEDECOR - {"DestroyDecor", DestroyDecor, F_DESTROY_DECOR, FUNC_NO_WINDOW}, + {"DestroyDecor", DestroyDecor, F_DESTROY_DECOR, FUNC_NO_WINDOW}, #endif /* USEDECOR */ - {"DestroyFunc", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, - {"DestroyMenu", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, - {"DestroyMenuStyle", DestroyMenuStyle, F_DESTROY_MENUSTYLE,FUNC_NO_WINDOW}, - {"DestroyModuleConfig", DestroyModConfig, F_DESTROY_MOD, FUNC_NO_WINDOW}, - {"Direction", DirectionFunc, F_DIRECTION, FUNC_NO_WINDOW}, - {"Echo", echo_func, F_ECHO, FUNC_NO_WINDOW}, - {"EdgeResistance",SetEdgeResistance,F_EDGE_RES, FUNC_NO_WINDOW}, - {"EdgeScroll", SetEdgeScroll, F_EDGE_SCROLL, FUNC_NO_WINDOW}, - {"EdgeThickness",setEdgeThickness, F_NOP, FUNC_NO_WINDOW}, - {"Emulate", Emulate, F_EMULATE, FUNC_NO_WINDOW}, - {"Exec", exec_function, F_EXEC, FUNC_NO_WINDOW}, - {"ExecUseSHELL", exec_setup, F_EXEC_SETUP, FUNC_NO_WINDOW}, - {"FlipFocus", flip_focus_func, F_FLIP_FOCUS, FUNC_NEEDS_WINDOW}, - {"Focus", focus_func, F_FOCUS, FUNC_NEEDS_WINDOW}, - {"Function", ComplexFunction, F_FUNCTION, FUNC_NO_WINDOW}, - {"GlobalOpts", SetGlobalOptions, F_GLOBAL_OPTS, FUNC_NO_WINDOW}, - {"GotoPage", goto_page_func, F_GOTO_PAGE, FUNC_NO_WINDOW}, - {"HilightColor", SetHiColor, F_HICOLOR, FUNC_NO_WINDOW}, - {"IconFont", LoadIconFont, F_ICONFONT, FUNC_NO_WINDOW}, - {"Iconify", iconify_function, F_ICONIFY, FUNC_NEEDS_WINDOW}, - {"IconPath", setIconPath, F_ICON_PATH, FUNC_NO_WINDOW}, - {"ImagePath", setImagePath, F_ICON_PATH, FUNC_NO_WINDOW}, - {"Key", ParseKeyEntry, F_KEY, FUNC_NO_WINDOW}, - {"KillModule", module_zapper, F_ZAP, FUNC_NO_WINDOW}, - {"Lower", lower_function, F_LOWER, FUNC_NEEDS_WINDOW}, - {"Maximize", Maximize, F_MAXIMIZE, FUNC_NEEDS_WINDOW}, - {"Menu", staysup_func, F_STAYSUP, FUNC_NO_WINDOW}, - {"MenuStyle", SetMenuStyle, F_MENUSTYLE, FUNC_NO_WINDOW}, - {"Module", executeModule, F_MODULE, FUNC_NO_WINDOW}, - {"ModulePath", setModulePath, F_MODULE_PATH, FUNC_NO_WINDOW}, - {"Mouse", ParseMouseEntry, F_MOUSE, FUNC_NO_WINDOW}, - {"Move", move_window, F_MOVE, FUNC_NEEDS_WINDOW}, - {"MoveToDesk", changeWindowsDesk,F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW}, - {"MoveToPage", move_window_to_page,F_MOVE_TO_PAGE, FUNC_NEEDS_WINDOW}, - {"Next", NextFunc, F_NEXT, FUNC_NO_WINDOW}, - {"None", NoneFunc, F_NONE, FUNC_NO_WINDOW}, - {"Nop", Nop_func, F_NOP, FUNC_NO_WINDOW}, - {"OpaqueMoveSize", SetOpaque, F_OPAQUE, FUNC_NO_WINDOW}, - {"PipeRead", PipeRead, F_READ, FUNC_NO_WINDOW}, - {"PixmapPath", setPixmapPath, F_PIXMAP_PATH, FUNC_NO_WINDOW}, - {"PopUp", popup_func, F_POPUP, FUNC_NO_WINDOW}, - {"Prev", PrevFunc, F_PREV, FUNC_NO_WINDOW}, - {"Quit", quit_func, F_QUIT, FUNC_NO_WINDOW}, - {"QuitScreen", quit_screen_func, F_QUIT_SCREEN, FUNC_NO_WINDOW}, - {"Raise", raise_function, F_RAISE, FUNC_NEEDS_WINDOW}, - {"RaiseLower", raiselower_func, F_RAISELOWER, FUNC_NEEDS_WINDOW}, - {"Read", ReadFile, F_READ, FUNC_NO_WINDOW}, - {"Recapture", Recapture, F_RECAPTURE, FUNC_NO_WINDOW}, - {"Refresh", refresh_function, F_REFRESH, FUNC_NO_WINDOW}, - {"RefreshWindow",refresh_win_function, F_REFRESH, FUNC_NEEDS_WINDOW}, - {"Resize", resize_window, F_RESIZE, FUNC_NEEDS_WINDOW}, - {"Restart", restart_function, F_RESTART, FUNC_NO_WINDOW}, - {"Scroll", scroll, F_SCROLL, FUNC_NO_WINDOW}, - {"Send_ConfigInfo",SendDataToModule, F_CONFIG_LIST, FUNC_NO_WINDOW}, - {"Send_WindowList",send_list_func, F_SEND_WINDOW_LIST, FUNC_NO_WINDOW}, - {"SendToModule", SendStrToModule, F_SEND_STRING, FUNC_NO_WINDOW}, - {"set_mask", set_mask_function,F_SET_MASK, FUNC_NO_WINDOW}, - {"SetAnimation", set_animation, F_SET_ANIMATION, FUNC_NO_WINDOW}, - {"SetEnv", SetEnv, F_SETENV, FUNC_NO_WINDOW}, - {"SnapAttraction",SetSnapAttraction,F_SNAP_ATT, FUNC_NO_WINDOW}, - {"SnapGrid", SetSnapGrid, F_SNAP_GRID, FUNC_NO_WINDOW}, - {"Stick", stick_function, F_STICK, FUNC_NEEDS_WINDOW}, - {"Style", ProcessNewStyle, F_STYLE, FUNC_NO_WINDOW}, - {"Title", Nop_func, F_TITLE, FUNC_NO_WINDOW}, - {"TitleStyle", SetTitleStyle, F_TITLESTYLE, FUNC_NO_WINDOW}, - {"UpdateDecor", UpdateDecor, F_UPDATE_DECOR, FUNC_NO_WINDOW}, - {"Wait", wait_func, F_WAIT, FUNC_NO_WINDOW}, - {"WarpToWindow", warp_func, F_WARP, FUNC_NEEDS_WINDOW}, - {"WindowFont", LoadWindowFont, F_WINDOWFONT, FUNC_NO_WINDOW}, - {"WindowId", WindowIdFunc, F_WINDOWID, FUNC_NO_WINDOW}, - {"WindowList", do_windowList, F_WINDOWLIST, FUNC_NO_WINDOW}, + {"DestroyFunc", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, + {"DestroyMenu", destroy_menu, F_DESTROY_MENU, FUNC_NO_WINDOW}, + {"DestroyMenuStyle", DestroyMenuStyle, F_DESTROY_MENUSTYLE, FUNC_NO_WINDOW}, + {"DestroyModuleConfig", DestroyModConfig, F_DESTROY_MOD, FUNC_NO_WINDOW}, + {"Direction", DirectionFunc, F_DIRECTION, FUNC_NO_WINDOW}, + {"Echo", echo_func, F_ECHO, FUNC_NO_WINDOW}, + {"EdgeResistance", SetEdgeResistance, F_EDGE_RES, FUNC_NO_WINDOW}, + {"EdgeScroll", SetEdgeScroll, F_EDGE_SCROLL, FUNC_NO_WINDOW}, + {"EdgeThickness", setEdgeThickness, F_NOP, FUNC_NO_WINDOW}, + {"Emulate", Emulate, F_EMULATE, FUNC_NO_WINDOW}, + {"Exec", exec_function, F_EXEC, FUNC_NO_WINDOW}, + {"ExecUseSHELL", exec_setup, F_EXEC_SETUP, FUNC_NO_WINDOW}, + {"FlipFocus", flip_focus_func, F_FLIP_FOCUS, FUNC_NEEDS_WINDOW}, + {"Focus", focus_func, F_FOCUS, FUNC_NEEDS_WINDOW}, + {"Function", ComplexFunction, F_FUNCTION, FUNC_NO_WINDOW}, + {"GlobalOpts", SetGlobalOptions, F_GLOBAL_OPTS, FUNC_NO_WINDOW}, + {"GotoPage", goto_page_func, F_GOTO_PAGE, FUNC_NO_WINDOW}, + {"HilightColor", SetHiColor, F_HICOLOR, FUNC_NO_WINDOW}, + {"IconFont", LoadIconFont, F_ICONFONT, FUNC_NO_WINDOW}, + {"Iconify", iconify_function, F_ICONIFY, FUNC_NEEDS_WINDOW}, + {"IconPath", setIconPath, F_ICON_PATH, FUNC_NO_WINDOW}, + {"ImagePath", setImagePath, F_ICON_PATH, FUNC_NO_WINDOW}, + {"Key", ParseKeyEntry, F_KEY, FUNC_NO_WINDOW}, + {"KillModule", module_zapper, F_ZAP, FUNC_NO_WINDOW}, + {"Lower", lower_function, F_LOWER, FUNC_NEEDS_WINDOW}, + {"Maximize", Maximize, F_MAXIMIZE, FUNC_NEEDS_WINDOW}, + {"Menu", staysup_func, F_STAYSUP, FUNC_NO_WINDOW}, + {"MenuStyle", SetMenuStyle, F_MENUSTYLE, FUNC_NO_WINDOW}, + {"Module", executeModule, F_MODULE, FUNC_NO_WINDOW}, + {"ModulePath", setModulePath, F_MODULE_PATH, FUNC_NO_WINDOW}, + {"Mouse", ParseMouseEntry, F_MOUSE, FUNC_NO_WINDOW}, + {"Move", move_window, F_MOVE, FUNC_NEEDS_WINDOW}, + {"MoveToDesk", changeWindowsDesk, F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW}, + {"MoveToPage", move_window_to_page, F_MOVE_TO_PAGE, FUNC_NEEDS_WINDOW}, + {"Next", NextFunc, F_NEXT, FUNC_NO_WINDOW}, + {"None", NoneFunc, F_NONE, FUNC_NO_WINDOW}, + {"Nop", Nop_func, F_NOP, FUNC_NO_WINDOW}, + {"OpaqueMoveSize", SetOpaque, F_OPAQUE, FUNC_NO_WINDOW}, + {"PipeRead", PipeRead, F_READ, FUNC_NO_WINDOW}, + {"PixmapPath", setPixmapPath, F_PIXMAP_PATH, FUNC_NO_WINDOW}, + {"PopUp", popup_func, F_POPUP, FUNC_NO_WINDOW}, + {"Prev", PrevFunc, F_PREV, FUNC_NO_WINDOW}, + {"Quit", quit_func, F_QUIT, FUNC_NO_WINDOW}, + {"QuitScreen", quit_screen_func, F_QUIT_SCREEN, FUNC_NO_WINDOW}, + {"Raise", raise_function, F_RAISE, FUNC_NEEDS_WINDOW}, + {"RaiseLower", raiselower_func, F_RAISELOWER, FUNC_NEEDS_WINDOW}, + {"Read", ReadFile, F_READ, FUNC_NO_WINDOW}, + {"Recapture", Recapture, F_RECAPTURE, FUNC_NO_WINDOW}, + {"Refresh", refresh_function, F_REFRESH, FUNC_NO_WINDOW}, + {"RefreshWindow", refresh_win_function, F_REFRESH, FUNC_NEEDS_WINDOW}, + {"Resize", resize_window, F_RESIZE, FUNC_NEEDS_WINDOW}, + {"Restart", restart_function, F_RESTART, FUNC_NO_WINDOW}, + {"Scroll", scroll, F_SCROLL, FUNC_NO_WINDOW}, + {"Send_ConfigInfo", SendDataToModule, F_CONFIG_LIST, FUNC_NO_WINDOW}, + {"Send_WindowList", send_list_func, F_SEND_WINDOW_LIST, FUNC_NO_WINDOW}, + {"SendToModule", SendStrToModule, F_SEND_STRING, FUNC_NO_WINDOW}, + {"set_mask", set_mask_function, F_SET_MASK, FUNC_NO_WINDOW}, + {"SetAnimation", set_animation, F_SET_ANIMATION, FUNC_NO_WINDOW}, + {"SetEnv", SetEnv, F_SETENV, FUNC_NO_WINDOW}, + {"SnapAttraction", SetSnapAttraction, F_SNAP_ATT, FUNC_NO_WINDOW}, + {"SnapGrid", SetSnapGrid, F_SNAP_GRID, FUNC_NO_WINDOW}, + {"Stick", stick_function, F_STICK, FUNC_NEEDS_WINDOW}, + {"Style", ProcessNewStyle, F_STYLE, FUNC_NO_WINDOW}, + {"Title", Nop_func, F_TITLE, FUNC_NO_WINDOW}, + {"TitleStyle", SetTitleStyle, F_TITLESTYLE, FUNC_NO_WINDOW}, + {"UpdateDecor", UpdateDecor, F_UPDATE_DECOR, FUNC_NO_WINDOW}, + {"Wait", wait_func, F_WAIT, FUNC_NO_WINDOW}, + {"WarpToWindow", warp_func, F_WARP, FUNC_NEEDS_WINDOW}, + {"WindowFont", LoadWindowFont, F_WINDOWFONT, FUNC_NO_WINDOW}, + {"WindowId", WindowIdFunc, F_WINDOWID, FUNC_NO_WINDOW}, + {"WindowList", do_windowList, F_WINDOWLIST, FUNC_NO_WINDOW}, /* {"WindowsDesk", changeWindowsDesk,F_CHANGE_WINDOWS_DESK, FUNC_NEEDS_WINDOW}, */ #ifdef WINDOWSHADE - {"WindowShade", WindowShade, F_WINDOW_SHADE, FUNC_NEEDS_WINDOW}, + {"WindowShade", WindowShade, F_WINDOW_SHADE, FUNC_NEEDS_WINDOW}, #endif /* WINDOWSHADE */ - {"XORValue", SetXOR, F_XOR, FUNC_NO_WINDOW}, - {"",0,0,0} -}; - + {"XORValue", SetXOR, F_XOR, FUNC_NO_WINDOW}, {"", 0, 0, 0}}; /* migo (02-Oct-1999): add ImagePath not to break 2.3.x configurations */ /* setPath() is from fvwm-2.3.x/libs/System.c */ @@ -185,72 +180,76 @@ static struct functions func_config[] = * Set a colon-separated path, with environment variable expansions, * and expand '+' to be the value of the previous path. **/ -void setPath( char** p_path, char* newpath, int free_old_path ) +void +setPath(char **p_path, char *newpath, int free_old_path) { - char* oldpath = *p_path; - int oldlen = strlen( oldpath ); - char* stripped_path = stripcpy( newpath ); - int found_plus = strchr( newpath, '+' ) != NULL; + char *oldpath = *p_path; + int oldlen = strlen(oldpath); + char *stripped_path = stripcpy(newpath); + int found_plus = strchr(newpath, '+') != NULL; - /** Leave room for the old path, if we find a '+' in newpath **/ - *p_path = envDupExpand( stripped_path, found_plus ? oldlen : 0 ); - free( stripped_path ); + /** Leave room for the old path, if we find a '+' in newpath **/ + *p_path = envDupExpand(stripped_path, found_plus ? oldlen : 0); + free(stripped_path); - if ( found_plus ) { - char* p = strchr( *p_path, '+' ); - memmove( p+oldlen, p+1, strlen(p+1) ); + if (found_plus) { + char *p = strchr(*p_path, '+'); + memmove(p + oldlen, p + 1, strlen(p + 1)); - /* copy oldlen+1 bytes to include the trailing NUL */ - strncpy( p, oldpath, oldlen+1 ); - } + /* copy oldlen+1 bytes to include the trailing NUL */ + strncpy(p, oldpath, oldlen + 1); + } - if ( free_old_path ) - free( oldpath ); + if (free_old_path) + free(oldpath); } -void setImagePath(F_CMD_ARGS) + +void +setImagePath(F_CMD_ARGS) { - extern char *PixmapPath, *IconPath; - char *newPixmapPath = strdup(PixmapPath); - char *newIconPath = strdup(IconPath ); - setPath( &newPixmapPath, action, 1 ); - setPath( &newIconPath, action, 1 ); - setPixmapPath(eventp, w, tmp_win, context, newPixmapPath, Module); - setIconPath (eventp, w, tmp_win, context, newIconPath, Module); + extern char *PixmapPath, *IconPath; + char *newPixmapPath = strdup(PixmapPath); + char *newIconPath = strdup(IconPath); + setPath(&newPixmapPath, action, 1); + setPath(&newIconPath, action, 1); + setPixmapPath(eventp, w, tmp_win, context, newPixmapPath, Module); + setIconPath(eventp, w, tmp_win, context, newIconPath, Module); } - /* ** do binary search on func list */ -static int func_comp(const void *a, const void *b) +static int +func_comp(const void *a, const void *b) { - char *key=(char *)a; - char *f=((struct functions *)b)->keyword; - return (strcasecmp(key,f)); + char *key = (char *)a; + char *f = ((struct functions *)b)->keyword; + return (strcasecmp(key, f)); } -static struct functions *FindBuiltinFunction(char *func) +static struct functions * +FindBuiltinFunction(char *func) { - static int func_config_size=0; + static int func_config_size = 0; - if (!func) - return NULL; + if (!func) + return NULL; - if (!func_config_size) - { - /* remove finial NULL entry from size */ - func_config_size=((sizeof(func_config))/(sizeof(struct functions)))-1; - } + if (!func_config_size) { + /* remove finial NULL entry from size */ + func_config_size = + ((sizeof(func_config)) / (sizeof(struct functions))) - 1; + } - /* since a lot of lines in a typical rc are probably menu/func continues: */ - if (func[0]=='+') - return &(func_config[0]); + /* since a lot of lines in a typical rc are probably menu/func + * continues: */ + if (func[0] == '+') + return &(func_config[0]); - return (struct functions *)bsearch(func, func_config, func_config_size, - sizeof(struct functions), func_comp); + return (struct functions *)bsearch(func, func_config, func_config_size, + sizeof(struct functions), func_comp); } - /*********************************************************************** * * Procedure: @@ -263,112 +262,112 @@ static struct functions *FindBuiltinFunction(char *func) * context - the context in which the button was pressed * ***********************************************************************/ -void ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp, - unsigned long context, int Module) +void +ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp, + unsigned long context, int Module) { - Window w; - int matched,j; - char *function; - char *action, *taction; - char *arguments[10]; - struct functions *bif; - - if (!Action || Action[0] == 0 || Action[1] == 0) - { - /* impossibly short command */ - return; /* done */ - } - if (Action[0] == '#') { /* a comment */ - return; /* done */ - } - /* Note: the module config command, "*" can not be handled by the - regular command table because there is no required white space after - the asterisk. */ - if (Action[0] == '*') { /* a module config command */ - ModuleConfig(NULL,0,0,0,Action,0); /* process the command */ - return; /* done */ - } - - for(j=0;j<10;j++) - arguments[j] = NULL; - - if(tmp_win == NULL) - w = Scr.Root; - else - w = tmp_win->w; - - if((tmp_win) &&(eventp)) - w = eventp->xany.window; - if((tmp_win)&&(eventp->xbutton.subwindow != None)&& - (eventp->xany.window != tmp_win->w)) - w = eventp->xbutton.subwindow; - - taction = expand(Action,arguments,tmp_win); - action = GetNextToken(taction,&function); - if (!function) - return; - j=0; - matched = FALSE; - - bif = FindBuiltinFunction(function); - if (bif) - { - matched = TRUE; - bif->action(eventp,w,tmp_win,context,action,&Module); - } - - if(!matched) - { - desperate = 1; - ComplexFunction(eventp,w,tmp_win,context,taction, &Module); - if(desperate) - executeModule(eventp,w,tmp_win,context,taction, &Module); - desperate = 0; - } - - /* Only wait for an all-buttons-up condition after calls from - * regular built-ins, not from complex-functions or modules. */ - if(Module == -1) - WaitForButtonsUp(); - - if (function) - free(function); - if(taction != NULL) - free(taction); - return; + Window w; + int matched, j; + char *function; + char *action, *taction; + char *arguments[10]; + struct functions *bif; + + if (!Action || Action[0] == 0 || Action[1] == 0) { + /* impossibly short command */ + return; /* done */ + } + if (Action[0] == '#') { /* a comment */ + return; /* done */ + } + /* Note: the module config command, "*" can not be handled by the + regular command table because there is no required white space after + the asterisk. */ + if (Action[0] == '*') { /* a module config command */ + ModuleConfig( + NULL, 0, 0, 0, Action, 0); /* process the command */ + return; /* done */ + } + + for (j = 0; j < 10; j++) + arguments[j] = NULL; + + if (tmp_win == NULL) + w = Scr.Root; + else + w = tmp_win->w; + + if ((tmp_win) && (eventp)) + w = eventp->xany.window; + if ((tmp_win) && (eventp->xbutton.subwindow != None) && + (eventp->xany.window != tmp_win->w)) + w = eventp->xbutton.subwindow; + + taction = expand(Action, arguments, tmp_win); + action = GetNextToken(taction, &function); + if (!function) + return; + j = 0; + matched = FALSE; + + bif = FindBuiltinFunction(function); + if (bif) { + matched = TRUE; + bif->action(eventp, w, tmp_win, context, action, &Module); + } + + if (!matched) { + desperate = 1; + ComplexFunction(eventp, w, tmp_win, context, taction, &Module); + if (desperate) + executeModule( + eventp, w, tmp_win, context, taction, &Module); + desperate = 0; + } + + /* Only wait for an all-buttons-up condition after calls from + * regular built-ins, not from complex-functions or modules. */ + if (Module == -1) + WaitForButtonsUp(); + + if (function) + free(function); + if (taction != NULL) + free(taction); + return; } - -void find_func_type(char *action, short *func_type, Bool *func_needs_window) +void +find_func_type(char *action, short *func_type, Bool *func_needs_window) { - int j, len = 0; - char *endtok = action; - Bool matched; - int mlen; - - if (action) - { - while (*endtok&&!isspace(*endtok))++endtok; - len = endtok - action; - j=0; - matched = FALSE; - while((!matched)&&((mlen = strlen(func_config[j].keyword))>0)) - { - if((mlen == len) && - (strncasecmp(action,func_config[j].keyword,mlen)==0)) - { - matched=TRUE; - /* found key word */ - *func_type = func_config[j].func_type; - *func_needs_window = func_config[j].func_needs_window; - return; - } - else - j++; - } - /* No clue what the function is. Just return "BEEP" */ - } - *func_type = F_BEEP; - *func_needs_window = False; - return; + int j, len = 0; + char *endtok = action; + Bool matched; + int mlen; + + if (action) { + while (*endtok && !isspace(*endtok)) + ++endtok; + len = endtok - action; + j = 0; + matched = FALSE; + while ((!matched) && + ((mlen = strlen(func_config[j].keyword)) > 0)) { + if ((mlen == len) && + (strncasecmp( + action, func_config[j].keyword, mlen) == 0)) { + matched = TRUE; + /* found key word */ + *func_type = func_config[j].func_type; + *func_needs_window = + func_config[j].func_needs_window; + return; + } else + j++; + } + /* No clue what the function is. Just return "BEEP" */ + } + *func_type = F_BEEP; + *func_needs_window = False; + return; } Index: fvwm/fvwm/fvwm.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm.c --- fvwm/fvwm/fvwm.c +++ fvwm/fvwm/fvwm.c @@ -1,4 +1,3 @@ - /**************************************************************************** * This module is all original code * by Rob Nation @@ -11,61 +10,50 @@ * fvwm - "F? Virtual Window Manager" ***********************************************************************/ -#include "config.h" +#include "fvwm.h" +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include #include -#include -#include "fvwm.h" + +#include "config.h" +#include "fvwm_sandbox.h" #include "menus.h" #include "misc.h" -#include "screen.h" -#include "parse.h" #include "module.h" - -#include -#include -/* need to get prototype for XrmUniqueQuark for XUniqueContext call */ -#include +#include "parse.h" +#include "screen.h" #ifdef SHAPE #include #endif /* SHAPE */ -#if defined(HAVE_SYS_SYSTEMINFO_H) -/* Solaris has sysinfo instead of gethostname. */ -#include -#endif - #define MAXHOSTNAME 255 - #ifndef lint static char sccsid[] = "@(#)fvwm.c " VERSION " fvwm"; #endif -int master_pid; /* process number of 1st fvwm process */ +int master_pid; /* process number of 1st fvwm process */ -ScreenInfo Scr; /* structures for the screen */ -Display *dpy; /* which display are we talking to */ +ScreenInfo Scr; /* structures for the screen */ +Display *dpy; /* which display are we talking to */ -Window BlackoutWin=None; /* window to hide window captures */ -Bool fFvwmInStartup = True; /* Set to False when startup has finished */ +Window BlackoutWin = None; /* window to hide window captures */ +Bool fFvwmInStartup = True; /* Set to False when startup has finished */ -char *default_config_command = "Read "FVWMRC; +char *default_config_command = "Read " FVWMRC; #define MAX_CFG_CMDS 10 static char *config_commands[MAX_CFG_CMDS]; -static int num_config_commands=0; - -#if 0 -/* unsused */ -char *output_file = NULL; -#endif +static int num_config_commands = 0; int FvwmErrorHandler(Display *, XErrorEvent *); int CatchFatal(Display *); @@ -78,14 +66,14 @@ void SetMWM_INFO(Window window); void SetRCDefaults(void); void StartupStuff(void); -XContext FvwmContext; /* context for fvwm windows */ -XContext MenuContext; /* context for fvwm menus */ +XContext FvwmContext; /* context for fvwm windows */ +XContext MenuContext; /* context for fvwm menus */ int JunkX = 0, JunkY = 0; -Window JunkRoot, JunkChild; /* junk window */ +Window JunkRoot, JunkChild; /* junk window */ unsigned int JunkWidth, JunkHeight, JunkBW, JunkDepth, JunkMask; -Boolean debugging = False,PPosOverride,Blackout = False; +Boolean debugging = False, PPosOverride, Blackout = False; char **g_argv; int g_argc; @@ -99,16 +87,9 @@ static char g_bits[] = {0x02, 0x01}; #define l_g_height 2 static char l_g_bits[] = {0x08, 0x02}; -#if 0 -/* code unused */ -#define s_g_width 4 -#define s_g_height 4 -static char s_g_bits[] = {0x01, 0x02, 0x04, 0x08}; -#endif - #ifdef SHAPE int ShapeEventBase, ShapeErrorBase; -Boolean ShapesSupported=False; +Boolean ShapesSupported = False; #endif long isIconicState = 0; @@ -117,7 +98,7 @@ Bool Restarting = False; int fd_width, x_fd; char *display_name = NULL; -typedef enum { FVWM_RUNNING=0, FVWM_DONE, FVWM_RESTART } FVWM_STATE; +typedef enum { FVWM_RUNNING = 0, FVWM_DONE, FVWM_RESTART } FVWM_STATE; /* * Currently, the "isTerminated" variable is superfluous. However, @@ -136,451 +117,414 @@ volatile sig_atomic_t isTerminated = False; * *********************************************************************** */ -int main(int argc, char **argv) +int +main(int argc, char **argv) { - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ - void InternUsefulAtoms (void); - void InitVariables(void); - int i; - extern int x_fd; - int len; - char *display_string; - char message[255]; - Bool single = False; - Bool option_error = FALSE; - int x, y; - size_t buflen; - - g_argv = argv; - g_argc = argc; - - DBUG("main","Entered, about to parse args"); - - /* Put the default module directory into the environment so it can be used - later by the config file, etc. */ - putenv("FVWM_MODULEDIR=" FVWM_MODULEDIR); - - for (i = 1; i < argc; i++) - { - if (strncasecmp(argv[i],"-debug",6)==0) - { - debugging = True; - } - else if (strncasecmp(argv[i],"-s",2)==0) - { - single = True; - } - else if (strncasecmp(argv[i],"-d",2)==0) - { - if (++i >= argc) - usage(); - display_name = argv[i]; - } - else if (strncasecmp(argv[i],"-f",2)==0) - { - if (++i >= argc) - usage(); - if (num_config_commands < MAX_CFG_CMDS) - { - buflen = 6+strlen(argv[i]); - config_commands[num_config_commands] = (char *)malloc(buflen); - strlcpy(config_commands[num_config_commands],"Read ", buflen); - strlcat(config_commands[num_config_commands],argv[i], buflen); - num_config_commands++; - } - else - { - fvwm_msg(ERR,"main","only %d -f and -cmd parms allowed!",MAX_CFG_CMDS); - } - } - else if (strncasecmp(argv[i],"-cmd",4)==0) - { - if (++i >= argc) - usage(); - if (num_config_commands < MAX_CFG_CMDS) - { - config_commands[num_config_commands] = strdup(argv[i]); - num_config_commands++; - } - else - { - fvwm_msg(ERR,"main","only %d -f and -cmd parms allowed!",MAX_CFG_CMDS); - } - } -#if 0 -/* unused */ - else if (strncasecmp(argv[i],"-outfile",8)==0) - { - if (++i >= argc) - usage(); - output_file = argv[i]; - } -#endif - else if (strncasecmp(argv[i],"-h",2)==0) - { - usage(); - exit(0); - } - else if (strncasecmp(argv[i],"-blackout",9)==0) - { - Blackout = True; - } - else if (strncasecmp(argv[i], "-version", 8) == 0) - { - fvwm_msg(INFO,"main", "Fvwm Version %s\n", VERSION); - } - else - { - fvwm_msg(ERR,"main","Unknown option: `%s'\n", argv[i]); - option_error = TRUE; - } - } - - DBUG("main","Done parsing args"); - - if (option_error) - { - usage(); - } - - DBUG("main","Installing signal handlers"); + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ + void InternUsefulAtoms(void); + void InitVariables(void); + int i; + extern int x_fd; + int len; + char *display_string; + char message[255]; + Bool single = False; + Bool option_error = FALSE; + int x, y; + size_t buflen; + + g_argv = argv; + g_argc = argc; + + DBUG("main", "Entered, about to parse args"); + + /* Put the default module directory into the environment so it can be + used later by the config file, etc. */ + putenv("FVWM_MODULEDIR=" FVWM_MODULEDIR); + + for (i = 1; i < argc; i++) { + if (strncasecmp(argv[i], "-debug", 6) == 0) { + debugging = True; + } else if (strncasecmp(argv[i], "-s", 2) == 0) { + single = True; + } else if (strncasecmp(argv[i], "-d", 2) == 0) { + if (++i >= argc) + usage(); + display_name = argv[i]; + } else if (strncasecmp(argv[i], "-f", 2) == 0) { + if (++i >= argc) + usage(); + if (num_config_commands < MAX_CFG_CMDS) { + buflen = 6 + strlen(argv[i]); + config_commands[num_config_commands] = + (char *)malloc(buflen); + strlcpy(config_commands[num_config_commands], + "Read ", buflen); + strlcat(config_commands[num_config_commands], + argv[i], buflen); + num_config_commands++; + } else { + fvwm_msg(ERR, "main", + "only %d -f and -cmd parms allowed!", + MAX_CFG_CMDS); + } + } else if (strncasecmp(argv[i], "-cmd", 4) == 0) { + if (++i >= argc) + usage(); + if (num_config_commands < MAX_CFG_CMDS) { + config_commands[num_config_commands] = + strdup(argv[i]); + num_config_commands++; + } else { + fvwm_msg(ERR, "main", + "only %d -f and -cmd parms allowed!", + MAX_CFG_CMDS); + } + } else if (strncasecmp(argv[i], "-h", 2) == 0) { + usage(); + exit(0); + } else if (strncasecmp(argv[i], "-blackout", 9) == 0) { + Blackout = True; + } else if (strncasecmp(argv[i], "-version", 8) == 0) { + fvwm_msg(INFO, "main", "Fvwm Version %s\n", VERSION); + } else { + fvwm_msg( + ERR, "main", "Unknown option: `%s'\n", argv[i]); + option_error = TRUE; + } + } + + DBUG("main", "Done parsing args"); + + if (option_error) { + usage(); + } + + DBUG("main", "Installing signal handlers"); #ifdef HAVE_SIGACTION - { - struct sigaction sigact; - - /* - * Use reliable signal semantics since they are predictable and portable. - * DeadPipe() looks like a no-op, so don't stop processing system calls - * to handle a SIGPIPE (Why don't we just -ignore- SIGPIPE?) - */ + { + struct sigaction sigact; + + /* + * Use reliable signal semantics since they are predictable and + * portable. DeadPipe() looks like a no-op, so don't stop + * processing system calls to handle a SIGPIPE (Why don't we + * just -ignore- SIGPIPE?) + */ #ifdef SA_RESTART - sigact.sa_flags = SA_RESTART; + sigact.sa_flags = SA_RESTART; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigemptyset(&sigact.sa_mask); + sigemptyset(&sigact.sa_mask); - sigact.sa_handler = DeadPipe; /* This handler does nothing ??? */ - sigaction(SIGPIPE, &sigact, NULL); + sigact.sa_handler = + DeadPipe; /* This handler does nothing ??? */ + sigaction(SIGPIPE, &sigact, NULL); - /* - * If we need to restart then we need to stop what we're doing as - * quickly as possible - hence interrupt any system call we're - * blocked in ... - */ + /* + * If we need to restart then we need to stop what we're doing + * as quickly as possible - hence interrupt any system call + * we're blocked in ... + */ #ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigact.sa_handler = Restart; - sigaction(SIGUSR1, &sigact, NULL); - } + sigact.sa_handler = Restart; + sigaction(SIGUSR1, &sigact, NULL); + } #else - /* We don't have sigaction(), so fall back to less robust methods. */ - signal(SIGPIPE, DeadPipe); - signal(SIGUSR1, Restart); + /* We don't have sigaction(), so fall back to less robust methods. */ + signal(SIGPIPE, DeadPipe); + signal(SIGUSR1, Restart); #endif - newhandler(SIGINT); - newhandler(SIGHUP); - newhandler(SIGQUIT); - newhandler(SIGTERM); - - ReapChildren(); - - if (!(dpy = XOpenDisplay(display_name))) - { - fvwm_msg(ERR,"main","can't open display %s", XDisplayName(display_name)); - exit (1); - } - Scr.screen= DefaultScreen(dpy); - Scr.NumberOfScreens = ScreenCount(dpy); - - master_pid = getpid(); - - if(!single) - { - int myscreen = 0; - char *cp; - - strlcpy(message, XDisplayString(dpy), sizeof(message)); - - for(i=0;i 0) - { - int i; - for(i=0;i 0) { + int i; + for (i = 0; i < num_config_commands; i++) { + ExecuteFunction( + config_commands[i], NULL, &Event, C_ROOT, 1); + free(config_commands[i]); + } + } else { + ExecuteFunction( + default_config_command, NULL, &Event, C_ROOT, 1); + } + DBUG("main", "Done running config_commands"); + + if (Scr.d_depth < 2) { + Scr.gray_pixmap = XCreatePixmapFromBitmapData(dpy, Scr.Root, + g_bits, g_width, g_height, Scr.StdColors.fore, + Scr.StdColors.back, Scr.d_depth); + Scr.light_gray_pixmap = XCreatePixmapFromBitmapData(dpy, + Scr.Root, l_g_bits, l_g_width, l_g_height, + Scr.StdColors.fore, Scr.StdColors.back, Scr.d_depth); + } + + /* create a window which will accept the keyboard focus when no other + windows have it */ + attributes.event_mask = KeyPressMask | FocusChangeMask; + attributes.override_redirect = True; + Scr.NoFocusWin = + XCreateWindow(dpy, Scr.Root, -10, -10, 10, 10, 0, 0, InputOnly, + CopyFromParent, CWEventMask | CWOverrideRedirect, &attributes); + XMapWindow(dpy, Scr.NoFocusWin); + + SetMWM_INFO(Scr.NoFocusWin); + + XSetInputFocus(dpy, Scr.NoFocusWin, RevertToParent, CurrentTime); + + XSync(dpy, 0); + if (debugging) + XSynchronize(dpy, 1); + + Scr.SizeStringWidth = + XTextWidth(Scr.StdFont.font, " +8888 x +8888 ", 15); + attributes.border_pixel = Scr.StdColors.fore; + attributes.background_pixel = Scr.StdColors.back; + attributes.bit_gravity = NorthWestGravity; + valuemask = (CWBorderPixel | CWBackPixel | CWBitGravity); + if (!Scr.gs.EmulateMWM) { + x = 0; + y = 0; + } else { + x = Scr.MyDisplayWidth / 2 - + (Scr.SizeStringWidth + SIZE_HINDENT * 2) / 2; + y = Scr.MyDisplayHeight / 2 - + (Scr.StdFont.height + SIZE_VINDENT * 2) / 2; + } + Scr.SizeWindow = XCreateWindow(dpy, Scr.Root, x, y, + (unsigned int)(Scr.SizeStringWidth + SIZE_HINDENT * 2), + (unsigned int)(Scr.StdFont.height + SIZE_VINDENT * 2), + (unsigned int)0, 0, (unsigned int)CopyFromParent, + (Visual *)CopyFromParent, valuemask, &attributes); + if (Scr.SizeWindow != None) + XSetWindowBackground(dpy, Scr.SizeWindow, Scr.StdColors.back); #ifndef NON_VIRTUAL - initPanFrames(); + initPanFrames(); #endif - MyXGrabServer(dpy); + MyXGrabServer(dpy); #ifndef NON_VIRTUAL - checkPanFrames(); + checkPanFrames(); #endif - MyXUngrabServer(dpy); - UnBlackoutScreen(); /* if we need to remove blackout window */ - CoerceEnterNotifyOnCurrentWindow(); - /* Make sure we have the correct click time now. */ - if (Scr.ClickTime < 0) - Scr.ClickTime = -Scr.ClickTime; - fFvwmInStartup = False; - DBUG("main","Entering HandleEvents loop..."); - - if (pledge("stdio rpath proc exec", NULL) == -1) - err(1, "pledge"); - - HandleEvents(); - switch( fvwmRunState ) - { - case FVWM_DONE: - Done(0, NULL); /* does not return */ - - case FVWM_RESTART: - Done(1, *g_argv); /* does not return */ - - default: - DBUG("main","Unknown FVWM run-state"); - } - - return 0; -} + MyXUngrabServer(dpy); + UnBlackoutScreen(); /* if we need to remove blackout window */ + CoerceEnterNotifyOnCurrentWindow(); + /* Make sure we have the correct click time now. */ + if (Scr.ClickTime < 0) + Scr.ClickTime = -Scr.ClickTime; + fFvwmInStartup = False; + DBUG("main", "Entering HandleEvents loop..."); + + if (unveil(FVWMLIBDIR, "rx") == -1) + err(1, "unveil %s", FVWMLIBDIR); + if (unveil("/etc/X11/fvwm", "r") == -1) + err(1, "unveil /etc/X11/fvwm"); + if (unveil("/tmp", "rwc") == -1) + err(1, "unveil /tmp"); + if (unveil(NULL, NULL) == -1) + err(1, "unveil"); + + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "pledge"); + + HandleEvents(); + switch (fvwmRunState) { + case FVWM_DONE: + Done(0, NULL); /* does not return */ + + case FVWM_RESTART: + Done(1, *g_argv); /* does not return */ + + default: + DBUG("main", "Unknown FVWM run-state"); + } + return 0; +} /* ** StartupStuff ** ** Does initial window captures and runs init/restart function */ -void StartupStuff(void) +void +StartupStuff(void) { - MenuRoot *mr; + MenuRoot *mr; - CaptureAllWindows(); - MakeMenus(); + CaptureAllWindows(); + MakeMenus(); #ifndef NON_VIRTUAL - /* Have to do this here too because preprocessor modules have not run to the - * end when HandleEvents is entered from the main loop. */ - checkPanFrames(); + /* Have to do this here too because preprocessor modules have not run to + * the end when HandleEvents is entered from the main loop. */ + checkPanFrames(); #endif - /* migo (02-Oct-1999): execute StartFunction */ - if (FindPopup("StartFunction")) { - ExecuteFunction("Function StartFunction", NULL, &Event, C_ROOT, 1); - } - - if(Restarting) - { - mr = FindPopup("RestartFunction"); - if(mr != NULL) - ExecuteFunction("Function RestartFunction",NULL,&Event,C_ROOT,1); - } - else - { - mr = FindPopup("InitFunction"); - if(mr != NULL) - ExecuteFunction("Function InitFunction",NULL,&Event,C_ROOT,1); - } -} /* StartupStuff */ + /* migo (02-Oct-1999): execute StartFunction */ + if (FindPopup("StartFunction")) { + ExecuteFunction( + "Function StartFunction", NULL, &Event, C_ROOT, 1); + } + if (Restarting) { + mr = FindPopup("RestartFunction"); + if (mr != NULL) + ExecuteFunction("Function RestartFunction", NULL, + &Event, C_ROOT, 1); + } else { + mr = FindPopup("InitFunction"); + if (mr != NULL) + ExecuteFunction( + "Function InitFunction", NULL, &Event, C_ROOT, 1); + } +} /* StartupStuff */ /*********************************************************************** * @@ -591,120 +535,111 @@ void StartupStuff(void) * ***********************************************************************/ -void CaptureAllWindows(void) +void +CaptureAllWindows(void) { - int i,j; - unsigned int nchildren; - Window root, parent, *children; - FvwmWindow *tmp,*next; /* temp fvwm window structure */ - Window w; - unsigned long data[1]; - unsigned char *prop; - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - - MyXGrabServer(dpy); - - if(!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) - { - MyXUngrabServer(dpy); - return; - } - - PPosOverride = True; - - if (!(Scr.flags & WindowsCaptured)) /* initial capture? */ - { - /* - ** weed out icon windows - */ - for (i=0;iflags & IconWindowHint) - { - for (j = 0; j < nchildren; j++) - { - if (children[j] == wmhintsp->icon_window) - { - children[j] = None; - break; - } - } - } - XFree ((char *) wmhintsp); - } - } - } - /* - ** map all of the non-override, non-icon windows - */ - for (i = 0; i < nchildren; i++) - { - if (children[i] && MappedNotOverride(children[i])) - { - XUnmapWindow(dpy, children[i]); - Event.xmaprequest.window = children[i]; - HandleMapRequestKeepRaised (BlackoutWin); - } - } - Scr.flags |= WindowsCaptured; - } - else /* must be recapture */ - { - /* reborder all windows */ - tmp = Scr.FvwmRoot.next; - for(i=0;iw,_XA_WM_STATE,0L,3L,False, - _XA_WM_STATE, - &atype,&aformat,&nitems,&bytes_remain,&prop)== - Success) - { - if(prop != NULL) - { - isIconicState = *(long *)prop; - XFree(prop); - } - } - next = tmp->next; - data[0] = (unsigned long) tmp->Desk; - XChangeProperty (dpy, tmp->w, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, - PropModeReplace, (unsigned char *) data, 1); - - XSelectInput(dpy, tmp->w, 0); - w = tmp->w; - XUnmapWindow(dpy,tmp->frame); - XUnmapWindow(dpy,w); - RestoreWithdrawnLocation (tmp,True); - Destroy(tmp); - Event.xmaprequest.window = w; - HandleMapRequestKeepRaised(BlackoutWin); - tmp = next; - } - } - } - - isIconicState = DontCareState; - - if(nchildren > 0) - XFree((char *)children); - - /* after the windows already on the screen are in place, - * don't use PPosition */ - PPosOverride = False; - KeepOnTop(); - MyXUngrabServer(dpy); - XSync(dpy,0); /* should we do this on initial capture? */ + int i, j; + unsigned int nchildren; + Window root, parent, *children; + FvwmWindow *tmp, *next; /* temp fvwm window structure */ + Window w; + unsigned long data[1]; + unsigned char *prop; + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + + MyXGrabServer(dpy); + + if (!XQueryTree(dpy, Scr.Root, &root, &parent, &children, &nchildren)) { + MyXUngrabServer(dpy); + return; + } + + PPosOverride = True; + + if (!(Scr.flags & WindowsCaptured)) { /* initial capture? */ + /* + ** weed out icon windows + */ + for (i = 0; i < nchildren; i++) { + if (children[i]) { + XWMHints *wmhintsp = + XGetWMHints(dpy, children[i]); + if (wmhintsp) { + if (wmhintsp->flags & IconWindowHint) { + for (j = 0; j < nchildren; + j++) { + if (children[j] == + wmhintsp + ->icon_window) { + children[j] = + None; + break; + } + } + } + XFree((char *)wmhintsp); + } + } + } + /* + ** map all of the non-override, non-icon windows + */ + for (i = 0; i < nchildren; i++) { + if (children[i] && MappedNotOverride(children[i])) { + XUnmapWindow(dpy, children[i]); + Event.xmaprequest.window = children[i]; + HandleMapRequestKeepRaised(BlackoutWin); + } + } + Scr.flags |= WindowsCaptured; + } else /* must be recapture */ { + /* reborder all windows */ + tmp = Scr.FvwmRoot.next; + for (i = 0; i < nchildren; i++) { + if (XFindContext(dpy, children[i], FvwmContext, + (caddr_t *)&tmp) != XCNOENT) { + isIconicState = DontCareState; + if (XGetWindowProperty(dpy, tmp->w, + _XA_WM_STATE, 0L, 3L, False, + _XA_WM_STATE, &atype, &aformat, &nitems, + &bytes_remain, &prop) == Success) { + if (prop != NULL) { + isIconicState = *(long *)prop; + XFree(prop); + } + } + next = tmp->next; + data[0] = (unsigned long)tmp->Desk; + XChangeProperty(dpy, tmp->w, _XA_WM_DESKTOP, + _XA_WM_DESKTOP, 32, PropModeReplace, + (unsigned char *)data, 1); + + XSelectInput(dpy, tmp->w, 0); + w = tmp->w; + XUnmapWindow(dpy, tmp->frame); + XUnmapWindow(dpy, w); + RestoreWithdrawnLocation(tmp, True); + Destroy(tmp); + Event.xmaprequest.window = w; + HandleMapRequestKeepRaised(BlackoutWin); + tmp = next; + } + } + } + + isIconicState = DontCareState; + + if (nchildren > 0) + XFree((char *)children); + + /* after the windows already on the screen are in place, + * don't use PPosition */ + PPosOverride = False; + KeepOnTop(); + MyXUngrabServer(dpy); + XSync(dpy, 0); /* should we do this on initial capture? */ } /* @@ -712,34 +647,28 @@ void CaptureAllWindows(void) ** ** Sets some initial style values & such */ -void SetRCDefaults() +void +SetRCDefaults() { - /* set up default colors, fonts, etc */ - char *defaults[] = { - "HilightColor black grey", - "XORValue 0", - "DefaultFont fixed", - "DefaultColors black grey", - "MenuStyle * fvwm, Foreground black, Background grey, Greyed slategrey", - "TitleStyle Centered -- Raised", - "Style \"*\" Color lightgrey/dimgrey, Title", - "Style \"*\" RandomPlacement, SmartPlacement", - "AddToMenu builtin_menu \"Builtin Menu\" Title", - "+ \"Exit FVWM\" Quit", - "Mouse 1 R N Popup builtin_menu", - "AddToFunc WindowListFunc \"I\" WindowId $0 Iconify -1", - "+ \"I\" WindowId $0 FlipFocus", - "+ \"I\" WindowId $0 Raise", - "+ \"I\" WindowId $0 WarpToWindow 5p 5p", - NULL - }; - int i=0; - - while (defaults[i]) - { - ExecuteFunction(defaults[i],NULL,&Event,C_ROOT,1); - i++; - } + /* set up default colors, fonts, etc */ + char *defaults[] = {"HilightColor black grey", "XORValue 0", + "DefaultFont fixed", "DefaultColors black grey", + "MenuStyle * fvwm, Foreground black, Background grey, Greyed " + "slategrey", + "TitleStyle Centered -- Raised", + "Style \"*\" Color lightgrey/dimgrey, Title", + "Style \"*\" RandomPlacement, SmartPlacement", + "AddToMenu builtin_menu \"Builtin Menu\" Title", + "+ \"Exit FVWM\" Quit", "Mouse 1 R N Popup builtin_menu", + "AddToFunc WindowListFunc \"I\" WindowId $0 Iconify -1", + "+ \"I\" WindowId $0 FlipFocus", "+ \"I\" WindowId $0 Raise", + "+ \"I\" WindowId $0 WarpToWindow 5p 5p", NULL}; + int i = 0; + + while (defaults[i]) { + ExecuteFunction(defaults[i], NULL, &Event, C_ROOT, 1); + i++; + } } /* SetRCDefaults */ /*********************************************************************** @@ -757,37 +686,36 @@ void SetRCDefaults() * ***********************************************************************/ -int MappedNotOverride(Window w) +int +MappedNotOverride(Window w) { - XWindowAttributes wa; - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - unsigned char *prop; - - isIconicState = DontCareState; - - if((w==Scr.NoFocusWin)||(!XGetWindowAttributes(dpy, w, &wa))) - return False; - - if(XGetWindowProperty(dpy,w,_XA_WM_STATE,0L,3L,False,_XA_WM_STATE, - &atype,&aformat,&nitems,&bytes_remain,&prop)==Success) - { - if(prop != NULL) - { - isIconicState = *(long *)prop; - XFree(prop); - } - } - if(wa.override_redirect == True) - { - XSelectInput(dpy,w,FocusChangeMask); - } - return (((isIconicState == IconicState)||(wa.map_state != IsUnmapped)) && - (wa.override_redirect != True)); + XWindowAttributes wa; + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + unsigned char *prop; + + isIconicState = DontCareState; + + if ((w == Scr.NoFocusWin) || (!XGetWindowAttributes(dpy, w, &wa))) + return False; + + if (XGetWindowProperty(dpy, w, _XA_WM_STATE, 0L, 3L, False, + _XA_WM_STATE, &atype, &aformat, &nitems, &bytes_remain, + &prop) == Success) { + if (prop != NULL) { + isIconicState = *(long *)prop; + XFree(prop); + } + } + if (wa.override_redirect == True) { + XSelectInput(dpy, w, FocusChangeMask); + } + return ( + ((isIconicState == IconicState) || (wa.map_state != IsUnmapped)) && + (wa.override_redirect != True)); } - /*********************************************************************** * * Procedure: @@ -820,35 +748,38 @@ Atom _XA_OL_DECOR_RESIZE; Atom _XA_OL_DECOR_HEADER; Atom _XA_OL_DECOR_ICON_NAME; -void InternUsefulAtoms (void) +void +InternUsefulAtoms(void) { - /* - * Create priority colors if necessary. - */ - _XA_MIT_PRIORITY_COLORS = XInternAtom(dpy, "_MIT_PRIORITY_COLORS", False); - _XA_WM_CHANGE_STATE = XInternAtom (dpy, "WM_CHANGE_STATE", False); - _XA_WM_STATE = XInternAtom (dpy, "WM_STATE", False); - _XA_WM_COLORMAP_WINDOWS = XInternAtom (dpy, "WM_COLORMAP_WINDOWS", False); - _XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); - _XA_WM_TAKE_FOCUS = XInternAtom (dpy, "WM_TAKE_FOCUS", False); - _XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False); - _XA_WM_DESKTOP = XInternAtom (dpy, "WM_DESKTOP", False); - _XA_MwmAtom=XInternAtom(dpy,"_MOTIF_WM_HINTS",False); - _XA_MOTIF_WM=XInternAtom(dpy,"_MOTIF_WM_INFO",False); - - _XA_OL_WIN_ATTR=XInternAtom(dpy,"_OL_WIN_ATTR",False); - _XA_OL_WT_BASE=XInternAtom(dpy,"_OL_WT_BASE",False); - _XA_OL_WT_CMD=XInternAtom(dpy,"_OL_WT_CMD",False); - _XA_OL_WT_HELP=XInternAtom(dpy,"_OL_WT_HELP",False); - _XA_OL_WT_NOTICE=XInternAtom(dpy,"_OL_WT_NOTICE",False); - _XA_OL_WT_OTHER=XInternAtom(dpy,"_OL_WT_OTHER",False); - _XA_OL_DECOR_ADD=XInternAtom(dpy,"_OL_DECOR_ADD",False); - _XA_OL_DECOR_DEL=XInternAtom(dpy,"_OL_DECOR_DEL",False); - _XA_OL_DECOR_CLOSE=XInternAtom(dpy,"_OL_DECOR_CLOSE",False); - _XA_OL_DECOR_RESIZE=XInternAtom(dpy,"_OL_DECOR_RESIZE",False); - _XA_OL_DECOR_HEADER=XInternAtom(dpy,"_OL_DECOR_HEADER",False); - _XA_OL_DECOR_ICON_NAME=XInternAtom(dpy,"_OL_DECOR_ICON_NAME",False); - return; + /* + * Create priority colors if necessary. + */ + _XA_MIT_PRIORITY_COLORS = + XInternAtom(dpy, "_MIT_PRIORITY_COLORS", False); + _XA_WM_CHANGE_STATE = XInternAtom(dpy, "WM_CHANGE_STATE", False); + _XA_WM_STATE = XInternAtom(dpy, "WM_STATE", False); + _XA_WM_COLORMAP_WINDOWS = + XInternAtom(dpy, "WM_COLORMAP_WINDOWS", False); + _XA_WM_PROTOCOLS = XInternAtom(dpy, "WM_PROTOCOLS", False); + _XA_WM_TAKE_FOCUS = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + _XA_WM_DELETE_WINDOW = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + _XA_WM_DESKTOP = XInternAtom(dpy, "WM_DESKTOP", False); + _XA_MwmAtom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); + _XA_MOTIF_WM = XInternAtom(dpy, "_MOTIF_WM_INFO", False); + + _XA_OL_WIN_ATTR = XInternAtom(dpy, "_OL_WIN_ATTR", False); + _XA_OL_WT_BASE = XInternAtom(dpy, "_OL_WT_BASE", False); + _XA_OL_WT_CMD = XInternAtom(dpy, "_OL_WT_CMD", False); + _XA_OL_WT_HELP = XInternAtom(dpy, "_OL_WT_HELP", False); + _XA_OL_WT_NOTICE = XInternAtom(dpy, "_OL_WT_NOTICE", False); + _XA_OL_WT_OTHER = XInternAtom(dpy, "_OL_WT_OTHER", False); + _XA_OL_DECOR_ADD = XInternAtom(dpy, "_OL_DECOR_ADD", False); + _XA_OL_DECOR_DEL = XInternAtom(dpy, "_OL_DECOR_DEL", False); + _XA_OL_DECOR_CLOSE = XInternAtom(dpy, "_OL_DECOR_CLOSE", False); + _XA_OL_DECOR_RESIZE = XInternAtom(dpy, "_OL_DECOR_RESIZE", False); + _XA_OL_DECOR_HEADER = XInternAtom(dpy, "_OL_DECOR_HEADER", False); + _XA_OL_DECOR_ICON_NAME = XInternAtom(dpy, "_OL_DECOR_ICON_NAME", False); + return; } /*********************************************************************** @@ -861,39 +792,38 @@ void newhandler(int sig) { #ifdef HAVE_SIGACTION - struct sigaction sigact; - - sigaction(sig,NULL,&sigact); - if (sigact.sa_handler != SIG_IGN) - { - /* - * SigDone requires that we QUIT as soon as possible afterwards, - * so we need to interrupt any system calls we are blocked in - */ - sigemptyset(&sigact.sa_mask); + struct sigaction sigact; + + sigaction(sig, NULL, &sigact); + if (sigact.sa_handler != SIG_IGN) { + /* + * SigDone requires that we QUIT as soon as possible afterwards, + * so we need to interrupt any system calls we are blocked in + */ + sigemptyset(&sigact.sa_mask); #ifdef SA_INTERRUPT - sigact.sa_flags = SA_INTERRUPT; + sigact.sa_flags = SA_INTERRUPT; #else - sigact.sa_flags = 0; + sigact.sa_flags = 0; #endif - sigact.sa_handler = SigDone; - sigaction(sig, &sigact, NULL); - } + sigact.sa_handler = SigDone; + sigaction(sig, &sigact, NULL); + } #else - /* We don't have sigaction(), so use less robust methods. */ - if (signal(sig,SIG_IGN) == SIG_IGN) - signal(sig,SigDone); + /* We don't have sigaction(), so use less robust methods. */ + if (signal(sig, SIG_IGN) == SIG_IGN) + signal(sig, SigDone); #endif } - /************************************************************************* * Restart on a signal ************************************************************************/ -RETSIGTYPE Restart(int nonsense) +void +Restart(int nonsense) { - isTerminated = True; - fvwmRunState = FVWM_RESTART; + isTerminated = True; + fvwmRunState = FVWM_RESTART; } /*********************************************************************** @@ -903,26 +833,31 @@ RETSIGTYPE Restart(int nonsense) * *********************************************************************** */ -void CreateCursors(void) +void +CreateCursors(void) { - /* define cursors */ - Scr.FvwmCursors[POSITION] = XCreateFontCursor(dpy,XC_top_left_corner); - Scr.FvwmCursors[DEFAULT] = XCreateFontCursor(dpy, XC_top_left_arrow); - Scr.FvwmCursors[SYS] = XCreateFontCursor(dpy, XC_hand2); - Scr.FvwmCursors[TITLE_CURSOR] = XCreateFontCursor(dpy, XC_top_left_arrow); - Scr.FvwmCursors[MOVE] = XCreateFontCursor(dpy, XC_fleur); - Scr.FvwmCursors[MENU] = XCreateFontCursor(dpy, XC_sb_left_arrow); - Scr.FvwmCursors[WAIT] = XCreateFontCursor(dpy, XC_watch); - Scr.FvwmCursors[SELECT] = XCreateFontCursor(dpy, XC_dot); - Scr.FvwmCursors[DESTROY] = XCreateFontCursor(dpy, XC_pirate); - Scr.FvwmCursors[LEFT] = XCreateFontCursor(dpy, XC_left_side); - Scr.FvwmCursors[RIGHT] = XCreateFontCursor(dpy, XC_right_side); - Scr.FvwmCursors[TOP] = XCreateFontCursor(dpy, XC_top_side); - Scr.FvwmCursors[BOTTOM] = XCreateFontCursor(dpy, XC_bottom_side); - Scr.FvwmCursors[TOP_LEFT] = XCreateFontCursor(dpy,XC_top_left_corner); - Scr.FvwmCursors[TOP_RIGHT] = XCreateFontCursor(dpy,XC_top_right_corner); - Scr.FvwmCursors[BOTTOM_LEFT] = XCreateFontCursor(dpy,XC_bottom_left_corner); - Scr.FvwmCursors[BOTTOM_RIGHT] =XCreateFontCursor(dpy,XC_bottom_right_corner); + /* define cursors */ + Scr.FvwmCursors[POSITION] = XCreateFontCursor(dpy, XC_top_left_corner); + Scr.FvwmCursors[DEFAULT] = XCreateFontCursor(dpy, XC_top_left_arrow); + Scr.FvwmCursors[SYS] = XCreateFontCursor(dpy, XC_hand2); + Scr.FvwmCursors[TITLE_CURSOR] = + XCreateFontCursor(dpy, XC_top_left_arrow); + Scr.FvwmCursors[MOVE] = XCreateFontCursor(dpy, XC_fleur); + Scr.FvwmCursors[MENU] = XCreateFontCursor(dpy, XC_sb_left_arrow); + Scr.FvwmCursors[WAIT] = XCreateFontCursor(dpy, XC_watch); + Scr.FvwmCursors[SELECT] = XCreateFontCursor(dpy, XC_dot); + Scr.FvwmCursors[DESTROY] = XCreateFontCursor(dpy, XC_pirate); + Scr.FvwmCursors[LEFT] = XCreateFontCursor(dpy, XC_left_side); + Scr.FvwmCursors[RIGHT] = XCreateFontCursor(dpy, XC_right_side); + Scr.FvwmCursors[TOP] = XCreateFontCursor(dpy, XC_top_side); + Scr.FvwmCursors[BOTTOM] = XCreateFontCursor(dpy, XC_bottom_side); + Scr.FvwmCursors[TOP_LEFT] = XCreateFontCursor(dpy, XC_top_left_corner); + Scr.FvwmCursors[TOP_RIGHT] = + XCreateFontCursor(dpy, XC_top_right_corner); + Scr.FvwmCursors[BOTTOM_LEFT] = + XCreateFontCursor(dpy, XC_bottom_left_corner); + Scr.FvwmCursors[BOTTOM_RIGHT] = + XCreateFontCursor(dpy, XC_bottom_right_corner); } /*********************************************************************** @@ -931,88 +866,88 @@ void CreateCursors(void) * assumes associated button memory is already free * ************************************************************************/ -void LoadDefaultLeftButton(ButtonFace *bf, int i) +void +LoadDefaultLeftButton(ButtonFace *bf, int i) { #ifndef VECTOR_BUTTONS - bf->style = SimpleButton; + bf->style = SimpleButton; #else - bf->style = VectorButton; - switch (i % 5) - { - case 0: - case 4: - bf->vector.x[0] = 22; - bf->vector.y[0] = 39; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 78; - bf->vector.y[1] = 39; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 78; - bf->vector.y[2] = 61; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 22; - bf->vector.y[3] = 61; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 22; - bf->vector.y[4] = 39; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 1: - bf->vector.x[0] = 32; - bf->vector.y[0] = 45; - bf->vector.line_style[0] = 0; - bf->vector.x[1] = 68; - bf->vector.y[1] = 45; - bf->vector.line_style[1] = 0; - bf->vector.x[2] = 68; - bf->vector.y[2] = 55; - bf->vector.line_style[2] = 1; - bf->vector.x[3] = 32; - bf->vector.y[3] = 55; - bf->vector.line_style[3] = 1; - bf->vector.x[4] = 32; - bf->vector.y[4] = 45; - bf->vector.line_style[4] = 0; - bf->vector.num = 5; - break; - case 2: - bf->vector.x[0] = 49; - bf->vector.y[0] = 49; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 51; - bf->vector.y[1] = 49; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 51; - bf->vector.y[2] = 51; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 49; - bf->vector.y[3] = 51; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 49; - bf->vector.y[4] = 49; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 3: - bf->vector.x[0] = 32; - bf->vector.y[0] = 45; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 68; - bf->vector.y[1] = 45; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 68; - bf->vector.y[2] = 55; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 32; - bf->vector.y[3] = 55; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 32; - bf->vector.y[4] = 45; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - } + bf->style = VectorButton; + switch (i % 5) { + case 0: + case 4: + bf->vector.x[0] = 22; + bf->vector.y[0] = 39; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 78; + bf->vector.y[1] = 39; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 78; + bf->vector.y[2] = 61; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 22; + bf->vector.y[3] = 61; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 22; + bf->vector.y[4] = 39; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 1: + bf->vector.x[0] = 32; + bf->vector.y[0] = 45; + bf->vector.line_style[0] = 0; + bf->vector.x[1] = 68; + bf->vector.y[1] = 45; + bf->vector.line_style[1] = 0; + bf->vector.x[2] = 68; + bf->vector.y[2] = 55; + bf->vector.line_style[2] = 1; + bf->vector.x[3] = 32; + bf->vector.y[3] = 55; + bf->vector.line_style[3] = 1; + bf->vector.x[4] = 32; + bf->vector.y[4] = 45; + bf->vector.line_style[4] = 0; + bf->vector.num = 5; + break; + case 2: + bf->vector.x[0] = 49; + bf->vector.y[0] = 49; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 51; + bf->vector.y[1] = 49; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 51; + bf->vector.y[2] = 51; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 49; + bf->vector.y[3] = 51; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 49; + bf->vector.y[4] = 49; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 3: + bf->vector.x[0] = 32; + bf->vector.y[0] = 45; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 68; + bf->vector.y[1] = 45; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 68; + bf->vector.y[2] = 55; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 32; + bf->vector.y[3] = 55; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 32; + bf->vector.y[4] = 45; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + } #endif /* VECTOR_BUTTONS */ } @@ -1022,88 +957,88 @@ void LoadDefaultLeftButton(ButtonFace *bf, int i) * assumes associated button memory is already free * ************************************************************************/ -void LoadDefaultRightButton(ButtonFace *bf, int i) +void +LoadDefaultRightButton(ButtonFace *bf, int i) { #ifndef VECTOR_BUTTONS - bf->style = SimpleButton; + bf->style = SimpleButton; #else - bf->style = VectorButton; - switch (i % 5) - { - case 0: - case 3: - bf->vector.x[0] = 25; - bf->vector.y[0] = 25; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 75; - bf->vector.y[1] = 25; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 75; - bf->vector.y[2] = 75; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 25; - bf->vector.y[3] = 75; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 25; - bf->vector.y[4] = 25; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 1: - bf->vector.x[0] = 39; - bf->vector.y[0] = 39; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 61; - bf->vector.y[1] = 39; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 61; - bf->vector.y[2] = 61; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 39; - bf->vector.y[3] = 61; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 39; - bf->vector.y[4] = 39; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 2: - bf->vector.x[0] = 49; - bf->vector.y[0] = 49; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 51; - bf->vector.y[1] = 49; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 51; - bf->vector.y[2] = 51; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 49; - bf->vector.y[3] = 51; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 49; - bf->vector.y[4] = 49; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - case 4: - bf->vector.x[0] = 36; - bf->vector.y[0] = 36; - bf->vector.line_style[0] = 1; - bf->vector.x[1] = 64; - bf->vector.y[1] = 36; - bf->vector.line_style[1] = 1; - bf->vector.x[2] = 64; - bf->vector.y[2] = 64; - bf->vector.line_style[2] = 0; - bf->vector.x[3] = 36; - bf->vector.y[3] = 64; - bf->vector.line_style[3] = 0; - bf->vector.x[4] = 36; - bf->vector.y[4] = 36; - bf->vector.line_style[4] = 1; - bf->vector.num = 5; - break; - } + bf->style = VectorButton; + switch (i % 5) { + case 0: + case 3: + bf->vector.x[0] = 25; + bf->vector.y[0] = 25; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 75; + bf->vector.y[1] = 25; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 75; + bf->vector.y[2] = 75; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 25; + bf->vector.y[3] = 75; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 25; + bf->vector.y[4] = 25; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 1: + bf->vector.x[0] = 39; + bf->vector.y[0] = 39; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 61; + bf->vector.y[1] = 39; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 61; + bf->vector.y[2] = 61; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 39; + bf->vector.y[3] = 61; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 39; + bf->vector.y[4] = 39; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 2: + bf->vector.x[0] = 49; + bf->vector.y[0] = 49; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 51; + bf->vector.y[1] = 49; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 51; + bf->vector.y[2] = 51; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 49; + bf->vector.y[3] = 51; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 49; + bf->vector.y[4] = 49; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + case 4: + bf->vector.x[0] = 36; + bf->vector.y[0] = 36; + bf->vector.line_style[0] = 1; + bf->vector.x[1] = 64; + bf->vector.y[1] = 36; + bf->vector.line_style[1] = 1; + bf->vector.x[2] = 64; + bf->vector.y[2] = 64; + bf->vector.line_style[2] = 0; + bf->vector.x[3] = 36; + bf->vector.y[3] = 64; + bf->vector.line_style[3] = 0; + bf->vector.x[4] = 36; + bf->vector.y[4] = 36; + bf->vector.line_style[4] = 1; + bf->vector.num = 5; + break; + } #endif /* VECTOR_BUTTONS */ } @@ -1113,14 +1048,16 @@ void LoadDefaultRightButton(ButtonFace *bf, int i) * assumes associated button memory is already free * ************************************************************************/ -void LoadDefaultButton(ButtonFace *bf, int i) +void +LoadDefaultButton(ButtonFace *bf, int i) { - int n = i / 2; - if ((n * 2) == i) { - if (--n < 0) n = 4; - LoadDefaultRightButton(bf, n); - } else - LoadDefaultLeftButton(bf, n); + int n = i / 2; + if ((n * 2) == i) { + if (--n < 0) + n = 4; + LoadDefaultRightButton(bf, n); + } else + LoadDefaultLeftButton(bf, n); } extern void FreeButtonFace(Display *dpy, ButtonFace *bf); @@ -1131,43 +1068,43 @@ extern void FreeButtonFace(Display *dpy, ButtonFace *bf); * destroys existing buttons * ************************************************************************/ -void ResetAllButtons(FvwmDecor *fl) +void +ResetAllButtons(FvwmDecor *fl) { - TitleButton *leftp, *rightp; - int i=0; + TitleButton *leftp, *rightp; + int i = 0; - for (leftp=fl->left_buttons, rightp=fl->right_buttons; - i < 5; - ++i, ++leftp, ++rightp) { - ButtonFace *lface, *rface; - int j; + for (leftp = fl->left_buttons, rightp = fl->right_buttons; i < 5; + ++i, ++leftp, ++rightp) { + ButtonFace *lface, *rface; + int j; - leftp->flags = 0; - rightp->flags = 0; + leftp->flags = 0; + rightp->flags = 0; - lface = leftp->state; - rface = rightp->state; + lface = leftp->state; + rface = rightp->state; - FreeButtonFace(dpy, lface); - FreeButtonFace(dpy, rface); + FreeButtonFace(dpy, lface); + FreeButtonFace(dpy, rface); - LoadDefaultLeftButton(lface++, i); - LoadDefaultRightButton(rface++, i); + LoadDefaultLeftButton(lface++, i); + LoadDefaultRightButton(rface++, i); - for (j = 1; j < MaxButtonState; ++j, ++lface, ++rface) { - FreeButtonFace(dpy, lface); - FreeButtonFace(dpy, rface); + for (j = 1; j < MaxButtonState; ++j, ++lface, ++rface) { + FreeButtonFace(dpy, lface); + FreeButtonFace(dpy, rface); - *lface = leftp->state[0]; - *rface = rightp->state[0]; - } - } + *lface = leftp->state[0]; + *rface = rightp->state[0]; + } + } - /* standard MWM decoration hint assignments (veliaa@rpi.edu) - [Menu] - Title Bar - [Minimize] [Maximize] */ - fl->left_buttons[0].flags |= MWMDecorMenu; - fl->right_buttons[1].flags |= MWMDecorMinimize; - fl->right_buttons[0].flags |= MWMDecorMaximize; + /* standard MWM decoration hint assignments (veliaa@rpi.edu) + [Menu] - Title Bar - [Minimize] [Maximize] */ + fl->left_buttons[0].flags |= MWMDecorMenu; + fl->right_buttons[1].flags |= MWMDecorMinimize; + fl->right_buttons[0].flags |= MWMDecorMaximize; } /*********************************************************************** @@ -1176,37 +1113,37 @@ void ResetAllButtons(FvwmDecor *fl) * structure, but does not free the FvwmDecor itself * ************************************************************************/ -void DestroyFvwmDecor(FvwmDecor *fl) +void +DestroyFvwmDecor(FvwmDecor *fl) { - int i; - /* reset to default button set (frees allocated mem) */ - ResetAllButtons(fl); - for (i = 0; i < 3; ++i) - { - int j = 0; - for (; j < MaxButtonState; ++j) - FreeButtonFace(dpy, &fl->titlebar.state[i]); - } + int i; + /* reset to default button set (frees allocated mem) */ + ResetAllButtons(fl); + for (i = 0; i < 3; ++i) { + int j = 0; + for (; j < MaxButtonState; ++j) + FreeButtonFace(dpy, &fl->titlebar.state[i]); + } #ifdef BORDERSTYLE - FreeButtonFace(dpy, &fl->BorderStyle.active); - FreeButtonFace(dpy, &fl->BorderStyle.inactive); + FreeButtonFace(dpy, &fl->BorderStyle.active); + FreeButtonFace(dpy, &fl->BorderStyle.inactive); #endif #ifdef USEDECOR - if (fl->tag) { - free(fl->tag); - fl->tag = NULL; - } + if (fl->tag) { + free(fl->tag); + fl->tag = NULL; + } #endif - if (fl->HiReliefGC != NULL) { - XFreeGC(dpy, fl->HiReliefGC); - fl->HiReliefGC = NULL; - } - if (fl->HiShadowGC != NULL) { - XFreeGC(dpy, fl->HiShadowGC); - fl->HiShadowGC = NULL; - } - if (fl->WindowFont.font != NULL) - XFreeFont(dpy, fl->WindowFont.font); + if (fl->HiReliefGC != NULL) { + XFreeGC(dpy, fl->HiReliefGC); + fl->HiReliefGC = NULL; + } + if (fl->HiShadowGC != NULL) { + XFreeGC(dpy, fl->HiShadowGC); + fl->HiShadowGC = NULL; + } + if (fl->WindowFont.font != NULL) + XFreeFont(dpy, fl->WindowFont.font); } /*********************************************************************** @@ -1214,60 +1151,61 @@ void DestroyFvwmDecor(FvwmDecor *fl) * InitFvwmDecor -- initializes an FvwmDecor structure to defaults * ************************************************************************/ -void InitFvwmDecor(FvwmDecor *fl) +void +InitFvwmDecor(FvwmDecor *fl) { - int i; - ButtonFace tmpbf; + int i; + ButtonFace tmpbf; - fl->HiReliefGC = NULL; - fl->HiShadowGC = NULL; - fl->TitleHeight = 0; - fl->WindowFont.font = NULL; + fl->HiReliefGC = NULL; + fl->HiShadowGC = NULL; + fl->TitleHeight = 0; + fl->WindowFont.font = NULL; #ifdef USEDECOR - fl->tag = NULL; - fl->next = NULL; - - if (fl != &Scr.DefaultDecor) { - extern void AddToDecor(FvwmDecor *, char *); - AddToDecor(fl, "HilightColor black grey"); - AddToDecor(fl, "WindowFont fixed"); - } + fl->tag = NULL; + fl->next = NULL; + + if (fl != &Scr.DefaultDecor) { + extern void AddToDecor(FvwmDecor *, char *); + AddToDecor(fl, "HilightColor black grey"); + AddToDecor(fl, "WindowFont fixed"); + } #endif - /* initialize title-bar button styles */ - tmpbf.style = SimpleButton; + /* initialize title-bar button styles */ + tmpbf.style = SimpleButton; #ifdef MULTISTYLE - tmpbf.next = NULL; + tmpbf.next = NULL; #endif - for (i = 0; i < 5; ++i) { - int j = 0; - for (; j < MaxButtonState; ++j) { - fl->left_buttons[i].state[j] = - fl->right_buttons[i].state[j] = tmpbf; + for (i = 0; i < 5; ++i) { + int j = 0; + for (; j < MaxButtonState; ++j) { + fl->left_buttons[i].state[j] = + fl->right_buttons[i].state[j] = tmpbf; + } } - } - /* reset to default button set */ - ResetAllButtons(fl); + /* reset to default button set */ + ResetAllButtons(fl); - /* initialize title-bar styles */ - fl->titlebar.flags = 0; + /* initialize title-bar styles */ + fl->titlebar.flags = 0; - for (i = 0; i < MaxButtonState; ++i) { - fl->titlebar.state[i].style = SimpleButton; + for (i = 0; i < MaxButtonState; ++i) { + fl->titlebar.state[i].style = SimpleButton; #ifdef MULTISTYLE - fl->titlebar.state[i].next = NULL; + fl->titlebar.state[i].next = NULL; #endif - } + } #ifdef BORDERSTYLE - /* initialize border texture styles */ - fl->BorderStyle.active.style = SimpleButton; - fl->BorderStyle.inactive.style = SimpleButton; + /* initialize border texture styles */ + fl->BorderStyle.active.style = SimpleButton; + fl->BorderStyle.inactive.style = SimpleButton; #ifdef MULTISTYLE - fl->BorderStyle.active.next = NULL; - fl->BorderStyle.inactive.next = NULL; + fl->BorderStyle.active.next = NULL; + fl->BorderStyle.inactive.next = NULL; #endif #endif } @@ -1278,138 +1216,138 @@ void InitFvwmDecor(FvwmDecor *fl) * InitVariables - initialize fvwm variables * ************************************************************************/ -void InitVariables(void) +void +InitVariables(void) { - FvwmContext = XUniqueContext(); - MenuContext = XUniqueContext(); - - /* initialize some lists */ - Scr.AllBindings = NULL; - Scr.TheList = NULL; - - Scr.menus.all = NULL; - Scr.menus.DefaultStyle = NULL; - Scr.menus.LastStyle = NULL; - Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; - Scr.menus.DoubleClickTime = DEFAULT_MENU_CLICKTIME; - - Scr.DefaultIcon = NULL; - - Scr.StdColors.fore = 0; - Scr.StdColors.back = 0; - Scr.StdRelief.fore = 0; - Scr.StdRelief.back = 0; - Scr.StdGC = 0; - Scr.StdReliefGC = 0; - Scr.StdShadowGC = 0; - Scr.DrawGC = 0; - Scr.hasIconFont = False; - Scr.hasWindowFont = False; - - /* create graphics contexts */ - CreateGCs(); - - Scr.d_depth = DefaultDepth(dpy, Scr.screen); - Scr.FvwmRoot.w = Scr.Root; - Scr.FvwmRoot.next = 0; - - /* RBW - 11/13/1998 - 2 new fields to init - stacking order chain. */ - Scr.FvwmRoot.stack_next = &Scr.FvwmRoot; - Scr.FvwmRoot.stack_prev = &Scr.FvwmRoot; - - XGetWindowAttributes(dpy,Scr.Root,&(Scr.FvwmRoot.attr)); - Scr.root_pushes = 0; - Scr.pushed_window = &Scr.FvwmRoot; - Scr.FvwmRoot.number_cmap_windows = 0; - - - Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); - Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); - - Scr.NoBoundaryWidth = 1; - Scr.BoundaryWidth = BOUNDARY_WIDTH; - Scr.CornerWidth = CORNER_WIDTH; - Scr.Hilite = NULL; - Scr.Focus = NULL; - Scr.PreviousFocus = NULL; - Scr.Ungrabbed = NULL; - - Scr.StdFont.font = NULL; - Scr.IconFont.font = NULL; + FvwmContext = XUniqueContext(); + MenuContext = XUniqueContext(); + + /* initialize some lists */ + Scr.AllBindings = NULL; + Scr.TheList = NULL; + + Scr.menus.all = NULL; + Scr.menus.DefaultStyle = NULL; + Scr.menus.LastStyle = NULL; + Scr.menus.PopupDelay10ms = DEFAULT_POPUP_DELAY; + Scr.menus.DoubleClickTime = DEFAULT_MENU_CLICKTIME; + + Scr.DefaultIcon = NULL; + + Scr.StdColors.fore = 0; + Scr.StdColors.back = 0; + Scr.StdRelief.fore = 0; + Scr.StdRelief.back = 0; + Scr.StdGC = 0; + Scr.StdReliefGC = 0; + Scr.StdShadowGC = 0; + Scr.DrawGC = 0; + Scr.hasIconFont = False; + Scr.hasWindowFont = False; + + /* create graphics contexts */ + CreateGCs(); + + Scr.d_depth = DefaultDepth(dpy, Scr.screen); + Scr.FvwmRoot.w = Scr.Root; + Scr.FvwmRoot.next = 0; + + /* RBW - 11/13/1998 - 2 new fields to init - stacking order chain. */ + Scr.FvwmRoot.stack_next = &Scr.FvwmRoot; + Scr.FvwmRoot.stack_prev = &Scr.FvwmRoot; + + XGetWindowAttributes(dpy, Scr.Root, &(Scr.FvwmRoot.attr)); + Scr.root_pushes = 0; + Scr.pushed_window = &Scr.FvwmRoot; + Scr.FvwmRoot.number_cmap_windows = 0; + + Scr.MyDisplayWidth = DisplayWidth(dpy, Scr.screen); + Scr.MyDisplayHeight = DisplayHeight(dpy, Scr.screen); + + Scr.NoBoundaryWidth = 1; + Scr.BoundaryWidth = BOUNDARY_WIDTH; + Scr.CornerWidth = CORNER_WIDTH; + Scr.Hilite = NULL; + Scr.Focus = NULL; + Scr.PreviousFocus = NULL; + Scr.Ungrabbed = NULL; + + Scr.StdFont.font = NULL; + Scr.IconFont.font = NULL; #ifndef NON_VIRTUAL - Scr.VxMax = 2*Scr.MyDisplayWidth; - Scr.VyMax = 2*Scr.MyDisplayHeight; + Scr.VxMax = 2 * Scr.MyDisplayWidth; + Scr.VyMax = 2 * Scr.MyDisplayHeight; #else - Scr.VxMax = 0; - Scr.VyMax = 0; + Scr.VxMax = 0; + Scr.VyMax = 0; #endif - Scr.Vx = Scr.Vy = 0; - - Scr.SizeWindow = None; - - /* Sets the current desktop number to zero */ - /* Multiple desks are available even in non-virtual - * compilations */ - { - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - unsigned char *prop; - - Scr.CurrentDesk = 0; - if ((XGetWindowProperty(dpy, Scr.Root, _XA_WM_DESKTOP, 0L, 1L, True, - _XA_WM_DESKTOP, &atype, &aformat, &nitems, - &bytes_remain, &prop))==Success) - { - if(prop != NULL) - { - Restarting = True; - Scr.CurrentDesk = *(unsigned long *)prop; - } - } - } - - Scr.EdgeScrollX = Scr.EdgeScrollY = 100; - Scr.ScrollResistance = Scr.MoveResistance = 0; - Scr.SnapAttraction = -1; - Scr.SnapMode = 0; - Scr.SnapGridX = 1; - Scr.SnapGridY = 1; - Scr.OpaqueSize = 5; - /* ClickTime is set to the positive value upon entering the event loop. */ - Scr.ClickTime = -DEFAULT_CLICKTIME; - Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; - - /* set major operating modes */ - Scr.NumBoxes = 0; - - Scr.randomx = Scr.randomy = 0; - Scr.buttons2grab = 7; - - InitFvwmDecor(&Scr.DefaultDecor); + Scr.Vx = Scr.Vy = 0; + + Scr.SizeWindow = None; + + /* Sets the current desktop number to zero */ + /* Multiple desks are available even in non-virtual + * compilations */ + { + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + unsigned char *prop; + + Scr.CurrentDesk = 0; + if ((XGetWindowProperty(dpy, Scr.Root, _XA_WM_DESKTOP, 0L, 1L, + True, _XA_WM_DESKTOP, &atype, &aformat, &nitems, + &bytes_remain, &prop)) == Success) { + if (prop != NULL) { + Restarting = True; + Scr.CurrentDesk = *(unsigned long *)prop; + } + } + } + + Scr.EdgeScrollX = Scr.EdgeScrollY = 100; + Scr.ScrollResistance = Scr.MoveResistance = 0; + Scr.SnapAttraction = -1; + Scr.SnapMode = 0; + Scr.SnapGridX = 1; + Scr.SnapGridY = 1; + Scr.OpaqueSize = 5; + /* ClickTime is set to the positive value upon entering the event loop. + */ + Scr.ClickTime = -DEFAULT_CLICKTIME; + Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE; + + /* set major operating modes */ + Scr.NumBoxes = 0; + + Scr.randomx = Scr.randomy = 0; + Scr.buttons2grab = 7; + + InitFvwmDecor(&Scr.DefaultDecor); #ifdef USEDECOR - Scr.DefaultDecor.tag = "Default"; + Scr.DefaultDecor.tag = "Default"; #endif - Scr.SmartPlacementIsClever = False; - Scr.ClickToFocusPassesClick = True; - Scr.ClickToFocusRaises = True; - Scr.MouseFocusClickRaises = False; - Scr.StipledTitles = False; - - /* RBW - 11/02/1998 */ - Scr.go.ModifyUSP = True; - Scr.go.CaptureHonorsStartsOnPage = True; - Scr.go.RecaptureHonorsStartsOnPage = False; - Scr.go.ActivePlacementHonorsStartsOnPage = False; - - Scr.gs.EmulateMWM = False; - Scr.gs.EmulateWIN = False; - /* Not the right place for this, should only be called once somewhere .. */ - InitPictureCMap(dpy,Scr.Root); - - return; + Scr.SmartPlacementIsClever = False; + Scr.ClickToFocusPassesClick = True; + Scr.ClickToFocusRaises = True; + Scr.MouseFocusClickRaises = False; + Scr.StipledTitles = False; + + /* RBW - 11/02/1998 */ + Scr.go.ModifyUSP = 1U; + Scr.go.CaptureHonorsStartsOnPage = 1U; + Scr.go.RecaptureHonorsStartsOnPage = 0U; + Scr.go.ActivePlacementHonorsStartsOnPage = 0U; + + Scr.gs.EmulateMWM = False; + Scr.gs.EmulateWIN = False; + /* Not the right place for this, should only be called once somewhere .. + */ + InitPictureCMap(dpy, Scr.Root); + + return; } /*********************************************************************** @@ -1418,29 +1356,30 @@ void InitVariables(void) * Reborder - Removes fvwm border windows * ************************************************************************/ -void Reborder(void) +void +Reborder(void) { - FvwmWindow *tmp; /* temp fvwm window structure */ - - /* put a border back around all windows */ - MyXGrabServer (dpy); - - InstallWindowColormaps (&Scr.FvwmRoot); /* force reinstall */ -/* - RBW - 05/15/1998 - Grab the last window and work backwards: preserve stacking order on restart. -*/ - for (tmp = Scr.FvwmRoot.stack_prev; tmp != &Scr.FvwmRoot; tmp = tmp->stack_prev) - { - RestoreWithdrawnLocation (tmp,True); - XUnmapWindow(dpy,tmp->frame); - XDestroyWindow(dpy,tmp->frame); - } - - MyXUngrabServer (dpy); - XSetInputFocus (dpy, PointerRoot, RevertToPointerRoot,CurrentTime); - XSync(dpy,0); + FvwmWindow *tmp; /* temp fvwm window structure */ + + /* put a border back around all windows */ + MyXGrabServer(dpy); + + InstallWindowColormaps(&Scr.FvwmRoot); /* force reinstall */ + /* + RBW - 05/15/1998 + Grab the last window and work backwards: preserve stacking order on + restart. + */ + for (tmp = Scr.FvwmRoot.stack_prev; tmp != &Scr.FvwmRoot; + tmp = tmp->stack_prev) { + RestoreWithdrawnLocation(tmp, True); + XUnmapWindow(dpy, tmp->frame); + XDestroyWindow(dpy, tmp->frame); + } + MyXUngrabServer(dpy); + XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); + XSync(dpy, 0); } /*********************************************************************** @@ -1450,84 +1389,84 @@ void Reborder(void) * *********************************************************************** */ -RETSIGTYPE SigDone(int nonsense) +void +SigDone(int nonsense) { - isTerminated = True; - fvwmRunState = FVWM_DONE; + isTerminated = True; + fvwmRunState = FVWM_DONE; } -void Done(int restart, char *command) +void +Done(int restart, char *command) { - MenuRoot *mr; + MenuRoot *mr; #ifndef NON_VIRTUAL - MoveViewport(0,0,False); + MoveViewport(0, 0, False); #endif - mr = FindPopup("ExitFunction"); - if(mr != NULL) - ExecuteFunction("Function ExitFunction",NULL,&Event,C_ROOT,1); - - /* Close all my pipes */ - ClosePipes(); - - Reborder (); - - if(restart) - { - SaveDesktopState(); /* I wonder why ... */ - - /* Really make sure that the connection is closed and cleared! */ - XSelectInput(dpy, Scr.Root, 0 ); - XSync(dpy, 0); - XCloseDisplay(dpy); - - { - char *my_argv[10]; - int i,done,j; - - i=0; - j=0; - done = 0; - while((g_argv[j] != NULL)&&(i<8)) - { - if(strcmp(g_argv[j],"-s")!=0) - { - my_argv[i] = g_argv[j]; - i++; - j++; - } - else - j++; - } - if(strstr(command,"fvwm")!= NULL) - my_argv[i++] = "-s"; - while(i<10) - my_argv[i++] = NULL; - - /* really need to destroy all windows, explicitly, - * not sleep, but this is adequate for now */ - sleep(1); - ReapChildren(); - execvp(command,my_argv); - } - fvwm_msg(ERR,"Done","Call of '%s' failed!!!! (restarting '%s' instead)", - command, - g_argv[0]); - execvp(g_argv[0], g_argv); /* that _should_ work */ - fvwm_msg(ERR,"Done","Call of '%s' failed!!!!", g_argv[0]); - } - else - { - XCloseDisplay(dpy); - } - exit(0); + mr = FindPopup("ExitFunction"); + if (mr != NULL) + ExecuteFunction( + "Function ExitFunction", NULL, &Event, C_ROOT, 1); + + /* Close all my pipes */ + ClosePipes(); + + Reborder(); + + if (restart) { + SaveDesktopState(); /* I wonder why ... */ + + /* Really make sure that the connection is closed and cleared! + */ + XSelectInput(dpy, Scr.Root, 0); + XSync(dpy, 0); + XCloseDisplay(dpy); + + { + char *my_argv[10]; + int i, j; + + if (strstr(command, "fvwm") != NULL) { + i = 0; + j = 0; + while ((g_argv[j] != NULL) && (i < 8)) { + if (strcmp(g_argv[j], "-s") != 0) { + my_argv[i] = g_argv[j]; + i++; + j++; + } else + j++; + } + my_argv[i++] = "-s"; + while (i < 10) + my_argv[i++] = NULL; + } else { + my_argv[0] = command; + my_argv[1] = NULL; + } + + sleep(1); + ReapChildren(); + execvp(command, my_argv); + } + fvwm_msg(ERR, "Done", + "Call of '%s' failed!!!! (restarting '%s' instead)", + command, g_argv[0]); + execvp(g_argv[0], g_argv); /* that _should_ work */ + fvwm_msg(ERR, "Done", "Call of '%s' failed!!!!", g_argv[0]); + } else { + XCloseDisplay(dpy); + } + exit(0); } -int CatchRedirectError(Display *dpy, XErrorEvent *event) +int +CatchRedirectError(Display *dpy, XErrorEvent *event) { - fvwm_msg(ERR,"CatchRedirectError","another WM is running"); - exit(1); + fvwm_msg(ERR, "CatchRedirectError", "another WM is running"); + exit(1); } /*********************************************************************** @@ -1536,13 +1475,14 @@ int CatchRedirectError(Display *dpy, XErrorEvent *event) * CatchFatal - Shuts down if the server connection is lost * ************************************************************************/ -int CatchFatal(Display *dpy) +int +CatchFatal(Display *dpy) { - /* No action is taken because usually this action is caused by someone - using "xlogout" to be able to switch between multiple window managers - */ - ClosePipes(); - exit(1); + /* No action is taken because usually this action is caused by someone + using "xlogout" to be able to switch between multiple window managers + */ + ClosePipes(); + exit(1); } /*********************************************************************** @@ -1551,37 +1491,36 @@ int CatchFatal(Display *dpy) * FvwmErrorHandler - displays info on internal errors * ************************************************************************/ -int FvwmErrorHandler(Display *dpy, XErrorEvent *event) +int +FvwmErrorHandler(Display *dpy, XErrorEvent *event) { - extern int last_event_type; - - /* some errors are acceptable, mostly they're caused by - * trying to update a lost window */ - if((event->error_code == BadWindow)||(event->request_code == X_GetGeometry)|| - (event->error_code==BadDrawable)||(event->request_code==X_SetInputFocus)|| - (event->request_code==X_GrabButton)|| - (event->request_code==X_ChangeWindowAttributes)|| - (event->request_code == X_InstallColormap)) - return 0 ; - - - fvwm_msg(ERR,"FvwmErrorHandler","*** internal error ***"); - fvwm_msg(ERR,"FvwmErrorHandler","Request %d, Error %d, EventType: %d", - event->request_code, - event->error_code, - last_event_type); - return 0; + extern int last_event_type; + + /* some errors are acceptable, mostly they're caused by + * trying to update a lost window */ + if ((event->error_code == BadWindow) || + (event->request_code == X_GetGeometry) || + (event->error_code == BadDrawable) || + (event->request_code == X_SetInputFocus) || + (event->request_code == X_GrabButton) || + (event->request_code == X_ChangeWindowAttributes) || + (event->request_code == X_InstallColormap)) + return 0; + + fvwm_msg(ERR, "FvwmErrorHandler", "*** internal error ***"); + fvwm_msg(ERR, "FvwmErrorHandler", "Request %d, Error %d, EventType: %d", + event->request_code, event->error_code, last_event_type); + return 0; } -void usage(void) +void +usage(void) { -#if 0 - fvwm_msg(INFO,"usage","\nFvwm Version %s Usage:\n\n",VERSION); - fvwm_msg(INFO,"usage"," %s [-d dpy] [-debug] [-f config_cmd] [-s] [-blackout] [-version] [-h]\n",g_argv[0]); -#else - fprintf(stderr,"\nFvwm Version %s Usage:\n\n",VERSION); - fprintf(stderr," %s [-d dpy] [-debug] [-f config_cmd] [-s] [-blackout] [-version] [-h]\n\n",g_argv[0]); -#endif + fprintf(stderr, "\nFvwm Version %s Usage:\n\n", VERSION); + fprintf(stderr, + " %s [-d dpy] [-debug] [-f config_cmd] [-s] [-blackout] " + "[-version] [-h]\n\n", + g_argv[0]); } /**************************************************************************** @@ -1589,80 +1528,76 @@ void usage(void) * Save Desktop State * ****************************************************************************/ -void SaveDesktopState() +void +SaveDesktopState() { - FvwmWindow *t; - unsigned long data[1]; + FvwmWindow *t; + unsigned long data[1]; - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - data[0] = (unsigned long) t->Desk; - XChangeProperty (dpy, t->w, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, - PropModeReplace, (unsigned char *) data, 1); - } + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + data[0] = (unsigned long)t->Desk; + XChangeProperty(dpy, t->w, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, + PropModeReplace, (unsigned char *)data, 1); + } - data[0] = (unsigned long) Scr.CurrentDesk; - XChangeProperty (dpy, Scr.Root, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, - PropModeReplace, (unsigned char *) data, 1); + data[0] = (unsigned long)Scr.CurrentDesk; + XChangeProperty(dpy, Scr.Root, _XA_WM_DESKTOP, _XA_WM_DESKTOP, 32, + PropModeReplace, (unsigned char *)data, 1); - XSync(dpy, 0); + XSync(dpy, 0); } - -void SetMWM_INFO(Window window) +void +SetMWM_INFO(Window window) { #ifdef MODALITY_IS_EVIL - struct mwminfo - { - long flags; - Window win; - } motif_wm_info; - - /* Set Motif WM_INFO atom to make motif relinquish - * broken handling of modal dialogs */ - motif_wm_info.flags = 2; - motif_wm_info.win = window; - - XChangeProperty(dpy,Scr.Root,_XA_MOTIF_WM,_XA_MOTIF_WM,32, - PropModeReplace,(char *)&motif_wm_info,2); + struct mwminfo { + long flags; + Window win; + } motif_wm_info; + + /* Set Motif WM_INFO atom to make motif relinquish + * broken handling of modal dialogs */ + motif_wm_info.flags = 2; + motif_wm_info.win = window; + + XChangeProperty(dpy, Scr.Root, _XA_MOTIF_WM, _XA_MOTIF_WM, 32, + PropModeReplace, (char *)&motif_wm_info, 2); #endif } -void BlackoutScreen() +void +BlackoutScreen() { - XSetWindowAttributes attributes; - unsigned long valuemask; - - if (Blackout && (BlackoutWin == None) && !debugging) - { - DBUG("BlackoutScreen","Blacking out screen during init..."); - /* blackout screen */ - attributes.border_pixel = BlackPixel(dpy,Scr.screen); - attributes.background_pixel = BlackPixel(dpy,Scr.screen); - attributes.bit_gravity = NorthWestGravity; - attributes.override_redirect = True; /* is override redirect needed? */ - valuemask = CWBorderPixel | - CWBackPixel | - CWBitGravity | - CWOverrideRedirect; - BlackoutWin = XCreateWindow(dpy,Scr.Root,0,0, - DisplayWidth(dpy, Scr.screen), - DisplayHeight(dpy, Scr.screen),0, - CopyFromParent, - CopyFromParent, CopyFromParent, - valuemask,&attributes); - XMapWindow(dpy,BlackoutWin); - XSync(dpy,0); - } + XSetWindowAttributes attributes; + unsigned long valuemask; + + if (Blackout && (BlackoutWin == None) && !debugging) { + DBUG("BlackoutScreen", "Blacking out screen during init..."); + /* blackout screen */ + attributes.border_pixel = BlackPixel(dpy, Scr.screen); + attributes.background_pixel = BlackPixel(dpy, Scr.screen); + attributes.bit_gravity = NorthWestGravity; + attributes.override_redirect = + True; /* is override redirect needed? */ + valuemask = CWBorderPixel | CWBackPixel | CWBitGravity | + CWOverrideRedirect; + BlackoutWin = XCreateWindow(dpy, Scr.Root, 0, 0, + DisplayWidth(dpy, Scr.screen), + DisplayHeight(dpy, Scr.screen), 0, CopyFromParent, + CopyFromParent, CopyFromParent, valuemask, &attributes); + XMapWindow(dpy, BlackoutWin); + XSync(dpy, 0); + } } /* BlackoutScreen */ -void UnBlackoutScreen() +void +UnBlackoutScreen() { - if (Blackout && (BlackoutWin != None) && !debugging) - { - DBUG("UnBlackoutScreen","UnBlacking out screen"); - XDestroyWindow(dpy,BlackoutWin); /* unblacken the screen */ - XSync(dpy,0); - BlackoutWin = None; - } + if (Blackout && (BlackoutWin != None) && !debugging) { + DBUG("UnBlackoutScreen", "UnBlacking out screen"); + XDestroyWindow(dpy, BlackoutWin); /* unblacken the screen */ + XSync(dpy, 0); + BlackoutWin = None; + } } /* UnBlackoutScreen */ Index: fvwm/fvwm/fvwm.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm.h --- fvwm/fvwm/fvwm.h +++ fvwm/fvwm/fvwm.h @@ -29,7 +29,6 @@ /** OR PERFORMANCE OF THIS SOFTWARE. **/ /*****************************************************************************/ - /*********************************************************************** * fvwm include file ***********************************************************************/ @@ -52,55 +51,54 @@ #include -#define BW 1 /* border width */ -#define BOUNDARY_WIDTH 7 /* border width */ -#define CORNER_WIDTH 16 /* border width */ +#define BW 1 /* border width */ +#define BOUNDARY_WIDTH 7 /* border width */ +#define CORNER_WIDTH 16 /* border width */ -# define HEIGHT_EXTRA 4 /* Extra height for texts in popus */ -# define HEIGHT_EXTRA_TITLE 4 /* Extra height for underlining title */ -# define HEIGHT_SEPARATOR 4 /* Height of separator lines */ +#define HEIGHT_EXTRA 4 /* Extra height for texts in popus */ +#define HEIGHT_EXTRA_TITLE 4 /* Extra height for underlining title */ +#define HEIGHT_SEPARATOR 4 /* Height of separator lines */ #ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 #endif -#define NULLSTR ((char *) NULL) +#define NULLSTR ((char *)NULL) /* contexts for button presses */ -#define C_NO_CONTEXT 0x00 -#define C_WINDOW 0x01 -#define C_TITLE 0x02 -#define C_ICON 0x04 -#define C_ROOT 0x08 -#define C_FRAME 0x10 -#define C_SIDEBAR 0x20 -#define C_L1 0x40 -#define C_L2 0x80 -#define C_L3 0x100 -#define C_L4 0x200 -#define C_L5 0x400 -#define C_R1 0x800 -#define C_R2 0x1000 -#define C_R3 0x2000 -#define C_R4 0x4000 -#define C_R5 0x8000 -#define C_RALL (C_R1|C_R2|C_R3|C_R4|C_R5) -#define C_LALL (C_L1|C_L2|C_L3|C_L4|C_L5) -#define C_ALL (C_WINDOW|C_TITLE|C_ICON|C_ROOT|C_FRAME|C_SIDEBAR|\ - C_L1|C_L2|C_L3|C_L4|C_L5|C_R1|C_R2|C_R3|C_R4|C_R5) - -typedef struct MyFont -{ - XFontStruct *font; /* font structure */ - int height; /* height of the font */ - int y; /* Y coordinate to draw characters */ +#define C_NO_CONTEXT 0x00 +#define C_WINDOW 0x01 +#define C_TITLE 0x02 +#define C_ICON 0x04 +#define C_ROOT 0x08 +#define C_FRAME 0x10 +#define C_SIDEBAR 0x20 +#define C_L1 0x40 +#define C_L2 0x80 +#define C_L3 0x100 +#define C_L4 0x200 +#define C_L5 0x400 +#define C_R1 0x800 +#define C_R2 0x1000 +#define C_R3 0x2000 +#define C_R4 0x4000 +#define C_R5 0x8000 +#define C_RALL (C_R1 | C_R2 | C_R3 | C_R4 | C_R5) +#define C_LALL (C_L1 | C_L2 | C_L3 | C_L4 | C_L5) +#define C_ALL \ + (C_WINDOW | C_TITLE | C_ICON | C_ROOT | C_FRAME | C_SIDEBAR | C_L1 |\ + C_L2 | C_L3 | C_L4 | C_L5 | C_R1 | C_R2 | C_R3 | C_R4 | C_R5) + +typedef struct MyFont { + XFontStruct *font; /* font structure */ + int height; /* height of the font */ + int y; /* Y coordinate to draw characters */ } MyFont; -typedef struct ColorPair -{ - Pixel fore; - Pixel back; +typedef struct ColorPair { + Pixel fore; + Pixel back; } ColorPair; #ifdef MINI_ICONS @@ -108,7 +106,7 @@ typedef struct ColorPair #endif #ifdef USEDECOR -struct FvwmDecor; /* definition in screen.h */ +struct FvwmDecor; /* definition in screen.h */ #endif /* @@ -116,174 +114,174 @@ struct FvwmDecor; /* definition in screen.h */ The name list points at the first one in the chain. */ typedef struct icon_boxes_struct { - struct icon_boxes_struct *next; /* next icon_boxes or zero */ - int IconBox[4]; /* x/y x/y for iconbox */ - short IconGrid[2]; /* x incr, y incr */ - unsigned char IconFlags; /* some bits */ - /* IconFill only takes 3 bits. Defaults are top, left, vert co-ord first */ - /* eg: t l = 0,0,0; l t = 0,0,1; b r = 1,1,0 */ -#define ICONFILLBOT (1<<0) -#define ICONFILLRGT (1<<1) -#define ICONFILLHRZ (1<<2) + struct icon_boxes_struct *next; /* next icon_boxes or zero */ + int IconBox[4]; /* x/y x/y for iconbox */ + short IconGrid[2]; /* x incr, y incr */ + unsigned char IconFlags; /* some bits */ + /* IconFill only takes 3 bits. Defaults are top, left, vert co-ord + * first */ + /* eg: t l = 0,0,0; l t = 0,0,1; b r = 1,1,0 */ +#define ICONFILLBOT (1 << 0) +#define ICONFILLRGT (1 << 1) +#define ICONFILLHRZ (1 << 2) } icon_boxes; /* for each window that is on the display, one of these structures * is allocated and linked into a list */ -typedef struct FvwmWindow -{ - struct FvwmWindow *next; /* next fvwm window */ - struct FvwmWindow *prev; /* prev fvwm window */ - struct FvwmWindow *stack_next; /* next (lower) fvwm window in stacking - * order*/ - struct FvwmWindow *stack_prev; /* prev (higher) fvwm window in stacking - * order */ - Window w; /* the child window */ - int old_bw; /* border width before reparenting */ - Window frame; /* the frame window */ - Window Parent; /* Ugly Ugly Ugly - it looks like you - * HAVE to reparent the app window into - * a window whose size = app window, - * or else you can't keep xv and matlab - * happy at the same time! */ - Window title_w; /* the title bar window */ - Window sides[4]; - Window corners[4]; /* Corner pieces */ - int nr_left_buttons; - int nr_right_buttons; - Window left_w[5]; - Window right_w[5]; +typedef struct FvwmWindow { + struct FvwmWindow *next; /* next fvwm window */ + struct FvwmWindow *prev; /* prev fvwm window */ + struct FvwmWindow *stack_next; /* next (lower) fvwm window in stacking + * order*/ + struct FvwmWindow *stack_prev; /* prev (higher) fvwm window in stacking + * order */ + Window w; /* the child window */ + int old_bw; /* border width before reparenting */ + Window frame; /* the frame window */ + Window Parent; /* Ugly Ugly Ugly - it looks like you + * HAVE to reparent the app window into + * a window whose size = app window, + * or else you can't keep xv and matlab + * happy at the same time! */ + Window title_w; /* the title bar window */ + Window sides[4]; + Window corners[4]; /* Corner pieces */ + int nr_left_buttons; + int nr_right_buttons; + Window left_w[5]; + Window right_w[5]; #ifdef USEDECOR - struct FvwmDecor *fl; + struct FvwmDecor *fl; #endif - Window icon_w; /* the icon window */ - Window icon_pixmap_w; /* the icon window */ + Window icon_w; /* the icon window */ + Window icon_pixmap_w; /* the icon window */ #ifdef SHAPE - int wShaped; /* is this a shaped window */ + int wShaped; /* is this a shaped window */ #endif - int frame_x; /* x position of frame */ - int frame_y; /* y position of frame */ - int frame_width; /* width of frame */ - int frame_height; /* height of frame */ - int boundary_width; - int corner_width; - int bw; - int title_x; - int title_y; - int title_height; /* height of the title bar */ - int title_width; /* width of the title bar */ - int icon_x_loc; /* icon window x coordinate */ - int icon_xl_loc; /* icon label window x coordinate */ - int icon_y_loc; /* icon window y coordiante */ - int icon_w_width; /* width of the icon window */ - int icon_w_height; /* height of the icon window */ - int icon_t_width; /* width of the icon title window */ - int icon_p_width; /* width of the icon pixmap window */ - int icon_p_height; /* height of the icon pixmap window */ - Pixmap iconPixmap; /* pixmap for the icon */ - int iconDepth; /* Drawable depth for the icon */ - Pixmap icon_maskPixmap; /* pixmap for the icon mask */ - char *name; /* name of the window */ - char *icon_name; /* name of the icon */ - XWindowAttributes attr; /* the child window attributes */ - XSizeHints hints; /* normal hints */ - XWMHints *wmhints; /* WM hints */ - XClassHint class; - int Desk; /* Tells which desktop this window is on */ - int FocusDesk; /* Where (if at all) was it focussed */ - int DeIconifyDesk; /* Desk to deiconify to, for StubbornIcons */ - Window transientfor; + int frame_x; /* x position of frame */ + int frame_y; /* y position of frame */ + int frame_width; /* width of frame */ + int frame_height; /* height of frame */ + int boundary_width; + int corner_width; + int bw; + int title_x; + int title_y; + int title_height; /* height of the title bar */ + int title_width; /* width of the title bar */ + int icon_x_loc; /* icon window x coordinate */ + int icon_xl_loc; /* icon label window x coordinate */ + int icon_y_loc; /* icon window y coordiante */ + int icon_w_width; /* width of the icon window */ + int icon_w_height; /* height of the icon window */ + int icon_t_width; /* width of the icon title window */ + int icon_p_width; /* width of the icon pixmap window */ + int icon_p_height; /* height of the icon pixmap window */ + Pixmap iconPixmap; /* pixmap for the icon */ + int iconDepth; /* Drawable depth for the icon */ + Pixmap icon_maskPixmap; /* pixmap for the icon mask */ + char *name; /* name of the window */ + char *icon_name; /* name of the icon */ + XWindowAttributes attr; /* the child window attributes */ + XSizeHints hints; /* normal hints */ + XWMHints *wmhints; /* WM hints */ + XClassHint class; + int Desk; /* Tells which desktop this window is on */ + int FocusDesk; /* Where (if at all) was it focussed */ + int DeIconifyDesk; /* Desk to deiconify to, for StubbornIcons */ + Window transientfor; #ifdef GSFR - struct { - start_iconic : 1; - staysontop : 1; - sticky : 1; - listskip : 1; - suppressicon : 1; - noicon_title : 1; - lenience : 1; - sticky_icon : 1; - circulate_skip_icon : 1; - circulateskip : 1; - click_focus : 1; - sloppy_focus : 1; - show_mapping : 1; - - notitle : 1; - noborder : 1; - icon : 1; - startsondesk : 1; - bw : 1; - nobw : 1; - fore_color : 1; - back_color : 1; - random_place : 1; - smart_place : 1; - mwm_button : 1; - mwm_decor : 1; - mwm_functions : 1; - mwm_override : 1; - mwm_border : 1; - decorate_transient : 1; - no_pposition : 1; - ol_decor : 1; + struct { + start_iconic :1; + staysontop :1; + sticky :1; + listskip :1; + suppressicon :1; + noicon_title :1; + lenience :1; + sticky_icon :1; + circulate_skip_icon :1; + circulateskip :1; + click_focus :1; + sloppy_focus :1; + show_mapping :1; + + notitle :1; + noborder :1; + icon :1; + startsondesk :1; + bw :1; + nobw :1; + fore_color :1; + back_color :1; + random_place :1; + smart_place :1; + mwm_button :1; + mwm_decor :1; + mwm_functions :1; + mwm_override :1; + mwm_border :1; + decorate_transient :1; + no_pposition :1; + ol_decor :1; #ifdef MINI_ICONS - miniicon : 1; + miniicon :1; #endif - } new_flags; + } new_flags; #else - unsigned long flags; -/* - RBW - 11/13/1998 - new flags to supplement the flags word, implemented - as named bit fields. -*/ - struct { - unsigned ViewportMoved : 1; /* To prevent double move in MoveViewport. */ - unsigned IconifiedByParent : 1; /* To prevent iconified transients in a - * parent icon from counting for Next */ - } tmpflags; + unsigned long flags; + /* + RBW - 11/13/1998 - new flags to supplement the flags word, implemented + as named bit fields. + */ + struct { + unsigned ViewportMoved:1; /* To prevent double move in MoveViewport. */ + unsigned IconifiedByParent:1; /* To prevent iconified transients in a + * parent icon from counting for Next */ + } tmpflags; #endif /* GSFR */ #ifdef MINI_ICONS - char *mini_pixmap_file; - FvwmPicture *mini_icon; + char *mini_pixmap_file; + FvwmPicture *mini_icon; #endif - char *icon_bitmap_file; - - int orig_x; /* unmaximized x coordinate */ - int orig_y; /* unmaximized y coordinate */ - int orig_wd; /* unmaximized window width */ - int orig_ht; /* unmaximized window height */ - - int xdiff,ydiff; /* used to restore window position on exit*/ - int *mwm_hints; - int ol_hints; - int functions; - Window *cmap_windows; /* Colormap windows property */ - int number_cmap_windows; /* Should generally be 0 */ - Pixel ReliefPixel; - Pixel ShadowPixel; - Pixel TextPixel; - Pixel BackPixel; - unsigned long buttons; - icon_boxes *IconBoxes; /* zero or more iconboxes */ + char *icon_bitmap_file; + + int orig_x; /* unmaximized x coordinate */ + int orig_y; /* unmaximized y coordinate */ + int orig_wd; /* unmaximized window width */ + int orig_ht; /* unmaximized window height */ + + int xdiff, ydiff; /* used to restore window position on exit*/ + int *mwm_hints; + int ol_hints; + int functions; + Window *cmap_windows; /* Colormap windows property */ + int number_cmap_windows; /* Should generally be 0 */ + Pixel ReliefPixel; + Pixel ShadowPixel; + Pixel TextPixel; + Pixel BackPixel; + unsigned long buttons; + icon_boxes *IconBoxes; /* zero or more iconboxes */ } FvwmWindow; /* Window mask for Circulate and Direction functions */ typedef struct WindowConditionMask { - Bool needsCurrentDesk; - Bool needsCurrentPage; - Bool needsName; - Bool needsNotName; - Bool useCirculateHit; - Bool useCirculateHitIcon; - Bool useCirculateSkip; - Bool useCirculateSkipIcon; - unsigned long onFlags; - unsigned long offFlags; - char *name; + Bool needsCurrentDesk; + Bool needsCurrentPage; + Bool needsName; + Bool needsNotName; + Bool useCirculateHit; + Bool useCirculateHitIcon; + Bool useCirculateSkip; + Bool useCirculateSkipIcon; + unsigned long onFlags; + unsigned long offFlags; + char *name; } WindowConditionMask; /*************************************************************************** @@ -291,71 +289,70 @@ typedef struct WindowConditionMask { ***************************************************************************/ /* The first 13 items are mapped directly from the style structure's * flag value, so they MUST correspond to the first 13 entries in misc.h */ -#define STARTICONIC (1<<0) -#define ONTOP (1<<1) /* does window stay on top */ -#define STICKY (1<<2) /* Does window stick to glass? */ -#define WINDOWLISTSKIP (1<<3) -#define SUPPRESSICON (1<<4) -#define NOICON_TITLE (1<<5) -#define Lenience (1<<6) -#define StickyIcon (1<<7) -#define CirculateSkipIcon (1<<8) -#define CirculateSkip (1<<9) -#define ClickToFocus (1<<10) -#define SloppyFocus (1<<11) -#define SHOW_ON_MAP (1<<12) /* switch to desk when it gets mapped? */ -#define ALL_COMMON_FLAGS (STARTICONIC|ONTOP|STICKY|WINDOWLISTSKIP| \ - SUPPRESSICON|NOICON_TITLE|Lenience|StickyIcon| \ - CirculateSkipIcon|CirculateSkip|ClickToFocus| \ - SloppyFocus|SHOW_ON_MAP) - -#define BORDER (1<<13) /* Is this decorated with border*/ -#define TITLE (1<<14) /* Is this decorated with title */ -#define MAPPED (1<<15) /* is it mapped? */ -#define ICONIFIED (1<<16) /* is it an icon now? */ -#define TRANSIENT (1<<17) /* is it a transient window? */ -#define RAISED (1<<18) /* if its a sticky window, needs raising? */ -#define VISIBLE (1<<19) /* is the window fully visible */ -#define ICON_OURS (1<<20) /* is the icon window supplied by the app? */ -#define PIXMAP_OURS (1<<21)/* is the icon pixmap ours to free? */ -#define SHAPED_ICON (1<<22)/* is the icon shaped? */ -#define MAXIMIZED (1<<23)/* is the window maximized? */ -#define DoesWmTakeFocus (1<<24) -#define DoesWmDeleteWindow (1<<25) +#define STARTICONIC (1 << 0) +#define ONTOP (1 << 1) /* does window stay on top */ +#define STICKY (1 << 2) /* Does window stick to glass? */ +#define WINDOWLISTSKIP (1 << 3) +#define SUPPRESSICON (1 << 4) +#define NOICON_TITLE (1 << 5) +#define Lenience (1 << 6) +#define StickyIcon (1 << 7) +#define CirculateSkipIcon (1 << 8) +#define CirculateSkip (1 << 9) +#define ClickToFocus (1 << 10) +#define SloppyFocus (1 << 11) +#define SHOW_ON_MAP (1 << 12) /* switch to desk when it gets mapped? */ +#define ALL_COMMON_FLAGS \ + (STARTICONIC | ONTOP | STICKY | WINDOWLISTSKIP | SUPPRESSICON | \ + NOICON_TITLE | Lenience | StickyIcon | CirculateSkipIcon | \ + CirculateSkip | ClickToFocus | SloppyFocus | SHOW_ON_MAP) + +#define BORDER (1 << 13) /* Is this decorated with border*/ +#define TITLE (1 << 14) /* Is this decorated with title */ +#define MAPPED (1 << 15) /* is it mapped? */ +#define ICONIFIED (1 << 16) /* is it an icon now? */ +#define TRANSIENT (1 << 17) /* is it a transient window? */ +#define RAISED (1 << 18) /* if its a sticky window, needs raising? */ +#define VISIBLE (1 << 19) /* is the window fully visible */ +#define ICON_OURS (1 << 20) /* is the icon window supplied by the app? */ +#define PIXMAP_OURS (1 << 21) /* is the icon pixmap ours to free? */ +#define SHAPED_ICON (1 << 22) /* is the icon shaped? */ +#define MAXIMIZED (1 << 23) /* is the window maximized? */ +#define DoesWmTakeFocus (1 << 24) +#define DoesWmDeleteWindow (1 << 25) /* has the icon been moved by the user? */ -#define ICON_MOVED (1<<26) +#define ICON_MOVED (1 << 26) /* was the icon unmapped, even though the window is still iconified * (Transients) */ -#define ICON_UNMAPPED (1<<27) +#define ICON_UNMAPPED (1 << 27) /* Sent an XMapWindow, but didn't receive a MapNotify yet.*/ -#define MAP_PENDING (1<<28) -#define HintOverride (1<<29) -#define MWMButtons (1<<30) -#define MWMBorders (1<<31) - +#define MAP_PENDING (1 << 28) +#define HintOverride (1 << 29) +#define MWMButtons (1 << 30) +#define MWMBorders (1 << 31) /* flags to suppress/enable title bar buttons */ -#define BUTTON1 1 -#define BUTTON2 2 -#define BUTTON3 4 -#define BUTTON4 8 -#define BUTTON5 16 -#define BUTTON6 32 -#define BUTTON7 64 -#define BUTTON8 128 -#define BUTTON9 256 -#define BUTTON10 512 +#define BUTTON1 1 +#define BUTTON2 2 +#define BUTTON3 4 +#define BUTTON4 8 +#define BUTTON5 16 +#define BUTTON6 32 +#define BUTTON7 64 +#define BUTTON8 128 +#define BUTTON9 256 +#define BUTTON10 512 #ifdef WINDOWSHADE /* we're sticking this at the end of the buttons window member since we don't want to use up any more flag bits */ -#define WSHADE (1<<31) +#define WSHADE (1 << 31) #endif #include extern void Reborder(void); -extern RETSIGTYPE SigDone(int nonsense); -extern RETSIGTYPE Restart(int nonsense); +extern void SigDone(int nonsense); +extern void Restart(int nonsense); extern void Done(int, char *) __attribute__((__noreturn__)); extern void BlackoutScreen(void); extern void UnBlackoutScreen(void); Index: fvwm/fvwm/fvwm_exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_exec.c --- /dev/null +++ fvwm/fvwm/fvwm_exec.c @@ -0,0 +1,169 @@ +/* + * fvwm_exec.c -- privilege-separated execution helper for fvwm(1) + * + * Runs as a separate process that receives exec requests via imsg(3) + * from the main fvwm process, executes them, and reports results. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "config.h" + +/* + * imsg_exec -- structured IPC message types for execution requests. + * + * Message flow: + * fvwm -> helper: IMSG_EXEC_RUN (path + argv + envp) + * helper -> fvwm: IMSG_EXEC_OK (pid of launched child) + * IMSG_EXEC_ERROR (errno + message) + * IMSG_EXEC_EXIT (pid + status, sent on child exit) + */ + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +__dead static void +usage(void) +{ + extern char *__progname; + + fprintf(stderr, "usage: %s\n", __progname); + exit(1); +} + +static void +exec_child(int argc, char **argv, char **envp) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "pledge"); + + closefrom(3); + + if (envp) + execve(argv[0], argv, envp); + else + execv(argv[0], argv); + + err(1, "execv: %s", argv[0]); +} + +int +main(int argc, char **argv) +{ + struct imsgbuf ibuf; + struct imsg imsg; + ssize_t n; + int s; + + if (argc != 1) + usage(); + + if (getenv("FVWM_EXEC_FD") == NULL) + errx(1, "FVWM_EXEC_FD not set"); + + s = (int)strtonum(getenv("FVWM_EXEC_FD"), 0, INT_MAX, NULL); + + signal(SIGPIPE, SIG_IGN); + + imsg_init(&ibuf, s); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + for (;;) { + if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) + err(1, "imsg_read"); + if (n == 0) + break; + + while ((n = imsg_get(&ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_RUN: { + pid_t pid; + char **child_argv; + char **child_envp; + int cargc, envc; + char *data = imsg.data; + + if (imsg.hdr.len < sizeof(int) * 2) { + warnx("short IMSG_EXEC_RUN"); + break; + } + memcpy(&cargc, data, sizeof(int)); + memcpy(&envc, data + sizeof(int), sizeof(int)); + data += sizeof(int) * 2; + + /* Reconstruct argv */ + child_argv = malloc( + (cargc + 1) * sizeof(char *)); + if (child_argv == NULL) + err(1, "malloc"); + for (int i = 0; i < cargc; i++) { + size_t len = strlen(data); + child_argv[i] = data; + data += len + 1; + } + child_argv[cargc] = NULL; + + /* Reconstruct envp */ + child_envp = malloc( + (envc + 1) * sizeof(char *)); + if (child_envp == NULL) + err(1, "malloc"); + for (int i = 0; i < envc; i++) { + size_t len = strlen(data); + child_envp[i] = data; + data += len + 1; + } + child_envp[envc] = NULL; + + pid = fork(); + if (pid == -1) { + warn("fork"); + imsg_compose(&ibuf, IMSG_EXEC_ERROR, + 0, 0, -1, &errno, sizeof(int)); + free(child_argv); + free(child_envp); + break; + } + if (pid == 0) + exec_child(cargc, child_argv, + child_envp); + + free(child_argv); + free(child_envp); + + imsg_compose(&ibuf, IMSG_EXEC_OK, + 0, 0, -1, &pid, sizeof(pid_t)); + imsg_flush(&ibuf); + break; + } + default: + warnx("unknown imsg type %d", + imsg.hdr.type); + break; + } + imsg_free(&imsg); + } + } + + imsg_clear(&ibuf); + close(s); + return 0; +} Index: fvwm/fvwm/fvwm_sandbox.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_sandbox.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_sandbox.h --- /dev/null +++ fvwm/fvwm/fvwm_sandbox.h @@ -0,0 +1,187 @@ +/* + * fvwm_sandbox.h -- common sandbox helper for fvwm processes. + * + * Provides pledge/unveil setup patterns used across the fvwm module set. + * Each module calls only the helpers it needs; there is no "one size fits + * all" policy. + * + * All pledge/unveil calls check return values and fail with diagnostics. + * + * IMPORTANT: Every policy declared here requires verification on a real + * OpenBSD system with ktrace(1) and a full X11 session. + */ + +#ifndef FVWM_SANDBOX_H +#define FVWM_SANDBOX_H + +#ifndef FVWMLIBDIR +#define FVWMLIBDIR "/usr/X11R6/lib/X11/fvwm" +#endif + +/* + * sandbox_x11_only -- process that only needs X11 + stdio + fvwm pipes. + * No filesystem access, no network, no process creation. + * Used by: FvwmAuto, FvwmBanner, FvwmBacker, FvwmIdent, FvwmIconBox, + * FvwmPager, FvwmScroll, FvwmTalk, FvwmWinList + */ +static inline void +sandbox_x11_only(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_x11_config -- X11 + read-only config file access. + * No write, no network, no process creation. + * Used by: FvwmButtons, FvwmIconMan (after config read), + * FvwmForm (after /dev/null open) + */ +static inline void +sandbox_x11_config(const char *progname) +{ + if (pledge("stdio rpath", NULL) == -1) + err(1, "%s: pledge stdio rpath", progname); +} + +/* + * sandbox_save_state -- X11 + write to home directory. + * No network, no process creation. + * Used by: FvwmSave, FvwmSaveDesk + * + * Unveil is set up BEFORE calling this to restrict to the exact file. + */ +static inline void +sandbox_save_state(const char *progname) +{ + if (pledge("stdio rpath wpath cpath", NULL) == -1) + err(1, "%s: pledge stdio rpath wpath cpath", progname); +} + +/* + * sandbox_cpp_preproc -- X11 + fork/exec cpp + tmp + dns. + * Used by: FvwmCpp + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_cpp_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_m4_preproc -- X11 + popen m4 + tmp + dns. + * Used by: FvwmM4 + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_m4_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_xpmroot -- X11-only utility, no filesystem writes. + */ +static inline void +sandbox_xpmroot(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_main_fvwm -- main window manager process. + * After startup: retains proc for module fork, exec for helper launch, + * rpath for config reads. + */ +static inline void +sandbox_main_fvwm(const char *progname) +{ + if (unveil(FVWMLIBDIR, "rx") == -1) + err(1, "%s: unveil %s", progname, FVWMLIBDIR); + if (unveil("/etc/X11/fvwm", "r") == -1) + err(1, "%s: unveil /etc/X11/fvwm", progname); + if (unveil("/tmp", "rwc") == -1) + err(1, "%s: unveil /tmp", progname); + if (unveil(NULL, NULL) == -1) + err(1, "%s: unveil lock", progname); + + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_helper -- fvwm_exec helper process. + * Receives imsg requests, forks children, and execs them. + */ +static inline void +sandbox_exec_helper(const char *progname) +{ + if (pledge("stdio proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_child -- child of the execution helper, about to exec. + */ +static inline void +sandbox_exec_child(const char *progname) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * unveil_tempdir -- unveil the temporary directory (from $TMPDIR or /tmp). + * For modules that create temp files (FvwmCpp, FvwmM4). + */ +static inline void +unveil_tempdir(const char *progname) +{ + const char *tmp; + + tmp = getenv("TMPDIR"); + if (tmp == NULL) + tmp = "/tmp"; + if (unveil(tmp, "rwc") == -1) + err(1, "%s: unveil %s", progname, tmp); +} + +/* + * unveil_home_read -- unveil $HOME for reading only. + */ +static inline void +unveil_home_read(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "r") == -1) + err(1, "%s: unveil %s", progname, home); +} + +/* + * unveil_home_write -- unveil $HOME for read/write/create. + */ +static inline void +unveil_home_write(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "rwc") == -1) + err(1, "%s: unveil %s", progname, home); +} + +#endif /* FVWM_SANDBOX_H */ Index: fvwm/fvwm/fvwmdebug.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwmdebug.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwmdebug.c --- fvwm/fvwm/fvwmdebug.c +++ fvwm/fvwm/fvwmdebug.c @@ -10,9 +10,10 @@ #ifndef _DEBUG_ #define _DEBUG_ +#include + #include "config.h" #include "fvwm.h" -#include /* Don't put this into the #ifdef, since some compilers don't like completely * empty source files. @@ -21,83 +22,148 @@ int DB_DUMMY_EXPORTED_SYMBOL; #ifdef DEBUG /* WI stands for 'window info' */ -void DB_WI_WINDOWS(char *label, FvwmWindow *fw) +void +DB_WI_WINDOWS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, next=0x%x, prev=0x%x, stack_next=0x%x, stack_prev=0x%x\n", label?label:"", fw, fw->next, fw->prev, fw->stack_next, fw->stack_prev); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, next=0x%x, prev=0x%x, stack_next=0x%x, " + "stack_prev=0x%x\n", + label ? label : "", fw, fw->next, fw->prev, fw->stack_next, + fw->stack_prev); + return; } -void DB_WI_SUBWINS(char *label, FvwmWindow *fw) +void +DB_WI_SUBWINS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, frame=0x%x, w=0x%x, parent=0x%x, title_w=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x\n", label?label:"", fw, fw->frame, fw->w, fw->Parent, fw->title_w, fw->icon_w, fw->icon_pixmap_w); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, frame=0x%x, w=0x%x, parent=0x%x, " + "title_w=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x\n", + label ? label : "", fw, fw->frame, fw->w, fw->Parent, fw->title_w, + fw->icon_w, fw->icon_pixmap_w); + return; } -void DB_WI_FRAMEWINS(char *label, FvwmWindow *fw) +void +DB_WI_FRAMEWINS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, side windows: 0x%x 0x%x 0x%x 0x%x, corner windows: 0x%x 0x%x 0x%x 0x%x\n", label?label:"", fw, fw->frame, fw->sides[0], fw->sides[1], fw->sides[2], fw->sides[3], fw->corners[0], fw->corners[1], fw->corners[2], fw->corners[3]); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, side windows: 0x%x 0x%x 0x%x 0x%x, " + "corner windows: 0x%x 0x%x 0x%x 0x%x\n", + label ? label : "", fw, fw->frame, fw->sides[0], fw->sides[1], + fw->sides[2], fw->sides[3], fw->corners[0], fw->corners[1], + fw->corners[2], fw->corners[3]); + return; } -void DB_WI_BUTTONWINS(char *label, FvwmWindow *fw) +void +DB_WI_BUTTONWINS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, left button windows: 0x%x 0x%x 0x%x 0x%x 0x%x, right button windows: 0x%x 0x%x 0x%x 0x%x 0x%x\n", label?label:"", fw, fw->frame, fw->left_w[0], fw->left_w[1], fw->left_w[2], fw->left_w[3], fw->left_w[4], fw->right_w[0], fw->right_w[1], fw->right_w[2], fw->right_w[3], fw->right_w[4]); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, left button windows: 0x%x 0x%x 0x%x " + "0x%x 0x%x, right button windows: 0x%x 0x%x 0x%x 0x%x 0x%x\n", + label ? label : "", fw, fw->frame, fw->left_w[0], fw->left_w[1], + fw->left_w[2], fw->left_w[3], fw->left_w[4], fw->right_w[0], + fw->right_w[1], fw->right_w[2], fw->right_w[3], fw->right_w[4]); + return; } -void DB_WI_FRAME(char *label, FvwmWindow *fw) +void +DB_WI_FRAME(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, frame=0x%x, name=%s, flags=0x%08x, frame_x=%d, frame_y=%d, frame_width=%d, frame_height=%d, orig_x=%d, orig_y=%d, orig_wd=%d, orig_ht=%d\n", label?label:"", fw, fw->frame, fw->name?fw->name:"(NULL)",fw->flags,fw->frame_x, fw->frame_y, fw->frame_width, fw->frame_height, fw->orig_x, fw->orig_y, fw->orig_wd, fw->orig_ht); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, frame=0x%x, name=%s, flags=0x%08x, " + "frame_x=%d, frame_y=%d, frame_width=%d, frame_height=%d, " + "orig_x=%d, orig_y=%d, orig_wd=%d, orig_ht=%d\n", + label ? label : "", fw, fw->frame, fw->name ? fw->name : "(NULL)", + fw->flags, fw->frame_x, fw->frame_y, fw->frame_width, + fw->frame_height, fw->orig_x, fw->orig_y, fw->orig_wd, fw->orig_ht); + return; } -void DB_WI_ICON(char *label, FvwmWindow *fw) +void +DB_WI_ICON(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x, icon_x_loc=%d, icon_xl_loc=%d, icon_y_loc=%d, icon_w_width=%d, icon_w_height=%d, icon_t_width=%d, icon_p_width=%d, icon_p_height=%d, icon_name=%d\n", label?label:"", fw, fw->icon_w, fw->icon_pixmap_w,fw->icon_x_loc,fw->icon_xl_loc,fw->icon_y_loc,fw->icon_w_width,fw->icon_w_height,fw->icon_t_width,fw->icon_p_width,fw->icon_p_height,fw->icon_name); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, icon_w=0x%x, icon_pixmap_w=0x%x, " + "icon_x_loc=%d, icon_xl_loc=%d, icon_y_loc=%d, " + "icon_w_width=%d, icon_w_height=%d, icon_t_width=%d, " + "icon_p_width=%d, icon_p_height=%d, icon_name=%d\n", + label ? label : "", fw, fw->icon_w, fw->icon_pixmap_w, + fw->icon_x_loc, fw->icon_xl_loc, fw->icon_y_loc, fw->icon_w_width, + fw->icon_w_height, fw->icon_t_width, fw->icon_p_width, + fw->icon_p_height, fw->icon_name); + return; } -void DB_WI_SIZEHINTS(char *label, FvwmWindow *fw) +void +DB_WI_SIZEHINTS(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, base_width=%d, base_height=%d, width_inc=%d, height_inc=%d, min_width=%d, max_width=%d, min_height=%d, max_height=%d, win_gravity=0x%x", label?label:"", fw, fw->hints.flags, fw->hints.base_width, fw->hints.base_height, fw->hints.width_inc, fw->hints.height_inc, fw->hints.min_width, fw->hints.max_width, fw->hints.min_height, fw->hints.max_height, fw->hints.win_gravity); - if (fw->hints.flags & PAspect) fprintf(stderr,"max_aspect.x=%d, max_aspect.y=%d, min_aspect.x=%d, min_aspect.y=%d", fw->hints.max_aspect.x, fw->hints.max_aspect.y, fw->hints.min_aspect.x, fw->hints.min_aspect.y); - fprintf(stderr,"\n"); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, base_width=%d, base_height=%d, " + "width_inc=%d, height_inc=%d, min_width=%d, max_width=%d, " + "min_height=%d, max_height=%d, win_gravity=0x%x", + label ? label : "", fw, fw->hints.flags, fw->hints.base_width, + fw->hints.base_height, fw->hints.width_inc, fw->hints.height_inc, + fw->hints.min_width, fw->hints.max_width, fw->hints.min_height, + fw->hints.max_height, fw->hints.win_gravity); + if (fw->hints.flags & PAspect) + fprintf(stderr, + "max_aspect.x=%d, max_aspect.y=%d, min_aspect.x=%d, " + "min_aspect.y=%d", + fw->hints.max_aspect.x, fw->hints.max_aspect.y, + fw->hints.min_aspect.x, fw->hints.min_aspect.y); + fprintf(stderr, "\n"); + return; } -void DB_WI_TITLE(char *label, FvwmWindow *fw) +void +DB_WI_TITLE(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, name=%s, icon_name=%s, title_x=%d, title_y=%d, title_width=%d, title_height=%d\n", label?label:"", fw, fw->name?fw->name:"(NULL)", fw->icon_name?fw->icon_name:"(NULL)", fw->title_x, fw->title_y, fw->title_width, fw->title_height); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, name=%s, icon_name=%s, title_x=%d, " + "title_y=%d, title_width=%d, title_height=%d\n", + label ? label : "", fw, fw->name ? fw->name : "(NULL)", + fw->icon_name ? fw->icon_name : "(NULL)", fw->title_x, fw->title_y, + fw->title_width, fw->title_height); + return; } -void DB_WI_BORDER(char *label, FvwmWindow *fw) +void +DB_WI_BORDER(char *label, FvwmWindow *fw) { - fprintf(stderr, "%s: FvwmWindow=0x%x, bw=%d, old_bw=%d, boundary_width=%d, corner_width=%d\n", label?label:"", fw, fw->bw, fw->old_bw, fw->boundary_width, fw->corner_width); - return; + fprintf(stderr, + "%s: FvwmWindow=0x%x, bw=%d, old_bw=%d, boundary_width=%d, " + "corner_width=%d\n", + label ? label : "", fw, fw->bw, fw->old_bw, fw->boundary_width, + fw->corner_width); + return; } -void DB_WI_XWINATTR(char *label, FvwmWindow *fw) +void +DB_WI_XWINATTR(char *label, FvwmWindow *fw) { - /* too much work for now */ - return; + /* too much work for now */ + return; } -void DB_WI_ALL(char *label, FvwmWindow *fw) +void +DB_WI_ALL(char *label, FvwmWindow *fw) { - fprintf(stderr,"%s: --- all fvwm window values for fw=0x%x ---\n", label,fw); - DB_WI_WINDOWS("",fw); - DB_WI_SUBWINS("",fw); - DB_WI_BUTTONWINS("",fw); - DB_WI_FRAMEWINS("",fw); - DB_WI_FRAME("",fw); - DB_WI_ICON("",fw); - DB_WI_SIZEHINTS("",fw); - DB_WI_TITLE("",fw); - DB_WI_BORDER("",fw); - DB_WI_XWINATTR("",fw); - fprintf(stderr,"%s: ---------- end ----------\n",label); - return; + fprintf(stderr, "%s: --- all fvwm window values for fw=0x%x ---\n", + label, fw); + DB_WI_WINDOWS("", fw); + DB_WI_SUBWINS("", fw); + DB_WI_BUTTONWINS("", fw); + DB_WI_FRAMEWINS("", fw); + DB_WI_FRAME("", fw); + DB_WI_ICON("", fw); + DB_WI_SIZEHINTS("", fw); + DB_WI_TITLE("", fw); + DB_WI_BORDER("", fw); + DB_WI_XWINATTR("", fw); + fprintf(stderr, "%s: ---------- end ----------\n", label); + return; } #endif Index: fvwm/fvwm/fvwmdebug.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwmdebug.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwmdebug.h --- fvwm/fvwm/fvwmdebug.h +++ fvwm/fvwm/fvwmdebug.h @@ -14,17 +14,17 @@ void DB_WI_BORDER(char *label, FvwmWindow *fw); void DB_WI_XWINATTR(char *label, FvwmWindow *fw); void DB_WI_ALL(char *label, FvwmWindow *fw); #else -#define DB_WI_WINDOWS(x,y) -#define DB_WI_SUBWINS(x,y) -#define DB_WI_FRAMEWINS(x,y) -#define DB_WI_BUTTONWINS(x,y) -#define DB_WI_FRAME(x,y) -#define DB_WI_ICON(x,y) -#define DB_WI_SIZEHINTS(x,y) -#define DB_WI_TITLE(x,y) -#define DB_WI_BORDER(x,y) -#define DB_WI_XWINATTR(x,y) -#define DB_WI_ALL(x,y) +#define DB_WI_WINDOWS(x, y) +#define DB_WI_SUBWINS(x, y) +#define DB_WI_FRAMEWINS(x, y) +#define DB_WI_BUTTONWINS(x, y) +#define DB_WI_FRAME(x, y) +#define DB_WI_ICON(x, y) +#define DB_WI_SIZEHINTS(x, y) +#define DB_WI_TITLE(x, y) +#define DB_WI_BORDER(x, y) +#define DB_WI_XWINATTR(x, y) +#define DB_WI_ALL(x, y) #endif #endif /* _DEBUG_ */ Index: fvwm/fvwm/icons.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/icons.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/icons.c --- fvwm/fvwm/icons.c +++ fvwm/fvwm/icons.c @@ -11,12 +11,12 @@ * ***********************************************************************/ -#include "config.h" - -#include -#include #include +#include #include +#include + +#include "config.h" #ifdef NeXT #include @@ -28,15 +28,14 @@ #endif /* XPM */ #include "fvwm.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" #ifdef SHAPE #include #endif /* SHAPE */ - void GrabIconButtons(FvwmWindow *, Window); void GrabIconKeys(FvwmWindow *, Window); @@ -45,148 +44,139 @@ void GrabIconKeys(FvwmWindow *, Window); * Creates an icon window as needed * ****************************************************************************/ -void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y) +void +CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y) { - int final_x, final_y; - unsigned long valuemask; /* mask for create windows */ - XSetWindowAttributes attributes; /* attributes for create windows */ + int final_x, final_y; + unsigned long valuemask; /* mask for create windows */ + XSetWindowAttributes attributes; /* attributes for create windows */ - tmp_win->flags |= ICON_OURS; - tmp_win->flags &= ~PIXMAP_OURS; - tmp_win->flags &= ~SHAPED_ICON; - tmp_win->icon_pixmap_w = None; - tmp_win->iconPixmap = None; - tmp_win->iconDepth = 0; + tmp_win->flags |= ICON_OURS; + tmp_win->flags &= ~PIXMAP_OURS; + tmp_win->flags &= ~SHAPED_ICON; + tmp_win->icon_pixmap_w = None; + tmp_win->iconPixmap = None; + tmp_win->iconDepth = 0; - if(tmp_win->flags & SUPPRESSICON) - return; + if (tmp_win->flags & SUPPRESSICON) + return; - /* First, see if it was specified in the .fvwmrc */ - tmp_win->icon_p_height = 0; - tmp_win->icon_p_width = 0; + /* First, see if it was specified in the .fvwmrc */ + tmp_win->icon_p_height = 0; + tmp_win->icon_p_width = 0; - /* First, check for a monochrome bitmap */ - if(tmp_win->icon_bitmap_file != NULL) - GetBitmapFile(tmp_win); + /* First, check for a monochrome bitmap */ + if (tmp_win->icon_bitmap_file != NULL) + GetBitmapFile(tmp_win); #ifdef XPM - /* Next, check for a color pixmap */ - if((tmp_win->icon_bitmap_file != NULL)&& - (tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0)) - GetXPMFile(tmp_win); + /* Next, check for a color pixmap */ + if ((tmp_win->icon_bitmap_file != NULL) && + (tmp_win->icon_p_height == 0) && (tmp_win->icon_p_width == 0)) + GetXPMFile(tmp_win); #endif /* XPM */ - /* Next, See if the app supplies its own icon window */ - if((tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0)&& - (tmp_win->wmhints) && (tmp_win->wmhints->flags & IconWindowHint)) - GetIconWindow(tmp_win); - - /* Finally, try to get icon bitmap from the application */ - if((tmp_win->icon_p_height == 0)&&(tmp_win->icon_p_width == 0)&& - (tmp_win->wmhints)&&(tmp_win->wmhints->flags & IconPixmapHint)) - GetIconBitmap(tmp_win); - - /* figure out the icon window size */ - if (!(tmp_win->flags & NOICON_TITLE)||(tmp_win->icon_p_height == 0)) - { - tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font, - tmp_win->icon_name, - strlen(tmp_win->icon_name)); - tmp_win->icon_w_height = ICON_HEIGHT; - } - else - { - tmp_win->icon_t_width = 0; - tmp_win->icon_w_height = 0; - } - if((tmp_win->flags & ICON_OURS)&&(tmp_win->icon_p_height >0)) - { - tmp_win->icon_p_width += 4; - tmp_win->icon_p_height +=4; - } - - if(tmp_win->icon_p_width == 0) - tmp_win->icon_p_width = tmp_win->icon_t_width+6; - tmp_win->icon_w_width = tmp_win->icon_p_width; - - final_x = def_x; - final_y = def_y; - if(final_x <0) - final_x = 0; - if(final_y <0) - final_y = 0; - - if(final_x + tmp_win->icon_w_width >=Scr.MyDisplayWidth) - final_x = Scr.MyDisplayWidth - tmp_win->icon_w_width-1; - if(final_y + tmp_win->icon_w_height >=Scr.MyDisplayHeight) - final_y = Scr.MyDisplayHeight - tmp_win->icon_w_height-1; - - tmp_win->icon_x_loc = final_x; - tmp_win->icon_xl_loc = final_x; - tmp_win->icon_y_loc = final_y; - - /* clip to fit on screen */ - attributes.background_pixel = Scr.StdColors.back; - valuemask = CWBorderPixel | CWCursor | CWEventMask | CWBackPixel; - attributes.border_pixel = Scr.StdColors.fore; - attributes.cursor = Scr.FvwmCursors[DEFAULT]; - attributes.event_mask = (ButtonPressMask | ButtonReleaseMask | - VisibilityChangeMask | - ExposureMask | KeyPressMask|EnterWindowMask | - FocusChangeMask ); - if (!(tmp_win->flags & NOICON_TITLE)||(tmp_win->icon_p_height == 0)) - tmp_win->icon_w = - XCreateWindow(dpy, Scr.Root, final_x, final_y+tmp_win->icon_p_height, - tmp_win->icon_w_width, tmp_win->icon_w_height,0, - CopyFromParent, - CopyFromParent,CopyFromParent,valuemask,&attributes); - - if((tmp_win->flags & ICON_OURS)&&(tmp_win->icon_p_width>0)&& - (tmp_win->icon_p_height>0)) - { - tmp_win->icon_pixmap_w = - XCreateWindow(dpy, Scr.Root, final_x, final_y, tmp_win->icon_p_width, - tmp_win->icon_p_height, 0, CopyFromParent, - CopyFromParent,CopyFromParent,valuemask,&attributes); - } - else - { - attributes.event_mask = (ButtonPressMask | ButtonReleaseMask | - VisibilityChangeMask | - KeyPressMask|EnterWindowMask | - FocusChangeMask | LeaveWindowMask ); - - valuemask = CWEventMask; - XChangeWindowAttributes(dpy,tmp_win->icon_pixmap_w, - valuemask,&attributes); - } + /* Next, See if the app supplies its own icon window */ + if ((tmp_win->icon_p_height == 0) && (tmp_win->icon_p_width == 0) && + (tmp_win->wmhints) && (tmp_win->wmhints->flags & IconWindowHint)) + GetIconWindow(tmp_win); + + /* Finally, try to get icon bitmap from the application */ + if ((tmp_win->icon_p_height == 0) && (tmp_win->icon_p_width == 0) && + (tmp_win->wmhints) && (tmp_win->wmhints->flags & IconPixmapHint)) + GetIconBitmap(tmp_win); + + /* figure out the icon window size */ + if (!(tmp_win->flags & NOICON_TITLE) || (tmp_win->icon_p_height == 0)) { + tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font, + tmp_win->icon_name, strlen(tmp_win->icon_name)); + tmp_win->icon_w_height = ICON_HEIGHT; + } else { + tmp_win->icon_t_width = 0; + tmp_win->icon_w_height = 0; + } + if ((tmp_win->flags & ICON_OURS) && (tmp_win->icon_p_height > 0)) { + tmp_win->icon_p_width += 4; + tmp_win->icon_p_height += 4; + } + if (tmp_win->icon_p_width == 0) + tmp_win->icon_p_width = tmp_win->icon_t_width + 6; + tmp_win->icon_w_width = tmp_win->icon_p_width; + + final_x = def_x; + final_y = def_y; + if (final_x < 0) + final_x = 0; + if (final_y < 0) + final_y = 0; + + if (final_x + tmp_win->icon_w_width >= Scr.MyDisplayWidth) + final_x = Scr.MyDisplayWidth - tmp_win->icon_w_width - 1; + if (final_y + tmp_win->icon_w_height >= Scr.MyDisplayHeight) + final_y = Scr.MyDisplayHeight - tmp_win->icon_w_height - 1; + + tmp_win->icon_x_loc = final_x; + tmp_win->icon_xl_loc = final_x; + tmp_win->icon_y_loc = final_y; + + /* clip to fit on screen */ + attributes.background_pixel = Scr.StdColors.back; + valuemask = CWBorderPixel | CWCursor | CWEventMask | CWBackPixel; + attributes.border_pixel = Scr.StdColors.fore; + attributes.cursor = Scr.FvwmCursors[DEFAULT]; + attributes.event_mask = + (ButtonPressMask | ButtonReleaseMask | VisibilityChangeMask | + ExposureMask | KeyPressMask | EnterWindowMask | + FocusChangeMask); + if (!(tmp_win->flags & NOICON_TITLE) || (tmp_win->icon_p_height == 0)) + tmp_win->icon_w = XCreateWindow(dpy, Scr.Root, final_x, + final_y + tmp_win->icon_p_height, tmp_win->icon_w_width, + tmp_win->icon_w_height, 0, CopyFromParent, CopyFromParent, + CopyFromParent, valuemask, &attributes); + + if ((tmp_win->flags & ICON_OURS) && (tmp_win->icon_p_width > 0) && + (tmp_win->icon_p_height > 0)) { + tmp_win->icon_pixmap_w = XCreateWindow(dpy, Scr.Root, final_x, + final_y, tmp_win->icon_p_width, tmp_win->icon_p_height, 0, + CopyFromParent, CopyFromParent, CopyFromParent, valuemask, + &attributes); + } else { + attributes.event_mask = + (ButtonPressMask | ButtonReleaseMask | + VisibilityChangeMask | KeyPressMask | EnterWindowMask | + FocusChangeMask | LeaveWindowMask); + + valuemask = CWEventMask; + XChangeWindowAttributes( + dpy, tmp_win->icon_pixmap_w, valuemask, &attributes); + } #ifdef XPM #ifdef SHAPE - if (ShapesSupported && (tmp_win->flags & SHAPED_ICON)) - { - XShapeCombineMask(dpy, tmp_win->icon_pixmap_w, ShapeBounding,2, 2, - tmp_win->icon_maskPixmap, ShapeSet); - } + if (ShapesSupported && (tmp_win->flags & SHAPED_ICON)) { + XShapeCombineMask(dpy, tmp_win->icon_pixmap_w, ShapeBounding, 2, + 2, tmp_win->icon_maskPixmap, ShapeSet); + } #endif #endif - if(tmp_win->icon_w != None) - { - XSaveContext(dpy, tmp_win->icon_w, FvwmContext, (caddr_t)tmp_win); - XDefineCursor(dpy, tmp_win->icon_w, Scr.FvwmCursors[DEFAULT]); - GrabIconButtons(tmp_win,tmp_win->icon_w); - GrabIconKeys(tmp_win,tmp_win->icon_w); - } - if(tmp_win->icon_pixmap_w != None) - { - XSaveContext(dpy, tmp_win->icon_pixmap_w, FvwmContext, (caddr_t)tmp_win); - XDefineCursor(dpy, tmp_win->icon_pixmap_w, Scr.FvwmCursors[DEFAULT]); - GrabIconButtons(tmp_win,tmp_win->icon_pixmap_w); - GrabIconKeys(tmp_win,tmp_win->icon_pixmap_w); - } - return; + if (tmp_win->icon_w != None) { + XSaveContext( + dpy, tmp_win->icon_w, FvwmContext, (caddr_t)tmp_win); + XDefineCursor(dpy, tmp_win->icon_w, Scr.FvwmCursors[DEFAULT]); + GrabIconButtons(tmp_win, tmp_win->icon_w); + GrabIconKeys(tmp_win, tmp_win->icon_w); + } + if (tmp_win->icon_pixmap_w != None) { + XSaveContext( + dpy, tmp_win->icon_pixmap_w, FvwmContext, (caddr_t)tmp_win); + XDefineCursor( + dpy, tmp_win->icon_pixmap_w, Scr.FvwmCursors[DEFAULT]); + GrabIconButtons(tmp_win, tmp_win->icon_pixmap_w); + GrabIconKeys(tmp_win, tmp_win->icon_pixmap_w); + } + return; } /**************************************************************************** @@ -194,136 +184,133 @@ void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y) * Draws the icon window * ****************************************************************************/ -void DrawIconWindow(FvwmWindow *Tmp_win) +void +DrawIconWindow(FvwmWindow *Tmp_win) { - GC Shadow, Relief; - Pixel TextColor,BackColor; - int x ; - - if(Tmp_win->flags & SUPPRESSICON) - return; - - if(Tmp_win->icon_w != None) - flush_expose (Tmp_win->icon_w); - if(Tmp_win->icon_pixmap_w != None) - flush_expose (Tmp_win->icon_pixmap_w); - - if(Scr.Hilite == Tmp_win) - { - if(Scr.d_depth < 2) { - Relief = - Shadow = Scr.DefaultDecor.HiShadowGC; - TextColor = Scr.DefaultDecor.HiColors.fore; - BackColor = Scr.DefaultDecor.HiColors.back; - } else { - Relief = GetDecor(Tmp_win,HiReliefGC); - Shadow = GetDecor(Tmp_win,HiShadowGC); - TextColor = GetDecor(Tmp_win,HiColors.fore); - BackColor = GetDecor(Tmp_win,HiColors.back); - } - /* resize the icon name window */ - if(Tmp_win->icon_w != None) - { - Tmp_win->icon_w_width = Tmp_win->icon_t_width+6; - if(Tmp_win->icon_w_width < Tmp_win->icon_p_width) - Tmp_win->icon_w_width = Tmp_win->icon_p_width; - Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc - - (Tmp_win->icon_w_width - Tmp_win->icon_p_width)/2; - /* start keep label on screen. dje 8/7/97 */ - if (Tmp_win->icon_xl_loc < 0) { /* if new loc neg (off left edge) */ - Tmp_win->icon_xl_loc = 0; /* move to edge */ - } else { /* if not on left edge */ - /* if (new loc + width) > screen width (off edge on right) */ - if ((Tmp_win->icon_xl_loc + Tmp_win->icon_w_width) > - Scr.MyDisplayWidth) { /* off right */ - /* position up against right edge */ - Tmp_win->icon_xl_loc = Scr.MyDisplayWidth - Tmp_win->icon_w_width; - } - /* end keep label on screen. dje 8/7/97 */ - } - } - } - else - { - if(Scr.d_depth < 2) - { - Relief = Scr.StdReliefGC; - Shadow = Scr.StdShadowGC; + GC Shadow, Relief; + Pixel TextColor, BackColor; + int x; + + if (Tmp_win->flags & SUPPRESSICON) + return; + + if (Tmp_win->icon_w != None) + flush_expose(Tmp_win->icon_w); + if (Tmp_win->icon_pixmap_w != None) + flush_expose(Tmp_win->icon_pixmap_w); + + if (Scr.Hilite == Tmp_win) { + if (Scr.d_depth < 2) { + Relief = Shadow = Scr.DefaultDecor.HiShadowGC; + TextColor = Scr.DefaultDecor.HiColors.fore; + BackColor = Scr.DefaultDecor.HiColors.back; + } else { + Relief = GetDecor(Tmp_win, HiReliefGC); + Shadow = GetDecor(Tmp_win, HiShadowGC); + TextColor = GetDecor(Tmp_win, HiColors.fore); + BackColor = GetDecor(Tmp_win, HiColors.back); + } + /* resize the icon name window */ + if (Tmp_win->icon_w != None) { + Tmp_win->icon_w_width = Tmp_win->icon_t_width + 6; + if (Tmp_win->icon_w_width < Tmp_win->icon_p_width) + Tmp_win->icon_w_width = Tmp_win->icon_p_width; + Tmp_win->icon_xl_loc = + Tmp_win->icon_x_loc - + (Tmp_win->icon_w_width - Tmp_win->icon_p_width) / 2; + /* start keep label on screen. dje 8/7/97 */ + if (Tmp_win->icon_xl_loc < + 0) { /* if new loc neg (off left edge) */ + Tmp_win->icon_xl_loc = 0; /* move to edge */ + } else { /* if not on left edge */ + /* if (new loc + width) > screen width (off edge + * on right) */ + if ((Tmp_win->icon_xl_loc + + Tmp_win->icon_w_width) > + Scr.MyDisplayWidth) { /* off right */ + /* position up against right edge */ + Tmp_win->icon_xl_loc = + Scr.MyDisplayWidth - + Tmp_win->icon_w_width; + } + /* end keep label on screen. dje 8/7/97 */ + } + } + } else { + if (Scr.d_depth < 2) { + Relief = Scr.StdReliefGC; + Shadow = Scr.StdShadowGC; + } else { + Globalgcv.foreground = Tmp_win->ReliefPixel; + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + Relief = Scr.ScratchGC1; + + Globalgcv.foreground = Tmp_win->ShadowPixel; + XChangeGC(dpy, Scr.ScratchGC2, Globalgcm, &Globalgcv); + Shadow = Scr.ScratchGC2; + } + /* resize the icon name window */ + if (Tmp_win->icon_w != None) { + Tmp_win->icon_w_width = Tmp_win->icon_p_width; + Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc; + } + TextColor = Tmp_win->TextPixel; + BackColor = Tmp_win->BackPixel; } - else - { - Globalgcv.foreground = Tmp_win->ReliefPixel; - Globalgcm = GCForeground; - XChangeGC(dpy,Scr.ScratchGC1,Globalgcm,&Globalgcv); - Relief = Scr.ScratchGC1; - - Globalgcv.foreground = Tmp_win->ShadowPixel; - XChangeGC(dpy,Scr.ScratchGC2,Globalgcm,&Globalgcv); - Shadow = Scr.ScratchGC2; + if ((Tmp_win->flags & ICON_OURS) && (Tmp_win->icon_pixmap_w != None)) + XSetWindowBackground(dpy, Tmp_win->icon_pixmap_w, BackColor); + if (Tmp_win->icon_w != None) + XSetWindowBackground(dpy, Tmp_win->icon_w, BackColor); + + /* write the icon label */ + NewFontAndColor(Scr.IconFont.font->fid, TextColor, BackColor); + + if (Tmp_win->icon_pixmap_w != None) + XMoveWindow(dpy, Tmp_win->icon_pixmap_w, Tmp_win->icon_x_loc, + Tmp_win->icon_y_loc); + if (Tmp_win->icon_w != None) { + Tmp_win->icon_w_height = ICON_HEIGHT; + XMoveResizeWindow(dpy, Tmp_win->icon_w, Tmp_win->icon_xl_loc, + Tmp_win->icon_y_loc + Tmp_win->icon_p_height, + Tmp_win->icon_w_width, ICON_HEIGHT); + + XClearWindow(dpy, Tmp_win->icon_w); } - /* resize the icon name window */ - if(Tmp_win->icon_w != None) - { - Tmp_win->icon_w_width = Tmp_win->icon_p_width; - Tmp_win->icon_xl_loc = Tmp_win->icon_x_loc; - } - TextColor = Tmp_win->TextPixel; - BackColor = Tmp_win->BackPixel; - - } - if((Tmp_win->flags & ICON_OURS)&&(Tmp_win->icon_pixmap_w != None)) - XSetWindowBackground(dpy,Tmp_win->icon_pixmap_w, - BackColor); - if(Tmp_win->icon_w != None) - XSetWindowBackground(dpy,Tmp_win->icon_w,BackColor); - - /* write the icon label */ - NewFontAndColor(Scr.IconFont.font->fid,TextColor,BackColor); - - if(Tmp_win->icon_pixmap_w != None) - XMoveWindow(dpy,Tmp_win->icon_pixmap_w,Tmp_win->icon_x_loc, - Tmp_win->icon_y_loc); - if(Tmp_win->icon_w != None) - { - Tmp_win->icon_w_height = ICON_HEIGHT; - XMoveResizeWindow(dpy, Tmp_win->icon_w, Tmp_win->icon_xl_loc, - Tmp_win->icon_y_loc+Tmp_win->icon_p_height, - Tmp_win->icon_w_width,ICON_HEIGHT); - - XClearWindow(dpy,Tmp_win->icon_w); - } - - if((Tmp_win->iconPixmap != None)&&(!(Tmp_win->flags & SHAPED_ICON))) - RelieveWindow(Tmp_win,Tmp_win->icon_pixmap_w,0,0, - Tmp_win->icon_p_width, Tmp_win->icon_p_height, - Relief,Shadow, FULL_HILITE); - - /* need to locate the icon pixmap */ - if(Tmp_win->iconPixmap != None) - { - if(Tmp_win->iconDepth == Scr.d_depth) - { - XCopyArea(dpy,Tmp_win->iconPixmap,Tmp_win->icon_pixmap_w,Scr.ScratchGC3, - 0,0,Tmp_win->icon_p_width-4, Tmp_win->icon_p_height-4,2,2); + + if ((Tmp_win->iconPixmap != None) && (!(Tmp_win->flags & SHAPED_ICON))) + RelieveWindow(Tmp_win, Tmp_win->icon_pixmap_w, 0, 0, + Tmp_win->icon_p_width, Tmp_win->icon_p_height, Relief, + Shadow, FULL_HILITE); + + /* need to locate the icon pixmap */ + if (Tmp_win->iconPixmap != None) { + if (Tmp_win->iconDepth == Scr.d_depth) { + XCopyArea(dpy, Tmp_win->iconPixmap, + Tmp_win->icon_pixmap_w, Scr.ScratchGC3, 0, 0, + Tmp_win->icon_p_width - 4, + Tmp_win->icon_p_height - 4, 2, 2); + } else + XCopyPlane(dpy, Tmp_win->iconPixmap, + Tmp_win->icon_pixmap_w, Scr.ScratchGC3, 0, 0, + Tmp_win->icon_p_width - 4, + Tmp_win->icon_p_height - 4, 2, 2, 1); + } + + if (Tmp_win->icon_w != None) { + /* text position */ + x = (Tmp_win->icon_w_width - Tmp_win->icon_t_width) / 2; + if (x < 3) + x = 3; + + XDrawString(dpy, Tmp_win->icon_w, Scr.ScratchGC3, x, + Tmp_win->icon_w_height - Scr.IconFont.height + + Scr.IconFont.y - 3, + Tmp_win->icon_name, strlen(Tmp_win->icon_name)); + RelieveWindow(Tmp_win, Tmp_win->icon_w, 0, 0, + Tmp_win->icon_w_width, ICON_HEIGHT, Relief, Shadow, + FULL_HILITE); } - else - XCopyPlane(dpy,Tmp_win->iconPixmap,Tmp_win->icon_pixmap_w,Scr.ScratchGC3,0, - 0,Tmp_win->icon_p_width-4, Tmp_win->icon_p_height-4,2,2,1); - } - - if(Tmp_win->icon_w != None) - { - /* text position */ - x = (Tmp_win->icon_w_width - Tmp_win->icon_t_width)/2; - if(x<3)x=3; - - XDrawString (dpy, Tmp_win->icon_w, Scr.ScratchGC3, x, - Tmp_win->icon_w_height-Scr.IconFont.height+ - Scr.IconFont.y-3, - Tmp_win->icon_name, strlen(Tmp_win->icon_name)); - RelieveWindow(Tmp_win,Tmp_win->icon_w,0,0,Tmp_win->icon_w_width, - ICON_HEIGHT,Relief,Shadow, FULL_HILITE); - } } /*********************************************************************** @@ -332,252 +319,339 @@ void DrawIconWindow(FvwmWindow *Tmp_win) * RedoIconName - procedure to re-position the icon window and name * ************************************************************************/ -void RedoIconName(FvwmWindow *Tmp_win) +void +RedoIconName(FvwmWindow *Tmp_win) { - if(Tmp_win->flags & SUPPRESSICON) - return; + if (Tmp_win->flags & SUPPRESSICON) + return; - if (Tmp_win->icon_w == (int)NULL) - return; + if (Tmp_win->icon_w == None) + return; - Tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font,Tmp_win->icon_name, - strlen(Tmp_win->icon_name)); - /* clear the icon window, and trigger a re-draw via an expose event */ - if (Tmp_win->flags & ICONIFIED) - XClearArea(dpy, Tmp_win->icon_w, 0, 0, 0, 0, True); - return; + Tmp_win->icon_t_width = XTextWidth( + Scr.IconFont.font, Tmp_win->icon_name, strlen(Tmp_win->icon_name)); + /* clear the icon window, and trigger a re-draw via an expose event */ + if (Tmp_win->flags & ICONIFIED) + XClearArea(dpy, Tmp_win->icon_w, 0, 0, 0, 0, True); + return; } - - - - /*********************************************************************** +/*********************************************************************** * * Procedure: * AutoPlace - Find a home for an icon * ************************************************************************/ -void AutoPlace(FvwmWindow *t) +void +AutoPlace(FvwmWindow *t) { - int tw,th,tx,ty; - int base_x, base_y; - int width,height; - FvwmWindow *test_window; - Bool loc_ok; - int real_x=10, real_y=10; - int new_x, new_y; - - /* New! Put icon in same page as the center of the window */ - /* Not a good idea for StickyIcons */ - if((t->flags & StickyIcon)||(t->flags & STICKY)) - { - base_x = 0; - base_y = 0; - /*Also, if its a stickyWindow, put it on the current page! */ - new_x = t->frame_x % Scr.MyDisplayWidth; - new_y = t->frame_y % Scr.MyDisplayHeight; - if(new_x < 0)new_x += Scr.MyDisplayWidth; - if(new_y < 0)new_y += Scr.MyDisplayHeight; - SetupFrame(t,new_x,new_y, - t->frame_width,t->frame_height,False); - t->Desk = Scr.CurrentDesk; - } - else - { - base_x=((t->frame_x+Scr.Vx+(t->frame_width>>1))/Scr.MyDisplayWidth)* - Scr.MyDisplayWidth - Scr.Vx; - base_y=((t->frame_y+Scr.Vy+(t->frame_height>>1))/Scr.MyDisplayHeight)* - Scr.MyDisplayHeight - Scr.Vy; - } - if(t->flags & ICON_MOVED) - { - /* just make sure the icon is on this screen */ - t->icon_x_loc = t->icon_x_loc % Scr.MyDisplayWidth + base_x; - t->icon_y_loc = t->icon_y_loc % Scr.MyDisplayHeight + base_y; - if(t->icon_x_loc < 0) - t->icon_x_loc += Scr.MyDisplayWidth; - if(t->icon_y_loc < 0) - t->icon_y_loc += Scr.MyDisplayHeight; - } - else if (t->wmhints && t->wmhints->flags & IconPositionHint) - { - t->icon_x_loc = t->wmhints->icon_x; - t->icon_y_loc = t->wmhints->icon_y; - } - /* dje 10/12/97: - Look thru chain of icon boxes assigned to window. - Add logic for grids and fill direction. - */ - else { - /* A place to hold inner and outer loop variables. */ - typedef struct dimension_struct { - int step; /* grid size (may be negative) */ - int start_at; /* starting edge */ - int real_start; /* on screen starting edge */ - int end_at; /* ending edge */ - int base; /* base for screen */ - int icon_dimension; /* height or width */ - int nom_dimension; /* nonminal height or width */ - int screen_dimension; /* screen height or width */ - } dimension; - dimension dim[3]; /* space for work, 1st, 2nd dimen */ - icon_boxes *icon_boxes_ptr; /* current icon box */ - int i; /* index for inner/outer loop data */ - - /* Hopefully this makes the following more readable. */ + int tw, th, tx, ty; + int base_x, base_y; + int width, height; + FvwmWindow *test_window; + Bool loc_ok; + int real_x = 10, real_y = 10; + int new_x, new_y; + + /* New! Put icon in same page as the center of the window */ + /* Not a good idea for StickyIcons */ + if ((t->flags & StickyIcon) || (t->flags & STICKY)) { + base_x = 0; + base_y = 0; + /*Also, if its a stickyWindow, put it on the current page! */ + new_x = t->frame_x % Scr.MyDisplayWidth; + new_y = t->frame_y % Scr.MyDisplayHeight; + if (new_x < 0) + new_x += Scr.MyDisplayWidth; + if (new_y < 0) + new_y += Scr.MyDisplayHeight; + SetupFrame( + t, new_x, new_y, t->frame_width, t->frame_height, False); + t->Desk = Scr.CurrentDesk; + } else { + base_x = ((t->frame_x + Scr.Vx + (t->frame_width >> 1)) / + Scr.MyDisplayWidth) * + Scr.MyDisplayWidth - + Scr.Vx; + base_y = ((t->frame_y + Scr.Vy + (t->frame_height >> 1)) / + Scr.MyDisplayHeight) * + Scr.MyDisplayHeight - + Scr.Vy; + } + if (t->flags & ICON_MOVED) { + /* just make sure the icon is on this screen */ + t->icon_x_loc = t->icon_x_loc % Scr.MyDisplayWidth + base_x; + t->icon_y_loc = t->icon_y_loc % Scr.MyDisplayHeight + base_y; + if (t->icon_x_loc < 0) + t->icon_x_loc += Scr.MyDisplayWidth; + if (t->icon_y_loc < 0) + t->icon_y_loc += Scr.MyDisplayHeight; + } else if (t->wmhints && t->wmhints->flags & IconPositionHint) { + t->icon_x_loc = t->wmhints->icon_x; + t->icon_y_loc = t->wmhints->icon_y; + } + /* dje 10/12/97: + Look thru chain of icon boxes assigned to window. + Add logic for grids and fill direction. + */ + else { + /* A place to hold inner and outer loop variables. */ + typedef struct dimension_struct { + int step; /* grid size (may be negative) */ + int start_at; /* starting edge */ + int real_start; /* on screen starting edge */ + int end_at; /* ending edge */ + int base; /* base for screen */ + int icon_dimension; /* height or width */ + int nom_dimension; /* nonminal height or width */ + int screen_dimension; /* screen height or width */ + } dimension; + dimension dim[3]; /* space for work, 1st, 2nd dimen */ + icon_boxes *icon_boxes_ptr; /* current icon box */ + int i; /* index for inner/outer loop data */ + + /* Hopefully this makes the following more readable. */ #define ICONBOX_LFT icon_boxes_ptr->IconBox[0] #define ICONBOX_TOP icon_boxes_ptr->IconBox[1] #define ICONBOX_RGT icon_boxes_ptr->IconBox[2] #define ICONBOX_BOT icon_boxes_ptr->IconBox[3] -#define BOT_FILL icon_boxes_ptr->IconFlags & ICONFILLBOT -#define RGT_FILL icon_boxes_ptr->IconFlags & ICONFILLRGT -#define HRZ_FILL icon_boxes_ptr->IconFlags & ICONFILLHRZ - - width = t->icon_p_width; /* unnecessary copy of width */ - height = t->icon_w_height + t->icon_p_height; /* total height */ - loc_ok = False; /* no slot found yet */ - - /* check all boxes in order */ - for(icon_boxes_ptr= t->IconBoxes; /* init */ - icon_boxes_ptr != NULL; /* until no more boxes */ - icon_boxes_ptr = icon_boxes_ptr->next) { /* all boxes */ - if (loc_ok == True) { - break; /* leave for loop */ - } - dim[1].step = icon_boxes_ptr->IconGrid[1]; /* y amount */ - dim[1].start_at = ICONBOX_TOP; /* init start from */ - dim[1].end_at = ICONBOX_BOT; /* init end at */ - dim[1].base = base_y; /* save base */ - dim[1].icon_dimension = height; /* save dimension */ - dim[1].screen_dimension = Scr.MyDisplayHeight; - if (BOT_FILL) { /* fill from bottom */ - dim[1].step = 0 - dim[1].step; /* reverse step */ - } /* end fill from bottom */ - - dim[2].step = icon_boxes_ptr->IconGrid[0]; /* x amount */ - dim[2].start_at = ICONBOX_LFT; /* init start from */ - dim[2].end_at = ICONBOX_RGT; /* init end at */ - dim[2].base = base_x; /* save base */ - dim[2].icon_dimension = width; /* save dimension */ - dim[2].screen_dimension = Scr.MyDisplayWidth; - if (RGT_FILL) { /* fill from right */ - dim[2].step = 0 - dim[2].step; /* reverse step */ - } /* end fill from right */ - for (i=1;i<=2;i++) { /* for dimensions 1 and 2 */ - /* If the window is taller than the icon box, ignore the icon height - * when figuring where to put it. Same goes for the width - * This should permit reasonably graceful handling of big icons. */ - dim[i].nom_dimension = dim[i].icon_dimension; - if (dim[i].icon_dimension >= dim[i].end_at - dim[i].start_at) { - dim[i].nom_dimension = dim[i].end_at - dim[i].start_at - 1; - } - if (dim[i].step < 0) { /* if moving backwards */ - dim[0].start_at = dim[i].start_at; /* save */ - dim[i].start_at = dim[i].end_at; /* swap one */ - dim[i].end_at = dim[0].start_at; /* swap the other */ - dim[i].start_at -= dim[i].icon_dimension; - } /* end moving backwards */ - dim[i].start_at += dim[i].base; /* adjust both to base */ - dim[i].end_at += dim[i].base; - } /* end 2 dimensions */ - if (HRZ_FILL) { /* if hrz first */ - memcpy(&dim[0],&dim[1],sizeof(dimension)); /* save */ - memcpy(&dim[1],&dim[2],sizeof(dimension)); /* switch one */ - memcpy(&dim[2],&dim[0],sizeof(dimension)); /* switch the other */ - } /* end horizontal dimension first */ - dim[0].start_at = dim[2].start_at; /* save for reseting inner loop */ - while((dim[1].step < 0 /* filling reversed */ - ? (dim[1].start_at + dim[1].icon_dimension - dim[1].nom_dimension - > dim[1].end_at) /* check back edge */ - : (dim[1].start_at + dim[1].nom_dimension - < dim[1].end_at)) /* check front edge */ - && (!loc_ok)) { /* nothing found yet */ - dim[1].real_start = dim[1].start_at; /* init */ - if (dim[1].start_at + dim[1].icon_dimension > - dim[1].screen_dimension - 2 + dim[1].base) { /* if off screen */ - dim[1].real_start = dim[1].screen_dimension - - dim[1].icon_dimension + dim[1].base; /* move on screen */ - } /* end off screen */ - if (dim[1].start_at < dim[1].base) { /* if off other edge */ - dim[1].real_start = dim[1].base; /* move on screen */ - } /* end off other edge */ - dim[2].start_at = dim[0].start_at; /* reset inner loop */ - while((dim[2].step < 0 /* filling reversed */ - ? (dim[2].start_at + dim[2].icon_dimension - dim[2].nom_dimension - > dim[2].end_at) /* check back edge */ - : (dim[2].start_at + dim[2].nom_dimension - < dim[2].end_at)) /* check front edge */ - && (!loc_ok)) { /* nothing found yet */ - dim[2].real_start = dim[2].start_at; /* init */ - if (dim[2].start_at + dim[2].icon_dimension > - dim[2].screen_dimension - 2 + dim[2].base) { /* if off screen */ - dim[2].real_start = dim[2].screen_dimension - - dim[2].icon_dimension + dim[2].base; /* move on screen */ - } /* end off screen */ - if (dim[2].start_at < dim[2].base) { /* if off other edge */ - dim[2].real_start = dim[2].base; /* move on screen */ - } /* end off other edge */ - - if (HRZ_FILL) { /* if hrz first */ - real_x = dim[1].real_start; /* unreverse them */ - real_y = dim[2].real_start; - } else { - real_x = dim[2].real_start; /* reverse them */ - real_y = dim[1].real_start; - } - - loc_ok = True; /* this may be a good location */ - test_window = Scr.FvwmRoot.next; - while((test_window != (FvwmWindow *)0) - &&(loc_ok == True)) { /* test overlap */ - if(test_window->Desk == t->Desk) { - if((test_window->flags&ICONIFIED) && - (!(test_window->flags&TRANSIENT) || - !test_window->tmpflags.IconifiedByParent) && - (test_window->icon_w||test_window->icon_pixmap_w) && - (test_window != t)) { - tw=test_window->icon_p_width; - th=test_window->icon_p_height+ - test_window->icon_w_height; - tx = test_window->icon_x_loc; - ty = test_window->icon_y_loc; - - if((tx<(real_x+width+3))&&((tx+tw+3) > real_x)&& - (ty<(real_y+height+3))&&((ty+th + 3)>real_y)) { - loc_ok = False; /* don't accept this location */ - } /* end if icons overlap */ - } /* end if its an icon */ - } /* end if same desk */ - test_window = test_window->next; - } /* end while icons that may overlap */ - dim[2].start_at += dim[2].step; /* Grid inner value & direction */ - } /* end while room inner dimension */ - dim[1].start_at += dim[1].step; /* Grid outer value & direction */ - } /* end while room outer dimension */ - } /* end for all icon boxes, or found space */ - if(loc_ok == False) /* If icon never found a home */ - return; /* just leave it */ - t->icon_x_loc = real_x; - t->icon_y_loc = real_y; - - if(t->icon_pixmap_w) - XMoveWindow(dpy,t->icon_pixmap_w,t->icon_x_loc, t->icon_y_loc); - - t->icon_w_width = t->icon_p_width; - t->icon_xl_loc = t->icon_x_loc; - - if (t->icon_w != None) - XMoveResizeWindow(dpy, t->icon_w, t->icon_xl_loc, - t->icon_y_loc+t->icon_p_height, - t->icon_w_width,ICON_HEIGHT); - BroadcastPacket(M_ICON_LOCATION, 7, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_w_width, t->icon_w_height+t->icon_p_height); - } - +#define BOT_FILL icon_boxes_ptr->IconFlags &ICONFILLBOT +#define RGT_FILL icon_boxes_ptr->IconFlags &ICONFILLRGT +#define HRZ_FILL icon_boxes_ptr->IconFlags &ICONFILLHRZ + + width = t->icon_p_width; /* unnecessary copy of width */ + height = t->icon_w_height + t->icon_p_height; /* total height */ + loc_ok = False; /* no slot found yet */ + + /* check all boxes in order */ + for (icon_boxes_ptr = t->IconBoxes; /* init */ + icon_boxes_ptr != NULL; /* until no more boxes */ + icon_boxes_ptr = icon_boxes_ptr->next) { /* all boxes */ + if (loc_ok == True) { + break; /* leave for loop */ + } + dim[1].step = + icon_boxes_ptr->IconGrid[1]; /* y amount */ + dim[1].start_at = ICONBOX_TOP; /* init start from */ + dim[1].end_at = ICONBOX_BOT; /* init end at */ + dim[1].base = base_y; /* save base */ + dim[1].icon_dimension = height; /* save dimension */ + dim[1].screen_dimension = Scr.MyDisplayHeight; + if (BOT_FILL) { /* fill from bottom */ + dim[1].step = + 0 - dim[1].step; /* reverse step */ + } /* end fill from bottom */ + + dim[2].step = + icon_boxes_ptr->IconGrid[0]; /* x amount */ + dim[2].start_at = ICONBOX_LFT; /* init start from */ + dim[2].end_at = ICONBOX_RGT; /* init end at */ + dim[2].base = base_x; /* save base */ + dim[2].icon_dimension = width; /* save dimension */ + dim[2].screen_dimension = Scr.MyDisplayWidth; + if (RGT_FILL) { /* fill from right */ + dim[2].step = + 0 - dim[2].step; /* reverse step */ + } /* end fill from right */ + for (i = 1; i <= 2; i++) { /* for dimensions 1 and 2 */ + /* If the window is taller than the icon box, + * ignore the icon height when figuring where to + * put it. Same goes for the width This should + * permit reasonably graceful handling of big + * icons. */ + dim[i].nom_dimension = dim[i].icon_dimension; + if (dim[i].icon_dimension >= + dim[i].end_at - dim[i].start_at) { + dim[i].nom_dimension = + dim[i].end_at - dim[i].start_at - 1; + } + if (dim[i].step < 0) { /* if moving backwards */ + dim[0].start_at = + dim[i].start_at; /* save */ + dim[i].start_at = + dim[i].end_at; /* swap one */ + dim[i].end_at = + dim[0] + .start_at; /* swap the other */ + dim[i].start_at -= + dim[i].icon_dimension; + } /* end moving backwards */ + dim[i].start_at += + dim[i].base; /* adjust both to base */ + dim[i].end_at += dim[i].base; + } /* end 2 dimensions */ + if (HRZ_FILL) { /* if hrz first */ + memcpy(&dim[0], &dim[1], + sizeof(dimension)); /* save */ + memcpy(&dim[1], &dim[2], + sizeof(dimension)); /* switch one */ + memcpy(&dim[2], &dim[0], + sizeof(dimension)); /* switch the other */ + } /* end horizontal dimension first */ + dim[0].start_at = + dim[2].start_at; /* save for reseting inner loop */ + while ((dim[1].step < 0 ? /* filling reversed */ + (dim[1].start_at + dim[1].icon_dimension - + dim[1].nom_dimension > + dim[1].end_at) : /* check back edge */ + (dim[1].start_at + dim[1].nom_dimension < + dim[1].end_at)) && /* check front edge */ + (!loc_ok)) { /* nothing found yet */ + dim[1].real_start = dim[1].start_at; /* init */ + if (dim[1].start_at + dim[1].icon_dimension > + dim[1].screen_dimension - 2 + + dim[1].base) { /* if off screen */ + dim[1].real_start = + dim[1].screen_dimension - + dim[1].icon_dimension + + dim[1].base; /* move on screen */ + } /* end off screen */ + if (dim[1].start_at < + dim[1].base) { /* if off other edge */ + dim[1].real_start = + dim[1].base; /* move on screen */ + } /* end off other edge */ + dim[2].start_at = + dim[0].start_at; /* reset inner loop */ + while ((dim[2].step < 0 ? /* filling reversed */ + (dim[2].start_at + + dim[2].icon_dimension - + dim[2].nom_dimension > + dim[2].end_at) /* check back + edge */ + : (dim[2].start_at + + dim[2].nom_dimension < + dim[2].end_at)) /* check front + edge */ + && (!loc_ok)) { /* nothing found yet */ + dim[2].real_start = + dim[2].start_at; /* init */ + if (dim[2].start_at + + dim[2].icon_dimension > + dim[2].screen_dimension - 2 + + dim[2] + .base) { /* if off screen */ + dim[2].real_start = + dim[2].screen_dimension - + dim[2].icon_dimension + + dim[2].base; /* move on + screen */ + } /* end off screen */ + if (dim[2].start_at < + dim[2] + .base) { /* if off other edge */ + dim[2].real_start = + dim[2].base; /* move on + screen */ + } /* end off other edge */ + + if (HRZ_FILL) { /* if hrz first */ + real_x = + dim[1] + .real_start; /* unreverse + them */ + real_y = dim[2].real_start; + } else { + real_x = + dim[2] + .real_start; /* reverse + them */ + real_y = dim[1].real_start; + } + + loc_ok = True; /* this may be a good + location */ + test_window = Scr.FvwmRoot.next; + while ((test_window != + (FvwmWindow *)0) && + (loc_ok == + True)) { /* test overlap */ + if (test_window->Desk == + t->Desk) { + if ((test_window + ->flags & + ICONIFIED) && + (!(test_window + ->flags & + TRANSIENT) || + !test_window + ->tmpflags + .IconifiedByParent) && + (test_window + ->icon_w || + test_window + ->icon_pixmap_w) && + (test_window != + t)) { + tw = + test_window + ->icon_p_width; + th = + test_window + ->icon_p_height + + test_window + ->icon_w_height; + tx = + test_window + ->icon_x_loc; + ty = + test_window + ->icon_y_loc; + + if ((tx < + (real_x + + width + + 3)) && + ((tx + tw + + 3) > + real_x) && + (ty < + (real_y + + height + + 3)) && + ((ty + th + + 3) > + real_y)) { + loc_ok = + False; /* don't accept this location */ + } /* end if + icons + overlap */ + } /* end if its an icon + */ + } /* end if same desk */ + test_window = test_window->next; + } /* end while icons that may overlap */ + dim[2].start_at += + dim[2].step; /* Grid inner value & + direction */ + } /* end while room inner dimension */ + dim[1].start_at += + dim[1].step; /* Grid outer value & direction + */ + } /* end while room outer dimension */ + } /* end for all icon boxes, or found space */ + if (loc_ok == False) /* If icon never found a home */ + return; /* just leave it */ + t->icon_x_loc = real_x; + t->icon_y_loc = real_y; + + if (t->icon_pixmap_w) + XMoveWindow(dpy, t->icon_pixmap_w, t->icon_x_loc, + t->icon_y_loc); + + t->icon_w_width = t->icon_p_width; + t->icon_xl_loc = t->icon_x_loc; + + if (t->icon_w != None) + XMoveResizeWindow(dpy, t->icon_w, t->icon_xl_loc, + t->icon_y_loc + t->icon_p_height, t->icon_w_width, + ICON_HEIGHT); + BroadcastPacket(M_ICON_LOCATION, 7, t->w, t->frame, + (unsigned long)t, t->icon_x_loc, t->icon_y_loc, + t->icon_w_width, t->icon_w_height + t->icon_p_height); + } } /*********************************************************************** @@ -589,45 +663,43 @@ void AutoPlace(FvwmWindow *t) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabIconButtons(FvwmWindow *tmp_win, Window w) +void +GrabIconButtons(FvwmWindow *tmp_win, Window w) { - Binding *MouseEntry; - - MouseEntry = Scr.AllBindings; - while(MouseEntry != (Binding *)0) - { - if((MouseEntry->Action != NULL)&&(MouseEntry->Context & C_ICON)&& - (MouseEntry->IsMouse == 1)) - { - if(MouseEntry->Button_Key >0) - XGrabButton(dpy, MouseEntry->Button_Key, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - else - { - XGrabButton(dpy, 1, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 2, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - XGrabButton(dpy, 3, MouseEntry->Modifier, w, - True, ButtonPressMask | ButtonReleaseMask, - GrabModeAsync, GrabModeAsync, None, - Scr.FvwmCursors[DEFAULT]); - } + Binding *MouseEntry; + + MouseEntry = Scr.AllBindings; + while (MouseEntry != (Binding *)0) { + if ((MouseEntry->Action != NULL) && + (MouseEntry->Context & C_ICON) && + (MouseEntry->IsMouse == 1)) { + if (MouseEntry->Button_Key > 0) + XGrabButton(dpy, MouseEntry->Button_Key, + MouseEntry->Modifier, w, True, + ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + else { + XGrabButton(dpy, 1, MouseEntry->Modifier, w, + True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 2, MouseEntry->Modifier, w, + True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + XGrabButton(dpy, 3, MouseEntry->Modifier, w, + True, ButtonPressMask | ButtonReleaseMask, + GrabModeAsync, GrabModeAsync, None, + Scr.FvwmCursors[DEFAULT]); + } + } + + MouseEntry = MouseEntry->NextBinding; } - - MouseEntry = MouseEntry->NextBinding; - } - return; + return; } - - /*********************************************************************** * * Procedure: @@ -637,44 +709,43 @@ void GrabIconButtons(FvwmWindow *tmp_win, Window w) * tmp_win - the fvwm window structure to use * ***********************************************************************/ -void GrabIconKeys(FvwmWindow *tmp_win,Window w) +void +GrabIconKeys(FvwmWindow *tmp_win, Window w) { - Binding *tmp; - for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) - { - if ((tmp->Context & C_ICON)&&(tmp->IsMouse == 0)) - XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, w, True, - GrabModeAsync, GrabModeAsync); - } - return; + Binding *tmp; + for (tmp = Scr.AllBindings; tmp != NULL; tmp = tmp->NextBinding) { + if ((tmp->Context & C_ICON) && (tmp->IsMouse == 0)) + XGrabKey(dpy, tmp->Button_Key, tmp->Modifier, w, True, + GrabModeAsync, GrabModeAsync); + } + return; } - /**************************************************************************** * * Looks for a monochrome icon bitmap file * ****************************************************************************/ -void GetBitmapFile(FvwmWindow *tmp_win) +void +GetBitmapFile(FvwmWindow *tmp_win) { - char *path = NULL; - int HotX,HotY; - extern char *IconPath; - - path = findIconFile(tmp_win->icon_bitmap_file, IconPath,R_OK); - - if(path == NULL)return; - if(XReadBitmapFile (dpy, Scr.Root,path, - (unsigned int *)&tmp_win->icon_p_width, - (unsigned int *)&tmp_win->icon_p_height, - &tmp_win->iconPixmap, - &HotX, &HotY) != BitmapSuccess) - { - tmp_win->icon_p_width = 0; - tmp_win->icon_p_height = 0; - } - - free(path); + char *path = NULL; + int HotX, HotY; + extern char *IconPath; + + path = findIconFile(tmp_win->icon_bitmap_file, IconPath, R_OK); + + if (path == NULL) + return; + if (XReadBitmapFile(dpy, Scr.Root, path, + (unsigned int *)&tmp_win->icon_p_width, + (unsigned int *)&tmp_win->icon_p_height, &tmp_win->iconPixmap, + &HotX, &HotY) != BitmapSuccess) { + tmp_win->icon_p_width = 0; + tmp_win->icon_p_height = 0; + } + + free(path); } /**************************************************************************** @@ -682,54 +753,55 @@ void GetBitmapFile(FvwmWindow *tmp_win) * Looks for a color XPM icon file * ****************************************************************************/ -void GetXPMFile(FvwmWindow *tmp_win) +void +GetXPMFile(FvwmWindow *tmp_win) { #ifdef XPM - XWindowAttributes root_attr; - XpmAttributes xpm_attributes; - extern char *PixmapPath; - char *path = NULL; - XpmImage my_image; - int rc; - - path = findIconFile(tmp_win->icon_bitmap_file, PixmapPath,R_OK); - if(path == NULL)return; - - XGetWindowAttributes(dpy,Scr.Root,&root_attr); - xpm_attributes.colormap = root_attr.colormap; - xpm_attributes.closeness = 40000; /* Allow for "similar" colors */ - xpm_attributes.valuemask = XpmSize|XpmReturnPixels|XpmColormap|XpmCloseness; - - rc =XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc != XpmSuccess) { - fvwm_msg(ERR,"GetXPMFile","XpmReadFileToXpmImage failed, pixmap %s, rc %d", - path, rc); - free(path); - return; - } - free(path); - color_reduce_pixmap(&my_image,Scr.ColorLimit); - rc = XpmCreatePixmapFromXpmImage(dpy,Scr.Root, &my_image, - &tmp_win->iconPixmap, - &tmp_win->icon_maskPixmap, - &xpm_attributes); - if (rc != XpmSuccess) { - fvwm_msg(ERR,"GetXPMFile", - "XpmCreatePixmapFromXpmImage failed, rc %d\n", rc); - XpmFreeXpmImage(&my_image); - return; - } - tmp_win->icon_p_width = my_image.width; - tmp_win->icon_p_height = my_image.height; - tmp_win->flags |= PIXMAP_OURS; - tmp_win->iconDepth = Scr.d_depth; + XWindowAttributes root_attr; + XpmAttributes xpm_attributes; + extern char *PixmapPath; + char *path = NULL; + XpmImage my_image; + int rc; + + path = findIconFile(tmp_win->icon_bitmap_file, PixmapPath, R_OK); + if (path == NULL) + return; + + XGetWindowAttributes(dpy, Scr.Root, &root_attr); + xpm_attributes.colormap = root_attr.colormap; + xpm_attributes.closeness = 40000; /* Allow for "similar" colors */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc != XpmSuccess) { + fvwm_msg(ERR, "GetXPMFile", + "XpmReadFileToXpmImage failed, pixmap %s, rc %d", path, rc); + free(path); + return; + } + free(path); + color_reduce_pixmap(&my_image, Scr.ColorLimit); + rc = XpmCreatePixmapFromXpmImage(dpy, Scr.Root, &my_image, + &tmp_win->iconPixmap, &tmp_win->icon_maskPixmap, &xpm_attributes); + if (rc != XpmSuccess) { + fvwm_msg(ERR, "GetXPMFile", + "XpmCreatePixmapFromXpmImage failed, rc %d\n", rc); + XpmFreeXpmImage(&my_image); + return; + } + tmp_win->icon_p_width = my_image.width; + tmp_win->icon_p_height = my_image.height; + tmp_win->flags |= PIXMAP_OURS; + tmp_win->iconDepth = Scr.d_depth; #ifdef SHAPE - if (ShapesSupported && tmp_win->icon_maskPixmap) - tmp_win->flags |= SHAPED_ICON; + if (ShapesSupported && tmp_win->icon_maskPixmap) + tmp_win->flags |= SHAPED_ICON; #endif - XpmFreeXpmImage(&my_image); + XpmFreeXpmImage(&my_image); #endif /* XPM */ } @@ -739,269 +811,243 @@ void GetXPMFile(FvwmWindow *tmp_win) * Looks for an application supplied icon window * ****************************************************************************/ -void GetIconWindow(FvwmWindow *tmp_win) +void +GetIconWindow(FvwmWindow *tmp_win) { - /* We are guaranteed that wmhints is non-null when calling this - * routine */ - if(XGetGeometry(dpy, tmp_win->wmhints->icon_window, &JunkRoot, - &JunkX, &JunkY,(unsigned int *)&tmp_win->icon_p_width, - (unsigned int *)&tmp_win->icon_p_height, - &JunkBW, &JunkDepth)==0) - { - fvwm_msg(ERR,"GetIconWindow","Help! Bad Icon Window!"); - } - tmp_win->icon_p_width += JunkBW<<1; - tmp_win->icon_p_height += JunkBW<<1; - /* - * Now make the new window the icon window for this window, - * and set it up to work as such (select for key presses - * and button presses/releases, set up the contexts for it, - * and define the cursor for it). - */ - tmp_win->icon_pixmap_w = tmp_win->wmhints->icon_window; + /* We are guaranteed that wmhints is non-null when calling this + * routine */ + if (XGetGeometry(dpy, tmp_win->wmhints->icon_window, &JunkRoot, &JunkX, + &JunkY, (unsigned int *)&tmp_win->icon_p_width, + (unsigned int *)&tmp_win->icon_p_height, &JunkBW, + &JunkDepth) == 0) { + fvwm_msg(ERR, "GetIconWindow", "Help! Bad Icon Window!"); + } + tmp_win->icon_p_width += JunkBW << 1; + tmp_win->icon_p_height += JunkBW << 1; + /* + * Now make the new window the icon window for this window, + * and set it up to work as such (select for key presses + * and button presses/releases, set up the contexts for it, + * and define the cursor for it). + */ + tmp_win->icon_pixmap_w = tmp_win->wmhints->icon_window; #ifdef SHAPE - if (ShapesSupported) - { - if (tmp_win->wmhints->flags & IconMaskHint) - { - tmp_win->flags |= SHAPED_ICON; - tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; - } - } + if (ShapesSupported) { + if (tmp_win->wmhints->flags & IconMaskHint) { + tmp_win->flags |= SHAPED_ICON; + tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; + } + } #endif - /* Make sure that the window is a child of the root window ! */ - /* Olwais screws this up, maybe others do too! */ - XReparentWindow(dpy, tmp_win->icon_pixmap_w, Scr.Root, 0,0); - tmp_win->flags &= ~ICON_OURS; + /* Make sure that the window is a child of the root window ! */ + /* Olwais screws this up, maybe others do too! */ + XReparentWindow(dpy, tmp_win->icon_pixmap_w, Scr.Root, 0, 0); + tmp_win->flags &= ~ICON_OURS; } - /**************************************************************************** * * Looks for an application supplied bitmap or pixmap * ****************************************************************************/ -void GetIconBitmap(FvwmWindow *tmp_win) +void +GetIconBitmap(FvwmWindow *tmp_win) { - /* We are guaranteed that wmhints is non-null when calling this - * routine */ - XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap, &JunkRoot, &JunkX, &JunkY, - (unsigned int *)&tmp_win->icon_p_width, - (unsigned int *)&tmp_win->icon_p_height, &JunkBW, &JunkDepth); - tmp_win->iconPixmap = tmp_win->wmhints->icon_pixmap; - tmp_win->iconDepth = JunkDepth; + /* We are guaranteed that wmhints is non-null when calling this + * routine */ + XGetGeometry(dpy, tmp_win->wmhints->icon_pixmap, &JunkRoot, &JunkX, + &JunkY, (unsigned int *)&tmp_win->icon_p_width, + (unsigned int *)&tmp_win->icon_p_height, &JunkBW, &JunkDepth); + tmp_win->iconPixmap = tmp_win->wmhints->icon_pixmap; + tmp_win->iconDepth = JunkDepth; #ifdef SHAPE - if (ShapesSupported) - { - if (tmp_win->wmhints->flags & IconMaskHint) - { - tmp_win->flags |= SHAPED_ICON; - tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; - } - } + if (ShapesSupported) { + if (tmp_win->wmhints->flags & IconMaskHint) { + tmp_win->flags |= SHAPED_ICON; + tmp_win->icon_maskPixmap = tmp_win->wmhints->icon_mask; + } + } #endif } - - /*********************************************************************** * * Procedure: * DeIconify a window * ***********************************************************************/ -void DeIconify(FvwmWindow *tmp_win) +void +DeIconify(FvwmWindow *tmp_win) { - FvwmWindow *t,*tmp; - - if(!tmp_win) - return; - - /* AS dje RaiseWindow(tmp_win); */ - /* now de-iconify transients */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if ((t == tmp_win)|| - ((t->flags & TRANSIENT) &&(t->transientfor == tmp_win->w))) - { - t->flags |= MAPPED; - t->tmpflags.IconifiedByParent = 0; - if(Scr.Hilite == t) - SetBorder (t, False,True,True,None); - - /* AS stuff starts here dje */ - if (t->icon_pixmap_w) - XUnmapWindow(dpy, t->icon_pixmap_w); - if (t->icon_w) - XUnmapWindow(dpy, t->icon_w); - XFlush(dpy); - if (t == tmp_win) - BroadcastPacket(M_DEICONIFY, 11, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_p_width, t->icon_p_height+t->icon_w_height, - t->frame_x, t->frame_y, - t->frame_width, t->frame_height); - else - BroadcastPacket(M_DEICONIFY, 7, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_p_width, t->icon_p_height+t->icon_w_height); - /* End AS */ - XMapWindow(dpy, t->w); - if(t->Desk == Scr.CurrentDesk) - { - XMapWindow(dpy, t->frame); - t->flags |= MAP_PENDING; - } - XMapWindow(dpy, t->Parent); - SetMapStateProp(t, NormalState); - t->flags &= ~ICONIFIED; - t->flags &= ~ICON_UNMAPPED; - /* Need to make sure the border is colored correctly, - * in case it was stuck or unstuck while iconified. */ - tmp = Scr.Hilite; - Scr.Hilite = t; - SetBorder(t,False,True,True,None); - Scr.Hilite = tmp; - XRaiseWindow(dpy,t->w); + FvwmWindow *t, *tmp; + + if (!tmp_win) + return; + + /* AS dje RaiseWindow(tmp_win); */ + /* now de-iconify transients */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t == tmp_win) || + IsTransientDescendantOf(t, tmp_win)) { + t->flags |= MAPPED; + t->tmpflags.IconifiedByParent = 0; + if (Scr.Hilite == t) + SetBorder(t, False, True, True, None); + + /* AS stuff starts here dje */ + if (t->icon_pixmap_w) + XUnmapWindow(dpy, t->icon_pixmap_w); + if (t->icon_w) + XUnmapWindow(dpy, t->icon_w); + XFlush(dpy); + if (t == tmp_win) + BroadcastPacket(M_DEICONIFY, 11, t->w, t->frame, + (unsigned long)t, t->icon_x_loc, + t->icon_y_loc, t->icon_p_width, + t->icon_p_height + t->icon_w_height, + t->frame_x, t->frame_y, t->frame_width, + t->frame_height); + else + BroadcastPacket(M_DEICONIFY, 7, t->w, t->frame, + (unsigned long)t, t->icon_x_loc, + t->icon_y_loc, t->icon_p_width, + t->icon_p_height + t->icon_w_height); + /* End AS */ + XMapWindow(dpy, t->w); + if (t->Desk == Scr.CurrentDesk) { + XMapWindow(dpy, t->frame); + t->flags |= MAP_PENDING; + } + XMapWindow(dpy, t->Parent); + SetMapStateProp(t, NormalState); + t->flags &= ~ICONIFIED; + t->flags &= ~ICON_UNMAPPED; + /* Need to make sure the border is colored correctly, + * in case it was stuck or unstuck while iconified. */ + tmp = Scr.Hilite; + Scr.Hilite = t; + SetBorder(t, False, True, True, None); + Scr.Hilite = tmp; + XRaiseWindow(dpy, t->w); + } } - } - RaiseWindow(tmp_win); /* moved dje */ + RaiseWindow(tmp_win); /* moved dje */ - if(tmp_win->flags & ClickToFocus) - FocusOn(tmp_win,TRUE); + if (tmp_win->flags & ClickToFocus) + FocusOn(tmp_win, TRUE); - KeepOnTop(); + KeepOnTop(); - return; + return; } - /**************************************************************************** * * Iconifies the selected window * ****************************************************************************/ -void Iconify(FvwmWindow *tmp_win, int def_x, int def_y) +void +Iconify(FvwmWindow *tmp_win, int def_x, int def_y) { - FvwmWindow *t; - XWindowAttributes winattrs = {0}; - unsigned long eventMask; - - if(!tmp_win) - return; - XGetWindowAttributes(dpy, tmp_win->w, &winattrs); - eventMask = winattrs.your_event_mask; - - if((tmp_win == Scr.Hilite)&& - (tmp_win->flags & ClickToFocus)&&(tmp_win->next)) - { - SetFocus(tmp_win->next->w,tmp_win->next,1); - } - - - /* iconify transients first */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if ((t==tmp_win)|| - ((t->flags & TRANSIENT) && (t->transientfor == tmp_win->w))) - { - /* - * Prevent the receipt of an UnmapNotify, since that would - * cause a transition to the Withdrawn state. - */ - t->flags &= ~MAPPED; - XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask); - XUnmapWindow(dpy, t->w); - XSelectInput(dpy, t->w, eventMask); - XUnmapWindow(dpy, t->frame); - t->DeIconifyDesk = t->Desk; - if (t->icon_w) - XUnmapWindow(dpy, t->icon_w); - if (t->icon_pixmap_w) - XUnmapWindow(dpy, t->icon_pixmap_w); - - SetMapStateProp(t, IconicState); - SetBorder (t, False,False,False,None); - if(t != tmp_win) - { - t->flags |= ICONIFIED|ICON_UNMAPPED; - t->tmpflags.IconifiedByParent = 1; - - BroadcastPacket(M_ICONIFY, 7, - t->w, t->frame, - (unsigned long)t, - -10000, -10000, - t->icon_w_width, - t->icon_w_height+t->icon_p_height); - BroadcastConfig(M_CONFIGURE_WINDOW,t); - } - } /* if */ - } /* for */ - if (tmp_win->icon_w == None) { - if(tmp_win->flags & ICON_MOVED) - CreateIconWindow(tmp_win,tmp_win->icon_x_loc,tmp_win->icon_y_loc); - else - CreateIconWindow(tmp_win, def_x, def_y); - } - - /* if no pixmap we want icon width to change to text width every iconify */ - if( (tmp_win->icon_w != None) && (tmp_win->icon_pixmap_w == None) ) { - tmp_win->icon_t_width = - XTextWidth(Scr.IconFont.font,tmp_win->icon_name, - strlen(tmp_win->icon_name)); - tmp_win->icon_p_width = tmp_win->icon_t_width+6; - tmp_win->icon_w_width = tmp_win->icon_p_width; - } - - AutoPlace(tmp_win); - tmp_win->flags |= ICONIFIED; - tmp_win->flags &= ~ICON_UNMAPPED; - BroadcastPacket(M_ICONIFY, 11, - tmp_win->w, tmp_win->frame, - (unsigned long)tmp_win, - tmp_win->icon_x_loc, - tmp_win->icon_y_loc, - tmp_win->icon_w_width, - tmp_win->icon_w_height+tmp_win->icon_p_height, - tmp_win->frame_x, /* next 4 added for Animate module */ - tmp_win->frame_y, - tmp_win->frame_width, - tmp_win->frame_height); - BroadcastConfig(M_CONFIGURE_WINDOW,tmp_win); - - LowerWindow(tmp_win); - if(tmp_win->Desk == Scr.CurrentDesk) - { - if (tmp_win->icon_w != None) - XMapWindow(dpy, tmp_win->icon_w); - - if(tmp_win->icon_pixmap_w != None) - XMapWindow(dpy, tmp_win->icon_pixmap_w); - KeepOnTop(); - } - if((tmp_win->flags & ClickToFocus)||(tmp_win->flags & SloppyFocus)) - { - if (tmp_win == Scr.Focus) - { - if(Scr.PreviousFocus == Scr.Focus) - Scr.PreviousFocus = NULL; - if((tmp_win->flags & ClickToFocus)&&(tmp_win->next)) - SetFocus(tmp_win->next->w, tmp_win->next,1); - else - { - SetFocus(Scr.NoFocusWin, NULL,1); - } + FvwmWindow *t; + XWindowAttributes winattrs = {0}; + unsigned long eventMask; + + if (!tmp_win) + return; + XGetWindowAttributes(dpy, tmp_win->w, &winattrs); + eventMask = winattrs.your_event_mask; + + if ((tmp_win == Scr.Hilite) && (tmp_win->flags & ClickToFocus) && + (tmp_win->next)) { + SetFocus(tmp_win->next->w, tmp_win->next, 1); } - } - return; -} + /* iconify transients first */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t == tmp_win) || + IsTransientDescendantOf(t, tmp_win)) { + /* + * Prevent the receipt of an UnmapNotify, since that + * would cause a transition to the Withdrawn state. + */ + t->flags &= ~MAPPED; + XSelectInput( + dpy, t->w, eventMask & ~StructureNotifyMask); + XUnmapWindow(dpy, t->w); + XSelectInput(dpy, t->w, eventMask); + XUnmapWindow(dpy, t->frame); + t->DeIconifyDesk = t->Desk; + if (t->icon_w) + XUnmapWindow(dpy, t->icon_w); + if (t->icon_pixmap_w) + XUnmapWindow(dpy, t->icon_pixmap_w); + + SetMapStateProp(t, IconicState); + SetBorder(t, False, False, False, None); + if (t != tmp_win) { + t->flags |= ICONIFIED | ICON_UNMAPPED; + t->tmpflags.IconifiedByParent = 1; + + BroadcastPacket(M_ICONIFY, 7, t->w, t->frame, + (unsigned long)t, -10000, -10000, + t->icon_w_width, + t->icon_w_height + t->icon_p_height); + BroadcastConfig(M_CONFIGURE_WINDOW, t); + } + } /* if */ + } /* for */ + if (tmp_win->icon_w == None) { + if (tmp_win->flags & ICON_MOVED) + CreateIconWindow( + tmp_win, tmp_win->icon_x_loc, tmp_win->icon_y_loc); + else + CreateIconWindow(tmp_win, def_x, def_y); + } + + /* if no pixmap we want icon width to change to text width every iconify + */ + if ((tmp_win->icon_w != None) && (tmp_win->icon_pixmap_w == None)) { + tmp_win->icon_t_width = XTextWidth(Scr.IconFont.font, + tmp_win->icon_name, strlen(tmp_win->icon_name)); + tmp_win->icon_p_width = tmp_win->icon_t_width + 6; + tmp_win->icon_w_width = tmp_win->icon_p_width; + } + AutoPlace(tmp_win); + tmp_win->flags |= ICONIFIED; + tmp_win->flags &= ~ICON_UNMAPPED; + BroadcastPacket(M_ICONIFY, 11, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_x_loc, tmp_win->icon_y_loc, + tmp_win->icon_w_width, + tmp_win->icon_w_height + tmp_win->icon_p_height, + tmp_win->frame_x, /* next 4 added for Animate module */ + tmp_win->frame_y, tmp_win->frame_width, tmp_win->frame_height); + BroadcastConfig(M_CONFIGURE_WINDOW, tmp_win); + + LowerWindow(tmp_win); + if (tmp_win->Desk == Scr.CurrentDesk) { + if (tmp_win->icon_w != None) + XMapWindow(dpy, tmp_win->icon_w); + + if (tmp_win->icon_pixmap_w != None) + XMapWindow(dpy, tmp_win->icon_pixmap_w); + KeepOnTop(); + } + if ((tmp_win->flags & ClickToFocus) || (tmp_win->flags & SloppyFocus)) { + if (tmp_win == Scr.Focus) { + if (Scr.PreviousFocus == Scr.Focus) + Scr.PreviousFocus = NULL; + if ((tmp_win->flags & ClickToFocus) && (tmp_win->next)) + SetFocus(tmp_win->next->w, tmp_win->next, 1); + else { + SetFocus(Scr.NoFocusWin, NULL, 1); + } + } + } + return; +} /**************************************************************************** * @@ -1010,15 +1056,16 @@ void Iconify(FvwmWindow *tmp_win, int def_x, int def_y) * that go with them. * ****************************************************************************/ -void SetMapStateProp(FvwmWindow *tmp_win, int state) +void +SetMapStateProp(FvwmWindow *tmp_win, int state) { - unsigned long data[2]; /* "suggested" by ICCCM version 1 */ + unsigned long data[2]; /* "suggested" by ICCCM version 1 */ - data[0] = (unsigned long) state; - data[1] = (unsigned long) tmp_win->icon_w; -/* data[2] = (unsigned long) tmp_win->icon_pixmap_w;*/ + data[0] = (unsigned long)state; + data[1] = (unsigned long)tmp_win->icon_w; + /* data[2] = (unsigned long) tmp_win->icon_pixmap_w;*/ - XChangeProperty (dpy, tmp_win->w, _XA_WM_STATE, _XA_WM_STATE, 32, - PropModeReplace, (unsigned char *) data, 2); - return; + XChangeProperty(dpy, tmp_win->w, _XA_WM_STATE, _XA_WM_STATE, 32, + PropModeReplace, (unsigned char *)data, 2); + return; } Index: fvwm/fvwm/menus.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/menus.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/menus.c --- fvwm/fvwm/menus.c +++ fvwm/fvwm/menus.c @@ -43,47 +43,47 @@ Rewrite of the MenuStyle code for cleaner parsing and better configurability. */ - /*********************************************************************** * * fvwm menu code * ***********************************************************************/ /* #define FVWM_DEBUG_MSGS */ -#include "config.h" +#include "menus.h" -#include +#include +#include + +#include #include -#include +#include #include -#include +#include #include -#include -#include -#include -#include +#include +#include +#include "config.h" #include "fvwm.h" -#include "menus.h" #include "misc.h" #include "parse.h" #include "screen.h" -static void DrawTrianglePattern(Window,GC,GC,GC,GC,int,int,int,int,char); -static void DrawSeparator(Window, GC,GC,int, int,int,int,int); -static void DrawUnderline(MenuRoot *mr, GC gc, int x, int y, - char *txt, int off); -static MenuStatus MenuInteraction(MenuRoot *menu,MenuRoot *menuPrior, - MenuItem **pmiExecuteAction,int cmenuDeep, - Bool fSticks); +static void DrawTrianglePattern( + Window, GC, GC, GC, GC, int, int, int, int, char); +static void DrawSeparator(Window, GC, GC, int, int, int, int, int); +static void DrawUnderline( + MenuRoot *mr, GC gc, int x, int y, char *txt, int off); +static MenuStatus MenuInteraction(MenuRoot *menu, MenuRoot *menuPrior, + MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks); static void WarpPointerToTitle(MenuRoot *menu); static MenuItem *MiWarpPointerToItem(MenuItem *mi, Bool fSkipTitle); static void PopDownMenu(MenuRoot *mr); static void PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps); -static int DoMenusOverlap(MenuRoot *mr, int x, int y, int width, int height, - Bool fTolerant); +static int DoMenusOverlap( + MenuRoot *mr, int x, int y, int width, int height, Bool fTolerant); static Bool FPopupMenu(MenuRoot *menu, MenuRoot *menuPrior, int x, int y, - Bool fWarpItem, MenuOptions *pops, Bool *ret_overlap); + Bool fWarpItem, MenuOptions *pops, Bool *ret_overlap); static void GetPreferredPopupPosition(MenuRoot *mr, int *x, int *y); static int PopupPositionOffset(MenuRoot *mr); static void GetPopupOptions(MenuItem *mi, MenuOptions *pops); @@ -91,19 +91,19 @@ static void PaintEntry(MenuItem *mi); static void PaintMenu(MenuRoot *, XEvent *); static void SetMenuItemSelected(MenuItem *mi, Bool f); static MenuRoot *MrPopupForMi(MenuItem *mi); -static int ButtonPosition(int context, FvwmWindow * t); +static int ButtonPosition(int context, FvwmWindow *t); static Bool FMenuMapped(MenuRoot *menu); Bool menuFromFrameOrWindowOrTitlebar = FALSE; Bool fShowPopupTimedout = FALSE; Bool mouse_moved = FALSE; -extern int Context,Button; +extern int Context, Button; extern FvwmWindow *ButtonWindow, *Tmp_win; extern XEvent Event; extern XContext MenuContext; -static FvwmWindow *s_Tmp_win=NULL; +static FvwmWindow *s_Tmp_win = NULL; /* dirty patch to pass the last popups position hints to popup_func */ MenuPosHints lastMenuPosHints; @@ -116,12 +116,19 @@ unsigned int dkp_keystate; unsigned int dkp_keycode; Time dkp_timestamp; -#define IS_TITLE_MENU_ITEM(mi) (((mi)?((mi)->func_type==F_TITLE):FALSE)) -#define IS_POPUP_MENU_ITEM(mi) (((mi)?((mi)->func_type==F_POPUP):FALSE)) -#define IS_SEPARATOR_MENU_ITEM(mi) ((mi)?(mi)->fIsSeparator:FALSE) -#define IS_REAL_SEPARATOR_MENU_ITEM(mi) ((mi)?((mi)->fIsSeparator && StrEquals((mi)->action,"nop") && !((mi)->strlen) && !((mi)->strlen2)):FALSE) -#define IS_LABEL_MENU_ITEM(mi) ((mi)?((mi)->fIsSeparator && StrEquals((mi)->action,"nop") && ((mi)->strlen || ((mi)->strlen2))):FALSE) -#define MENU_MIDDLE_OFFSET(menu) ((menu)->xoffset + ((menu)->width - (menu)->xoffset)/2) +#define IS_TITLE_MENU_ITEM(mi) (((mi) ? ((mi)->func_type == F_TITLE) : FALSE)) +#define IS_POPUP_MENU_ITEM(mi) (((mi) ? ((mi)->func_type == F_POPUP) : FALSE)) +#define IS_SEPARATOR_MENU_ITEM(mi) ((mi) ? (mi)->fIsSeparator : FALSE) +#define IS_REAL_SEPARATOR_MENU_ITEM(mi) \ + ((mi) ? ((mi)->fIsSeparator && StrEquals((mi)->action, "nop") &&\ + !((mi)->strlen) && !((mi)->strlen2)) \ + : FALSE) +#define IS_LABEL_MENU_ITEM(mi) \ + ((mi) ? ((mi)->fIsSeparator && StrEquals((mi)->action, "nop") &&\ + ((mi)->strlen || ((mi)->strlen2))) \ + : FALSE) +#define MENU_MIDDLE_OFFSET(menu) \ + ((menu)->xoffset + ((menu)->width - (menu)->xoffset) / 2) #define IS_LEFT_MENU(menu) ((menu)->flags.f.is_left) #define IS_RIGHT_MENU(menu) ((menu)->flags.f.is_right) #define IS_UP_MENU(menu) ((menu)->flags.f.is_up) @@ -143,149 +150,156 @@ Time dkp_timestamp; * * Returns one of MENU_NOP, MENU_ERROR, MENU_ABORTED, MENU_DONE ***************************************************************************/ -MenuStatus do_menu(MenuRoot *menu, MenuRoot *menuPrior, - MenuItem **pmiExecuteAction,int cmenuDeep,Bool fStick, - XEvent *eventp, MenuOptions *pops) +MenuStatus +do_menu(MenuRoot *menu, MenuRoot *menuPrior, MenuItem **pmiExecuteAction, + int cmenuDeep, Bool fStick, XEvent *eventp, MenuOptions *pops) { - MenuStatus retval=MENU_NOP; - int x,y; - static int x_start, y_start; - Bool fFailedPopup = FALSE; - Bool fWasAlreadyPopped = FALSE; - Bool key_press; - Bool fDoubleClick = FALSE; - Time t0 = lastTimestamp; - extern Time lastTimestamp; - static int cindirectDeep = 0; - - DBUG("do_menu","called"); - - key_press = (eventp && (eventp == (XEvent *)1 || eventp->type == KeyPress)); - /* this condition could get ugly */ - if(menu == NULL || menu->in_use) { - /* DBUG("do_menu","menu->in_use for %s -- returning",menu->name); */ - return MENU_ERROR; - } - - /* Try to pick a root-relative optimal x,y to - put the mouse right on the title w/o warping */ - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - /* Save these-- we want to warp back here if this is a top level - menu brought up by a keystroke */ - if (cmenuDeep == 0 && cindirectDeep == 0) { - if (key_press) { - x_start = x; - y_start = y; - } else { - x_start = -1; - y_start = -1; - } - } - /* calculate position from positioning hints */ - if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { - pops->pos_hints.x += pops->pos_hints.x_factor * menu->width; - pops->pos_hints.y += pops->pos_hints.y_factor * menu->height; - } - /* Figure out where we should popup, if possible */ - if (!FMenuMapped(menu)) { - if(cmenuDeep > 0) { - /* this is a submenu popup */ - assert(menuPrior); - if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { - x = pops->pos_hints.x; - y = pops->pos_hints.y; - } else { - GetPreferredPopupPosition(menuPrior, &x, &y); - } - } else { - /* we're a top level menu */ - mouse_moved = FALSE; - if(!GrabEm(MENU)) { /* GrabEm specifies the cursor to use */ - XBell(dpy, 0); - return MENU_ABORTED; - } - if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { - x = pops->pos_hints.x; - y = pops->pos_hints.y; - } else { - /* Make the menu appear under the pointer rather than warping */ - x -= MENU_MIDDLE_OFFSET(menu); - y -= menu->ms->look.EntryHeight/2 + 2; - } - } - - /* FPopupMenu may move the x,y to make it fit on screen more nicely */ - /* it might also move menuPrior out of the way */ - if (!FPopupMenu (menu, menuPrior, x, y, key_press /*warp*/, pops, NULL)) { - fFailedPopup = TRUE; - XBell (dpy, 0); - } - } - else { - fWasAlreadyPopped = TRUE; - if (key_press) MiWarpPointerToItem(menu->first, TRUE /* skip Title */); - } - fWarpPointerToTitle = FALSE; - - menu->in_use = TRUE; - /* Remember the key that popped up the root menu. */ - if (!(cmenuDeep++)) { - if (eventp && eventp != (XEvent *)1) { - /* we have a real key event */ - dkp_keystate = eventp->xkey.state; - dkp_keycode = eventp->xkey.keycode; - } - dkp_timestamp = (key_press) ? t0 : 0; - } - if (!fFailedPopup) - retval = MenuInteraction(menu,menuPrior,pmiExecuteAction,cmenuDeep,fStick); - else - retval = MENU_ABORTED; - cmenuDeep--; - menu->in_use = FALSE; - - if (!fWasAlreadyPopped) - PopDownMenu(menu); - /* FIX: this global is bad */ - menuFromFrameOrWindowOrTitlebar = FALSE; - XFlush(dpy); - - if (cmenuDeep == 0 && x_start >= 0 && y_start >= 0 && - IS_MENU_BUTTON(retval)) { - /* warp pointer back to where invoked if this was brought up - with a keypress and we're returning from a top level menu, - and a button release event didn't end it */ - XWarpPointer(dpy, 0, Scr.Root, 0, 0, - Scr.MyDisplayWidth, Scr.MyDisplayHeight,x_start, y_start); - } - - if (lastTimestamp-t0 < Scr.menus.DoubleClickTime && !mouse_moved && - (!key_press || dkp_timestamp != 0)) { - /* dkp_timestamp is non-zero if a double-keypress occured! */ - fDoubleClick = TRUE; - } - dkp_timestamp = 0; - if(cmenuDeep == 0) { - UngrabEm(); - WaitForButtonsUp(); - if (retval == MENU_DONE || retval == MENU_DONE_BUTTON) { - if (pmiExecuteAction && *pmiExecuteAction && !fDoubleClick) { - cindirectDeep++; - ExecuteFunction( - (*pmiExecuteAction)->action,ButtonWindow, &Event,Context, -1); - cindirectDeep--; - } - fIgnorePosHints = FALSE; - fLastMenuPosHintsValid = FALSE; - } - } - - if (fDoubleClick) - retval = MENU_DOUBLE_CLICKED; - return retval; -} + MenuStatus retval = MENU_NOP; + int x, y; + static int x_start, y_start; + Bool fFailedPopup = FALSE; + Bool fWasAlreadyPopped = FALSE; + Bool key_press; + Bool fDoubleClick = FALSE; + Time t0 = lastTimestamp; + extern Time lastTimestamp; + static int cindirectDeep = 0; + + DBUG("do_menu", "called"); + + key_press = + (eventp && (eventp == (XEvent *)1 || eventp->type == KeyPress)); + /* this condition could get ugly */ + if (menu == NULL || menu->in_use) { + /* DBUG("do_menu","menu->in_use for %s -- + * returning",menu->name); */ + return MENU_ERROR; + } + + /* Try to pick a root-relative optimal x,y to + put the mouse right on the title w/o warping */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); + /* Save these-- we want to warp back here if this is a top level + menu brought up by a keystroke */ + if (cmenuDeep == 0 && cindirectDeep == 0) { + if (key_press) { + x_start = x; + y_start = y; + } else { + x_start = -1; + y_start = -1; + } + } + /* calculate position from positioning hints */ + if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { + pops->pos_hints.x += pops->pos_hints.x_factor * menu->width; + pops->pos_hints.y += pops->pos_hints.y_factor * menu->height; + } + /* Figure out where we should popup, if possible */ + if (!FMenuMapped(menu)) { + if (cmenuDeep > 0) { + /* this is a submenu popup */ + assert(menuPrior); + if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { + x = pops->pos_hints.x; + y = pops->pos_hints.y; + } else { + GetPreferredPopupPosition(menuPrior, &x, &y); + } + } else { + /* we're a top level menu */ + mouse_moved = FALSE; + if (!GrabEm(MENU)) { /* GrabEm specifies the cursor to + use */ + XBell(dpy, 0); + return MENU_ABORTED; + } + if ((pops->flags.f.has_poshints) && !fIgnorePosHints) { + x = pops->pos_hints.x; + y = pops->pos_hints.y; + } else { + /* Make the menu appear under the pointer rather + * than warping */ + x -= MENU_MIDDLE_OFFSET(menu); + y -= menu->ms->look.EntryHeight / 2 + 2; + } + } + /* FPopupMenu may move the x,y to make it fit on screen more + * nicely */ + /* it might also move menuPrior out of the way */ + if (!FPopupMenu(menu, menuPrior, x, y, key_press /*warp*/, pops, + NULL)) { + fFailedPopup = TRUE; + XBell(dpy, 0); + } + } else { + fWasAlreadyPopped = TRUE; + if (key_press) + MiWarpPointerToItem(menu->first, TRUE /* skip Title */); + } + fWarpPointerToTitle = FALSE; + + menu->in_use = TRUE; + /* Remember the key that popped up the root menu. */ + if (!(cmenuDeep++)) { + if (eventp && eventp != (XEvent *)1) { + /* we have a real key event */ + dkp_keystate = eventp->xkey.state; + dkp_keycode = eventp->xkey.keycode; + } + dkp_timestamp = (key_press) ? t0 : 0; + } + if (!fFailedPopup) + retval = MenuInteraction( + menu, menuPrior, pmiExecuteAction, cmenuDeep, fStick); + else + retval = MENU_ABORTED; + cmenuDeep--; + menu->in_use = FALSE; + + if (!fWasAlreadyPopped) + PopDownMenu(menu); + /* FIX: this global is bad */ + menuFromFrameOrWindowOrTitlebar = FALSE; + XFlush(dpy); + + if (cmenuDeep == 0 && x_start >= 0 && y_start >= 0 && + IS_MENU_BUTTON(retval)) { + /* warp pointer back to where invoked if this was brought up + with a keypress and we're returning from a top level menu, + and a button release event didn't end it */ + XWarpPointer(dpy, 0, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x_start, y_start); + } + + if (lastTimestamp - t0 < Scr.menus.DoubleClickTime && !mouse_moved && + (!key_press || dkp_timestamp != 0)) { + /* dkp_timestamp is non-zero if a double-keypress occured! */ + fDoubleClick = TRUE; + } + dkp_timestamp = 0; + if (cmenuDeep == 0) { + UngrabEm(); + WaitForButtonsUp(); + if (retval == MENU_DONE || retval == MENU_DONE_BUTTON) { + if (pmiExecuteAction && *pmiExecuteAction && + !fDoubleClick) { + cindirectDeep++; + ExecuteFunction((*pmiExecuteAction)->action, + ButtonWindow, &Event, Context, -1); + cindirectDeep--; + } + fIgnorePosHints = FALSE; + fLastMenuPosHintsValid = FALSE; + } + } + + if (fDoubleClick) + retval = MENU_DOUBLE_CLICKED; + return retval; +} /*********************************************************************** * @@ -294,114 +308,115 @@ MenuStatus do_menu(MenuRoot *menu, MenuRoot *menuPrior, * * Return value is a menu item ***********************************************************************/ -static -MenuItem *FindEntry(int *px_offset /*NULL means don't return this value */) +static MenuItem * +FindEntry(int *px_offset /*NULL means don't return this value */) { - MenuItem *mi; - MenuRoot *mr; - int root_x, root_y; - int x,y; - Window Child; - - /* x_offset returns the x offset of the pointer in the found menu item */ - if (px_offset) - *px_offset = 0; - - XQueryPointer( dpy, Scr.Root, &JunkRoot, &Child, - &root_x,&root_y, &JunkX, &JunkY, &JunkMask); - if (XFindContext (dpy, Child,MenuContext,(caddr_t *)&mr)==XCNOENT) { - return NULL; - } - - /* now get position in that child window */ - XQueryPointer( dpy, Child, &JunkRoot, &JunkChild, - &root_x,&root_y, &x, &y, &JunkMask); - - /* look for the entry that the mouse is in */ - for(mi=mr->first; mi; mi=mi->next) - if(y>=mi->y_offset && y<=mi->y_offset+mi->y_height) - break; - if(xxoffset || x>mr->width+2) - mi = NULL; - - if (mi && px_offset) - *px_offset = x; - - return mi; + MenuItem *mi; + MenuRoot *mr; + int root_x, root_y; + int x, y; + Window Child; + + /* x_offset returns the x offset of the pointer in the found menu item + */ + if (px_offset) + *px_offset = 0; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &Child, &root_x, &root_y, + &JunkX, &JunkY, &JunkMask); + if (XFindContext(dpy, Child, MenuContext, (caddr_t *)&mr) == XCNOENT) { + return NULL; + } + + /* now get position in that child window */ + XQueryPointer(dpy, Child, &JunkRoot, &JunkChild, &root_x, &root_y, &x, + &y, &JunkMask); + + /* look for the entry that the mouse is in */ + for (mi = mr->first; mi; mi = mi->next) + if (y >= mi->y_offset && y <= mi->y_offset + mi->y_height) + break; + if (x < mr->xoffset || x > mr->width + 2) + mi = NULL; + + if (mi && px_offset) + *px_offset = x; + + return mi; } /* return the appropriate x offset from the prior menu to use as the location of a popup menu */ -static -int PopupPositionOffset(MenuRoot *mr) +static int +PopupPositionOffset(MenuRoot *mr) { - return (mr->width * mr->ms->feel.PopupOffsetPercent / 100 + - mr->ms->feel.PopupOffsetAdd); + return (mr->width * mr->ms->feel.PopupOffsetPercent / 100 + + mr->ms->feel.PopupOffsetAdd); } -static -void GetPreferredPopupPosition(MenuRoot *mr, int *px, int *py) +static void +GetPreferredPopupPosition(MenuRoot *mr, int *px, int *py) { - int menu_x, menu_y; - XGetGeometry(dpy,mr->w,&JunkRoot,&menu_x,&menu_y, - &JunkWidth,&JunkHeight,&JunkBW,&JunkDepth); - *px = menu_x + PopupPositionOffset(mr); - *py = menu_y; - if(mr->selected) { - /* *py = mr->selected->y_offset + menu_y - (mr->ms->look.EntryHeight/2); */ - *py = mr->selected->y_offset + menu_y; - } + int menu_x, menu_y; + XGetGeometry(dpy, mr->w, &JunkRoot, &menu_x, &menu_y, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth); + *px = menu_x + PopupPositionOffset(mr); + *py = menu_y; + if (mr->selected) { + /* *py = mr->selected->y_offset + menu_y - + * (mr->ms->look.EntryHeight/2); */ + *py = mr->selected->y_offset + menu_y; + } } - -static -int IndexFromMi(MenuItem *miTarget) +static int +IndexFromMi(MenuItem *miTarget) { - int i = 0; - MenuRoot *mr = miTarget->mr; - MenuItem *mi = mr->first; - for (; mi && mi != miTarget; mi = mi->next) { - if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) - i++; - } - if (mi == miTarget) { - /* DBUG("IndexFromMi","%s = %d",miTarget->item,i); */ - return i; - } - return -1; + int i = 0; + MenuRoot *mr = miTarget->mr; + MenuItem *mi = mr->first; + for (; mi && mi != miTarget; mi = mi->next) { + if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) + i++; + } + if (mi == miTarget) { + /* DBUG("IndexFromMi","%s = %d",miTarget->item,i); */ + return i; + } + return -1; } -static -Bool FMenuMapped(MenuRoot *menu) +static Bool +FMenuMapped(MenuRoot *menu) { - XWindowAttributes win_attribs; - XGetWindowAttributes(dpy,menu->w,&win_attribs); - return (menu->w == None) ? False : (win_attribs.map_state == IsViewable); + XWindowAttributes win_attribs; + XGetWindowAttributes(dpy, menu->w, &win_attribs); + return (menu->w == None) ? False : + (win_attribs.map_state == IsViewable); } -static -MenuItem *MiFromMenuIndex(MenuRoot *mr, int index) +static MenuItem * +MiFromMenuIndex(MenuRoot *mr, int index) { - int i = -1; - MenuItem *mi = mr->first; - MenuItem *miLastOk = NULL; - for (; mi && (i < index || miLastOk == NULL); mi=mi->next) { - if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) { - miLastOk = mi; - i++; - } - } - /* DBUG("MiFromMenuIndex","%d = %s",index,miLastOk->item); */ - return miLastOk; + int i = -1; + MenuItem *mi = mr->first; + MenuItem *miLastOk = NULL; + for (; mi && (i < index || miLastOk == NULL); mi = mi->next) { + if (!IS_TITLE_MENU_ITEM(mi) && !IS_SEPARATOR_MENU_ITEM(mi)) { + miLastOk = mi; + i++; + } + } + /* DBUG("MiFromMenuIndex","%d = %s",index,miLastOk->item); */ + return miLastOk; } -static -int CmiFromMenu(MenuRoot *mr) +static int +CmiFromMenu(MenuRoot *mr) { - return IndexFromMi(mr->last); + return IndexFromMi(mr->last); } - /*********************************************************************** * Procedure * menuShortcuts() - Menu keyboard processing @@ -414,152 +429,154 @@ int CmiFromMenu(MenuRoot *mr) * routine is called. * TKP - uses XLookupString so that keypad numbers work with windowlist ***********************************************************************/ -static -MenuStatus menuShortcuts(MenuRoot *menu,XEvent *Event,MenuItem **pmiCurrent) +static MenuStatus +menuShortcuts(MenuRoot *menu, XEvent *Event, MenuItem **pmiCurrent) { - int fControlKey = Event->xkey.state & ControlMask? TRUE : FALSE; - int fShiftedKey = Event->xkey.state & ShiftMask? TRUE: FALSE; - KeySym keysym; - char keychar; - MenuItem *newItem; - MenuItem *miCurrent = pmiCurrent?*pmiCurrent:NULL; - int index; - - /* handle double-keypress */ - if (dkp_timestamp && - lastTimestamp-dkp_timestamp < Scr.menus.DoubleClickTime && - Event->xkey.state == dkp_keystate && Event->xkey.keycode == dkp_keycode){ - *pmiCurrent = NULL; - return MENU_SELECTED; - } - dkp_timestamp = 0; - /* Is it okay to treat keysym-s as Ascii? */ - /* No, because the keypad numbers don't work. Use XlookupString */ - index = XLookupString(&(Event->xkey), &keychar, 1, &keysym, NULL); - /* Try to match hot keys */ - /* Need isascii here - isgraph might coredump! */ - if (index == 1 && isascii((int)keychar) && isgraph((int)keychar) && - fControlKey == FALSE) { - /* allow any printable character to be a keysym, but be sure control - isn't pressed */ - MenuItem *mi; - char key; - /* Search menu for matching hotkey */ - for (mi = menu->first; mi; mi = mi->next) { - key = tolower(mi->chHotkey); - if (keychar == key) { - *pmiCurrent = mi; - if (IS_POPUP_MENU_ITEM(mi)) - return MENU_POPUP; - else - return MENU_SELECTED; - } - } - } - - switch(keysym) /* Other special keyboard handling */ - { - case XK_Escape: /* Escape key pressed. Abort */ - return MENU_ABORTED; - break; - - case XK_Return: - case XK_KP_Enter: - return MENU_SELECTED; - break; - - case XK_Left: - case XK_KP_4: - case XK_b: /* back */ - case XK_h: /* vi left */ - return MENU_POPDOWN; - break; - - case XK_Right: - case XK_KP_6: - case XK_f: /* forward */ - case XK_l: /* vi right */ - if (IS_POPUP_MENU_ITEM(miCurrent)) - return MENU_POPUP; - break; - - case XK_Up: - case XK_KP_8: - case XK_k: /* vi up */ - case XK_p: /* prior */ - if (!miCurrent) { - if ((*pmiCurrent = menu->last) != NULL) - return MENU_NEWITEM; - else - return MENU_NOP; - } - /* Need isascii here - isgraph might coredump! */ - if (isascii(keysym) && isgraph(keysym)) - fControlKey = FALSE; /* don't use control modifier - for k or p, since those might - be shortcuts too-- C-k, C-p will - always work to do a single up */ - index = IndexFromMi(miCurrent); - if (index == 0) - /* wraparound */ - index = CmiFromMenu(miCurrent->mr); - else if (fShiftedKey) - index = 0; - else { - index -= (fControlKey?5:1); - } - newItem = MiFromMenuIndex(miCurrent->mr,index); - if (newItem) { - *pmiCurrent = newItem; - return MENU_NEWITEM; - } else - return MENU_NOP; - break; - - case XK_Down: - case XK_KP_2: - case XK_j: /* vi down */ - case XK_n: /* next */ - if (!miCurrent) { - if ((*pmiCurrent = MiFromMenuIndex(menu,0)) != NULL) - return MENU_NEWITEM; - else - return MENU_NOP; - } - /* Need isascii here - isgraph might coredump! */ - if (isascii(keysym) && isgraph(keysym)) - fControlKey = FALSE; /* don't use control modifier - for j or n, since those might - be shortcuts too-- C-j, C-n will - always work to do a single down */ - if (fShiftedKey) - index = CmiFromMenu(miCurrent->mr); - else { - index = IndexFromMi(miCurrent) + (fControlKey?5:1); - /* correct for the case that we're between items */ - if (IS_SEPARATOR_MENU_ITEM(miCurrent) || - IS_TITLE_MENU_ITEM(miCurrent)) - index--; - } - newItem = MiFromMenuIndex(miCurrent->mr,index); - if (newItem == miCurrent) - newItem = MiFromMenuIndex(miCurrent->mr,0); - if (newItem) { - *pmiCurrent = newItem; - return MENU_NEWITEM; - } else - return MENU_NOP; - break; + int fControlKey = Event->xkey.state & ControlMask ? TRUE : FALSE; + int fShiftedKey = Event->xkey.state & ShiftMask ? TRUE : FALSE; + KeySym keysym; + char keychar; + MenuItem *newItem; + MenuItem *miCurrent = pmiCurrent ? *pmiCurrent : NULL; + int index; + + /* handle double-keypress */ + if (dkp_timestamp && + lastTimestamp - dkp_timestamp < Scr.menus.DoubleClickTime && + Event->xkey.state == dkp_keystate && + Event->xkey.keycode == dkp_keycode) { + *pmiCurrent = NULL; + return MENU_SELECTED; + } + dkp_timestamp = 0; + /* Is it okay to treat keysym-s as Ascii? */ + /* No, because the keypad numbers don't work. Use XlookupString */ + index = XLookupString(&(Event->xkey), &keychar, 1, &keysym, NULL); + /* Try to match hot keys */ + /* Need isascii here - isgraph might coredump! */ + if (index == 1 && isascii((int)keychar) && isgraph((int)keychar) && + fControlKey == FALSE) { + /* allow any printable character to be a keysym, but be sure + control isn't pressed */ + MenuItem *mi; + char key; + /* Search menu for matching hotkey */ + for (mi = menu->first; mi; mi = mi->next) { + key = tolower(mi->chHotkey); + if (keychar == key) { + *pmiCurrent = mi; + if (IS_POPUP_MENU_ITEM(mi)) + return MENU_POPUP; + else + return MENU_SELECTED; + } + } + } - /* Nothing special --- Allow other shortcuts */ - default: - /* There are no useful shortcuts, so don't do that. - * (Dominik Vogt, 11-Nov-1998) - * Keyboard_shortcuts(Event, NULL, ButtonRelease); */ - break; - } + switch (keysym) { /* Other special keyboard handling */ + case XK_Escape: /* Escape key pressed. Abort */ + return MENU_ABORTED; + break; + + case XK_Return: + case XK_KP_Enter: + return MENU_SELECTED; + break; + + case XK_Left: + case XK_KP_4: + case XK_b: /* back */ + case XK_h: /* vi left */ + return MENU_POPDOWN; + break; + + case XK_Right: + case XK_KP_6: + case XK_f: /* forward */ + case XK_l: /* vi right */ + if (IS_POPUP_MENU_ITEM(miCurrent)) + return MENU_POPUP; + break; + + case XK_Up: + case XK_KP_8: + case XK_k: /* vi up */ + case XK_p: /* prior */ + if (!miCurrent) { + if ((*pmiCurrent = menu->last) != NULL) + return MENU_NEWITEM; + else + return MENU_NOP; + } + /* Need isascii here - isgraph might coredump! */ + if (isascii(keysym) && isgraph(keysym)) + fControlKey = + FALSE; /* don't use control modifier + for k or p, since those might + be shortcuts too-- C-k, C-p will + always work to do a single up */ + index = IndexFromMi(miCurrent); + if (index == 0) + /* wraparound */ + index = CmiFromMenu(miCurrent->mr); + else if (fShiftedKey) + index = 0; + else { + index -= (fControlKey ? 5 : 1); + } + newItem = MiFromMenuIndex(miCurrent->mr, index); + if (newItem) { + *pmiCurrent = newItem; + return MENU_NEWITEM; + } else + return MENU_NOP; + break; + + case XK_Down: + case XK_KP_2: + case XK_j: /* vi down */ + case XK_n: /* next */ + if (!miCurrent) { + if ((*pmiCurrent = MiFromMenuIndex(menu, 0)) != NULL) + return MENU_NEWITEM; + else + return MENU_NOP; + } + /* Need isascii here - isgraph might coredump! */ + if (isascii(keysym) && isgraph(keysym)) + fControlKey = + FALSE; /* don't use control modifier + for j or n, since those might + be shortcuts too-- C-j, C-n will + always work to do a single down */ + if (fShiftedKey) + index = CmiFromMenu(miCurrent->mr); + else { + index = IndexFromMi(miCurrent) + (fControlKey ? 5 : 1); + /* correct for the case that we're between items */ + if (IS_SEPARATOR_MENU_ITEM(miCurrent) || + IS_TITLE_MENU_ITEM(miCurrent)) + index--; + } + newItem = MiFromMenuIndex(miCurrent->mr, index); + if (newItem == miCurrent) + newItem = MiFromMenuIndex(miCurrent->mr, 0); + if (newItem) { + *pmiCurrent = newItem; + return MENU_NEWITEM; + } else + return MENU_NOP; + break; + + /* Nothing special --- Allow other shortcuts */ + default: + /* There are no useful shortcuts, so don't do that. + * (Dominik Vogt, 11-Nov-1998) + * Keyboard_shortcuts(Event, NULL, ButtonRelease); */ + break; + } - return MENU_NOP; + return MENU_NOP; } #define MICRO_S_FOR_10MS 10000 @@ -584,510 +601,564 @@ MenuStatus menuShortcuts(MenuRoot *menu,XEvent *Event,MenuItem **pmiCurrent) * *pmiExecuteAction * ***********************************************************************/ -static -MenuStatus MenuInteraction(MenuRoot *menu,MenuRoot *menuPrior, - MenuItem **pmiExecuteAction,int cmenuDeep, - Bool fSticks) +static MenuStatus +MenuInteraction(MenuRoot *menu, MenuRoot *menuPrior, + MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks) { - Bool fPopupImmediately; - MenuItem *mi = NULL, *tmi; - MenuRoot *mrPopup = NULL; - MenuRoot *mrMiPopup = NULL; - MenuRoot *mrNeedsPainting = NULL; - Bool fDoPopupNow = FALSE; /* used for delay popups, to just popup the menu */ - Bool fPopupAndWarp = FALSE; /* used for keystrokes, to popup and move to - * that menu */ - Bool fKeyPress = FALSE; - Bool fForceReposition = TRUE; - int x_init = 0, y_init = 0; - int x_offset = 0; - MenuStatus retval = MENU_NOP; - int c10msDelays = 0; - MenuOptions mops; - Bool fOffMenuAllowed = FALSE; - Bool fPopdown = FALSE; - Bool fPopup = FALSE; - Bool fDoMenu = FALSE; - Bool fMotionFirst = FALSE; - Bool fReleaseFirst = FALSE; - Bool fFakedMotion = FALSE; - Bool fSubmenuOverlaps = False; - - mops.flags.allflags = 0; - fPopupImmediately = (menu->ms->feel.f.PopupImmediately && - (Scr.menus.PopupDelay10ms > 0)); - - /* remember where the pointer was so we can tell if it has moved */ - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x_init, &y_init, &JunkX, &JunkY, &JunkMask); - - while (TRUE) { - fPopupAndWarp = FALSE; - fDoPopupNow = FALSE; - fKeyPress = FALSE; - if (fForceReposition) { - Event.type = MotionNotify; - Event.xmotion.time = lastTimestamp; - fFakedMotion = TRUE; - fForceReposition = FALSE; - } else if (!XCheckMaskEvent(dpy,ExposureMask,&Event)) { - /* handle exposure events first */ - if (Scr.menus.PopupDelay10ms > 0) { - while (XCheckMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask| - ExposureMask|KeyPressMask| - VisibilityChangeMask|ButtonMotionMask, - &Event) == FALSE) { - usleep(MICRO_S_FOR_10MS); - if (c10msDelays++ == Scr.menus.PopupDelay10ms) { - DBUG("MenuInteraction","Faking motion"); - /* fake a motion event, and set fDoPopupNow */ - Event.type = MotionNotify; - Event.xmotion.time = lastTimestamp; - fFakedMotion = TRUE; - fDoPopupNow = TRUE; - break; - } - } - } else { /* block until there is an event */ - XMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask|ExposureMask | - KeyPressMask|VisibilityChangeMask|ButtonMotionMask, - &Event); - } - } - /*DBUG("MenuInteraction","mrPopup=%s",mrPopup?mrPopup->name:"(none)");*/ - - StashEventTime(&Event); - if (Event.type == MotionNotify) { - /* discard any extra motion events before a release */ - while((XCheckMaskEvent(dpy,ButtonMotionMask|ButtonReleaseMask, - &Event))&&(Event.type != ButtonRelease)); - } - - switch(Event.type) - { - case ButtonRelease: - mi = FindEntry(&x_offset); - /* hold the menu up when the button is released - for the first time if released OFF of the menu */ - if(fSticks && !fMotionFirst) { - fReleaseFirst = TRUE; - fSticks = FALSE; - continue; - /* break; */ - } - retval = mi?MENU_SELECTED:MENU_ABORTED; - dkp_timestamp = 0; - goto DO_RETURN; - - case ButtonPress: - /* if the first event is a button press allow the release to - select something */ - fSticks = FALSE; - continue; - - case VisibilityNotify: - continue; - - case KeyPress: - /* Handle a key press events to allow mouseless operation */ - fKeyPress = TRUE; - x_offset = 0; - retval = menuShortcuts(menu,&Event,&mi); - if (retval == MENU_POPDOWN || - retval == MENU_ABORTED || - retval == MENU_SELECTED) - goto DO_RETURN; - /* now warp to the new menu-item, if any */ - if (mi && mi != FindEntry(NULL)) { - MiWarpPointerToItem(mi,FALSE); - /* DBUG("MenuInteraction","Warping on keystroke to %s",mi->item);*/ - } - if (retval == MENU_POPUP && IS_POPUP_MENU_ITEM(mi)) { - fPopupAndWarp = TRUE; - DBUG("MenuInteraction","fPopupAndWarp = TRUE"); - break; - } - break; - - case MotionNotify: - if (mouse_moved == FALSE) { - int x_root, y_root; - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x_root,&y_root, &JunkX, &JunkY, &JunkMask); - if(x_root-x_init > 3 || x_init-x_root > 3 || - y_root-y_init > 3 || y_init-y_root > 3) { - /* global variable remember that this isn't just - a click any more since the pointer moved */ - mouse_moved = TRUE; - } - } - mi = FindEntry(&x_offset); - if (!fReleaseFirst && !fFakedMotion && mouse_moved) - fMotionFirst = TRUE; - fFakedMotion = FALSE; - break; - - case Expose: - /* grab our expose events, let the rest go through */ - if((XFindContext(dpy, Event.xany.window,MenuContext, - (caddr_t *)&mrNeedsPainting)!=XCNOENT)) { - flush_expose(Event.xany.window); - PaintMenu(mrNeedsPainting,&Event); - } - /* continue; */ /* instead of continuing, we want to - dispatch this too by letting it fall - through so window decorations get redrawn - after being obscured by menus */ - s_Tmp_win = Tmp_win; /* BUT we need to save Tmp_win first - because DispatchEvent changes - Tmp_win and messes up our calls to - check_allowed_function for stippling - disallowed menu items */ - - default: - DispatchEvent(); - if (s_Tmp_win) - { - Tmp_win = s_Tmp_win; /* restore Tmp_win */ - s_Tmp_win = NULL; - continue; /* now 'continue' if event was an expose */ - } - break; - } /* switch (Event.type) */ - - /* Now handle new menu items, whether it is from a keypress or - a pointer motion event */ - if (mi) { - /* we're on a menu item */ - fOffMenuAllowed = FALSE; - mrMiPopup = MrPopupForMi(mi); - if (mi->mr != menu && mi->mr != mrPopup && mi->mr != mrMiPopup) { - /* we're on an item from a prior menu */ - /* DBUG("MenuInteraction","menu %s: returning popdown",menu->name);*/ - retval = MENU_POPDOWN; - dkp_timestamp = 0; - goto DO_RETURN; - } - - /* see if we're on a new item of this menu */ - if (mi != menu->selected && mi->mr == menu) { - c10msDelays = 0; - /* we're on the same menu, but a different item, - so we need to unselect the old item */ - if (menu->selected) { - /* something else was already selected on this menu */ - if (mrPopup) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - mrPopup = NULL; - } - /* We have to pop down the menu before unselecting the item in case - * we are using gradient menus. The recalled image would paint over - * the submenu. */ - SetMenuItemSelected(menu->selected,FALSE); - } else { - /* DBUG("MenuInteraction","Menu %s had nothing else selected", - menu->name); */ - } - /* do stuff to highlight the new item; this - sets menu->selected, too */ - SetMenuItemSelected(mi,TRUE); - } /* new item of the same menu */ - - /* check what has to be done with the item */ - fPopdown = FALSE; - fPopup = FALSE; - fDoMenu = FALSE; - - if (mi->mr == mrPopup) { - /* must make current popup menu a real menu */ - fDoMenu = TRUE; - } - else if (fPopupAndWarp) { - /* must create a real menu and warp into it */ - if (mrPopup == NULL || mrPopup != mrMiPopup) { - fPopup = TRUE; - } else { - XRaiseWindow(dpy, mrPopup->w); - MiWarpPointerToItem(mrPopup->first,TRUE); - fDoMenu = TRUE; - } - } - else if (IS_POPUP_MENU_ITEM(mi)) { - if (x_offset >= mi->mr->width*3/4 || fDoPopupNow || - fPopupImmediately) { - /* must create a new menu or popup */ - if (mrPopup == NULL || mrPopup != mrMiPopup) - fPopup = TRUE; - else if (fPopupAndWarp) - MiWarpPointerToItem(mrPopup->first,TRUE); - } - } /* else if (IS_POPUP_MENU_ITEM(mi)) */ - if (fPopup && mrPopup && mrPopup != mrMiPopup) { - /* must remove previous popup first */ - fPopdown = TRUE; - } - - if (fPopdown) { - DBUG("MenuInteraction","Popping down"); - /* popdown previous popup */ - if (mrPopup) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - } - mrPopup = NULL; - fPopdown = FALSE; - } - if (fPopup) { - DBUG("MenuInteraction","Popping up"); - /* get pos hints for item's action */ - GetPopupOptions(mi,&mops); - mrPopup = mrMiPopup; - if (!mrPopup) { - fDoMenu = FALSE; - fPopdown = FALSE; - } else { - /* create a popup menu */ - if (!FMenuMapped(mrPopup)) { - /* We want to pop prepop menus so it doesn't *have* to be - unpopped; do_menu pops down any menus it pops up, but we - want to be able to popdown w/o actually removing the menu */ - int x, y; - if (mops.flags.f.has_poshints) { - x = mops.pos_hints.x + mops.pos_hints.x_factor*mrPopup->width; - y = mops.pos_hints.y + mops.pos_hints.y_factor*mrPopup->height; - } else { - GetPreferredPopupPosition(menu,&x,&y); - } - FPopupMenu(mrPopup, menu, x, y, fPopupAndWarp, &mops, - &fSubmenuOverlaps); - } - if (mrPopup->mrDynamicPrev == menu) { - mi = FindEntry(NULL); - if (mi && mi->mr == mrPopup) { - fDoMenu = TRUE; - fPopdown = !menu->ms->feel.f.PopupImmediately; - } - } - else { - /* This menu must be already mapped somewhere else, so ignore - * it completely. */ - fDoMenu = FALSE; - fPopdown = FALSE; - mrPopup = NULL; - } - } /* if (!mrPopup) */ - } /* if (fPopup) */ - if (fDoMenu) { - /* recursively do the new menu we've moved into */ - retval = do_menu(mrPopup,menu,pmiExecuteAction,cmenuDeep,FALSE, - (fPopupAndWarp) ? (XEvent *)1 : NULL, &mops); - if (IS_MENU_RETURN(retval)) { - dkp_timestamp = 0; - goto DO_RETURN; - } - if (fPopdown || !menu->ms->feel.f.PopupImmediately) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - mrPopup = NULL; - } - if (retval == MENU_POPDOWN) { - c10msDelays = 0; - fForceReposition = TRUE; - } - } /* if (fDoMenu) */ - - /* Now check whether we can animate the current popup menu - over to the right to unobscure the current menu; this - happens only when using animation */ - tmi = FindEntry(NULL); - if (mrPopup && mrPopup->xanimation && tmi && - (tmi == menu->selected || tmi->mr != menu)) { - int x_popup, y_popup; - DBUG("MenuInteraction","Moving the popup menu back over"); - XGetGeometry(dpy, mrPopup->w, &JunkRoot, &x_popup, &y_popup, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - /* move it back */ - AnimatedMoveOfWindow(mrPopup->w,x_popup,y_popup, - x_popup-mrPopup->xanimation, y_popup, - FALSE /* no warp ptr */,-1,NULL); - mrPopup->xanimation = 0; - } - /* now check whether we should animate the current real menu - over to the right to unobscure the prior menu; only a very - limited case where this might be helpful and not too disruptive */ - if (mrPopup == NULL && menuPrior != NULL && menu->xanimation != 0 && - x_offset < menu->width/4) { - int x_menu, y_menu; - DBUG("MenuInteraction","Moving the menu back over"); - /* we have to see if we need menu to be moved */ - XGetGeometry( dpy, menu->w, &JunkRoot, &x_menu, &y_menu, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - /* move it back */ - AnimatedMoveOfWindow(menu->w,x_menu,y_menu, - x_menu - menu->xanimation,y_menu, - TRUE /* warp ptr */,-1,NULL); - menu->xanimation = 0; - } + Bool fPopupImmediately; + MenuItem *mi = NULL, *tmi; + MenuRoot *mrPopup = NULL; + MenuRoot *mrMiPopup = NULL; + MenuRoot *mrNeedsPainting = NULL; + Bool fDoPopupNow = + FALSE; /* used for delay popups, to just popup the menu */ + Bool fPopupAndWarp = FALSE; /* used for keystrokes, to popup and move to + * that menu */ + Bool fKeyPress = FALSE; + Bool fForceReposition = TRUE; + int x_init = 0, y_init = 0; + int x_offset = 0; + MenuStatus retval = MENU_NOP; + int c10msDelays = 0; + MenuOptions mops; + Bool fOffMenuAllowed = FALSE; + Bool fPopdown = FALSE; + Bool fPopup = FALSE; + Bool fDoMenu = FALSE; + Bool fMotionFirst = FALSE; + Bool fReleaseFirst = FALSE; + Bool fFakedMotion = FALSE; + Bool fSubmenuOverlaps = False; + + mops.flags.allflags = 0; + fPopupImmediately = (menu->ms->feel.f.PopupImmediately && + (Scr.menus.PopupDelay10ms > 0)); + + /* remember where the pointer was so we can tell if it has moved */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x_init, &y_init, + &JunkX, &JunkY, &JunkMask); + + while (TRUE) { + fPopupAndWarp = FALSE; + fDoPopupNow = FALSE; + fKeyPress = FALSE; + if (fForceReposition) { + Event.type = MotionNotify; + Event.xmotion.time = lastTimestamp; + fFakedMotion = TRUE; + fForceReposition = FALSE; + } else if (!XCheckMaskEvent(dpy, ExposureMask, &Event)) { + /* handle exposure events first */ + if (Scr.menus.PopupDelay10ms > 0) { + while (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | + ExposureMask | KeyPressMask | + VisibilityChangeMask | + ButtonMotionMask, + &Event) == FALSE) { + usleep(MICRO_S_FOR_10MS); + if (c10msDelays++ == + Scr.menus.PopupDelay10ms) { + DBUG("MenuInteraction", + "Faking motion"); + /* fake a motion event, and set + * fDoPopupNow */ + Event.type = MotionNotify; + Event.xmotion.time = + lastTimestamp; + fFakedMotion = TRUE; + fDoPopupNow = TRUE; + break; + } + } + } else { /* block until there is an event */ + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | + ExposureMask | KeyPressMask | + VisibilityChangeMask | ButtonMotionMask, + &Event); + } + } + /*DBUG("MenuInteraction","mrPopup=%s",mrPopup?mrPopup->name:"(none)");*/ + + StashEventTime(&Event); + if (Event.type == MotionNotify) { + /* discard any extra motion events before a release */ + while ((XCheckMaskEvent(dpy, + ButtonMotionMask | ButtonReleaseMask, + &Event)) && + (Event.type != ButtonRelease)) + ; + } - } /* if (mi) */ - else { - /* moved off menu, deselect selected item... */ - if (menu->selected) { - SetMenuItemSelected(menu->selected,FALSE); - if (mrPopup && fOffMenuAllowed == FALSE) { - int x, y, mx, my; - unsigned int mw, mh; - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - XGetGeometry( dpy, menu->w, &JunkRoot, &mx, &my, - &mw, &mh, &JunkBW, &JunkDepth); - if ((!IS_LEFT_MENU(mrPopup) && x < mx) || - (!IS_RIGHT_MENU(mrPopup) && x > mx+mw) || - (!IS_UP_MENU(mrPopup) && y < my) || - (!IS_DOWN_MENU(mrPopup) && y > my+mh)) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - mrPopup = NULL; - } else { - fOffMenuAllowed = TRUE; - } - } /* if (mrPopup && fOffMenuAllowed == FALSE) */ - } /* if (menu->selected) */ - } /* else (!mi) */ - XFlush(dpy); - } /* while (TRUE) */ - - DO_RETURN: - if (mrPopup) { - PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); - } - if (retval == MENU_POPDOWN) { - if (menu->selected) - SetMenuItemSelected(menu->selected,FALSE); - if (fKeyPress) { - if (cmenuDeep == 1) - /* abort a root menu rather than pop it down */ - retval = MENU_ABORTED; - if (menuPrior && menuPrior->selected) { - MiWarpPointerToItem(menuPrior->selected, FALSE); - if (menuPrior->selected != FindEntry(NULL) && - menu->xanimation == 0) { - XRaiseWindow(dpy, menuPrior->w); + switch (Event.type) { + case ButtonRelease: + mi = FindEntry(&x_offset); + /* hold the menu up when the button is released + for the first time if released OFF of the menu */ + if (fSticks && !fMotionFirst) { + fReleaseFirst = TRUE; + fSticks = FALSE; + continue; + /* break; */ + } + retval = mi ? MENU_SELECTED : MENU_ABORTED; + dkp_timestamp = 0; + goto DO_RETURN; + + case ButtonPress: + /* if the first event is a button press allow the + release to select something */ + fSticks = FALSE; + continue; + + case VisibilityNotify: + continue; + + case KeyPress: + /* Handle a key press events to allow mouseless + * operation */ + fKeyPress = TRUE; + x_offset = 0; + retval = menuShortcuts(menu, &Event, &mi); + if (retval == MENU_POPDOWN || retval == MENU_ABORTED || + retval == MENU_SELECTED) + goto DO_RETURN; + /* now warp to the new menu-item, if any */ + if (mi && mi != FindEntry(NULL)) { + MiWarpPointerToItem(mi, FALSE); + /* DBUG("MenuInteraction","Warping on keystroke + * to %s",mi->item);*/ + } + if (retval == MENU_POPUP && IS_POPUP_MENU_ITEM(mi)) { + fPopupAndWarp = TRUE; + DBUG("MenuInteraction", "fPopupAndWarp = TRUE"); + break; + } + break; + + case MotionNotify: + if (mouse_moved == FALSE) { + int x_root, y_root; + XQueryPointer(dpy, Scr.Root, &JunkRoot, + &JunkChild, &x_root, &y_root, &JunkX, + &JunkY, &JunkMask); + if (x_root - x_init > 3 || + x_init - x_root > 3 || + y_root - y_init > 3 || + y_init - y_root > 3) { + /* global variable remember that this + isn't just a click any more since the + pointer moved */ + mouse_moved = TRUE; + } + } + mi = FindEntry(&x_offset); + if (!fReleaseFirst && !fFakedMotion && mouse_moved) + fMotionFirst = TRUE; + fFakedMotion = FALSE; + break; + + case Expose: + /* grab our expose events, let the rest go through */ + if ((XFindContext(dpy, Event.xany.window, MenuContext, + (caddr_t *)&mrNeedsPainting) != XCNOENT)) { + flush_expose(Event.xany.window); + PaintMenu(mrNeedsPainting, &Event); + } + /* continue; */ /* instead of continuing, we want to + dispatch this too by letting it fall + through so window decorations get redrawn + after being obscured by menus */ + s_Tmp_win = + Tmp_win; /* BUT we need to save Tmp_win first + because DispatchEvent changes + Tmp_win and messes up our calls to + check_allowed_function for stippling + disallowed menu items */ + + default: + DispatchEvent(); + if (s_Tmp_win) { + Tmp_win = s_Tmp_win; /* restore Tmp_win */ + s_Tmp_win = NULL; + continue; /* now 'continue' if event was an + expose */ + } + break; + } /* switch (Event.type) */ + + /* Now handle new menu items, whether it is from a keypress or + a pointer motion event */ + if (mi) { + /* we're on a menu item */ + fOffMenuAllowed = FALSE; + mrMiPopup = MrPopupForMi(mi); + if (mi->mr != menu && mi->mr != mrPopup && + mi->mr != mrMiPopup) { + /* we're on an item from a prior menu */ + /* DBUG("MenuInteraction","menu %s: returning + * popdown",menu->name);*/ + retval = MENU_POPDOWN; + dkp_timestamp = 0; + goto DO_RETURN; + } + + /* see if we're on a new item of this menu */ + if (mi != menu->selected && mi->mr == menu) { + c10msDelays = 0; + /* we're on the same menu, but a different item, + so we need to unselect the old item */ + if (menu->selected) { + /* something else was already selected + * on this menu */ + if (mrPopup) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + mrPopup = NULL; + } + /* We have to pop down the menu before + * unselecting the item in case we are + * using gradient menus. The recalled + * image would paint over the submenu. + */ + SetMenuItemSelected( + menu->selected, FALSE); + } else { + /* DBUG("MenuInteraction","Menu %s had + nothing else selected", menu->name); + */ + } + /* do stuff to highlight the new item; this + sets menu->selected, too */ + SetMenuItemSelected(mi, TRUE); + } /* new item of the same menu */ + + /* check what has to be done with the item */ + fPopdown = FALSE; + fPopup = FALSE; + fDoMenu = FALSE; + + if (mi->mr == mrPopup) { + /* must make current popup menu a real menu */ + fDoMenu = TRUE; + } else if (fPopupAndWarp) { + /* must create a real menu and warp into it */ + if (mrPopup == NULL || mrPopup != mrMiPopup) { + fPopup = TRUE; + } else { + XRaiseWindow(dpy, mrPopup->w); + MiWarpPointerToItem( + mrPopup->first, TRUE); + fDoMenu = TRUE; + } + } else if (IS_POPUP_MENU_ITEM(mi)) { + if (x_offset >= mi->mr->width * 3 / 4 || + fDoPopupNow || fPopupImmediately) { + /* must create a new menu or popup */ + if (mrPopup == NULL || + mrPopup != mrMiPopup) + fPopup = TRUE; + else if (fPopupAndWarp) + MiWarpPointerToItem( + mrPopup->first, TRUE); + } + } /* else if (IS_POPUP_MENU_ITEM(mi)) */ + if (fPopup && mrPopup && mrPopup != mrMiPopup) { + /* must remove previous popup first */ + fPopdown = TRUE; + } + + if (fPopdown) { + DBUG("MenuInteraction", "Popping down"); + /* popdown previous popup */ + if (mrPopup) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + } + mrPopup = NULL; + fPopdown = FALSE; + } + if (fPopup) { + DBUG("MenuInteraction", "Popping up"); + /* get pos hints for item's action */ + GetPopupOptions(mi, &mops); + mrPopup = mrMiPopup; + if (!mrPopup) { + fDoMenu = FALSE; + fPopdown = FALSE; + } else { + /* create a popup menu */ + if (!FMenuMapped(mrPopup)) { + /* We want to pop prepop menus + so it doesn't *have* to be + unpopped; do_menu pops down + any menus it pops up, but we + want to be able to popdown + w/o actually removing the + menu */ + int x, y; + if (mops.flags.f.has_poshints) { + x = mops.pos_hints.x + + mops.pos_hints + .x_factor * + mrPopup->width; + y = mops.pos_hints.y + + mops.pos_hints + .y_factor * + mrPopup->height; + } else { + GetPreferredPopupPosition( + menu, + &x, &y); + } + FPopupMenu(mrPopup, menu, x, y, + fPopupAndWarp, &mops, + &fSubmenuOverlaps); + } + if (mrPopup->mrDynamicPrev == menu) { + mi = FindEntry(NULL); + if (mi && mi->mr == mrPopup) { + fDoMenu = TRUE; + fPopdown = + !menu->ms->feel.f + .PopupImmediately; + } + } else { + /* This menu must be already + * mapped somewhere else, so + * ignore it completely. */ + fDoMenu = FALSE; + fPopdown = FALSE; + mrPopup = NULL; + } + } /* if (!mrPopup) */ + } /* if (fPopup) */ + if (fDoMenu) { + /* recursively do the new menu we've moved into + */ + retval = do_menu(mrPopup, menu, + pmiExecuteAction, cmenuDeep, FALSE, + (fPopupAndWarp) ? (XEvent *)1 : NULL, + &mops); + if (IS_MENU_RETURN(retval)) { + dkp_timestamp = 0; + goto DO_RETURN; + } + if (fPopdown || + !menu->ms->feel.f.PopupImmediately) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + mrPopup = NULL; + } + if (retval == MENU_POPDOWN) { + c10msDelays = 0; + fForceReposition = TRUE; + } + } /* if (fDoMenu) */ + + /* Now check whether we can animate the current popup + menu over to the right to unobscure the current menu; + this happens only when using animation */ + tmi = FindEntry(NULL); + if (mrPopup && mrPopup->xanimation && tmi && + (tmi == menu->selected || tmi->mr != menu)) { + int x_popup, y_popup; + DBUG("MenuInteraction", + "Moving the popup menu back over"); + XGetGeometry(dpy, mrPopup->w, &JunkRoot, + &x_popup, &y_popup, &JunkWidth, &JunkHeight, + &JunkBW, &JunkDepth); + /* move it back */ + AnimatedMoveOfWindow(mrPopup->w, x_popup, + y_popup, x_popup - mrPopup->xanimation, + y_popup, FALSE /* no warp ptr */, -1, NULL); + mrPopup->xanimation = 0; + } + /* now check whether we should animate the current real + menu over to the right to unobscure the prior menu; + only a very limited case where this might be helpful + and not too disruptive */ + if (mrPopup == NULL && menuPrior != NULL && + menu->xanimation != 0 && + x_offset < menu->width / 4) { + int x_menu, y_menu; + DBUG("MenuInteraction", + "Moving the menu back over"); + /* we have to see if we need menu to be moved */ + XGetGeometry(dpy, menu->w, &JunkRoot, &x_menu, + &y_menu, &JunkWidth, &JunkHeight, &JunkBW, + &JunkDepth); + /* move it back */ + AnimatedMoveOfWindow(menu->w, x_menu, y_menu, + x_menu - menu->xanimation, y_menu, + TRUE /* warp ptr */, -1, NULL); + menu->xanimation = 0; + } + + } /* if (mi) */ else { + /* moved off menu, deselect selected item... */ + if (menu->selected) { + SetMenuItemSelected(menu->selected, FALSE); + if (mrPopup && fOffMenuAllowed == FALSE) { + int x, y, mx, my; + unsigned int mw, mh; + XQueryPointer(dpy, Scr.Root, &JunkRoot, + &JunkChild, &x, &y, &JunkX, &JunkY, + &JunkMask); + XGetGeometry(dpy, menu->w, &JunkRoot, + &mx, &my, &mw, &mh, &JunkBW, + &JunkDepth); + if ((!IS_LEFT_MENU(mrPopup) && + x < mx) || + (!IS_RIGHT_MENU(mrPopup) && + x > mx + mw) || + (!IS_UP_MENU(mrPopup) && y < my) || + (!IS_DOWN_MENU(mrPopup) && + y > my + mh)) { + PopDownAndRepaintParent( + mrPopup, &fSubmenuOverlaps); + mrPopup = NULL; + } else { + fOffMenuAllowed = TRUE; + } + } /* if (mrPopup && fOffMenuAllowed == FALSE) */ + } /* if (menu->selected) */ + } /* else (!mi) */ + XFlush(dpy); + } /* while (TRUE) */ + +DO_RETURN: + if (mrPopup) { + PopDownAndRepaintParent(mrPopup, &fSubmenuOverlaps); } - } - } - /* DBUG("MenuInteraction","Prior menu has %s selected", - menuPrior?(menuPrior->selected? - menuPrior->selected->item:"(no selected item)"):"(no prior menu)"); */ - } else if (retval == MENU_SELECTED) { - /* DBUG("MenuInteraction","Got MENU_SELECTED for menu %s, on item %s", - menu->name,mi->item); */ - *pmiExecuteAction = mi; - retval = MENU_ADD_BUTTON_IF(fKeyPress,MENU_DONE); - } - if ((retval == MENU_DONE || retval == MENU_DONE_BUTTON) && - pmiExecuteAction && *pmiExecuteAction && (*pmiExecuteAction)->action) { - switch ((*pmiExecuteAction)->func_type) - { - case F_POPUP: - case F_STAYSUP: - case F_WINDOWLIST: - GetPopupOptions(mi, &mops); - if (!(mops.flags.f.select_in_place)) { - fIgnorePosHints = TRUE; - } else { - if (mops.flags.f.has_poshints) { - lastMenuPosHints = mops.pos_hints; - } else { - GetPreferredPopupPosition( - menu, &lastMenuPosHints.x, &lastMenuPosHints.y); - lastMenuPosHints.x_factor = 0; - lastMenuPosHints.y_factor = 0; - lastMenuPosHints.fRelative = FALSE; - } - fLastMenuPosHintsValid = TRUE; - if (mops.flags.f.select_warp) { - fWarpPointerToTitle = TRUE; + if (retval == MENU_POPDOWN) { + if (menu->selected) + SetMenuItemSelected(menu->selected, FALSE); + if (fKeyPress) { + if (cmenuDeep == 1) + /* abort a root menu rather than pop it down */ + retval = MENU_ABORTED; + if (menuPrior && menuPrior->selected) { + MiWarpPointerToItem(menuPrior->selected, FALSE); + if (menuPrior->selected != FindEntry(NULL) && + menu->xanimation == 0) { + XRaiseWindow(dpy, menuPrior->w); + } + } + } + /* DBUG("MenuInteraction","Prior menu has %s selected", + menuPrior?(menuPrior->selected? + menuPrior->selected->item:"(no selected item)"):"(no prior + menu)"); */ + } else if (retval == MENU_SELECTED) { + /* DBUG("MenuInteraction","Got MENU_SELECTED for menu %s, on + item %s", menu->name,mi->item); */ + *pmiExecuteAction = mi; + retval = MENU_ADD_BUTTON_IF(fKeyPress, MENU_DONE); } - } /* else (mops.flags.f.select_in_place) */ - break; - default: - break; - } - } /* ((retval == MENU_DONE ||... */ - return MENU_ADD_BUTTON_IF(fKeyPress,retval); + if ((retval == MENU_DONE || retval == MENU_DONE_BUTTON) && + pmiExecuteAction && *pmiExecuteAction && + (*pmiExecuteAction)->action) { + switch ((*pmiExecuteAction)->func_type) { + case F_POPUP: + case F_STAYSUP: + case F_WINDOWLIST: + GetPopupOptions(mi, &mops); + if (!(mops.flags.f.select_in_place)) { + fIgnorePosHints = TRUE; + } else { + if (mops.flags.f.has_poshints) { + lastMenuPosHints = mops.pos_hints; + } else { + GetPreferredPopupPosition(menu, + &lastMenuPosHints.x, + &lastMenuPosHints.y); + lastMenuPosHints.x_factor = 0; + lastMenuPosHints.y_factor = 0; + lastMenuPosHints.fRelative = FALSE; + } + fLastMenuPosHintsValid = TRUE; + if (mops.flags.f.select_warp) { + fWarpPointerToTitle = TRUE; + } + } /* else (mops.flags.f.select_in_place) */ + break; + default: + break; + } + } /* ((retval == MENU_DONE ||... */ + return MENU_ADD_BUTTON_IF(fKeyPress, retval); } -static -void WarpPointerToTitle(MenuRoot *menu) +static void +WarpPointerToTitle(MenuRoot *menu) { - int y = menu->ms->look.EntryHeight/2 + 2; - int x = MENU_MIDDLE_OFFSET(menu); - XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); + int y = menu->ms->look.EntryHeight / 2 + 2; + int x = MENU_MIDDLE_OFFSET(menu); + XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); } -static -MenuItem *MiWarpPointerToItem(MenuItem *mi, Bool fSkipTitle) +static MenuItem * +MiWarpPointerToItem(MenuItem *mi, Bool fSkipTitle) { - MenuRoot *menu = mi->mr; - int y; - int x = MENU_MIDDLE_OFFSET(menu); - - if (fSkipTitle && IS_TITLE_MENU_ITEM(mi) && - /* also don't skip if there is no next item */ - mi->next != NULL) { - mi = mi->next; - /* Shouldn't ever have a separator right after a title, but - lets skip one if we do, anyway */ - if (IS_SEPARATOR_MENU_ITEM(mi) && mi->next != NULL) - mi = mi->next; - } - - y = mi->y_offset + menu->ms->look.EntryHeight/2; - XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); - return mi; + MenuRoot *menu = mi->mr; + int y; + int x = MENU_MIDDLE_OFFSET(menu); + + if (fSkipTitle && IS_TITLE_MENU_ITEM(mi) && + /* also don't skip if there is no next item */ + mi->next != NULL) { + mi = mi->next; + /* Shouldn't ever have a separator right after a title, but + lets skip one if we do, anyway */ + if (IS_SEPARATOR_MENU_ITEM(mi) && mi->next != NULL) + mi = mi->next; + } + + y = mi->y_offset + menu->ms->look.EntryHeight / 2; + XWarpPointer(dpy, 0, menu->w, 0, 0, 0, 0, x, y); + return mi; } -static -int DoMenusOverlap(MenuRoot *mr, int x, int y, int width, int height, - Bool fTolerant) +static int +DoMenusOverlap( + MenuRoot *mr, int x, int y, int width, int height, Bool fTolerant) { - int prior_x, prior_y, x_overlap; - unsigned int prior_width, prior_height; - int tolerance1; - int tolerance2; - - if (mr == NULL) - return 0; - - if (fTolerant) - { - tolerance1 = 3; - if (mr->ms->feel.PopupOffsetAdd < 0) - tolerance1 -= mr->ms->feel.PopupOffsetAdd; - tolerance2 = 4; - } - else - { - tolerance1 = 1; - tolerance2 = 1; - } - XGetGeometry(dpy,mr->w,&JunkRoot,&prior_x,&prior_y, - &prior_width,&prior_height,&JunkBW,&JunkDepth); - x_overlap = 0; - if (fTolerant) { - /* Don't use multiplier if doing an intolerant check */ - prior_width *= (float)(mr->ms->feel.PopupOffsetPercent) / 100.0; - } - if (y <= prior_y + prior_height - tolerance2 && - prior_y <= y + height - tolerance2 && - x <= prior_x + prior_width - tolerance1 && - prior_x <= x + width - tolerance2) { - x_overlap = x - prior_x; - if (x <= prior_x) { - x_overlap--; - } - } - return x_overlap; + int prior_x, prior_y, x_overlap; + unsigned int prior_width, prior_height; + int tolerance1; + int tolerance2; + + if (mr == NULL) + return 0; + + if (fTolerant) { + tolerance1 = 3; + if (mr->ms->feel.PopupOffsetAdd < 0) + tolerance1 -= mr->ms->feel.PopupOffsetAdd; + tolerance2 = 4; + } else { + tolerance1 = 1; + tolerance2 = 1; + } + XGetGeometry(dpy, mr->w, &JunkRoot, &prior_x, &prior_y, &prior_width, + &prior_height, &JunkBW, &JunkDepth); + x_overlap = 0; + if (fTolerant) { + /* Don't use multiplier if doing an intolerant check */ + prior_width *= (float)(mr->ms->feel.PopupOffsetPercent) / 100.0; + } + if (y <= prior_y + prior_height - tolerance2 && + prior_y <= y + height - tolerance2 && + x <= prior_x + prior_width - tolerance1 && + prior_x <= x + width - tolerance2) { + x_overlap = x - prior_x; + if (x <= prior_x) { + x_overlap--; + } + } + return x_overlap; } /*********************************************************************** @@ -1102,349 +1173,363 @@ int DoMenusOverlap(MenuRoot *mr, int x, int y, int width, int height, * pops - pointer to the menu options for new menu * ***********************************************************************/ -static -Bool FPopupMenu (MenuRoot *menu, MenuRoot *menuPrior, int x, int y, - Bool fWarpItem, MenuOptions *pops, Bool *ret_overlap) +static Bool +FPopupMenu(MenuRoot *menu, MenuRoot *menuPrior, int x, int y, Bool fWarpItem, + MenuOptions *pops, Bool *ret_overlap) { - Bool fWarpTitle = FALSE; - int x_overlap, x_clipped_overlap; - MenuItem *mi = NULL; - - DBUG("FPopupMenu","called"); - if ((!menu)||(menu->w == None)||(menu->items == 0)||(menu->in_use)) { - fWarpPointerToTitle = FALSE; - return False; - } - menu->mrDynamicPrev = menuPrior; - menu->flags.f.painted = 0; - menu->flags.f.is_left = 0; - menu->flags.f.is_right = 0; - menu->flags.f.is_up = 0; - menu->flags.f.is_down = 0; - menu->xanimation = 0; - - /* RepaintAlreadyReversedMenuItems(menu); */ - - InstallRootColormap(); - - /* First handle popups from button clicks on buttons in the title bar, - or the title bar itself. Position hints override this. */ - if (!(pops->flags.f.has_poshints)) { - if((Tmp_win)&&(menuPrior == NULL)&&(Context&C_LALL)) - { - y = Tmp_win->frame_y+Tmp_win->boundary_width+Tmp_win->title_height+1; - x = Tmp_win->frame_x + Tmp_win->boundary_width + - ButtonPosition(Context,Tmp_win)*Tmp_win->title_height+1; - } - if((Tmp_win)&&(menuPrior == NULL)&&(Context&C_RALL)) - { - y = Tmp_win->frame_y+Tmp_win->boundary_width+Tmp_win->title_height+1; - x = Tmp_win->frame_x +Tmp_win->frame_width - Tmp_win->boundary_width- - ButtonPosition(Context,Tmp_win)*Tmp_win->title_height-menu->width+1; - } - if((Tmp_win)&&(menuPrior == NULL)&&(Context&C_TITLE)) - { - y = Tmp_win->frame_y+Tmp_win->boundary_width+Tmp_win->title_height+1; - if(x < Tmp_win->frame_x + Tmp_win->title_x) - x = Tmp_win->frame_x + Tmp_win->title_x; - if((x + menu->width) > - (Tmp_win->frame_x + Tmp_win->title_x +Tmp_win->title_width)) - x = Tmp_win->frame_x + Tmp_win->title_x +Tmp_win->title_width- - menu->width +1; - } - } /* if (pops->flags.f.has_poshints) */ - x_overlap = DoMenusOverlap(menuPrior, x, y, menu->width, menu->height, True); - /* clip to screen */ - if (x + menu->width > Scr.MyDisplayWidth - 2) - x = Scr.MyDisplayWidth - 2 - menu->width; - if (y + menu->height > Scr.MyDisplayHeight) - y = Scr.MyDisplayHeight - menu->height; - if (x < 0) - x = 0; - if (y < 0) - y = 0; - - if (menuPrior != NULL) { - int prev_x, prev_y, left_x, right_x; - unsigned int prev_width, prev_height; - int x_offset; - - /* try to find a better place */ - XGetGeometry(dpy,menuPrior->w,&JunkRoot,&prev_x,&prev_y, - &prev_width,&prev_height,&JunkBW,&JunkDepth); - - /* check if menus overlap */ - x_clipped_overlap = DoMenusOverlap(menuPrior, x, y, menu->width, - menu->height, True); - if (x_clipped_overlap && - (!(pops->flags.f.has_poshints) || - pops->pos_hints.fRelative == FALSE || x_overlap == 0)) { - /* menus do overlap, but do not reposition if overlap was caused by - relative positioning hints */ - Bool fDefaultLeft; - Bool fEmergencyLeft; - - x_offset = prev_width * menuPrior->ms->feel.PopupOffsetPercent / 100 + - menuPrior->ms->feel.PopupOffsetAdd; - left_x = prev_x - menu->width + 2; - right_x = prev_x + x_offset; - if (x_offset > prev_width - 2) - right_x = prev_x + prev_width - 2; - if (x + menu->width < prev_x + right_x) - fDefaultLeft = TRUE; - else - fDefaultLeft = FALSE; - fEmergencyLeft = (prev_x > Scr.MyDisplayWidth - right_x) ? TRUE : FALSE; - - if (menu->ms->feel.f.Animated) { - /* animate previous out of the way */ - int left_x, right_x, end_x; - - left_x = x - x_offset; - if (x_offset >= prev_width) - left_x = x - x_offset + 3; - right_x = x + menu->width; - if (fDefaultLeft) { - /* popup menu is left of old menu, try to move prior menu right */ - if (right_x + prev_width <= Scr.MyDisplayWidth - 2) - end_x = right_x; - else if (left_x >= 0) - end_x = left_x; - else - end_x = Scr.MyDisplayWidth - 2 - prev_width; - } else { - /* popup menu is right of old menu, try to move prior menu left */ - if (left_x >= 0) - end_x = left_x; - else if (right_x + prev_width <= Scr.MyDisplayWidth - 2) - end_x = right_x; - else - end_x = 0; - } - menuPrior->xanimation += end_x - prev_x; - AnimatedMoveOfWindow(menuPrior->w,prev_x,prev_y,end_x,prev_y, - TRUE, -1, NULL); - } /* if (menu->ms->feel.f.Animated) */ - else if (prev_x + x_offset > x + 3 && x_offset + 3 > -menu->width && - !(pops->flags.f.fixed)) { - Bool fLeftIsOK = FALSE; - Bool fRightIsOK = FALSE; - Bool fUseLeft = FALSE; - - if (left_x >= 0) - fLeftIsOK = TRUE; - if (right_x + menu->width < Scr.MyDisplayWidth - 2) - fRightIsOK = TRUE; - if (!fLeftIsOK && !fRightIsOK) - fUseLeft = fEmergencyLeft; - else if (fLeftIsOK && (fDefaultLeft || !fRightIsOK)) - fUseLeft = TRUE; - else - fUseLeft = FALSE; - x = (fUseLeft) ? left_x : right_x; - /* force the menu onto the screen; prefer to have the left border - * visible if the menu is wider than the screen. But leave at least - * 20 pixels of the parent menu visible */ - - if (x + menu->width >= Scr.MyDisplayWidth - 2) - { - int d = x + menu->width - Scr.MyDisplayWidth + 3; - int c; - - if (prev_width >= 20) - c = prev_x + 20; - else - c = prev_x + prev_width; - - if (x - c >= d || x <= prev_x) - x -= d; - else if (x > c) - x = c; + Bool fWarpTitle = FALSE; + int x_overlap, x_clipped_overlap; + MenuItem *mi = NULL; + + DBUG("FPopupMenu", "called"); + if ((!menu) || (menu->w == None) || (menu->items == 0) || + (menu->in_use)) { + fWarpPointerToTitle = FALSE; + return False; } + menu->mrDynamicPrev = menuPrior; + menu->flags.f.painted = 0; + menu->flags.f.is_left = 0; + menu->flags.f.is_right = 0; + menu->flags.f.is_up = 0; + menu->flags.f.is_down = 0; + menu->xanimation = 0; + + /* RepaintAlreadyReversedMenuItems(menu); */ + + InstallRootColormap(); + + /* First handle popups from button clicks on buttons in the title bar, + or the title bar itself. Position hints override this. */ + if (!(pops->flags.f.has_poshints)) { + if ((Tmp_win) && (menuPrior == NULL) && (Context & C_LALL)) { + y = Tmp_win->frame_y + Tmp_win->boundary_width + + Tmp_win->title_height + 1; + x = Tmp_win->frame_x + Tmp_win->boundary_width + + ButtonPosition(Context, Tmp_win) * + Tmp_win->title_height + + 1; + } + if ((Tmp_win) && (menuPrior == NULL) && (Context & C_RALL)) { + y = Tmp_win->frame_y + Tmp_win->boundary_width + + Tmp_win->title_height + 1; + x = Tmp_win->frame_x + Tmp_win->frame_width - + Tmp_win->boundary_width - + ButtonPosition(Context, Tmp_win) * + Tmp_win->title_height - + menu->width + 1; + } + if ((Tmp_win) && (menuPrior == NULL) && (Context & C_TITLE)) { + y = Tmp_win->frame_y + Tmp_win->boundary_width + + Tmp_win->title_height + 1; + if (x < Tmp_win->frame_x + Tmp_win->title_x) + x = Tmp_win->frame_x + Tmp_win->title_x; + if ((x + menu->width) > + (Tmp_win->frame_x + Tmp_win->title_x + + Tmp_win->title_width)) + x = Tmp_win->frame_x + Tmp_win->title_x + + Tmp_win->title_width - menu->width + 1; + } + } /* if (pops->flags.f.has_poshints) */ + x_overlap = + DoMenusOverlap(menuPrior, x, y, menu->width, menu->height, True); + /* clip to screen */ + if (x + menu->width > Scr.MyDisplayWidth - 2) + x = Scr.MyDisplayWidth - 2 - menu->width; + if (y + menu->height > Scr.MyDisplayHeight) + y = Scr.MyDisplayHeight - menu->height; if (x < 0) - { - int c = prev_width - 20; - - if (c < 0) - c = 0; - if (-x > c) - x += c; - else - x = 0; + x = 0; + if (y < 0) + y = 0; + + if (menuPrior != NULL) { + int prev_x, prev_y, left_x, right_x; + unsigned int prev_width, prev_height; + int x_offset; + + /* try to find a better place */ + XGetGeometry(dpy, menuPrior->w, &JunkRoot, &prev_x, &prev_y, + &prev_width, &prev_height, &JunkBW, &JunkDepth); + + /* check if menus overlap */ + x_clipped_overlap = DoMenusOverlap( + menuPrior, x, y, menu->width, menu->height, True); + if (x_clipped_overlap && + (!(pops->flags.f.has_poshints) || + pops->pos_hints.fRelative == FALSE || x_overlap == 0)) { + /* menus do overlap, but do not reposition if overlap + was caused by relative positioning hints */ + Bool fDefaultLeft; + Bool fEmergencyLeft; + + x_offset = prev_width * + menuPrior->ms->feel.PopupOffsetPercent / + 100 + + menuPrior->ms->feel.PopupOffsetAdd; + left_x = prev_x - menu->width + 2; + right_x = prev_x + x_offset; + if (x_offset > prev_width - 2) + right_x = prev_x + prev_width - 2; + if (x + menu->width < prev_x + right_x) + fDefaultLeft = TRUE; + else + fDefaultLeft = FALSE; + fEmergencyLeft = (prev_x > + Scr.MyDisplayWidth - right_x) ? TRUE : FALSE; + + if (menu->ms->feel.f.Animated) { + /* animate previous out of the way */ + int left_x, right_x, end_x; + + left_x = x - x_offset; + if (x_offset >= prev_width) + left_x = x - x_offset + 3; + right_x = x + menu->width; + if (fDefaultLeft) { + /* popup menu is left of old menu, try + * to move prior menu right */ + if (right_x + prev_width <= + Scr.MyDisplayWidth - 2) + end_x = right_x; + else if (left_x >= 0) + end_x = left_x; + else + end_x = Scr.MyDisplayWidth - 2 - + prev_width; + } else { + /* popup menu is right of old menu, try + * to move prior menu left */ + if (left_x >= 0) + end_x = left_x; + else if (right_x + prev_width <= + Scr.MyDisplayWidth - 2) + end_x = right_x; + else + end_x = 0; + } + menuPrior->xanimation += end_x - prev_x; + AnimatedMoveOfWindow(menuPrior->w, prev_x, + prev_y, end_x, prev_y, TRUE, -1, NULL); + } /* if (menu->ms->feel.f.Animated) */ else if (prev_x + + x_offset > x + 3 && x_offset + 3 > -menu->width && + !(pops->flags.f.fixed)) { + Bool fLeftIsOK = FALSE; + Bool fRightIsOK = FALSE; + Bool fUseLeft = FALSE; + + if (left_x >= 0) + fLeftIsOK = TRUE; + if (right_x + menu->width < + Scr.MyDisplayWidth - 2) + fRightIsOK = TRUE; + if (!fLeftIsOK && !fRightIsOK) + fUseLeft = fEmergencyLeft; + else if (fLeftIsOK && + (fDefaultLeft || !fRightIsOK)) + fUseLeft = TRUE; + else + fUseLeft = FALSE; + x = (fUseLeft) ? left_x : right_x; + /* force the menu onto the screen; prefer to + * have the left border visible if the menu is + * wider than the screen. But leave at least 20 + * pixels of the parent menu visible */ + + if (x + menu->width >= Scr.MyDisplayWidth - 2) { + int d = x + menu->width - + Scr.MyDisplayWidth + 3; + int c; + + if (prev_width >= 20) + c = prev_x + 20; + else + c = prev_x + prev_width; + + if (x - c >= d || x <= prev_x) + x -= d; + else if (x > c) + x = c; + } + if (x < 0) { + int c = prev_width - 20; + + if (c < 0) + c = 0; + if (-x > c) + x += c; + else + x = 0; + } + } /* else if (non-overlapping menu style) */ + } /* if (x_clipped_overlap && ...) */ + + if (x < prev_x) + menu->flags.f.is_left = 1; + if (x + menu->width > prev_x + prev_width) + menu->flags.f.is_right = 1; + if (y < prev_y) + menu->flags.f.is_up = 1; + if (y + menu->height > prev_y + prev_height) + menu->flags.f.is_down = 1; + if (!menu->flags.f.is_left && !menu->flags.f.is_right) { + menu->flags.f.is_left = 1; + menu->flags.f.is_right = 1; + } + } /* if (menuPrior) */ + + /* popup the menu */ + XMoveWindow(dpy, menu->w, x, y); + XMapRaised(dpy, menu->w); + if (ret_overlap) { + *ret_overlap = DoMenusOverlap(menuPrior, x, y, menu->width, + menu->height, False) ? + True : + False; } - } /* else if (non-overlapping menu style) */ - } /* if (x_clipped_overlap && ...) */ - - if (x < prev_x) - menu->flags.f.is_left = 1; - if (x + menu->width > prev_x + prev_width) - menu->flags.f.is_right = 1; - if (y < prev_y) - menu->flags.f.is_up = 1; - if (y + menu->height > prev_y + prev_height) - menu->flags.f.is_down = 1; - if (!menu->flags.f.is_left && !menu->flags.f.is_right) - { - menu->flags.f.is_left = 1; - menu->flags.f.is_right = 1; - } - } /* if (menuPrior) */ - - /* popup the menu */ - XMoveWindow(dpy, menu->w, x, y); - XMapRaised(dpy, menu->w); - if (ret_overlap) { - *ret_overlap = - DoMenusOverlap(menuPrior, x, y, menu->width, menu->height, False) ? - True : False; - } - - if (!fWarpItem) { - mi = FindEntry(NULL); - if (mi && mi->mr == menu && mi != mi->mr->first) { - /* pointer is on an item of the popup */ - if (menu->ms->feel.f.TitleWarp) { - /* warp pointer if not on a root menu and MWM/WIN menu style */ - fWarpTitle = TRUE; - } - } - } /* if (!fWarpItem) */ - - if (pops->flags.f.no_warp) { - fWarpTitle = FALSE; - } else if (pops->flags.f.warp_title) { - fWarpTitle = TRUE; - } - if (fWarpPointerToTitle) { - fWarpTitle = TRUE; - fWarpPointerToTitle = FALSE; - } - if (fWarpItem) { - /* also warp */ - DBUG("FPopupMenu","Warping to item"); - menu->selected = MiWarpPointerToItem(menu->first, TRUE /* skip Title */); - SetMenuItemSelected( - MiWarpPointerToItem(menu->first, TRUE /* skip Title */),TRUE); - } else if(fWarpTitle) { - /* Warp pointer to middle of top line, since we don't - * want the user to come up directly on an option */ - DBUG("FPopupMenu","Warping to title"); - WarpPointerToTitle(menu); - } - return True; + + if (!fWarpItem) { + mi = FindEntry(NULL); + if (mi && mi->mr == menu && mi != mi->mr->first) { + /* pointer is on an item of the popup */ + if (menu->ms->feel.f.TitleWarp) { + /* warp pointer if not on a root menu and + * MWM/WIN menu style */ + fWarpTitle = TRUE; + } + } + } /* if (!fWarpItem) */ + + if (pops->flags.f.no_warp) { + fWarpTitle = FALSE; + } else if (pops->flags.f.warp_title) { + fWarpTitle = TRUE; + } + if (fWarpPointerToTitle) { + fWarpTitle = TRUE; + fWarpPointerToTitle = FALSE; + } + if (fWarpItem) { + /* also warp */ + DBUG("FPopupMenu", "Warping to item"); + menu->selected = + MiWarpPointerToItem(menu->first, TRUE /* skip Title */); + SetMenuItemSelected( + MiWarpPointerToItem(menu->first, TRUE /* skip Title */), + TRUE); + } else if (fWarpTitle) { + /* Warp pointer to middle of top line, since we don't + * want the user to come up directly on an option */ + DBUG("FPopupMenu", "Warping to title"); + WarpPointerToTitle(menu); + } + return True; } /* Set the selected-ness state of the menuitem passed in */ -static -void SetMenuItemSelected(MenuItem *mi, Bool f) +static void +SetMenuItemSelected(MenuItem *mi, Bool f) { - if (f == True && mi->mr->selected != NULL && mi->mr->selected != mi) - SetMenuItemSelected(mi->mr->selected, False); - if (f == False && mi->mr->selected == NULL) - return; + if (f == True && mi->mr->selected != NULL && mi->mr->selected != mi) + SetMenuItemSelected(mi->mr->selected, False); + if (f == False && mi->mr->selected == NULL) + return; - if (mi->state == f) - return; + if (mi->state == f) + return; #ifdef GRADIENT_BUTTONS - switch (mi->mr->ms->look.face.type) - { - case HGradMenu: - case VGradMenu: - case DGradMenu: - case BGradMenu: - if (f == True) - { - int iy, ih; - int mw, mh; - - if (!mi->mr->flags.f.painted) - { - PaintMenu(mi->mr, NULL); - flush_expose(mi->mr->w); - } - iy = mi->y_offset - 2; - ih = mi->y_height + 4; - if (iy < 0) - { - ih += iy; - iy = 0; - } - XGetGeometry(dpy, mi->mr->w, &JunkRoot, &JunkX, &JunkY, - &mw, &mh, &JunkBW, &JunkDepth); - if (iy + ih > mh) - ih = mh - iy; - /* grab image */ - mi->mr->stored_item.stored = XCreatePixmap(dpy, Scr.Root, mw, ih, - Scr.d_depth); - XCopyArea(dpy, mi->mr->w, mi->mr->stored_item.stored, - mi->mr->ms->look.MenuGC, 0, iy, mw, ih, 0, 0); - mi->mr->stored_item.y = iy; - mi->mr->stored_item.width = mw; - mi->mr->stored_item.height = ih; - } - else if (f == False && mi->mr->stored_item.width != 0) - { - /* ungrab image */ - - XCopyArea(dpy, mi->mr->stored_item.stored, mi->mr->w, - mi->mr->ms->look.MenuGC, 0,0, mi->mr->stored_item.width, - mi->mr->stored_item.height, 0, mi->mr->stored_item.y); - - XFreePixmap(dpy, mi->mr->stored_item.stored); - mi->mr->stored_item.width = 0; - mi->mr->stored_item.height = 0; - mi->mr->stored_item.y = 0; - - } - break; - default: - if (mi->mr->stored_item.width != 0) - { - XFreePixmap(dpy, mi->mr->stored_item.stored); - mi->mr->stored_item.width = 0; - mi->mr->stored_item.height = 0; - mi->mr->stored_item.y = 0; - } - break; - } + switch (mi->mr->ms->look.face.type) { + case HGradMenu: + case VGradMenu: + case DGradMenu: + case BGradMenu: + if (f == True) { + int iy, ih; + int mw, mh; + + if (!mi->mr->flags.f.painted) { + PaintMenu(mi->mr, NULL); + flush_expose(mi->mr->w); + } + iy = mi->y_offset - 2; + ih = mi->y_height + 4; + if (iy < 0) { + ih += iy; + iy = 0; + } + XGetGeometry(dpy, mi->mr->w, &JunkRoot, &JunkX, &JunkY, + &mw, &mh, &JunkBW, &JunkDepth); + if (iy + ih > mh) + ih = mh - iy; + /* grab image */ + mi->mr->stored_item.stored = + XCreatePixmap(dpy, Scr.Root, mw, ih, Scr.d_depth); + XCopyArea(dpy, mi->mr->w, mi->mr->stored_item.stored, + mi->mr->ms->look.MenuGC, 0, iy, mw, ih, 0, 0); + mi->mr->stored_item.y = iy; + mi->mr->stored_item.width = mw; + mi->mr->stored_item.height = ih; + } else if (f == False && mi->mr->stored_item.width != 0) { + /* ungrab image */ + + XCopyArea(dpy, mi->mr->stored_item.stored, mi->mr->w, + mi->mr->ms->look.MenuGC, 0, 0, + mi->mr->stored_item.width, + mi->mr->stored_item.height, 0, + mi->mr->stored_item.y); + + XFreePixmap(dpy, mi->mr->stored_item.stored); + mi->mr->stored_item.width = 0; + mi->mr->stored_item.height = 0; + mi->mr->stored_item.y = 0; + } + break; + default: + if (mi->mr->stored_item.width != 0) { + XFreePixmap(dpy, mi->mr->stored_item.stored); + mi->mr->stored_item.width = 0; + mi->mr->stored_item.height = 0; + mi->mr->stored_item.y = 0; + } + break; + } #endif - mi->state = f; - mi->mr->selected = (f) ? mi : NULL; - PaintEntry(mi); + mi->state = f; + mi->mr->selected = (f) ? mi : NULL; + PaintEntry(mi); } /* Returns a menu root that a given menu item pops up */ -static -MenuRoot *MrPopupForMi(MenuItem *mi) +static MenuRoot * +MrPopupForMi(MenuItem *mi) { - char *menu_name = NULL; - MenuRoot *tmp = NULL; - - /* This checks if mi is != NULL too */ - if (!IS_POPUP_MENU_ITEM(mi)) - return NULL; - /* just look past "Popup " in the action, and find that menu root */ - GetNextToken(SkipNTokens(mi->action, 1), &menu_name); - tmp = FindPopup(menu_name); - if (menu_name != NULL) - free(menu_name); - return tmp; + char *menu_name = NULL; + MenuRoot *tmp = NULL; + + /* This checks if mi is != NULL too */ + if (!IS_POPUP_MENU_ITEM(mi)) + return NULL; + /* just look past "Popup " in the action, and find that menu root */ + GetNextToken(SkipNTokens(mi->action, 1), &menu_name); + tmp = FindPopup(menu_name); + if (menu_name != NULL) + free(menu_name); + return tmp; } /* Returns the menu options for the menu that a given menu item pops up */ -static -void GetPopupOptions(MenuItem *mi, MenuOptions *pops) +static void +GetPopupOptions(MenuItem *mi, MenuOptions *pops) { - if (!mi) - return; - pops->flags.f.has_poshints = 0; - /* just look past "Popup " in the action */ - GetMenuOptions(SkipNTokens(mi->action, 2), mi->mr->w, NULL, mi, pops); + if (!mi) + return; + pops->flags.f.has_poshints = 0; + /* just look past "Popup " in the action */ + GetMenuOptions(SkipNTokens(mi->action, 2), mi->mr->w, NULL, mi, pops); } - /*********************************************************************** * * Procedure: @@ -1459,29 +1544,29 @@ void GetPopupOptions(MenuItem *mi, MenuOptions *pops) * being processed here. DO NOT USE mr->mrDynamicPrev here! * ***********************************************************************/ -static -void PopDownMenu(MenuRoot *mr) +static void +PopDownMenu(MenuRoot *mr) { - MenuItem *mi; - assert(mr); - - mr->flags.allflags = 0; - XUnmapWindow(dpy, mr->w); - - UninstallRootColormap(); - XFlush(dpy); - /* FIX: Context and menuFromFrameOrWindowOrTitlebar should really - be passed around, and not global */ - if (Context & (C_WINDOW | C_FRAME | C_TITLE | C_SIDEBAR)) - menuFromFrameOrWindowOrTitlebar = TRUE; - else - menuFromFrameOrWindowOrTitlebar = FALSE; - if ((mi = mr->selected) != NULL) { - SetMenuItemSelected(mi,FALSE); - } - - /* DBUG("PopDownMenu","popped down %s",mr->name); */ - return; + MenuItem *mi; + assert(mr); + + mr->flags.allflags = 0; + XUnmapWindow(dpy, mr->w); + + UninstallRootColormap(); + XFlush(dpy); + /* FIX: Context and menuFromFrameOrWindowOrTitlebar should really + be passed around, and not global */ + if (Context & (C_WINDOW | C_FRAME | C_TITLE | C_SIDEBAR)) + menuFromFrameOrWindowOrTitlebar = TRUE; + else + menuFromFrameOrWindowOrTitlebar = FALSE; + if ((mi = mr->selected) != NULL) { + SetMenuItemSelected(mi, FALSE); + } + + /* DBUG("PopDownMenu","popped down %s",mr->name); */ + return; } /*********************************************************************** @@ -1493,34 +1578,32 @@ void PopDownMenu(MenuRoot *mr) * afterwards. * ***********************************************************************/ -static void PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps) +static void +PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps) { - MenuRoot *parent = mr->mrDynamicPrev; - XEvent event; - int mr_y; - int mr_height; - int parent_y; - - if (*fSubmenuOverlaps && parent) - { - XGetGeometry(dpy, mr->w, &JunkRoot, &JunkX, &mr_y, - &JunkWidth, &mr_height, &JunkBW, &JunkDepth); - XGetGeometry(dpy, parent->w, &JunkRoot, &JunkX, &parent_y, - &JunkWidth, &JunkWidth, &JunkBW, &JunkDepth); - PopDownMenu(mr); - /* Create a fake event to pass into PaintMenu */ - event.type = Expose; - event.xexpose.y = mr_y - parent_y; - event.xexpose.height = mr_height; - PaintMenu(parent, &event); - flush_expose(parent->w); - } - else - { - PopDownMenu(mr); - } - *fSubmenuOverlaps = False; - return; + MenuRoot *parent = mr->mrDynamicPrev; + XEvent event; + int mr_y; + int mr_height; + int parent_y; + + if (*fSubmenuOverlaps && parent) { + XGetGeometry(dpy, mr->w, &JunkRoot, &JunkX, &mr_y, &JunkWidth, + &mr_height, &JunkBW, &JunkDepth); + XGetGeometry(dpy, parent->w, &JunkRoot, &JunkX, &parent_y, + &JunkWidth, &JunkWidth, &JunkBW, &JunkDepth); + PopDownMenu(mr); + /* Create a fake event to pass into PaintMenu */ + event.type = Expose; + event.xexpose.y = mr_y - parent_y; + event.xexpose.height = mr_height; + PaintMenu(parent, &event); + flush_expose(parent->w); + } else { + PopDownMenu(mr); + } + *fSubmenuOverlaps = False; + return; } /*********************************************************************** @@ -1529,14 +1612,14 @@ static void PopDownAndRepaintParent(MenuRoot *mr, Bool *fSubmenuOverlaps) * RelieveRectangle - add relief lines to a rectangular window * ***********************************************************************/ -static -void RelieveRectangle(Window win,int x,int y,int w, int h,GC Hilite,GC Shadow) +static void +RelieveRectangle(Window win, int x, int y, int w, int h, GC Hilite, GC Shadow) { - XDrawLine(dpy, win, Hilite, x, y, w+x-1, y); - XDrawLine(dpy, win, Hilite, x, y, x, h+y-1); + XDrawLine(dpy, win, Hilite, x, y, w + x - 1, y); + XDrawLine(dpy, win, Hilite, x, y, x, h + y - 1); - XDrawLine(dpy, win, Shadow, x, h+y-1, w+x-1, h+y-1); - XDrawLine(dpy, win, Shadow, w+x-1, y, w+x-1, h+y-1); + XDrawLine(dpy, win, Shadow, x, h + y - 1, w + x - 1, h + y - 1); + XDrawLine(dpy, win, Shadow, w + x - 1, y, w + x - 1, h + y - 1); } /*********************************************************************** @@ -1546,294 +1629,285 @@ void RelieveRectangle(Window win,int x,int y,int w, int h,GC Hilite,GC Shadow) * rectangular window * ***********************************************************************/ -static -void RelieveHalfRectangle(Window win,int x,int y,int w,int h, - GC Hilite,GC Shadow) +static void +RelieveHalfRectangle( + Window win, int x, int y, int w, int h, GC Hilite, GC Shadow) { - XDrawLine(dpy, win, Hilite, x, y-1, x, h+y); - XDrawLine(dpy, win, Hilite, x+1, y, x+1, h+y-1); + XDrawLine(dpy, win, Hilite, x, y - 1, x, h + y); + XDrawLine(dpy, win, Hilite, x + 1, y, x + 1, h + y - 1); - XDrawLine(dpy, win, Shadow, w+x-1, y-1, w+x-1, h+y); - XDrawLine(dpy, win, Shadow, w+x-2, y, w+x-2, h+y-1); + XDrawLine(dpy, win, Shadow, w + x - 1, y - 1, w + x - 1, h + y); + XDrawLine(dpy, win, Shadow, w + x - 2, y, w + x - 2, h + y - 1); } - /*********************************************************************** * * Procedure: * PaintEntry - draws a single entry in a popped up menu * ***********************************************************************/ -static -void PaintEntry(MenuItem *mi) +static void +PaintEntry(MenuItem *mi) { - int y_offset,text_y,d, y_height,y,x; - GC ShadowGC, ReliefGC, currentGC; - MenuRoot *mr = mi->mr; - char th = mr->ms->look.ReliefThickness; - Bool fClear = False; + int y_offset, text_y, d, y_height, y, x; + GC ShadowGC, ReliefGC, currentGC; + MenuRoot *mr = mi->mr; + char th = mr->ms->look.ReliefThickness; + Bool fClear = False; #ifdef GRADIENT_BUTTONS - Bool fGradient; - - switch (mi->mr->ms->look.face.type) - { - case HGradMenu: - case VGradMenu: - case DGradMenu: - case BGradMenu: - fGradient = True; - break; - default: - fGradient = False; - break; - } + Bool fGradient; + + switch (mi->mr->ms->look.face.type) { + case HGradMenu: + case VGradMenu: + case DGradMenu: + case BGradMenu: + fGradient = True; + break; + default: + fGradient = False; + break; + } #endif - y_offset = mi->y_offset; - y_height = mi->y_height; - text_y = y_offset + mi->mr->ms->look.pStdFont->y; - /* center text vertically if the pixmap is taller */ - if(mi->picture) - text_y+=mi->picture->height; - if (mi->lpicture) - { - y = mi->lpicture->height - mi->mr->ms->look.pStdFont->height; - if (y>1) - text_y += y/2; - } - - ShadowGC = mr->ms->look.MenuShadowGC; - if(Scr.d_depth<2) - ReliefGC = mr->ms->look.MenuShadowGC; - else - ReliefGC = mr->ms->look.MenuReliefGC; - - /* Hilight background */ - if (mr->ms->look.f.Hilight) { - if (mi->state && (!mi->fIsSeparator) && - (((*mi->item)!=0) || mi->picture || mi->lpicture)) { - int d = (th == 2 && mi->prev && mi->prev->state) ? 1 : 0; - - XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); - XFillRectangle(dpy, mr->w, mr->ms->look.MenuActiveBackGC, mr->xoffset+3, - y_offset + d, mr->width - mr->xoffset-6, y_height - d); - } else if (th == 0) { + y_offset = mi->y_offset; + y_height = mi->y_height; + text_y = y_offset + mi->mr->ms->look.pStdFont->y; + /* center text vertically if the pixmap is taller */ + if (mi->picture) + text_y += mi->picture->height; + if (mi->lpicture) { + y = mi->lpicture->height - mi->mr->ms->look.pStdFont->height; + if (y > 1) + text_y += y / 2; + } + + ShadowGC = mr->ms->look.MenuShadowGC; + if (Scr.d_depth < 2) + ReliefGC = mr->ms->look.MenuShadowGC; + else + ReliefGC = mr->ms->look.MenuReliefGC; + + /* Hilight background */ + if (mr->ms->look.f.Hilight) { + if (mi->state && (!mi->fIsSeparator) && + (((*mi->item) != 0) || mi->picture || mi->lpicture)) { + int d = + (th == 2 && mi->prev && mi->prev->state) ? 1 : 0; + + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + XFillRectangle(dpy, mr->w, + mr->ms->look.MenuActiveBackGC, mr->xoffset + 3, + y_offset + d, mr->width - mr->xoffset - 6, + y_height - d); + } else if (th == 0) { #ifdef GRADIENT_BUTTONS - if (!fGradient) + if (!fGradient) #endif - XClearArea(dpy,mr->w,mr->xoffset+3,y_offset,mr->width -mr->xoffset-6, - y_height,0); - } else { - fClear = True; - } - if (th == 0) { - RelieveHalfRectangle(mr->w, 0, y_offset-1, mr->width, y_height+3, - ReliefGC, ShadowGC); - } - } - - if (mr->ms->look.ReliefThickness > 0 && (fClear || !mr->ms->look.f.Hilight)){ - /* background was already painted above? */ + XClearArea(dpy, mr->w, mr->xoffset + 3, + y_offset, mr->width - mr->xoffset - 6, + y_height, 0); + } else { + fClear = True; + } + if (th == 0) { + RelieveHalfRectangle(mr->w, 0, y_offset - 1, mr->width, + y_height + 3, ReliefGC, ShadowGC); + } + } + + if (mr->ms->look.ReliefThickness > 0 && + (fClear || !mr->ms->look.f.Hilight)) { + /* background was already painted above? */ #ifdef GRADIENT_BUTTONS - if (!fGradient) + if (!fGradient) #endif - { - - if (th == 2 && mi->prev && mi->prev->state) - XClearArea(dpy, mr->w,mr->xoffset,y_offset+1,mr->width,y_height-1,0); - else - XClearArea(dpy, mr->w, mr->xoffset, y_offset - th + 1, mr->width, - y_height + 2*(th - 1), 0); - } - } - - - - /* Hilight 3D */ - if (mr->ms->look.ReliefThickness > 0) { - int sw = 0; - - if (mr->sidePic != NULL) - sw = mr->sidePic->width + 5; - else if (mr->ms->look.sidePic != NULL) - sw = mr->ms->look.sidePic->width + 5; - - if ((mi->state)&&(!mi->fIsSeparator)&& - (((*mi->item)!=0) || mi->picture || mi->lpicture)) { - RelieveRectangle(mr->w, mr->xoffset + th + 1, y_offset, - mr->width - 2*(th + 1) - sw, mi->y_height, - ReliefGC,ShadowGC); - if (th == 2) { - RelieveRectangle(mr->w, mr->xoffset + 2, y_offset - 1, - mr->width - 4 - sw, mi->y_height + 2, - ReliefGC,ShadowGC); - } - } - - RelieveHalfRectangle(mr->w, 0, y_offset - th + 1, mr->width, - y_height + 2*(th - 1), ReliefGC, ShadowGC); - } - - - /* Draw the shadows for the absolute outside of the menus - This stuff belongs in here, not in PaintMenu, since we only - want to redraw it when we have too (i.e. on expose event) */ - - /* Top of the menu */ - if(mi == mr->first) - DrawSeparator(mr->w,ReliefGC,ReliefGC,0,0, mr->width-1,0,-1); - - /* Botton of the menu */ - if(mi->next == NULL) - DrawSeparator(mr->w,ShadowGC,ShadowGC,1,mr->height-2, - mr->width-2, mr->height-2,1); - - if(IS_TITLE_MENU_ITEM(mi)) - { - if(mr->ms->look.TitleUnderlines == 2) - { - text_y += HEIGHT_EXTRA/2; - XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset+2, y_offset+y_height-2, - mr->width-3, y_offset+y_height-2); - XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset+2, y_offset+y_height-4, - mr->width-3, y_offset+y_height-4); + { + if (th == 2 && mi->prev && mi->prev->state) + XClearArea(dpy, mr->w, mr->xoffset, + y_offset + 1, mr->width, y_height - 1, 0); + else + XClearArea(dpy, mr->w, mr->xoffset, + y_offset - th + 1, mr->width, + y_height + 2 * (th - 1), 0); + } } - else if(mr->ms->look.TitleUnderlines == 1) - { - if(mi->next != NULL) - { - DrawSeparator(mr->w,ShadowGC,ReliefGC,mr->xoffset+5, - y_offset+y_height-3, - mr->width-6, y_offset+y_height-3,1); - } - if(mi != mr->first) - { - text_y += HEIGHT_EXTRA_TITLE/2; - DrawSeparator(mr->w,ShadowGC,ReliefGC,mr->xoffset+5, y_offset+1, - mr->width-6, y_offset+1,1); - } + + /* Hilight 3D */ + if (mr->ms->look.ReliefThickness > 0) { + int sw = 0; + + if (mr->sidePic != NULL) + sw = mr->sidePic->width + 5; + else if (mr->ms->look.sidePic != NULL) + sw = mr->ms->look.sidePic->width + 5; + + if ((mi->state) && (!mi->fIsSeparator) && + (((*mi->item) != 0) || mi->picture || mi->lpicture)) { + RelieveRectangle(mr->w, mr->xoffset + th + 1, y_offset, + mr->width - 2 * (th + 1) - sw, mi->y_height, + ReliefGC, ShadowGC); + if (th == 2) { + RelieveRectangle(mr->w, mr->xoffset + 2, + y_offset - 1, mr->width - 4 - sw, + mi->y_height + 2, ReliefGC, ShadowGC); + } + } + + RelieveHalfRectangle(mr->w, 0, y_offset - th + 1, mr->width, + y_height + 2 * (th - 1), ReliefGC, ShadowGC); } - } - else - text_y += HEIGHT_EXTRA/2; - - /* see if it's an actual separator (titles are also separators) */ - if(mi->fIsSeparator && !IS_TITLE_MENU_ITEM(mi) && !IS_LABEL_MENU_ITEM(mi)) - { - int d = (mr->ms->look.f.LongSeparators) ? 3 : 0; - - DrawSeparator(mr->w,ShadowGC,ReliefGC,mr->xoffset+5-d, - y_offset-1+HEIGHT_SEPARATOR/2, - mr->width-6+d,y_offset-1+HEIGHT_SEPARATOR/2,1); - } - if(mi->next == NULL) - DrawSeparator(mr->w,ShadowGC,ShadowGC,mr->xoffset+1,mr->height-2, - mr->width-2, mr->height-2,1); - if(mi == mr->first) - DrawSeparator(mr->w,ReliefGC,ReliefGC,mr->xoffset,0, mr->width-1,0,-1); - - if(check_allowed_function(mi)) - { - if(mi->state && !IS_TITLE_MENU_ITEM(mi)) - currentGC = mr->ms->look.MenuActiveGC; - else - currentGC = mr->ms->look.MenuGC; - } - else - /* should be a shaded out word, not just re-colored. */ - currentGC = mr->ms->look.MenuStippleGC; - - if (mr->ms->look.f.Hilight && !mr->ms->look.f.hasActiveFore && - mi->state && mi->fIsSeparator == FALSE) - /* Use a lighter color for highlighted windows menu items for win mode */ - currentGC = mr->ms->look.MenuReliefGC; - - if(*mi->item) - XDrawString(dpy, mr->w,currentGC,mi->x+mr->xoffset,text_y, mi->item, - mi->strlen); - if(mi->strlen2>0) - XDrawString(dpy, mr->w,currentGC,mi->x2+mr->xoffset,text_y, mi->item2, - mi->strlen2); - - /* pete@tecc.co.uk: If the item has a hot key, underline it */ - if (mi->hotkey > 0) - DrawUnderline(mr, currentGC,mr->xoffset+mi->x,text_y,mi->item, - mi->hotkey - 1); - if (mi->hotkey < 0) - DrawUnderline(mr, currentGC,mr->xoffset+mi->x2,text_y,mi->item2, - -1 - mi->hotkey); - - d=(mr->ms->look.EntryHeight-7)/2; - if(mi->func_type == F_POPUP) { - if(mi->state) - DrawTrianglePattern(mr->w, ShadowGC, ReliefGC, ShadowGC, ReliefGC, - mr->width-13, y_offset+d-1, mr->width-7, - y_offset+d+7, mr->ms->look.f.TriangleRelief); - else - DrawTrianglePattern(mr->w, ReliefGC, ShadowGC, ReliefGC, - mr->ms->look.MenuGC, - mr->width-13, y_offset+d-1, mr->width-7, - y_offset+d+7, mr->ms->look.f.TriangleRelief); - } - - if(mi->picture) - { - x = (mr->width - mi->picture->width)/2; - if(mi->lpicture && x < mr->width0 + 5) - x = mr->width0+5; - - if(mi->picture->depth > 0) /* pixmap? */ - { - Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = mi->picture->mask; - Globalgcv.clip_x_origin= x; - Globalgcv.clip_y_origin = y_offset+1; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - XCopyArea(dpy,mi->picture->picture,mr->w,ReliefGC, 0, 0, - mi->picture->width, mi->picture->height, - x,y_offset+1); - Globalgcm = GCClipMask; - Globalgcv.clip_mask = None; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); + + /* Draw the shadows for the absolute outside of the menus + This stuff belongs in here, not in PaintMenu, since we only + want to redraw it when we have too (i.e. on expose event) */ + + /* Top of the menu */ + if (mi == mr->first) + DrawSeparator( + mr->w, ReliefGC, ReliefGC, 0, 0, mr->width - 1, 0, -1); + + /* Botton of the menu */ + if (mi->next == NULL) + DrawSeparator(mr->w, ShadowGC, ShadowGC, 1, mr->height - 2, + mr->width - 2, mr->height - 2, 1); + + if (IS_TITLE_MENU_ITEM(mi)) { + if (mr->ms->look.TitleUnderlines == 2) { + text_y += HEIGHT_EXTRA / 2; + XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset + 2, + y_offset + y_height - 2, mr->width - 3, + y_offset + y_height - 2); + XDrawLine(dpy, mr->w, ShadowGC, mr->xoffset + 2, + y_offset + y_height - 4, mr->width - 3, + y_offset + y_height - 4); + } else if (mr->ms->look.TitleUnderlines == 1) { + if (mi->next != NULL) { + DrawSeparator(mr->w, ShadowGC, ReliefGC, + mr->xoffset + 5, y_offset + y_height - 3, + mr->width - 6, y_offset + y_height - 3, 1); + } + if (mi != mr->first) { + text_y += HEIGHT_EXTRA_TITLE / 2; + DrawSeparator(mr->w, ShadowGC, ReliefGC, + mr->xoffset + 5, y_offset + 1, + mr->width - 6, y_offset + 1, 1); + } + } + } else + text_y += HEIGHT_EXTRA / 2; + + /* see if it's an actual separator (titles are also separators) */ + if (mi->fIsSeparator && !IS_TITLE_MENU_ITEM(mi) && + !IS_LABEL_MENU_ITEM(mi)) { + int d = (mr->ms->look.f.LongSeparators) ? 3 : 0; + + DrawSeparator(mr->w, ShadowGC, ReliefGC, mr->xoffset + 5 - d, + y_offset - 1 + HEIGHT_SEPARATOR / 2, mr->width - 6 + d, + y_offset - 1 + HEIGHT_SEPARATOR / 2, 1); } - else - { - XCopyPlane(dpy,mi->picture->picture,mr->w, - currentGC,0,0,mi->picture->width,mi->picture->height, - x,y_offset+1,1); + if (mi->next == NULL) + DrawSeparator(mr->w, ShadowGC, ShadowGC, mr->xoffset + 1, + mr->height - 2, mr->width - 2, mr->height - 2, 1); + if (mi == mr->first) + DrawSeparator(mr->w, ReliefGC, ReliefGC, mr->xoffset, 0, + mr->width - 1, 0, -1); + + if (check_allowed_function(mi)) { + if (mi->state && !IS_TITLE_MENU_ITEM(mi)) + currentGC = mr->ms->look.MenuActiveGC; + else + currentGC = mr->ms->look.MenuGC; + } else + /* should be a shaded out word, not just re-colored. */ + currentGC = mr->ms->look.MenuStippleGC; + + if (mr->ms->look.f.Hilight && !mr->ms->look.f.hasActiveFore && + mi->state && mi->fIsSeparator == FALSE) + /* Use a lighter color for highlighted windows menu items for + * win mode */ + currentGC = mr->ms->look.MenuReliefGC; + + if (*mi->item) + XDrawString(dpy, mr->w, currentGC, mi->x + mr->xoffset, text_y, + mi->item, mi->strlen); + if (mi->strlen2 > 0) + XDrawString(dpy, mr->w, currentGC, mi->x2 + mr->xoffset, text_y, + mi->item2, mi->strlen2); + + /* pete@tecc.co.uk: If the item has a hot key, underline it */ + if (mi->hotkey > 0) + DrawUnderline(mr, currentGC, mr->xoffset + mi->x, text_y, + mi->item, mi->hotkey - 1); + if (mi->hotkey < 0) + DrawUnderline(mr, currentGC, mr->xoffset + mi->x2, text_y, + mi->item2, -1 - mi->hotkey); + + d = (mr->ms->look.EntryHeight - 7) / 2; + if (mi->func_type == F_POPUP) { + if (mi->state) + DrawTrianglePattern(mr->w, ShadowGC, ReliefGC, ShadowGC, + ReliefGC, mr->width - 13, y_offset + d - 1, + mr->width - 7, y_offset + d + 7, + mr->ms->look.f.TriangleRelief); + else + DrawTrianglePattern(mr->w, ReliefGC, ShadowGC, ReliefGC, + mr->ms->look.MenuGC, mr->width - 13, + y_offset + d - 1, mr->width - 7, y_offset + d + 7, + mr->ms->look.f.TriangleRelief); } - } - - if(mi->lpicture) - { - int lp_offset = 6; - if(mi->picture && *mi->item != 0) - y = y_offset + mi->y_height - mi->lpicture->height-1; - else - y = y_offset + mi->y_height/2 - mi->lpicture->height/2; - if(mi->lpicture->depth > 0) /* pixmap? */ - { - Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = mi->lpicture->mask; - Globalgcv.clip_x_origin= lp_offset + mr->xoffset; - Globalgcv.clip_y_origin = y; - - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - XCopyArea(dpy,mi->lpicture->picture,mr->w,ReliefGC,0,0, - mi->lpicture->width, mi->lpicture->height, - lp_offset + mr->xoffset,y); - Globalgcm = GCClipMask; - Globalgcv.clip_mask = None; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); + + if (mi->picture) { + x = (mr->width - mi->picture->width) / 2; + if (mi->lpicture && x < mr->width0 + 5) + x = mr->width0 + 5; + + if (mi->picture->depth > 0) { /* pixmap? */ + Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = mi->picture->mask; + Globalgcv.clip_x_origin = x; + Globalgcv.clip_y_origin = y_offset + 1; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + XCopyArea(dpy, mi->picture->picture, mr->w, ReliefGC, 0, + 0, mi->picture->width, mi->picture->height, x, + y_offset + 1); + Globalgcm = GCClipMask; + Globalgcv.clip_mask = None; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + } else { + XCopyPlane(dpy, mi->picture->picture, mr->w, currentGC, + 0, 0, mi->picture->width, mi->picture->height, x, + y_offset + 1, 1); + } } - else - { - XCopyPlane(dpy,mi->lpicture->picture,mr->w, - currentGC,0,0,mi->lpicture->width,mi->lpicture->height, - lp_offset + mr->xoffset,y,1); + + if (mi->lpicture) { + int lp_offset = 6; + if (mi->picture && *mi->item != 0) + y = y_offset + mi->y_height - mi->lpicture->height - 1; + else + y = y_offset + mi->y_height / 2 - + mi->lpicture->height / 2; + if (mi->lpicture->depth > 0) { /* pixmap? */ + Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = mi->lpicture->mask; + Globalgcv.clip_x_origin = lp_offset + mr->xoffset; + Globalgcv.clip_y_origin = y; + + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + XCopyArea(dpy, mi->lpicture->picture, mr->w, ReliefGC, + 0, 0, mi->lpicture->width, mi->lpicture->height, + lp_offset + mr->xoffset, y); + Globalgcm = GCClipMask; + Globalgcv.clip_mask = None; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + } else { + XCopyPlane(dpy, mi->lpicture->picture, mr->w, currentGC, + 0, 0, mi->lpicture->width, mi->lpicture->height, + lp_offset + mr->xoffset, y, 1); + } } - } - return; + return; } /************************************************************ @@ -1842,59 +1916,55 @@ void PaintEntry(MenuItem *mi) * ************************************************************/ -void PaintSidePic(MenuRoot *mr) +void +PaintSidePic(MenuRoot *mr) { - GC ReliefGC, TextGC; - FvwmPicture *sidePic; - - if (mr->sidePic) - sidePic = mr->sidePic; - else if (mr->ms->look.sidePic) - sidePic = mr->ms->look.sidePic; - else - return; - - if(Scr.d_depth<2) - ReliefGC = mr->ms->look.MenuShadowGC; - else - ReliefGC = mr->ms->look.MenuReliefGC; - TextGC = mr->ms->look.MenuGC; - - if(mr->colorize) - Globalgcv.foreground = mr->sideColor; - else if (mr->ms->look.f.hasSideColor) - Globalgcv.foreground = mr->ms->look.sideColor; - if (mr->colorize || mr->ms->look.f.hasSideColor) { - Globalgcm = GCForeground; - XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); - XFillRectangle(dpy, mr->w, Scr.ScratchGC1, 3, 3, - sidePic->width, mr->height - 6); - } - - if(sidePic->depth > 0) /* pixmap? */ - { - Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; - Globalgcv.clip_mask = sidePic->mask; - Globalgcv.clip_x_origin = 3; - Globalgcv.clip_y_origin = mr->height - sidePic->height -3; - - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - XCopyArea(dpy, sidePic->picture, mr->w, - ReliefGC, 0, 0, - sidePic->width, sidePic->height, - Globalgcv.clip_x_origin, Globalgcv.clip_y_origin); - Globalgcm = GCClipMask; - Globalgcv.clip_mask = None; - XChangeGC(dpy,ReliefGC,Globalgcm,&Globalgcv); - } else { - XCopyPlane(dpy, sidePic->picture, mr->w, - TextGC, 0, 0, - sidePic->width, sidePic->height, - 1, mr->height - sidePic->height, 1); - } -} + GC ReliefGC, TextGC; + FvwmPicture *sidePic; + if (mr->sidePic) + sidePic = mr->sidePic; + else if (mr->ms->look.sidePic) + sidePic = mr->ms->look.sidePic; + else + return; + + if (Scr.d_depth < 2) + ReliefGC = mr->ms->look.MenuShadowGC; + else + ReliefGC = mr->ms->look.MenuReliefGC; + TextGC = mr->ms->look.MenuGC; + + if (mr->colorize) + Globalgcv.foreground = mr->sideColor; + else if (mr->ms->look.f.hasSideColor) + Globalgcv.foreground = mr->ms->look.sideColor; + if (mr->colorize || mr->ms->look.f.hasSideColor) { + Globalgcm = GCForeground; + XChangeGC(dpy, Scr.ScratchGC1, Globalgcm, &Globalgcv); + XFillRectangle(dpy, mr->w, Scr.ScratchGC1, 3, 3, sidePic->width, + mr->height - 6); + } + if (sidePic->depth > 0) { /* pixmap? */ + Globalgcm = GCClipMask | GCClipXOrigin | GCClipYOrigin; + Globalgcv.clip_mask = sidePic->mask; + Globalgcv.clip_x_origin = 3; + Globalgcv.clip_y_origin = mr->height - sidePic->height - 3; + + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + XCopyArea(dpy, sidePic->picture, mr->w, ReliefGC, 0, 0, + sidePic->width, sidePic->height, Globalgcv.clip_x_origin, + Globalgcv.clip_y_origin); + Globalgcm = GCClipMask; + Globalgcv.clip_mask = None; + XChangeGC(dpy, ReliefGC, Globalgcm, &Globalgcv); + } else { + XCopyPlane(dpy, sidePic->picture, mr->w, TextGC, 0, 0, + sidePic->width, sidePic->height, 1, + mr->height - sidePic->height, 1); + } +} /**************************************************************************** * Procedure: @@ -1906,24 +1976,26 @@ void PaintSidePic(MenuRoot *mr) * the character... * ****************************************************************************/ -static -void DrawUnderline(MenuRoot *mr, GC gc, int x, int y, char *txt, int posn) +static void +DrawUnderline(MenuRoot *mr, GC gc, int x, int y, char *txt, int posn) { - int off1 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn); - int off2 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn + 1) - 1; - XDrawLine(dpy, mr->w, gc, x + off1, y + 2, x + off2, y + 2); + int off1 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn); + int off2 = XTextWidth(mr->ms->look.pStdFont->font, txt, posn + 1) - 1; + XDrawLine(dpy, mr->w, gc, x + off1, y + 2, x + off2, y + 2); } + /**************************************************************************** * * Draws two horizontal lines to form a separator * ****************************************************************************/ -static -void DrawSeparator(Window w, GC TopGC, GC BottomGC,int x1,int y1,int x2,int y2, - int extra_off) +static void +DrawSeparator(Window w, GC TopGC, GC BottomGC, int x1, int y1, int x2, int y2, + int extra_off) { - XDrawLine(dpy, w, TopGC , x1, y1, x2, y2); - XDrawLine(dpy, w, BottomGC, x1-extra_off, y1+1,x2+extra_off,y2+1); + XDrawLine(dpy, w, TopGC, x1, y1, x2, y2); + XDrawLine( + dpy, w, BottomGC, x1 - extra_off, y1 + 1, x2 + extra_off, y2 + 1); } /**************************************************************************** @@ -1931,27 +2003,30 @@ void DrawSeparator(Window w, GC TopGC, GC BottomGC,int x1,int y1,int x2,int y2, * Draws a little Triangle pattern within a window * ****************************************************************************/ -static -void DrawTrianglePattern(Window w,GC GC1,GC GC2,GC GC3,GC gc,int l,int u, - int r,int b, char relief) +static void +DrawTrianglePattern(Window w, GC GC1, GC GC2, GC GC3, GC gc, int l, int u, + int r, int b, char relief) { - int m; - - m = (u + b)/2; - - if (!relief) { - /* solid triangle */ - XPoint points[3]; - points[0].x = l; points[0].y = u; - points[1].x = l; points[1].y = b; - points[2].x = r; points[2].y = m; - XFillPolygon(dpy, w, gc, points, 3, Convex, CoordModeOrigin); - } else { - /* relief triangle */ - XDrawLine(dpy,w,GC1,l,u,l,b); - XDrawLine(dpy,w,GC2,l,b,r,m); - XDrawLine(dpy,w,GC3,r,m,l,u); - } + int m; + + m = (u + b) / 2; + + if (!relief) { + /* solid triangle */ + XPoint points[3]; + points[0].x = l; + points[0].y = u; + points[1].x = l; + points[1].y = b; + points[2].x = r; + points[2].y = m; + XFillPolygon(dpy, w, gc, points, 3, Convex, CoordModeOrigin); + } else { + /* relief triangle */ + XDrawLine(dpy, w, GC1, l, u, l, b); + XDrawLine(dpy, w, GC2, l, b, r, m); + XDrawLine(dpy, w, GC3, r, m, l, u); + } } /*********************************************************************** @@ -1960,269 +2035,271 @@ void DrawTrianglePattern(Window w,GC GC1,GC GC2,GC GC3,GC gc,int l,int u, * PaintMenu - draws the entire menu * ***********************************************************************/ -void PaintMenu(MenuRoot *mr, XEvent *pevent) +void +PaintMenu(MenuRoot *mr, XEvent *pevent) { - MenuItem *mi; - MenuStyle *ms = mr->ms; - register int type; - XRectangle bounds; + MenuItem *mi; + MenuStyle *ms = mr->ms; + register int type; + XRectangle bounds; #ifdef PIXMAP_BUTTONS - FvwmPicture *p; - int border = 0; - int width, height, x, y; + FvwmPicture *p; + int border = 0; + int width, height, x, y; #endif #ifdef GRADIENT_BUTTONS - Pixmap pmap; - GC pmapgc; - XGCValues gcv; - unsigned long gcm = 0; - gcv.line_width=3; - gcm = GCLineWidth; + Pixmap pmap; + GC pmapgc; + XGCValues gcv; + unsigned long gcm = 0; + gcv.line_width = 3; + gcm = GCLineWidth; #endif - mr->flags.f.painted = 1; - if( ms ) - { - type = ms->look.face.type; - switch(type) - { - case SolidMenu: - XSetWindowBackground(dpy, mr->w, mr->ms->look.face.u.back); - flush_expose(mr->w); - XClearWindow(dpy,mr->w); - break; + mr->flags.f.painted = 1; + if (ms) { + type = ms->look.face.type; + switch (type) { + case SolidMenu: + XSetWindowBackground( + dpy, mr->w, mr->ms->look.face.u.back); + flush_expose(mr->w); + XClearWindow(dpy, mr->w); + break; #ifdef GRADIENT_BUTTONS - case HGradMenu: - case VGradMenu: - case DGradMenu: - case BGradMenu: - bounds.x = 2; bounds.y = 2; - bounds.width = mr->width - 5; - bounds.height = mr->height; - - if (type == HGradMenu) { - if (mr->backgroundset == False) - { - register int i = 0; - register int dw; - - pmap = XCreatePixmap(dpy, Scr.Root, mr->width, 5, Scr.d_depth); - pmapgc = XCreateGC(dpy, pmap, gcm, &gcv); - - bounds.width = mr->width; - dw= (float) bounds.width / ms->look.face.u.grad.npixels + 1; - while (i < ms->look.face.u.grad.npixels) - { - unsigned short x = i * bounds.width / ms->look.face.u.grad.npixels; - XSetForeground(dpy, pmapgc, - ms->look.face.u.grad.pixels[i++ ]); - XFillRectangle(dpy, pmap, pmapgc, - x, 0, - dw, 5); - } - XSetWindowBackgroundPixmap(dpy, mr->w, pmap); - XFreeGC(dpy,pmapgc); - XFreePixmap(dpy,pmap); - mr->backgroundset = True; - } - XClearWindow(dpy, mr->w); - } - else if (type == VGradMenu) - { - if (mr->backgroundset == False) - { - register int i = 0; - register int dh = bounds.height / ms->look.face.u.grad.npixels + 1; - - pmap = XCreatePixmap(dpy, Scr.Root, 5, mr->height, Scr.d_depth); - pmapgc = XCreateGC(dpy, pmap, gcm, &gcv); - - while (i < ms->look.face.u.grad.npixels) - { - unsigned short y = i*bounds.height / ms->look.face.u.grad.npixels; - XSetForeground(dpy, pmapgc, - ms->look.face.u.grad.pixels[i++]); - XFillRectangle(dpy, pmap, pmapgc, - 0, y, - 5, dh); - } - XSetWindowBackgroundPixmap(dpy, mr->w, pmap); - XFreeGC(dpy,pmapgc); - XFreePixmap(dpy,pmap); - mr->backgroundset = True; - } - XClearWindow(dpy, mr->w); - } - else /* D or BGradient */ - { - register int i = 0, numLines; - int cindex = -1; - - XSetClipMask(dpy, Scr.TransMaskGC, None); - numLines = mr->width + mr->height - 1; - for(i = 0; i < numLines; i++) - { - if((int)(i * ms->look.face.u.grad.npixels / numLines) > cindex) - { - /* pick the next colour (skip if necc.) */ - cindex = i * ms->look.face.u.grad.npixels / numLines; - XSetForeground(dpy, Scr.TransMaskGC, ms->look.face.u.grad.pixels[cindex]); - } - if (type == DGradMenu) - XDrawLine(dpy, mr->w, Scr.TransMaskGC, - 0, i, i, 0); - else /* BGradient */ - XDrawLine(dpy, mr->w, Scr.TransMaskGC, - 0, mr->height - 1 - i, i, mr->height - 1); - } - } - break; -#endif /* GRADIENT_BUTTONS */ + case HGradMenu: + case VGradMenu: + case DGradMenu: + case BGradMenu: + bounds.x = 2; + bounds.y = 2; + bounds.width = mr->width - 5; + bounds.height = mr->height; + + if (type == HGradMenu) { + if (mr->backgroundset == False) { + register int i = 0; + register int dw; + + pmap = XCreatePixmap(dpy, Scr.Root, + mr->width, 5, Scr.d_depth); + pmapgc = + XCreateGC(dpy, pmap, gcm, &gcv); + + bounds.width = mr->width; + dw = (float)bounds.width / + ms->look.face.u.grad.npixels + + 1; + while (i < + ms->look.face.u.grad.npixels) { + unsigned short x = + i * bounds.width / + ms->look.face.u.grad + .npixels; + XSetForeground(dpy, pmapgc, + ms->look.face.u.grad + .pixels[i++]); + XFillRectangle(dpy, pmap, + pmapgc, x, 0, dw, 5); + } + XSetWindowBackgroundPixmap( + dpy, mr->w, pmap); + XFreeGC(dpy, pmapgc); + XFreePixmap(dpy, pmap); + mr->backgroundset = True; + } + XClearWindow(dpy, mr->w); + } else if (type == VGradMenu) { + if (mr->backgroundset == False) { + register int i = 0; + register int dh = + bounds.height / + ms->look.face.u.grad.npixels + + 1; + + pmap = XCreatePixmap(dpy, Scr.Root, 5, + mr->height, Scr.d_depth); + pmapgc = + XCreateGC(dpy, pmap, gcm, &gcv); + + while (i < + ms->look.face.u.grad.npixels) { + unsigned short y = + i * bounds.height / + ms->look.face.u.grad + .npixels; + XSetForeground(dpy, pmapgc, + ms->look.face.u.grad + .pixels[i++]); + XFillRectangle(dpy, pmap, + pmapgc, 0, y, 5, dh); + } + XSetWindowBackgroundPixmap( + dpy, mr->w, pmap); + XFreeGC(dpy, pmapgc); + XFreePixmap(dpy, pmap); + mr->backgroundset = True; + } + XClearWindow(dpy, mr->w); + } else /* D or BGradient */ { + register int i = 0, numLines; + int cindex = -1; + + XSetClipMask(dpy, Scr.TransMaskGC, None); + numLines = mr->width + mr->height - 1; + for (i = 0; i < numLines; i++) { + if ((int)(i * + ms->look.face.u.grad.npixels / + numLines) > cindex) { + /* pick the next colour (skip if + * necc.) */ + cindex = i * + ms->look.face.u.grad + .npixels / + numLines; + XSetForeground(dpy, + Scr.TransMaskGC, + ms->look.face.u.grad + .pixels[cindex]); + } + if (type == DGradMenu) + XDrawLine(dpy, mr->w, + Scr.TransMaskGC, 0, i, i, + 0); + else /* BGradient */ + XDrawLine(dpy, mr->w, + Scr.TransMaskGC, 0, + mr->height - 1 - i, i, + mr->height - 1); + } + } + break; +#endif /* GRADIENT_BUTTONS */ #ifdef PIXMAP_BUTTONS - case PixmapMenu: - p = ms->look.face.u.p; - - border = 0; - width = mr->width - border * 2; height = mr->height - border * 2; - -#if 0 - /* these flags are never set at the moment */ - x = border; - if (ms->look.FaceStyle & HOffCenter) { - if (ms->look.FaceStyle & HRight) - x += (int)(width - p->width); - } else - x += (int)(width - p->width) / 2; - - y = border; - if (ms->look.FaceStyle & VOffCenter) { - if (ms->look.FaceStyle & VBottom) - y += (int)(height - p->height); - } else -#else - y = border + (int)(height - p->height) / 2; - x = border + (int)(width - p->width) / 2; -#endif - - if (x < border) - x = border; - if (y < border) - y = border; - if (width > p->width) - width = p->width; - if (height > p->height) - height = p->height; - if (width > mr->width - x - border) - width = mr->width - x - border; - if (height > mr->height - y - border) - height = mr->height - y - border; - - XSetClipMask(dpy, Scr.TransMaskGC, p->mask); - XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); - XCopyArea(dpy, p->picture, mr->w, Scr.TransMaskGC, - 0, 0, width, height, x, y); - break; - - case TiledPixmapMenu: - XSetWindowBackgroundPixmap(dpy, mr->w, ms->look.face.u.p->picture); - flush_expose(mr->w); - XClearWindow(dpy,mr->w); - break; + case PixmapMenu: + p = ms->look.face.u.p; + + border = 0; + width = mr->width - border * 2; + height = mr->height - border * 2; + + y = border + (int)(height - p->height) / 2; + x = border + (int)(width - p->width) / 2; + + if (x < border) + x = border; + if (y < border) + y = border; + if (width > p->width) + width = p->width; + if (height > p->height) + height = p->height; + if (width > mr->width - x - border) + width = mr->width - x - border; + if (height > mr->height - y - border) + height = mr->height - y - border; + + XSetClipMask(dpy, Scr.TransMaskGC, p->mask); + XSetClipOrigin(dpy, Scr.TransMaskGC, x, y); + XCopyArea(dpy, p->picture, mr->w, Scr.TransMaskGC, 0, 0, + width, height, x, y); + break; + + case TiledPixmapMenu: + XSetWindowBackgroundPixmap( + dpy, mr->w, ms->look.face.u.p->picture); + flush_expose(mr->w); + XClearWindow(dpy, mr->w); + break; #endif /* PIXMAP_BUTTONS */ - } - } - - for (mi = mr->first; mi != NULL; mi = mi->next) - { - /* be smart about handling the expose, redraw only the entries - * that we need to */ - if( (mr->ms->look.face.type != SolidMenu && - mr->ms->look.face.type != SimpleMenu) || pevent == NULL || - (pevent->xexpose.y < (mi->y_offset + mi->y_height) && - (pevent->xexpose.y + pevent->xexpose.height) > mi->y_offset)) - { - PaintEntry(mi); - } - } - - PaintSidePic(mr); - XSync(dpy, 0); - return; -} + } + } + for (mi = mr->first; mi != NULL; mi = mi->next) { + /* be smart about handling the expose, redraw only the entries + * that we need to */ + if ((mr->ms->look.face.type != SolidMenu && + mr->ms->look.face.type != SimpleMenu) || + pevent == NULL || + (pevent->xexpose.y < (mi->y_offset + mi->y_height) && + (pevent->xexpose.y + pevent->xexpose.height) > + mi->y_offset)) { + PaintEntry(mi); + } + } -void FreeMenuItem(MenuItem *mi) -{ - if (!mi) - return; - if (mi->item != NULL) - free(mi->item); - if (mi->item2 != NULL) - free(mi->item2); - if (mi->action != NULL) - free(mi->action); - if(mi->picture) - DestroyPicture(dpy,mi->picture); - if(mi->lpicture) - DestroyPicture(dpy,mi->lpicture); - free(mi); + PaintSidePic(mr); + XSync(dpy, 0); + return; } +void +FreeMenuItem(MenuItem *mi) +{ + if (!mi) + return; + if (mi->item != NULL) + free(mi->item); + if (mi->item2 != NULL) + free(mi->item2); + if (mi->action != NULL) + free(mi->action); + if (mi->picture) + DestroyPicture(dpy, mi->picture); + if (mi->lpicture) + DestroyPicture(dpy, mi->lpicture); + free(mi); +} -void DestroyMenu(MenuRoot *mr) +void +DestroyMenu(MenuRoot *mr) { - MenuItem *mi,*tmp2; - MenuRoot *tmp, *prev; - - if(mr == NULL) - return; - - tmp = Scr.menus.all; - prev = NULL; - while((tmp != NULL)&&(tmp != mr)) - { - prev = tmp; - tmp = tmp->next; - } - if(tmp != mr) - return; - - if(prev == NULL) - Scr.menus.all = mr->next; - else - prev->next = mr->next; - - free(mr->name); - XDestroyWindow(dpy,mr->w); - XDeleteContext(dpy, mr->w, MenuContext); - - if (mr->sidePic) - DestroyPicture(dpy, mr->sidePic); - -#if 0 - /* Hey, we can't just destroy the menu face here. Another menu may need it */ - if (mr->ms != Scr.DefaultMenuStyle && mr->ms) /* I'm a bit paranoid about - segfaults :) */ - { - XFreeGC(dpy,mr->ms->look.MenuReliefGC); - XFreeGC(dpy,mr->ms->look.MenuShadowGC); - XFreeGC(dpy,mr->ms->look.MenuActiveGC); - XFreeGC(dpy,mr->ms->look.MenuGC); - free( mr->ms ); - } -#endif + MenuItem *mi, *tmp2; + MenuRoot *tmp, *prev; + + if (mr == NULL) + return; + + if (mr->in_use) { + PopDownMenu(mr); + mr->in_use = 0; + if (mr->mrDynamicPrev && mr->mrDynamicPrev->selected && + MrPopupForMi(mr->mrDynamicPrev->selected) == mr) { + mr->mrDynamicPrev->selected = NULL; + } + } - /* need to free the window list ? */ - mi = mr->first; - while(mi != NULL) - { - tmp2 = mi->next; - FreeMenuItem(mi); - mi = tmp2; - } - free(mr); + tmp = Scr.menus.all; + prev = NULL; + while ((tmp != NULL) && (tmp != mr)) { + prev = tmp; + tmp = tmp->next; + } + if (tmp != mr) + return; + + if (prev == NULL) + Scr.menus.all = mr->next; + else + prev->next = mr->next; + + free(mr->name); + XDestroyWindow(dpy, mr->w); + XDeleteContext(dpy, mr->w, MenuContext); + + if (mr->sidePic) + DestroyPicture(dpy, mr->sidePic); + + /* need to free the window list ? */ + mi = mr->first; + while (mi != NULL) { + tmp2 = mi->next; + FreeMenuItem(mi); + mi = tmp2; + } + free(mr); } /**************************************************************************** @@ -2230,16 +2307,16 @@ void DestroyMenu(MenuRoot *mr) * Generates the windows for all menus * ****************************************************************************/ -void MakeMenus(void) +void +MakeMenus(void) { - MenuRoot *mr; - - mr = Scr.menus.all; - while(mr != NULL) - { - MakeMenu(mr); - mr = mr->next; - } + MenuRoot *mr; + + mr = Scr.menus.all; + while (mr != NULL) { + MakeMenu(mr); + mr = mr->next; + } } /**************************************************************************** @@ -2247,228 +2324,231 @@ void MakeMenus(void) * Generates the window for a menu * ****************************************************************************/ -void MakeMenu(MenuRoot *mr) +void +MakeMenu(MenuRoot *mr) { - MenuItem *cur; - MenuItem *cur_prev; - unsigned long valuemask; - XSetWindowAttributes attributes; - int y,width; - int cItems; - size_t len; - - if((mr->func != F_POPUP)||(!(Scr.flags & WindowsCaptured))) - return; - - /* merge menu continuations into one menu again - needed when changing the - * font size of a long menu. */ - while (mr->continuation != NULL) - { - MenuRoot *cont = mr->continuation; - - if (mr->first == mr->last) - { - fvwm_msg(ERR, "MakeMenu", "BUG: Menu contains only contionuation"); - break; - } - /* link first item of continuation to item before 'more...' */ - mr->last->prev->next = cont->first; - cont->first->prev = mr->last->prev; - FreeMenuItem(mr->last); - mr ->last = cont->last; - mr->continuation = cont->continuation; - /* fake an empty menu so that DestroyMenu does not destroy the items. */ - cont->first = NULL; - DestroyMenu(cont); - } - - mr->width = 0; - mr->width2 = 0; - mr->width0 = 0; - for (cur = mr->first; cur != NULL; cur = cur->next) - { - width = XTextWidth(mr->ms->look.pStdFont->font, cur->item, cur->strlen); - if(cur->picture && width < cur->picture->width) - width = cur->picture->width; - if(cur->func_type == F_POPUP) - width += 15; - if (width <= 0) - width = 1; - if (width > mr->width) - mr->width = width; - - width = XTextWidth(mr->ms->look.pStdFont->font, cur->item2,cur->strlen2); - if (width < 0) - width = 0; - if (width > mr->width2) - mr->width2 = width; - if((width==0)&&(cur->strlen2>0)) - mr->width2 = 1; - - if(cur->lpicture) - if(mr->width0 < (cur->lpicture->width+3)) - mr->width0 = cur->lpicture->width+3; - } - - /* lets first size the window accordingly */ - mr->width += 10; - if(mr->width2 > 0) - mr->width += 5; - - /* cur_prev trails one behind cur, since we need to move that - into a newly-made menu if we run out of space */ - for (y=2, cItems = 0, cur = mr->first, cur_prev = NULL; - cur != NULL; - cur_prev = cur, cur = cur->next, cItems++) - { - cur->mr = mr; - cur->y_offset = y; - cur->x = 5+mr->width0; - if(IS_TITLE_MENU_ITEM(cur)) - { - width = XTextWidth(mr->ms->look.pStdFont->font, cur->item, - cur->strlen); - /* Title */ - if(cur->strlen2 == 0) - cur->x = (mr->width+mr->width2+mr->width0 - width) / 2; - - if((cur->strlen > 0)||(cur->strlen2>0)) - { - if(mr->ms->look.TitleUnderlines == 2) - cur->y_height = mr->ms->look.EntryHeight + HEIGHT_EXTRA_TITLE; - else - { - if((cur == mr->first)||(cur->next == NULL)) - cur->y_height=mr->ms->look.EntryHeight-HEIGHT_EXTRA+1+ - (HEIGHT_EXTRA_TITLE/2); - else - cur->y_height = mr->ms->look.EntryHeight-HEIGHT_EXTRA +1+ - HEIGHT_EXTRA_TITLE; + MenuItem *cur; + MenuItem *cur_prev; + unsigned long valuemask; + XSetWindowAttributes attributes; + int y, width; + int cItems; + size_t len; + + if ((mr->func != F_POPUP) || (!(Scr.flags & WindowsCaptured))) + return; + + /* merge menu continuations into one menu again - needed when changing + * the font size of a long menu. */ + while (mr->continuation != NULL) { + MenuRoot *cont = mr->continuation; + + if (mr->first == mr->last) { + fvwm_msg(ERR, "MakeMenu", + "BUG: Menu contains only continuation"); + mr->continuation = cont->continuation; + continue; } - } - else { - cur->y_height = HEIGHT_SEPARATOR; - } - /* Titles are separators, too */ - cur->fIsSeparator = TRUE; - } - else if((cur->strlen==0)&&(cur->strlen2 == 0)&& - /* added check for NOP to distinguish from items with no text, - * only pixmap */ - StrEquals(cur->action,"nop")) { - /* Separator */ - cur->y_height = HEIGHT_SEPARATOR; - cur->fIsSeparator = TRUE; - } - else { - /* Normal text entry */ - cur->fIsSeparator = FALSE; - if ((cur->strlen==0)&&(cur->strlen2 == 0)) - cur->y_height = HEIGHT_EXTRA; - else - cur->y_height = mr->ms->look.EntryHeight; - } - if(cur->picture) - cur->y_height += cur->picture->height; - if(cur->lpicture && cur->y_height < cur->lpicture->height+4) - cur->y_height = cur->lpicture->height+4; - y += cur->y_height; - if(mr->width2 == 0) - { - cur->x2 = cur->x; - } - else - { - cur->x2 = mr->width -5 + mr->width0; + /* link first item of continuation to item before 'more...' */ + mr->last->prev->next = cont->first; + cont->first->prev = mr->last->prev; + FreeMenuItem(mr->last); + mr->last = cont->last; + mr->continuation = cont->continuation; + /* fake an empty menu so that DestroyMenu does not destroy the + * items. */ + cont->first = NULL; + DestroyMenu(cont); } - /* this item would have to be the last item, or else - we need to add a "More..." entry pointing to a new menu */ - if (y+mr->ms->look.EntryHeight > Scr.MyDisplayHeight && - cur->next != NULL) - { - char *szMenuContinuationActionAndName; - MenuRoot *menuContinuation; - - if (mr->continuation != NULL) { - fvwm_msg(ERR, "MakeMenu", - "Confused-- expected continuation to be null"); - break; - } - len = 8 + strlen(mr->name); - szMenuContinuationActionAndName = (char *) safemalloc(len); - strlcpy(szMenuContinuationActionAndName,"Popup ", len); - strlcat(szMenuContinuationActionAndName, mr->name, len); - strlcat(szMenuContinuationActionAndName,"$", len); - /* NewMenuRoot inserts at the head of the list of menus - but, we need it at the end */ - /* (Give it just the name, which is 6 chars past the action - since strlen("Popup ")==6 ) */ - menuContinuation = NewMenuRoot(szMenuContinuationActionAndName+6, - False); - mr->continuation = menuContinuation; - - /* Now move this item and the remaining items into the new menu */ - cItems--; - menuContinuation->first = cur; - menuContinuation->last = mr->last; - menuContinuation->items = mr->items - cItems; - cur->prev = NULL; - - /* cur_prev is now the last item in the current menu */ - mr->last = cur_prev; - mr->items = cItems; - cur_prev->next = NULL; - - /* Go back one, so that this loop will process the new item */ - y -= cur->y_height; - cur = cur_prev; - - /* And add the entry pointing to the new menu */ - AddToMenu(mr,"More&...",szMenuContinuationActionAndName, - FALSE /* no pixmap scan */, FALSE); - MakeMenu(menuContinuation); - free(szMenuContinuationActionAndName); + + mr->width = 0; + mr->width2 = 0; + mr->width0 = 0; + for (cur = mr->first; cur != NULL; cur = cur->next) { + width = XTextWidth( + mr->ms->look.pStdFont->font, cur->item, cur->strlen); + if (cur->picture && width < cur->picture->width) + width = cur->picture->width; + if (cur->func_type == F_POPUP) + width += 15; + if (width <= 0) + width = 1; + if (width > mr->width) + mr->width = width; + + width = XTextWidth( + mr->ms->look.pStdFont->font, cur->item2, cur->strlen2); + if (width < 0) + width = 0; + if (width > mr->width2) + mr->width2 = width; + if ((width == 0) && (cur->strlen2 > 0)) + mr->width2 = 1; + + if (cur->lpicture) + if (mr->width0 < (cur->lpicture->width + 3)) + mr->width0 = cur->lpicture->width + 3; } - } /* for */ - mr->in_use = 0; - /* allow two pixels for top border */ - mr->height = y + ((mr->ms->look.ReliefThickness == 1) ? 2 : 3); - mr->flags.allflags = 0; - mr->xanimation = 0; + + /* lets first size the window accordingly */ + mr->width += 10; + if (mr->width2 > 0) + mr->width += 5; + + /* cur_prev trails one behind cur, since we need to move that + into a newly-made menu if we run out of space */ + for (y = 2, cItems = 0, cur = mr->first, cur_prev = NULL; cur != NULL; + cur_prev = cur, cur = cur->next, cItems++) { + cur->mr = mr; + cur->y_offset = y; + cur->x = 5 + mr->width0; + if (IS_TITLE_MENU_ITEM(cur)) { + width = XTextWidth(mr->ms->look.pStdFont->font, + cur->item, cur->strlen); + /* Title */ + if (cur->strlen2 == 0) + cur->x = (mr->width + mr->width2 + mr->width0 - + width) / + 2; + + if ((cur->strlen > 0) || (cur->strlen2 > 0)) { + if (mr->ms->look.TitleUnderlines == 2) + cur->y_height = + mr->ms->look.EntryHeight + + HEIGHT_EXTRA_TITLE; + else { + if ((cur == mr->first) || + (cur->next == NULL)) + cur->y_height = + mr->ms->look.EntryHeight - + HEIGHT_EXTRA + 1 + + (HEIGHT_EXTRA_TITLE / 2); + else + cur->y_height = + mr->ms->look.EntryHeight - + HEIGHT_EXTRA + 1 + + HEIGHT_EXTRA_TITLE; + } + } else { + cur->y_height = HEIGHT_SEPARATOR; + } + /* Titles are separators, too */ + cur->fIsSeparator = TRUE; + } else if ((cur->strlen == 0) && (cur->strlen2 == 0) && + /* added check for NOP to distinguish from items with + * no text, only pixmap */ + StrEquals(cur->action, "nop")) { + /* Separator */ + cur->y_height = HEIGHT_SEPARATOR; + cur->fIsSeparator = TRUE; + } else { + /* Normal text entry */ + cur->fIsSeparator = FALSE; + if ((cur->strlen == 0) && (cur->strlen2 == 0)) + cur->y_height = HEIGHT_EXTRA; + else + cur->y_height = mr->ms->look.EntryHeight; + } + if (cur->picture) + cur->y_height += cur->picture->height; + if (cur->lpicture && cur->y_height < cur->lpicture->height + 4) + cur->y_height = cur->lpicture->height + 4; + y += cur->y_height; + if (mr->width2 == 0) { + cur->x2 = cur->x; + } else { + cur->x2 = mr->width - 5 + mr->width0; + } + /* this item would have to be the last item, or else + we need to add a "More..." entry pointing to a new menu */ + if (y + mr->ms->look.EntryHeight > Scr.MyDisplayHeight && + cur->next != NULL) { + char *szMenuContinuationActionAndName; + MenuRoot *menuContinuation; + + if (mr->continuation != NULL) { + fvwm_msg(ERR, "MakeMenu", + "Confused-- expected continuation to be " + "null"); + break; + } + len = 8 + strlen(mr->name); + szMenuContinuationActionAndName = + (char *)xmalloc(len); + strlcpy(szMenuContinuationActionAndName, "Popup ", len); + strlcat(szMenuContinuationActionAndName, mr->name, len); + strlcat(szMenuContinuationActionAndName, "$", len); + /* NewMenuRoot inserts at the head of the list of menus + but, we need it at the end */ + /* (Give it just the name, which is 6 chars past the + action since strlen("Popup ")==6 ) */ + menuContinuation = NewMenuRoot( + szMenuContinuationActionAndName + 6, False); + mr->continuation = menuContinuation; + + /* Now move this item and the remaining items into the + * new menu */ + cItems--; + menuContinuation->first = cur; + menuContinuation->last = mr->last; + menuContinuation->items = mr->items - cItems; + cur->prev = NULL; + + /* cur_prev is now the last item in the current menu */ + mr->last = cur_prev; + mr->items = cItems; + cur_prev->next = NULL; + + /* Go back one, so that this loop will process the new + * item */ + y -= cur->y_height; + cur = cur_prev; + + /* And add the entry pointing to the new menu */ + AddToMenu(mr, "More&...", + szMenuContinuationActionAndName, + FALSE /* no pixmap scan */, FALSE); + MakeMenu(menuContinuation); + free(szMenuContinuationActionAndName); + } + } /* for */ + mr->in_use = 0; + /* allow two pixels for top border */ + mr->height = y + ((mr->ms->look.ReliefThickness == 1) ? 2 : 3); + mr->flags.allflags = 0; + mr->xanimation = 0; #ifndef NO_SAVEUNDERS - valuemask = (CWBackPixel | CWEventMask | CWCursor | CWSaveUnder); + valuemask = (CWBackPixel | CWEventMask | CWCursor | CWSaveUnder); #else - valuemask = (CWBackPixel | CWEventMask | CWCursor); + valuemask = (CWBackPixel | CWEventMask | CWCursor); #endif - attributes.background_pixel = mr->ms->look.MenuColors.back; - attributes.event_mask = (ExposureMask | EnterWindowMask); - attributes.cursor = Scr.FvwmCursors[MENU]; + attributes.background_pixel = mr->ms->look.MenuColors.back; + attributes.event_mask = (ExposureMask | EnterWindowMask); + attributes.cursor = Scr.FvwmCursors[MENU]; #ifndef NO_SAVEUNDERS - attributes.save_under = TRUE; + attributes.save_under = TRUE; #endif - if(mr->w != None) - XDestroyWindow(dpy,mr->w); - - mr->xoffset = 0; - if(mr->sidePic) { - mr->xoffset = mr->sidePic->width + 5; - } - else if (mr->ms->look.sidePic) { - mr->xoffset = mr->ms->look.sidePic->width + 5; - } - - mr->width = mr->width0 + mr->width + mr->width2 + mr->xoffset; - mr->backgroundset = False; - - mr->w = XCreateWindow (dpy, Scr.Root, 0, 0, (unsigned int) (mr->width), - (unsigned int) mr->height, (unsigned int) 0, - CopyFromParent, (unsigned int) InputOutput, - (Visual *) CopyFromParent, - valuemask, &attributes); - XSaveContext(dpy,mr->w,MenuContext,(caddr_t)mr); - - return; + if (mr->w != None) + XDestroyWindow(dpy, mr->w); + + mr->xoffset = 0; + if (mr->sidePic) { + mr->xoffset = mr->sidePic->width + 5; + } else if (mr->ms->look.sidePic) { + mr->xoffset = mr->ms->look.sidePic->width + 5; + } + + mr->width = mr->width0 + mr->width + mr->width2 + mr->xoffset; + mr->backgroundset = False; + + mr->w = XCreateWindow(dpy, Scr.Root, 0, 0, (unsigned int)(mr->width), + (unsigned int)mr->height, (unsigned int)0, CopyFromParent, + (unsigned int)InputOutput, (Visual *)CopyFromParent, valuemask, + &attributes); + XSaveContext(dpy, mr->w, MenuContext, (caddr_t)mr); + + return; } /* FHotKeyUsedBefore @@ -2476,23 +2556,22 @@ void MakeMenu(MenuRoot *mr) * used the given hotkey already * This means that it doesn't check the last element of the menu */ -int FHotKeyUsedBefore(MenuRoot *menu, char ch) { - int f = FALSE; - MenuItem *currentMenuItem = menu->first; - /* we want to stop just before the last item in the menu */ - while (currentMenuItem != 0 && currentMenuItem->next != 0) - { - if (currentMenuItem->chHotkey == ch) - { - f = TRUE; - break; - } - currentMenuItem = currentMenuItem->next; - } - return f; +int +FHotKeyUsedBefore(MenuRoot *menu, char ch) +{ + int f = FALSE; + MenuItem *currentMenuItem = menu->first; + /* we want to stop just before the last item in the menu */ + while (currentMenuItem != 0 && currentMenuItem->next != 0) { + if (currentMenuItem->chHotkey == ch) { + f = TRUE; + break; + } + currentMenuItem = currentMenuItem->next; + } + return f; } - /*********************************************************************** * Procedure: * scanForHotkeys - Look for hotkey markers in a MenuItem @@ -2503,171 +2582,172 @@ int FHotKeyUsedBefore(MenuRoot *menu, char ch) { * which - +1 to look in it->item1 and -1 to look in it->item2. * ***********************************************************************/ -char scanForHotkeys(MenuItem *it, int which) +char +scanForHotkeys(MenuItem *it, int which) { - char *start, *txt; - - start = (which > 0) ? it->item : it->item2; /* Get start of string */ - for (txt = start; *txt != '\0'; txt++) - { - /* Scan whole string */ - if (*txt == '&') - { /* A hotkey marker? */ - if (txt[1] == '&') - { /* Just an escaped & */ - char *tmp; /* Copy the string down over it */ - for (tmp = txt; *tmp != '\0'; tmp++) tmp[0] = tmp[1]; - continue; /* ...And skip to the key char */ - } - else { - char ch = txt[1]; - /* It's a hot key marker - work out the offset value */ - it->hotkey = (1 + (txt - start)) * which; - for (; *txt != '\0'; txt++) txt[0] = txt[1];/* Copy down.. */ - return ch; /* Only one hotkey per item... */ - } + char *start, *txt; + + start = (which > 0) ? it->item : it->item2; /* Get start of string + */ + for (txt = start; *txt != '\0'; txt++) { + /* Scan whole string */ + if (*txt == '&') { /* A hotkey marker? */ + if (txt[1] == + '&') { /* Just an escaped & */ + char *tmp; /* Copy the string down over it + */ + for (tmp = txt; *tmp != '\0'; tmp++) + tmp[0] = tmp[1]; + continue; /* ...And skip to the key char + */ + } else { + char ch = txt[1]; + /* It's a hot key marker - work out the offset + * value */ + it->hotkey = (1 + (txt - start)) * which; + for (; *txt != '\0'; txt++) + txt[0] = txt[1]; /* Copy down.. */ + return ch; /* Only one hotkey per item... + */ + } + } } - } - it->hotkey = 0; /* No hotkey found. Set offset to zero */ - return '\0'; + it->hotkey = 0; /* No hotkey found. Set offset to zero */ + return '\0'; } - /* Side picture support: this scans for a color int the menu name for colorization */ -void scanForColor(char *instring, Pixel *p, Bool *c, char identifier) +void +scanForColor(char *instring, Pixel *p, Bool *c, char identifier) { - char *tstart, *txt, *save_instring, *name; - int i; - size_t len; - - *c = False; - - /* save instring in case can't find pixmap */ - save_instring = (char *)safemalloc(strlen(instring)+1); - len = strlen(instring)+1; - name = (char *)safemalloc(len); - strlcpy(save_instring,instring, len); - - /* Scan whole string */ - for (txt = instring; *txt != '\0'; txt++) - { - /* A hotkey marker? */ - if (*txt == identifier) - { - /* Just an escaped '^' */ - if (txt[1] == identifier) - { - char *tmp; /* Copy the string down over it */ - for (tmp = txt; *tmp != '\0'; tmp++) tmp[0] = tmp[1]; - continue; /* ...And skip to the key char */ - } - /* It's a hot key marker - work out the offset value */ - tstart = txt; - txt++; - i=0; - while((*txt != identifier)&&(*txt != '\0')) - { - name[i] = *txt; - txt++; - i++; - } - name[i] = 0; - - *p = GetColor(name); - *c = True; - - if(*txt != '\0')txt++; - while(*txt != '\0') - { - *tstart++ = *txt++; - } - *tstart = 0; - break; - } - } - free(name); - free(save_instring); - return; + char *tstart, *txt, *save_instring, *name; + int i; + size_t len; + + *c = False; + + /* save instring in case can't find pixmap */ + save_instring = (char *)xmalloc(strlen(instring) + 1); + len = strlen(instring) + 1; + name = (char *)xmalloc(len); + strlcpy(save_instring, instring, len); + + /* Scan whole string */ + for (txt = instring; *txt != '\0'; txt++) { + /* A hotkey marker? */ + if (*txt == identifier) { + /* Just an escaped '^' */ + if (txt[1] == identifier) { + char *tmp; /* Copy the string down over it */ + for (tmp = txt; *tmp != '\0'; tmp++) + tmp[0] = tmp[1]; + continue; /* ...And skip to the key char */ + } + /* It's a hot key marker - work out the offset value */ + tstart = txt; + txt++; + i = 0; + while ((*txt != identifier) && (*txt != '\0')) { + name[i] = *txt; + txt++; + i++; + } + name[i] = 0; + + *p = GetColor(name); + *c = True; + + if (*txt != '\0') + txt++; + while (*txt != '\0') { + *tstart++ = *txt++; + } + *tstart = 0; + break; + } + } + free(name); + free(save_instring); + return; } -void scanForPixmap(char *instring, FvwmPicture **p, char identifier) +void +scanForPixmap(char *instring, FvwmPicture **p, char identifier) { - char *tstart, *txt, *name; - int i; - FvwmPicture *pp; - extern char *IconPath; - extern char *PixmapPath; + char *tstart, *txt, *name; + int i; + FvwmPicture *pp; + extern char *IconPath; + extern char *PixmapPath; #ifdef UGLY_WHEN_PIXMAPS_MISSING - char *save_instring; - size_t len; + char *save_instring; + size_t len; #endif - if (!instring) - { - *p = NULL; - return; - } + if (!instring) { + *p = NULL; + return; + } #ifdef UGLY_WHEN_PIXMAPS_MISSING - /* save instring in case can't find pixmap */ - len = strlen(instring)+1; - save_instring = (char *)safemalloc(len); - strlcpy(save_instring,instring,len); + /* save instring in case can't find pixmap */ + len = strlen(instring) + 1; + save_instring = (char *)xmalloc(len); + strlcpy(save_instring, instring, len); #endif - name = (char *)safemalloc(strlen(instring)+1); - - /* Scan whole string */ - for (txt = instring; *txt != '\0'; txt++) - { - /* A hotkey marker? */ - if (*txt == identifier) - { - /* Just an escaped & */ - if (txt[1] == identifier) - { - char *tmp; /* Copy the string down over it */ - for (tmp = txt; *tmp != '\0'; tmp++) - tmp[0] = tmp[1]; - continue; /* ...And skip to the key char */ - } - /* It's a hot key marker - work out the offset value */ - tstart = txt; - txt++; - i=0; - while((*txt != identifier)&&(*txt != '\0')) - { - name[i] = *txt; - txt++; - i++; - } - name[i] = 0; - - /* Next, check for a color pixmap */ - pp=CachePicture(dpy,Scr.Root,IconPath,PixmapPath,name, - Scr.ColorLimit); - if(*txt != '\0') - txt++; - while(*txt != '\0') - { - *tstart++ = *txt++; - } - *tstart = 0; - if (pp) - *p = pp; - else + name = (char *)xmalloc(strlen(instring) + 1); + + /* Scan whole string */ + for (txt = instring; *txt != '\0'; txt++) { + /* A hotkey marker? */ + if (*txt == identifier) { + /* Just an escaped & */ + if (txt[1] == identifier) { + char *tmp; /* Copy the string down over it + */ + for (tmp = txt; *tmp != '\0'; tmp++) + tmp[0] = tmp[1]; + continue; /* ...And skip to the key char + */ + } + /* It's a hot key marker - work out the offset value + */ + tstart = txt; + txt++; + i = 0; + while ((*txt != identifier) && (*txt != '\0')) { + name[i] = *txt; + txt++; + i++; + } + name[i] = 0; + + /* Next, check for a color pixmap */ + pp = CachePicture(dpy, Scr.Root, IconPath, PixmapPath, + name, Scr.ColorLimit); + if (*txt != '\0') + txt++; + while (*txt != '\0') { + *tstart++ = *txt++; + } + *tstart = 0; + if (pp) + *p = pp; + else #ifdef UGLY_WHEN_PIXMAPS_MISSING - strlcpy(instring,save_instring,len); + strlcpy(instring, save_instring, len); #else - fvwm_msg(WARN,"scanForPixmap","Couldn't find pixmap %s",name); + fvwm_msg(WARN, "scanForPixmap", + "Couldn't find pixmap %s", name); #endif - break; + break; + } } - } - free(name); + free(name); #ifdef UGLY_WHEN_PIXMAPS_MISSING - free(save_instring); + free(save_instring); #endif } @@ -2675,16 +2755,15 @@ void scanForPixmap(char *instring, FvwmPicture **p, char identifier) * Given an menu root, return the menu root to add to by * following continuation links until there are no more */ -MenuRoot *FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior ) +MenuRoot * +FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior) { - *pmrPrior = NULL; - while ((mr != NULL) && - (mr->continuation != NULL)) - { - *pmrPrior = mr; - mr = mr->continuation; - } - return mr; + *pmrPrior = NULL; + while ((mr != NULL) && (mr->continuation != NULL)) { + *pmrPrior = mr; + mr = mr->continuation; + } + return mr; } /*********************************************************************** @@ -2705,171 +2784,150 @@ MenuRoot *FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior ) * so built in window list can handle windows w/ * and % in title. * ***********************************************************************/ -void AddToMenu(MenuRoot *menu, char *item, char *action, Bool fPixmapsOk, - Bool fNoPlus) +void +AddToMenu( + MenuRoot *menu, char *item, char *action, Bool fPixmapsOk, Bool fNoPlus) { - MenuItem *tmp; - char *start,*end; - char *token = NULL; - char *token2 = NULL; - char *option = NULL; - - if ((item == NULL || *item == 0) && fNoPlus) - return; - /* empty items screw up our menu when painted, so we replace them with a - * separator */ - if (item == NULL) - item = ""; - if (action == NULL || *action == 0) - action = "Nop"; - GetNextToken(GetNextToken(action, &token), &option); - - tmp = (MenuItem *)safemalloc(sizeof(MenuItem)); - tmp->chHotkey = '\0'; - tmp->next = NULL; - tmp->mr = menu; /* this gets updated in MakeMenu if we split the menu - because it's too large vertically */ - if (menu->first == NULL) - { - menu->first = tmp; - menu->last = tmp; - tmp->prev = NULL; - } - else if (StrEquals(token, "title") && option && StrEquals(option, "top")) - { - if (menu->first->action) - { - GetNextToken(menu->first->action, &token2); - } - if (StrEquals(token2, "title")) - { - tmp->next = menu->first->next; - FreeMenuItem(menu->first); - } - else - { - tmp->next = menu->first; - } - if (token2) - free(token2); - tmp->prev = NULL; - if (menu->first == NULL) - menu->last = tmp; - menu->first = tmp; - } - else - { - menu->last->next = tmp; - tmp->prev = menu->last; - menu->last = tmp; - } - if (token) - free(token); - if (option) - free(option); - tmp->picture=NULL; - tmp->lpicture=NULL; - - /* skip leading spaces */ - /*while(isspace(*item)&&(item != NULL)) - item++;*/ - /* up to first tab goes in "item" field */ - start = item; - end=item; - while((*end != '\t')&&(*end != 0)) - end++; - tmp->item = safemalloc(end-start+1); - strncpy(tmp->item,start,end-start); - tmp->item[end-start] = 0; - tmp->item2 = NULL; - if(*end=='\t') - { - start = end+1; - while(*start == '\t') - start++; - end = start; - while(*end != 0) - end++; - if(end > start) - { - char *s; - - tmp->item2 = safemalloc(end-start+1); - strncpy(tmp->item2,start,end-start); - tmp->item2[end-start] = 0; - s = tmp->item2; - while (*s) - { - if (*s == '\t') - *s = ' '; - s++; - } - } - } - - if (item != (char *)0) - { - char ch; - if (fPixmapsOk) - { - scanForPixmap(tmp->item,&tmp->picture,'*'); - scanForPixmap(tmp->item,&tmp->lpicture,'%'); - } - ch = scanForHotkeys(tmp, 1); /* pete@tecc.co.uk */ - if (ch != '\0') - { - if (FHotKeyUsedBefore(menu,ch)) - { - fvwm_msg(WARN, "AddToMenu", - "Hotkey %c is reused in menu %s; second binding ignored.", - ch, menu->name); - tmp->hotkey = 0; - } - else - { - tmp->chHotkey = ch; - } + MenuItem *tmp; + char *start, *end; + char *token = NULL; + char *token2 = NULL; + char *option = NULL; + + if ((item == NULL || *item == 0) && fNoPlus) + return; + /* empty items screw up our menu when painted, so we replace them with a + * separator */ + if (item == NULL) + item = ""; + if (action == NULL || *action == 0) + action = "Nop"; + GetNextToken(GetNextToken(action, &token), &option); + + tmp = (MenuItem *)xmalloc(sizeof(MenuItem)); + tmp->chHotkey = '\0'; + tmp->next = NULL; + tmp->mr = menu; /* this gets updated in MakeMenu if we split the menu + because it's too large vertically */ + if (menu->first == NULL) { + menu->first = tmp; + menu->last = tmp; + tmp->prev = NULL; + } else if (StrEquals(token, "title") && option && + StrEquals(option, "top")) { + if (menu->first->action) { + GetNextToken(menu->first->action, &token2); + } + if (StrEquals(token2, "title")) { + tmp->next = menu->first->next; + FreeMenuItem(menu->first); + } else { + tmp->next = menu->first; + } + if (token2) + free(token2); + tmp->prev = NULL; + if (menu->first == NULL) + menu->last = tmp; + menu->first = tmp; + } else { + menu->last->next = tmp; + tmp->prev = menu->last; + menu->last = tmp; } - tmp->strlen = strlen(tmp->item); - } - else - tmp->strlen = 0; - - if (tmp->item2 != (char *)0) - { - if (fPixmapsOk) - { - if(!tmp->picture) - scanForPixmap(tmp->item2,&tmp->picture,'*'); - if(!tmp->lpicture) - scanForPixmap(tmp->item2,&tmp->lpicture,'%'); - } - if (tmp->hotkey == 0) { - char ch = scanForHotkeys(tmp, -1); /* pete@tecc.co.uk */ - if (ch != '\0') - { - if (FHotKeyUsedBefore(menu,ch)) - { - fvwm_msg(WARN, "AddToMenu", - "Hotkey %c is reused in menu %s; second binding ignored.", - ch, menu->name); - tmp->hotkey = 0; - } - else - { - tmp->chHotkey = ch; - } + if (token) + free(token); + if (option) + free(option); + tmp->picture = NULL; + tmp->lpicture = NULL; + + /* skip leading spaces */ + /*while(isspace(*item)&&(item != NULL)) + item++;*/ + /* up to first tab goes in "item" field */ + start = item; + end = item; + while ((*end != '\t') && (*end != 0)) + end++; + tmp->item = xmalloc(end - start + 1); + strncpy(tmp->item, start, end - start); + tmp->item[end - start] = 0; + tmp->item2 = NULL; + if (*end == '\t') { + start = end + 1; + while (*start == '\t') + start++; + end = start; + while (*end != 0) + end++; + if (end > start) { + char *s; + + tmp->item2 = xmalloc(end - start + 1); + strncpy(tmp->item2, start, end - start); + tmp->item2[end - start] = 0; + s = tmp->item2; + while (*s) { + if (*s == '\t') + *s = ' '; + s++; + } + } } - } - tmp->strlen2 = strlen(tmp->item2); - } - else - tmp->strlen2 = 0; - - tmp->action = stripcpy(action); - tmp->state = 0; - find_func_type(tmp->action, &(tmp->func_type), &(tmp->func_needs_window)); - tmp->item_num = menu->items++; + + if (item != (char *)0) { + char ch; + if (fPixmapsOk) { + scanForPixmap(tmp->item, &tmp->picture, '*'); + scanForPixmap(tmp->item, &tmp->lpicture, '%'); + } + ch = scanForHotkeys(tmp, 1); /* pete@tecc.co.uk */ + if (ch != '\0') { + if (FHotKeyUsedBefore(menu, ch)) { + fvwm_msg(WARN, "AddToMenu", + "Hotkey %c is reused in menu %s; second " + "binding ignored.", + ch, menu->name); + tmp->hotkey = 0; + } else { + tmp->chHotkey = ch; + } + } + tmp->strlen = strlen(tmp->item); + } else + tmp->strlen = 0; + + if (tmp->item2 != (char *)0) { + if (fPixmapsOk) { + if (!tmp->picture) + scanForPixmap(tmp->item2, &tmp->picture, '*'); + if (!tmp->lpicture) + scanForPixmap(tmp->item2, &tmp->lpicture, '%'); + } + if (tmp->hotkey == 0) { + char ch = scanForHotkeys(tmp, -1); /* pete@tecc.co.uk */ + if (ch != '\0') { + if (FHotKeyUsedBefore(menu, ch)) { + fvwm_msg(WARN, "AddToMenu", + "Hotkey %c is reused in menu %s; " + "second binding ignored.", + ch, menu->name); + tmp->hotkey = 0; + } else { + tmp->chHotkey = ch; + } + } + } + tmp->strlen2 = strlen(tmp->item2); + } else + tmp->strlen2 = 0; + + tmp->action = stripcpy(action); + tmp->state = 0; + find_func_type( + tmp->action, &(tmp->func_type), &(tmp->func_needs_window)); + tmp->item_num = menu->items++; } /*********************************************************************** @@ -2886,46 +2944,45 @@ void AddToMenu(MenuRoot *menu, char *item, char *action, Bool fPixmapsOk, * F_POPUP otherwise * ***********************************************************************/ -MenuRoot *NewMenuRoot(char *name, Bool fFunction) +MenuRoot * +NewMenuRoot(char *name, Bool fFunction) { - MenuRoot *tmp; + MenuRoot *tmp; - tmp = (MenuRoot *) safemalloc(sizeof(MenuRoot)); + tmp = (MenuRoot *)xmalloc(sizeof(MenuRoot)); - tmp->first = NULL; - tmp->last = NULL; - tmp->selected = NULL; + tmp->first = NULL; + tmp->last = NULL; + tmp->selected = NULL; #ifdef GRADIENT_BUTTONS - tmp->stored_item.width = 0; - tmp->stored_item.height = 0; - tmp->stored_item.y = 0; + tmp->stored_item.width = 0; + tmp->stored_item.height = 0; + tmp->stored_item.y = 0; #endif - tmp->next = Scr.menus.all; - tmp->continuation = NULL; - tmp->mrDynamicPrev = NULL; - tmp->name = stripcpy(name); - tmp->w = None; - tmp->height = 0; - tmp->width = 0; - tmp->width2 = 0; - tmp->width0 = 0; - tmp->items = 0; - tmp->in_use = 0; - tmp->func = (fFunction) ? F_FUNCTION : F_POPUP; - tmp->sidePic = NULL; - scanForPixmap(tmp->name, &tmp->sidePic, '@'); - scanForColor(tmp->name, &tmp->sideColor, &tmp->colorize,'^'); - tmp->xoffset = 0; - tmp->ms = Scr.menus.DefaultStyle; - tmp->flags.allflags = 0; - tmp->xanimation = 0; - - Scr.menus.all = tmp; - return (tmp); + tmp->next = Scr.menus.all; + tmp->continuation = NULL; + tmp->mrDynamicPrev = NULL; + tmp->name = stripcpy(name); + tmp->w = None; + tmp->height = 0; + tmp->width = 0; + tmp->width2 = 0; + tmp->width0 = 0; + tmp->items = 0; + tmp->in_use = 0; + tmp->func = (fFunction) ? F_FUNCTION : F_POPUP; + tmp->sidePic = NULL; + scanForPixmap(tmp->name, &tmp->sidePic, '@'); + scanForColor(tmp->name, &tmp->sideColor, &tmp->colorize, '^'); + tmp->xoffset = 0; + tmp->ms = Scr.menus.DefaultStyle; + tmp->flags.allflags = 0; + tmp->xanimation = 0; + + Scr.menus.all = tmp; + return (tmp); } - - /*********************************************************************** * change by KitS@bartley.demon.co.uk to correct popups off title buttons * @@ -2942,33 +2999,31 @@ MenuRoot *NewMenuRoot(char *name, Bool fFunction) * t - the window (FvwmWindow) to test against * ***********************************************************************/ -int ButtonPosition(int context, FvwmWindow * t) +int +ButtonPosition(int context, FvwmWindow *t) { - int i; - int buttons = -1; - - if (context&C_RALL) { - for(i=0;iright_w[i]) { - buttons++; + int i; + int buttons = -1; + + if (context & C_RALL) { + for (i = 0; i < Scr.nr_right_buttons; i++) { + if (t->right_w[i]) { + buttons++; + } + /* is this the button ? */ + if (((1 << i) * C_R1) & context) + return (buttons); + } + } else { + for (i = 0; i < Scr.nr_left_buttons; i++) { + if (t->left_w[i]) { + buttons++; + } + /* is this the button ? */ + if (((1 << i) * C_L1) & context) + return (buttons); + } } - /* is this the button ? */ - if (((1<left_w[i]) - { - buttons++; - } - /* is this the button ? */ - if (((1<mr when - selected IS_POPUP_MENU_ITEM(selected) */ - struct MenuRoot *mrDynamicPrev; /* the menu that popped this up, if any */ + struct MenuRoot *next; /* next in list of root menus */ + struct MenuRoot *continuation; /* continuation of this menu + * (too tall for screen */ + /* can get the menu that this popped up through selected->mr when + selected IS_POPUP_MENU_ITEM(selected) */ + struct MenuRoot *mrDynamicPrev; /* the menu that popped this up, if any */ - char *name; /* name of root */ - Window w; /* the window of the menu */ - short height; /* height of the menu */ - short width; /* width of the menu for 1st col */ - short width2; /* width of the menu for 2nd col */ - short width0; /* width of the menu-left-picture col */ - short items; /* number of items in the menu */ - Bool backgroundset; /* is win background set for this menu ?? */ - Bool in_use; - int func; - FvwmPicture *sidePic; - Pixel sideColor; - Bool colorize; - short xoffset; - MenuStyle *ms; /* Menu Face */ - union /* internal flags, deleted when menu pops down! */ - { - /* need to change that type if we have more than 8 flags. - * more that a word will entail some changes in the code! */ - unsigned char allflags; - struct - { - unsigned painted : 1; - unsigned is_left : 1; /* menu direction relative to parent menu */ - unsigned is_right : 1; - unsigned is_up : 1; - unsigned is_down : 1; - } f; - } flags; - int xanimation; /* x distance window was moved by animation */ + char *name; /* name of root */ + Window w; /* the window of the menu */ + short height; /* height of the menu */ + short width; /* width of the menu for 1st col */ + short width2; /* width of the menu for 2nd col */ + short width0; /* width of the menu-left-picture col */ + short items; /* number of items in the menu */ + Bool backgroundset; /* is win background set for this menu ?? */ + Bool in_use; + int func; + FvwmPicture *sidePic; + Pixel sideColor; + Bool colorize; + short xoffset; + MenuStyle *ms; /* Menu Face */ + union /* internal flags, deleted when menu pops down! */ { + /* need to change that type if we have more than 8 flags. + * more that a word will entail some changes in the code! */ + unsigned char allflags; + struct { + unsigned painted:1; + unsigned is_left:1; /* menu direction relative to parent menu */ + unsigned is_right:1; + unsigned is_up:1; + unsigned is_down:1; + } f; + } flags; + int xanimation; /* x distance window was moved by animation */ } MenuRoot; /* don't forget to initialise new members in NewMenuRoot()! */ typedef struct MenuGlobals { - MenuRoot *all; - struct MenuStyle *DefaultStyle; - struct MenuStyle *LastStyle; - int PopupDelay10ms; - int DoubleClickTime; + MenuRoot *all; + struct MenuStyle *DefaultStyle; + struct MenuStyle *LastStyle; + int PopupDelay10ms; + int DoubleClickTime; } MenuGlobals; -typedef struct Binding -{ - char IsMouse; /* Is it a mouse or key binding 1= mouse; */ - int Button_Key; /* Mouse Button number of Keycode */ - char *key_name; /* In case of keycode, give the key_name too */ - int Context; /* Contex is Fvwm context, ie titlebar, frame, etc */ - int Modifier; /* Modifiers for keyboard state */ - char *Action; /* What to do? */ - struct Binding *NextBinding; +typedef struct Binding { + char IsMouse; /* Is it a mouse or key binding 1= mouse; */ + int Button_Key; /* Mouse Button number of Keycode */ + char *key_name; /* In case of keycode, give the key_name too */ + int Context; /* Contex is Fvwm context, ie titlebar, frame, etc */ + int Modifier; /* Modifiers for keyboard state */ + char *Action; /* What to do? */ + struct Binding *NextBinding; } Binding; -typedef struct -{ - int x; /* suggested x position */ - int y; /* suggested y position */ - float x_factor; /* to take menu width into account (0, -1 or -0.5) */ - float y_factor; /* same with height */ - Bool fRelative; /* FALSE if referring to absolute screen position */ +typedef struct { + int x; /* suggested x position */ + int y; /* suggested y position */ + float x_factor; /* to take menu width into account (0, -1 or -0.5) */ + float y_factor; /* same with height */ + Bool fRelative; /* FALSE if referring to absolute screen position */ } MenuPosHints; -typedef struct -{ - MenuPosHints pos_hints; - union - { - /* need to change that type if we have more than 8 flags. - * more that a word will entail some changes in the code! */ - unsigned char allflags; - struct - { - unsigned no_warp : 1; - unsigned warp_title : 1; - unsigned fixed : 1; - unsigned select_in_place : 1; - unsigned select_warp : 1; - unsigned has_poshints : 1; - } f; - } flags; +typedef struct { + MenuPosHints pos_hints; + union { + /* need to change that type if we have more than 8 flags. + * more that a word will entail some changes in the code! */ + unsigned char allflags; + struct { + unsigned no_warp:1; + unsigned warp_title:1; + unsigned fixed:1; + unsigned select_in_place:1; + unsigned select_warp:1; + unsigned has_poshints:1; + } f; + } flags; } MenuOptions; extern MenuPosHints lastMenuPosHints; extern Bool fLastMenuPosHintsValid; - /* Return values for UpdateMenu, do_menu, menuShortcuts */ /* Just uses enum-s for their constant value, replaced a bunch of #define-s * before */ /* This is a lame hack, in that "_BUTTON" is added to mean a button-release caused the return-- the macros below help deal with the ugliness */ typedef enum { - MENU_ERROR = -1, - MENU_NOP = 0, - MENU_DONE = 1, - MENU_DONE_BUTTON = 2, /* must be MENU_DONE + 1 */ - MENU_ABORTED = 3, - MENU_ABORTED_BUTTON = 4, /* must be MENU_ABORTED + 1 */ - MENU_SUBMENU_DONE, - MENU_DOUBLE_CLICKED, - MENU_POPUP, - MENU_POPDOWN, - MENU_SELECTED, - MENU_NEWITEM + MENU_ERROR = -1, + MENU_NOP = 0, + MENU_DONE = 1, + MENU_DONE_BUTTON = 2, /* must be MENU_DONE + 1 */ + MENU_ABORTED = 3, + MENU_ABORTED_BUTTON = 4, /* must be MENU_ABORTED + 1 */ + MENU_SUBMENU_DONE, + MENU_DOUBLE_CLICKED, + MENU_POPUP, + MENU_POPDOWN, + MENU_SELECTED, + MENU_NEWITEM } MenuStatus; -#define IS_MENU_RETURN(x) ((x)>=MENU_DONE && (x)<=MENU_ABORTED_BUTTON) -#define IS_MENU_BUTTON(x) ((x)==MENU_DONE_BUTTON || (x)==MENU_ABORTED_BUTTON) -#define MENU_ADD_BUTTON(x) ((x)==MENU_DONE || (x)==MENU_ABORTED?(x)+1:(x)) -#define MENU_ADD_BUTTON_IF(y,x) (y?MENU_ADD_BUTTON((x)):(x)) +#define IS_MENU_RETURN(x) ((x) >= MENU_DONE && (x) <= MENU_ABORTED_BUTTON) +#define IS_MENU_BUTTON(x) \ + ((x) == MENU_DONE_BUTTON || (x) == MENU_ABORTED_BUTTON) +#define MENU_ADD_BUTTON(x) \ + ((x) == MENU_DONE || (x) == MENU_ABORTED ? (x) + 1 : (x)) +#define MENU_ADD_BUTTON_IF(y, x) (y ? MENU_ADD_BUTTON((x)) : (x)) /* Types of events for the FUNCTION builtin */ #define MOTION 'm' @@ -310,10 +299,8 @@ typedef enum { #define DOUBLE_CLICK 'd' #define ONE_AND_A_HALF_CLICKS 'o' -MenuRoot *FollowMenuContinuations(MenuRoot *mr,MenuRoot **pmrPrior); -void AnimatedMoveOfWindow(Window w,int startX,int startY,int endX, int endY, - Bool fWarpPointerToo, int cusDelay, - float *ppctMovement ); +MenuRoot *FollowMenuContinuations(MenuRoot *mr, MenuRoot **pmrPrior); +void AnimatedMoveOfWindow(Window w, int startX, int startY, int endX, int endY, + Bool fWarpPointerToo, int cusDelay, float *ppctMovement); #endif /* _MENUS_ */ - Index: fvwm/fvwm/misc.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/misc.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/misc.c --- fvwm/fvwm/misc.c +++ fvwm/fvwm/misc.c @@ -12,30 +12,30 @@ * **************************************************************************/ +#include "misc.h" -#include "config.h" +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include +#include "config.h" #include "fvwm.h" -#include -#include #include "menus.h" -#include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" FvwmWindow *FocusOnNextTimeStamp = NULL; -char NoName[] = "Untitled"; /* name if no name in XA_WM_NAME */ -char NoClass[] = "NoClass"; /* Class if no res_class in class hints */ +char NoName[] = "Untitled"; /* name if no name in XA_WM_NAME */ +char NoClass[] = "NoClass"; /* Class if no res_class in class hints */ char NoResource[] = "NoResource"; /* Class if no res_name in class hints */ /************************************************************************** @@ -43,25 +43,24 @@ char NoResource[] = "NoResource"; /* Class if no res_name in class hints */ * Releases dynamically allocated space used to store window/icon names * **************************************************************************/ -void free_window_names (FvwmWindow *tmp, Bool nukename, Bool nukeicon) +void +free_window_names(FvwmWindow *tmp, Bool nukename, Bool nukeicon) { - if (!tmp) - return; - - if (nukename && tmp->name) - { - if (tmp->name != tmp->icon_name && tmp->name != NoName) - XFree(tmp->name); - tmp->name = NULL; - } - if (nukeicon && tmp->icon_name) - { - if (tmp->name != tmp->icon_name && tmp->icon_name != NoName) - XFree(tmp->icon_name); - tmp->icon_name = NULL; - } - - return; + if (!tmp) + return; + + if (nukename && tmp->name) { + if (tmp->name != tmp->icon_name && tmp->name != NoName) + XFree(tmp->name); + tmp->name = NULL; + } + if (nukeicon && tmp->icon_name) { + if (tmp->name != tmp->icon_name && tmp->icon_name != NoName) + XFree(tmp->icon_name); + tmp->icon_name = NULL; + } + + return; } /*************************************************************************** @@ -69,170 +68,153 @@ void free_window_names (FvwmWindow *tmp, Bool nukename, Bool nukeicon) * Handles destruction of a window * ****************************************************************************/ -void Destroy(FvwmWindow *Tmp_win) +void +Destroy(FvwmWindow *Tmp_win) { - int i; - extern FvwmWindow *ButtonWindow; - extern FvwmWindow *colormap_win; - extern Boolean PPosOverride; - - /* - * Warning, this is also called by HandleUnmapNotify; if it ever needs to - * look at the event, HandleUnmapNotify will have to mash the UnmapNotify - * into a DestroyNotify. - */ - if(!Tmp_win) - return; - - /* first of all, remove the window from the list of all windows! */ - /* - RBW - 11/13/1998 - new: have to unhook the stacking order chain also. - There's always a prev and next, since this is a ring anchored on - Scr.FvwmRoot - */ - Tmp_win->stack_prev->stack_next = Tmp_win->stack_next; - Tmp_win->stack_next->stack_prev = Tmp_win->stack_prev; - - Tmp_win->prev->next = Tmp_win->next; - if (Tmp_win->next != NULL) - Tmp_win->next->prev = Tmp_win->prev; - - XUnmapWindow(dpy, Tmp_win->frame); - - if(!PPosOverride) - XSync(dpy,0); - - if(Tmp_win == Scr.Hilite) - Scr.Hilite = NULL; - - BroadcastPacket(M_DESTROY_WINDOW, 3, - Tmp_win->w, Tmp_win->frame, (unsigned long)Tmp_win); - - if(Scr.PreviousFocus == Tmp_win) - Scr.PreviousFocus = NULL; - - if(ButtonWindow == Tmp_win) - ButtonWindow = NULL; - - if((Tmp_win == Scr.Focus)&&(Tmp_win->flags & ClickToFocus)) - { - if(Tmp_win->next) - { - HandleHardFocus(Tmp_win->next); - } - else - SetFocus(Scr.NoFocusWin, NULL,1); - } - else if(Scr.Focus == Tmp_win) - SetFocus(Scr.NoFocusWin, NULL,1); + int i; + extern FvwmWindow *ButtonWindow; + extern FvwmWindow *colormap_win; + extern Boolean PPosOverride; + + /* + * Warning, this is also called by HandleUnmapNotify; if it ever needs + * to look at the event, HandleUnmapNotify will have to mash the + * UnmapNotify into a DestroyNotify. + */ + if (!Tmp_win) + return; + + /* first of all, remove the window from the list of all windows! */ + /* + RBW - 11/13/1998 - new: have to unhook the stacking order chain + also. There's always a prev and next, since this is a ring anchored + on Scr.FvwmRoot + */ + Tmp_win->stack_prev->stack_next = Tmp_win->stack_next; + Tmp_win->stack_next->stack_prev = Tmp_win->stack_prev; + + Tmp_win->prev->next = Tmp_win->next; + if (Tmp_win->next != NULL) + Tmp_win->next->prev = Tmp_win->prev; + + XUnmapWindow(dpy, Tmp_win->frame); + + if (!PPosOverride) + XSync(dpy, 0); + + if (Tmp_win == Scr.Hilite) + Scr.Hilite = NULL; + + BroadcastPacket(M_DESTROY_WINDOW, 3, Tmp_win->w, Tmp_win->frame, + (unsigned long)Tmp_win); + + if (Scr.PreviousFocus == Tmp_win) + Scr.PreviousFocus = NULL; + + if (ButtonWindow == Tmp_win) + ButtonWindow = NULL; - if(Tmp_win == FocusOnNextTimeStamp) - FocusOnNextTimeStamp = NULL; + if ((Tmp_win == Scr.Focus) && (Tmp_win->flags & ClickToFocus)) { + if (Tmp_win->next) { + HandleHardFocus(Tmp_win->next); + } else + SetFocus(Scr.NoFocusWin, NULL, 1); + } else if (Scr.Focus == Tmp_win) + SetFocus(Scr.NoFocusWin, NULL, 1); - if(Tmp_win == Scr.Ungrabbed) - Scr.Ungrabbed = NULL; + if (Tmp_win == FocusOnNextTimeStamp) + FocusOnNextTimeStamp = NULL; - if(Tmp_win == Scr.pushed_window) - Scr.pushed_window = NULL; + if (Tmp_win == Scr.Ungrabbed) + Scr.Ungrabbed = NULL; - if(Tmp_win == colormap_win) - colormap_win = NULL; + if (Tmp_win == Scr.pushed_window) + Scr.pushed_window = NULL; - XDestroyWindow(dpy, Tmp_win->frame); - XDeleteContext(dpy, Tmp_win->frame, FvwmContext); + if (Tmp_win == colormap_win) + colormap_win = NULL; - XDestroyWindow(dpy, Tmp_win->Parent); + XDestroyWindow(dpy, Tmp_win->frame); + XDeleteContext(dpy, Tmp_win->frame, FvwmContext); - XDeleteContext(dpy, Tmp_win->Parent, FvwmContext); + XDestroyWindow(dpy, Tmp_win->Parent); - XDeleteContext(dpy, Tmp_win->w, FvwmContext); + XDeleteContext(dpy, Tmp_win->Parent, FvwmContext); - if ((Tmp_win->icon_w)&&(Tmp_win->flags & PIXMAP_OURS)) - { - XFreePixmap(dpy, Tmp_win->iconPixmap); - XFreePixmap(dpy, Tmp_win->icon_maskPixmap); - } + XDeleteContext(dpy, Tmp_win->w, FvwmContext); + + if ((Tmp_win->icon_w) && (Tmp_win->flags & PIXMAP_OURS)) { + XFreePixmap(dpy, Tmp_win->iconPixmap); + XFreePixmap(dpy, Tmp_win->icon_maskPixmap); + } #ifdef MINI_ICON - if (Tmp_win->mini_icon) - { - DestroyPicture(dpy, Tmp_win->mini_icon); - } + if (Tmp_win->mini_icon) { + DestroyPicture(dpy, Tmp_win->mini_icon); + } #endif - if (Tmp_win->icon_w) - { - XDestroyWindow(dpy, Tmp_win->icon_w); - XDeleteContext(dpy, Tmp_win->icon_w, FvwmContext); - } - if((Tmp_win->flags &ICON_OURS)&&(Tmp_win->icon_pixmap_w != None)) - XDestroyWindow(dpy, Tmp_win->icon_pixmap_w); - if(Tmp_win->icon_pixmap_w != None) - XDeleteContext(dpy, Tmp_win->icon_pixmap_w, FvwmContext); - - if (Tmp_win->flags & TITLE) - { - XDeleteContext(dpy, Tmp_win->title_w, FvwmContext); - for(i=0;ileft_w[i], FvwmContext); - for(i=0;iright_w[i] != None) - XDeleteContext(dpy, Tmp_win->right_w[i], FvwmContext); - } - if (Tmp_win->flags & BORDER) - { - for(i=0;i<4;i++) - XDeleteContext(dpy, Tmp_win->sides[i], FvwmContext); - for(i=0;i<4;i++) - XDeleteContext(dpy, Tmp_win->corners[i], FvwmContext); - } - - free_window_names (Tmp_win, True, True); - if (Tmp_win->wmhints) - XFree ((char *)Tmp_win->wmhints); - /* removing NoClass change for now... */ -#if 0 - if (Tmp_win->class.res_name) - XFree ((char *)Tmp_win->class.res_name); - if (Tmp_win->class.res_class) - XFree ((char *)Tmp_win->class.res_class); -#else - if (Tmp_win->class.res_name && Tmp_win->class.res_name != NoResource) - XFree ((char *)Tmp_win->class.res_name); - if (Tmp_win->class.res_class && Tmp_win->class.res_class != NoClass) - XFree ((char *)Tmp_win->class.res_class); -#endif /* 0 */ - if(Tmp_win->mwm_hints) - XFree((char *)Tmp_win->mwm_hints); - - if(Tmp_win->cmap_windows != (Window *)NULL) - XFree((void *)Tmp_win->cmap_windows); - - free((char *)Tmp_win); - - if(!PPosOverride) - XSync(dpy,0); - return; -} + if (Tmp_win->icon_w) { + XDestroyWindow(dpy, Tmp_win->icon_w); + XDeleteContext(dpy, Tmp_win->icon_w, FvwmContext); + } + if ((Tmp_win->flags & ICON_OURS) && (Tmp_win->icon_pixmap_w != None)) + XDestroyWindow(dpy, Tmp_win->icon_pixmap_w); + if (Tmp_win->icon_pixmap_w != None) + XDeleteContext(dpy, Tmp_win->icon_pixmap_w, FvwmContext); + + if (Tmp_win->flags & TITLE) { + XDeleteContext(dpy, Tmp_win->title_w, FvwmContext); + for (i = 0; i < Scr.nr_left_buttons; i++) + XDeleteContext(dpy, Tmp_win->left_w[i], FvwmContext); + for (i = 0; i < Scr.nr_right_buttons; i++) + if (Tmp_win->right_w[i] != None) + XDeleteContext( + dpy, Tmp_win->right_w[i], FvwmContext); + } + if (Tmp_win->flags & BORDER) { + for (i = 0; i < 4; i++) + XDeleteContext(dpy, Tmp_win->sides[i], FvwmContext); + for (i = 0; i < 4; i++) + XDeleteContext(dpy, Tmp_win->corners[i], FvwmContext); + } + free_window_names(Tmp_win, True, True); + if (Tmp_win->wmhints) + XFree((char *)Tmp_win->wmhints); + if (Tmp_win->class.res_name && Tmp_win->class.res_name != NoResource) + XFree((char *)Tmp_win->class.res_name); + if (Tmp_win->class.res_class && Tmp_win->class.res_class != NoClass) + XFree((char *)Tmp_win->class.res_class); + if (Tmp_win->mwm_hints) + XFree((char *)Tmp_win->mwm_hints); + if (Tmp_win->cmap_windows != (Window *)NULL) + XFree((void *)Tmp_win->cmap_windows); + + free((char *)Tmp_win); + + if (!PPosOverride) + XSync(dpy, 0); + return; +} /************************************************************************** * * Removes expose events for a specific window from the queue * *************************************************************************/ -int flush_expose (Window w) +int +flush_expose(Window w) { - XEvent dummy; - int i=0; + XEvent dummy; + int i = 0; - while (XCheckTypedWindowEvent (dpy, w, Expose, &dummy))i++; - return i; + while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy)) + i++; + return i; } - - /*********************************************************************** * * Procedure: @@ -241,190 +223,190 @@ int flush_expose (Window w) * Puts windows back where they were before fvwm took over * ************************************************************************/ -void RestoreWithdrawnLocation (FvwmWindow *tmp,Bool restart) +void +RestoreWithdrawnLocation(FvwmWindow *tmp, Bool restart) { - int a,b,w2,h2; - unsigned int mask; - XWindowChanges xwc; - - if(!tmp) - return; - - if (XGetGeometry (dpy, tmp->w, &JunkRoot, &xwc.x, &xwc.y, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth)) - { - XTranslateCoordinates(dpy,tmp->frame,Scr.Root,xwc.x,xwc.y, - &a,&b,&JunkChild); - xwc.x = a + tmp->xdiff; - xwc.y = b + tmp->ydiff; - xwc.border_width = tmp->old_bw; - mask = (CWX | CWY| CWBorderWidth); - - /* We can not assume that the window is currently on the screen. - * Although this is normally the case, it is not always true. The - * most common example is when the user does something in an - * application which will, after some amount of computational delay, - * cause the window to be unmapped, but then switches screens before - * this happens. The XTranslateCoordinates call above will set the - * window coordinates to either be larger than the screen, or negative. - * This will result in the window being placed in odd, or even - * unviewable locations when the window is remapped. The followin code - * forces the "relative" location to be within the bounds of the display. - * - * gpw -- 11/11/93 - * - * Unfortunately, this does horrendous things during re-starts, - * hence the "if(restart)" clause (RN) - * - * Also, fixed so that it only does this stuff if a window is more than - * half off the screen. (RN) - */ - - if(!restart) - { - /* Don't mess with it if its partially on the screen now */ - if((tmp->frame_x < 0)||(tmp->frame_y<0)|| - (tmp->frame_x >= Scr.MyDisplayWidth)|| - (tmp->frame_y >= Scr.MyDisplayHeight)) - { - w2 = (tmp->frame_width>>1); - h2 = (tmp->frame_height>>1); - if (( xwc.x < -w2) || (xwc.x > (Scr.MyDisplayWidth-w2 ))) - { - xwc.x = xwc.x % Scr.MyDisplayWidth; - if ( xwc.x < -w2 ) - xwc.x += Scr.MyDisplayWidth; + int a, b, w2, h2; + unsigned int mask; + XWindowChanges xwc; + + if (!tmp) + return; + + if (XGetGeometry(dpy, tmp->w, &JunkRoot, &xwc.x, &xwc.y, &JunkWidth, + &JunkHeight, &JunkBW, &JunkDepth)) { + XTranslateCoordinates(dpy, tmp->frame, Scr.Root, xwc.x, xwc.y, + &a, &b, &JunkChild); + xwc.x = a + tmp->xdiff; + xwc.y = b + tmp->ydiff; + xwc.border_width = tmp->old_bw; + mask = (CWX | CWY | CWBorderWidth); + + /* We can not assume that the window is currently on the screen. + * Although this is normally the case, it is not always true. + * The most common example is when the user does something in an + * application which will, after some amount of computational + * delay, cause the window to be unmapped, but then switches + * screens before this happens. The XTranslateCoordinates call + * above will set the window coordinates to either be larger + * than the screen, or negative. This will result in the window + * being placed in odd, or even unviewable locations when the + * window is remapped. The followin code forces the "relative" + * location to be within the bounds of the display. + * + * gpw -- 11/11/93 + * + * Unfortunately, this does horrendous things during re-starts, + * hence the "if(restart)" clause (RN) + * + * Also, fixed so that it only does this stuff if a window is + * more than half off the screen. (RN) + */ + + if (!restart) { + /* Don't mess with it if its partially on the screen now + */ + if ((tmp->frame_x < 0) || (tmp->frame_y < 0) || + (tmp->frame_x >= Scr.MyDisplayWidth) || + (tmp->frame_y >= Scr.MyDisplayHeight)) { + w2 = (tmp->frame_width >> 1); + h2 = (tmp->frame_height >> 1); + if ((xwc.x < -w2) || + (xwc.x > (Scr.MyDisplayWidth - w2))) { + xwc.x = xwc.x % Scr.MyDisplayWidth; + if (xwc.x < -w2) + xwc.x += Scr.MyDisplayWidth; + } + if ((xwc.y < -h2) || + (xwc.y > (Scr.MyDisplayHeight - h2))) { + xwc.y = xwc.y % Scr.MyDisplayHeight; + if (xwc.y < -h2) + xwc.y += Scr.MyDisplayHeight; + } + } } - if ((xwc.y < -h2) || (xwc.y > (Scr.MyDisplayHeight-h2 ))) - { - xwc.y = xwc.y % Scr.MyDisplayHeight; - if ( xwc.y < -h2 ) - xwc.y += Scr.MyDisplayHeight; + XReparentWindow(dpy, tmp->w, Scr.Root, xwc.x, xwc.y); + + if ((tmp->flags & ICONIFIED) && + (!(tmp->flags & SUPPRESSICON))) { + if (tmp->icon_w) + XUnmapWindow(dpy, tmp->icon_w); + if (tmp->icon_pixmap_w) + XUnmapWindow(dpy, tmp->icon_pixmap_w); } - } - } - XReparentWindow (dpy, tmp->w,Scr.Root,xwc.x,xwc.y); - - if((tmp->flags & ICONIFIED)&&(!(tmp->flags & SUPPRESSICON))) - { - if (tmp->icon_w) - XUnmapWindow(dpy, tmp->icon_w); - if (tmp->icon_pixmap_w) - XUnmapWindow(dpy, tmp->icon_pixmap_w); - } - XConfigureWindow (dpy, tmp->w, mask, &xwc); - if(!restart) - XSync(dpy,0); - } + XConfigureWindow(dpy, tmp->w, mask, &xwc); + if (!restart) + XSync(dpy, 0); + } } - /**************************************************************************** * * Records the time of the last processed event. Used in XSetInputFocus * ****************************************************************************/ -Time lastTimestamp = CurrentTime; /* until Xlib does this for us */ +Time lastTimestamp = CurrentTime; /* until Xlib does this for us */ -Bool StashEventTime (XEvent *ev) +Bool +StashEventTime(XEvent *ev) { - Time NewTimestamp = CurrentTime; - - switch (ev->type) - { - case KeyPress: - case KeyRelease: - NewTimestamp = ev->xkey.time; - break; - case ButtonPress: - case ButtonRelease: - NewTimestamp = ev->xbutton.time; - break; - case MotionNotify: - NewTimestamp = ev->xmotion.time; - break; - case EnterNotify: - case LeaveNotify: - NewTimestamp = ev->xcrossing.time; - break; - case PropertyNotify: - NewTimestamp = ev->xproperty.time; - break; - case SelectionClear: - NewTimestamp = ev->xselectionclear.time; - break; - case SelectionRequest: - NewTimestamp = ev->xselectionrequest.time; - break; - case SelectionNotify: - NewTimestamp = ev->xselection.time; - break; - default: - return False; - } - /* Only update is the new timestamp is later than the old one, or - * if the new one is from a time at least 30 seconds earlier than the - * old one (in which case the system clock may have changed) */ - if((NewTimestamp > lastTimestamp)||((lastTimestamp - NewTimestamp) > 30000)) - lastTimestamp = NewTimestamp; - if(FocusOnNextTimeStamp) - { - SetFocus(FocusOnNextTimeStamp->w,FocusOnNextTimeStamp,1); - FocusOnNextTimeStamp = NULL; - } - return True; + Time NewTimestamp = CurrentTime; + + switch (ev->type) { + case KeyPress: + case KeyRelease: + NewTimestamp = ev->xkey.time; + break; + case ButtonPress: + case ButtonRelease: + NewTimestamp = ev->xbutton.time; + break; + case MotionNotify: + NewTimestamp = ev->xmotion.time; + break; + case EnterNotify: + case LeaveNotify: + NewTimestamp = ev->xcrossing.time; + break; + case PropertyNotify: + NewTimestamp = ev->xproperty.time; + break; + case SelectionClear: + NewTimestamp = ev->xselectionclear.time; + break; + case SelectionRequest: + NewTimestamp = ev->xselectionrequest.time; + break; + case SelectionNotify: + NewTimestamp = ev->xselection.time; + break; + default: + return False; + } + /* Only update is the new timestamp is later than the old one, or + * if the new one is from a time at least 30 seconds earlier than the + * old one (in which case the system clock may have changed) */ + if ((NewTimestamp > lastTimestamp) || + ((lastTimestamp - NewTimestamp) > 30000)) + lastTimestamp = NewTimestamp; + if (FocusOnNextTimeStamp) { + SetFocus(FocusOnNextTimeStamp->w, FocusOnNextTimeStamp, 1); + FocusOnNextTimeStamp = NULL; + } + return True; } - -void ComputeActualPosition(int x,int y,int x_unit,int y_unit, - int width,int height,int *pfinalX, int *pfinalY) +void +ComputeActualPosition(int x, int y, int x_unit, int y_unit, int width, + int height, int *pfinalX, int *pfinalY) { - *pfinalX = x*x_unit/100; - *pfinalY = y*y_unit/100; - if (*pfinalX < 0) - *pfinalX += Scr.MyDisplayWidth - width; - if (*pfinalY < 0) - *pfinalY += Scr.MyDisplayHeight - height; + *pfinalX = x * x_unit / 100; + *pfinalY = y * y_unit / 100; + if (*pfinalX < 0) + *pfinalX += Scr.MyDisplayWidth - width; + if (*pfinalY < 0) + *pfinalY += Scr.MyDisplayHeight - height; } -int GetTwoArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit) +int +GetTwoArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit) { - *val1_unit = Scr.MyDisplayWidth; - *val2_unit = Scr.MyDisplayHeight; - return GetTwoPercentArguments(action, val1, val2, val1_unit, val2_unit); + *val1_unit = Scr.MyDisplayWidth; + *val2_unit = Scr.MyDisplayHeight; + return GetTwoPercentArguments(action, val1, val2, val1_unit, val2_unit); } /* The vars are named for the x-direction, but this is used for both x and y */ -static -int GetOnePositionArgument(char *s1,int x,int w,int *pFinalX,float factor, - int max) +static int +GetOnePositionArgument( + char *s1, int x, int w, int *pFinalX, float factor, int max) { - int val; - int cch = strlen(s1); - - if (cch == 0) - return 0; - if (s1[cch-1] == 'p') { - factor = 1; /* Use pixels, so don't multiply by factor */ - s1[cch-1] = '\0'; - } - if (strcmp(s1,"w") == 0) { - *pFinalX = x; - } else if (sscanf(s1,"w-%d",&val) == 1) { - *pFinalX = x-(val*factor); - } else if (sscanf(s1,"w+%d",&val) == 1) { - *pFinalX = x+(val*factor); - } else if (sscanf(s1,"-%d",&val) == 1) { - *pFinalX = max-w - val*factor; - } else if (sscanf(s1,"%d",&val) == 1) { - *pFinalX = val*factor; - } else { - return 0; - } - /* DEBUG_FPRINTF((stderr,"Got %d\n",*pFinalX)); */ - return 1; + int val; + int cch = strlen(s1); + + if (cch == 0) + return 0; + if (s1[cch - 1] == 'p') { + factor = 1; /* Use pixels, so don't multiply by factor */ + s1[cch - 1] = '\0'; + } + if (strcmp(s1, "w") == 0) { + *pFinalX = x; + } else if (sscanf(s1, "w-%d", &val) == 1) { + *pFinalX = x - (val * factor); + } else if (sscanf(s1, "w+%d", &val) == 1) { + *pFinalX = x + (val * factor); + } else if (sscanf(s1, "-%d", &val) == 1) { + *pFinalX = max - w - val * factor; + } else if (sscanf(s1, "%d", &val) == 1) { + *pFinalX = val * factor; + } else { + return 0; + } + /* DEBUG_FPRINTF((stderr,"Got %d\n",*pFinalX)); */ + return 1; } /* GetMoveArguments is used for Move & AnimatedMove @@ -436,32 +418,39 @@ int GetOnePositionArgument(char *s1,int x,int w,int *pFinalX,float factor, * w+5 w-10p Relative position, right 5%, up ten pixels * Returns 2 when x & y have parsed without error, 0 otherwise */ -int GetMoveArguments(char *action, int x, int y, int w, int h, - int *pFinalX, int *pFinalY, Bool *fWarp) +int +GetMoveArguments(char *action, int x, int y, int w, int h, int *pFinalX, + int *pFinalY, Bool *fWarp) { - char *s1, *s2, *warp; - int scrWidth = Scr.MyDisplayWidth; - int scrHeight = Scr.MyDisplayHeight; - int retval = 0; - - action = GetNextToken(action, &s1); - action = GetNextToken(action, &s2); - GetNextToken(action, &warp); - *fWarp = StrEquals(warp, "Warp"); - - if (s1 != NULL && s2 != NULL) { - if (GetOnePositionArgument(s1,x,w,pFinalX,(float)scrWidth/100,scrWidth) && - GetOnePositionArgument(s2,y,h,pFinalY,(float)scrHeight/100,scrHeight)) - retval = 2; - else - *fWarp = FALSE; /* make sure warping is off for interactive moves */ - } - - if (s1) free(s1); - if (s2) free(s2); - if (warp) free(warp); - - return retval; + char *s1, *s2, *warp; + int scrWidth = Scr.MyDisplayWidth; + int scrHeight = Scr.MyDisplayHeight; + int retval = 0; + + action = GetNextToken(action, &s1); + action = GetNextToken(action, &s2); + GetNextToken(action, &warp); + *fWarp = StrEquals(warp, "Warp"); + + if (s1 != NULL && s2 != NULL) { + if (GetOnePositionArgument( + s1, x, w, pFinalX, (float)scrWidth / 100, scrWidth) && + GetOnePositionArgument( + s2, y, h, pFinalY, (float)scrHeight / 100, scrHeight)) + retval = 2; + else + *fWarp = FALSE; /* make sure warping is off for + interactive moves */ + } + + if (s1) + free(s1); + if (s2) + free(s2); + if (warp) + free(warp); + + return retval; } /***************************************************************************** @@ -469,54 +458,54 @@ int GetMoveArguments(char *action, int x, int y, int w, int h, * * The vars are named for the x-direction, but this is used for both x and y *****************************************************************************/ -static -char *GetOneMenuPositionArgument(char *action,int x,int w,int *pFinalX, - float *width_factor) +static char * +GetOneMenuPositionArgument( + char *action, int x, int w, int *pFinalX, float *width_factor) { - char *token, *orgtoken, *naction; - char c; - int val; - int chars; - float factor = (float)w/100; - - naction = GetNextToken(action, &token); - if (token == NULL) - return action; - orgtoken = token; - *pFinalX = x; - *width_factor = 0; - if (sscanf(token,"o%d%n", &val, &chars) >= 1) { - token += chars; - *pFinalX += val*factor; - *width_factor -= val/100; - } else if (token[0] == 'c') { - token++; - *pFinalX += w/2; - *width_factor -= 0.5; - } - while (*token != 0) { - if (sscanf(token,"%d%n", &val, &chars) >= 1) { - token += chars; - if (sscanf(token,"%c", &c) == 1) { - if (c == 'm') { - token++; - *width_factor += val/100; - } else if (c == 'p') { - token++; - *pFinalX += val; - } else { - *pFinalX += val*factor; + char *token, *orgtoken, *naction; + char c; + int val; + int chars; + float factor = (float)w / 100; + + naction = GetNextToken(action, &token); + if (token == NULL) + return action; + orgtoken = token; + *pFinalX = x; + *width_factor = 0; + if (sscanf(token, "o%d%n", &val, &chars) >= 1) { + token += chars; + *pFinalX += val * factor; + *width_factor -= val / 100; + } else if (token[0] == 'c') { + token++; + *pFinalX += w / 2; + *width_factor -= 0.5; + } + while (*token != 0) { + if (sscanf(token, "%d%n", &val, &chars) >= 1) { + token += chars; + if (sscanf(token, "%c", &c) == 1) { + if (c == 'm') { + token++; + *width_factor += val / 100; + } else if (c == 'p') { + token++; + *pFinalX += val; + } else { + *pFinalX += val * factor; + } + } else { + *pFinalX += val * factor; + } + } else { + naction = action; + break; + } } - } else { - *pFinalX += val*factor; - } - } else { - naction = action; - break; - } - } - free(orgtoken); - return naction; + free(orgtoken); + return naction; } /***************************************************************************** @@ -530,182 +519,208 @@ char *GetOneMenuPositionArgument(char *action,int x,int w,int *pFinalX, * * See documentation for a detailed description. ****************************************************************************/ -char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, - MenuItem *mi, MenuOptions *pops) +char * +GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, MenuItem *mi, + MenuOptions *pops) { - char *tok = NULL, *naction = action, *taction; - int x, y, button, gflags; - unsigned int width, height; - Window context_window = 0; - Bool fHasContext, fUseItemOffset; - Bool fValidPosHints = fLastMenuPosHintsValid; - - fLastMenuPosHintsValid = FALSE; - if (pops == NULL) { - fvwm_msg(ERR,"GetMenuOptions","no MenuOptions pointer passed"); - return action; - } - - taction = action; - while (action != NULL) { - /* ^ just to be able to jump to end of loop without 'goto' */ - gflags = NoValue; - pops->flags.allflags = 0; - pops->pos_hints.fRelative = FALSE; - /* parse context argument (if present) */ - naction = GetNextToken(taction, &tok); - if (!tok) { - /* no context string */ - fHasContext = FALSE; - break; - } - - pops->pos_hints.fRelative = TRUE; /* set to FALSE for absolute hints! */ - fUseItemOffset = FALSE; - fHasContext = TRUE; - if (StrEquals(tok, "context")) { - if (mi && mi->mr) context_window = mi->mr->w; - else if (tmp_win) { - if (tmp_win->flags & ICONIFIED) context_window=tmp_win->icon_pixmap_w; - else context_window = tmp_win->frame; - } else context_window = w; - pops->pos_hints.fRelative = TRUE; - } else if (StrEquals(tok,"menu")) { - if (mi && mi->mr) context_window = mi->mr->w; - } else if (StrEquals(tok,"item")) { - if (mi && mi->mr) { - context_window = mi->mr->w; - fUseItemOffset = TRUE; - } - } else if (StrEquals(tok,"icon")) { - if (tmp_win) context_window = tmp_win->icon_pixmap_w; - } else if (StrEquals(tok,"window")) { - if (tmp_win) context_window = tmp_win->frame; - } else if (StrEquals(tok,"interior")) { - if (tmp_win) context_window = tmp_win->w; - } else if (StrEquals(tok,"title")) { - if (tmp_win) { - if (tmp_win->flags & ICONIFIED) context_window = tmp_win->icon_w; - else context_window = tmp_win->title_w; - } - } else if (strncasecmp(tok,"button",6) == 0) { - if (sscanf(&(tok[6]),"%d",&button) != 1 || - tok[6] == '+' || tok[6] == '-' || button < 0 || button > 9) { - fHasContext = FALSE; - } else if (tmp_win) { - if (button == 0) button = 10; - if (button & 0x01) context_window = tmp_win->left_w[button/2]; - else context_window = tmp_win->right_w[button/2-1]; - } - } else if (StrEquals(tok,"root")) { - context_window = Scr.Root; - pops->pos_hints.fRelative = FALSE; - } else if (StrEquals(tok,"mouse")) { - context_window = 0; - } else if (StrEquals(tok,"rectangle")) { - int flags; - /* parse the rectangle */ - free(tok); - naction = GetNextToken(taction, &tok); - if (tok == NULL) { - fvwm_msg(ERR,"GetMenuOptions","missing rectangle geometry"); - return action; - } - flags = XParseGeometry(tok, &x, &y, &width, &height); - if ((flags & AllValues) != AllValues) { - free(tok); - fvwm_msg(ERR,"GetMenuOptions","invalid rectangle geometry"); + char *tok = NULL, *naction = action, *taction; + int x, y, button, gflags; + unsigned int width, height; + Window context_window = 0; + Bool fHasContext, fUseItemOffset; + Bool fValidPosHints = fLastMenuPosHintsValid; + + fLastMenuPosHintsValid = FALSE; + if (pops == NULL) { + fvwm_msg( + ERR, "GetMenuOptions", "no MenuOptions pointer passed"); + return action; + } + + taction = action; + while (action != NULL) { + /* ^ just to be able to jump to end of loop without 'goto' */ + gflags = NoValue; + pops->flags.allflags = 0; + pops->pos_hints.fRelative = FALSE; + /* parse context argument (if present) */ + naction = GetNextToken(taction, &tok); + if (!tok) { + /* no context string */ + fHasContext = FALSE; + break; + } + + pops->pos_hints.fRelative = + TRUE; /* set to FALSE for absolute hints! */ + fUseItemOffset = FALSE; + fHasContext = TRUE; + if (StrEquals(tok, "context")) { + if (mi && mi->mr) + context_window = mi->mr->w; + else if (tmp_win) { + if (tmp_win->flags & ICONIFIED) + context_window = tmp_win->icon_pixmap_w; + else + context_window = tmp_win->frame; + } else + context_window = w; + pops->pos_hints.fRelative = TRUE; + } else if (StrEquals(tok, "menu")) { + if (mi && mi->mr) + context_window = mi->mr->w; + } else if (StrEquals(tok, "item")) { + if (mi && mi->mr) { + context_window = mi->mr->w; + fUseItemOffset = TRUE; + } + } else if (StrEquals(tok, "icon")) { + if (tmp_win) + context_window = tmp_win->icon_pixmap_w; + } else if (StrEquals(tok, "window")) { + if (tmp_win) + context_window = tmp_win->frame; + } else if (StrEquals(tok, "interior")) { + if (tmp_win) + context_window = tmp_win->w; + } else if (StrEquals(tok, "title")) { + if (tmp_win) { + if (tmp_win->flags & ICONIFIED) + context_window = tmp_win->icon_w; + else + context_window = tmp_win->title_w; + } + } else if (strncasecmp(tok, "button", 6) == 0) { + if (sscanf(&(tok[6]), "%d", &button) != 1 || + tok[6] == '+' || tok[6] == '-' || button < 0 || + button > 9) { + fHasContext = FALSE; + } else if (tmp_win) { + if (button == 0) + button = 10; + if (button & 0x01) + context_window = + tmp_win->left_w[button / 2]; + else + context_window = + tmp_win->right_w[button / 2 - 1]; + } + } else if (StrEquals(tok, "root")) { + context_window = Scr.Root; + pops->pos_hints.fRelative = FALSE; + } else if (StrEquals(tok, "mouse")) { + context_window = 0; + } else if (StrEquals(tok, "rectangle")) { + int flags; + /* parse the rectangle */ + free(tok); + naction = GetNextToken(taction, &tok); + if (tok == NULL) { + fvwm_msg(ERR, "GetMenuOptions", + "missing rectangle geometry"); + return action; + } + flags = XParseGeometry(tok, &x, &y, &width, &height); + if ((flags & AllValues) != AllValues) { + free(tok); + fvwm_msg(ERR, "GetMenuOptions", + "invalid rectangle geometry"); + return action; + } + if (flags & XNegative) + x = Scr.MyDisplayWidth - x - width; + if (flags & YNegative) + y = Scr.MyDisplayHeight - y - height; + pops->pos_hints.fRelative = FALSE; + } else if (StrEquals(tok, "this")) { + context_window = w; + } else { + /* no context string */ + fHasContext = FALSE; + } + + if (tok) + free(tok); + if (fHasContext) + taction = naction; + else + naction = action; + + if (!context_window || !fHasContext || + !XGetGeometry(dpy, context_window, &JunkRoot, &JunkX, + &JunkY, &width, &height, &JunkBW, &JunkDepth) || + !XTranslateCoordinates(dpy, context_window, Scr.Root, 0, 0, + &x, &y, &JunkChild)) { + /* now window or could not get geometry */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, + &y, &JunkX, &JunkY, &JunkMask); + width = height = 1; + } else if (fUseItemOffset) { + y += mi->y_offset; + height = mi->y_height; + } + + /* parse position arguments */ + taction = GetOneMenuPositionArgument(naction, x, width, + &(pops->pos_hints.x), &(pops->pos_hints.x_factor)); + naction = GetOneMenuPositionArgument(taction, y, height, + &(pops->pos_hints.y), &(pops->pos_hints.y_factor)); + if (naction == taction) { + /* argument is missing or invalid */ + if (fHasContext) + fvwm_msg(ERR, "GetMenuOptions", + "invalid position arguments"); + naction = action; + taction = action; + break; + } + taction = naction; + pops->flags.f.has_poshints = 1; + if (fValidPosHints == TRUE && + pops->pos_hints.fRelative == TRUE) { + pops->pos_hints = lastMenuPosHints; + } + /* we want to do this only once */ + break; + } /* while (1) */ + + if (!pops->flags.f.has_poshints && fValidPosHints) { + DBUG("GetMenuOptions", "recycling position hints"); + pops->flags.f.has_poshints = 1; + pops->pos_hints = lastMenuPosHints; + pops->pos_hints.fRelative = FALSE; + } + + action = naction; + /* parse additional options */ + while (naction && *naction) { + naction = GetNextToken(action, &tok); + if (!tok) + break; + if (StrEquals(tok, "WarpTitle")) { + pops->flags.f.warp_title = 1; + pops->flags.f.no_warp = 0; + } else if (StrEquals(tok, "NoWarp")) { + pops->flags.f.warp_title = 0; + pops->flags.f.no_warp = 1; + } else if (StrEquals(tok, "Fixed")) { + pops->flags.f.fixed = 1; + } else if (StrEquals(tok, "SelectInPlace")) { + pops->flags.f.select_in_place = 1; + } else if (StrEquals(tok, "SelectWarp")) { + pops->flags.f.select_warp = 1; + } else { + free(tok); + break; + } + action = naction; + free(tok); + } + if (!pops->flags.f.select_in_place) { + pops->flags.f.select_warp = 0; + } + return action; - } - if (flags & XNegative) x = Scr.MyDisplayWidth - x - width; - if (flags & YNegative) y = Scr.MyDisplayHeight - y - height; - pops->pos_hints.fRelative = FALSE; - } else if (StrEquals(tok,"this")) { - context_window = w; - } else { - /* no context string */ - fHasContext = FALSE; - } - - if (tok) - free(tok); - if (fHasContext) - taction = naction; - else naction = action; - - if (!context_window || !fHasContext - || !XGetGeometry(dpy, context_window, &JunkRoot, &JunkX, &JunkY, - &width, &height, &JunkBW, &JunkDepth) - || !XTranslateCoordinates( - dpy, context_window, Scr.Root, 0, 0, &x, &y, &JunkChild)) { - /* now window or could not get geometry */ - XQueryPointer(dpy,Scr.Root,&JunkRoot,&JunkChild,&x,&y,&JunkX,&JunkY, - &JunkMask); - width = height = 1; - } else if (fUseItemOffset) { - y += mi->y_offset; - height = mi->y_height; - } - - /* parse position arguments */ - taction = GetOneMenuPositionArgument( - naction, x, width, &(pops->pos_hints.x), &(pops->pos_hints.x_factor)); - naction = GetOneMenuPositionArgument( - taction, y, height, &(pops->pos_hints.y), &(pops->pos_hints.y_factor)); - if (naction == taction) { - /* argument is missing or invalid */ - if (fHasContext) - fvwm_msg(ERR,"GetMenuOptions","invalid position arguments"); - naction = action; - taction = action; - break; - } - taction = naction; - pops->flags.f.has_poshints = 1; - if (fValidPosHints == TRUE && pops->pos_hints.fRelative == TRUE) { - pops->pos_hints = lastMenuPosHints; - } - /* we want to do this only once */ - break; - } /* while (1) */ - - if (!pops->flags.f.has_poshints && fValidPosHints) { - DBUG("GetMenuOptions","recycling position hints"); - pops->flags.f.has_poshints = 1; - pops->pos_hints = lastMenuPosHints; - pops->pos_hints.fRelative = FALSE; - } - - action = naction; - /* parse additional options */ - while (naction && *naction) { - naction = GetNextToken(action, &tok); - if (!tok) - break; - if (StrEquals(tok, "WarpTitle")) { - pops->flags.f.warp_title = 1; - pops->flags.f.no_warp = 0; - } else if (StrEquals(tok, "NoWarp")) { - pops->flags.f.warp_title = 0; - pops->flags.f.no_warp = 1; - } else if (StrEquals(tok, "Fixed")) { - pops->flags.f.fixed = 1; - } else if (StrEquals(tok, "SelectInPlace")) { - pops->flags.f.select_in_place = 1; - } else if (StrEquals(tok, "SelectWarp")) { - pops->flags.f.select_warp = 1; - } else { - free (tok); - break; - } - action = naction; - free (tok); - } - if (!pops->flags.f.select_in_place) { - pops->flags.f.select_warp = 0; - } - - return action; } /*************************************************************************** @@ -716,31 +731,29 @@ char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, * Discard superflous button events during this wait period. * ***************************************************************************/ -void WaitForButtonsUp() +void +WaitForButtonsUp() { - Bool AllUp = False; - XEvent JunkEvent; - unsigned int mask; - - while(!AllUp) - { - XAllowEvents(dpy,ReplayPointer,CurrentTime); - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &JunkX, &JunkY, &mask); - - if((mask& - (Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask))==0) - AllUp = True; - } - XSync(dpy,0); - while(XCheckMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask|ButtonMotionMask, - &JunkEvent)) - { - StashEventTime (&JunkEvent); - XAllowEvents(dpy,ReplayPointer,CurrentTime); - } - + Bool AllUp = False; + XEvent JunkEvent; + unsigned int mask; + + while (!AllUp) { + XAllowEvents(dpy, ReplayPointer, CurrentTime); + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, + &JunkY, &JunkX, &JunkY, &mask); + + if ((mask & (Button1Mask | Button2Mask | Button3Mask | + Button4Mask | Button5Mask)) == 0) + AllUp = True; + } + XSync(dpy, 0); + while (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask, + &JunkEvent)) { + StashEventTime(&JunkEvent); + XAllowEvents(dpy, ReplayPointer, CurrentTime); + } } /***************************************************************************** @@ -748,70 +761,65 @@ void WaitForButtonsUp() * Grab the pointer and keyboard * ****************************************************************************/ -Bool GrabEm(int cursor) +Bool +GrabEm(int cursor) { - int i=0,val=0; - unsigned int mask; - - XSync(dpy,0); - /* move the keyboard focus prior to grabbing the pointer to - * eliminate the enterNotify and exitNotify events that go - * to the windows */ - if(Scr.PreviousFocus == NULL) - Scr.PreviousFocus = Scr.Focus; - SetFocus(Scr.NoFocusWin,NULL,0); - mask = ButtonPressMask|ButtonReleaseMask|ButtonMotionMask|PointerMotionMask - | EnterWindowMask | LeaveWindowMask; - while((i<1000)&&(val=XGrabPointer(dpy, Scr.Root, True, mask, - GrabModeAsync, GrabModeAsync, Scr.Root, - Scr.FvwmCursors[cursor], CurrentTime)!= - GrabSuccess)) - { - i++; - /* If you go too fast, other windows may not get a change to release - * any grab that they have. */ - usleep(1000); - } - - /* If we fall out of the loop without grabbing the pointer, its - time to give up */ - XSync(dpy,0); - if(val!=GrabSuccess) - { - return False; - } - return True; -} + int i = 0, val = 0; + unsigned int mask; + + XSync(dpy, 0); + /* move the keyboard focus prior to grabbing the pointer to + * eliminate the enterNotify and exitNotify events that go + * to the windows */ + if (Scr.PreviousFocus == NULL) + Scr.PreviousFocus = Scr.Focus; + SetFocus(Scr.NoFocusWin, NULL, 0); + mask = ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | + PointerMotionMask | EnterWindowMask | LeaveWindowMask; + while ((i < 1000) && + (val = XGrabPointer(dpy, Scr.Root, True, mask, GrabModeAsync, + GrabModeAsync, Scr.Root, Scr.FvwmCursors[cursor], + CurrentTime) != GrabSuccess)) { + i++; + /* If you go too fast, other windows may not get a change to + * release any grab that they have. */ + usleep(1000); + } + /* If we fall out of the loop without grabbing the pointer, its + time to give up */ + XSync(dpy, 0); + if (val != GrabSuccess) { + return False; + } + return True; +} /***************************************************************************** * * UnGrab the pointer and keyboard * ****************************************************************************/ -void UngrabEm() +void +UngrabEm() { - Window w; + Window w; - XSync(dpy,0); - XUngrabPointer(dpy,CurrentTime); + XSync(dpy, 0); + XUngrabPointer(dpy, CurrentTime); - if(Scr.PreviousFocus != NULL) - { - w = Scr.PreviousFocus->w; + if (Scr.PreviousFocus != NULL) { + w = Scr.PreviousFocus->w; - /* if the window still exists, focus on it */ - if (w) - { - SetFocus(w,Scr.PreviousFocus,0); + /* if the window still exists, focus on it */ + if (w) { + SetFocus(w, Scr.PreviousFocus, 0); + } + Scr.PreviousFocus = NULL; } - Scr.PreviousFocus = NULL; - } - XSync(dpy,0); + XSync(dpy, 0); } - - /**************************************************************************** * * Keeps the "StaysOnTop" windows on the top of the pile. @@ -820,52 +828,47 @@ void UngrabEm() * obscured by other OnTop windows, which need to be raised here. * ****************************************************************************/ -void KeepOnTop() +void +KeepOnTop() { - FvwmWindow *t; - - /* flag that on-top windows should be re-raised */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if((t->flags & ONTOP)&&!(t->flags & VISIBLE)) - { - RaiseWindow(t); - t->flags &= ~RAISED; + FvwmWindow *t; + + /* flag that on-top windows should be re-raised */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t->flags & ONTOP) && !(t->flags & VISIBLE)) { + RaiseWindow(t); + t->flags &= ~RAISED; + } else + t->flags |= RAISED; } - else - t->flags |= RAISED; - } } - /************************************************************************** * * Unmaps a window on transition to a new desktop * *************************************************************************/ -void UnmapIt(FvwmWindow *t) +void +UnmapIt(FvwmWindow *t) { - XWindowAttributes winattrs; - unsigned long eventMask; - /* - * Prevent the receipt of an UnmapNotify, since that would - * cause a transition to the Withdrawn state. - */ - XGetWindowAttributes(dpy, t->w, &winattrs); - eventMask = winattrs.your_event_mask; - XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask); - if(t->flags & ICONIFIED) - { - if(t->icon_pixmap_w != None) - XUnmapWindow(dpy,t->icon_pixmap_w); - if(t->icon_w != None) - XUnmapWindow(dpy,t->icon_w); - } - else if(t->flags & (MAPPED|MAP_PENDING)) - { - XUnmapWindow(dpy,t->frame); - } - XSelectInput(dpy, t->w, eventMask); + XWindowAttributes winattrs; + unsigned long eventMask; + /* + * Prevent the receipt of an UnmapNotify, since that would + * cause a transition to the Withdrawn state. + */ + XGetWindowAttributes(dpy, t->w, &winattrs); + eventMask = winattrs.your_event_mask; + XSelectInput(dpy, t->w, eventMask & ~StructureNotifyMask); + if (t->flags & ICONIFIED) { + if (t->icon_pixmap_w != None) + XUnmapWindow(dpy, t->icon_pixmap_w); + if (t->icon_w != None) + XUnmapWindow(dpy, t->icon_w); + } else if (t->flags & (MAPPED | MAP_PENDING)) { + XUnmapWindow(dpy, t->frame); + } + XSelectInput(dpy, t->w, eventMask); } /************************************************************************** @@ -873,236 +876,246 @@ void UnmapIt(FvwmWindow *t) * Maps a window on transition to a new desktop * *************************************************************************/ -void MapIt(FvwmWindow *t) +void +MapIt(FvwmWindow *t) { - if(t->flags & ICONIFIED) - { - if(t->icon_pixmap_w != None) - XMapWindow(dpy,t->icon_pixmap_w); - if(t->icon_w != None) - XMapWindow(dpy,t->icon_w); - } - else if(t->flags & MAPPED) - { - XMapWindow(dpy,t->frame); - t->flags |= MAP_PENDING; - XMapWindow(dpy, t->Parent); - } + if (t->flags & ICONIFIED) { + if (t->icon_pixmap_w != None) + XMapWindow(dpy, t->icon_pixmap_w); + if (t->icon_w != None) + XMapWindow(dpy, t->icon_w); + } else if (t->flags & MAPPED) { + XMapWindow(dpy, t->frame); + t->flags |= MAP_PENDING; + XMapWindow(dpy, t->Parent); + } } +Bool +IsTransientDescendantOf(FvwmWindow *t, FvwmWindow *ancestor) +{ + FvwmWindow *p; + Window tw; + + if (t == ancestor) + return False; + if ((t->flags & TRANSIENT) == 0) + return False; + tw = t->transientfor; + while (tw != None && tw != Scr.Root) { + if (tw == ancestor->w) + return True; + for (p = Scr.FvwmRoot.next; p != NULL; p = p->next) { + if (p->w == tw) { + if ((p->flags & TRANSIENT) == 0) + return False; + tw = p->transientfor; + break; + } + } + if (p == NULL) + return False; + } + return False; +} - - -void RaiseWindow(FvwmWindow *t) +void +RaiseWindow(FvwmWindow *t) { - FvwmWindow *t2; - int count, i; - Window *wins; - XWindowChanges changes; - FvwmWindow *t1; - FvwmWindow **FvwmTopwins = NULL; - int j, count2; - - - memset((void *) &changes, '\0', sizeof(changes)); - /* raise the target, at least */ - count = 1; - BroadcastPacket(M_RAISE_WINDOW, 3, t->w, t->frame, (unsigned long)t); - - for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; t2 = t2->stack_next) - { - if(t2->flags & ONTOP) - count++; - if((t2->flags & TRANSIENT) &&(t2->transientfor == t->w)&& - (t2 != t)) - { - count++; - BroadcastPacket(M_RAISE_WINDOW, 3, - t2->w, t2->frame,(unsigned long) t2); - if ((t2->flags & ICONIFIED)&&(!(t2->flags & SUPPRESSICON))) - { - count += 2; - } + FvwmWindow *t2; + int count, i; + Window *wins; + XWindowChanges changes; + FvwmWindow *t1; + FvwmWindow **FvwmTopwins = NULL; + int j, count2; + + memset((void *)&changes, '\0', sizeof(changes)); + /* raise the target, at least */ + count = 1; + BroadcastPacket(M_RAISE_WINDOW, 3, t->w, t->frame, (unsigned long)t); + + for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; + t2 = t2->stack_next) { + if (t2->flags & ONTOP) + count++; + if (IsTransientDescendantOf(t2, t)) { + count++; + BroadcastPacket(M_RAISE_WINDOW, 3, t2->w, t2->frame, + (unsigned long)t2); + if ((t2->flags & ICONIFIED) && + (!(t2->flags & SUPPRESSICON))) { + count += 2; + } + } } - } - if ((t->flags & ICONIFIED)&&(!(t->flags & SUPPRESSICON))) - { - count += 2; - } - - wins = (Window *)safemalloc(count*sizeof(Window)); - FvwmTopwins = (FvwmWindow **)safemalloc(count*sizeof(FvwmWindow)); - - i=0; - j = 0; - count2 = 0; - - /* ONTOP windows on top */ - for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; t2 = t2->stack_next) - { - if(t2->flags & ONTOP) - { - BroadcastPacket(M_RAISE_WINDOW, 3, - t2->w, t2->frame, (unsigned long) t2); - wins[i++] = t2->frame; - FvwmTopwins[j++] = t2; + if ((t->flags & ICONIFIED) && (!(t->flags & SUPPRESSICON))) { + count += 2; } - } - /* now raise transients */ + wins = (Window *)xmalloc(count * sizeof(Window)); + FvwmTopwins = (FvwmWindow **)xmalloc(count * sizeof(FvwmWindow)); + + i = 0; + j = 0; + count2 = 0; + + /* ONTOP windows on top */ + for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; + t2 = t2->stack_next) { + if (t2->flags & ONTOP) { + BroadcastPacket(M_RAISE_WINDOW, 3, t2->w, t2->frame, + (unsigned long)t2); + wins[i++] = t2->frame; + FvwmTopwins[j++] = t2; + } + } + + /* now raise transients */ #ifndef DONT_RAISE_TRANSIENTS - for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; t2 = t2->stack_next) - { - if((t2->flags & TRANSIENT) && - (t2->transientfor == t->w) && - (t2 != t) && - (!(t2->flags & ONTOP))) - { - wins[i++] = t2->frame; - FvwmTopwins[j++] = t2; - if ((t2->flags & ICONIFIED)&&(!(t2->flags & SUPPRESSICON))) - { - if(!(t2->flags & NOICON_TITLE)) - wins[i++] = t2->icon_w; - if(!(t2->icon_pixmap_w)) - wins[i++] = t2->icon_pixmap_w; - } - } - } + for (t2 = Scr.FvwmRoot.stack_next; t2 != &Scr.FvwmRoot; + t2 = t2->stack_next) { + if (IsTransientDescendantOf(t2, t) && + (!(t2->flags & ONTOP))) { + wins[i++] = t2->frame; + FvwmTopwins[j++] = t2; + if ((t2->flags & ICONIFIED) && + (!(t2->flags & SUPPRESSICON))) { + if (!(t2->flags & NOICON_TITLE)) + wins[i++] = t2->icon_w; + if (!(t2->icon_pixmap_w)) + wins[i++] = t2->icon_pixmap_w; + } + } + } #endif - if ((t->flags & ICONIFIED)&&(!(t->flags & SUPPRESSICON))) - { - if(!(t->flags & NOICON_TITLE)) - wins[i++] = t->icon_w; - if (t->icon_pixmap_w) - wins[i++] = t->icon_pixmap_w; - } - if(!(t->flags & ONTOP)) - { - wins[i++] = t->frame; - FvwmTopwins[j++] = t; - Scr.LastWindowRaised = t; - } - count2 = j; - - if(i > 0) - { -/* XRaiseWindow(dpy,wins[0]); */ - /* - clasen@mathematik.uni-freiburg.de - 01/01/1999 - - simply calling XRaiseWindow(dpy,wins[0]); here will put StaysOnTop - windows over override_redirect windows like FvwmPager ballon_win or - Motif menus. Instead raise wins[0] only above the topmost window - which is managed by us. - */ - if (wins[0] != Scr.FvwmRoot.stack_next->frame && wins[0] != Scr.FvwmRoot.stack_next->icon_w && wins[0] != Scr.FvwmRoot.stack_next->icon_pixmap_w) - { - if (Scr.FvwmRoot.stack_next->flags & ICONIFIED) - { - /* - RBW - use the icon window or pixmap if there is one; but - there may not be (NoIconTitle or NoIcon) -- - */ - if (Scr.FvwmRoot.stack_next->icon_w) - { - changes.sibling = Scr.FvwmRoot.stack_next->icon_w; - } - else if (Scr.FvwmRoot.stack_next->icon_pixmap_w) - { - changes.sibling = Scr.FvwmRoot.stack_next->icon_pixmap_w; - } - else - { - changes.sibling = Scr.FvwmRoot.stack_next->frame; - } - } - else - { - changes.sibling = Scr.FvwmRoot.stack_next->frame; - } - changes.stack_mode = Above; - XConfigureWindow(dpy, wins[0], (CWSibling|CWStackMode), &changes); - } - - - /* - RBW - 01/05/1998 - move all raised windows to front of stacking - order chain. - */ - j = 0; - t2 = &Scr.FvwmRoot; - while (j < count2) - { - t1 = FvwmTopwins[j]; - if (t1 != t2->stack_next) - { - t1->stack_prev->stack_next = t1->stack_next; /* Pluck from chain. */ - t1->stack_next->stack_prev = t1->stack_prev; - t1->stack_next = t2->stack_next; /* Set new pointers. */ - t1->stack_prev = t2->stack_next->stack_prev; - t2->stack_next->stack_prev = t1; /* Insert in new position in chain. */ - t2->stack_next = t1; - } - j++; - if (t2->stack_next != &Scr.FvwmRoot) - { - t2 = t2->stack_next; - } - } - - } - - XRestackWindows(dpy,wins,i); - free(wins); - if (FvwmTopwins) free(FvwmTopwins); - raisePanFrames(); -} + if ((t->flags & ICONIFIED) && (!(t->flags & SUPPRESSICON))) { + if (!(t->flags & NOICON_TITLE)) + wins[i++] = t->icon_w; + if (t->icon_pixmap_w) + wins[i++] = t->icon_pixmap_w; + } + if (!(t->flags & ONTOP)) { + wins[i++] = t->frame; + FvwmTopwins[j++] = t; + Scr.LastWindowRaised = t; + } + count2 = j; + + if (i > 0) { + /* XRaiseWindow(dpy,wins[0]); */ + /* + clasen@mathematik.uni-freiburg.de - 01/01/1999 - + Simply calling XRaiseWindow(dpy,wins[0]); here will put + StaysOnTop windows over override_redirect windows like + FvwmPager ballon_win or Motif menus. Instead raise wins[0] + only above the topmost window which is managed by us. + */ + if (wins[0] != Scr.FvwmRoot.stack_next->frame && + wins[0] != Scr.FvwmRoot.stack_next->icon_w && + wins[0] != Scr.FvwmRoot.stack_next->icon_pixmap_w) { + if (Scr.FvwmRoot.stack_next->flags & ICONIFIED) { + /* + RBW - use the icon window or pixmap if + there is one; but there may not be + (NoIconTitle or NoIcon) -- + */ + if (Scr.FvwmRoot.stack_next->icon_w) { + changes.sibling = + Scr.FvwmRoot.stack_next->icon_w; + } else if (Scr.FvwmRoot.stack_next + ->icon_pixmap_w) { + changes.sibling = + Scr.FvwmRoot.stack_next + ->icon_pixmap_w; + } else { + changes.sibling = + Scr.FvwmRoot.stack_next->frame; + } + } else { + changes.sibling = + Scr.FvwmRoot.stack_next->frame; + } + changes.stack_mode = Above; + XConfigureWindow( + dpy, wins[0], (CWSibling | CWStackMode), &changes); + } + /* + RBW - 01/05/1998 - move all raised windows to front of + stacking order chain. + */ + j = 0; + t2 = &Scr.FvwmRoot; + while (j < count2) { + t1 = FvwmTopwins[j]; + if (t1 != t2->stack_next) { + t1->stack_prev->stack_next = + t1->stack_next; /* Pluck from chain. */ + t1->stack_next->stack_prev = t1->stack_prev; + t1->stack_next = + t2->stack_next; /* Set new pointers. */ + t1->stack_prev = t2->stack_next->stack_prev; + t2->stack_next->stack_prev = + t1; /* Insert in new position in chain. */ + t2->stack_next = t1; + } + j++; + if (t2->stack_next != &Scr.FvwmRoot) { + t2 = t2->stack_next; + } + } + } -void LowerWindow(FvwmWindow *t) -{ - XLowerWindow(dpy,t->frame); - - BroadcastPacket(M_LOWER_WINDOW, 3, t->w, t->frame, (unsigned long)t); - - if((t->flags & ICONIFIED)&&(!(t->flags & SUPPRESSICON))) - { - XLowerWindow(dpy, t->icon_w); - XLowerWindow(dpy, t->icon_pixmap_w); - } - Scr.LastWindowRaised = (FvwmWindow *)0; - /* - RBW - 11/13/1998 - new: maintain the stacking order chain. - */ - t->stack_prev->stack_next = t->stack_next; /* Pluck from chain. */ - t->stack_next->stack_prev = t->stack_prev; - t->stack_next = Scr.FvwmRoot.stack_prev->stack_next; /* Set new pointers. */ - t->stack_prev = Scr.FvwmRoot.stack_prev; - Scr.FvwmRoot.stack_prev->stack_next = t; /* Insert at end of chain. */ - Scr.FvwmRoot.stack_prev = t; + XRestackWindows(dpy, wins, i); + free(wins); + if (FvwmTopwins) + free(FvwmTopwins); + raisePanFrames(); } - -void HandleHardFocus(FvwmWindow *t) +void +LowerWindow(FvwmWindow *t) { - int x,y; - - FocusOnNextTimeStamp = t; - Scr.Focus = NULL; - /* Do something to guarantee a new time stamp! */ - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &x, &y, &JunkMask); - GrabEm(WAIT); - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, - x + 2,y+2); - XSync(dpy,0); - XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, - Scr.MyDisplayHeight, - x ,y); - UngrabEm(); + XLowerWindow(dpy, t->frame); + + BroadcastPacket(M_LOWER_WINDOW, 3, t->w, t->frame, (unsigned long)t); + + if ((t->flags & ICONIFIED) && (!(t->flags & SUPPRESSICON))) { + XLowerWindow(dpy, t->icon_w); + XLowerWindow(dpy, t->icon_pixmap_w); + } + Scr.LastWindowRaised = (FvwmWindow *)0; + /* + RBW - 11/13/1998 - new: maintain the stacking order chain. + */ + t->stack_prev->stack_next = t->stack_next; /* Pluck from chain. */ + t->stack_next->stack_prev = t->stack_prev; + t->stack_next = + Scr.FvwmRoot.stack_prev->stack_next; /* Set new pointers. */ + t->stack_prev = Scr.FvwmRoot.stack_prev; + Scr.FvwmRoot.stack_prev->stack_next = t; /* Insert at end of chain. */ + Scr.FvwmRoot.stack_prev = t; } +void +HandleHardFocus(FvwmWindow *t) +{ + int x, y; + + FocusOnNextTimeStamp = t; + Scr.Focus = NULL; + /* Do something to guarantee a new time stamp! */ + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY, &x, + &y, &JunkMask); + GrabEm(WAIT); + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x + 2, y + 2); + XSync(dpy, 0); + XWarpPointer(dpy, Scr.Root, Scr.Root, 0, 0, Scr.MyDisplayWidth, + Scr.MyDisplayHeight, x, y); + UngrabEm(); +} /* ** fvwm_msg: used to send output from fvwm to files and or stderr/stdout @@ -1110,51 +1123,48 @@ void HandleHardFocus(FvwmWindow *t) ** type -> DBG == Debug, ERR == Error, INFO == Information, WARN == Warning ** id -> name of function, or other identifier */ -void fvwm_msg(int type,char *id,char *msg,...) +void +fvwm_msg(int type, const char *id, const char *msg, ...) { - char *typestr; - va_list args1, args2; - - switch(type) - { - case DBG: -#if 0 - if (!debugging) - return; -#endif /* 0 */ - typestr="<>"; - break; - case ERR: - typestr="<>"; - break; - case WARN: - typestr="<>"; - break; - case INFO: - default: - typestr=""; - break; - } - - va_start(args1,msg); - va_copy(args2,args1); - - fprintf(stderr,"[FVWM][%s]: %s ",id,typestr); - vfprintf(stderr, msg, args1); - fprintf(stderr,"\n"); - - if (type == ERR) - { - char tmp[1024]; /* I hate to use a fixed length but this will do for now */ - snprintf(tmp, sizeof(tmp), "[FVWM][%s]: %s ",id,typestr); - vsnprintf(tmp+strlen(tmp), sizeof(tmp)-strlen(tmp), msg, args2); - tmp[strlen(tmp)+1]='\0'; - tmp[strlen(tmp)]='\n'; - BroadcastName(M_ERROR,0,0,0,tmp); - } - - va_end(args1); - va_end(args2); + char *typestr; + va_list args1, args2; + + switch (type) { + case DBG: + typestr = "<>"; + break; + case ERR: + typestr = "<>"; + break; + case WARN: + typestr = "<>"; + break; + case INFO: + default: + typestr = ""; + break; + } + + va_start(args1, msg); + va_copy(args2, args1); + + fprintf(stderr, "[FVWM][%s]: %s ", id, typestr); + vfprintf(stderr, msg, args1); + fprintf(stderr, "\n"); + + if (type == ERR) { + char tmp[1024]; /* I hate to use a fixed length but this will do + for now */ + snprintf(tmp, sizeof(tmp), "[FVWM][%s]: %s ", id, typestr); + vsnprintf( + tmp + strlen(tmp), sizeof(tmp) - strlen(tmp), msg, args2); + tmp[strlen(tmp) + 1] = '\0'; + tmp[strlen(tmp)] = '\n'; + BroadcastName(M_ERROR, 0, 0, 0, tmp); + } + + va_end(args1); + va_end(args2); } /* fvwm_msg */ /* CoerceEnterNotifyOnCurrentWindow() @@ -1167,18 +1177,18 @@ void fvwm_msg(int type,char *id,char *msg,...) void CoerceEnterNotifyOnCurrentWindow() { - extern FvwmWindow *Tmp_win; /* from events.c */ - Window child, root; - int root_x, root_y; - int win_x, win_y; - Bool f = XQueryPointer(dpy, Scr.Root, &root, - &child, &root_x, &root_y, &win_x, &win_y, &JunkMask); - if (f && child != None) { - Event.xany.window = child; - if (XFindContext(dpy, child, FvwmContext, (caddr_t *) &Tmp_win) == -XCNOENT) - Tmp_win = NULL; - HandleEnterNotify(); - Tmp_win = None; - } + extern FvwmWindow *Tmp_win; /* from events.c */ + Window child, root; + int root_x, root_y; + int win_x, win_y; + Bool f = XQueryPointer(dpy, Scr.Root, &root, &child, &root_x, &root_y, + &win_x, &win_y, &JunkMask); + if (f && child != None) { + Event.xany.window = child; + if (XFindContext(dpy, child, FvwmContext, + (caddr_t *)&Tmp_win) == XCNOENT) + Tmp_win = NULL; + HandleEnterNotify(); + Tmp_win = None; + } } Index: fvwm/fvwm/misc.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/misc.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/misc.h --- fvwm/fvwm/misc.h +++ fvwm/fvwm/misc.h @@ -2,9 +2,11 @@ #define MISC_H #include +#include + +#include "../libs/fvwmlib.h" #include "defaults.h" #include "menus.h" -#include "../libs/fvwmlib.h" /************************************************************************ * ReapChildren - wait() for all dead child processes @@ -12,121 +14,107 @@ #include #include -#if HAVE_WAITPID -# define ReapChildren() while ((waitpid(-1, NULL, WNOHANG)) > 0); -#elif HAVE_WAIT3 -# define ReapChildren() while ((wait3(NULL, WNOHANG, NULL)) > 0); -#else -# error One of waitpid or wait3 is needed. -#endif +#define ReapChildren() \ + while ((waitpid(-1, NULL, WNOHANG)) > 0) \ + ; -typedef struct name_list_struct -{ - struct name_list_struct *next; /* pointer to the next name */ - char *name; /* the name of the window */ - char *value; /* icon name */ +typedef struct name_list_struct { + struct name_list_struct *next; /* pointer to the next name */ + char *name; /* the name of the window */ + char *value; /* icon name */ #ifdef MINI_ICONS - char *mini_value; /* mini icon name */ + char *mini_value; /* mini icon name */ #endif #ifdef USEDECOR - char *Decor; + char *Decor; #endif - int Desk; /* Desktop number */ -/* RBW - 11/02/1998 - page x,y numbers */ - int PageX; - int PageY; -/**/ - unsigned long on_flags; - unsigned long off_flags; - int border_width; - int resize_width; - char *ForeColor; - char *BackColor; - icon_boxes *IconBoxes; /* pointer to iconbox(s) */ - unsigned long on_buttons; - unsigned long off_buttons; - + int Desk; /* Desktop number */ + /* RBW - 11/02/1998 - page x,y numbers */ + int PageX; + int PageY; + /**/ + unsigned long on_flags; + unsigned long off_flags; + int border_width; + int resize_width; + char *ForeColor; + char *BackColor; + icon_boxes *IconBoxes; /* pointer to iconbox(s) */ + unsigned long on_buttons; + unsigned long off_buttons; } name_list; /* used for parsing configuration */ -struct config -{ - char *keyword; -#ifdef __STDC__ - void (*action)(char *, FILE *, char **, int *); -#else - void (*action)(); -#endif - char **arg; - int *arg2; +struct config { + char *keyword; + void (*action)(char *, FILE *, char **, int *); + char **arg; + int *arg2; }; /* used for parsing commands*/ -struct functions -{ - char *keyword; -#ifdef __STDC__ - void (*action)(XEvent *,Window,FvwmWindow *, unsigned long,char *, int *); -#else - void (*action)(); -#endif - short func_type; - Bool func_needs_window; +struct functions { + char *keyword; + void (*action)(XEvent *, Window, FvwmWindow *, unsigned long, char *, + int *); + short func_type; + Bool func_needs_window; }; /* values for name_list flags */ /* The first 13 items are mapped directly into the FvwmWindow structures * flag value, so they MUST correspond to the first 13 entries in fvwm.h */ -#define START_ICONIC_FLAG (1<<0) -#define STAYSONTOP_FLAG (1<<1) -#define STICKY_FLAG (1<<2) -#define LISTSKIP_FLAG (1<<3) -#define SUPPRESSICON_FLAG (1<<4) -#define NOICON_TITLE_FLAG (1<<5) -#define LENIENCE_FLAG (1<<6) -#define STICKY_ICON_FLAG (1<<7) -#define CIRCULATE_SKIP_ICON_FLAG (1<<8) -#define CIRCULATESKIP_FLAG (1<<9) -#define CLICK_FOCUS_FLAG (1<<10) -#define SLOPPY_FOCUS_FLAG (1<<11) -#define SHOW_MAPPING (1<<12) - -#define NOTITLE_FLAG (1<<13) -#define NOBORDER_FLAG (1<<14) -#define ICON_FLAG (1<<15) -#define STARTSONDESK_FLAG (1<<16) -#define BW_FLAG (1<<17) -#define NOBW_FLAG (1<<18) -#define FORE_COLOR_FLAG (1<<19) -#define BACK_COLOR_FLAG (1<<20) -#define RANDOM_PLACE_FLAG (1<<21) -#define SMART_PLACE_FLAG (1<<22) -#define MWM_BUTTON_FLAG (1<<23) -#define MWM_DECOR_FLAG (1<<24) -#define MWM_FUNCTIONS_FLAG (1<<25) -#define MWM_OVERRIDE_FLAG (1<<26) -#define MWM_BORDER_FLAG (1<<27) -#define DECORATE_TRANSIENT_FLAG (1<<28) -#define NO_PPOSITION_FLAG (1<<29) -#define OL_DECOR_FLAG (1<<30) +#define START_ICONIC_FLAG (1 << 0) +#define STAYSONTOP_FLAG (1 << 1) +#define STICKY_FLAG (1 << 2) +#define LISTSKIP_FLAG (1 << 3) +#define SUPPRESSICON_FLAG (1 << 4) +#define NOICON_TITLE_FLAG (1 << 5) +#define LENIENCE_FLAG (1 << 6) +#define STICKY_ICON_FLAG (1 << 7) +#define CIRCULATE_SKIP_ICON_FLAG (1 << 8) +#define CIRCULATESKIP_FLAG (1 << 9) +#define CLICK_FOCUS_FLAG (1 << 10) +#define SLOPPY_FOCUS_FLAG (1 << 11) +#define SHOW_MAPPING (1 << 12) + +#define NOTITLE_FLAG (1 << 13) +#define NOBORDER_FLAG (1 << 14) +#define ICON_FLAG (1 << 15) +#define STARTSONDESK_FLAG (1 << 16) +#define BW_FLAG (1 << 17) +#define NOBW_FLAG (1 << 18) +#define FORE_COLOR_FLAG (1 << 19) +#define BACK_COLOR_FLAG (1 << 20) +#define RANDOM_PLACE_FLAG (1 << 21) +#define SMART_PLACE_FLAG (1 << 22) +#define MWM_BUTTON_FLAG (1 << 23) +#define MWM_DECOR_FLAG (1 << 24) +#define MWM_FUNCTIONS_FLAG (1 << 25) +#define MWM_OVERRIDE_FLAG (1 << 26) +#define MWM_BORDER_FLAG (1 << 27) +#define DECORATE_TRANSIENT_FLAG (1 << 28) +#define NO_PPOSITION_FLAG (1 << 29) +#define OL_DECOR_FLAG (1 << 30) #ifdef MINI_ICONS -#define MINIICON_FLAG (1<<31) +#define MINIICON_FLAG (1 << 31) #endif /* some fancy font handling stuff */ -#define NewFontAndColor(newfont,color,backcolor) {\ - Globalgcv.font = newfont;\ - Globalgcv.foreground = color;\ - Globalgcv.background = backcolor;\ - Globalgcm = GCFont | GCForeground | GCBackground; \ - XChangeGC(dpy,Scr.ScratchGC3,Globalgcm,&Globalgcv); \ -} +#define NewFontAndColor(newfont, color, backcolor) \ + { \ + Globalgcv.font = newfont; \ + Globalgcv.foreground = color; \ + Globalgcv.background = backcolor; \ + Globalgcm = GCFont | GCForeground | GCBackground; \ + XChangeGC(dpy, Scr.ScratchGC3, Globalgcm, &Globalgcv); \ + } #ifdef NO_ICONS #define ICON_HEIGHT 1 #else -#define ICON_HEIGHT (Scr.IconFont.height+6) +#define ICON_HEIGHT (Scr.IconFont.height + 6) #endif extern XGCValues Globalgcv; @@ -149,145 +137,147 @@ extern char NoResource[]; /* Macro for args passed to fvwm commands... For now, this macro is only used within this file. dje 12/19/98 */ -#define F_CMD_ARGS XEvent *eventp,Window w,FvwmWindow *tmp_win,\ -unsigned long context,char *action, int *Module - -extern void LookInList(FvwmWindow *, name_list *); -extern void MoveOutline(Window, int,int,int,int); -extern void AnimatedMoveOfWindow(Window w,int startX,int startY,int endX, - int endY,Bool fWarpPointerToo, - int cusDelay, float *ppctMovement); -extern void DisplaySize(FvwmWindow *, int, int, Bool, Bool); -extern void DisplayPosition(FvwmWindow *, int, int,Bool); -extern void SetupFrame(FvwmWindow *,int,int,int,int,Bool); -extern void CreateGCs(void); -extern void InstallWindowColormaps(FvwmWindow *); -extern void InstallRootColormap(void); -extern void UninstallRootColormap(void); -extern void FetchWmProtocols(FvwmWindow *); -extern void FetchWmColormapWindows (FvwmWindow *tmp); -extern void InitEventHandlerJumpTable(void); -extern void DispatchEvent(void); -extern void HandleEvents(void); -extern void HandleExpose(void); -extern void HandleFocusIn(void); -extern void HandleFocusOut(void); -extern void HandleDestroyNotify(void); -extern void HandleMapRequest(void); -extern void HandleMapRequestKeepRaised(Window keepraised); -extern void HandleMapNotify(void); -extern void HandleUnmapNotify(void); -extern void HandleMotionNotify(void); -extern void HandleButtonRelease(void); -extern void HandleButtonPress(void); -extern void HandleEnterNotify(void); -extern void HandleLeaveNotify(void); -extern void HandleConfigureRequest(void); -extern void HandleClientMessage(void); -extern void HandlePropertyNotify(void); -extern void HandleKeyPress(void); -extern void HandleVisibilityNotify(void); -extern void HandleColormapNotify(void); -extern void SetTitleBar(FvwmWindow *, Bool,Bool); -extern void RestoreWithdrawnLocation(FvwmWindow *, Bool); -extern void Destroy(FvwmWindow *); -extern void GetGravityOffsets (FvwmWindow *, int *, int *); -extern void MoveViewport(int newx, int newy,Bool); +#define F_CMD_ARGS \ + XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context,\ + char *action, int *Module + +extern void LookInList(FvwmWindow *, name_list *); +extern void MoveOutline(Window, int, int, int, int); +extern void AnimatedMoveOfWindow(Window w, int startX, int startY, int endX, + int endY, Bool fWarpPointerToo, int cusDelay, float *ppctMovement); +extern void DisplaySize(FvwmWindow *, int, int, Bool, Bool); +extern void DisplayPosition(FvwmWindow *, int, int, Bool); +extern void SetupFrame(FvwmWindow *, int, int, int, int, Bool); +extern void CreateGCs(void); +extern void InstallWindowColormaps(FvwmWindow *); +extern void InstallRootColormap(void); +extern void UninstallRootColormap(void); +extern void FetchWmProtocols(FvwmWindow *); +extern void FetchWmColormapWindows(FvwmWindow *tmp); +extern void InitEventHandlerJumpTable(void); +extern void DispatchEvent(void); +extern void HandleEvents(void); +extern void HandleExpose(void); +extern void HandleFocusIn(void); +extern void HandleFocusOut(void); +extern void HandleDestroyNotify(void); +extern void HandleMapRequest(void); +extern void HandleMapRequestKeepRaised(Window keepraised); +extern void HandleMapNotify(void); +extern void HandleUnmapNotify(void); +extern void HandleMotionNotify(void); +extern void HandleButtonRelease(void); +extern void HandleButtonPress(void); +extern void HandleEnterNotify(void); +extern void HandleLeaveNotify(void); +extern void HandleConfigureRequest(void); +extern void HandleClientMessage(void); +extern void HandlePropertyNotify(void); +extern void HandleKeyPress(void); +extern void HandleVisibilityNotify(void); +extern void HandleColormapNotify(void); +extern void SetTitleBar(FvwmWindow *, Bool, Bool); +extern void RestoreWithdrawnLocation(FvwmWindow *, Bool); +extern void Destroy(FvwmWindow *); +extern void GetGravityOffsets(FvwmWindow *, int *, int *); +extern void MoveViewport(int newx, int newy, Bool); extern FvwmWindow *AddWindow(Window w); -extern int MappedNotOverride(Window w); -extern void GrabButtons(FvwmWindow *); -extern void GrabKeys(FvwmWindow *); -extern void GetWindowSizeHints(FvwmWindow *); -extern void SwitchPages(Bool,Bool); -extern void NextPage(void); -extern void PrevPage(void); -extern void moveLoop(FvwmWindow *,int,int,int,int,int *,int *,Bool,Bool); - -extern void Keyboard_shortcuts(XEvent *, FvwmWindow*, int); -extern void RedoIconName(FvwmWindow *); -extern void DrawIconWindow(FvwmWindow *); -extern void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y); - - -extern void RelieveWindow(FvwmWindow *, Window, int, int, int, int, GC, GC, - int); -extern void RelieveWindowHH(FvwmWindow *,Window, int,int,int,int, GC, GC, int, - int); -void RelieveParts(FvwmWindow *t,int i,GC hor, GC vert); -#define NO_HILITE 0x0000 -#define TOP_HILITE 0x0001 -#define RIGHT_HILITE 0x0002 +extern int MappedNotOverride(Window w); +extern void GrabButtons(FvwmWindow *); +extern void GrabKeys(FvwmWindow *); +extern void GetWindowSizeHints(FvwmWindow *); +extern void SwitchPages(Bool, Bool); +extern void NextPage(void); +extern void PrevPage(void); +extern void moveLoop( + FvwmWindow *, int, int, int, int, int *, int *, Bool, Bool); + +extern void Keyboard_shortcuts(XEvent *, FvwmWindow *, int); +extern void RedoIconName(FvwmWindow *); +extern void DrawIconWindow(FvwmWindow *); +extern void CreateIconWindow(FvwmWindow *tmp_win, int def_x, int def_y); + +extern void RelieveWindow( + FvwmWindow *, Window, int, int, int, int, GC, GC, int); +extern void RelieveWindowHH( + FvwmWindow *, Window, int, int, int, int, GC, GC, int, int); +void RelieveParts(FvwmWindow *t, int i, GC hor, GC vert); +#define NO_HILITE 0x0000 +#define TOP_HILITE 0x0001 +#define RIGHT_HILITE 0x0002 #define BOTTOM_HILITE 0x0004 -#define LEFT_HILITE 0x0008 -#define FULL_HILITE 0x000F -#define HH_HILITE 0x0010 +#define LEFT_HILITE 0x0008 +#define FULL_HILITE 0x000F +#define HH_HILITE 0x0010 void Maximize(F_CMD_ARGS); -#ifdef WINDOWSHADE +#ifdef WINDOWSHADE void WindowShade(F_CMD_ARGS); #endif -extern void RaiseWindow(FvwmWindow *t); -extern void LowerWindow(FvwmWindow *t); -extern Bool GrabEm(int); -extern void UngrabEm(void); -extern MenuRoot *NewMenuRoot(char *name, Bool function_or_popup); -extern void AddToMenu(MenuRoot *, char *, char *, Bool, Bool); -extern void MakeMenu(MenuRoot *); -extern void CaptureAllWindows(void); -extern void SetTimer(int); -extern int flush_expose(Window w); +extern void RaiseWindow(FvwmWindow *t); +extern void LowerWindow(FvwmWindow *t); +extern Bool IsTransientDescendantOf(FvwmWindow *t, FvwmWindow *ancestor); +extern Bool GrabEm(int); +extern void UngrabEm(void); +extern MenuRoot *NewMenuRoot(char *name, Bool function_or_popup); +extern void AddToMenu(MenuRoot *, char *, char *, Bool, Bool); +extern void MakeMenu(MenuRoot *); +extern void CaptureAllWindows(void); +extern void SetTimer(int); +extern int flush_expose(Window w); void ExecuteFunction(char *Action, FvwmWindow *tmp_win, XEvent *eventp, - unsigned long context, int Module); + unsigned long context, int Module); void do_windowList(F_CMD_ARGS); -extern void RaiseThisWindow(int); -extern int GetContext(FvwmWindow *, XEvent *, Window *dummy); -extern void ConstrainSize (FvwmWindow *, int *, int *, Bool roundUp, - int xmotion, int ymotion); -extern void HandlePaging(int, int, int *, int *, int *, int *,Bool); -extern void SetShape(FvwmWindow *, int); -extern void AutoPlace(FvwmWindow *); +extern void RaiseThisWindow(int); +extern int GetContext(FvwmWindow *, XEvent *, Window *dummy); +extern void ConstrainSize( + FvwmWindow *, int *, int *, Bool roundUp, int xmotion, int ymotion); +extern void HandlePaging(int, int, int *, int *, int *, int *, Bool); +extern void SetShape(FvwmWindow *, int); +extern void AutoPlace(FvwmWindow *); void executeModule(F_CMD_ARGS); -extern void SetFocus(Window,FvwmWindow *, Bool FocusByMouse); -extern void CheckAndSetFocus(void); -extern void initModules(void); -extern int HandleModuleInput(Window w, int channel); -extern void match_string(struct config *, char *, char *, FILE *); -extern void no_popup(char *ptr); -extern void KillModule(int channel, int place); -extern void ClosePipes(void); -extern char *findIconFile(char *icon, char *pathlist, int mode); +extern void SetFocus(Window, FvwmWindow *, Bool FocusByMouse); +extern void CheckAndSetFocus(void); +extern void initModules(void); +extern int HandleModuleInput(Window w, int channel); +extern void match_string(struct config *, char *, char *, FILE *); +extern void no_popup(char *ptr); +extern void KillModule(int channel, int place); +extern void ClosePipes(void); +extern char *findIconFile(char *icon, char *pathlist, int mode); void find_func_type(char *action, short *func_type, Bool *func_needs_window); -extern void GetBitmapFile(FvwmWindow *tmp_win); -extern void GetXPMFile(FvwmWindow *tmp_win); -extern void GetIconWindow(FvwmWindow *tmp_win); -extern void GetIconBitmap(FvwmWindow *tmp_win); +extern void GetBitmapFile(FvwmWindow *tmp_win); +extern void GetXPMFile(FvwmWindow *tmp_win); +extern void GetIconWindow(FvwmWindow *tmp_win); +extern void GetIconBitmap(FvwmWindow *tmp_win); /* RBW - 11/02/1998 */ -extern int SmartPlacement(FvwmWindow *t, int width, int height,int *x,int *y, - int pdeltax, int pdeltay); +extern int SmartPlacement(FvwmWindow *t, int width, int height, int *x, int *y, + int pdeltax, int pdeltay); /**/ extern void usage(void); void BroadcastPacket(unsigned long event_type, unsigned long num_datum, ...); -void SendPacket(int channel, unsigned long event_type, - unsigned long num_datum, ...); +void SendPacket( + int channel, unsigned long event_type, unsigned long num_datum, ...); void BroadcastConfig(unsigned long event_type, const FvwmWindow *t); void SendConfig(int Module, unsigned long event_type, const FvwmWindow *t); void BroadcastName(unsigned long event_type, unsigned long data1, - unsigned long data2, unsigned long data3, const char *name); + unsigned long data2, unsigned long data3, const char *name); void SendName(int channel, unsigned long event_type, unsigned long data1, - unsigned long data2, unsigned long data3, const char *name); + unsigned long data2, unsigned long data3, const char *name); void SendStrToModule(F_CMD_ARGS); -RETSIGTYPE DeadPipe(int nonsense); +void DeadPipe(int nonsense); void GetMwmHints(FvwmWindow *t); void GetOlHints(FvwmWindow *t); -void SelectDecor(FvwmWindow *, unsigned long, int,int); +void SelectDecor(FvwmWindow *, unsigned long, int, int); extern Bool PopUpMenu(MenuRoot *, int, int); void ComplexFunction(F_CMD_ARGS); -extern int DeferExecution(XEvent *, Window *,FvwmWindow **, unsigned long *, int, int); -void SetBorder (FvwmWindow *, Bool,Bool,Bool, Window); +extern int DeferExecution( + XEvent *, Window *, FvwmWindow **, unsigned long *, int, int); +void SetBorder(FvwmWindow *, Bool, Bool, Bool, Window); void move_window(F_CMD_ARGS); -void move_window_doit(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module, - Bool fAnimated, Bool fMoveToPage); +void move_window_doit(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module, Bool fAnimated, + Bool fMoveToPage); void animated_move_window(F_CMD_ARGS); void move_window_to_page(F_CMD_ARGS); void set_animation(F_CMD_ARGS); @@ -301,30 +291,30 @@ void DeIconify(FvwmWindow *); void KeepOnTop(void); void show_panner(void); void WaitForButtonsUp(void); -void FocusOn(FvwmWindow *t,Bool FocusByMouse); -void WarpOn(FvwmWindow *t,int warp_x, int x_unit, int warp_y, int y_unit); +void FocusOn(FvwmWindow *t, Bool FocusByMouse); +void WarpOn(FvwmWindow *t, int warp_x, int x_unit, int warp_y, int y_unit); /* RBW - 11/02/1998 */ -Bool PlaceWindow(FvwmWindow *tmp_win, unsigned long flags, - int Desk, int PageX, int PageY); -void free_window_names (FvwmWindow *tmp, Bool nukename, Bool nukeicon); +Bool PlaceWindow( + FvwmWindow *tmp_win, unsigned long flags, int Desk, int PageX, int PageY); +void free_window_names(FvwmWindow *tmp, Bool nukename, Bool nukeicon); -MenuStatus do_menu (MenuRoot *menu,MenuRoot *menuPrior, - MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks, - XEvent *eventp, MenuOptions *pops); +MenuStatus do_menu(MenuRoot *menu, MenuRoot *menuPrior, + MenuItem **pmiExecuteAction, int cmenuDeep, Bool fSticks, XEvent *eventp, + MenuOptions *pops); int check_allowed_function(MenuItem *mi); int check_allowed_function2(int function, FvwmWindow *t); void ReInstallActiveColormap(void); -void ParsePopupEntry(char *,FILE *, char **, int *); +void ParsePopupEntry(char *, FILE *, char **, int *); void ParseMouseEntry(F_CMD_ARGS); void ParseKeyEntry(F_CMD_ARGS); -void SetOneStyle(char *text,FILE *,char **,int *); -void ParseStyle(char *text,FILE *,char **,int *); -void assign_string(char *text, FILE *fd, char **arg,int *); -void SetFlag(char *text, FILE *fd, char **arg,int *); -void SetCursor(char *text, FILE *fd, char **arg,int *); -void SetInts(char *text, FILE *fd, char **arg,int *); -void SetBox(char *text, FILE *fd, char **arg,int *); -void set_func(char *, FILE *, char **,int *); +void SetOneStyle(char *text, FILE *, char **, int *); +void ParseStyle(char *text, FILE *, char **, int *); +void assign_string(char *text, FILE *fd, char **arg, int *); +void SetFlag(char *text, FILE *fd, char **arg, int *); +void SetCursor(char *text, FILE *fd, char **arg, int *); +void SetInts(char *text, FILE *fd, char **arg, int *); +void SetBox(char *text, FILE *fd, char **arg, int *); +void set_func(char *, FILE *, char **, int *); void copy_config(FILE **config_fd); void SetEdgeScroll(F_CMD_ARGS); void SetEdgeResistance(F_CMD_ARGS); @@ -350,16 +340,16 @@ void do_save(void); void checkPanFrames(void); void raisePanFrames(void); void initPanFrames(void); -Bool StashEventTime (XEvent *ev); +Bool StashEventTime(XEvent *ev); int My_XNextEvent(Display *dpy, XEvent *event); void FlushQueue(int Module); void QuickRestart(void); -void AddFuncKey (char *, int, int, int, char *, int, int, MenuRoot *, - char , char); +void AddFuncKey( + char *, int, int, int, char *, int, int, MenuRoot *, char, char); char *GetNextPtr(char *ptr); -void InteractiveMove(Window *w, FvwmWindow *tmp_win, int *FinalX, int *FinalY, - XEvent *eventp); +void InteractiveMove( + Window *w, FvwmWindow *tmp_win, int *FinalX, int *FinalY, XEvent *eventp); MenuRoot *FindPopup(char *action); @@ -384,14 +374,14 @@ void changeDesks_func(F_CMD_ARGS); void changeDesks(int desk); void changeWindowsDesk(F_CMD_ARGS); -int GetMoveArguments(char *action, int x, int y, int w, int h, - int *pfinalX, int *pfinalY, Bool *fWarp); -char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, - MenuItem *mi, MenuOptions *pops); -int GetTwoArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit); -int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit); +int GetMoveArguments(char *action, int x, int y, int w, int h, int *pfinalX, + int *pfinalY, Bool *fWarp); +char *GetMenuOptions(char *action, Window w, FvwmWindow *tmp_win, MenuItem *mi, + MenuOptions *pops); +int GetTwoArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit); +int GetTwoPercentArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit); void goto_page_func(F_CMD_ARGS); @@ -416,8 +406,8 @@ Pixel GetColor(char *); void FreeColors(Pixel *pixels, int n); #ifdef GRADIENT_BUTTONS Pixel *AllocLinearGradient(char *s_from, char *s_to, int npixels); -Pixel *AllocNonlinearGradient(char *s_colors[], int clen[], - int nsegs, int npixels); +Pixel *AllocNonlinearGradient( + char *s_colors[], int clen[], int nsegs, int npixels); #endif void bad_binding(int num); void nocolor(char *note, char *name); @@ -478,11 +468,10 @@ void CoerceEnterNotifyOnCurrentWindow(); /* ** message levels for fvwm_msg: */ -#define DBG -1 +#define DBG -1 #define INFO 0 #define WARN 1 -#define ERR 2 -void fvwm_msg(int type,char *id,char *msg,...); +#define ERR 2 +void fvwm_msg(int type, const char *id, const char *msg, ...); #endif /* MISC_H */ - Index: fvwm/fvwm/modconf.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/modconf.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/modconf.c --- fvwm/fvwm/modconf.c +++ fvwm/fvwm/modconf.c @@ -24,40 +24,38 @@ * ******************************************************************** */ -#include "config.h" +#include +#include -#include -#include +#include +#include #include +#include #include -#include -#include -#include -#include +#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" -extern unsigned long *PipeMask; /* in module.c */ +extern unsigned long *PipeMask; /* in module.c */ extern Boolean debugging; -struct moduleInfoList -{ - char *data; - struct moduleInfoList *next; +struct moduleInfoList { + char *data; + struct moduleInfoList *next; }; struct moduleInfoList *modlistroot = NULL; -void AddToModList(char *tline); /* prototypes */ +void AddToModList(char *tline); /* prototypes */ extern void StartupStuff(void); - /* * ModuleConfig handles commands starting with "*". * @@ -67,141 +65,136 @@ extern void StartupStuff(void); * Some modules request that module config commands be sent to them * as the commands are entered. Send to modules that want it. */ -void ModuleConfig(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, - char *action, int *Module) { - int module; - AddToModList(action); /* save for config request */ - for (module=0;modulenext; - } - - this = (struct moduleInfoList *)safemalloc(sizeof(struct moduleInfoList)); - len = strlen(tline)+1; - this->data = (char *)safemalloc(len); - this->next = NULL; - strlcpy(this->data, tline, len); - if(prev == NULL) - { - modlistroot = this; - } - else - prev->next = this; + struct moduleInfoList *t, *prev, *this; + size_t len; + + /* Find end of list */ + t = modlistroot; + prev = NULL; + + while (t != NULL) { + prev = t; + t = t->next; + } + + this = + (struct moduleInfoList *)xmalloc(sizeof(struct moduleInfoList)); + len = strlen(tline) + 1; + this->data = (char *)xmalloc(len); + this->next = NULL; + strlcpy(this->data, tline, len); + if (prev == NULL) { + modlistroot = this; + } else + prev->next = this; } /* interface function for AddToModList */ /* dje, this doesn't seem to be used? */ -void AddModConfig(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +AddModConfig(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - AddToModList( action ); + AddToModList(action); } /**************************************************************/ /* delete from module configuration */ /**************************************************************/ -void DestroyModConfig(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +DestroyModConfig(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - struct moduleInfoList *current, *next, *prev; - char *info; /* info to be deleted - may contain wildcards */ - char *mi; - - GetNextToken(action, &info); - if( info == NULL ) - { - return; - } - - current = modlistroot; - prev = NULL; - - while(current != NULL) - { - GetNextToken( current->data, &mi); - next = current->next; - if( matchWildcards(info, mi+1) ) - { - free(current->data); - free(current); - if( prev ) - { - prev->next = next; - } - else - { - modlistroot = next; - } - } - else - { - prev = current; - } - current = next; - if (mi) - free(mi); - } - free(info); + struct moduleInfoList *current, *next, *prev; + char *info; /* info to be deleted - may contain wildcards */ + char *mi; + + GetNextToken(action, &info); + if (info == NULL) { + return; + } + + current = modlistroot; + prev = NULL; + + while (current != NULL) { + GetNextToken(current->data, &mi); + next = current->next; + if (mi != NULL && matchWildcards(info, mi + 1)) { + free(current->data); + free(current); + if (prev) { + prev->next = next; + } else { + modlistroot = next; + } + } else { + prev = current; + } + current = next; + if (mi) + free(mi); + } + free(info); } -void SendDataToModule(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +SendDataToModule(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - struct moduleInfoList *t; - char *message,msg2[32]; - extern char *IconPath; - extern char *PixmapPath; - size_t len; - - if (IconPath && strlen(IconPath)) - { - len=strlen(IconPath)+11; - message=safemalloc(len); - snprintf(message,len,"IconPath %s\n",IconPath); - SendName(*Module,M_CONFIG_INFO,0,0,0,message); - free(message); - } + struct moduleInfoList *t; + char *message, msg2[32]; + extern char *IconPath; + extern char *PixmapPath; + size_t len; + + if (IconPath && strlen(IconPath)) { + len = strlen(IconPath) + 11; + message = xmalloc(len); + snprintf(message, len, "IconPath %s\n", IconPath); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, message); + free(message); + } #ifdef XPM - if (PixmapPath && strlen(PixmapPath)) - { - len=strlen(PixmapPath)+13; - message=safemalloc(len); - snprintf(message,len,"PixmapPath %s\n",PixmapPath); - SendName(*Module,M_CONFIG_INFO,0,0,0,message); - snprintf(message,len,"ColorLimit %d\n",Scr.ColorLimit); - SendName(*Module,M_CONFIG_INFO,0,0,0,message); - free(message); - } + if (PixmapPath && strlen(PixmapPath)) { + len = strlen(PixmapPath) + 13; + message = xmalloc(len); + snprintf(message, len, "PixmapPath %s\n", PixmapPath); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, message); + snprintf(message, len, "ColorLimit %d\n", Scr.ColorLimit); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, message); + free(message); + } #endif - /* Dominik Vogt (8-Nov-1998): Scr.ClickTime patch to set ClickTime to - * 'not at all' during InitFunction and RestartFunction. */ - snprintf(msg2,sizeof(msg2),"ClickTime %d\n", (Scr.ClickTime < 0) ? - -Scr.ClickTime : Scr.ClickTime); - SendName(*Module,M_CONFIG_INFO,0,0,0,msg2); - - t = modlistroot; - while(t != NULL) - { - SendName(*Module,M_CONFIG_INFO,0,0,0,t->data); - t = t->next; - } - SendPacket(*Module,M_END_CONFIG_INFO,0,0,0,0,0,0,0,0); + /* Dominik Vogt (8-Nov-1998): Scr.ClickTime patch to set ClickTime to + * 'not at all' during InitFunction and RestartFunction. */ + snprintf(msg2, sizeof(msg2), "ClickTime %d\n", + (Scr.ClickTime < 0) ? -Scr.ClickTime : Scr.ClickTime); + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, msg2); + + t = modlistroot; + while (t != NULL) { + SendName(*Module, M_CONFIG_INFO, 0, 0, 0, t->data); + t = t->next; + } + SendPacket(*Module, M_END_CONFIG_INFO, 0, 0, 0, 0, 0, 0, 0, 0); } Index: fvwm/fvwm/module.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/module.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/module.c --- fvwm/fvwm/module.c +++ fvwm/fvwm/module.c @@ -12,27 +12,26 @@ * ***********************************************************************/ -#include "config.h" +#include "module.h" + +#include +#include -#include -#include -#include #include -#include #include - -#include #include -#include -#include +#include +#include +#include +#include +#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" #include "parse.h" #include "screen.h" -#include "module.h" - int npipes; int *readPipes; @@ -47,792 +46,750 @@ inline int PositiveWrite(int module, unsigned long *ptr, int size); void DeleteQueueBuff(int module); void AddToQueue(int module, unsigned long *ptr, int size, int done); -void initModules(void) +void +initModules(void) { - int i; - - npipes = GetFdWidth(); - - writePipes = (int *)safemalloc(sizeof(int)*npipes); - readPipes = (int *)safemalloc(sizeof(int)*npipes); - pipeOn = (int *)safemalloc(sizeof(int)*npipes); - PipeMask = (unsigned long *)safemalloc(sizeof(unsigned long)*npipes); - pipeName = (char **)safemalloc(sizeof(char *)*npipes); - pipeQueue=(struct queue_buff_struct **) - safemalloc(sizeof(struct queue_buff_struct *)*npipes); - - for(i=0;i0) - { - close(writePipes[i]); - close(readPipes[i]); + int i; + for (i = 0; i < npipes; i++) { + if (writePipes[i] > 0) { + close(writePipes[i]); + close(readPipes[i]); + } + if (pipeName[i] != NULL) { + free(pipeName[i]); + pipeName[i] = 0; + } + while (pipeQueue[i] != NULL) { + DeleteQueueBuff(i); + } } - if(pipeName[i] != NULL) - { - free(pipeName[i]); - pipeName[i] = 0; +} + +void +executeModule(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) +{ + int fvwm_to_app[2], app_to_fvwm[2]; + int i, val, nargs = 0; + char *cptr; + char *args[20]; + char *arg1 = NULL; + char arg2[20]; + char arg3[20]; + char arg5[20]; + char arg6[20]; + extern char *ModulePath; + extern char *fvwm_file; + Window win; + + if (eventp->type != KeyPress) + UngrabEm(); + + if (action == NULL) + return; + + if (tmp_win) + win = tmp_win->w; + else + win = None; + + /* If we execute a module, don't wait for buttons to come up, + * that way, a pop-up menu could be implemented */ + *Module = 0; + + action = GetNextToken(action, &cptr); + if (!cptr) + return; + + arg1 = findIconFile(cptr, ModulePath, X_OK); + if (arg1 == NULL) { + fvwm_msg(ERR, "executeModule", + "No such module '%s' in ModulePath '%s'", cptr, ModulePath); + free(cptr); + return; } - while(pipeQueue[i] != NULL) - { - DeleteQueueBuff(i); + + /* Look for an available pipe slot */ + i = 0; + while ((i < npipes) && (writePipes[i] >= 0)) + i++; + if (i >= npipes) { + fvwm_msg(ERR, "executeModule", "Too many Accessories!"); + free(arg1); + free(cptr); + return; } - } -} + /* I want one-ended pipes, so I open two two-ended pipes, + * and close one end of each. I need one ended pipes so that + * I can detect when the module crashes/malfunctions */ + if (pipe(fvwm_to_app) != 0) { + fvwm_msg(ERR, "executeModule", "Failed to open pipe"); + free(arg1); + free(cptr); + return; + } + if (pipe(app_to_fvwm) != 0) { + fvwm_msg(ERR, "executeModule", "Failed to open pipe2"); + free(arg1); + free(cptr); + close(fvwm_to_app[0]); + close(fvwm_to_app[1]); + return; + } -void executeModule(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) -{ - int fvwm_to_app[2],app_to_fvwm[2]; - int i,val,nargs = 0; - char *cptr; - char *args[20]; - char *arg1 = NULL; - char arg2[20]; - char arg3[20]; - char arg5[20]; - char arg6[20]; - extern char *ModulePath; - extern char *fvwm_file; - Window win; - - if(eventp->type != KeyPress) - UngrabEm(); - - if(action == NULL) - return; - - if(tmp_win) - win = tmp_win->w; - else - win = None; - - /* If we execute a module, don't wait for buttons to come up, - * that way, a pop-up menu could be implemented */ - *Module = 0; - - action = GetNextToken(action, &cptr); - if (!cptr) - return; - - arg1 = findIconFile(cptr,ModulePath,X_OK); - if(arg1 == NULL) - { - fvwm_msg(ERR,"executeModule", - "No such module '%s' in ModulePath '%s'",cptr,ModulePath); - free(cptr); - return; - } - - /* Look for an available pipe slot */ - i=0; - while((i=0)) - i++; - if(i>=npipes) - { - fvwm_msg(ERR,"executeModule","Too many Accessories!"); - free(arg1); - free(cptr); - return; - } - - /* I want one-ended pipes, so I open two two-ended pipes, - * and close one end of each. I need one ended pipes so that - * I can detect when the module crashes/malfunctions */ - if(pipe(fvwm_to_app)!=0) - { - fvwm_msg(ERR,"executeModule","Failed to open pipe"); - free(arg1); - free(cptr); - return; - } - if(pipe(app_to_fvwm)!=0) - { - fvwm_msg(ERR,"executeModule","Failed to open pipe2"); - free(arg1); - free(cptr); - close(fvwm_to_app[0]); - close(fvwm_to_app[1]); - return; - } - - pipeName[i] = stripcpy(cptr); - free(cptr); - snprintf(arg2,sizeof(arg2),"%d",app_to_fvwm[1]); - snprintf(arg3,sizeof(arg3),"%d",fvwm_to_app[0]); - snprintf(arg5,sizeof(arg5),"%lx",(unsigned long)win); - snprintf(arg6,sizeof(arg6),"%lx",(unsigned long)context); - args[0]=arg1; - args[1]=arg2; - args[2]=arg3; - if(fvwm_file != NULL) - args[3]=fvwm_file; - else - args[3]="none"; - args[4]=arg5; - args[5]=arg6; - nargs = 6; - while((action != NULL)&&(nargs < 20)&&(args[nargs-1] != NULL)) - { - args[nargs] = 0; - action = GetNextToken(action,&args[nargs]); - nargs++; - } - if(args[nargs-1] == NULL) - nargs--; - args[nargs] = 0; - - /* Try vfork instead of fork. The man page says that vfork is better! */ - /* Also, had to change exit to _exit() */ - /* Not everyone has vfork! */ - val = fork(); - if(val > 0) - { - /* This fork remains running fvwm */ - /* close appropriate descriptors from each pipe so - * that fvwm will be able to tell when the app dies */ - close(app_to_fvwm[1]); - close(fvwm_to_app[0]); - - /* add these pipes to fvwm's active pipe list */ - writePipes[i] = fvwm_to_app[1]; - readPipes[i] = app_to_fvwm[0]; - pipeOn[i] = -1; - PipeMask[i] = MAX_MASK; - free(arg1); - pipeQueue[i] = NULL; - - /* make the PositiveWrite pipe non-blocking. Don't want to jam up - fvwm because of an uncooperative module */ -#ifdef O_NONBLOCK - fcntl(writePipes[i],F_SETFL,O_NONBLOCK); /* POSIX, better behavior */ -#else - fcntl(writePipes[i],F_SETFL,O_NDELAY); /* early SYSV, bad behavior */ -#endif - /* Mark the pipes close-on exec so other programs - * won`t inherit them */ - if (fcntl(readPipes[i], F_SETFD, 1) == -1) - fvwm_msg(ERR,"executeModule","module close-on-exec failed"); - if (fcntl(writePipes[i], F_SETFD, 1) == -1) - fvwm_msg(ERR,"executeModule","module close-on-exec failed"); - for(i=6;i 0) { + /* This fork remains running fvwm */ + /* close appropriate descriptors from each pipe so + * that fvwm will be able to tell when the app dies */ + close(app_to_fvwm[1]); + close(fvwm_to_app[0]); + + /* add these pipes to fvwm's active pipe list */ + writePipes[i] = fvwm_to_app[1]; + readPipes[i] = app_to_fvwm[0]; + pipeOn[i] = -1; + PipeMask[i] = MAX_MASK; + free(arg1); + pipeQueue[i] = NULL; + + /* make the PositiveWrite pipe non-blocking. Don't want to jam + up fvwm because of an uncooperative module */ + fcntl(writePipes[i], F_SETFL, O_NONBLOCK); + /* Mark the pipes close-on exec so other programs + * won`t inherit them */ + if (fcntl(readPipes[i], F_SETFD, 1) == -1) + fvwm_msg(ERR, "executeModule", + "module close-on-exec failed"); + if (fcntl(writePipes[i], F_SETFD, 1) == -1) + fvwm_msg(ERR, "executeModule", + "module close-on-exec failed"); + for (i = 6; i < nargs; i++) { + if (args[i] != 0) + free(args[i]); + } + } else if (val == 0) { + /* this is the child */ + /* this fork execs the module */ + close(fvwm_to_app[1]); + close(app_to_fvwm[0]); + + execvp(arg1, args); + fvwm_msg(ERR, "executeModule", "Execution of module failed: %s", + arg1); + perror(""); + _exit(1); + } else { + fvwm_msg(ERR, "executeModule", "Fork failed"); + free(arg1); + for (i = 6; i < nargs; i++) { + if (args[i] != 0) + free(args[i]); + } } - } - return; + return; } /* Changed to return 66, Locking code AS dje */ -int HandleModuleInput(Window w, int channel) +int +HandleModuleInput(Window w, int channel) { - char text[256]; - int size; - int cont,n; - - /* Already read a (possibly NULL) window id from the pipe, - * Now read an fvwm bultin command line */ - n = read(readPipes[channel], &size, sizeof(size)); - if(n < sizeof(size)) - { - KillModule(channel,1); - return 0; - } - - if(size >255) - { - fvwm_msg(ERR, "HandleModuleInput", - "Module command is too big (%d)", size); - size=255; - } - - pipeOn[channel] = 1; - - n = read(readPipes[channel],text, size); - if(n < size) - { - KillModule(channel,2); - return 0; - } - text[n] = '\0'; - /* DB(("Module read[%d] (%d): `%s'", n, size, text)); */ - - n = read(readPipes[channel],&cont, sizeof(cont)); - /* DB(("Module read[%d] cont = %d", n, cont)); */ - if(n < sizeof(cont)) - { - KillModule(channel,3); - return 0; - } - if(cont == 0) - { - KillModule(channel,4); - } - if(strlen(text)>0) - { - extern int Context; - FvwmWindow *tmp_win; - - if(strncasecmp(text,"UNLOCK",6)==0) { /* synchronous response */ - return 66; - } - - /* perhaps the module would like us to kill it? */ - if(strncasecmp(text,"KillMe",6)==0) - { - KillModule(channel,12); - return 0; - } - - /* If a module does XUngrabPointer(), it can now get proper Popups */ - if(StrEquals(text, "popup")) - Event.xany.type = ButtonPress; - else - Event.xany.type = ButtonRelease; - Event.xany.window = w; - - if (XFindContext (dpy, w, FvwmContext, (caddr_t *) &tmp_win) == XCNOENT) - { - tmp_win = NULL; - w = None; + char text[256]; + int size; + int cont, n; + + /* Already read a (possibly NULL) window id from the pipe, + * Now read an fvwm bultin command line */ + n = read(readPipes[channel], &size, sizeof(size)); + if (n < sizeof(size)) { + KillModule(channel, 1); + return 0; + } + + if (size < 0) { + fvwm_msg(ERR, "HandleModuleInput", + "Module sent negative command size (%d)", size); + KillModule(channel, 5); + return 0; + } + if (size > (int)(sizeof(text) - 1)) { + fvwm_msg(ERR, "HandleModuleInput", + "Module command is too big (%d)", size); + size = (int)(sizeof(text) - 1); + } + + pipeOn[channel] = 1; + + n = read(readPipes[channel], text, size); + if (n < size) { + KillModule(channel, 2); + return 0; } - if(tmp_win) - { - Event.xbutton.button = 1; - Event.xbutton.x_root = tmp_win->frame_x; - Event.xbutton.y_root = tmp_win->frame_y; - Event.xbutton.x = 0; - Event.xbutton.y = 0; - Event.xbutton.subwindow = None; + text[n] = '\0'; + /* DB(("Module read[%d] (%d): `%s'", n, size, text)); */ + + n = read(readPipes[channel], &cont, sizeof(cont)); + /* DB(("Module read[%d] cont = %d", n, cont)); */ + if (n < sizeof(cont)) { + KillModule(channel, 3); + return 0; } - else - { - Event.xbutton.button = 1; - Event.xbutton.x_root = 0; - Event.xbutton.y_root = 0; - Event.xbutton.x = 0; - Event.xbutton.y = 0; - Event.xbutton.subwindow = None; + if (cont == 0) { + KillModule(channel, 4); } - Context = GetContext(tmp_win,&Event,&w); - ExecuteFunction(text,tmp_win,&Event,Context ,channel); - } - return 0; + if (strlen(text) > 0) { + extern int Context; + FvwmWindow *tmp_win; + + if (strncasecmp(text, "UNLOCK", 6) == + 0) { /* synchronous response */ + return 66; + } + + /* perhaps the module would like us to kill it? */ + if (strncasecmp(text, "KillMe", 6) == 0) { + KillModule(channel, 12); + return 0; + } + + /* If a module does XUngrabPointer(), it can now get proper + * Popups */ + if (StrEquals(text, "popup")) + Event.xany.type = ButtonPress; + else + Event.xany.type = ButtonRelease; + Event.xany.window = w; + + if (XFindContext(dpy, w, FvwmContext, (caddr_t *)&tmp_win) == + XCNOENT) { + tmp_win = NULL; + w = None; + } + if (tmp_win) { + Event.xbutton.button = 1; + Event.xbutton.x_root = tmp_win->frame_x; + Event.xbutton.y_root = tmp_win->frame_y; + Event.xbutton.x = 0; + Event.xbutton.y = 0; + Event.xbutton.subwindow = None; + } else { + Event.xbutton.button = 1; + Event.xbutton.x_root = 0; + Event.xbutton.y_root = 0; + Event.xbutton.x = 0; + Event.xbutton.y = 0; + Event.xbutton.subwindow = None; + } + Context = GetContext(tmp_win, &Event, &w); + ExecuteFunction(text, tmp_win, &Event, Context, channel); + } + return 0; } - -RETSIGTYPE DeadPipe(int nonsense) +void +DeadPipe(int nonsense) { } - -void KillModule(int channel, int place) +void +KillModule(int channel, int place) { - close(readPipes[channel]); - close(writePipes[channel]); - - readPipes[channel] = -1; - writePipes[channel] = -1; - pipeOn[channel] = -1; - while(pipeQueue[channel] != NULL) - { - DeleteQueueBuff(channel); - } - if(pipeName[channel] != NULL) - { - free(pipeName[channel]); - pipeName[channel] = NULL; - } - - return; + close(readPipes[channel]); + close(writePipes[channel]); + + readPipes[channel] = -1; + writePipes[channel] = -1; + pipeOn[channel] = -1; + while (pipeQueue[channel] != NULL) { + DeleteQueueBuff(channel); + } + if (pipeName[channel] != NULL) { + free(pipeName[channel]); + pipeName[channel] = NULL; + } + + return; } -void KillModuleByName(char *name) +void +KillModuleByName(char *name) { - int i = 0; + int i = 0; - if(name == NULL) - return; + if (name == NULL) + return; - while(i 0; --num) - *(bp++) = va_arg(ap, unsigned long); + for (; num > 0; --num) + *(bp++) = va_arg(ap, unsigned long); - return body; + return body; } void SendPacket(int module, unsigned long event_type, unsigned long num_datum, ...) { - unsigned long body[MAX_BODY_SIZE+HEADER_SIZE]; - va_list ap; + unsigned long body[MAX_BODY_SIZE + HEADER_SIZE]; + va_list ap; - va_start(ap, num_datum); - make_vpacket(body, event_type, num_datum, ap); - va_end(ap); + va_start(ap, num_datum); + make_vpacket(body, event_type, num_datum, ap); + va_end(ap); - PositiveWrite(module, body, (num_datum+HEADER_SIZE)*sizeof(body[0])); + PositiveWrite( + module, body, (num_datum + HEADER_SIZE) * sizeof(body[0])); } void BroadcastPacket(unsigned long event_type, unsigned long num_datum, ...) { - unsigned long body[MAX_BODY_SIZE+HEADER_SIZE]; - va_list ap; - int i; + unsigned long body[MAX_BODY_SIZE + HEADER_SIZE]; + va_list ap; + int i; - va_start(ap,num_datum); - make_vpacket(body, event_type, num_datum, ap); - va_end(ap); + va_start(ap, num_datum); + make_vpacket(body, event_type, num_datum, ap); + va_end(ap); - for (i=0; iw,\ - (_t)->frame,\ - (unsigned long)(_t),\ - (_t)->frame_x,\ - (_t)->frame_y,\ - (_t)->frame_width,\ - (_t)->frame_height,\ - (_t)->Desk,\ - (_t)->flags,\ - (_t)->title_height,\ - (_t)->boundary_width,\ - ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_width : 0,\ - ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_height: 0,\ - ((_t)->hints.flags & PResizeInc)? (_t)->hints.width_inc : 1,\ - ((_t)->hints.flags & PResizeInc)? (_t)->hints.height_inc : 1,\ - (_t)->hints.min_width,\ - (_t)->hints.min_height,\ - (_t)->hints.max_width,\ - (_t)->hints.max_height,\ - (_t)->icon_w,\ - (_t)->icon_pixmap_w,\ - (_t)->hints.win_gravity,\ - (_t)->TextPixel,\ - (_t)->BackPixel - -void SendConfig(int module, unsigned long event_type, const FvwmWindow *t) +#define CONFIGARGS(_t) \ + 24, (_t)->w, (_t)->frame, (unsigned long)(_t), (_t)->frame_x, \ + (_t)->frame_y, (_t)->frame_width, (_t)->frame_height, (_t)->Desk,\ + (_t)->flags, (_t)->title_height, (_t)->boundary_width, \ + ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_width : 0,\ + ((_t)->hints.flags & PBaseSize) ? (_t)->hints.base_height : 0,\ + ((_t)->hints.flags & PResizeInc) ? (_t)->hints.width_inc : 1,\ + ((_t)->hints.flags & PResizeInc) ? (_t)->hints.height_inc : 1,\ + (_t)->hints.min_width, (_t)->hints.min_height, \ + (_t)->hints.max_width, (_t)->hints.max_height, (_t)->icon_w,\ + (_t)->icon_pixmap_w, (_t)->hints.win_gravity, (_t)->TextPixel,\ + (_t)->BackPixel + +void +SendConfig(int module, unsigned long event_type, const FvwmWindow *t) { - SendPacket(module, event_type, CONFIGARGS(t)); + SendPacket(module, event_type, CONFIGARGS(t)); } - -void BroadcastConfig(unsigned long event_type, const FvwmWindow *t) +void +BroadcastConfig(unsigned long event_type, const FvwmWindow *t) { - BroadcastPacket(event_type, CONFIGARGS(t)); + BroadcastPacket(event_type, CONFIGARGS(t)); } static unsigned long * -make_named_packet(int *len, unsigned long event_type, const char *name, - int num, ...) +make_named_packet( + int *len, unsigned long event_type, const char *name, int num, ...) { - unsigned long *body; - va_list ap; + unsigned long *body; + va_list ap; - /* Packet is the header plus the items plus enough items to hold the name - string. */ - *len = HEADER_SIZE + num + (strlen(name) / sizeof(unsigned long)) + 1; + /* Packet is the header plus the items plus enough items to hold the + name string. */ + *len = HEADER_SIZE + num + (strlen(name) / sizeof(unsigned long)) + 1; - body = (unsigned long *)safemalloc(*len * sizeof(unsigned long)); - body[*len-1] = 0; /* Zero out end of memory to avoid uninit memory access. */ + body = (unsigned long *)xmalloc(*len * sizeof(unsigned long)); + body[*len - 1] = + 0; /* Zero out end of memory to avoid uninit memory access. */ - va_start(ap, num); - make_vpacket(body, event_type, num, ap); - va_end(ap); + va_start(ap, num); + make_vpacket(body, event_type, num, ap); + va_end(ap); - strlcpy((char *)&body[HEADER_SIZE+num], name, - *len * sizeof(unsigned long) - HEADER_SIZE - num); - body[2] = *len; + strlcpy((char *)&body[HEADER_SIZE + num], name, + (*len - HEADER_SIZE - num) * sizeof(unsigned long)); + body[2] = *len; - /* DB(("Packet (%lu): %lu %lu %lu `%s'", *len, - body[HEADER_SIZE], body[HEADER_SIZE+1], body[HEADER_SIZE+2], name)); */ + /* DB(("Packet (%lu): %lu %lu %lu `%s'", *len, + body[HEADER_SIZE], body[HEADER_SIZE+1], body[HEADER_SIZE+2], + name)); */ - return (body); + return (body); } void -SendName(int module, unsigned long event_type, - unsigned long data1,unsigned long data2, unsigned long data3, - const char *name) +SendName(int module, unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, const char *name) { - unsigned long *body; - int l; + unsigned long *body; + int l; - if (name == NULL) - return; + if (name == NULL) + return; - body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); - PositiveWrite(module, body, l*sizeof(unsigned long)); - free(body); + body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); + PositiveWrite(module, body, l * sizeof(unsigned long)); + free(body); } void -BroadcastName(unsigned long event_type, - unsigned long data1, unsigned long data2, unsigned long data3, - const char *name) +BroadcastName(unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, const char *name) { - unsigned long *body; - int i, l; + unsigned long *body; + int i, l; - if (name == NULL) - return; + if (name == NULL) + return; - body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); + body = make_named_packet(&l, event_type, name, 3, data1, data2, data3); - for (i=0; i < npipes; i++) - PositiveWrite(i, body, l*sizeof(unsigned long)); + for (i = 0; i < npipes; i++) + PositiveWrite(i, body, l * sizeof(unsigned long)); - free(body); + free(body); } #ifdef MINI_ICONS void -SendMiniIcon(int module, unsigned long event_type, - unsigned long data1, unsigned long data2, - unsigned long data3, unsigned long data4, - unsigned long data5, unsigned long data6, - unsigned long data7, unsigned long data8, - const char *name) +SendMiniIcon(int module, unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, unsigned long data4, + unsigned long data5, unsigned long data6, unsigned long data7, + unsigned long data8, const char *name) { - unsigned long *body; - int l; + unsigned long *body; + int l; - if ((name == NULL) || (event_type != M_MINI_ICON)) - return; + if ((name == NULL) || (event_type != M_MINI_ICON)) + return; - body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, - data4, data5, data6, data7, data8); - PositiveWrite(module, body, l*sizeof(unsigned long)); - free(body); + body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, + data4, data5, data6, data7, data8); + PositiveWrite(module, body, l * sizeof(unsigned long)); + free(body); } void -BroadcastMiniIcon(unsigned long event_type, - unsigned long data1, unsigned long data2, - unsigned long data3, unsigned long data4, - unsigned long data5, unsigned long data6, - unsigned long data7, unsigned long data8, - const char *name) +BroadcastMiniIcon(unsigned long event_type, unsigned long data1, + unsigned long data2, unsigned long data3, unsigned long data4, + unsigned long data5, unsigned long data6, unsigned long data7, + unsigned long data8, const char *name) { - unsigned long *body; - int i, l; + unsigned long *body; + int i, l; - body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, - data4, data5, data6, data7, data8); + body = make_named_packet(&l, event_type, name, 8, data1, data2, data3, + data4, data5, data6, data7, data8); - for (i=0; i < npipes; i++) - PositiveWrite(i, body, l*sizeof(unsigned long)); + for (i = 0; i < npipes; i++) + PositiveWrite(i, body, l * sizeof(unsigned long)); - free(body); + free(body); } #endif /* MINI_ICONS */ /* ** send an arbitrary string to all instances of a module */ -void SendStrToModule(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +SendStrToModule(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - char *module,*str; - int i; - - if (!action) - return; - GetNextToken(action,&module); - if (!module) - return; - str = strdup(action + strlen(module) + 1); - - for (i=0;i 0) { - if (HandleModuleInput(targetWindow,module) == 66) { - break; - } - } - if (e <= 0) { - KillModule(module,10); - } - fcntl(readPipes[module],F_SETFL,O_NDELAY); - } - return size; + if ((pipeOn[module] < 0) || (!((PipeMask[module]) & ptr[1]))) + return -1; + + /* + * fvwm2 recapture has the x server grabbed while iconify events are + * simulated. Right now (01/24/99), the only module using lock on send + * is FvwmAnimate which always does a grab of its own. To avoid a + * deadlock, iconify events are not sent to a lock on send module while + * the server is grabbed. In the future, it might make sense to send + * the fact that the server is grabbed to the lock on send module, or + * in some other way get finer control. + */ + if ((PipeMask[module] & M_LOCKONSEND) && /* module uses lock on send */ + (myxgrabcount != 0) && /* and server grabbed */ + (ptr[1] & M_ICONIFY)) { /* and its an iconify event */ + return -1; /* don't send it */ + } + AddToQueue(module, ptr, size, 0); + /* dje, from afterstep, for FvwmAnimate, + allows the module to synchronize with fvwm. + */ + if (PipeMask[module] & M_LOCKONSEND) { + Window targetWindow; + int e; + + FlushQueue(module); + fcntl(readPipes[module], F_SETFL, 0); + while ((e = read(readPipes[module], &targetWindow, + sizeof(Window))) > 0) { + if (HandleModuleInput(targetWindow, module) == 66) { + break; + } + } + if (e <= 0) { + KillModule(module, 10); + } + fcntl(readPipes[module], F_SETFL, O_NDELAY); + } + return size; } - -void AddToQueue(int module, unsigned long *ptr, int size, int done) +void +AddToQueue(int module, unsigned long *ptr, int size, int done) { - struct queue_buff_struct *c,*e; - unsigned long *d; - - c = (struct queue_buff_struct *)safemalloc(sizeof(struct queue_buff_struct)); - c->next = NULL; - c->size = size; - c->done = done; - d = (unsigned long *)safemalloc(size); - c->data = d; - memcpy((void*)d,(const void*)ptr,size); - - e = pipeQueue[module]; - if(e == NULL) - { - pipeQueue[module] = c; - return; - } - while(e->next != NULL) - e = e->next; - e->next = c; + struct queue_buff_struct *c, *e; + unsigned long *d; + + c = (struct queue_buff_struct *)xmalloc( + sizeof(struct queue_buff_struct)); + c->next = NULL; + c->size = size; + c->done = done; + d = (unsigned long *)xmalloc(size); + c->data = d; + memcpy((void *)d, (const void *)ptr, size); + + e = pipeQueue[module]; + if (e == NULL) { + pipeQueue[module] = c; + return; + } + while (e->next != NULL) + e = e->next; + e->next = c; } -void DeleteQueueBuff(int module) +void +DeleteQueueBuff(int module) { - struct queue_buff_struct *a; - - if(pipeQueue[module] == NULL) - return; - a = pipeQueue[module]; - pipeQueue[module] = a->next; - free(a->data); - free(a); - return; + struct queue_buff_struct *a; + + if (pipeQueue[module] == NULL) + return; + a = pipeQueue[module]; + pipeQueue[module] = a->next; + free(a->data); + free(a); + return; } -void FlushQueue(int module) +void +FlushQueue(int module) { - char *dptr; - struct queue_buff_struct *d; - int a; - - if((pipeOn[module] <= 0)||(pipeQueue[module] == NULL)) - return; - - while(pipeQueue[module] != NULL) - { - d = pipeQueue[module]; - dptr = (char *)d->data; - while(d->done < d->size) - { - a = write(writePipes[module],&dptr[d->done], d->size - d->done); - if(a >=0) - d->done += a; - /* the write returns EWOULDBLOCK or EAGAIN if the pipe is full. - * (This is non-blocking I/O). SunOS returns EWOULDBLOCK, OSF/1 - * returns EAGAIN under these conditions. Hopefully other OSes - * return one of these values too. Solaris 2 doesn't seem to have - * a man page for write(2) (!) */ - else if ((errno == EWOULDBLOCK)||(errno == EAGAIN)||(errno==EINTR)) - { - return; - } - else - { - KillModule(module,123); - return; - } + char *dptr; + struct queue_buff_struct *d; + int a; + + if ((pipeOn[module] <= 0) || (pipeQueue[module] == NULL)) + return; + + while (pipeQueue[module] != NULL) { + d = pipeQueue[module]; + dptr = (char *)d->data; + while (d->done < d->size) { + a = write(writePipes[module], &dptr[d->done], + d->size - d->done); + if (a >= 0) + d->done += a; + /* the write returns EWOULDBLOCK or EAGAIN if the pipe + * is full. (This is non-blocking I/O). SunOS returns + * EWOULDBLOCK, OSF/1 returns EAGAIN under these + * conditions. Hopefully other OSes return one of these + * values too. Solaris 2 doesn't seem to have a man page + * for write(2) (!) */ + else if ((errno == EWOULDBLOCK) || (errno == EAGAIN) || + (errno == EINTR)) { + return; + } else { + KillModule(module, 123); + return; + } + } + DeleteQueueBuff(module); } - DeleteQueueBuff(module); - } } - -void send_list_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, - unsigned long context, char *action, int *Module) +void +send_list_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - FvwmWindow *t; - - if(*Module >= 0) - { - SendPacket(*Module, M_NEW_DESK, 1, Scr.CurrentDesk); - SendPacket(*Module, M_NEW_PAGE, 5, - Scr.Vx, Scr.Vy, Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); - - if(Scr.Hilite != NULL) - SendPacket(*Module, M_FOCUS_CHANGE, 5, - Scr.Hilite->w, - Scr.Hilite->frame, - (unsigned long)Scr.Hilite, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - else - SendPacket(*Module, M_FOCUS_CHANGE, 5, - 0, 0, 0, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - if (Scr.DefaultIcon != NULL) - SendName(*Module, M_DEFAULTICON, 0, 0, 0, Scr.DefaultIcon); - - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - SendConfig(*Module,M_CONFIGURE_WINDOW,t); - SendName(*Module,M_WINDOW_NAME,t->w,t->frame, - (unsigned long)t,t->name); - SendName(*Module,M_ICON_NAME,t->w,t->frame, - (unsigned long)t,t->icon_name); - - if (t->icon_bitmap_file != NULL - && t->icon_bitmap_file != Scr.DefaultIcon) - SendName(*Module,M_ICON_FILE,t->w,t->frame, - (unsigned long)t,t->icon_bitmap_file); - - SendName(*Module,M_RES_CLASS,t->w,t->frame, - (unsigned long)t,t->class.res_class); - SendName(*Module,M_RES_NAME,t->w,t->frame, - (unsigned long)t,t->class.res_name); - - if((t->flags & ICONIFIED)&&(!(t->flags & ICON_UNMAPPED))) - SendPacket(*Module, M_ICONIFY, 7, t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_w_width, t->icon_w_height+t->icon_p_height); - - if((t->flags & ICONIFIED) && (t->flags & ICON_UNMAPPED)) - SendPacket(*Module, M_ICONIFY, 7, t->w, t->frame, - (unsigned long)t, - 0, 0, 0, 0); + FvwmWindow *t; + + if (*Module >= 0) { + SendPacket(*Module, M_NEW_DESK, 1, Scr.CurrentDesk); + SendPacket(*Module, M_NEW_PAGE, 5, Scr.Vx, Scr.Vy, + Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); + + if (Scr.Hilite != NULL) + SendPacket(*Module, M_FOCUS_CHANGE, 5, Scr.Hilite->w, + Scr.Hilite->frame, (unsigned long)Scr.Hilite, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + else + SendPacket(*Module, M_FOCUS_CHANGE, 5, 0, 0, 0, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + if (Scr.DefaultIcon != NULL) + SendName( + *Module, M_DEFAULTICON, 0, 0, 0, Scr.DefaultIcon); + + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + SendConfig(*Module, M_CONFIGURE_WINDOW, t); + SendName(*Module, M_WINDOW_NAME, t->w, t->frame, + (unsigned long)t, t->name); + SendName(*Module, M_ICON_NAME, t->w, t->frame, + (unsigned long)t, t->icon_name); + + if (t->icon_bitmap_file != NULL && + t->icon_bitmap_file != Scr.DefaultIcon) + SendName(*Module, M_ICON_FILE, t->w, t->frame, + (unsigned long)t, t->icon_bitmap_file); + + SendName(*Module, M_RES_CLASS, t->w, t->frame, + (unsigned long)t, t->class.res_class); + SendName(*Module, M_RES_NAME, t->w, t->frame, + (unsigned long)t, t->class.res_name); + + if ((t->flags & ICONIFIED) && + (!(t->flags & ICON_UNMAPPED))) + SendPacket(*Module, M_ICONIFY, 7, t->w, + t->frame, (unsigned long)t, t->icon_x_loc, + t->icon_y_loc, t->icon_w_width, + t->icon_w_height + t->icon_p_height); + + if ((t->flags & ICONIFIED) && + (t->flags & ICON_UNMAPPED)) + SendPacket(*Module, M_ICONIFY, 7, t->w, + t->frame, (unsigned long)t, 0, 0, 0, 0); #ifdef MINI_ICONS - if (t->mini_icon != NULL) - SendMiniIcon(*Module, M_MINI_ICON, - t->w, t->frame, (unsigned long)t, - t->mini_icon->width, - t->mini_icon->height, - t->mini_icon->depth, - t->mini_icon->picture, - t->mini_icon->mask, - t->mini_pixmap_file); + if (t->mini_icon != NULL) + SendMiniIcon(*Module, M_MINI_ICON, t->w, + t->frame, (unsigned long)t, + t->mini_icon->width, t->mini_icon->height, + t->mini_icon->depth, t->mini_icon->picture, + t->mini_icon->mask, t->mini_pixmap_file); #endif + } + + if (Scr.Hilite == NULL) + BroadcastPacket(M_FOCUS_CHANGE, 5, 0, 0, 0, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + else + BroadcastPacket(M_FOCUS_CHANGE, 5, Scr.Hilite->w, + Scr.Hilite->frame, (unsigned long)Scr.Hilite, + Scr.DefaultDecor.HiColors.fore, + Scr.DefaultDecor.HiColors.back); + + SendPacket(*Module, M_END_WINDOWLIST, 0); } - - if(Scr.Hilite == NULL) - BroadcastPacket(M_FOCUS_CHANGE, 5, - 0, 0, 0, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - else - BroadcastPacket(M_FOCUS_CHANGE, 5, - Scr.Hilite->w, - Scr.Hilite->frame, - (unsigned long)Scr.Hilite, - Scr.DefaultDecor.HiColors.fore, - Scr.DefaultDecor.HiColors.back); - - SendPacket(*Module, M_END_WINDOWLIST, 0); - } } -void set_mask_function(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) + +void +set_mask_function(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val = 0; + int val = 0; - GetIntegerArguments(action, NULL, &val, 1); - PipeMask[*Module] = (unsigned long)val; + GetIntegerArguments(action, NULL, &val, 1); + PipeMask[*Module] = (unsigned long)val; } Index: fvwm/fvwm/module.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/module.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/module.h --- fvwm/fvwm/module.h +++ fvwm/fvwm/module.h @@ -1,12 +1,11 @@ #ifndef MODULE_H #define MODULE_H -struct queue_buff_struct -{ - struct queue_buff_struct *next; - unsigned long *data; - int size; - int done; +struct queue_buff_struct { + struct queue_buff_struct *next; + unsigned long *data; + int size; + int done; }; extern int npipes; @@ -16,43 +15,43 @@ extern struct queue_buff_struct **pipeQueue; #define START_FLAG 0xffffffff -#define M_NEW_PAGE (1) -#define M_NEW_DESK (1<<1) -#define M_ADD_WINDOW (1<<2) -#define M_RAISE_WINDOW (1<<3) -#define M_LOWER_WINDOW (1<<4) -#define M_CONFIGURE_WINDOW (1<<5) -#define M_FOCUS_CHANGE (1<<6) -#define M_DESTROY_WINDOW (1<<7) -#define M_ICONIFY (1<<8) -#define M_DEICONIFY (1<<9) -#define M_WINDOW_NAME (1<<10) -#define M_ICON_NAME (1<<11) -#define M_RES_CLASS (1<<12) -#define M_RES_NAME (1<<13) -#define M_END_WINDOWLIST (1<<14) -#define M_ICON_LOCATION (1<<15) -#define M_MAP (1<<16) +#define M_NEW_PAGE (1) +#define M_NEW_DESK (1 << 1) +#define M_ADD_WINDOW (1 << 2) +#define M_RAISE_WINDOW (1 << 3) +#define M_LOWER_WINDOW (1 << 4) +#define M_CONFIGURE_WINDOW (1 << 5) +#define M_FOCUS_CHANGE (1 << 6) +#define M_DESTROY_WINDOW (1 << 7) +#define M_ICONIFY (1 << 8) +#define M_DEICONIFY (1 << 9) +#define M_WINDOW_NAME (1 << 10) +#define M_ICON_NAME (1 << 11) +#define M_RES_CLASS (1 << 12) +#define M_RES_NAME (1 << 13) +#define M_END_WINDOWLIST (1 << 14) +#define M_ICON_LOCATION (1 << 15) +#define M_MAP (1 << 16) /* It turns out this is defined by on Solaris 2.6. - I suspect that simply redefining this will lead to trouble; + I suspect that simply redefining this will lead to trouble; at some point, these should probably be renamed (FVWM_MSG_ERROR?). */ #ifdef M_ERROR -# undef M_ERROR +#undef M_ERROR #endif -#define M_ERROR (1<<17) +#define M_ERROR (1 << 17) -#define M_CONFIG_INFO (1<<18) -#define M_END_CONFIG_INFO (1<<19) -#define M_ICON_FILE (1<<20) -#define M_DEFAULTICON (1<<21) -#define M_STRING (1<<22) -#define M_MINI_ICON (1<<23) -#define M_WINDOWSHADE (1<<24) -#define M_DEWINDOWSHADE (1<<25) -#define M_LOCKONSEND (1<<26) -#define M_SENDCONFIG (1<<27) -#define MAX_MESSAGES 28 +#define M_CONFIG_INFO (1 << 18) +#define M_END_CONFIG_INFO (1 << 19) +#define M_ICON_FILE (1 << 20) +#define M_DEFAULTICON (1 << 21) +#define M_STRING (1 << 22) +#define M_MINI_ICON (1 << 23) +#define M_WINDOWSHADE (1 << 24) +#define M_DEWINDOWSHADE (1 << 25) +#define M_LOCKONSEND (1 << 26) +#define M_SENDCONFIG (1 << 27) +#define MAX_MESSAGES 28 /* * MAX_MASK is used to initialize the pipeMask array. In a few places @@ -71,8 +70,7 @@ extern struct queue_buff_struct **pipeQueue; * creating and looping over large arrays. The impact seems to be in * module.c, modconf.c and event.c. dje 10/2/98 */ -#define MAX_MASK (((1< +#include #include +#include #include #include -#include + +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" extern XEvent Event; extern int menuFromFrameOrWindowOrTitlebar; @@ -33,374 +33,379 @@ Bool NeedToResizeToo; /* Animated move stuff added by Greg J. Badros, gjb@cs.washington.edu */ float rgpctMovementDefault[32] = { - -.01, 0, .01, .03,.08,.18,.3,.45,.60,.75,.85,.90,.94,.97,.99,1.0 + -.01, 0, .01, .03, .08, .18, .3, .45, .60, .75, .85, .90, .94, .97, .99, 1.0 /* must end in 1.0 */ - }; +}; int cmsDelayDefault = 10; /* milliseconds */ /* Perform the movement of the window. ppctMovement *must* have a 1.0 entry * somewhere in ins list of floats, and movement will stop when it hits a 1.0 * entry */ -void AnimatedMoveOfWindow(Window w,int startX,int startY,int endX, int endY, - Bool fWarpPointerToo, int cmsDelay, - float *ppctMovement ) +void +AnimatedMoveOfWindow(Window w, int startX, int startY, int endX, int endY, + Bool fWarpPointerToo, int cmsDelay, float *ppctMovement) { - int pointerX, pointerY; - int currentX, currentY; - int lastX, lastY; - int deltaX, deltaY; - - /* set our defaults */ - if (ppctMovement == NULL) ppctMovement = rgpctMovementDefault; - if (cmsDelay < 0) cmsDelay = cmsDelayDefault; - - if (startX < 0 || startY < 0) - { - XGetGeometry(dpy, w, &JunkRoot, ¤tX, ¤tY, - &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); - if (startX < 0) startX = currentX; - if (startY < 0) startY = currentY; - } - - deltaX = endX - startX; - deltaY = endY - startY; - lastX = startX; - lastY = startY; - - if (deltaX == 0 && deltaY == 0) return; /* go nowhere fast */ - do { - currentX = startX + deltaX * (*ppctMovement); - currentY = startY + deltaY * (*ppctMovement); - XMoveWindow(dpy,w,currentX,currentY); - if (fWarpPointerToo == TRUE) { - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX,&JunkY,&pointerX,&pointerY,&JunkMask); - pointerX += currentX - lastX; - pointerY += currentY - lastY; - XWarpPointer(dpy,None,Scr.Root,0,0,0,0, - pointerX,pointerY); - } - XFlush(dpy); - usleep(cmsDelay*1000); /* usleep takes microseconds */ + int pointerX, pointerY; + int currentX, currentY; + int lastX, lastY; + int deltaX, deltaY; + + /* set our defaults */ + if (ppctMovement == NULL) + ppctMovement = rgpctMovementDefault; + if (cmsDelay < 0) + cmsDelay = cmsDelayDefault; + + if (startX < 0 || startY < 0) { + XGetGeometry(dpy, w, &JunkRoot, ¤tX, ¤tY, + &JunkWidth, &JunkHeight, &JunkBW, &JunkDepth); + if (startX < 0) + startX = currentX; + if (startY < 0) + startY = currentY; + } + + deltaX = endX - startX; + deltaY = endY - startY; + lastX = startX; + lastY = startY; + + if (deltaX == 0 && deltaY == 0) + return; /* go nowhere fast */ + do { + currentX = startX + deltaX * (*ppctMovement); + currentY = startY + deltaY * (*ppctMovement); + XMoveWindow(dpy, w, currentX, currentY); + if (fWarpPointerToo == TRUE) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, + &JunkX, &JunkY, &pointerX, &pointerY, &JunkMask); + pointerX += currentX - lastX; + pointerY += currentY - lastY; + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, pointerX, + pointerY); + } + XFlush(dpy); + usleep(cmsDelay * 1000); /* usleep takes microseconds */ #ifdef GJB_ALLOW_ABORTING_ANIMATED_MOVES - /* this didn't work for me -- maybe no longer necessary since - we warn the user when they use > .5 seconds as a between-frame delay - time */ - if (XCheckMaskEvent(dpy, - ButtonPressMask|ButtonReleaseMask|KeyPressMask, - &Event)) { - /* finish the move immediately */ - XMoveWindow(dpy,w,endX,endY); - XFlush(dpy); - return; - } + /* this didn't work for me -- maybe no longer necessary since + we warn the user when they use > .5 seconds as a + between-frame delay time */ + if (XCheckMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | KeyPressMask, + &Event)) { + /* finish the move immediately */ + XMoveWindow(dpy, w, endX, endY); + XFlush(dpy); + return; + } #endif - lastX = currentX; - lastY = currentY; - } - while (*ppctMovement != 1.0 && ppctMovement++); - + lastX = currentX; + lastY = currentY; + } while (*ppctMovement != 1.0 && ppctMovement++); } - /**************************************************************************** * * Start a window move operation * ****************************************************************************/ -void move_window_doit(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module, - Bool fAnimated, Bool fMoveToPage) +void +move_window_doit(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module, Bool fAnimated, + Bool fMoveToPage) { - int FinalX, FinalY; - int n; - int x,y; - int width, height; - int page[2]; - Bool fWarp = FALSE; - - if (DeferExecution(eventp,&w,&tmp_win,&context, MOVE,ButtonPress)) - return; - - if (tmp_win == NULL) - return; - - /* gotta have a window */ - w = tmp_win->frame; - if(tmp_win->flags & ICONIFIED) - { - if(tmp_win->icon_pixmap_w != None) - { - XUnmapWindow(dpy,tmp_win->icon_w); - w = tmp_win->icon_pixmap_w; + int FinalX, FinalY; + int n; + int x, y; + int width, height; + int page[2]; + Bool fWarp = FALSE; + + if (DeferExecution(eventp, &w, &tmp_win, &context, MOVE, ButtonPress)) + return; + + if (tmp_win == NULL) + return; + + /* gotta have a window */ + w = tmp_win->frame; + if (tmp_win->flags & ICONIFIED) { + if (tmp_win->icon_pixmap_w != None) { + XUnmapWindow(dpy, tmp_win->icon_w); + w = tmp_win->icon_pixmap_w; + } else + w = tmp_win->icon_w; } - else - w = tmp_win->icon_w; - } - - XGetGeometry(dpy, w, &JunkRoot, &x, &y, - &width, &height, &JunkBW, &JunkDepth); - if (fMoveToPage) - { - fAnimated = FALSE; - FinalX = x % Scr.MyDisplayWidth; - FinalY = y % Scr.MyDisplayHeight; - if (GetIntegerArguments(action, NULL, page, 2) == 2) - { - if (page[0] < 0 || page[1] < 0 || - page[0]*Scr.MyDisplayWidth > Scr.VxMax || - page[1]*Scr.MyDisplayHeight > Scr.VyMax) - { - fvwm_msg(ERR, "move_window_doit", - "MoveToPage: invalid page number"); - return; - } - tmp_win->flags &= ~STICKY; - FinalX += page[0]*Scr.MyDisplayWidth - Scr.Vx; - FinalY += page[1]*Scr.MyDisplayHeight - Scr.Vy; - } - } - else - { - n = GetMoveArguments(action,x,y,width+tmp_win->bw,height+tmp_win->bw, - &FinalX,&FinalY,&fWarp); - if (n != 2) - InteractiveMove(&w,tmp_win,&FinalX,&FinalY,eventp); - } - - if (w == tmp_win->frame) - { - if (fAnimated) { - AnimatedMoveOfWindow(w,-1,-1,FinalX,FinalY,fWarp,-1,NULL); - } - SetupFrame (tmp_win, FinalX, FinalY, - tmp_win->frame_width, tmp_win->frame_height,FALSE); - if (fWarp & !fAnimated) - XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, FinalY - y); - } - else /* icon window */ - { - tmp_win->flags |= ICON_MOVED; - tmp_win->icon_x_loc = FinalX ; - tmp_win->icon_xl_loc = FinalX - - (tmp_win->icon_w_width - tmp_win->icon_p_width)/2; - tmp_win->icon_y_loc = FinalY; - BroadcastPacket(M_ICON_LOCATION, 7, - tmp_win->w, tmp_win->frame, - (unsigned long)tmp_win, - tmp_win->icon_x_loc, tmp_win->icon_y_loc, - tmp_win->icon_w_width, - tmp_win->icon_w_height + tmp_win->icon_p_height); - if (fAnimated) { - AnimatedMoveOfWindow(tmp_win->icon_w,-1,-1,tmp_win->icon_xl_loc, - FinalY+tmp_win->icon_p_height, fWarp,-1,NULL); - } else { - XMoveWindow(dpy,tmp_win->icon_w, tmp_win->icon_xl_loc, - FinalY+tmp_win->icon_p_height); - if (fWarp) - XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, FinalY - y); - } - if(tmp_win->icon_pixmap_w != None) - { - XMapWindow(dpy,tmp_win->icon_w); - if (fAnimated) { - AnimatedMoveOfWindow(tmp_win->icon_pixmap_w, -1,-1, - tmp_win->icon_x_loc,FinalY,fWarp,-1,NULL); - } else { - XMoveWindow(dpy, tmp_win->icon_pixmap_w, tmp_win->icon_x_loc, - FinalY); - if (fWarp) - XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, - FinalY - y); - } - XMapWindow(dpy,w); + + XGetGeometry( + dpy, w, &JunkRoot, &x, &y, &width, &height, &JunkBW, &JunkDepth); + if (fMoveToPage) { + fAnimated = FALSE; + FinalX = x % Scr.MyDisplayWidth; + FinalY = y % Scr.MyDisplayHeight; + if (GetIntegerArguments(action, NULL, page, 2) == 2) { + if (page[0] < 0 || page[1] < 0 || + page[0] * Scr.MyDisplayWidth > Scr.VxMax || + page[1] * Scr.MyDisplayHeight > Scr.VyMax) { + fvwm_msg(ERR, "move_window_doit", + "MoveToPage: invalid page number"); + return; + } + tmp_win->flags &= ~STICKY; + FinalX += page[0] * Scr.MyDisplayWidth - Scr.Vx; + FinalY += page[1] * Scr.MyDisplayHeight - Scr.Vy; + } + } else { + n = GetMoveArguments(action, x, y, width + tmp_win->bw, + height + tmp_win->bw, &FinalX, &FinalY, &fWarp); + if (n != 2) + InteractiveMove(&w, tmp_win, &FinalX, &FinalY, eventp); } - } + if (w == tmp_win->frame) { + if (fAnimated) { + AnimatedMoveOfWindow( + w, -1, -1, FinalX, FinalY, fWarp, -1, NULL); + } + SetupFrame(tmp_win, FinalX, FinalY, tmp_win->frame_width, + tmp_win->frame_height, FALSE); + if (fWarp & !fAnimated) + XWarpPointer(dpy, None, None, 0, 0, 0, 0, FinalX - x, + FinalY - y); + } else /* icon window */ { + tmp_win->flags |= ICON_MOVED; + tmp_win->icon_x_loc = FinalX; + tmp_win->icon_xl_loc = + FinalX - + (tmp_win->icon_w_width - tmp_win->icon_p_width) / 2; + tmp_win->icon_y_loc = FinalY; + BroadcastPacket(M_ICON_LOCATION, 7, tmp_win->w, tmp_win->frame, + (unsigned long)tmp_win, tmp_win->icon_x_loc, + tmp_win->icon_y_loc, tmp_win->icon_w_width, + tmp_win->icon_w_height + tmp_win->icon_p_height); + if (fAnimated) { + AnimatedMoveOfWindow(tmp_win->icon_w, -1, -1, + tmp_win->icon_xl_loc, + FinalY + tmp_win->icon_p_height, fWarp, -1, NULL); + } else { + XMoveWindow(dpy, tmp_win->icon_w, tmp_win->icon_xl_loc, + FinalY + tmp_win->icon_p_height); + if (fWarp) + XWarpPointer(dpy, None, None, 0, 0, 0, 0, + FinalX - x, FinalY - y); + } + if (tmp_win->icon_pixmap_w != None) { + XMapWindow(dpy, tmp_win->icon_w); + if (fAnimated) { + AnimatedMoveOfWindow(tmp_win->icon_pixmap_w, -1, + -1, tmp_win->icon_x_loc, FinalY, fWarp, -1, + NULL); + } else { + XMoveWindow(dpy, tmp_win->icon_pixmap_w, + tmp_win->icon_x_loc, FinalY); + if (fWarp) + XWarpPointer(dpy, None, None, 0, 0, 0, + 0, FinalX - x, FinalY - y); + } + XMapWindow(dpy, w); + } + } - return; + return; } -void move_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +move_window(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - move_window_doit(eventp,w,tmp_win,context,action,Module,FALSE,FALSE); + move_window_doit( + eventp, w, tmp_win, context, action, Module, FALSE, FALSE); } -void animated_move_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +animated_move_window(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - move_window_doit(eventp,w,tmp_win,context,action,Module,TRUE,FALSE); + move_window_doit( + eventp, w, tmp_win, context, action, Module, TRUE, FALSE); } -void move_window_to_page(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +move_window_to_page(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - move_window_doit(eventp,w,tmp_win,context,action,Module,FALSE,TRUE); + move_window_doit( + eventp, w, tmp_win, context, action, Module, FALSE, TRUE); } -typedef struct _FvwmMoveable -{ - int w; - int h; - int x; - int y; +typedef struct _FvwmMoveable { + int w; + int h; + int x; + int y; } FvwmMoveable; /* This function does the SnapAttraction stuff. If takes x and y coordinates * (*px and *py) and returns the snapped values. */ -static void DoSnapAttract(FvwmWindow *tmp_win, int Width, int Height, - int *px, int *py) +static void +DoSnapAttract(FvwmWindow *tmp_win, int Width, int Height, int *px, int *py) { - int nyt,nxl,dist,closestLeft,closestRight,closestBottom,closestTop; - FvwmMoveable self, other; - FvwmWindow *tmp; - - /* START OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ - /* resist based on window edges */ - tmp = Scr.FvwmRoot.next; - closestTop = Scr.SnapAttraction; - closestBottom = Scr.SnapAttraction; - closestRight = Scr.SnapAttraction; - closestLeft = Scr.SnapAttraction; - nxl = -1; - nyt = -1; - self.x = *px; - self.y = *py; - if(tmp_win->flags&ICONIFIED) - { - self.w = Width; - self.h = Height; - } - else - { - self.w = Width + 2 * tmp_win->bw; - self.h = Height + 2 * tmp_win->bw; - } - while(Scr.SnapAttraction >= 0 && tmp) - { - if(Scr.SnapMode == 0) /* All */ - { - /* NOOP */ + int nyt, nxl, dist, closestLeft, closestRight, closestBottom, + closestTop; + FvwmMoveable self, other; + FvwmWindow *tmp; + + /* START OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ + /* resist based on window edges */ + tmp = Scr.FvwmRoot.next; + closestTop = Scr.SnapAttraction; + closestBottom = Scr.SnapAttraction; + closestRight = Scr.SnapAttraction; + closestLeft = Scr.SnapAttraction; + nxl = -1; + nyt = -1; + self.x = *px; + self.y = *py; + if (tmp_win->flags & ICONIFIED) { + self.w = Width; + self.h = Height; + } else { + self.w = Width + 2 * tmp_win->bw; + self.h = Height + 2 * tmp_win->bw; } - if(Scr.SnapMode == 1) /* SameType */ - { - if( (tmp->flags&ICONIFIED) != (tmp_win->flags&ICONIFIED) ) - { tmp = tmp->next; continue; } - } - if(Scr.SnapMode == 2) /* Icons */ - { - if( !(tmp->flags&ICONIFIED) || !(tmp_win->flags&ICONIFIED) ) - { tmp = tmp->next; continue; } - } - if(Scr.SnapMode == 3) /* Windows */ - { - if( (tmp->flags&ICONIFIED) || (tmp_win->flags&ICONIFIED) ) - { tmp = tmp->next; continue; } - } - if (tmp_win != tmp && (tmp_win->Desk == tmp->Desk)) - { - if(tmp->flags&ICONIFIED) - { - if(tmp->icon_p_height > 0) - { - other.w = tmp->icon_p_width; - other.h = tmp->icon_p_height; - } - else - { - other.w = tmp->icon_w_width; - other.h = tmp->icon_w_height; + while (Scr.SnapAttraction >= 0 && tmp) { + if (Scr.SnapMode == 0) { /* All */ + /* NOOP */ } - other.x = tmp->icon_x_loc; - other.y = tmp->icon_y_loc; - } - else - { - other.w = tmp->frame_width + 2 * tmp->bw; - other.h = tmp->frame_height + 2 * tmp->bw; - other.x = tmp->frame_x; - other.y = tmp->frame_y; - } - if(!((other.y + other.h) < (*py) || - (other.y) > (*py + self.h) )) - { - dist = abs(other.x - (*px + self.w)); - if(dist < closestRight) - { - closestRight = dist; - if(((*px + self.w) >= other.x)&& - ((*px + self.w) < other.x+Scr.SnapAttraction)) - nxl = other.x - self.w; - - if(((*px + self.w) >= other.x - Scr.SnapAttraction)&& - ((*px + self.w) < other.x)) - nxl = other.x - self.w; + if (Scr.SnapMode == 1) { /* SameType */ + if ((tmp->flags & ICONIFIED) != + (tmp_win->flags & ICONIFIED)) { + tmp = tmp->next; + continue; + } } - dist = abs(other.x + other.w - *px); - if(dist < closestLeft) - { - closestLeft = dist; - if((*px <= other.x + other.w)&& - (*px > other.x + other.w - Scr.SnapAttraction)) - nxl = other.x + other.w; - if((*px <= other.x + other.w + Scr.SnapAttraction)&& - (*px > other.x + other.w)) - nxl = other.x + other.w; + if (Scr.SnapMode == 2) { /* Icons */ + if (!(tmp->flags & ICONIFIED) || + !(tmp_win->flags & ICONIFIED)) { + tmp = tmp->next; + continue; + } } - } - if(!((other.x + other.w) < (*px) || (other.x) > (*px + self.w) )) - { - dist = abs(other.y - (*py + self.h)); - if(dist < closestBottom) - { - closestBottom = dist; - if(((*py + self.h) >= other.y)&& - ((*py + self.h) < other.y+Scr.SnapAttraction)) - nyt = other.y - self.h; - if(((*py + self.h) >= other.y - Scr.SnapAttraction)&& - ((*py + self.h) < other.y)) - nyt = other.y - self.h; + if (Scr.SnapMode == 3) { /* Windows */ + if ((tmp->flags & ICONIFIED) || + (tmp_win->flags & ICONIFIED)) { + tmp = tmp->next; + continue; + } } - dist = abs(other.y + other.h - *py); - if(dist < closestTop) - { - closestTop = dist; - if((*py <= other.y + other.h)&& - (*py > other.y + other.h - Scr.SnapAttraction)) - nyt = other.y + other.h; - if((*py <= other.y + other.h + Scr.SnapAttraction)&& - (*py > other.y + other.h)) - nyt = other.y + other.h; + if (tmp_win != tmp && (tmp_win->Desk == tmp->Desk)) { + if (tmp->flags & ICONIFIED) { + if (tmp->icon_p_height > 0) { + other.w = tmp->icon_p_width; + other.h = tmp->icon_p_height; + } else { + other.w = tmp->icon_w_width; + other.h = tmp->icon_w_height; + } + other.x = tmp->icon_x_loc; + other.y = tmp->icon_y_loc; + } else { + other.w = tmp->frame_width + 2 * tmp->bw; + other.h = tmp->frame_height + 2 * tmp->bw; + other.x = tmp->frame_x; + other.y = tmp->frame_y; + } + if (!((other.y + other.h) < (*py) || + (other.y) > (*py + self.h))) { + dist = abs(other.x - (*px + self.w)); + if (dist < closestRight) { + closestRight = dist; + if (((*px + self.w) >= other.x) && + ((*px + self.w) < + other.x + Scr.SnapAttraction)) + nxl = other.x - self.w; + + if (((*px + self.w) >= + other.x - Scr.SnapAttraction) && + ((*px + self.w) < other.x)) + nxl = other.x - self.w; + } + dist = abs(other.x + other.w - *px); + if (dist < closestLeft) { + closestLeft = dist; + if ((*px <= other.x + other.w) && + (*px > other.x + other.w - + Scr.SnapAttraction)) + nxl = other.x + other.w; + if ((*px <= other.x + other.w + + Scr.SnapAttraction) && + (*px > other.x + other.w)) + nxl = other.x + other.w; + } + } + if (!((other.x + other.w) < (*px) || + (other.x) > (*px + self.w))) { + dist = abs(other.y - (*py + self.h)); + if (dist < closestBottom) { + closestBottom = dist; + if (((*py + self.h) >= other.y) && + ((*py + self.h) < + other.y + Scr.SnapAttraction)) + nyt = other.y - self.h; + if (((*py + self.h) >= + other.y - Scr.SnapAttraction) && + ((*py + self.h) < other.y)) + nyt = other.y - self.h; + } + dist = abs(other.y + other.h - *py); + if (dist < closestTop) { + closestTop = dist; + if ((*py <= other.y + other.h) && + (*py > other.y + other.h - + Scr.SnapAttraction)) + nyt = other.y + other.h; + if ((*py <= other.y + other.h + + Scr.SnapAttraction) && + (*py > other.y + other.h)) + nyt = other.y + other.h; + } + } } - } + tmp = tmp->next; } - tmp = tmp->next; - } - if(nxl == -1) - { - if(*px != *px / Scr.SnapGridX * Scr.SnapGridX) - { - *px = (*px+Scr.SnapGridX/2) / Scr.SnapGridX * Scr.SnapGridX; + if (nxl == -1) { + if (*px != *px / Scr.SnapGridX * Scr.SnapGridX) { + *px = (*px + Scr.SnapGridX / 2) / Scr.SnapGridX * + Scr.SnapGridX; + } + } else { + *px = nxl; } - } - else - { - *px = nxl; - } - if(nyt == -1) - { - if(*py != *py / Scr.SnapGridY * Scr.SnapGridY) - { - *py = (*py+Scr.SnapGridY/2) / Scr.SnapGridY * Scr.SnapGridY; + if (nyt == -1) { + if (*py != *py / Scr.SnapGridY * Scr.SnapGridY) { + *py = (*py + Scr.SnapGridY / 2) / Scr.SnapGridY * + Scr.SnapGridY; + } + } else { + *py = nyt; } - } - else - { - *py = nyt; - } - /* END OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ + /* END OF SNAPATTRACTION BLOCK, mirrored in ButtonRelease */ +} + +static void +ClampToScreen(int *x, int *y, int width, int height, int bw) +{ + int margin = 32; + + if (*x + width < margin) + *x = margin - width + 1; + if (*x > Scr.MyDisplayWidth - margin) + *x = Scr.MyDisplayWidth - margin; + if (*y + height < margin) + *y = margin - height + 1; + if (*y > Scr.MyDisplayHeight - margin) + *y = Scr.MyDisplayHeight - margin; } /**************************************************************************** @@ -408,218 +413,251 @@ static void DoSnapAttract(FvwmWindow *tmp_win, int Width, int Height, * Move the rubberband around, return with the new window location * ****************************************************************************/ -void moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width, - int Height, int *FinalX, int *FinalY,Bool opaque_move, - Bool AddWindow) +void +moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width, int Height, + int *FinalX, int *FinalY, Bool opaque_move, Bool AddWindow) { - Bool finished = False; - Bool done; - int xl,yt,delta_x,delta_y,paged; - unsigned int button_mask = 0; - unsigned int bw = tmp_win->bw; - - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild,&xl, &yt, - &JunkX, &JunkY, &button_mask); - button_mask &= Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask; - xl += XOffset; - yt += YOffset; - - if(((!opaque_move)&&(!Scr.gs.EmulateMWM))||(AddWindow)) - MoveOutline(Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); - - DisplayPosition(tmp_win,xl,yt,True); - - while (!finished) - { - /* block until there is an interesting event */ - XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | KeyPressMask | - PointerMotionMask | ButtonMotionMask | ExposureMask, &Event); - StashEventTime(&Event); - - /* discard any extra motion events before a logical release */ - if (Event.type == MotionNotify) - { - while(XCheckMaskEvent(dpy, PointerMotionMask | ButtonMotionMask | - ButtonPressMask |ButtonRelease, &Event)) - { - StashEventTime(&Event); - if(Event.type == ButtonRelease) break; - } - } - - done = FALSE; - /* Handle a limited number of key press events to allow mouseless - * operation */ - if (Event.type == KeyPress) - Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); - switch(Event.type) - { - case KeyPress: - /* simple code to bag out of move - CKH */ - if (XLookupKeysym(&(Event.xkey),0) == XK_Escape) - { - if(!opaque_move) - MoveOutline(Scr.Root, 0, 0, 0, 0); - *FinalX = tmp_win->frame_x; - *FinalY = tmp_win->frame_y; - finished = TRUE; - } - done = TRUE; - break; - case ButtonPress: - XAllowEvents(dpy,ReplayPointer,CurrentTime); - if (((Event.xbutton.button == 1) && (button_mask & Button1Mask)) || - ((Event.xbutton.button == 2) && (button_mask & Button2Mask)) || - ((Event.xbutton.button == 3) && (button_mask & Button3Mask)) || - ((Event.xbutton.button == 4) && (button_mask & Button4Mask)) || - ((Event.xbutton.button == 5) && (button_mask & Button5Mask))) - { - /* No new button was pressed, just a delayed event */ - done = 1; - break; - } - if(((Event.xbutton.button == 2)&&(!Scr.gs.EmulateMWM))|| - ((Event.xbutton.button == 1)&&(Scr.gs.EmulateMWM)&& - (Event.xbutton.state & ShiftMask))) - { - NeedToResizeToo = True; - /* Fallthrough to button-release */ - } - else - { - /* Abort the move if - * - the move started with a pressed button and another button - * was pressed during the operation - * - no button was started at the beginning and any button - * except button 1 was pressed. */ - if (button_mask || (Event.xbutton.button != 1)) - { - if(!opaque_move) - MoveOutline(Scr.Root, 0, 0, 0, 0); - *FinalX = tmp_win->frame_x; - *FinalY = tmp_win->frame_y; - finished = TRUE; + Bool finished = False; + Bool done; + int xl, yt, delta_x, delta_y, paged; + unsigned int button_mask = 0; + unsigned int bw = tmp_win->bw; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &xl, &yt, &JunkX, + &JunkY, &button_mask); + button_mask &= + Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask; + xl += XOffset; + yt += YOffset; + + if (((!opaque_move) && (!Scr.gs.EmulateMWM)) || (AddWindow)) + MoveOutline( + Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); + + DisplayPosition(tmp_win, xl, yt, True); + + while (!finished) { + /* block until there is an interesting event */ + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | KeyPressMask | + PointerMotionMask | ButtonMotionMask | ExposureMask, + &Event); + StashEventTime(&Event); + + /* discard any extra motion events before a logical release */ + if (Event.type == MotionNotify) { + while (XCheckMaskEvent(dpy, + PointerMotionMask | ButtonMotionMask | + ButtonPressMask | ButtonRelease, + &Event)) { + StashEventTime(&Event); + if (Event.type == ButtonRelease) + break; + } } - done = 1; - break; - } - case ButtonRelease: - if(!opaque_move) - MoveOutline(Scr.Root, 0, 0, 0, 0); - xl = Event.xmotion.x_root + XOffset; - yt = Event.xmotion.y_root + YOffset; - - DoSnapAttract(tmp_win, Width, Height, &xl, &yt); - - /* Resist moving windows over the edge of the screen! */ - if(((xl + Width) >= Scr.MyDisplayWidth)&& - ((xl + Width) < Scr.MyDisplayWidth+Scr.MoveResistance)) - xl = Scr.MyDisplayWidth - Width - 2 * bw; - if((xl <= 0)&&(xl > -Scr.MoveResistance)) - xl = 0; - if(((yt + Height) >= Scr.MyDisplayHeight)&& - ((yt + Height) < Scr.MyDisplayHeight+Scr.MoveResistance)) - yt = Scr.MyDisplayHeight - Height - 2 * bw; - if((yt <= 0)&&(yt > -Scr.MoveResistance)) - yt = 0; - - *FinalX = xl; - *FinalY = yt; - - done = TRUE; - finished = TRUE; - break; - - case MotionNotify: - xl = Event.xmotion.x_root; - yt = Event.xmotion.y_root; -/* HandlePaging(Scr.MyDisplayWidth,Scr.MyDisplayHeight,&xl,&yt, - &delta_x,&delta_y,False); mab */ - /* redraw the rubberband */ - xl += XOffset; - yt += YOffset; - - DoSnapAttract(tmp_win, Width, Height, &xl, &yt); - - /* Resist moving windows over the edge of the screen! */ - if(((xl + Width) >= Scr.MyDisplayWidth)&& - ((xl + Width) < Scr.MyDisplayWidth+Scr.MoveResistance)) - xl = Scr.MyDisplayWidth - Width - 2 * bw; - if((xl <= 0)&&(xl > -Scr.MoveResistance)) - xl = 0; - if(((yt + Height) >= Scr.MyDisplayHeight)&& - ((yt + Height) < Scr.MyDisplayHeight+Scr.MoveResistance)) - yt = Scr.MyDisplayHeight - Height - 2 * bw; - if((yt <= 0)&&(yt > -Scr.MoveResistance)) - yt = 0; - - /* check Paging request once and only once after outline redrawn */ - /* redraw after paging if needed - mab */ - paged=0; - while(paged<=1) - { - if(!opaque_move) - MoveOutline(Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); - else - { - if (tmp_win->flags & ICONIFIED) - { - tmp_win->icon_x_loc = xl ; - tmp_win->icon_xl_loc = xl - - (tmp_win->icon_w_width - tmp_win->icon_p_width)/2; - tmp_win->icon_y_loc = yt; - if(tmp_win->icon_pixmap_w != None) - XMoveWindow (dpy, tmp_win->icon_pixmap_w, - tmp_win->icon_x_loc,yt); - else if (tmp_win->icon_w != None) - XMoveWindow(dpy, tmp_win->icon_w,tmp_win->icon_xl_loc, - yt+tmp_win->icon_p_height); - - } - else - XMoveWindow(dpy,tmp_win->frame,xl,yt); - } - DisplayPosition(tmp_win,xl,yt,False); - - /* prevent window from lagging behind mouse when paging - mab */ - if(paged==0) - { - int dx; - int dy; - - xl = Event.xmotion.x_root; - yt = Event.xmotion.y_root; - dx = Scr.EdgeScrollX ? Scr.EdgeScrollX : Scr.MyDisplayWidth; - dy = Scr.EdgeScrollY ? Scr.EdgeScrollY : Scr.MyDisplayHeight; - HandlePaging(dx, dy, &xl,&yt, &delta_x,&delta_y,False); - xl += XOffset; - yt += YOffset; - if ( (delta_x==0) && (delta_y==0)) - /* break from while paged */ - break; - } - paged++; - } /* end while paged */ - done = TRUE; - break; - - default: - break; - } /* switch */ - if(!done) - { - if(!opaque_move) - MoveOutline(Scr.Root,0,0,0,0); - DispatchEvent(); - if(!opaque_move) - MoveOutline(Scr.Root, xl, yt, Width - 1 + 2 * bw, Height - 1 + 2 * bw); + done = FALSE; + /* Handle a limited number of key press events to allow + * mouseless operation */ + if (Event.type == KeyPress) + Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); + switch (Event.type) { + case KeyPress: + /* simple code to bag out of move - CKH */ + if (XLookupKeysym(&(Event.xkey), 0) == XK_Escape) { + if (!opaque_move) + MoveOutline(Scr.Root, 0, 0, 0, 0); + *FinalX = tmp_win->frame_x; + *FinalY = tmp_win->frame_y; + ClampToScreen(FinalX, FinalY, + Width, Height, bw); + finished = TRUE; + } + done = TRUE; + break; + case ButtonPress: + XAllowEvents(dpy, ReplayPointer, CurrentTime); + if (((Event.xbutton.button == 1) && + (button_mask & Button1Mask)) || + ((Event.xbutton.button == 2) && + (button_mask & Button2Mask)) || + ((Event.xbutton.button == 3) && + (button_mask & Button3Mask)) || + ((Event.xbutton.button == 4) && + (button_mask & Button4Mask)) || + ((Event.xbutton.button == 5) && + (button_mask & Button5Mask))) { + /* No new button was pressed, just a delayed + * event */ + done = 1; + break; + } + if (((Event.xbutton.button == 2) && + (!Scr.gs.EmulateMWM)) || + ((Event.xbutton.button == 1) && + (Scr.gs.EmulateMWM) && + (Event.xbutton.state & ShiftMask))) { + NeedToResizeToo = True; + /* Fallthrough to button-release */ + } else { + /* Abort the move if + * - the move started with a pressed button and + * another button was pressed during the + * operation + * - no button was started at the beginning and + * any button except button 1 was pressed. */ + if (button_mask || + (Event.xbutton.button != 1)) { + if (!opaque_move) + MoveOutline( + Scr.Root, 0, 0, 0, 0); + *FinalX = tmp_win->frame_x; + *FinalY = tmp_win->frame_y; + ClampToScreen(FinalX, FinalY, + Width, Height, bw); + finished = TRUE; + } + done = 1; + break; + } + case ButtonRelease: + if (!opaque_move) + MoveOutline(Scr.Root, 0, 0, 0, 0); + xl = Event.xmotion.x_root + XOffset; + yt = Event.xmotion.y_root + YOffset; + + DoSnapAttract(tmp_win, Width, Height, &xl, &yt); + + /* Resist moving windows over the edge of the screen! */ + if (((xl + Width) >= Scr.MyDisplayWidth) && + ((xl + Width) < + Scr.MyDisplayWidth + Scr.MoveResistance)) + xl = Scr.MyDisplayWidth - Width - 2 * bw; + if ((xl <= 0) && (xl > -Scr.MoveResistance)) + xl = 0; + if (((yt + Height) >= Scr.MyDisplayHeight) && + ((yt + Height) < + Scr.MyDisplayHeight + Scr.MoveResistance)) + yt = Scr.MyDisplayHeight - Height - 2 * bw; + if ((yt <= 0) && (yt > -Scr.MoveResistance)) + yt = 0; + + *FinalX = xl; + *FinalY = yt; + + done = TRUE; + finished = TRUE; + break; + + case MotionNotify: + xl = Event.xmotion.x_root; + yt = Event.xmotion.y_root; + /* HandlePaging(Scr.MyDisplayWidth,Scr.MyDisplayHeight,&xl,&yt, + &delta_x,&delta_y,False); mab */ + /* redraw the rubberband */ + xl += XOffset; + yt += YOffset; + + DoSnapAttract(tmp_win, Width, Height, &xl, &yt); + + /* Resist moving windows over the edge of the screen! */ + if (((xl + Width) >= Scr.MyDisplayWidth) && + ((xl + Width) < + Scr.MyDisplayWidth + Scr.MoveResistance)) + xl = Scr.MyDisplayWidth - Width - 2 * bw; + if ((xl <= 0) && (xl > -Scr.MoveResistance)) + xl = 0; + if (((yt + Height) >= Scr.MyDisplayHeight) && + ((yt + Height) < + Scr.MyDisplayHeight + Scr.MoveResistance)) + yt = Scr.MyDisplayHeight - Height - 2 * bw; + if ((yt <= 0) && (yt > -Scr.MoveResistance)) + yt = 0; + + /* check Paging request once and only once after outline + * redrawn */ + /* redraw after paging if needed - mab */ + paged = 0; + while (paged <= 1) { + if (!opaque_move) + MoveOutline(Scr.Root, xl, yt, + Width - 1 + 2 * bw, + Height - 1 + 2 * bw); + else { + if (tmp_win->flags & ICONIFIED) { + tmp_win->icon_x_loc = xl; + tmp_win->icon_xl_loc = + xl - + (tmp_win->icon_w_width - + tmp_win->icon_p_width) / + 2; + tmp_win->icon_y_loc = yt; + if (tmp_win->icon_pixmap_w != + None) + XMoveWindow(dpy, + tmp_win + ->icon_pixmap_w, + tmp_win->icon_x_loc, + yt); + else if (tmp_win->icon_w != + None) + XMoveWindow(dpy, + tmp_win->icon_w, + tmp_win + ->icon_xl_loc, + yt + + tmp_win + ->icon_p_height); + } else + XMoveWindow(dpy, tmp_win->frame, + xl, yt); + } + DisplayPosition(tmp_win, xl, yt, False); + + /* prevent window from lagging behind mouse when + * paging - mab */ + if (paged == 0) { + int dx; + int dy; + + xl = Event.xmotion.x_root; + yt = Event.xmotion.y_root; + dx = Scr.EdgeScrollX ? + Scr.EdgeScrollX : + Scr.MyDisplayWidth; + dy = Scr.EdgeScrollY ? + Scr.EdgeScrollY : + Scr.MyDisplayHeight; + HandlePaging(dx, dy, &xl, &yt, &delta_x, + &delta_y, False); + xl += XOffset; + yt += YOffset; + if ((delta_x == 0) && (delta_y == 0)) + /* break from while paged */ + break; + } + paged++; + } /* end while paged */ + + done = TRUE; + break; + + default: + break; + } /* switch */ + if (!done) { + if (!opaque_move) + MoveOutline(Scr.Root, 0, 0, 0, 0); + DispatchEvent(); + if (!opaque_move) + MoveOutline(Scr.Root, xl, yt, + Width - 1 + 2 * bw, Height - 1 + 2 * bw); + } } - } - if (!NeedToResizeToo) - /* Don't wait for buttons to come up when user is placing a new window - * and wants to resize it. */ - WaitForButtonsUp(); + if (!NeedToResizeToo) + /* Don't wait for buttons to come up when user is placing a new + * window and wants to resize it. */ + WaitForButtonsUp(); } /*********************************************************************** @@ -633,37 +671,31 @@ void moveLoop(FvwmWindow *tmp_win, int XOffset, int YOffset, int Width, * ************************************************************************/ -void DisplayPosition (FvwmWindow *tmp_win, int x, int y,int Init) +void +DisplayPosition(FvwmWindow *tmp_win, int x, int y, int Init) { - char str [100]; - int offset; - - (void) snprintf (str, sizeof(str), " %+-4d %+-4d ", x, y); - if(Init) - { - XClearWindow(dpy,Scr.SizeWindow); - if(Scr.d_depth >= 2) - RelieveWindow(tmp_win,Scr.SizeWindow,0,0, - Scr.SizeStringWidth+ SIZE_HINDENT*2, - Scr.StdFont.height + SIZE_VINDENT*2, - Scr.StdReliefGC, - Scr.StdShadowGC, FULL_HILITE); - - } - else - { - XClearArea(dpy,Scr.SizeWindow,SIZE_HINDENT,SIZE_VINDENT, - Scr.SizeStringWidth, Scr.StdFont.height,False); - } - - offset = (Scr.SizeStringWidth + SIZE_HINDENT*2 - - XTextWidth(Scr.StdFont.font,str,strlen(str)))/2; - XDrawString (dpy, Scr.SizeWindow, Scr.StdGC, - offset, - Scr.StdFont.font->ascent + SIZE_VINDENT, - str, strlen(str)); -} + char str[100]; + int offset; + + (void)snprintf(str, sizeof(str), " %+-4d %+-4d ", x, y); + if (Init) { + XClearWindow(dpy, Scr.SizeWindow); + if (Scr.d_depth >= 2) + RelieveWindow(tmp_win, Scr.SizeWindow, 0, 0, + Scr.SizeStringWidth + SIZE_HINDENT * 2, + Scr.StdFont.height + SIZE_VINDENT * 2, + Scr.StdReliefGC, Scr.StdShadowGC, FULL_HILITE); + } else { + XClearArea(dpy, Scr.SizeWindow, SIZE_HINDENT, SIZE_VINDENT, + Scr.SizeStringWidth, Scr.StdFont.height, False); + } + offset = (Scr.SizeStringWidth + SIZE_HINDENT * 2 - + XTextWidth(Scr.StdFont.font, str, strlen(str))) / + 2; + XDrawString(dpy, Scr.SizeWindow, Scr.StdGC, offset, + Scr.StdFont.font->ascent + SIZE_VINDENT, str, strlen(str)); +} /**************************************************************************** * @@ -671,164 +703,162 @@ void DisplayPosition (FvwmWindow *tmp_win, int x, int y,int Init) * shortcuts by warping the pointer. * ****************************************************************************/ -void Keyboard_shortcuts(XEvent *Event, FvwmWindow *w, int ReturnEvent) +void +Keyboard_shortcuts(XEvent *Event, FvwmWindow *w, int ReturnEvent) { - int x,y,x_root,y_root; - int x_move_size = 0, y_move_size = 0; - int x_move,y_move; - - KeySym keysym; - - if (w) - { - x_move_size = w->hints.width_inc; - y_move_size = w->hints.height_inc; - } - if (y_move_size < 5) y_move_size = 5; - if (x_move_size < 5) x_move_size = 5; - if(Event->xkey.state & ControlMask) - x_move_size = y_move_size = 1; - if(Event->xkey.state & ShiftMask) - x_move_size = y_move_size = 100; - - keysym = XLookupKeysym(&Event->xkey,0); - - x_move = 0; - y_move = 0; - switch(keysym) - { - case XK_Up: - case XK_KP_8: - case XK_k: - case XK_p: - y_move = -y_move_size; - break; - case XK_Down: - case XK_KP_2: - case XK_n: - case XK_j: - y_move = y_move_size; - break; - case XK_Left: - case XK_KP_4: - case XK_b: - case XK_h: - x_move = -x_move_size; - break; - case XK_Right: - case XK_KP_6: - case XK_f: - case XK_l: - x_move = x_move_size; - break; - case XK_KP_1: - x_move = -x_move_size; - y_move = y_move_size; - break; - case XK_KP_3: - x_move = x_move_size; - y_move = y_move_size; - break; - case XK_KP_7: - x_move = -x_move_size; - y_move = -y_move_size; - break; - case XK_KP_9: - x_move = x_move_size; - y_move = -y_move_size; - break; - case XK_Return: - case XK_KP_Enter: - case XK_space: - /* beat up the event */ - Event->type = ReturnEvent; - break; - case XK_Escape: - /* simple code to bag out of move - CKH */ - /* return keypress event instead */ - Event->type = KeyPress; - Event->xkey.keycode = XKeysymToKeycode(Event->xkey.display,keysym); - break; - default: - break; - } - XQueryPointer( dpy, Scr.Root, &JunkRoot, &Event->xany.window, - &x_root, &y_root, &x, &y, &JunkMask); - - if((x_move != 0)||(y_move != 0)) - { - /* beat up the event */ - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x_root+x_move, - y_root+y_move); - - /* beat up the event */ - Event->type = MotionNotify; - Event->xkey.x += x_move; - Event->xkey.y += y_move; - Event->xkey.x_root += x_move; - Event->xkey.y_root += y_move; - } -} + int x, y, x_root, y_root; + int x_move_size = 0, y_move_size = 0; + int x_move, y_move; + + KeySym keysym; + if (w) { + x_move_size = w->hints.width_inc; + y_move_size = w->hints.height_inc; + } + if (y_move_size < 5) + y_move_size = 5; + if (x_move_size < 5) + x_move_size = 5; + if (Event->xkey.state & ControlMask) + x_move_size = y_move_size = 1; + if (Event->xkey.state & ShiftMask) + x_move_size = y_move_size = 100; + + keysym = XLookupKeysym(&Event->xkey, 0); + + x_move = 0; + y_move = 0; + switch (keysym) { + case XK_Up: + case XK_KP_8: + case XK_k: + case XK_p: + y_move = -y_move_size; + break; + case XK_Down: + case XK_KP_2: + case XK_n: + case XK_j: + y_move = y_move_size; + break; + case XK_Left: + case XK_KP_4: + case XK_b: + case XK_h: + x_move = -x_move_size; + break; + case XK_Right: + case XK_KP_6: + case XK_f: + case XK_l: + x_move = x_move_size; + break; + case XK_KP_1: + x_move = -x_move_size; + y_move = y_move_size; + break; + case XK_KP_3: + x_move = x_move_size; + y_move = y_move_size; + break; + case XK_KP_7: + x_move = -x_move_size; + y_move = -y_move_size; + break; + case XK_KP_9: + x_move = x_move_size; + y_move = -y_move_size; + break; + case XK_Return: + case XK_KP_Enter: + case XK_space: + /* beat up the event */ + Event->type = ReturnEvent; + break; + case XK_Escape: + /* simple code to bag out of move - CKH */ + /* return keypress event instead */ + Event->type = KeyPress; + Event->xkey.keycode = + XKeysymToKeycode(Event->xkey.display, keysym); + break; + default: + break; + } + XQueryPointer(dpy, Scr.Root, &JunkRoot, &Event->xany.window, &x_root, + &y_root, &x, &y, &JunkMask); + + if ((x_move != 0) || (y_move != 0)) { + /* beat up the event */ + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, x_root + x_move, + y_root + y_move); + + /* beat up the event */ + Event->type = MotionNotify; + Event->xkey.x += x_move; + Event->xkey.y += y_move; + Event->xkey.x_root += x_move; + Event->xkey.y_root += y_move; + } +} -void InteractiveMove(Window *win, FvwmWindow *tmp_win, int *FinalX, int *FinalY, XEvent *eventp) +void +InteractiveMove( + Window *win, FvwmWindow *tmp_win, int *FinalX, int *FinalY, XEvent *eventp) { - int origDragX,origDragY,DragX, DragY, DragWidth, DragHeight; - int XOffset, YOffset; - Window w; - - Bool opaque_move = False; - - w = *win; - - InstallRootColormap(); - if (menuFromFrameOrWindowOrTitlebar) - { - /* warp the pointer to the cursor position from before menu appeared*/ - XFlush(dpy); - } - - /* Although a move is usually done with a button depressed we have to check - * for ButtonRelease too since the event may be faked. */ - if (eventp->type == ButtonPress || eventp->type == ButtonRelease) - { - DragX = eventp->xbutton.x_root; - DragY = eventp->xbutton.y_root; - } - else - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &DragX, &DragY, - &JunkX, &JunkY, &JunkMask); - - if(!GrabEm(MOVE)) - { - XBell(dpy, 0); - return; - } - - XGetGeometry(dpy, w, &JunkRoot, &origDragX, &origDragY, - (unsigned int *)&DragWidth, (unsigned int *)&DragHeight, - &JunkBW, &JunkDepth); - - if(DragWidth*DragHeight < - (Scr.OpaqueSize*Scr.MyDisplayWidth*Scr.MyDisplayHeight)/100) - opaque_move = True; - else - MyXGrabServer(dpy); - - if((!opaque_move)&&(tmp_win->flags & ICONIFIED)) - XUnmapWindow(dpy,w); - - XOffset = origDragX - DragX; - YOffset = origDragY - DragY; - XMapRaised(dpy,Scr.SizeWindow); - moveLoop(tmp_win, XOffset,YOffset,DragWidth,DragHeight, FinalX,FinalY, - opaque_move,False); - - XUnmapWindow(dpy,Scr.SizeWindow); - UninstallRootColormap(); - - if(!opaque_move) - MyXUngrabServer(dpy); - UngrabEm(); + int origDragX, origDragY, DragX, DragY, DragWidth, DragHeight; + int XOffset, YOffset; + Window w; + + Bool opaque_move = False; + + w = *win; + + InstallRootColormap(); + if (menuFromFrameOrWindowOrTitlebar) { + /* warp the pointer to the cursor position from before menu + * appeared*/ + XFlush(dpy); + } + + /* Although a move is usually done with a button depressed we have to + * check for ButtonRelease too since the event may be faked. */ + if (eventp->type == ButtonPress || eventp->type == ButtonRelease) { + DragX = eventp->xbutton.x_root; + DragY = eventp->xbutton.y_root; + } else + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &DragX, + &DragY, &JunkX, &JunkY, &JunkMask); + + if (!GrabEm(MOVE)) { + XBell(dpy, 0); + return; + } + + XGetGeometry(dpy, w, &JunkRoot, &origDragX, &origDragY, + (unsigned int *)&DragWidth, (unsigned int *)&DragHeight, &JunkBW, + &JunkDepth); + + if (DragWidth * DragHeight < + (Scr.OpaqueSize * Scr.MyDisplayWidth * Scr.MyDisplayHeight) / 100) + opaque_move = True; + else + MyXGrabServer(dpy); + + if ((!opaque_move) && (tmp_win->flags & ICONIFIED)) + XUnmapWindow(dpy, w); + + XOffset = origDragX - DragX; + YOffset = origDragY - DragY; + XMapRaised(dpy, Scr.SizeWindow); + moveLoop(tmp_win, XOffset, YOffset, DragWidth, DragHeight, FinalX, + FinalY, opaque_move, False); + + XUnmapWindow(dpy, Scr.SizeWindow); + UninstallRootColormap(); + if (!opaque_move) + MyXUngrabServer(dpy); + UngrabEm(); } Index: fvwm/fvwm/parse.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/parse.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/parse.h --- fvwm/fvwm/parse.h +++ fvwm/fvwm/parse.h @@ -18,113 +18,112 @@ #define _PARSE_ enum { - F_NOP = 0, - F_BEEP, - F_QUIT, - F_RESTART, - F_REFRESH, - F_TITLE, - F_SCROLL, - F_CIRCULATE_UP, - F_CIRCULATE_DOWN, - F_TOGGLE_PAGE, - F_GOTO_PAGE, - F_WINDOWLIST, - F_MOVECURSOR, - F_FUNCTION, - F_MODULE = 15, - F_DESK, - F_CHANGE_WINDOWS_DESK, - F_EXEC, - F_POPUP, - F_WAIT, - F_CLOSE, - F_SET_MASK, - F_ADDMENU, - F_ADDFUNC, - F_STYLE, - F_EDGE_SCROLL, - F_PIXMAP_PATH, - F_ICON_PATH, - F_MODULE_PATH, - F_HICOLOR, - F_SETDESK, - F_MOUSE, - F_KEY, - F_OPAQUE, - F_XOR, - F_CLICK, - F_MENUSTYLE, - F_ICONFONT, - F_WINDOWFONT, - F_EDGE_RES, - F_BUTTON_STYLE, - F_READ, - F_ADDMENU2, - F_DIRECTION, - F_NEXT, - F_PREV, - F_NONE, - F_STAYSUP, - F_RECAPTURE, - F_CONFIG_LIST, - F_DESTROY_MENU, - F_ZAP, - F_QUIT_SCREEN, - F_COLORMAP_FOCUS, - F_TITLESTYLE, - F_EXEC_SETUP, - F_CURSOR_STYLE, - F_CURRENT, - F_SETENV, - F_SET_ANIMATION, - F_CHANGE_MENUSTYLE, - F_DESTROY_MENUSTYLE, - F_SNAP_ATT, - F_SNAP_GRID, - F_DFLT_FONT, - F_DFLT_COLORS, - F_GLOBAL_OPTS, - F_EMULATE, + F_NOP = 0, + F_BEEP, + F_QUIT, + F_RESTART, + F_REFRESH, + F_TITLE, + F_SCROLL, + F_CIRCULATE_UP, + F_CIRCULATE_DOWN, + F_TOGGLE_PAGE, + F_GOTO_PAGE, + F_WINDOWLIST, + F_MOVECURSOR, + F_FUNCTION, + F_MODULE = 15, + F_DESK, + F_CHANGE_WINDOWS_DESK, + F_EXEC, + F_POPUP, + F_WAIT, + F_CLOSE, + F_SET_MASK, + F_ADDMENU, + F_ADDFUNC, + F_STYLE, + F_EDGE_SCROLL, + F_PIXMAP_PATH, + F_ICON_PATH, + F_MODULE_PATH, + F_HICOLOR, + F_SETDESK, + F_MOUSE, + F_KEY, + F_OPAQUE, + F_XOR, + F_CLICK, + F_MENUSTYLE, + F_ICONFONT, + F_WINDOWFONT, + F_EDGE_RES, + F_BUTTON_STYLE, + F_READ, + F_ADDMENU2, + F_DIRECTION, + F_NEXT, + F_PREV, + F_NONE, + F_STAYSUP, + F_RECAPTURE, + F_CONFIG_LIST, + F_DESTROY_MENU, + F_ZAP, + F_QUIT_SCREEN, + F_COLORMAP_FOCUS, + F_TITLESTYLE, + F_EXEC_SETUP, + F_CURSOR_STYLE, + F_CURRENT, + F_SETENV, + F_SET_ANIMATION, + F_CHANGE_MENUSTYLE, + F_DESTROY_MENUSTYLE, + F_SNAP_ATT, + F_SNAP_GRID, + F_DFLT_FONT, + F_DFLT_COLORS, + F_GLOBAL_OPTS, + F_EMULATE, - F_RESIZE = 100, - F_RAISE, - F_LOWER, - F_DESTROY, - F_DELETE, - F_MOVE, - F_MOVE_TO_PAGE, - F_ICONIFY, - F_STICK, - F_RAISELOWER, - F_MAXIMIZE, - F_FOCUS, - F_WARP, - F_SEND_STRING, - F_ADD_MOD, - F_DESTROY_MOD, - F_FLIP_FOCUS, - F_ECHO, - F_BORDERSTYLE, - F_WINDOWID, - F_ADD_BUTTON_STYLE, - F_ADD_TITLE_STYLE, - F_ADD_DECOR, - F_CHANGE_DECOR, - F_DESTROY_DECOR, - F_UPDATE_DECOR, - F_WINDOW_SHADE, - F_COLOR_LIMIT, - F_ANIMATED_MOVE, + F_RESIZE = 100, + F_RAISE, + F_LOWER, + F_DESTROY, + F_DELETE, + F_MOVE, + F_MOVE_TO_PAGE, + F_ICONIFY, + F_STICK, + F_RAISELOWER, + F_MAXIMIZE, + F_FOCUS, + F_WARP, + F_SEND_STRING, + F_ADD_MOD, + F_DESTROY_MOD, + F_FLIP_FOCUS, + F_ECHO, + F_BORDERSTYLE, + F_WINDOWID, + F_ADD_BUTTON_STYLE, + F_ADD_TITLE_STYLE, + F_ADD_DECOR, + F_CHANGE_DECOR, + F_DESTROY_DECOR, + F_UPDATE_DECOR, + F_WINDOW_SHADE, + F_COLOR_LIMIT, + F_ANIMATED_MOVE, - F_END_OF_LIST = 999, + F_END_OF_LIST = 999, -/* Functions for use by modules only! */ - F_SEND_WINDOW_LIST = 1000 + /* Functions for use by modules only! */ + F_SEND_WINDOW_LIST = 1000 -/* Functions for internal only! */ - /* F_RAISE_IT = 2000 */ + /* Functions for internal only! */ + /* F_RAISE_IT = 2000 */ }; #endif /* _PARSE_ */ - Index: fvwm/fvwm/placement.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/placement.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/placement.c --- fvwm/fvwm/placement.c +++ fvwm/fvwm/placement.c @@ -9,12 +9,11 @@ * warrantees of any sort whatsoever are given or implied or anything. ****************************************************************************/ -#include "config.h" - #include -#include #include +#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" @@ -22,16 +21,17 @@ #include "screen.h" #ifndef MIN -#define MIN(A,B) ((A)<(B)? (A):(B)) +#define MIN(A, B) ((A) < (B) ? (A) : (B)) #endif #ifndef MAX -#define MAX(A,B) ((A)>(B)? (A):(B)) +#define MAX(A, B) ((A) > (B) ? (A) : (B)) #endif /* RBW - 11/02/1998 */ int get_next_x(FvwmWindow *t, int x, int y, int pdeltax, int pdeltay); int get_next_y(FvwmWindow *t, int y, int pdeltay); -int test_fit(FvwmWindow *t, int test_x, int test_y, int aoimin, int pdeltax, int pdeltay); +int test_fit(FvwmWindow *t, int test_x, int test_y, int aoimin, int pdeltax, + int pdeltay); void CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay); /**/ @@ -49,366 +49,354 @@ void CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay); #define AVOIDONTOP 5 #define AVOIDSTICKY 1 #ifdef NO_STUBBORN_PLACEMENT -#define AVOIDICON 0 /* Ignore Icons. Place windows over them */ +#define AVOIDICON 0 /* Ignore Icons. Place windows over them */ #else -#define AVOIDICON 10 /* Try hard no to place windows over icons */ +#define AVOIDICON 10 /* Try hard no to place windows over icons */ #endif /* RBW - 11/02/1998 */ -int SmartPlacement(FvwmWindow *t, - int width, - int height, - int *x, - int *y, - int pdeltax, - int pdeltay) +int +SmartPlacement(FvwmWindow *t, int width, int height, int *x, int *y, + int pdeltax, int pdeltay) { - int PageBottom = Scr.MyDisplayHeight - pdeltay; - int PageRight = Scr.MyDisplayWidth - pdeltax; - int PageTop = 0 - pdeltay; - int PageLeft = 0 - pdeltax; - int rc = True; -/**/ - int temp_h,temp_w; - int test_x = 0,test_y = 0; - int loc_ok = False, tw,tx,ty,th; - FvwmWindow *test_window; - int stickyx, stickyy; - - if (Scr.SmartPlacementIsClever) /* call clever placement instead? */ - { -/* RBW - 11/02/1998 */ - CleverPlacement(t,x,y,pdeltax,pdeltay); -/**/ - return rc; - } -/* RBW - 11/02/1998 */ -test_x = PageLeft; -test_y = PageTop; -/**/ - - temp_h = height; - temp_w = width; - -/* RBW - 11/02/1998 */ - while(((test_y + temp_h) < (PageBottom))&&(!loc_ok)) - { - test_x = PageLeft; - while(((test_x + temp_w) < (PageRight))&&(!loc_ok)) - { - loc_ok = True; - test_window = Scr.FvwmRoot.next; - while((test_window != (FvwmWindow *)0)&&(loc_ok == True)) - { - /* RBW - account for sticky windows... */ - if(test_window->Desk == t->Desk || (test_window->flags & STICKY)) - { - if (test_window->flags & STICKY) - { - stickyx = pdeltax; - stickyy = pdeltay; - } - else - { - stickyx = 0; - stickyy = 0; - } + int PageBottom = Scr.MyDisplayHeight - pdeltay; + int PageRight = Scr.MyDisplayWidth - pdeltax; + int PageTop = 0 - pdeltay; + int PageLeft = 0 - pdeltax; + int rc = True; + /**/ + int temp_h, temp_w; + int test_x = 0, test_y = 0; + int loc_ok = False, tw, tx, ty, th; + FvwmWindow *test_window; + int stickyx, stickyy; + + if (Scr.SmartPlacementIsClever) { /* call clever placement instead? */ + /* RBW - 11/02/1998 */ + CleverPlacement(t, x, y, pdeltax, pdeltay); + /**/ + return rc; + } + /* RBW - 11/02/1998 */ + test_x = PageLeft; + test_y = PageTop; + /**/ + + temp_h = height; + temp_w = width; + + /* RBW - 11/02/1998 */ + while (((test_y + temp_h) < (PageBottom)) && (!loc_ok)) { + test_x = PageLeft; + while (((test_x + temp_w) < (PageRight)) && (!loc_ok)) { + loc_ok = True; + test_window = Scr.FvwmRoot.next; + while ((test_window != (FvwmWindow *)0) && + (loc_ok == True)) { + /* RBW - account for sticky windows... */ + if (test_window->Desk == t->Desk || + (test_window->flags & STICKY)) { + if (test_window->flags & STICKY) { + stickyx = pdeltax; + stickyy = pdeltay; + } else { + stickyx = 0; + stickyy = 0; + } #ifndef NO_STUBBORN_PLACEMENT - if((test_window->flags & ICONIFIED)&& - (!(test_window->flags & ICON_UNMAPPED))&& - (test_window->icon_w)&& - (test_window != t)) - { - tw=test_window->icon_p_width; - th=test_window->icon_p_height+ - test_window->icon_w_height; - tx = test_window->icon_x_loc - stickyx; - ty = test_window->icon_y_loc - stickyy; - - if((tx<(test_x+width))&&((tx + tw) > test_x)&& - (ty<(test_y+height))&&((ty + th)>test_y)) - { - loc_ok = False; - test_x = tx + tw; - } - } + if ((test_window->flags & ICONIFIED) && + (!(test_window->flags & + ICON_UNMAPPED)) && + (test_window->icon_w) && + (test_window != t)) { + tw = test_window->icon_p_width; + th = + test_window->icon_p_height + + test_window->icon_w_height; + tx = test_window->icon_x_loc - + stickyx; + ty = test_window->icon_y_loc - + stickyy; + + if ((tx < (test_x + width)) && + ((tx + tw) > test_x) && + (ty < (test_y + height)) && + ((ty + th) > test_y)) { + loc_ok = False; + test_x = tx + tw; + } + } #endif /* !NO_STUBBORN_PLACEMENT */ - if(!(test_window->flags & ICONIFIED)&&(test_window != t)) - { - tw=test_window->frame_width+2*test_window->bw; - th=test_window->frame_height+2*test_window->bw; - tx = test_window->frame_x - stickyx; - ty = test_window->frame_y - stickyy; - if((tx <= (test_x+width))&&((tx + tw) >= test_x)&& - (ty <= (test_y+height))&&((ty + th)>= test_y)) - { - loc_ok = False; - test_x = tx + tw; - } - } - } - test_window = test_window->next; - } - test_x +=1; - } - test_y +=1; - } - /* RBW - 11/02/1998 */ - if(loc_ok == False) - { - rc = False; - return rc; - } - *x = test_x; - *y = test_y; - return rc; - /**/ + if (!(test_window->flags & ICONIFIED) && + (test_window != t)) { + tw = test_window->frame_width + + 2 * test_window->bw; + th = test_window->frame_height + + 2 * test_window->bw; + tx = test_window->frame_x - + stickyx; + ty = test_window->frame_y - + stickyy; + if ((tx <= (test_x + width)) && + ((tx + tw) >= test_x) && + (ty <= (test_y + height)) && + ((ty + th) >= test_y)) { + loc_ok = False; + test_x = tx + tw; + } + } + } + test_window = test_window->next; + } + test_x += 1; + } + test_y += 1; + } + /* RBW - 11/02/1998 */ + if (loc_ok == False) { + rc = False; + return rc; + } + *x = test_x; + *y = test_y; + return rc; + /**/ } - /* CleverPlacement by Anthony Martin * This function will place a new window such that there is a minimum amount * of interference with other windows. If it can place a window without any * interference, fine. Otherwise, it places it so that the area of of * interference between the new window and the other windows is minimized */ /* RBW - 11/02/1998 */ -void CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay) +void +CleverPlacement(FvwmWindow *t, int *x, int *y, int pdeltax, int pdeltay) { -/**/ - int test_x = 0,test_y = 0; - int xbest, ybest; - int aoi, aoimin; /* area of interference */ - -/* RBW - 11/02/1998 */ - int PageTop = 0 - pdeltay; - int PageLeft = 0 - pdeltax; - - test_x = PageLeft; - test_y = PageTop; - aoi = aoimin = test_fit(t, test_x, test_y, -1, pdeltax, pdeltay); -/**/ - xbest = test_x; - ybest = test_y; - - while((aoi != 0) && (aoi != -1)) - { - if(aoi > 0) /* Windows interfere. Try next x. */ - { - test_x = get_next_x(t, test_x, test_y, pdeltax, pdeltay); - } - else /* Out of room in x direction. Try next y. Reset x.*/ - { - test_x = PageLeft; - test_y = get_next_y(t, test_y, pdeltay); - } - aoi = test_fit(t, test_x, test_y, aoimin, pdeltax, pdeltay); - if((aoi >= 0) && (aoi < aoimin)) - { - xbest = test_x; - ybest = test_y; - aoimin = aoi; - } - } - *x = xbest; - *y = ybest; + /**/ + int test_x = 0, test_y = 0; + int xbest, ybest; + int aoi, aoimin; /* area of interference */ + + /* RBW - 11/02/1998 */ + int PageTop = 0 - pdeltay; + int PageLeft = 0 - pdeltax; + + test_x = PageLeft; + test_y = PageTop; + aoi = aoimin = test_fit(t, test_x, test_y, -1, pdeltax, pdeltay); + /**/ + xbest = test_x; + ybest = test_y; + + while ((aoi != 0) && (aoi != -1)) { + if (aoi > 0) { /* Windows interfere. Try next x. */ + test_x = + get_next_x(t, test_x, test_y, pdeltax, pdeltay); + } else /* Out of room in x direction. Try next y. Reset x.*/ { + test_x = PageLeft; + test_y = get_next_y(t, test_y, pdeltay); + } + aoi = test_fit(t, test_x, test_y, aoimin, pdeltax, pdeltay); + if ((aoi >= 0) && (aoi < aoimin)) { + xbest = test_x; + ybest = test_y; + aoimin = aoi; + } + } + *x = xbest; + *y = ybest; } /* RBW - 11/02/1998 */ -int get_next_x(FvwmWindow *t, int x, int y, int pdeltax, int pdeltay) +int +get_next_x(FvwmWindow *t, int x, int y, int pdeltax, int pdeltay) { -/**/ - int xnew; - int xtest; - FvwmWindow *testw; - int PageRight = Scr.MyDisplayWidth - pdeltax; - int stickyx, stickyy; - - /* Test window at far right of screen */ -/* RBW - 11/02/1998 */ - xnew = PageRight; - xtest = PageRight - (t->frame_width + 2 * t->bw); -/**/ - if(xtest > x) - xnew = MIN(xnew, xtest); - /* Test the values of the right edges of every window */ - for(testw = Scr.FvwmRoot.next ; testw != NULL ; testw = testw->next) - { - if((testw == t) || ((testw->Desk != t->Desk) && (! (testw->flags & STICKY)))) - continue; - - if (testw->flags & STICKY) - { - stickyx = pdeltax; - stickyy = pdeltay; - } - else - { - stickyx = 0; - stickyy = 0; - } - - if(testw->flags & ICONIFIED) - { - if((y < (testw->icon_p_height+testw->icon_w_height+testw->icon_y_loc - stickyy))&& - (testw->icon_y_loc - stickyy < (t->frame_height+2*t->bw+y))) - { - xtest = testw->icon_p_width+testw->icon_x_loc - stickyx; - if(xtest > x) - xnew = MIN(xnew, xtest); - xtest = testw->icon_x_loc - stickyx - (t->frame_width + 2 * t->bw); - if(xtest > x) - xnew = MIN(xnew, xtest); - } - } - else if((y < (testw->frame_height+2*testw->bw+testw->frame_y - stickyy)) && - (testw->frame_y - stickyy < (t->frame_height+2*t->bw+y))) - { - xtest = testw->frame_width+2*testw->bw+testw->frame_x - stickyx; - if(xtest > x) - xnew = MIN(xnew, xtest); - xtest = testw->frame_x - stickyx - (t->frame_width + 2 * t->bw); - if(xtest > x) - xnew = MIN(xnew, xtest); - } - } - return xnew; + /**/ + int xnew; + int xtest; + FvwmWindow *testw; + int PageRight = Scr.MyDisplayWidth - pdeltax; + int stickyx, stickyy; + + /* Test window at far right of screen */ + /* RBW - 11/02/1998 */ + xnew = PageRight; + xtest = PageRight - (t->frame_width + 2 * t->bw); + /**/ + if (xtest > x) + xnew = MIN(xnew, xtest); + /* Test the values of the right edges of every window */ + for (testw = Scr.FvwmRoot.next; testw != NULL; testw = testw->next) { + if ((testw == t) || + ((testw->Desk != t->Desk) && (!(testw->flags & STICKY)))) + continue; + + if (testw->flags & STICKY) { + stickyx = pdeltax; + stickyy = pdeltay; + } else { + stickyx = 0; + stickyy = 0; + } + + if (testw->flags & ICONIFIED) { + if ((y < (testw->icon_p_height + testw->icon_w_height + + testw->icon_y_loc - stickyy)) && + (testw->icon_y_loc - stickyy < + (t->frame_height + 2 * t->bw + y))) { + xtest = testw->icon_p_width + + testw->icon_x_loc - stickyx; + if (xtest > x) + xnew = MIN(xnew, xtest); + xtest = testw->icon_x_loc - stickyx - + (t->frame_width + 2 * t->bw); + if (xtest > x) + xnew = MIN(xnew, xtest); + } + } else if ((y < (testw->frame_height + 2 * testw->bw + + testw->frame_y - stickyy)) && + (testw->frame_y - stickyy < + (t->frame_height + 2 * t->bw + y))) { + xtest = testw->frame_width + 2 * testw->bw + + testw->frame_x - stickyx; + if (xtest > x) + xnew = MIN(xnew, xtest); + xtest = testw->frame_x - stickyx - + (t->frame_width + 2 * t->bw); + if (xtest > x) + xnew = MIN(xnew, xtest); + } + } + return xnew; } -/* RBW - 11/02/1998 */ -int get_next_y(FvwmWindow *t, int y, int pdeltay) -{ -/**/ - int ynew; - int ytest; - FvwmWindow *testw; - int PageBottom = Scr.MyDisplayHeight - pdeltay; - int stickyy; - /* Test window at far bottom of screen */ /* RBW - 11/02/1998 */ - ynew = PageBottom; - ytest = PageBottom - (t->frame_height + 2 * t->bw); -/**/ - if(ytest > y) - ynew = MIN(ynew, ytest); - /* Test the values of the bottom edge of every window */ - for(testw = Scr.FvwmRoot.next ; testw != NULL ; testw = testw->next) - { - if((testw == t) || ((testw->Desk != t->Desk) && (! (testw->flags & STICKY)))) - continue; - - if (testw->flags & STICKY) - { - stickyy = pdeltay; - } - else - { - stickyy = 0; - } - - if(testw->flags & ICONIFIED) - { - ytest = testw->icon_p_height+testw->icon_w_height+testw->icon_y_loc - stickyy; - if(ytest > y) - ynew = MIN(ynew, ytest); - ytest = testw->icon_y_loc - stickyy - (t->frame_height + 2 * t->bw); - if(ytest > y) - ynew = MIN(ynew, ytest); - } - else - { - ytest = testw->frame_height+2*testw->bw+testw->frame_y - stickyy; - if(ytest > y) - ynew = MIN(ynew, ytest); - ytest = testw->frame_y - stickyy - (t->frame_height + 2 * t->bw); - if(ytest > y) - ynew = MIN(ynew, ytest); - } - } - return ynew; +int +get_next_y(FvwmWindow *t, int y, int pdeltay) +{ + /**/ + int ynew; + int ytest; + FvwmWindow *testw; + int PageBottom = Scr.MyDisplayHeight - pdeltay; + int stickyy; + + /* Test window at far bottom of screen */ + /* RBW - 11/02/1998 */ + ynew = PageBottom; + ytest = PageBottom - (t->frame_height + 2 * t->bw); + /**/ + if (ytest > y) + ynew = MIN(ynew, ytest); + /* Test the values of the bottom edge of every window */ + for (testw = Scr.FvwmRoot.next; testw != NULL; testw = testw->next) { + if ((testw == t) || + ((testw->Desk != t->Desk) && (!(testw->flags & STICKY)))) + continue; + + if (testw->flags & STICKY) { + stickyy = pdeltay; + } else { + stickyy = 0; + } + + if (testw->flags & ICONIFIED) { + ytest = testw->icon_p_height + testw->icon_w_height + + testw->icon_y_loc - stickyy; + if (ytest > y) + ynew = MIN(ynew, ytest); + ytest = testw->icon_y_loc - stickyy - + (t->frame_height + 2 * t->bw); + if (ytest > y) + ynew = MIN(ynew, ytest); + } else { + ytest = testw->frame_height + 2 * testw->bw + + testw->frame_y - stickyy; + if (ytest > y) + ynew = MIN(ynew, ytest); + ytest = testw->frame_y - stickyy - + (t->frame_height + 2 * t->bw); + if (ytest > y) + ynew = MIN(ynew, ytest); + } + } + return ynew; } /* RBW - 11/02/1998 */ -int test_fit(FvwmWindow *t, int x11, int y11, int aoimin, int pdeltax, - int pdeltay) +int +test_fit(FvwmWindow *t, int x11, int y11, int aoimin, int pdeltax, int pdeltay) { -/**/ - FvwmWindow *testw; - int x12, x21, x22; - int y12, y21, y22; - int xl, xr, yt, yb; /* xleft, xright, ytop, ybottom */ - int aoi = 0; /* area of interference */ - int anew; - int avoidance_factor; - int PageBottom = Scr.MyDisplayHeight - pdeltay; - int PageRight = Scr.MyDisplayWidth - pdeltax; - int stickyx, stickyy; - - x12 = x11 + t->frame_width + 2 * t->bw; - y12 = y11 + t->frame_height + 2 * t->bw; - - if (y12 > PageBottom) /* No room in y direction */ - return -1; - if (x12 > PageRight) /* No room in x direction */ - return -2; - for(testw = Scr.FvwmRoot.next ; testw != NULL ; testw = testw->next) - { - if ((testw == t) || ((testw->Desk != t->Desk) && (! (testw->flags & STICKY)))) - continue; - - if (testw->flags & STICKY) - { - stickyx = pdeltax; - stickyy = pdeltay; - } - else - { - stickyx = 0; - stickyy = 0; - } - - if(testw->flags & ICONIFIED) - { - if(testw->icon_w == None || testw->flags & ICON_UNMAPPED) - continue; - x21 = testw->icon_x_loc - stickyx; - y21 = testw->icon_y_loc - stickyy; - x22 = x21 + testw->icon_p_width; - y22 = y21 + testw->icon_p_height + testw->icon_w_height; - } - else - { - x21 = testw->frame_x - stickyx; - y21 = testw->frame_y - stickyy; - x22 = x21 + testw->frame_width + 2 * testw->bw; - y22 = y21 + testw->frame_height + 2 * testw->bw; - } - if((x11 < x22) && (x12 > x21) && - (y11 < y22) && (y12 > y21)) - { - /* Windows interfere */ - xl = MAX(x11, x21); - xr = MIN(x12, x22); - yt = MAX(y11, y21); - yb = MIN(y12, y22); - anew = (xr - xl) * (yb - yt); - if(testw->flags & ICONIFIED) - avoidance_factor = AVOIDICON; - else if(testw->flags & ONTOP) - avoidance_factor = AVOIDONTOP; - else if(testw->flags & STICKY) - avoidance_factor = AVOIDSTICKY; - else - avoidance_factor = 1; - anew *= avoidance_factor; - aoi += anew; - if((aoi > aoimin)&&(aoimin != -1)) - return aoi; - } - } - return aoi; + /**/ + FvwmWindow *testw; + int x12, x21, x22; + int y12, y21, y22; + int xl, xr, yt, yb; /* xleft, xright, ytop, ybottom */ + int aoi = 0; /* area of interference */ + int anew; + int avoidance_factor; + int PageBottom = Scr.MyDisplayHeight - pdeltay; + int PageRight = Scr.MyDisplayWidth - pdeltax; + int stickyx, stickyy; + + x12 = x11 + t->frame_width + 2 * t->bw; + y12 = y11 + t->frame_height + 2 * t->bw; + + if (y12 > PageBottom) /* No room in y direction */ + return -1; + if (x12 > PageRight) /* No room in x direction */ + return -2; + for (testw = Scr.FvwmRoot.next; testw != NULL; testw = testw->next) { + if ((testw == t) || + ((testw->Desk != t->Desk) && (!(testw->flags & STICKY)))) + continue; + + if (testw->flags & STICKY) { + stickyx = pdeltax; + stickyy = pdeltay; + } else { + stickyx = 0; + stickyy = 0; + } + + if (testw->flags & ICONIFIED) { + if (testw->icon_w == None || + testw->flags & ICON_UNMAPPED) + continue; + x21 = testw->icon_x_loc - stickyx; + y21 = testw->icon_y_loc - stickyy; + x22 = x21 + testw->icon_p_width; + y22 = y21 + testw->icon_p_height + testw->icon_w_height; + } else { + x21 = testw->frame_x - stickyx; + y21 = testw->frame_y - stickyy; + x22 = x21 + testw->frame_width + 2 * testw->bw; + y22 = y21 + testw->frame_height + 2 * testw->bw; + } + if ((x11 < x22) && (x12 > x21) && (y11 < y22) && (y12 > y21)) { + /* Windows interfere */ + xl = MAX(x11, x21); + xr = MIN(x12, x22); + yt = MAX(y11, y21); + yb = MIN(y12, y22); + anew = (xr - xl) * (yb - yt); + if (testw->flags & ICONIFIED) + avoidance_factor = AVOIDICON; + else if (testw->flags & ONTOP) + avoidance_factor = AVOIDONTOP; + else if (testw->flags & STICKY) + avoidance_factor = AVOIDSTICKY; + else + avoidance_factor = 1; + anew *= avoidance_factor; + aoi += anew; + if ((aoi > aoimin) && (aoimin != -1)) + return aoi; + } + } + return aoi; } - /************************************************************************** * * Handles initial placement and sizing of a new window @@ -416,377 +404,385 @@ int test_fit(FvwmWindow *t, int x11, int y11, int aoimin, int pdeltax, * **************************************************************************/ /* RBW - 11/02/1998 */ -Bool PlaceWindow(FvwmWindow *tmp_win, unsigned long tflag,int Desk, int PageX, int PageY) +Bool +PlaceWindow( + FvwmWindow *tmp_win, unsigned long tflag, int Desk, int PageX, int PageY) { -/**/ - FvwmWindow *t; - int xl = -1,yt,DragWidth,DragHeight; - int gravx, gravy; /* gravity signs for positioning */ -/* RBW - 11/02/1998 */ - int px = 0, py = 0, pdeltax = 0, pdeltay = 0; - int PageRight = Scr.MyDisplayWidth, PageBottom = Scr.MyDisplayHeight; - int smartlyplaced = False; - Bool HonorStartsOnPage = False; - extern Bool Restarting; -/**/ - extern Boolean PPosOverride; - - yt = 0; - - GetGravityOffsets (tmp_win, &gravx, &gravy); - - - /* Select a desk to put the window on (in list of priority): - * 1. Sticky Windows stay on the current desk. - * 2. Windows specified with StartsOnDesk go where specified - * 3. Put it on the desk it was on before the restart. - * 4. Transients go on the same desk as their parents. - * 5. Window groups stay together (completely untested) - */ - -/* RBW - 11/02/1998 */ -/* - Let's get the StartsOnDesk/Page tests out of the way first. -*/ - if (tflag & STARTSONDESK_FLAG) - { - HonorStartsOnPage = True; - /* - Honor the flag unless... - it's a restart or recapture, and that option's disallowed... - */ - if (PPosOverride && (Restarting || (Scr.flags & WindowsCaptured)) && - !Scr.go.RecaptureHonorsStartsOnPage) - { - HonorStartsOnPage = False; - } - /* - it's a cold start window capture, and that's disallowed... - */ - if (PPosOverride && (!Restarting && !(Scr.flags & WindowsCaptured)) && - !Scr.go.CaptureHonorsStartsOnPage) - { - HonorStartsOnPage = False; - } - /* - we have a USPosition, and overriding it is disallowed... + /**/ + FvwmWindow *t; + int xl = -1, yt, DragWidth, DragHeight; + int gravx, gravy; /* gravity signs for positioning */ + /* RBW - 11/02/1998 */ + int px = 0, py = 0, pdeltax = 0, pdeltay = 0; + int PageRight = Scr.MyDisplayWidth, PageBottom = Scr.MyDisplayHeight; + int smartlyplaced = False; + Bool HonorStartsOnPage = False; + extern Bool Restarting; + /**/ + extern Boolean PPosOverride; + + yt = 0; + + GetGravityOffsets(tmp_win, &gravx, &gravy); + + /* Select a desk to put the window on (in list of priority): + * 1. Sticky Windows stay on the current desk. + * 2. Windows specified with StartsOnDesk go where specified + * 3. Put it on the desk it was on before the restart. + * 4. Transients go on the same desk as their parents. + * 5. Window groups stay together (completely untested) + */ + + /* RBW - 11/02/1998 */ + /* + Let's get the StartsOnDesk/Page tests out of the way first. */ - if (!PPosOverride && (USPosition && !Scr.go.ModifyUSP)) - { - HonorStartsOnPage = False; - } - /* - it's ActivePlacement and SkipMapping, and that's disallowed. + if (tflag & STARTSONDESK_FLAG) { + HonorStartsOnPage = True; + /* + Honor the flag unless... + it's a restart or recapture, and that option's + disallowed... + */ + if (PPosOverride && + (Restarting || (Scr.flags & WindowsCaptured)) && + !Scr.go.RecaptureHonorsStartsOnPage) { + HonorStartsOnPage = False; + } + /* + it's a cold start window capture, and that's disallowed... + */ + if (PPosOverride && + (!Restarting && !(Scr.flags & WindowsCaptured)) && + !Scr.go.CaptureHonorsStartsOnPage) { + HonorStartsOnPage = False; + } + /* + we have a USPosition, and overriding it is disallowed... + */ + if (!PPosOverride && ((USPosition != 0) && !Scr.go.ModifyUSP)) { + HonorStartsOnPage = False; + } + /* + it's ActivePlacement and SkipMapping, and that's + disallowed. + */ + if (!PPosOverride && + ((tmp_win->flags & SHOW_ON_MAP) && + (!(tflag & RANDOM_PLACE_FLAG)) && + !Scr.go.ActivePlacementHonorsStartsOnPage)) { + HonorStartsOnPage = False; + } + } + /**/ + + tmp_win->Desk = Scr.CurrentDesk; + if (tflag & STICKY_FLAG) + tmp_win->Desk = Scr.CurrentDesk; + else if ((tflag & STARTSONDESK_FLAG) && Desk && HonorStartsOnPage) + tmp_win->Desk = + (Desk > -1) ? Desk - 1 : Desk; /* RBW - 11/20/1998 */ + else { + Atom atype; + int aformat; + unsigned long nitems, bytes_remain; + unsigned char *prop; + + if ((tmp_win->wmhints) && + (tmp_win->wmhints->flags & WindowGroupHint) && + (tmp_win->wmhints->window_group != None) && + (tmp_win->wmhints->window_group != Scr.Root)) { + /* Try to find the group leader or another window + * in the group */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if ((t->w == tmp_win->wmhints->window_group) || + ((t->wmhints) && + (t->wmhints->flags & WindowGroupHint) && + (t->wmhints->window_group == + tmp_win->wmhints->window_group))) + tmp_win->Desk = t->Desk; + } + } + if ((tmp_win->flags & TRANSIENT) && + (tmp_win->transientfor != None) && + (tmp_win->transientfor != Scr.Root)) { + /* Try to find the parent's desktop */ + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + if (t->w == tmp_win->transientfor) + tmp_win->Desk = t->Desk; + } + } + + if ((XGetWindowProperty(dpy, tmp_win->w, _XA_WM_DESKTOP, 0L, 1L, + True, _XA_WM_DESKTOP, &atype, &aformat, &nitems, + &bytes_remain, &prop)) == Success) { + if (prop != NULL) { + tmp_win->Desk = *(unsigned long *)prop; + XFree(prop); + } + } + } + /* I think it would be good to switch to the selected desk + * whenever a new window pops up, except during initialization */ + if ((!PPosOverride) && (!(tmp_win->flags & SHOW_ON_MAP))) + /* RBW - 11/02/1998 -- I dont. */ + { + changeDesks(tmp_win->Desk); + } + + /* + Don't move viewport if SkipMapping, or if recapturing the window, + adjust the coordinates later. Otherwise, just switch to the target + page - it's ever so much simpler. */ - if (!PPosOverride && ((tmp_win->flags & SHOW_ON_MAP) && - (!(tflag & RANDOM_PLACE_FLAG)) && - !Scr.go.ActivePlacementHonorsStartsOnPage)) - { - HonorStartsOnPage = False; - } - } -/**/ - - tmp_win->Desk = Scr.CurrentDesk; - if (tflag & STICKY_FLAG) - tmp_win->Desk = Scr.CurrentDesk; - else if ((tflag & STARTSONDESK_FLAG) && Desk && HonorStartsOnPage) - tmp_win->Desk = (Desk > -1) ? Desk - 1 : Desk; /* RBW - 11/20/1998 */ - else - { - Atom atype; - int aformat; - unsigned long nitems, bytes_remain; - unsigned char *prop; - - if((tmp_win->wmhints)&&(tmp_win->wmhints->flags & WindowGroupHint)&& - (tmp_win->wmhints->window_group != None)&& - (tmp_win->wmhints->window_group != Scr.Root)) - { - /* Try to find the group leader or another window - * in the group */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if((t->w == tmp_win->wmhints->window_group)|| - ((t->wmhints)&&(t->wmhints->flags & WindowGroupHint)&& - (t->wmhints->window_group==tmp_win->wmhints->window_group))) - tmp_win->Desk = t->Desk; - } - } - if((tmp_win->flags & TRANSIENT)&&(tmp_win->transientfor!=None)&& - (tmp_win->transientfor != Scr.Root)) - { - /* Try to find the parent's desktop */ - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - if(t->w == tmp_win->transientfor) - tmp_win->Desk = t->Desk; - } - } - - if ((XGetWindowProperty(dpy, tmp_win->w, _XA_WM_DESKTOP, 0L, 1L, True, - _XA_WM_DESKTOP, &atype, &aformat, &nitems, - &bytes_remain, &prop))==Success) - { - if(prop != NULL) - { - tmp_win->Desk = *(unsigned long *)prop; - XFree(prop); - } - } - } - /* I think it would be good to switch to the selected desk - * whenever a new window pops up, except during initialization */ - if((!PPosOverride)&&(!(tmp_win->flags & SHOW_ON_MAP))) -/* RBW - 11/02/1998 -- I dont. */ - { - changeDesks(tmp_win->Desk); - } - -/* - Don't move viewport if SkipMapping, or if recapturing the window, - adjust the coordinates later. Otherwise, just switch to the target - page - it's ever so much simpler. -*/ - if (!(tflag & STICKY_FLAG) && (tflag & STARTSONDESK_FLAG)) - { - if (PageX && PageY) - { - px = PageX - 1; - py = PageY -1 ; - px *= Scr.MyDisplayWidth; - py *= Scr.MyDisplayHeight; - if ( (!PPosOverride) && (!(tmp_win->flags & SHOW_ON_MAP)) ) - { - MoveViewport(px,py,True); - } - else - { - if (HonorStartsOnPage) - { - /* Save the delta from current page */ - pdeltax = Scr.Vx - px; - pdeltay = Scr.Vy - py; - PageRight -= pdeltax; - PageBottom -= pdeltay; - } - } - } - } - -/**/ - - - /* Desk has been selected, now pick a location for the window */ - /* - * If - * o the window is a transient, or - * - * o a USPosition was requested - * - * then put the window where requested. - * - * If RandomPlacement was specified, - * then place the window in a psuedo-random location - */ - if (!(tmp_win->flags & TRANSIENT) && - !(tmp_win->hints.flags & USPosition) && - ((tflag & NO_PPOSITION_FLAG)|| - !(tmp_win->hints.flags & PPosition)) && - !(PPosOverride) && - /* RBW - allow StartsOnPage to go through, even if iconic. */ - ( ((!((tmp_win->wmhints)&& - (tmp_win->wmhints->flags & StateHint)&& - (tmp_win->wmhints->initial_state == IconicState))) - || (HonorStartsOnPage)) ) ) - { - /* Get user's window placement, unless RandomPlacement is specified */ - if(tflag & RANDOM_PLACE_FLAG) - { - if(tflag & SMART_PLACE_FLAG) - smartlyplaced = SmartPlacement(tmp_win,tmp_win->frame_width+2*tmp_win->bw, - tmp_win->frame_height+2*tmp_win->bw, - &xl,&yt, pdeltax, pdeltay); - if(! smartlyplaced) - { - /* place window in a random location */ - if ((Scr.randomx += GetDecor(tmp_win,TitleHeight)) > Scr.MyDisplayWidth / 2) - Scr.randomx = GetDecor(tmp_win,TitleHeight); - if ((Scr.randomy += 2*GetDecor(tmp_win,TitleHeight)) > Scr.MyDisplayHeight / 2) - Scr.randomy = 2 * GetDecor(tmp_win,TitleHeight); - tmp_win->attr.x = (Scr.randomx - pdeltax) - tmp_win->old_bw; - tmp_win->attr.y = (Scr.randomy - pdeltay) - tmp_win->old_bw; - } - else - { - tmp_win->attr.x = xl - tmp_win->old_bw + tmp_win->bw; - tmp_win->attr.y = yt - tmp_win->old_bw + tmp_win->bw; - } - /* patches 11/93 to try to keep the window on the - * screen */ - tmp_win->frame_x = tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; - tmp_win->frame_y = tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; - - if(tmp_win->frame_x + tmp_win->frame_width + - 2*tmp_win->boundary_width> PageRight) - { - tmp_win->attr.x = PageRight -tmp_win->attr.width - - tmp_win->old_bw +tmp_win->bw - 2*tmp_win->boundary_width; - Scr.randomx = 0; - } - if(tmp_win->frame_y + 2*tmp_win->boundary_width+tmp_win->title_height - + tmp_win->frame_height > PageBottom) - { - tmp_win->attr.y = PageBottom -tmp_win->attr.height - - tmp_win->old_bw +tmp_win->bw - tmp_win->title_height - - 2*tmp_win->boundary_width;; - Scr.randomy = 0; - } - - tmp_win->xdiff = tmp_win->attr.x; - tmp_win->ydiff = tmp_win->attr.y; - /* put it where asked, mod title bar */ - /* if the gravity is towards the top, move it by the title height */ - tmp_win->ydiff += gravy*(tmp_win->bw-tmp_win->old_bw); - tmp_win->xdiff += gravx*(tmp_win->bw-tmp_win->old_bw); - if(gravy > 0) - tmp_win->ydiff += 2*tmp_win->boundary_width + tmp_win->title_height; - if(gravx > 0) - tmp_win->xdiff += 2*tmp_win->boundary_width; - } - else - { - /* Must be ActivePlacement */ - xl = -1; - yt = -1; - if(tflag & SMART_PLACE_FLAG) - smartlyplaced = SmartPlacement(tmp_win,tmp_win->frame_width+2*tmp_win->bw, - tmp_win->frame_height+2*tmp_win->bw, - &xl,&yt, pdeltax, pdeltay); - if(! smartlyplaced) - { - if(GrabEm(POSITION)) - { - /* Grabbed the pointer - continue */ - MyXGrabServer(dpy); - if(XGetGeometry(dpy, tmp_win->w, &JunkRoot, &JunkX, &JunkY, - (unsigned int *)&DragWidth, - (unsigned int *)&DragHeight, - &JunkBW, &JunkDepth) == 0) - { - free((char *)tmp_win); - MyXUngrabServer(dpy); - return False; - } - DragWidth = tmp_win->frame_width; - DragHeight = tmp_win->frame_height; - - XMapRaised(dpy,Scr.SizeWindow); - moveLoop(tmp_win,0,0,DragWidth,DragHeight,&xl,&yt,False,True); - XUnmapWindow(dpy,Scr.SizeWindow); - MyXUngrabServer(dpy); - UngrabEm(); - } - else - { - /* couldn't grab the pointer - better do something */ - XBell(dpy, 0); - xl = 0; - yt = 0; - } - } - /* RBW - 01/24/1999 */ - if (HonorStartsOnPage && ! smartlyplaced) - { - xl -= pdeltax; - yt -= pdeltay; - } - /**/ - tmp_win->attr.y = yt - tmp_win->old_bw + tmp_win->bw; - tmp_win->attr.x = xl - tmp_win->old_bw + tmp_win->bw; - tmp_win->xdiff = xl ; - tmp_win->ydiff = yt ; - } - } - else - { - /* the USPosition was specified, or the window is a transient, - * or it starts iconic so place it automatically */ - -/* RBW - 11/02/1998 */ -/* - If SkipMapping, and other legalities are observed, adjust for StartsOnPage. -*/ - - if ( ( (tmp_win->flags & SHOW_ON_MAP) && HonorStartsOnPage ) && - - ( !(tmp_win->flags & TRANSIENT) && - - ((tflag & NO_PPOSITION_FLAG) || - !(tmp_win->hints.flags & PPosition)) && - - /* RBW - allow StartsOnPage to go through, even if iconic. */ - ( ((!((tmp_win->wmhints)&& - (tmp_win->wmhints->flags & StateHint)&& - (tmp_win->wmhints->initial_state == IconicState))) - || (HonorStartsOnPage)) ) - - ) ) - { - /* - We're placing a SkipMapping window - either capturing one that's - previously been mapped, or overriding USPosition - so what we - have here is its actual untouched coordinates. In case it was - a StartsOnPage window, we have to 1) convert the existing x,y - offsets relative to the requested page (i.e., as though there - were only one page, no virtual desktop), then 2) readjust - relative to the current page. - */ - - - if (tmp_win->attr.x < 0) - { - tmp_win->attr.x = ((Scr.MyDisplayWidth + tmp_win->attr.x) % Scr.MyDisplayWidth); - } - else - { - tmp_win->attr.x = tmp_win->attr.x % Scr.MyDisplayWidth; - } -/* - Noticed a quirk here. With some apps (e.g., xman), we find the - placement has moved 1 pixel away from where we originally put it when we - come through here. Why is this happening? - Probably old_bw, try xclock -borderwidth 100 -*/ - if (tmp_win->attr.y < 0) - { - tmp_win->attr.y = ((Scr.MyDisplayHeight + tmp_win->attr.y) % Scr.MyDisplayHeight); - } - else - { - tmp_win->attr.y = tmp_win->attr.y % Scr.MyDisplayHeight; - } - tmp_win->attr.x -= pdeltax; - tmp_win->attr.y -= pdeltay; - } -/**/ - - tmp_win->xdiff = tmp_win->attr.x; - tmp_win->ydiff = tmp_win->attr.y; - /* put it where asked, mod title bar */ - /* if the gravity is towards the top, move it by the title height */ - tmp_win->attr.y -= gravy*(tmp_win->bw-tmp_win->old_bw); - tmp_win->attr.x -= gravx*(tmp_win->bw-tmp_win->old_bw); - if(gravy > 0) - tmp_win->attr.y -= 2*tmp_win->boundary_width + tmp_win->title_height; - if(gravx > 0) - tmp_win->attr.x -= 2*tmp_win->boundary_width; - } - return True; + if (!(tflag & STICKY_FLAG) && (tflag & STARTSONDESK_FLAG)) { + if (PageX || PageY) { + int current_px = (Scr.MyDisplayWidth != 0) ? + Scr.Vx / Scr.MyDisplayWidth : + 0; + int current_py = (Scr.MyDisplayHeight != 0) ? + Scr.Vy / Scr.MyDisplayHeight : + 0; + + px = (PageX != 0) ? ((PageX > 0) ? PageX - 1 : PageX) : + current_px; + py = (PageY != 0) ? ((PageY > 0) ? PageY - 1 : PageY) : + current_py; + + px *= Scr.MyDisplayWidth; + py *= Scr.MyDisplayHeight; + + if ((!PPosOverride) && + (!(tmp_win->flags & SHOW_ON_MAP))) { + MoveViewport(px, py, True); + } else if (HonorStartsOnPage) { + pdeltax = Scr.Vx - px; + pdeltay = Scr.Vy - py; + PageRight -= pdeltax; + PageBottom -= pdeltay; + } + } + } + + /**/ + + /* Desk has been selected, now pick a location for the window */ + /* + * If + * o the window is a transient, or + * + * o a USPosition was requested + * + * then put the window where requested. + * + * If RandomPlacement was specified, + * then place the window in a psuedo-random location + */ + if (!(tmp_win->flags & TRANSIENT) && + !(tmp_win->hints.flags & USPosition) && + ((tflag & NO_PPOSITION_FLAG) || + !(tmp_win->hints.flags & PPosition)) && + !(PPosOverride) && + /* RBW - allow StartsOnPage to go through, even if iconic. */ + (((!((tmp_win->wmhints) && (tmp_win->wmhints->flags & StateHint) && + (tmp_win->wmhints->initial_state == IconicState))) || + (HonorStartsOnPage)))) { + /* Get user's window placement, unless RandomPlacement is + * specified */ + if (tflag & RANDOM_PLACE_FLAG) { + if (tflag & SMART_PLACE_FLAG) + smartlyplaced = SmartPlacement(tmp_win, + tmp_win->frame_width + 2 * tmp_win->bw, + tmp_win->frame_height + 2 * tmp_win->bw, + &xl, &yt, pdeltax, pdeltay); + if (!smartlyplaced) { + /* place window in a random location */ + if ((Scr.randomx += GetDecor(tmp_win, + TitleHeight)) > Scr.MyDisplayWidth / 2) + Scr.randomx = + GetDecor(tmp_win, TitleHeight); + if ((Scr.randomy += + 2 * GetDecor(tmp_win, TitleHeight)) > + Scr.MyDisplayHeight / 2) + Scr.randomy = + 2 * GetDecor(tmp_win, TitleHeight); + tmp_win->attr.x = + (Scr.randomx - pdeltax) - tmp_win->old_bw; + tmp_win->attr.y = + (Scr.randomy - pdeltay) - tmp_win->old_bw; + } else { + tmp_win->attr.x = + xl - tmp_win->old_bw + tmp_win->bw; + tmp_win->attr.y = + yt - tmp_win->old_bw + tmp_win->bw; + } + /* patches 11/93 to try to keep the window on the + * screen */ + tmp_win->frame_x = + tmp_win->attr.x + tmp_win->old_bw - tmp_win->bw; + tmp_win->frame_y = + tmp_win->attr.y + tmp_win->old_bw - tmp_win->bw; + + if (tmp_win->frame_x + tmp_win->frame_width + + 2 * tmp_win->boundary_width > + PageRight) { + tmp_win->attr.x = + PageRight - tmp_win->attr.width - + tmp_win->old_bw + tmp_win->bw - + 2 * tmp_win->boundary_width; + Scr.randomx = 0; + } + if (tmp_win->frame_y + 2 * tmp_win->boundary_width + + tmp_win->title_height + tmp_win->frame_height > + PageBottom) { + tmp_win->attr.y = + PageBottom - tmp_win->attr.height - + tmp_win->old_bw + tmp_win->bw - + tmp_win->title_height - + 2 * tmp_win->boundary_width; + ; + Scr.randomy = 0; + } + + tmp_win->xdiff = tmp_win->attr.x; + tmp_win->ydiff = tmp_win->attr.y; + /* put it where asked, mod title bar */ + /* if the gravity is towards the top, move it by the + * title height */ + tmp_win->ydiff += + gravy * (tmp_win->bw - tmp_win->old_bw); + tmp_win->xdiff += + gravx * (tmp_win->bw - tmp_win->old_bw); + if (gravy > 0) + tmp_win->ydiff += 2 * tmp_win->boundary_width + + tmp_win->title_height; + if (gravx > 0) + tmp_win->xdiff += 2 * tmp_win->boundary_width; + } else { + /* Must be ActivePlacement */ + xl = -1; + yt = -1; + if (tflag & SMART_PLACE_FLAG) + smartlyplaced = SmartPlacement(tmp_win, + tmp_win->frame_width + 2 * tmp_win->bw, + tmp_win->frame_height + 2 * tmp_win->bw, + &xl, &yt, pdeltax, pdeltay); + if (!smartlyplaced) { + if (GrabEm(POSITION)) { + /* Grabbed the pointer - continue */ + MyXGrabServer(dpy); + if (XGetGeometry(dpy, tmp_win->w, + &JunkRoot, &JunkX, &JunkY, + (unsigned int *)&DragWidth, + (unsigned int *)&DragHeight, + &JunkBW, &JunkDepth) == 0) { + free((char *)tmp_win); + MyXUngrabServer(dpy); + return False; + } + DragWidth = tmp_win->frame_width; + DragHeight = tmp_win->frame_height; + + XMapRaised(dpy, Scr.SizeWindow); + moveLoop(tmp_win, 0, 0, DragWidth, + DragHeight, &xl, &yt, False, True); + XUnmapWindow(dpy, Scr.SizeWindow); + MyXUngrabServer(dpy); + UngrabEm(); + } else { + /* couldn't grab the pointer - better do + * something */ + XBell(dpy, 0); + xl = 0; + yt = 0; + } + } + /* RBW - 01/24/1999 */ + if (HonorStartsOnPage && !smartlyplaced) { + xl -= pdeltax; + yt -= pdeltay; + } + /**/ + tmp_win->attr.y = yt - tmp_win->old_bw + tmp_win->bw; + tmp_win->attr.x = xl - tmp_win->old_bw + tmp_win->bw; + tmp_win->xdiff = xl; + tmp_win->ydiff = yt; + } + } else { + /* the USPosition was specified, or the window is a transient, + * or it starts iconic so place it automatically */ + + /* RBW - 11/02/1998 */ + /* + If SkipMapping, and other legalities are observed, adjust for + StartsOnPage. + */ + + if (((tmp_win->flags & SHOW_ON_MAP) && HonorStartsOnPage) && + (!(tmp_win->flags & TRANSIENT) && + ((tflag & NO_PPOSITION_FLAG) || + !(tmp_win->hints.flags & PPosition)) && + /* RBW - allow StartsOnPage to go through, even if + iconic. */ + (((!((tmp_win->wmhints) && + (tmp_win->wmhints->flags & StateHint) && + (tmp_win->wmhints->initial_state == IconicState))) || + (HonorStartsOnPage))))) { + /* + We're placing a SkipMapping window - either + capturing one that's previously been mapped, or + overriding USPosition - so what we have here is its + actual untouched coordinates. In case it was a + StartsOnPage window, we have to 1) convert the + existing x,y offsets relative to the requested page + (i.e., as though there were only one page, no virtual + desktop), then 2) readjust relative to the current + page. + */ + + if (tmp_win->attr.x < 0) { + tmp_win->attr.x = + ((Scr.MyDisplayWidth + tmp_win->attr.x) % + Scr.MyDisplayWidth); + } else { + tmp_win->attr.x = + tmp_win->attr.x % Scr.MyDisplayWidth; + } + /* + Noticed a quirk here. With some apps (e.g., xman), we find + the placement has moved 1 pixel away from where we + originally put it when we come through here. Why is this + happening? Probably old_bw, try xclock -borderwidth 100 + */ + if (tmp_win->attr.y < 0) { + tmp_win->attr.y = + ((Scr.MyDisplayHeight + tmp_win->attr.y) % + Scr.MyDisplayHeight); + } else { + tmp_win->attr.y = + tmp_win->attr.y % Scr.MyDisplayHeight; + } + tmp_win->attr.x -= pdeltax; + tmp_win->attr.y -= pdeltay; + } + /**/ + + tmp_win->xdiff = tmp_win->attr.x; + tmp_win->ydiff = tmp_win->attr.y; + /* put it where asked, mod title bar */ + /* if the gravity is towards the top, move it by the title + * height */ + tmp_win->attr.y -= gravy * (tmp_win->bw - tmp_win->old_bw); + tmp_win->attr.x -= gravx * (tmp_win->bw - tmp_win->old_bw); + if (gravy > 0) + tmp_win->attr.y -= + 2 * tmp_win->boundary_width + tmp_win->title_height; + if (gravx > 0) + tmp_win->attr.x -= 2 * tmp_win->boundary_width; + } + return True; } - - /************************************************************************ * * Procedure: @@ -794,36 +790,35 @@ Bool PlaceWindow(FvwmWindow *tmp_win, unsigned long tflag,int Desk, int PageX, i * to x and y when window is mapped to get proper placement. * ************************************************************************/ -struct _gravity_offset -{ - int x, y; +struct _gravity_offset { + int x, y; }; -void GetGravityOffsets (FvwmWindow *tmp,int *xp,int *yp) +void +GetGravityOffsets(FvwmWindow *tmp, int *xp, int *yp) { - static struct _gravity_offset gravity_offsets[11] = - { - { 0, 0 }, /* ForgetGravity */ - { -1, -1 }, /* NorthWestGravity */ - { 0, -1 }, /* NorthGravity */ - { 1, -1 }, /* NorthEastGravity */ - { -1, 0 }, /* WestGravity */ - { 0, 0 }, /* CenterGravity */ - { 1, 0 }, /* EastGravity */ - { -1, 1 }, /* SouthWestGravity */ - { 0, 1 }, /* SouthGravity */ - { 1, 1 }, /* SouthEastGravity */ - { 0, 0 }, /* StaticGravity */ - }; - register int g = ((tmp->hints.flags & PWinGravity) - ? tmp->hints.win_gravity : NorthWestGravity); - - if (g < ForgetGravity || g > StaticGravity) - *xp = *yp = 0; - else - { - *xp = (int)gravity_offsets[g].x; - *yp = (int)gravity_offsets[g].y; - } - return; + static struct _gravity_offset gravity_offsets[11] = { + {0, 0}, /* ForgetGravity */ + {-1, -1}, /* NorthWestGravity */ + {0, -1}, /* NorthGravity */ + {1, -1}, /* NorthEastGravity */ + {-1, 0}, /* WestGravity */ + {0, 0}, /* CenterGravity */ + {1, 0}, /* EastGravity */ + {-1, 1}, /* SouthWestGravity */ + {0, 1}, /* SouthGravity */ + {1, 1}, /* SouthEastGravity */ + {0, 0}, /* StaticGravity */ + }; + register int g = + ((tmp->hints.flags & PWinGravity) ? tmp->hints.win_gravity : + NorthWestGravity); + + if (g < ForgetGravity || g > StaticGravity) + *xp = *yp = 0; + else { + *xp = (int)gravity_offsets[g].x; + *yp = (int)gravity_offsets[g].y; + } + return; } Index: fvwm/fvwm/read.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/read.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/read.c --- fvwm/fvwm/read.c +++ fvwm/fvwm/read.c @@ -11,21 +11,26 @@ * Its now in "modconf.c". * ************************************************************************* */ -#include "config.h" +#include +#include +#include +#include -#include +#include +#include +#include #include +#include #include -#include #include -#include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" extern Boolean debugging; @@ -33,10 +38,114 @@ char *fvwm_file = NULL; int numfilesread = 0; -static int last_read_failed=0; +#define MAX_NESTING_DEPTH 128 + +static int last_read_failed = 0; + +static const char *read_system_rc_cmd = "Read system" FVWMRC; + +typedef struct { + FILE *stream; + pid_t pid; + int fd; +} PipeChild; + +#define PIPE_READ_INTERVAL_SEC 1 +#define PIPE_READ_MAX_IDLE_LOOPS 10 +#define PIPE_REAP_WAIT_USEC 100000 +#define PIPE_REAP_ATTEMPTS 20 + +static int +start_pipe_process(const char *command, PipeChild *child) +{ + int pipe_fd[2]; + pid_t pid; + + if (pipe(pipe_fd) < 0) + return -1; + + pid = fork(); + if (pid < 0) { + close(pipe_fd[0]); + close(pipe_fd[1]); + return -1; + } + + if (pid == 0) { + close(pipe_fd[0]); + if (dup2(pipe_fd[1], STDOUT_FILENO) == -1) + _exit(127); + close(pipe_fd[1]); + execl("/bin/sh", "sh", "-c", command, (char *)NULL); + _exit(127); + } + + close(pipe_fd[1]); + child->fd = pipe_fd[0]; + child->stream = fdopen(child->fd, "r"); + if (child->stream == NULL) { + close(child->fd); + kill(pid, SIGTERM); + (void)waitpid(pid, NULL, 0); + child->fd = -1; + return -1; + } + fcntl(child->fd, F_SETFD, 1); + child->pid = pid; + return 0; +} + +static void +stop_pipe_process( + PipeChild *child, int timed_out, const char *cmdname, const char *command) +{ + int status; + int attempt; + pid_t waited = -1; + + if (child->stream) { + fclose(child->stream); + child->stream = NULL; + } + + if (child->fd >= 0) + child->fd = -1; + + if (child->pid <= 0) + return; -static const char *read_system_rc_cmd="Read system"FVWMRC; + if (timed_out) { + fvwm_msg(WARN, cmdname, + "command '%s' did not close pipe, terminating it", command); + kill(child->pid, SIGTERM); + } + for (attempt = 0; attempt < PIPE_REAP_ATTEMPTS; ++attempt) { + waited = waitpid(child->pid, &status, timed_out ? WNOHANG : 0); + if (waited == child->pid) + break; + if (waited == -1) { + if (errno == EINTR) + continue; + if (errno != ECHILD) + fvwm_msg(ERR, cmdname, + "waitpid failed for '%s': %s", command, + strerror(errno)); + break; + } + if (waited == 0) + usleep(PIPE_REAP_WAIT_USEC); + } + + if (timed_out && waited != child->pid) { + kill(child->pid, SIGKILL); + while ((waited = waitpid(child->pid, &status, 0)) == -1 && + errno == EINTR) + ; + } + + child->pid = -1; +} extern void StartupStuff(void); @@ -45,209 +154,248 @@ extern void StartupStuff(void); * Arg 1 is file name to read. * Arg 2 (optional) "Quiet" to suppress message on missing file. */ -static void ReadSubFunc(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module, - int piperead) +static void +ReadSubFunc(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module, int piperead) { - char *filename= NULL,*Home, *home_file, *ofilename = NULL; - char *option; /* optional arg to read */ - char *rest,*tline,line[1024]; - FILE *fd; - int thisfileno; - char missing_quiet; /* missing file msg control */ - char *cmdname; - size_t len; - - /* domivogt (30-Dec-1998: I tried using conditional evaluation instead - * of the cmdname variable ( piperead?"PipeRead":"Read" ), but gcc seems - * to treat this expression as a pointer to a character pointer, not just - * as a character pointer, but it doesn't complain either. Or perhaps - * insure++ gets this wrong? */ - if (piperead) - cmdname = "PipeRead"; - else - cmdname = "Read"; - - thisfileno = numfilesread; - numfilesread++; - -/* fvwm_msg(INFO,cmdname,"action == '%s'",action); */ - - rest = GetNextToken(action,&ofilename); /* read file name arg */ - if(ofilename == NULL) - { - fvwm_msg(ERR, cmdname,"missing parameter"); - last_read_failed = 1; - return; - } - missing_quiet='n'; /* init */ - rest = GetNextToken(rest,&option); /* read optional arg */ - if (option != NULL) { /* if there is a second arg */ - if (strncasecmp(option,"Quiet",5)==0) { /* is the arg "quiet"? */ - missing_quiet='y'; /* no missing file message wanted */ - } /* end quiet arg */ - free(option); /* arg not needed after this */ - } /* end there is a second arg */ - - filename = ofilename; -/* fvwm_msg(INFO, cmdname,"trying '%s'",filename); */ - - if (piperead) - fd = popen(filename,"r"); - else if (ofilename[0] != '/') - { - /* find the home directory to look in */ - Home = getenv("HOME"); - if (Home != NULL) - { - len = strlen(Home) + strlen(ofilename) + 3; - home_file = safemalloc(len); - strlcpy(home_file,Home,len); - strlcat(home_file,"/",len); - strlcat(home_file,ofilename,len); - filename = home_file; - fd = fopen(filename,"r"); - } - else - { - fd = 0; - } - if (fd == 0) - { - if((filename != NULL)&&(filename!= ofilename)) - free(filename); - /* find the home directory to look in */ - Home = FVWM_CONFIGDIR; - len = strlen(Home) + strlen(ofilename) + 3; - home_file = safemalloc(len); - strlcpy(home_file,Home,len); - strlcat(home_file,"/",len); - strlcat(home_file,ofilename,len); - filename = home_file; - fd = fopen(filename,"r"); - } - } - else - { - /* open file with absolute path */ - fd = fopen(filename,"r"); - } - - if(fd == NULL) - { - if (missing_quiet == 'n') { /* if quiet option not on */ - if (piperead) - fvwm_msg(ERR, cmdname, "command '%s' not run", ofilename); - else - fvwm_msg(ERR, cmdname, - "file '%s' not found in $HOME or "FVWM_CONFIGDIR, ofilename); - } /* end quiet option not on */ - if((ofilename != filename)&&(filename != NULL)) - { - free(filename); - } - if(ofilename != NULL) - { - free(ofilename); - } - last_read_failed = 1; - return; - } - if((ofilename != NULL)&&(filename!= ofilename)) - free(ofilename); - fcntl(fileno(fd), F_SETFD, 1); - if (!piperead) - { - if(fvwm_file != NULL) - free(fvwm_file); - fvwm_file = filename; - } - else - { - if (filename) - free(filename); - } - - tline = fgets(line,(sizeof line)-1,fd); - while(tline) - { - int l; - while(tline && (l = strlen(line)) < sizeof(line) && l >= 2 && - line[l-2]=='\\' && line[l-1]=='\n') - { - tline = fgets(line+l-2,sizeof(line)-l+1,fd); - } - tline=line; - while(isspace(*tline)) - tline++; - if (debugging) - { - fvwm_msg(DBG,"ReadSubFunc","about to exec: '%s'",tline); - } - ExecuteFunction(tline,tmp_win,eventp,context,*Module); - tline = fgets(line,(sizeof line)-1,fd); - } - - if (piperead) - pclose(fd); - else - fclose(fd); - last_read_failed = 0; + + if (numfilesread >= MAX_NESTING_DEPTH) { + fvwm_msg(ERR, piperead ? "PipeRead" : "Read", + "nesting depth exceeded (%d)", MAX_NESTING_DEPTH); + return; + } + char *filename = NULL, *Home, *home_file, *ofilename = NULL; + char *option; /* optional arg to read */ + char *rest, *tline, line[1024]; + FILE *stream = NULL; + PipeChild child = {NULL, -1, -1}; + int thisfileno; + char missing_quiet; /* missing file msg control */ + char *cmdname; + size_t len; + int timed_out = 0; + int idle_loops = 0; + + /* domivogt (30-Dec-1998: I tried using conditional evaluation instead + * of the cmdname variable ( piperead?"PipeRead":"Read" ), but gcc seems + * to treat this expression as a pointer to a character pointer, not + * just as a character pointer, but it doesn't complain either. Or + * perhaps insure++ gets this wrong? */ + if (piperead) + cmdname = "PipeRead"; + else + cmdname = "Read"; + + thisfileno = numfilesread; + numfilesread++; + + /* fvwm_msg(INFO,cmdname,"action == '%s'",action); */ + + rest = GetNextToken(action, &ofilename); /* read file name arg */ + if (ofilename == NULL) { + fvwm_msg(ERR, cmdname, "missing parameter"); + last_read_failed = 1; + return; + } + missing_quiet = 'n'; /* init */ + rest = GetNextToken(rest, &option); /* read optional arg */ + if (option != NULL) { /* if there is a second arg */ + if (strncasecmp(option, "Quiet", 5) == + 0) { /* is the arg "quiet"? */ + missing_quiet = + 'y'; /* no missing file message wanted */ + } /* end quiet arg */ + free(option); /* arg not needed after this */ + } /* end there is a second arg */ + + if (piperead) { + child.pid = -1; + child.fd = -1; + child.stream = NULL; + if (start_pipe_process(ofilename, &child) == 0) + stream = child.stream; + } else { + filename = ofilename; + if (ofilename[0] != '/') { + Home = getenv("HOME"); + if (Home != NULL) { + len = strlen(Home) + strlen(ofilename) + 3; + home_file = xmalloc(len); + strlcpy(home_file, Home, len); + strlcat(home_file, "/", len); + strlcat(home_file, ofilename, len); + filename = home_file; + stream = fopen(filename, "r"); + } else { + stream = NULL; + } + if (stream == NULL) { + if ((filename != NULL) && + (filename != ofilename)) + free(filename); + Home = FVWM_CONFIGDIR; + len = strlen(Home) + strlen(ofilename) + 3; + home_file = xmalloc(len); + strlcpy(home_file, Home, len); + strlcat(home_file, "/", len); + strlcat(home_file, ofilename, len); + filename = home_file; + stream = fopen(filename, "r"); + } + } else { + stream = fopen(filename, "r"); + } + } + + if (stream == NULL) { + if (missing_quiet == 'n') { + if (piperead) + fvwm_msg(ERR, cmdname, "command '%s' not run", + ofilename); + else + fvwm_msg(ERR, cmdname, + "file '%s' not found in $HOME " + "or " FVWM_CONFIGDIR, + ofilename); + } + if (!piperead && filename && filename != ofilename) + free(filename); + if (piperead && child.pid > 0) + stop_pipe_process(&child, 1, cmdname, ofilename); + if (piperead || (filename != ofilename)) + free(ofilename); + last_read_failed = 1; + return; + } + + if (!piperead) { + if (filename != ofilename && ofilename != NULL) { + free(ofilename); + ofilename = NULL; + } + fcntl(fileno(stream), F_SETFD, 1); + if (fvwm_file != NULL) + free(fvwm_file); + fvwm_file = filename; + } + + while (stream && !timed_out) { + if (piperead) { + fd_set readfds; + struct timeval tv; + int ready; + + FD_ZERO(&readfds); + FD_SET(child.fd, &readfds); + tv.tv_sec = PIPE_READ_INTERVAL_SEC; + tv.tv_usec = 0; + + ready = select(child.fd + 1, &readfds, NULL, NULL, &tv); + if (ready < 0) { + if (errno == EINTR) + continue; + timed_out = 1; + break; + } + if (ready == 0) { + if (++idle_loops >= PIPE_READ_MAX_IDLE_LOOPS) { + timed_out = 1; + break; + } + continue; + } + idle_loops = 0; + } + + tline = fgets(line, (sizeof line) - 1, stream); + if (tline == NULL) { + if (!piperead || feof(stream)) + break; + if (ferror(stream)) { + clearerr(stream); + continue; + } + break; + } + { + int l; + while ((l = strlen(line)) < sizeof(line) && l >= 2 && + line[l - 2] == '\\' && line[l - 1] == '\n') { + char *cont = fgets( + line + l - 2, sizeof(line) - l + 1, stream); + if (cont == NULL) + break; + } + } + tline = line; + while (isspace(*tline)) + tline++; + if (debugging) { + fvwm_msg( + DBG, "ReadSubFunc", "about to exec: '%s'", tline); + } + ExecuteFunction(tline, tmp_win, eventp, context, *Module); + } + + if (piperead) + stop_pipe_process(&child, timed_out, cmdname, ofilename); + else + fclose(stream); + if (piperead && ofilename) + free(ofilename); + last_read_failed = timed_out; } -void ReadFile(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +ReadFile(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int this_read = numfilesread; - - if (debugging) - { - fvwm_msg(DBG,"ReadFile","about to attempt '%s'",action); - } - - ReadSubFunc(eventp,junk,tmp_win,context,action,Module,0); - - if (last_read_failed && this_read == 0) - { - fvwm_msg(INFO,"Read","trying to read system rc file"); - ExecuteFunction((char *)read_system_rc_cmd,NULL,&Event,C_ROOT,-1); - } - - if (this_read == 0) - { - if (debugging) - { - fvwm_msg(DBG,"ReadFile","about to call startup functions"); - } - StartupStuff(); - } + int this_read = numfilesread; + + if (debugging) { + fvwm_msg(DBG, "ReadFile", "about to attempt '%s'", action); + } + + ReadSubFunc(eventp, junk, tmp_win, context, action, Module, 0); + + if (last_read_failed && this_read == 0) { + fvwm_msg(INFO, "Read", "trying to read system rc file"); + ExecuteFunction( + (char *)read_system_rc_cmd, NULL, &Event, C_ROOT, -1); + } + + if (this_read == 0) { + if (debugging) { + fvwm_msg( + DBG, "ReadFile", "about to call startup functions"); + } + StartupStuff(); + } } -void PipeRead(XEvent *eventp,Window junk,FvwmWindow *tmp_win, - unsigned long context, char *action,int* Module) +void +PipeRead(XEvent *eventp, Window junk, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int this_read = numfilesread; - - if (debugging) - { - fvwm_msg(DBG,"PipeRead","about to attempt '%s'",action); - } - - ReadSubFunc(eventp,junk,tmp_win,context,action,Module,1); - - if (last_read_failed && this_read == 0) - { - fvwm_msg(INFO,"PipeRead","trying to read system rc file"); - ExecuteFunction((char *)read_system_rc_cmd,NULL,&Event,C_ROOT,-1); - } - - if (this_read == 0) - { - if (debugging) - { - fvwm_msg(DBG,"PipeRead","about to call startup functions"); - } - StartupStuff(); - } -} + int this_read = numfilesread; + + if (debugging) { + fvwm_msg(DBG, "PipeRead", "about to attempt '%s'", action); + } + ReadSubFunc(eventp, junk, tmp_win, context, action, Module, 1); + + if (last_read_failed && this_read == 0) { + fvwm_msg(INFO, "PipeRead", "trying to read system rc file"); + ExecuteFunction( + (char *)read_system_rc_cmd, NULL, &Event, C_ROOT, -1); + } + + if (this_read == 0) { + if (debugging) { + fvwm_msg( + DBG, "PipeRead", "about to call startup functions"); + } + StartupStuff(); + } +} Index: fvwm/fvwm/resize.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/resize.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/resize.c --- fvwm/fvwm/resize.c +++ fvwm/fvwm/resize.c @@ -1,4 +1,3 @@ - /**************************************************************************** * This module is all original code * by Rob Nation @@ -7,27 +6,25 @@ * copyright remains in the source code and all documentation ****************************************************************************/ - /*********************************************************************** * * window resizing borrowed from the "wm" window manager * ***********************************************************************/ -#include "config.h" - -#include #include +#include + +#include "config.h" #include "fvwm.h" #include "misc.h" -#include "screen.h" #include "parse.h" +#include "screen.h" -typedef struct geom -{ - int x; - int y; - int width; - int height; +typedef struct geom { + int x; + int y; + int width; + int height; } geom; /* DO NOT USE (STATIC) GLOBALS IN THIS MODULE! @@ -37,282 +34,279 @@ typedef struct geom extern int menuFromFrameOrWindowOrTitlebar; extern Window PressedW; -static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, - geom *drag, geom *orig, int *xmotionp, int *ymotionp); +static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, geom *drag, + geom *orig, int *xmotionp, int *ymotionp); /**************************************************************************** * * Starts a window resize operation * ****************************************************************************/ -void resize_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +resize_window(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - Bool finished = FALSE, done = FALSE, abort = FALSE; - int x,y,delta_x,delta_y,stashed_x,stashed_y; - Window ResizeWindow; - Bool flags; - Bool fButtonAbort = False; - int val1, val2, val1_unit,val2_unit,n; - unsigned int button_mask = 0; - geom sdrag; - geom sorig; - geom *drag = &sdrag; - geom *orig = &sorig; - int ymotion=0, xmotion = 0; - - if (DeferExecution(eventp,&w,&tmp_win,&context, MOVE, ButtonPress)) - return; - - if (tmp_win == NULL) - return; - - XQueryPointer( dpy, Scr.Root, &JunkRoot, &JunkChild, - &JunkX, &JunkY, &JunkX, &JunkY, &button_mask); - button_mask &= Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask; - - if(check_allowed_function2(F_RESIZE,tmp_win) == 0 + Bool finished = FALSE, done = FALSE, abort = FALSE; + int x, y, delta_x, delta_y, stashed_x, stashed_y; + Window ResizeWindow; + Bool flags; + Bool fButtonAbort = False; + int val1, val2, val1_unit, val2_unit, n; + unsigned int button_mask = 0; + geom sdrag; + geom sorig; + geom *drag = &sdrag; + geom *orig = &sorig; + int ymotion = 0, xmotion = 0; + + if (DeferExecution(eventp, &w, &tmp_win, &context, MOVE, ButtonPress)) + return; + + if (tmp_win == NULL) + return; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &JunkX, &JunkY, + &JunkX, &JunkY, &button_mask); + button_mask &= + Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask; + + if (check_allowed_function2(F_RESIZE, tmp_win) == 0 #ifdef WINDOWSHADE - || (tmp_win->buttons & WSHADE) + || (tmp_win->buttons & WSHADE) #endif - ) - { - XBell(dpy, 0); - return; - } - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - - tmp_win->flags &= ~MAXIMIZED; - - /* Already checked this in functions.c, but its here too incase - * there's a resize on initial placement. */ - if(check_allowed_function2(F_RESIZE,tmp_win) == 0) - { - XBell(dpy, 0); - return; - } - /* can't resize icons */ - if(tmp_win->flags & ICONIFIED) - return; - - ResizeWindow = tmp_win->frame; - - if(n == 2) - { - drag->width = val1*val1_unit/100; - drag->height = val2*val2_unit/100; - drag->width += (2*tmp_win->boundary_width); - drag->height += (tmp_win->title_height + 2*tmp_win->boundary_width); - - /* size will be less or equal to requested */ - ConstrainSize (tmp_win, &drag->width, &drag->height, False, xmotion, - ymotion); - SetupFrame (tmp_win, tmp_win->frame_x, - tmp_win->frame_y ,drag->width, drag->height,FALSE); - - ResizeWindow = None; - return; - } - - InstallRootColormap(); - - if(!GrabEm(MOVE)) - { - XBell(dpy, 0); - return; - } - - MyXGrabServer(dpy); - - - /* handle problems with edge-wrapping while resizing */ - flags = Scr.flags; - Scr.flags &= ~(EdgeWrapX|EdgeWrapY); - - XGetGeometry(dpy, (Drawable) ResizeWindow, &JunkRoot, - &drag->x, &drag->y, (unsigned int *)&drag->width, - (unsigned int *)&drag->height, &JunkBW,&JunkDepth); - - drag->x += tmp_win->bw; - drag->y += tmp_win->bw; - orig->x = drag->x; - orig->y = drag->y; - orig->width = drag->width; - orig->height = drag->height; - ymotion=xmotion=0; - - /* pop up a resize dimensions window */ - XMapRaised(dpy, Scr.SizeWindow); - DisplaySize(tmp_win, orig->width, orig->height,True,True); - - /* Get the current position to determine which border to resize */ - if((PressedW != Scr.Root)&&(PressedW != None)) - { - if(PressedW == tmp_win->sides[0]) /* top */ - ymotion = 1; - if(PressedW == tmp_win->sides[1]) /* right */ - xmotion = -1; - if(PressedW == tmp_win->sides[2]) /* bottom */ - ymotion = -1; - if(PressedW == tmp_win->sides[3]) /* left */ - xmotion = 1; - if(PressedW == tmp_win->corners[0]) /* upper-left */ - { - ymotion = 1; - xmotion = 1; - } - if(PressedW == tmp_win->corners[1]) /* upper-right */ - { - xmotion = -1; - ymotion = 1; + ) { + XBell(dpy, 0); + return; } - if(PressedW == tmp_win->corners[2]) /* lower left */ - { - ymotion = -1; - xmotion = 1; + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + + tmp_win->flags &= ~MAXIMIZED; + + /* Already checked this in functions.c, but its here too incase + * there's a resize on initial placement. */ + if (check_allowed_function2(F_RESIZE, tmp_win) == 0) { + XBell(dpy, 0); + return; } - if(PressedW == tmp_win->corners[3]) /* lower right */ - { - ymotion = -1; - xmotion = -1; + /* can't resize icons */ + if (tmp_win->flags & ICONIFIED) + return; + + ResizeWindow = tmp_win->frame; + + if (n == 2) { + drag->width = val1 * val1_unit / 100; + drag->height = val2 * val2_unit / 100; + drag->width += (2 * tmp_win->boundary_width); + drag->height += + (tmp_win->title_height + 2 * tmp_win->boundary_width); + + /* size will be less or equal to requested */ + ConstrainSize(tmp_win, &drag->width, &drag->height, False, + xmotion, ymotion); + SetupFrame(tmp_win, tmp_win->frame_x, tmp_win->frame_y, + drag->width, drag->height, FALSE); + + ResizeWindow = None; + return; } - } - /* draw the rubber-band window */ - MoveOutline (Scr.Root, drag->x - tmp_win->bw, drag->y - tmp_win->bw, - drag->width - 1 + 2 * tmp_win->bw, - drag->height - 1 + 2 * tmp_win->bw); - /* kick off resizing without requiring any motion if invoked with a key press */ - if (eventp->type == KeyPress) - { - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &stashed_x,&stashed_y,&JunkX, &JunkY, &JunkMask); - DoResize(stashed_x, stashed_y, tmp_win, drag, orig, &xmotion, &ymotion); - } - else - stashed_x = stashed_y = -1; - - /* loop to resize */ - while(!finished) - { - XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | KeyPressMask | - ButtonMotionMask | PointerMotionMask | ExposureMask, &Event); - StashEventTime(&Event); - - if (Event.type == MotionNotify) - /* discard any extra motion events before a release */ - while(XCheckMaskEvent(dpy, ButtonMotionMask | ButtonReleaseMask | - PointerMotionMask,&Event)) - { - StashEventTime(&Event); - if (Event.type == ButtonRelease) break; - } - - done = FALSE; - /* Handle a limited number of key press events to allow mouseless - * operation */ - if(Event.type == KeyPress) - Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); - switch(Event.type) - { - case ButtonPress: - XAllowEvents(dpy,ReplayPointer,CurrentTime); - done = TRUE; - if (((Event.xbutton.button == 1) && (button_mask & Button1Mask)) || - ((Event.xbutton.button == 2) && (button_mask & Button2Mask)) || - ((Event.xbutton.button == 3) && (button_mask & Button3Mask)) || - ((Event.xbutton.button == 4) && (button_mask & Button4Mask)) || - ((Event.xbutton.button == 5) && (button_mask & Button5Mask))) - { - /* No new button was pressed, just a delayed event */ - break; - } - /* Abort the resize if - * - the move started with a pressed button and another button - * was pressed during the operation - * - no button was started at the beginning and any button - * except button 1 was pressed. */ - if (button_mask || (Event.xbutton.button != 1)) - fButtonAbort = TRUE; - case KeyPress: - /* simple code to bag out of move - CKH */ - if (XLookupKeysym(&(Event.xkey),0) == XK_Escape || fButtonAbort) - { - abort = TRUE; - finished = TRUE; - /* return pointer if aborted resize was invoked with key */ - if (stashed_x >= 0) - XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, stashed_x, - stashed_y); - } - done = TRUE; - break; - - case ButtonRelease: - finished = TRUE; - done = TRUE; - break; - - case MotionNotify: - x = Event.xmotion.x_root; - y = Event.xmotion.y_root; - /* resize before paging request to prevent resize from lagging - * mouse - mab */ - DoResize(x, y, tmp_win, drag, orig, &xmotion, &ymotion); - /* need to move the viewport */ - HandlePaging(Scr.EdgeScrollX,Scr.EdgeScrollY,&x,&y, - &delta_x,&delta_y,False); - /* redraw outline if we paged - mab */ - if ( (delta_x != 0) || (delta_y != 0) ) - { - orig->x -= delta_x; - orig->y -= delta_y; - drag->x -= delta_x; - drag->y -= delta_y; - - DoResize(x, y, tmp_win, drag, orig, &xmotion, &ymotion); - } - done = TRUE; - default: - break; + + InstallRootColormap(); + + if (!GrabEm(MOVE)) { + XBell(dpy, 0); + return; } - if(!done) - { - MoveOutline(Scr.Root,0,0,0,0); - DispatchEvent(); - MoveOutline(Scr.Root, drag->x - tmp_win->bw, drag->y - tmp_win->bw, - drag->width - 1 + 2 * tmp_win->bw, - drag->height - 1 + 2 * tmp_win->bw); + MyXGrabServer(dpy); + + /* handle problems with edge-wrapping while resizing */ + flags = Scr.flags; + Scr.flags &= ~(EdgeWrapX | EdgeWrapY); + + XGetGeometry(dpy, (Drawable)ResizeWindow, &JunkRoot, &drag->x, &drag->y, + (unsigned int *)&drag->width, (unsigned int *)&drag->height, + &JunkBW, &JunkDepth); + + drag->x += tmp_win->bw; + drag->y += tmp_win->bw; + orig->x = drag->x; + orig->y = drag->y; + orig->width = drag->width; + orig->height = drag->height; + ymotion = xmotion = 0; + + /* pop up a resize dimensions window */ + XMapRaised(dpy, Scr.SizeWindow); + DisplaySize(tmp_win, orig->width, orig->height, True, True); + + /* Get the current position to determine which border to resize */ + if ((PressedW != Scr.Root) && (PressedW != None)) { + if (PressedW == tmp_win->sides[0]) /* top */ + ymotion = 1; + if (PressedW == tmp_win->sides[1]) /* right */ + xmotion = -1; + if (PressedW == tmp_win->sides[2]) /* bottom */ + ymotion = -1; + if (PressedW == tmp_win->sides[3]) /* left */ + xmotion = 1; + if (PressedW == tmp_win->corners[0]) { /* upper-left */ + ymotion = 1; + xmotion = 1; + } + if (PressedW == tmp_win->corners[1]) { /* upper-right */ + xmotion = -1; + ymotion = 1; + } + if (PressedW == tmp_win->corners[2]) { /* lower left */ + ymotion = -1; + xmotion = 1; + } + if (PressedW == tmp_win->corners[3]) { /* lower right */ + ymotion = -1; + xmotion = -1; + } + } + /* draw the rubber-band window */ + MoveOutline(Scr.Root, drag->x - tmp_win->bw, drag->y - tmp_win->bw, + drag->width - 1 + 2 * tmp_win->bw, + drag->height - 1 + 2 * tmp_win->bw); + /* kick off resizing without requiring any motion if invoked with a key + * press */ + if (eventp->type == KeyPress) { + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &stashed_x, + &stashed_y, &JunkX, &JunkY, &JunkMask); + DoResize(stashed_x, stashed_y, tmp_win, drag, orig, &xmotion, + &ymotion); + } else + stashed_x = stashed_y = -1; + + /* loop to resize */ + while (!finished) { + XMaskEvent(dpy, + ButtonPressMask | ButtonReleaseMask | KeyPressMask | + ButtonMotionMask | PointerMotionMask | ExposureMask, + &Event); + StashEventTime(&Event); + + if (Event.type == MotionNotify) + /* discard any extra motion events before a release */ + while (XCheckMaskEvent(dpy, + ButtonMotionMask | ButtonReleaseMask | + PointerMotionMask, + &Event)) { + StashEventTime(&Event); + if (Event.type == ButtonRelease) + break; + } + + done = FALSE; + /* Handle a limited number of key press events to allow + * mouseless operation */ + if (Event.type == KeyPress) + Keyboard_shortcuts(&Event, tmp_win, ButtonRelease); + switch (Event.type) { + case ButtonPress: + XAllowEvents(dpy, ReplayPointer, CurrentTime); + done = TRUE; + if (((Event.xbutton.button == 1) && + (button_mask & Button1Mask)) || + ((Event.xbutton.button == 2) && + (button_mask & Button2Mask)) || + ((Event.xbutton.button == 3) && + (button_mask & Button3Mask)) || + ((Event.xbutton.button == 4) && + (button_mask & Button4Mask)) || + ((Event.xbutton.button == 5) && + (button_mask & Button5Mask))) { + /* No new button was pressed, just a delayed + * event */ + break; + } + /* Abort the resize if + * - the move started with a pressed button and another + * button was pressed during the operation + * - no button was started at the beginning and any + * button except button 1 was pressed. */ + if (button_mask || (Event.xbutton.button != 1)) + fButtonAbort = TRUE; + case KeyPress: + /* simple code to bag out of move - CKH */ + if (XLookupKeysym(&(Event.xkey), 0) == XK_Escape || + fButtonAbort) { + abort = TRUE; + finished = TRUE; + /* return pointer if aborted resize was invoked + * with key */ + if (stashed_x >= 0) + XWarpPointer(dpy, None, Scr.Root, 0, 0, + 0, 0, stashed_x, stashed_y); + } + done = TRUE; + break; + + case ButtonRelease: + finished = TRUE; + done = TRUE; + break; + + case MotionNotify: + x = Event.xmotion.x_root; + y = Event.xmotion.y_root; + /* resize before paging request to prevent resize from + * lagging mouse - mab */ + DoResize(x, y, tmp_win, drag, orig, &xmotion, &ymotion); + /* need to move the viewport */ + HandlePaging(Scr.EdgeScrollX, Scr.EdgeScrollY, &x, &y, + &delta_x, &delta_y, False); + /* redraw outline if we paged - mab */ + if ((delta_x != 0) || (delta_y != 0)) { + orig->x -= delta_x; + orig->y -= delta_y; + drag->x -= delta_x; + drag->y -= delta_y; + + DoResize(x, y, tmp_win, drag, orig, &xmotion, + &ymotion); + } + done = TRUE; + default: + break; + } + if (!done) { + MoveOutline(Scr.Root, 0, 0, 0, 0); + DispatchEvent(); + MoveOutline(Scr.Root, drag->x - tmp_win->bw, + drag->y - tmp_win->bw, + drag->width - 1 + 2 * tmp_win->bw, + drag->height - 1 + 2 * tmp_win->bw); + } } - } - - /* erase the rubber-band */ - MoveOutline(Scr.Root, 0, 0, 0, 0); - - /* pop down the size window */ - XUnmapWindow(dpy, Scr.SizeWindow); - - if(!abort) - { - /* size will be >= to requested */ - ConstrainSize (tmp_win, &drag->width, &drag->height, True, xmotion, - ymotion); - SetupFrame (tmp_win, drag->x - tmp_win->bw, - drag->y - tmp_win->bw, drag->width, drag->height,FALSE); - } - UninstallRootColormap(); - ResizeWindow = None; - MyXUngrabServer(dpy); - UngrabEm(); - xmotion = 0; - ymotion = 0; - WaitForButtonsUp(); - - Scr.flags |= flags & (EdgeWrapX|EdgeWrapY); - return; -} + /* erase the rubber-band */ + MoveOutline(Scr.Root, 0, 0, 0, 0); + /* pop down the size window */ + XUnmapWindow(dpy, Scr.SizeWindow); + + if (!abort) { + /* size will be >= to requested */ + ConstrainSize(tmp_win, &drag->width, &drag->height, True, + xmotion, ymotion); + SetupFrame(tmp_win, drag->x - tmp_win->bw, + drag->y - tmp_win->bw, drag->width, drag->height, FALSE); + } + UninstallRootColormap(); + ResizeWindow = None; + MyXUngrabServer(dpy); + UngrabEm(); + xmotion = 0; + ymotion = 0; + WaitForButtonsUp(); + + Scr.flags |= flags & (EdgeWrapX | EdgeWrapY); + return; +} /*********************************************************************** * @@ -330,63 +324,57 @@ void resize_window(XEvent *eventp,Window w,FvwmWindow *tmp_win, * ymotionp - pointer to ymotion in resize_window * ************************************************************************/ -static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, - geom *drag, geom *orig, int *xmotionp, int *ymotionp) +static void +DoResize(int x_root, int y_root, FvwmWindow *tmp_win, geom *drag, geom *orig, + int *xmotionp, int *ymotionp) { - int action=0; - - if ((y_root <= orig->y) || - ((*ymotionp == 1)&&(y_root < orig->y+orig->height-1))) - { - drag->y = y_root; - drag->height = orig->y + orig->height - y_root; - action = 1; - *ymotionp = 1; - } - else if ((y_root >= orig->y + orig->height - 1)|| - ((*ymotionp == -1)&&(y_root > orig->y))) - { - drag->y = orig->y; - drag->height = 1 + y_root - drag->y; - action = 1; - *ymotionp = -1; - } - - if ((x_root <= orig->x)|| - ((*xmotionp == 1)&&(x_root < orig->x + orig->width - 1))) - { - drag->x = x_root; - drag->width = orig->x + orig->width - x_root; - action = 1; - *xmotionp = 1; - } - if ((x_root >= orig->x + orig->width - 1)|| - ((*xmotionp == -1)&&(x_root > orig->x))) - { - drag->x = orig->x; - drag->width = 1 + x_root - orig->x; - action = 1; - *xmotionp = -1; - } - - if (action) - { - /* round up to nearest OK size to keep pointer inside rubberband */ - ConstrainSize (tmp_win, &drag->width, &drag->height, True, *xmotionp, - *ymotionp); - if (*xmotionp == 1) - drag->x = orig->x + orig->width - drag->width; - if (*ymotionp == 1) - drag->y = orig->y + orig->height - drag->height; - - MoveOutline(Scr.Root, drag->x - tmp_win->bw,drag->y - tmp_win->bw, - drag->width - 1 + 2 * tmp_win->bw, - drag->height - 1 + 2 * tmp_win->bw); - } - DisplaySize(tmp_win, drag->width, drag->height,False,False); -} + int action = 0; + + if ((y_root <= orig->y) || + ((*ymotionp == 1) && (y_root < orig->y + orig->height - 1))) { + drag->y = y_root; + drag->height = orig->y + orig->height - y_root; + action = 1; + *ymotionp = 1; + } else if ((y_root >= orig->y + orig->height - 1) || + ((*ymotionp == -1) && (y_root > orig->y))) { + drag->y = orig->y; + drag->height = 1 + y_root - drag->y; + action = 1; + *ymotionp = -1; + } + if ((x_root <= orig->x) || + ((*xmotionp == 1) && (x_root < orig->x + orig->width - 1))) { + drag->x = x_root; + drag->width = orig->x + orig->width - x_root; + action = 1; + *xmotionp = 1; + } + if ((x_root >= orig->x + orig->width - 1) || + ((*xmotionp == -1) && (x_root > orig->x))) { + drag->x = orig->x; + drag->width = 1 + x_root - orig->x; + action = 1; + *xmotionp = -1; + } + if (action) { + /* round up to nearest OK size to keep pointer inside rubberband + */ + ConstrainSize(tmp_win, &drag->width, &drag->height, True, + *xmotionp, *ymotionp); + if (*xmotionp == 1) + drag->x = orig->x + orig->width - drag->width; + if (*ymotionp == 1) + drag->y = orig->y + orig->height - drag->height; + + MoveOutline(Scr.Root, drag->x - tmp_win->bw, + drag->y - tmp_win->bw, drag->width - 1 + 2 * tmp_win->bw, + drag->height - 1 + 2 * tmp_win->bw); + } + DisplaySize(tmp_win, drag->width, drag->height, False, False); +} /*********************************************************************** * @@ -399,54 +387,51 @@ static void DoResize(int x_root, int y_root, FvwmWindow *tmp_win, * height - the height of the rubber band * ***********************************************************************/ -void DisplaySize(FvwmWindow *tmp_win, int width, int height, Bool Init, - Bool resetLast) +void +DisplaySize( + FvwmWindow *tmp_win, int width, int height, Bool Init, Bool resetLast) { - char str[100]; - int dwidth,dheight,offset; - static int last_width = 0; - static int last_height = 0; - - if (resetLast) - { - last_width = 0; - last_height = 0; - } - if (last_width == width && last_height == height) - return; - - last_width = width; - last_height = height; - - dheight = height - tmp_win->title_height - 2*tmp_win->boundary_width; - dwidth = width - 2*tmp_win->boundary_width; - - dwidth -= tmp_win->hints.base_width; - dheight -= tmp_win->hints.base_height; - dwidth /= tmp_win->hints.width_inc; - dheight /= tmp_win->hints.height_inc; - - (void) snprintf (str, sizeof(str), " %4d x %-4d ", dwidth, dheight); - offset = (Scr.SizeStringWidth + SIZE_HINDENT*2 - - XTextWidth(Scr.StdFont.font,str,strlen(str)))/2; - if(Init) - { - XClearWindow(dpy,Scr.SizeWindow); - if(Scr.d_depth >= 2) - RelieveWindow(tmp_win, - Scr.SizeWindow,0,0,Scr.SizeStringWidth+ SIZE_HINDENT*2, - Scr.StdFont.height + SIZE_VINDENT*2, - Scr.StdReliefGC, - Scr.StdShadowGC,FULL_HILITE); - } - else - { - XClearArea(dpy, Scr.SizeWindow, SIZE_HINDENT, SIZE_VINDENT, - Scr.SizeStringWidth, Scr.StdFont.height,False); - } - - XDrawString (dpy, Scr.SizeWindow, Scr.StdGC, - offset, Scr.StdFont.font->ascent + SIZE_VINDENT, str, 13); + char str[100]; + int dwidth, dheight, offset; + static int last_width = 0; + static int last_height = 0; + + if (resetLast) { + last_width = 0; + last_height = 0; + } + if (last_width == width && last_height == height) + return; + + last_width = width; + last_height = height; + + dheight = height - tmp_win->title_height - 2 * tmp_win->boundary_width; + dwidth = width - 2 * tmp_win->boundary_width; + + dwidth -= tmp_win->hints.base_width; + dheight -= tmp_win->hints.base_height; + dwidth /= tmp_win->hints.width_inc; + dheight /= tmp_win->hints.height_inc; + + (void)snprintf(str, sizeof(str), " %4d x %-4d ", dwidth, dheight); + offset = (Scr.SizeStringWidth + SIZE_HINDENT * 2 - + XTextWidth(Scr.StdFont.font, str, strlen(str))) / + 2; + if (Init) { + XClearWindow(dpy, Scr.SizeWindow); + if (Scr.d_depth >= 2) + RelieveWindow(tmp_win, Scr.SizeWindow, 0, 0, + Scr.SizeStringWidth + SIZE_HINDENT * 2, + Scr.StdFont.height + SIZE_VINDENT * 2, + Scr.StdReliefGC, Scr.StdShadowGC, FULL_HILITE); + } else { + XClearArea(dpy, Scr.SizeWindow, SIZE_HINDENT, SIZE_VINDENT, + Scr.SizeStringWidth, Scr.StdFont.height, False); + } + + XDrawString(dpy, Scr.SizeWindow, Scr.StdGC, offset, + Scr.StdFont.font->ascent + SIZE_VINDENT, str, 13); } /*********************************************************************** @@ -460,146 +445,144 @@ void DisplaySize(FvwmWindow *tmp_win, int width, int height, Bool Init, * ***********************************************************************/ -void ConstrainSize (FvwmWindow *tmp_win, int *widthp, int *heightp, - Bool roundUp, int xmotion, int ymotion) +void +ConstrainSize(FvwmWindow *tmp_win, int *widthp, int *heightp, Bool roundUp, + int xmotion, int ymotion) { -#define makemult(a,b) ((b==1) ? (a) : (((int)((a)/(b))) * (b)) ) -#define _min(a,b) (((a) < (b)) ? (a) : (b)) - int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; - int baseWidth, baseHeight; - int dwidth = *widthp, dheight = *heightp; - int constrainx, constrainy; - - /* roundUp is True if called from an interactive resize */ - if (roundUp) - { - constrainx = tmp_win->hints.width_inc - 1; - constrainy = tmp_win->hints.height_inc - 1; - } - else - { - constrainx = 0; - constrainy = 0; - } - dwidth -= 2 *tmp_win->boundary_width; - dheight -= (tmp_win->title_height + 2*tmp_win->boundary_width); - - minWidth = tmp_win->hints.min_width; - minHeight = tmp_win->hints.min_height; - - baseWidth = tmp_win->hints.base_width; - baseHeight = tmp_win->hints.base_height; - - maxWidth = tmp_win->hints.max_width; - maxHeight = tmp_win->hints.max_height; - -/* maxWidth = Scr.VxMax + Scr.MyDisplayWidth; - maxHeight = Scr.VyMax + Scr.MyDisplayHeight;*/ - - xinc = tmp_win->hints.width_inc; - yinc = tmp_win->hints.height_inc; - - /* - * First, clamp to min and max values - */ - if (dwidth < minWidth) dwidth = minWidth; - if (dheight < minHeight) dheight = minHeight; - - if (dwidth > maxWidth) dwidth = maxWidth; - if (dheight > maxHeight) dheight = maxHeight; - - - /* - * Second, round to base + N * inc (up or down depending on resize type) - */ - dwidth = ((dwidth - baseWidth + constrainx) / xinc * xinc) + baseWidth; - dheight = ((dheight - baseHeight + constrainy) / yinc * yinc) + baseHeight; - - - /* - * Third, adjust for aspect ratio - */ +#define makemult(a, b) ((b == 1) ? (a) : (((int)((a) / (b))) * (b))) +#define _min(a, b) (((a) < (b)) ? (a) : (b)) + int minWidth, minHeight, maxWidth, maxHeight, xinc, yinc, delta; + int baseWidth, baseHeight; + int dwidth = *widthp, dheight = *heightp; + int constrainx, constrainy; + + /* roundUp is True if called from an interactive resize */ + if (roundUp) { + constrainx = tmp_win->hints.width_inc - 1; + constrainy = tmp_win->hints.height_inc - 1; + } else { + constrainx = 0; + constrainy = 0; + } + dwidth -= 2 * tmp_win->boundary_width; + dheight -= (tmp_win->title_height + 2 * tmp_win->boundary_width); + + minWidth = tmp_win->hints.min_width; + minHeight = tmp_win->hints.min_height; + + baseWidth = tmp_win->hints.base_width; + baseHeight = tmp_win->hints.base_height; + + maxWidth = tmp_win->hints.max_width; + maxHeight = tmp_win->hints.max_height; + + /* maxWidth = Scr.VxMax + Scr.MyDisplayWidth; + maxHeight = Scr.VyMax + Scr.MyDisplayHeight;*/ + + xinc = tmp_win->hints.width_inc; + yinc = tmp_win->hints.height_inc; + + /* + * First, clamp to min and max values + */ + if (dwidth < minWidth) + dwidth = minWidth; + if (dheight < minHeight) + dheight = minHeight; + + if (dwidth > maxWidth) + dwidth = maxWidth; + if (dheight > maxHeight) + dheight = maxHeight; + + /* + * Second, round to base + N * inc (up or down depending on resize type) + */ + dwidth = ((dwidth - baseWidth + constrainx) / xinc * xinc) + baseWidth; + dheight = + ((dheight - baseHeight + constrainy) / yinc * yinc) + baseHeight; + + /* + * Third, adjust for aspect ratio + */ #define maxAspectX tmp_win->hints.max_aspect.x #define maxAspectY tmp_win->hints.max_aspect.y #define minAspectX tmp_win->hints.min_aspect.x #define minAspectY tmp_win->hints.min_aspect.y - /* - * The math looks like this: - * - * minAspectX dwidth maxAspectX - * ---------- <= ------- <= ---------- - * minAspectY dheight maxAspectY - * - * If that is multiplied out, then the width and height are - * invalid in the following situations: - * - * minAspectX * dheight > minAspectY * dwidth - * maxAspectX * dheight < maxAspectY * dwidth - * - */ - - if (tmp_win->hints.flags & PAspect) - { - if ((minAspectX * dheight > minAspectY * dwidth)&&(xmotion == 0)) - { - /* Change width to match */ - delta = makemult(minAspectX * dheight / minAspectY - dwidth, - xinc); - if (dwidth + delta <= maxWidth) - dwidth += delta; - } - if (minAspectX * dheight > minAspectY * dwidth) - { - delta = makemult(dheight - dwidth*minAspectY/minAspectX, - yinc); - if (dheight - delta >= minHeight) - dheight -= delta; - else - { - delta = makemult(minAspectX*dheight / minAspectY - dwidth, - xinc); - if (dwidth + delta <= maxWidth) - dwidth += delta; - } - } - - if ((maxAspectX * dheight < maxAspectY * dwidth)&&(ymotion == 0)) - { - delta = makemult(dwidth * maxAspectY / maxAspectX - dheight, - yinc); - if (dheight + delta <= maxHeight) - dheight += delta; - } - if ((maxAspectX * dheight < maxAspectY * dwidth)) - { - delta = makemult(dwidth - maxAspectX*dheight/maxAspectY, - xinc); - if (dwidth - delta >= minWidth) - dwidth -= delta; - else - { - delta = makemult(dwidth * maxAspectY / maxAspectX - dheight, - yinc); - if (dheight + delta <= maxHeight) - dheight += delta; - } - } - } - - /* - * Fourth, account for border width and title height - */ - *widthp = dwidth + 2*tmp_win->boundary_width; - *heightp = dheight + tmp_win->title_height + 2*tmp_win->boundary_width; + /* + * The math looks like this: + * + * minAspectX dwidth maxAspectX + * ---------- <= ------- <= ---------- + * minAspectY dheight maxAspectY + * + * If that is multiplied out, then the width and height are + * invalid in the following situations: + * + * minAspectX * dheight > minAspectY * dwidth + * maxAspectX * dheight < maxAspectY * dwidth + * + */ + + if (tmp_win->hints.flags & PAspect) { + if ((minAspectX * dheight > minAspectY * dwidth) && + (xmotion == 0)) { + /* Change width to match */ + delta = makemult( + minAspectX * dheight / minAspectY - dwidth, xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + } + if (minAspectX * dheight > minAspectY * dwidth) { + delta = makemult( + dheight - dwidth * minAspectY / minAspectX, yinc); + if (dheight - delta >= minHeight) + dheight -= delta; + else { + delta = makemult( + minAspectX * dheight / minAspectY - dwidth, + xinc); + if (dwidth + delta <= maxWidth) + dwidth += delta; + } + } + + if ((maxAspectX * dheight < maxAspectY * dwidth) && + (ymotion == 0)) { + delta = makemult( + dwidth * maxAspectY / maxAspectX - dheight, yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + } + if ((maxAspectX * dheight < maxAspectY * dwidth)) { + delta = makemult( + dwidth - maxAspectX * dheight / maxAspectY, xinc); + if (dwidth - delta >= minWidth) + dwidth -= delta; + else { + delta = makemult( + dwidth * maxAspectY / maxAspectX - dheight, + yinc); + if (dheight + delta <= maxHeight) + dheight += delta; + } + } + } + + /* + * Fourth, account for border width and title height + */ + *widthp = dwidth + 2 * tmp_win->boundary_width; + *heightp = + dheight + tmp_win->title_height + 2 * tmp_win->boundary_width; #ifdef WINDOWSHADE - if (tmp_win->buttons & WSHADE) - *heightp = tmp_win->title_height + tmp_win->boundary_width; + if (tmp_win->buttons & WSHADE) + *heightp = tmp_win->title_height + tmp_win->boundary_width; #endif - return; + return; } - /*********************************************************************** * * Procedure: @@ -613,52 +596,49 @@ void ConstrainSize (FvwmWindow *tmp_win, int *widthp, int *heightp, * height - the height of the rectangle * ***********************************************************************/ -void MoveOutline(Window root, int x, int y, int width, int height) +void +MoveOutline(Window root, int x, int y, int width, int height) { - static int lastx = 0; - static int lasty = 0; - static int lastWidth = 0; - static int lastHeight = 0; - char draw; - XRectangle rects[5]; - - if (x == lastx && y == lasty && width == lastWidth && height == lastHeight) - return; - - /* undraw the old one, if any */ - /* draw the new one, if any */ - draw = 0; - while (1) - { - if (lastWidth || lastHeight) - { - int i; - - for (i=0; i < 4; i++) - { - rects[i].x = lastx + i; - rects[i].y = lasty + i; - rects[i].width = lastWidth - (i << 1); - rects[i].height = lastHeight - (i << 1); - } - rects[3].y = lasty+3 + (lastHeight-6)/3; - rects[3].height = (lastHeight-6)/3; - rects[4].x = lastx+3 + (lastWidth-6)/3; - rects[4].y = lasty+3; - rects[4].width = (lastWidth-6)/3; - rects[4].height = (lastHeight-6); - XDrawRectangles(dpy,Scr.Root,Scr.DrawGC,rects,5); - } - draw++; - - if (draw < 2) - { - lastx = x; - lasty = y; - lastWidth = width; - lastHeight = height; - } - else - break; - } + static int lastx = 0; + static int lasty = 0; + static int lastWidth = 0; + static int lastHeight = 0; + char draw; + XRectangle rects[5]; + + if (x == lastx && y == lasty && width == lastWidth && + height == lastHeight) + return; + + /* undraw the old one, if any */ + /* draw the new one, if any */ + draw = 0; + while (1) { + if (lastWidth || lastHeight) { + int i; + + for (i = 0; i < 4; i++) { + rects[i].x = lastx + i; + rects[i].y = lasty + i; + rects[i].width = lastWidth - (i << 1); + rects[i].height = lastHeight - (i << 1); + } + rects[3].y = lasty + 3 + (lastHeight - 6) / 3; + rects[3].height = (lastHeight - 6) / 3; + rects[4].x = lastx + 3 + (lastWidth - 6) / 3; + rects[4].y = lasty + 3; + rects[4].width = (lastWidth - 6) / 3; + rects[4].height = (lastHeight - 6); + XDrawRectangles(dpy, Scr.Root, Scr.DrawGC, rects, 5); + } + draw++; + + if (draw < 2) { + lastx = x; + lasty = y; + lastWidth = width; + lastHeight = height; + } else + break; + } } Index: fvwm/fvwm/screen.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/screen.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/screen.h --- fvwm/fvwm/screen.h +++ fvwm/fvwm/screen.h @@ -35,28 +35,28 @@ #include #include #include -#include "misc.h" + #include "menus.h" +#include "misc.h" #define SIZE_HINDENT 5 #define SIZE_VINDENT 3 #define MAX_WINDOW_WIDTH 32767 #define MAX_WINDOW_HEIGHT 32767 - /* Cursor types */ -#define POSITION 0 /* upper Left corner cursor */ -#define TITLE_CURSOR 1 /* title-bar cursor */ -#define DEFAULT 2 /* cursor for apps to inherit */ -#define SYS 3 /* sys-menu and iconify boxes cursor */ -#define MOVE 4 /* resize cursor */ +#define POSITION 0 /* upper Left corner cursor */ +#define TITLE_CURSOR 1 /* title-bar cursor */ +#define DEFAULT 2 /* cursor for apps to inherit */ +#define SYS 3 /* sys-menu and iconify boxes cursor */ +#define MOVE 4 /* resize cursor */ #ifdef WAIT #undef WAIT -#endif /*WAIT */ -#define WAIT 5 /* wait a while cursor */ -#define MENU 6 /* menu cursor */ -#define SELECT 7 /* dot cursor for f.move, etc. from menus */ -#define DESTROY 8 /* skull and cross bones, f.destroy */ +#endif /*WAIT */ +#define WAIT 5 /* wait a while cursor */ +#define MENU 6 /* menu cursor */ +#define SELECT 7 /* dot cursor for f.move, etc. from menus */ +#define DESTROY 8 /* skull and cross bones, f.destroy */ #define TOP 9 #define RIGHT 10 #define BOTTOM 11 @@ -71,271 +71,258 @@ #define COLORMAP_FOLLOWS_MOUSE 1 /* default */ #define COLORMAP_FOLLOWS_FOCUS 2 - #ifndef NON_VIRTUAL -typedef struct -{ - Window win; - int isMapped; +typedef struct { + Window win; + int isMapped; } PanFrame; #endif - typedef enum { - /* button types */ +/* button types */ #ifdef VECTOR_BUTTONS - VectorButton , + VectorButton, #endif - SimpleButton , + SimpleButton, #ifdef GRADIENT_BUTTONS - HGradButton , - VGradButton , + HGradButton, + VGradButton, #endif #ifdef PIXMAP_BUTTONS - PixmapButton , - TiledPixmapButton , + PixmapButton, + TiledPixmapButton, #endif #ifdef MINI_ICONS - MiniIconButton , + MiniIconButton, #endif - SolidButton - /* max button is 15 (0xF) */ + SolidButton + /* max button is 15 (0xF) */ } ButtonFaceStyle; -#define ButtonFaceTypeMask 0x000F +#define ButtonFaceTypeMask 0x000F /* button style flags (per-state) */ enum { - - /* specific style flags */ - /* justification bits (3.17 -> 4 bits) */ - HOffCenter = (1<<4), - HRight = (1<<5), - VOffCenter = (1<<6), - VBottom = (1<<7), - - /* general style flags */ + /* specific style flags */ + /* justification bits (3.17 -> 4 bits) */ + HOffCenter = (1 << 4), + HRight = (1 << 5), + VOffCenter = (1 << 6), + VBottom = (1 << 7), + +/* general style flags */ #ifdef EXTENDED_TITLESTYLE - UseTitleStyle = (1<<8), + UseTitleStyle = (1 << 8), #endif #ifdef BORDERSTYLE - UseBorderStyle = (1<<9), + UseBorderStyle = (1 << 9), #endif - FlatButton = (1<<10), - SunkButton = (1<<11) + FlatButton = (1 << 10), + SunkButton = (1 << 11) }; #ifdef BORDERSTYLE /* border style flags (uses ButtonFace) */ -enum { - HiddenHandles = (1<<8), - NoInset = (1<<9) -}; +enum { HiddenHandles = (1 << 8), NoInset = (1 << 9) }; #endif typedef struct ButtonFace { - ButtonFaceStyle style; - union { + ButtonFaceStyle style; + union { #ifdef PIXMAP_BUTTONS - FvwmPicture *p; + FvwmPicture *p; #endif - Pixel back; + Pixel back; #ifdef GRADIENT_BUTTONS - struct { - int npixels; - Pixel *pixels; - } grad; + struct { + int npixels; + Pixel *pixels; + } grad; #endif - } u; + } u; #ifdef VECTOR_BUTTONS - struct vector_coords { - int num; - int x[20]; - int y[20]; - int line_style[20]; - } vector; + struct vector_coords { + int num; + int x[20]; + int y[20]; + int line_style[20]; + } vector; #endif #ifdef MULTISTYLE - struct ButtonFace *next; + struct ButtonFace *next; #endif } ButtonFace; /* button style flags (per title button) */ enum { - /* MWM function hint button assignments */ - MWMDecorMenu = (1<<0), - MWMDecorMinimize = (1<<1), - MWMDecorMaximize = (1<<2) + /* MWM function hint button assignments */ + MWMDecorMenu = (1 << 0), + MWMDecorMinimize = (1 << 1), + MWMDecorMaximize = (1 << 2) }; enum ButtonState { - ActiveUp, + ActiveUp, #ifdef ACTIVEDOWN_BTNS - ActiveDown, + ActiveDown, #endif #ifdef INACTIVE_BTNS - Inactive, + Inactive, #endif - MaxButtonState + MaxButtonState }; typedef struct { - int flags; - ButtonFace state[MaxButtonState]; + int flags; + ButtonFace state[MaxButtonState]; } TitleButton; typedef struct FvwmDecor { #ifdef USEDECOR - char *tag; /* general style tag */ + char *tag; /* general style tag */ #endif - ColorPair HiColors; /* standard fore/back colors */ - ColorPair HiRelief; - GC HiReliefGC; /* GC for highlighted window relief */ - GC HiShadowGC; /* GC for highlighted window shadow */ - - int TitleHeight; /* height of the title bar window */ - MyFont WindowFont; /* font structure for window titles */ - - /* titlebar buttons */ - TitleButton left_buttons[5]; - TitleButton right_buttons[5]; - TitleButton titlebar; + ColorPair HiColors; /* standard fore/back colors */ + ColorPair HiRelief; + GC HiReliefGC; /* GC for highlighted window relief */ + GC HiShadowGC; /* GC for highlighted window shadow */ + + int TitleHeight; /* height of the title bar window */ + MyFont WindowFont; /* font structure for window titles */ + + /* titlebar buttons */ + TitleButton left_buttons[5]; + TitleButton right_buttons[5]; + TitleButton titlebar; #ifdef BORDERSTYLE - struct BorderStyle - { - ButtonFace active, inactive; - } BorderStyle; + struct BorderStyle { + ButtonFace active, inactive; + } BorderStyle; #endif #ifdef USEDECOR - struct FvwmDecor *next; /* additional user-defined styles */ + struct FvwmDecor *next; /* additional user-defined styles */ #endif } FvwmDecor; - -typedef struct ScreenInfo -{ - - unsigned long screen; - int d_depth; /* copy of DefaultDepth(dpy, screen) */ - int NumberOfScreens; /* number of screens on display */ - int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ - int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ - - FvwmWindow FvwmRoot; /* the head of the fvwm window list */ - Window Root; /* the root window */ - Window SizeWindow; /* the resize dimensions window */ - Window NoFocusWin; /* Window which will own focus when no other - * windows have it */ +typedef struct ScreenInfo { + unsigned long screen; + int d_depth; /* copy of DefaultDepth(dpy, screen) */ + int NumberOfScreens; /* number of screens on display */ + int MyDisplayWidth; /* my copy of DisplayWidth(dpy, screen) */ + int MyDisplayHeight; /* my copy of DisplayHeight(dpy, screen) */ + + FvwmWindow FvwmRoot; /* the head of the fvwm window list */ + Window Root; /* the root window */ + Window SizeWindow; /* the resize dimensions window */ + Window NoFocusWin; /* Window which will own focus when no other + * windows have it */ #ifndef NON_VIRTUAL - PanFrame PanFrameTop,PanFrameLeft,PanFrameRight,PanFrameBottom; + PanFrame PanFrameTop, PanFrameLeft, PanFrameRight, PanFrameBottom; #endif - Pixmap gray_bitmap; /*dark gray pattern for shaded out menu items*/ - Pixmap gray_pixmap; /* dark gray pattern for inactive borders */ - Pixmap light_gray_pixmap; /* light gray pattern for inactive borders */ - Pixmap sticky_gray_pixmap; /* light gray pattern for sticky borders */ + Pixmap gray_bitmap; /*dark gray pattern for shaded out menu items*/ + Pixmap gray_pixmap; /* dark gray pattern for inactive borders */ + Pixmap light_gray_pixmap; /* light gray pattern for inactive borders */ + Pixmap sticky_gray_pixmap; /* light gray pattern for sticky borders */ - Binding *AllBindings; + Binding *AllBindings; - int root_pushes; /* current push level to install root - colormap windows */ - FvwmWindow *pushed_window; /* saved window to install when pushes drops - to zero */ - Cursor FvwmCursors[MAX_CURSORS]; + int root_pushes; /* current push level to install root + colormap windows */ + FvwmWindow *pushed_window; /* saved window to install when pushes drops + to zero */ + Cursor FvwmCursors[MAX_CURSORS]; - name_list *TheList; /* list of window names with attributes */ - char *DefaultIcon; /* Icon to use when no other icons are found */ + name_list *TheList; /* list of window names with attributes */ + char *DefaultIcon; /* Icon to use when no other icons are found */ - ColorPair StdColors; /* standard fore/back colors */ - ColorPair StdRelief; + ColorPair StdColors; /* standard fore/back colors */ + ColorPair StdRelief; - MenuGlobals menus; + MenuGlobals menus; - MyFont StdFont; /* font structure */ - MyFont IconFont; /* for icon labels */ + MyFont StdFont; /* font structure */ + MyFont IconFont; /* for icon labels */ #if defined(PIXMAP_BUTTONS) || defined(GRADIENT_BUTTONS) - GC TransMaskGC; /* GC for transparency masks */ + GC TransMaskGC; /* GC for transparency masks */ #endif - GC StdGC; - GC StdReliefGC; - GC StdShadowGC; - GC DrawGC; /* GC to draw lines for move and resize */ - GC ScratchGC1; - GC ScratchGC2; - GC ScratchGC3; - int SizeStringWidth; /* minimum width of size window */ - int CornerWidth; /* corner width for decoratedwindows */ - int BoundaryWidth; /* frame width for decorated windows */ - int NoBoundaryWidth; /* frame width for decorated windows */ - - FvwmDecor DefaultDecor; /* decoration style(s) */ - - int nr_left_buttons; /* number of left-side title-bar buttons */ - int nr_right_buttons; /* number of right-side title-bar buttons */ - - FvwmWindow *Hilite; /* the fvwm window that is highlighted - * except for networking delays, this is the - * window which REALLY has the focus */ - FvwmWindow *Focus; /* Last window which Fvwm gave the focus to - * NOT the window that really has the focus */ - Window UnknownWinFocused; /* None, if the focus is nowhere or on an fvwm - * managed window. Set to id of otherwindow - * with focus otherwise */ - FvwmWindow *Ungrabbed; - FvwmWindow *PreviousFocus; /* Window which had focus before fvwm stole it - * to do moves/menus/etc. */ - int EdgeScrollX; /* #pixels to scroll on screen edge */ - int EdgeScrollY; /* #pixels to scroll on screen edge */ - unsigned char buttons2grab; /* buttons to grab in click to focus mode */ - unsigned long flags; - int NumBoxes; - int randomx; /* values used for randomPlacement */ - int randomy; - FvwmWindow *LastWindowRaised; /* Last window which was raised. Used for raise - * lower func. */ - int VxMax; /* Max location for top left of virt desk*/ - int VyMax; - int Vx; /* Current loc for top left of virt desk */ - int Vy; - - int ClickTime; /*Max button-click delay for Function built-in*/ - int ScrollResistance; /* resistance to scrolling in desktop */ - int MoveResistance; /* res to moving windows over viewport edge */ - int SnapAttraction; /* attractiveness of window edges */ - int SnapMode; /* mode of snap attraction */ - int SnapGridX; /* snap grid X size */ - int SnapGridY; /* snap grid Y size */ - int OpaqueSize; - int CurrentDesk; /* The current desktop number */ - int ColormapFocus; /* colormap focus style */ - int ColorLimit; /* Limit on colors used in pixmaps */ - - /* - ** some additional global options which will probably become window - ** specific options later on: - */ - int SmartPlacementIsClever; - int ClickToFocusPassesClick; - int ClickToFocusRaises; - int MouseFocusClickRaises; - int StipledTitles; - struct - { - Bool ModifyUSP : 1; /* - RBW - 11/02/1998 */ - Bool CaptureHonorsStartsOnPage : 1; /* - RBW - 11/02/1998 */ - Bool RecaptureHonorsStartsOnPage : 1; /* - RBW - 11/02/1998 */ - Bool ActivePlacementHonorsStartsOnPage : 1; /* - RBW - 11/02/1998 */ - } go; /* global options */ - struct - { - Bool EmulateMWM : 1; - Bool EmulateWIN : 1; - } gs; /* global style structure */ - Bool hasIconFont; - Bool hasWindowFont; + GC StdGC; + GC StdReliefGC; + GC StdShadowGC; + GC DrawGC; /* GC to draw lines for move and resize */ + GC ScratchGC1; + GC ScratchGC2; + GC ScratchGC3; + int SizeStringWidth; /* minimum width of size window */ + int CornerWidth; /* corner width for decoratedwindows */ + int BoundaryWidth; /* frame width for decorated windows */ + int NoBoundaryWidth; /* frame width for decorated windows */ + + FvwmDecor DefaultDecor; /* decoration style(s) */ + + int nr_left_buttons; /* number of left-side title-bar buttons */ + int nr_right_buttons; /* number of right-side title-bar buttons */ + + FvwmWindow *Hilite; /* the fvwm window that is highlighted + * except for networking delays, this is the + * window which REALLY has the focus */ + FvwmWindow *Focus; /* Last window which Fvwm gave the focus to + * NOT the window that really has the focus */ + Window UnknownWinFocused; /* None, if the focus is nowhere or on an fvwm + * managed window. Set to id of otherwindow + * with focus otherwise */ + FvwmWindow *Ungrabbed; + FvwmWindow *PreviousFocus; /* Window which had focus before fvwm stole + * it to do moves/menus/etc. */ + int EdgeScrollX; /* #pixels to scroll on screen edge */ + int EdgeScrollY; /* #pixels to scroll on screen edge */ + unsigned char buttons2grab; /* buttons to grab in click to focus mode */ + unsigned long flags; + int NumBoxes; + int randomx; /* values used for randomPlacement */ + int randomy; + FvwmWindow *LastWindowRaised; /* Last window which was raised. Used for + * raise lower func. */ + int VxMax; /* Max location for top left of virt desk*/ + int VyMax; + int Vx; /* Current loc for top left of virt desk */ + int Vy; + + int ClickTime; /*Max button-click delay for Function built-in*/ + int ScrollResistance; /* resistance to scrolling in desktop */ + int MoveResistance; /* res to moving windows over viewport edge */ + int SnapAttraction; /* attractiveness of window edges */ + int SnapMode; /* mode of snap attraction */ + int SnapGridX; /* snap grid X size */ + int SnapGridY; /* snap grid Y size */ + int OpaqueSize; + int CurrentDesk; /* The current desktop number */ + int ColormapFocus; /* colormap focus style */ + int ColorLimit; /* Limit on colors used in pixmaps */ + + /* + ** some additional global options which will probably become window + ** specific options later on: + */ + int SmartPlacementIsClever; + int ClickToFocusPassesClick; + int ClickToFocusRaises; + int MouseFocusClickRaises; + int StipledTitles; + struct { + unsigned int ModifyUSP:1; /* - RBW - 11/02/1998 */ + unsigned int CaptureHonorsStartsOnPage:1; /* - RBW - 11/02/1998 */ + unsigned int RecaptureHonorsStartsOnPage:1; /* - RBW - 11/02/1998 */ + unsigned int ActivePlacementHonorsStartsOnPage:1; /* - RBW - 11/02/1998 */ + } go; /* global options */ + struct { + unsigned int EmulateMWM:1; + unsigned int EmulateWIN:1; + } gs; /* global style structure */ + Bool hasIconFont; + Bool hasWindowFont; } ScreenInfo; /* @@ -344,9 +331,9 @@ typedef struct ScreenInfo the UseDecor mechanism. */ #ifdef USEDECOR -#define GetDecor(window,part) ((window)->fl->part) +#define GetDecor(window, part) ((window)->fl->part) #else -#define GetDecor(window,part) (Scr.DefaultDecor.part) +#define GetDecor(window, part) (Scr.DefaultDecor.part) #endif /* some protos for the decoration structures */ @@ -360,10 +347,10 @@ void DestroyFvwmDecor(FvwmDecor *fl); extern ScreenInfo Scr; /* for the flags value - these used to be seperate Bool's */ -#define WindowsCaptured (1) -#define EdgeWrapX (64) /* Should EdgeScroll wrap around? */ -#define EdgeWrapY (128) -#define AnimatedMenus (1024) +#define WindowsCaptured (1) +#define EdgeWrapX (64) /* Should EdgeScroll wrap around? */ +#define EdgeWrapY (128) +#define AnimatedMenus (1024) /* Have to declare this here because FvwmDecor isn't declared in misc.h when * this gets parsed :( */ Index: fvwm/fvwm/style.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/style.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/style.c --- fvwm/fvwm/style.c +++ fvwm/fvwm/style.c @@ -21,14 +21,13 @@ * code for parsing the fvwm style command * ***********************************************************************/ -#include "config.h" - -#include -#include #include +#include #include +#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" @@ -36,906 +35,1011 @@ #include "screen.h" static int Get_TBLR(char *, unsigned char *); /* prototype */ -static void AddToList(name_list *); /* prototype */ +static void AddToList(name_list *); /* prototype */ /* A macro for skipping over white space */ -#define SKIPSPACE \ - while(isspace(*restofline))restofline++; +#define SKIPSPACE \ + while (isspace(*restofline)) \ + restofline++; /* A macro for checking the command with a caseless compare */ -#define ITIS(THIS) \ - strncasecmp(restofline,THIS,sizeof(THIS)-1)==0 +#define ITIS(THIS) strncasecmp(restofline, THIS, sizeof(THIS) - 1) == 0 /* A macro for skipping over the command without counting it's size */ -#define SKIP(THIS) \ - restofline += sizeof(THIS)-1 +#define SKIP(THIS) restofline += sizeof(THIS) - 1 /* A macro for getting a non-quoted operand */ -#define GETWORD \ - SKIPSPACE; \ - tmp = restofline; \ - len = 0; \ - while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&& \ - (*tmp != '\n')&&(!isspace(*tmp))) { \ - tmp++; \ - len++; \ - } +#define GETWORD \ + SKIPSPACE; \ + tmp = restofline; \ + len = 0; \ + while ((tmp != NULL) && (*tmp != 0) && (*tmp != ',') && \ + (*tmp != '\n') && (!isspace(*tmp))) { \ + tmp++; \ + len++; \ + } /* A macro for getting a quoted operand */ -#define GETQUOTEDWORD \ - is_quoted = 0; \ - SKIPSPACE; \ - if (*restofline == '"') { \ - is_quoted = 1; \ - ++restofline; \ - } \ - tmp = restofline; \ - len = 0; \ - while (tmp && *tmp && \ - ((!is_quoted&&(*tmp != ',')&&(*tmp != '\n')&&(!isspace(*tmp))) \ - || (is_quoted&&(*tmp != '\n')&&(*tmp != '"')))) \ - { \ - tmp++; \ - len++; \ - } \ - if (tmp && (*tmp == '"')) ++tmp; +#define GETQUOTEDWORD \ + is_quoted = 0; \ + SKIPSPACE; \ + if (*restofline == '"') { \ + is_quoted = 1; \ + ++restofline; \ + } \ + tmp = restofline; \ + len = 0; \ + while (tmp && *tmp && \ + ((!is_quoted && (*tmp != ',') && (*tmp != '\n') && \ + (!isspace(*tmp))) || \ + (is_quoted && (*tmp != '\n') && (*tmp != '"')))) { \ + tmp++; \ + len++; \ + } \ + if (tmp && (*tmp == '"')) \ + ++tmp; /* Process a style command. First built up in a temp area. If valid, added to the list in a malloced area. */ -void ProcessNewStyle(XEvent *eventp, - Window w, - FvwmWindow *tmp_win, - unsigned long context, - char *text, - int *Module) +void +ProcessNewStyle(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *text, int *Module) { - char *line; - char *restofline,*tmp; - name_list *nptr; - int butt; /* work area for button number */ - int num,i; - /* RBW - 11/02/1998 */ - int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; - /**/ + char *line; + char *restofline, *tmp; + name_list *nptr; + int butt; /* work area for button number */ + int num, i; + /* RBW - 11/02/1998 */ + int tmpno1 = -1, tmpno2 = -1, tmpno3 = -1, spargs = 0; + /**/ - name_list tname; /* temp area to build name list */ - int len = 0; - icon_boxes *which = 0; /* which current boxes to chain to */ - int is_quoted; /* for parsing args with quotes */ + name_list tname; /* temp area to build name list */ + int len = 0; + icon_boxes *which = 0; /* which current boxes to chain to */ + int is_quoted; /* for parsing args with quotes */ - memset(&tname, 0, sizeof(name_list)); /* init temp name_list area */ + memset(&tname, 0, sizeof(name_list)); /* init temp name_list area */ - restofline = GetNextToken(text,&tname.name); /* parse style name */ - /* in case there was no argument! */ - if((tname.name == NULL)||(restofline == NULL))/* If no name, or blank cmd */ - { - if (tname.name) - free(tname.name); - return; /* drop it. */ - } + restofline = GetNextToken(text, &tname.name); /* parse style name */ + /* in case there was no argument! */ + if ((tname.name == NULL) || + (restofline == NULL)) { /* If no name, or blank cmd */ + if (tname.name) + free(tname.name); + return; /* drop it. */ + } - SKIPSPACE; /* skip over white space */ - line = restofline; + SKIPSPACE; /* skip over white space */ + line = restofline; - if(restofline == NULL) - { - free(tname.name); - return; - } - while((*restofline != 0)&&(*restofline != '\n')) - { - SKIPSPACE; /* skip white space */ - /* It might make more sense to capture the whole word, fix its - case, and use strcmp, but there aren't many caseless compares - because of this "switch" on the first letter. */ - switch (tolower(restofline[0])) - { - case 'a': - if(ITIS("ACTIVEPLACEMENT")) - { - SKIP("ACTIVEPLACEMENT"); - tname.on_flags |= RANDOM_PLACE_FLAG; - } - break; - case 'b': - if(ITIS("BACKCOLOR")) - { - SKIP("BACKCOLOR"); - GETWORD; - if(len > 0) - { - tname.BackColor = safemalloc(len+1); - strncpy(tname.BackColor,restofline,len); - tname.BackColor[len] = 0; - tname.off_flags |= BACK_COLOR_FLAG; - } - restofline = tmp; - } - else if (ITIS("BUTTON")) - { - SKIP("BUTTON"); - butt = -1; /* just in case sscanf fails */ - sscanf(restofline,"%d",&butt); - GETWORD; - restofline = tmp; - SKIPSPACE; - if (butt == 0) butt = 10; - if (butt > 0 && butt <= 10) - tname.on_buttons |= (1<<(butt-1)); - } - else if(ITIS("BorderWidth")) - { - SKIP("BorderWidth"); - tname.off_flags |= BW_FLAG; - sscanf(restofline,"%d",&tname.border_width); - GETWORD; - restofline = tmp; - SKIPSPACE; - } - break; - case 'c': - if(ITIS("COLOR")) - { - SKIP("COLOR"); - SKIPSPACE; - tmp = restofline; - len = 0; - while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&& - (*tmp != '\n')&&(*tmp != '/')&&(!isspace(*tmp))) - { - tmp++; - len++; - } - if(len > 0) - { - tname.ForeColor = safemalloc(len+1); - strncpy(tname.ForeColor,restofline,len); - tname.ForeColor[len] = 0; - tname.off_flags |= FORE_COLOR_FLAG; - } + if (restofline == NULL) { + free(tname.name); + return; + } + while ((*restofline != 0) && (*restofline != '\n')) { + SKIPSPACE; /* skip white space */ + /* It might make more sense to capture the whole word, fix its + case, and use strcmp, but there aren't many caseless compares + because of this "switch" on the first letter. */ + switch (tolower(restofline[0])) { + case 'a': + if (ITIS("ACTIVEPLACEMENT")) { + SKIP("ACTIVEPLACEMENT"); + tname.on_flags |= RANDOM_PLACE_FLAG; + } + break; + case 'b': + if (ITIS("BACKCOLOR")) { + SKIP("BACKCOLOR"); + GETWORD; + if (len > 0) { + tname.BackColor = xmalloc(len + 1); + strncpy( + tname.BackColor, restofline, len); + tname.BackColor[len] = 0; + tname.off_flags |= BACK_COLOR_FLAG; + } + restofline = tmp; + } else if (ITIS("BUTTON")) { + SKIP("BUTTON"); + butt = -1; /* just in case sscanf fails */ + sscanf(restofline, "%d", &butt); + GETWORD; + restofline = tmp; + SKIPSPACE; + if (butt == 0) + butt = 10; + if (butt > 0 && butt <= 10) + tname.on_buttons |= (1 << (butt - 1)); + } else if (ITIS("BorderWidth")) { + SKIP("BorderWidth"); + tname.off_flags |= BW_FLAG; + sscanf(restofline, "%d", &tname.border_width); + GETWORD; + restofline = tmp; + SKIPSPACE; + } + break; + case 'c': + if (ITIS("COLOR")) { + SKIP("COLOR"); + SKIPSPACE; + tmp = restofline; + len = 0; + while ((tmp != NULL) && (*tmp != 0) && + (*tmp != ',') && (*tmp != '\n') && + (*tmp != '/') && (!isspace(*tmp))) { + tmp++; + len++; + } + if (len > 0) { + tname.ForeColor = xmalloc(len + 1); + strncpy( + tname.ForeColor, restofline, len); + tname.ForeColor[len] = 0; + tname.off_flags |= FORE_COLOR_FLAG; + } - while(isspace(*tmp))tmp++; - if(*tmp == '/') - { - tmp++; - while(isspace(*tmp))tmp++; - restofline = tmp; - len = 0; - while((tmp != NULL)&&(*tmp != 0)&&(*tmp != ',')&& - (*tmp != '\n')&&(*tmp != '/')&&(!isspace(*tmp))) - { - tmp++; - len++; - } - if(len > 0) - { - tname.BackColor = safemalloc(len+1); - strncpy(tname.BackColor,restofline,len); - tname.BackColor[len] = 0; - tname.off_flags |= BACK_COLOR_FLAG; - } - } - restofline = tmp; - } - else if(ITIS("CirculateSkipIcon")) - { - SKIP("CirculateSkipIcon"); - tname.off_flags |= CIRCULATE_SKIP_ICON_FLAG; - } - else if(ITIS("CirculateHitIcon")) - { - SKIP("CirculateHitIcon"); - tname.on_flags |= CIRCULATE_SKIP_ICON_FLAG; - } - else if(ITIS("CLICKTOFOCUS")) - { - SKIP("CLICKTOFOCUS"); - tname.off_flags |= CLICK_FOCUS_FLAG; - tname.on_flags |= SLOPPY_FOCUS_FLAG; - } - else if(ITIS("CirculateSkip")) - { - SKIP("CirculateSkip"); - tname.off_flags |= CIRCULATESKIP_FLAG; - } - else if(ITIS("CirculateHit")) - { - SKIP("CirculateHit"); - tname.on_flags |= CIRCULATESKIP_FLAG; - } - break; - case 'd': - if(ITIS("DecorateTransient")) - { - SKIP("DecorateTransient"); - tname.off_flags |= DECORATE_TRANSIENT_FLAG; - } - else if(ITIS("DUMBPLACEMENT")) - { - SKIP("DUMBPLACEMENT"); - tname.on_flags |= SMART_PLACE_FLAG; - } - break; - case 'e': - break; - case 'f': - if(ITIS("FORECOLOR")) - { - SKIP("FORECOLOR"); - GETWORD; - if(len > 0) - { - tname.ForeColor = safemalloc(len+1); - strncpy(tname.ForeColor,restofline,len); - tname.ForeColor[len] = 0; - tname.off_flags |= FORE_COLOR_FLAG; - } - restofline = tmp; - } - else if(ITIS("FVWMBUTTONS")) - { - SKIP("FVWMBUTTONS"); - tname.on_flags |= MWM_BUTTON_FLAG; - } - else if(ITIS("FVWMBORDER")) - { - SKIP("FVWMBORDER"); - tname.on_flags |= MWM_BORDER_FLAG; - } - else if(ITIS("FocusFollowsMouse")) - { - SKIP("FocusFollowsMouse"); - tname.on_flags |= CLICK_FOCUS_FLAG; - tname.on_flags |= SLOPPY_FOCUS_FLAG; - } - break; - case 'g': - break; - case 'h': - if(ITIS("HINTOVERRIDE")) - { - SKIP("HINTOVERRIDE"); - tname.off_flags |= MWM_OVERRIDE_FLAG; - } - else if(ITIS("HANDLES")) - { - SKIP("HANDLES"); - tname.on_flags |= NOBORDER_FLAG; - } - else if(ITIS("HandleWidth")) - { - SKIP("HandleWidth"); - tname.off_flags |= NOBW_FLAG; - sscanf(restofline,"%d",&tname.resize_width); - GETWORD; - restofline = tmp; - SKIPSPACE; - } - break; - case 'i': - if(ITIS("IconTitle")) - { - SKIP("IconTitle"); - tname.on_flags |= NOICON_TITLE_FLAG; - } - else if(ITIS("IconBox")) - { - icon_boxes *IconBoxes = 0; - SKIP("IconBox"); /* Skip over word "IconBox" */ - IconBoxes = (icon_boxes *)safemalloc(sizeof(icon_boxes)); - memset(IconBoxes, 0, sizeof(icon_boxes)); /* clear it */ - IconBoxes->IconGrid[0] = 3; /* init grid x */ - IconBoxes->IconGrid[1] = 3; /* init grid y */ - /* try for 4 numbers x y x y */ - num = sscanf(restofline,"%d%d%d%d", - &IconBoxes->IconBox[0], - &IconBoxes->IconBox[1], - &IconBoxes->IconBox[2], - &IconBoxes->IconBox[3]); - if (num == 4) { /* if 4 numbers */ - for(i=0;iIconBox[i] += Scr.MyDisplayWidth; - } else { /* it must be a height */ - IconBoxes->IconBox[i] += Scr.MyDisplayHeight; - } /* end width/height */ - } /* end leading minus sign */ - while((!isspace(*restofline))&&(*restofline!= 0)&& - (*restofline != ',')&&(*restofline != '\n')) - restofline++; - } - /* Note: here there is no test for valid co-ords, use geom */ - } else { /* Not 4 numeric args dje */ - char geom_string[25]; /* bigger than =32767x32767+32767+32767 */ - int geom_flags; - GETWORD; /* read in 1 word w/o advancing */ - if(len > 0 && len < 24) { /* if word found, not too long */ - strncpy(geom_string,restofline,len); /* copy and null term */ - geom_string[len] = 0; /* null terminate it */ - geom_flags=XParseGeometry(geom_string, - &IconBoxes->IconBox[0], - &IconBoxes->IconBox[1], /* x/y */ - &IconBoxes->IconBox[2], - &IconBoxes->IconBox[3]); /* width/ht */ - if (IconBoxes->IconBox[2] == 0) { /* zero width ind invalid */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconBox requires 4 numbers or geometry! Invalid string <%s>.", - geom_string); - free(IconBoxes); /* Drop the box */ - IconBoxes = 0; /* forget about it */ - } else { /* got valid iconbox geom */ - if (geom_flags&XNegative) { - IconBoxes->IconBox[0] = Scr.MyDisplayWidth /* screen width */ - + IconBoxes->IconBox[0] /* neg x coord */ - - IconBoxes->IconBox[2] -2; /* width - 2 */ - } - if (geom_flags&YNegative) { - IconBoxes->IconBox[1] = Scr.MyDisplayHeight /* scr height */ - + IconBoxes->IconBox[1] /* neg y coord */ - - IconBoxes->IconBox[3] -2; /* height - 2 */ - } - IconBoxes->IconBox[2] += - IconBoxes->IconBox[0]; /* x + wid = right x */ - IconBoxes->IconBox[3] += - IconBoxes->IconBox[1]; /* y + height = bottom y */ - } /* end icon geom worked */ - } else { /* no word or too long */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconBox requires 4 numbers or geometry! Too long (%d).", - len); - free(IconBoxes); /* Drop the box */ - IconBoxes = 0; /* forget about it */ - } /* end word found, not too long */ - restofline = tmp; /* got word, move past it */ - } /* end not 4 args */ - /* If we created an IconBox, put it in the chain. */ - if (IconBoxes != 0) { /* If no error */ - if (tname.IconBoxes == 0) { /* If first one */ - tname.IconBoxes = IconBoxes; /* chain to root */ - } else { /* else not first one */ - which->next = IconBoxes; /* add to end of chain */ - } /* end not first one */ - which = IconBoxes; /* new current box. save for grid */ - } /* end no error */ - } /* end iconbox parameter */ - else if(ITIS("ICONGRID")) { - SKIP("ICONGRID"); - SKIPSPACE; /* skip whitespace after keyword */ - /* The grid always affects the prior iconbox */ - if (which == 0) { /* If no current box */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconGrid must follow an IconBox in same Style command"); - } else { /* have a place to grid */ - num = sscanf(restofline,"%hd%hd", /* 2 shorts */ - &which->IconGrid[0], - &which->IconGrid[1]); - if (num != 2 - || which->IconGrid[0] < 1 - || which->IconGrid[1] < 1) { - fvwm_msg(ERR,"ProcessNewStyle", - "IconGrid needs 2 numbers > 0. Got %d numbers. x=%d y=%d!", - num, (int)which->IconGrid[0], (int)which->IconGrid[1]); - which->IconGrid[0] = 3; /* reset grid x */ - which->IconGrid[1] = 3; /* reset grid y */ - } else { /* it worked */ - GETWORD; /* swallow word */ - restofline = tmp; - GETWORD; /* swallow word */ - restofline = tmp; - } /* end bad grid */ - } /* end place to grid */ - } else if(ITIS("ICONFILL")) { /* direction to fill iconbox */ - SKIP("ICONFILL"); - SKIPSPACE; /* skip whitespace after keyword */ - /* The fill always affects the prior iconbox */ - if (which == 0) { /* If no current box */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must follow an IconBox in same Style command"); - } else { /* have a place to fill */ - unsigned char IconFill_1; /* first type direction parsed */ - unsigned char IconFill_2; /* second type direction parsed */ - GETWORD; /* read in word for length */ - if (Get_TBLR(restofline,&IconFill_1) == 0) { /* top/bot/lft/rgt */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must be followed by T|B|R|L, found %.*s.", - len, restofline); /* its wrong */ - } else { /* first word valid */ - restofline = tmp; /* swallow it */ - SKIPSPACE; /* skip space between words */ - GETWORD; /* read in second word */ - if (Get_TBLR(restofline,&IconFill_2) == 0) {/* top/bot/lft/rgt */ - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must be followed by T|B|R|L, found %.*s.", - len, restofline); /* its wrong */ - } else if ((IconFill_1&ICONFILLHRZ)==(IconFill_2&ICONFILLHRZ)) { - fvwm_msg(ERR,"ProcessNewStyle", - "IconFill must specify a horizontal and vertical direction."); - } else { /* Its valid! */ - which->IconFlags |= IconFill_1; /* merge in flags */ - IconFill_2 &= ~ICONFILLHRZ; /* ignore horiz in 2nd arg */ - which->IconFlags |= IconFill_2; /* merge in flags */ - } /* end second word valid */ - } /* end first word valid */ - restofline = tmp; /* swallow first or second word */ - } /* end have a place to fill */ - } /* end iconfill */ - else if(ITIS("ICON")) - { - SKIP("ICON"); - GETWORD; - if(len > 0) - { - tname.value = safemalloc(len+1); - strncpy(tname.value,restofline,len); - tname.value[len] = 0; - tname.off_flags |= ICON_FLAG; - tname.on_flags |= SUPPRESSICON_FLAG; - } - else - tname.on_flags |= SUPPRESSICON_FLAG; - restofline = tmp; - } - break; - case 'j': - break; - case 'k': - break; - case 'l': - if(ITIS("LENIENCE")) - { - SKIP("LENIENCE"); - tname.off_flags |= LENIENCE_FLAG; - } - break; - case 'm': - if(ITIS("MWMBUTTONS")) - { - SKIP("MWMBUTTONS"); - tname.off_flags |= MWM_BUTTON_FLAG; - } + while (isspace(*tmp)) + tmp++; + if (*tmp == '/') { + tmp++; + while (isspace(*tmp)) + tmp++; + restofline = tmp; + len = 0; + while ((tmp != NULL) && (*tmp != 0) && + (*tmp != ',') && (*tmp != '\n') && + (*tmp != '/') && (!isspace(*tmp))) { + tmp++; + len++; + } + if (len > 0) { + tname.BackColor = + xmalloc(len + 1); + strncpy(tname.BackColor, + restofline, len); + tname.BackColor[len] = 0; + tname.off_flags |= + BACK_COLOR_FLAG; + } + } + restofline = tmp; + } else if (ITIS("CirculateSkipIcon")) { + SKIP("CirculateSkipIcon"); + tname.off_flags |= CIRCULATE_SKIP_ICON_FLAG; + } else if (ITIS("CirculateHitIcon")) { + SKIP("CirculateHitIcon"); + tname.on_flags |= CIRCULATE_SKIP_ICON_FLAG; + } else if (ITIS("CLICKTOFOCUS")) { + SKIP("CLICKTOFOCUS"); + tname.off_flags |= CLICK_FOCUS_FLAG; + tname.on_flags |= SLOPPY_FOCUS_FLAG; + } else if (ITIS("CirculateSkip")) { + SKIP("CirculateSkip"); + tname.off_flags |= CIRCULATESKIP_FLAG; + } else if (ITIS("CirculateHit")) { + SKIP("CirculateHit"); + tname.on_flags |= CIRCULATESKIP_FLAG; + } + break; + case 'd': + if (ITIS("DecorateTransient")) { + SKIP("DecorateTransient"); + tname.off_flags |= DECORATE_TRANSIENT_FLAG; + } else if (ITIS("DUMBPLACEMENT")) { + SKIP("DUMBPLACEMENT"); + tname.on_flags |= SMART_PLACE_FLAG; + } + break; + case 'e': + break; + case 'f': + if (ITIS("FORECOLOR")) { + SKIP("FORECOLOR"); + GETWORD; + if (len > 0) { + tname.ForeColor = xmalloc(len + 1); + strncpy( + tname.ForeColor, restofline, len); + tname.ForeColor[len] = 0; + tname.off_flags |= FORE_COLOR_FLAG; + } + restofline = tmp; + } else if (ITIS("FVWMBUTTONS")) { + SKIP("FVWMBUTTONS"); + tname.on_flags |= MWM_BUTTON_FLAG; + } else if (ITIS("FVWMBORDER")) { + SKIP("FVWMBORDER"); + tname.on_flags |= MWM_BORDER_FLAG; + } else if (ITIS("FocusFollowsMouse")) { + SKIP("FocusFollowsMouse"); + tname.on_flags |= CLICK_FOCUS_FLAG; + tname.on_flags |= SLOPPY_FOCUS_FLAG; + } + break; + case 'g': + break; + case 'h': + if (ITIS("HINTOVERRIDE")) { + SKIP("HINTOVERRIDE"); + tname.off_flags |= MWM_OVERRIDE_FLAG; + } else if (ITIS("HANDLES")) { + SKIP("HANDLES"); + tname.on_flags |= NOBORDER_FLAG; + } else if (ITIS("HandleWidth")) { + SKIP("HandleWidth"); + tname.off_flags |= NOBW_FLAG; + sscanf(restofline, "%d", &tname.resize_width); + GETWORD; + restofline = tmp; + SKIPSPACE; + } + break; + case 'i': + if (ITIS("IconTitle")) { + SKIP("IconTitle"); + tname.on_flags |= NOICON_TITLE_FLAG; + } else if (ITIS("IconBox")) { + icon_boxes *IconBoxes = 0; + SKIP("IconBox"); /* Skip over word "IconBox" */ + IconBoxes = (icon_boxes *)xmalloc( + sizeof(icon_boxes)); + memset(IconBoxes, 0, + sizeof(icon_boxes)); /* clear it */ + IconBoxes->IconGrid[0] = 3; /* init grid x */ + IconBoxes->IconGrid[1] = 3; /* init grid y */ + /* try for 4 numbers x y x y */ + num = sscanf(restofline, "%d%d%d%d", + &IconBoxes->IconBox[0], + &IconBoxes->IconBox[1], + &IconBoxes->IconBox[2], + &IconBoxes->IconBox[3]); + if (num == 4) { /* if 4 numbers */ + for (i = 0; i < num; i++) { + SKIPSPACE; + if (*restofline == + '-') { /* If leading minus + sign */ + if (i == 0 || + i == + 2) { /* if a + width */ + IconBoxes + ->IconBox + [i] += + Scr.MyDisplayWidth; + } else { /* it must be a + height */ + IconBoxes + ->IconBox + [i] += + Scr.MyDisplayHeight; + } /* end width/height */ + } /* end leading minus sign */ + while ((!isspace( + *restofline)) && + (*restofline != 0) && + (*restofline != ',') && + (*restofline != '\n')) + restofline++; + } + /* Note: here there is no test for valid + * co-ords, use geom */ + } else { /* Not 4 numeric args dje */ + char geom_string[25]; /* bigger than + =32767x32767+32767+32767 + */ + int geom_flags; + GETWORD; /* read in 1 word w/o advancing + */ + if (len > 0 && + len < 24) { /* if word found, not + too long */ + strncpy(geom_string, restofline, + len); /* copy and null term + */ + geom_string[len] = + 0; /* null terminate it */ + geom_flags = XParseGeometry( + geom_string, + &IconBoxes->IconBox[0], + &IconBoxes + ->IconBox[1], /* x/y */ + &IconBoxes->IconBox[2], + &IconBoxes->IconBox + [3]); /* width/ht + */ + if (IconBoxes->IconBox[2] == + 0) { /* zero width ind + invalid */ + fvwm_msg(ERR, + "ProcessNewStyle", + "IconBox requires " + "4 numbers or " + "geometry! " + "Invalid string " + "<%s>.", + geom_string); + free(IconBoxes); /* Drop + the + box + */ + IconBoxes = + 0; /* forget about + it */ + } else { /* got valid iconbox + geom */ + if (geom_flags & + XNegative) { + IconBoxes + ->IconBox + [0] = + Scr.MyDisplayWidth + + /* screen width */ + IconBoxes->IconBox + [0] /* neg + x coord */ + - + IconBoxes + ->IconBox + [2] - + 2; /* width + - 2 */ + } + if (geom_flags & + YNegative) { + IconBoxes + ->IconBox + [1] = + Scr.MyDisplayHeight + + /* scr height */ + IconBoxes->IconBox + [1] /* neg + y coord */ + - + IconBoxes + ->IconBox + [3] - + 2; /* height + - 2 */ + } + IconBoxes->IconBox[2] += + IconBoxes->IconBox + [0]; /* x + wid + = right + x */ + IconBoxes->IconBox[3] += + IconBoxes->IconBox + [1]; /* y + + height = + bottom y + */ + } /* end icon geom worked */ + } else { /* no word or too long */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconBox requires 4 " + "numbers or geometry! Too " + "long (%d).", + len); + free(IconBoxes); /* Drop the box + */ + IconBoxes = + 0; /* forget about it */ + } /* end word found, not too long */ + restofline = + tmp; /* got word, move past it */ + } /* end not 4 args */ + /* If we created an IconBox, put it in the + * chain. */ + if (IconBoxes != 0) { /* If no error */ + if (tname.IconBoxes == + 0) { /* If first one */ + tname.IconBoxes = + IconBoxes; /* chain to root + */ + } else { /* else not first one */ + which->next = + IconBoxes; /* add to end of + chain */ + } /* end not first one */ + which = IconBoxes; /* new current box. + save for grid */ + } /* end no error */ + } /* end iconbox parameter */ else if (ITIS( + "ICONGRID")) { + SKIP("ICONGRID"); + SKIPSPACE; /* skip whitespace after keyword */ + /* The grid always affects the prior iconbox */ + if (which == 0) { /* If no current box */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconGrid must follow an IconBox " + "in same Style command"); + } else { /* have a place to grid */ + num = sscanf(restofline, + "%hd%hd", /* 2 shorts */ + &which->IconGrid[0], + &which->IconGrid[1]); + if (num != 2 || + which->IconGrid[0] < 1 || + which->IconGrid[1] < 1) { + fvwm_msg(ERR, "ProcessNewStyle", + "IconGrid needs 2 numbers " + "> 0. Got %d numbers. " + "x=%d y=%d!", + num, + (int)which->IconGrid[0], + (int)which->IconGrid[1]); + which->IconGrid[0] = + 3; /* reset grid x */ + which->IconGrid[1] = + 3; /* reset grid y */ + } else { /* it worked */ + GETWORD; /* swallow word */ + restofline = tmp; + GETWORD; /* swallow word */ + restofline = tmp; + } /* end bad grid */ + } /* end place to grid */ + } else if (ITIS("ICONFILL")) { /* direction to fill + iconbox */ + SKIP("ICONFILL"); + SKIPSPACE; /* skip whitespace after keyword */ + /* The fill always affects the prior iconbox */ + if (which == 0) { /* If no current box */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconFill must follow an IconBox " + "in same Style command"); + } else { /* have a place to fill */ + unsigned char IconFill_1; /* first type direction + parsed */ + unsigned char IconFill_2; /* second type direction + parsed */ + GETWORD; /* read in word for length */ + if (Get_TBLR(restofline, &IconFill_1) == + 0) { /* top/bot/lft/rgt */ + fvwm_msg(ERR, "ProcessNewStyle", + "IconFill must be followed " + "by T|B|R|L, found %.*s.", + len, + restofline); /* its wrong */ + } else { /* first word valid */ + restofline = + tmp; /* swallow it */ + SKIPSPACE; /* skip space between + words */ + GETWORD; /* read in second word + */ + if (Get_TBLR(restofline, + &IconFill_2) == + 0) { /* top/bot/lft/rgt */ + fvwm_msg(ERR, + "ProcessNewStyle", + "IconFill must be " + "followed by " + "T|B|R|L, found " + "%.*s.", + len, + restofline); /* its + wrong + */ + } else if ((IconFill_1 & + ICONFILLHRZ) == + (IconFill_2 & + ICONFILLHRZ)) { + fvwm_msg(ERR, + "ProcessNewStyle", + "IconFill must " + "specify a " + "horizontal and " + "vertical " + "direction."); + } else { /* Its valid! */ + which->IconFlags |= + IconFill_1; /* merge + in + flags + */ + IconFill_2 &= + ~ICONFILLHRZ; /* ignore + horiz + in + 2nd + arg + */ + which->IconFlags |= + IconFill_2; /* merge + in + flags + */ + } /* end second word valid */ + } /* end first word valid */ + restofline = tmp; /* swallow first or + second word */ + } /* end have a place to fill */ + } /* end iconfill */ else if (ITIS("ICON")) { + SKIP("ICON"); + GETWORD; + if (len > 0) { + tname.value = xmalloc(len + 1); + strncpy(tname.value, restofline, len); + tname.value[len] = 0; + tname.off_flags |= ICON_FLAG; + tname.on_flags |= SUPPRESSICON_FLAG; + } else + tname.on_flags |= SUPPRESSICON_FLAG; + restofline = tmp; + } + break; + case 'j': + break; + case 'k': + break; + case 'l': + if (ITIS("LENIENCE")) { + SKIP("LENIENCE"); + tname.off_flags |= LENIENCE_FLAG; + } + break; + case 'm': + if (ITIS("MWMBUTTONS")) { + SKIP("MWMBUTTONS"); + tname.off_flags |= MWM_BUTTON_FLAG; + } #ifdef MINI_ICONS - else if (ITIS("MINIICON")) - { - SKIP("MINIICON"); - GETWORD; - if(len > 0) - { - tname.mini_value = safemalloc(len+1); - strncpy(tname.mini_value,restofline,len); - tname.mini_value[len] = 0; - tname.off_flags |= MINIICON_FLAG; - } - restofline = tmp; - } + else if (ITIS("MINIICON")) { + SKIP("MINIICON"); + GETWORD; + if (len > 0) { + tname.mini_value = xmalloc(len + 1); + strncpy( + tname.mini_value, restofline, len); + tname.mini_value[len] = 0; + tname.off_flags |= MINIICON_FLAG; + } + restofline = tmp; + } #endif - else if(ITIS("MWMBORDER")) - { - SKIP("MWMBORDER"); - tname.off_flags |= MWM_BORDER_FLAG; - } - else if(ITIS("MWMDECOR")) - { - SKIP("MWMDECOR"); - tname.off_flags |= MWM_DECOR_FLAG; - } - else if(ITIS("MWMFUNCTIONS")) - { - SKIP("MWMFUNCTIONS"); - tname.off_flags |= MWM_FUNCTIONS_FLAG; - } - else if(ITIS("MOUSEFOCUS")) - { - SKIP("MOUSEFOCUS"); - tname.on_flags |= CLICK_FOCUS_FLAG; - tname.on_flags |= SLOPPY_FOCUS_FLAG; - } - break; - case 'n': - if(ITIS("NoIconTitle")) - { - SKIP("NoIconTitle"); - tname.off_flags |= NOICON_TITLE_FLAG; - } - else if(ITIS("NOICON")) - { - SKIP("NOICON"); - tname.off_flags |= SUPPRESSICON_FLAG; - } - else if(ITIS("NOTITLE")) - { - SKIP("NOTITLE"); - tname.off_flags |= NOTITLE_FLAG; - } - else if(ITIS("NoPPosition")) - { - SKIP("NoPPosition"); - tname.off_flags |= NO_PPOSITION_FLAG; - } - else if(ITIS("NakedTransient")) - { - SKIP("NakedTransient"); - tname.on_flags |= DECORATE_TRANSIENT_FLAG; - } - else if(ITIS("NODECORHINT")) - { - SKIP("NODECORHINT"); - tname.on_flags |= MWM_DECOR_FLAG; - } - else if(ITIS("NOFUNCHINT")) - { - SKIP("NOFUNCHINT"); - tname.on_flags |= MWM_FUNCTIONS_FLAG; - } - else if(ITIS("NOOVERRIDE")) - { - SKIP("NOOVERRIDE"); - tname.on_flags |= MWM_OVERRIDE_FLAG; - } - else if(ITIS("NOHANDLES")) - { - SKIP("NOHANDLES"); - tname.off_flags |= NOBORDER_FLAG; - } - else if(ITIS("NOLENIENCE")) - { - SKIP("NOLENIENCE"); - tname.on_flags |= LENIENCE_FLAG; - } - else if (ITIS("NOBUTTON")) - { - SKIP("NOBUTTON"); - - butt = -1; /* just in case sscanf fails */ - sscanf(restofline,"%d",&butt); - GETWORD; - SKIPSPACE; + else if (ITIS("MWMBORDER")) { + SKIP("MWMBORDER"); + tname.off_flags |= MWM_BORDER_FLAG; + } else if (ITIS("MWMDECOR")) { + SKIP("MWMDECOR"); + tname.off_flags |= MWM_DECOR_FLAG; + } else if (ITIS("MWMFUNCTIONS")) { + SKIP("MWMFUNCTIONS"); + tname.off_flags |= MWM_FUNCTIONS_FLAG; + } else if (ITIS("MOUSEFOCUS")) { + SKIP("MOUSEFOCUS"); + tname.on_flags |= CLICK_FOCUS_FLAG; + tname.on_flags |= SLOPPY_FOCUS_FLAG; + } + break; + case 'n': + if (ITIS("NoIconTitle")) { + SKIP("NoIconTitle"); + tname.off_flags |= NOICON_TITLE_FLAG; + } else if (ITIS("NOICON")) { + SKIP("NOICON"); + tname.off_flags |= SUPPRESSICON_FLAG; + } else if (ITIS("NOTITLE")) { + SKIP("NOTITLE"); + tname.off_flags |= NOTITLE_FLAG; + } else if (ITIS("NoPPosition")) { + SKIP("NoPPosition"); + tname.off_flags |= NO_PPOSITION_FLAG; + } else if (ITIS("NakedTransient")) { + SKIP("NakedTransient"); + tname.on_flags |= DECORATE_TRANSIENT_FLAG; + } else if (ITIS("NODECORHINT")) { + SKIP("NODECORHINT"); + tname.on_flags |= MWM_DECOR_FLAG; + } else if (ITIS("NOFUNCHINT")) { + SKIP("NOFUNCHINT"); + tname.on_flags |= MWM_FUNCTIONS_FLAG; + } else if (ITIS("NOOVERRIDE")) { + SKIP("NOOVERRIDE"); + tname.on_flags |= MWM_OVERRIDE_FLAG; + } else if (ITIS("NOHANDLES")) { + SKIP("NOHANDLES"); + tname.off_flags |= NOBORDER_FLAG; + } else if (ITIS("NOLENIENCE")) { + SKIP("NOLENIENCE"); + tname.on_flags |= LENIENCE_FLAG; + } else if (ITIS("NOBUTTON")) { + SKIP("NOBUTTON"); - if (butt == 0) butt = 10; - if (butt > 0 && butt <= 10) - tname.off_buttons |= (1<<(butt-1)); - restofline = tmp; - } - else if(ITIS("NOOLDECOR")) - { - SKIP("NOOLDECOR"); - tname.on_flags |= OL_DECOR_FLAG; - } - break; - case 'o': - if(ITIS("OLDECOR")) - { - SKIP("OLDECOR"); - tname.off_flags |= OL_DECOR_FLAG; - } - break; - case 'p': - break; - case 'q': - break; - case 'r': - if(ITIS("RANDOMPLACEMENT")) - { - SKIP("RANDOMPLACEMENT"); - tname.off_flags |= RANDOM_PLACE_FLAG; - } - break; - case 's': - if(ITIS("SMARTPLACEMENT")) - { - SKIP("SMARTPLACEMENT"); - tname.off_flags |= SMART_PLACE_FLAG; - } - else if(ITIS("SkipMapping")) - { - SKIP("SkipMapping"); - tname.off_flags |= SHOW_MAPPING; - } - else if(ITIS("ShowMapping")) - { - SKIP("ShowMapping"); - tname.on_flags |= SHOW_MAPPING; - } - else if(ITIS("StickyIcon")) - { - SKIP("StickyIcon"); - tname.off_flags |= STICKY_ICON_FLAG; - } - else if(ITIS("SlipperyIcon")) - { - SKIP("SlipperyIcon"); - tname.on_flags |= STICKY_ICON_FLAG; - } - else if(ITIS("SLOPPYFOCUS")) - { - SKIP("SLOPPYFOCUS"); - tname.on_flags |= CLICK_FOCUS_FLAG; - tname.off_flags |= SLOPPY_FOCUS_FLAG; - } - else if(ITIS("StartIconic")) - { - SKIP("StartIconic"); - tname.off_flags |= START_ICONIC_FLAG; - } - else if(ITIS("StartNormal")) - { - SKIP("StartNormal"); - tname.on_flags |= START_ICONIC_FLAG; - } - else if(ITIS("StaysOnTop")) - { - SKIP("StaysOnTop"); - tname.off_flags |= STAYSONTOP_FLAG; - } - else if(ITIS("StaysPut")) - { - SKIP("StaysPut"); - tname.on_flags |= STAYSONTOP_FLAG; - } - else if(ITIS("Sticky")) - { - tname.off_flags |= STICKY_FLAG; - SKIP("Sticky"); - } - else if(ITIS("Slippery")) - { - tname.on_flags |= STICKY_FLAG; - SKIP("Slippery"); - } - else if(ITIS("STARTSONDESK")) - { - SKIP("STARTSONDESK"); - tname.off_flags |= STARTSONDESK_FLAG; - /* RBW - 11/02/1998 */ - spargs = sscanf(restofline,"%d",&tmpno1); - if (spargs == 1) - { - /* RBW - 11/20/1998 - allow for the special case of -1 */ - tname.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - } - else - { - tname.off_flags &= ~STARTSONDESK_FLAG; - fvwm_msg(ERR,"ProcessNewStyle", - "bad StartsOnDesk arg: %s", restofline); - } - /**/ - GETWORD; - restofline = tmp; - SKIPSPACE; - } - /* RBW - 11/02/1998 - StartsOnPage is like StartsOnDesk-Plus - */ - else if(ITIS("STARTSONPAGE")) - { - SKIP("STARTSONPAGE"); - tname.off_flags |= STARTSONDESK_FLAG; - spargs = sscanf(restofline,"%d %d %d", &tmpno1, &tmpno2, &tmpno3); + butt = -1; /* just in case sscanf fails */ + sscanf(restofline, "%d", &butt); + GETWORD; + SKIPSPACE; - if (spargs == 1 || spargs == 3) - { - /* We have a desk no., with or without page. */ - /* RBW - 11/20/1998 - allow for the special case of -1 */ - tname.Desk = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; /* Desk is now actual + 1 */ - /* Bump past desk no. */ - GETWORD; - restofline = tmp; - SKIPSPACE; - } + if (butt == 0) + butt = 10; + if (butt > 0 && butt <= 10) + tname.off_buttons |= (1 << (butt - 1)); + restofline = tmp; + } else if (ITIS("NOOLDECOR")) { + SKIP("NOOLDECOR"); + tname.on_flags |= OL_DECOR_FLAG; + } + break; + case 'o': + if (ITIS("OLDECOR")) { + SKIP("OLDECOR"); + tname.off_flags |= OL_DECOR_FLAG; + } + break; + case 'p': + break; + case 'q': + break; + case 'r': + if (ITIS("RANDOMPLACEMENT")) { + SKIP("RANDOMPLACEMENT"); + tname.off_flags |= RANDOM_PLACE_FLAG; + } + break; + case 's': + if (ITIS("SMARTPLACEMENT")) { + SKIP("SMARTPLACEMENT"); + tname.off_flags |= SMART_PLACE_FLAG; + } else if (ITIS("SkipMapping")) { + SKIP("SkipMapping"); + tname.off_flags |= SHOW_MAPPING; + } else if (ITIS("ShowMapping")) { + SKIP("ShowMapping"); + tname.on_flags |= SHOW_MAPPING; + } else if (ITIS("StickyIcon")) { + SKIP("StickyIcon"); + tname.off_flags |= STICKY_ICON_FLAG; + } else if (ITIS("SlipperyIcon")) { + SKIP("SlipperyIcon"); + tname.on_flags |= STICKY_ICON_FLAG; + } else if (ITIS("SLOPPYFOCUS")) { + SKIP("SLOPPYFOCUS"); + tname.on_flags |= CLICK_FOCUS_FLAG; + tname.off_flags |= SLOPPY_FOCUS_FLAG; + } else if (ITIS("StartIconic")) { + SKIP("StartIconic"); + tname.off_flags |= START_ICONIC_FLAG; + } else if (ITIS("StartNormal")) { + SKIP("StartNormal"); + tname.on_flags |= START_ICONIC_FLAG; + } else if (ITIS("StaysOnTop")) { + SKIP("StaysOnTop"); + tname.off_flags |= STAYSONTOP_FLAG; + } else if (ITIS("StaysPut")) { + SKIP("StaysPut"); + tname.on_flags |= STAYSONTOP_FLAG; + } else if (ITIS("Sticky")) { + tname.off_flags |= STICKY_FLAG; + SKIP("Sticky"); + } else if (ITIS("Slippery")) { + tname.on_flags |= STICKY_FLAG; + SKIP("Slippery"); + } else if (ITIS("STARTSONDESK")) { + SKIP("STARTSONDESK"); + tname.off_flags |= STARTSONDESK_FLAG; + /* RBW - 11/02/1998 */ + spargs = sscanf(restofline, "%d", &tmpno1); + if (spargs == 1) { + /* RBW - 11/20/1998 - allow for the + * special case of -1 */ + tname.Desk = + (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; + } else { + tname.off_flags &= ~STARTSONDESK_FLAG; + fvwm_msg(ERR, "ProcessNewStyle", + "bad StartsOnDesk arg: %s", + restofline); + } + /**/ + GETWORD; + restofline = tmp; + SKIPSPACE; + } + /* RBW - 11/02/1998 + StartsOnPage is like StartsOnDesk-Plus + */ + else if (ITIS("STARTSONPAGE")) { + SKIP("STARTSONPAGE"); + tname.off_flags |= STARTSONDESK_FLAG; + spargs = sscanf(restofline, "%d %d %d", &tmpno1, + &tmpno2, &tmpno3); - if (spargs == 2 || spargs == 3) - { - if (spargs == 3) - { - /* RBW - 11/20/1998 - allow for the special case of -1 */ - tname.PageX = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - tname.PageY = (tmpno3 > -1) ? tmpno3 + 1 : tmpno3; - } - else - { - tname.PageX = (tmpno1 > -1) ? tmpno1 + 1 : tmpno1; - tname.PageY = (tmpno2 > -1) ? tmpno2 + 1 : tmpno2; - } - /* Bump past next 2 args. */ - GETWORD; - restofline = tmp; - SKIPSPACE; - GETWORD; - restofline = tmp; - SKIPSPACE; + if (spargs == 1 || spargs == 3) { + /* We have a desk no., with or without + * page. */ + /* RBW - 11/20/1998 - allow for the + * special case of -1 */ + tname.Desk = + (tmpno1 > -1) ? + tmpno1 + 1 : + tmpno1; /* Desk is now actual + + 1 */ + /* Bump past desk no. */ + GETWORD; + restofline = tmp; + SKIPSPACE; + } - } - if (spargs < 1 || spargs > 3) - { - tname.off_flags &= ~STARTSONDESK_FLAG; - fvwm_msg(ERR,"ProcessNewStyle", - "bad StartsOnPage args: %s", restofline); - } - - } - /**/ - else if(ITIS("STARTSANYWHERE")) - { - SKIP("STARTSANYWHERE"); - tname.on_flags |= STARTSONDESK_FLAG; - } - break; - case 't': - if(ITIS("TITLE")) - { - SKIP("TITLE"); - tname.on_flags |= NOTITLE_FLAG; - } - break; - case 'u': - if(ITIS("UsePPosition")) - { - SKIP("UsePPosition"); - tname.on_flags |= NO_PPOSITION_FLAG; - } + if (spargs == 2 || spargs == 3) { + if (spargs == 3) { + /* RBW - 11/20/1998 - allow for + * the special case of -1 */ + tname.PageX = (tmpno2 > -1) ? + tmpno2 + 1 : + tmpno2; + tname.PageY = (tmpno3 > -1) ? + tmpno3 + 1 : + tmpno3; + } else { + tname.PageX = (tmpno1 > -1) ? + tmpno1 + 1 : + tmpno1; + tname.PageY = (tmpno2 > -1) ? + tmpno2 + 1 : + tmpno2; + } + /* Bump past next 2 args. */ + GETWORD; + restofline = tmp; + SKIPSPACE; + GETWORD; + restofline = tmp; + SKIPSPACE; + } + if (spargs < 1 || spargs > 3) { + tname.off_flags &= ~STARTSONDESK_FLAG; + fvwm_msg(ERR, "ProcessNewStyle", + "bad StartsOnPage args: %s", + restofline); + } + } + /**/ + else if (ITIS("STARTSANYWHERE")) { + SKIP("STARTSANYWHERE"); + tname.on_flags |= STARTSONDESK_FLAG; + } + break; + case 't': + if (ITIS("TITLE")) { + SKIP("TITLE"); + tname.on_flags |= NOTITLE_FLAG; + } + break; + case 'u': + if (ITIS("UsePPosition")) { + SKIP("UsePPosition"); + tname.on_flags |= NO_PPOSITION_FLAG; + } #ifdef USEDECOR - if(ITIS("UseDecor")) - { - SKIP("UseDecor"); - GETQUOTEDWORD; - if (len > 0) - { - tname.Decor = safemalloc(len+1); - strncpy(tname.Decor,restofline,len); - tname.Decor[len] = 0; - } - restofline = tmp; - } + if (ITIS("UseDecor")) { + SKIP("UseDecor"); + GETQUOTEDWORD; + if (len > 0) { + tname.Decor = xmalloc(len + 1); + strncpy(tname.Decor, restofline, len); + tname.Decor[len] = 0; + } + restofline = tmp; + } #endif - else if(ITIS("UseStyle")) - { - SKIP("UseStyle"); - GETQUOTEDWORD; - if (len > 0) { - int hit = 0; - /* changed to accum multiple Style definitions (veliaa@rpi.edu) */ - for ( nptr = Scr.TheList; nptr; nptr = nptr->next ) { - if (!strncasecmp(restofline,nptr->name,len)) { /* match style */ - if (!hit) { /* first match */ - char *save_name; - save_name = tname.name; - memcpy((void*)&tname, (const void*)nptr, sizeof(name_list)); /* copy everything */ - tname.next = 0; /* except the next pointer */ - tname.name = save_name; /* and the name */ - hit = 1; /* set not first match */ - } else { /* subsequent match */ - tname.off_flags |= nptr->off_flags; - tname.on_flags &= ~(nptr->on_flags); - tname.off_buttons |= nptr->off_buttons; - tname.on_buttons &= ~(nptr->on_buttons); - if(nptr->value) tname.value = nptr->value; + else if (ITIS("UseStyle")) { + SKIP("UseStyle"); + GETQUOTEDWORD; + if (len > 0) { + int hit = 0; + /* changed to accum multiple Style + * definitions (veliaa@rpi.edu) */ + for (nptr = Scr.TheList; nptr; + nptr = nptr->next) { + if (!strncasecmp(restofline, + nptr->name, + len)) { /* match style + */ + if (!hit) { /* first + match */ + char *save_name; + save_name = + tname.name; + memcpy( + (void *)&tname, + (const void *) + nptr, + sizeof( + name_list)); /* copy everything */ + tname.next = + 0; /* except + the + next + pointer + */ + tname.name = + save_name; /* and the name */ + hit = + 1; /* set + not + first + match + */ + } else { /* subsequent + match */ + tname + .off_flags |= + nptr->off_flags; + tname + .on_flags &= ~( + nptr->on_flags); + tname + .off_buttons |= + nptr->off_buttons; + tname + .on_buttons &= + ~(nptr->on_buttons); + if (nptr->value) + tname + .value = + nptr->value; #ifdef MINI_ICONS - if(nptr->mini_value) tname.mini_value = nptr->mini_value; + if (nptr->mini_value) + tname + .mini_value = + nptr->mini_value; #endif #ifdef USEDECOR - if(nptr->Decor) tname.Decor = nptr->Decor; + if (nptr->Decor) + tname + .Decor = + nptr->Decor; #endif - if(nptr->off_flags & STARTSONDESK_FLAG) - /* RBW - 11/02/1998 */ - { - tname.Desk = nptr->Desk; - tname.PageX = nptr->PageX; - tname.PageY = nptr->PageY; - } - /**/ - if(nptr->off_flags & BW_FLAG) - tname.border_width = nptr->border_width; - if(nptr->off_flags & NOBW_FLAG) - tname.resize_width = nptr->resize_width; - if(nptr->off_flags & FORE_COLOR_FLAG) - tname.ForeColor = nptr->ForeColor; - if(nptr->off_flags & BACK_COLOR_FLAG) - tname.BackColor = nptr->BackColor; - tname.IconBoxes = nptr->IconBoxes; /* use same chain */ - } /* end hit/not hit */ - } /* end found matching style */ - } /* end looking at all styles */ - restofline = tmp; /* move forward one word */ - if (!hit) { - tmp=safemalloc(500); - strlcat(tmp,"UseStyle: ", 500); - strlcat(tmp,restofline-len,500); - strlcat(tmp," style not found!",500); - fvwm_msg(ERR,"ProcessNewStyle",tmp); - free(tmp); - } - } - while(isspace(*restofline)) restofline++; - } - break; - case 'v': - break; - case 'w': - if(ITIS("WindowListSkip")) - { - SKIP("WindowListSkip"); - tname.off_flags |= LISTSKIP_FLAG; - } - else if(ITIS("WindowListHit")) - { - SKIP("WindowListHit"); - tname.on_flags |= LISTSKIP_FLAG; - } - break; - case 'x': - break; - case 'y': - break; - case 'z': - break; - default: - break; - } + if (nptr->off_flags & + STARTSONDESK_FLAG) + /* RBW - + 11/02/1998 */ + { + tname + .Desk = + nptr->Desk; + tname + .PageX = + nptr->PageX; + tname + .PageY = + nptr->PageY; + } + /**/ + if (nptr->off_flags & + BW_FLAG) + tname + .border_width = + nptr->border_width; + if (nptr->off_flags & + NOBW_FLAG) + tname + .resize_width = + nptr->resize_width; + if (nptr->off_flags & + FORE_COLOR_FLAG) + tname + .ForeColor = + nptr->ForeColor; + if (nptr->off_flags & + BACK_COLOR_FLAG) + tname + .BackColor = + nptr->BackColor; + tname + .IconBoxes = + nptr->IconBoxes; /* use same chain */ + } /* end hit/not hit */ + } /* end found matching style */ + } /* end looking at all styles */ + restofline = + tmp; /* move forward one word */ + if (!hit) { + tmp = xmalloc(500); + tmp[0] = '\0'; + strlcat(tmp, "UseStyle: ", 500); + strlcat( + tmp, restofline - len, 500); + strlcat(tmp, + " style not found!", 500); + fvwm_msg(ERR, "ProcessNewStyle", + tmp); + free(tmp); + } + } + while (isspace(*restofline)) + restofline++; + } + break; + case 'v': + break; + case 'w': + if (ITIS("WindowListSkip")) { + SKIP("WindowListSkip"); + tname.off_flags |= LISTSKIP_FLAG; + } else if (ITIS("WindowListHit")) { + SKIP("WindowListHit"); + tname.on_flags |= LISTSKIP_FLAG; + } + break; + case 'x': + break; + case 'y': + break; + case 'z': + break; + default: + break; + } - SKIPSPACE; - if(*restofline == ',') - restofline++; - else if((*restofline != 0)&&(*restofline != '\n')) - { - fvwm_msg(ERR,"ProcessNewStyle", - "bad style command: %s", restofline); - /* Can't return here since all malloced memory will be lost. Ignore rest - * of line instead. */ - break; - } - } /* end while still stuff on command */ + SKIPSPACE; + if (*restofline == ',') + restofline++; + else if ((*restofline != 0) && (*restofline != '\n')) { + fvwm_msg(ERR, "ProcessNewStyle", + "bad style command: %s", restofline); + /* Can't return here since all malloced memory will be + * lost. Ignore rest of line instead. */ + break; + } + } /* end while still stuff on command */ - /* capture default icons */ - if(strcmp(tname.name,"*") == 0) - { - if(tname.off_flags & ICON_FLAG) - Scr.DefaultIcon = tname.value; - tname.off_flags &= ~ICON_FLAG; - tname.value = NULL; - } - AddToList(&tname); /* add temp name list to list */ + /* capture default icons */ + if (strcmp(tname.name, "*") == 0) { + if (tname.off_flags & ICON_FLAG) + Scr.DefaultIcon = tname.value; + tname.off_flags &= ~ICON_FLAG; + tname.value = NULL; + } + AddToList(&tname); /* add temp name list to list */ } /* Check word after IconFill to see if its "Top,Bottom,Left,Right" */ -static int Get_TBLR(char *restofline,unsigned char *IconFill) { - *IconFill = 0; /* init */ - if (ITIS("B") || ITIS("BOT")|| ITIS("BOTTOM")) { - *IconFill |= ICONFILLBOT; /* turn on bottom bit */ - *IconFill |= ICONFILLHRZ; /* turn on vertical */ - } else if (ITIS("T") || ITIS("TOP")) { /* else if its "top" */ - *IconFill |= ICONFILLHRZ; /* turn on vertical */ - } else if (ITIS("R") || ITIS("RGT") || ITIS("RIGHT")) { - *IconFill |= ICONFILLRGT; /* turn on right bit */ - } else if (!(ITIS("L") || ITIS("LFT") || ITIS("LEFT"))) { /* "left" */ - return 0; /* anything else is bad */ - } - return 1; /* return OK */ +static int +Get_TBLR(char *restofline, unsigned char *IconFill) +{ + *IconFill = 0; /* init */ + if (ITIS("B") || ITIS("BOT") || ITIS("BOTTOM")) { + *IconFill |= ICONFILLBOT; /* turn on bottom bit */ + *IconFill |= ICONFILLHRZ; /* turn on vertical */ + } else if (ITIS("T") || ITIS("TOP")) { /* else if its "top" */ + *IconFill |= ICONFILLHRZ; /* turn on vertical */ + } else if (ITIS("R") || ITIS("RGT") || ITIS("RIGHT")) { + *IconFill |= ICONFILLRGT; /* turn on right bit */ + } else if (!(ITIS("L") || ITIS("LFT") || ITIS("LEFT"))) { /* "left" */ + return 0; /* anything else is bad */ + } + return 1; /* return OK */ } -static void AddToList(name_list *tname) +static void +AddToList(name_list *tname) { - name_list *nptr,*lastptr = NULL; + name_list *nptr, *lastptr = NULL; - /* This used to contain logic that returned if the style didn't contain - anything. I don't see why we should bother. dje. */ + /* This used to contain logic that returned if the style didn't contain + anything. I don't see why we should bother. dje. */ - /* used to merge duplicate entries, but that is no longer - * appropriate since conficting styles are possible, and the - * last match should win! */ + /* used to merge duplicate entries, but that is no longer + * appropriate since conficting styles are possible, and the + * last match should win! */ - /* seems like a pretty inefficient way to keep track of the end - of the list, but how long can the style list be? dje */ - for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { - lastptr=nptr; /* find end of style list */ - } + /* seems like a pretty inefficient way to keep track of the end + of the list, but how long can the style list be? dje */ + for (nptr = Scr.TheList; nptr != NULL; nptr = nptr->next) { + lastptr = nptr; /* find end of style list */ + } - nptr = (name_list *)safemalloc(sizeof(name_list)); /* malloc area */ - memcpy((void*)nptr, (const void*)tname, sizeof(name_list)); /* copy term area into list */ - if(lastptr != NULL) /* If not first entry in list */ - lastptr->next = nptr; /* chain this entry to the list */ - else /* else first entry in list */ - Scr.TheList = nptr; /* set the list root pointer. */ + nptr = (name_list *)xmalloc(sizeof(name_list)); /* malloc area */ + memcpy((void *)nptr, (const void *)tname, + sizeof(name_list)); /* copy term area into list */ + if (lastptr != NULL) /* If not first entry in list */ + lastptr->next = nptr; /* chain this entry to the list */ + else /* else first entry in list */ + Scr.TheList = nptr; /* set the list root pointer. */ } /* end function */ - Index: fvwm/fvwm/virtual.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/virtual.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/virtual.c --- fvwm/fvwm/virtual.c +++ fvwm/fvwm/virtual.c @@ -1,17 +1,16 @@ -#include "config.h" - -#include +#include #include +#include #include -#include #include +#include "config.h" #include "fvwm.h" #include "menus.h" #include "misc.h" +#include "module.h" #include "parse.h" #include "screen.h" -#include "module.h" /* * dje 12/19/98 @@ -35,24 +34,26 @@ int edge_thickness = 2; int last_edge_thickness = 2; -void setEdgeThickness(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +setEdgeThickness(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val, n; - - n = GetIntegerArguments(action, NULL, &val, 1); - if(n != 1) { - fvwm_msg(ERR,"setEdgeThickness", - "EdgeThickness requires 1 numeric argument, found %d args",n); - return; - } - if (val < 0 || val > 2) { /* check range */ - fvwm_msg(ERR,"setEdgeThickness", - "EdgeThickness arg must be between 0 and 2, found %d",val); - return; - } - edge_thickness = val; - checkPanFrames(); + int val, n; + + n = GetIntegerArguments(action, NULL, &val, 1); + if (n != 1) { + fvwm_msg(ERR, "setEdgeThickness", + "EdgeThickness requires 1 numeric argument, found %d args", + n); + return; + } + if (val < 0 || val > 2) { /* check range */ + fvwm_msg(ERR, "setEdgeThickness", + "EdgeThickness arg must be between 0 and 2, found %d", val); + return; + } + edge_thickness = val; + checkPanFrames(); } /*************************************************************************** @@ -60,175 +61,151 @@ void setEdgeThickness(XEvent *eventp,Window w,FvwmWindow *tmp_win, * Check to see if the pointer is on the edge of the screen, and scroll/page * if needed ***************************************************************************/ -void HandlePaging(int HorWarpSize, int VertWarpSize, int *xl, int *yt, - int *delta_x, int *delta_y,Bool Grab) +void +HandlePaging(int HorWarpSize, int VertWarpSize, int *xl, int *yt, int *delta_x, + int *delta_y, Bool Grab) { - int x,y,total; - - *delta_x = 0; - *delta_y = 0; - - if((Scr.ScrollResistance >= 10000)|| - ((HorWarpSize ==0)&&(VertWarpSize==0))) - return; - - /* need to move the viewport */ - if(( Scr.VxMax == 0 || - (*xl >= edge_thickness && - *xl < Scr.MyDisplayWidth - edge_thickness)) && - ( Scr.VyMax == 0 || - (*yt >= edge_thickness && - *yt < Scr.MyDisplayHeight - edge_thickness))) - return; - - total = 0; - while(total < Scr.ScrollResistance) - { - usleep(10000); - total+=10; - - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - - if(XCheckWindowEvent(dpy,Scr.PanFrameTop.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - if(XCheckWindowEvent(dpy,Scr.PanFrameBottom.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - if(XCheckWindowEvent(dpy,Scr.PanFrameLeft.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - if(XCheckWindowEvent(dpy,Scr.PanFrameRight.win, - LeaveWindowMask,&Event)) - { - StashEventTime(&Event); - return; - } - /* check actual pointer location since PanFrames can get buried under - a window being moved or resized - mab */ - if(( x >= edge_thickness )&& - ( x < Scr.MyDisplayWidth-edge_thickness )&& - ( y >= edge_thickness )&& - ( y < Scr.MyDisplayHeight-edge_thickness )) - return ; - } - - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - &x, &y, &JunkX, &JunkY, &JunkMask); - - /* Move the viewport */ - /* and/or move the cursor back to the approximate correct location */ - /* that is, the same place on the virtual desktop that it */ - /* started at */ - if( x= Scr.MyDisplayWidth-edge_thickness) - *delta_x = HorWarpSize; - else - *delta_x = 0; - if (Scr.VxMax == 0) *delta_x = 0; - if( y= Scr.MyDisplayHeight-edge_thickness) - *delta_y = VertWarpSize; - else - *delta_y = 0; - if (Scr.VyMax == 0) *delta_y = 0; - - /* Ouch! lots of bounds checking */ - if(Scr.Vx + *delta_x < 0) - { - if (!(Scr.flags & EdgeWrapX )) - { - *delta_x = -Scr.Vx; - *xl = x - *delta_x; - } - else - { - *delta_x += Scr.VxMax + Scr.MyDisplayWidth; - *xl = x + *delta_x % Scr.MyDisplayWidth + HorWarpSize; - } - } - else if(Scr.Vx + *delta_x > Scr.VxMax) - { - if (!(Scr.flags & EdgeWrapX)) - { - *delta_x = Scr.VxMax - Scr.Vx; - *xl = x - *delta_x; + int x, y, total; + + *delta_x = 0; + *delta_y = 0; + + if ((Scr.ScrollResistance >= 10000) || + ((HorWarpSize == 0) && (VertWarpSize == 0))) + return; + + /* need to move the viewport */ + if ((Scr.VxMax == 0 || + (*xl >= edge_thickness && + *xl < Scr.MyDisplayWidth - edge_thickness)) && + (Scr.VyMax == 0 || (*yt >= edge_thickness && + *yt < Scr.MyDisplayHeight - edge_thickness))) + return; + + total = 0; + while (total < Scr.ScrollResistance) { + usleep(10000); + total += 10; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, + &JunkX, &JunkY, &JunkMask); + + if (XCheckWindowEvent( + dpy, Scr.PanFrameTop.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + if (XCheckWindowEvent( + dpy, Scr.PanFrameBottom.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + if (XCheckWindowEvent( + dpy, Scr.PanFrameLeft.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + if (XCheckWindowEvent( + dpy, Scr.PanFrameRight.win, LeaveWindowMask, &Event)) { + StashEventTime(&Event); + return; + } + /* check actual pointer location since PanFrames can get buried + under a window being moved or resized - mab */ + if ((x >= edge_thickness) && + (x < Scr.MyDisplayWidth - edge_thickness) && + (y >= edge_thickness) && + (y < Scr.MyDisplayHeight - edge_thickness)) + return; } - else - { - *delta_x -= Scr.VxMax +Scr.MyDisplayWidth; - *xl = x + *delta_x % Scr.MyDisplayWidth - HorWarpSize; - } - } - else - *xl = x - *delta_x; - - if(Scr.Vy + *delta_y < 0) - { - if (!(Scr.flags & EdgeWrapY)) - { - *delta_y = -Scr.Vy; - *yt = y - *delta_y; - } - else - { - *delta_y += Scr.VyMax + Scr.MyDisplayHeight; - *yt = y + *delta_y % Scr.MyDisplayHeight + VertWarpSize; - } - } - else if(Scr.Vy + *delta_y > Scr.VyMax) - { - if (!(Scr.flags & EdgeWrapY)) - { - *delta_y = Scr.VyMax - Scr.Vy; - *yt = y - *delta_y; - } - else - { - *delta_y -= Scr.VyMax + Scr.MyDisplayHeight; - *yt = y + *delta_y % Scr.MyDisplayHeight - VertWarpSize; + + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, &x, &y, &JunkX, + &JunkY, &JunkMask); + + /* Move the viewport */ + /* and/or move the cursor back to the approximate correct location */ + /* that is, the same place on the virtual desktop that it */ + /* started at */ + if (x < edge_thickness) + *delta_x = -HorWarpSize; + else if (x >= Scr.MyDisplayWidth - edge_thickness) + *delta_x = HorWarpSize; + else + *delta_x = 0; + if (Scr.VxMax == 0) + *delta_x = 0; + if (y < edge_thickness) + *delta_y = -VertWarpSize; + else if (y >= Scr.MyDisplayHeight - edge_thickness) + *delta_y = VertWarpSize; + else + *delta_y = 0; + if (Scr.VyMax == 0) + *delta_y = 0; + + /* Ouch! lots of bounds checking */ + if (Scr.Vx + *delta_x < 0) { + if (!(Scr.flags & EdgeWrapX)) { + *delta_x = -Scr.Vx; + *xl = x - *delta_x; + } else { + *delta_x += Scr.VxMax + Scr.MyDisplayWidth; + *xl = x + *delta_x % Scr.MyDisplayWidth + HorWarpSize; + } + } else if (Scr.Vx + *delta_x > Scr.VxMax) { + if (!(Scr.flags & EdgeWrapX)) { + *delta_x = Scr.VxMax - Scr.Vx; + *xl = x - *delta_x; + } else { + *delta_x -= Scr.VxMax + Scr.MyDisplayWidth; + *xl = x + *delta_x % Scr.MyDisplayWidth - HorWarpSize; + } + } else + *xl = x - *delta_x; + + if (Scr.Vy + *delta_y < 0) { + if (!(Scr.flags & EdgeWrapY)) { + *delta_y = -Scr.Vy; + *yt = y - *delta_y; + } else { + *delta_y += Scr.VyMax + Scr.MyDisplayHeight; + *yt = y + *delta_y % Scr.MyDisplayHeight + VertWarpSize; + } + } else if (Scr.Vy + *delta_y > Scr.VyMax) { + if (!(Scr.flags & EdgeWrapY)) { + *delta_y = Scr.VyMax - Scr.Vy; + *yt = y - *delta_y; + } else { + *delta_y -= Scr.VyMax + Scr.MyDisplayHeight; + *yt = y + *delta_y % Scr.MyDisplayHeight - VertWarpSize; + } + } else + *yt = y - *delta_y; + + /* make sure the pointer isn't warped into the panframes */ + if (*xl < edge_thickness) + *xl = edge_thickness; + if (*yt < edge_thickness) + *yt = edge_thickness; + if (*xl >= Scr.MyDisplayWidth - edge_thickness) + *xl = Scr.MyDisplayWidth - edge_thickness - 1; + if (*yt >= Scr.MyDisplayHeight - edge_thickness) + *yt = Scr.MyDisplayHeight - edge_thickness - 1; + + if ((*delta_x != 0) || (*delta_y != 0)) { + if (Grab) + MyXGrabServer(dpy); + /* Turn off the rubberband if its on */ + MoveOutline(Scr.Root, 0, 0, 0, 0); + XWarpPointer(dpy, None, Scr.Root, 0, 0, 0, 0, *xl, *yt); + MoveViewport(Scr.Vx + *delta_x, Scr.Vy + *delta_y, False); + XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, xl, yt, + &JunkX, &JunkY, &JunkMask); + if (Grab) + MyXUngrabServer(dpy); } - } - else - *yt = y - *delta_y; - - /* make sure the pointer isn't warped into the panframes */ - if(*xl < edge_thickness) *xl = edge_thickness; - if(*yt < edge_thickness) *yt = edge_thickness; - if(*xl >= Scr.MyDisplayWidth - edge_thickness) - *xl = Scr.MyDisplayWidth - edge_thickness -1; - if(*yt >= Scr.MyDisplayHeight - edge_thickness) - *yt = Scr.MyDisplayHeight - edge_thickness -1; - - if((*delta_x != 0)||(*delta_y!=0)) - { - if(Grab) - MyXGrabServer(dpy); - /* Turn off the rubberband if its on */ - MoveOutline(Scr.Root,0,0,0,0); - XWarpPointer(dpy,None,Scr.Root,0,0,0,0,*xl,*yt); - MoveViewport(Scr.Vx + *delta_x,Scr.Vy + *delta_y,False); - XQueryPointer(dpy, Scr.Root, &JunkRoot, &JunkChild, - xl, yt, &JunkX, &JunkY, &JunkMask); - if(Grab) - MyXUngrabServer(dpy); - } } - - /* the root window is surrounded by four window slices, which are InputOnly. * So you can see 'through' them, but they eat the input. An EnterEvent in * one of these windows causes a Paging. The windows have the according cursor @@ -238,118 +215,110 @@ void HandlePaging(int HorWarpSize, int VertWarpSize, int *xl, int *yt, * eat all mouse events. * * Hermann Dunkel, HEDU, dunkel@cul-ipn.uni-kiel.de 1/94 -*/ + */ /*************************************************************************** * checkPanFrames hides PanFrames if they are on the very border of the * VIRTUAL screen and EdgeWrap for that direction is off. * (A special cursor for the EdgeWrap border could be nice) HEDU ****************************************************************************/ -void checkPanFrames(void) +void +checkPanFrames(void) { - Bool wrapX = (Scr.flags & EdgeWrapX) && Scr.VxMax; - Bool wrapY = (Scr.flags & EdgeWrapY) && Scr.VyMax; - - if(!(Scr.flags & WindowsCaptured)) - return; - - /* thickness of 0 means remove the pan frames */ - if (edge_thickness == 0) { - if (Scr.PanFrameTop.isMapped) { - XUnmapWindow(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=False; - } - if (Scr.PanFrameBottom.isMapped) { - XUnmapWindow (dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=False; - } - if (Scr.PanFrameLeft.isMapped) { - XUnmapWindow(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=False; - } - if (Scr.PanFrameRight.isMapped) { - XUnmapWindow (dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=False; - } - return; - } - - /* check they are the right size */ - if (edge_thickness != last_edge_thickness) { - XResizeWindow (dpy, Scr.PanFrameTop.win, Scr.MyDisplayWidth, edge_thickness); - XResizeWindow (dpy, Scr.PanFrameLeft.win, edge_thickness, Scr.MyDisplayHeight); - XMoveResizeWindow (dpy, Scr.PanFrameRight.win, - Scr.MyDisplayWidth - edge_thickness, 0, - edge_thickness, Scr.MyDisplayHeight); - XMoveResizeWindow (dpy, Scr.PanFrameBottom.win, - 0, Scr.MyDisplayHeight - edge_thickness, - Scr.MyDisplayWidth, edge_thickness); - last_edge_thickness = edge_thickness; - } - - /* Remove Pan frames if paging by edge-scroll is permanently or - * temporarily disabled */ - if(Scr.EdgeScrollY == 0) - { - XUnmapWindow(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=False; - XUnmapWindow (dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=False; - } - if(Scr.EdgeScrollX == 0) - { - XUnmapWindow(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=False; - XUnmapWindow (dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=False; - } - if((Scr.EdgeScrollX == 0)&&(Scr.EdgeScrollY == 0)) - return; - - /* LEFT, hide only if EdgeWrap is off */ - if (Scr.Vx==0 && Scr.PanFrameLeft.isMapped && (!wrapX)) - { - XUnmapWindow(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=False; - } - else if ((Scr.Vx > 0 || wrapX) && Scr.PanFrameLeft.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameLeft.win); - Scr.PanFrameLeft.isMapped=True; - } - /* RIGHT, hide only if EdgeWrap is off */ - if (Scr.Vx == Scr.VxMax && Scr.PanFrameRight.isMapped && (!wrapX)) - { - XUnmapWindow (dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=False; - } - else if ((Scr.Vx < Scr.VxMax || wrapX) && Scr.PanFrameRight.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameRight.win); - Scr.PanFrameRight.isMapped=True; - } - /* TOP, hide only if EdgeWrap is off */ - if (Scr.Vy==0 && Scr.PanFrameTop.isMapped && (!wrapY)) - { - XUnmapWindow(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=False; - } - else if ((Scr.Vy > 0 || wrapY) && Scr.PanFrameTop.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameTop.win); - Scr.PanFrameTop.isMapped=True; - } - /* BOTTOM, hide only if EdgeWrap is off */ - if (Scr.Vy == Scr.VyMax && Scr.PanFrameBottom.isMapped && (!wrapY)) - { - XUnmapWindow (dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=False; - } - else if ((Scr.Vy < Scr.VyMax || wrapY) && Scr.PanFrameBottom.isMapped==False) - { - XMapRaised(dpy,Scr.PanFrameBottom.win); - Scr.PanFrameBottom.isMapped=True; - } + Bool wrapX = (Scr.flags & EdgeWrapX) && Scr.VxMax; + Bool wrapY = (Scr.flags & EdgeWrapY) && Scr.VyMax; + + if (!(Scr.flags & WindowsCaptured)) + return; + + /* thickness of 0 means remove the pan frames */ + if (edge_thickness == 0) { + if (Scr.PanFrameTop.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = False; + } + if (Scr.PanFrameBottom.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = False; + } + if (Scr.PanFrameLeft.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = False; + } + if (Scr.PanFrameRight.isMapped) { + XUnmapWindow(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = False; + } + return; + } + + /* check they are the right size */ + if (edge_thickness != last_edge_thickness) { + XResizeWindow(dpy, Scr.PanFrameTop.win, Scr.MyDisplayWidth, + edge_thickness); + XResizeWindow(dpy, Scr.PanFrameLeft.win, edge_thickness, + Scr.MyDisplayHeight); + XMoveResizeWindow(dpy, Scr.PanFrameRight.win, + Scr.MyDisplayWidth - edge_thickness, 0, edge_thickness, + Scr.MyDisplayHeight); + XMoveResizeWindow(dpy, Scr.PanFrameBottom.win, 0, + Scr.MyDisplayHeight - edge_thickness, Scr.MyDisplayWidth, + edge_thickness); + last_edge_thickness = edge_thickness; + } + + /* Remove Pan frames if paging by edge-scroll is permanently or + * temporarily disabled */ + if (Scr.EdgeScrollY == 0) { + XUnmapWindow(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = False; + XUnmapWindow(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = False; + } + if (Scr.EdgeScrollX == 0) { + XUnmapWindow(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = False; + XUnmapWindow(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = False; + } + if ((Scr.EdgeScrollX == 0) && (Scr.EdgeScrollY == 0)) + return; + + /* LEFT, hide only if EdgeWrap is off */ + if (Scr.Vx == 0 && Scr.PanFrameLeft.isMapped && (!wrapX)) { + XUnmapWindow(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = False; + } else if ((Scr.Vx > 0 || wrapX) && + Scr.PanFrameLeft.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameLeft.win); + Scr.PanFrameLeft.isMapped = True; + } + /* RIGHT, hide only if EdgeWrap is off */ + if (Scr.Vx == Scr.VxMax && Scr.PanFrameRight.isMapped && (!wrapX)) { + XUnmapWindow(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = False; + } else if ((Scr.Vx < Scr.VxMax || wrapX) && + Scr.PanFrameRight.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameRight.win); + Scr.PanFrameRight.isMapped = True; + } + /* TOP, hide only if EdgeWrap is off */ + if (Scr.Vy == 0 && Scr.PanFrameTop.isMapped && (!wrapY)) { + XUnmapWindow(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = False; + } else if ((Scr.Vy > 0 || wrapY) && Scr.PanFrameTop.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameTop.win); + Scr.PanFrameTop.isMapped = True; + } + /* BOTTOM, hide only if EdgeWrap is off */ + if (Scr.Vy == Scr.VyMax && Scr.PanFrameBottom.isMapped && (!wrapY)) { + XUnmapWindow(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = False; + } else if ((Scr.Vy < Scr.VyMax || wrapY) && + Scr.PanFrameBottom.isMapped == False) { + XMapRaised(dpy, Scr.PanFrameBottom.win); + Scr.PanFrameBottom.isMapped = True; + } } /**************************************************************************** @@ -360,12 +329,17 @@ void checkPanFrames(void) * For some reason, this seems to be unneeded. * ***************************************************************************/ -void raisePanFrames(void) +void +raisePanFrames(void) { - if (Scr.PanFrameTop.isMapped) XRaiseWindow(dpy,Scr.PanFrameTop.win); - if (Scr.PanFrameLeft.isMapped) XRaiseWindow(dpy,Scr.PanFrameLeft.win); - if (Scr.PanFrameRight.isMapped) XRaiseWindow(dpy,Scr.PanFrameRight.win); - if (Scr.PanFrameBottom.isMapped) XRaiseWindow(dpy,Scr.PanFrameBottom.win); + if (Scr.PanFrameTop.isMapped) + XRaiseWindow(dpy, Scr.PanFrameTop.win); + if (Scr.PanFrameLeft.isMapped) + XRaiseWindow(dpy, Scr.PanFrameLeft.win); + if (Scr.PanFrameRight.isMapped) + XRaiseWindow(dpy, Scr.PanFrameRight.win); + if (Scr.PanFrameBottom.isMapped) + XRaiseWindow(dpy, Scr.PanFrameBottom.win); } /**************************************************************************** @@ -373,239 +347,254 @@ void raisePanFrames(void) * Creates the windows for edge-scrolling * ****************************************************************************/ -void initPanFrames() +void +initPanFrames() { - XSetWindowAttributes attributes; /* attributes for create */ - unsigned long valuemask; - int saved_thickness; - - /* Not creating the frames disables all subsequent behavior */ - /* TKP. This is bad, it will cause an XMap request on a null window later*/ - /* if (edge_thickness == 0) return; */ - saved_thickness = edge_thickness; - if (edge_thickness == 0) edge_thickness = 2; - - attributes.event_mask = (EnterWindowMask | LeaveWindowMask | - VisibilityChangeMask); - valuemask= (CWEventMask | CWCursor ); - - attributes.cursor = Scr.FvwmCursors[TOP]; - /* I know these overlap, it's useful when at (0,0) and the top one is unmapped */ - Scr.PanFrameTop.win = - XCreateWindow (dpy, Scr.Root, - 0, 0, - Scr.MyDisplayWidth, edge_thickness, - 0, /* no border */ - CopyFromParent, InputOnly, - CopyFromParent, - valuemask, &attributes); - attributes.cursor = Scr.FvwmCursors[LEFT]; - Scr.PanFrameLeft.win = - XCreateWindow (dpy, Scr.Root, - 0, 0, - edge_thickness, Scr.MyDisplayHeight, - 0, /* no border */ - CopyFromParent, InputOnly, CopyFromParent, - valuemask, &attributes); - attributes.cursor = Scr.FvwmCursors[RIGHT]; - Scr.PanFrameRight.win = - XCreateWindow (dpy, Scr.Root, - Scr.MyDisplayWidth - edge_thickness, 0, - edge_thickness, Scr.MyDisplayHeight, - 0, /* no border */ - CopyFromParent, InputOnly, CopyFromParent, - valuemask, &attributes); - attributes.cursor = Scr.FvwmCursors[BOTTOM]; - Scr.PanFrameBottom.win = - XCreateWindow (dpy, Scr.Root, - 0, Scr.MyDisplayHeight - edge_thickness, - Scr.MyDisplayWidth, edge_thickness, - 0, /* no border */ - CopyFromParent, InputOnly, CopyFromParent, - valuemask, &attributes); - Scr.PanFrameTop.isMapped=Scr.PanFrameLeft.isMapped= - Scr.PanFrameRight.isMapped= Scr.PanFrameBottom.isMapped=False; - - edge_thickness = saved_thickness; + XSetWindowAttributes attributes; /* attributes for create */ + unsigned long valuemask; + int saved_thickness; + + /* Not creating the frames disables all subsequent behavior */ + /* TKP. This is bad, it will cause an XMap request on a null window + * later*/ + /* if (edge_thickness == 0) return; */ + saved_thickness = edge_thickness; + if (edge_thickness == 0) + edge_thickness = 2; + + attributes.event_mask = + (EnterWindowMask | LeaveWindowMask | VisibilityChangeMask); + valuemask = (CWEventMask | CWCursor); + + attributes.cursor = Scr.FvwmCursors[TOP]; + /* I know these overlap, it's useful when at (0,0) and the top one is + * unmapped */ + Scr.PanFrameTop.win = XCreateWindow(dpy, Scr.Root, 0, 0, + Scr.MyDisplayWidth, edge_thickness, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[LEFT]; + Scr.PanFrameLeft.win = XCreateWindow(dpy, Scr.Root, 0, 0, + edge_thickness, Scr.MyDisplayHeight, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[RIGHT]; + Scr.PanFrameRight.win = XCreateWindow(dpy, Scr.Root, + Scr.MyDisplayWidth - edge_thickness, 0, edge_thickness, + Scr.MyDisplayHeight, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + attributes.cursor = Scr.FvwmCursors[BOTTOM]; + Scr.PanFrameBottom.win = XCreateWindow(dpy, Scr.Root, 0, + Scr.MyDisplayHeight - edge_thickness, Scr.MyDisplayWidth, + edge_thickness, 0, /* no border */ + CopyFromParent, InputOnly, CopyFromParent, valuemask, &attributes); + Scr.PanFrameTop.isMapped = Scr.PanFrameLeft.isMapped = + Scr.PanFrameRight.isMapped = Scr.PanFrameBottom.isMapped = False; + + edge_thickness = saved_thickness; } - /*************************************************************************** * * Moves the viewport within the virtual desktop * ***************************************************************************/ -void MoveViewport(int newx, int newy, Bool grab) +void +MoveViewport(int newx, int newy, Bool grab) { - FvwmWindow *t, *t1; - int deltax,deltay; - int PageTop, PageLeft; - int PageBottom, PageRight; - int txl, txr, tyt, tyb; - - if(grab) - MyXGrabServer(dpy); - - - if(newx > Scr.VxMax) - newx = Scr.VxMax; - if(newy > Scr.VyMax) - newy = Scr.VyMax; - if(newx <0) - newx = 0; - if(newy <0) - newy = 0; - - deltay = Scr.Vy - newy; - deltax = Scr.Vx - newx; - /* - Identify the bounding rectangle that will be moved into - the viewport. - */ - PageBottom = Scr.MyDisplayHeight - deltay; - PageRight = Scr.MyDisplayWidth - deltax; - PageTop = 0 - deltay; - PageLeft = 0 - deltax; - - Scr.Vx = newx; - Scr.Vy = newy; - BroadcastPacket(M_NEW_PAGE, 5, - Scr.Vx, Scr.Vy, Scr.CurrentDesk, Scr.VxMax, Scr.VyMax); - - if((deltax!=0)||(deltay!=0)) - { - -/* - RBW - 11/13/1998 - new: chase the chain bidirectionally, all at once! - The idea is to move the windows that are moving out of the viewport from - the bottom of the stacking order up, to minimize the expose-redraw overhead. - Windows that will be moving into view will be moved top down, for the same - reason. Use the new stacking-order chain, rather than the old - last-focussed chain. -*/ - - t = Scr.FvwmRoot.stack_next; - t1 = Scr.FvwmRoot.stack_prev; - while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) - { - if (t != &Scr.FvwmRoot) - { - /* - If the window is moving into the viewport... + FvwmWindow *t, *t1; + int deltax, deltay; + int PageTop, PageLeft; + int PageBottom, PageRight; + int txl, txr, tyt, tyb; + + if (grab) + MyXGrabServer(dpy); + + if (newx > Scr.VxMax) + newx = Scr.VxMax; + if (newy > Scr.VyMax) + newy = Scr.VyMax; + if (newx < 0) + newx = 0; + if (newy < 0) + newy = 0; + + deltay = Scr.Vy - newy; + deltax = Scr.Vx - newx; + /* + Identify the bounding rectangle that will be moved into + the viewport. + */ + PageBottom = Scr.MyDisplayHeight - deltay; + PageRight = Scr.MyDisplayWidth - deltax; + PageTop = 0 - deltay; + PageLeft = 0 - deltax; + + Scr.Vx = newx; + Scr.Vy = newy; + BroadcastPacket(M_NEW_PAGE, 5, Scr.Vx, Scr.Vy, Scr.CurrentDesk, + Scr.VxMax, Scr.VyMax); + + if ((deltax != 0) || (deltay != 0)) { + /* + RBW - 11/13/1998 - new: chase the chain bidirectionally, all + at once! The idea is to move the windows that are moving out of + the viewport from the bottom of the stacking order up, to + minimize the expose-redraw overhead. Windows that will be moving + into view will be moved top down, for the same reason. Use the + new stacking-order chain, rather than the old last-focussed + chain. */ - txl = t->frame_x; - tyt = t->frame_y; - txr = t->frame_x + t->frame_width; - tyb = t->frame_y + t->frame_height; - if ((txr >= PageLeft && txl <= PageRight - && tyb >= PageTop && tyt <= PageBottom) - && ! t->tmpflags.ViewportMoved) - { - t->tmpflags.ViewportMoved = True; /* Block double move. */ - /* If the window is iconified, and sticky Icons is set, - * then the window should essentially be sticky */ - if(!((t->flags & ICONIFIED)&&(t->flags & StickyIcon)) && - (!(t->flags & STICKY))) - { - if(!(t->flags & StickyIcon)) - { - t->icon_x_loc += deltax; - t->icon_xl_loc += deltax; - t->icon_y_loc += deltay; - if(t->icon_pixmap_w != None) - XMoveWindow(dpy,t->icon_pixmap_w,t->icon_x_loc, - t->icon_y_loc); - if(t->icon_w != None) - XMoveWindow(dpy,t->icon_w,t->icon_x_loc, - t->icon_y_loc+t->icon_p_height); - if(!(t->flags &ICON_UNMAPPED)) - { - BroadcastPacket(M_ICON_LOCATION, 7, - t->w, t->frame, - (unsigned long)t, - t->icon_x_loc, t->icon_y_loc, - t->icon_w_width, - t->icon_w_height+t->icon_p_height); - } - } - SetupFrame (t, t->frame_x+ deltax, t->frame_y + deltay, - t->frame_width, t->frame_height,FALSE); - } - } - /* Bump to next win... */ - t = t->stack_next; - } - if (t1 != &Scr.FvwmRoot) - { - /* - If the window is not moving into the viewport... - */ - txl = t1->frame_x; - tyt = t1->frame_y; - txr = t1->frame_x + t1->frame_width; - tyb = t1->frame_y + t1->frame_height; - if (! (txr >= PageLeft && txl <= PageRight - && tyb >= PageTop && tyt <= PageBottom) - && ! t1->tmpflags.ViewportMoved) - { - t1->tmpflags.ViewportMoved = True; /* Block double move.*/ - /* If the window is iconified, and sticky Icons is set, - * then the window should essentially be sticky */ - if(!((t1->flags & ICONIFIED)&&(t1->flags & StickyIcon)) && - (!(t1->flags & STICKY))) - { - if(!(t1->flags & StickyIcon)) - { - t1->icon_x_loc += deltax; - t1->icon_xl_loc += deltax; - t1->icon_y_loc += deltay; - if(t1->icon_pixmap_w != None) - XMoveWindow(dpy,t1->icon_pixmap_w, - t1->icon_x_loc, - t1->icon_y_loc); - if(t1->icon_w != None) - XMoveWindow(dpy,t1->icon_w,t1->icon_x_loc, - t1->icon_y_loc+t1->icon_p_height); - if(!(t1->flags &ICON_UNMAPPED)) - { - BroadcastPacket(M_ICON_LOCATION, 7, - t1->w, t1->frame, - (unsigned long)t1, - t1->icon_x_loc, t1->icon_y_loc, - t1->icon_w_width, - t1->icon_w_height + - t1->icon_p_height); - } - } - SetupFrame (t1, t1->frame_x+ deltax, - t1->frame_y + deltay, - t1->frame_width, t1->frame_height,FALSE); - } - } - /* Bump to next win... */ - t1 = t1->stack_prev; - } - } - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - t->tmpflags.ViewportMoved = False; /* Clear double move blocker. */ - /* If its an icon, and its sticking, autoplace it so - * that it doesn't wind up on top a a stationary - * icon */ - if(((t->flags & STICKY)||(t->flags & StickyIcon))&& - (t->flags & ICONIFIED)&&(!(t->flags & ICON_MOVED))&& - (!(t->flags & ICON_UNMAPPED))) - AutoPlace(t); - } - } - checkPanFrames(); + t = Scr.FvwmRoot.stack_next; + t1 = Scr.FvwmRoot.stack_prev; + while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) { + if (t != &Scr.FvwmRoot) { + /* + If the window is moving into the + viewport... + */ + txl = t->frame_x; + tyt = t->frame_y; + txr = t->frame_x + t->frame_width; + tyb = t->frame_y + t->frame_height; + if ((txr >= PageLeft && txl <= PageRight && + tyb >= PageTop && tyt <= PageBottom) && + !t->tmpflags.ViewportMoved) { + t->tmpflags.ViewportMoved = + True; /* Block double move. */ + /* If the window is iconified, and + * sticky Icons is set, then the window + * should essentially be sticky */ + if (!((t->flags & ICONIFIED) && + (t->flags & StickyIcon)) && + (!(t->flags & STICKY))) { + if (!(t->flags & StickyIcon)) { + t->icon_x_loc += deltax; + t->icon_xl_loc += + deltax; + t->icon_y_loc += deltay; + if (t->icon_pixmap_w != + None) + XMoveWindow(dpy, + t->icon_pixmap_w, + t->icon_x_loc, + t->icon_y_loc); + if (t->icon_w != None) + XMoveWindow(dpy, + t->icon_w, + t->icon_x_loc, + t->icon_y_loc + + t->icon_p_height); + if (!(t->flags & + ICON_UNMAPPED)) { + BroadcastPacket( + M_ICON_LOCATION, + 7, t->w, + t->frame, + (unsigned long) + t, + t->icon_x_loc, + t->icon_y_loc, + t->icon_w_width, + t->icon_w_height + + t->icon_p_height); + } + } + SetupFrame(t, + t->frame_x + deltax, + t->frame_y + deltay, + t->frame_width, + t->frame_height, FALSE); + } + } + /* Bump to next win... */ + t = t->stack_next; + } + if (t1 != &Scr.FvwmRoot) { + /* + If the window is not moving into the + viewport... + */ + txl = t1->frame_x; + tyt = t1->frame_y; + txr = t1->frame_x + t1->frame_width; + tyb = t1->frame_y + t1->frame_height; + if (!(txr >= PageLeft && txl <= PageRight && + tyb >= PageTop && tyt <= PageBottom) && + !t1->tmpflags.ViewportMoved) { + t1->tmpflags.ViewportMoved = + True; /* Block double move.*/ + /* If the window is iconified, and + * sticky Icons is set, then the window + * should essentially be sticky */ + if (!((t1->flags & ICONIFIED) && + (t1->flags & StickyIcon)) && + (!(t1->flags & STICKY))) { + if (!(t1->flags & StickyIcon)) { + t1->icon_x_loc += + deltax; + t1->icon_xl_loc += + deltax; + t1->icon_y_loc += + deltay; + if (t1->icon_pixmap_w != + None) + XMoveWindow(dpy, + t1->icon_pixmap_w, + t1->icon_x_loc, + t1->icon_y_loc); + if (t1->icon_w != None) + XMoveWindow(dpy, + t1->icon_w, + t1->icon_x_loc, + t1->icon_y_loc + + t1->icon_p_height); + if (!(t1->flags & + ICON_UNMAPPED)) { + BroadcastPacket( + M_ICON_LOCATION, + 7, t1->w, + t1->frame, + (unsigned long) + t1, + t1->icon_x_loc, + t1->icon_y_loc, + t1->icon_w_width, + t1->icon_w_height + + t1->icon_p_height); + } + } + SetupFrame(t1, + t1->frame_x + deltax, + t1->frame_y + deltay, + t1->frame_width, + t1->frame_height, FALSE); + } + } + /* Bump to next win... */ + t1 = t1->stack_prev; + } + } + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + t->tmpflags.ViewportMoved = + False; /* Clear double move blocker. */ + /* If its an icon, and its sticking, autoplace it so + * that it doesn't wind up on top a a stationary + * icon */ + if (((t->flags & STICKY) || (t->flags & StickyIcon)) && + (t->flags & ICONIFIED) && + (!(t->flags & ICON_MOVED)) && + (!(t->flags & ICON_UNMAPPED))) + AutoPlace(t); + } + } + checkPanFrames(); - /* do this with PanFrames too ??? HEDU */ - while(XCheckTypedEvent(dpy,MotionNotify,&Event)) - StashEventTime(&Event); - if(grab) - MyXUngrabServer(dpy); + /* do this with PanFrames too ??? HEDU */ + while (XCheckTypedEvent(dpy, MotionNotify, &Event)) + StashEventTime(&Event); + if (grab) + MyXUngrabServer(dpy); } /************************************************************************** @@ -626,77 +615,65 @@ void MoveViewport(int newx, int newy, Bool grab) * read (or if action is empty). * **************************************************************************/ -int GetDeskNumber(char *action) +int +GetDeskNumber(char *action) { - int n; - int m; - int desk; - int val[4]; - int min, max; - - n = GetIntegerArguments(action, NULL, &(val[0]), 4); - if (n <= 0) - return Scr.CurrentDesk; - if (n == 1) - return Scr.CurrentDesk + val[0]; - - desk = Scr.CurrentDesk; - m = 0; - - if (val[0] == 0) - { - /* absolute desk number */ - desk = val[1]; - } - else - { - /* relative desk number */ - desk += val[0]; - } - - if (n == 3) - { - m = 1; - } - if (n == 4) - { - m = 2; - } - - - if (n > 2) - { - /* handle limits */ - if (val[m] <= val[m+1]) - { - min = val[m]; - max = val[m+1]; + int n; + int m; + int desk; + int val[4]; + int min, max; + + n = GetIntegerArguments(action, NULL, &(val[0]), 4); + if (n <= 0) + return Scr.CurrentDesk; + if (n == 1) + return Scr.CurrentDesk + val[0]; + + desk = Scr.CurrentDesk; + m = 0; + + if (val[0] == 0) { + /* absolute desk number */ + desk = val[1]; + } else { + /* relative desk number */ + desk += val[0]; } - else - { - /* min > max is nonsense, so swap 'em. */ - min = val[m+1]; - max = val[m]; + + if (n == 3) { + m = 1; } - if (desk < min) - { - /* Relative move outside of range, wrap around. */ - if (val[0] < 0) - desk = max; - else - desk = min; + if (n == 4) { + m = 2; } - else if (desk > max) - { - /* Relative move outside of range, wrap around. */ - if (val[0] > 0) - desk = min; - else - desk = max; + + if (n > 2) { + /* handle limits */ + if (val[m] <= val[m + 1]) { + min = val[m]; + max = val[m + 1]; + } else { + /* min > max is nonsense, so swap 'em. */ + min = val[m + 1]; + max = val[m]; + } + if (desk < min) { + /* Relative move outside of range, wrap around. */ + if (val[0] < 0) + desk = max; + else + desk = min; + } else if (desk > max) { + /* Relative move outside of range, wrap around. */ + if (val[0] > 0) + desk = min; + else + desk = max; + } } - } - return desk; + return desk; } /************************************************************************** @@ -704,228 +681,210 @@ int GetDeskNumber(char *action) * Move to a new desktop * *************************************************************************/ -void changeDesks_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +changeDesks_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - changeDesks(GetDeskNumber(action)); + changeDesks(GetDeskNumber(action)); } -void changeDesks(int desk) +void +changeDesks(int desk) { - int oldDesk; - FvwmWindow *FocusWin = 0, *t, *t1; - static FvwmWindow *StickyWin = 0; - - oldDesk = Scr.CurrentDesk; - Scr.CurrentDesk = desk; - if(Scr.CurrentDesk == oldDesk) - return; - BroadcastPacket(M_NEW_DESK, 1, Scr.CurrentDesk); - /* Scan the window list, mapping windows on the new Desk, - * unmapping windows on the old Desk */ - MyXGrabServer(dpy); + int oldDesk; + FvwmWindow *FocusWin = 0, *t, *t1; + static FvwmWindow *StickyWin = 0; + + oldDesk = Scr.CurrentDesk; + Scr.CurrentDesk = desk; + if (Scr.CurrentDesk == oldDesk) + return; + BroadcastPacket(M_NEW_DESK, 1, Scr.CurrentDesk); + /* Scan the window list, mapping windows on the new Desk, + * unmapping windows on the old Desk */ + MyXGrabServer(dpy); -/* - RBW - 11/13/1998 - new: chase the chain bidirectionally, unmapping - windows bottom-up and mapping them top-down, to minimize expose-redraw - overhead. Use the new stacking-order chain, rather than the old - last-focussed chain. -*/ - t = Scr.FvwmRoot.stack_next; - t1 = Scr.FvwmRoot.stack_prev; - while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) - { - if (t != &Scr.FvwmRoot) - { - if(!((t->flags & ICONIFIED)&&(t->flags & StickyIcon)) && - (!(t->flags & STICKY))&&(!(t->flags & ICON_UNMAPPED))) - { - if(t->Desk == Scr.CurrentDesk) - { - MapIt(t); - if (t->FocusDesk == Scr.CurrentDesk) - { - FocusWin = t; - } - } - } - else - /* - Only need to do these in one of the passes... - */ - { - /* Window is sticky */ - t->Desk = Scr.CurrentDesk; - if (Scr.Focus == t) - { - t->FocusDesk =oldDesk; - StickyWin = t; - } - } - t = t->stack_next; - } - if (t1 != &Scr.FvwmRoot) - { - /* Only change mapping for non-sticky windows */ - if(!((t1->flags & ICONIFIED)&&(t1->flags & StickyIcon)) && - (!(t1->flags & STICKY))&&(!(t1->flags & ICON_UNMAPPED))) - { - if(t1->Desk == oldDesk) - { - if (Scr.Focus == t1) - t1->FocusDesk = oldDesk; - else - t1->FocusDesk = -1; - UnmapIt(t1); - } - } - t1 = t1->stack_prev; - } - } - - - MyXUngrabServer(dpy); - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - /* If its an icon, and its sticking, autoplace it so - * that it doesn't wind up on top a a stationary - * icon */ - if(((t->flags & STICKY)||(t->flags & StickyIcon))&& - (t->flags & ICONIFIED)&&(!(t->flags & ICON_MOVED))&& - (!(t->flags & ICON_UNMAPPED))) - AutoPlace(t); - } - - if((FocusWin)&&(FocusWin->flags & ClickToFocus)) + /* + RBW - 11/13/1998 - new: chase the chain bidirectionally, unmapping + windows bottom-up and mapping them top-down, to minimize expose-redraw + overhead. Use the new stacking-order chain, rather than the old + last-focussed chain. + */ + t = Scr.FvwmRoot.stack_next; + t1 = Scr.FvwmRoot.stack_prev; + while (t != &Scr.FvwmRoot || t1 != &Scr.FvwmRoot) { + if (t != &Scr.FvwmRoot) { + if (!((t->flags & ICONIFIED) && + (t->flags & StickyIcon)) && + (!(t->flags & STICKY)) && + (!(t->flags & ICON_UNMAPPED))) { + if (t->Desk == Scr.CurrentDesk) { + MapIt(t); + if (t->FocusDesk == Scr.CurrentDesk) { + FocusWin = t; + } + } + } else + /* + Only need to do these in one of the + passes... + */ + { + /* Window is sticky */ + t->Desk = Scr.CurrentDesk; + if (Scr.Focus == t) { + t->FocusDesk = oldDesk; + StickyWin = t; + } + } + t = t->stack_next; + } + if (t1 != &Scr.FvwmRoot) { + /* Only change mapping for non-sticky windows */ + if (!((t1->flags & ICONIFIED) && + (t1->flags & StickyIcon)) && + (!(t1->flags & STICKY)) && + (!(t1->flags & ICON_UNMAPPED))) { + if (t1->Desk == oldDesk) { + if (Scr.Focus == t1) + t1->FocusDesk = oldDesk; + else + t1->FocusDesk = -1; + UnmapIt(t1); + } + } + t1 = t1->stack_prev; + } + } + + MyXUngrabServer(dpy); + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + /* If its an icon, and its sticking, autoplace it so + * that it doesn't wind up on top a a stationary + * icon */ + if (((t->flags & STICKY) || (t->flags & StickyIcon)) && + (t->flags & ICONIFIED) && (!(t->flags & ICON_MOVED)) && + (!(t->flags & ICON_UNMAPPED))) + AutoPlace(t); + } + + if ((FocusWin) && (FocusWin->flags & ClickToFocus)) #ifndef NO_REMEMBER_FOCUS - SetFocus(FocusWin->w, FocusWin,0); - /* OK, someone beat me up, but I don't like this. If you are a predominantly - * focus-follows-mouse person, but put in one sticky click-to-focus window - * (typically because you don't really want to give focus to this window), - * then the following lines are screwed up. */ -/* else if (StickyWin && (StickyWin->flags & STICKY)) - SetFocus(StickyWin->w, StickyWin,1);*/ - else + SetFocus(FocusWin->w, FocusWin, 0); + /* OK, someone beat me up, but I don't like this. If you are a + * predominantly focus-follows-mouse person, but put in one sticky + * click-to-focus window (typically because you don't really want to + * give focus to this window), then the following lines are screwed up. + */ + /* else if (StickyWin && (StickyWin->flags & STICKY)) + SetFocus(StickyWin->w, StickyWin,1);*/ + else #endif - SetFocus(Scr.NoFocusWin,NULL,1); + SetFocus(Scr.NoFocusWin, NULL, 1); } - - /************************************************************************** * * Move a window to a new desktop * *************************************************************************/ -void changeWindowsDesk(XEvent *eventp,Window w,FvwmWindow *t, - unsigned long context,char *action, int *Module) +void +changeWindowsDesk(XEvent *eventp, Window w, FvwmWindow *t, + unsigned long context, char *action, int *Module) { - int desk; - - if (DeferExecution(eventp,&w,&t,&context,SELECT,ButtonRelease)) - return; - - if(t == NULL) - return; - - desk = GetDeskNumber(action); - if(desk == t->Desk) - return; - - /* - Set the window's desktop, and map or unmap it as needed. - */ - /* Only change mapping for non-sticky windows */ - if(!((t->flags & ICONIFIED)&&(t->flags & StickyIcon)) && - (!(t->flags & STICKY))&&(!(t->flags & ICON_UNMAPPED))) - { - if(t->Desk == Scr.CurrentDesk) - { - t->Desk = desk; - UnmapIt(t); + int desk; + + if (DeferExecution(eventp, &w, &t, &context, SELECT, ButtonRelease)) + return; + + if (t == NULL) + return; + + desk = GetDeskNumber(action); + if (desk == t->Desk) + return; + + /* + Set the window's desktop, and map or unmap it as needed. + */ + /* Only change mapping for non-sticky windows */ + if (!((t->flags & ICONIFIED) && (t->flags & StickyIcon)) && + (!(t->flags & STICKY)) && (!(t->flags & ICON_UNMAPPED))) { + if (t->Desk == Scr.CurrentDesk) { + t->Desk = desk; + UnmapIt(t); + } else if (desk == Scr.CurrentDesk) { + t->Desk = desk; + /* If its an icon, auto-place it */ + if (t->flags & ICONIFIED) + AutoPlace(t); + MapIt(t); + } else + t->Desk = desk; } - else if(desk == Scr.CurrentDesk) - { - t->Desk = desk; - /* If its an icon, auto-place it */ - if(t->flags & ICONIFIED) - AutoPlace(t); - MapIt(t); - } - else - t->Desk = desk; - - } - BroadcastConfig(M_CONFIGURE_WINDOW,t); + BroadcastConfig(M_CONFIGURE_WINDOW, t); } - -void scroll(XEvent *eventp,Window w,FvwmWindow *tmp_win,unsigned long context, - char *action, int *Module) +void +scroll(XEvent *eventp, Window w, FvwmWindow *tmp_win, unsigned long context, + char *action, int *Module) { - int x,y; - int val1, val2, val1_unit,val2_unit,n; - - n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); - - if((val1 > -100000)&&(val1 < 100000)) - x=Scr.Vx + val1*val1_unit/100; - else - x = Scr.Vx + (val1/1000)*val1_unit/100; - - if((val2 > -100000)&&(val2 < 100000)) - y=Scr.Vy + val2*val2_unit/100; - else - y = Scr.Vy + (val2/1000)*val2_unit/100; - - if(((val1 <= -100000)||(val1 >= 100000))&&(x>Scr.VxMax)) - { - x = 0; - y += Scr.MyDisplayHeight; - if(y > Scr.VyMax) - y=0; - } - if(((val1 <= -100000)||(val1 >= 100000))&&(x<0)) - { - x = Scr.VxMax; - y -= Scr.MyDisplayHeight; - if(y < 0) - y=Scr.VyMax; - } - if(((val2 <= -100000)||(val2>= 100000))&&(y>Scr.VyMax)) - { - y = 0; - x += Scr.MyDisplayWidth; - if(x > Scr.VxMax) - x=0; - } - if(((val2 <= -100000)||(val2>= 100000))&&(y<0)) - { - y = Scr.VyMax; - x -= Scr.MyDisplayWidth; - if(x < 0) - x=Scr.VxMax; - } - MoveViewport(x,y,True); + int x, y; + int val1, val2, val1_unit, val2_unit, n; + + n = GetTwoArguments(action, &val1, &val2, &val1_unit, &val2_unit); + + if ((val1 > -100000) && (val1 < 100000)) + x = Scr.Vx + val1 * val1_unit / 100; + else + x = Scr.Vx + (val1 / 1000) * val1_unit / 100; + + if ((val2 > -100000) && (val2 < 100000)) + y = Scr.Vy + val2 * val2_unit / 100; + else + y = Scr.Vy + (val2 / 1000) * val2_unit / 100; + + if (((val1 <= -100000) || (val1 >= 100000)) && (x > Scr.VxMax)) { + x = 0; + y += Scr.MyDisplayHeight; + if (y > Scr.VyMax) + y = 0; + } + if (((val1 <= -100000) || (val1 >= 100000)) && (x < 0)) { + x = Scr.VxMax; + y -= Scr.MyDisplayHeight; + if (y < 0) + y = Scr.VyMax; + } + if (((val2 <= -100000) || (val2 >= 100000)) && (y > Scr.VyMax)) { + y = 0; + x += Scr.MyDisplayWidth; + if (x > Scr.VxMax) + x = 0; + } + if (((val2 <= -100000) || (val2 >= 100000)) && (y < 0)) { + y = Scr.VyMax; + x -= Scr.MyDisplayWidth; + if (x < 0) + x = Scr.VxMax; + } + MoveViewport(x, y, True); } -void goto_page_func(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context,char *action, int *Module) +void +goto_page_func(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - int val[2], n, x, y; - - n = GetIntegerArguments(action, NULL, val, 2); - if(n != 2) - { - fvwm_msg(ERR,"goto_page_func","GotoPage requires two arguments"); - return; - } - - x = val[0] * Scr.MyDisplayWidth; - y = val[1] * Scr.MyDisplayHeight; - MoveViewport(x,y,True); -} - - + int val[2], n, x, y; + n = GetIntegerArguments(action, NULL, val, 2); + if (n != 2) { + fvwm_msg( + ERR, "goto_page_func", "GotoPage requires two arguments"); + return; + } + x = val[0] * Scr.MyDisplayWidth; + y = val[1] * Scr.MyDisplayHeight; + MoveViewport(x, y, True); +} Index: fvwm/fvwm/windows.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/windows.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/windows.c --- fvwm/fvwm/windows.c +++ fvwm/fvwm/windows.c @@ -11,341 +11,351 @@ * ***********************************************************************/ +#include +#include #include #include -#include #include -#include #include "config.h" -#include "fvwmlib.h" - #include "fvwm.h" +#include "fvwmlib.h" #include "menus.h" #include "misc.h" #include "parse.h" #include "screen.h" -#define SHOW_GEOMETRY (1<<0) -#define SHOW_ALLDESKS (1<<1) -#define SHOW_NORMAL (1<<2) -#define SHOW_ICONIC (1<<3) -#define SHOW_STICKY (1<<4) -#define SHOW_ONTOP (1<<5) -#define NO_DESK_SORT (1<<6) -#define SHOW_ICONNAME (1<<7) -#define SHOW_ALPHABETIC (1<<8) -#define SHOW_EVERYTHING (SHOW_GEOMETRY | SHOW_ALLDESKS | SHOW_NORMAL | SHOW_ICONIC | SHOW_STICKY | SHOW_ONTOP) +#define SHOW_GEOMETRY (1 << 0) +#define SHOW_ALLDESKS (1 << 1) +#define SHOW_NORMAL (1 << 2) +#define SHOW_ICONIC (1 << 3) +#define SHOW_STICKY (1 << 4) +#define SHOW_ONTOP (1 << 5) +#define NO_DESK_SORT (1 << 6) +#define SHOW_ICONNAME (1 << 7) +#define SHOW_ALPHABETIC (1 << 8) +#define SHOW_EVERYTHING \ + (SHOW_GEOMETRY | SHOW_ALLDESKS | SHOW_NORMAL | SHOW_ICONIC | \ + SHOW_STICKY | SHOW_ONTOP) /* Function to compare window title names */ static int globalFlags; -int winCompare(const FvwmWindow **a, const FvwmWindow **b) +int +winCompare(const FvwmWindow **a, const FvwmWindow **b) { - if(globalFlags & SHOW_ICONNAME) - return strcasecmp((*a)->icon_name,(*b)->icon_name); - else - return strcasecmp((*a)->name,(*b)->name); + if (globalFlags & SHOW_ICONNAME) + return strcasecmp((*a)->icon_name, (*b)->icon_name); + else + return strcasecmp((*a)->name, (*b)->name); } - /* * Change by PRB (pete@tecc.co.uk), 31/10/93. Prepend a hot key * specifier to each item in the list. This means allocating the * memory for each item (& freeing it) rather than just using the window * title directly. */ -void do_windowList(XEvent *eventp,Window w,FvwmWindow *tmp_win, - unsigned long context, char *action,int *Module) +void +do_windowList(XEvent *eventp, Window w, FvwmWindow *tmp_win, + unsigned long context, char *action, int *Module) { - MenuRoot *mr; - MenuItem *miExecuteAction; - FvwmWindow *t; - FvwmWindow **windowList; - int numWindows; - int ii; - char tname[80] = ""; - char loc[40],*name=NULL; - int dwidth,dheight; - char tlabel[50]=""; - int last_desk_done = INT_MIN; - int last_desk_displayed = INT_MIN; - int next_desk = 0; - char *t_hot=NULL; /* Menu label with hotkey added */ - char scut = '0'; /* Current short cut key */ - char *line=NULL,*tok=NULL; - int desk = Scr.CurrentDesk; - int flags = SHOW_EVERYTHING; - char *func=NULL; - char *tfunc=NULL; - char *default_action = NULL; - MenuStatus menu_retval; - XEvent *teventp; - MenuOptions mops; - size_t hotlen; + MenuRoot *mr; + MenuItem *miExecuteAction; + FvwmWindow *t; + FvwmWindow **windowList; + int numWindows; + int ii; + char tname[80] = ""; + char loc[40], *name = NULL; + int dwidth, dheight; + char tlabel[50] = ""; + int last_desk_done = INT_MIN; + int last_desk_displayed = INT_MIN; + int next_desk = 0; + char *t_hot = NULL; /* Menu label with hotkey added */ + char scut = '0'; /* Current short cut key */ + char *line = NULL, *tok = NULL; + int desk = Scr.CurrentDesk; + int flags = SHOW_EVERYTHING; + char *func = NULL; + char *tfunc = NULL; + char *default_action = NULL; + MenuStatus menu_retval; + XEvent *teventp; + MenuOptions mops; + size_t hotlen; - mops.flags.allflags = 0; - if (action && *action) - { - /* parse postitioning args */ - action = GetMenuOptions(action,w,tmp_win,NULL,&mops); - line = action; - /* parse options */ - while (line && *line) - { - line = GetNextOption(line, &tok); - if (!tok) - break; + mops.flags.allflags = 0; + if (action && *action) { + /* parse postitioning args */ + action = GetMenuOptions(action, w, tmp_win, NULL, &mops); + line = action; + /* parse options */ + while (line && *line) { + line = GetNextOption(line, &tok); + if (!tok) + break; - if (StrEquals(tok,"Function")) - { - line = GetNextOption(line, &func); - } - else if (StrEquals(tok,"Desk")) - { - free(tok); - line = GetNextOption(line, &tok); - if (tok) - { - desk = atoi(tok); - flags &= ~SHOW_ALLDESKS; + if (StrEquals(tok, "Function")) { + line = GetNextOption(line, &func); + } else if (StrEquals(tok, "Desk")) { + free(tok); + line = GetNextOption(line, &tok); + if (tok) { + desk = atoi(tok); + flags &= ~SHOW_ALLDESKS; + } + } else if (StrEquals(tok, "CurrentDesk")) { + desk = Scr.CurrentDesk; + flags &= ~SHOW_ALLDESKS; + } else if (StrEquals(tok, "NotAlphabetic")) + flags &= ~SHOW_ALPHABETIC; + else if (StrEquals(tok, "Alphabetic")) + flags |= SHOW_ALPHABETIC; + else if (StrEquals(tok, "NoDeskSort")) + flags |= NO_DESK_SORT; + else if (StrEquals(tok, "UseIconName")) + flags |= SHOW_ICONNAME; + else if (StrEquals(tok, "NoGeometry")) + flags &= ~SHOW_GEOMETRY; + else if (StrEquals(tok, "Geometry")) + flags |= SHOW_GEOMETRY; + else if (StrEquals(tok, "NoIcons")) + flags &= ~SHOW_ICONIC; + else if (StrEquals(tok, "Icons")) + flags |= SHOW_ICONIC; + else if (StrEquals(tok, "OnlyIcons")) + flags = SHOW_ICONIC; + else if (StrEquals(tok, "NoNormal")) + flags &= ~SHOW_NORMAL; + else if (StrEquals(tok, "Normal")) + flags |= SHOW_NORMAL; + else if (StrEquals(tok, "OnlyNormal")) + flags = SHOW_NORMAL; + else if (StrEquals(tok, "NoSticky")) + flags &= ~SHOW_STICKY; + else if (StrEquals(tok, "Sticky")) + flags |= SHOW_STICKY; + else if (StrEquals(tok, "OnlySticky")) + flags = SHOW_STICKY; + else if (StrEquals(tok, "NoOnTop")) + flags &= ~SHOW_ONTOP; + else if (StrEquals(tok, "OnTop")) + flags |= SHOW_ONTOP; + else if (StrEquals(tok, "OnlyOnTop")) + flags = SHOW_ONTOP; + else if (!line || !*line) + default_action = strdup(tok); + else { + fvwm_msg(ERR, "WindowList", + "Unknown option '%s'", tok); + } + if (tok) + free(tok); + } } - } - else if (StrEquals(tok,"CurrentDesk")) - { - desk = Scr.CurrentDesk; - flags &= ~SHOW_ALLDESKS; - } - else if (StrEquals(tok,"NotAlphabetic")) - flags &= ~SHOW_ALPHABETIC; - else if (StrEquals(tok,"Alphabetic")) - flags |= SHOW_ALPHABETIC; - else if (StrEquals(tok,"NoDeskSort")) - flags |= NO_DESK_SORT; - else if (StrEquals(tok,"UseIconName")) - flags |= SHOW_ICONNAME; - else if (StrEquals(tok,"NoGeometry")) - flags &= ~SHOW_GEOMETRY; - else if (StrEquals(tok,"Geometry")) - flags |= SHOW_GEOMETRY; - else if (StrEquals(tok,"NoIcons")) - flags &= ~SHOW_ICONIC; - else if (StrEquals(tok,"Icons")) - flags |= SHOW_ICONIC; - else if (StrEquals(tok,"OnlyIcons")) - flags = SHOW_ICONIC; - else if (StrEquals(tok,"NoNormal")) - flags &= ~SHOW_NORMAL; - else if (StrEquals(tok,"Normal")) - flags |= SHOW_NORMAL; - else if (StrEquals(tok,"OnlyNormal")) - flags = SHOW_NORMAL; - else if (StrEquals(tok,"NoSticky")) - flags &= ~SHOW_STICKY; - else if (StrEquals(tok,"Sticky")) - flags |= SHOW_STICKY; - else if (StrEquals(tok,"OnlySticky")) - flags = SHOW_STICKY; - else if (StrEquals(tok,"NoOnTop")) - flags &= ~SHOW_ONTOP; - else if (StrEquals(tok,"OnTop")) - flags |= SHOW_ONTOP; - else if (StrEquals(tok,"OnlyOnTop")) - flags = SHOW_ONTOP; - else if (!line || !*line) - default_action = strdup(tok); - else - { - fvwm_msg(ERR,"WindowList","Unknown option '%s'",tok); - } - if (tok) - free(tok); - } - } - globalFlags = flags; - if (flags & SHOW_GEOMETRY) - { - snprintf(tlabel,sizeof(tlabel),"Desk: %d\tGeometry",desk); - } - else - { - snprintf(tlabel,sizeof(tlabel),"Desk: %d",desk); - } - mr=NewMenuRoot(tlabel, False); - AddToMenu(mr, tlabel, "TITLE", FALSE, FALSE); + globalFlags = flags; + if (flags & SHOW_GEOMETRY) { + snprintf(tlabel, sizeof(tlabel), "Desk: %d\tGeometry", desk); + } else { + snprintf(tlabel, sizeof(tlabel), "Desk: %d", desk); + } + mr = NewMenuRoot(tlabel, False); + AddToMenu(mr, tlabel, "TITLE", FALSE, FALSE); - numWindows = 0; - for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) - { - numWindows++; - } - windowList = malloc(numWindows*sizeof(t)); - if (windowList == NULL) - { - return; - } - /* get the windowlist starting from the current window (if any)*/ - if ((t = Scr.Focus) == NULL) t = Scr.FvwmRoot.next; - for (ii = 0; ii < numWindows; ii++) - { - windowList[ii] = t; - if (t->next) - t = t->next; - else - t = Scr.FvwmRoot.next; - } + numWindows = 0; + for (t = Scr.FvwmRoot.next; t != NULL; t = t->next) { + numWindows++; + } + windowList = malloc(numWindows * sizeof(t)); + if (windowList == NULL) { + return; + } + /* get the windowlist starting from the current window (if any)*/ + if ((t = Scr.Focus) == NULL) + t = Scr.FvwmRoot.next; + for (ii = 0; ii < numWindows; ii++) { + windowList[ii] = t; + if (t->next) + t = t->next; + else + t = Scr.FvwmRoot.next; + } - /* Do alphabetic sort */ - if (flags & SHOW_ALPHABETIC) - qsort(windowList,numWindows,sizeof(t), - (int(*)(const void*,const void*))winCompare); + /* Do alphabetic sort */ + if (flags & SHOW_ALPHABETIC) + qsort(windowList, numWindows, sizeof(t), + (int (*)(const void *, const void *))winCompare); - while(next_desk != INT_MAX) - { - /* Sort window list by desktop number */ - if((flags & SHOW_ALLDESKS) && !(flags & NO_DESK_SORT)) - { - /* run through the windowlist finding the first desk not already processed */ - next_desk = INT_MAX; - for (ii = 0; ii < numWindows; ii++) - { - t = windowList[ii]; - if((t->Desk >last_desk_done)&&(t->Desk < next_desk)) - next_desk = t->Desk; - } - } - if(!(flags & SHOW_ALLDESKS)) - { - /* if only doing one desk and it hasn't been done */ - if(last_desk_done == INT_MIN) - next_desk = desk; /* select the desk */ - else - next_desk = INT_MAX; /* flag completion */ - } - if(flags & NO_DESK_SORT) - next_desk = INT_MAX; /* only go through loop once */ + while (next_desk != INT_MAX) { + /* Sort window list by desktop number */ + if ((flags & SHOW_ALLDESKS) && !(flags & NO_DESK_SORT)) { + /* run through the windowlist finding the first desk not + * already processed */ + next_desk = INT_MAX; + for (ii = 0; ii < numWindows; ii++) { + t = windowList[ii]; + if ((t->Desk > last_desk_done) && + (t->Desk < next_desk)) + next_desk = t->Desk; + } + } + if (!(flags & SHOW_ALLDESKS)) { + /* if only doing one desk and it hasn't been done */ + if (last_desk_done == INT_MIN) + next_desk = desk; /* select the desk */ + else + next_desk = INT_MAX; /* flag completion */ + } + if (flags & NO_DESK_SORT) + next_desk = INT_MAX; /* only go through loop once */ - last_desk_done = next_desk; - for (ii = 0; ii < numWindows; ii++) - { - t = windowList[ii]; - if(((t->Desk == next_desk) || (flags & NO_DESK_SORT)) && - (!(t->flags & WINDOWLISTSKIP))) - { - if (!(flags & SHOW_ICONIC) && (t->flags & ICONIFIED)) - continue; /* don't want icons - skip */ - if (!(flags & SHOW_STICKY) && (t->flags & STICKY)) - continue; /* don't want sticky ones - skip */ - if (!(flags & SHOW_ONTOP) && (t->flags & ONTOP)) - continue; /* don't want ontop ones - skip */ - if (!(flags & SHOW_NORMAL) && - !((t->flags & ICONIFIED) || - (t->flags & STICKY) || - (t->flags & ONTOP))) - continue; /* don't want "normal" ones - skip */ + last_desk_done = next_desk; + for (ii = 0; ii < numWindows; ii++) { + t = windowList[ii]; + if (((t->Desk == next_desk) || + (flags & NO_DESK_SORT)) && + (!(t->flags & WINDOWLISTSKIP))) { + if (!(flags & SHOW_ICONIC) && + (t->flags & ICONIFIED)) + continue; /* don't want icons - skip */ + if (!(flags & SHOW_STICKY) && + (t->flags & STICKY)) + continue; /* don't want sticky ones - + skip */ + if (!(flags & SHOW_ONTOP) && (t->flags & ONTOP)) + continue; /* don't want ontop ones - + skip */ + if (!(flags & SHOW_NORMAL) && + !((t->flags & ICONIFIED) || + (t->flags & STICKY) || + (t->flags & ONTOP))) + continue; /* don't want "normal" ones - + skip */ - /* put a seperator between desks, but not at the top */ - if (t->Desk != last_desk_displayed) - { - if (last_desk_displayed != INT_MIN) - AddToMenu(mr, NULL, NULL, FALSE, FALSE); - last_desk_displayed = t->Desk; - } + /* put a seperator between desks, but not at the + * top */ + if (t->Desk != last_desk_displayed) { + if (last_desk_displayed != INT_MIN) + AddToMenu(mr, NULL, NULL, FALSE, + FALSE); + last_desk_displayed = t->Desk; + } - if(flags & SHOW_ICONNAME) - name = t->icon_name; - else - name = t->name; - hotlen = strlen(name) + strlen(tname) + 48; - t_hot = safemalloc(hotlen); - snprintf(t_hot, hotlen, "&%c. %s", scut, name); /* Generate label */ - if (scut++ == '9') scut = 'A'; /* Next shortcut key */ + if (flags & SHOW_ICONNAME) + name = t->icon_name; + else + name = t->name; + hotlen = strlen(name) + strlen(tname) + 48; + t_hot = xmalloc(hotlen); + snprintf(t_hot, hotlen, "&%c. %s", scut, + name); /* Generate label */ + if (scut++ == '9') + scut = 'A'; /* Next shortcut key */ - if (flags & SHOW_GEOMETRY) - { - tname[0]=0; - if(t->flags & ICONIFIED) - strlcpy(tname, "(", sizeof(tname)); - snprintf(loc, sizeof(loc), "%d:",t->Desk); - strlcat(tname, loc, sizeof(tname)); + if (flags & SHOW_GEOMETRY) { + tname[0] = 0; + if (t->flags & ICONIFIED) + strlcpy( + tname, "(", sizeof(tname)); + snprintf( + loc, sizeof(loc), "%d:", t->Desk); + strlcat(tname, loc, sizeof(tname)); - dheight = t->frame_height - t->title_height - 2*t->boundary_width; - dwidth = t->frame_width - 2*t->boundary_width; + dheight = t->frame_height - + t->title_height - + 2 * t->boundary_width; + dwidth = t->frame_width - + 2 * t->boundary_width; - dwidth -= t->hints.base_width; - dheight -= t->hints.base_height; + dwidth -= t->hints.base_width; + dheight -= t->hints.base_height; - dwidth /= t->hints.width_inc; - dheight /= t->hints.height_inc; + dwidth /= t->hints.width_inc; + dheight /= t->hints.height_inc; - snprintf(loc, sizeof(loc), "%d", dwidth); - strlcat(tname, loc,sizeof(tname)); - snprintf(loc, sizeof(loc), "x%d", dheight); - strlcat(tname, loc,sizeof(tname)); - if(t->frame_x >=0) - snprintf(loc, sizeof(loc), "+%d", t->frame_x); - else - snprintf(loc, sizeof(loc), "%d", t->frame_x); - strlcat(tname, loc, sizeof(tname)); - if(t->frame_y >=0) - snprintf(loc, sizeof(loc), "+%d", t->frame_y); - else - snprintf(loc, sizeof(loc), "%d", t->frame_y); - strlcat(tname, loc, sizeof(tname)); + snprintf( + loc, sizeof(loc), "%d", dwidth); + strlcat(tname, loc, sizeof(tname)); + snprintf( + loc, sizeof(loc), "x%d", dheight); + strlcat(tname, loc, sizeof(tname)); + if (t->frame_x >= 0) + snprintf(loc, sizeof(loc), + "+%d", t->frame_x); + else + snprintf(loc, sizeof(loc), "%d", + t->frame_x); + strlcat(tname, loc, sizeof(tname)); + if (t->frame_y >= 0) + snprintf(loc, sizeof(loc), + "+%d", t->frame_y); + else + snprintf(loc, sizeof(loc), "%d", + t->frame_y); + strlcat(tname, loc, sizeof(tname)); - if (t->flags & STICKY) - strlcat(tname, " S", sizeof(tname)); - if (t->flags & ONTOP) - strlcat(tname, " T", sizeof(tname)); - if (t->flags & ICONIFIED) - strlcat(tname, ")", sizeof(tname)); - strlcat(t_hot,"\t",hotlen); - strlcat(t_hot,tname,hotlen); - } - if (!func) - { - tfunc = safemalloc(40); - snprintf(tfunc,40,"WindowListFunc %ld",t->w); - } - else - { - size_t funclen = strlen(func) + 32; - tfunc = safemalloc(funclen); - snprintf(tfunc,funclen,"%s %ld",func,t->w); - free(func); - func = NULL; - } - AddToMenu(mr, t_hot, tfunc, FALSE, FALSE); - free(tfunc); + if (t->flags & STICKY) + strlcat( + tname, " S", sizeof(tname)); + if (t->flags & ONTOP) + strlcat( + tname, " T", sizeof(tname)); + if (t->flags & ICONIFIED) + strlcat( + tname, ")", sizeof(tname)); + strlcat(t_hot, "\t", hotlen); + strlcat(t_hot, tname, hotlen); + } + if (!func) { + tfunc = xmalloc(40); + snprintf(tfunc, 40, + "WindowListFunc %ld", t->w); + } else { + size_t funclen = strlen(func) + 32; + tfunc = xmalloc(funclen); + snprintf(tfunc, funclen, "%s %ld", func, + t->w); + free(func); + func = NULL; + } + AddToMenu(mr, t_hot, tfunc, FALSE, FALSE); + free(tfunc); #ifdef MINI_ICONS - /* Add the title pixmap */ - if (t->mini_icon) { - mr->last->lpicture = t->mini_icon; - t->mini_icon->count++; /* increase the cache count!! - otherwise the pixmap will be - eventually removed from the - cache by DestroyMenu */ - } + /* Add the title pixmap */ + if (t->mini_icon) { + mr->last->lpicture = t->mini_icon; + t->mini_icon + ->count++; /* increase the cache + count!! otherwise the + pixmap will be + eventually removed + from the cache by + DestroyMenu */ + } #endif - if (t_hot) - free(t_hot); - } - } - } + if (t_hot) + free(t_hot); + } + } + } - if (func) - free(func); - free(windowList); - MakeMenu(mr); - if (!default_action && eventp && eventp->type == KeyPress) - teventp = (XEvent *)1; - else - teventp = eventp; - menu_retval = do_menu(mr, NULL, &miExecuteAction, 0, TRUE, teventp, &mops); - DestroyMenu(mr); - if (menu_retval == MENU_DOUBLE_CLICKED && default_action && *default_action) - ExecuteFunction(default_action,tmp_win,eventp,context,*Module); - if (default_action != NULL) - free(default_action); + if (func) + free(func); + free(windowList); + MakeMenu(mr); + if (!default_action && eventp && eventp->type == KeyPress) + teventp = (XEvent *)1; + else + teventp = eventp; + menu_retval = + do_menu(mr, NULL, &miExecuteAction, 0, TRUE, teventp, &mops); + DestroyMenu(mr); + if (menu_retval == MENU_DOUBLE_CLICKED && default_action && + *default_action) + ExecuteFunction( + default_action, tmp_win, eventp, context, *Module); + if (default_action != NULL) + free(default_action); } - Index: fvwm/fvwm/xalloc.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/xalloc.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/xalloc.h --- /dev/null +++ fvwm/fvwm/xalloc.h @@ -0,0 +1,77 @@ +#ifndef FVWM_XALLOC_H +#define FVWM_XALLOC_H + +#include +#include +#include + +static inline void * +xmalloc(size_t size) +{ + void *ptr; + + if (size == 0) + size = 1; + ptr = malloc(size); + if (ptr == NULL) + err(1, "malloc"); + return ptr; +} + +static inline void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (nmemb == 0 || size == 0) { + nmemb = 1; + size = 1; + } + ptr = calloc(nmemb, size); + if (ptr == NULL) + err(1, "calloc"); + return ptr; +} + +static inline void * +xrealloc(void *ptr, size_t size) +{ + void *newptr; + + if (size == 0) + size = 1; + newptr = realloc(ptr, size); + if (newptr == NULL) + err(1, "realloc"); + return newptr; +} + +static inline void * +xreallocarray(void *ptr, size_t nmemb, size_t size) +{ + return xrealloc(ptr, nmemb * size); +} + +static inline char * +xstrdup(const char *s) +{ + char *copy; + + copy = strdup(s); + if (copy == NULL) + err(1, "strdup"); + return copy; +} + +static inline char * +xstrndup(const char *s, size_t n) +{ + char *copy; + + copy = strndup(s, n); + if (copy == NULL) + err(1, "strndup"); + return copy; +} + +#endif /* FVWM_XALLOC_H */ Index: fvwm/libs/ClientMsg.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ClientMsg.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ClientMsg.c --- fvwm/libs/ClientMsg.c +++ fvwm/libs/ClientMsg.c @@ -11,24 +11,25 @@ * data[1] time stamp * ****************************************************************************/ -#include #include +#include #include Atom _XA_WM_PROTOCOLS = None; -void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp) +void +send_clientmessage(Display *disp, Window w, Atom a, Time timestamp) { - XClientMessageEvent ev; + XClientMessageEvent ev; - if (_XA_WM_PROTOCOLS == None) - _XA_WM_PROTOCOLS = XInternAtom(disp, "WM_PROTOCOLS", False); + if (_XA_WM_PROTOCOLS == None) + _XA_WM_PROTOCOLS = XInternAtom(disp, "WM_PROTOCOLS", False); - ev.type = ClientMessage; - ev.window = w; - ev.message_type = _XA_WM_PROTOCOLS; - ev.format = 32; - ev.data.l[0] = a; - ev.data.l[1] = timestamp; - XSendEvent (disp, w, False, 0L, (XEvent *) &ev); + ev.type = ClientMessage; + ev.window = w; + ev.message_type = _XA_WM_PROTOCOLS; + ev.format = 32; + ev.data.l[0] = a; + ev.data.l[1] = timestamp; + XSendEvent(disp, w, False, 0L, (XEvent *)&ev); } Index: fvwm/libs/GetFont.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/GetFont.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/GetFont.c --- fvwm/libs/GetFont.c +++ fvwm/libs/GetFont.c @@ -1,32 +1,30 @@ -#include "config.h" - -#include -#include -#include - #include #include +#include +#include +#include +#include "config.h" #include "fvwmlib.h" /* ** loads font or "fixed" on failure */ -XFontStruct *GetFontOrFixed(Display *disp, char *fontname) +XFontStruct * +GetFontOrFixed(Display *disp, char *fontname) { - XFontStruct *fnt; + XFontStruct *fnt; - if ((fnt = XLoadQueryFont(disp,fontname))==NULL) - { - fprintf(stderr, - "[GetFontOrFixed]: WARNING -- can't get font %s, trying 'fixed'", - fontname); - /* fixed should always be avail, so try that */ - if ((fnt = XLoadQueryFont(disp,"fixed"))==NULL) - { - fprintf(stderr,"[GetFontOrFixed]: ERROR -- can't get font 'fixed'"); - } - } - return fnt; + if ((fnt = XLoadQueryFont(disp, fontname)) == NULL) { + fprintf(stderr, + "[GetFontOrFixed]: WARNING -- can't get font %s, trying " + "'fixed'", + fontname); + /* fixed should always be avail, so try that */ + if ((fnt = XLoadQueryFont(disp, "fixed")) == NULL) { + fprintf(stderr, "[GetFontOrFixed]: ERROR -- can't get " + "font 'fixed'"); + } + } + return fnt; } - Index: fvwm/libs/GetFontSet.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/GetFontSet.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/GetFontSet.c --- fvwm/libs/GetFontSet.c +++ fvwm/libs/GetFontSet.c @@ -1,38 +1,38 @@ /* This file brings from GetFont.c */ -#include "../configure.h" - -#include -#include -#include - #include #include +#include +#include +#include +#include "../configure.h" #include "fvwmlib.h" /* ** loads fontset or "fixed" on failure */ -XFontSet GetFontSetOrFixed(Display *disp, char *fontname) +XFontSet +GetFontSetOrFixed(Display *disp, char *fontname) { - XFontSet fontset; - char **ml; - int mc; - char *ds; + XFontSet fontset; + char **ml; + int mc; + char *ds; - if ((fontset = XCreateFontSet(disp,fontname,&ml,&mc,&ds))==NULL) - { - fprintf(stderr, - "[FVWM][GetFontSetOrFixed]: WARNING -- can't get fontset %s, trying 'fixed'\n", - fontname); - /* fixed should always be avail, so try that */ - /* plain X11R6.3 hack */ - if ((fontset = XCreateFontSet(disp,"fixed,-*--14-*",&ml,&mc,&ds))==NULL) - { - fprintf(stderr,"[FVWM][GetFontSetOrFixed]: ERROR -- can't get fontset 'fixed'\n"); - } - } - return fontset; + if ((fontset = XCreateFontSet(disp, fontname, &ml, &mc, &ds)) == NULL) { + fprintf(stderr, + "[FVWM][GetFontSetOrFixed]: WARNING -- can't get fontset " + "%s, trying 'fixed'\n", + fontname); + /* fixed should always be avail, so try that */ + /* plain X11R6.3 hack */ + if ((fontset = XCreateFontSet( + disp, "fixed,-*--14-*", &ml, &mc, &ds)) == NULL) { + fprintf(stderr, + "[FVWM][GetFontSetOrFixed]: ERROR -- can't get " + "fontset 'fixed'\n"); + } + } + return fontset; } - Index: fvwm/libs/Grab.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Grab.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Grab.c --- fvwm/libs/Grab.c +++ fvwm/libs/Grab.c @@ -7,25 +7,23 @@ /* Made into global for module interface. See module.c. */ int myxgrabcount = 0; -void MyXGrabServer(Display *disp) +void +MyXGrabServer(Display *disp) { - if (myxgrabcount == 0) - { - XGrabServer(disp); - } - ++myxgrabcount; + if (myxgrabcount == 0) { + XGrabServer(disp); + } + ++myxgrabcount; } -void MyXUngrabServer(Display *disp) +void +MyXUngrabServer(Display *disp) { - if (--myxgrabcount < 0) /* should never happen */ - { - /* fvwm_msg(ERR,"MyXUngrabServer","too many ungrabs!\n"); */ - myxgrabcount = 0; - } - if (myxgrabcount == 0) - { - XUngrabServer(disp); - } + if (--myxgrabcount < 0) { /* should never happen */ + /* fvwm_msg(ERR,"MyXUngrabServer","too many ungrabs!\n"); */ + myxgrabcount = 0; + } + if (myxgrabcount == 0) { + XUngrabServer(disp); + } } - Index: fvwm/libs/ModParse.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ModParse.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ModParse.c --- fvwm/libs/ModParse.c +++ fvwm/libs/ModParse.c @@ -9,9 +9,9 @@ itself for parsing. */ +#include "ModParse.h" #include "fvwmlib.h" -#include "ModParse.h" /* ** PeekArgument: returns next token from string, leaving string intact @@ -24,146 +24,130 @@ ** to MAX_TOKEN_LENGTH in size. */ - -char *DoPeekArgument(const char *pstr, char **pret) +char * +DoPeekArgument(const char *pstr, const char **pret) { - char *tok=NULL; - const char *p; - char bc=0,be=0,tmptok[MAX_TOKEN_LENGTH]; - int len=0; - - if (!pstr) - return NULL; - - p=pstr; - EatWS(p); /* skip leading space */ - if (*p) - { - if (IsQuote(*p) || IsBlockStart(*p)) /* quoted string or block start? */ - { - bc = *p; /* save block start char */ - p++; - } - /* find end of token */ - while (*p && len < MAX_TOKEN_LENGTH) - { - /* first, check stop conditions based on block or normal token */ - if (bc) - { - if ((IsQuote(*p) && bc == *p) || IsBlockEnd(*p,bc)) - { - be = *p; - break; - } - } - else /* normal token */ - { - if (isspace(*p) || *p == ',') - break; - } - - if (*p == '\\' && *(p+1)) /* if \, copy next char verbatim */ - p++; - tmptok[len] = *p; - len++; - p++; - } - - /* sanity checks: */ - if (bc && !be) /* did we have block start, but not end? */ - { - /* should yell about this */ - return NULL; - } - - if (len) - { - tok = (char *)safemalloc(len+1); - strncpy(tok,tmptok,len); - tok[len]='\0'; - } - } - - if (!isspace(*p)) p++; - if (pret) *pret = p; - return tok; + char *tok = NULL; + const char *p; + char bc = 0, be = 0, tmptok[MAX_TOKEN_LENGTH]; + int len = 0; + + if (!pstr) + return NULL; + + p = pstr; + EatWS(p); /* skip leading space */ + if (*p) { + if (IsQuote(*p) || + IsBlockStart(*p)) { /* quoted string or block start? */ + bc = *p; /* save block start char */ + p++; + } + /* find end of token */ + while (*p && len < MAX_TOKEN_LENGTH) { + /* first, check stop conditions based on block or normal + * token */ + if (bc) { + if ((IsQuote(*p) && bc == *p) || + IsBlockEnd(*p, bc)) { + be = *p; + break; + } + } else /* normal token */ { + if (isspace(*p) || *p == ',') + break; + } + + if (*p == '\\' && + *(p + 1)) /* if \, copy next char verbatim */ + p++; + tmptok[len] = *p; + len++; + p++; + } + + /* sanity checks: */ + if (bc && !be) { /* did we have block start, but not end? */ + /* should yell about this */ + return NULL; + } + + if (len) { + tok = (char *)xmalloc(len + 1); + strncpy(tok, tmptok, len); + tok[len] = '\0'; + } + } + + if (*p && !isspace((unsigned char)*p)) + p++; + if (pret) + *pret = p; + return tok; } -char *PeekArgument(const char *pstr) +char * +PeekArgument(const char *pstr) { - return DoPeekArgument(pstr, NULL); + return DoPeekArgument(pstr, NULL); } /* ** GetArgument: destructively rips next token from string, returning it ** (you should free returned string later) */ -char *GetArgument(char **pstr) +char * +GetArgument(char **pstr) { - char *tok ; + char *tok; + const char *next = NULL; - if (!pstr || !*pstr || !(tok=DoPeekArgument(*pstr, pstr))) - return NULL; /* *pstr=NULL; ???? */ + if (!pstr || !*pstr || !(tok = DoPeekArgument(*pstr, &next))) + return NULL; - /* skip tok and following whitespace/separators in pstr & DON'T realloc */ - EatWS(*pstr); + *pstr = (char *)next; + /* skip tok and following whitespace/separators in pstr & DON'T realloc + */ + EatWS(*pstr); - if (!**pstr) - *pstr=NULL; /* change \0 to NULL */ + if (*pstr && !**pstr) + *pstr = NULL; /* change \0 to NULL */ - return tok; + return tok; } /* ** CmpArgument: does case-insensitive compare on next token in string, leaving ** string intact (return code like strcmp) */ -int CmpArgument(const char *pstr,char *tok) +int +CmpArgument(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekArgument(pstr); - if (ntok) - { - rc = strcasecmp(tok,ntok); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekArgument(pstr); + if (ntok) { + rc = strcasecmp(tok, ntok); + free(ntok); + } + return rc; } /* ** MatchArgument: does case-insensitive compare on next token in string, leaving ** string intact (returns true if matches, false otherwise) */ -int MatchArgument(const char *pstr,char *tok) +int +MatchArgument(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekArgument(pstr); - if (ntok) - { - rc = (strcasecmp(tok,ntok)==0); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekArgument(pstr); + if (ntok) { + rc = (strcasecmp(tok, ntok) == 0); + free(ntok); + } + return rc; } - -#if 0 -/* -** GetNextArgument: equiv interface of old parsing routine, for ease of transition -*/ -char *GetNextArgument(char *indata,char **token) -{ - char *nindata=indata; - - *token = PeekArgument(indata); - - if (*token) - nindata+=strlen(*token); - EatWS(nindata); - - return nindata; -} -#else /**************************************************************************** * * Gets the next "word" of input from char string indata. @@ -171,83 +155,71 @@ char *GetNextArgument(char *indata,char **token) * Return value is ptr to indata,updated to point to text after the word * which is extracted. * token is the extracted word, which is copied into a malloced - * space, and must be freed after use. + * space, and must be freed after use. * **************************************************************************/ -char *GetNextArgument(char *indata,char **token) -{ - char *t,*start, *end, *text; - - t = indata; - if(t == NULL) - { - *token = NULL; - return NULL; - } - while(isspace(*t)&&(*t != 0))t++; - start = t; - while(!isspace(*t)&&(*t != 0)) - { - /* Check for qouted text */ - if(*t == '"') - { - t++; - while((*t != '"')&&(*t != 0)) - { - /* Skip over escaped text, ie \" or \space " */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; - } - if(*t == '"') - t++; - } - else - { - /* Skip over escaped text, ie \" or \space " */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; +char * +GetNextArgument(char *indata, char **token) +{ + char *t, *start, *end, *text; + + t = indata; + if (t == NULL) { + *token = NULL; + return NULL; } - } - end = t; - - text = safemalloc(end-start+1); - *token = text; - - while(start < end) - { - /* Check for qouted text */ - if(*start == '"') - { - start++; - while((*start != '"')&&(*start != 0)) - { - /* Skip over escaped text, ie \" or \space " */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; - } - if(*start == '"') - start++; + while (isspace(*t) && (*t != 0)) + t++; + start = t; + while (!isspace(*t) && (*t != 0)) { + /* Check for qouted text */ + if (*t == '"') { + t++; + while ((*t != '"') && (*t != 0)) { + /* Skip over escaped text, ie \" or \space " */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } + if (*t == '"') + t++; + } else { + /* Skip over escaped text, ie \" or \space " */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } } - else - { - /* Skip over escaped text, ie \" or \space " */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; + end = t; + + text = xmalloc(end - start + 1); + *token = text; + + while (start < end) { + /* Check for qouted text */ + if (*start == '"') { + start++; + while ((*start != '"') && (*start != 0)) { + /* Skip over escaped text, ie \" or \space " */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } + if (*start == '"') + start++; + } else { + /* Skip over escaped text, ie \" or \space " */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } } - } - *text = 0; - if(*end != 0) - end++; + *text = 0; + if (*end != 0) + end++; - return end; + return end; } -#endif /* 0 */ - - /* function: MatchToken @@ -256,29 +228,6 @@ char *GetNextArgument(char *indata,char **token) NULL if no match */ -#if 0 /* supported in 2.0.47b */ -const char *MatchToken(register const char *s, register const char *w) -{ - if (s==NULL) return NULL; - assert(w!=NULL); /* the token may not be NULL -> design flaw */ - - while (*w && (*s==*w || -#ifdef WORD_IS_UPPERCASE - isupper(*s) && _toupper(*s)==*w -#else - toupper(*s)==toupper(*w) -#endif - )) - s++,w++; - - if (*w=='\0' && /* end of word and */ - (*s=='\0' || ispunct(*s) || isspace(*s))) /* same in string */ - return s; /* return endptr */ - else - return NULL; /* no match */ -} -#endif - /* function: CmpToken description: compare 1st word of s to 1st word of w @@ -286,31 +235,44 @@ const char *MatchToken(register const char *s, register const char *w) = 0 if s = t > 0 if s > t - Note arguments are not declares register, so the function can be + Note arguments are not declares register, so the function can be used with the bsearch() function of the c library. */ -int XCmpToken(char *s, char **t) +int +XCmpToken(const void *vs, const void *vt) { - register char *w=*t; + const char *s = (const char *)vs; + const char *w = *(const char *const *)vt; - if (w==NULL) return 1; /* non existant word */ - if (s==NULL) return -1; /* non existant string */ + if (w == NULL) + return 1; /* non existant word */ + if (s == NULL) + return -1; /* non existant string */ - while (*w && (*s==*w || #ifdef WORD_IS_UPPERCASE - isupper(*s) && _toupper(*s)==*w + while (*w && + (*s == *w || + (isupper((unsigned char)*s) && + _toupper((unsigned char)*s) == *w))) { + s++, w++; + } #else - toupper(*s)==toupper(*w) + while (*w && + (*s == *w || + toupper((unsigned char)*s) == + toupper((unsigned char)*w))) { + s++, w++; + } #endif - )) - s++,w++; - - if ((*s=='\0' && (ispunct(*w) || isspace(*w)))|| - (*w=='\0' && (ispunct(*s) || isspace(*s))) ) - return 0; /* 1st word equal */ - else - return toupper(*s)-toupper(*w); /* smaller/greater */ -} + if ((*s == '\0' && + (ispunct((unsigned char)*w) || isspace((unsigned char)*w))) || + (*w == '\0' && + (ispunct((unsigned char)*s) || isspace((unsigned char)*s)))) + return 0; /* 1st word equal */ + else + return toupper((unsigned char)*s) - + toupper((unsigned char)*w); /* smaller/greater */ +} Index: fvwm/libs/ModParse.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/ModParse.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/ModParse.h --- fvwm/libs/ModParse.h +++ fvwm/libs/ModParse.h @@ -13,16 +13,15 @@ #include #include +#include /* for free() */ #include -#include /* for free() */ char *PeekArgument(const char *pstr); char *GetArgument(char **pstr); -int CmpArgument(const char *pstr,char *tok); -int MatchArgument(const char *pstr,char *tok); +int CmpArgument(const char *pstr, char *tok); +int MatchArgument(const char *pstr, char *tok); #define NukeArgument(pstr) free(GetArgument(pstr)) - /* function: FindToken description: find the entry of type 'struct_entry' @@ -33,44 +32,12 @@ int MatchArgument(const char *pstr,char *tok); table must be sorted in ascending order for FindToken. */ -#define FindToken(key,table,struct_entry) \ - (struct_entry *) bsearch(key, \ - (char *)(table), \ - sizeof(table) / sizeof(struct_entry), \ - sizeof(struct_entry), \ - XCmpToken) - -int XCmpToken(); /* (char *s, char **t); but avoid compiler warning */ - /* needed by (L)FindToken */ - -#if 0 -/* e.g: */ - - struct entry /* these are stored in the table */ - { char *token; - /* ... */ /* any info */ - }; - - struct entry table[] = { /* ... */ }; /* define entries here */ - - char *word = GetArgument( /* ... */); - entry_ptr = FindToken(word,table,struct entry); - - (struct token *)bsearch("Style", - (char *)table, sizeof (table)/sizeof (struct entry), - sizeof(struct entry), CmpToken); -#endif /* 0 */ +#define FindToken(key, table, struct_entry) \ + (struct_entry *)bsearch(key, (char *)(table), \ + sizeof(table) / sizeof(struct_entry), sizeof(struct_entry), \ + XCmpToken) -#if 0 -/* Note that lfind() is not part of the ANSI standard. This is never used - * currently; I think we should just keep it that way... - */ -# define LFindToken(key,table,struct_entry) \ - (struct_entry *) lfind(key, \ - (char *)(table), \ - sizeof(table) / sizeof(struct_entry), \ - sizeof(struct_entry), \ - XCmpToken) -#endif /* 0 */ +int XCmpToken(const void *s, const void *t); +/* needed by (L)FindToken */ -#endif /* MODPARSE_H */ +#endif /* MODPARSE_H */ Index: fvwm/libs/Module.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Module.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Module.c --- fvwm/libs/Module.c +++ fvwm/libs/Module.c @@ -1,17 +1,15 @@ /* ** Module.c: code for modules to communicate with fvwm */ -#include "config.h" +#include "../fvwm/module.h" -#include -#include #include - #include +#include +#include +#include "config.h" #include "fvwmlib.h" -#include "../fvwm/module.h" - /************************************************************************ * @@ -30,43 +28,40 @@ * body is a malloc'ed space which needs to be freed * **************************************************************************/ -int ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body) +int +ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body) { - int count,total,count2,body_length; - char *cbody; - extern RETSIGTYPE DeadPipe(int); - - errno = 0; - if((count = read(fd,header,HEADER_SIZE*sizeof(unsigned long))) >0) - { - if(header[0] == START_FLAG) - { - body_length = header[2]-HEADER_SIZE; - *body = (unsigned long *) - safemalloc(body_length * sizeof(unsigned long)); - cbody = (char *)(*body); - total = 0; - while(total < body_length*sizeof(unsigned long)) - { - errno = 0; - if((count2= - read(fd,&cbody[total], - body_length*sizeof(unsigned long)-total)) >0) - { - total += count2; - } - else if(count2 < 0) - { - DeadPipe(errno); - } - } - } - else - count = 0; - } - if(count <= 0) - DeadPipe(errno); - return count; + int count, total, count2, body_length; + char *cbody; + extern void DeadPipe(int); + + errno = 0; + if ((count = read(fd, header, HEADER_SIZE * sizeof(unsigned long))) > + 0) { + if (header[0] == START_FLAG) { + if (header[2] < HEADER_SIZE) + return -1; + body_length = header[2] - HEADER_SIZE; + *body = (unsigned long *)xmalloc( + body_length * sizeof(unsigned long)); + cbody = (char *)(*body); + total = 0; + while (total < body_length * sizeof(unsigned long)) { + errno = 0; + if ((count2 = read(fd, &cbody[total], + body_length * sizeof(unsigned long) - + total)) > 0) { + total += count2; + } else if (count2 < 0) { + DeadPipe(errno); + } + } + } else + count = 0; + } + if (count <= 0) + DeadPipe(errno); + return count; } /************************************************************************ @@ -74,23 +69,23 @@ int ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body) * SendText - Sends arbitrary text/command back to fvwm * ***********************************************************************/ -void SendText(int *fd,char *message,unsigned long window) +void +SendText(int *fd, char *message, unsigned long window) { - int w; + int w; - if(message != NULL) - { - write(fd[0],&window, sizeof(unsigned long)); + if (message != NULL) { + write(fd[0], &window, sizeof(unsigned long)); - w=strlen(message); - write(fd[0],&w,sizeof(int)); - if (w) - write(fd[0],message,w); + w = strlen(message); + write(fd[0], &w, sizeof(int)); + if (w) + write(fd[0], message, w); - /* keep going */ - w = 1; - write(fd[0],&w,sizeof(int)); - } + /* keep going */ + w = 1; + write(fd[0], &w, sizeof(int)); + } } /*************************************************************************** @@ -98,12 +93,13 @@ void SendText(int *fd,char *message,unsigned long window) * Sets the which-message-types-do-I-want mask for modules * **************************************************************************/ -void SetMessageMask(int *fd, unsigned long mask) +void +SetMessageMask(int *fd, unsigned long mask) { - char set_mask_mesg[50]; + char set_mask_mesg[50]; - snprintf(set_mask_mesg, sizeof(set_mask_mesg), "SET_MASK %lu\n",mask); - SendText(fd,set_mask_mesg,0); + snprintf(set_mask_mesg, sizeof(set_mask_mesg), "SET_MASK %lu\n", mask); + SendText(fd, set_mask_mesg, 0); } /*************************************************************************** @@ -116,50 +112,48 @@ void SetMessageMask(int *fd, unsigned long mask) * input area. This could have led to the creation of a core file. Added * "body_size" to keep it in bounds. **************************************************************************/ -void GetConfigLine(int *fd, char **tline) +void +GetConfigLine(int *fd, char **tline) { - static int first_pass = 1; - int count,done = 0; - int body_size; - static char *line = NULL; - unsigned long header[HEADER_SIZE]; - - if(line != NULL) - free(line); - - if(first_pass) - { - SendInfo(fd,"Send_ConfigInfo",0); - first_pass = 0; - } - - while(!done) - { - count = ReadFvwmPacket(fd[1],header,(unsigned long **)&line); - /* DB(("Packet count is %d", count)); */ - if (count <= 0) - *tline = NULL; - else { - *tline = &line[3*sizeof(long)]; - body_size = header[2]-HEADER_SIZE; - /* DB(("Config line (%d): `%s'", body_size, body_size ? *tline : "")); */ - while((body_size > 0) - && isspace(**tline)) { - (*tline)++; - --body_size; - } - } - -/* fprintf(stderr,"%x %x\n",header[1],M_END_CONFIG_INFO);*/ - if(header[1] == M_CONFIG_INFO) - done = 1; - else if(header[1] == M_END_CONFIG_INFO) - { - done = 1; - if(line != NULL) - free(line); - line = NULL; - *tline = NULL; - } - } + static int first_pass = 1; + int count, done = 0; + int body_size; + static char *line = NULL; + unsigned long header[HEADER_SIZE]; + + if (line != NULL) + free(line); + + if (first_pass) { + SendInfo(fd, "Send_ConfigInfo", 0); + first_pass = 0; + } + + while (!done) { + count = ReadFvwmPacket(fd[1], header, (unsigned long **)&line); + /* DB(("Packet count is %d", count)); */ + if (count <= 0) + *tline = NULL; + else { + *tline = &line[3 * sizeof(long)]; + body_size = header[2] - HEADER_SIZE; + /* DB(("Config line (%d): `%s'", body_size, body_size ? + * *tline : "")); */ + while ((body_size > 0) && isspace(**tline)) { + (*tline)++; + --body_size; + } + } + + /* fprintf(stderr,"%x %x\n",header[1],M_END_CONFIG_INFO);*/ + if (header[1] == M_CONFIG_INFO) + done = 1; + else if (header[1] == M_END_CONFIG_INFO) { + done = 1; + if (line != NULL) + free(line); + line = NULL; + *tline = NULL; + } + } } Index: fvwm/libs/Parse.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Parse.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Parse.c --- fvwm/libs/Parse.c +++ fvwm/libs/Parse.c @@ -2,11 +2,11 @@ ** Parse.c: routines for parsing in fvwm & modules */ -#include "config.h" - #include -#include #include +#include + +#include "config.h" #include "fvwmlib.h" /* If the string s begins with a quote chracter SkipQuote returns a pointer @@ -30,48 +30,43 @@ * * The defaults are used if NULL is passed for the corresponding string. */ -char *SkipQuote(char *s, const char *qlong, const char *qstart, - const char *qend) +char * +SkipQuote(char *s, const char *qlong, const char *qstart, const char *qend) { - char *t; - - if (s == NULL || *s == 0) - return s; - if (!qlong) - qlong = "\"'`"; - if (!qstart) - qstart = ""; - if (!qend) - qend = ""; - - if (*s == '\\' && s[1] != 0) - return s+2; - else if (*qlong && (t = strchr(qlong, *s))) - { - char c = *t; - - s++; - while(*s && *s != c) - { - /* Skip over escaped text, ie \quote */ - if(*s == '\\' && *(s+1) != 0) - s++; - s++; - } - if(*s == c) - s++; - return s; - } - else if (*qstart && (t = strchr(qstart, *s))) - { - char c = *((t - qstart) + qend); - - while (*s && *s != c) - s = SkipQuote(s, qlong, "", ""); - return (*s == *t) ? ++s : s; - } - else - return ++s; + char *t; + + if (s == NULL || *s == 0) + return s; + if (!qlong) + qlong = "\"'`"; + if (!qstart) + qstart = ""; + if (!qend) + qend = ""; + + if (*s == '\\' && s[1] != 0) + return s + 2; + else if (*qlong && (t = strchr(qlong, *s))) { + char c = *t; + + s++; + while (*s && *s != c) { + /* Skip over escaped text, ie \quote */ + if (*s == '\\' && *(s + 1) != 0) + s++; + s++; + } + if (*s == c) + s++; + return s; + } else if (*qstart && (t = strchr(qstart, *s))) { + char c = *((t - qstart) + qend); + + while (*s && *s != c) + s = SkipQuote(s, qlong, "", ""); + return (*s == *t) ? ++s : s; + } else + return ++s; } /* Returns a string up to the first character from the string delims in a @@ -79,27 +74,27 @@ char *SkipQuote(char *s, const char *qlong, const char *qstart, * returned string. The returned string is stored in *sout, the return value * of this call is a pointer to the first character after the delimiter or * to the terminating '\0'. Quoting is handled like in SkipQuote. */ -char *GetQuotedString(char *sin, char **sout, const char *delims, - const char *qlong, const char *qstart, const char *qend) +char * +GetQuotedString(char *sin, char **sout, const char *delims, const char *qlong, + const char *qstart, const char *qend) { - char *t = sin; - unsigned int len; - - if (!sout || !sin) - return NULL; - - while (*t && !strchr(delims, *t)) - t = SkipQuote(t, qlong, qstart, qend); - len = t - sin; - *sout = (char *)safemalloc(len + 1); - memcpy(*sout, sin, len); - (*sout)[len] = 0; - if (*t) - t++; - - return t; -} + char *t = sin; + unsigned int len; + + if (!sout || !sin) + return NULL; + + while (*t && !strchr(delims, *t)) + t = SkipQuote(t, qlong, qstart, qend); + len = t - sin; + *sout = (char *)xmalloc(len + 1); + memcpy(*sout, sin, len); + (*sout)[len] = 0; + if (*t) + t++; + return t; +} /* ** PeekToken: returns next token from string, leaving string intact @@ -111,117 +106,114 @@ char *GetQuotedString(char *sin, char **sout, const char *delims, ** must be escaped too, if you want one... (\\). Tokens may be up ** to MAX_TOKEN_LENGTH in size. */ -char *PeekToken(const char *pstr) +char * +PeekToken(const char *pstr) { - char *tok=NULL; - const char* p; - char bc=0,be=0,tmptok[MAX_TOKEN_LENGTH]; - int len=0; - - if (!pstr) - return NULL; - - p=pstr; - EatWS(p); /* skip leading space */ - if (*p) - { - if (IsQuote(*p) || IsBlockStart(*p)) /* quoted string or block start? */ - { - bc = *p; /* save block start char */ - p++; - } - /* find end of token */ - while (*p && len < MAX_TOKEN_LENGTH) - { - /* first, check stop conditions based on block or normal token */ - if (bc) - { - if ((IsQuote(*p) && bc == *p) || IsBlockEnd(*p,bc)) - { - be = *p; - break; - } - } - else /* normal token */ - { - if (isspace((unsigned char)*p) || *p == ',') - break; - } - - if (*p == '\\' && *(p+1)) /* if \, copy next char verbatim */ - p++; - tmptok[len] = *p; - len++; - p++; - } - - /* sanity checks: */ - if (bc && !be) /* did we have block start, but not end? */ - { - /* should yell about this */ - return NULL; - } - - if (len) - { - tok = (char *)malloc(len+1); - strncpy(tok,tmptok,len); - tok[len]='\0'; - } - } - - return tok; + char *tok = NULL; + const char *p; + char bc = 0, be = 0, tmptok[MAX_TOKEN_LENGTH]; + int len = 0; + + if (!pstr) + return NULL; + + p = pstr; + EatWS(p); /* skip leading space */ + if (*p) { + if (IsQuote(*p) || + IsBlockStart(*p)) { /* quoted string or block start? */ + bc = *p; /* save block start char */ + p++; + } + /* find end of token */ + while (*p && len < MAX_TOKEN_LENGTH) { + /* first, check stop conditions based on block or normal + * token */ + if (bc) { + if ((IsQuote(*p) && bc == *p) || + IsBlockEnd(*p, bc)) { + be = *p; + break; + } + } else /* normal token */ { + if (isspace((unsigned char)*p) || *p == ',') + break; + } + + if (*p == '\\' && + *(p + 1)) /* if \, copy next char verbatim */ + p++; + tmptok[len] = *p; + len++; + p++; + } + + /* sanity checks: */ + if (bc && !be) { /* did we have block start, but not end? */ + /* should yell about this */ + return NULL; + } + + if (len) { + tok = (char *)malloc(len + 1); + strncpy(tok, tmptok, len); + tok[len] = '\0'; + } + } + + return tok; } /* ** CmpToken: does case-insensitive compare on next token in string, leaving ** string intact (return code like strcmp) */ -int CmpToken(const char *pstr,char *tok) +int +CmpToken(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekToken(pstr); - if (ntok) - { - rc = strcasecmp(tok,ntok); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekToken(pstr); + if (ntok) { + rc = strcasecmp(tok, ntok); + free(ntok); + } + return rc; } /* ** MatchToken: does case-insensitive compare on next token in string, leaving ** string intact (returns true if matches, false otherwise) */ -int MatchToken(const char *pstr,char *tok) +int +MatchToken(const char *pstr, char *tok) { - int rc=0; - char *ntok=PeekToken(pstr); - if (ntok) - { - rc = (strcasecmp(tok,ntok)==0); - free(ntok); - } - return rc; + int rc = 0; + char *ntok = PeekToken(pstr); + if (ntok) { + rc = (strcasecmp(tok, ntok) == 0); + free(ntok); + } + return rc; } /* ** NukeToken: removes next token from string */ -void NukeToken(char **pstr) +void +NukeToken(char **pstr) { - char *tok; - char *next; - char *temp = NULL; - - next = GetNextToken(*pstr, &tok); - if (next != NULL) - temp = strdup(next); - if (pstr && *pstr) - free(*pstr); - *pstr = temp; - if (tok) - free(tok); + char *tok; + char *next; + char *temp = NULL; + + next = GetNextToken(*pstr, &tok); + if (next != NULL) + temp = strdup(next); + if (pstr && *pstr) + free(*pstr); + *pstr = temp; + if (tok) + free(tok); } /**************************************************************************** @@ -243,128 +235,114 @@ void NukeToken(char **pstr) * characters (spaces are skipped before a token, delimiters are not). * **************************************************************************/ -char *DoGetNextToken(char *indata, char **token, char *spaces, char *delims, - char *out_delim) +char * +DoGetNextToken( + char *indata, char **token, char *spaces, char *delims, char *out_delim) { - char *t, *start, *end, *text; - int snum; - int dnum; - - snum = (spaces) ? strlen(spaces) : 0; - dnum = (delims) ? strlen(delims) : 0; - if(indata == NULL) - { - if (out_delim) - *out_delim = '\0'; - *token = NULL; - return NULL; - } - t = indata; - while ( (*t != 0) && - ( isspace((unsigned char)*t) || - (snum && - strchr(spaces, *t)) ) ) - t++; - start = t; - while ( (*t != 0) && - !( isspace((unsigned char)*t) || - (snum && - strchr(spaces, *t)) || - (dnum && - strchr(delims, *t)) ) ) - { - /* Check for qouted text */ - if (IsQuote(*t)) - { - char c = *t; - - t++; - while((*t != c)&&(*t != 0)) - { - /* Skip over escaped text, ie \quote */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; - } - if(*t == c) - t++; + char *t, *start, *end, *text; + int snum; + int dnum; + + snum = (spaces) ? strlen(spaces) : 0; + dnum = (delims) ? strlen(delims) : 0; + if (indata == NULL) { + if (out_delim) + *out_delim = '\0'; + *token = NULL; + return NULL; } - else - { - /* Skip over escaped text, ie \" or \space */ - if((*t == '\\')&&(*(t+1) != 0)) - t++; - t++; + t = indata; + while ((*t != 0) && + (isspace((unsigned char)*t) || (snum && strchr(spaces, *t)))) + t++; + start = t; + while ((*t != 0) && + !(isspace((unsigned char)*t) || (snum && strchr(spaces, *t)) || + (dnum && strchr(delims, *t)))) { + /* Check for qouted text */ + if (IsQuote(*t)) { + char c = *t; + + t++; + while ((*t != c) && (*t != 0)) { + /* Skip over escaped text, ie \quote */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } + if (*t == c) + t++; + } else { + /* Skip over escaped text, ie \" or \space */ + if ((*t == '\\') && (*(t + 1) != 0)) + t++; + t++; + } } - } - end = t; - if (out_delim) - *out_delim = *end; - - text = safemalloc(end-start+1); - *token = text; - - /* copy token */ - while(start < end) - { - /* Check for qouted text */ - if(IsQuote(*start)) - { - char c = *start; - start++; - while((*start != c)&&(*start != 0)) - { - /* Skip over escaped text, ie \" or \space */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; - } - if(*start == c) - start++; + end = t; + if (out_delim) + *out_delim = *end; + + text = xmalloc(end - start + 1); + *token = text; + + /* copy token */ + while (start < end) { + /* Check for qouted text */ + if (IsQuote(*start)) { + char c = *start; + start++; + while ((*start != c) && (*start != 0)) { + /* Skip over escaped text, ie \" or \space */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } + if (*start == c) + start++; + } else { + /* Skip over escaped text, ie \" or \space */ + if ((*start == '\\') && (*(start + 1) != 0)) + start++; + *text++ = *start++; + } } - else - { - /* Skip over escaped text, ie \" or \space */ - if((*start == '\\')&&(*(start+1) != 0)) - start++; - *text++ = *start++; + *text = 0; + if (*end != 0) + end++; + + if (**token == 0) { + free(*token); + *token = NULL; } - } - *text = 0; - if(*end != 0) - end++; - - if (**token == 0) - { - free(*token); - *token = NULL; - } - return end; + return end; } -char *GetNextToken(char *indata, char **token) +char * +GetNextToken(char *indata, char **token) { - return DoGetNextToken(indata, token, NULL, NULL, NULL); + return DoGetNextToken(indata, token, NULL, NULL, NULL); } -char *GetNextOption(char *indata, char **token) +char * +GetNextOption(char *indata, char **token) { - return DoGetNextToken(indata, token, ",", NULL, NULL); + return DoGetNextToken(indata, token, ",", NULL, NULL); } -char *SkipNTokens(char *indata, unsigned int n) +char * +SkipNTokens(char *indata, unsigned int n) { - char *tmp; - char *junk; - - tmp = indata; - for ( ; n > 0 ; n--) - { - tmp = GetNextToken(tmp, &junk); - if (junk) - free(junk); - } - return tmp; + char *tmp; + char *junk; + + tmp = indata; + for (; n > 0; n--) { + tmp = GetNextToken(tmp, &junk); + if (junk) + free(junk); + } + return tmp; } /**************************************************************************** @@ -378,28 +356,28 @@ char *SkipNTokens(char *indata, unsigned int n) * returns "Geometry" in token. * **************************************************************************/ -char *GetModuleResource(char *indata, char **resource, char *module_name) +char * +GetModuleResource(char *indata, char **resource, char *module_name) { - char *tmp; - char *next; - - if (!module_name) - { - *resource = NULL; - return indata; - } - next = GetNextToken(indata, &tmp); - if (!tmp) - return next; - - if (tmp[0] != '*' || strncasecmp(tmp+1, module_name, strlen(module_name))) - { - *resource = NULL; - return indata; - } - CopyString(resource, tmp+1+strlen(module_name)); - free(tmp); - return next; + char *tmp; + char *next; + + if (!module_name) { + *resource = NULL; + return indata; + } + next = GetNextToken(indata, &tmp); + if (!tmp) + return next; + + if (tmp[0] != '*' || + strncasecmp(tmp + 1, module_name, strlen(module_name))) { + *resource = NULL; + return indata; + } + CopyString(resource, tmp + 1 + strlen(module_name)); + free(tmp); + return next; } /**************************************************************************** @@ -409,27 +387,27 @@ char *GetModuleResource(char *indata, char **resource, char *module_name) * If ret_action is non-NULL, a pointer to the next token is returned there. * **************************************************************************/ -int GetIntegerArguments(char *action, char **ret_action, int retvals[],int num) +int +GetIntegerArguments(char *action, char **ret_action, int retvals[], int num) { - int i; - char *token; - - for (i = 0; i < num && action; i++) - { - action = GetNextToken(action, &token); - if (token == NULL) - break; - if (sscanf(token, "%d", &(retvals[i])) != 1) - break; - free(token); - token = NULL; - } - if (token) - free(token); - if (ret_action != NULL) - *ret_action = action; - - return i; + int i; + char *token; + + for (i = 0; i < num && action; i++) { + action = GetNextToken(action, &token); + if (token == NULL) + break; + if (sscanf(token, "%d", &(retvals[i])) != 1) + break; + free(token); + token = NULL; + } + if (token) + free(token); + if (ret_action != NULL) + *ret_action = action; + + return i; } /*************************************************************************** @@ -446,35 +424,33 @@ int GetIntegerArguments(char *action, char **ret_action, int retvals[],int num) * in token after the match. * **************************************************************************/ -int GetTokenIndex(char *token, char *list[], int len, char **next) +int +GetTokenIndex(char *token, char *list[], int len, char **next) { - int i; - int l; - int k; - - if (!token || !list) - { - if (next) - *next = NULL; - return -1; - } - l = (len) ? len : strlen(token); - for (i = 0; list[i] != NULL; i++) - { - k = strlen(list[i]); - if (len < 0) - l = k; - if (len == 0 && k != l) - continue; - if (!strncasecmp(token, list[i], l)) - break; - } - if (next) - { - *next = (list[i]) ? token + l : token; - } - - return (list[i]) ? i : -1; + int i; + int l; + int k; + + if (!token || !list) { + if (next) + *next = NULL; + return -1; + } + l = (len) ? len : strlen(token); + for (i = 0; list[i] != NULL; i++) { + k = strlen(list[i]); + if (len < 0) + l = k; + if (len == 0 && k != l) + continue; + if (!strncasecmp(token, list[i], l)) + break; + } + if (next) { + *next = (list[i]) ? token + l : token; + } + + return (list[i]) ? i : -1; } /*************************************************************************** @@ -485,96 +461,95 @@ int GetTokenIndex(char *token, char *list[], int len, char **next) * token (just like the return value of GetNextToken). * **************************************************************************/ -char *GetNextTokenIndex(char *action, char *list[], int len, int *index) +char * +GetNextTokenIndex(char *action, char *list[], int len, int *index) { - char *token; - char *next; - - if (!index) - return action; - - next = GetNextToken(action, &token); - if (!token) - { - *index = -1; - return action; - } - *index = GetTokenIndex(token, list, len, NULL); - free(token); - - return (*index == -1) ? action : next; -} + char *token; + char *next; + if (!index) + return action; -int GetRectangleArguments(char *action, int *width, int *height) + next = GetNextToken(action, &token); + if (!token) { + *index = -1; + return action; + } + *index = GetTokenIndex(token, list, len, NULL); + free(token); + + return (*index == -1) ? action : next; +} + +int +GetRectangleArguments(char *action, int *width, int *height) { - char *token; - int n; + char *token; + int n; - GetNextToken(action, &token); - if (!token) - return 0; - /* now try MxN style number, specifically for DeskTopSize: */ - n = sscanf(token, "%d%*c%d", width, height); - free(token); + GetNextToken(action, &token); + if (!token) + return 0; + /* now try MxN style number, specifically for DeskTopSize: */ + n = sscanf(token, "%d%*c%d", width, height); + free(token); - return (n == 2) ? 2 : 0; + return (n == 2) ? 2 : 0; } /* unit_io is input as well as output. If action has a postfix 'p' or 'P', * *unit_io is set to 100, otherwise it is left untouched. */ -int GetOnePercentArgument(char *action, int *value, int *unit_io) +int +GetOnePercentArgument(char *action, int *value, int *unit_io) { - unsigned int len; - char *token; - int n; - - *value = 0; - if (!action) - return 0; - GetNextToken(action, &token); - if (!token) - return 0; - - len = strlen(token); - /* token never contains an empty string, so this is ok */ - if (token[len - 1] == 'p' || token[len - 1] == 'P') - { - *unit_io = 100; - token[len - 1] = '\0'; - } - n = sscanf(token, "%d", value); - - free(token); - return n; -} + unsigned int len; + char *token; + int n; + + *value = 0; + if (!action) + return 0; + GetNextToken(action, &token); + if (!token) + return 0; + + len = strlen(token); + /* token never contains an empty string, so this is ok */ + if (token[len - 1] == 'p' || token[len - 1] == 'P') { + *unit_io = 100; + token[len - 1] = '\0'; + } + n = sscanf(token, "%d", value); + free(token); + return n; +} -int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit) +int +GetTwoPercentArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit) { - char *tok1, *tok2; - int n = 0; - - *val1 = 0; - *val2 = 0; - - action = GetNextToken(action, &tok1); - if (!tok1) - return 0; - GetNextToken(action, &tok2); - if (GetOnePercentArgument(tok2, val2, val2_unit) == 1 && - GetOnePercentArgument(tok1, val1, val1_unit) == 1) - { - free(tok1); - free(tok2); - return 2; - } - - /* now try MxN style number, specifically for DeskTopSize: */ - n = GetRectangleArguments(tok1, val1, val2); - free(tok1); - if (tok2) - free(tok2); - return n; + char *tok1, *tok2; + int n = 0; + + *val1 = 0; + *val2 = 0; + + action = GetNextToken(action, &tok1); + if (!tok1) + return 0; + GetNextToken(action, &tok2); + if (GetOnePercentArgument(tok2, val2, val2_unit) == 1 && + GetOnePercentArgument(tok1, val1, val1_unit) == 1) { + free(tok1); + free(tok2); + return 2; + } + + /* now try MxN style number, specifically for DeskTopSize: */ + n = GetRectangleArguments(tok1, val1, val2); + free(tok1); + if (tok2) + free(tok2); + return n; } Index: fvwm/libs/Picture.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Picture.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Picture.c --- fvwm/libs/Picture.c +++ fvwm/libs/Picture.c @@ -1,4 +1,4 @@ - /**************************************************************************** +/**************************************************************************** * This module is all original code * by Rob Nation * Copyright 1993, Robert Nation @@ -31,189 +31,188 @@ * ****************************************************************************/ -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" #ifdef XPM /* static function prototypes */ -static void c100_init_base_table (); /* prototype */ -static void c200_substitute_color(char **,int); /* prototype */ +static void c100_init_base_table(); /* prototype */ +static void c200_substitute_color(char **, int); /* prototype */ static void c300_color_to_rgb(char *, XColor *); /* prototype */ static double c400_distance(XColor *, XColor *); /* prototype */ #endif #include "fvwmlib.h" - -static FvwmPicture *PictureList=NULL; +static FvwmPicture *PictureList = NULL; Colormap PictureCMap; -Display *PictureSaveDisplay; /* Save area for display pointer */ +Display *PictureSaveDisplay; /* Save area for display pointer */ /* This routine called during fvwm and some modules initialization */ -void InitPictureCMap(Display *dpy,Window Root) +void +InitPictureCMap(Display *dpy, Window Root) { - XWindowAttributes root_attr; - PictureSaveDisplay = dpy; /* save for latter */ - XGetWindowAttributes(dpy,Root,&root_attr); - PictureCMap=root_attr.colormap; + XWindowAttributes root_attr; + PictureSaveDisplay = dpy; /* save for latter */ + XGetWindowAttributes(dpy, Root, &root_attr); + PictureCMap = root_attr.colormap; } - -FvwmPicture *LoadPicture(Display *dpy,Window Root,char *path, int color_limit) +FvwmPicture * +LoadPicture(Display *dpy, Window Root, char *path, int color_limit) { - int l; - FvwmPicture *p; + int l; + FvwmPicture *p; #ifdef XPM - XpmAttributes xpm_attributes; - int rc; - XpmImage my_image = {0}; + XpmAttributes xpm_attributes; + int rc; + XpmImage my_image = {0}; #endif - p=(FvwmPicture*)safemalloc(sizeof(FvwmPicture)); - p->count=1; - p->name=path; - p->next=NULL; + p = (FvwmPicture *)xmalloc(sizeof(FvwmPicture)); + p->count = 1; + p->name = path; + p->next = NULL; #ifdef XPM - /* Try to load it as an X Pixmap first */ - xpm_attributes.colormap=PictureCMap; - xpm_attributes.closeness=40000; /* Allow for "similar" colors */ - xpm_attributes.valuemask= - XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; - - rc =XpmReadFileToXpmImage(path, &my_image, NULL); - if (rc == XpmSuccess) { - color_reduce_pixmap(&my_image, color_limit); - rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, - &p->picture,&p->mask, - &xpm_attributes); - if (rc == XpmSuccess) { - p->width = my_image.width; - p->height = my_image.height; - XpmFreeXpmImage(&my_image); - p->depth = DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy)); - return p; - } - XpmFreeXpmImage(&my_image); - } + /* Try to load it as an X Pixmap first */ + xpm_attributes.colormap = PictureCMap; + xpm_attributes.closeness = 40000; /* Allow for "similar" colors */ + xpm_attributes.valuemask = + XpmSize | XpmReturnPixels | XpmColormap | XpmCloseness; + + rc = XpmReadFileToXpmImage(path, &my_image, NULL); + if (rc == XpmSuccess) { + color_reduce_pixmap(&my_image, color_limit); + rc = XpmCreatePixmapFromXpmImage(dpy, Root, &my_image, + &p->picture, &p->mask, &xpm_attributes); + if (rc == XpmSuccess) { + p->width = my_image.width; + p->height = my_image.height; + XpmFreeXpmImage(&my_image); + p->depth = + DefaultDepthOfScreen(DefaultScreenOfDisplay(dpy)); + return p; + } + XpmFreeXpmImage(&my_image); + } #endif - /* If no XPM support, or XPM loading failed, try bitmap */ - if(XReadBitmapFile(dpy,Root,path,&p->width,&p->height,&p->picture,&l,&l) - == BitmapSuccess) - { - p->depth = 0; - p->mask = None; - return p; - } - - free(p); - return NULL; + /* If no XPM support, or XPM loading failed, try bitmap */ + if (XReadBitmapFile(dpy, Root, path, &p->width, &p->height, &p->picture, + &l, &l) == BitmapSuccess) { + p->depth = 0; + p->mask = None; + return p; + } + + free(p); + return NULL; } -FvwmPicture *GetPicture(Display *dpy,Window Root,char *IconPath, - char *PixmapPath, char *name, int color_limit) +FvwmPicture * +GetPicture(Display *dpy, Window Root, char *IconPath, char *PixmapPath, + char *name, int color_limit) { - char *path; - FvwmPicture *p; - - if(!(path=findIconFile(name,PixmapPath,R_OK))) - if(!(path=findIconFile(name,IconPath,R_OK))) - return NULL; - p = LoadPicture(dpy,Root,path, color_limit); - if (!p) - free(path); - return p; + char *path; + FvwmPicture *p; + + if (!(path = findIconFile(name, PixmapPath, R_OK))) + if (!(path = findIconFile(name, IconPath, R_OK))) + return NULL; + p = LoadPicture(dpy, Root, path, color_limit); + if (!p) + free(path); + return p; } -FvwmPicture *CachePicture(Display *dpy,Window Root,char *IconPath,char *PixmapPath, - char *name, int color_limit) +FvwmPicture * +CachePicture(Display *dpy, Window Root, char *IconPath, char *PixmapPath, + char *name, int color_limit) { - char *path; - FvwmPicture *p=PictureList; + char *path; + FvwmPicture *p = PictureList; - /* First find the full pathname */ + /* First find the full pathname */ #ifdef XPM - if(!(path=findIconFile(name,PixmapPath,R_OK))) - if(!(path=findIconFile(name,IconPath,R_OK))) - return NULL; + if (!(path = findIconFile(name, PixmapPath, R_OK))) + if (!(path = findIconFile(name, IconPath, R_OK))) + return NULL; #else - /* Ignore the given pixmap path when compiled without XPM support */ - if(!(path=findIconFile(name,IconPath,R_OK))) - return NULL; + /* Ignore the given pixmap path when compiled without XPM support */ + if (!(path = findIconFile(name, IconPath, R_OK))) + return NULL; #endif - /* See if the picture is already cached */ - while(p) - { - register char *p1, *p2; - - for (p1=path, p2=p->name; *p1 && *p2; ++p1, ++p2) - if (*p1 != *p2) - break; - - if(!*p1 && !*p2) /* We have found a picture with the wanted name */ - { - p->count++; /* Put another weight on the picture */ - free(path); - return p; + /* See if the picture is already cached */ + while (p) { + register char *p1, *p2; + + for (p1 = path, p2 = p->name; *p1 && *p2; ++p1, ++p2) + if (*p1 != *p2) + break; + + if (!*p1 && + !*p2) { /* We have found a picture with the wanted name */ + p->count++; /* Put another weight on the picture */ + free(path); + return p; + } + p = p->next; } - p=p->next; - } - - /* Not previously cached, have to load it ourself. Put it first in list */ - p=LoadPicture(dpy,Root,path, color_limit); - if(p) - { - p->next=PictureList; - PictureList=p; - } - else - free(path); - return p; -} + /* Not previously cached, have to load it ourself. Put it first in list + */ + p = LoadPicture(dpy, Root, path, color_limit); + if (p) { + p->next = PictureList; + PictureList = p; + } else + free(path); + return p; +} -void DestroyPicture(Display *dpy,FvwmPicture *p) +void +DestroyPicture(Display *dpy, FvwmPicture *p) { - FvwmPicture *q=PictureList; - - if (!p) /* bag out if NULL */ - return; - if(--(p->count)>0) /* Remove a weight, still too heavy? */ - return; - - /* Let it fly */ - if(p->name!=NULL) - free(p->name); - if(p->picture!=None) - XFreePixmap(dpy,p->picture); - if(p->mask!=None) - XFreePixmap(dpy,p->mask); - - /* Link it out of the list (it might not be there) */ - if(p==q) /* in head? simple */ - PictureList=p->next; - else - { - while(q && q->next!=p) /* fast forward until end or found */ - q=q->next; - if(q) /* not end? means we found it in there, possibly at end */ - q->next=p->next; /* link around it */ - } - free(p); + FvwmPicture *q = PictureList; + + if (!p) /* bag out if NULL */ + return; + if (--(p->count) > 0) /* Remove a weight, still too heavy? */ + return; + + /* Let it fly */ + if (p->name != NULL) + free(p->name); + if (p->picture != None) + XFreePixmap(dpy, p->picture); + if (p->mask != None) + XFreePixmap(dpy, p->mask); + + /* Link it out of the list (it might not be there) */ + if (p == q) /* in head? simple */ + PictureList = p->next; + else { + while (q && q->next != p) /* fast forward until end or found */ + q = q->next; + if (q) /* not end? means we found it in there, possibly at end + */ + q->next = p->next; /* link around it */ + } + free(p); } /**************************************************************************** @@ -225,66 +224,62 @@ void DestroyPicture(Display *dpy,FvwmPicture *p) * Oh well. * ****************************************************************************/ -char *findIconFile(char *icon, char *pathlist, int type) +char * +findIconFile(char *icon, char *pathlist, int type) { - char *path; - char *dir_end; - int l; - size_t pathlen; - - if (!icon) - return NULL; - - l = (pathlist) ? strlen(pathlist) : 0; - pathlen = strlen(icon) + l + 10; - path = safemalloc(pathlen); - *path = '\0'; - if (*icon == '/' || pathlist == NULL || *pathlist == '\0') - { - /* No search if icon begins with a slash */ - /* No search if pathlist is empty */ - strlcpy(path, icon, pathlen); - return path; - } - - /* Search each element of the pathlist for the icon file */ - while ((pathlist)&&(*pathlist)) - { - dir_end = strchr(pathlist, ':'); - if (dir_end != NULL) - { - strncpy(path, pathlist, dir_end - pathlist); - path[dir_end - pathlist] = 0; + char *path; + char *dir_end; + int l; + size_t pathlen; + + if (!icon) + return NULL; + + l = (pathlist) ? strlen(pathlist) : 0; + pathlen = strlen(icon) + l + 10; + path = xmalloc(pathlen); + *path = '\0'; + if (*icon == '/' || pathlist == NULL || *pathlist == '\0') { + /* No search if icon begins with a slash */ + /* No search if pathlist is empty */ + strlcpy(path, icon, pathlen); + return path; } - else - strlcpy(path, pathlist, pathlen); - - strlcat(path, "/", pathlen); - strlcat(path, icon, pathlen); - if (access(path, type) == 0) - return path; - strlcat(path, ".gz", pathlen); - if (access(path, type) == 0) - return path; - - /* Point to next element of the path */ - if(dir_end == NULL) - pathlist = NULL; - else - pathlist = dir_end + 1; - } - /* Hmm, couldn't find the file. Return NULL */ - free(path); - return NULL; -} + /* Search each element of the pathlist for the icon file */ + while ((pathlist) && (*pathlist)) { + dir_end = strchr(pathlist, ':'); + if (dir_end != NULL) { + strncpy(path, pathlist, dir_end - pathlist); + path[dir_end - pathlist] = 0; + } else + strlcpy(path, pathlist, pathlen); + + strlcat(path, "/", pathlen); + strlcat(path, icon, pathlen); + if (access(path, type) == 0) + return path; + strlcat(path, ".gz", pathlen); + if (access(path, type) == 0) + return path; + + /* Point to next element of the path */ + if (dir_end == NULL) + pathlist = NULL; + else + pathlist = dir_end + 1; + } + /* Hmm, couldn't find the file. Return NULL */ + free(path); + return NULL; +} #ifdef XPM /* This structure is used to quickly access the RGB values of the colors */ /* without repeatedly having to transform them. */ typedef struct { - char * c_color; /* Pointer to the name of the color */ - XColor rgb_space; /* rgb color info */ + char *c_color; /* Pointer to the name of the color */ + XColor rgb_space; /* rgb color info */ } Color_Info; /* First thing in base array are colors probably already in the color map @@ -295,188 +290,169 @@ typedef struct { Currently 61 colors in this list. */ static Color_Info base_array[] = { - {"white"}, - {"black"}, - {"grey"}, - {"green"}, - {"blue"}, - {"red"}, - {"cyan"}, - {"yellow"}, - {"magenta"}, - {"DodgerBlue"}, - {"SteelBlue"}, - {"chartreuse"}, - {"wheat"}, - {"turquoise"}, - {"CadetBlue"}, - {"gray87"}, - {"CornflowerBlue"}, - {"YellowGreen"}, - {"NavyBlue"}, - {"MediumBlue"}, - {"plum"}, - {"aquamarine"}, - {"orchid"}, - {"ForestGreen"}, - {"lightyellow"}, - {"brown"}, - {"orange"}, - {"red3"}, - {"HotPink"}, - {"LightBlue"}, - {"gray47"}, - {"pink"}, - {"red4"}, - {"violet"}, - {"purple"}, - {"gray63"}, - {"gray94"}, - {"plum1"}, - {"PeachPuff"}, - {"maroon"}, - {"lavender"}, - {"salmon"}, /* for peachpuff, orange gap */ - {"blue4"}, /* for navyblue/mediumblue gap */ - {"PaleGreen4"}, /* for forestgreen, yellowgreen gap */ - {"#AA7700"}, /* brick, no close named color */ - {"#11EE88"}, /* light green, no close named color */ - {"#884466"}, /* dark brown, no close named color */ - {"#CC8888"}, /* light brick, no close named color */ - {"#EECC44"}, /* gold, no close named color */ - {"#AAAA44"}, /* dull green, no close named color */ - {"#FF1188"}, /* pinkish red */ - {"#992299"}, /* purple */ - {"#CCFFAA"}, /* light green */ - {"#664400"}, /* dark brown*/ - {"#AADD99"}, /* light green */ - {"#66CCFF"}, /* light blue */ - {"#CC2299"}, /* dark red */ - {"#FF11CC"}, /* bright pink */ - {"#11CC99"}, /* grey/green */ - {"#AA77AA"}, /* purple/red */ - {"#EEBB77"} /* orange/yellow */ + {"white"}, {"black"}, {"grey"}, {"green"}, {"blue"}, {"red"}, {"cyan"}, + {"yellow"}, {"magenta"}, {"DodgerBlue"}, {"SteelBlue"}, {"chartreuse"}, + {"wheat"}, {"turquoise"}, {"CadetBlue"}, {"gray87"}, {"CornflowerBlue"}, + {"YellowGreen"}, {"NavyBlue"}, {"MediumBlue"}, {"plum"}, {"aquamarine"}, + {"orchid"}, {"ForestGreen"}, {"lightyellow"}, {"brown"}, {"orange"}, + {"red3"}, {"HotPink"}, {"LightBlue"}, {"gray47"}, {"pink"}, {"red4"}, + {"violet"}, {"purple"}, {"gray63"}, {"gray94"}, {"plum1"}, {"PeachPuff"}, + {"maroon"}, {"lavender"}, {"salmon"}, /* for peachpuff, orange gap */ + {"blue4"}, /* for navyblue/mediumblue gap */ + {"PaleGreen4"}, /* for forestgreen, yellowgreen gap */ + {"#AA7700"}, /* brick, no close named color */ + {"#11EE88"}, /* light green, no close named color */ + {"#884466"}, /* dark brown, no close named color */ + {"#CC8888"}, /* light brick, no close named color */ + {"#EECC44"}, /* gold, no close named color */ + {"#AAAA44"}, /* dull green, no close named color */ + {"#FF1188"}, /* pinkish red */ + {"#992299"}, /* purple */ + {"#CCFFAA"}, /* light green */ + {"#664400"}, /* dark brown*/ + {"#AADD99"}, /* light green */ + {"#66CCFF"}, /* light blue */ + {"#CC2299"}, /* dark red */ + {"#FF11CC"}, /* bright pink */ + {"#11CC99"}, /* grey/green */ + {"#AA77AA"}, /* purple/red */ + {"#EEBB77"} /* orange/yellow */ }; #define NColors (sizeof(base_array) / sizeof(Color_Info)) /* if c_color isn't set, copy it from one of the other colours */ -Bool xpmcolor_require_c_color(XpmColor *p) +Bool +xpmcolor_require_c_color(XpmColor *p) { - if (p->c_color != NULL) - return False; - else if (p->g_color != NULL) - p->c_color = strdup(p->g_color); - else if (p->g4_color != NULL) - p->c_color = strdup(p->g4_color); - else if (p->m_color != NULL) - p->c_color = strdup(p->m_color); - else - p->c_color = strdup("none"); - - return True; + if (p->c_color != NULL) + return False; + else if (p->g_color != NULL) + p->c_color = strdup(p->g_color); + else if (p->g4_color != NULL) + p->c_color = strdup(p->g4_color); + else if (p->m_color != NULL) + p->c_color = strdup(p->m_color); + else + p->c_color = strdup("none"); + + return True; } /* given an xpm, change colors to colors close to the subset above. */ void -color_reduce_pixmap(XpmImage *image,int color_limit) { - int i; - XpmColor *color_table_ptr; - static char base_init = 'n'; - - if (color_limit > 0) { /* If colors to be limited */ - if (base_init == 'n') { /* if base table not created yet */ - c100_init_base_table(); /* init the base table */ - base_init = 'y'; /* remember that its set now. */ - } /* end base table init */ - color_table_ptr = image->colorTable; /* start of xpm color table */ - for(i=0; incolors; i++) { /* all colors in the xpm */ - /* Theres an array for this in the xpm library, but it doesn't - appear to be part of the API. Too bad. dje 01/09/00 */ - char **visual_color = 0; - if (color_table_ptr->c_color) { - visual_color = &color_table_ptr->c_color; - } else if (color_table_ptr->g_color) { - visual_color = &color_table_ptr->g_color; - } else if (color_table_ptr->g4_color) { - visual_color = &color_table_ptr->g4_color; - } else { /* its got to be one of these */ - visual_color = &color_table_ptr->m_color; - } - c200_substitute_color(visual_color,color_limit); - color_table_ptr +=1; /* counter for loop */ - } /* end all colors in xpm */ - } /* end colors limited */ - return; /* return, no rc! */ +color_reduce_pixmap(XpmImage *image, int color_limit) +{ + int i; + XpmColor *color_table_ptr; + static char base_init = 'n'; + + if (color_limit > 0) { /* If colors to be limited */ + if (base_init == 'n') { /* if base table not created yet */ + c100_init_base_table(); /* init the base table */ + base_init = 'y'; /* remember that its set now. */ + } /* end base table init */ + color_table_ptr = + image->colorTable; /* start of xpm color table */ + for (i = 0; i < image->ncolors; + i++) { /* all colors in the xpm */ + /* Theres an array for this in the xpm library, but it + doesn't appear to be part of the API. Too bad. dje + 01/09/00 */ + char **visual_color = 0; + if (color_table_ptr->c_color) { + visual_color = &color_table_ptr->c_color; + } else if (color_table_ptr->g_color) { + visual_color = &color_table_ptr->g_color; + } else if (color_table_ptr->g4_color) { + visual_color = &color_table_ptr->g4_color; + } else { /* its got to be one of these */ + visual_color = &color_table_ptr->m_color; + } + c200_substitute_color(visual_color, color_limit); + color_table_ptr += 1; /* counter for loop */ + } /* end all colors in xpm */ + } /* end colors limited */ + return; /* return, no rc! */ } /* from the color names in the base table, calc rgbs */ static void -c100_init_base_table () { - int i; - for (i=0; ired - target_ptr->red )/655.35) - + SQUARE((double)(base_ptr->green - target_ptr->green)/655.35) - + SQUARE((double)(base_ptr->blue - target_ptr->blue )/655.35); - return dst; +double +c400_distance(XColor *target_ptr, XColor *base_ptr) +{ + register double dst; + dst = SQUARE((double)(base_ptr->red - target_ptr->red) / 655.35) + + SQUARE((double)(base_ptr->green - target_ptr->green) / 655.35) + + SQUARE((double)(base_ptr->blue - target_ptr->blue) / 655.35); + return dst; } #endif /* XPM */ Index: fvwm/libs/Strings.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/Strings.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/Strings.c --- fvwm/libs/Strings.c +++ fvwm/libs/Strings.c @@ -2,10 +2,10 @@ ** Strings.c: various routines for dealing with strings */ +#include #include #include #include -#include #include "fvwmlib.h" @@ -16,102 +16,101 @@ *************************************************************************/ char CatS[256]; -char *CatString3(char *a, char *b, char *c) +char * +CatString3(char *a, char *b, char *c) { - int len = 0; + int len = 0; - if(a != NULL) - len += strlen(a); - if(b != NULL) - len += strlen(b); - if(c != NULL) - len += strlen(c); + if (a != NULL) + len += strlen(a); + if (b != NULL) + len += strlen(b); + if (c != NULL) + len += strlen(c); - if (len > 255) - return NULL; + if (len > 255) + return NULL; - if(a == NULL) - CatS[0] = 0; - else - strlcpy(CatS, a, sizeof(CatS)); - if(b != NULL) - strlcat(CatS, b, sizeof(CatS)); - if(c != NULL) - strlcat(CatS, c, sizeof(CatS)); - return CatS; + if (a == NULL) + CatS[0] = 0; + else + strlcpy(CatS, a, sizeof(CatS)); + if (b != NULL) + strlcat(CatS, b, sizeof(CatS)); + if (c != NULL) + strlcat(CatS, c, sizeof(CatS)); + return CatS; } /*************************************************************************** * A simple routine to copy a string, stripping spaces and mallocing - * space for the new string + * space for the new string ***************************************************************************/ -void CopyString(char **dest, char *source) +void +CopyString(char **dest, char *source) { - int len; - char *start; - - if (source == NULL) - { - *dest = NULL; - return; - } - while(((isspace(*source))&&(*source != '\n'))&&(*source != 0)) - { - source++; - } - len = 0; - start = source; - while((*source != '\n')&&(*source != 0)) - { - len++; - source++; - } - - source--; - while((isspace(*source))&&(*source != 0)&&(len >0)) - { - len--; - source--; - } - *dest = safemalloc(len+1); - strncpy(*dest,start,len); - (*dest)[len]=0; + int len; + char *start; + + if (source == NULL) { + *dest = NULL; + return; + } + while (((isspace(*source)) && (*source != '\n')) && (*source != 0)) { + source++; + } + len = 0; + start = source; + while ((*source != '\n') && (*source != 0)) { + len++; + source++; + } + + source--; + while ((isspace(*source)) && (*source != 0) && (len > 0)) { + len--; + source--; + } + *dest = xmalloc(len + 1); + strncpy(*dest, start, len); + (*dest)[len] = 0; } /**************************************************************************** - * + * * Copies a string into a new, malloc'ed string * Strips leading spaces and trailing spaces and new lines * - ****************************************************************************/ -char *stripcpy(char *source) + ****************************************************************************/ +char * +stripcpy(char *source) { - char *tmp,*ptr; - int len; + char *tmp, *ptr; + int len; - if(source == NULL) - return NULL; + if (source == NULL) + return NULL; - while(isspace(*source)) - source++; - len = strlen(source); - tmp = source + len -1; - while(((isspace(*tmp))||(*tmp == '\n'))&&(tmp >=source)) - { - tmp--; - len--; - } - ptr = safemalloc(len+1); - strncpy(ptr,source,len); - ptr[len]=0; - return ptr; + while (isspace(*source)) + source++; + len = strlen(source); + tmp = source + len - 1; + while (((isspace(*tmp)) || (*tmp == '\n')) && (tmp >= source)) { + tmp--; + len--; + } + ptr = xmalloc(len + 1); + strncpy(ptr, source, len); + ptr[len] = 0; + return ptr; } - -int StrEquals(char *s1,char *s2) + +int +StrEquals(char *s1, char *s2) { - if (!s1 && !s2) - return 1; - if (!s1 || !s2) - return 0; - return (strcasecmp(s1,s2)==0); + if (!s1 && !s2) + return 1; + if (!s1 || !s2) + return 0; + return (strcasecmp(s1, s2) == 0); } Index: fvwm/libs/System.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/System.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/System.c --- fvwm/libs/System.c +++ fvwm/libs/System.c @@ -1,44 +1,27 @@ -/* -** System.c: code for dealing with various OS system call variants -*/ - -#include "config.h" - -#include - -#if HAVE_UNAME #include -#endif +#include +#include "config.h" -/* -** just in case... -*/ #ifndef FD_SETSIZE #define FD_SETSIZE 2048 #endif - -int GetFdWidth(void) +int +GetFdWidth(void) { -#if HAVE_SYSCONF - return min(sysconf(_SC_OPEN_MAX),FD_SETSIZE); -#else - return min(getdtablesize(),FD_SETSIZE); -#endif + return min(sysconf(_SC_OPEN_MAX), FD_SETSIZE); } -/* return a string indicating the OS type (i.e. "Linux", "SINIX-D", ... ) */ -int getostype(char *buf, int max) +int +getostype(char *buf, int max) { -#if HAVE_UNAME - struct utsname sysname; - - if ( uname( &sysname ) >= 0 ) { - strlcpy( buf, sysname.sysname, max); - return 0; - } -#endif - strlcpy (buf,"",max); - return -1; + struct utsname sysname; + + if (uname(&sysname) >= 0) { + strlcpy(buf, sysname.sysname, max); + return 0; + } + strlcpy(buf, "", max); + return -1; } Index: fvwm/libs/XResource.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/XResource.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/XResource.c --- fvwm/libs/XResource.c +++ fvwm/libs/XResource.c @@ -5,107 +5,34 @@ ** file lines) in the same way (Xrm database). */ -#include "config.h" - #include #include #include +#include "config.h" #include "fvwmlib.h" - - -/*************************************************************************** - * If you have a module MyModule and want to parse X resources as well as - * command line options and a config file: - * - *** EXAMPLE ***************************************************************/ -#if 0 -#include - - void main(int argc, char **argv) - { - const char *MyName = "MyModule"; - XrmDatabase db = NULL; - char *value; - char *line; - - /* our private options */ - const XrmOptionDescRec my_opts[] = { - { "-iconic", ".Iconic", XrmoptionNoArg, "any_string" }, - { "-foo", "*bar", XrmoptionSepArg, NULL } - }; - int opt_argc = argc - 6; /* options start at 6th argument for modules */ - char **opt_argv = argv + 6; - - /* ... (open config file, etc.) */ - - /* Get global X resources */ - MergeXResources(NULL, &db, False); - - /* config file descriptor in fd; config file takes precedence over X - * resources (this may not be what you want). */ - for (GetConfigLine(fd, &line); line != NULL; GetConfigLine(fd, &line)) - { - if (!MergeConfigLineResource(&db, line, MyName, '*')) - { - /* Parse other lines here (e.g. "IconPath") */ - } - else - { - /* You may still have to parse the line here yourself (e.g. - * FvwmButtons may have multiple lines for the same resource). */ - } - } - - /* command line takes precedence over all */ - MergeCmdLineResources(&db, (XrmOptionDescList)my_opts, 2, MyName, - &opt_argc, opt_argv, True /*no default options*/); - - /* Now parse the database values: */ - if (GetResourceString(db, "iconic", MyName, &value)) - { - /* Just see if there is *any* string and don't mind it's value. */ - /* flags |= ICONIC */ - } - if (GetResourceString(db, "bar", MyName, &value)) - { - /* ... */ - } - - /* ... */ - XrmDestroyDatabase(db); - } -#endif - -/*** END OF EXAMPLE ********************************************************/ - - - - /* Default option table */ -static XrmOptionDescRec default_opts[] = -{ - { "-fg", "*Foreground", XrmoptionSepArg, NULL }, - { "-bg", "*Background", XrmoptionSepArg, NULL }, - { "-fn", "*Font", XrmoptionSepArg, NULL }, - { "-geometry", "*Geometry", XrmoptionSepArg, NULL }, - { "-title", "*Title", XrmoptionSepArg, NULL } - /* Remember to update NUM_DEFAULT_OPTIONS if you change this list! */ +static XrmOptionDescRec default_opts[] = { + {"-fg", "*Foreground", XrmoptionSepArg, NULL}, + {"-bg", "*Background", XrmoptionSepArg, NULL}, + {"-fn", "*Font", XrmoptionSepArg, NULL}, + {"-geometry", "*Geometry", XrmoptionSepArg, NULL}, + {"-title", "*Title", XrmoptionSepArg, NULL} + /* Remember to update NUM_DEFAULT_OPTIONS if you change this list! */ }; #define NUM_DEFAULT_OPTS 5 - - /* internal function */ -static void DoMergeString(char *resource, XrmDatabase *ptarget, Bool override) +static void +DoMergeString(char *resource, XrmDatabase *ptarget, Bool override) { - XrmDatabase db; + XrmDatabase db; - if (!resource) - return; - db = XrmGetStringDatabase(resource); - XrmCombineDatabase(db, ptarget, override); + if (!resource) + return; + db = XrmGetStringDatabase(resource); + XrmCombineDatabase(db, ptarget, override); } /*************************************************************************** @@ -118,14 +45,15 @@ static void DoMergeString(char *resource, XrmDatabase *ptarget, Bool override) * if you do not need it amymore. * ***************************************************************************/ -void MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override) +void +MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override) { - if (!*pdb) - /* create new database */ - XrmPutStringResource(pdb, "", ""); - DoMergeString(XResourceManagerString(dpy), pdb, override); - DoMergeString(XScreenResourceString(DefaultScreenOfDisplay(dpy)), pdb, - override); + if (!*pdb) + /* create new database */ + XrmPutStringResource(pdb, "", ""); + DoMergeString(XResourceManagerString(dpy), pdb, override); + DoMergeString( + XScreenResourceString(DefaultScreenOfDisplay(dpy)), pdb, override); } /*************************************************************************** @@ -145,15 +73,15 @@ void MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override) * if you do not need it amymore. * ***************************************************************************/ -void MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, - int num_opts, char *name, int *pargc, char **argv, - Bool fNoDefaults) +void +MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, int num_opts, + char *name, int *pargc, char **argv, Bool fNoDefaults) { - if (opts && num_opts > 0) - XrmParseCommand(pdb, opts, num_opts, name, pargc, argv); - if (!fNoDefaults) - XrmParseCommand(pdb, default_opts, NUM_DEFAULT_OPTS, - name, pargc, argv); + if (opts && num_opts > 0) + XrmParseCommand(pdb, opts, num_opts, name, pargc, argv); + if (!fNoDefaults) + XrmParseCommand( + pdb, default_opts, NUM_DEFAULT_OPTS, name, pargc, argv); } /*************************************************************************** @@ -178,55 +106,56 @@ void MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, * if you do not need it amymore. * ***************************************************************************/ -Bool MergeConfigLineResource(XrmDatabase *pdb, char *line, char *prefix, - char *bindstr) +Bool +MergeConfigLineResource( + XrmDatabase *pdb, char *line, char *prefix, char *bindstr) { - int len; - char *end; - char *value; - char *myvalue; - char *resource; - size_t reslen; - - /* translate "*(prefix)(suffix)" to "(prefix)(binding)(suffix)", - * e.g. "*FvwmPagerGeometry" to "FvwmPager.Geometry" */ - if (!line || *line != '*') - return False; - - line++; - len = (prefix) ? strlen(prefix) : 0; - if (!prefix || strncasecmp(line, prefix, len)) - return False; - - line += len; - end = line; - while (*end && !isspace(*end)) - end++; - if (line == end) - return False; - value = end; - while (*value && isspace(*value)) - value++; - - /* prefix*suffix: value */ - reslen = len + (end - line) + 2; - resource = (char *)safemalloc(reslen); - strlcpy(resource, prefix,reslen); - strlcat(resource, bindstr,reslen); - strncat(resource, line, end - line); - - len = strlen(value); - myvalue = (char *)safemalloc(len + 1); - strlcpy(myvalue, value,len+1); - for (len--; len >= 0 && isspace(myvalue[len]); len--) - myvalue[len] = 0; - - /* merge string into database */ - XrmPutStringResource(pdb, resource, myvalue); - - free(resource); - free(myvalue); - return True; + int len; + char *end; + char *value; + char *myvalue; + char *resource; + size_t reslen; + + /* translate "*(prefix)(suffix)" to "(prefix)(binding)(suffix)", + * e.g. "*FvwmPagerGeometry" to "FvwmPager.Geometry" */ + if (!line || *line != '*') + return False; + + line++; + len = (prefix) ? strlen(prefix) : 0; + if (!prefix || strncasecmp(line, prefix, len)) + return False; + + line += len; + end = line; + while (*end && !isspace(*end)) + end++; + if (line == end) + return False; + value = end; + while (*value && isspace(*value)) + value++; + + /* prefix*suffix: value */ + reslen = len + (end - line) + 2; + resource = (char *)xmalloc(reslen); + strlcpy(resource, prefix, reslen); + strlcat(resource, bindstr, reslen); + strncat(resource, line, end - line); + + len = strlen(value); + myvalue = (char *)xmalloc(len + 1); + strlcpy(myvalue, value, len + 1); + for (len--; len >= 0 && isspace(myvalue[len]); len--) + myvalue[len] = 0; + + /* merge string into database */ + XrmPutStringResource(pdb, resource, myvalue); + + free(resource); + free(myvalue); + return True; } /*************************************************************************** @@ -246,30 +175,31 @@ Bool MergeConfigLineResource(XrmDatabase *pdb, char *line, char *prefix, * returns the string value of the "Geometry" resource for MyModule in s. * ***************************************************************************/ -Bool GetResourceString(XrmDatabase db, const char *resource, - const char *prefix, char **val) +Bool +GetResourceString( + XrmDatabase db, const char *resource, const char *prefix, char **val) { - XrmValue xval = { 0, NULL }; - char *str_type; - char *name; - size_t len; - - len = strlen(resource) + strlen(prefix) + 2; - name = (char *)safemalloc(len); - strlcpy(name, prefix,len); - strlcat(name, ".",len); - strlcat(name, resource,len); - - if (!XrmGetResource(db, name, name, &str_type, &xval) || xval.addr == NULL) - { - free(name); - if (val) - *val = NULL; - return False; - } - free(name); - if (val) - *val = xval.addr; - - return True; + XrmValue xval = {0, NULL}; + char *str_type; + char *name; + size_t len; + + len = strlen(resource) + strlen(prefix) + 2; + name = (char *)xmalloc(len); + strlcpy(name, prefix, len); + strlcat(name, ".", len); + strlcat(name, resource, len); + + if (!XrmGetResource(db, name, name, &str_type, &xval) || + xval.addr == NULL) { + free(name); + if (val) + *val = NULL; + return False; + } + free(name); + if (val) + *val = xval.addr; + + return True; } Index: fvwm/libs/debug.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/debug.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/debug.c --- fvwm/libs/debug.c +++ fvwm/libs/debug.c @@ -8,25 +8,14 @@ * 6 Nov 1998 - Paul D. Smith */ -#include "config.h" - -#include #include +#include +#include "config.h" #include "fvwmlib.h" -#ifndef HAVE_VFPRINTF -# define VA_PRINTF(fp, lastarg, args) _doprnt((lastarg), (args), (fp)) -#else -# define VA_PRINTF(fp, lastarg, args) vfprintf((fp), (lastarg), (args)) -#endif - -/* Don't put this into the #ifdef, since some compilers don't like completely - * empty source files. - */ int f_db_level = 0; - #ifdef DEBUG struct f_db_info f_db_info; @@ -34,15 +23,15 @@ struct f_db_info f_db_info; void f_db_print(const char *fmt, ...) { - va_list ap; + va_list ap; - fprintf(stderr, "%s:%ld: ", f_db_info.filenm, f_db_info.lineno); + fprintf(stderr, "%s:%ld: ", f_db_info.filenm, f_db_info.lineno); - va_start(ap, fmt); - VA_PRINTF(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - fputc('\n', stderr); + fputc('\n', stderr); } #endif Index: fvwm/libs/envvar.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/envvar.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/envvar.c --- fvwm/libs/envvar.c +++ fvwm/libs/envvar.c @@ -13,9 +13,9 @@ * **************************************************************************/ +#include #include #include -#include #include "fvwmlib.h" @@ -51,24 +51,23 @@ * characters back. * */ -static void strDel(char *s, int idx, int n) +static void +strDel(char *s, int idx, int n) { - int l; - char *p; + int l; + char *p; - if (idx >= (l = strlen(s))) - return; - if (idx + n > l) - n = l - idx; - s += idx; - p = s + n; - do { - *s++ = *p; - } while (*p++); + if (idx >= (l = strlen(s))) + return; + if (idx + n > l) + n = l - idx; + s += idx; + p = s + n; + do { + *s++ = *p; + } while (*p++); } - - /*------------------------------------------------------------------------- * * NAME strIns @@ -87,34 +86,33 @@ static void strDel(char *s, int idx, int n) * The string is always '\0'-terminated. * */ -static void strIns(char *s, const char *ins, int idx, int maxstrlen) +static void +strIns(char *s, const char *ins, int idx, int maxstrlen) { - int l, li, move; - char *p1, *p2; + int l, li, move; + char *p1, *p2; - if (idx > (l = strlen(s))) - idx = l; - li = strlen(ins); - move = l - idx + 1; /* include '\0' in move */ - p1 = s + l; - p2 = p1 + li; - while (p2 >= s + maxstrlen) { - --p1; - --p2; - --move; - } - while (move-- > 0) - *p2-- = *p1--; - p1 = s + idx; - if (idx + li >= maxstrlen) - li = maxstrlen - idx - 1; - while (li--) - *p1++ = *ins++; - s[maxstrlen - 1] = '\0'; + if (idx > (l = strlen(s))) + idx = l; + li = strlen(ins); + move = l - idx + 1; /* include '\0' in move */ + p1 = s + l; + p2 = p1 + li; + while (p2 >= s + maxstrlen) { + --p1; + --p2; + --move; + } + while (move-- > 0) + *p2-- = *p1--; + p1 = s + idx; + if (idx + li >= maxstrlen) + li = maxstrlen - idx - 1; + while (li--) + *p1++ = *ins++; + s[maxstrlen - 1] = '\0'; } - - /*------------------------------------------------------------------------- * * NAME findEnvVar @@ -138,41 +136,41 @@ static void strIns(char *s, const char *ins, int idx, int maxstrlen) * occurrences are skipped. * */ -static char *findEnvVar(const char *s, int *len) +static char * +findEnvVar(const char *s, int *len) { - int brace = 0; - char *ret = NULL; - const char *next; + int brace = 0; + char *ret = NULL; + const char *next; - if (!s) - return NULL; - while (*s) { - next = s + 1; - if (*s == '$' && (isalpha(*next) || *next == '_' || *next == '{')) { - ret = (char *) s++; - if (*s == '{') { - brace = 1; - ++s; - } - while (*s && (isalnum(*s) || *s == '_')) - ++s; - *len = s - ret; - if (brace) { - if (*s == '}') { - ++*len; - break; + if (!s) + return NULL; + while (*s) { + next = s + 1; + if (*s == '$' && + (isalpha(*next) || *next == '_' || *next == '{')) { + ret = (char *)s++; + if (*s == '{') { + brace = 1; + ++s; + } + while (*s && (isalnum(*s) || *s == '_')) + ++s; + *len = s - ret; + if (brace) { + if (*s == '}') { + ++*len; + break; + } + ret = NULL; + } else + break; } - ret = NULL; - } else - break; + ++s; } - ++s; - } - return ret; + return ret; } - - /*------------------------------------------------------------------------- * * NAME getEnv @@ -185,29 +183,28 @@ static char *findEnvVar(const char *s, int *len) * RETURNS The variable contents, or "" if not found. * */ -static const char *getEnv(const char *name) +static const char * +getEnv(const char *name) { - static char *empty = ""; - char *ret, *tmp, *p, *p2; + static char *empty = ""; + char *ret, *tmp, *p, *p2; - if ((tmp = strdup(name)) == NULL) - return empty; /* better than no test at all. */ - p = tmp; - if (*p == '$') - ++p; - if (*p == '{') { - ++p; - if ((p2 = strchr(p, '}')) != NULL) - *p2 = '\0'; - } - if ((ret = getenv(p)) == NULL) - ret = empty; - free(tmp); - return ret; + if ((tmp = strdup(name)) == NULL) + return empty; /* better than no test at all. */ + p = tmp; + if (*p == '$') + ++p; + if (*p == '{') { + ++p; + if ((p2 = strchr(p, '}')) != NULL) + *p2 = '\0'; + } + if ((ret = getenv(p)) == NULL) + ret = empty; + free(tmp); + return ret; } - - /************************************************************************** * * * P U B L I C F U N C T I O N S * @@ -234,28 +231,27 @@ static const char *getEnv(const char *name) * string. * */ -int envExpand(char *s, int maxstrlen) +int +envExpand(char *s, int maxstrlen) { - char *var, *s2, save; - const char *env; - int len, ret = 0; + char *var, *s2, save; + const char *env; + int len, ret = 0; - s2 = s; - while ((var = findEnvVar(s2, &len)) != NULL) { - ++ret; - save = var[len]; - var[len] = '\0'; - env = getEnv(var); - var[len] = save; - strDel(s, var - s, len); - strIns(s, env, var - s, maxstrlen); - s2 = var + strlen(env); - } - return ret; + s2 = s; + while ((var = findEnvVar(s2, &len)) != NULL) { + ++ret; + save = var[len]; + var[len] = '\0'; + env = getEnv(var); + var[len] = save; + strDel(s, var - s, len); + strIns(s, env, var - s, maxstrlen); + s2 = var + strlen(env); + } + return ret; } - - /*------------------------------------------------------------------------- * * NAME envDupExpand @@ -280,39 +276,40 @@ int envExpand(char *s, int maxstrlen) * string. * */ -char *envDupExpand(const char *s, int extra) +char * +envDupExpand(const char *s, int extra) { - char *var, *ret, save; - const char *env, *s2; - int len, slen, elen, bufflen; + char *var, *ret, save; + const char *env, *s2; + int len, slen, elen, bufflen; - /* - * calculate length needed. - */ - s2 = s; - slen = strlen(s); - bufflen = slen + 1 + extra; - while ((var = findEnvVar(s2, &len)) != NULL) { - save = var[len]; - var[len] = '\0'; - env = getEnv(var); - var[len] = save; - elen = strlen(env); - /* need to make a buffer the maximum possible size, else we - * may get trouble while expanding. */ - bufflen += len > elen ? len : elen; - s2 = var + len; - } - if (bufflen < slen + 1) - bufflen = slen + 1; + /* + * calculate length needed. + */ + s2 = s; + slen = strlen(s); + bufflen = slen + 1 + extra; + while ((var = findEnvVar(s2, &len)) != NULL) { + save = var[len]; + var[len] = '\0'; + env = getEnv(var); + var[len] = save; + elen = strlen(env); + /* need to make a buffer the maximum possible size, else we + * may get trouble while expanding. */ + bufflen += len > elen ? len : elen; + s2 = var + len; + } + if (bufflen < slen + 1) + bufflen = slen + 1; - ret = safemalloc(bufflen); + ret = xmalloc(bufflen); - /* - * now do the real expansion. - */ - strlcpy(ret, s,bufflen); - envExpand(ret, bufflen - extra); + /* + * now do the real expansion. + */ + strlcpy(ret, s, bufflen); + envExpand(ret, bufflen - extra); - return ret; + return ret; } Index: fvwm/libs/fvwmlib.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/fvwmlib.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/fvwmlib.h --- fvwm/libs/fvwmlib.h +++ fvwm/libs/fvwmlib.h @@ -1,47 +1,38 @@ #ifndef FVWMLIB_H #define FVWMLIB_H +#include /* needed for xpm.h and Pixel defn */ #include -#include #include -#include /* needed for xpm.h and Pixel defn */ +#include #include -/* Allow GCC extensions to work, if you have GCC */ - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__) -# define __attribute__(x) -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - /*********************************************************************** * Generic debugging ***********************************************************************/ #ifndef DEBUG -# define DB(_x) +#define DB(_x) #else -# ifndef __FILE__ -# define __FILE__ "?" -# define __LINE__ 0 -# endif -# define DB(_x) do{f_db_info.filenm=__FILE__;f_db_info.lineno=__LINE__;\ - f_db_print _x;}while(0) -struct f_db_info { const char *filenm; unsigned long lineno; }; +#ifndef __FILE__ +#define __FILE__ "?" +#define __LINE__ 0 +#endif +#define DB(_x) \ + do { \ + f_db_info.filenm = __FILE__; \ + f_db_info.lineno = __LINE__; \ + f_db_print _x; \ + } while (0) +struct f_db_info { + const char *filenm; + unsigned long lineno; +}; extern struct f_db_info f_db_info; extern void f_db_print(const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 1, 2))); + __attribute__((__format__(__printf__, 1, 2))); #endif - /*********************************************************************** * Routines for dealing with strings ***********************************************************************/ @@ -49,9 +40,9 @@ extern void f_db_print(const char *fmt, ...) char *CatString3(char *a, char *b, char *c); void CopyString(char **dest, char *source); char *stripcpy(char *source); -int StrEquals(char *s1,char *s2); +int StrEquals(char *s1, char *s2); -int envExpand(char *s, int maxstrlen); +int envExpand(char *s, int maxstrlen); char *envDupExpand(const char *s, int extra); int matchWildcards(char *pattern, char *string); @@ -59,37 +50,43 @@ int matchWildcards(char *pattern, char *string); /*********************************************************************** * Stuff for consistent parsing ***********************************************************************/ -#define EatWS(s) do { while ((s) && (isspace(*(s)) || *(s) == ',')) (s)++; } while (0) -#define IsQuote(c) ((c) == '"' || (c) == '\'' || (c) =='`') +#define EatWS(s) \ + do { \ + while ((s) && (isspace(*(s)) || *(s) == ',')) \ + (s)++; \ + } while (0) +#define IsQuote(c) ((c) == '"' || (c) == '\'' || (c) == '`') #define IsBlockStart(c) ((c) == '[' || (c) == '{' || (c) == '(') -#define IsBlockEnd(c,cs) (((c) == ']' && (cs) == '[') || ((c) == '}' && (cs) == '{') || ((c) == ')' && (cs) == '(')) +#define IsBlockEnd(c, cs) \ + (((c) == ']' && (cs) == '[') || ((c) == '}' && (cs) == '{') || \ + ((c) == ')' && (cs) == '(')) #define MAX_TOKEN_LENGTH 255 -char *SkipQuote(char *s, const char *qlong, const char *qstart, - const char *qend); +char *SkipQuote( + char *s, const char *qlong, const char *qstart, const char *qend); char *GetQuotedString(char *sin, char **sout, const char *delims, - const char *qlong, const char *qstart, const char *qend); + const char *qlong, const char *qstart, const char *qend); char *PeekToken(const char *pstr); char *GetToken(char **pstr); -int CmpToken(const char *pstr,char *tok); -int MatchToken(const char *pstr,char *tok); +int CmpToken(const char *pstr, char *tok); +int MatchToken(const char *pstr, char *tok); void NukeToken(char **pstr); /* old style parse routine: */ -char *DoGetNextToken(char *indata,char **token, char *spaces, char *delims, - char *out_delim); -char *GetNextToken(char *indata,char **token); -char *GetNextOption(char *indata,char **token); +char *DoGetNextToken( + char *indata, char **token, char *spaces, char *delims, char *out_delim); +char *GetNextToken(char *indata, char **token); +char *GetNextOption(char *indata, char **token); char *SkipNTokens(char *indata, unsigned int n); char *GetModuleResource(char *indata, char **resource, char *module_name); -int GetIntegerArguments(char *action, char**ret_action, int retvals[],int num); +int GetIntegerArguments( + char *action, char **ret_action, int retvals[], int num); int GetTokenIndex(char *token, char *list[], int len, char **next); char *GetNextTokenIndex(char *action, char *list[], int len, int *index); int GetRectangleArguments(char *action, int *width, int *height); int GetOnePercentArgument(char *action, int *value, int *unit_io); -int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, - int *val2_unit); - +int GetTwoPercentArguments( + char *action, int *val1, int *val2, int *val1_unit, int *val2_unit); /*********************************************************************** * Various system related utils @@ -97,13 +94,12 @@ int GetTwoPercentArguments(char *action, int *val1, int *val2, int *val1_unit, int GetFdWidth(void); int getostype(char *buf, int max); -char *safemalloc(int); /*********************************************************************** * Stuff for modules to communicate with fvwm ***********************************************************************/ int ReadFvwmPacket(int fd, unsigned long *header, unsigned long **body); -void SendText(int *fd,char *message,unsigned long window); +void SendText(int *fd, char *message, unsigned long window); #define SendInfo SendText void GetConfigLine(int *fd, char **tline); void SetMessageMask(int *fd, unsigned long mask); @@ -111,34 +107,32 @@ void SetMessageMask(int *fd, unsigned long mask); /*********************************************************************** * Stuff for dealing w/ bitmaps & pixmaps: ***********************************************************************/ -typedef struct PictureThing -{ - struct PictureThing *next; - char *name; - Pixmap picture; - Pixmap mask; - unsigned int depth; - unsigned int width; - unsigned int height; - unsigned int count; +typedef struct PictureThing { + struct PictureThing *next; + char *name; + Pixmap picture; + Pixmap mask; + unsigned int depth; + unsigned int width; + unsigned int height; + unsigned int count; } FvwmPicture; -void InitPictureCMap(Display*,Window); -FvwmPicture *GetPicture(Display* dpy, Window Root, char* IconPath, - char* PixmapPath, char* name, int color_limit); -FvwmPicture *CachePicture(Display*,Window,char *iconpath, - char *pixmappath,char*,int); -void DestroyPicture(Display*,FvwmPicture*); +void InitPictureCMap(Display *, Window); +FvwmPicture *GetPicture(Display *dpy, Window Root, char *IconPath, + char *PixmapPath, char *name, int color_limit); +FvwmPicture *CachePicture( + Display *, Window, char *iconpath, char *pixmappath, char *, int); +void DestroyPicture(Display *, FvwmPicture *); char *findIconFile(char *icon, char *pathlist, int type); #ifdef XPM -#include /* needed for next prototype */ +#include /* needed for next prototype */ void color_reduce_pixmap(XpmImage *, int); #endif -Pixel GetShadow(Pixel); /* 3d.c */ -Pixel GetHilite(Pixel); /* 3d.c */ - +Pixel GetShadow(Pixel); /* 3d.c */ +Pixel GetHilite(Pixel); /* 3d.c */ /*********************************************************************** * Wrappers around various X11 routines @@ -149,19 +143,17 @@ XFontStruct *GetFontOrFixed(Display *disp, char *fontname); void MyXGrabServer(Display *disp); void MyXUngrabServer(Display *disp); -void send_clientmessage (Display *disp, Window w, Atom a, Time timestamp); +void send_clientmessage(Display *disp, Window w, Atom a, Time timestamp); /*********************************************************************** * Wrappers around Xrm routines (XResources.c) ***********************************************************************/ void MergeXResources(Display *dpy, XrmDatabase *pdb, Bool override); void MergeCmdLineResources(XrmDatabase *pdb, XrmOptionDescList opts, - int num_opts, char *name, int *pargc, char **argv, - Bool fNoDefaults); -Bool MergeConfigLineResource(XrmDatabase *pdb, char *line, char *prefix, - char *bindstr); -Bool GetResourceString(XrmDatabase db, const char *resource, - const char *prefix, char **val); - + int num_opts, char *name, int *pargc, char **argv, Bool fNoDefaults); +Bool MergeConfigLineResource( + XrmDatabase *pdb, char *line, char *prefix, char *bindstr); +Bool GetResourceString( + XrmDatabase db, const char *resource, const char *prefix, char **val); #endif Index: fvwm/libs/lang-strings.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/lang-strings.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/lang-strings.h --- fvwm/libs/lang-strings.h +++ fvwm/libs/lang-strings.h @@ -1,9 +1,9 @@ /*************************************************************************** - * Please translate the strings into the language which you use for + * Please translate the strings into the language which you use for * your pop-up menus. * - * Some decisions about where a function is prohibited (based on - * mwm-function-hints) is based on a string comparison between the + * Some decisions about where a function is prohibited (based on + * mwm-function-hints) is based on a string comparison between the * menu item and the strings below. ***************************************************************************/ #define MOVE_STRING "move" Index: fvwm/libs/safemalloc.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/safemalloc.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/safemalloc.c --- fvwm/libs/safemalloc.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include - -/*********************************************************************** - * - * Procedure: - * safemalloc - mallocs specified space or exits if there's a - * problem - * - ***********************************************************************/ -char *safemalloc(int length) -{ - char *ptr; - - if(length <= 0) - length = 1; - - ptr = malloc(length); - if(ptr == (char *)0) - { - fprintf(stderr,"malloc of %d bytes failed. Exiting\n",length); - exit(1); - } - return ptr; -} - - Index: fvwm/libs/wild.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/wild.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/wild.c --- fvwm/libs/wild.c +++ fvwm/libs/wild.c @@ -1,9 +1,9 @@ #include #include -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 #endif /***************************************************************************** @@ -11,66 +11,55 @@ * (including the null string) '?' matches any single char. For use * by filenameforall. Note that '*' matches across directory boundaries * - * This code donated by Paul Hudson + * This code donated by Paul Hudson * It is public domain, no strings attached. No guarantees either. * *****************************************************************************/ -int matchWildcards(char *pattern, char *string) +int +matchWildcards(char *pattern, char *string) { - if(string == NULL) - { - if(pattern == NULL) - return TRUE; - else if(strcmp(pattern,"*")==0) - return TRUE; - else - return FALSE; - } - if(pattern == NULL) - return TRUE; - - while (*string && *pattern) - { - if (*pattern == '?') - { - /* match any character */ - pattern += 1; - string += 1; + if (string == NULL) { + if (pattern == NULL) + return TRUE; + else if (strcmp(pattern, "*") == 0) + return TRUE; + else + return FALSE; } - else if (*pattern == '*') - { - /* see if the rest of the pattern matches any trailing substring - of the string. */ - pattern += 1; - if (*pattern == 0) - { - return TRUE; /* trailing * must match rest */ - } - while (*string) - { - if (matchWildcards(pattern,string)) - { - return TRUE; + if (pattern == NULL) + return TRUE; + + while (*string && *pattern) { + if (*pattern == '?') { + /* match any character */ + pattern += 1; + string += 1; + } else if (*pattern == '*') { + /* see if the rest of the pattern matches any trailing + substring of the string. */ + pattern += 1; + if (*pattern == 0) { + return TRUE; /* trailing * must match rest */ + } + while (*string) { + if (matchWildcards(pattern, string)) { + return TRUE; + } + string++; + } + return FALSE; + } else { + if (*pattern == '\\') + pattern++; /* has strange, but harmless effects + if the last character is a '\\' */ + if (*pattern++ != *string++) { + return FALSE; + } } - string++; - } - return FALSE; } - else - { - if (*pattern == '\\') - pattern ++; /* has strange, but harmless effects if the last - character is a '\\' */ - if (*pattern++ != *string++) - { - return FALSE; - } - } - } - if((*pattern == 0)&&(*string == 0)) - return TRUE; - if((*string == 0)&&(strcmp(pattern,"*")==0)) - return TRUE; - return FALSE; + if ((*pattern == 0) && (*string == 0)) + return TRUE; + if ((*string == 0) && (strcmp(pattern, "*") == 0)) + return TRUE; + return FALSE; } - --- /dev/null +++ fvwm/fvwm/exec.c @@ -0,0 +1,208 @@ +/* + * exec.c -- interface to the privilege-separated execution helper. + * + * The main fvwm process communicates with fvwm_exec via imsg(3) + * over a socketpair(2). The helper executes external commands + * without inheriting the X11 connection. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "config.h" +#include "fvwm.h" +#include "misc.h" + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +static struct imsgbuf *exec_ibuf; +static int exec_fd = -1; +static pid_t exec_pid = -1; + +/* + * exec_helper_start -- fork and exec the execution helper. + * The helper receives one end of a socketpair for imsg communication. + */ +void +exec_helper_start(void) +{ + int sv[2]; + + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sv) == -1) + err(1, "socketpair"); + + exec_pid = fork(); + if (exec_pid == -1) + err(1, "fork"); + + if (exec_pid == 0) { + char fdstr[32]; + + close(sv[0]); + snprintf(fdstr, sizeof(fdstr), "%d", sv[1]); + setenv("FVWM_EXEC_FD", fdstr, 1); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + execl(FVWMLIBDIR "/fvwm_exec", "fvwm_exec", NULL); + err(1, "execl %s/fvwm_exec", FVWMLIBDIR); + } + + close(sv[1]); + exec_fd = sv[0]; + + exec_ibuf = malloc(sizeof(struct imsgbuf)); + if (exec_ibuf == NULL) + err(1, "malloc"); + imsg_init(exec_ibuf, exec_fd); +} + +/* + * exec_helper_stop -- request helper shutdown and reap. + */ +void +exec_helper_stop(void) +{ + if (exec_ibuf == NULL) + return; + + imsg_clear(exec_ibuf); + close(exec_fd); + free(exec_ibuf); + exec_ibuf = NULL; + exec_fd = -1; + + if (exec_pid > 0) { + kill(exec_pid, SIGTERM); + waitpid(exec_pid, NULL, 0); + exec_pid = -1; + } +} + +/* + * exec_helper_handle -- process imsg responses from the helper. + * Called from the event loop when exec_fd is readable. + */ +void +exec_helper_handle(void) +{ + struct imsg imsg; + ssize_t n; + + if (exec_ibuf == NULL) + return; + + if ((n = imsg_read(exec_ibuf)) == -1 && errno != EAGAIN) + warn("imsg_read"); + if (n == 0) { + warnx("exec helper disconnected"); + exec_helper_stop(); + return; + } + + while ((n = imsg_get(exec_ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_OK: { + pid_t pid; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(pid_t))) + break; + memcpy(&pid, imsg.data, sizeof(pid_t)); + break; + } + case IMSG_EXEC_ERROR: { + int errnum; + + if (imsg.hdr.len < (IMSG_HEADER_SIZE + sizeof(int))) + break; + memcpy(&errnum, imsg.data, sizeof(int)); + warnc(errnum, "exec helper reported error"); + break; + } + case IMSG_EXEC_EXIT: { + /* Module/command exit; handled by signal watching */ + break; + } + default: + break; + } + imsg_free(&imsg); + } +} + +/* + * exec_helper_launch -- request the helper to execute a command. + * On success, returns 0. On failure (fork error in helper), returns -1. + */ +int +exec_helper_launch(int argc, char **argv, char **envp) +{ + struct ibuf *buf; + size_t datalen, total; + int cargc = argc - 1; /* skip argv[0] which is the path */ + int envc = 0; + int i, ret = -1; + int fd; + + if (exec_ibuf == NULL) + return -1; + + /* Calculate total payload size: sizeof(int)*2 + all strings */ + datalen = sizeof(int) * 2; + for (i = 1; i < argc; i++) + datalen += strlen(argv[i]) + 1; + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + datalen += strlen(envp[i]) + 1; + envc++; + } + } + + if (datalen > MAX_BODY_SIZE * sizeof(unsigned long)) { + warnx("exec argument too large"); + return -1; + } + + /* Compose and send the request */ + buf = imsg_create(exec_ibuf, IMSG_EXEC_RUN, 0, 0, datalen); + if (buf == NULL) + return -1; + + /* argc */ + buf->wpos += imsg_add(buf, &cargc, sizeof(int)); + /* envc */ + buf->wpos += imsg_add(buf, &envc, sizeof(int)); + /* strings */ + for (i = 1; i < argc; i++) { + buf->wpos += imsg_add(buf, argv[i], strlen(argv[i]) + 1); + } + if (envp) { + for (i = 0; envp[i] != NULL; i++) { + buf->wpos += imsg_add(buf, envp[i], + strlen(envp[i]) + 1); + } + } + imsg_close(exec_ibuf, buf); + imsg_flush(exec_ibuf); + + return 0; +} --- /dev/null +++ fvwm/fvwm/fvwm_exec.c @@ -0,0 +1,169 @@ +/* + * fvwm_exec.c -- privilege-separated execution helper for fvwm(1) + * + * Runs as a separate process that receives exec requests via imsg(3) + * from the main fvwm process, executes them, and reports results. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "config.h" + +/* + * imsg_exec -- structured IPC message types for execution requests. + * + * Message flow: + * fvwm -> helper: IMSG_EXEC_RUN (path + argv + envp) + * helper -> fvwm: IMSG_EXEC_OK (pid of launched child) + * IMSG_EXEC_ERROR (errno + message) + * IMSG_EXEC_EXIT (pid + status, sent on child exit) + */ + +enum imsg_exec_type { + IMSG_EXEC_RUN = 0, + IMSG_EXEC_OK, + IMSG_EXEC_ERROR, + IMSG_EXEC_EXIT, +}; + +__dead static void +usage(void) +{ + extern char *__progname; + + fprintf(stderr, "usage: %s\n", __progname); + exit(1); +} + +static void +exec_child(int argc, char **argv, char **envp) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "pledge"); + + closefrom(3); + + if (envp) + execve(argv[0], argv, envp); + else + execv(argv[0], argv); + + err(1, "execv: %s", argv[0]); +} + +int +main(int argc, char **argv) +{ + struct imsgbuf ibuf; + struct imsg imsg; + ssize_t n; + int s; + + if (argc != 1) + usage(); + + if (getenv("FVWM_EXEC_FD") == NULL) + errx(1, "FVWM_EXEC_FD not set"); + + s = (int)strtonum(getenv("FVWM_EXEC_FD"), 0, INT_MAX, NULL); + + signal(SIGPIPE, SIG_IGN); + + imsg_init(&ibuf, s); + + if (pledge("stdio proc exec", NULL) == -1) + err(1, "pledge"); + + for (;;) { + if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) + err(1, "imsg_read"); + if (n == 0) + break; + + while ((n = imsg_get(&ibuf, &imsg)) != -1) { + if (n == 0) + break; + + switch (imsg.hdr.type) { + case IMSG_EXEC_RUN: { + pid_t pid; + char **child_argv; + char **child_envp; + int cargc, envc; + char *data = imsg.data; + + if (imsg.hdr.len < sizeof(int) * 2) { + warnx("short IMSG_EXEC_RUN"); + break; + } + memcpy(&cargc, data, sizeof(int)); + memcpy(&envc, data + sizeof(int), sizeof(int)); + data += sizeof(int) * 2; + + /* Reconstruct argv */ + child_argv = malloc( + (cargc + 1) * sizeof(char *)); + if (child_argv == NULL) + err(1, "malloc"); + for (int i = 0; i < cargc; i++) { + size_t len = strlen(data); + child_argv[i] = data; + data += len + 1; + } + child_argv[cargc] = NULL; + + /* Reconstruct envp */ + child_envp = malloc( + (envc + 1) * sizeof(char *)); + if (child_envp == NULL) + err(1, "malloc"); + for (int i = 0; i < envc; i++) { + size_t len = strlen(data); + child_envp[i] = data; + data += len + 1; + } + child_envp[envc] = NULL; + + pid = fork(); + if (pid == -1) { + warn("fork"); + imsg_compose(&ibuf, IMSG_EXEC_ERROR, + 0, 0, -1, &errno, sizeof(int)); + free(child_argv); + free(child_envp); + break; + } + if (pid == 0) + exec_child(cargc, child_argv, + child_envp); + + free(child_argv); + free(child_envp); + + imsg_compose(&ibuf, IMSG_EXEC_OK, + 0, 0, -1, &pid, sizeof(pid_t)); + imsg_flush(&ibuf); + break; + } + default: + warnx("unknown imsg type %d", + imsg.hdr.type); + break; + } + imsg_free(&imsg); + } + } + + imsg_clear(&ibuf); + close(s); + return 0; +} --- /dev/null +++ fvwm/fvwm/fvwm_sandbox.h @@ -0,0 +1,187 @@ +/* + * fvwm_sandbox.h -- common sandbox helper for fvwm processes. + * + * Provides pledge/unveil setup patterns used across the fvwm module set. + * Each module calls only the helpers it needs; there is no "one size fits + * all" policy. + * + * All pledge/unveil calls check return values and fail with diagnostics. + * + * IMPORTANT: Every policy declared here requires verification on a real + * OpenBSD system with ktrace(1) and a full X11 session. + */ + +#ifndef FVWM_SANDBOX_H +#define FVWM_SANDBOX_H + +#ifndef FVWMLIBDIR +#define FVWMLIBDIR "/usr/X11R6/lib/X11/fvwm" +#endif + +/* + * sandbox_x11_only -- process that only needs X11 + stdio + fvwm pipes. + * No filesystem access, no network, no process creation. + * Used by: FvwmAuto, FvwmBanner, FvwmBacker, FvwmIdent, FvwmIconBox, + * FvwmPager, FvwmScroll, FvwmTalk, FvwmWinList + */ +static inline void +sandbox_x11_only(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_x11_config -- X11 + read-only config file access. + * No write, no network, no process creation. + * Used by: FvwmButtons, FvwmIconMan (after config read), + * FvwmForm (after /dev/null open) + */ +static inline void +sandbox_x11_config(const char *progname) +{ + if (pledge("stdio rpath", NULL) == -1) + err(1, "%s: pledge stdio rpath", progname); +} + +/* + * sandbox_save_state -- X11 + write to home directory. + * No network, no process creation. + * Used by: FvwmSave, FvwmSaveDesk + * + * Unveil is set up BEFORE calling this to restrict to the exact file. + */ +static inline void +sandbox_save_state(const char *progname) +{ + if (pledge("stdio rpath wpath cpath", NULL) == -1) + err(1, "%s: pledge stdio rpath wpath cpath", progname); +} + +/* + * sandbox_cpp_preproc -- X11 + fork/exec cpp + tmp + dns. + * Used by: FvwmCpp + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_cpp_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_m4_preproc -- X11 + popen m4 + tmp + dns. + * Used by: FvwmM4 + * + * Unveil is set up BEFORE calling this. + */ +static inline void +sandbox_m4_preproc(const char *progname) +{ + if (pledge("stdio rpath wpath cpath proc exec dns getpw", + NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_xpmroot -- X11-only utility, no filesystem writes. + */ +static inline void +sandbox_xpmroot(const char *progname) +{ + if (pledge("stdio", NULL) == -1) + err(1, "%s: pledge stdio", progname); +} + +/* + * sandbox_main_fvwm -- main window manager process. + * After startup: retains proc for module fork, exec for helper launch, + * rpath for config reads. + */ +static inline void +sandbox_main_fvwm(const char *progname) +{ + if (unveil(FVWMLIBDIR, "rx") == -1) + err(1, "%s: unveil %s", progname, FVWMLIBDIR); + if (unveil("/etc/X11/fvwm", "r") == -1) + err(1, "%s: unveil /etc/X11/fvwm", progname); + if (unveil("/tmp", "rwc") == -1) + err(1, "%s: unveil /tmp", progname); + if (unveil(NULL, NULL) == -1) + err(1, "%s: unveil lock", progname); + + if (pledge("stdio rpath proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_helper -- fvwm_exec helper process. + * Receives imsg requests, forks children, and execs them. + */ +static inline void +sandbox_exec_helper(const char *progname) +{ + if (pledge("stdio proc exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * sandbox_exec_child -- child of the execution helper, about to exec. + */ +static inline void +sandbox_exec_child(const char *progname) +{ + if (pledge("stdio exec", NULL) == -1) + err(1, "%s: pledge", progname); +} + +/* + * unveil_tempdir -- unveil the temporary directory (from $TMPDIR or /tmp). + * For modules that create temp files (FvwmCpp, FvwmM4). + */ +static inline void +unveil_tempdir(const char *progname) +{ + const char *tmp; + + tmp = getenv("TMPDIR"); + if (tmp == NULL) + tmp = "/tmp"; + if (unveil(tmp, "rwc") == -1) + err(1, "%s: unveil %s", progname, tmp); +} + +/* + * unveil_home_read -- unveil $HOME for reading only. + */ +static inline void +unveil_home_read(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "r") == -1) + err(1, "%s: unveil %s", progname, home); +} + +/* + * unveil_home_write -- unveil $HOME for read/write/create. + */ +static inline void +unveil_home_write(const char *progname) +{ + const char *home; + + home = getenv("HOME"); + if (home == NULL) + home = "."; + if (unveil(home, "rwc") == -1) + err(1, "%s: unveil %s", progname, home); +} + +#endif /* FVWM_SANDBOX_H */ --- /dev/null +++ fvwm/fvwm/xalloc.h @@ -0,0 +1,77 @@ +#ifndef FVWM_XALLOC_H +#define FVWM_XALLOC_H + +#include +#include +#include + +static inline void * +xmalloc(size_t size) +{ + void *ptr; + + if (size == 0) + size = 1; + ptr = malloc(size); + if (ptr == NULL) + err(1, "malloc"); + return ptr; +} + +static inline void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (nmemb == 0 || size == 0) { + nmemb = 1; + size = 1; + } + ptr = calloc(nmemb, size); + if (ptr == NULL) + err(1, "calloc"); + return ptr; +} + +static inline void * +xrealloc(void *ptr, size_t size) +{ + void *newptr; + + if (size == 0) + size = 1; + newptr = realloc(ptr, size); + if (newptr == NULL) + err(1, "realloc"); + return newptr; +} + +static inline void * +xreallocarray(void *ptr, size_t nmemb, size_t size) +{ + return xrealloc(ptr, nmemb * size); +} + +static inline char * +xstrdup(const char *s) +{ + char *copy; + + copy = strdup(s); + if (copy == NULL) + err(1, "strdup"); + return copy; +} + +static inline char * +xstrndup(const char *s, size_t n) +{ + char *copy; + + copy = strndup(s, n); + if (copy == NULL) + err(1, "strndup"); + return copy; +} + +#endif /* FVWM_XALLOC_H */ Index: fvwm/fvwm/Makefile =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/Makefile,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/Makefile --- fvwm/fvwm/Makefile +++ fvwm/fvwm/Makefile @@ -11,6 +11,7 @@ SRCS= add_window.c bindings.c borders.c \ virtual.c windows.c CPPFLAGS+= -DFVWM_MODULEDIR=\"$(FVWMLIBDIR)\" \ + -DFVWMLIBDIR=\"$(FVWMLIBDIR)\" \ -DFVWMRC=\".fvwmrc\" \ -DFVWM_CONFIGDIR=\"$(FVWMLIBDIR)\" Index: fvwm/fvwm/events.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/events.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/events.c --- fvwm/fvwm/events.c +++ fvwm/fvwm/events.c @@ -37,8 +37,6 @@ #include "config.h" -#endif - #include #include @@ -1478,9 +1476,7 @@ My_XNextEvent(Display *dpy, XEvent *event) DBUG("My_XNextEvent", "waiting for module input/output"); XFlush(dpy); - if (select((SELECT_TYPE_ARG1)fd_width, SELECT_TYPE_ARG234 & in_fdset, - SELECT_TYPE_ARG234 & out_fdset, SELECT_TYPE_ARG234 0, - SELECT_TYPE_ARG5 NULL) > 0) { + if (select(fd_width, &in_fdset, &out_fdset, NULL, NULL) > 0) { /* Check for module input. */ for (i = 0; i < npipes; i++) { if (readPipes[i] >= 0) { Index: fvwm/fvwm/exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/exec.c --- fvwm/fvwm/exec.c +++ fvwm/fvwm/exec.c @@ -21,6 +21,7 @@ #include "config.h" #include "fvwm.h" +#include "module.h" #include "misc.h" enum imsg_exec_type { @@ -70,7 +71,8 @@ exec_helper_start(void) exec_ibuf = malloc(sizeof(struct imsgbuf)); if (exec_ibuf == NULL) err(1, "malloc"); - imsg_init(exec_ibuf, exec_fd); + if (imsgbuf_init(exec_ibuf, exec_fd) == -1) + err(1, "imsgbuf_init"); } /* @@ -82,7 +84,7 @@ exec_helper_stop(void) if (exec_ibuf == NULL) return; - imsg_clear(exec_ibuf); + imsgbuf_clear(exec_ibuf); close(exec_fd); free(exec_ibuf); exec_ibuf = NULL; @@ -108,8 +110,8 @@ exec_helper_handle(void) if (exec_ibuf == NULL) return; - if ((n = imsg_read(exec_ibuf)) == -1 && errno != EAGAIN) - warn("imsg_read"); + if ((n = imsgbuf_read(exec_ibuf)) == -1 && errno != EAGAIN) + warn("imsgbuf_read"); if (n == 0) { warnx("exec helper disconnected"); exec_helper_stop(); @@ -202,7 +204,7 @@ exec_helper_launch(int argc, char **argv, char **envp) } } imsg_close(exec_ibuf, buf); - imsg_flush(exec_ibuf); + imsgbuf_flush(exec_ibuf); return 0; } Index: fvwm/fvwm/fvwm.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm.h --- fvwm/fvwm/fvwm.h +++ fvwm/fvwm/fvwm.h @@ -40,6 +40,8 @@ #include #include +#include "xalloc.h" + #ifndef WithdrawnState #define WithdrawnState 0 #endif Index: fvwm/fvwm/fvwm_exec.c =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_exec.c,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_exec.c --- fvwm/fvwm/fvwm_exec.c +++ fvwm/fvwm/fvwm_exec.c @@ -10,7 +10,9 @@ #include #include +#include #include +#include #include #include #include @@ -78,14 +80,15 @@ main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - imsg_init(&ibuf, s); + if (imsgbuf_init(&ibuf, s) == -1) + err(1, "imsgbuf_init"); if (pledge("stdio proc exec", NULL) == -1) err(1, "pledge"); for (;;) { - if ((n = imsg_read(&ibuf)) == -1 && errno != EAGAIN) - err(1, "imsg_read"); + if ((n = imsgbuf_read(&ibuf)) == -1 && errno != EAGAIN) + err(1, "imsgbuf_read"); if (n == 0) break; @@ -151,7 +154,7 @@ main(int argc, char **argv) imsg_compose(&ibuf, IMSG_EXEC_OK, 0, 0, -1, &pid, sizeof(pid_t)); - imsg_flush(&ibuf); + imsgbuf_flush(&ibuf); break; } default: @@ -163,7 +166,7 @@ main(int argc, char **argv) } } - imsg_clear(&ibuf); + imsgbuf_clear(&ibuf); close(s); return 0; } Index: fvwm/fvwm/fvwm_sandbox.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwm_sandbox.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwm_sandbox.h --- fvwm/fvwm/fvwm_sandbox.h +++ fvwm/fvwm/fvwm_sandbox.h @@ -14,6 +14,8 @@ #ifndef FVWM_SANDBOX_H #define FVWM_SANDBOX_H +#include + #ifndef FVWMLIBDIR #define FVWMLIBDIR "/usr/X11R6/lib/X11/fvwm" #endif Index: fvwm/fvwm/fvwmdebug.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/fvwmdebug.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/fvwmdebug.h --- fvwm/fvwm/fvwmdebug.h +++ fvwm/fvwm/fvwmdebug.h @@ -27,4 +27,8 @@ void DB_WI_ALL(char *label, FvwmWindow *fw); #define DB_WI_ALL(x, y) #endif +#ifndef DBUG +#define DBUG(x, y) do { (void)(x); (void)(y); } while (0) +#endif + #endif /* _DEBUG_ */ Index: fvwm/fvwm/module.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/fvwm/module.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/fvwm/module.h --- fvwm/fvwm/module.h +++ fvwm/fvwm/module.h @@ -1,6 +1,8 @@ #ifndef MODULE_H #define MODULE_H +#include "xalloc.h" + struct queue_buff_struct { struct queue_buff_struct *next; unsigned long *data; Index: fvwm/libs/fvwmlib.h =================================================================== RCS file: /cvs/src/xenocara/app/fvwm/libs/fvwmlib.h,v retrieving revision 1.1 diff -u -r1.1 fvwm/libs/fvwmlib.h --- fvwm/libs/fvwmlib.h +++ fvwm/libs/fvwmlib.h @@ -7,6 +7,8 @@ #include #include +#include "../fvwm/xalloc.h" + /*********************************************************************** * Generic debugging ***********************************************************************/